Ejemplo n.º 1
1
 static function updateAssetsUrls($content, $ajaxMode)
 {
     $serverUrl = \BearCMS\Internal\Options::$serverUrl;
     if ($ajaxMode) {
         $hasChange = false;
         $contentData = json_decode($content, true);
         if (isset($contentData['jsFiles'])) {
             $newJsFiles = [];
             foreach ($contentData['jsFiles'] as $src) {
                 if (isset($src[0]) && strpos($src, $serverUrl) === 0) {
                     $hasChange = true;
                     $scriptBundle[] = $src;
                 } else {
                     $newJsFiles[] = $src;
                 }
             }
             if (!empty($scriptBundle)) {
                 $newJsFiles[] = self::getAssetsUrl(array_unique($scriptBundle));
             }
             $contentData['jsFiles'] = $newJsFiles;
         }
         if ($hasChange) {
             return json_encode($contentData);
         }
     } else {
         $hasChange = false;
         $dom = new \IvoPetkov\HTML5DOMDocument();
         $dom->loadHTML($content);
         $scripts = $dom->querySelectorAll('script');
         $scriptBundle = [];
         $scriptsToRemove = [];
         foreach ($scripts as $script) {
             $src = (string) $script->getAttribute('src');
             if (isset($src[0]) && strpos($src, $serverUrl) === 0) {
                 $hasChange = true;
                 if ($script->getAttribute('async') === 'async') {
                     $scriptsToRemove[] = $script;
                     $scriptBundle[] = $src;
                 } else {
                     $script->setAttribute('src', self::getAssetsUrl([$src]));
                 }
             }
         }
         foreach ($scriptsToRemove as $script) {
             $script->parentNode->removeChild($script);
         }
         if (!empty($scriptBundle)) {
             $script = $dom->createElement('script');
             $script->setAttribute('async', 'async');
             $script->setAttribute('src', self::getAssetsUrl(array_unique($scriptBundle)));
             $dom->querySelector('body')->appendChild($script);
         }
         if ($hasChange) {
             return $dom->saveHTML();
         }
     }
     return $content;
 }
if (strlen($component->class) > 0) {
    $attributes .= ' class="' . htmlentities($component->class) . '"';
}
$attributes .= ' moreItemHtml="' . htmlentities('<li class="bearcms-navigation-element-item bearcms-navigation-element-item-more"><a></a><ul class="bearcms-navigation-element-item-children"></ul></li>') . '"';
$dataResponsiveAttributes = $component->getAttribute('data-responsive-attributes');
if (strlen($dataResponsiveAttributes) > 0) {
    $attributes .= ' data-responsive-attributes="' . htmlentities(str_replace('=>menuType=', '=>type=', $dataResponsiveAttributes)) . '"';
}
if ($pages !== null && $showHomeButton) {
    $pages->unshift(new \BearCMS\DataObject(['id' => '_home', 'path' => '/', 'name' => $homeButtomText, 'parentID' => '', 'status' => 'published']));
}
$itemsHtml = (string) $component->innerHTML;
if (isset($itemsHtml[0])) {
    $domDocument = new IvoPetkov\HTML5DOMDocument();
    $domDocument->loadHTML($itemsHtml);
    $ulElements = $domDocument->querySelectorAll('ul');
    foreach ($ulElements as $index => $ulElement) {
        $ulElement->setAttribute('class', trim($ulElement->getAttribute('class') . ' ' . ($index === 0 ? 'bearcms-navigation-element' : 'bearcms-navigation-element-item-children')));
    }
    $liElements = $domDocument->querySelectorAll('li');
    foreach ($liElements as $index => $liElement) {
        $liClasssName = 'bearcms-navigation-element-item';
        if ($liElement->firstChild) {
            $liPath = str_replace($app->request->base, '', $liElement->firstChild->getAttribute('href'));
            if ($liPath === $selectedPath) {
                $liClasssName .= ' bearcms-navigation-element-item-selected';
            } elseif ($liPath !== '/' && strpos($selectedPath, $liPath) === 0) {
                $liClasssName .= ' bearcms-navigation-element-item-in-path';
            }
        }
        $liElement->setAttribute('class', trim($liElement->getAttribute('class') . ' ' . $liClasssName));
Ejemplo n.º 3
0
 static function getRawDataFromComponent($component)
 {
     $type = self::$elementTypes[$component->src];
     $data = [];
     $copyString = function ($name) use($component, &$data) {
         $data[$name] = (string) $component->{$name};
     };
     $copyBoolean = function ($name) use($component, &$data) {
         $data[$name] = $component->{$name} === 'true' ? true : false;
     };
     $copyInt = function ($name) use($component, &$data) {
         $data[$name] = (int) $component->{$name};
     };
     if ($type === 'heading') {
         $copyString('text');
         $copyString('size');
     } elseif ($type === 'text') {
         $copyString('text');
     } elseif ($type === 'link') {
         $copyString('url');
         $copyString('text');
         $copyString('title');
     } elseif ($type === 'video') {
         $copyString('url');
         $copyString('filename');
     } elseif ($type === 'image') {
         $copyString('filename');
         $copyString('title');
         $copyString('onClick');
         $copyString('url');
     } elseif ($type === 'imageGallery') {
         $copyString('type');
         $copyString('columnsCount');
         if (is_numeric($data['columnsCount'])) {
             $data['columnsCount'] = (int) $data['columnsCount'];
         }
         $copyString('imageSize');
         $copyString('imageAspectRatio');
         $data['files'] = [];
         if (strlen($component->innerHTML) > 0) {
             $domDocument = new \IvoPetkov\HTML5DOMDocument();
             $domDocument->loadHTML($component->innerHTML);
             $files = $domDocument->querySelectorAll('file');
             foreach ($files as $file) {
                 $filename = $file->getAttribute('filename');
                 $data['files'][] = ['filename' => $filename];
             }
         }
     } elseif ($type === 'navigation') {
         $copyString('type');
         $copyString('pageID');
     } elseif ($type === 'html') {
         $copyString('code');
     } elseif ($type === 'blogPosts') {
         $copyString('type');
         $copyBoolean('showDate');
         $copyInt('limit');
     }
     return ['id' => $component->id, 'type' => $type, 'data' => $data];
 }
 * Image gallery addon for Bear Framework
 * https://github.com/ivopetkov/image-gallery-bearframework-addon
 * Copyright (c) 2016 Ivo Petkov
 * Free to use under the MIT license.
 */
use BearFramework\App;
$app = App::get();
$context = $app->getContext(__FILE__);
$hasLightbox = false;
$hasResponsiveAttributes = false;
$hasElementID = false;
$internalOptionRenderContainer = $component->getAttribute('internal-option-render-container') !== 'false';
$internalOptionRenderImageContainer = $component->getAttribute('internal-option-render-image-container') !== 'false';
$domDocument = new IvoPetkov\HTML5DOMDocument();
$domDocument->loadHTML($component->innerHTML);
$files = $domDocument->querySelectorAll('file');
$onClick = 'fullscreen';
$temp = (string) $component->onClick;
if ($temp !== '') {
    if (array_search($temp, ['fullscreen', 'url', 'custom', 'none']) !== false) {
        $onClick = $temp;
    }
}
$imageAspectRatio = null;
$temp = (string) $component->imageAspectRatio;
if ($temp !== '') {
    if (preg_match('/^[0-9\\.]+:[0-9\\.]+$/', $temp) === 1) {
        $imageAspectRatio = $temp;
    }
}
$imageLoadingBackground = null;