예제 #1
0
 public function __construct(XmlElement $node, $control_name = '', $options = null)
 {
     $this->control_name = $control_name;
     $attributes = $node->getAttributes();
     // unset cf-namespace attribute
     if (isset($attributes['cf-namespace'])) {
         unset($attributes['cf-namespace']);
     }
     if (array_key_exists("name", $attributes)) {
         $this->name = $attributes["name"];
     }
     if (isset($attributes["value"])) {
         $this->value = $attributes["value"];
     }
     if (!isset($attributes["id"])) {
         $attributes["id"] = $attributes["name"] . "_id";
     }
     unset($attributes["value"]);
     if (!is_null($options)) {
         $this->options = $options;
     }
     $this->attributes = $attributes;
     $this->label = new FormFieldLabel($this);
     if (!empty($this->unset_attributes)) {
         $this->unsetAttributes($this->unset_attributes);
     }
     $this->initialize();
 }
예제 #2
0
 private function parseTemplate(XmlElement $composition)
 {
     $templateName = $composition->getAttribute("template");
     $title = $composition->getAttribute("title");
     $description = $composition->getAttribute("description");
     $tplXml = $this->getTemplateLocation($templateName);
     if (!file_exists($tplXml)) {
         throw new TemplateNotExistsException($templateName);
     }
     $replaces = array();
     foreach ($composition->getChildren() as $define) {
         $key = "<insert name=\"{$define->getAttribute("name")}\"/>";
         $replaces[$key] = $define->asXmlChildren();
     }
     $tplNode = $this->xmlFactory->fromFile($tplXml)->getRootElement();
     $result = $tplNode->asXml();
     $result = StringUtil::replaceWith($result, "<template>", "<view>");
     $result = StringUtil::replaceWith($result, "</template>", "</view>");
     $inserts = $tplNode->getNbDescendants("insert");
     for ($i = 0; $i < $inserts; $i++) {
         $result = StringUtil::replaceAssoc($result, $replaces);
     }
     $root = $this->xmlFactory->fromString($result)->getRootElement();
     if (!is_null($title)) {
         $root->addAttribute("title", $title);
     }
     if (!is_null($description)) {
         $root->addAttribute("description", $description);
     }
     return $root;
 }
예제 #3
0
파일: RssWriter.php 프로젝트: hugcoday/wiki
 /**
  * Finish construction of RSS.
  */
 function finish()
 {
     if (isset($this->_finished)) {
         return;
     }
     $channel =& $this->_channel;
     $items =& $this->_items;
     $seq = new XmlElement('rdf:Seq');
     if ($items) {
         foreach ($items as $item) {
             $seq->pushContent($this->__ref('rdf:li', $item));
         }
     }
     $channel->pushContent(new XmlElement('items', false, $seq));
     if (isset($this->_image)) {
         $channel->pushContent($this->__ref('image', $this->_image));
         $items[] = $this->_image;
     }
     if (isset($this->_textinput)) {
         $channel->pushContent($this->__ref('textinput', $this->_textinput));
         $items[] = $this->_textinput;
     }
     $this->pushContent($channel);
     if ($items) {
         $this->pushContent($items);
     }
     $this->__spew();
     $this->_finished = true;
 }
예제 #4
0
 /**
  * @return string
  */
 protected function _getHierarchicalData()
 {
     $this->_xml = new XmlElement('<config/>');
     foreach ($this->_collection as $item) {
         /** @var $item \Mage_Core_Model_Config_Data */
         $path = $item->getPath() . '/' . $item->getScope();
         $nodePathValues = $this->_xml->setNode($path);
         $valueChild = $nodePathValues->addChild('value', $item->getValue());
         $valueChild->addAttribute('scope_id', $item->getScopeId());
     }
     return $this->_xml->asNiceXml();
 }
예제 #5
0
 private function getXmlElement(SimpleXMLElement $el)
 {
     $result = new XmlElement(String::create($el->getName()));
     $result->setText(String::create($el));
     foreach ($el->children() as $child) {
         $xmlChild = $this->getXmlElement($child);
         $xmlChild->setParent($result);
         $result->addChild($xmlChild);
     }
     foreach ($el->attributes() as $name => $val) {
         $result->addAttribute($name, (string) $val);
     }
     return $result;
 }
예제 #6
0
 /**
  * FormFieldLabel constructor.
  *
  * @param XmlElement $field
  *
  * @since 1.0.0
  */
 public function __construct($field)
 {
     $fieldAttributes = $field->getAttributes();
     $attributes = $this->getAttributes();
     $this->unsetAttributes(array('name'));
     if (isset($fieldAttributes["label"])) {
         $this->setValue($fieldAttributes["label"]);
     }
     $attributes["for"] = $fieldAttributes["id"];
     $attributes['id'] = str_replace("_id", "_lbl", $fieldAttributes['id']);
     if (empty($attributes['class'])) {
         $attributes["class"] = self::$label_class;
     } else {
         $attributes["class"] = $fieldAttributes['class'] . " " . self::$label_class;
     }
     $this->setAttributes($attributes);
 }
예제 #7
0
 /**
  * @param XmlElement $toAppend
  * @param boolean $root
  * @return void
  */
 public function appendChild($toAppend, $root = false)
 {
     if ($root) {
         $node = $this->addChild($toAppend->getName());
         foreach ($toAppend->attributes() as $key => $value) {
             $node->addAttribute($key, $value);
         }
         $node->appendChild($toAppend);
     } else {
         foreach ($toAppend as $name => $tree) {
             $child = $this->addChild($name, $this->_fixContent(strval($tree)));
             foreach ($tree->attributes() as $attrKey => $attrValue) {
                 $child->addAttribute($attrKey, $attrValue);
             }
             $child->appendChild($tree->children());
         }
     }
 }
예제 #8
0
 private function getXmlElement(DOMElement $el)
 {
     $result = new XmlElement(String::create($el->tagName));
     for ($i = 0; $i < $el->childNodes->length; $i++) {
         $child = $el->childNodes->item($i);
         if ($child instanceof DOMText) {
             $result->setText(String::create($child->textContent));
         } elseif ($child instanceof DOMElement) {
             $xmlChild = $this->getXmlElement($child);
             $xmlChild->setParent($result);
             $result->addChild($xmlChild);
         }
     }
     for ($i = 0; $i < $el->attributes->length; $i++) {
         $attr = $el->attributes->item($i);
         $result->addAttribute($attr->nodeName, $attr->nodeValue);
     }
     return $result;
 }
예제 #9
0
 /**
  * @param XmlElement $menu_node
  * @return \stdClass
  */
 private static function getMenuManifestNode(XmlElement $menu_node)
 {
     $Cyan = \Cyan::initialize();
     $App = $Cyan->getContainer('application');
     $User = $App->getContainer('user');
     $acl_menu_permission = $menu_node->getAttribute('acl_check');
     if ($acl_menu_permission) {
         $acl_check = explode(',', $acl_menu_permission);
         $continue = false;
         foreach ($acl_check as $acl_permission) {
             if (!$continue && $User->can($acl_permission)) {
                 $continue = true;
                 break;
             }
         }
         if (!$continue) {
             return [];
         }
     }
     $route_name = $menu_node->getAttribute('route_name');
     $route_params = json_decode($menu_node->getAttribute('route_params', '{}'), true);
     if (!is_array($route_params)) {
         $route_params = [];
     }
     $menu = new \stdClass();
     $menu->icon = $menu_node->getAttribute('icon', 'fa fa-circle-o');
     $menu->title = $menu_node->getAttribute('title');
     $menu->link = !empty($route_name) ? $App->Router->generate($route_name, $route_params) : '#';
     if (isset($menu_node->submenu) && $menu_node->submenu->menu->count()) {
         $menu->items = [];
         foreach ($menu_node->submenu->menu as $submenu_node) {
             $submenu_items = self::getMenuManifestNode($submenu_node);
             if (!empty($submenu_items)) {
                 $menu->items[] = $submenu_items;
             }
         }
     }
     return $menu;
 }
예제 #10
0
 private static function internalFindComponentTag(XmlElement $markup, $componentTagId, Component $component)
 {
     if ($markup instanceof ComponentTag && $markup->getComponentTagId() == $componentTagId) {
         return $markup;
     } else {
         if ($markup instanceof MarkupElement && $markup->hasChildren() && (!$markup instanceof ComponentTag || $component->getId() == $markup->getComponentTagId())) {
             $componentTag = null;
             foreach ($markup->getChildren() as $element) {
                 if ($element instanceof MarkupElement) {
                     $componentTag = self::internalFindComponentTag($element, $componentTagId, $component);
                     if ($componentTag != null) {
                         return $componentTag;
                     }
                 }
             }
         }
         return null;
     }
 }
예제 #11
0
 /**
  * Append other XMLElement, support namespaces.
  *
  * @param XmlElement $append
  */
 public function append($append)
 {
     //if ( $append ) not working for 'defs'
     if (isset($append)) {
         //list all namespaces used in append object
         $namespaces = $append->getNameSpaces();
         //get all childs
         if (strlen(trim((string) $append)) == 0) {
             $xml = $this->addChild($append->getName());
             foreach ($append->children() as $child) {
                 $xml->append($child);
             }
         } else {
             //add one child
             $xml = $this->addChild($append->getName(), (string) $append);
         }
         //add simple attributes
         foreach ($append->attributes() as $attribute => $value) {
             $xml->addAttribute($attribute, $value);
         }
         //add attributes with namespace example xlink:href
         foreach ($namespaces as $index => $namespace) {
             foreach ($append->attributes($namespace) as $attribute => $value) {
                 $xml->addAttribute($index . ':' . $attribute, $value, $namespace);
             }
         }
     }
 }
예제 #12
0
파일: xml.php 프로젝트: evrard/cakephp2x
 /**
  * Creates an XmlElement object that can be appended to this document or a node in it
  *
  * @param string $name Element name
  * @param string $value Element value
  * @param array $attributes Element attributes
  * @param string $namespace Node namespace
  * @return object XmlElement
  */
 public function createElement($name = null, $value = null, $attributes = array(), $namespace = false)
 {
     $element = new XmlElement($name, $value, $attributes, $namespace);
     $element->setParent($this);
     return $element;
 }
예제 #13
0
파일: Xml.php 프로젝트: hofmeister/Pimple
 public static function toXml($data, $parent = 'root')
 {
     if (!$parent instanceof XmlNode) {
         $parent = new XmlElement((string) $parent);
     }
     switch (true) {
         case is_array($data):
         case is_object($data):
             $parent->setAttribute('type', 'structure');
             foreach ($data as $key => $value) {
                 if (is_int($key)) {
                     $key = 'element';
                 }
                 $node = new XmlElement($key);
                 $parent->addChild($node);
                 Xml::toXml($value, $node);
             }
             break;
         case is_bool($data):
             $parent->setAttribute('type', 'boolean');
             $parent->addChild(new XmlText($data ? 'true' : 'false'));
             break;
         case is_int($data):
             $parent->setAttribute('type', 'integer');
             $parent->addChild(new XmlText($data));
             break;
         case is_string($data):
             $parent->setAttribute('type', 'string');
             $parent->addChild(new XmlText($data));
             break;
         case is_float($data):
             $parent->setAttribute('type', 'float');
             $parent->addChild(new XmlText($data));
             break;
         case is_double($data):
             $parent->setAttribute('type', 'double');
             $parent->addChild(new XmlText($data));
             break;
         case is_null($data):
             //break;
         //break;
         default:
             $parent->addChild(new XmlText($data));
             break;
     }
     return $parent;
 }
예제 #14
0
 function printXML()
 {
     // Not all PHP's have vsprintf, so...
     $args[] = XmlElement::_quote((string) $this->_fs);
     foreach ($this->_args as $arg) {
         $args[] = AsXML($arg);
     }
     call_user_func_array('printf', $args);
 }
예제 #15
0
 /**
  * testAddAndRemoveAttributes
  *
  * @access public
  * @return void
  */
 function testAddAndRemoveAttributes()
 {
     $node = new XmlElement('myElement', 'superValue');
     $this->assertTrue(empty($node->attributes));
     $attrs = array('id' => 'test', 'show' => 1, 'is_spotlight' => 1);
     $node->addAttribute($attrs);
     $this->assertEqual($node->attributes, $attrs);
     $node = new XmlElement('myElement', 'superValue');
     $node->addAttribute('test', 'value');
     $this->assertTrue(isset($node->attributes['test']));
     $node = new XmlElement('myElement', 'superValue');
     $obj = new StdClass();
     $obj->class = 'info';
     $obj->id = 'primaryInfoBox';
     $node->addAttribute($obj);
     $expected = array('class' => 'info', 'id' => 'primaryInfoBox');
     $this->assertEqual($node->attributes, $expected);
     $result = $node->removeAttribute('class');
     $this->assertTrue($result);
     $this->assertFalse(isset($node->attributes['class']));
     $result = $node->removeAttribute('missing');
     $this->assertFalse($result);
 }