Exemple #1
0
 private function get_ordered_plugins()
 {
     $plugins = get_option('mvc_plugins', array());
     $plugin_app_paths = array();
     // Allow plugins to be loaded in a specific order by setting a PluginOrder config value like
     // this ('all' is an optional token; it includes all unenumerated plugins):
     // MvcConfiguration::set(array(
     //		'PluginOrder' => array('my-first-plugin', 'my-second-plugin', 'all', 'my-last-plugin')
     // );
     $plugin_order = MvcConfiguration::get('PluginOrder');
     if (!empty($plugin_order)) {
         $ordered_plugins = array();
         $index_of_all = array_search('all', $plugin_order);
         if ($index_of_all !== false) {
             $first_plugins = array_slice($plugin_order, 0, $index_of_all - 1);
             $last_plugins = array_slice($plugin_order, $index_of_all);
             $middle_plugins = array_diff($plugins, $first_plugins, $last_plugins);
             $plugins = array_merge($first_plugins, $middle_plugins, $last_plugins);
         } else {
             $unordered_plugins = array_diff($plugins, $plugin_order);
             $plugins = array_merge($plugin_order, $unordered_plugins);
         }
     }
     return $plugins;
 }
 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++;
         }
     }
 }
Exemple #3
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) {
             $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"));');
             add_menu_page($controller_titleized, $controller_titleized, 'administrator', $top_level_handle, array($this->dispatcher, $method), null, $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++;
         }
     }
 }
Exemple #4
0
 private static function write($type_key, $message)
 {
     $type_name = self::get_type($type_key);
     $context = self::get_context();
     $line = $context['line'];
     $file = $context['file'];
     $execution_context = MvcConfiguration::get('ExecutionContext');
     if ($execution_context == 'shell') {
         echo '-- ' . $type_name . ': ' . $message . "\n" . '   (Thrown on line ' . $line . ' of ' . $file . ")\n";
     } else {
         echo '
             <br />
             <strong>[MVC] ' . $type_name . '</strong>: ' . $message . '
             <br />
             Thrown on line ' . $line . ' of ' . $file . ' <br />';
     }
 }
Exemple #5
0
 protected function get_available_shells()
 {
     $exclude = array('mvc_shell.php', 'mvc_shell_dispatcher.php');
     $pluginAppPaths = MvcConfiguration::get('PluginAppPaths');
     $pluginAppPaths['core'] = MVC_CORE_PATH;
     $shells = array();
     foreach ($pluginAppPaths as $plugin => $path) {
         $path = $path . '/shells';
         $files = $this->file_includer->get_php_files_in_directory($path);
         $key = MvcInflector::camelize($plugin);
         $shells[$plugin] = array();
         foreach ($files as $file) {
             if (!in_array($file, $exclude)) {
                 $name = str_replace('_shell.php', '', $file);
                 $shells[$plugin][] = $name;
             }
         }
     }
     return $shells;
 }
Exemple #6
0
 function __construct()
 {
     $this->core_path = MVC_CORE_PATH;
     $this->plugin_app_paths = MvcConfiguration::get('PluginAppPaths');
 }
Exemple #7
0
 function __construct()
 {
     global $wpdb;
     $this->wpdb = $wpdb;
     $this->debug = MvcConfiguration::get('Debug');
 }
 public function get_user_defined_query_vars()
 {
     $vars = array();
     $params = MvcConfiguration::get('RouteParams');
     foreach ($params as $param) {
         $param = 'mvc_' . $param;
         $vars[] = $param;
     }
     return $vars;
 }
Exemple #9
0
 protected function load_controllers()
 {
     foreach ($this->plugin_app_paths as $plugin_app_path) {
         $admin_controller_filenames = $this->file_includer->require_php_files_in_directory($plugin_app_path . 'controllers/admin/');
         $public_controller_filenames = $this->file_includer->require_php_files_in_directory($plugin_app_path . 'controllers/');
         foreach ($admin_controller_filenames as $filename) {
             if (preg_match('/admin_([^\\/]+)_controller\\.php/', $filename, $match)) {
                 $controller_name = $match[1];
                 $this->admin_controller_names[] = $controller_name;
                 $capabilities = MvcConfiguration::get('admin_controller_capabilities');
                 if (empty($capabilities) || !isset($capabilities[$controller_name])) {
                     $capabilities = array($controller_name => 'administrator');
                 }
                 $this->admin_controller_capabilities[$controller_name] = $capabilities[$controller_name];
             }
         }
         foreach ($public_controller_filenames as $filename) {
             if (preg_match('/([^\\/]+)_controller\\.php/', $filename, $match)) {
                 $this->public_controller_names[] = $match[1];
             }
         }
     }
 }
Exemple #10
0
function mvc_plugin_app_path($plugin)
{
    $plugin_app_paths = MvcConfiguration::get('PluginAppPaths');
    return $plugin_app_paths[$plugin];
}