PageRenderTime 36ms CodeModel.GetById 13ms RepoModel.GetById 1ms app.codeStats 0ms

/wp-content/plugins/events-manager/admin/em-admin.php

https://github.com/90rdon/bric
PHP | 272 lines | 222 code | 16 blank | 34 comment | 86 complexity | 33c46e7277a4e92d1af85c7fb9660c8e MD5 | raw file
Possible License(s): BSD-3-Clause
  1. <?php
  2. //Admin functions
  3. function em_admin_menu(){
  4. global $menu, $submenu, $pagenow;
  5. //Count pending bookings
  6. if( get_option('dbem_rsvp_enabled') ){
  7. $bookings_num = '';
  8. $bookings_pending_count = apply_filters('em_bookings_pending_count',0);
  9. if( get_option('dbem_bookings_approval') == 1){
  10. $bookings_pending_count += count(EM_Bookings::get(array('status'=>'0', 'blog'=>get_current_blog_id()))->bookings);
  11. }
  12. if($bookings_pending_count > 0){
  13. $bookings_num = '<span class="update-plugins count-'.$bookings_pending_count.'"><span class="plugin-count">'.$bookings_pending_count.'</span></span>';
  14. }
  15. }else{
  16. $bookings_num = '';
  17. $bookings_pending_count = 0;
  18. }
  19. //Count pending events
  20. $events_num = '';
  21. $events_pending_count = EM_Events::count(array('status'=>0, 'scope'=>'all', 'blog'=>get_current_blog_id()));
  22. //TODO Add flexible permissions
  23. if($events_pending_count > 0){
  24. $events_num = '<span class="update-plugins count-'.$events_pending_count.'"><span class="plugin-count">'.$events_pending_count.'</span></span>';
  25. }
  26. //Count pending recurring events
  27. $events_recurring_num = '';
  28. $events_recurring_pending_count = EM_Events::count(array('status'=>0, 'recurring'=>1, 'scope'=>'all', 'blog'=>get_current_blog_id()));
  29. //TODO Add flexible permissions
  30. if($events_recurring_pending_count > 0){
  31. $events_recurring_num = '<span class="update-plugins count-'.$events_recurring_pending_count.'"><span class="plugin-count">'.$events_recurring_pending_count.'</span></span>';
  32. }
  33. $both_pending_count = apply_filters('em_items_pending_count', $events_pending_count + $bookings_pending_count + $events_recurring_pending_count);
  34. $both_num = ($both_pending_count > 0) ? '<span class="update-plugins count-'.$both_pending_count.'"><span class="plugin-count">'.$both_pending_count.'</span></span>':'';
  35. // Add a submenu to the custom top-level menu:
  36. $plugin_pages = array();
  37. if( get_option('dbem_rsvp_enabled') ){
  38. $plugin_pages['bookings'] = add_submenu_page('edit.php?post_type='.EM_POST_TYPE_EVENT, __('Bookings', 'dbem'), __('Bookings', 'dbem').$bookings_num, 'manage_bookings', 'events-manager-bookings', "em_bookings_page");
  39. }
  40. $plugin_pages['options'] = add_submenu_page('edit.php?post_type='.EM_POST_TYPE_EVENT, __('Events Manager Settings','dbem'),__('Settings','dbem'), 'list_users', "events-manager-options", 'em_admin_options_page');
  41. $plugin_pages['help'] = add_submenu_page('edit.php?post_type='.EM_POST_TYPE_EVENT, __('Getting Help for Events Manager','dbem'),__('Help','dbem'), 'list_users', "events-manager-help", 'em_admin_help_page');
  42. //If multisite global with locations set to be saved in main blogs we can force locations to be created on the main blog only
  43. if( EM_MS_GLOBAL && !is_main_site() && get_site_option('dbem_ms_mainblog_locations') ){
  44. include( dirname(__FILE__)."/em-ms-locations.php" );
  45. $plugin_pages['locations'] = add_submenu_page('edit.php?post_type='.EM_POST_TYPE_EVENT, __('Locations','dbem'),__('Locations','dbem'), 'read_others_locations', "locations", 'em_admin_ms_locations');
  46. }
  47. $plugin_pages = apply_filters('em_create_events_submenu',$plugin_pages);
  48. //We have to modify the menus manually
  49. if( !empty($both_num) ){ //Main Event Menu
  50. //go through the menu array and modify the events menu if found
  51. foreach ( (array)$menu as $key => $parent_menu ) {
  52. if ( $parent_menu[2] == 'edit.php?post_type='.EM_POST_TYPE_EVENT ){
  53. $menu[$key][0] = $menu[$key][0]. $both_num;
  54. break;
  55. }
  56. }
  57. }
  58. if( !empty($events_num) && !empty($submenu['edit.php?post_type='.EM_POST_TYPE_EVENT]) ){ //Submenu Event Item
  59. //go through the menu array and modify the events menu if found
  60. foreach ( (array)$submenu['edit.php?post_type='.EM_POST_TYPE_EVENT] as $key => $submenu_item ) {
  61. if ( $submenu_item[2] == 'edit.php?post_type='.EM_POST_TYPE_EVENT ){
  62. $submenu['edit.php?post_type='.EM_POST_TYPE_EVENT][$key][0] = $submenu['edit.php?post_type='.EM_POST_TYPE_EVENT][$key][0]. $events_num;
  63. break;
  64. }
  65. }
  66. }
  67. if( !empty($events_recurring_num) && !empty($submenu['edit.php?post_type='.EM_POST_TYPE_EVENT]) ){ //Submenu Recurring Event Item
  68. //go through the menu array and modify the events menu if found
  69. foreach ( (array)$submenu['edit.php?post_type='.EM_POST_TYPE_EVENT] as $key => $submenu_item ) {
  70. if ( $submenu_item[2] == 'edit.php?post_type=event-recurring' ){
  71. $submenu['edit.php?post_type='.EM_POST_TYPE_EVENT][$key][0] = $submenu['edit.php?post_type='.EM_POST_TYPE_EVENT][$key][0]. $events_recurring_num;
  72. break;
  73. }
  74. }
  75. }
  76. /* Hack! Add location/recurrence isn't possible atm so this is a workaround */
  77. global $_wp_submenu_nopriv;
  78. if( $pagenow == 'post-new.php' && !empty($_REQUEST['post_type']) ){
  79. if( $_REQUEST['post_type'] == EM_POST_TYPE_LOCATION && !empty($_wp_submenu_nopriv['edit.php']['post-new.php']) && current_user_can('edit_locations') ){
  80. unset($_wp_submenu_nopriv['edit.php']['post-new.php']);
  81. }
  82. if( $_REQUEST['post_type'] == 'event-recurring' && !empty($_wp_submenu_nopriv['edit.php']['post-new.php']) && current_user_can('edit_recurring_events') ){
  83. unset($_wp_submenu_nopriv['edit.php']['post-new.php']);
  84. }
  85. }
  86. }
  87. add_action('admin_menu','em_admin_menu');
  88. function em_ms_admin_menu(){
  89. add_menu_page( __('Events Manager','dbem'), __('Events Manager','dbem'), 'activate_plugins', 'events-manager-options', 'em_ms_admin_options_page', plugins_url('includes/images/calendar-16.png', dirname(dirname(__FILE__)).'/events-manager.php') );
  90. add_submenu_page('events-manager-options', __('Update Blogs','dbem'),__('Update Blogs','dbem'), 'activate_plugins', "events-manager-update", 'em_ms_upgrade');
  91. }
  92. add_action('network_admin_menu','em_ms_admin_menu');
  93. function em_admin_init(){
  94. //in MS global mode and locations are stored in the main blog, then a user must have at least a subscriber role
  95. if( EM_MS_GLOBAL && is_user_logged_in() && !is_main_site() && get_site_option('dbem_ms_mainblog_locations') ){
  96. EM_Object::ms_global_switch();
  97. $user = new WP_User(get_current_user_id());
  98. if( count($user->roles) == 0 ){
  99. $user->set_role('subscriber');
  100. }
  101. EM_Object::ms_global_switch_back();
  102. }
  103. }
  104. add_action('admin_init','em_admin_init');
  105. /**
  106. * Generate warnings and notices in the admin area
  107. */
  108. function em_admin_warnings() {
  109. global $EM_Notices;
  110. //If we're editing the events page show hello to new user
  111. $events_page_id = get_option ( 'dbem_events_page' );
  112. $dismiss_link_joiner = ( count($_GET) > 0 ) ? '&amp;':'?';
  113. if( current_user_can('activate_plugins') ){
  114. //New User Intro
  115. if (isset ( $_GET ['disable_hello_to_user'] ) && $_GET ['disable_hello_to_user'] == 'true'){
  116. // Disable Hello to new user if requested
  117. update_option('dbem_hello_to_user',0);
  118. }elseif ( get_option ( 'dbem_hello_to_user' ) ) {
  119. //FIXME update welcome msg with good links
  120. $advice = sprintf( __("<p>Events Manager is ready to go! It is highly recommended you read the <a href='%s'>Getting Started</a> guide on our site, as well as checking out the <a href='%s'>Settings Page</a>. <a href='%s' title='Don't show this advice again'>Dismiss</a></p>", 'dbem'), 'http://wp-events-plugin.com/documentation/getting-started/?utm_source=em&utm_medium=plugin&utm_content=installationlink&utm_campaign=plugin_links', EM_ADMIN_URL .'&amp;page=events-manager-options', $_SERVER['REQUEST_URI'].$dismiss_link_joiner.'disable_hello_to_user=true');
  121. ?>
  122. <div id="message" class="updated">
  123. <?php echo $advice; ?>
  124. </div>
  125. <?php
  126. }
  127. //If events page couldn't be created or is missing
  128. if( !empty($_GET['em_dismiss_events_page']) ){
  129. update_option('dbem_dismiss_events_page',1);
  130. }else{
  131. if ( !get_page($events_page_id) && !get_option('dbem_dismiss_events_page') ){
  132. ?>
  133. <div id="em_page_error" class="updated">
  134. <p><?php echo sprintf ( __( 'Uh Oh! For some reason WordPress could not create an events page for you (or you just deleted it). Not to worry though, all you have to do is create an empty page, name it whatever you want, and select it as your events page in your <a href="%s">settings page</a>. Sorry for the extra step! If you know what you are doing, you may have done this on purpose, if so <a href="%s">ignore this message</a>', 'dbem'), EM_ADMIN_URL .'&amp;page=events-manager-options', $_SERVER['REQUEST_URI'].$dismiss_link_joiner.'em_dismiss_events_page=1' ); ?></p>
  135. </div>
  136. <?php
  137. }
  138. }
  139. if( defined('EMP_VERSION') && EMP_VERSION < EM_PRO_MIN_VERSION && !defined('EMP_DISABLE_WARNINGS')){
  140. ?>
  141. <div id="em_page_error" class="updated">
  142. <p><?php _e('There is a newer version of Events Manager Pro which is recommended for this current version of Events Manager as new features have been added. Please go to the plugin website and download the latest update.','dbem'); ?></p>
  143. </div>
  144. <?php
  145. }
  146. if( is_multisite() && !empty($_REQUEST['page']) && $_REQUEST['page']=='events-manager-options' && is_super_admin() && get_option('dbem_ms_update_nag') ){
  147. if( !empty($_GET['disable_dbem_ms_update_nag']) ){
  148. delete_site_option('dbem_ms_update_nag');
  149. }else{
  150. ?>
  151. <div id="em_page_error" class="updated">
  152. <p><?php echo sprintf(__('MultiSite options have moved <a href="%s">here</a>. <a href="%s">Dismiss message</a>','dbem'),admin_url().'network/admin.php?page=events-manager-options', $_SERVER['REQUEST_URI'].'&amp;disable_dbem_ms_update_nag=1'); ?></p>
  153. </div>
  154. <?php
  155. }
  156. }
  157. if( is_super_admin() && get_option('dbem_migrate_images_nag') ){
  158. if( !empty($_GET['disable_dbem_migrate_images_nag']) ){
  159. delete_site_option('dbem_migrate_images_nag');
  160. }else{
  161. ?>
  162. <div id="em_page_error" class="updated">
  163. <p><?php echo sprintf(__('Whilst they will still appear using placeholders, you need to <a href="%s">migrate your location and event images</a> in order for them to appear in your edit forms and media library. <a href="%s">Dismiss message</a>','dbem'),admin_url().'edit.php?post_type=event&page=events-manager-options&em_migrate_images=1&_wpnonce='.wp_create_nonce('em_migrate_images'), em_add_get_params($_SERVER['REQUEST_URI'], array('disable_dbem_migrate_images_nag' => 1))); ?></p>
  164. </div>
  165. <?php
  166. }
  167. }
  168. if( !empty($_REQUEST['page']) && 'events-manager-options' == $_REQUEST['page'] && get_option('dbem_pro_dev_updates') == 1 ){
  169. ?>
  170. <div id="message" class="updated">
  171. <p><?php echo sprintf(__('Dev Mode active: Just a friendly reminder that you are updating to development versions. Only admins see this message, and it will go away when you disable this <a href="#pro-api">here</a> in your settings.','dbem'),'<code>define(\'EMP_DEV_UPDATES\',true);</code>'); ?></p>
  172. </div>
  173. <?php
  174. }
  175. if( class_exists('SitePress') && !class_exists('EM_WPML') && !get_site_option('disable_em_wpml_warning') ){
  176. if( !empty($_REQUEST['disable_em_wpml_warning']) ){
  177. update_site_option('disable_em_wpml_warning',1);
  178. }else{
  179. ?>
  180. <div id="message" class="updated">
  181. <p><?php echo sprintf(__('It looks like you have WPML enabled on your site. We advise you also install our extra <a href="%s">Events Manager WPML Connector</a> plugin which helps the two work better together. <a href="%s">Dismiss message</a>','dbem'),'http://wordpress.org/extend/plugins/events-manager-wpml/', add_query_arg(array('disable_em_wpml_warning'=>1))); ?></p>
  182. </div>
  183. <?php
  184. }
  185. }
  186. }
  187. //Warn about EM page edit
  188. if ( preg_match( '/(post|page).php/', $_SERVER ['SCRIPT_NAME']) && isset ( $_GET ['action'] ) && $_GET ['action'] == 'edit' && isset ( $_GET ['post'] ) && $_GET ['post'] == "$events_page_id") {
  189. $message = sprintf ( __ ( "This page corresponds to the <strong>Events Manager</strong> %s page. Its content will be overriden by Events Manager, although if you include the word CONTENTS (exactly in capitals) and surround it with other text, only CONTENTS will be overwritten. If you want to change the way your events look, go to the <a href='%s'>settings</a> page. ", 'dbem' ), __('Events','dbem'), EM_ADMIN_URL .'&amp;page=events-manager-options' );
  190. $notice = "<div class='error'><p>$message</p></div>";
  191. echo $notice;
  192. }
  193. echo $EM_Notices;
  194. }
  195. add_action ( 'admin_notices', 'em_admin_warnings', 100 );
  196. /**
  197. * Settings link in the plugins page menu
  198. * @param array $links
  199. * @param string $file
  200. * @return array
  201. */
  202. function em_plugin_action_links($actions, $file, $plugin_data) {
  203. $new_actions = array();
  204. $new_actions[] = sprintf( '<a href="'.EM_ADMIN_URL.'&amp;page=events-manager-options">%s</a>', __('Settings', 'dbem') );
  205. $new_actions = array_merge($new_actions, $actions);
  206. if( is_multisite() ){
  207. $uninstall_url = admin_url().'network/admin.php?page=events-manager-options&amp;action=uninstall&amp;_wpnonce='.wp_create_nonce('em_uninstall_'.get_current_user_id().'_wpnonce');
  208. }else{
  209. $uninstall_url = EM_ADMIN_URL.'&amp;page=events-manager-options&amp;action=uninstall&amp;_wpnonce='.wp_create_nonce('em_uninstall_'.get_current_user_id().'_wpnonce');
  210. }
  211. $new_actions[] = '<span class="delete"><a href="'.$uninstall_url.'" class="delete">'.__('Uninstall','dbem').'</a></span>';
  212. return $new_actions;
  213. }
  214. add_filter( 'plugin_action_links_events-manager/events-manager.php', 'em_plugin_action_links', 10, 3 );
  215. //Updates and Dev versions
  216. function em_updates_check( $transient ) {
  217. // Check if the transient contains the 'checked' information
  218. if( empty( $transient->checked ) )
  219. return $transient;
  220. //only bother if we're checking for dev versions
  221. if( get_option('em_check_dev_version') || get_option('dbem_pro_dev_updates') ){
  222. //check WP repo for trunk version
  223. $request = wp_remote_get('http://plugins.svn.wordpress.org/events-manager/trunk/events-manager.php');
  224. if( !is_wp_error($request) ){
  225. preg_match('/Version: ([0-9a-z\.]+)/', $request['body'], $matches);
  226. if( !empty($matches[1]) ){
  227. //we have a version number!
  228. if( version_compare($transient->checked[EM_SLUG], $matches[1]) < 0) {
  229. $response = new stdClass();
  230. $response->slug = EM_SLUG;
  231. $response->new_version = $matches[1] ;
  232. $response->url = 'http://wordpress.org/extend/plugins/events-manager/';
  233. $response->package = 'http://downloads.wordpress.org/plugin/events-manager.zip';
  234. $transient->response[EM_SLUG] = $response;
  235. }
  236. }
  237. }
  238. delete_option('em_check_dev_version');
  239. }
  240. return $transient;
  241. }
  242. add_filter('pre_set_site_transient_update_plugins', 'em_updates_check'); // Hook into the plugin update check and mod for dev version
  243. function em_user_action_links( $actions, $user ){
  244. if ( !is_network_admin() && current_user_can( 'manage_others_bookings' ) ){
  245. if( get_option('dbem_edit_bookings_page') && (!is_admin() || !empty($_REQUEST['is_public'])) ){
  246. $my_bookings_page = get_permalink(get_option('dbem_edit_bookings_page'));
  247. $bookings_link = em_add_get_params($my_bookings_page, array('person_id'=>$user->ID), false);
  248. }else{
  249. $bookings_link = EM_ADMIN_URL. "&page=events-manager-bookings&person_id=".$user->ID;
  250. }
  251. $actions['bookings'] = "<a href='$bookings_link'>" . __( 'Bookings','dbem' ) . "</a>";
  252. }
  253. return $actions;
  254. }
  255. add_filter('user_row_actions','em_user_action_links',10,2);
  256. ?>