/** * 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; }
/** * @param string|null $locale * @return Release[] */ function getReleases($locale = null) { if (empty($locale)) { $locale = $this->project->getDefaultLocale(); } $files = call_user_func($this->finders['findReleaseFiles'], $this->getReleasesPath($locale), $locale); $result = []; foreach ($files as $version_number => $file) { $release = new Release($this->project, $version_number, $file, true); if ($release->isLoaded()) { $result[$release->getVersionNumber()] = $release; } } return $result; }
/** * @param InputInterface $input * @param OutputInterface $output * @return void */ protected function execute(InputInterface $input, OutputInterface $output) { $project = new Project(getcwd()); if ($project->isValid()) { $default_locale = $project->getDefaultLocale(); $table = new Table($output); $table->setHeaders(['Code', 'Name', 'Is Default?']); foreach ($project->getLocales() as $code => $name) { $table->addRow([$code, $name, $code === $default_locale ? 'Yes' : 'No']); } $table->render(); } else { $output->writeln('<error>This is not a valid Shade project</error>'); } }
/** * Build videos * * @param InputInterface $input * @param OutputInterface $output * @param Project $project * @param string $target_path * @param Theme $theme * @param string $locale * @return bool * @throws Exception * @throws \SmartyException */ public function buildVideos(InputInterface $input, OutputInterface $output, Project $project, $target_path, Theme $theme, $locale) { $videos_path = $locale === $project->getDefaultLocale() ? "{$target_path}/videos" : "{$target_path}/{$locale}/videos"; Shade::createDir($videos_path, function ($path) use(&$output) { $output->writeln("Directory '{$path}' created"); }); if (is_dir($project->getFinder()->getVideosPath($locale) . '/images')) { $video_images_path = $locale === $project->getDefaultLocale() ? "{$target_path}/assets/images/videos" : "{$target_path}/assets/images/{$locale}/videos"; Shade::createDir($video_images_path, function ($path) use(&$output) { $output->writeln("Directory '{$path}' created"); }); Shade::copyDir($project->getFinder()->getVideosPath($locale) . '/images', $video_images_path, null, function ($path) use(&$output) { $output->writeln("{$path} copied"); }); } $videos = $project->getVideos(); if (!$videos->count()) { return true; // Skip video section rendering } $video_groups = $project->getVideoGroups(); $this->smarty->assign(['video_groups' => $video_groups, 'videos' => $videos, 'page_level' => 1, 'video_player' => $project->getVideoPlayer(), 'current_video' => $this->getCurrentVideo($video_groups, $videos), 'current_section' => 'videos']); Shade::writeFile("{$videos_path}/index.html", $this->smarty->fetch('videos.tpl'), function ($path) use(&$output) { $output->writeln("File '{$path}' created"); }); foreach ($videos as $video) { $this->smarty->assign(['current_video' => $video]); Shade::writeFile("{$videos_path}/" . $video->getSlug() . ".html", $this->smarty->fetch('videos.tpl'), function ($path) use(&$output) { $output->writeln("File '{$path}' created"); }); } return true; }