Exemple #1
0
 static function delete($post_ID)
 {
     // global $grape_synced;
     if (!GrapePostController::check_nonce()) {
         return $post_ID;
     }
     $post = new GrapePost($post_ID);
     if (!$post->was_synced()) {
         grape_debug("controller: delete -> STOP (was never synced before)");
         return $post_ID;
     }
     do_action('grape_post_delete', $post);
     foreach ($post->get_connections() as $connection) {
         $post->use_custom_title_field($connection['custom_title_field']);
         $api = new GRAPE_API($connection['api_token'], $connection['api_url']);
         $api->delete($post);
     }
     return $post_ID;
 }
Exemple #2
0
 private function find_a_post_image_url()
 {
     $image_url = false;
     // Check for post image
     if (current_theme_supports('post-thumbnails') && null != get_post_thumbnail_id($this->wp_id)) {
         $image_url = wp_get_attachment_url(get_post_thumbnail_id($this->wp_id));
         grape_debug('post image found');
     }
     // if we have no post image check for images inside content
     if (!$image_url) {
         // strip html except img
         $stripped_content = trim(str_replace('&nbsp;', '', strip_tags($this->wp_post->post_content, '<img>')));
         // find image urls
         $output = preg_match_all('/<img.+src=[\'"]([^\'"]+)[\'"].*>/i', $stripped_content, $matches, PREG_SET_ORDER);
         // do we have at least one image in post?
         if (count($matches) > 0 && 2 == count($matches[0])) {
             // first image
             $found_image_url = $matches[0][1];
             $found_image_tag = $matches[0][0];
             grape_debug("image tag found in post: {$found_image_url}");
             // wordpress resizes images and gives them names like image-150x150.jpg
             $image_url = preg_replace('/\\-[0-9]+x[0-9]+/', '', $found_image_url);
             grape_debug("original image: {$image_url}");
             if ($image_url) {
                 // does the post start with the image? then remove image
                 if (0 == strpos($stripped_content, $found_image_tag)) {
                     grape_debug('post starts with image, removing image from content');
                     $this->content = str_replace($found_image_tag, '', $this->content);
                 }
             } else {
                 grape_debug('image not found mediathek, ignoring');
             }
         }
     }
     if (!$image_url) {
         grape_debug('no usable image found in post');
     }
     return $image_url;
 }
function grape_full_sync()
{
    global $wpdb;
    // TODO: implement syncing of taxonomies
    // we need an array of post types that looks like array("post", "page")
    $options = grape_get_options();
    $post_types = array_unique(array_keys($options['syncables']['post_type']));
    // get all the posts from the DB. query takes multiple post types
    $args = array('post_type' => $post_types, 'posts_per_page' => -1);
    $posts = get_posts($args);
    // TODO: if someone adds two post types twice, we have a problem
    $post_count = count($posts);
    // $post_id is not the real post id! it's just the index in the list
    $post_id = 0;
    if (isset($_POST['postId'])) {
        $post_id = intval($_POST['postId']);
    }
    $next_post_id = $post_id + 1;
    $current_post = $posts[$post_id];
    grape_debug('Full Sync: post id ' . $current_post->ID);
    GrapePostController::post($current_post->ID, true);
    $response = array('postsTotal' => $post_count, 'currentPostId' => $post_id, 'currentPostTitle' => $current_post->title);
    if ($next_post_id < $post_count) {
        $response['nextPostId'] = $next_post_id;
    }
    echo json_encode($response);
    wp_die();
    // this is required to terminate immediately and return a proper response
}
Exemple #4
0
 private function log($function_name, $message = "start")
 {
     grape_debug("Grape API ({$function_name}): {$message}");
 }