示例#1
0
 public function restore_missing_pages()
 {
     $shortcodes = awpcp_pages();
     $missing_pages = $this->missing_pages_finder->find_missing_pages();
     $pages_to_restore = array_merge($missing_pages['not-found'], $missing_pages['not-referenced']);
     $page_refs = awpcp_get_properties($pages_to_restore, 'page');
     // If we are restoring the main page, let's do it first!
     if (($p = array_search('main-page-name', $page_refs)) !== FALSE) {
         // put the main page as the first page to restore
         array_splice($pages_to_restore, 0, 0, array($pages_to_restore[$p]));
         array_splice($pages_to_restore, $p + 1, 1);
     }
     $restored_pages = array();
     foreach ($pages_to_restore as $page) {
         $refname = $page->page;
         $name = get_awpcp_option($refname);
         if (strcmp($refname, 'main-page-name') == 0) {
             awpcp_create_pages($name, $subpages = false);
         } else {
             awpcp_create_subpage($refname, $name, $shortcodes[$refname][1]);
         }
         $restored_pages[] = $page;
     }
     update_option('awpcp-flush-rewrite-rules', true);
     return $restored_pages;
 }
 public function find_missing_pages()
 {
     $plugin_pages = awpcp_get_plugin_pages_info();
     $registered_pages = array_keys(awpcp_pages());
     $referenced_pages = array_keys($plugin_pages);
     // pages that are registered in the code but no referenced in the DB
     $pages_not_referenced = array_diff($registered_pages, $referenced_pages);
     $registered_pages_ids = awpcp_get_page_ids_by_ref($registered_pages);
     $query = 'SELECT posts.ID post, posts.post_status status ';
     $query .= 'FROM ' . $this->db->posts . ' AS posts ';
     $query .= "WHERE posts.ID IN (" . join(",", $registered_pages_ids) . ") ";
     $existing_pages = $this->db->get_results($query, OBJECT_K);
     $missing_pages = array('not-found' => array(), 'not-published' => array(), 'not-referenced' => array());
     foreach ($plugin_pages as $page_ref => $page_info) {
         $page = isset($existing_pages[$page_info['page_id']]) ? $existing_pages[$page_info['page_id']] : null;
         if (is_object($page) && isset($page->status) && $page->status != 'publish') {
             $page->page = $page_ref;
             $page->id = $page_info['page_id'];
             $missing_pages['not-published'][] = $page;
         } else {
             if (is_null($page)) {
                 $page = new stdClass();
                 $page->page = $page_ref;
                 $page->id = $page_info['page_id'];
                 $page->post = null;
                 $page->status = null;
                 $missing_pages['not-found'][] = $page;
             }
         }
     }
     // if a page is registered in the code but there is no reference of it
     // in the database, include a dummy object to represent it.
     foreach ($pages_not_referenced as $page) {
         $item = new stdClass();
         $item->page = $page;
         $item->id = null;
         $item->post = null;
         $item->status = null;
         $missing_pages['not-referenced'][] = $item;
     }
     return $missing_pages;
 }
示例#3
0
 public function uninstall()
 {
     global $wpdb, $awpcp_plugin_path, $table_prefix, $awpcp;
     // Remove the upload folders with uploaded images
     $dirname = AWPCPUPLOADDIR;
     if (file_exists($dirname)) {
         require_once $awpcp_plugin_path . '/fileop.class.php';
         $fileop = new fileop();
         $fileop->delete($dirname);
     }
     // Delete the classifieds page(s)
     $pages = awpcp_pages();
     foreach ($pages as $page => $data) {
         wp_delete_post(awpcp_get_page_id_by_ref($page), true);
     }
     // Drop the tables
     $wpdb->query("DROP TABLE IF EXISTS " . AWPCP_TABLE_ADFEES);
     $wpdb->query("DROP TABLE IF EXISTS " . AWPCP_TABLE_ADPHOTOS);
     $wpdb->query("DROP TABLE IF EXISTS " . AWPCP_TABLE_ADS);
     $wpdb->query("DROP TABLE IF EXISTS " . AWPCP_TABLE_ADSETTINGS);
     $wpdb->query("DROP TABLE IF EXISTS " . AWPCP_TABLE_AD_META);
     $wpdb->query("DROP TABLE IF EXISTS " . AWPCP_TABLE_AD_REGIONS);
     $wpdb->query("DROP TABLE IF EXISTS " . AWPCP_TABLE_CATEGORIES);
     $wpdb->query("DROP TABLE IF EXISTS " . AWPCP_TABLE_CREDIT_PLANS);
     $wpdb->query("DROP TABLE IF EXISTS " . AWPCP_TABLE_MEDIA);
     $wpdb->query("DROP TABLE IF EXISTS " . AWPCP_TABLE_PAGES);
     $wpdb->query("DROP TABLE IF EXISTS " . AWPCP_TABLE_PAYMENTS);
     // TODO: implement uninstall methods in other modules
     $tables = array($wpdb->prefix . 'awpcp_comments');
     foreach ($tables as $table) {
         $wpdb->query("DROP TABLE IF EXISTS " . $table);
     }
     // remove AWPCP options from options table
     array_map('delete_option', array('awpcp-pending-manual-upgrade', 'awpcp_installationcomplete', 'awpcp_pagename_warning', 'widget_awpcplatestads', 'awpcp_db_version', $awpcp->settings->setting_name));
     // delete payment transactions
     $sql = 'SELECT option_name FROM ' . $wpdb->options . ' ';
     $sql .= "WHERE option_name LIKE 'awpcp-payment-transaction-%%'";
     array_map('delete_option', $wpdb->get_col($sql));
     // remove widgets
     unregister_widget("AWPCP_LatestAdsWidget");
     unregister_widget('AWPCP_RandomAdWidget');
     unregister_widget('AWPCP_Search_Widget');
     // Clear the ad expiration schedule
     wp_clear_scheduled_hook('doadexpirations_hook');
     wp_clear_scheduled_hook('doadcleanup_hook');
     wp_clear_scheduled_hook('awpcp_ad_renewal_email_hook');
     wp_clear_scheduled_hook('awpcp-clean-up-payment-transactions');
     // TODO: use deactivate_plugins function
     // http://core.trac.wordpress.org/browser/branches/3.2/wp-admin/includes/plugin.php#L548
     $current = get_option('active_plugins');
     $thepluginfile = sprintf("%s/awpcp.php", trim(AWPCP_BASENAME, '/'));
     array_splice($current, array_search($thepluginfile, $current), 1);
     update_option('active_plugins', $current);
     do_action('deactivate_' . $thepluginfile);
 }
示例#4
0
 /**
  * Classifieds Pages Settings checks
  */
 public function validate_classifieds_pages_settings($options, $group)
 {
     global $wpdb, $wp_rewrite;
     $pageids = awpcp_get_plugin_pages_ids();
     $pages_updated = 0;
     foreach (awpcp_pages() as $key => $data) {
         $id = intval($pageids[$key]);
         if ($id <= 0) {
             continue;
         }
         $page = get_post($id);
         if (is_null($page)) {
             continue;
         }
         if (sanitize_title($page->post_title) != $page->post_name) {
             $post_name = $page->post_name;
         } else {
             $post_name = sanitize_title($options[$key]);
         }
         $page = array('ID' => $id, 'post_title' => add_slashes_recursive($options[$key]), 'post_name' => $post_name);
         wp_update_post($page);
         $pages_updated = $pages_updated + 1;
     }
     if ($pages_updated) {
         do_action('awpcp-pages-updated');
     }
     flush_rewrite_rules();
     return $options;
 }