Beispiel #1
0
 /**
  * @param \Render\APIs\APIv1\CSSAPI $api
  * @param \Render\Unit              $unit
  *
  * @return array
  */
 protected function getAnchor($api, $unit)
 {
     $anchorName = $api->getFormValue($unit, 'anchorName', '');
     $anchorId = $api->getFormValue($unit, 'anchorId', '');
     if (substr($anchorId, 0, 1) === '#') {
         $anchorId = substr($anchorId, 1);
     }
     return array('name' => $anchorName, 'id' => empty($anchorId) ? base64_encode($anchorName) : $anchorId);
 }
Beispiel #2
0
 /**
  * Load Google Fonts
  * @param \Render\APIs\APIv1\CSSAPI $api
  * @param \Render\Unit $unit
  * @param \Render\ModuleInfo $moduleInfo
  * @return string
  */
 public function htmlHeadUnit($api, $unit, $moduleInfo)
 {
     $fonts = array();
     $googleFontFormValue = $api->getFormValue($unit, 'cssFontFamilyGoogle');
     foreach ($googleFontFormValue as $res => $font) {
         if ($res === 'type') {
             continue;
         }
         if ($font != '' && !in_array($font, self::$googleFonts)) {
             array_push(self::$googleFonts, $font);
             $fonts[] = '<link href="https://fonts.googleapis.com/css?family=' . htmlspecialchars(urlencode($font)) . ':100,200,300,400,500,600,700,800,900,100italic,200italic,300italic,400italic,500italic,600italic,700italic,800italic,900italic" data-font-name="' . htmlspecialchars($font) . '" rel="stylesheet">';
         }
     }
     return implode("\n", $fonts);
 }
 /**
  * @param \Render\APIs\APIv1\CSSAPI $api
  * @param \Render\Unit $unit
  * @param \Render\ModuleInfo $moduleInfo
  * @return string
  */
 protected function htmlHeadUnit($api, $unit, $moduleInfo)
 {
     $parentUnit = $api->getParentUnit($unit);
     // enable animation only if this extension unit is a direct child of default unit
     if (!$api->getModuleInfo($parentUnit)->isExtension()) {
         $selector = '#' . $parentUnit->getId();
         return "<script>window.rz_style_animation_scroll.push('" . $selector . "');</script>";
     } else {
         if ($api->isEditMode()) {
             $i18n = new Translator($api, $moduleInfo);
             $msg = $i18n->translate('error.insideExtensionModule');
             return '<script>alert("' . addslashes($msg) . '");</script>';
         }
     }
 }
Beispiel #4
0
 /**
  * Content for the <head> area of the website
  * @param \Render\APIs\APIv1\CSSAPI $api
  * @param \Render\Unit $unit
  * @param \Render\ModuleInfo $moduleInfo
  * @return string
  */
 public function htmlHeadUnit($api, $unit, $moduleInfo)
 {
     // TODO: allow this module only once!
     $ogTitle = new HtmlTagBuilder('meta', array('property' => 'og:title', 'content' => $api->getFormValue($unit, 'ogTitle')));
     $ogType = new HtmlTagBuilder('meta', array('property' => 'og:type', 'content' => $api->getFormValue($unit, 'ogType')));
     $url = $api->getFormValue($unit, 'ogUrl');
     $ogUrl = new HtmlTagBuilder('meta', array('property' => 'og:url', 'content' => $api->getFormValue($unit, 'ogUrl')));
     $ogImageStr = '';
     try {
         $mediaItem = $api->getMediaItem($api->getFormValue($unit, 'ogImage'));
         $imgUrl = $mediaItem->getUrl();
         $absoluteImgUrl = $_SERVER['REQUEST_SCHEME'] . '://' . $_SERVER['HTTP_HOST'] . $imgUrl;
         $ogImage = new HtmlTagBuilder('meta', array('property' => 'og:image', 'content' => $absoluteImgUrl));
         $ogImageStr = $ogImage->toString();
     } catch (\Exception $ignore) {
     }
     $ogDesc = new HtmlTagBuilder('meta', array('property' => 'og:description', 'content' => $api->getFormValue($unit, 'ogDesc')));
     return $ogTitle->toString() . $ogType->toString() . $ogUrl->toString() . $ogImageStr . $ogDesc->toString();
 }
Beispiel #5
0
 /**
  * Inserts the code for the favicon (as well as touch icons)
  * @param \Render\APIs\APIv1\CSSAPI $api
  * @param \Render\Unit $unit
  */
 private function insertFavicon($api, $unit)
 {
     $favicon = $api->getFormValue($unit, 'favicon');
     $appleTouchIcon = $api->getFormValue($unit, 'appleTouchIcon');
     if ($favicon) {
         try {
             echo HtmlTagBuilder::link()->set(array('rel' => 'shortcut icon', 'href' => $api->getMediaItem($favicon)->getUrl(), 'type' => 'image/x-icon'));
         } catch (\Exception $e) {
         }
     }
     if ($appleTouchIcon) {
         try {
             $touchIcon = $api->getMediaItem($appleTouchIcon)->getImage();
             $touchIcon->resizeScale(144, 144);
             $touchIconUrl = $touchIcon->getUrl();
             echo HtmlTagBuilder::link()->set(array('rel' => 'apple-touch-icon', 'href' => $touchIconUrl));
             echo HtmlTagBuilder::link()->set(array('rel' => 'icon', 'href' => $touchIconUrl));
         } catch (\Exception $e) {
         }
     }
 }
Beispiel #6
0
 /**
  * Compile CSS using absurd.js (wrapped in dyncss.js)
  * @param array $moduleCssData
  * @param $jsonTree
  * @param $formValues
  * @param \Render\APIs\APIv1\CSSAPI $api
  * @return string
  */
 public function compile($moduleCssData, $jsonTree, $formValues, $api)
 {
     $vm = $this->getVM();
     // data
     $vm->jsonTree = $jsonTree;
     $vm->resolutions = $api->getResolutions();
     $vm->isEditMode = $api->isEditMode();
     // functions
     $compiledCss = '';
     $vm->callback = function ($result) use(&$compiledCss) {
         $compiledCss = $result;
     };
     $vm->getFormValues = function ($unitId) use(&$formValues) {
         if (isset($formValues[$unitId])) {
             return $formValues[$unitId];
         }
         return array();
     };
     $vm->getColorById = function ($colorId) use(&$api) {
         $color = $api->getColorById($colorId);
         return $color;
     };
     $vm->getImageUrl = function ($mediaId, $width, $quality) use(&$api) {
         if (!$mediaId || $mediaId === 'null') {
             return null;
         }
         try {
             $mediaItem = $api->getMediaItem($mediaId);
         } catch (\Exception $e) {
             // media item not found
             return null;
         }
         try {
             $img = $mediaItem->getImage();
             if ($width > 0) {
                 $img->resizeScale($width);
             }
             if (is_numeric($quality) && !is_nan($quality)) {
                 $img->setQuality($quality);
             }
             return $img->getUrl();
         } catch (\Exception $e) {
             // use just the url (svg for example)
             return $mediaItem->getUrl();
         }
     };
     $vm->getMediaUrl = function ($mediaId, $download = false) use(&$api) {
         if (!$mediaId || $mediaId === 'null') {
             return null;
         }
         try {
             $mediaItem = $api->getMediaItem($mediaId);
             if ($download) {
                 return $mediaItem->getDownloadUrl();
             } else {
                 return $mediaItem->getUrl();
             }
         } catch (\Exception $e) {
             return null;
         }
     };
     // run module code (only once per file)
     foreach ($moduleCssData as $data) {
         $path = $data['path'];
         if (!isset($this->loadedPlugins[$path])) {
             $this->loadedPlugins[$path] = true;
             $vm->executeString(file_get_contents($path), $path, \V8Js::FLAG_FORCE_ARRAY);
         }
     }
     // run dyncss compiler
     $dynCssBackendJsPath = $this->basePath . 'dyncssBackend.js';
     $vm->executeString(file_get_contents($dynCssBackendJsPath), $dynCssBackendJsPath, \V8Js::FLAG_FORCE_ARRAY);
     return $compiledCss;
 }
Beispiel #7
0
 /**
  * Returns all parent unit Ids until root is reached (including root)
  * @param \Render\APIs\APIv1\CSSAPI $api
  * @param \Render\Unit $unit
  * @return array
  */
 private function getAllParentUnitIds($api, $unit)
 {
     $unitIdPath = array();
     do {
         $unitIdPath[] = $unit->getId();
     } while ($unit = $api->getParentUnit($unit));
     return array_reverse($unitIdPath);
 }
Beispiel #8
0
 /**
  * Converts flat unitData into a tree (which only includes the extension children, but at any depth)
  * @param \Render\APIs\APIv1\CSSAPI $api
  * @param $unitData
  * @param string $unitId
  *
  * @return array
  */
 private function buildUnitTree($api, $unitData, $unitId)
 {
     // map data in newly create tree
     $tree = array();
     $data = $unitData[$unitId]['dyncss'];
     $tree[$unitId]['data'] = $data;
     // children (only extension modules, but at any nesting level)
     foreach ($api->getChildren($api->getUnitById($unitId)) as $child) {
         $childId = $child->getId();
         if ($unitData[$childId]['dyncss']['isExtension']) {
             $tree[$unitId]['children'][] = $this->buildUnitTree($api, $unitData, $childId);
         }
     }
     return $tree;
 }
Beispiel #9
0
 /**
  * Output content for HTML head
  * @param \Render\APIs\APIv1\CSSAPI $api
  * @param \Render\Unit $unit
  * @param \Render\ModuleInfo $moduleInfo
  * @return string
  */
 public function htmlHeadUnit($api, $unit, $moduleInfo)
 {
     return $api->getFormValue($unit, 'headCode');
 }
Beispiel #10
0
 /**
  * @param AbstractVisitor $renderingVisitor
  * @param NodeTree        $nodeTree
  * @param RenderContext   $renderContext
  */
 public function __construct(AbstractVisitor $renderingVisitor, NodeTree $nodeTree, RenderContext $renderContext)
 {
     parent::__construct($nodeTree, $renderContext);
     $this->renderingVisitor = $renderingVisitor;
 }