| 1 |
<?php |
| 2 |
/* |
| 3 |
* working behind the seen |
| 4 |
*/ |
| 5 |
|
| 6 |
|
| 7 |
class NM_PLUGIN_WPComments_Admin extends NM_PLUGIN_WPComments{ |
| 8 |
|
| 9 |
|
| 10 |
var $menu_pages, $plugin_scripts_admin, $plugin_settings; |
| 11 |
|
| 12 |
|
| 13 |
function __construct(){ |
| 14 |
|
| 15 |
|
| 16 |
//setting plugin meta saved in config.php |
| 17 |
$this -> plugin_meta = get_plugin_meta_wpcomment(); |
| 18 |
|
| 19 |
//getting saved settings |
| 20 |
$this -> plugin_settings = get_option($this->plugin_meta['shortname'].'_settings'); |
| 21 |
|
| 22 |
|
| 23 |
/* |
| 24 |
* [1] |
| 25 |
* TODO: change this for plugin admin pages |
| 26 |
*/ |
| 27 |
$this -> menu_pages = array(array('page_title' => $this->plugin_meta['name'], |
| 28 |
'menu_title' => $this->plugin_meta['name'], |
| 29 |
'cap' => 'manage_options', |
| 30 |
'slug' => $this->plugin_meta['shortname'], |
| 31 |
'callback' => 'main_settings', |
| 32 |
'parent_slug' => '',), |
| 33 |
); |
| 34 |
|
| 35 |
|
| 36 |
/* |
| 37 |
* [2] |
| 38 |
* TODO: Change this for admin related scripts |
| 39 |
* JS scripts and styles to loaded |
| 40 |
* ADMIN |
| 41 |
*/ |
| 42 |
$this -> plugin_scripts_admin = array(array( 'script_name' => 'scripts-global', |
| 43 |
'script_source' => '/js/nm-global.js', |
| 44 |
'localized' => false, |
| 45 |
'type' => 'js', |
| 46 |
'page_slug' => $this->plugin_meta['shortname'] |
| 47 |
), |
| 48 |
array( 'script_name' => 'scripts-admin', |
| 49 |
'script_source' => '/js/admin.js', |
| 50 |
'localized' => true, |
| 51 |
'type' => 'js', |
| 52 |
'page_slug' => $this->plugin_meta['shortname'], |
| 53 |
'depends' => array ( |
| 54 |
'jquery', |
| 55 |
'jquery-ui-accordion', |
| 56 |
'jquery-ui-draggable', |
| 57 |
'jquery-ui-droppable', |
| 58 |
'jquery-ui-sortable', |
| 59 |
'jquery-ui-slider', |
| 60 |
'jquery-ui-dialog', |
| 61 |
'jquery-ui-tabs', |
| 62 |
'media-upload', |
| 63 |
'thickbox' |
| 64 |
) |
| 65 |
), |
| 66 |
array ( |
| 67 |
'script_name' => 'ui-style', |
| 68 |
'script_source' => '/js/ui/css/smoothness/jquery-ui-1.10.3.custom.min.css', |
| 69 |
'localized' => false, |
| 70 |
'type' => 'style', |
| 71 |
'page_slug' => $this->plugin_meta ['shortname'], |
| 72 |
'depends' => '', |
| 73 |
), |
| 74 |
|
| 75 |
); |
| 76 |
|
| 77 |
|
| 78 |
add_action('admin_menu', array($this, 'add_menu_pages')); |
| 79 |
} |
| 80 |
|
| 81 |
function load_scripts_admin(){ |
| 82 |
|
| 83 |
//localized vars in js |
| 84 |
$arrLocalizedVars = array( 'ajaxurl' => admin_url( 'admin-ajax.php' ), |
| 85 |
'plugin_url' => $this -> plugin_meta['url'] |
| 86 |
); |
| 87 |
|
| 88 |
//admin end scripts |
| 89 |
|
| 90 |
if($this -> plugin_scripts_admin){ |
| 91 |
foreach($this -> plugin_scripts_admin as $script){ |
| 92 |
|
| 93 |
//checking if it is style |
| 94 |
if( $script['type'] == 'js'){ |
| 95 |
$depends = (isset($script['depends']) ? $script['depends'] : NULL); |
| 96 |
wp_enqueue_script ( $this->plugin_meta ['shortname'] . '-' . $script ['script_name'], $this->plugin_meta ['url'] . $script ['script_source'], $depends ); |
| 97 |
|
| 98 |
//if localized |
| 99 |
if( $script['localized'] ) |
| 100 |
wp_localize_script( $this -> plugin_meta['shortname'].'-'.$script['script_name'], $this -> plugin_meta['shortname'].'_vars', $arrLocalizedVars); |
| 101 |
}else{ |
| 102 |
|
| 103 |
wp_enqueue_style($this -> plugin_meta['shortname'].'-'.$script['script_name'], $this -> plugin_meta['url'].$script['script_source'], __FILE__); |
| 104 |
} |
| 105 |
} |
| 106 |
} |
| 107 |
|
| 108 |
} |
| 109 |
|
| 110 |
|
| 111 |
|
| 112 |
/* |
| 113 |
* creating menu page for this plugin |
| 114 |
*/ |
| 115 |
|
| 116 |
function add_menu_pages(){ |
| 117 |
|
| 118 |
foreach ($this -> menu_pages as $page){ |
| 119 |
|
| 120 |
if ($page['parent_slug'] == ''){ |
| 121 |
|
| 122 |
$menu = add_menu_page(sprintf(__("%s", 'nm-wpcomments'), $page['page_title']), |
| 123 |
sprintf(__("%s", 'nm-wpcomments'), $page['menu_title']), |
| 124 |
$page['cap'], |
| 125 |
$page['slug'], |
| 126 |
array($this, $page['callback']), |
| 127 |
$this->plugin_meta['logo']); |
| 128 |
}else{ |
| 129 |
|
| 130 |
$menu = add_submenu_page($page['parent_slug'], |
| 131 |
sprintf(__("%s", 'nm-wpcomments'), $page['page_title']), |
| 132 |
sprintf(__("%s", 'nm-wpcomments'), $page['menu_title']), |
| 133 |
$page['cap'], |
| 134 |
$page['slug'], |
| 135 |
array($this, $page['callback']) |
| 136 |
); |
| 137 |
|
| 138 |
} |
| 139 |
|
| 140 |
//loading script for only plugin optios pages |
| 141 |
// page_slug is key in $plugin_scripts_admin which determine the page |
| 142 |
foreach ($this -> plugin_scripts_admin as $script){ |
| 143 |
|
| 144 |
if (is_array($script['page_slug'])){ |
| 145 |
|
| 146 |
if (in_array($page['slug'], $script['page_slug'])) |
| 147 |
add_action('admin_print_scripts-'.$menu, array($this, 'load_scripts_admin')); |
| 148 |
}else if ($script['page_slug'] == $page['slug']){ |
| 149 |
add_action('admin_print_scripts-'.$menu, array($this, 'load_scripts_admin')); |
| 150 |
} |
| 151 |
} |
| 152 |
} |
| 153 |
|
| 154 |
|
| 155 |
} |
| 156 |
|
| 157 |
|
| 158 |
//====================== CALLBACKS ================================= |
| 159 |
function main_settings(){ |
| 160 |
|
| 161 |
$this -> load_template('admin/settings.php'); |
| 162 |
|
| 163 |
} |
| 164 |
|
| 165 |
function list_users(){ |
| 166 |
|
| 167 |
|
| 168 |
} |
| 169 |
} |
| 170 |
|
| 171 |
new NM_PLUGIN_WPComments_Admin(); |