HTMLPurifier 4.4.0
/home/ezyang/Dev/htmlpurifier/library/HTMLPurifier/AttrTypes.php
Go to the documentation of this file.
00001 <?php
00002 
00006 class HTMLPurifier_AttrTypes
00007 {
00011     protected $info = array();
00012 
00017     public function __construct() {
00018         // XXX This is kind of poor, since we don't actually /clone/
00019         // instances; instead, we use the supplied make() attribute. So,
00020         // the underlying class must know how to deal with arguments.
00021         // With the old implementation of Enum, that ignored its
00022         // arguments when handling a make dispatch, the IAlign
00023         // definition wouldn't work.
00024 
00025         // pseudo-types, must be instantiated via shorthand
00026         $this->info['Enum']    = new HTMLPurifier_AttrDef_Enum();
00027         $this->info['Bool']    = new HTMLPurifier_AttrDef_HTML_Bool();
00028 
00029         $this->info['CDATA']    = new HTMLPurifier_AttrDef_Text();
00030         $this->info['ID']       = new HTMLPurifier_AttrDef_HTML_ID();
00031         $this->info['Length']   = new HTMLPurifier_AttrDef_HTML_Length();
00032         $this->info['MultiLength'] = new HTMLPurifier_AttrDef_HTML_MultiLength();
00033         $this->info['NMTOKENS'] = new HTMLPurifier_AttrDef_HTML_Nmtokens();
00034         $this->info['Pixels']   = new HTMLPurifier_AttrDef_HTML_Pixels();
00035         $this->info['Text']     = new HTMLPurifier_AttrDef_Text();
00036         $this->info['URI']      = new HTMLPurifier_AttrDef_URI();
00037         $this->info['LanguageCode'] = new HTMLPurifier_AttrDef_Lang();
00038         $this->info['Color']    = new HTMLPurifier_AttrDef_HTML_Color();
00039         $this->info['IAlign']   = self::makeEnum('top,middle,bottom,left,right');
00040         $this->info['LAlign']   = self::makeEnum('top,bottom,left,right');
00041         $this->info['FrameTarget'] = new HTMLPurifier_AttrDef_HTML_FrameTarget();
00042 
00043         // unimplemented aliases
00044         $this->info['ContentType'] = new HTMLPurifier_AttrDef_Text();
00045         $this->info['ContentTypes'] = new HTMLPurifier_AttrDef_Text();
00046         $this->info['Charsets'] = new HTMLPurifier_AttrDef_Text();
00047         $this->info['Character'] = new HTMLPurifier_AttrDef_Text();
00048 
00049         // "proprietary" types
00050         $this->info['Class'] = new HTMLPurifier_AttrDef_HTML_Class();
00051 
00052         // number is really a positive integer (one or more digits)
00053         // FIXME: ^^ not always, see start and value of list items
00054         $this->info['Number']   = new HTMLPurifier_AttrDef_Integer(false, false, true);
00055     }
00056 
00057     private static function makeEnum($in) {
00058         return new HTMLPurifier_AttrDef_Clone(new HTMLPurifier_AttrDef_Enum(explode(',', $in)));
00059     }
00060 
00066     public function get($type) {
00067 
00068         // determine if there is any extra info tacked on
00069         if (strpos($type, '#') !== false) list($type, $string) = explode('#', $type, 2);
00070         else $string = '';
00071 
00072         if (!isset($this->info[$type])) {
00073             trigger_error('Cannot retrieve undefined attribute type ' . $type, E_USER_ERROR);
00074             return;
00075         }
00076 
00077         return $this->info[$type]->make($string);
00078 
00079     }
00080 
00086     public function set($type, $impl) {
00087         $this->info[$type] = $impl;
00088     }
00089 }
00090 
00091 // vim: et sw=4 sts=4