Beispiel #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++;
         }
     }
 }
 private function dispatch($args)
 {
     MvcConfiguration::set('ExecutionContext', 'shell');
     echo Console_Color::convert("\n%P%UWelcome to WP MVC Console!%n%n\n\n");
     $shell_name = 'help';
     if (!empty($args[1])) {
         $shell_name = $args[1];
     }
     $shell_title = MvcInflector::camelize($shell_name);
     $shell_name .= '_shell';
     $shell_class_name = MvcInflector::camelize($shell_name);
     $shell_path = 'shells/' . $shell_name . '.php';
     $shell_exists = $this->file_includer->include_first_app_file_or_core_file($shell_path);
     if (!$shell_exists) {
         echo 'Sorry, a shell named "' . $shell_name . '" couldn\'t be found in any of the MVC plugins.';
         echo "\n";
         echo 'Please make sure a shell class exists in "app/' . $shell_path . '", or execute "./wpmvc" to see a list of available shells.';
         echo "\n";
         die;
     }
     $args = array_slice($args, 2);
     if (empty($args[0])) {
         $args = array('main');
     }
     $shell = new $shell_class_name($args);
     $method = $args[0];
     $args = array_slice($args, 1);
     if ($shell_name != 'help_shell') {
         $shell->out(Console_Color::convert("\n%_[Running " . $shell_title . "::" . $method . "]%n"));
     }
     $shell->{$method}($args);
     if ($shell_name != 'help_shell') {
         $shell->out(Console_Color::convert("\n%_[Complete]%n"));
     }
 }
Beispiel #4
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++;
         }
     }
 }
Beispiel #5
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 />';
     }
 }
 private function dispatch($args)
 {
     MvcConfiguration::set('ExecutionContext', 'shell');
     if (empty($args[1])) {
         MvcError::fatal('Please provide the name of the shell as the first argument.');
     }
     $shell_name = $args[1];
     $shell_name .= '_shell';
     $shell_class_name = MvcInflector::camelize($shell_name);
     $this->file_includer->require_first_app_file_or_core_file('shells/' . $shell_name . '.php');
     $args = array_slice($args, 2);
     if (empty($args[0])) {
         $args = array('main');
     }
     $shell = new $shell_class_name($args);
     $method = $args[0];
     $args = array_slice($args, 1);
     $shell->{$method}($args);
 }
Beispiel #7
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;
 }
Beispiel #8
0
 function get($config)
 {
     $_this =& MvcConfiguration::get_instance();
     if (strpos($config, '.') !== false) {
         $names = explode('.', $config, 2);
         $config = $names[0];
     }
     if (!isset($_this->{$config})) {
         return null;
     }
     if (!isset($names[1])) {
         return $_this->{$config};
     }
     if (count($names) == 2) {
         if (isset($_this->{$config}[$names[1]])) {
             return $_this->{$config}[$names[1]];
         }
     }
     return null;
 }
<?php

MvcConfiguration::set(array('Debug' => false));
MvcConfiguration::append(array('AdminPages' => array('supra_mongodb_documents' => array('add' => array('in_menu' => false)))));
add_action('mvc_admin_init', 'supramongodb_on_mvc_admin_init');
function supramongodb_on_mvc_admin_init($options)
{
    wp_register_style('mongodb-style', mvc_css_url('supra-mongodb-manager', 'main'));
    wp_enqueue_style('mongodb-style');
    wp_enqueue_script('mongodb-script', mvc_js_url('supra-mongodb-manager', 'main'), array('jquery'));
}
Beispiel #10
0
<?php

MvcConfiguration::set(array('Debug' => false));
add_action('mvc_admin_init', 'events_calendar_on_mvc_admin_init');
function events_calendar_on_mvc_admin_init($options)
{
    wp_register_style('mvc_admin', mvc_css_url('events-calendar-example', 'admin'));
    wp_enqueue_style('mvc_admin');
}
Beispiel #11
0
<?php

MvcConfiguration::set(array('Debug' => false));
MvcConfiguration::append(array('AdminPages' => array('documentation_nodes' => array('add', 'delete', 'edit', 'tree', 'export' => array('parent_slug' => 'tools.php', 'label' => 'Export Documentation')))));
function current_documentation_version()
{
    global $current_documentation_version;
    return $current_documentation_version;
}
function url_documentation_version_name()
{
    global $url_documentation_version;
    if (isset($url_documentation_version->name)) {
        return $url_documentation_version->name;
    }
    return null;
}
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;
Beispiel #12
0
 function __construct()
 {
     $this->core_path = MVC_CORE_PATH;
     $this->plugin_app_paths = MvcConfiguration::get('PluginAppPaths');
 }
Beispiel #13
0
 function __construct()
 {
     global $wpdb;
     $this->wpdb = $wpdb;
     $this->debug = MvcConfiguration::get('Debug');
 }
Beispiel #14
0
 public function get_user_defined_query_vars()
 {
     $vars = array();
     $params = MvcConfiguration::get('RouteParams');
     foreach ($params as $param) {
         $param = 'mvc_' . $param;
         $vars[] = $param;
     }
     return $vars;
 }
Beispiel #15
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];
             }
         }
     }
 }
Beispiel #16
0
<?php

MvcConfiguration::set(array('Debug' => false));
MvcConfiguration::append(array('AdminPages' => array('sections' => false, 'survey_users' => false, 'questions' => false, 'question_options' => false, 'results' => false)));
add_action('mvc_admin_init', 'surveys_on_mvc_admin_init', 10, 1);
function surveys_on_mvc_admin_init($args)
{
    //error_log(print_r($args, true));
    extract($args);
    if (in_array($action, array('add', 'edit'))) {
        wp_register_style('mvc_surveys_admin', mvc_css_url('ease-surveys', 'admin'));
        //wp_enqueue_style('mvc_survey_admin');
        wp_enqueue_style('mvc_surveys_admin');
        //wp_register_script('mvc_admin', mvc_js_url('ease-surveys', 'admin'));
        //wp_enqueue_script('mvc_admin');
        wp_enqueue_script('mvc_surveys_admin', mvc_js_url('ease-surveys', 'admin'), array('jquery', 'jquery-ui-core', 'jquery-ui-widget', 'jquery-ui-mouse', 'jquery-ui-accordion', 'jquery-ui-draggable', 'jquery-ui-droppable', 'jquery-ui-sortable'), null, true);
    }
}
//redefine the create or save method to spit out JSON if the request is JSON based
class EaseSurveysMvcAdminController extends MvcAdminController
{
    public function create_or_save_json()
    {
        if (!empty($this->params['data'][$this->model->name])) {
            error_log('NEW CREATE OR SAVE JSON');
            //error_log( print_r($this->params['data'], true) );
            error_log(print_r($_REQUEST, true));
            $object = $this->params['data'][$this->model->name];
            error_log('create or save CREATE');
            error_log(print_r($this->params, true));
            if (empty($object['id']) || $object['id'] == null) {
Beispiel #17
0
function mvc_plugin_app_path($plugin)
{
    $plugin_app_paths = MvcConfiguration::get('PluginAppPaths');
    return $plugin_app_paths[$plugin];
}
Beispiel #18
0
<?php

MvcConfiguration::set(array('Debug' => false));
MvcConfiguration::append(array('AdminPages' => array('speakers' => array('add', 'delete', 'edit', 'example_page'))));
add_action('mvc_admin_init', 'events_calendar_on_mvc_admin_init');
function events_calendar_on_mvc_admin_init($options)
{
    wp_register_style('mvc_admin', mvc_css_url('events-calendar-example', 'admin'));
    wp_enqueue_style('mvc_admin');
}