コード例 #1
0
ファイル: import.php プロジェクト: AlexanderDolgan/ojahuri
 /**
  * Imports a single blob content into matching post.
  *
  * @param stdClass $blob
  */
 protected function import_blob($blob)
 {
     // Break out meta, if present
     preg_match('/(^---(.*?)---$)?(.*)/ms', $blob->content, $matches);
     $body = array_pop($matches);
     if (3 === count($matches)) {
         $meta = cyps_load($matches[2]);
         if (isset($meta['permalink'])) {
             $meta['permalink'] = str_replace(home_url(), '', get_permalink($meta['permalink']));
         }
     } else {
         $meta = array();
     }
     if (function_exists('wpmarkdown_markdown_to_html')) {
         $body = wpmarkdown_markdown_to_html($body);
     }
     $args = array('post_content' => apply_filters('wpghs_content_import', $body));
     if (!empty($meta)) {
         if (array_key_exists('layout', $meta)) {
             $args['post_type'] = $meta['layout'];
             unset($meta['layout']);
         }
         if (array_key_exists('published', $meta)) {
             $args['post_status'] = true === $meta['published'] ? 'publish' : 'draft';
             unset($meta['published']);
         }
         if (array_key_exists('post_title', $meta)) {
             $args['post_title'] = $meta['post_title'];
             unset($meta['post_title']);
         }
         if (array_key_exists('ID', $meta)) {
             $args['ID'] = $meta['ID'];
             unset($meta['ID']);
         }
     }
     if (!isset($args['ID'])) {
         // @todo create a revision when we add revision author support
         $post_id = wp_insert_post($args);
     } else {
         $post_id = wp_update_post($args);
     }
     /** @var WordPress_GitHub_Sync_Post $post */
     $post = new WordPress_GitHub_Sync_Post($post_id);
     $post->set_sha($blob->sha);
     foreach ($meta as $key => $value) {
         update_post_meta($post_id, $key, $value);
     }
     WordPress_GitHub_Sync::write_log(__('Updated blob ', 'wordpress-github-sync') . $blob->sha);
 }
コード例 #2
0
ファイル: controller.php プロジェクト: sdh100shaun/pantheon
 /**
  * Use the new tree to save sha data
  * for all the updated posts
  */
 public function save_post_shas($tree)
 {
     foreach ($this->posts as $post_id) {
         $post = new WordPress_GitHub_Sync_Post($post_id);
         $match = false;
         foreach ($tree as $blob) {
             // this might be a problem if the filename changed since it was set
             // (i.e. post updated in middle mass export)
             // solution?
             if ($post->github_path() === $blob->path) {
                 $post->set_sha($blob->sha);
                 $match = true;
                 break;
             }
         }
         if (!$match) {
             WordPress_GitHub_Sync::write_log(__('No sha matched for post ID ', WordPress_GitHub_Sync::$text_domain) . $post_id);
         }
     }
 }
コード例 #3
0
ファイル: export.php プロジェクト: rexcode/rexappz-wordpress
 /**
  * Use the new tree to save sha data
  * for all the updated posts
  */
 public function save_post_shas()
 {
     foreach ($this->ids as $post_id) {
         $post = new WordPress_GitHub_Sync_Post($post_id);
         $blob = $this->tree->get_blob_for_path($post->github_path());
         if ($blob) {
             $post->set_sha($blob->sha);
         } else {
             WordPress_GitHub_Sync::write_log(sprintf(__('No sha matched for post ID %d', 'wordpress-github-sync'), $post_id));
         }
     }
 }