コード例 #1
0
ファイル: Config.php プロジェクト: nasaa0528/core
 /**
  * update config revision information (ROOT.revision tag)
  * @param array|null $revision revision tag (associative array)
  * @param \SimpleXMLElement|null pass trough xml node
  */
 private function updateRevision($revision, $node = null)
 {
     // input must be an array
     if (is_array($revision)) {
         if ($node == null) {
             if (isset($this->simplexml->revision)) {
                 $node = $this->simplexml->revision;
             } else {
                 $node = $this->simplexml->addChild("revision");
             }
         }
         foreach ($revision as $revKey => $revItem) {
             if (isset($node->{$revKey})) {
                 // key already in revision object
                 $childNode = $node->{$revKey};
             } else {
                 $childNode = $node->addChild($revKey);
             }
             if (is_array($revItem)) {
                 $this->updateRevision($revItem, $childNode);
             } else {
                 $childNode[0] = $revItem;
             }
         }
     }
 }
コード例 #2
0
ファイル: Config.php プロジェクト: reelsense/core
 /**
  * update config revision information (ROOT.revision tag)
  * @param array|null $revision revision tag (associative array)
  * @param \SimpleXMLElement|null pass trough xml node
  */
 private function updateRevision($revision, $node = null)
 {
     // if revision info is not provided, create a default.
     if (!is_array($revision)) {
         $revision = array();
         // try to fetch userinfo from session
         if (!empty($_SESSION["Username"])) {
             $revision['username'] = $_SESSION["Username"];
         } else {
             $revision['username'] = "******";
         }
         if (!empty($_SERVER['REMOTE_ADDR'])) {
             $revision['username'] .= "@" . $_SERVER['REMOTE_ADDR'];
         }
         if (!empty($_SERVER['REQUEST_URI'])) {
             // when update revision is called from a controller, log the endpoint uri
             $revision['description'] = sprintf(gettext('%s made changes'), $_SERVER['REQUEST_URI']);
         } else {
             // called from a script, log script name and path
             $revision['description'] = sprintf(gettext('%s made changes'), $_SERVER['SCRIPT_NAME']);
         }
     }
     // always set timestamp
     $revision['time'] = microtime(true);
     if ($node == null) {
         if (isset($this->simplexml->revision)) {
             $node = $this->simplexml->revision;
         } else {
             $node = $this->simplexml->addChild("revision");
         }
     }
     foreach ($revision as $revKey => $revItem) {
         if (isset($node->{$revKey})) {
             // key already in revision object
             $childNode = $node->{$revKey};
         } else {
             $childNode = $node->addChild($revKey);
         }
         if (is_array($revItem)) {
             $this->updateRevision($revItem, $childNode);
         } else {
             $childNode[0] = $revItem;
         }
     }
 }
コード例 #3
0
ファイル: utility.php プロジェクト: TrinityCore/aowow
 protected function generateRSS()
 {
     $this->generateContent();
     $root = new SimpleXML('<rss />');
     $root->addAttribute('version', '2.0');
     $channel = $root->addChild('channel');
     $channel->addChild('title', CFG_NAME_SHORT . ' - ' . $this->name);
     $channel->addChild('link', HOST_URL . '/?' . $this->page . ($this->category ? '=' . $this->category[0] : null));
     $channel->addChild('description', CFG_NAME);
     $channel->addChild('language', implode('-', str_split(User::$localeString, 2)));
     $channel->addChild('ttl', CFG_TTL_RSS);
     $channel->addChild('lastBuildDate', date(DATE_RSS));
     foreach ($this->feedData as $row) {
         $item = $channel->addChild('item');
         foreach ($row as $key => list($isCData, $attrib, $text)) {
             if ($isCData && $text) {
                 $child = $item->addChild($key)->addCData($text);
             } else {
                 $child = $item->addChild($key, $text);
             }
             foreach ($attrib as $k => $v) {
                 $child->addAttribute($k, $v);
             }
         }
     }
     return $root->asXML();
 }
コード例 #4
0
 /**
  * SimpleXML helper, append 2 objects together
  * @param SimpleXML $to
  * @param SimpleXML $from
  */
 protected function _append(&$to, $from)
 {
     // go through each kid
     foreach ($from->children() as $child) {
         $temp = $to->addChild($child->getName(), (string) $child);
         foreach ($child->attributes() as $key => $value) {
             $temp->addAttribute($key, $value);
         }
         // perform append
         $this->_append($temp, $child);
     }
 }
コード例 #5
0
ファイル: item.php プロジェクト: Carbenium/aowow
 protected function generateXML($asError = false)
 {
     $root = new SimpleXML('<aowow />');
     if ($asError) {
         $root->addChild('error', 'Item not found!');
     } else {
         // item root
         $xml = $root->addChild('item');
         $xml->addAttribute('id', $this->subject->id);
         // name
         $xml->addChild('name')->addCData($this->subject->getField('name', true));
         // itemlevel
         $xml->addChild('level', $this->subject->getField('itemLevel'));
         // quality
         $xml->addChild('quality', Lang::item('quality', $this->subject->getField('quality')))->addAttribute('id', $this->subject->getField('quality'));
         // class
         $x = Lang::item('cat', $this->subject->getField('class'));
         $xml->addChild('class')->addCData(is_array($x) ? $x[0] : $x)->addAttribute('id', $this->subject->getField('class'));
         // subclass
         $x = $this->subject->getField('class') == 2 ? Lang::spell('weaponSubClass') : Lang::item('cat', $this->subject->getField('class'), 1);
         $xml->addChild('subclass')->addCData(is_array($x) ? is_array($x[$this->subject->getField('subClass')]) ? $x[$this->subject->getField('subClass')][0] : $x[$this->subject->getField('subClass')] : null)->addAttribute('id', $this->subject->getField('subClass'));
         // icon + displayId
         $xml->addChild('icon', $this->subject->getField('iconString'))->addAttribute('displayId', $this->subject->getField('displayId'));
         // inventorySlot
         $xml->addChild('inventorySlot', Lang::item('inventoryType', $this->subject->getField('slot')))->addAttribute('id', $this->subject->getField('slot'));
         // tooltip
         $xml->addChild('htmlTooltip')->addCData($this->subject->renderTooltip());
         $this->subject->extendJsonStats();
         // json
         $fields = ["classs", "displayid", "dps", "id", "level", "name", "reqlevel", "slot", "slotbak", "source", "sourcemore", "speed", "subclass"];
         $json = '';
         foreach ($fields as $f) {
             if (isset($this->subject->json[$this->subject->id][$f])) {
                 $_ = $this->subject->json[$this->subject->id][$f];
                 if ($f == 'name') {
                     $_ = 7 - $this->subject->getField('quality') . $_;
                 }
                 $json .= ',"' . $f . '":' . $_;
             }
         }
         $xml->addChild('json')->addCData(substr($json, 1));
         // jsonEquip missing: avgbuyout, cooldown, source, sourcemore
         $json = '';
         if ($_ = $this->subject->getField('sellPrice')) {
             // sellprice
             $json .= ',"sellprice":' . $_;
         }
         if ($_ = $this->subject->getField('requiredLevel')) {
             // reqlevel
             $json .= ',"reqlevel":' . $_;
         }
         if ($_ = $this->subject->getField('requiredSkill')) {
             // reqskill
             $json .= ',"reqskill":' . $_;
         }
         if ($_ = $this->subject->getField('requiredSkillRank')) {
             // reqskillrank
             $json .= ',"reqskillrank":' . $_;
         }
         foreach ($this->subject->itemMods[$this->subject->id] as $mod => $qty) {
             $json .= ',"' . $mod . '":' . $qty;
         }
         foreach ($_ = $this->subject->json[$this->subject->id] as $name => $qty) {
             if (in_array($name, Util::$itemFilter)) {
                 $json .= ',"' . $name . '":' . $qty;
             }
         }
         $xml->addChild('jsonEquip')->addCData(substr($json, 1));
         // jsonUse
         if ($onUse = $this->subject->getOnUseStats()) {
             $j = '';
             foreach ($onUse as $idx => $qty) {
                 $j .= ',"' . Util::$itemMods[$idx] . '":' . $qty;
             }
             $xml->addChild('jsonUse')->addCData(substr($j, 1));
         }
         // reagents
         $cnd = array('OR', ['AND', ['effect1CreateItemId', $this->subject->id], ['OR', ['effect1Id', SpellList::$effects['itemCreate']], ['effect1AuraId', SpellList::$auras['itemCreate']]]], ['AND', ['effect2CreateItemId', $this->subject->id], ['OR', ['effect2Id', SpellList::$effects['itemCreate']], ['effect2AuraId', SpellList::$auras['itemCreate']]]], ['AND', ['effect3CreateItemId', $this->subject->id], ['OR', ['effect3Id', SpellList::$effects['itemCreate']], ['effect3AuraId', SpellList::$auras['itemCreate']]]]);
         $spellSource = new SpellList($cnd);
         if (!$spellSource->error) {
             $cbNode = $xml->addChild('createdBy');
             foreach ($spellSource->iterate() as $sId => $__) {
                 foreach ($spellSource->canCreateItem() as $idx) {
                     if ($spellSource->getField('effect' . $idx . 'CreateItemId') != $this->subject->id) {
                         continue;
                     }
                     $splNode = $cbNode->addChild('spell');
                     $splNode->addAttribute('id', $sId);
                     $splNode->addAttribute('name', $spellSource->getField('name', true));
                     $splNode->addAttribute('icon', $this->subject->getField('iconString'));
                     $splNode->addAttribute('minCount', $spellSource->getField('effect' . $idx . 'BasePoints') + 1);
                     $splNode->addAttribute('maxCount', $spellSource->getField('effect' . $idx . 'BasePoints') + $spellSource->getField('effect' . $idx . 'DieSides'));
                     foreach ($spellSource->getReagentsForCurrent() as $rId => $qty) {
                         if ($reagent = $spellSource->relItems->getEntry($rId)) {
                             $rgtNode = $splNode->addChild('reagent');
                             $rgtNode->addAttribute('id', $rId);
                             $rgtNode->addAttribute('name', Util::localizedString($reagent, 'name'));
                             $rgtNode->addAttribute('quality', $reagent['quality']);
                             $rgtNode->addAttribute('icon', $reagent['iconString']);
                             $rgtNode->addAttribute('count', $qty[1]);
                         }
                     }
                     break;
                 }
             }
         }
         // link
         $xml->addChild('link', HOST_URL . '?item=' . $this->subject->id);
     }
     return $root->asXML();
 }