Пример #1
0
<?php

switch (self::$plugins[$which]['plugin_version']) {
    case '0.7.0':
    case '0.7.1':
    default:
        if (!defined('BLOGS_TAGS_TABLE')) {
            define('BLOGS_TAGS_TABLE', $table_prefix . 'blogs_tags');
        }
        if (!function_exists('get_tags_from_text')) {
            include $blog_plugins_path . 'tags/functions.' . $phpEx;
        }
        $db->sql_query('DELETE FROM ' . BLOGS_TAGS_TABLE);
        $all_tags = get_blog_tags();
        $sql = 'SELECT blog_id, blog_tags FROM ' . BLOGS_TABLE;
        $result = $db->sql_query($sql);
        while ($row = $db->sql_fetchrow($result)) {
            $tag_ary = get_tags_from_text($row['blog_tags']);
            if (!sizeof($tag_ary)) {
                continue;
            }
            $db->sql_query('UPDATE ' . BLOGS_TABLE . ' SET ' . $db->sql_build_array('UPDATE', array('blog_tags' => '[tag_delim]' . implode('[tag_delim]', $tag_ary) . '[tag_delim]')) . ' WHERE blog_id = ' . $row['blog_id']);
            foreach ($tag_ary as $tag) {
                if (isset($all_tags[$tag])) {
                    $db->sql_query('UPDATE ' . BLOGS_TAGS_TABLE . ' SET tag_count = tag_count + 1 WHERE tag_id = ' . $all_tags[$tag]['tag_id']);
                } else {
                    $sql_ary = array('tag_name' => $tag, 'tag_count' => 1);
                    $db->sql_query('INSERT INTO ' . BLOGS_TAGS_TABLE . ' ' . $db->sql_build_array('INSERT', $sql_ary));
                    $all_tags[$tag] = array('tag_id' => $db->sql_nextid());
                }
            }
Пример #2
0
function tags_blog_edit_sql(&$args)
{
    global $blog_id, $cache, $db;
    // If there were not tags before we edited we simply need to add the new tags
    if (!isset(blog_data::$blog[$blog_id]['blog_tags']) || blog_data::$blog[$blog_id]['blog_tags'] == '') {
        tags_blog_add_sql($args);
        return;
    }
    $all_tags = get_blog_tags();
    $old_tags = get_tags_from_text(blog_data::$blog[$blog_id]['blog_tags']);
    $tags = request_var('tags', '', true);
    $tag_ary = get_tags_from_text($tags);
    $new_tags = '';
    foreach ($old_tags as $tag) {
        if (!in_array($tag, $tag_ary)) {
            if ($all_tags[$tag]['tag_count'] == 1) {
                $db->sql_query('DELETE FROM ' . BLOGS_TAGS_TABLE . ' WHERE tag_id = ' . $all_tags[$tag]['tag_id']);
            } else {
                $db->sql_query('UPDATE ' . BLOGS_TAGS_TABLE . ' SET tag_count = tag_count - 1 WHERE tag_id = ' . $all_tags[$tag]['tag_id']);
            }
        }
    }
    foreach ($tag_ary as $tag) {
        if (!in_array($tag, $old_tags)) {
            $new_tags .= $tag . "\n";
        }
    }
    $cache->destroy('_blog_tags');
    tags_blog_add_sql($args, $new_tags);
    $args['blog_tags'] = '[tag_delim]' . implode('[tag_delim]', $tag_ary) . '[tag_delim]';
}