Exemplo n.º 1
0
 /**
  * returns true if the url's have been written. false if not
  */
 public static function rewrittenURLs()
 {
     return I2CE::rewrittenURLs();
 }
Exemplo n.º 2
0
 /**
  * Add a script or css to the header as a link 
  * 
  * @param string $file
  * @param mixed $attr   --   an array of attribute/value pairs.   Defaults to the empty array.  can also be a string
  *   in which case it is the id that you want to give the import node.
  * @param boolean $use_filedump -- default to true meaning that we should use the filedump utility 
  *       when looking for the script/css
  * @returm DOMNode -- the node just created or appended to
  *  You might use this by calling
  *  addHeaderLink("printer.css",'',array('media'=>'print'));
  * Note: Uses the file's extension to determine the proper behavior.  Valid ones are 'js', 'css', and 'vb'
  */
 public function addHeaderLink($file, $attr = array(), $use_filedump = true)
 {
     if (array_key_exists($file, $this->files_loaded) && $this->files_loaded[$file]) {
         // Check to make sure this  file hasn't already been loaded and ignore it if so.
         return;
     }
     // we have not loaded the file so start loading it
     $this->files_loaded[$file] = true;
     $ext = strtolower(substr(strrchr($file, "."), 1));
     if ($use_filedump) {
         if (I2CE::rewrittenURLs()) {
             $file_src = 'file/' . $file;
         } else {
             $file_src = 'index.php/file/' . $file;
         }
     }
     if (is_scalar($attr)) {
         $attr = array('id' => $attr);
     }
     if (!is_array($attr)) {
         $attr = array();
     }
     switch ($ext) {
         case 'js':
             $node = null;
             $existed = false;
             foreach ($this->query('//script[@type="text/javascript"]') as $js_node) {
                 if (!($src = $js_node->getAttribute('src'))) {
                     continue;
                 }
                 if (substr($src, 0, 15) == 'index.php/file/') {
                     $src = substr($src, 15);
                 } else {
                     if (substr($src, 0, 5) == 'file/') {
                         $src = substr($src, 5);
                     }
                 }
                 if ($src == $file) {
                     $existed = true;
                     return $js_node;
                 }
             }
             if (array_key_exists('id', $attr)) {
                 $node = $this->getElementById($attr['id']);
                 if ($node instanceof DOMElement) {
                     $existed = true;
                 } else {
                     $node = $this->doc->createElement('script', '');
                     $node->setAttribute('id', $attr['id']);
                 }
                 unset($attr['id']);
             } else {
                 $node = $this->doc->createElement('script', '');
             }
             if ($existed) {
                 $old_file = $node->getAttribute('src');
                 if ($old_file) {
                     $node->removeAttribute('src');
                     $node->appendChild($this->doc->createTextNode('document.write(\'<script type="text/javascript" src="' . $old_file . '"></script>\');'));
                 }
                 $node->appendChild($this->doc->createTextNode('document.write(\'<script type="text/javascript" src="' . $file_src . '"></script>\');'));
             } else {
                 $node->setAttribute('src', $file_src);
                 $node->setAttribute('type', 'text/javascript');
             }
             break;
         case 'vb':
             $node = $this->doc->createElement('script', '');
             $node->setAttribute('src', $file_src);
             $node->setAttribute('type', 'text/vbscript');
             break;
         case 'css':
             if (array_key_exists('ie6', $attr) && $attr['ie6']) {
                 $node = $this->doc->createComment('[if lt IE 7]>');
                 $link = $this->doc->createElement('link', '');
                 $link->setAttribute('rel', 'stylesheet');
                 $link->setAttribute('media', 'screen');
                 $link->setAttribute('href', $file_src . "?newman");
                 $link->setAttribute('type', 'text/css');
                 foreach ($attr as $a => $v) {
                     $link->setAttribute($a, $v);
                 }
                 $node->appendData($this->doc->saveXML($link));
                 $node->appendData("<![endif]");
                 $attr = array();
             } else {
                 $node = $this->doc->createElement('link', '');
                 $node->setAttribute('rel', 'stylesheet');
                 $node->setAttribute('media', 'screen');
                 $node->setAttribute('href', $file_src);
                 $node->setAttribute('type', 'text/css');
             }
             break;
         default:
             $this->raiseError("Unknown file type ({$ext}) for linking in the header", E_USER_NOTICE);
             return;
     }
     foreach ($attr as $a => $v) {
         $node->setAttribute($a, $v);
     }
     if (!($head_node = $this->doc->getElementsByTagName("head")->item(0)) instanceof DOMNode) {
         return false;
     }
     return $this->appendNode($node, $head_node);
     //append the node to the begining of the header
 }