示例#1
0
function build_board($boards, $is_cat = false)
{
    global $settings, $context, $user_info, $smcFunc, $boardurl, $boarddir, $modSettings, $board;
    $response = array();
    foreach ($boards as $id => $tt_board) {
        if (empty($tt_board['id'])) {
            continue;
        }
        $new_post = false;
        if ($tt_board['new'] || $tt_board['children_new']) {
            $new_post = true;
            $logo_url = $settings['images_url'] . '/' . $context['theme_variant_url'] . 'on' . ($tt_board['new'] ? '' : '2') . '.png';
        } elseif ($tt_board['redirect']) {
            $logo_url = $settings['images_url'] . '/' . $context['theme_variant_url'] . 'redirect.png';
        } else {
            $logo_url = $settings['images_url'] . '/' . $context['theme_variant_url'] . 'off.png';
        }
        $logo_dir = str_replace($boardurl, $boarddir, $logo_url);
        if (!file_exists($logo_dir) && file_exists(preg_replace('/png$/', 'gif', $logo_dir))) {
            $logo_url = preg_replace('/png$/', 'gif', $logo_url);
        }
        $is_link_forum = isset($tt_board['redirect']) && !empty($tt_board['redirect']);
        if (!$is_cat && !$user_info['is_guest']) {
            $can_subscribe = allowedTo('mark_notify', $tt_board['id']);
            $request = $smcFunc['db_query']('', '
                SELECT sent
                FROM {db_prefix}log_notify
                WHERE id_board = {int:current_board}
                    AND id_member = {int:current_member}
                LIMIT 1', array('current_board' => $tt_board['id'], 'current_member' => $user_info['id']));
            $is_subscribed = $smcFunc['db_num_rows']($request) != 0;
            $smcFunc['db_free_result']($request);
            $board = $tt_board['id'];
            loadBoard();
            loadPermissions();
            $can_post_new = (allowedTo('post_new') || $modSettings['postmod_active'] && allowedTo('post_unapproved_topics')) && !$is_link_forum;
            $mobiquo_can_post = true;
            if (isset($modSettings['boards_disable_new_topic']) && !empty($modSettings['boards_disable_new_topic'])) {
                $dis_new_topic_boards = explode(',', $modSettings['boards_disable_new_topic']);
                $mobiquo_can_post = !in_array($tt_board['id'], $dis_new_topic_boards);
            }
            $can_post = $can_post_new && $mobiquo_can_post ? true : false;
        } else {
            $can_subscribe = false;
            $is_subscribed = false;
            $can_post = false;
        }
        $tp_board_id = $is_cat ? preg_replace('/c/', '', $tt_board['id']) : $tt_board['id'];
        $logo_url = ($tp_logo_url = tp_get_forum_icon($tp_board_id, $is_link_forum ? 'link' : ($is_cat ? 'category' : 'forum'), false, $new_post)) ? $tp_logo_url : $logo_url;
        $xmlrpc_forum = array('forum_id' => new xmlrpcval($tt_board['id'], 'string'), 'forum_name' => new xmlrpcval(basic_clean($tt_board['name']), 'base64'), 'parent_id' => new xmlrpcval($tt_board['id_parent'] ? $tt_board['id_parent'] : 'c' . $tt_board['id_cat'], 'string'), 'logo_url' => new xmlrpcval($logo_url, 'string'), 'new_post' => new xmlrpcval($new_post, 'boolean'), 'url' => new xmlrpcval($tt_board['redirect'], 'string'), 'sub_only' => new xmlrpcval($is_cat, 'boolean'), 'can_subscribe' => new xmlrpcval($can_subscribe, 'boolean'), 'is_subscribed' => new xmlrpcval($is_subscribed, 'boolean'), 'is_protected' => new xmlrpcval(false, 'boolean'), 'can_post' => new xmlrpcval($can_post, 'boolean'));
        if ($_GET['return_description']) {
            $xmlrpc_forum['description'] = new xmlrpcval(basic_clean($tt_board['description']), 'base64');
        }
        if (isset($_GET['forum_id']) && (!empty($_GET['forum_id']) || $_GET['forum_id'] === 0)) {
            $xmlrpc_forum['has_child'] = new xmlrpcval($tt_board['has_child'], 'boolean');
        }
        if (isset($tt_board['boards']) && !empty($tt_board['boards'])) {
            $xmlrpc_forum['child'] = new xmlrpcval(build_board($tt_board['boards']), 'array');
        }
        $response[] = new xmlrpcval($xmlrpc_forum, 'struct');
    }
    return $response;
}
示例#2
0
function get_forum_func($xmlrpc_params)
{
    global $db, $auth, $user, $config, $mobiquo_config, $phpbb_home;
    $params = php_xmlrpc_decode($xmlrpc_params);
    $return_description = isset($params[0]) ? $params[0] : false;
    if (isset($params[1])) {
        $fid = intval($params[1]);
        $forum_filter = " WHERE f.parent_id = '{$fid}'";
        $root_forum_id = $fid;
    } else {
        $forum_filter = '';
        $root_forum_id = 0;
    }
    $user_watch_array = array();
    if ($user->data['is_registered']) {
        $sql = "SELECT notify_status,forum_id FROM " . FORUMS_WATCH_TABLE . " WHERE user_id = '" . $user->data['user_id'] . "'";
        $result_watch = $db->sql_query($sql);
        while ($row_watch = $db->sql_fetchrow($result_watch)) {
            if (isset($row_watch['notify_status']) && !is_null($row_watch['notify_status']) && $row_watch['notify_status'] !== '') {
                $user_watch_array[] = $row_watch['forum_id'];
            }
        }
    }
    $forum_rows = array();
    $forum_rows[$root_forum_id] = array('forum_id' => $root_forum_id, 'parent_id' => -1, 'child' => array());
    $forum_hide_forum_arr = !empty($mobiquo_config['hide_forum_id']) ? $mobiquo_config['hide_forum_id'] : array();
    $sql = 'SELECT f.*  FROM ' . FORUMS_TABLE . ' f ' . $forum_filter . '
            ORDER BY f.left_id ASC';
    $result = $db->sql_query($sql, 600);
    while ($row = $db->sql_fetchrow($result)) {
        $forum_id = $row['forum_id'];
        if ($row['forum_type'] == FORUM_CAT && $row['left_id'] + 1 == $row['right_id']) {
            // Non-postable forum with no subforums, don't display
            continue;
        }
        if (in_array($row['forum_id'], $forum_hide_forum_arr)) {
            continue;
        } elseif (in_array($row['parent_id'], $forum_hide_forum_arr)) {
            array_push($forum_hide_forum_arr, $row['forum_id']);
            continue;
        }
        // Skip branch
        if (isset($right_id)) {
            if ($row['left_id'] < $right_id) {
                continue;
            }
            unset($right_id);
        }
        if (!$auth->acl_get('f_list', $forum_id) || isset($mobiquo_config['hide_forum_id']) && in_array($forum_id, $mobiquo_config['hide_forum_id'])) {
            // if the user does not have permissions to list this forum, skip everything until next branch
            $right_id = $row['right_id'];
            continue;
        }
        $row['unread_count'] = 0;
        if ($user->data['is_registered'] && ($config['email_enable'] || $config['jab_enable']) && $config['allow_forum_notify'] && $row['forum_type'] == FORUM_POST && $auth->acl_get('f_subscribe', $forum_id)) {
            $row['can_subscribe'] = true;
            $row['is_subscribed'] = in_array($row['forum_id'], $user_watch_array) ? true : false;
        } else {
            $row['can_subscribe'] = false;
            $row['is_subscribed'] = false;
        }
        $forum_rows[$forum_id] = $row;
    }
    $db->sql_freeresult($result);
    $fids = array(-1);
    foreach ($forum_rows as $id => $value) {
        if (!in_array($value['parent_id'], $fids)) {
            unset($forum_rows[$id]);
        } else {
            if ($value['left_id'] > $value['right_id']) {
                unset($forum_rows[$id]);
            } else {
                $fids[] = $id;
            }
        }
    }
    while (empty($forum_rows[$root_forum_id]['child']) && count($forum_rows) > 1) {
        $current_parent_id = -1;
        $leaves_forum = array();
        foreach ($forum_rows as $row) {
            $row_parent_id = $row['parent_id'];
            if ($row_parent_id != $current_parent_id) {
                if (isset($leaves_forum[$row_parent_id])) {
                    $leaves_forum[$row_parent_id] = array();
                } else {
                    if (isset($leaves_forum[$forum_rows[$row_parent_id]['parent_id']])) {
                        $leaves_forum[$forum_rows[$row_parent_id]['parent_id']] = array();
                    }
                    $leaves_forum[$row_parent_id][] = $row['forum_id'];
                }
                $current_parent_id = $row_parent_id;
            } else {
                if ($row_parent_id == $current_parent_id) {
                    if (!empty($leaves_forum[$row_parent_id])) {
                        $leaves_forum[$row_parent_id][] = $row['forum_id'];
                    }
                }
            }
        }
        foreach ($leaves_forum as $node_forum_id => $leaves) {
            foreach ($leaves as $forum_id) {
                $forum =& $forum_rows[$forum_id];
                if (function_exists('get_unread_topics')) {
                    $unread_count = count(get_unread_topics(false, "AND t.forum_id = {$forum_id}"));
                } else {
                    $unread_count = count(tt_get_unread_topics(false, "AND t.forum_id = {$forum_id}"));
                }
                $forum['unread_count'] += $unread_count;
                if ($forum['unread_count']) {
                    $forum_rows[$forum['parent_id']]['unread_count'] += $forum['unread_count'];
                }
                $forum_type = $forum['forum_link'] ? 'link' : ($forum['forum_type'] != FORUM_POST ? 'category' : 'forum');
                if ($logo_icon_name = tp_get_forum_icon($forum_id, $forum_type, $forum['forum_status'], $forum['unread_count'])) {
                    $logo_url = $phpbb_home . $config['tapatalkdir'] . '/forum_icons/' . $logo_icon_name;
                } else {
                    if ($forum['forum_image']) {
                        if (preg_match('#^https?://#i', $forum['forum_image'])) {
                            $logo_url = $forum['forum_image'];
                        } else {
                            $logo_url = $phpbb_home . $forum['forum_image'];
                        }
                    } else {
                        $logo_url = '';
                    }
                }
                $xmlrpc_forum = array('forum_id' => new xmlrpcval($forum_id), 'forum_name' => new xmlrpcval(basic_clean($forum['forum_name']), 'base64'), 'parent_id' => new xmlrpcval($node_forum_id), 'logo_url' => new xmlrpcval($logo_url), 'url' => new xmlrpcval($forum['forum_link']));
                if ($forum['unread_count']) {
                    $xmlrpc_forum['unread_count'] = new xmlrpcval($forum['unread_count'], 'int');
                }
                if ($forum['unread_count']) {
                    $xmlrpc_forum['new_post'] = new xmlrpcval(true, 'boolean');
                }
                if ($forum['forum_password']) {
                    $xmlrpc_forum['is_protected'] = new xmlrpcval(true, 'boolean');
                }
                if (!empty($forum['can_subscribe'])) {
                    $xmlrpc_forum['can_subscribe'] = new xmlrpcval(true, 'boolean');
                } else {
                    $xmlrpc_forum['can_subscribe'] = new xmlrpcval(false, 'boolean');
                }
                if (!empty($forum['is_subscribed'])) {
                    $xmlrpc_forum['is_subscribed'] = new xmlrpcval(true, 'boolean');
                } else {
                    $xmlrpc_forum['is_subscribed'] = new xmlrpcval(false, 'boolean');
                }
                if ($forum['forum_type'] != FORUM_POST) {
                    $xmlrpc_forum['sub_only'] = new xmlrpcval(true, 'boolean');
                }
                if ($return_description) {
                    $description = smiley_text($forum['forum_desc'], true);
                    $description = generate_text_for_display($description, $forum['forum_desc_uid'], $forum['forum_desc_bitfield'], $forum['forum_desc_options']);
                    $description = preg_replace('/<br *?\\/?>/i', "\n", $description);
                    $xmlrpc_forum['description'] = new xmlrpcval(basic_clean($description), 'base64');
                }
                if (isset($forum['child'])) {
                    $xmlrpc_forum['child'] = new xmlrpcval($forum['child'], 'array');
                }
                $forum_rows[$node_forum_id]['child'][] = new xmlrpcval($xmlrpc_forum, 'struct');
                unset($forum_rows[$forum_id]);
            }
        }
    }
    $response = new xmlrpcval($forum_rows[$root_forum_id]['child'], 'array');
    return new xmlrpcresp($response);
}
示例#3
0
function processForum($forum)
{
    global $db, $lang, $theme, $plugins, $mybb, $session, $settings, $cache, $time, $mybbgroups, $forumpermissions, $fcache;
    static $private_forums;
    $permissions = $forumpermissions[$forum['fid']];
    $hideinfo = false;
    $showlockicon = 0;
    if ($permissions['canviewthreads'] != 1) {
        $hideinfo = true;
    }
    if ($permissions['canonlyviewownthreads'] == 1) {
        $hideinfo = true;
        // If we only see our own threads, find out if there's a new post in one of them so the lightbulb shows
        if (!is_array($private_forums)) {
            $private_forums = $fids = array();
            foreach ($fcache[$forum['pid']] as $parent_p) {
                foreach ($parent_p as $forum_p) {
                    if ($forumpermissions[$forum_p['fid']]['canonlyviewownthreads']) {
                        $fids[] = $forum_p['fid'];
                    }
                }
            }
            if (!empty($fids)) {
                $fids = implode(',', $fids);
                $query = $db->simple_select("threads", "tid, fid, lastpost", "uid = '{$mybb->user['uid']}' AND fid IN ({$fids})", array("order_by" => "lastpost", "order_dir" => "desc"));
                while ($thread = $db->fetch_array($query)) {
                    if (!$private_forums[$thread['fid']]) {
                        $private_forums[$thread['fid']] = $thread;
                    }
                }
            }
        }
        if ($private_forums[$forum['fid']]['lastpost']) {
            $forum['lastpost'] = $private_forums[$forum['fid']]['lastpost'];
            $lastpost_data = array("lastpost" => $private_forums[$forum['fid']]['lastpost']);
        }
    } else {
        $lastpost_data = array("lastpost" => $forum['lastpost'], "lastpostsubject" => $forum['lastpostsubject'], "lastposter" => $forum['lastposter'], "lastposttid" => $forum['lastposttid'], "lastposteruid" => $forum['lastposteruid']);
    }
    if ($forum['password'] != '' && $mybb->cookies['forumpass'][$forum['fid']] != md5($mybb->user['uid'] . $forum['password'])) {
        $hideinfo = true;
        $showlockicon = 1;
    }
    // If we are hiding information (lastpost) because we aren't authenticated against the password for this forum, remove them
    if ($hideinfo == true) {
        unset($lastpost_data);
    }
    $lightbulb = get_forum_lightbulb($forum, $lastpost_data, $showlockicon);
    $new_post = $lightbulb['folder'] == 'on';
    $is_locked = $forum['open'] == 0;
    $forum_type = $forum['linkto'] ? 'link' : ($forum['type'] == 'c' ? 'category' : 'forum');
    if ($logo_icon_name = tp_get_forum_icon($forum['fid'], $forum_type, $is_locked, $new_post)) {
        $logo_url = $mybb->settings['bburl'] . '/' . $mybb->settings['tapatalk_directory'] . '/forum_icons/' . $logo_icon_name;
    } else {
        if ($forum['forum_image']) {
            if (preg_match('#^https?://#i', $forum['forum_image'])) {
                $logo_url = $forum['forum_image'];
            } else {
                $logo_url = $mybb->settings['bburl'] . '/' . $forum['forum_image'];
            }
        } else {
            $logo_url = '';
        }
    }
    $xmlrpc_forum = new xmlrpcval(array('forum_id' => new xmlrpcval($forum['fid'], 'string'), 'forum_name' => new xmlrpcval(basic_clean($forum['name']), 'base64'), 'description' => new xmlrpcval($forum['description'], 'base64'), 'parent_id' => new xmlrpcval($forum['pid'], 'string'), 'logo_url' => new xmlrpcval($logo_url, 'string'), 'new_post' => new xmlrpcval($new_post, 'boolean'), 'unread_count' => new xmlrpcval($forum['unread_count'], 'int'), 'is_protected' => new xmlrpcval(!empty($forum['password']), 'boolean'), 'url' => new xmlrpcval($forum['linkto'], 'string'), 'sub_only' => new xmlrpcval($forum['type'] == 'c', 'boolean'), 'can_subscribe' => new xmlrpcval($forumpermissions[$forum['fid']]['canviewthreads'] == 1, 'boolean'), 'is_subscribed' => new xmlrpcval(!empty($forum['fsid']), 'boolean')), 'struct');
    return array($xmlrpc_forum, $new_post);
}