nggAdminPanel

NggAdminPanel - Admin Section for NextGEN Gallery.

Defined (1)

The class is defined in the following location(s).

/products/photocrati_nextgen/modules/ngglegacy/admin/admin.php  
  1. class nggAdminPanel{ 
  2.  
  3. // constructor 
  4. function __construct() { 
  5.  
  6. // Buffer the output 
  7. add_action('admin_init', array(&$this, 'start_buffer')); 
  8.  
  9. // Add the admin menu 
  10. add_action( 'admin_menu', array (&$this, 'add_menu') ); 
  11. add_action( 'admin_bar_menu', array(&$this, 'admin_bar_menu'), 99 ); 
  12. add_action( 'network_admin_menu', array (&$this, 'add_network_admin_menu') ); 
  13.  
  14. // Add the script and style files 
  15. add_action('admin_print_scripts', array(&$this, 'load_scripts') ); 
  16. add_action('admin_print_styles', array(&$this, 'load_styles') ); 
  17.  
  18. // Try to detect plugins that embed their own jQuery and jQuery UI 
  19. // libraries and load them in NGG's admin pages 
  20. add_action('admin_enqueue_scripts', array(&$this, 'buffer_scripts'), 0); 
  21. add_action('admin_print_scripts', array(&$this, 'output_scripts'), PHP_INT_MAX); 
  22.  
  23. //TODO: remove after release of Wordpress 3.3 
  24. add_filter('contextual_help', array(&$this, 'show_help'), 10, 2); 
  25. add_filter('current_screen', array(&$this, 'edit_current_screen')); 
  26.  
  27. function start_buffer() 
  28. // Notify of page event 
  29. if (isset($_REQUEST['page']) && $_POST) { 
  30. $event = array( 
  31. 'event' => str_replace('-', '_', str_replace('nggallery', '', $_REQUEST['page'])) 
  32. ); 
  33.  
  34. // Do we have a list of galleries that are being affected? 
  35. if (isset($_REQUEST['doaction'])) { 
  36. $event['gallery_ids'] = $_REQUEST['doaction']; 
  37.  
  38. // Do we have a particular gallery id? 
  39. elseif (isset($_REQUEST['gid'])) { 
  40. $event['gallery_id'] = $_REQUEST['gid']; 
  41.  
  42. // Do we have an album id? 
  43. elseif (isset($_REQUEST['act_album']) && $_REQUEST['act_album']) { 
  44. $event['album_id'] = $_REQUEST['act_album']; 
  45. if (strpos($event['event'], '_') === 0) $event['event'] = substr($event['event'], 1); 
  46.  
  47. do_action('ngg_page_event', $event); 
  48. ob_start(); 
  49.  
  50. /** 
  51. * If a NGG page is being requested, we buffer any rendering of <script> 
  52. * tags to detect conflicts and remove them if need be 
  53. */ 
  54. function buffer_scripts() 
  55. // Is this a NGG admin page? 
  56. if (isset($_REQUEST['page']) && strpos($_REQUEST['page'] , 'nggallery') !== FALSE) { 
  57. ob_start(); 
  58.  
  59. function output_scripts() 
  60. // Is this a NGG admin page? 
  61. if (isset($_REQUEST['page']) && strpos($_REQUEST['page'] , 'nggallery') !== FALSE) { 
  62. $plugin_folder = NGGFOLDER; 
  63. $skipjs_count = 0; 
  64. $html = ob_get_contents(); 
  65. ob_end_clean(); 
  66.  
  67. if (!defined('NGG_JQUERY_CONFLICT_DETECTION')) { 
  68. define('NGG_JQUERY_CONFLICT_DETECTION', TRUE); 
  69.  
  70. if (NGG_JQUERY_CONFLICT_DETECTION) { 
  71. // Detect custom jQuery script 
  72. if (preg_match_all("/<script.*wp-content.*jquery[-_\.](min\.)?js.*<\script>/", $html, $matches, PREG_SET_ORDER)) { 
  73. foreach ($matches as $match) { 
  74. $old_script = array_shift($match); 
  75. if (strpos($old_script, NGG_PLUGIN_DIR) === FALSE) 
  76. $html = str_replace($old_script, '', $html); 
  77.  
  78. // Detect custom jQuery UI script and remove 
  79. if (preg_match_all("/<script.*wp-content.*jquery[-_\.]ui.*<\/script>/", $html, $matches, PREG_SET_ORDER)) { 
  80. $detected_jquery_ui = TRUE; 
  81. foreach ($matches as $match) { 
  82. $old_script = array_shift($match); 
  83. if (strpos($old_script, NGG_PLUGIN_DIR) === FALSE) 
  84. $html = str_replace($old_script, '', $html); 
  85.  
  86. if (isset($_REQUEST['skipjs'])) { 
  87. foreach ($_REQUEST['skipjs'] as $js) { 
  88. $js = preg_quote($js); 
  89. if (preg_match_all("#<script.*{$js}.*</script>#", $html, $matches, PREG_SET_ORDER)) { 
  90. foreach ($matches as $match) { 
  91. $old_script = array_shift($match); 
  92. if (strpos($old_script, NGGFOLDER) === FALSE) 
  93. $html = str_replace($old_script, '', $html); 
  94. $skipjs_count = count($_REQUEST['skipjs']); 
  95.  
  96.  
  97. // Use WordPress built-in version of jQuery 
  98. $jquery_url = includes_url('js/jquery/jquery.js'); 
  99. $html = implode('', array( 
  100. "<script type='text/javascript' src='{$jquery_url}'></script>\n",  
  101. "<script type='text/javascript'> 
  102. window.onerror = function(msg, url, line) { 
  103. if (url.match(/\.js$|\.js\?/)) { 
  104. if (window.location.search.length > 0) { 
  105. if (window.location.search.indexOf(url) == -1) 
  106. window.location.search += '&skipjs[{$skipjs_count}]='+url; 
  107. else { 
  108. window.location.search = '?skipjs[{$skipjs_count}]='+url; 
  109. return true; 
  110. };</script>\n",  
  111. $html 
  112. )); 
  113.  
  114. echo $html; 
  115.  
  116. // integrate the menu 
  117. function add_menu() { 
  118.  
  119. add_menu_page( _n( 'Gallery', 'Galleries', 1, 'nggallery' ), _n( 'Gallery', 'Galleries', 1, 'nggallery' ), 'NextGEN Gallery overview', NGGFOLDER, array (&$this, 'show_menu'), path_join(NGGALLERY_URLPATH, 'admin/images/nextgen_16_color.png') ); 
  120. add_submenu_page( NGGFOLDER , __('Overview', 'nggallery'), __('Overview', 'nggallery'), 'NextGEN Gallery overview', NGGFOLDER, array (&$this, 'show_menu')); 
  121. add_submenu_page( NGGFOLDER , __('Manage Galleries', 'nggallery'), __('Manage Galleries', 'nggallery'), 'NextGEN Manage gallery', 'nggallery-manage-gallery', array (&$this, 'show_menu')); 
  122. add_submenu_page( NGGFOLDER , _n( 'Manage Albums', 'Albums', 1, 'nggallery' ), _n( 'Manage Albums', 'Manage Albums', 1, 'nggallery' ), 'NextGEN Edit album', 'nggallery-manage-album', array (&$this, 'show_menu')); 
  123. add_submenu_page( NGGFOLDER , __('Manage Tags', 'nggallery'), __('Manage Tags', 'nggallery'), 'NextGEN Manage tags', 'nggallery-tags', array (&$this, 'show_menu')); 
  124.  
  125. //register the column fields 
  126. $this->register_columns(); 
  127.  
  128. // integrate the network menu 
  129. function add_network_admin_menu() { 
  130.  
  131. add_menu_page( _n( 'Gallery', 'Galleries', 1, 'nggallery' ), _n( 'Gallery', 'Galleries', 1, 'nggallery' ), 'nggallery-wpmu', NGGFOLDER, array (&$this, 'show_network_settings'), path_join(NGGALLERY_URLPATH, 'admin/images/nextgen_16_color.png') ); 
  132. add_submenu_page( NGGFOLDER , __('Network settings', 'nggallery'), __('Network settings', 'nggallery'), 'nggallery-wpmu', NGGFOLDER, array (&$this, 'show_network_settings')); 
  133.  
  134. /** 
  135. * Adding NextGEN Gallery to the Admin bar 
  136. * @since 1.9.0 
  137. * @return void 
  138. */ 
  139. function admin_bar_menu() { 
  140. // If the current user can't write posts, this is all of no use, so let's not output an admin menu 
  141. if ( !current_user_can('NextGEN Gallery overview') ) 
  142. return; 
  143.  
  144. global $wp_admin_bar; 
  145.  
  146. $wp_admin_bar->add_menu( array( 'id' => 'ngg-menu', 'title' => __( 'Gallery' ), 'href' => admin_url('admin.php?page='. NGGFOLDER) ) ); 
  147. $wp_admin_bar->add_menu( array( 'parent' => 'ngg-menu', 'id' => 'ngg-menu-overview', 'title' => __('Overview', 'nggallery'), 'href' => admin_url('admin.php?page='. NGGFOLDER) ) ); 
  148. if ( current_user_can('NextGEN Upload images') ) 
  149. $wp_admin_bar->add_menu( array( 'parent' => 'ngg-menu', 'id' => 'ngg-menu-add-gallery', 'title' => __('Add Gallery / Images', 'nggallery'), 'href' => admin_url('admin.php?page=ngg_addgallery') ) ); 
  150. if ( current_user_can('NextGEN Manage gallery') ) 
  151. $wp_admin_bar->add_menu( array( 'parent' => 'ngg-menu', 'id' => 'ngg-menu-manage-gallery', 'title' => __('Manage Galleries', 'nggallery'), 'href' => admin_url('admin.php?page=nggallery-manage-gallery') ) ); 
  152. if ( current_user_can('NextGEN Edit album') ) 
  153. $wp_admin_bar->add_menu( array( 'parent' => 'ngg-menu', 'id' => 'ngg-menu-manage-album', 'title' => _n( 'Manage Albums', 'Manage Albums', 1, 'nggallery' ), 'href' => admin_url('admin.php?page=nggallery-manage-album') ) ); 
  154. if ( current_user_can('NextGEN Manage tags') ) 
  155. $wp_admin_bar->add_menu( array( 'parent' => 'ngg-menu', 'id' => 'ngg-menu-tags', 'title' => __('Manage Tags', 'nggallery'), 'href' => admin_url('admin.php?page=nggallery-tags') ) ); 
  156.  
  157. // show the network page 
  158. function show_network_settings() { 
  159. include_once ( dirname (__FILE__) . '/wpmu.php' ); 
  160. nggallery_wpmu_setup(); 
  161.  
  162. // load the script for the defined page and load only this code 
  163. function show_menu() { 
  164. global $ngg; 
  165.  
  166. // Set installation date 
  167. if( empty($ngg->options['installDate']) ) { 
  168. $ngg->options['installDate'] = time(); 
  169. update_option('ngg_options', $ngg->options); 
  170.  
  171. // Show donation message only one time. 
  172. if (isset ( $_GET['hide_donation']) ) { 
  173. $ngg->options['hideDonation'] = true; 
  174. update_option('ngg_options', $ngg->options); 
  175.  
  176. echo '<div id="ngg_page_content">'; 
  177. switch ($_GET['page']) { 
  178. case "nggallery-manage-gallery" : 
  179. include_once ( dirname (__FILE__) . '/functions.php' ); // admin functions 
  180. include_once ( dirname (__FILE__) . '/manage.php' ); // nggallery_admin_manage_gallery 
  181. // Initate the Manage Gallery page 
  182. $ngg->manage_page = new nggManageGallery (); 
  183. // Render the output now, because you cannot access a object during the constructor is not finished 
  184. $ngg->manage_page->controller(); 
  185. break; 
  186. case "nggallery-manage-album" : 
  187. include_once ( dirname (__FILE__) . '/album.php' ); // nggallery_admin_manage_album 
  188. $ngg->manage_album = new nggManageAlbum (); 
  189. $ngg->manage_album->controller(); 
  190. break; 
  191. case "nggallery-tags" : 
  192. include_once ( dirname (__FILE__) . '/tags.php' ); // nggallery_admin_tags 
  193. break; 
  194. case "nggallery-roles" : 
  195. include_once ( dirname (__FILE__) . '/roles.php' ); // nggallery_admin_roles 
  196. nggallery_admin_roles(); 
  197. break; 
  198. case "nggallery-import" : 
  199. include_once ( dirname (__FILE__) . '/myimport.php' ); // nggallery_admin_import 
  200. nggallery_admin_import(); 
  201. break; 
  202. case "nggallery-about" : 
  203. include_once ( dirname (__FILE__) . '/about.php' ); // nggallery_admin_about 
  204. nggallery_admin_about(); 
  205. break; 
  206. case "nggallery" : 
  207. default : 
  208. include_once ( dirname (__FILE__) . '/overview.php' ); // nggallery_admin_overview 
  209. nggallery_admin_overview(); 
  210. break; 
  211. echo "</div>"; 
  212.  
  213. function load_scripts() { 
  214. global $wp_version; 
  215.  
  216. // no need to go on if it's not a plugin page 
  217. if( !isset($_GET['page']) ) 
  218. return; 
  219.  
  220. // used to retrieve the uri of some module resources 
  221. $router = C_Router::get_instance(); 
  222.  
  223. wp_register_script('ngg-ajax', NGGALLERY_URLPATH . 'admin/js/ngg.ajax.js', array('jquery'), NGG_SCRIPT_VERSION); 
  224. wp_localize_script('ngg-ajax', 'nggAjaxSetup', array( 
  225. 'url' => admin_url('admin-ajax.php'),  
  226. 'action' => 'ngg_ajax_operation',  
  227. 'operation' => '',  
  228. 'nonce' => wp_create_nonce( 'ngg-ajax' ),  
  229. 'ids' => '',  
  230. 'permission' => __('You do not have the correct permission', 'nggallery'),  
  231. 'error' => __('Unexpected Error', 'nggallery'),  
  232. 'failure' => __('A failure occurred', 'nggallery') 
  233. ) ); 
  234. wp_register_script('ngg-progressbar', NGGALLERY_URLPATH .'admin/js/ngg.progressbar.js', array('jquery'), NGG_SCRIPT_VERSION); 
  235.  
  236. // Enqueue the new Gritter-based progress bars 
  237. wp_enqueue_style('ngg_progressbar'); 
  238. wp_enqueue_script('ngg_progressbar'); 
  239.  
  240. switch ($_GET['page']) { 
  241. case NGGFOLDER : 
  242. wp_enqueue_script( 'ngg_overview', $router->get_static_url('photocrati-nextgen-legacy#overview.js'), array('jquery'), NGG_SCRIPT_VERSION); 
  243. break; 
  244. case "nggallery-manage-gallery" : 
  245. wp_enqueue_script( 'postbox' ); 
  246. wp_enqueue_script( 'ngg-ajax' ); 
  247. wp_enqueue_script( 'ngg-progressbar' ); 
  248. wp_enqueue_script( 'jquery-ui-dialog' ); 
  249. wp_enqueue_script( 'jquery-ui-sortable' ); 
  250. wp_register_script('shutter', $router->get_static_url('photocrati-lightbox#shutter/shutter.js'), false, NGG_SCRIPT_VERSION); 
  251. wp_localize_script('shutter', 'shutterSettings', array( 
  252. 'msgLoading' => __('L O A D I N G', 'nggallery'),  
  253. 'msgClose' => __('Click to Close', 'nggallery'),  
  254. 'imageCount' => '1' 
  255. ) ); 
  256. wp_enqueue_script( 'shutter' ); 
  257.  
  258. // includes tooltip styling 
  259. wp_enqueue_style('nextgen_admin_page', $router->get_static_url('photocrati-nextgen_admin#nextgen_admin_page.css'), FALSE, NGG_SCRIPT_VERSION); 
  260. break; 
  261. case "nggallery-manage-album" : 
  262. wp_enqueue_script( 'jquery-ui-dialog' ); 
  263. wp_enqueue_script( 'jquery-ui-sortable' ); 
  264. wp_enqueue_script( 'ngg_select2' ); 
  265. wp_enqueue_style('ngg_select2'); 
  266. break; 
  267.  
  268.  
  269. function enqueue_jquery_ui_theme() 
  270. $settings = C_NextGen_Settings::get_instance(); 
  271. wp_enqueue_style( 
  272. $settings->jquery_ui_theme,  
  273. $settings->jquery_ui_theme_url,  
  274. array(),  
  275. $settings->jquery_ui_theme_version 
  276. ); 
  277.  
  278. function load_styles() { 
  279. global $ngg; 
  280.  
  281. // load the icon for the navigation menu 
  282. wp_enqueue_style( 'nggmenu', NGGALLERY_URLPATH .'admin/css/menu.css', false, NGG_SCRIPT_VERSION ); 
  283. wp_register_style( 'nggadmin', NGGALLERY_URLPATH .'admin/css/nggadmin.css', false, NGG_SCRIPT_VERSION, 'screen' ); 
  284. wp_register_style( 'ngg-jqueryui', NGGALLERY_URLPATH .'admin/css/jquery.ui.css', false, NGG_SCRIPT_VERSION, 'screen' ); 
  285.  
  286. // no need to go on if it's not a plugin page 
  287. if( !isset($_GET['page']) ) 
  288. return; 
  289.  
  290. // used to retrieve the uri of some module resources 
  291. $router = C_Router::get_instance(); 
  292.  
  293. switch ($_GET['page']) { 
  294. case NGGFOLDER : 
  295. wp_add_inline_style( 'nggadmin', file_get_contents(C_Fs::get_instance()->find_static_abspath('photocrati-nextgen-legacy#overview.css') ) );  
  296. case "nggallery-about" : 
  297. wp_enqueue_style( 'nggadmin' ); 
  298. //TODO:Remove after WP 3.3 release 
  299. if ( !defined('IS_WP_3_3') ) 
  300. wp_admin_css( 'css/dashboard' ); 
  301. break; 
  302. case "nggallery-manage-gallery" : 
  303. wp_enqueue_script('jquery-ui-tooltip'); 
  304. wp_enqueue_style('shutter', $router->get_static_url('photocrati-lightbox#shutter/shutter.css'), false, NGG_SCRIPT_VERSION, 'screen'); 
  305. case "nggallery-roles" : 
  306. case "nggallery-manage-album" : 
  307. $this->enqueue_jquery_ui_theme(); 
  308. wp_enqueue_style( 'nggadmin' ); 
  309. break; 
  310. case "nggallery-tags" : 
  311. wp_enqueue_style( 'nggtags', NGGALLERY_URLPATH .'admin/css/tags-admin.css', false, NGG_SCRIPT_VERSION, 'screen' ); 
  312. break; 
  313.  
  314. function show_help($help, $screen) { 
  315.  
  316. // since WP3.0 it's an object 
  317. if ( is_object($screen) ) 
  318. $screen = $screen->id; 
  319.  
  320. $link = ''; 
  321. // menu title is localized... 
  322. $i18n = strtolower ( _n( 'Gallery', 'Galleries', 1, 'nggallery' ) ); 
  323.  
  324. switch ($screen) { 
  325. case 'toplevel_page_' . NGGFOLDER : 
  326. $link = __('<a href="https://www.imagely.com/wordpress-gallery-plugin/nextgen-gallery/" target="_blank">Introduction</a>', 'nggallery'); 
  327. break; 
  328. case "{$i18n}_page_nggallery-about" : 
  329. $link = __('<a href="https://www.imagely.com/languages/" target="_blank">Languages</a>', 'nggallery'); 
  330. break; 
  331.  
  332. if ( !empty($link) ) { 
  333. $help = '<h5>' . __('Get help with NextGEN Gallery', 'nggallery') . '</h5>'; 
  334. $help .= '<div class="metabox-prefs">'; 
  335. $help .= $link; 
  336. $help .= "</div>\n"; 
  337. $help .= '<h5>' . __('More Help & Info', 'nggallery') . '</h5>'; 
  338. $help .= '<div class="metabox-prefs">'; 
  339. $help .= __('<a href="http://wordpress.org/tags/nextgen-gallery?forum_id=10" target="_blank">Support Forums</a>', 'nggallery'); 
  340. $help .= ' | <a href="http://www.nextgen-gallery.com/faq/" target="_blank">' . __('FAQ', 'nggallery') . '</a>'; 
  341. $help .= ' | <a href="https://bitbucket.org/photocrati/nextgen-gallery/issues" target="_blank">' . __('Feature request', 'nggallery') . '</a>'; 
  342. $help .= ' | <a href="https://www.imagely.com/languages/" target="_blank">' . __('Get your language pack', 'nggallery') . '</a>'; 
  343. $help .= ' | <a href="https://bitbucket.org/photocrati/nextgen-gallery" target="_blank">' . __('Contribute development', 'nggallery') . '</a>'; 
  344. $help .= ' | <a href="http://wordpress.org/extend/plugins/nextgen-gallery" target="_blank">' . __('Download latest version', 'nggallery') . '</a>'; 
  345. $help .= "</div>\n"; 
  346.  
  347. return $help; 
  348.  
  349. /** 
  350. * New wrapper for WordPress 3.3, so contextual help will be added to the admin bar 
  351. * Rework this see http://wpdevel.wordpress.com/2011/12/06/help-and-screen-api-changes-in-3-3/ 
  352. * @since 1.9.0 
  353. * @param object $screen 
  354. * @return void 
  355. */ 
  356. function add_contextual_help($screen) { 
  357.  
  358. $help = $this->show_help('', $screen); 
  359. //add_contextual_help( $screen, $help ); 
  360.  
  361. /** 
  362. * We need to manipulate the current_screen name so that we can show the correct column screen options 
  363. * @since 1.8.0 
  364. * @param object $screen 
  365. * @return object $screen 
  366. */ 
  367. function edit_current_screen($screen) { 
  368.  
  369. if ( is_string($screen) ) 
  370. $screen = convert_to_screen($screen); 
  371.  
  372. // menu title is localized, so we need to change the toplevel name 
  373. $i18n = strtolower ( _n( 'Gallery', 'Galleries', 1, 'nggallery' ) ); 
  374.  
  375. switch ($screen->id) { 
  376. case "{$i18n}_page_nggallery-manage-gallery" : 
  377. // we would like to have screen option only at the manage images / gallery page 
  378. if ( isset ($_POST['sortGallery']) ) 
  379. $screen = $screen; 
  380. else if ( (isset($_GET['mode']) && $_GET['mode'] == 'edit') || isset ($_POST['backToGallery']) ) 
  381. $screen->base = $screen->id = 'nggallery-manage-images'; 
  382. else if ( (isset($_GET['mode']) && $_GET['mode'] == 'sort') ) 
  383. $screen = $screen; 
  384. else 
  385. $screen->base = $screen->id = 'nggallery-manage-gallery'; 
  386. break; 
  387.  
  388. if ( defined('IS_WP_3_3') ) 
  389. $this->add_contextual_help($screen); 
  390.  
  391. return $screen; 
  392.  
  393. /** 
  394. * We need to register the columns at a very early point 
  395. * @return void 
  396. */ 
  397. function register_columns() { 
  398. include_once ( dirname (__FILE__) . '/manage-images.php' ); 
  399.  
  400. $wp_list_table = new _NGG_Images_List_Table('nggallery-manage-images'); 
  401.  
  402. include_once ( dirname (__FILE__) . '/manage-galleries.php' ); 
  403.  
  404. $wp_list_table = new _NGG_Galleries_List_Table('nggallery-manage-gallery'); 
  405.  
  406. /** 
  407. * Read an array from a remote url 
  408. * @param string $url 
  409. * @return array of the content 
  410. */ 
  411. function get_remote_array($url) { 
  412.  
  413. if ( function_exists('wp_remote_request') ) { 
  414.  
  415. if ( false === ( $content = get_transient( 'ngg_request_' . md5($url) ) ) ) { 
  416.  
  417. $options = array(); 
  418. $options['headers'] = array( 
  419. 'User-Agent' => 'NextGEN Gallery Information Reader V' . NGGVERSION . '; (' . get_bloginfo('url') .')' 
  420. ); 
  421.  
  422. $response = wp_remote_request($url, $options); 
  423.  
  424. if ( is_wp_error( $response ) ) 
  425. return false; 
  426.  
  427. if ( 200 != $response['response']['code'] ) 
  428. return false; 
  429.  
  430. $content = $response['body']; 
  431. set_transient( 'ngg_request_' . md5($url), $content, 60*60*48 ); 
  432.  
  433. $content = unserialize($content); 
  434.  
  435. if (is_array($content)) 
  436. return $content; 
  437.  
  438. return false; 
  439.