Example #1
0
 public static function import($xml_file, $import_frontpage = true, $frontpage_params = array(), $import_categories = true, $category_params = array(), $element_assignment = array(), $types = array())
 {
     if ($xml = YXML::loadFile($xml_file)) {
         // get application
         if ($application = Zoo::getApplication()) {
             // import frontpage
             if ($import_frontpage) {
                 self::_importFrontpage($application, $xml->getElementByPath('categories/category[@id="_root"]'), $frontpage_params);
             }
             // import categories
             if ($import_categories) {
                 $categories = self::_importCategories($application, $xml->getElementsByPath('categories/category[not(@id="_root")]'), $category_params);
             }
             // import items
             $items = self::_importItems($application, $xml->items, $element_assignment, $types);
             // save item -> category relationship
             if ($import_categories) {
                 foreach ($items as $item) {
                     $values = array();
                     foreach ($item->categories as $category_alias) {
                         if (isset($categories[$category_alias]) || $category_alias == '_root') {
                             $values[] = $category_alias == '_root' ? 0 : (int) $categories[$category_alias]->id;
                         }
                     }
                     if (!empty($values)) {
                         CategoryHelper::saveCategoryItemRelations($item->id, $values);
                     }
                 }
             }
             return true;
         }
         throw new ImportHelperException('No application to import too.');
     }
     throw new ImportHelperException('No valid xml file.');
 }
Example #2
0
 public function __construct($path)
 {
     if ($xml = YXML::loadFile($path)) {
         // add other character
         if ($xml->attributes()->other) {
             $this->_other = (string) $xml->attributes()->other;
         }
         // add characters
         foreach ($xml->children() as $option) {
             if (!in_array((string) $option, $this->_index)) {
                 $key = $option->attributes()->value ? (string) $option->attributes()->value : (string) $option;
                 $this->_index[$key] = (string) $option;
             }
         }
     }
 }
Example #3
0
 public function setData($xml)
 {
     $this->_data_array = array();
     if (!empty($xml)) {
         $xml = YXML::loadString($xml);
         foreach ($xml->children() as $xml_element) {
             if ((string) $xml_element->attributes()->identifier == $this->identifier) {
                 $data = ElementData::newInstance($this);
                 $data->decodeXML($xml_element);
                 $this->_data_array[] = $data;
             }
         }
     }
     if (empty($this->_data_array)) {
         $this->_data_array[0] = ElementData::newInstance($this);
     }
     $this->_data = $this->_data_array[0];
 }
Example #4
0
 public function render()
 {
     // create html
     $html = '<ul>';
     foreach ($this->_root->getChildren() as $child) {
         $html .= $child->render($this);
     }
     $html .= '</ul>';
     // decorator callbacks ?
     if (func_num_args()) {
         // parse html
         if ($xml = YXML::loadString($html)) {
             foreach (func_get_args() as $callback) {
                 if (is_callable($callback)) {
                     $xml->map($callback);
                 }
             }
             $html = $xml->asXML(true);
         }
     }
     return $html;
 }
Example #5
0
 public function getLayoutMetaData($layout)
 {
     // init vars
     $metadata = new YArray();
     $parts = explode($this->_separator, $layout);
     $name = array_pop($parts);
     if ($file = JPath::find($this->_getPath(implode(DIRECTORY_SEPARATOR, $parts)), $this->_metafile)) {
         if ($xml = YXML::loadFile($file)) {
             foreach ($xml->children() as $child) {
                 $attributes = $child->attributes();
                 if ($child->getName() == 'layout' && (string) $attributes->name == $name) {
                     foreach ($attributes as $key => $attribute) {
                         $metadata[$key] = (string) $attribute;
                     }
                     $metadata['layout'] = $layout;
                     $metadata['name'] = (string) $child->name;
                     $metadata['description'] = (string) $child->description;
                     break;
                 }
             }
         }
     }
     return $metadata;
 }
Example #6
0
 public function getPositions($dir)
 {
     // init vars
     $positions = array();
     $parts = explode('.', $dir);
     $layout = array_pop($parts);
     $path = implode('/', $parts);
     // parse positions xml
     if ($xml = YXML::loadFile(JPath::find($this->_getPath($path), $this->_xml_file))) {
         foreach ($xml->children() as $pos) {
             if ((string) $pos->attributes()->layout == $layout) {
                 $positions['name'] = $layout;
                 foreach ($pos->children() as $child) {
                     if ($child->getName() == 'name') {
                         $positions['name'] = (string) $child;
                     }
                     if ($child->getName() == 'position') {
                         if ($child->attributes()->name) {
                             $name = (string) $child->attributes()->name;
                             $positions['positions'][$name] = (string) $child;
                         }
                     }
                 }
                 break;
             }
         }
     }
     return $positions;
 }
Example #7
0
 public function getMetaXML()
 {
     if (empty($this->_metaxml)) {
         $this->_metaxml = YXML::loadFile($this->getPath() . '/' . $this->getElementType() . '.xml');
     }
     return $this->_metaxml;
 }
Example #8
0
                if ($description = $metadata->get('description')) {
                    $link = '<span class="editlinktip hasTip" title="' . $metadata->get('name', $layout) . '::' . $description . '">' . $link . '</span>';
                }
                $links[] = $link;
            }
            echo implode(' | ', $links);
            echo '</div>';
        }
        ?>
			</td>
			<td class="plugin">
				<?php 
        foreach ($this->plugins as $plugin_type => $plugins) {
            foreach ($plugins as $plugin) {
                $plugin_name = $plugin['name'];
                if (($xml = YXML::loadFile(dirname($plugin['path']) . DIRECTORY_SEPARATOR . $plugin['name'] . '.xml')) && $xml->getName() == 'install') {
                    $plugin_name = (string) $xml->getElementByPath('name');
                }
                echo '<div>' . $plugin_name . ': ';
                $renderer = new YRenderer();
                $renderer->addPath($plugin['path']);
                $links = array();
                foreach ($renderer->getLayouts('item') as $layout) {
                    // get layout metadata
                    $metadata = $renderer->getLayoutMetaData("item.{$layout}");
                    // create link
                    $link = '<a href="' . JRoute::_($this->baseurl . '&task=assignelements&type=' . $type->id . '&plugin=' . $plugin_type . '/' . $plugin['name'] . '&layout=' . $layout) . '">' . $metadata->get('name', $layout) . '</a>';
                    // create tooltip
                    if ($description = $metadata->get('description')) {
                        $link = '<span class="editlinktip hasTip" title="' . $metadata->get('name', $layout) . '::' . $description . '">' . $link . '</span>';
                    }
Example #9
0
 public function getMetaXML()
 {
     if (empty($this->_metaxml)) {
         $this->_metaxml = YXML::loadFile($this->getMetaXMLFile());
     }
     return $this->_metaxml;
 }
Example #10
0
 public function setData($data, $cdata = false)
 {
     if (!empty($data)) {
         $node = dom_import_simplexml($this);
         // remove children and text content
         while ($node->hasChildNodes()) {
             $node->removeChild($node->childNodes->item(0));
         }
         $doc = $node->ownerDocument;
         $data = YXML::stripInvalidXMLCharacters($data);
         if ($cdata) {
             $node->appendChild($doc->createCDATASection($data));
         } else {
             $node->appendChild($doc->createTextNode($data));
         }
     }
     return $this;
 }
Example #11
0
 public static function createElementsFromXML($xml_string, Type $type)
 {
     $i = 0;
     $results = array();
     $xml = YXML::loadString($xml_string);
     $params = $xml->xpath('params/param');
     if ($params) {
         foreach ($params as $param) {
             if ($element = self::_getElementFromXMLNode($param, $type)) {
                 $results[$element->identifier] = $element;
                 $results[$element->identifier]->setOrdering($i++);
             }
         }
     }
     return $results;
 }
Example #12
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;
 }
Example #13
0
 public static function findManifest($path)
 {
     $path = rtrim($path, "\\/") . '/';
     foreach (YFile::readDirectoryFiles($path, $path, '/\\.xml$/', false) as $file) {
         if (($xml = YXML::loadFile($file)) && self::isManifest($xml)) {
             return $xml;
         }
     }
     return false;
 }
Example #14
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;
 }