Esempio n. 1
0
 /**
  * Generate 'dynamic' CSS (css which depends on formValues)
  * @param \Render\APIs\RootAPIv1\RootCssAPI|\Render\APIs\RootAPIv1\RootRenderAPI $rootCssApi
  * @param \Render\Unit $rootUnit
  * @param boolean $outputTreeData - weather data required for client side recompile is written or not
  */
 public function generateCSS($rootCssApi, $rootUnit, $outputTreeData)
 {
     $unitData = $rootCssApi->getAllUnitData($rootUnit);
     $globalDataHash = md5(json_encode($rootCssApi->getColorScheme()) . json_encode($rootCssApi->getResolutions()));
     // collect css.js code
     $dynCSSPlugins = array();
     $formValues = array();
     foreach ($unitData as $uid => $data) {
         if (isset($data['dyncss']['formValues'])) {
             $formValues[$uid] = $data['dyncss']['formValues'];
         }
         if ($data['dyncss']['plugin']) {
             $pluginName = $data['dyncss']['plugin']['name'];
             $dynCSSPlugins[$pluginName] = $data['dyncss']['plugin'];
         }
     }
     // create css for each non-extension unit
     foreach ($unitData as $unitId => $singleUnitData) {
         if ($singleUnitData['dyncss']['isExtension']) {
             continue;
         }
         // unit data subtree
         $unitDataTree = $this->buildUnitTree($rootCssApi, $unitData, $unitId);
         // convert to json tree (used by dyncss)
         $cssJsonTree = array();
         $this->buildJsonTree($cssJsonTree, $unitDataTree);
         $cssCode = '';
         // try to get cached value
         $cacheKey = md5(json_encode($unitDataTree) . $globalDataHash . self::CACHE_VERSION);
         $cachedValue = $rootCssApi->getUnitCache($rootCssApi->getUnitById($unitId), 'css');
         if (isset($cachedValue['hash']) && $cachedValue['hash'] === $cacheKey) {
             $cssCode = $cachedValue['cssCode'];
         } else {
             // regenerate css
             try {
                 $cssCode = $this->cssEngine->compile($dynCSSPlugins, $cssJsonTree, $formValues, $rootCssApi);
                 $rootCssApi->setUnitCache($rootCssApi->getUnitById($unitId), 'css', array('hash' => $cacheKey, 'cssCode' => $cssCode));
             } catch (\Exception $e) {
                 $this->addError($e->getMessage());
             }
         }
         if ($outputTreeData) {
             echo '<style data-tree="' . htmlentities(json_encode($cssJsonTree)) . '" class="generatedStyles" id="generatedStyle_' . $unitId . '" data-unit-id="' . $unitId . '">';
             echo $cssCode;
             echo '</style>';
         } else {
             echo $cssCode;
         }
     }
     // load dyncss js module definition for client
     if ($outputTreeData) {
         $pluginUrls = array();
         foreach ($dynCSSPlugins as $data) {
             $pluginUrls[] = $data['url'];
         }
         echo '<script type="application/json" id="dyncss-plugins">' . json_encode($pluginUrls) . '</script>';
     }
 }
Esempio n. 2
0
 /**
  * Title and Description
  * @param \Render\APIs\RootAPIv1\RootRenderAPI $rootApi
  * @param \Render\Unit $rootUnit
  */
 private function insertTitleAndDescription($rootApi, $rootUnit)
 {
     // title
     $nav = $rootApi->getNavigation();
     $currentPage = $nav->getPage($nav->getCurrentPageId());
     $pageTitle = $currentPage->getTitle();
     $title = $rootApi->getFormValue($rootUnit, 'titlePrefix', '') . $pageTitle . $rootApi->getFormValue($rootUnit, 'titleSuffix', '');
     echo HtmlTagBuilder::title($title);
     // description
     $description = $currentPage->getDescription();
     if ($description != '') {
         echo HtmlTagBuilder::meta()->set(array('name' => 'description', 'content' => $description));
     }
 }
 /**
  * @param \Render\APIs\RootAPIv1\RootRenderAPI $api
  * @param \Render\Unit                         $unit
  * @param \Render\ModuleInfo                   $moduleInfo
  */
 public function render($api, $unit, $moduleInfo)
 {
     echo "START-RENDER:" . $unit->getId() . "\n";
     echo "JS-API:" . $api->getJsApiUrl() . "\n";
     echo "CSS-URL:" . $api->getCSSUrl() . "\n";
     echo "START-INSERT-CSS:\n";
     $api->insertCss($unit);
     echo "END-INSERT-CSS:\n";
     echo "START-MODULE-DATA:\n";
     echo json_encode($api->getAllModuleData($unit));
     echo "END-MODULE-DATA:\n";
     echo "START-UNIT-DATA:\n";
     echo json_encode($api->getAllUnitData($unit));
     echo "END-UNIT-DATA:\n";
     echo "ASSET-PATH:" . $moduleInfo->getAssetPath('assetPath') . "\n";
     echo "ASSET-URL:" . $moduleInfo->getAssetUrl('assetUrl') . "\n";
     echo "MEDIA-URL:" . $api->getMediaItem($api->getFormValue($unit, 'download'))->getUrl() . "\n";
     echo "IMAGE-URL:" . $api->getMediaItem($api->getFormValue($unit, 'image'))->getImage()->resizeCenter(100, 100)->getUrl() . "\n";
     try {
         $url = $api->getMediaItem('ITEM-NOT-EXISTS')->getUrl();
     } catch (\Exception $ignore) {
         $url = '#exception';
     }
     echo "NOT-EXISTS-MEDIA-URL:" . $url . "\n";
     $api->renderChildren($unit);
     echo "END-RENDER:" . $unit->getId() . "\n";
 }