Пример #1
0
/**
* Create clean topic title
*/
function create_clean_topic_title($topic_id = 0, $forum_id = 0, $topic_title = '', $forum_name = '')
{
    global $db, $lang;
    if (empty($topic_id)) {
        return false;
    }
    if (empty($forum_id)) {
        $sql = "SELECT forum_id FROM " . TOPICS_TABLE . " WHERE topic_id = " . $topic_id;
        $result = $db->sql_query($sql);
        while ($row = $db->sql_fetchrow($result)) {
            $forum_id = $row['forum_id'];
        }
        $db->sql_freeresult($result);
    }
    if (empty($forum_id)) {
        return false;
    }
    if (empty($forum_name)) {
        $sql = "SELECT * FROM " . FORUMS_TABLE . " WHERE forum_id = " . $forum_id;
        $result = $db->sql_query($sql);
        while ($row = $db->sql_fetchrow($result)) {
            if (empty($row['forum_name_clean'])) {
                if (!function_exists('update_clean_forum_name')) {
                    @(include_once IP_ROOT_PATH . 'includes/functions_admin_forums.' . PHP_EXT);
                }
                $forum_name = substr(ip_clean_string($row['forum_name'], $lang['ENCODING']), 0, 254);
                update_clean_forum_name($row['forum_id'], $forum_name);
            } else {
                $forum_name = $row['forum_name_clean'];
            }
        }
        $db->sql_freeresult($result);
    }
    if (empty($topic_title)) {
        $sql = "SELECT * FROM " . TOPICS_TABLE . " WHERE topic_id = " . $topic_id;
        $result = $db->sql_query($sql);
        while ($row = $db->sql_fetchrow($result)) {
            $topic_title = empty($row['topic_title_clean']) ? $row['topic_title'] : $row['topic_title_clean'];
        }
        $db->sql_freeresult($result);
    }
    $topic_title = substr(ip_clean_string($topic_title, $lang['ENCODING']), 0, 254);
    $forum_name = substr(ip_clean_string($forum_name, $lang['ENCODING']), 0, 254);
    $sql = "UPDATE " . TOPICS_TABLE . " SET topic_title_clean = " . $db->sql_validate_value($topic_title) . ", topic_ftitle_clean = " . $db->sql_validate_value($forum_name) . " WHERE topic_id = " . $topic_id;
    $result = $db->sql_query($sql);
    return true;
}
Пример #2
0
function create_meta_content()
{
    global $db, $cache, $config, $lang;
    global $meta_content;
    if (!empty($meta_content['post_id']) && $meta_content['post_id'] > 0 || !empty($meta_content['topic_id']) && $meta_content['topic_id'] > 0) {
        if (!empty($meta_content['post_id']) && $meta_content['post_id'] > 0) {
            $sql = "SELECT f.forum_name, f.forum_name_clean, t.topic_title, t.topic_title_clean, t.topic_tags, t.title_compl_infos, p.topic_id, p.forum_id\n\t\t\t\t\t\t\tFROM " . POSTS_TABLE . " p, " . TOPICS_TABLE . " t, " . FORUMS_TABLE . " f\n\t\t\t\t\t\t\tWHERE p.post_id = '" . $meta_content['post_id'] . "'\n\t\t\t\t\t\t\t\tAND t.topic_id = p.topic_id\n\t\t\t\t\t\t\t\tAND f.forum_id = p.forum_id\n\t\t\t\t\t\t\tLIMIT 1";
            // Mighty Gorgon: shall we cache this as well? Maybe too many files... better avoid...
            //$result = $db->sql_query($sql, 0, 'posts_meta_', TOPICS_CACHE_FOLDER);
            $db->sql_return_on_error(true);
            $result = $db->sql_query($sql);
            $db->sql_return_on_error(false);
        } else {
            $sql = "SELECT f.forum_name, f.forum_name_clean, t.forum_id, t.topic_id, t.topic_title, t.topic_title_clean, t.topic_tags, t.title_compl_infos\n\t\t\t\t\t\t\tFROM " . TOPICS_TABLE . " t, " . FORUMS_TABLE . " f\n\t\t\t\t\t\t\tWHERE t.topic_id = '" . $meta_content['topic_id'] . "'\n\t\t\t\t\t\t\t\tAND f.forum_id = t.forum_id\n\t\t\t\t\t\t\tLIMIT 1";
            $db->sql_return_on_error(true);
            $result = CACHE_TOPICS_META ? $db->sql_query($sql, 0, 'topics_meta_', TOPICS_CACHE_FOLDER) : $db->sql_query($sql);
            $db->sql_return_on_error(false);
        }
        if ($result) {
            while ($meta_row = $db->sql_fetchrow($result)) {
                $meta_content['forum_id'] = $meta_row['forum_id'];
                $meta_content['forum_name'] = strip_tags(stripslashes($meta_row['forum_name']));
                $meta_content['forum_name_clean'] = $meta_row['forum_name_clean'];
                $meta_content['topic_id'] = $meta_row['topic_id'];
                $meta_content['topic_title'] = strip_tags(stripslashes($meta_row['topic_title']));
                $meta_content['topic_title_clean'] = $meta_row['topic_title_clean'];
                $meta_content['topic_tags'] = $meta_row['topic_tags'];
                $meta_content['title_compl_infos'] = $meta_row['title_compl_infos'];
                $meta_content['keywords'] = $meta_content['topic_tags'];
                $meta_content['keywords'] = empty($meta_content['keywords']) ? str_replace(array(' ', ',, '), array(', ', ', '), ip_clean_string($meta_content['topic_title'], $lang['ENCODING'], true)) : $meta_content['keywords'];
                $meta_content['description'] = $meta_content['forum_name'] . ' - ' . $meta_content['topic_title'];
                $meta_content['page_title'] = $meta_content['forum_name'] . ' :: ' . $meta_content['page_title'];
            }
            $db->sql_freeresult($result);
        }
    } elseif (!empty($meta_content['forum_id']) && $meta_content['forum_id'] > 0) {
        $sql = "SELECT f.forum_name, f.forum_name_clean, f.forum_desc\n\t\t\t\t\t\tFROM " . FORUMS_TABLE . " f\n\t\t\t\t\t\tWHERE f.forum_id = '" . $meta_content['forum_id'] . "'\n\t\t\t\t\t\t\tAND f.forum_type = " . FORUM_POST . "\n\t\t\t\t\t\tLIMIT 1";
        $db->sql_return_on_error(true);
        $result = $db->sql_query($sql);
        $db->sql_return_on_error(false);
        if ($result) {
            while ($meta_row = $db->sql_fetchrow($result)) {
                $meta_content['forum_name'] = strip_tags(stripslashes($meta_row['forum_name']));
                $meta_content['forum_name_clean'] = $meta_row['forum_name_clean'];
                $meta_content['description'] = $meta_content['forum_name'] . (empty($meta_row['forum_desc']) ? '' : ' - ' . strip_tags(stripslashes($meta_row['forum_desc'])));
                $meta_content['keywords'] = $meta_content['forum_name'] . ', ';
            }
            $db->sql_freeresult($result);
        }
    } elseif (!empty($meta_content['cat_id']) && $meta_content['cat_id'] > 0) {
        $sql = "SELECT c.forum_name AS cat_name, c.forum_name_clean AS cat_name_clean, c.forum_desc\n\t\t\t\t\t\tFROM " . FORUMS_TABLE . " c\n\t\t\t\t\t\tWHERE c.forum_id = " . $meta_content['cat_id'] . "\n\t\t\t\t\t\t\tAND f.forum_type = " . FORUM_CAT . "\n\t\t\t\t\t\tLIMIT 1";
        $db->sql_return_on_error(true);
        $result = $db->sql_query($sql);
        $db->sql_return_on_error(false);
        if ($result) {
            while ($meta_row = $db->sql_fetchrow($result)) {
                $meta_content['cat_name'] = strip_tags(stripslashes($meta_row['cat_name']));
                $meta_content['cat_name_clean'] = $meta_row['cat_name_clean'];
                $meta_content['description'] = $meta_content['cat_name'] . (empty($meta_row['cat_desc']) ? '' : ' - ' . strip_tags(stripslashes($meta_row['cat_desc'])));
                $meta_content['keywords'] = $meta_content['cat_name'] . ', ';
            }
            $db->sql_freeresult($result);
        }
    } else {
        /*
        $meta_content['description'] = '';
        $meta_content['keywords'] = '';
        */
    }
    if (!empty($meta_content['cat_id']) && !empty($meta_content['cat_title']) && empty($meta_content['cat_title_clean'])) {
        $meta_content['cat_title_clean'] = ip_clean_string($meta_row['cat_title'], $lang['ENCODING']);
        if (!function_exists('update_clean_cat_title')) {
            @(include_once IP_ROOT_PATH . 'includes/functions_admin_forums.' . PHP_EXT);
        }
        update_clean_cat_title($meta_content['cat_id'], $meta_content['cat_title_clean']);
    }
    if (!empty($meta_content['forum_id']) && !empty($meta_content['forum_name']) && empty($meta_content['forum_name_clean'])) {
        $meta_content['forum_name_clean'] = ip_clean_string($meta_row['forum_name'], $lang['ENCODING']);
        if (!function_exists('update_clean_forum_name')) {
            @(include_once IP_ROOT_PATH . 'includes/functions_admin_forums.' . PHP_EXT);
        }
        update_clean_forum_name($meta_content['forum_id'], $meta_content['forum_name_clean']);
    }
    if (!empty($meta_content['topic_id']) && !empty($meta_content['topic_title']) && empty($meta_content['topic_title_clean'])) {
        $meta_content['topic_title_clean'] = ip_clean_string($meta_row['topic_title'], $lang['ENCODING']);
        if (!function_exists('update_clean_topic_title')) {
            @(include_once IP_ROOT_PATH . 'includes/functions_topics.' . PHP_EXT);
        }
        update_clean_topic_title($meta_content['topic_id'], $meta_content['topic_title_clean']);
    }
    // Mighty Gorgon: shall we UTF8 decode also page_title and meta?
    /*
    $meta_content['page_title'] = ip_utf8_decode($meta_content['page_title']);
    $meta_content['description'] = ip_utf8_decode($meta_content['description']);
    $meta_content['keywords'] = ip_utf8_decode($meta_content['keywords']);
    */
    return true;
}
function cache_tree($write = false)
{
    global $db, $cache, $config, $user, $lang, $tree;
    $parents = array();
    // read categories
    $cats = array();
    $sql = "SELECT forum_id, parent_id, main_type, forum_name, forum_name_clean, forum_desc, icon, forum_order\n\t\t\t\t\tFROM " . FORUMS_TABLE . "\n\t\t\t\t\tWHERE forum_type = " . FORUM_CAT . "\n\t\t\t\t\tORDER BY forum_order, forum_id";
    $result = $db->sql_query($sql, 0, 'forums_cats_', FORUMS_CACHE_FOLDER);
    while ($row = $db->sql_fetchrow($result)) {
        if ($row['parent_id'] == $row['forum_id']) {
            $row['parent_id'] = 0;
        }
        if (empty($row['main_type'])) {
            $row['main_type'] = POST_CAT_URL;
            $row['forum_order'] = $row['forum_order'] + 9000000;
        }
        $row['main'] = $row['parent_id'] == 0 ? 'Root' : $row['main_type'] . $row['parent_id'];
        $idx = sizeof($cats);
        if (empty($row['forum_name_clean'])) {
            if (!function_exists('update_clean_forum_name')) {
                @(include_once IP_ROOT_PATH . 'includes/functions_admin_forums.' . PHP_EXT);
            }
            $row['forum_name_clean'] = substr(ip_clean_string($row['forum_name_clean'], $lang['ENCODING']), 0, 254);
            update_clean_forum_name($row['forum_id'], $row['forum_name_clean']);
        }
        $cats[$idx] = $row;
        $parents[POST_CAT_URL][$row['main']][] = $idx;
    }
    $db->sql_freeresult($result);
    // read forums
    $sql = "SELECT * FROM " . FORUMS_TABLE . " WHERE forum_type <> " . FORUM_CAT . " ORDER BY forum_order, forum_id";
    $result = $db->sql_query($sql, 0, 'forums_', FORUMS_CACHE_FOLDER);
    while ($row = $db->sql_fetchrow($result)) {
        $main_type = empty($row['main_type']) ? POST_CAT_URL : $row['main_type'];
        $row['main'] = $row['parent_id'] == 0 ? 'Root' : $main_type . $row['parent_id'];
        $idx = sizeof($forums);
        if (empty($row['forum_name_clean'])) {
            if (!function_exists('update_clean_forum_name')) {
                @(include_once IP_ROOT_PATH . 'includes/functions_admin_forums.' . PHP_EXT);
            }
            $row['forum_name_clean'] = substr(ip_clean_string($row['forum_name'], $lang['ENCODING']), 0, 254);
            update_clean_forum_name($row['forum_id'], $row['forum_name_clean']);
        }
        $forums[$idx] = $row;
        $parents[POST_FORUM_URL][$row['main']][] = $idx;
    }
    $db->sql_freeresult($result);
    // build the tree
    $tree = array();
    cache_tree_level('Root', $parents, $cats, $forums);
    // Obtain list of moderators of each forum
    $moderators = array();
    $moderators = $cache->obtain_moderators(true);
    foreach ($moderators as $k => $v) {
        if ($k == 'users') {
            foreach ($moderators[$k] as $moderator_row) {
                $idx = $tree['keys'][POST_FORUM_URL . $moderator_row['forum_id']];
                $tree['mods'][$idx]['user_id'][] = $moderator_row['user_id'];
                $tree['mods'][$idx]['username'][] = $moderator_row['username'];
                $tree['mods'][$idx]['user_active'][] = $moderator_row['user_active'];
                $tree['mods'][$idx]['user_color'][] = $moderator_row['user_color'];
            }
        } elseif ($k == 'groups') {
            foreach ($moderators[$k] as $moderator_row) {
                $idx = $tree['keys'][POST_FORUM_URL . $moderator_row['forum_id']];
                $tree['mods'][$idx]['group_id'][] = $moderator_row['group_id'];
                $tree['mods'][$idx]['group_name'][] = $moderator_row['group_name'];
                $tree['mods'][$idx]['group_color'][] = $moderator_row['group_color'];
            }
        }
    }
    if ($write) {
        cache_tree_output();
    }
}
/**
* Update clean forum name for all forums
*/
function update_all_clean_forum_names()
{
    global $db, $lang;
    $sql = "SELECT * FROM " . FORUMS_TABLE . " ORDER BY forum_order, forum_id";
    $result = $db->sql_query($sql);
    while ($row = $db->sql_fetchrow($result)) {
        if (empty($row['forum_name_clean'])) {
            $row['forum_name_clean'] = substr(ip_clean_string($row['forum_name'], $lang['ENCODING']), 0, 254);
            update_clean_forum_name($row['forum_id'], $row['forum_name_clean']);
        }
    }
    $db->sql_freeresult($result);
    return true;
}