Exemple #1
0
 /**
  * encode an item to XML
  *
  * @param array attributes of the item to encode
  * @param object overlay instance of this item, if any
  * @return string the XML encoding of this item
  */
 public static function to_xml($item, $overlay)
 {
     global $context;
     // section header
     $text = '<section>' . "\n";
     // get unique handle of the anchor of this item
     if (isset($item['anchor']) && !strncmp($item['anchor'], 'section:', 8) && ($handle = Sections::get_handle(substr($item['anchor'], 8)))) {
         $text .= "\t" . '<anchor_type>section</anchor_type>' . "\n" . "\t" . '<anchor_handle>' . $handle . '</anchor_handle>' . "\n";
     }
     // fields to be exported
     $labels = array('id', 'activation_date', 'active', 'active_set', 'articles_canvas', 'articles_layout', 'articles_template', 'behaviors', 'content_options', 'content_overlay', 'create_address', 'create_date', 'create_id', 'create_name', 'description', 'edit_action', 'edit_address', 'edit_date', 'edit_id', 'edit_name', 'expiry_date', 'extra', 'family', 'handle', 'hits', 'home_panel', 'icon_url', 'index_map', 'index_news', 'index_news_count', 'index_title', 'introduction', 'language', 'locked', 'maximum_items', 'meta', 'nick_name', 'options', 'owner_id', 'prefix', 'rank', 'section_overlay', 'sections_layout', 'suffix', 'tags', 'template', 'thumbnail_url', 'title', 'trailer');
     // process all fields
     foreach ($labels as $label) {
         // export this field
         if (isset($item[$label]) && $item[$label]) {
             $text .= "\t" . '<' . $label . '>' . encode_field($item[$label]) . '</' . $label . '>' . "\n";
         }
     }
     // handle of item owner
     if (isset($item['owner_id']) && ($user = Users::get($item['owner_id']))) {
         $text .= "\t" . '<owner_nick_name>' . $user['nick_name'] . '</owner_nick_name>' . "\n";
     }
     // handle of item creator
     if (isset($item['create_id']) && ($user = Users::get($item['create_id']))) {
         $text .= "\t" . '<create_nick_name>' . $user['nick_name'] . '</create_nick_name>' . "\n";
     }
     // handle of last editor
     if (isset($item['edit_id']) && ($user = Users::get($item['edit_id']))) {
         $text .= "\t" . '<edit_nick_name>' . $user['nick_name'] . '</edit_nick_name>' . "\n";
     }
     // the overlay, if any
     if (is_object($overlay)) {
         $text .= $overlay->export();
     }
     // section footer
     $text .= '</section>' . "\n";
     // list articles in this section
     $text .= Articles::list_for_anchor('section:' . $item['id'], 0, 500, 'xml');
     // list sub-sections
     $text .= Sections::list_for_anchor('section:' . $item['id'], 'xml');
     // job done
     return $text;
 }
Exemple #2
0
 /**
  * encode an item to XML
  *
  * @param array attributes of the item to encode
  * @param object overlay instance of this item, if any
  * @return string the XML encoding of this item
  */
 public static function to_xml($item, $overlay)
 {
     global $context;
     // article header
     $text = '<article>' . "\n";
     // get unique handle of the anchor of this item
     if (isset($item['anchor']) && !strncmp($item['anchor'], 'section:', 8) && ($handle = Sections::get_handle(substr($item['anchor'], 8)))) {
         $text .= "\t" . '<anchor_type>section</anchor_type>' . "\n" . "\t" . '<anchor_handle>' . $handle . '</anchor_handle>' . "\n";
     }
     // fields to be exported
     $labels = array('id', 'active', 'active_set', 'behaviors', 'canvas', 'create_address', 'create_date', 'create_id', 'create_name', 'description', 'edit_action', 'edit_address', 'edit_date', 'edit_id', 'edit_name', 'expiry_date', 'extra', 'handle', 'hits', 'icon_url', 'introduction', 'language', 'locked', 'meta', 'nick_name', 'options', 'owner_id', 'prefix', 'publish_address', 'publish_date', 'publish_id', 'publish_name', 'rank', 'rating_count', 'rating_sum', 'review_date', 'source', 'suffix', 'tags', 'thumbnail_url', 'title', 'trailer');
     // process all fields
     foreach ($labels as $label) {
         // export this field
         if (isset($item[$label]) && $item[$label]) {
             $text .= "\t" . '<' . $label . '>' . encode_field($item[$label]) . '</' . $label . '>' . "\n";
         }
     }
     // handle of item owner
     if (isset($item['owner_id']) && ($user = Users::get($item['owner_id']))) {
         $text .= "\t" . '<owner_nick_name>' . $user['nick_name'] . '</owner_nick_name>' . "\n";
     }
     // handle of item creator
     if (isset($item['create_id']) && ($user = Users::get($item['create_id']))) {
         $text .= "\t" . '<create_nick_name>' . $user['nick_name'] . '</create_nick_name>' . "\n";
     }
     // handle of last editor
     if (isset($item['edit_id']) && ($user = Users::get($item['edit_id']))) {
         $text .= "\t" . '<edit_nick_name>' . $user['nick_name'] . '</edit_nick_name>' . "\n";
     }
     // handle of publisher
     if (isset($item['publish_id']) && ($user = Users::get($item['publish_id']))) {
         $text .= "\t" . '<publish_nick_name>' . $user['nick_name'] . '</publish_nick_name>' . "\n";
     }
     // the overlay, if any
     if (is_object($overlay)) {
         $text .= $overlay->export();
     }
     // article footer
     $text .= '</article>' . "\n";
     // job done
     return $text;
 }