XML_Feed_Parser
[ class tree: XML_Feed_Parser ] [ index: XML_Feed_Parser ] [ all elements ]

Source for file Sanitizer.php

Documentation is available at Sanitizer.php

  1. <?php
  2. /** @see http://code.google.com/p/feedparser/source/browse/trunk/feedparser/feedparser.py */
  3. interface XML_Feed_Parser_Sanitizer {
  4.     public function sanitize($input);
  5. }
  6.  
  7. class XML_Feed_Parser_Unsafe_Sanitizer implements XML_Feed_Parser_Sanitizer {
  8.     public function sanitize($input{
  9.         return $input;
  10.     }
  11. }
  12.  
  13. class XML_Feed_Parser_StripTags_Sanitizer implements XML_Feed_Parser_Sanitizer {
  14.     protected $acceptable_elements = array('a''abbr''acronym''address''area',
  15.         'article''aside''audio''b''big''blockquote''br''button',
  16.         'canvas''caption''center''cite''code''col''colgroup',
  17.         'command''datagrid''datalist''dd''del''details''dfn',
  18.         'dialog''dir''div''dl''dt''em''event-source''fieldset',
  19.         'figcaption''figure''footer''font''form''header''h1',
  20.         'h2''h3''h4''h5''h6''hr''i''img''input''ins',
  21.         'keygen''kbd''label''legend''li''m''map''menu''meter',
  22.         'multicol''nav''nextid''ol''output''optgroup''option',
  23.         'p''pre''progress''q''s''samp''section''select',
  24.         'small''sound''source''spacer''span''strike''strong',
  25.         'sub''sup''table''tbody''td''textarea''time''tfoot',
  26.         'th''thead''tr''tt''u''ul''var''video''noscript');
  27.  
  28.     protected $acceptable_attributes = array('abbr''accept''accept-charset''accesskey',
  29.       'action''align''alt''autocomplete''autofocus''axis',
  30.       'background''balance''bgcolor''bgproperties''border',
  31.       'bordercolor''bordercolordark''bordercolorlight''bottompadding',
  32.       'cellpadding''cellspacing''ch''challenge''char''charoff',
  33.       'choff''charset''checked''cite''class''clear''color''cols',
  34.       'colspan''compact''contenteditable''controls''coords''data',
  35.       'datafld''datapagesize''datasrc''datetime''default''delay',
  36.       'dir''disabled''draggable''dynsrc''enctype''end''face''for',
  37.       'form''frame''galleryimg''gutter''headers''height''hidefocus',
  38.       'hidden''high''href''hreflang''hspace''icon''id''inputmode',
  39.       'ismap''keytype''label''leftspacing''lang''list''longdesc',
  40.       'loop''loopcount''loopend''loopstart''low''lowsrc''max',
  41.       'maxlength''media''method''min''multiple''name''nohref',
  42.       'noshade''nowrap''open''optimum''pattern''ping''point-size',
  43.       'prompt''pqg''radiogroup''readonly''rel''repeat-max',
  44.       'repeat-min''replace''required''rev''rightspacing''rows',
  45.       'rowspan''rules''scope''selected''shape''size''span''src',
  46.       'start''step''summary''suppress''tabindex''target''template',
  47.       'title''toppadding''type''unselectable''usemap''urn''valign',
  48.       'value''variable''volume''vspace''vrml''width''wrap',
  49.       'xml:lang');
  50.  
  51.     protected $unacceptable_elements_with_end_tag = array('script''applet''style');
  52.  
  53.     protected $acceptable_css_properties = array('azimuth''background-color',
  54.       'border-bottom-color''border-collapse''border-color',
  55.       'border-left-color''border-right-color''border-top-color''clear',
  56.       'color''cursor''direction''display''elevation''float''font',
  57.       'font-family''font-size''font-style''font-variant''font-weight',
  58.       'height''letter-spacing''line-height''overflow''pause',
  59.       'pause-after''pause-before''pitch''pitch-range''richness',
  60.       'speak''speak-header''speak-numeral''speak-punctuation',
  61.       'speech-rate''stress''text-align''text-decoration''text-indent',
  62.       'unicode-bidi''vertical-align''voice-family''volume',
  63.       'white-space''width');
  64.  
  65.     # survey of common keywords found in feeds
  66.     protected $acceptable_css_keywords = array('auto''aqua''black''block''blue',
  67.       'bold''both''bottom''brown''center''collapse''dashed',
  68.       'dotted''fuchsia''gray''green''!important''italic''left',
  69.       'lime''maroon''medium''none''navy''normal''nowrap''olive',
  70.       'pointer''purple''red''right''solid''silver''teal''top',
  71.       'transparent''underline''white''yellow');
  72.  
  73.     protected $valid_css_values '^(#[0-9a-f]+|rgb\(\d+%?,\d*%?,?\d*%?\)?|\d{0,2}\.?\d{0,2}(cm|em|ex|in|mm|pc|pt|px|%|,|\))?)$';
  74.  
  75.     protected $mathml_elements = array('annotation''annotation-xml''maction''math',
  76.       'merror''mfenced''mfrac''mi''mmultiscripts''mn''mo''mover''mpadded',
  77.       'mphantom''mprescripts''mroot''mrow''mspace''msqrt''mstyle',
  78.       'msub''msubsup''msup''mtable''mtd''mtext''mtr''munder',
  79.       'munderover''none''semantics');
  80.  
  81.     protected $mathml_attributes = array('actiontype''align''columnalign''columnalign',
  82.       'columnalign''close''columnlines''columnspacing''columnspan''depth',
  83.       'display''displaystyle''encoding''equalcolumns''equalrows',
  84.       'fence''fontstyle''fontweight''frame''height''linethickness',
  85.       'lspace''mathbackground''mathcolor''mathvariant''mathvariant',
  86.       'maxsize''minsize''open''other''rowalign''rowalign''rowalign',
  87.       'rowlines''rowspacing''rowspan''rspace''scriptlevel''selection',
  88.       'separator''separators''stretchy''width''width''xlink:href',
  89.       'xlink:show''xlink:type''xmlns''xmlns:xlink');
  90.  
  91.     # svgtiny - foreignObject + linearGradient + radialGradient + stop
  92.     protected $svg_elements = array('a''animate''animateColor''animateMotion',
  93.       'animateTransform''circle''defs''desc''ellipse''foreignObject',
  94.       'font-face''font-face-name''font-face-src''g''glyph''hkern',
  95.       'linearGradient''line''marker''metadata''missing-glyph''mpath',
  96.       'path''polygon''polyline''radialGradient''rect''set''stop',
  97.       'svg''switch''text''title''tspan''use');
  98.  
  99.     # svgtiny + class + opacity + offset + xmlns + xmlns:xlink
  100.     protected $svg_attributes = array('accent-height''accumulate''additive''alphabetic',
  101.        'arabic-form''ascent''attributeName''attributeType',
  102.        'baseProfile''bbox''begin''by''calcMode''cap-height',
  103.        'class''color''color-rendering''content''cx''cy''d''dx',
  104.        'dy''descent''display''dur''end''fill''fill-opacity',
  105.        'fill-rule''font-family''font-size''font-stretch''font-style',
  106.        'font-variant''font-weight''from''fx''fy''g1''g2',
  107.        'glyph-name''gradientUnits''hanging''height''horiz-adv-x',
  108.        'horiz-origin-x''id''ideographic''k''keyPoints''keySplines',
  109.        'keyTimes''lang''mathematical''marker-end''marker-mid',
  110.        'marker-start''markerHeight''markerUnits''markerWidth''max',
  111.        'min''name''offset''opacity''orient''origin',
  112.        'overline-position''overline-thickness''panose-1''path',
  113.        'pathLength''points''preserveAspectRatio''r''refX''refY',
  114.        'repeatCount''repeatDur''requiredExtensions''requiredFeatures',
  115.        'restart''rotate''rx''ry''slope''stemh''stemv',
  116.        'stop-color''stop-opacity''strikethrough-position',
  117.        'strikethrough-thickness''stroke''stroke-dasharray',
  118.        'stroke-dashoffset''stroke-linecap''stroke-linejoin',
  119.        'stroke-miterlimit''stroke-opacity''stroke-width''systemLanguage',
  120.        'target''text-anchor''to''transform''type''u1''u2',
  121.        'underline-position''underline-thickness''unicode''unicode-range',
  122.        'units-per-em''values''version''viewBox''visibility''width',
  123.        'widths''x''x-height''x1''x2''xlink:actuate''xlink:arcrole',
  124.        'xlink:href''xlink:role''xlink:show''xlink:title''xlink:type',
  125.        'xml:base''xml:lang''xml:space''xmlns''xmlns:xlink''y''y1',
  126.        'y2''zoomAndPan');
  127.  
  128.  
  129.     protected $acceptable_svg_properties = array('fill''fill-opacity''fill-rule',
  130.       'stroke''stroke-width''stroke-linecap''stroke-linejoin',
  131.       'stroke-opacity');
  132.  
  133.     public function sanitize($input{
  134.         $acceptable "";
  135.         foreach ($this->acceptable_elements as $element{
  136.             $acceptable .= "<" $element ">";
  137.         }
  138.  
  139.         return strip_tags($input$acceptable);
  140.     }
  141. }

Documentation generated on Mon, 11 Mar 2019 15:47:22 -0400 by phpDocumentor 1.4.4. PEAR Logo Copyright © PHP Group 2004.