Example #1
0
 /**
  * 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);
 }
 /**
  * Returns the formatted/filtered blob content used for import.
  *
  * @return string
  */
 public function content_import()
 {
     $content = $this->content();
     if ($this->has_frontmatter()) {
         // Break out content.
         preg_match('/(^---(.*?)---$)?(.*)/ms', $content, $matches);
         $content = array_pop($matches);
     }
     if (function_exists('wpmarkdown_markdown_to_html')) {
         $content = wpmarkdown_markdown_to_html($content);
     }
     /**
      * Filters the content for import.
      */
     return apply_filters('wpghs_content_import', trim($content));
 }
 public function bbp_topic_pre_content($content)
 {
     if ($this->is_Markdownable('topic')) {
         $content = stripslashes($content);
         $content = wpmarkdown_markdown_to_html($content);
         $content = addslashes($content);
     }
     return $content;
 }
Example #4
0
 /**
  * Imports a single blob content into matching post
  */
 public function import_blob($blob)
 {
     global $wpdb;
     // Skip the repo's readme
     if ('readme' === strtolower(substr($blob->path, 0, 6))) {
         WordPress_GitHub_Sync::write_log(__('Skipping README', WordPress_GitHub_Sync::$text_domain));
         return;
     }
     // If the blob sha already matches a post, then move on
     $id = $wpdb->get_var("SELECT post_id FROM {$wpdb->postmeta} WHERE meta_key = '_sha' AND meta_value = '{$blob->sha}'");
     if ($id) {
         WordPress_GitHub_Sync::write_log(__('Already synced blob ', WordPress_GitHub_Sync::$text_domain) . $blob->path);
         return;
     }
     $blob = $this->api->get_blob($blob->sha);
     if (is_wp_error($blob)) {
         WordPress_GitHub_Sync::write_log(__('Failed getting blob with error: ', WordPress_GitHub_Sync::$text_domain) . $blob->get_error_message());
         return;
     }
     $content = base64_decode($blob->content);
     // If it doesn't have YAML frontmatter, then move on
     if ('---' !== substr($content, 0, 3)) {
         WordPress_GitHub_Sync::write_log(__('No front matter on blob ', WordPress_GitHub_Sync::$text_domain) . $blob->sha);
         return;
     }
     // Break out meta, if present
     preg_match('/(^---(.*?)---$)?(.*)/ms', $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' => $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);
     }
     $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::$text_domain) . $blob->sha);
 }