Exemplo n.º 1
0
 public function add_menu_pages()
 {
     global $_registered_pages;
     $menu_position = 12;
     $menu_position = apply_filters('mvc_menu_position', $menu_position);
     $admin_pages = MvcConfiguration::get('AdminPages');
     foreach ($this->admin_controller_names as $controller_name) {
         if (isset($admin_pages[$controller_name])) {
             if (empty($admin_pages[$controller_name]) || !$admin_pages[$controller_name]) {
                 continue;
             }
             $pages = $admin_pages[$controller_name];
         } else {
             $pages = null;
         }
         $processed_pages = $this->process_admin_pages($controller_name, $pages);
         $hide_menu = isset($pages['hide_menu']) ? $pages['hide_menu'] : false;
         if (!$hide_menu) {
             $menu_icon = 'dashicons-admin-generic';
             /* check if there is a corresponding model with a menu_icon post type argument */
             try {
                 $model_name = MvcInflector::singularize(MvcInflector::camelize($controller_name));
                 $model = mvc_model($model_name);
                 if (isset($model->wp_post['post_type']['args']['menu_icon'])) {
                     $menu_icon = $model->wp_post['post_type']['args']['menu_icon'];
                 }
             } catch (Exception $e) {
                 //not every controller must have a corresponding model, continue silently
             }
             $controller_titleized = MvcInflector::titleize($controller_name);
             $admin_controller_name = 'admin_' . $controller_name;
             $top_level_handle = 'mvc_' . $controller_name;
             $method = $admin_controller_name . '_index';
             $this->dispatcher->{$method} = create_function('', 'MvcDispatcher::dispatch(array("controller" => "' . $admin_controller_name . '", "action" => "index"));');
             $capability = $this->admin_controller_capabilities[$controller_name];
             add_menu_page($controller_titleized, $controller_titleized, $capability, $top_level_handle, array($this->dispatcher, $method), $menu_icon, $menu_position);
             foreach ($processed_pages as $key => $admin_page) {
                 $method = $admin_controller_name . '_' . $admin_page['action'];
                 if (!method_exists($this->dispatcher, $method)) {
                     $this->dispatcher->{$method} = create_function('', 'MvcDispatcher::dispatch(array("controller" => "' . $admin_controller_name . '", "action" => "' . $admin_page['action'] . '"));');
                 }
                 $page_handle = $top_level_handle . '-' . $key;
                 $parent_slug = empty($admin_page['parent_slug']) ? $top_level_handle : $admin_page['parent_slug'];
                 if ($admin_page['in_menu']) {
                     add_submenu_page($parent_slug, $admin_page['label'] . ' ‹ ' . $controller_titleized, $admin_page['label'], $admin_page['capability'], $page_handle, array($this->dispatcher, $method));
                 } else {
                     // It looks like there isn't a more native way of creating an admin page without
                     // having it show up in the menu, but if there is, it should be implemented here.
                     // To do: set up capability handling and page title handling for these pages that aren't in the menu
                     $hookname = get_plugin_page_hookname($page_handle, '');
                     if (!empty($hookname)) {
                         add_action($hookname, array($this->dispatcher, $method));
                     }
                     $_registered_pages[$hookname] = true;
                 }
             }
             $menu_position++;
         }
     }
 }
Exemplo n.º 2
0
 public function get_all_versions()
 {
     $documentation_version_model = mvc_model('DocumentationVersion');
     $versions = $documentation_version_model->find();
     $list = array();
     foreach ($versions as $version) {
         $list[$version->id] = $version->name;
     }
     return $list;
 }
Exemplo n.º 3
0
 function after_create($object)
 {
     $documentation_node_model = mvc_model('DocumentationNode');
     $max_existing_documentation_version_id = $documentation_node_model->max('documentation_version_id');
     $documentation_nodes = $documentation_node_model->find(array('conditions' => array('documentation_version_id' => $max_existing_documentation_version_id)));
     foreach ($documentation_nodes as $documentation_node) {
         $node = $documentation_node->to_array();
         unset($node['id']);
         $node['documentation_version_id'] = $object->id;
         $documentation_node_model->create($node);
     }
 }
Exemplo n.º 4
0
function displayed_documentation_version()
{
    global $current_documentation_version, $url_documentation_version;
    if (!empty($url_documentation_version)) {
        return $url_documentation_version;
    }
    if (isset($_GET['version_id'])) {
        $documentation_version_model = mvc_model('DocumentationVersion');
        $version = $documentation_version_model->find_by_id($_GET['version_id']);
        if (!empty($version)) {
            return $version;
        }
    }
    return $current_documentation_version;
}