Пример #1
0
 /**
  * Init when you only know the WP post
  *
  * @param $wp_post - a WP_Post instance
  * @return a new PmpSyncer
  */
 public static function fromPost(WP_Post $wp_post)
 {
     $sdk = new SDKWrapper();
     $guid = get_post_meta($wp_post->ID, 'pmp_guid', true);
     if ($guid) {
         $doc = $sdk->fetchDoc($guid);
         return new self($doc, $wp_post);
         // doc might be null
     } else {
         return new self(null, $wp_post);
     }
 }
Пример #2
0
/**
 * Make sure distributor-set collections are preserved when pushing to the PMP
 *
 * @since 0.0.1
 */
function pmp_dist_preserve_distributor_collection($doc, $previous_collection, $post)
{
    $current_guids = array_map(function ($item) {
        return SDKWrapper::guid4href($item->href);
    }, $doc->links->collection);
    $previous_guids = array_map(function ($item) {
        return SDKWrapper::guid4href($item->href);
    }, $previous_collection);
    $difference = array_diff($previous_guids, $current_guids);
    if (!empty($difference)) {
        $sdk = new SDKWrapper();
        foreach ($difference as $idx => $guid_to_check) {
            $collection = $sdk->fetchDoc($guid_to_check);
            foreach ($doc->links->distributor as $distributor) {
                if ($distributor->href == $collection->links->owner[0]->href) {
                    $doc->links->collection[] = $previous_collection[$idx];
                }
            }
        }
    }
    return $doc;
}
Пример #3
0
function _pmp_ajax_create_post($is_draft = false)
{
    $sdk = new SDKWrapper();
    // make sure we don't search for a blank string
    $guid = empty($_POST['pmp_guid']) ? 'nothing' : $_POST['pmp_guid'];
    $doc = $sdk->fetchDoc($guid);
    if (empty($doc)) {
        return array('success' => false, 'message' => "Cannot find PMP document {$guid}");
    } else {
        $syncer = PmpPost::fromDoc($doc);
        // pull from PMP
        if ($syncer->pull()) {
            return array('success' => true, 'data' => array('edit_url' => html_entity_decode(get_edit_post_link($syncer->post->ID)), 'post_id' => $syncer->post->ID));
        } else {
            return array('success' => false, 'message' => "Error: unable to pull PMP document {$guid}");
        }
    }
}