当前位置: 首页>>代码示例>>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;未经允许,请勿转载。