Beispiel #1
0
 public function finalize()
 {
     Document::registerAssets();
 }
Beispiel #2
0
 public function print_inline_scripts()
 {
     Document::registerScripts('footer');
     $scripts = Gantry::instance()->scripts('footer');
     if ($scripts) {
         echo implode("\n    ", $scripts) . "\n";
     }
 }
 /**
  * Move supported document head elements into platform document object, return all
  * unsupported tags in a string.
  *
  * @param string $input
  * @param string $location
  * @param int $priority
  * @return string
  */
 public function parseAssetsFunc($input, $location = 'head', $priority = 0)
 {
     $doc = new \DOMDocument();
     $doc->loadHTML('<html><head>' . $input . '</head><body></body></html>');
     $raw = [];
     /** @var \DomElement $element */
     foreach ($doc->getElementsByTagName('head')->item(0)->childNodes as $element) {
         $result = ['tag' => $element->tagName, 'content' => $element->textContent];
         foreach ($element->attributes as $attribute) {
             $result[$attribute->name] = $attribute->value;
         }
         $success = Document::addHeaderTag($result, $location, $priority);
         if (!$success) {
             $raw[] = $doc->saveHTML($element);
         }
     }
     return implode("\n", $raw);
 }
Beispiel #4
0
 /**
  * @param string $location
  * @return array
  */
 public function scripts($location = 'head')
 {
     return RealDocument::getScripts($location);
 }
 /**
  * Move supported document head elements into platform document object, return all
  * unsupported tags in a string.
  *
  * @param string $input
  * @param string $location
  * @param int $priority
  * @return string
  */
 public function parseAssetsFunc($input, $location = 'head', $priority = 0)
 {
     if ($location == 'head') {
         $scope = 'head';
     } else {
         $scope = 'body';
     }
     $html = "<html><{$scope}>{$input}</{$scope}></html>";
     $internal = libxml_use_internal_errors(true);
     $doc = new \DOMDocument();
     $doc->loadHTML($html);
     foreach (libxml_get_errors() as $error) {
         $this->dealXmlError($error, $html);
     }
     libxml_clear_errors();
     libxml_use_internal_errors($internal);
     $raw = [];
     /** @var \DomElement $element */
     foreach ($doc->getElementsByTagName($scope)->item(0)->childNodes as $element) {
         if (empty($element->tagName)) {
             continue;
         }
         $result = ['tag' => $element->tagName, 'content' => $element->textContent];
         foreach ($element->attributes as $attribute) {
             $result[$attribute->name] = $attribute->value;
         }
         $success = Document::addHeaderTag($result, $location, (int) $priority);
         if (!$success) {
             $raw[] = $doc->saveHTML($element);
         }
     }
     return implode("\n", $raw);
 }