public function action_docs() { $module = $this->request->param('module'); $page = $this->request->param('page'); // Trim trailing slash $page = rtrim($page, '/'); // If no module provided in the url, show the user guide index page, which lists the modules. if (!$module) { return $this->index(); } // If this module's userguide pages are disabled, show the error page if (!Kohana::$config->load('userguide.modules.' . $module . '.enabled')) { return $this->error('That module doesn\'t exist, or has userguide pages disabled.'); } // Prevent "guide/module" and "guide/module/index" from having duplicate content if ($page == 'index') { return $this->error('Userguide page not found'); } // If a module is set, but no page was provided in the url, show the index page if (!$page) { $page = 'index'; } // Find the markdown file for this page $file = $this->file($module . '/' . $page); // If it's not found, show the error page if (!$file) { return $this->error('Userguide page not found'); } // Namespace the markdown parser Kodoc_Markdown::$base_url = URL::site($this->guide->uri()) . '/' . $module . '/'; Kodoc_Markdown::$image_url = URL::site($this->media->uri()) . '/' . $module . '/'; // Set the page title $this->template->title = $page == 'index' ? Kohana::$config->load('userguide.modules.' . $module . '.name') : $this->title($page); // Parse the page contents into the template Kodoc_Markdown::$show_toc = TRUE; $this->template->content = Kodoc_Markdown::markdown(file_get_contents($file)); Kodoc_Markdown::$show_toc = FALSE; // Attach this module's menu to the template $this->template->menu = Kodoc_Markdown::markdown($this->_get_all_menu_markdown()); // Bind the breadcrumb $this->template->bind('breadcrumb', $breadcrumb); // Bind the copyright $this->template->copyright = Kohana::$config->load('userguide.modules.' . $module . '.copyright'); // Add the breadcrumb trail $breadcrumb = array(); $breadcrumb[$this->guide->uri()] = 'User Guide'; $breadcrumb[$this->guide->uri(array('module' => $module))] = Kohana::$config->load('userguide.modules.' . $module . '.name'); // TODO try and get parent category names (from menu). Regex magic or javascript dom stuff perhaps? // Only add the current page title to breadcrumbs if it isn't the index, otherwise we get repeats. if ($page != 'index') { $breadcrumb[] = $this->template->title; } }
public function action_docs() { $module = $this->request->param('module'); $page = $this->request->param('page'); // Trim trailing slash $page = rtrim($page, '/'); // If no module provided in the url, show the user guide index page, which lists the modules. if (!$module) { return $this->index(); } // If this module's userguide pages are disabled, show the error page if (!Kohana::$config->load('userguide.modules.' . $module . '.enabled')) { return $this->error(__('That module doesn\'t exist, or has userguide pages disabled.')); } // Prevent "guide/module" and "guide/module/index" from having duplicate content if ($page == 'index') { return $this->error(__('Userguide page not found')); } // If a module is set, but no page was provided in the url, show the index page if (!$page) { $page = 'index'; } // Find the markdown file for this page $file = $this->file($module . '/' . $page); // If it's not found, show the error page if (!$file) { return $this->error(__('Userguide page not found')); } // Namespace the markdown parser Kodoc_Markdown::$base_url = URL::site($this->guide->uri()) . '/' . $module . '/'; Kodoc_Markdown::$image_url = URL::site($this->media->uri()) . '/' . $module . '/'; // Set the page title $this->template->title = $page == 'index' ? Kohana::$config->load('userguide.modules.' . $module . '.name') : $this->title($page); // Parse the page contents into the template Kodoc_Markdown::$show_toc = true; $this->template->content = Markdown(file_get_contents($file)); Kodoc_Markdown::$show_toc = false; // Attach this module's menu to the template $this->template->menu = View::factory('userguide/doc/menu')->set('menu', Markdown($this->_get_all_menu_markdown())); // Bind the copyright $this->template->copyright = Kohana::$config->load('userguide.modules.' . $module . '.copyright'); // Add the breadcrumb trail $this->breadcrumbs->add(__('User Guide'), $this->guide->uri())->add(Kohana::$config->load('userguide.modules.' . $module . '.name'), $this->guide->uri(array('module' => $module))); }