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