$trow = alt_trow();
 if ($similar_thread['icon'] > 0 && $icon_cache[$similar_thread['icon']]) {
     $icon = $icon_cache[$similar_thread['icon']];
     $icon = "<img src=\"{$icon['path']}\" alt=\"{$icon['name']}\" />";
 } else {
     $icon = "&nbsp;";
 }
 if (!$similar_thread['username']) {
     $similar_thread['username'] = $similar_thread['threadusername'];
     $similar_thread['profilelink'] = $similar_thread['threadusername'];
 } else {
     $similar_thread['profilelink'] = build_profile_link($similar_thread['username'], $similar_thread['uid']);
 }
 // If this thread has a prefix, insert a space between prefix and subject
 if ($similar_thread['prefix'] != 0) {
     $prefix = build_prefixes($similar_thread['prefix']);
     $similar_thread['threadprefix'] = $prefix['displaystyle'] . '&nbsp;';
 }
 $similar_thread['subject'] = $parser->parse_badwords($similar_thread['subject']);
 $similar_thread['subject'] = htmlspecialchars_uni($similar_thread['subject']);
 $similar_thread['threadlink'] = get_thread_link($similar_thread['tid']);
 $similar_thread['lastpostlink'] = get_thread_link($similar_thread['tid'], 0, "lastpost");
 $lastpostdate = my_date($mybb->settings['dateformat'], $similar_thread['lastpost']);
 $lastposttime = my_date($mybb->settings['timeformat'], $similar_thread['lastpost']);
 $lastposter = $similar_thread['lastposter'];
 $lastposteruid = $similar_thread['lastposteruid'];
 // Don't link to guest's profiles (they have no profile).
 if ($lastposteruid == 0) {
     $lastposterlink = $lastposter;
 } else {
     $lastposterlink = build_profile_link($lastposter, $lastposteruid);
/**
 * Builds a friendly named Who's Online location from an "activity" and array of user data. Assumes fetch_wol_activity has already been called.
 *
 * @param array Array containing activity and essential IDs.
 * @return string Location name for the activity being performed.
 */
function build_friendly_wol_location($user_activity)
{
    global $db, $lang, $uid_list, $aid_list, $pid_list, $tid_list, $fid_list, $ann_list, $eid_list, $plugins, $parser, $mybb;
    global $threads, $forums, $forums_linkto, $forum_cache, $posts, $announcements, $events, $usernames, $attachments;
    // Fetch forum permissions for this user
    $unviewableforums = get_unviewable_forums();
    $inactiveforums = get_inactive_forums();
    $fidnot = '';
    $unviewablefids = $inactivefids = array();
    if ($unviewableforums) {
        $fidnot = " AND fid NOT IN ({$unviewableforums})";
        $unviewablefids = explode(',', $unviewableforums);
    }
    if ($inactiveforums) {
        $fidnot .= " AND fid NOT IN ({$inactiveforums})";
        $inactivefids = explode(',', $inactiveforums);
    }
    // Fetch any users
    if (!is_array($usernames) && count($uid_list) > 0) {
        $uid_sql = implode(",", $uid_list);
        if ($uid_sql != $mybb->user['uid']) {
            $query = $db->simple_select("users", "uid,username", "uid IN ({$uid_sql})");
            while ($user = $db->fetch_array($query)) {
                $usernames[$user['uid']] = $user['username'];
            }
        } else {
            $usernames[$mybb->user['uid']] = $mybb->user['username'];
        }
    }
    // Fetch any attachments
    if (!is_array($attachments) && count($aid_list) > 0) {
        $aid_sql = implode(",", $aid_list);
        $query = $db->simple_select("attachments", "aid,pid", "aid IN ({$aid_sql})");
        while ($attachment = $db->fetch_array($query)) {
            $attachments[$attachment['aid']] = $attachment['pid'];
            $pid_list[] = $attachment['pid'];
        }
    }
    // Fetch any announcements
    if (!is_array($announcements) && count($ann_list) > 0) {
        $aid_sql = implode(",", $ann_list);
        $query = $db->simple_select("announcements", "aid,subject", "aid IN ({$aid_sql}) {$fidnot}");
        while ($announcement = $db->fetch_array($query)) {
            $announcement_title = htmlspecialchars_uni($parser->parse_badwords($announcement['subject']));
            $announcements[$announcement['aid']] = $announcement_title;
        }
    }
    // Fetch any posts
    if (!is_array($posts) && count($pid_list) > 0) {
        $pid_sql = implode(",", $pid_list);
        $query = $db->simple_select("posts", "pid,tid", "pid IN ({$pid_sql}) {$fidnot}");
        while ($post = $db->fetch_array($query)) {
            $posts[$post['pid']] = $post['tid'];
            $tid_list[] = $post['tid'];
        }
    }
    // Fetch any threads
    if (!is_array($threads) && count($tid_list) > 0) {
        $perms = array();
        $tid_sql = implode(",", $tid_list);
        $query = $db->simple_select('threads', 'uid, fid, tid, subject, visible, prefix', "tid IN({$tid_sql}) {$fidnot}");
        $threadprefixes = build_prefixes();
        while ($thread = $db->fetch_array($query)) {
            $thread['threadprefix'] = '';
            if ($thread['prefix'] && !empty($threadprefixes[$thread['prefix']])) {
                $thread['threadprefix'] = $threadprefixes[$thread['prefix']]['displaystyle'];
            }
            if (empty($perms[$thread['fid']])) {
                $perms[$thread['fid']] = forum_permissions($thread['fid']);
            }
            if (isset($perms[$thread['fid']]['canonlyviewownthreads']) && $perms[$thread['fid']]['canonlyviewownthreads'] == 1 && $thread['uid'] != $mybb->user['uid'] && !is_moderator($thread['fid'])) {
                continue;
            }
            if (is_moderator($thread['fid']) || $thread['visible'] == 1) {
                $thread_title = '';
                if ($thread['threadprefix']) {
                    $thread_title = $thread['threadprefix'] . '&nbsp;';
                }
                $thread_title .= htmlspecialchars_uni($parser->parse_badwords($thread['subject']));
                $threads[$thread['tid']] = $thread_title;
                $fid_list[] = $thread['fid'];
            }
        }
    }
    // Fetch any forums
    if (!is_array($forums) && count($fid_list) > 0) {
        $fidnot = array_merge($unviewablefids, $inactivefids);
        foreach ($forum_cache as $fid => $forum) {
            if (in_array($fid, $fid_list) && !in_array($fid, $fidnot)) {
                $forums[$fid] = $forum['name'];
                $forums_linkto[$fid] = $forum['linkto'];
            }
        }
    }
    // And finaly any events
    if (!is_array($events) && count($eid_list) > 0) {
        $eid_sql = implode(",", $eid_list);
        $query = $db->simple_select("events", "eid,name", "eid IN ({$eid_sql})");
        while ($event = $db->fetch_array($query)) {
            $events[$event['eid']] = htmlspecialchars_uni($parser->parse_badwords($event['name']));
        }
    }
    // Now we've got everything we need we can put a name to the location
    switch ($user_activity['activity']) {
        // announcement.php functions
        case "announcements":
            if (!empty($announcements[$user_activity['ann']])) {
                $location_name = $lang->sprintf($lang->viewing_announcements, get_announcement_link($user_activity['ann']), $announcements[$user_activity['ann']]);
            } else {
                $location_name = $lang->viewing_announcements2;
            }
            break;
            // attachment.php actions
        // attachment.php actions
        case "attachment":
            $pid = $attachments[$user_activity['aid']];
            $tid = $posts[$pid];
            if (!empty($threads[$tid])) {
                $location_name = $lang->sprintf($lang->viewing_attachment2, $user_activity['aid'], $threads[$tid], get_thread_link($tid));
            } else {
                $location_name = $lang->viewing_attachment;
            }
            break;
            // calendar.php functions
        // calendar.php functions
        case "calendar":
            $location_name = $lang->viewing_calendar;
            break;
        case "calendar_event":
            if (!empty($events[$user_activity['eid']])) {
                $location_name = $lang->sprintf($lang->viewing_event2, get_event_link($user_activity['eid']), $events[$user_activity['eid']]);
            } else {
                $location_name = $lang->viewing_event;
            }
            break;
        case "calendar_addevent":
            $location_name = $lang->adding_event;
            break;
        case "calendar_editevent":
            $location_name = $lang->editing_event;
            break;
        case "contact":
            $location_name = $lang->viewing_contact_us;
            break;
            // editpost.php functions
        // editpost.php functions
        case "editpost":
            $location_name = $lang->editing_post;
            break;
            // forumdisplay.php functions
        // forumdisplay.php functions
        case "forumdisplay":
            if (!empty($forums[$user_activity['fid']])) {
                if ($forums_linkto[$user_activity['fid']]) {
                    $location_name = $lang->sprintf($lang->forum_redirect_to, get_forum_link($user_activity['fid']), $forums[$user_activity['fid']]);
                } else {
                    $location_name = $lang->sprintf($lang->viewing_forum2, get_forum_link($user_activity['fid']), $forums[$user_activity['fid']]);
                }
            } else {
                $location_name = $lang->viewing_forum;
            }
            break;
            // index.php functions
        // index.php functions
        case "index":
            $location_name = $lang->sprintf($lang->viewing_index, $mybb->settings['bbname']);
            break;
            // managegroup.php functions
        // managegroup.php functions
        case "managegroup":
            $location_name = $lang->managing_group;
            break;
            // member.php functions
        // member.php functions
        case "member_activate":
            $location_name = $lang->activating_account;
            break;
        case "member_profile":
            if (!empty($usernames[$user_activity['uid']])) {
                $location_name = $lang->sprintf($lang->viewing_profile2, get_profile_link($user_activity['uid']), $usernames[$user_activity['uid']]);
            } else {
                $location_name = $lang->viewing_profile;
            }
            break;
        case "member_register":
            $location_name = $lang->registering;
            break;
        case "member":
        case "member_login":
            // Guest or member?
            if ($mybb->user['uid'] == 0) {
                $location_name = $lang->logging_in;
            } else {
                $location_name = $lang->logging_in_plain;
            }
            break;
        case "member_logout":
            $location_name = $lang->logging_out;
            break;
        case "member_emailuser":
            $location_name = $lang->emailing_user;
            break;
        case "member_rate":
            $location_name = $lang->rating_user;
            break;
        case "member_resendactivation":
            $location_name = $lang->member_resendactivation;
            break;
        case "member_lostpw":
            $location_name = $lang->member_lostpw;
            break;
            // memberlist.php functions
        // memberlist.php functions
        case "memberlist":
            $location_name = $lang->viewing_memberlist;
            break;
            // misc.php functions
        // misc.php functions
        case "misc_dstswitch":
            $location_name = $lang->changing_dst;
            break;
        case "misc_whoposted":
            if (!empty($threads[$user_activity['tid']])) {
                $location_name = $lang->sprintf($lang->viewing_whoposted2, get_thread_link($user_activity['tid']), $threads[$user_activity['tid']]);
            } else {
                $location_name = $lang->viewing_whoposted;
            }
            break;
        case "misc_markread":
            $location_name = $lang->sprintf($lang->marking_read, $mybb->post_code);
            break;
        case "misc_help":
            $location_name = $lang->viewing_helpdocs;
            break;
        case "misc_buddypopup":
            $location_name = $lang->viewing_buddylist;
            break;
        case "misc_smilies":
            $location_name = $lang->viewing_smilies;
            break;
        case "misc_syndication":
            $location_name = $lang->viewing_syndication;
            break;
        case "misc_imcenter":
            $location_name = $lang->viewing_imcenter;
            break;
            // modcp.php functions
        // modcp.php functions
        case "modcp_modlogs":
            $location_name = $lang->viewing_modlogs;
            break;
        case "modcp_announcements":
            $location_name = $lang->managing_announcements;
            break;
        case "modcp_finduser":
            $location_name = $lang->search_for_user;
            break;
        case "modcp_warninglogs":
            $location_name = $lang->managing_warninglogs;
            break;
        case "modcp_ipsearch":
            $location_name = $lang->searching_ips;
            break;
        case "modcp_report":
            $location_name = $lang->viewing_reports;
            break;
        case "modcp_new_announcement":
            $location_name = $lang->adding_announcement;
            break;
        case "modcp_delete_announcement":
            $location_name = $lang->deleting_announcement;
            break;
        case "modcp_edit_announcement":
            $location_name = $lang->editing_announcement;
            break;
        case "modcp_mod_queue":
            $location_name = $lang->managing_modqueue;
            break;
        case "modcp_editprofile":
            $location_name = $lang->editing_user_profiles;
            break;
        case "modcp_banning":
            $location_name = $lang->managing_bans;
            break;
        case "modcp":
            $location_name = $lang->viewing_modcp;
            break;
            // moderation.php functions
        // moderation.php functions
        case "moderation":
            $location_name = $lang->using_modtools;
            break;
            // newreply.php functions
        // newreply.php functions
        case "newreply":
            if (!empty($threads[$user_activity['tid']])) {
                $location_name = $lang->sprintf($lang->replying_thread2, get_thread_link($user_activity['tid']), $threads[$user_activity['tid']]);
            } else {
                $location_name = $lang->replying_thread;
            }
            break;
            // newthread.php functions
        // newthread.php functions
        case "newthread":
            if (!empty($forums[$user_activity['fid']])) {
                $location_name = $lang->sprintf($lang->posting_thread2, get_forum_link($user_activity['fid']), $forums[$user_activity['fid']]);
            } else {
                $location_name = $lang->posting_thread;
            }
            break;
            // online.php functions
        // online.php functions
        case "wol":
            $location_name = $lang->viewing_wol;
            break;
        case "woltoday":
            $location_name = $lang->viewing_woltoday;
            break;
            // polls.php functions
        // polls.php functions
        case "newpoll":
            $location_name = $lang->creating_poll;
            break;
        case "editpoll":
            $location_name = $lang->editing_poll;
            break;
        case "showresults":
            $location_name = $lang->viewing_pollresults;
            break;
        case "vote":
            $location_name = $lang->voting_poll;
            break;
            // printthread.php functions
        // printthread.php functions
        case "printthread":
            if (!empty($threads[$user_activity['tid']])) {
                $location_name = $lang->sprintf($lang->printing_thread2, get_thread_link($user_activity['tid']), $threads[$user_activity['tid']]);
            } else {
                $location_name = $lang->printing_thread;
            }
            break;
            // private.php functions
        // private.php functions
        case "private_send":
            $location_name = $lang->sending_pm;
            break;
        case "private_read":
            $location_name = $lang->reading_pm;
            break;
        case "private_folders":
            $location_name = $lang->editing_pmfolders;
            break;
        case "private":
            $location_name = $lang->using_pmsystem;
            break;
            /* Ratethread functions */
        /* Ratethread functions */
        case "ratethread":
            $location_name = $lang->rating_thread;
            break;
            // report.php functions
        // report.php functions
        case "report":
            $location_name = $lang->reporting_post;
            break;
            // reputation.php functions
        // reputation.php functions
        case "reputation":
            $location_name = $lang->sprintf($lang->giving_reputation, get_profile_link($user_activity['uid']), $usernames[$user_activity['uid']]);
            break;
        case "reputation_report":
            if (!empty($usernames[$user_activity['uid']])) {
                $location_name = $lang->sprintf($lang->viewing_reputation_report, "reputation.php?uid={$user_activity['uid']}", $usernames[$user_activity['uid']]);
            } else {
                $location_name = $lang->sprintf($lang->viewing_reputation_report2);
            }
            break;
            // search.php functions
        // search.php functions
        case "search":
            $location_name = $lang->sprintf($lang->searching_forum, $mybb->settings['bbname']);
            break;
            // showthread.php functions
        // showthread.php functions
        case "showthread":
            if (!empty($threads[$user_activity['tid']])) {
                $pagenote = '';
                $location_name = $lang->sprintf($lang->reading_thread2, get_thread_link($user_activity['tid']), $threads[$user_activity['tid']], $pagenote);
            } else {
                $location_name = $lang->reading_thread;
            }
            break;
        case "showpost":
            if (!empty($posts[$user_activity['pid']]) && !empty($threads[$posts[$user_activity['pid']]])) {
                $pagenote = '';
                $location_name = $lang->sprintf($lang->reading_thread2, get_thread_link($posts[$user_activity['pid']]), $threads[$posts[$user_activity['pid']]], $pagenote);
            } else {
                $location_name = $lang->reading_thread;
            }
            break;
            // showteam.php functions
        // showteam.php functions
        case "showteam":
            $location_name = $lang->viewing_team;
            break;
            // stats.php functions
        // stats.php functions
        case "stats":
            $location_name = $lang->viewing_stats;
            break;
            // usercp.php functions
        // usercp.php functions
        case "usercp_profile":
            $location_name = $lang->updating_profile;
            break;
        case "usercp_editlists":
            $location_name = $lang->managing_buddyignorelist;
            break;
        case "usercp_options":
            $location_name = $lang->updating_options;
            break;
        case "usercp_editsig":
            $location_name = $lang->editing_signature;
            break;
        case "usercp_avatar":
            $location_name = $lang->changing_avatar;
            break;
        case "usercp_subscriptions":
            $location_name = $lang->viewing_subscriptions;
            break;
        case "usercp_favorites":
            $location_name = $lang->viewing_favorites;
            break;
        case "usercp_notepad":
            $location_name = $lang->editing_pad;
            break;
        case "usercp_password":
            $location_name = $lang->editing_password;
            break;
        case "usercp":
            $location_name = $lang->user_cp;
            break;
        case "usercp2_favorites":
            $location_name = $lang->managing_favorites;
            break;
        case "usercp2_subscriptions":
            $location_name = $lang->managing_subscriptions;
            break;
        case "portal":
            $location_name = $lang->viewing_portal;
            break;
            // sendthread.php functions
        // sendthread.php functions
        case "sendthread":
            $location_name = $lang->sending_thread;
            break;
            // warnings.php functions
        // warnings.php functions
        case "warnings_revoke":
            $location_name = $lang->revoking_warning;
            break;
        case "warnings_warn":
            $location_name = $lang->warning_user;
            break;
        case "warnings_view":
            $location_name = $lang->viewing_warning;
            break;
        case "warnings":
            $location_name = $lang->managing_warnings;
            break;
    }
    $plugin_array = array('user_activity' => &$user_activity, 'location_name' => &$location_name);
    $plugins->run_hooks("build_friendly_wol_location_end", $plugin_array);
    if (isset($user_activity['nopermission']) && $user_activity['nopermission'] == 1) {
        $location_name = $lang->viewing_noperms;
    }
    if (!$location_name) {
        $location_name = $lang->sprintf($lang->unknown_location, $user_activity['location']);
    }
    return $location_name;
}
define("IN_MYBB", 1);
define('THIS_SCRIPT', 'sendthread.php');
$templatelist = "sendthread,forumdisplay_password_wrongpass,forumdisplay_password";
require_once "./global.php";
require_once MYBB_ROOT . "inc/functions_post.php";
require_once MYBB_ROOT . "inc/class_parser.php";
$parser = new postParser();
// Load global language phrases
$lang->load("sendthread");
// Get thread info
$tid = intval($mybb->input['tid']);
$thread = get_thread($tid);
// Get thread prefix
$breadcrumbprefix = '';
if ($thread['prefix']) {
    $threadprefix = build_prefixes($thread['prefix']);
    if (isset($threadprefix['displaystyle'])) {
        $breadcrumbprefix = $threadprefix['displaystyle'] . '&nbsp;';
    }
}
$thread['subject'] = htmlspecialchars_uni($parser->parse_badwords($thread['subject']));
// Invalid thread
if (!$thread['tid']) {
    error($lang->error_invalidthread);
}
// Guests cannot use this feature
if (!$mybb->user['uid']) {
    error_no_permission();
}
$fid = $thread['fid'];
// Make navigation
Exemple #4
0
 // Threads being read?
 if ($mybb->settings['threadreadcut'] > 0) {
     $query = $db->simple_select("threadsread", "*", "uid='{$mybb->user['uid']}' AND tid IN ({$tids})");
     while ($readthread = $db->fetch_array($query)) {
         $threadcache[$readthread['tid']]['lastread'] = $readthread['dateline'];
     }
 }
 // Icon Stuff
 if ($mybb->settings['dotfolders'] != 0) {
     $query = $db->simple_select("posts", "tid,uid", "uid='{$mybb->user['uid']}' AND tid IN ({$tids})");
     while ($post = $db->fetch_array($query)) {
         $threadcache[$post['tid']]['doticon'] = 1;
     }
 }
 $icon_cache = $cache->read("posticons");
 $threadprefixes = build_prefixes();
 // Run the threads...
 $latest_threads_threads = '';
 foreach ($threadcache as $thread) {
     if ($thread['tid']) {
         $bgcolor = alt_trow();
         $folder = '';
         $folder_label = '';
         $prefix = '';
         $gotounread = '';
         $isnew = 0;
         $donenew = 0;
         $lastread = 0;
         // If this thread has a prefix...
         if ($thread['prefix'] != 0) {
             if (!empty($threadprefixes[$thread['prefix']])) {
Exemple #5
0
/**
 * Create a unique URL in the database for a specific item type,id.
 * First fetch the title of the item from the MyBB database,
 * then process (translate, separate, truncate, uniquify) that title,
 * then check for existing entries in the Google SEO database,
 * finally insert it into the database if it's not already there.
 *
 * @param string Type of the item (forums, threads, etc.)
 * @param array IDs of the item (fid for forums, tid for threads, etc.)
 */
function google_seo_url_create($type, $ids)
{
    global $db, $settings;
    global $google_seo_url_cache;
    $ids = array_map('intval', (array) $ids);
    foreach ($ids as $id) {
        $google_seo_url_cache[$type][$id] = 0;
    }
    if ($db->google_seo_query_limit <= 0) {
        return;
    }
    $data = $db->google_seo_url[$type];
    // Is Google SEO URL enabled for this type?
    if ($data['scheme']) {
        // Query the item title as base for our URL.
        $db->google_seo_query_limit--;
        $titles = $db->query("SELECT {$data['name']},{$data['id']}{$data['extra']}\n                              FROM {$data['table']}\n                              WHERE {$data['id']} IN (" . implode(",", $ids) . ")");
        while ($row = $db->fetch_array($titles)) {
            $url = $row[$data['name']];
            // MyBB unfortunately allows HTML in forum names.
            if ($type == GOOGLE_SEO_FORUM) {
                $url = strip_tags($url);
            }
            // Thread Prefixes
            if ($row['prefix']) {
                $prefix = build_prefixes($row['prefix']);
                if ($prefix['prefix']) {
                    $url = google_seo_expand($settings['google_seo_url_threadprefix'], array('url' => $url, 'prefix' => $prefix['prefix'], 'separator' => $settings['google_seo_url_separator']));
                }
            }
            $id = $row[$data['id']];
            // Prepare the URL.
            if ($settings['google_seo_url_translation']) {
                $url = google_seo_url_translation($url);
            }
            $url = google_seo_url_separate($url);
            $url = google_seo_url_truncate($url);
            $uniqueurl = google_seo_url_uniquify($url, $id);
            // Special case: for empty URLs we must use the unique variant
            if ($url == "" || $settings['google_seo_url_uniquifier_force']) {
                $url = $uniqueurl;
            }
            // Parents
            if ($row['parent']) {
                $parent_type = $db->google_seo_url[$type]['parent_type'];
                $parent_id = (int) $row['parent'];
                // TODO: Parents costs us an extra query. Cache?
                $db->google_seo_query_limit--;
                $query = $db->simple_select('google_seo', 'url AS parent', "active=1 AND idtype={$parent_type} AND id={$parent_id}");
                $parent = $db->fetch_field($query, 'parent');
                if ($parent) {
                    $url = google_seo_expand($db->google_seo_url[$type]['parent'], array('url' => $url, 'parent' => $parent));
                    $uniqueurl = google_seo_expand($db->google_seo_url[$type]['parent'], array('url' => $url, 'parent' => $parent));
                }
            }
            // Check for existing entry and possible collisions.
            $db->google_seo_query_limit--;
            $query = $db->query("SELECT url,id FROM " . TABLE_PREFIX . "google_seo\n                                 WHERE active=1 AND idtype={$type} AND id<={$id}\n                                 AND url IN ('" . $db->escape_string($url) . "','" . $db->escape_string($uniqueurl) . "')\n                                 AND EXISTS(SELECT {$data['id']}\n                                            FROM {$data['table']}\n                                            WHERE {$data['id']}=id)\n                                 ORDER BY id ASC");
            $urlrow = $db->fetch_array($query);
            $uniquerow = $db->fetch_array($query);
            // Check if the entry was not up to date anyway.
            if ($urlrow && $urlrow['id'] == $id && $urlrow['url'] == $url) {
                // It's up to date. Do nothing.
            } else {
                if ($uniquerow && $uniquerow['id'] == $id && $uniquerow['url'] == $uniqueurl) {
                    // It's up to date for the unique URL.
                    $url = $uniqueurl;
                } else {
                    // Use unique URL if there was a row with a different id.
                    if ($urlrow && $urlrow['id'] != $id) {
                        $url = $uniqueurl;
                    }
                    // Set old entries for us to not active.
                    $db->google_seo_query_limit--;
                    $db->write_query("UPDATE " . TABLE_PREFIX . "google_seo\n                                  SET active=NULL\n                                  WHERE active=1\n                                  AND idtype={$type}\n                                  AND id={$id}");
                    // Insert new entry (while possibly replacing old ones).
                    $db->google_seo_query_limit--;
                    $db->write_query("REPLACE INTO " . TABLE_PREFIX . "google_seo\n                                  VALUES (active,idtype,id,url),\n                                  ('1','{$type}','{$id}','" . $db->escape_string($url) . "')");
                }
            }
            // Finalize URL.
            if ($settings['google_seo_url_lowercase']) {
                $url = my_strtolower($url);
            }
            $url = google_seo_url_finalize($url, $data['scheme']);
            $google_seo_url_cache[$type][$id] = $url;
        }
    }
}
Exemple #6
0
function get_thread_func($xmlrpc_params)
{
    global $db, $lang, $mybb, $position, $plugins, $pids;
    global $pforumcache, $currentitem, $forum_cache, $navbits, $base_url, $archiveurl;
    $input = Tapatalk_Input::filterXmlInput(array('topic_id' => Tapatalk_Input::STRING, 'start_num' => Tapatalk_Input::INT, 'last_num' => Tapatalk_Input::INT, 'return_html' => Tapatalk_Input::INT), $xmlrpc_params);
    if (preg_match('/^ann_/', $input['topic_id'])) {
        $_GET["aid"] = intval(str_replace('ann_', '', $input['topic_id']));
        return get_announcement_func($xmlrpc_params);
    }
    $lang->load("showthread");
    global $parser;
    $parser = new Tapatalk_Parser();
    // Get the thread details from the database.
    $thread = get_thread($input['topic_id']);
    if (!empty($thread['closed'])) {
        $moved = explode("|", $thread['closed']);
        if ($moved[0] == "moved") {
            $thread = get_thread($moved[1]);
        }
    }
    // Get thread prefix if there is one.
    $thread['threadprefix'] = '';
    $thread['displayprefix'] = '';
    if ($thread['prefix'] != 0) {
        $threadprefix = build_prefixes($thread['prefix']);
        if ($threadprefix['prefix']) {
            $thread['threadprefix'] = $threadprefix['prefix'] . '&nbsp;';
            $thread['displayprefix'] = $threadprefix['displaystyle'] . '&nbsp;';
        }
    }
    $thread['subject'] = $parser->parse_badwords($thread['subject']);
    $tid = $thread['tid'];
    $fid = $thread['fid'];
    if (!$thread['username']) {
        $thread['username'] = $lang->guest;
    }
    $visibleonly = "AND visible='1'";
    // Is the currently logged in user a moderator of this forum?
    if (is_moderator($fid)) {
        $visibleonly = " AND (visible='1' OR visible='0')";
        $ismod = true;
    } else {
        $ismod = false;
    }
    $forumpermissions = forum_permissions($thread['fid']);
    // Does the user have permission to view this thread?
    if ($forumpermissions['canview'] != 1 || $forumpermissions['canviewthreads'] != 1) {
        error_no_permission();
    }
    if ($forumpermissions['canonlyviewownthreads'] == 1 && $thread['uid'] != $mybb->user['uid']) {
        error_no_permission();
    }
    // Make sure we are looking at a real thread here.
    if (!$thread['tid'] || $thread['visible'] == 0 && $ismod == false || $thread['visible'] > 1 && $ismod == true) {
        return xmlrespfalse($lang->error_invalidthread);
    }
    // Does the thread belong to a valid forum?
    $forum = get_forum($fid);
    if (!$forum || $forum['type'] != "f") {
        return xmlrespfalse($lang->error_invalidforum);
    }
    tt_check_forum_password($forum['fid']);
    if ($thread['firstpost'] == 0) {
        update_first_post($tid);
    }
    // Mark this thread as read
    mark_thread_read($tid, $fid);
    // Increment the thread view.
    if ($mybb->settings['delayedthreadviews'] == 1) {
        $db->shutdown_query("INSERT INTO " . TABLE_PREFIX . "threadviews (tid) VALUES('{$tid}')");
    } else {
        $db->shutdown_query("UPDATE " . TABLE_PREFIX . "threads SET views=views+1 WHERE tid='{$tid}'");
    }
    ++$thread['views'];
    // Work out if we are showing unapproved posts as well (if the user is a moderator etc.)
    if ($ismod) {
        $visible = "AND (p.visible='0' OR p.visible='1')";
    } else {
        $visible = "AND p.visible='1'";
    }
    // Fetch the ignore list for the current user if they have one
    $ignored_users = array();
    if ($mybb->user['uid'] > 0 && $mybb->user['ignorelist'] != "") {
        $ignore_list = explode(',', $mybb->user['ignorelist']);
        foreach ($ignore_list as $uid) {
            $ignored_users[$uid] = 1;
        }
    }
    list($start, $limit) = process_page($input['start_num'], $input['last_num']);
    // Recount replies if user is a moderator to take into account unapproved posts.
    if ($ismod) {
        $query = $db->simple_select("posts p", "COUNT(*) AS replies", "p.tid='{$tid}' {$visible}");
        $thread['replies'] = $db->fetch_field($query, 'replies') - 1;
    }
    $postcount = intval($thread['replies']) + 1;
    $pids = "";
    $comma = '';
    $query = $db->simple_select("posts p", "p.pid", "p.tid='{$tid}' {$visible}", array('order_by' => 'p.dateline', 'limit_start' => $start, 'limit' => $limit));
    while ($getid = $db->fetch_array($query)) {
        // Set the ID of the first post on page to $pid if it doesn't hold any value
        // to allow this value to be used for Thread Mode/Linear Mode links
        // and ensure the user lands on the correct page after changing view mode
        if (!$pid) {
            $pid = $getid['pid'];
        }
        // Gather a comma separated list of post IDs
        $pids .= "{$comma}'{$getid['pid']}'";
        $comma = ",";
    }
    if ($pids) {
        $pids = "pid IN({$pids})";
        global $attachcache;
        $attachcache = array();
        if ($thread['attachmentcount'] > 0) {
            // Now lets fetch all of the attachments for these posts.
            $query = $db->simple_select("attachments", "*", $pids);
            while ($attachment = $db->fetch_array($query)) {
                $attachcache[$attachment['pid']][$attachment['aid']] = $attachment;
            }
        }
    } else {
        // If there are no pid's the thread is probably awaiting approval.
        return xmlrespfalse($lang->error_invalidthread);
    }
    $post_list = array();
    // Get the actual posts from the database here.
    $posts = '';
    $query = $db->query("\n        SELECT u.*, u.username AS userusername, p.*, f.*, eu.username AS editusername, IF(b.lifted > UNIX_TIMESTAMP() OR b.lifted = 0, 1, 0) as isbanned\n        FROM " . TABLE_PREFIX . "posts p\n        LEFT JOIN " . TABLE_PREFIX . "users u ON (u.uid=p.uid)\n        LEFT JOIN " . TABLE_PREFIX . "userfields f ON (f.ufid=u.uid)\n        LEFT JOIN " . TABLE_PREFIX . "users eu ON (eu.uid=p.edituid)\n        LEFT JOIN " . TABLE_PREFIX . "banned b ON (b.uid = p.uid)\n        WHERE {$pids}\n        ORDER BY p.dateline\n    ");
    //can_rename topic
    $can_rename = (is_moderator($fid, "caneditposts") || $forumpermissions['caneditposts'] == 1 && $mybb->user['uid'] == $thread['uid']) && $mybb->user['uid'] != 0;
    while ($post = $db->fetch_array($query)) {
        if ($thread['firstpost'] == $post['pid'] && $thread['visible'] == 0) {
            $post['visible'] = 0;
        }
        //$posts .= build_postbit($post);
        $parser_options = array();
        $parser_options['allow_html'] = false;
        $parser_options['allow_mycode'] = true;
        $parser_options['allow_smilies'] = false;
        $parser_options['allow_imgcode'] = true;
        $parser_options['allow_videocode'] = true;
        $parser_options['nl2br'] = (bool) $input['return_html'];
        $parser_options['filter_badwords'] = 1;
        if (!$post['username']) {
            $post['username'] = $lang->guest;
        }
        if ($post['userusername']) {
            $parser_options['me_username'] = $post['userusername'];
        } else {
            $parser_options['me_username'] = $post['username'];
        }
        $post['subject'] = $parser->parse_badwords($post['subject']);
        $post['author'] = $post['uid'];
        if ($post['userusername']) {
            // This post was made by a registered user
            $post['username'] = $post['userusername'];
        }
        // Eidt Option
        $can_edit = (is_moderator($fid, "caneditposts") || $forumpermissions['caneditposts'] == 1 && $mybb->user['uid'] == $post['uid']) && $mybb->user['uid'] != 0;
        // Quick Delete Option
        $can_delete = 0;
        if ($mybb->user['uid'] == $post['uid']) {
            if ($forumpermissions['candeletethreads'] == 1 && $postcounter == 1) {
                $can_delete = 1;
            } else {
                if ($forumpermissions['candeleteposts'] == 1 && $postcounter != 1) {
                    $can_delete = 1;
                }
            }
        }
        $can_delete = (is_moderator($fid, "candeleteposts") || $can_delete == 1) && $mybb->user['uid'] != 0;
        // User Online status
        $is_online = false;
        $timecut = TIME_NOW - $mybb->settings['wolcutoff'];
        if ($post['lastactive'] > $timecut && ($post['invisible'] != 1 || $mybb->usergroup['canviewwolinvis'] == 1) && $post['lastvisit'] != $post['lastactive']) {
            $is_online = true;
        }
        $post['message'] = post_bbcode_clean($post['message']);
        $plugins->remove_hook('parse_message', 'mybbirckeditor_parser');
        // Post content and attachments
        $post['message'] = $parser->parse_message($post['message'], $parser_options);
        $attachment_list = process_post_attachments($post['pid'], $post);
        // add for thank/like support
        $post = $plugins->run_hooks("postbit", $post);
        if (is_array($ignored_users) && $post['uid'] != 0 && $ignored_users[$post['uid']] == 1) {
            $show_spoiler = "[spoiler]" . $post['message'] . "[/spoiler]";
            $post['message'] = $lang->sprintf($lang->postbit_currently_ignoring_user, $post['username']) . $show_spoiler;
        }
        $post_xmlrpc = array('post_id' => new xmlrpcval($post['pid'], 'string'), 'post_title' => new xmlrpcval(basic_clean($post['subject']), 'base64'), 'post_content' => new xmlrpcval(process_post($post['message'], $input['return_html']), 'base64'), 'post_author_id' => new xmlrpcval($post['uid'], 'string'), 'post_author_name' => new xmlrpcval(basic_clean($post['username']), 'base64'), 'icon_url' => new xmlrpcval(absolute_url($post['avatar']), 'string'), 'post_time' => new xmlrpcval(mobiquo_iso8601_encode($post['dateline']), 'dateTime.iso8601'), 'timestamp' => new xmlrpcval($post['dateline'], 'string'), 'attachments' => new xmlrpcval($attachment_list, 'array'));
        if (!$post['visible']) {
            $post_xmlrpc['is_approved'] = new xmlrpcval(false, 'boolean');
        }
        // default as true
        if ($post['smilieoff']) {
            $post_xmlrpc['allow_smilies'] = new xmlrpcval(false, 'boolean');
        }
        // default as true
        if ($post['isbanned']) {
            $post_xmlrpc['is_ban'] = new xmlrpcval(true, 'boolean');
        }
        if ($is_online) {
            $post_xmlrpc['is_online'] = new xmlrpcval(true, 'boolean');
        }
        if ($can_edit) {
            $post_xmlrpc['can_edit'] = new xmlrpcval(true, 'boolean');
        }
        if ($can_delete) {
            $post_xmlrpc['can_delete'] = new xmlrpcval(true, 'boolean');
        }
        if (is_moderator($fid, 'canmanagethreads')) {
            $post_xmlrpc['can_approve'] = new xmlrpcval(true, 'boolean');
        }
        if (is_moderator($fid, 'canmanagethreads')) {
            $post_xmlrpc['can_move'] = new xmlrpcval(true, 'boolean');
        }
        if ($mybb->usergroup['canmodcp'] == 1) {
            $post_xmlrpc['can_ban'] = new xmlrpcval(true, 'boolean');
        }
        if ($post['edituid']) {
            //add edit info
            $edit_info = array('editor_id' => new xmlrpcval($post['edituid'], 'string'), 'editor_name' => new xmlrpcval($post['editusername'], 'base64'), 'edit_time' => new xmlrpcval($post['edittime'], 'string'));
            if (!empty($post['editreason'])) {
                $edit_info['edit_reason'] = new xmlrpcval($post['editreason'], 'base64');
            }
            $post_xmlrpc = array_merge($post_xmlrpc, $edit_info);
        }
        // add for thank/like support
        if (isset($post['button_tyl']) && $mybb->user['uid']) {
            global $mobiquo_config, $g33k_pcache;
            $thlprefix = $mobiquo_config['thlprefix'];
            $tyled = false;
            $tyl_list = array();
            if ($mybb->settings[$thlprefix . 'enabled'] == "1") {
                if ($post['thankyoulike'] && isset($g33k_pcache[$post['pid']])) {
                    foreach ($g33k_pcache[$post['pid']] as $tyl) {
                        if ($tyl['uid'] == $mybb->user['uid']) {
                            $tyled = true;
                        }
                        $tyl_list[] = new xmlrpcval(array('userid' => new xmlrpcval($tyl['uid'], 'string'), 'username' => new xmlrpcval(basic_clean($tyl['username']), 'base64')), 'struct');
                    }
                }
                if ($mybb->settings[$thlprefix . 'thankslike'] == "like") {
                    if ($post['button_tyl']) {
                        $post_xmlrpc['can_like'] = new xmlrpcval(true, 'boolean');
                    }
                    if ($tyled) {
                        $post_xmlrpc['is_liked'] = new xmlrpcval(true, 'boolean');
                    }
                    if ($tyl_list) {
                        $post_xmlrpc['likes_info'] = new xmlrpcval($tyl_list, 'array');
                    }
                } else {
                    if ($mybb->settings[$thlprefix . 'thankslike'] == "thanks") {
                        if ($post['button_tyl']) {
                            $post_xmlrpc['can_thank'] = new xmlrpcval(true, 'boolean');
                        }
                        if ($mybb->settings[$thlprefix . 'removing'] == 1) {
                            $post_xmlrpc['can_remove_thank'] = new xmlrpcval(true, 'boolean');
                        }
                        if ($tyled) {
                            $post_xmlrpc['is_thanked'] = new xmlrpcval(true, 'boolean');
                        }
                        if ($tyl_list) {
                            $post_xmlrpc['thanks_info'] = new xmlrpcval($tyl_list, 'array');
                        }
                    }
                }
            }
        }
        $post_list[] = new xmlrpcval($post_xmlrpc, 'struct');
    }
    $query = $db->simple_select("threadsubscriptions", "tid", "tid='" . intval($tid) . "' AND uid='" . intval($mybb->user['uid']) . "'", array('limit' => 1));
    $subscribed = (bool) $db->fetch_field($query, 'tid');
    $query = $db->simple_select("banned", "uid", "uid='{$thread['uid']}'");
    $isbanned = !!$db->fetch_field($query, "uid");
    $can_reply = $forumpermissions['canpostreplys'] != 0 && $mybb->user['suspendposting'] != 1 && ($thread['closed'] != 1 || is_moderator($fid)) && $forum['open'] != 0;
    build_tt_breadcrumb($fid);
    $navgation_arr = $navbits;
    if (is_array($navgation_arr) && count($navgation_arr) > 1) {
        unset($navgation_arr[0]);
        foreach ($navgation_arr as $navigation) {
            $forum_id = $navigation['fid'];
            $sub_only = false;
            if ($navigation['type'] != 'f') {
                $sub_only = true;
            }
            $breadcrumb[] = new xmlrpcval(array('forum_id' => new xmlrpcval($forum_id, 'string'), 'forum_name' => new xmlrpcval($navigation['name'], 'base64'), 'sub_only' => new xmlrpcval($sub_only, 'boolean')), 'struct');
        }
    }
    $is_poll = !empty($thread['poll']) ? true : false;
    $result = array('total_post_num' => new xmlrpcval($postcount, 'int'), 'forum_id' => new xmlrpcval($thread['fid'], 'string'), 'forum_name' => new xmlrpcval(basic_clean($forum['name']), 'base64'), 'topic_id' => new xmlrpcval($thread['tid'], 'string'), 'topic_title' => new xmlrpcval(basic_clean($thread['subject']), 'base64'), 'can_upload' => new xmlrpcval($forumpermissions['canpostattachments'] != 0, 'boolean'), 'can_report' => new xmlrpcval(true, 'boolean'), 'can_reply' => new xmlrpcval($can_reply, 'boolean'), 'is_poll' => new xmlrpcval($is_poll, 'boolean'), 'view_number' => new xmlrpcval(intval($thread['views']), 'int'));
    if ($forumpermissions['canview'] == 0 || $forumpermissions['canviewthreads'] == 0) {
        $new_topic['can_subscribe'] = new xmlrpcval(false, 'boolean');
    } else {
        $new_topic['can_subscribe'] = new xmlrpcval(true, 'boolean');
    }
    if ($thread['prefix']) {
        $result['prefix'] = new xmlrpcval(basic_clean($thread['displayprefix']), 'base64');
    }
    if (!$thread['visible']) {
        $result['is_approved'] = new xmlrpcval(false, 'boolean');
    }
    // default as true
    if ($thread['closed']) {
        $result['is_closed'] = new xmlrpcval(true, 'boolean');
    }
    if ($thread['sticky']) {
        $result['is_sticky'] = new xmlrpcval(true, 'boolean');
    }
    if ($subscribed) {
        $result['is_subscribed'] = new xmlrpcval(true, 'boolean');
    } else {
        $result['is_subscribed'] = new xmlrpcval(false, 'boolean');
    }
    if ($isbanned) {
        $result['is_ban'] = new xmlrpcval(true, 'boolean');
    }
    if ($position) {
        $result['position'] = new xmlrpcval(intval($position), 'int');
    }
    if (is_moderator($fid, "canopenclosethreads")) {
        $result['can_close'] = new xmlrpcval(true, 'boolean');
    }
    if (is_moderator($fid, "candeleteposts")) {
        $result['can_delete'] = new xmlrpcval(true, 'boolean');
    }
    if (is_moderator($fid, "canmanagethreads")) {
        $result['can_stick'] = new xmlrpcval(true, 'boolean');
    }
    if (is_moderator($fid, "canmanagethreads")) {
        $result['can_move'] = new xmlrpcval(true, 'boolean');
        $result['can_merge'] = new xmlrpcval(true, 'boolean');
        $result['can_merge_post'] = new xmlrpcval(true, 'boolean');
    }
    if (is_moderator($fid, "canopenclosethreads")) {
        $result['can_approve'] = new xmlrpcval(true, 'boolean');
    }
    if ($can_rename) {
        $result['can_rename'] = new xmlrpcval(true, 'boolean');
    }
    if ($mybb->usergroup['canmodcp'] == 1) {
        $result['can_ban'] = new xmlrpcval(true, 'boolean');
    }
    if (!empty($breadcrumb)) {
        $result['breadcrumb'] = new xmlrpcval($breadcrumb, 'array');
    }
    $result['posts'] = new xmlrpcval($post_list, 'array');
    return new xmlrpcresp(new xmlrpcval($result, 'struct'));
}
Exemple #7
0
 /**
  * Verify thread prefix.
  *
  * @return boolean True when valid, false when not valid.
  */
 function verify_prefix()
 {
     $prefix =& $this->data['prefix'];
     $prefix_cache = build_prefixes();
     // If a valid prefix isn't supplied, don't assign one.
     if (empty($prefix)) {
         $prefix = 0;
     } else {
         $prefix_cache = build_prefixes($prefix);
         if (empty($prefix_cache)) {
             $this->set_error('invalid_prefix');
             return false;
         }
         if ($prefix_cache['groups'] != "-1") {
             if (!empty($this->data['edit_uid'])) {
                 // Post is being edited
                 $user = get_user($this->data['edit_uid']);
             } else {
                 $user = get_user($this->data['uid']);
             }
             if (!is_member($prefix_cache['groups'], array('usergroup' => $user['usergroup'], 'additionalgroups' => $user['additionalgroups']))) {
                 $this->set_error('invalid_prefix');
                 return false;
             }
         }
         if ($prefix_cache['forums'] != "-1") {
             // Decide whether this prefix can be used in our forum
             $forums = explode(",", $prefix_cache['forums']);
             if (!in_array($this->data['fid'], $forums)) {
                 $this->set_error('invalid_prefix');
                 return false;
             }
         }
     }
     // Does this forum require a prefix?
     $forum = get_forum($this->data['fid']);
     if ($forum['requireprefix'] == 1) {
         $num_prefixes = false;
         // Go through each of our prefixes and decide if there are any possible prefixes to use.
         if (!empty($this->data['edit_uid'])) {
             // Post is being edited
             $user = get_user($this->data['edit_uid']);
         } else {
             $user = get_user($this->data['uid']);
         }
         $prefix_cache = build_prefixes();
         if (!empty($prefix_cache)) {
             foreach ($prefix_cache as $required) {
                 if ($required['forums'] != "-1") {
                     // Decide whether this prefix can be used in our forum
                     $forums = explode(",", $required['forums']);
                     if (!in_array($forum['fid'], $forums)) {
                         continue;
                     }
                 }
                 if ($required['groups'] != "-1") {
                     if (!is_member($required['groups'], array('usergroup' => $user['usergroup'], 'additionalgroups' => $user['additionalgroups']))) {
                         $num_prefixes = true;
                     }
                 } else {
                     $num_prefixes = true;
                 }
             }
         }
         if ($prefix == 0 && $num_prefixes) {
             $this->set_error('require_prefix');
             return false;
         }
     }
     return true;
 }
Exemple #8
0
        log_admin_action($prefix['pid'], $prefix['prefix']);
        $cache->update_threadprefixes();
        flash_message($lang->success_thread_prefix_deleted, 'success');
        admin_redirect('index.php?module=config-thread_prefixes');
    } else {
        $page->output_confirm_action("index.php?module=config-thread_prefixes&amp;action=delete_prefix&amp;pid={$mybb->input['pid']}", $lang->confirm_thread_prefix_deletion);
    }
}
if (!$mybb->input['action']) {
    $plugins->run_hooks('admin_config_thread_prefixes_start');
    $page->output_header($lang->thread_prefixes);
    $page->output_nav_tabs($sub_tabs, 'thread_prefixes');
    $table = new Table();
    $table->construct_header($lang->prefix);
    $table->construct_header($lang->controls, array('class' => 'align_center', 'colspan' => 2));
    $prefixes = build_prefixes();
    if ($prefixes) {
        foreach ($prefixes as $prefix) {
            $table->construct_cell("<a href=\"index.php?module=config-thread_prefixes&amp;action=edit_prefix&amp;pid={$prefix['pid']}\"><strong>" . htmlspecialchars_uni($prefix['prefix']) . "</strong></a>");
            $table->construct_cell("<a href=\"index.php?module=config-thread_prefixes&amp;action=edit_prefix&amp;pid={$prefix['pid']}\">{$lang->edit}</a>", array('width' => 100, 'class' => "align_center"));
            $table->construct_cell("<a href=\"index.php?module=config-thread_prefixes&amp;action=delete_prefix&amp;pid={$prefix['pid']}&amp;my_post_key={$mybb->post_code}\" onclick=\"return AdminCP.deleteConfirmation(this, '{$lang->confirm_thread_prefix_deletion}')\">{$lang->delete}</a>", array('width' => 100, 'class' => 'align_center'));
            $table->construct_row();
        }
    }
    if ($table->num_rows() == 0) {
        $table->construct_cell($lang->no_thread_prefixes, array('colspan' => 3));
        $table->construct_row();
    }
    $table->output($lang->thread_prefixes);
    $page->output_footer();
}
Exemple #9
0
function get_prefix_list($fid)
{
    global $db, $mybb;
    if ($fid != 'all') {
        $fid = intval($fid);
    }
    if (defined('OLD_PREFIX')) {
        // Does this user have additional groups?
        if ($mybb->user['additionalgroups']) {
            $exp = explode(",", $mybb->user['additionalgroups']);
            // Because we like apostrophes...
            $imps = array();
            foreach ($exp as $group) {
                $imps[] = "'{$group}'";
            }
            $additional_groups = implode(",", $imps);
            $extra_sql = "groups IN ({$additional_groups}) OR ";
        } else {
            $extra_sql = '';
        }
        switch ($db->type) {
            case "pgsql":
            case "sqlite":
                $whereforum = "";
                if ($fid != 'all') {
                    $whereforum = " AND (','||forums||',' LIKE '%,{$fid},%' OR ','||forums||',' LIKE '%,-1,%' OR forums='')";
                }
                $query = $db->query("\n                    SELECT pid, prefix\n                    FROM " . TABLE_PREFIX . "threadprefixes\n                    WHERE ({$extra_sql}','||groups||',' LIKE '%,{$mybb->user['usergroup']},%' OR ','||groups||',' LIKE '%,-1,%' OR groups='')\n                    {$whereforum}\n                ");
                break;
            default:
                $whereforum = "";
                if ($fid != 'all') {
                    $whereforum = " AND (CONCAT(',',forums,',') LIKE '%,{$fid},%' OR CONCAT(',',forums,',') LIKE '%,-1,%' OR forums='')";
                }
                $query = $db->query("\n                    SELECT pid, prefix\n                    FROM " . TABLE_PREFIX . "threadprefixes\n                    WHERE ({$extra_sql}CONCAT(',',groups,',') LIKE '%,{$mybb->user['usergroup']},%' OR CONCAT(',',groups,',') LIKE '%,-1,%' OR groups='')\n                    {$whereforum}\n                ");
        }
        $prefixes = array();
        if ($db->num_rows($query) > 0) {
            while ($prefix = $db->fetch_array($query)) {
                $prefixes[$prefix['pid']] = $prefix;
            }
        }
    } else {
        $prefix_cache = build_prefixes(0);
        if (!$prefix_cache) {
            return array();
            // We've got no prefixes to show
        }
        $groups = array($mybb->user['usergroup']);
        if ($mybb->user['additionalgroups']) {
            $exp = explode(",", $mybb->user['additionalgroups']);
            foreach ($exp as $group) {
                $groups[] = $group;
            }
        }
        // Go through each of our prefixes and decide which ones we can use
        $prefixes = array();
        foreach ($prefix_cache as $prefix) {
            if ($fid != "all" && $prefix['forums'] != "-1") {
                // Decide whether this prefix can be used in our forum
                $forums = explode(",", $prefix['forums']);
                if (!in_array($fid, $forums)) {
                    // This prefix is not in our forum list
                    continue;
                }
            }
            if ($prefix['groups'] != "-1") {
                $prefix_groups = explode(",", $prefix['groups']);
                foreach ($groups as $group) {
                    if (in_array($group, $prefix_groups) && !isset($prefixes[$prefix['pid']])) {
                        // Our group can use this prefix!
                        $prefixes[$prefix['pid']] = $prefix;
                    }
                }
            } else {
                // This prefix is for anybody to use...
                $prefixes[$prefix['pid']] = $prefix;
            }
        }
    }
    return $prefixes;
}
Exemple #10
0
/**
 * Build the thread prefix selection menu
 *
 *  @param mixed The forum ID (integer ID or string all)
 *  @param mixed The selected prefix ID (integer ID or string any)
 *  @return string The thread prefix selection menu
 */
function build_prefix_select($fid, $selected_pid = 0, $multiple = 0)
{
    global $cache, $db, $lang, $mybb;
    if ($fid != 'all') {
        $fid = intval($fid);
    }
    $prefix_cache = build_prefixes(0);
    if (!$prefix_cache) {
        return false;
        // We've got no prefixes to show
    }
    $groups = array($mybb->user['usergroup']);
    if ($mybb->user['additionalgroups']) {
        $exp = explode(",", $mybb->user['additionalgroups']);
        foreach ($exp as $group) {
            $groups[] = $group;
        }
    }
    // Go through each of our prefixes and decide which ones we can use
    $prefixes = array();
    foreach ($prefix_cache as $prefix) {
        if ($fid != "all" && $prefix['forums'] != "-1") {
            // Decide whether this prefix can be used in our forum
            $forums = explode(",", $prefix['forums']);
            if (!in_array($fid, $forums)) {
                // This prefix is not in our forum list
                continue;
            }
        }
        if ($prefix['groups'] != "-1") {
            $prefix_groups = explode(",", $prefix['groups']);
            foreach ($groups as $group) {
                if (in_array($group, $prefix_groups) && !isset($prefixes[$prefix['pid']])) {
                    // Our group can use this prefix!
                    $prefixes[$prefix['pid']] = $prefix;
                }
            }
        } else {
            // This prefix is for anybody to use...
            $prefixes[$prefix['pid']] = $prefix;
        }
    }
    if (empty($prefixes)) {
        return false;
    }
    $prefixselect = "";
    if ($multiple != 0) {
        $prefixselect = "<select name=\"threadprefix[]\" multiple=\"multiple\" size=\"5\">\n";
    } else {
        $prefixselect = "<select name=\"threadprefix\">\n";
    }
    if ($multiple == 1) {
        $any_selected = "";
        if ($selected_pid == 'any') {
            $any_selected = " selected=\"selected\"";
        }
        $prefixselect .= "<option value=\"any\"" . $any_selected . ">" . $lang->any_prefix . "</option>\n";
    }
    $default_selected = "";
    if (intval($selected_pid) == 0 && $selected_pid != 'any') {
        $default_selected = " selected=\"selected\"";
    }
    $prefixselect .= "<option value=\"0\"" . $default_selected . ">" . $lang->no_prefix . "</option>\n";
    foreach ($prefixes as $prefix) {
        $selected = "";
        if ($prefix['pid'] == $selected_pid) {
            $selected = " selected=\"selected\"";
        }
        $prefixselect .= "<option value=\"" . $prefix['pid'] . "\"" . $selected . ">" . htmlspecialchars_uni($prefix['prefix']) . "</option>\n";
    }
    $prefixselect .= "</select>\n&nbsp;";
    return $prefixselect;
}
Exemple #11
0
 /**
  * Verify thread prefix.
  *
  * @return boolean True when valid, false when not valid.
  */
 function verify_prefix()
 {
     $prefix =& $this->data['prefix'];
     // If a valid prefix isn't supplied, don't assign one.
     if (empty($prefix)) {
         $prefix = 0;
     } else {
         $verification = build_prefixes($prefix);
         if (!$verification) {
             $this->set_error('invalid_prefix');
             return false;
         }
         if ($verification['groups'] != "-1") {
             if (!empty($this->data['edit_uid'])) {
                 // Post is being edited
                 $user = get_user($this->data['edit_uid']);
             } else {
                 $user = get_user($this->data['uid']);
             }
             $groups = array($user['usergroup']);
             if (!empty($user['additionalgroups'])) {
                 $groups = array_merge($groups, explode(',', $user['additionalgroups']));
             }
             $prefix_groups = explode(",", $verification['groups']);
             $valid_group = false;
             foreach ($groups as $group) {
                 if (in_array($group, $prefix_groups)) {
                     $valid_group = true;
                     break;
                 }
             }
             if (!$valid_group) {
                 $this->set_error('invalid_prefix');
                 return false;
             }
         }
         if ($verification['forums'] != "-1") {
             // Decide whether this prefix can be used in our forum
             $forums = explode(",", $verification['forums']);
             if (!in_array($this->data['fid'], $forums)) {
                 $this->set_error('invalid_prefix');
                 return false;
             }
         }
     }
     return true;
 }
Exemple #12
0
/**
 * Build the thread prefix selection menu for a forum
 *
 *  @param int $fid The forum ID (integer ID)
 *  @param int $selected_pid The selected prefix ID (integer ID)
 */
function build_forum_prefix_select($fid, $selected_pid = 0)
{
    global $cache, $db, $lang, $mybb, $templates;
    $fid = (int) $fid;
    $prefix_cache = build_prefixes(0);
    if (empty($prefix_cache)) {
        return false;
        // We've got no prefixes to show
    }
    // Go through each of our prefixes and decide which ones we can use
    $prefixes = array();
    foreach ($prefix_cache as $prefix) {
        if ($prefix['forums'] != "-1") {
            // Decide whether this prefix can be used in our forum
            $forums = explode(",", $prefix['forums']);
            if (in_array($fid, $forums)) {
                // This forum can use this prefix!
                $prefixes[$prefix['pid']] = $prefix;
            }
        } else {
            // This prefix is for anybody to use...
            $prefixes[$prefix['pid']] = $prefix;
        }
    }
    if (empty($prefixes)) {
        return false;
    }
    $default_selected = array();
    $selected_pid = (int) $selected_pid;
    if ($selected_pid == 0) {
        $default_selected['all'] = ' selected="selected"';
    } else {
        if ($selected_pid == -1) {
            $default_selected['none'] = ' selected="selected"';
        } else {
            if ($selected_pid == -2) {
                $default_selected['any'] = ' selected="selected"';
            }
        }
    }
    foreach ($prefixes as $prefix) {
        $selected = '';
        if ($prefix['pid'] == $selected_pid) {
            $selected = ' selected="selected"';
        }
        $prefix['prefix'] = htmlspecialchars_uni($prefix['prefix']);
        eval('$prefixselect_prefix .= "' . $templates->get("forumdisplay_threadlist_prefixes_prefix") . '";');
    }
    eval('$prefixselect = "' . $templates->get("forumdisplay_threadlist_prefixes") . '";');
    return $prefixselect;
}