';
if ($_GET["action"] == "savetagupdate") {
$tagid = $_GET["edittag"];
if ($_GET["updateaction"] == "Rename") {
$tag = $_GET["renametagvalue"];
$tagset = explode(",", $tag);
$q = "SELECT post_id FROM $tablepost2tag WHERE tag_id = $tagid";
$postids = $wpdb->get_results($q);
$tagids = array();
foreach ($tagset as $tag) {
$tag = trim($tag);
$q = "SELECT tag_id FROM $tabletags WHERE tag = '$tag'";
$thistagid = $wpdb->get_var($q);
if (is_null($thistagid)) {
$q = "INSERT INTO $tabletags (tag) VALUES ('$tag')";
$wpdb->query($q);
$thistagid = $wpdb->insert_id;
}
$tagids[] = $thistagid;
}
$keepold = false;
foreach($tagids as $newtagid) {
if ($postids ) {
foreach ($postids as $postid) {
if ($wpdb->get_var("SELECT COUNT(*) FROM $tablepost2tag WHERE tag_id = $newtagid AND post_id = $postid->post_id") == 0) {
$wpdb->query("INSERT INTO $tablepost2tag (tag_id, post_id) VALUES ($newtagid, $postid->post_id)");
}
}
} else {
// I guess we were renaming something which wasn't being used...
}
if ($newtagid == $tagid) {
$keepold = true;
}
}
if (!$keepold) {
$q = "delete from $tablepost2tag where tag_id = $tagid";
$wpdb->query($q);
$q = "delete from $tabletags where tag_id = $tagid";
$wpdb->query($q);
}
echo "
";
}
if ($_GET["updateaction"] == __("Save Synonyms", $lzndomain)) {
$synonyms = $_GET["synonyms"];
$synonyms = explode(',', $synonyms);
$utw->ClearSynonymsForTag($_GET["synonymtag"]);
$message = "";
foreach($synonyms as $synonym) {
$message .= $utw->AddSynonymForTag("", $_GET["synonymtag"], $synonym);
$message .= $synonym . " ";
}
echo "
";
}
if ($_GET["updateaction"] ==__("Delete Tag", $lzndomain)) {
$q = "delete from $tablepost2tag where tag_id = $tagid";
$wpdb->query($q);
$q = "delete from $tabletags where tag_id = $tagid";
$wpdb->query($q);
echo "
";
}
if ($_GET["updateaction"] == __("Force Reinstall", $lzndomain)) {
$message = $utw->ForceInstall();
if ($message) {
echo "
";
} else {
echo "
";
}
}
if ($_GET["updateaction"] == __("Tidy Tags", $lzndomain)) {
$utw->TidyTags();
echo "
";
}
if ($_GET["updateaction"] == __("Convert Categories to Tags", $lzndomain)) {
$postids = $wpdb->get_results("SELECT id FROM $wpdb->posts");
foreach ($postids as $postid) {
$utw->SaveCategoriesAsTags($postid->id);
}
echo "
Categories have been converted to tags
";
}
if ($_GET["updateaction"] == __("Import from Custom Field", $lzndomain)) {
update_option('utw_custom_field_conversion_field_name', $_GET["fieldName"]);
update_option('utw_custom_field_conversion_delimiter', $_GET["delimiter"]);
if ($_GET['fieldName'] && $_GET['delimiter']) {
$postids = $wpdb->get_results("SELECT id FROM $wpdb->posts");
foreach ($postids as $postid) {
$utw->SaveCustomFieldAsTags($postid->id, $_GET["fieldName"], $_GET["delimiter"]);
}
echo "
Tags have been imported from a custom field
";
} else {
echo "
Could not import tags from custom field
";
}
}
if ($_GET["updateaction"] == __("Export to Custom Field", $lzndomain)) {
update_option('utw_custom_field_conversion_field_name', $_GET["fieldName"]);
update_option('utw_custom_field_conversion_delimiter', $_GET["delimiter"]);
if ($_GET['fieldName'] && $_GET['delimiter']) {
$postids = $wpdb->get_results("SELECT id FROM $wpdb->posts");
foreach ($postids as $postid) {
$utw->SaveTagsAsCustomField($postid->id, $_GET["fieldName"], $_GET["delimiter"]);
}
echo "
Tags have been exported to a custom field
";
} else {
echo "
Could not export tags to custom field
";
}
}
}
echo "
";
echo '
";
echo '
";
echo "
';
}
function show_dropdown($settingName, $label, $value, $options) {
echo "
$label | |
";
}
function show_multiselect($settingName, $label, $value, $options) {
echo "
$label | ";
foreach($options as $option) {
echo " 0) {
echo " checked";
}
echo "> $option ";
}
echo " |
";
}
function show_label($settingName, $label, $value) {
echo <<
$label |
FORMWIDGET;
}
function show_color($settingName, $label, $value) {
echo <<$label | |
FORMWIDGET;
}
function show_string($settingName, $label, $value) {
echo <<$label | |
FORMWIDGET;
}
function show_toggle($settingName, $label, $value) {
if ($value == 'yes') {
$yeschecked = " checked";
}
echo <<$label | |
FORMWIDGET;
}
/*
ultimate_tag_templates
Handles the inclusion of templates, when appropriate.
index.php?archive=tag (or equivalent) will try and use the template tag_all.php
index.php?tag={tag name} (or equivalent) will try and use the template tag.php
*/
function ultimate_tag_templates() {
if ($_GET["archive"] == "tag") {
include(TEMPLATEPATH . '/tag_all.php');
exit;
} else if (get_query_var("tag") != "") {
ultimate_get_posts();
if (file_exists(TEMPLATEPATH . "/tag.php")) {
if ( isset($_GET['feed']) || $_GET["feed"] == '') {
include(TEMPLATEPATH . '/tag.php');
exit;
}
} else {
// include(TEMPLATEPATH . '/index.php');
}
}
}
/*
ultimate_save_tags
Saves the tags for the current post to the database.
$postID the ID of the current post
$_POST['tagset'] the list of tags.
*/
function ultimate_save_tags($postID)
{
global $wpdb, $tableposts, $table_prefix, $utw;
$tags = $wpdb->escape($_POST['tagset']);
$tags = explode(',',$tags);
$utw->SaveTags($postID, $tags);
if (get_option('utw_include_categories_as_tags') == "yes") {
$utw->SaveCategoriesAsTags($postID);
}
return $postID;
}
function ultimate_delete_post($postID) {
global $utw;
$utw->DeletePostTags($postID);
return $postID;
}
/*
ultimate_display_tag_widget
Displays the tag box on the content editing page.
*/
function ultimate_display_tag_widget() {
global $post, $wpdb, $table_prefix, $utw;
$tabletags = $table_prefix . "tags";
$tablepost2tag = $table_prefix . "post2tag";
$taglist = "";
if ( (is_object($post) && $post->ID) || (!is_object($post) && $post)) {
if (is_object($post)) {
$postid = $post->ID;
} else {
$postid = $post;
}
$q = "select t.tag from $tabletags t inner join $tablepost2tag p2t on t.tag_id = p2t.tag_id and p2t.post_id=$postid";
$tags = $wpdb->get_results($q);
if ($tags) {
foreach($tags as $tag) {
$taglist .= $tag->tag . " ";
}
$taglist = substr($taglist, 0, -1); // trim the trailing space.
}
}
echo '';
echo '';
}
function ultimate_the_content_filter($thecontent='') {
global $post, $utw, $lzndomain;
$tags = $utw->GetTagsForPost($post->ID);
if (count($tags) == 0 && $post->post_status == 'static') {
return $thecontent;
}
if (get_option('utw_include_local_links') == 'yes') {
if (get_option('utw_primary_automagically_included_link_format') != '') {
$thecontent = $thecontent . $utw->FormatTags($tags, $utw->GetFormatForType(get_option('utw_primary_automagically_included_link_format')));
} else {
$thecontent = $thecontent . $utw->FormatTags($tags, array("first"=>"%taglink% ","default"=>"%taglink% ", "last"=>"%taglink%"));
}
}
if (get_option('utw_include_technorati_links') == 'yes') {
if (get_option('utw_secondary_automagically_included_link_format') != '') {
$thecontent = $thecontent . $utw->FormatTags($tags, $utw->GetFormatForType(get_option('utw_secondary_automagically_included_link_format')));
} else {
$thecontent = $thecontent . $utw->FormatTags($tags, array("pre"=>__("Technorati Tags", $lzndomain) . ": ","default"=>"%technoratitag% ", "last"=>"%technoratitag%","none"=>"","post"=>""));
}
}
if (is_feed() && get_option('utw_append_tag_links_to_feed')) {
$thecontent = $thecontent . $utw->FormatTags($tags, $utw->GetFormatForType('commalist'));
}
return $thecontent;
}
function ultimate_add_tags_to_rss($the_list, $type="") {
global $post, $utw;
$categories = get_the_category();
$the_list = '';
foreach ($categories as $category) {
$category->cat_name = convert_chars($category->cat_name);
$the_list .= "\n\t$category->cat_name";
}
$format="%tagdisplay%";
echo $the_list;
echo $utw->FormatTags($utw->GetTagsForPost($post->ID), $format);
}
function ultimate_add_ajax_javascript() {
global $install_directory;
$rpcurl = get_option('siteurl') . "/wp-content/plugins$install_directory/ultimate-tag-warrior-ajax.php";
$jsurl = get_option('siteurl') . "/wp-content/plugins$install_directory/ultimate-tag-warrior-ajax-js.php";
echo "";
}
function ultimate_posts_join($join) {
if (get_query_var("tag") != "") {
global $table_prefix, $wpdb;
$tabletags = $table_prefix . "tags";
$tablepost2tag = $table_prefix . "post2tag";
$join .= " INNER JOIN $tablepost2tag p2t on $wpdb->posts.ID = p2t.post_id INNER JOIN $tabletags t on p2t.tag_id = t.tag_id ";
}
return $join;
}
function ultimate_posts_where($where) {
global $utw;
if (get_query_var("tag") != "") {
global $table_prefix, $wpdb;
$tabletags = $table_prefix . "tags";
$tablepost2tag = $table_prefix . "post2tag";
$tags = get_query_var("tag");
$tagset = explode(" ", $tags);
if (count($tagset) == 1) {
$tagset = explode("|", $tags);
}
$tags = array();
foreach($tagset as $tag) {
$tags[] = "'" . $utw->GetCanonicalTag($tag) . "'";
}
$tags = array_unique($tags);
$taglist = implode (',',$tags);
$where .= " AND t.tag IN ($taglist) ";
}
return $where;
}
function ultimate_query_vars($vars) {
$vars[] = 'tag';
return $vars;
}
/* Maaaaaybe some day...
function ultimate_posts_having () {
if (get_query_var("tag") != "") {
$tags = get_query_var("tag");
$tagset = explode(" ", $tags);
$taglist = "'" . $tagset[0] . "'";
$tagcount = count($tagset);
return " HAVING count(wp_posts.id) = $tagcount ";
}
}
*/
}
// Admin menu items
add_action('admin_menu', array('UltimateTagWarriorActions', 'ultimate_admin_menus'));
// Add or edit tags
add_action('simple_edit_form', array('UltimateTagWarriorActions','ultimate_display_tag_widget'));
add_action('edit_form_advanced', array('UltimateTagWarriorActions','ultimate_display_tag_widget'));
// Save changes to tags
add_action('publish_post', array('UltimateTagWarriorActions','ultimate_save_tags'));
add_action('edit_post', array('UltimateTagWarriorActions','ultimate_save_tags'));
add_action('save_post', array('UltimateTagWarriorActions','ultimate_save_tags'));
add_action('wp_insert_post', array('UltimateTagWarriorActions','ultimate_save_tags'));
add_action('delete_post', array('UltimateTagWarriorActions', 'ultimate_delete_post'));
// Display tag pages
add_action('template_redirect', array('UltimateTagWarriorActions','ultimate_tag_templates'));
add_filter('posts_join', array('UltimateTagWarriorActions','ultimate_posts_join'));
add_filter('posts_where', array('UltimateTagWarriorActions','ultimate_posts_where'));
// add_filter('posts_having',array('UltimateTagWarriorActions','ultimate_posts_having'));
// URL rewriting
add_filter('rewrite_rules_array', array('UltimateTagWarriorActions','ultimate_rewrite_rules'));
add_filter('query_vars', array('UltimateTagWarriorActions','ultimate_query_vars'));
add_filter('the_content', array('UltimateTagWarriorActions', 'ultimate_the_content_filter'));
add_filter('the_category_rss', array('UltimateTagWarriorActions', 'ultimate_add_tags_to_rss'));
#add_filter('wp_head', array('UltimateTagWarriorActions', 'ultimate_add_ajax_javascript'));
add_filter('admin_head', array('UltimateTagWarriorActions', 'ultimate_add_ajax_javascript'));
?>