admin.php
117 lines
| 1 | <?php |
| 2 | /** |
| 3 | * Introduce special type for controllers which render pages inside admin area |
| 4 | * |
| 5 | * @author Pavel Kulbakin <p.kulbakin@gmail.com> |
| 6 | */ |
| 7 | abstract class PMXE_Controller_Admin extends PMXE_Controller { |
| 8 | /** |
| 9 | * Admin page base url (request url without all get parameters but `page`) |
| 10 | * @var string |
| 11 | */ |
| 12 | public $baseUrl; |
| 13 | /** |
| 14 | * Parameters which is left when baseUrl is detected |
| 15 | * @var array |
| 16 | */ |
| 17 | public $baseUrlParamNames = array('page', 'pagenum', 'order', 'order_by', 'type', 's', 'f'); |
| 18 | /** |
| 19 | * Whether controller is rendered inside wordpress page |
| 20 | * @var bool |
| 21 | */ |
| 22 | public $isInline = false; |
| 23 | /** |
| 24 | * Constructor |
| 25 | */ |
| 26 | public function __construct() { |
| 27 | |
| 28 | $remove = array_diff(array_keys($_GET), $this->baseUrlParamNames); |
| 29 | if ($remove) { |
| 30 | $this->baseUrl = remove_query_arg($remove); |
| 31 | } else { |
| 32 | $this->baseUrl = $_SERVER['REQUEST_URI']; |
| 33 | } |
| 34 | parent::__construct(); |
| 35 | |
| 36 | // add special filter for url fields |
| 37 | $this->input->addFilter('pmxe_url_filter'); |
| 38 | |
| 39 | // enqueue required sripts and styles |
| 40 | global $wp_styles; |
| 41 | if ( ! is_a($wp_styles, 'WP_Styles')) |
| 42 | $wp_styles = new WP_Styles(); |
| 43 | |
| 44 | wp_enqueue_style('jquery-ui', PMXE_ROOT_URL . '/static/js/jquery/css/redmond/jquery-ui.css', array('media-views')); |
| 45 | wp_enqueue_style('jquery-tipsy', PMXE_ROOT_URL . '/static/js/jquery/css/smoothness/jquery.tipsy.css', array('media-views')); |
| 46 | wp_enqueue_style('pmxe-admin-style', PMXE_ROOT_URL . '/static/css/admin.css',array('media-views'), PMXE_VERSION.PMXE_ASSETS_VERSION); |
| 47 | wp_enqueue_style('pmxe-admin-style-upgrade-notice', PMXE_ROOT_URL . '/static/css/upgrade-notice.css',array('media-views'), PMXE_VERSION.PMXE_ASSETS_VERSION); |
| 48 | wp_enqueue_style('pmxe-admin-style-ie', PMXE_ROOT_URL . '/static/css/admin-ie.css', array('media-views')); |
| 49 | wp_enqueue_style('jquery-select2', PMXE_ROOT_URL . '/static/js/jquery/css/select2/select2.css', array('media-views')); |
| 50 | wp_enqueue_style('jquery-select2', PMXE_ROOT_URL . '/static/js/jquery/css/select2/select2-bootstrap.css', array('media-views')); |
| 51 | wp_enqueue_style('jquery-chosen', PMXE_ROOT_URL . '/static/js/jquery/css/chosen/chosen.css', array('media-views')); |
| 52 | wp_enqueue_style('jquery-codemirror', PMXE_ROOT_URL . '/static/codemirror/codemirror.css', array('media-views'), PMXE_VERSION.PMXE_ASSETS_VERSION); |
| 53 | wp_enqueue_style('jquery-timepicker', PMXE_ROOT_URL . '/static/js/jquery/css/timepicker/jquery.timepicker.css', array('media-views'), PMXE_VERSION.PMXE_ASSETS_VERSION); |
| 54 | wp_enqueue_style('pmxe-angular-scss', PMXE_ROOT_URL . '/dist/styles.css', array('media-views'), PMXE_VERSION.PMXE_ASSETS_VERSION); |
| 55 | |
| 56 | $wp_styles->add_data('pmxe-admin-style-ie', 'conditional', 'lte IE 7'); |
| 57 | wp_enqueue_style('wp-pointer'); |
| 58 | |
| 59 | if ( version_compare(get_bloginfo('version'), '3.8-RC1') >= 0 ){ |
| 60 | wp_enqueue_style('pmxe-admin-style-wp-3.8', PMXE_ROOT_URL . '/static/css/admin-wp-3.8.css', array('media-views')); |
| 61 | } |
| 62 | |
| 63 | if ( version_compare(get_bloginfo('version'), '4.4') >= 0 ){ |
| 64 | wp_enqueue_style('pmxe-admin-style-wp-4.4', PMXE_ROOT_URL . '/static/css/admin-wp-4.4.css', array('media-views')); |
| 65 | } |
| 66 | |
| 67 | $scheme_color = get_user_option('admin_color') and is_file(PMXE_Plugin::ROOT_DIR . '/static/css/admin-colors-' . $scheme_color . '.css') or $scheme_color = 'fresh'; |
| 68 | if (is_file(PMXE_Plugin::ROOT_DIR . '/static/css/admin-colors-' . $scheme_color . '.css')) { |
| 69 | wp_enqueue_style('pmxe-admin-style-color', PMXE_ROOT_URL . '/static/css/admin-colors-' . $scheme_color . '.css', array('media-views')); |
| 70 | } |
| 71 | |
| 72 | wp_deregister_script('wp-codemirror'); |
| 73 | |
| 74 | wp_enqueue_script('jquery-ui-datepicker', PMXE_ROOT_URL . '/static/js/jquery/ui.datepicker.js', 'jquery-ui-core'); |
| 75 | wp_enqueue_script('tipsy', PMXE_ROOT_URL . '/static/js/jquery/jquery.tipsy.js', 'jquery', PMXE_VERSION.PMXE_ASSETS_VERSION); |
| 76 | wp_enqueue_script('jquery-pmxe-nestable', PMXE_ROOT_URL . '/static/js/jquery/jquery.mjs.pmxe_nestedSortable.js', array('jquery', 'jquery-ui-dialog', 'jquery-ui-sortable', 'jquery-ui-draggable', 'jquery-ui-droppable', 'jquery-ui-tabs', 'jquery-ui-progressbar')); |
| 77 | wp_enqueue_script('jquery-select2', PMXE_ROOT_URL . '/static/js/jquery/select2.min.js', 'jquery'); |
| 78 | wp_enqueue_script('jquery-ddslick', PMXE_ROOT_URL . '/static/js/jquery/jquery.ddslick.min.js', 'jquery'); |
| 79 | wp_enqueue_script('jquery-chosen', PMXE_ROOT_URL . '/static/js/jquery/chosen.jquery.js', 'jquery'); |
| 80 | wp_enqueue_script('jquery-codemirror', PMXE_ROOT_URL . '/static/codemirror/codemirror.js', array(), PMXE_VERSION.PMXE_ASSETS_VERSION); |
| 81 | wp_enqueue_script('jquery-codemirror-matchbrackets', PMXE_ROOT_URL . '/static/codemirror/matchbrackets.js', array('jquery-codemirror'), PMXE_VERSION.PMXE_ASSETS_VERSION); |
| 82 | wp_enqueue_script('jquery-codemirror-htmlmixed', PMXE_ROOT_URL . '/static/codemirror/htmlmixed.js', array('jquery-codemirror-matchbrackets'), PMXE_VERSION.PMXE_ASSETS_VERSION); |
| 83 | wp_enqueue_script('jquery-codemirror-xml', PMXE_ROOT_URL . '/static/codemirror/xml.js', array('jquery-codemirror-htmlmixed'), PMXE_VERSION.PMXE_ASSETS_VERSION); |
| 84 | wp_enqueue_script('jquery-codemirror-javascript', PMXE_ROOT_URL . '/static/codemirror/javascript.js', array('jquery-codemirror-xml'), PMXE_VERSION.PMXE_ASSETS_VERSION); |
| 85 | wp_enqueue_script('jquery-codemirror-clike', PMXE_ROOT_URL . '/static/codemirror/clike.js', array('jquery-codemirror-javascript'), PMXE_VERSION.PMXE_ASSETS_VERSION); |
| 86 | wp_enqueue_script('jquery-codemirror-php', PMXE_ROOT_URL . '/static/codemirror/php.js', array('jquery-codemirror-clike'), PMXE_VERSION.PMXE_ASSETS_VERSION); |
| 87 | wp_enqueue_script('jquery-codemirror-autorefresh', PMXE_ROOT_URL . '/static/codemirror/autorefresh.js', array('jquery-codemirror'), PMXE_VERSION.PMXE_ASSETS_VERSION); |
| 88 | wp_enqueue_script('jquery-timepicker', PMXE_ROOT_URL . '/static/js/jquery/jquery.timepicker.js', array('jquery'), PMXE_VERSION.PMXE_ASSETS_VERSION); |
| 89 | |
| 90 | wp_enqueue_script('wp-pointer'); |
| 91 | |
| 92 | /* load plupload scripts */ |
| 93 | wp_enqueue_script('pmxe-admin-script', PMXE_ROOT_URL . '/static/js/admin.js', array('jquery', 'jquery-ui-dialog', 'jquery-ui-datepicker', 'jquery-ui-draggable', 'jquery-ui-droppable', 'jquery-ui-core', 'jquery-ui-widget', 'jquery-ui-position', 'jquery-ui-autocomplete' ), PMXE_VERSION); |
| 94 | wp_enqueue_script('pmxe-admin-validate-braces', PMXE_ROOT_URL . '/static/js/validate-braces.js', array('pmxe-admin-script' ), PMXE_VERSION.PMXE_ASSETS_VERSION); |
| 95 | wp_enqueue_script('pmxe-admin-update-notice', PMXE_ROOT_URL . '/static/js/upgrade-notice.js', array('pmxe-admin-script' ), PMXE_VERSION.PMXE_ASSETS_VERSION); |
| 96 | |
| 97 | if(getenv('WPAE_DEV')) { |
| 98 | wp_enqueue_script('pmxe-angular-app', PMXE_ROOT_URL . '/dist/app.js', array('jquery'), PMXE_VERSION.PMXE_ASSETS_VERSION); |
| 99 | } else { |
| 100 | wp_enqueue_script('pmxe-angular-app', PMXE_ROOT_URL . '/dist/app.min.js', array('jquery'), PMXE_VERSION.PMXE_ASSETS_VERSION); |
| 101 | } |
| 102 | } |
| 103 | |
| 104 | /** |
| 105 | * @see Controller::render() |
| 106 | */ |
| 107 | protected function render($viewPath = NULL) |
| 108 | { |
| 109 | // assume template file name depending on calling function |
| 110 | if (is_null($viewPath)) { |
| 111 | $trace = debug_backtrace(); |
| 112 | $viewPath = str_replace('_', '/', preg_replace('%^' . preg_quote(PMXE_Plugin::PREFIX, '%') . '%', '', strtolower($trace[1]['class']))) . '/' . $trace[1]['function']; |
| 113 | } |
| 114 | parent::render($viewPath); |
| 115 | } |
| 116 | |
| 117 | } |