Skip to content

Commit

Permalink
added methods to export posts
Browse files Browse the repository at this point in the history
  • Loading branch information
ttp committed Aug 18, 2016
1 parent d69fc21 commit 68c3c1d
Show file tree
Hide file tree
Showing 2 changed files with 68 additions and 5 deletions.
37 changes: 32 additions & 5 deletions fish-map/fish_map.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@
require_once 'includes/marker_model.php';
require_once 'includes/fish_model.php';
require_once 'includes/gallery_model.php';
require_once 'includes/post_info.php';
require_once 'includes/marker_info.php';
require_once 'includes/markers_cache.php';
require_once 'fish_map_views.php';
Expand All @@ -77,6 +78,11 @@
add_action('wp_ajax_nopriv_fish_map_marker_post', 'fish_map_marker_post');
add_action('wp_ajax_fish_map_marker_post', 'fish_map_marker_post');

add_action('wp_ajax_nopriv_fish_map_post_info', 'fish_map_post_info');
add_action('wp_ajax_fish_map_post_info', 'fish_map_post_info');
add_action('wp_ajax_nopriv_fish_map_posts_ids', 'fish_map_posts_ids');
add_action('wp_ajax_fish_map_posts_ids', 'fish_map_posts_ids');

add_action('wp_ajax_nopriv_fish_map_fishes', 'fish_map_fishes');
add_action('wp_ajax_fish_map_fishes', 'fish_map_fishes');

Expand Down Expand Up @@ -214,11 +220,32 @@ function fish_map_marker_post() {
$marker_row = $markerModel->getById($marker_id);

if ($marker_row['post_id']) {
$marker_post = get_post($marker_row['post_id'], ARRAY_A);
$marker_post['rendered_content'] = get_post_content_by_id($marker_row['post_id']);
$marker_post['featured_image'] = wp_get_attachment_url( get_post_thumbnail_id($marker_row['post_id']) );
$marker_post['_yoast_wpseo_title'] = get_post_meta($marker_row['post_id'], '_yoast_wpseo_title', true);
$marker_post['_yoast_wpseo_metadesc'] = get_post_meta($marker_row['post_id'], '_yoast_wpseo_metadesc', true);
$postInfo = new PostInfo($marker_row['post_id']);
$marker_post = $postInfo->getPostInfo();
} else {
$marker_post = array();
}
echo json_encode($marker_post, JSON_UNESCAPED_UNICODE);
die();
}

function fish_map_posts_ids() {
if (!is_export_info_request()) {
die();
}

echo json_encode(PostInfo::getPostIds(), JSON_UNESCAPED_UNICODE);
die();
}

function fish_map_post_info() {
if (!is_export_info_request()) {
die();
}

if ($_GET['post_id']) {
$postInfo = new PostInfo($_GET['post_id']);
$marker_post = $postInfo->getPostInfo();
} else {
$marker_post = array();
}
Expand Down
36 changes: 36 additions & 0 deletions fish-map/includes/post_info.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<?php
class PostInfo
{
public function __construct($postId)
{
global $wpdb;
$this->db = $wpdb;
$this->postId = $postId;
}

public function getPostTaxonomy()
{
$sql = "SELECT name, slug, taxonomy, description
FROM wp_term_relationships tr
JOIN wp_term_taxonomy tt ON tt.term_taxonomy_id = tr.term_taxonomy_id
JOIN wp_terms t ON t.term_id = tt.term_id
WHERE object_id = %d";
$query_taxonomy = $this->db->prepare($sql, $this->postId);
return $this->db->get_results($query_taxonomy, ARRAY_A);
}

public function getPostInfo()
{
$marker_post = get_post($this->postId, ARRAY_A);
$marker_post['rendered_content'] = get_post_content_by_id($this->postId);
$marker_post['featured_image'] = wp_get_attachment_url( get_post_thumbnail_id($this->postId) );
$marker_post['taxonomy'] = $this->getPostTaxonomy();
return $marker_post;
}

public static function getPostIds()
{
global $wpdb;
return $wpdb->get_col("SELECT ID FROM wp_posts where post_type = 'post' and post_status = 'publish'");
}
}

0 comments on commit 68c3c1d

Please sign in to comment.