Example #1
0
/**
 *从某节点开始向下遍历遍历XML文档所有节点的方法
 *@param DOMDocument $node
 *@param int $depth
 *@param StructNode $arr
 *@return StructNode
 */
function walk_xml($node, $depth, $arr)
{
    for ($i = 0, $indent = ''; $i < $depth; $i++) {
        $indent .= '   ';
    }
    if (!empty($node->tagName)) {
        //非空格换行或非纯文本的有效标签
        $arr->tagName = $node->tagName;
        $arr->depth = $depth;
        $arr->xmlTagName = $node->getAttribute("name");
        //设置对应xml的标签名
        $arr->xmlTagType = $node->getAttribute("type");
        //设置对应xml的标签属性
    }
    $children = $node->childNodes;
    if (isset($children->length)) {
        $children_count = $children->length;
        if ($children_count > 0) {
            $depth++;
            for ($i = 0; $i < $children_count; $i++) {
                if (!empty($children->item($i)->tagName)) {
                    $child = new StructNode();
                    walk_xml($children->item($i), $depth, $child);
                    $arr->children_list[] = $child;
                }
            }
        }
    }
    return $arr;
}
Example #2
0
 /**
  * DOMから有効なサムネイルを取得する
  * 有効な場合は画像のURLを返却する
  * 無効な場合は false を返却する
  *
  * @param  DOMDocument $dom
  * @return mixed
  */
 public function get($dom)
 {
     if ($dom->hasAttribute('class') && strpos($dom->getAttribute('class'), 'pict') === 0) {
         return $dom->getAttribute('src');
     }
     return false;
 }
Example #3
0
 /**
  * DOMから有効なサムネイルを取得する
  * 有効な場合は画像のURLを返却する
  * 無効な場合は false を返却する
  *
  * @param  DOMDocument $dom
  * @return mixed
  */
 public function get($dom)
 {
     if ($dom->hasAttribute('width') && $dom->hasAttribute('height') && $dom->hasAttribute('alt') && !$dom->hasAttribute('title')) {
         $src = $dom->getAttribute('src');
         if (preg_match('/^http(s)?:\\/\\/blog-imgs-.*\\.fc2\\.com.*/', $src)) {
             return str_replace('-origin', '', $src);
         }
     }
     return false;
 }
Example #4
0
 /**
  * DOMから有効なサムネイルを取得する
  * 有効な場合は画像のURLを返却する
  * 無効な場合は false を返却する
  *
  * @param  DOMDocument $dom
  * @return mixed
  */
 public function get($dom)
 {
     if ($dom->hasAttribute('width') && $dom->hasAttribute('height') && $dom->hasAttribute('alt') && !$dom->hasAttribute('title')) {
         $src = $dom->getAttribute('src');
         if (preg_match('/^http(s)?:\\/\\/stat.*\\.ameba\\.jp.*/', $src)) {
             return $src;
         }
     }
     return false;
 }
Example #5
0
    $XMLNav->AddNode($node->documentElement, $XMLNav->XML->documentElement);
    $XPath = new DOMXPath($XMLNav->XML);
    $entries = $XPath->query('//node[@type = "tasks"]', $XMLNav->XML->documentElement);
    if ($entries && $entries->item(0)) {
        foreach ($entries as $node) {
            if ($node instanceof DOMElement) {
                $node->setAttribute("title", sprintf(_("Tasks for %s"), "{$_SESSION['domain']}.{$_SESSION['TLD']}"));
            }
        }
    }
    $entries = $XPath->query('//item[@type != ""]', $XMLNav->XML->documentElement);
    if ($entries && $entries->item(0)) {
        foreach ($entries as $node) {
            if ($node instanceof DOMElement) {
                $exists = false;
                $type = $node->getAttribute("type");
                foreach (UI::GetContactsListForSmarty($Registry->Manifest->GetSectionConfig()) as $ck => $cv) {
                    if ($cv["type"] == $type) {
                        $exists = true;
                    }
                }
                if (!$exists) {
                    $node->parentNode->removeChild($node);
                }
            }
        }
    }
}
// Language Node
if (count($display["languages"]) > 1) {
    //
 /**
  * @param             $tag
  * @param             $propertyName
  * @param             $propertyValue
  * @param DOMDocument $node
  *
  * @return array
  */
 public function getElementsByProperty($tag, $propertyName, $propertyValue, $node = null)
 {
     $nodes = $node == null ? $this->getElementsByTagName($tag) : $node->getElementsByTagName($tag);
     $result = array();
     /** @var DOMElement $node */
     foreach ($nodes as $node) {
         if ($node->hasAttribute($propertyName)) {
             if ($node->getAttribute($propertyName) == $propertyValue) {
                 $result[] = $node;
             }
         }
     }
     return $result;
 }