title = awpcp_admin_page_title(); $this->menu = _x('Classifieds', 'awpcp admin menu', 'another-wordpress-classifieds-plugin'); // not a page, but an extension to the Users table $this->users = new AWPCP_AdminUsers(); $this->home = new AWPCP_AdminHome(); $this->upgrade = new AWPCP_AdminUpgrade(false, false, $this->menu); $this->settings = new AWPCP_Admin_Settings(); $this->credit_plans = new AWPCP_AdminCreditPlans(); // $this->categories = new AWPCP_AdminCategories(); $this->fees = new AWPCP_AdminFees(); $this->listings = new AWPCP_Admin_Listings(); $this->importer = awpcp_admin_csv_importer(); $this->debug = new AWPCP_Admin_Debug(); $this->uninstall = new AWPCP_Admin_Uninstall(); add_action('wp_ajax_disable-quick-start-guide-notice', array($this, 'disable_quick_start_guide_notice')); add_action('wp_ajax_disable-widget-modification-notice', array($this, 'disable_widget_modification_notice')); add_action('admin_init', array($this, 'init')); add_action('admin_enqueue_scripts', array($this, 'scripts')); add_action('admin_menu', array($this, 'menu')); add_action('admin_notices', array($this, 'notices')); add_action( 'awpcp-admin-notices', array( $this, 'check_duplicate_page_names' ) ); add_filter( 'plugin_action_links', array( $this, 'add_settings_link' ),10, 2 ); // make sure AWPCP admins (WP Administrators and/or Editors) can edit settings add_filter('option_page_capability_awpcp-options', 'awpcp_admin_capability'); // hook filter to output Admin panel sidebar. To remove the sidebar // just remove this action add_filter('awpcp-admin-sidebar', 'awpcp_admin_sidebar_output', 10, 2); } public function notices() { if ( ! awpcp_current_user_is_admin() ) { return; } if ( awpcp_request_param( 'page', false ) == 'awpcp-admin-upgrade' ) { return; } if ( awpcp()->manual_upgrades->has_pending_tasks() ) { ob_start(); include( AWPCP_DIR . '/admin/templates/admin-pending-manual-upgrade-notice.tpl.php' ); $html = ob_get_contents(); ob_end_clean(); echo $html; return; } $show_quick_start_quide_notice = get_awpcp_option( 'show-quick-start-guide-notice' ); $show_drip_autoresponder = get_awpcp_option( 'show-drip-autoresponder' ); if ( $show_quick_start_quide_notice && is_awpcp_admin_page() && ! $show_drip_autoresponder ) { ob_start(); include(AWPCP_DIR . '/admin/templates/admin-quick-start-guide-notice.tpl.php'); $html = ob_get_contents(); ob_end_clean(); echo $html; } if (get_awpcp_option('show-widget-modification-notice')) { ob_start(); include(AWPCP_DIR . '/admin/templates/admin-widget-modification-notice.tpl.php'); $html = ob_get_contents(); ob_end_clean(); echo $html; } do_action( 'awpcp-admin-notices' ); } /** * Add settings link on plugins page * * @author Aman Saini * @since 3.6.5 * @param Array $links * @param String $file */ public function add_settings_link( $links, $file ){ $settings_link = '' . esc_html__( 'Settings', 'another-wordpress-classifieds-plugin' ) . ''; if ( $file == 'another-wordpress-classifieds-plugin/awpcp.php' ){ array_unshift( $links, $settings_link ); } return $links; } /** * Shows a notice if any of the AWPCP pages shares its name with the * dynamic page View Categories. * * If a page share its name with the View Categories page, that page * will become unreachable. * * @since 3.0.2 */ public function check_duplicate_page_names() { global $wpdb; $view_categories_option = 'view-categories-page-name'; $view_categories = sanitize_title( awpcp_get_page_name( $view_categories_option ) ); $view_categories_url = awpcp_get_view_categories_url(); $duplicates = array(); $awpcp_pages = array(); $wp_pages = array(); $posts = get_posts( array( 'post_type' => 'page', 'name' => $view_categories ) ); foreach ( $posts as $post ) { if ( $view_categories_url == get_permalink( $post->ID ) ) { $duplicates[] = $post; } } $pages = empty( $duplicates ) ? array() : awpcp_get_plugin_pages_refs(); foreach ( $duplicates as $page ) { if ( isset( $pages[ $page->ID ] ) ) { $awpcp_pages[] = ucwords( awpcp()->settings->get_option_label( $pages[ $page->ID ]->page ) ); } else { $wp_pages[] = $page->post_title; } } if ( !empty( $awpcp_pages ) || !empty( $wp_pages ) ) { $view_categories_label = awpcp()->settings->get_option_label( $view_categories_option ); $view_categories_label = sprintf( '%s', ucwords( $view_categories_label ) ); } if ( !empty( $awpcp_pages ) ) { $duplicated_pages = '' . join( ', ', $awpcp_pages ) . ''; $message = _n( '%1$s has the same name as the %2$s. That will cause %1$s to become unreachable. Please make sure you don\'t have duplicate page names.', '%1$s have the same name as the %2$s. That will cause %1$s to become unreachable. Please make sure you don\'t have duplicate page names.', count( $awpcp_pages), 'another-wordpress-classifieds-plugin' ); $message = sprintf( $message, $duplicated_pages, $view_categories_label ); echo awpcp_print_error( $message ); } if ( !empty( $wp_pages ) ) { $duplicated_pages = '' . join( ', ', $wp_pages ) . ''; $message = _n( 'Page %1$s has the same name as the AWPCP %2$s. That will cause WordPress page %1$s to become unreachable. The %2$s is dynamic; you don\'t need to create a real WordPress page to show the list of cateogries, the plugin will generate it for you. If the WordPress page was created to show the default list of AWPCP categories, you can delete it and this error message will go away. Otherwise, please make sure you don\'t have duplicate page names.', 'Pages %1$s have the same name as the AWPCP %2$s. That will cause WordPress pages %1$s to become unreachable. The %2$s is dynamic; you don\'t need to create a real WordPress page to show the list of cateogries, the plugin will generate it for you. If the WordPress pages were created to show the default list of AWPCP categories, you can delete them and this error message will go away. Otherwise, please make sure you don\'t have duplicate page names.', count( $wp_pages), 'another-wordpress-classifieds-plugin' ); $message = sprintf( $message, $duplicated_pages, $view_categories_label ); echo awpcp_print_error( $message ); } } public function init() { add_filter( 'parent_file', array( $this, 'parent_file' ) ); // This functions were executed on plugins_loaded. However, // to avoid execution of AWPCP functions without propperly // upgrading the plugin database, we execute them here, only // after AWPCP_Admin has been instatiated by AWPCP. awpcp_handle_admin_requests(); } public function scripts() { } private function get_manage_credits_section_url() { $full_url = add_query_arg( 'action', 'awpcp-manage-credits', admin_url( 'users.php' ) ); $domain = awpcp_request()->domain(); $domain_position = strpos( $full_url, $domain ); return substr( $full_url, $domain_position + strlen( $domain ) ); } /** * A hack to show the WP Users associated to a submenu under * Classifieds menu. * * @since 3.0.2 */ public function parent_file($parent_file) { global $current_screen, $submenu_file, $typenow; if ( $current_screen->base == 'users' && awpcp_request_param( 'action' ) == 'awpcp-manage-credits' ) { // make Classifieds menu the current menu $parent_file = 'awpcp.php'; // highlight Manage Credits submenu in Classifieds menu $submenu_file = $this->get_manage_credits_section_url(); // make $typenow non empty so Users menu is not highlighted // in _wp_menu_output, despite the fact we are showing the // All Users page. $typenow = 'hide-users-menu'; } return $parent_file; } public function menu() { global $submenu; global $hasregionsmodule; global $hasextrafieldsmodule; $capability = awpcp_admin_capability(); if ( awpcp()->manual_upgrades->has_pending_tasks() ) { $parts = array($this->upgrade->title, $this->upgrade->menu, $this->upgrade->page); $page = add_menu_page($parts[0], $parts[1], $capability, $parts[2], array($this->upgrade, 'dispatch'), MENUICO); add_action('admin_print_styles-' . $page, array($this->upgrade, 'scripts')); } else { $parent = $this->home->page; $parts = array($this->home->title, $this->home->menu, $this->home->page); $page = add_menu_page($parts[0], $parts[1], $capability, $parts[2], array($this->home, 'dispatch'), MENUICO); // add hidden upgrade page, so the URL works even if there are no // pending manual upgrades please note that this is a hack and // it is important to use a subpage as parent page for it to work $parts = array($this->title, $this->menu, $this->upgrade->page); $page = add_submenu_page('awpcp-admin-uninstall', $parts[0], $parts[1], $capability, $parts[2], array($this->home, 'dispatch'), MENUICO); $page = add_submenu_page( $parent, awpcp_admin_page_title( __( 'Settings', 'another-wordpress-classifieds-plugin' ) ), __( 'Settings', 'another-wordpress-classifieds-plugin' ), $capability, 'awpcp-admin-settings', array( $this->settings, 'dispatch' ) ); add_action('admin_print_styles-' . $page, array($this->settings, 'scripts')); $parts = array($this->credit_plans->title, $this->credit_plans->menu, $this->credit_plans->page); $page = add_submenu_page($parent, $parts[0], $parts[1], $capability, $parts[2], array($this->credit_plans, 'dispatch')); add_action('admin_print_styles-' . $page, array($this->credit_plans, 'scripts')); if ( current_user_can( $capability ) ) { $url = $this->get_manage_credits_section_url(); $submenu['awpcp.php'][] = array( __( 'Manage Credit', 'another-wordpress-classifieds-plugin' ), $capability, $url ); } $parts = array($this->fees->title, $this->fees->menu, $this->fees->page); $page = add_submenu_page($parent, $parts[0], $parts[1], $capability, $parts[2], array($this->fees, 'dispatch')); add_action('admin_print_styles-' . $page, array($this->fees, 'scripts')); add_submenu_page( $parent, awpcp_admin_page_title( __( 'Manage Categories', 'another-wordpress-classifieds-plugin' ) ), __( 'Categories', 'another-wordpress-classifieds-plugin' ), $capability, 'awpcp-admin-categories', 'awpcp_opsconfig_categories' ); $page = add_submenu_page( $parent, $this->listings->title, $this->listings->menu, 'manage_classifieds_listings', 'awpcp-listings', array( $this->listings, 'dispatch' ) ); add_action('admin_print_styles-' . $page, array($this->listings, 'scripts')); $this->form_fields = awpcp_form_fields_admin_page(); $parts = array( $this->form_fields->title, $this->form_fields->menu, $this->form_fields->page ); $page = add_submenu_page( $parent, $parts[0], $parts[1], $capability, 'awpcp-form-fields', array( $this->form_fields, 'dispatch' ) ); add_action( 'admin_print_styles-' . $page, array( $this->form_fields, 'scripts' ) ); // allow plugins to define additional sub menu entries do_action('awpcp_admin_add_submenu_page', $parent, $capability); if ($hasextrafieldsmodule) { add_submenu_page($parent, __('Manage Extra Fields', 'another-wordpress-classifieds-plugin'), __('Extra Fields', 'another-wordpress-classifieds-plugin'), $capability, 'Configure5', 'awpcp_add_new_field'); } $hook = add_submenu_page($parent, __('Import Ad', 'another-wordpress-classifieds-plugin'), __('Import', 'another-wordpress-classifieds-plugin'), $capability, 'awpcp-import', array($this->importer, 'dispatch')); add_action("load-{$hook}", array($this->importer, 'scripts')); add_submenu_page($parent, __( 'Debug', 'another-wordpress-classifieds-plugin' ), __( 'Debug', 'another-wordpress-classifieds-plugin' ), $capability, 'awpcp-debug', array($this->debug, 'dispatch')); $parts = array($this->uninstall->title, $this->uninstall->menu, $this->uninstall->page); add_submenu_page($parent, $parts[0], $parts[1], $capability, $parts[2], array($this->uninstall, 'dispatch')); // allow plugins to define additional menu entries do_action('awpcp_add_menu_page'); } } public function upgrade() { global $plugin_page; if (!isset($this->upgrade) && isset($this->pages[$plugin_page])) $this->upgrade = new AWPCP_AdminUpgrade($plugin_page, $this->pages[$plugin_page]); return $this->upgrade->dispatch(); } public function disable_quick_start_guide_notice() { global $awpcp; $awpcp->settings->update_option('show-quick-start-guide-notice', false); die('Success!'); } public function disable_widget_modification_notice() { global $awpcp; $awpcp->settings->update_option('show-widget-modification-notice', false); die('Success!'); } } // // if there's a page name collision remove AWPCP menus so that nothing can be accessed // add_action('init', 'awpcp_pagename_warning_check', -1); // function awpcp_pagename_warning_check() { // if (!get_option('awpcp_pagename_warning', false)) { // return; // } // remove_action('admin_menu', 'awpcp_launch'); // } // // display a warning if necessary // add_action('admin_notices', 'awpcp_pagename_warning', 10); // function awpcp_pagename_warning() { // if (!get_option('awpcp_pagename_warning', false)) { // return; // } // echo '

'; // echo 'WARNING: A page named AWPCP already exists. You must either delete that page and its subpages, or rename them before continuing with the plugin configuration.'; // echo '

'; // } // START FUNCTION: Check if the user side classified page exists function checkifclassifiedpage($pagename) { global $wpdb; $id = awpcp_get_page_id_by_ref( 'main-page-name' ); $query = 'SELECT ID FROM ' . $wpdb->posts . ' WHERE ID = %d'; $page_id = intval( $wpdb->get_var( $wpdb->prepare( $query, $id ) ) ); return $page_id === $id; } function awpcp_home_screen() { global $awpcp_db_version; global $awpcp_imagesurl; global $hasextrafieldsmodule, $extrafieldsversioncompatibility; global $message; // check if there is a duplicate page conflict $main_page_name = get_awpcp_option('main-page-name'); $page_conflict = checkforduplicate(add_slashes_recursive(sanitize_title($main_page_name))); ob_start(); include(AWPCP_DIR . '/admin/templates/admin-panel-home.tpl.php'); $content = ob_get_contents(); ob_end_clean(); echo $content; } function awpcp_get_categories_hierarchy() { $categories = AWPCP_Category::query(); $hierarchy = array(); foreach ( $categories as $category ) { if ( $category->parent > 0 ) { if ( !isset( $hierarchy[ $category->parent ] ) ) { $hierarchy[ $category->parent ] = array(); } $hierarchy[ $category->parent ][] = $category->id; } } return $hierarchy; } function awpcp_admin_categories_render_category_items($categories, &$children, $start=0, $per_page=10, &$count, $parent=0, $level=0) { $end = $start + $per_page; $items = array(); foreach ($categories as $key => $category) { if ( $count >= $end ) break; if ( $category->parent != $parent ) continue; if ( $count == $start && $category->parent > 0 ) { $category_parent = AWPCP_Category::find_by_id( $category->parent ); $items[] = awpcp_admin_categories_render_category_item( $category_parent, $level - 1, $start, $per_page ); } if ( $count >= $start ) { $items[] = awpcp_admin_categories_render_category_item( $category, $level, $start, $per_page ); } $count++; if ( isset( $children[ $category->id ] ) ) { $_children = awpcp_admin_categories_render_category_items( $categories, $children, $start, $per_page, $count, $category->id, $level + 1 ); $items = array_merge( $items, $_children ); } } return $items; } function awpcp_admin_categories_render_category_item($category, $level, $start, $per_page) { global $hascaticonsmodule, $awpcp_imagesurl; if ( function_exists( 'awpcp_get_category_icon' ) ) { $category_icon = awpcp_get_category_icon( $category ); } if ( isset( $category_icon ) && !empty( $category_icon ) && function_exists( 'awpcp_category_icon_url' ) ) { $caticonsurl = awpcp_category_icon_url( $category_icon ); $thecategoryicon = '%s'; $thecategoryicon = sprintf( $thecategoryicon, esc_url( $caticonsurl ), esc_attr( $category->name ) ); } else { $thecategoryicon = ''; } $params = array( 'page' => 'awpcp-admin-categories', 'cat_ID' => $category->id ); $admin_listings_url = add_query_arg( urlencode_deep( $params ), admin_url( 'admin.php' ) ); $thecategory_parent_id = $category->parent; $thecategory_parent_name = stripslashes(get_adparentcatname($thecategory_parent_id)); $thecategory_order = $category->order ? $category->order : 0; $thecategory_name = sprintf( '%s%s%s', str_repeat( '— ', $level ), $thecategoryicon, esc_url( $admin_listings_url ), esc_attr( stripslashes( $category->name ) ) ); $totaladsincat = total_ads_in_cat( $category->id ); $params = array( 'cat_ID' => $category->id, 'offset' => $start, 'results' => $per_page ); $admin_categories_url = add_query_arg( urlencode_deep( $params ), awpcp_get_admin_categories_url() ); if ($hascaticonsmodule == 1 && is_installed_category_icon_module()) { $url = esc_url( add_query_arg( 'action', 'managecaticon', $admin_categories_url ) ); $managecaticon = "\"";"; } else { $managecaticon = ''; } $awpcpeditcategoryword = __("Edit Category",'another-wordpress-classifieds-plugin'); $awpcpdeletecategoryword = __("Delete Category",'another-wordpress-classifieds-plugin'); $row = ''; $row.= '' . $category->id . ''; $row.= ""; $row.= "$thecategory_parent_name"; $row.= "$thecategory_order"; $row.= ""; $url = esc_url( add_query_arg( 'action', 'editcat', $admin_categories_url ) ); $row.= "\"$awpcpeditcategoryword\""; $url = esc_url( add_query_arg( 'action', 'delcat', $admin_categories_url ) ); $row.= "\"$awpcpdeletecategoryword\""; $row.= $managecaticon; $row.= ""; $row.= ""; return $row; } function awpcp_opsconfig_categories() { global $wpdb, $message, $awpcp_imagesurl, $clearform, $hascaticonsmodule; $cpagename_awpcp = get_awpcp_option('main-page-name'); $awpcppagename = sanitize_title($cpagename_awpcp); $action=''; $output = ''; $tbl_ad_categories = $wpdb->prefix . "awpcp_categories"; $offset=(isset($_REQUEST['offset'])) ? (clean_field($_REQUEST['offset'])) : ($offset=0); $results=(isset($_REQUEST['results']) && !empty($_REQUEST['results'])) ? clean_field($_REQUEST['results']) : ($results=10); if ( isset( $_REQUEST['results'] ) && !empty( $_REQUEST['results'] ) ) { $results = max( intval( $_REQUEST['results'] ), 5 ); update_user_option( get_current_user_id(), 'awpcp-admin-categories-results', $results ); } else { $results = intval( get_user_option( 'awpcp-admin-categories-results', get_current_user_id() ) ); } if ( empty( $results ) ) { $results = 10; } $cat_ID=''; $category_name=''; $aeaction=''; $category_parent_id=''; $promptmovetocat=''; $aeaction=''; /////////////////// // Check for existence of a category ID and action if ( isset($_REQUEST['editcat']) && !empty($_REQUEST['editcat']) ) { $cat_ID=$_REQUEST['editcat']; $action = "edit"; } elseif ( isset($_REQUEST['delcat']) && !empty($_REQUEST['delcat']) ) { $cat_ID=$_REQUEST['delcat']; $action = "delcat"; } elseif ( isset($_REQUEST['managecaticon']) && !empty($_REQUEST['managecaticon']) ) { $cat_ID=$_REQUEST['managecaticon']; $action = "managecaticon"; } elseif (isset($_REQUEST['cat_ID']) && !empty($_REQUEST['cat_ID'])) { $cat_ID=$_REQUEST['cat_ID']; } if ( !isset($action) || empty($action) ) { if ( isset($_REQUEST['action']) && !empty($_REQUEST['action']) ) { $action=$_REQUEST['action']; } } if ( $action == 'edit' ) { $aeaction='edit'; } if ( $action == 'editcat' ) { $aeaction='edit'; } if ( $action == 'delcat' ) { $aeaction='delete'; } if ( $action == 'managecaticon' ) { $return = apply_filters( 'awpcp-custom-manage-categories-action', '', $cat_ID ); if ( $return ) { return; } } if ( $action == 'setcategoryicon' ) { global $awpcp_plugin_path; if ($hascaticonsmodule == 1) { if (is_installed_category_icon_module()) { if (isset($_REQUEST['cat_ID']) && !empty($_REQUEST['cat_ID'])) { $thecategory_id=$_REQUEST['cat_ID']; } if (isset($_REQUEST['category_icon']) && !empty($_REQUEST['category_icon'])) { $theiconfile=$_REQUEST['category_icon']; } elseif ( isset( $_REQUEST['clear_icon'] ) ) { $theiconfile = null; } else { $theiconfile = ''; } if (isset($_REQUEST['offset']) && !empty($_REQUEST['offset'])) { $offset=$_REQUEST['offset']; } $message=set_category_icon($thecategory_id,$theiconfile,$offset,$results); if (isset($message) && !empty($message)) { $clearform=1; } } } } if (isset($clearform) && ($clearform == 1)) { $action = $aeaction = null; } try { $category = awpcp_categories_collection()->get( $cat_ID ); $category_name = $category->name; $category_order = $category->order; $cat_parent_ID = $category->parent; } catch ( AWPCP_Exception $e ) { $category_name = null; $category_order = null; $cat_parent_ID = null; } $add_label = __( 'Add A New Category', 'another-wordpress-classifieds-plugin' ); $add_url = awpcp_get_admin_categories_url(); $addnewlink = '%1$s'; $addnewlink = sprintf( $addnewlink, $add_label, $add_url ); if ($aeaction == 'edit') { $aeword1=__("You are currently editing the category shown below",'another-wordpress-classifieds-plugin'); $aeword2=__("Save Category Changes",'another-wordpress-classifieds-plugin'); $aeword3=__("Parent Category",'another-wordpress-classifieds-plugin'); $aeword4=__("Category List Order",'another-wordpress-classifieds-plugin'); } elseif ($aeaction == 'delete') { if ( $cat_ID != 1) { $aeword1=__("If you're sure that you want to delete this category please press the delete button",'another-wordpress-classifieds-plugin'); $aeword2=__("Delete Category",'another-wordpress-classifieds-plugin'); $aeword3=__("Parent Category",'another-wordpress-classifieds-plugin'); $aeword4=''; if (ads_exist_cat($cat_ID)) { if ( category_is_child($cat_ID) ) { $movetocat=get_cat_parent_ID($cat_ID); } else { $movetocat=1; } try { $move_to_category = awpcp_categories_collection()->get( $movetocat ); $movetoname = $move_to_category->name; } catch ( AWPCP_Exception $e ) { $movetoname = __( 'Untitled', 'another-wordpress-classifieds-plugin' ); } $promptmovetocat="

"; $promptmovetocat.=__("The category contains ads. If you do not select a category to move them to the ads will be moved to:",'another-wordpress-classifieds-plugin'); $promptmovetocat.="$movetoname

"; try { $move_to_category = awpcp_categories_collection()->get( 1 ); $defaultcatname = $move_to_category->name; } catch ( AWPCP_Exception $e ) { $defaultcatname = __( 'Untitled', 'another-wordpress-classifieds-plugin' ); } if (category_has_children($cat_ID)) { $promptmovetocat.="

"; $promptmovetocat.=__("The category also has children. If you do not specify a move-to category the children will be adopted by",'another-wordpress-classifieds-plugin'); $promptmovetocat.="$defaultcatname

"; $promptmovetocat.=__("Note",'another-wordpress-classifieds-plugin'); $promptmovetocat.=":"; $promptmovetocat.=__("The move-to category specified applies to both ads and categories",'another-wordpress-classifieds-plugin'); $promptmovetocat.="

"; } $promptmovetocat.="

"; } $thecategoryparentname=get_adparentcatname($cat_parent_ID); } else { $aeword1 = __( 'Sorry but you cannot delete %s. It is the default category and the default category cannot be deleted.', 'another-wordpress-classifieds-plugin' ); $aeword1 = sprintf( $aeword1, '' . $category_name . '' ); $aeword2=''; $aeword3=''; $aeword4=''; } } else { if ( empty($aeaction) ) { $aeaction="newcategory"; } $aeword1 = __( 'Add a new category', 'another-wordpress-classifieds-plugin' ); $aeword2=__( 'Add new category', 'another-wordpress-classifieds-plugin' ); $aeword3=__( 'List category under', 'another-wordpress-classifieds-plugin' ); $aeword4=__( 'Category list order', 'another-wordpress-classifieds-plugin' ); $addnewlink = ''; } if ($aeaction == 'delete') { $section_icon_style = "background:transparent url($awpcp_imagesurl/edit_ico.png) left center no-repeat;padding-left:20px;"; $categorynamefield = ''; $exclude = ''; $orderinput=''; if ($cat_ID == 1) { $categorynameinput=''; $selectinput=''; } else { $categorynameinput=""; $categorynameinput.=__("Category to Delete",'another-wordpress-classifieds-plugin'); $categorynameinput.=": $category_name"; $selectinput="

$thecategoryparentname

"; $submitbuttoncode=""; } } elseif ($aeaction == 'edit') { $section_icon_style = "background:transparent url($awpcp_imagesurl/edit_ico.png) left center no-repeat;padding-left:20px;"; $categorynameinput = __("Category to Edit",'another-wordpress-classifieds-plugin'); $categorynameinput.=": $category_name "; $categorynamefield = ""; $selectinput=""; $categories= get_categorynameid($cat_ID,$cat_parent_ID,$exclude=''); $selectinput.="$categories "; $submitbuttoncode=""; } else { $section_icon_style = "background:transparent url($awpcp_imagesurl/post_ico.png) left center no-repeat;padding-left:20px;"; $categorynameinput = __( 'Enter the category name', 'another-wordpress-classifieds-plugin' ); $categorynamefield =""; $selectinput=""; $categories= get_categorynameid($cat_ID,$cat_parent_ID,$exclude=''); $selectinput.="$categories "; $submitbuttoncode=""; } // Start the page display $output .= "

"; $output .= awpcp_admin_page_title( __( 'Manage Categories', 'another-wordpress-classifieds-plugin' ) ); $output .= "

"; if (isset($message) && !empty($message)) { $output .= $message; } $sidebar = awpcp_admin_sidebar(); $output .= $sidebar; if (empty($sidebar)) { $output .= "
"; } else { $output .= "
"; } $output .= ""; $output .= __("Icon Meanings",'another-wordpress-classifieds-plugin'); $output .= ":    \"";"; $output .= __("Edit Category",'another-wordpress-classifieds-plugin'); $output .= "    \"";"; $output .= __("Delete Category",'another-wordpress-classifieds-plugin'); if ($hascaticonsmodule == 1 && is_installed_category_icon_module() ) { $label = __("Manage Category Icon", 'another-wordpress-classifieds-plugin'); $output .= "    \"";"; $output .= $label; } $output .= "
"; if (empty($sidebar)) { $output .= "

"; } else { $output .= "

"; } $output .= "
$aeword1
$categorynameinput $aeword3 $aeword4
$categorynamefield $selectinput $orderinput
$promptmovetocat
$submitbuttoncode $addnewlink
"; if (empty($sidebar)) { $output .= "

"; } else { $output .= "

"; } /////////////////////////// // Show the paginated categories list for management ////////////////////////// $where="category_name <> ''"; $pager1=create_pager( AWPCP_TABLE_CATEGORIES, $where,$offset,$results,$tpname=''); $pager2=create_pager( AWPCP_TABLE_CATEGORIES, $where,$offset,$results,$tpname=''); $output .= "$pager1

"; $output .= __( 'Delete categories should do this with existing Ads', 'another-wordpress-classifieds-plugin' ); $output .= ": "; $output .= "

"; $children = awpcp_get_categories_hierarchy(); $categories = AWPCP_Category::query( array( 'orderby' => 'category_order, category_name', 'order' => 'ASC', ) ); $count = 0; $items = awpcp_admin_categories_render_category_items( $categories, $children, $offset, $results, $count ); $opentable=''; $opentable.=''; $opentable.=""; $closetable=''; $closetable.=''; $closetable.='
' . __('Category ID', 'another-wordpress-classifieds-plugin') . '"; $opentable.=__("Parent",'another-wordpress-classifieds-plugin'); $opentable.=""; $opentable.=__("Order",'another-wordpress-classifieds-plugin'); $opentable.=""; $opentable.=__("Action",'another-wordpress-classifieds-plugin'); $opentable.="
' . __('Category ID', 'another-wordpress-classifieds-plugin') . ''; $closetable.=__("Category Name (Total Ads)",'another-wordpress-classifieds-plugin'); $closetable.=""; $closetable.=__("Parent",'another-wordpress-classifieds-plugin'); $closetable.=""; $closetable.=__("Order",'another-wordpress-classifieds-plugin'); $closetable.=""; $closetable.=__("Action",'another-wordpress-classifieds-plugin'); $closetable.="
"; $theitems=smart_table2($items,intval($results/$results),$opentable,$closetable, false); $showcategories="$theitems"; $output .= " $showcategories
$pager2
"; echo $output; } function awpcp_pages() { $pages = array('main-page-name' => array(get_awpcp_option('main-page-name'), '[AWPCP]')); return $pages + awpcp_subpages(); } function awpcp_subpages() { $pages = array( 'show-ads-page-name' => array(get_awpcp_option('show-ads-page-name'), '[AWPCPSHOWAD]'), 'reply-to-ad-page-name' => array(get_awpcp_option('reply-to-ad-page-name'), '[AWPCPREPLYTOAD]'), 'edit-ad-page-name' => array(get_awpcp_option('edit-ad-page-name'), '[AWPCPEDITAD]'), 'place-ad-page-name' => array(get_awpcp_option('place-ad-page-name'), '[AWPCPPLACEAD]'), 'renew-ad-page-name' => array(get_awpcp_option('renew-ad-page-name'), '[AWPCP-RENEW-AD]'), 'browse-ads-page-name' => array(get_awpcp_option('browse-ads-page-name'), '[AWPCPBROWSEADS]'), 'search-ads-page-name' => array(get_awpcp_option('search-ads-page-name'), '[AWPCPSEARCHADS]'), 'payment-thankyou-page-name' => array(get_awpcp_option('payment-thankyou-page-name'), '[AWPCPPAYMENTTHANKYOU]'), 'payment-cancel-page-name' => array(get_awpcp_option('payment-cancel-page-name'), '[AWPCPCANCELPAYMENT]') ); $pages = apply_filters('awpcp_subpages', $pages); return $pages; } function awpcp_create_pages($awpcp_page_name, $subpages=true) { global $wpdb; $refname = 'main-page-name'; $date = date("Y-m-d"); // create AWPCP main page if it does not exist if (!awpcp_find_page($refname)) { $awpcp_page = array( 'post_author' => 1, 'post_date' => $date, 'post_date_gmt' => $date, 'post_content' => '[AWPCPCLASSIFIEDSUI]', 'post_title' => add_slashes_recursive($awpcp_page_name), 'post_status' => 'publish', 'post_name' => sanitize_title($awpcp_page_name), 'post_modified' => $date, 'comments_status' => 'closed', 'post_content_filtered' => '[AWPCPCLASSIFIEDSUI]', 'post_parent' => 0, 'post_type' => 'page', 'menu_order' => 0 ); $id = wp_insert_post($awpcp_page); awpcp_update_plugin_page_id( $refname, $id ); } else { $id = awpcp_get_page_id_by_ref($refname); } // create subpages if ($subpages) { awpcp_create_subpages($id); } } function awpcp_create_subpages($awpcp_page_id) { $pages = awpcp_subpages(); foreach ($pages as $key => $page) { awpcp_create_subpage($key, $page[0], $page[1], $awpcp_page_id); } do_action('awpcp_create_subpage'); } /** * Creates a subpage of the main AWPCP page. * * This functions takes care of checking if the main AWPCP * page exists, finding its id and verifying that the new * page doesn't exist already. Useful for module plugins. */ function awpcp_create_subpage($refname, $name, $shortcode, $awpcp_page_id=null) { global $wpdb; $id = 0; if (!empty($name)) { // it is possible that the main AWPCP page does not exist, in that case // we should create Subpages without a parent. if (is_null($awpcp_page_id) && awpcp_find_page('main-page-name')) { $awpcp_page_id = awpcp_get_page_id_by_ref('main-page-name'); } else if (is_null(($awpcp_page_id))) { $awpcp_page_id = ''; } if (!awpcp_find_page($refname)) { $id = maketheclassifiedsubpage($name, $awpcp_page_id, $shortcode); } } if ($id > 0) { awpcp_update_plugin_page_id( $refname, $id ); } return $id; } function maketheclassifiedsubpage( $page_name, $parent_page_id, $short_code ) { $post_date = date("Y-m-d"); $parent_page_id = intval( $parent_page_id ); $post_name = sanitize_title( $page_name ); $page_name = add_slashes_recursive( $page_name ); $page_id = wp_insert_post( array( 'post_date' => $post_date, 'post_date_gmt' => $post_date, 'post_title' => $page_name, 'post_content' => $short_code, 'post_status' => 'publish', 'comment_status' => 'closed', 'post_name' => $post_name, 'post_modified' => $post_date, 'post_modified_gmt' => $post_date, 'post_content_filtered' => $short_code, 'post_parent' => $parent_page_id, 'post_type' => 'page', ) ); return $page_id; } /** * A function created to wrap code intended to handle * Admin Panel requests. * * The body of this function was in the content of awpcp.php * being executed every time the plugin file was read. * * The part of this function that handles Fees is @deprecated since 2.1.4. * The part of this function that handles Ads is @deprecated since 2.1.4. * The part of this function that handles Categories is still being used. */ function awpcp_handle_admin_requests() { global $wpdb; global $message; if (isset($_REQUEST['createeditadcategory']) && !empty($_REQUEST['createeditadcategory'])) { $tbl_ad_categories = $wpdb->prefix . "awpcp_categories"; $tbl_ads = $wpdb->prefix . "awpcp_ads"; $category_id=clean_field($_REQUEST['category_id']); if (isset($_REQUEST['$movetocat']) && !empty($_REQUEST['$movetocat'])) { $movetocat=clean_field($_REQUEST['movetocat']); } if (isset($_REQUEST['$deletetheads']) && !empty($_REQUEST['$deletetheads'])) { $deletetheads=$_REQUEST['deletetheads']; } $aeaction=clean_field($_REQUEST['aeaction']); if ( $aeaction == 'newcategory' ) { $name = stripslashes_deep( awpcp_request_param( 'category_name' ) ); $parent = intval( awpcp_request_param( 'category_parent_id' ) ); $order = intval( awpcp_request_param( 'category_order' ) ); $category = new AWPCP_Category( null, $name, null, $order, $parent ); try { awpcp_categories_collection()->save( $category ); $themessagetoprint = __( 'The new category was successfully added.', 'another-wordpress-classifieds-plugin' ); } catch ( AWPCP_Exception $e ) { $themessagetoprint = $e->getMessage(); } } elseif ($aeaction == 'delete') { if (isset($_REQUEST['category_name']) && !empty($_REQUEST['category_name'])) { $category_name=clean_field($_REQUEST['category_name']); } if (isset($_REQUEST['category_parent_id']) && !empty($_REQUEST['category_parent_id'])) { $category_parent_id=clean_field($_REQUEST['category_parent_id']); } // Make sure this is not the default category. If it is the default category alert that the default category can only be renamed not deleted if ($category_id == 1) { $themessagetoprint=__("Sorry but you cannot delete the default category. The default category can only be renamed",'another-wordpress-classifieds-plugin'); } else { //Proceed with the delete instructions // Move any ads that the category contains if move-to category value is set and does not equal zero if ( isset($movetocat) && !empty($movetocat) && ($movetocat != 0) ) { $movetocatparent=get_cat_parent_ID($movetocat); $query = 'UPDATE ' . AWPCP_TABLE_ADS . ' SET ad_category_id = %d ad_category_parent_id=%d '; $query.= 'WHERE ad_category_id = %d'; $query = $wpdb->prepare( $query, $movetocat, $movetocatparent, $category_id ); $wpdb->query( $query ); // Must also relocate ads where the main category was a child of the category being deleted $query = 'UPDATE ' . AWPCP_TABLE_ADS . ' SET ad_category_parent_id = %d WHERE ad_category_parent_id = %d'; $query = $wpdb->prepare( $query, $movetocat, $category_id ); $wpdb->query( $query ); // Must also relocate any children categories to the the move-to-cat $query = 'UPDATE ' . AWPCP_TABLE_CATEGORIES . ' SET category_parent_id = %d WHERE category_parent_id = %d'; $wpdb->prepare( $query, $movetocat, $category_id ); $wpdb->query( $query ); } // Else if the move-to value is zero move the ads to the parent category if category is a child or the default category if // category is not a child elseif ( !isset($movetocat) || empty($movetocat) || ($movetocat == 0) ) { // If the category has a parent move the ads to the parent otherwise move the ads to the default if ( category_is_child($category_id) ) { $movetocat=get_cat_parent_ID($category_id); } else { $movetocat=1; } $movetocatparent=get_cat_parent_ID($movetocat); // Adjust any ads transferred from the main category $query="UPDATE ".$tbl_ads." SET ad_category_id='$movetocat', ad_category_parent_id='$movetocatparent' WHERE ad_category_id='$category_id'"; $wpdb->query( $query ); // Must also relocate any children categories to the the move-to-cat $query="UPDATE ".$tbl_ad_categories." SET category_parent_id='$movetocat' WHERE category_parent_id='$category_id'"; $wpdb->query( $query ); // Adjust any ads transferred from children categories $query="UPDATE ".$tbl_ads." SET ad_category_parent_id='$movetocat' WHERE ad_category_parent_id='$category_id'"; $wpdb->query( $query ); } $query = "DELETE FROM " . AWPCP_TABLE_CATEGORIES . " WHERE category_id='$category_id'"; $wpdb->query( $query ); do_action( 'awpcp-category-deleted', $category_id ); $themessagetoprint=__("The category has been deleted",'another-wordpress-classifieds-plugin'); } } elseif ($aeaction == 'edit') { $category = AWPCP_Category::find_by_id( $category_id ); $category->name = stripslashes( awpcp_request_param( 'category_name' ) ); $category->parent = intval( awpcp_request_param( 'category_parent_id' ) ); $category->order = intval( awpcp_request_param( 'category_order', 0 ) ); try { awpcp_categories_collection()->save( $category ); $themessagetoprint = __( 'Your category changes have been saved.', 'another-wordpress-classifieds-plugin' ); } catch ( AWPCP_Exception $e ) { $themessagetoprint = $e->getMessage(); } } else { $themessagetoprint=__("No changes made to categories.",'another-wordpress-classifieds-plugin'); } $message="
$themessagetoprint
"; $clearform=1; } // Move multiple categories if ( isset($_REQUEST['movemultiplecategories']) && !empty($_REQUEST['movemultiplecategories']) ) { $tbl_ad_categories = $wpdb->prefix . "awpcp_categories"; $tbl_ads = $wpdb->prefix . "awpcp_ads"; // First get the array of categories to be deleted $categoriestomove=clean_field($_REQUEST['category_to_delete_or_move']); // Next get the value for where the admin wants to move the ads if ( isset($_REQUEST['moveadstocategory']) && !empty($_REQUEST['moveadstocategory']) && ($_REQUEST['moveadstocategory'] != 0) ) { $moveadstocategory=clean_field($_REQUEST['moveadstocategory']); // Next loop through the categories and move them to the new category foreach($categoriestomove as $cattomove) { if ($cattomove != $moveadstocategory) { // First update all the ads in the category to take on the new parent ID $query = "UPDATE " . AWPCP_TABLE_ADS . " SET ad_category_parent_id='$moveadstocategory' WHERE ad_category_id='$cattomove'"; $wpdb->query( $query ); $query = "UPDATE " . AWPCP_TABLE_CATEGORIES . " SET category_parent_id='$moveadstocategory' WHERE category_id='$cattomove'"; $wpdb->query( $query ); } } $themessagetoprint=__("With the exception of any category that was being moved to itself, the categories have been moved",'another-wordpress-classifieds-plugin'); } else { $themessagetoprint=__("The categories have not been moved because you did not indicate where you want the categories to be moved to",'another-wordpress-classifieds-plugin'); } $message="
$themessagetoprint
"; } // Delete multiple categories if ( isset($_REQUEST['deletemultiplecategories']) && !empty($_REQUEST['deletemultiplecategories']) ) { $tbl_ad_categories = $wpdb->prefix . "awpcp_categories"; $tbl_ads = $wpdb->prefix . "awpcp_ads"; // First get the array of categories to be deleted $categoriestodelete = (array) clean_field($_REQUEST['category_to_delete_or_move']); // Next get the value of move/delete ads if ( isset($_REQUEST['movedeleteads']) && !empty($_REQUEST['movedeleteads']) ) { $movedeleteads=clean_field($_REQUEST['movedeleteads']); } else { $movedeleteads=1; } // Next get the value for where the admin wants to move the ads if ( isset($_REQUEST['moveadstocategory']) && !empty($_REQUEST['moveadstocategory']) && ($_REQUEST['moveadstocategory'] != 0) ) { $moveadstocategory=clean_field($_REQUEST['moveadstocategory']); } else { $moveadstocategory=1; } // Next make sure there is a default category with an ID of 1 because any ads that exist in the // categories will need to be moved to a default category if admin has checked move ads but // has not selected a move to category if ( ($moveadstocategory == 1) && (!(defaultcatexists($defid=1))) ) { createdefaultcategory($idtomake=1,$titletocallit='Untitled'); } // Next loop through the categories and move all their ads foreach($categoriestodelete as $cattodel) { // Make sure this is not the default category which cannot be deleted if ($cattodel != 1) { // If admin has instructed moving ads move the ads if ($movedeleteads == 1) { // Now move the ads if any $movetocat=$moveadstocategory; $movetocatparent=get_cat_parent_ID($movetocat); // Move the ads in the category main $query = "UPDATE " . AWPCP_TABLE_ADS . " SET ad_category_id='$movetocat',ad_category_parent_id='$movetocatparent' WHERE ad_category_id='$cattodel'"; $wpdb->query( $query ); // Must also relocate ads where the main category was a child of the category being deleted $query = "UPDATE " . AWPCP_TABLE_ADS . " SET ad_category_parent_id='$movetocat' WHERE ad_category_parent_id='$cattodel'"; $wpdb->query( $query ); // Must also relocate any children categories that do not exist in the categories to delete loop to the the move-to-cat $query = "UPDATE " . AWPCP_TABLE_CATEGORIES . " SET category_parent_id='$movetocat' WHERE category_parent_id='$cattodel' AND category_id NOT IN (".implode(',',$categoriestodelete).")"; $wpdb->query( $query ); } elseif ($movedeleteads == 2) { $movetocat=$moveadstocategory; // If the category has children move the ads in the child categories to the default category if ( category_has_children($cattodel) ) { // Relocate the ads ads in any children categories of the category being deleted $query = "UPDATE " . AWPCP_TABLE_ADS . " SET ad_category_parent_id='$movetocat' WHERE ad_category_parent_id='$cattodel'"; $wpdb->query( $query ); // Relocate any children categories that exist under the category being deleted $query = "UPDATE " . AWPCP_TABLE_CATEGORIES . " SET category_parent_id='$movetocat' WHERE category_parent_id='$cattodel'"; $wpdb->query( $query ); } // Now delete the ads because the admin has checked Delete ads if any massdeleteadsfromcategory($cattodel); } // Now delete the categories $query = "DELETE FROM " . AWPCP_TABLE_CATEGORIES . " WHERE category_id='$cattodel'"; $wpdb->query( $query ); $themessagetoprint=__("The categories have been deleted",'another-wordpress-classifieds-plugin'); } } if ( isset( $themessagetoprint ) ) { $message= "
$themessagetoprint
"; } } } /** * Calls awpcp-admin-sidebar filter to output Admin panel sidebar. * * To remove Admin panel sidebar remove the mentioned filter on init. * * XXX: this may belong to AdminPage class */ function awpcp_admin_sidebar($float='') { $html = apply_filters('awpcp-admin-sidebar', '', $float); return $html; } /** * XXX: this may belong to AdminPage class */ function awpcp_admin_sidebar_output($html, $float) { global $awpcp; $modules = array( 'premium' => array( 'installed' => array(), 'not-installed' => array(), ), 'other' => array( 'installed' => array(), 'not-installed' => array(), ), ); $premium_modules = $awpcp->get_premium_modules_information(); foreach ($premium_modules as $module) { if ( isset( $module['private'] ) && $module['private'] ) { continue; } if ( $module['installed'] ) { $modules['premium']['installed'][] = $module; } else { $modules['premium']['not-installed'][] = $module; } } $apath = get_option('siteurl') . '/wp-admin/images'; $float = '' == $float ? 'float:right !important' : $float; $url = AWPCP_URL; ob_start(); include(AWPCP_DIR . '/admin/templates/admin-sidebar.tpl.php'); $content = ob_get_contents(); ob_end_clean(); return $content; }