Example #1
0
 /**
  * Initialize Smarty
  *
  * @param Project $project
  * @param Theme $theme
  * @return Smarty
  * @throws TempNotFoundError
  * @throws \SmartyException
  */
 public static function &initSmarty(Project &$project, Theme $theme)
 {
     if (self::$smarty === false) {
         self::$smarty = new Smarty();
         $temp_path = $project->getTempPath();
         if (is_dir($temp_path)) {
             self::$smarty->setCompileDir($temp_path);
         } else {
             throw new TempNotFoundError($temp_path);
         }
         self::$smarty->setTemplateDir($theme->getPath() . '/templates');
         self::$smarty->compile_check = true;
         self::$smarty->left_delimiter = '<{';
         self::$smarty->right_delimiter = '}>';
         self::$smarty->registerFilter('variable', '\\ActiveCollab\\Shade::clean');
         // {$foo nofilter}
         $helper_class = new ReflectionClass('\\ActiveCollab\\Shade\\SmartyHelpers');
         foreach ($helper_class->getMethods(ReflectionMethod::IS_STATIC | ReflectionMethod::IS_PUBLIC) as $method) {
             $method_name = $method->getName();
             if (substr($method_name, 0, 6) === 'block_') {
                 self::$smarty->registerPlugin('block', substr($method_name, 6), ['\\ActiveCollab\\Shade\\SmartyHelpers', $method_name]);
             } elseif (substr($method_name, 0, 9) === 'function_') {
                 self::$smarty->registerPlugin('function', substr($method_name, 9), ['\\ActiveCollab\\Shade\\SmartyHelpers', $method_name]);
             }
         }
         SmartyHelpers::setDefaultLocale($project->getDefaultLocale());
         self::$smarty->assign(['project' => $project, 'default_locale' => $project->getDefaultLocale(), 'copyright' => $project->getConfigurationOption('copyright', '--UNKNOWN--'), 'copyright_since' => $project->getConfigurationOption('copyright_since'), 'page_level' => 0, 'plugins' => self::getPlugins($project)]);
     }
     return self::$smarty;
 }
Example #2
0
 /**
  * Render body of a given element
  *
  * @return string
  * @throws Exception
  */
 public function renderBody()
 {
     $smarty =& Shade::getSmarty();
     $template = $smarty->createTemplate($this->getIndexFilePath());
     SmartyHelpers::setCurrentElement($this);
     if ($this instanceof Element) {
         SmartyHelpers::setCurrentProject($this->getProject());
     } elseif ($this instanceof Project) {
         SmartyHelpers::setCurrentProject($this);
     }
     $content = $template->fetch();
     SmartyHelpers::resetCurrentElementAndProject();
     $separator_pos = strpos($content, $this->properties_separator);
     if ($separator_pos === false) {
         if (substr($content, 0, 1) == '*') {
             $content = '*Content Not Provided*';
         }
     } else {
         $content = trim(substr($content, $separator_pos + strlen($this->properties_separator)));
     }
     return Shade::markdownToHtml($content);
 }
Example #3
0
 /**
  * @param InputInterface  $input
  * @param OutputInterface $output
  * @return void
  */
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     ini_set('date.timezone', 'UTC');
     $project = new Project(getcwd());
     if ($project->isValid()) {
         $target_path = $this->getBuildTarget($input, $project);
         $theme = $this->getTheme($input, $project);
         if (!$this->isValidTargetPath($target_path)) {
             $output->writeln("Build target '{$target_path}' not found or not writable");
             return;
         }
         if (!$theme instanceof Theme) {
             $output->writeln("Theme not found");
             return;
         }
         $this->smarty =& Shade::initSmarty($project, $theme);
         $this->prepareTargetPath($input, $output, $project, $target_path, $theme);
         foreach ($project->getLocales() as $locale => $locale_name) {
             Shade\SmartyHelpers::setCurrentLocale($locale);
             $this->smarty->assign('current_locale', $locale);
             foreach (['buildLandingPage', 'buildWhatsNew', 'buildReleaseNotes', 'buildBooks', 'buildVideos'] as $build_step) {
                 try {
                     if (!$this->{$build_step}($input, $output, $project, $target_path, $theme, $locale)) {
                         $output->writeln("Build process failed at step '{$build_step}'. Aborting...");
                         return;
                     }
                 } catch (Exception $e) {
                     $output->writeln('Exception: ' . $e->getMessage());
                     $output->writeln($e->getTraceAsString());
                 }
             }
         }
     } else {
         $output->writeln('<error>This is not a valid Shade project</error>');
     }
 }