prefix.'az_indexes'); define('AZ_PAGENAME', ($wp_version >= 2.7 ? 'tools.php' : 'edit.php').'?page=az-index-manager'); define('AZ_INDEXCHARS', '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ'); define('AZ_MAXPAGELINKS', 10); // Note: Must be an even number. define('AZ_OS_WIN', substr(PHP_OS, 0, 3) == 'WIN'); define('AZ_DEFAULT_LANGUAGE_TABLE', 'General European'); register_activation_hook(__FILE__, 'az_plugin_activate'); register_deactivation_hook(__FILE__, 'az_plugin_deactivate'); add_action('admin_menu', 'az_add_admin_page'); add_shortcode('az-index', 'az_insert_index'); // Only add this action if we're on the index management page. // Avoids function getting called unnecessarily. if ($_GET['page'] == 'az-index-manager') { add_action('init', 'az_process_requests'); } /** * Add the manage indexes admin page to the admin menu, and if there * was a problem installing this version of AZIndex, then hook into * the admin_notices action to display the error message. */ function az_add_admin_page() { add_management_page('Manage Indexes', 'AZIndex', 8, 'az-index-manager', 'az_display_admin_page'); $error = get_option('az_plugin_error'); if (!empty($error)) { add_action('admin_notices', 'az_admin_notices'); } } /** * Set up all the available options as keys to an array with the values being * the description of what each option does. * * @param $keys if true, create an array of the keys (option names) only * @return array of options */ function az_get_options($keys = false) { $options = array('child-cats' => 'Include child categories', 'include-pages' => 'Include blog pages', 'include-pages-exclude-posts' => 'Exclude blog posts (i.e. only include blog pages)', 'multipage' => 'Use multiple pages', 'multipage-links-above' => 'Display page links above the index (default)', 'multipage-links-below' => 'Display page links below the index', 'group-subhead' => 'Group items with the same heading under one main entry', 'alpha-head' => 'Display alphabetical headings', 'alpha-head-page' => 'Display an alphabetical heading at the start of every page', 'alpha-head-col' => 'Display an alphabetical heading at the start of every column', 'add-spaces' => 'Insert a gap between entries beginning with a different character', 'alpha-links' => 'Display alphabetical links above the index', 'alpha-links-unused' => 'Include unused characters in the alphabetical links', 'alpha-links-two-rows' => 'Use two rows for the alphabetical links', 'ignore-chars' => 'Ignore specified characters, like quotes, when sorting the index', 'non-alpha-end' => 'Put all index items starting with non-alphanumeric characters at the end of the index', 'nls' => 'Turn on additional support for national languages', 'nls-equiv' => 'Set collation table to use for grouping index items', 'nls-locale' => 'Set locale to be used while sorting index', 'custom-css' => 'Use customized stylesheets for the index', 'custom-css-striping' => 'Enable CSS striping of index entries (every other index entry is tagged with the "azalt" CSS class)', 'custom-links' => 'Customize the alphabetical links to be displayed', 'custom-sort' => 'Use a customized comparison function for sorting the index', 'disable-cache' => 'Disable caching for the index. (Use only as last resort. Does not disable caching plugins like WP-Super-Cache.)' ); if ($keys) { $options = array_keys($options); } return $options; } /** * Called when the plugin is activated. Create an empty indexes table in the WordPress * database, if one does not already exist. If we are upgrading then we create a * wp_az_indexes_upgrade table first and then, if the table is successfully upgraded then * we rename it to wp_az_indexes. This prevents data loss if something goes badly wrong * during the upgrade. */ function az_plugin_activate() { az_trace("fn:az_plugin_activate : start"); include_once(ABSPATH.'/wp-admin/includes/upgrade.php'); global $wpdb; // Check to see if we need to upgrade the database table. if (az_is_table_present() && !az_is_compatible_version() && !az_is_alpha_version()) { az_trace("upgrading..."); $upgrade = '_upgrade'; // Suffix of new table during the upgrade $old = '_old'; // Suffix of old table during the upgrade $indexes = $wpdb->get_results("SELECT * FROM ".AZ_TABLE); } // Create the AZIndex database table. $options = az_get_options(true); $sql = "CREATE TABLE ".AZ_TABLE.$upgrade." ( name text NOT NULL, idindex int NOT NULL, categories text," ." tags text, heading text, subheading text, description text," ." cols tinyint, headingseparator text, itemsperpage smallint," ." ignorechars text, nlslocale text, nlsequiv text," ." customcsssingle text, customcssgroup text," ." customlinks text, customsort text," ." options set("; for ($i = 0; $i < count($options); $i++) { $sql .= ($i > 0 ? ", " : "")."'".$options[$i]."'"; } // Always put the cache columns at the end of the table. $sql .= "), itemcache mediumblob, linkcache blob, PRIMARY KEY(idindex))"; // If the database supports the default character set then add it to // the creation query (Note: might be giving a false positive in some cases). if ($wpdb->supports_collation()) { $charset = " DEFAULT CHARACTER SET $wpdb->charset;"; } // Try creating with the default charset clause, but if that fails try again without it $created = maybe_create_table(AZ_TABLE.$upgrade, $sql.$charset); if (!$create) { $created = maybe_create_table(AZ_TABLE.$upgrade, $sql); } // Only create the table if old does not already exist. if ($created) { if (!empty($upgrade)) { az_trace("upgrading..."); $cr = chr(10); $css30 = $cr.'.azindex ul li.azalt {float:left; width:100%; background-color:lightgray;}'; $css40 = $cr.'.azindex h2 { padding-top:0;margin-top:0}' .$cr.'.azindex h2 .azcont {font-size:50%;font-style:italic;}'; $css40g = $cr.'.azindex .head .azcont {font-size:90%;font-style:italic;}' .$cr.'.azindex .subhead .azcont {font-size:90%;font-style:italic;}'; foreach ($indexes as $index) { // Upgrade the custom css with new styles added since version 0.3, if necessary. // Note: must assign back to $index for this to work in PHP4. $index = az_maybe_add_css($index, 'li.azalt', $css30); $index = az_maybe_add_css($index, 'h2 .azcont', $css40); $index = az_maybe_add_css($index, '.head .azcont', $css40g, true); // Upgrade the database table if ($wpdb->query("INSERT INTO ".AZ_TABLE.$upgrade." VALUES ('$index->name', '$index->idindex', '$index->categories'," ." '$index->tags', '$index->heading', '$index->subheading', '$index->description', '$index->cols'," ." '$index->headingseparator', '$index->itemsperpage', '$index->ignorechars'," ." '$index->nlslocale', '$index->nlsequiv'," ." '$index->customcsssingle', '$index->customcssgroup'," ." '$index->customlinks', '$index->customsort', '$index->options', null, null)") === false) { $error = 'upgrade-table-failed'; break; } } } update_option("az_plugin_version", AZ_PLUGIN_VERSION); // Only adds and sets the value if the option does not exist. add_option("az_max_index", '0'); az_trace("fn:az_plugin_activate : end"); } else { $error = !empty($upgrade) ? 'create-table-failed' : 'fresh-create-table-failed'; } // Perform the final step of the upgrade if everything has gone well so far, by // renaming the upgraded database table to wp_az_indexes. if (!empty($upgrade) && empty($error)) { $rc = $wpdb->query("RENAME TABLE ".AZ_TABLE." TO ".AZ_TABLE.$old.', '.AZ_TABLE.$upgrade." TO ".AZ_TABLE); if ($rc !== false) { $rc = $wpdb->query("DROP TABLE IF EXISTS ".AZ_TABLE.$old); } else { $error = 'rename-table-failed'; } } // If there was an error then remove the extra tables created during // the upgrade and save the error to be display during the admin-notices hook. if (!empty($error)) { if (!empty($upgrade)) { $wpdb->query("DROP TABLE IF EXISTS ".AZ_TABLE.$upgrade); $wpdb->query("DROP TABLE IF EXISTS ".AZ_TABLE.$old); } add_option('az_plugin_error', $error); } } /** * Called when the plugin is deactivated. Currently does nothing. */ function az_plugin_deactivate() { az_trace("fn:az_plugin_deactivate : start"); az_trace("fn:az_plugin_deactivate : end"); } /** * Called when the plugin is uninstalled. Removes the database table * and all the AZIndex options. */ function az_plugin_uninstall() { require_once(ABSPATH.'wp-admin/includes/plugin.php'); az_trace("fn:az_plugin_uninstall : start"); global $wpdb; deactivate_plugins(AZ_PLUGIN_FILE); delete_option('az_plugin_version'); delete_option('az_max_index'); delete_option('az_cache_dirty'); $wpdb->query("DROP TABLE IF EXISTS ".AZ_TABLE); az_trace("fn:az_plugin_uninstall : end"); } /** * Check for the first compatible level of the database. * This is currently version 0.7.1 when the CREATE TABLE statement was modified. * * NOTE: The following is the way to test for a field change (if there are no option changes) * $compatible = $wpdb->query("SHOW COLUMNS FROM ".AZ_TABLE." LIKE 'itemcache'"); * * The following is the way to test for an option change (i.e. just a new option was added: * $compatible = false; * $results = $wpdb->get_col("SHOW COLUMNS FROM ".AZ_TABLE." LIKE 'options'", 1); * if (!empty($results)) { * $compatible = strpos($results[0], 'child-cats') !== false; * } * * @return true if this is a compatible version of the database */ function az_is_compatible_version() { global $wpdb; $version = get_option('az_plugin_version'); $compatible = version_compare($version, '0.7.1', '>='); return $compatible; } /** * Check for version of the database we cannot upgrade from. * This is version 0.2.1 or lower. * * @return true if this is an incompatible alpha version of the database */ function az_is_alpha_version() { global $wpdb; return !$wpdb->query("SHOW COLUMNS FROM ".AZ_TABLE." LIKE 'idindex'"); } /** * Detect the wp_az_indexes table to make sure it is present. * * @return true if the table is found in the blog's database */ function az_is_table_present() { global $wpdb; return $wpdb->query("DESCRIBE ".AZ_TABLE); } /** * Helper function for tacking CSS styles on to the custom CSS if * they are missing from a previous version. * * @param class $index * @param string $needle * @param string $style * @param boolean $grouponly */ function az_maybe_add_css($index, $needle, $style, $grouponly = false) { if (!$grouponly && !empty($index->customcsssingle) && strpos($index->customcsssingle, $needle) === false) { $index->customcsssingle .= $style; } if (!empty($index->customcssgroup) && strpos($index->customcssgroup, $needle) === false) { $index->customcssgroup .= $style; } return $index; } /** * Process the action requested by the user, then redirect to the main indexes admin page. * If no action is specified, then skip all processing. */ function az_process_requests() { //az_trace('POST keys = '.implode('|', array_keys($_POST))); //az_trace('POST vals = '.implode('|', $_POST)); //az_trace(' GET keys = '.implode('|', array_keys($_GET))); //az_trace(' GET vals = '.implode('|', $_GET)); az_trace('--- init --------------------------------------------'); az_trace('fn:az_process_requests : start'); global $az_req; $req = new az_request(); az_trace('fn:az_process_requests : action = '.$req->action); if (!empty($req->action) && ($req->action == 'az-add-index' || $req->action == 'az-update-index' || $req->action == 'az-delete-index' || $req->action == 'az-clear-cache' || $req->action == 'cancel' || $req->action == 'az-uninstall-plugin')) { if ($req->action == 'az-update-index' || $req->action == 'az-add-index') { // Collect the parameters from the POST data returned from the user. $req->set_vars_from_post(); if (empty($req->error_field)) { az_trace("fn:az_process_requests : no errors found"); $req->escape_vars(); if ($req->head == 'custom') $req->head .= ':'.$req->headkey; if ($req->subhead == 'custom') $req->subhead .= ':'.$req->subheadkey; if ($req->desc == 'custom') $req->desc .= ':'.$req->desckey; } } else if ($req->action == 'az-delete-index' || $req->action == 'az-clear-cache') { // Collect the parameters from the GET data returned from the user and // fill the rest in from the database entry for the index. $req->set_vars_from_get(); } if (empty($req->error_field)) { global $wpdb; $msgno = 0; $wpdb->show_errors(); if ($req->action == 'az-update-index') { // Update the settings for the index being edited. az_trace("fn:az_process_requests : updating index for indexid : ".$req->id." options: ".$req->options); $query = "UPDATE ".AZ_TABLE." SET name = '$req->name', categories = '$req->catids', tags = '$req->tagids', heading = '$req->head', " ."subheading = '$req->subhead', description = '$req->desc', cols = $req->cols, " ."headingseparator = '$req->headsep', itemsperpage = $req->perpage, ignorechars = '$req->ignorechars', " ."nlslocale = '$req->nlslocale', nlsequiv = '$req->nlsequiv', " ."customcsssingle = '$req->csssingle', customcssgroup = '$req->cssgroup', " ."customlinks = '$req->customlinks', customsort = '$req->customsort', " ."options = '$req->options', itemcache = NULL, linkcache = NULL WHERE idindex = $req->id"; $rc = $wpdb->query($query); // Remove all HTML cache instances of the index page. az_flush_html_cache($req->id); $msgno = 1; az_trace("fn:az_process_requests : rc = ".$rc." query = ".$query); } else if ($req->action == 'az-add-index') { $msgno = 2; // Create a new index and index page using the settings provided by the user. az_trace("fn:az_process_requests : adding index for indexid : ".$req->id); // Get the next available index id -- always increment, even if previous indexes are deleted. $idindex = intval(get_option('az_max_index')) + 1; $rc = $wpdb->query("INSERT INTO ".AZ_TABLE." VALUES ('$req->name', '$idindex', '$req->catids', '$req->tagids'," ."'$req->head', '$req->subhead', '$req->desc', '$req->cols', '$req->headsep', '$req->perpage'," ."'$req->ignorechars', '$req->nlslocale', '$req->nlsequiv', '$req->csssingle', '$req->cssgroup', '$req->customlinks'," ."'$req->customsort', '$req->options', null, null)"); if ($rc) { update_option('az_max_index', $idindex); $pageid = wp_insert_post(array('post_title' => $req->name, 'post_type' => 'page', 'post_content' => '[az-index id="'.$idindex.'"]')); if (empty($pageid)) { $msgno = 22; } } else { $msgno = 21; } az_trace("fn:az_process_requests : az-add-index : rc = ".$rc.""); } else if ($req->action == 'az-delete-index') { // Delete the index selected by the user. az_trace("fn:az_process_requests : az-delete index : ".$req->id); $rc = $wpdb->query("DELETE FROM ".AZ_TABLE." WHERE idindex = $req->id"); $msgno = $rc ? 3 : 31; az_flush_html_cache($req->id); } else if ($req->action == 'az-clear-cache') { // Clear the cache for the selected index az_trace("fn:az_process_requests : clearing cache for indexid : ".$req->id." options: ".$req->options); $query = "UPDATE ".AZ_TABLE." SET itemcache = NULL, linkcache = NULL WHERE idindex = $req->id"; $rc = $wpdb->query($query); az_flush_html_cache($req->id); az_trace("fn:az_process_requests : az-clear-cache : rc = ".$rc." query = ".$query); $msgno = 4; } else if ($req->action == 'az-uninstall-plugin') { az_plugin_uninstall(); wp_redirect('plugins.php'); return; } // Redirect the browser to the main admin index page. $req->action = 'az-redirect'; az_redirect($msgno); } } else { // Nothing to do but fetch the parameters from the 'GET' request. $req->set_vars_from_get(); } // Save the request parameters in a global variable for later use. $az_req = $req; az_trace('fn:az_process_requests : end'); } function az_get_indexes($fields) { global $wpdb; return $wpdb->get_results("SELECT $fields FROM ".AZ_TABLE); } function az_get_index($idindex, $fields) { global $wpdb; return $wpdb->get_results("SELECT $fields FROM ".AZ_TABLE." WHERE idindex = $idindex"); } /** * Fetch the names of the categories/tags being used by the current index. * If the specified category/tag has been deleted by the user, an error * string is returned instead. There may be a ~ character in front of the * number which signifies that it should be excluded from the search. * * @param $term_id_string string of term ids (either categories or tags) * @param $taxonomy type of terms * @return the names of the categories or tags in the supplied string */ function az_get_term_names($term_id_string, $taxonomy) { az_trace('fn:az_get_term_names: term_id_string = '.$term_id_string.", taxonomy = ".$taxonomy); if (!empty($term_id_string)) { $items = preg_split('/([,]+)/', $term_id_string, -1, PREG_SPLIT_DELIM_CAPTURE); foreach ($items as $item) { $item = trim($item); if ($item == ',') { $output .= $item.($item == ',' ? ' ' : ''); } else { az_trace('fn:az_get_term_names: item = '.$item); $not = ''; if ($item[0] == '~') { $not = '~'; $item = trim($item, '~'); } $term = get_term_field('name', $item, $taxonomy, 'edit'); if (!empty($term)) { $output .= $not.$term; } else { $output .= '*deleted '.$taxonomy.'*'; } } } } return $output; } /** * Make an http redirect request to put us back on the main indexes admin page. * * @param $msg number of the message to be displayed, if non-zero. */ function az_redirect($msg) { az_trace('fn:az_redirect : redirect to '.AZ_PAGENAME.($msg != 0 ? '&msg='.$msg : '')); wp_redirect(AZ_PAGENAME.($msg != 0 ? '&msg='.$msg : '')); } /** * Display the manage index administration page. The page will only * be displayed if the supplied action isn't 'az-redirect'. */ function az_display_admin_page() { az_trace('--- admin --------------------------------------------'); az_trace('fn:az_manage_indexes : start'); global $az_req; az_trace('fn:az_manage_indexes : action = '.$az_req->action); if (empty($az_req->action) && empty($az_req->error_field)) { // By default, display the table of indexes. az_display_index_table($az_req); } else if ($az_req->action != 'az-redirect') { // Otherwise, display the edit panel for an index. az_display_index_dialog($az_req); } az_trace('fn:az_manage_indexes : end'); } /** * Display the table of indexes. * * @param $req request parameters used to fill in the table contents on the page */ function az_display_index_table($req) { global $wpdb; ?>
| Index ID | Index Name | Included | Categories | Tags | Heading Field | Subheading Field | Description Field | Actions | ||
|---|---|---|---|---|---|---|---|---|---|---|
| idindex; ?> | name; ?> | options); ?> | categories != null ? az_get_term_names($index->categories, 'category') : '-'; ?> | tags != null ? az_get_term_names($index->tags, 'post_tag') : '-'; ?> | heading; ?> | subheading != 'none' ? $index->subheading : '-'; ?> | description != 'none' ? $index->description : '-'; ?> | Edit | Delete | Clear Cache |
No index pages found.
You are about to uninstall the AZIndex plugin.
All indexes and settings created using the AZIndex plugin will be deleted, including the database table used by the plugin (wp_az_indexes).
If you just want to deactivate the plugin temporarily, go to the Plugin Management page and deactivate it from there
Once you click uninstall, it cannot be undone.
Note: this will not delete the plugin from the system. The plugin can still be reactivated from the Plugin Management page later.
Are you sure you want to uninstall the AZIndex plugin?
YesPlease correct the highlighted field(s).