Пример #1
0
 /**
  * Returns the path to the template file.
  *
  * The file locator is used to locate the template when the naming convention
  * is the symfony one (i.e. the name can be parsed).
  * Otherwise the template is located using the locator from the twig library.
  *
  * @param string|TemplateReferenceInterface $template The template
  *
  * @throws \Twig_Error_Loader if the template could not be found
  *
  * @return string The path to the template file
  */
 protected function findTemplate($template)
 {
     $logicalName = (string) $template;
     if (isset($this->cache[$logicalName])) {
         return $this->cache[$logicalName];
     }
     $file = null;
     $previous = null;
     try {
         $template = $this->parser->parse($template);
         try {
             $file = $this->locator->locate($template);
         } catch (\InvalidArgumentException $e) {
             $previous = $e;
         }
     } catch (\Exception $e) {
         try {
             $file = parent::findTemplate($template);
         } catch (\Twig_Error_Loader $e) {
             $previous = $e;
         }
     }
     if (false === $file || null === $file) {
         throw new \Twig_Error_Loader(sprintf('Unable to find template "%s".', $logicalName), -1, null, $previous);
     }
     return $this->cache[$logicalName] = $file;
 }
Пример #2
0
 /**
  * Returns true if this class is able to render the given template.
  *
  * @param string $name A template name
  *
  * @return boolean True if this class supports the given resource, false otherwise
  */
 public function supports($name)
 {
     if ($name instanceof \Twig_Template) {
         return true;
     }
     $template = $this->parser->parse($name);
     return 'twig' === $template->get('engine');
 }
Пример #3
0
 /**
  * Parsing the News tags.
  *
  * @global type $_ARRAYLANG
  * @param type $objTpl
  * @param type $newsId
  */
 public function parseNewsTags($objTpl = null, $newsId = null, $block = 'newsTagList')
 {
     global $_ARRAYLANG;
     if (!empty($newsId)) {
         $newsTagDetails = $this->getNewsTags($newsId);
         $newsTags = $newsTagDetails['tagList'];
     }
     $tags = $this->getTags(array_keys($newsTags));
     if (empty($tags)) {
         if ($objTpl->blockExists('noTags')) {
             $objTpl->setVariable('TXT_NEWS_NO_TAGS_FOUND', $_ARRAYLANG['TXT_NEWS_NO_TAGS_FOUND']);
             $objTpl->showBlock('noTags');
         }
         return;
     }
     $tagCount = count($tags);
     $currentTagCount = 0;
     if ($objTpl->blockExists($block) && !empty($tags)) {
         foreach ($tags as $tag) {
             ++$currentTagCount;
             $newsLink = \Cx\Core\Routing\Url::fromModuleAndCmd('news', '', FRONTEND_LANG_ID, array('tag' => urlencode($tag)));
             $objTpl->setVariable(array('NEWS_TAG_NAME' => $tag, 'NEWS_TAG_LINK' => '<a class="tags" href="' . $newsLink . '">' . ucfirst($tag) . '</a>' . ($currentTagCount < $tagCount ? ',' : '')));
             $objTpl->parse($block);
         }
         if ($objTpl->blockExists('tagsBlock')) {
             $objTpl->touchBlock('tagsBlock');
         }
     }
 }
Пример #4
0
 /**
  * Generates chapter HTML files.
  */
 protected function generateChapters($langCode, $markdown)
 {
     $this->log("Generating chapters in HTML format for language {$langCode}\n");
     $upperAdContent = null;
     $lowerAdContent = null;
     if ($this->bookProps['google_adsence']['enabled'] == true) {
         if (is_readable($this->bookDir . $this->bookProps['google_adsence']['chapter_upper_ad'])) {
             $upperAdContent = file_get_contents($this->bookDir . $this->bookProps['google_adsence']['chapter_upper_ad']);
         }
         if (is_readable($this->bookDir . $this->bookProps['google_adsence']['chapter_bottom_ad'])) {
             $lowerAdContent = file_get_contents($this->bookDir . $this->bookProps['google_adsence']['chapter_bottom_ad']);
         }
     }
     $this->markdownParser->parse($markdown);
     foreach ($this->markdownParser->warnings as $warning) {
         $this->log('Warning: ' . $warning . "\n");
     }
     $this->warnings = array_merge($this->warnings, $this->markdownParser->warnings);
     $linkCurrentChapter = null;
     $currentChapterTitle = '';
     // Generate an HTML file per chapter
     $outFiles = $this->markdownParser->outFiles;
     foreach ($outFiles as $idx => $outFile) {
         $id = $outFile['id'];
         $isSection = strpos($id, '/') != false;
         $title = $outFile['title'];
         $content = $outFile['content'];
         if (!$isSection) {
             $linkCurrentChapter = $id;
             $currentChapterTitle = $title;
         }
         $linkPrev = null;
         if ($idx > 0) {
             $linkPrev = $outFiles[$idx - 1]['id'];
         }
         $linkNext = null;
         if ($idx < count($outFiles) - 1) {
             $linkNext = $outFiles[$idx + 1]['id'];
         }
         $vars = ['content' => $content, 'linkPrev' => $linkPrev, 'linkNext' => $linkNext, 'linkCurrentChapter' => $isSection ? $linkCurrentChapter : null, 'currentChapterTitle' => $currentChapterTitle, 'upperAdContent' => $upperAdContent, 'lowerAdContent' => $lowerAdContent, 'bookProps' => $this->bookProps, 'langCode' => $langCode, 'dirPrefix' => $isSection ? '../../' : '../', 'langDirPrefix' => $isSection ? '../' : ''];
         $this->phpRenderer->clearVars();
         $content = $this->phpRenderer->render("data/theme/default/layout/chapter.php", $vars);
         $html = $this->renderMainLayout($content, $title, $isSection ? '../../' : '../', $langCode);
         $outFile = $this->outDir . $langCode . '/' . $id;
         $dirName = dirname($outFile);
         if (!is_dir($dirName)) {
             mkdir($dirName, 0775, true);
         }
         $this->log("Generating chapter: {$outFile}\n");
         file_put_contents($outFile, $html);
         $this->siteUrls[] = [$this->bookProps['book_website'] . '/' . $langCode . '/' . $id, 0.5];
     }
     if ($this->validateLinks) {
         // Validate links
         $this->log("Validating links\n");
         foreach ($this->markdownParser->links as $link) {
             $url = $link['url'];
             $chapterId = $link['chapter_id'];
             $errorMsg = '';
             $isValid = $this->linkValidator->validateLink($url, $errorMsg);
             if (!$isValid) {
                 $this->log('Warning:' . $errorMsg . " (in chapter {$chapterId})\n");
                 $this->warnings[] = $errorMsg . " (in chapter {$chapterId})";
             } else {
                 $this->log($errorMsg);
             }
         }
     }
     // Add image files to be copied later
     foreach ($this->markdownParser->images as $fileName) {
         $srcFilePath = $this->bookDir . 'manuscript/' . $langCode . '/' . $fileName;
         $dstFilePath = $this->outDir . $langCode . '/' . $fileName;
         $this->filesToCopy[$srcFilePath] = $dstFilePath;
     }
 }
 /**
  * Modify the content to include subsite links
  * @global array $subsiteDomainIDs
  * @param array $arguments
  * @param string $content
  * @param type $parser
  * @return string links
  */
 public static function link_shortcode_handler($arguments, $content = null, $parser = null)
 {
     if (!isset($arguments['id'])) {
         return;
     }
     $argumentarray = explode('-', $arguments['id']);
     if (count($argumentarray) != 2) {
         return;
     }
     $subsiteid = $argumentarray[0];
     $id = $argumentarray[1];
     $page = null;
     if ($id) {
         $page = DataObject::get_by_id('SiteTree', $id);
         // Get the current page by ID.
         if (!$page) {
             $page = Versioned::get_latest_version('SiteTree', $id);
             // Attempt link to old version.
         }
     } else {
         $page = DataObject::get_one('ErrorPage', '"ErrorPage"."ErrorCode" = \'404\'');
         // Link to 404 page.
     }
     if (!$page) {
         return;
         // There were no suitable matches at all.
     }
     $currentSubsite = Subsite::get()->byID((int) $subsiteid);
     $currenturl = null;
     if ($currentSubsite) {
         if (Director::isDev()) {
             $currenturl = $currentSubsite->DevDomainID ? $currentSubsite->DevDomain() : null;
         }
         if (Director::isTest()) {
             $currenturl = $currentSubsite->TestDomainID ? $currentSubsite->TestDomain() : null;
         }
         if (!$currenturl) {
             $currenturl = $currentSubsite->getPrimarySubsiteDomain();
         }
         $currenturl = $currenturl->getFullProtocol() . $currenturl->Domain;
         // override
         if (Director::isDev() || Director::isTest()) {
             if (defined('DEV_SUBSITE_' . (int) $subsiteid)) {
                 $subsiteurl = 'DEV_SUBSITE_' . (int) $subsiteid;
                 $currenturl = constant($subsiteurl);
             }
         }
     }
     $link = Convert::raw2att($page->Link());
     if ($content) {
         return sprintf('<a href="%s">%s</a>', $currenturl . $link, $parser->parse($content));
     } else {
         return $currenturl . $link;
     }
 }