/**
  * Creates an html list of all classes sorted by category (or package if no category)
  *
  * @return   string   the html for the menu
  */
 public static function menu()
 {
     $classes = Kodoc::classes();
     ksort($classes);
     $menu = array();
     $route = Route::get('docs/api');
     foreach ($classes as $class) {
         if (Kodoc::is_transparent($class, $classes)) {
             continue;
         }
         $class = Kodoc_Class::factory($class);
         // Test if we should show this class
         if (!Kodoc::show_class($class)) {
             continue;
         }
         $link = HTML::anchor($route->uri(array('class' => $class->class->name)), $class->class->name);
         if (isset($class->tags['package'])) {
             foreach ($class->tags['package'] as $package) {
                 if (isset($class->tags['category'])) {
                     foreach ($class->tags['category'] as $category) {
                         $menu[$package][$category][] = $link;
                     }
                 } else {
                     $menu[$package]['Base'][] = $link;
                 }
             }
         } else {
             $menu['[Unknown]']['Base'][] = $link;
         }
     }
     // Sort the packages
     ksort($menu);
     return View::factory('userguide/api/menu')->bind('menu', $menu);
 }
예제 #2
0
 public function api($package = NULL, $class_name = NULL)
 {
     if ($class_name) {
         // Do we have anything cached?
         if ($this->cache and ($class = $this->cache->get('kodoc_class_' . $class_name)) !== NULL) {
             // Nothing to do, it's cached.
         } else {
             try {
                 $class = Kodoc_Class::factory($class_name);
             } catch (Exception $e) {
                 Event::run('system.404');
             }
             if ($this->cache) {
                 $this->cache->set('kodoc_class_' . $class_name, $class);
             }
         }
         $this->breadcrumb['userguide/api/kohana'] = 'API Reference';
         $this->template->title = $class_name;
         $this->template->content = View::factory('userguide/api/class', array('class' => $class));
         $this->template->menu = View::factory('userguide/api/menu', array('class' => $class));
     } else {
         $this->template->title = 'API Reference';
         $this->template->content = View::factory('userguide/api/toc', array('toc' => Kodoc::packages()));
         $this->template->menu = $this->markdown('kohana/menu');
     }
     $breadcrumb[] = $this->template->title;
 }
예제 #3
0
파일: kodoc.php 프로젝트: ZerGabriel/cms-1
 /**
  * Creates an html list of all classes sorted by category (or package if no category)
  *
  * @return   string   the html for the menu
  */
 public static function menu()
 {
     $menu = Cache::instance()->get('kodocMenu');
     if ($menu !== NULL) {
         return View::factory('userguide/api/menu')->bind('menu', $menu);
     }
     $profiler = Profiler::start('Userguide', 'build menu');
     $classes = Kodoc::classes();
     foreach ($classes as $class) {
         if (isset($classes['kohana_' . $class])) {
             // Remove extended classes
             unset($classes['kohana_' . $class]);
         }
         if (isset($classes['kodicms_' . $class])) {
             // Remove extended classes
             unset($classes['kodicms_' . $class]);
         }
     }
     ksort($classes);
     $menu = array();
     $route = Route::get('docs/api');
     foreach ($classes as $class) {
         $class = Kodoc_Class::factory($class);
         // Test if we should show this class
         if (!Kodoc::show_class($class)) {
             continue;
         }
         $link = HTML::anchor($route->uri(array('class' => $class->class->name)), $class->class->name);
         if (isset($class->tags['package'])) {
             foreach ($class->tags['package'] as $package) {
                 if (isset($class->tags['category'])) {
                     foreach ($class->tags['category'] as $category) {
                         $menu[$package][$category][] = $link;
                     }
                 } else {
                     $menu[$package]['Base'][] = $link;
                 }
             }
         } else {
             $menu['[Unknown]']['Base'][] = $link;
         }
     }
     // Sort the packages
     ksort($menu);
     Cache::instance()->set('kodocMenu', $menu, Date::DAY);
     if (isset($profiler)) {
         Profiler::stop($profiler);
     }
     return View::factory('userguide/api/menu')->bind('menu', $menu);
 }
예제 #4
0
 public function action_api()
 {
     // Enable the missing class autoloader.  If a class cannot be found a
     // fake class will be created that extends Kodoc_Missing
     spl_autoload_register(array('Kodoc_Missing', 'create_class'));
     // Get the class from the request
     $class = $this->request->param('class');
     // If no class was passed to the url, display the API index page
     if (!$class) {
         $this->template->title = 'Table of Contents';
         $this->template->content = View::factory('userguide/api/toc')->set('classes', Kodoc::class_methods())->set('route', $this->request->route());
     } else {
         // Create the Kodoc_Class version of this class.
         $_class = Kodoc_Class::factory($class);
         // If the class requested and the actual class name are different
         // (different case, orm vs ORM, auth vs Auth) redirect
         if ($_class->class->name != $class) {
             $this->redirect($this->request->route()->uri(array('class' => $_class->class->name)));
         }
         // If this classes immediate parent is Kodoc_Missing, then it should 404
         if ($_class->class->getParentClass() and $_class->class->getParentClass()->name == 'Kodoc_Missing') {
             return $this->error('That class was not found. Check your url and make sure that the module with that class is enabled.');
         }
         // If this classes package has been disabled via the config, 404
         if (!Kodoc::show_class($_class)) {
             return $this->error('That class is in package that is hidden.  Check the <code>api_packages</code> config setting.');
         }
         // Everything is fine, display the class.
         $this->template->title = $class;
         $this->template->content = View::factory('userguide/api/class')->set('doc', $_class)->set('route', $this->request->route());
     }
     // Attach the menu to the template
     $this->template->menu = Kodoc::menu();
     // Bind the breadcrumb
     $this->template->bind('breadcrumb', $breadcrumb);
     // Add the breadcrumb
     $breadcrumb = array();
     $breadcrumb[$this->guide->uri(array('page' => NULL))] = 'User Guide';
     $breadcrumb[$this->request->route()->uri()] = 'API Browser';
     $breadcrumb[] = $this->template->title;
 }
예제 #5
0
 public function action_api()
 {
     // Enable the missing class autoloader
     spl_autoload_register(array('Kodoc_Missing', 'create_class'));
     // Get the class from the request
     $class = $this->request->param('class');
     if ($class) {
         try {
             $_class = Kodoc_Class::factory($class);
             if (!Kodoc::show_class($_class)) {
                 throw new Exception(__('That class is hidden'));
             }
         } catch (Exception $e) {
             return $this->error(__('API Reference: Class not found.'));
         }
         $this->template->title = $class;
         $this->template->content = View::factory('userguide/api/class')->set('doc', Kodoc::factory($class))->set('route', $this->request->route);
     } else {
         $this->template->title = __('Table of Contents');
         $this->template->content = View::factory('userguide/api/toc')->set('classes', Kodoc::class_methods())->set('route', $this->request->route);
     }
     // Attach the menu to the template
     $this->template->menu = Kodoc::menu();
     // Bind the breadcrumb
     $this->template->bind('breadcrumb', $breadcrumb);
     // Get the docs URI
     $guide = Route::get('docs/guide');
     // Add the breadcrumb
     $breadcrumb = array();
     $breadcrumb[$this->guide->uri(array('page' => NULL))] = __('User Guide');
     $breadcrumb[$this->request->route->uri()] = $this->title('api');
     $breadcrumb[] = $this->template->title;
 }
예제 #6
0
 public function action_index()
 {
     $msg = array();
     $exclude_class = array_map('strtolower', Kohana::config('cs.exclude_class'));
     // arrays of different mask types and precise names
     $prec = array();
     // like 'someword'
     $ast_left = array();
     // like '*someword'
     $ast_right = array();
     // like 'someword*'
     $two_ast = array();
     // like '*someword*'
     foreach ($exclude_class as $mask) {
         if (strpos($mask, '*') === 0 and strrpos($mask, '*') === strlen($mask) - 1) {
             // any occurrence
             $two_ast[] = substr($mask, 1, -1);
         } elseif (strpos($mask, '*') === 0) {
             // masked as '*someword'
             $ast_left[] = substr($mask, 1);
         } elseif (strrpos($mask, '*') === strlen($mask) - 1) {
             // masked as 'someword*'
             $ast_right[] = substr($mask, 0, -1);
         } else {
             $prec[] = $mask;
         }
     }
     $classes = Kodoc::classes();
     // remove excluded classes from list
     foreach ($classes as $class) {
         if (isset($classes['kohana_' . $class])) {
             unset($classes['kohana_' . $class]);
         }
         // exclude classes that have names set precisely
         if (in_array(strtolower($class), $prec)) {
             unset($classes[$class]);
             continue;
         }
         $is_class_unset = FALSE;
         // exclude classes that have names set by mask of type '*someword*'
         foreach ($two_ast as $mask) {
             if (strpos(strtolower($class), $mask) !== FALSE) {
                 unset($classes[$class]);
                 $is_class_unset = TRUE;
                 break;
             }
         }
         if ($is_class_unset) {
             continue;
         }
         // exclude classes that have names set by mask of type '*someword'
         foreach ($ast_left as $mask) {
             if (substr(strtolower($class), -strlen($mask)) == $mask) {
                 unset($classes[$class]);
                 $is_class_unset = TRUE;
                 break;
             }
         }
         if ($is_class_unset) {
             continue;
         }
         // exclude classes that have names set by mask of type 'someword*'
         foreach ($ast_right as $mask) {
             if (strpos(strtolower($class), $mask) === 0) {
                 unset($classes[$class]);
                 break;
             }
         }
     }
     $is_cache = Kohana::config('cs.cache');
     // do we need to save actual state in cache
     $is_save_cache = FALSE;
     // check if caching turned on
     if ($is_cache) {
         // check whether classes set + exclude classes set was modified
         $cache_name = sha1(serialize($classes)) . $this->ext;
         $dir = Kohana_Core::$cache_dir . DIRECTORY_SEPARATOR;
         if (!is_dir($dir)) {
             $msg[] = 'No cache directory ' . $dir;
             $is_save_cache = TRUE;
         } else {
             if (is_file($dir . $cache_name)) {
                 $tmp = file_get_contents($dir . $cache_name);
                 if ($tmp) {
                     $classes = unserialize($tmp);
                     $msg[] = 'Data loaded from cache';
                 } else {
                     $is_save_cache = TRUE;
                     // set for data not be taken from cache
                     $msg[] = 'Failed to load cache';
                 }
             } else {
                 $is_save_cache = TRUE;
                 foreach (glob($dir . '*' . $this->ext) as $filename) {
                     if (!unlink($filename)) {
                         $msg[] = 'Can not delete cache file ' . $filename;
                     }
                 }
             }
         }
     }
     if (!$is_cache or $is_save_cache) {
         foreach ($classes as $class) {
             $r_class = Kodoc_Class::factory($class);
             // to prevent exception when Kodoc::properties() throws exception
             try {
                 $props = $r_class->properties();
             } catch (Kohana_Exception $e) {
                 $props = array();
                 $msg[] = $e->getMessage();
             }
             $classes[$class] = array('description' => $r_class->description, 'modifiers' => $r_class->modifiers, 'properties' => $props, 'methods' => $r_class->methods());
         }
         if ($is_save_cache) {
             if (is_dir($dir) and is_writable($dir)) {
                 if (!file_put_contents($dir . $cache_name, serialize($classes))) {
                     $msg[] = 'Failed to save cache';
                 }
             } else {
                 $msg[] = 'Not exsisting or not writable cache dir';
             }
         }
     }
     $this->template->content = $classes;
     $this->template->msg = $msg;
 }