當前位置: 首頁>>代碼示例>>PHP>>正文


PHP TexyHtml::validateAttrs方法代碼示例

本文整理匯總了PHP中TexyHtml::validateAttrs方法的典型用法代碼示例。如果您正苦於以下問題:PHP TexyHtml::validateAttrs方法的具體用法?PHP TexyHtml::validateAttrs怎麽用?PHP TexyHtml::validateAttrs使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在TexyHtml的用法示例。


在下文中一共展示了TexyHtml::validateAttrs方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。

示例1: solveTag


//.........這裏部分代碼省略.........
     }
     $name = $el->getName();
     $lower = strtolower($name);
     if (isset($tx->dtd[$lower]) || $name === strtoupper($name)) {
         $name = $lower;
         $el->setName($name);
     }
     if (is_array($allowedTags)) {
         if (!isset($allowedTags[$name])) {
             return FALSE;
         }
         $allowedAttrs = $allowedTags[$name];
     } else {
         if ($forceEmpty) {
             $el->setName($name, TRUE);
         }
         $allowedAttrs = Texy::ALL;
     }
     if (!$isStart) {
         return $el;
     }
     $elAttrs =& $el->attrs;
     if (!$allowedAttrs) {
         $elAttrs = array();
     } elseif (is_array($allowedAttrs)) {
         $allowedAttrs = array_flip($allowedAttrs);
         foreach ($elAttrs as $key => $foo) {
             if (!isset($allowedAttrs[$key])) {
                 unset($elAttrs[$key]);
             }
         }
     }
     $tmp = $tx->_classes;
     if (isset($elAttrs['class'])) {
         if (is_array($tmp)) {
             $elAttrs['class'] = explode(' ', $elAttrs['class']);
             foreach ($elAttrs['class'] as $key => $value) {
                 if (!isset($tmp[$value])) {
                     unset($elAttrs['class'][$key]);
                 }
             }
         } elseif ($tmp !== Texy::ALL) {
             $elAttrs['class'] = NULL;
         }
     }
     if (isset($elAttrs['id'])) {
         if (is_array($tmp)) {
             if (!isset($tmp['#' . $elAttrs['id']])) {
                 $elAttrs['id'] = NULL;
             }
         } elseif ($tmp !== Texy::ALL) {
             $elAttrs['id'] = NULL;
         }
     }
     if (isset($elAttrs['style'])) {
         $tmp = $tx->_styles;
         if (is_array($tmp)) {
             $styles = explode(';', $elAttrs['style']);
             $elAttrs['style'] = NULL;
             foreach ($styles as $value) {
                 $pair = explode(':', $value, 2);
                 $prop = trim($pair[0]);
                 if (isset($pair[1]) && isset($tmp[strtolower($prop)])) {
                     $elAttrs['style'][$prop] = $pair[1];
                 }
             }
         } elseif ($tmp !== Texy::ALL) {
             $elAttrs['style'] = NULL;
         }
     }
     if ($name === 'img') {
         if (!isset($elAttrs['src'])) {
             return FALSE;
         }
         if (!$tx->checkURL($elAttrs['src'], Texy::FILTER_IMAGE)) {
             return FALSE;
         }
         $tx->summary['images'][] = $elAttrs['src'];
     } elseif ($name === 'a') {
         if (!isset($elAttrs['href']) && !isset($elAttrs['name']) && !isset($elAttrs['id'])) {
             return FALSE;
         }
         if (isset($elAttrs['href'])) {
             if ($tx->linkModule->forceNoFollow && strpos($elAttrs['href'], '//') !== FALSE) {
                 if (isset($elAttrs['rel'])) {
                     $elAttrs['rel'] = (array) $elAttrs['rel'];
                 }
                 $elAttrs['rel'][] = 'nofollow';
             }
             if (!$tx->checkURL($elAttrs['href'], Texy::FILTER_ANCHOR)) {
                 return FALSE;
             }
             $tx->summary['links'][] = $elAttrs['href'];
         }
     } elseif (preg_match('#^h[1-6]#i', $name)) {
         $tx->headingModule->TOC[] = array('el' => $el, 'level' => (int) substr($name, 1), 'type' => 'html');
     }
     $el->validateAttrs($tx->dtd);
     return $el;
 }
開發者ID:radimklaska,項目名稱:Drupal.cz,代碼行數:101,代碼來源:texy.compact.5.php

示例2: solveTag


//.........這裏部分代碼省略.........
     } else {
         // allowedTags === Texy::ALL
         if ($forceEmpty) {
             $el->setName($name, TRUE);
         }
         $allowedAttrs = Texy::ALL;
         // all attrs are allowed
     }
     // end tag? we are finished
     if (!$isStart) {
         return $el;
     }
     $elAttrs =& $el->attrs;
     // process attributes
     if (!$allowedAttrs) {
         $elAttrs = array();
     } elseif (is_array($allowedAttrs)) {
         // skip disabled
         $allowedAttrs = array_flip($allowedAttrs);
         foreach ($elAttrs as $key => $foo) {
             if (!isset($allowedAttrs[$key])) {
                 unset($elAttrs[$key]);
             }
         }
     }
     // apply allowedClasses
     $tmp = $tx->_classes;
     // speed-up
     if (isset($elAttrs['class'])) {
         if (is_array($tmp)) {
             $elAttrs['class'] = explode(' ', $elAttrs['class']);
             foreach ($elAttrs['class'] as $key => $value) {
                 if (!isset($tmp[$value])) {
                     unset($elAttrs['class'][$key]);
                 }
             }
             // id & class are case-sensitive
         } elseif ($tmp !== Texy::ALL) {
             $elAttrs['class'] = NULL;
         }
     }
     // apply allowedClasses for ID
     if (isset($elAttrs['id'])) {
         if (is_array($tmp)) {
             if (!isset($tmp['#' . $elAttrs['id']])) {
                 $elAttrs['id'] = NULL;
             }
         } elseif ($tmp !== Texy::ALL) {
             $elAttrs['id'] = NULL;
         }
     }
     // apply allowedStyles
     if (isset($elAttrs['style'])) {
         $tmp = $tx->_styles;
         // speed-up
         if (is_array($tmp)) {
             $styles = explode(';', $elAttrs['style']);
             $elAttrs['style'] = NULL;
             foreach ($styles as $value) {
                 $pair = explode(':', $value, 2);
                 $prop = trim($pair[0]);
                 if (isset($pair[1]) && isset($tmp[strtolower($prop)])) {
                     // CSS is case-insensitive
                     $elAttrs['style'][$prop] = $pair[1];
                 }
             }
         } elseif ($tmp !== Texy::ALL) {
             $elAttrs['style'] = NULL;
         }
     }
     if ($name === 'img') {
         if (!isset($elAttrs['src'])) {
             return FALSE;
         }
         if (!$tx->checkURL($elAttrs['src'], Texy::FILTER_IMAGE)) {
             return FALSE;
         }
         $tx->summary['images'][] = $elAttrs['src'];
     } elseif ($name === 'a') {
         if (!isset($elAttrs['href']) && !isset($elAttrs['name']) && !isset($elAttrs['id'])) {
             return FALSE;
         }
         if (isset($elAttrs['href'])) {
             if ($tx->linkModule->forceNoFollow && strpos($elAttrs['href'], '//') !== FALSE) {
                 if (isset($elAttrs['rel'])) {
                     $elAttrs['rel'] = (array) $elAttrs['rel'];
                 }
                 $elAttrs['rel'][] = 'nofollow';
             }
             if (!$tx->checkURL($elAttrs['href'], Texy::FILTER_ANCHOR)) {
                 return FALSE;
             }
             $tx->summary['links'][] = $elAttrs['href'];
         }
     } elseif (preg_match('#^h[1-6]#i', $name)) {
         $tx->headingModule->TOC[] = array('el' => $el, 'level' => (int) substr($name, 1), 'type' => 'html');
     }
     $el->validateAttrs($tx->dtd);
     return $el;
 }
開發者ID:jiripudil,項目名稱:texy,代碼行數:101,代碼來源:TexyHtmlModule.php


注:本文中的TexyHtml::validateAttrs方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。