Exemplo n.º 1
0
 /**
  * Gather the data that will be deployed
  *
  * @param string $raw - doesn't optimize the deploy data for transit
  * @return array
  */
 public function get_deploy_data($raw = false, $preflight = false)
 {
     $this->_deploy_data = array('taxonomies' => array(), 'users' => array(), 'post_types' => array(), 'menus' => array(), 'bookmarks' => array());
     foreach ($this->data as $key => $group) {
         switch ($key) {
             case 'post_types':
                 foreach ($group as $post_type => $post_ids) {
                     if (!empty($post_ids)) {
                         // start all our post objects
                         foreach ($post_ids as $post_id) {
                             try {
                                 $posts[$post_id] = new cfd_post($post_id);
                             } catch (Exception $e) {
                                 // no real error handling yet
                                 error_log('cfd_post object error: ' . $e->getMessage() . ' - ' . __FILE__ . '::' . __LINE__);
                             }
                         }
                         // sort the post objects
                         $post_type_object = get_post_type_object($post_type);
                         if ($post_type_object->hierarchical) {
                             $posts = $this->sort_posts_by_parent($posts);
                         }
                         //  process the post objects
                         foreach ($posts as $post) {
                             // pull post and distribute parts across the deploy data
                             $this->parse_post_for_deploy($post, $raw);
                         }
                         // cleanup
                         unset($posts);
                     }
                 }
                 break;
             case 'users':
                 if (!empty($group)) {
                     $this->_deploy_data['users'] = array_merge($this->_deploy_data['users'], $this->get_users_by_ids($group));
                 }
                 break;
             case 'taxonomies':
                 if (!empty($group)) {
                     foreach ($group as $tax_type => $term_ids) {
                         if (!empty($term_ids)) {
                             foreach ($this->get_terms($tax_type, $term_ids) as $slug => $term) {
                                 $this->_deploy_data['taxonomies'][$tax_type][$slug] = $term;
                             }
                         }
                     }
                 }
                 break;
             case 'bookmarks':
                 if (!empty($group)) {
                     foreach ($group as $bookmark_id) {
                         $bookmark = $this->get_bookmark($bookmark_id);
                         if (!empty($bookmark->link_category)) {
                             $link_cats = $bookmark->link_category;
                             $bookmark->link_category = array();
                             foreach ($link_cats as $key => $term) {
                                 $bookmark->link_category[] = $term->slug;
                                 $this->_deploy_data['taxonomies']['link_category'][$term->slug] = $term;
                             }
                         }
                         $this->_deploy_data['bookmarks'][$bookmark->link_url] = $bookmark;
                     }
                 }
                 break;
             case 'menus':
                 if (!empty($group)) {
                     foreach ($group as $menu_id) {
                         try {
                             $menu = new cfd_menu($menu_id);
                             if ($raw) {
                                 $this->_deploy_data['menus'][$menu->guid()] = $menu;
                             } else {
                                 $this->_deploy_data['menus'][$menu->guid()] = $menu->get_data_for_transit();
                             }
                         } catch (Exception $e) {
                             // no real error handling yet
                             error_log('cfd_menu object error: ' . $e->getMessage . ' - ' . __FILE__ . '::' . __LINE__);
                         }
                     }
                 }
                 break;
         }
     }
     // we have to wait to reorder taxonomies since post_types & bookmarks can add to the list of terms
     foreach ($this->_deploy_data['taxonomies'] as $tax_type => &$terms) {
         $taxonomy = get_taxonomy($tax_type);
         if ($taxonomy->hierarchical) {
             $terms = $this->sort_terms_by_parent($terms);
         }
     }
     // raw returns objects, not-raw returns data ready for transit
     if (!$raw) {
         array_walk_recursive($this->_deploy_data, array($this, 'object_to_array'));
         #array_walk_recursive($this->_deploy_data, array($this, 'trim_scalar'));
     }
     if ($preflight) {
         foreach ($this->_deploy_data['post_types'] as $post_type => $objects) {
             if (!empty($objects)) {
                 foreach ($objects as $key => $post_obj) {
                     $this->_deploy_data['post_types'][$post_type][$key]['post']['post_content'] = md5($post_obj['post']['post_content']);
                     if (!empty($post_obj['post']['post_excerpt'])) {
                         $this->_deploy_data['post_types'][$post_type][$key]['post']['post_excerpt'] = md5($post_obj['post']['post_excerpt']);
                     }
                 }
             }
         }
     }
     // make absolutely sure that attachments are last in the post_types array
     if (!empty($this->_deploy_data['post_types']['attachment'])) {
         $a = $this->_deploy_data['post_types']['attachment'];
         unset($this->_deploy_data['post_types']['attachment']);
         $this->_deploy_data['post_types']['attachment'] = $a;
     }
     return $this->_deploy_data;
 }
Exemplo n.º 2
0
 protected function compare_menus($data)
 {
     $menus = array();
     if (count($data)) {
         foreach ($data as $menu) {
             try {
                 $m = new cfd_menu($menu['guid']);
                 $menus[$m->guid()] = array('guid' => $m->guid(), 'last_modified' => $m->last_modified());
             } catch (Exception $e) {
                 // doesn't exist, which is fine here
             }
         }
     }
     return $menus;
 }