Exemple #1
0
 public function encodeData()
 {
     $xml = YXMLElement::create($this->_element->getElementType())->addAttribute('identifier', $this->_element->identifier);
     $value = $this->_params->get('value', '');
     if (!empty($value)) {
         $tzoffset = JFactory::getConfig()->getValue('config.offset');
         $date = JFactory::getDate($value, $tzoffset);
         $value = $date->toMySQL();
     }
     $xml->addChild('value', $value, null, true);
     return $xml;
 }
Exemple #2
0
 public function encodeData()
 {
     $xml = YXMLElement::create($this->_element->getElementType());
     $xml->addAttribute('identifier', $this->_element->identifier);
     foreach ($this->_params->get('country', array()) as $country) {
         $xml->addChild('country', $country, null, true);
     }
     return $xml;
 }
Exemple #3
0
 protected function _buildElement($name, $alias, $element_name, array $values = array())
 {
     $elem_xml = YXMLElement::create($name)->addAttribute('identifier', $alias)->addAttribute('name', $element_name);
     foreach ($values as $key => $value) {
         if (is_array($value)) {
             foreach ($value as $single_value) {
                 $elem_xml->addChild($key, $single_value, null, true);
             }
         } else {
             $elem_xml->addChild($key, $value, null, true);
         }
     }
     return $elem_xml;
 }
Exemple #4
0
 public function decodeXML(YXMLElement $element_xml)
 {
     foreach ($element_xml->children() as $child) {
         $this->set($child->getName(), (string) $child);
     }
     return $this;
 }
Exemple #5
0
 public static function getImportInfo(YXMLElement $export_xml)
 {
     $info = array();
     $application = Zoo::getApplication();
     // get frontpage count
     $info['frontpage_count'] = count($export_xml->getElementsByPath('categories/category[@id="_root"]'));
     // get category count
     $info['category_count'] = count($export_xml->getElementsByPath('categories/category[not(@id="_root")]'));
     // get frontpage params
     $info['frontpage_params'] = array();
     foreach ($application->getMetaXML()->getElementsByPath('params[@group="application-content"]/param') as $param) {
         $info['frontpage_params'][(string) $param->attributes()->type][(string) $param->attributes()->name] = (string) $param->attributes()->label;
     }
     $info['frontpage_params_to_assign'] = array();
     foreach ($export_xml->getElementsByPath('categories/category[@id="_root"]/content') as $content) {
         foreach ($content->children() as $param) {
             $name = (string) $param->attributes()->name;
             if (!isset($info['frontpage_params_to_assign'][$param->getName()]) || !in_array($name, $info['frontpage_params_to_assign'][$param->getName()])) {
                 $param_name = $param->getName() == 'image' ? 'zooimage' : $param->getName();
                 $info['frontpage_params_to_assign'][$param_name][] = $name;
             }
         }
     }
     // get category params
     $info['category_params'] = array();
     foreach ($application->getMetaXML()->getElementsByPath('params[@group="category-content"]/param') as $param) {
         $info['category_params'][(string) $param->attributes()->type][(string) $param->attributes()->name] = (string) $param->attributes()->label;
     }
     $info['category_params_to_assign'] = array();
     foreach ($export_xml->getElementsByPath('categories/category[not(@id="_root")]/content') as $content) {
         foreach ($content->children() as $param) {
             $name = (string) $param->attributes()->name;
             $param_name = $param->getName() == 'image' ? 'zooimage' : $param->getName();
             if (!isset($info['category_params_to_assign'][$param_name]) || !in_array($name, $info['category_params_to_assign'][$param_name])) {
                 $info['category_params_to_assign'][$param_name][] = $name;
             }
         }
     }
     // get types
     foreach ($application->getTypes() as $type) {
         foreach ($type->getElements() as $element) {
             $type_elements[$type->id][$element->getElementType()][] = $element;
         }
     }
     // get item types
     $info['items'] = array();
     foreach ($export_xml->items as $group => $items) {
         $group = $items->attributes()->name ? (string) $items->attributes()->name : $group;
         if (($count = count($items->item)) && ($data = $items->item[0]->data)) {
             $info['items'][$group]['elements'] = array();
             foreach ($data->children() as $element_xml) {
                 $alias = (string) $element_xml->attributes()->identifier;
                 if (!isset($info['items'][$group]['elements'][$alias])) {
                     $element_type = $element_xml->getName();
                     $element_name = (string) $element_xml->attributes()->name;
                     // add element type
                     $info['items'][$group]['elements'][$alias]['type'] = ucfirst($element_type);
                     // add element name
                     $info['items'][$group]['elements'][$alias]['name'] = $element_name;
                     // add elements to assign too
                     $info['items'][$group]['elements'][$alias]['assign'] = array();
                     foreach ($type_elements as $type => $assign_elements) {
                         if (isset($assign_elements[$element_type])) {
                             $info['items'][$group]['elements'][$alias]['assign'][$type] = $assign_elements[$element_type];
                         }
                     }
                 }
             }
             $info['items'][$group]['item_count'] = $count;
         }
     }
     return $info;
 }
Exemple #6
0
 public static function toXML($elements)
 {
     $type = YXMLElement::create('type')->addAttribute('version', '1.0.0');
     $params = YXMLElement::create('params');
     foreach ($elements as $element) {
         $params->appendChild($element->getConfigXML());
     }
     return $type->appendChild($params)->asXML(true, true);
 }
Exemple #7
0
 public function save()
 {
     $old_identifier = $this->id;
     $rename = false;
     if (empty($this->id)) {
         // check identifier
         if (file_exists($this->getXMLFile($this->identifier))) {
             throw new TypeException('Identifier already exists');
         }
         // set xml
         $this->setXML(YXMLElement::create('type')->addAttribute('version', '1.0.0')->asXML(true, true));
     } else {
         if ($old_identifier != $this->identifier) {
             // check identifier
             if (file_exists($this->getXMLFile($this->identifier))) {
                 throw new TypeException('Identifier already exists');
             }
             // rename xml file
             if (!JFile::move($this->getXMLFile(), $this->getXMLFile($this->identifier))) {
                 throw new TypeException('Renaming xml file failed');
             }
             $rename = true;
         }
     }
     // update id
     $this->id = $this->identifier;
     // set data
     $this->setXML(YXML::loadString($this->getXML())->addAttribute('name', $this->name)->asXML(true, true));
     // save xml file
     if ($file = $this->getXMLFile()) {
         if (!JFile::write($file, $this->getXML())) {
             throw new TypeException('Writing type xml file failed');
         }
     }
     // rename related items
     if ($rename) {
         $table = YTable::getInstance('item');
         // get database
         $db = $table->getDBO();
         // update childrens parent category
         $query = "UPDATE " . $table->getTableName() . " SET type=" . $db->quote($this->identifier) . " WHERE type=" . $db->quote($old_identifier);
         $db->query($query);
     }
     return $this;
 }
Exemple #8
0
 public function encodeData()
 {
     $xml = YXMLElement::create($this->_element->getElementType())->addAttribute('identifier', $this->_element->identifier);
     foreach ($this->_params->get('category', array()) as $category) {
         $xml->addChild('category')->setData($category);
     }
     return $xml;
 }
Exemple #9
0
 public static function isManifest(YXMLElement $xml)
 {
     return $xml->getName() == 'application';
 }
Exemple #10
0
 public static function index(YXMLElement $node, $args)
 {
     if ($node->getName() == 'ul') {
         // set ul level
         $level = $args['level'] / 2 + 1;
         $node->addAttribute('class', trim($node->attributes()->class . ' level' . $level));
         // set order/first/last for li
         $count = count($node->children());
         foreach ($node->children() as $i => $child) {
             $child->addAttribute('level', $level);
             $child->addAttribute('order', $i + 1);
             if ($i == 0) {
                 $child->addAttribute('first', 1);
             }
             if ($i == $count - 1) {
                 $child->addAttribute('last', 1);
             }
         }
     }
     if ($node->getName() == 'li') {
         // level and item order
         $css = 'level' . $node->attributes()->level;
         $css .= ' item' . $node->attributes()->order;
         // first, last and parent
         if ($node->attributes()->first) {
             $css .= ' first';
         }
         if ($node->attributes()->last) {
             $css .= ' last';
         }
         if (isset($node->ul)) {
             $css .= ' parent';
         }
         // add li css classes
         $node->addAttribute('class', trim($node->attributes()->class . ' ' . $css));
         // add a/span css classes
         if ($firstChild = $node->firstChild()) {
             $firstChild->addAttribute('class', trim($firstChild->attributes()->class . ' ' . $css));
         }
     }
     $node->removeAttribute('level')->removeAttribute('order')->removeAttribute('first')->removeAttribute('last');
 }
Exemple #11
0
 protected function _itemToXML(Item $item)
 {
     $attributes = array();
     foreach (self::$item_attributes as $attribute) {
         if (isset($item->{$attribute})) {
             $attributes[$attribute] = $item->{$attribute};
         }
     }
     $attributes['author'] = JFactory::getUser($item->created_by)->username;
     $item_xml = $this->_buildItem($item->alias, $item->name, $attributes);
     foreach ($item->getRelatedCategoryIds() as $category_id) {
         $alias = '';
         if (empty($category_id)) {
             $alias = '_root';
         } else {
             if (isset($this->categories[$category_id])) {
                 $alias = $this->categories[$category_id]->alias;
             }
         }
         if (!empty($alias)) {
             $this->_addItemCategory($item_xml, $alias);
         }
     }
     foreach ($item->getTags() as $tag) {
         $this->_addItemTag($item_xml, $tag);
     }
     foreach ($item->getElements() as $element) {
         $xml = YXML::loadString('<wrapper>' . $element->toXML() . '</wrapper>');
         foreach ($xml->children() as $element_xml) {
             $element_xml->addAttribute('name', $element->getConfig()->get('name'));
             $this->_addItemData($item_xml, $element_xml);
         }
     }
     $metadata = array();
     foreach ($item->getParams()->get('metadata.', array()) as $key => $value) {
         $metadata[preg_replace('/^metadata\\./', '', $key)] = $value;
     }
     if (!empty($metadata)) {
         $this->_addItemMetadata($item_xml, $metadata);
     }
     // sanitize relateditems elements
     $related_item_xmls = $item_xml->xpath('data/relateditems/item');
     if ($related_item_xmls) {
         foreach ($related_item_xmls as $related_item_xml) {
             $item_xml->replaceChild(YXMLElement::create('item', ItemHelper::translateIDToAlias((string) $related_item_xml), true), $related_item_xml);
         }
     }
     return $item_xml;
 }