Пример #1
0
 /**
  * Creates and return eZPageZone object from given XML
  *
  * @static
  * @param DOMElement $node
  * @return eZPageZone
  */
 public static function createFromXML(DOMElement $node)
 {
     $newObj = new eZPageZone();
     if ($node->hasAttributes()) {
         foreach ($node->attributes as $attr) {
             if ($attr->name == 'id') {
                 $value = explode('_', $attr->value);
                 $newObj->setAttribute($attr->name, $value[1]);
             } else {
                 $newObj->setAttribute($attr->name, $attr->value);
             }
         }
     }
     foreach ($node->childNodes as $node) {
         if ($node->nodeType == XML_ELEMENT_NODE && $node->nodeName == 'block') {
             $blockNode = eZPageBlock::createFromXML($node);
             $newObj->addBlock($blockNode);
         } elseif ($node->nodeType == XML_ELEMENT_NODE) {
             $newObj->setAttribute($node->nodeName, $node->nodeValue);
         }
     }
     return $newObj;
 }
Пример #2
0
 /**
  * Creates object structure from given XML type string
  *
  * @static
  * @param string $source
  * @return eZPage
  */
 public static function createFromXML($source)
 {
     $newObj = new eZPage();
     if ($source) {
         $dom = new DOMDocument('1.0', 'utf-8');
         $success = $dom->loadXML($source);
         $root = $dom->documentElement;
         foreach ($root->childNodes as $node) {
             if ($node->nodeType == XML_ELEMENT_NODE && $node->nodeName == 'zone') {
                 $zoneNode = eZPageZone::createFromXML($node);
                 $newObj->addZone($zoneNode);
             } elseif ($node->nodeType == XML_ELEMENT_NODE) {
                 $newObj->setAttribute($node->nodeName, $node->nodeValue);
             }
         }
         if ($root->hasAttributes()) {
             foreach ($root->attributes as $attr) {
                 $newObj->setAttribute($attr->name, $attr->value);
             }
         }
     }
     return $newObj;
 }
Пример #3
0
 /**
  * Creates object structure from given XML type string
  *
  * @static
  * @param string $source
  * @return eZPage
  */
 public static function createFromXML($source)
 {
     $newObj = new eZPage();
     if ($source) {
         $dom = new DOMDocument('1.0', 'utf-8');
         $success = $dom->loadXML($source);
         $root = $dom->documentElement;
         foreach ($root->childNodes as $node) {
             if ($node->nodeType == XML_ELEMENT_NODE && $node->nodeName == 'zone') {
                 $zoneNode = eZPageZone::createFromXML($node);
                 $newObj->addZone($zoneNode);
             } elseif ($node->nodeType == XML_ELEMENT_NODE) {
                 $newObj->setAttribute($node->nodeName, $node->nodeValue);
             }
         }
         if ($root->hasAttributes()) {
             foreach ($root->attributes as $attr) {
                 $newObj->setAttribute($attr->name, $attr->value);
             }
         }
     }
     $zoneINI = eZINI::instance('zone.ini');
     $layoutName = $newObj->attribute('zone_layout');
     if ($zoneINI->hasVariable($layoutName, 'Zones')) {
         foreach ($zoneINI->variable($layoutName, 'Zones') as $zoneIdentifier) {
             foreach ($newObj->attribute('zones') as $inObjectZone) {
                 if ($inObjectZone->attribute('zone_identifier') === $zoneIdentifier) {
                     continue 2;
                 }
             }
             $newZone = $newObj->addZone(new eZPageZone());
             $newZone->setAttribute('id', md5(mt_rand() . microtime() . $newObj->getZoneCount()));
             $newZone->setAttribute('zone_identifier', $zoneIdentifier);
             $newZone->setAttribute('action', 'add');
         }
     }
     return $newObj;
 }