/** * 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(); }
/** * 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) { } } }
/** * 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; }