public function preferencesAction()
 {
     $title = _T('Preferences');
     $path = DirectoryHelper::slashDirname(FrontController::DOCBOOK_ASSETS) . 'USER_PREFERENCES.md';
     $page_infos = array('name' => 'USER_PREFERENCES.md', 'path' => 'prefs', 'update' => Helper::getDateTimeFromTimestamp(filemtime($path)));
     $tpl_params = array('breadcrumbs' => array($title), 'title' => $title, 'page' => $page_infos, 'page_tools' => 'false');
     $file_content = file_get_contents($path);
     $md_parser = $this->docbook->getMarkdownParser();
     $md_content = $md_parser->transformString($file_content);
     $output_bag = $md_parser->get('OutputFormatBag');
     $menu = $output_bag->getHelper()->getToc($md_content, $output_bag->getFormatter());
     $content = $this->docbook->display($md_content->getBody(), 'admin_panel', array('page' => $page_infos, 'page_tools' => 'false', 'page_title' => 'true', 'page_notes' => $md_content->getNotesToString(), 'title' => $title, 'toc' => $menu, 'config' => $this->docbook->getRegistry()->getConfigs()));
     return array('default', $content, $tpl_params);
 }
 /**
  * Build a hierarchical menu
  *
  * @param object $content \MarkdownExtended\API\ContentInterface
  * @param object $formatter \MarkdownExtended\API\OutputFormatInterface
  *
  * @return string
  */
 public function getToc(ContentInterface $md_content, OutputFormatInterface $formatter, array $attributes = null)
 {
     $cfg_toc_max_level = $this->getConfigOrDefault('toc_max_level');
     $cfg_toc_title = $this->getConfigOrDefault('toc_title');
     $cfg_toc_title_level = $this->getConfigOrDefault('toc_title_level');
     $cfg_toc_id = $this->getConfigOrDefault('toc_id');
     $cfg_toc_class = $this->getConfigOrDefault('toc_class');
     $cfg_toc_item_title = $this->getConfigOrDefault('toc_item_title');
     $menu = $md_content->getMenu();
     $content = $list_content = '';
     $max_level = isset($attributes['max_level']) ? $attributes['max_level'] : $cfg_toc_max_level;
     if (!empty($menu) && count($menu) > 1) {
         $depth = 0;
         $current_level = null;
         foreach ($menu as $item_id => $menu_item) {
             $_item_id = Helper::getSafeIdString($item_id);
             if (isset($max_level) && $menu_item['level'] > $max_level) {
                 continue;
             }
             $diff = $menu_item['level'] - (is_null($current_level) ? $menu_item['level'] : $current_level);
             if ($diff > 0) {
                 $list_content .= str_repeat('<ul><li>', $diff);
             } elseif ($diff < 0) {
                 $list_content .= str_repeat('</li></ul></li>', -$diff);
                 $list_content .= '<li>';
             } else {
                 if (!is_null($current_level)) {
                     $list_content .= '</li>';
                 }
                 $list_content .= '<li>';
             }
             $depth += $diff;
             $list_content .= $formatter->buildTag('link', $menu_item['text'], array('href' => '#' . $_item_id, 'title' => isset($attributes['toc_item_title']) ? $attributes['toc_item_title'] : $cfg_toc_item_title));
             $current_level = $menu_item['level'];
         }
         if ($depth != 0) {
             $list_content .= str_repeat('</ul></li>', $depth);
         }
         $content .= $formatter->buildTag('title', $cfg_toc_title, array('level' => isset($attributes['toc_title_level']) ? $attributes['toc_title_level'] : $cfg_toc_title_level, 'id' => isset($attributes['toc_id']) ? $attributes['toc_id'] : $cfg_toc_id, 'no-addon' => true));
         $content .= $formatter->buildTag('unordered_list', $list_content, array('class' => isset($attributes['class']) ? $attributes['class'] : $cfg_toc_class));
     }
     return $content;
 }
Example #3
0
 public function buildTitle($text, array $attributes = array())
 {
     if (!isset($attributes['id']) || empty($attributes['id'])) {
         $attributes['id'] = uniqid();
     } else {
         $attributes['id'] = Helper::getSafeIdString($attributes['id']);
     }
     if (!isset($attributes['name']) || empty($attributes['name'])) {
         $attributes['name'] = $attributes['id'];
     }
     if (isset($attributes['level'])) {
         $tag = 'h' . $attributes['level'];
         unset($attributes['level']);
     } else {
         $tag = 'h' . MarkdownExtended::getVar('baseheaderlevel');
     }
     if (!isset($attributes['no-addon']) || $attributes['no-addon'] !== true) {
         $text = $this->addTitleAddon($text, $attributes);
     }
     if (isset($attributes['no-addon'])) {
         unset($attributes['no-addon']);
     }
     $_ttl = $this->getTagString($text, $tag, $attributes);
     return $_ttl;
 }
 public function searchAction($path)
 {
     $this->setPath($path);
     $search = $this->docbook->getRequest()->getArgument('s');
     if (empty($search)) {
         return $this->indexAction($path);
     }
     $_s = Helper::processDocBookSearch($search, $this->getPath());
     $title = _T('Search for "%search_str%"', array('search_str' => $search));
     $breadcrumbs = Helper::getBreadcrumbs($this->getPath());
     $breadcrumbs[] = $title;
     $dbfile = new DocBookFile($this->getpath());
     $page = $dbfile->getDocBookStack();
     $page['type'] = 'search';
     $tpl_params = array('page' => $page, 'breadcrumbs' => $breadcrumbs, 'title' => $title);
     $search_content = $this->docbook->display($_s, 'search', array('search_str' => $search, 'path' => Helper::buildPageTitle($this->getPath())));
     return array('default', $search_content, $tpl_params);
 }
Example #5
0
 /**
  * Find previous file in current chapter
  *
  * @return array
  */
 public function findPrevious()
 {
     if (!isset($this->cache['docbook_previous'])) {
         $this->cache['docbook_previous'] = null;
         $filepath = $this->getPathname();
         if ($this->isLink() || $this->isRootLink()) {
             $filepath = DirectoryHelper::slashDirname($this->getWebPath()) . $this->getFilename();
         }
         $dir_realpath = dirname(realpath($filepath));
         $dir_targetpath = dirname($filepath);
         if (empty($dir_realpath)) {
             $dir_realpath = $dir_targetpath;
         }
         $dir = new FilesystemIterator($dir_realpath, FilesystemIterator::CURRENT_AS_PATHNAME);
         $dir_table = iterator_to_array($dir, false);
         $i = array_search($this->getRealPath(), $dir_table);
         if (false !== $i) {
             $j = $i - 1;
             while ($j >= 0 && array_key_exists($j, $dir_table) && (is_dir($dir_table[$j]) && !Helper::isDirValid($dir_table[$j]) || !Helper::isFileValid($dir_table[$j]) || DirectoryHelper::isDotPath($dir_table[$j]) || Helper::isTranslationFile($dir_table[$j]))) {
                 $j = $j - 1;
             }
             if ($j >= 0 && array_key_exists($j, $dir_table) && (is_dir($dir_table[$j]) && Helper::isDirValid($dir_table[$j]) || !is_dir($dir_table[$j]) && Helper::isFileValid($dir_table[$j]) && !Helper::isTranslationFile($dir_table[$j])) && !DirectoryHelper::isDotPath($dir_table[$j])) {
                 $previous = new DocBookFile($dir_table[$j]);
                 $this->cache['docbook_previous'] = $previous->getDocBookStack();
             }
         }
     }
     return $this->cache['docbook_previous'];
 }
 public function getChapters()
 {
     $www_http = $this->getPath('base_dir_http');
     $dir = new DocBookRecursiveDirectoryIterator($www_http);
     $paths = array();
     foreach ($dir as $file) {
         if ($file->isDir()) {
             $paths[] = array('path' => Helper::getSecuredRealpath($file->getRealPath()), 'route' => Helper::getRoute($file->getDocBookPath()), 'name' => $file->getHumanReadableFilename());
         }
     }
     return $paths;
 }
 public static function dirValidation($file_path)
 {
     return Helper::isDirValid($file_path);
     $name = basename($file_path);
     return $name !== FrontController::DOCBOOK_ASSETS;
 }