function get_thread_by_unread_func($xmlrpc_params)
{
    global $db, $mybb;
    $input = Tapatalk_Input::filterXmlInput(array('topic_id' => Tapatalk_Input::STRING, 'posts_per_request' => 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);
    }
    $thread = get_thread($input['topic_id']);
    if (!empty($thread['closed'])) {
        $moved = explode("|", $thread['closed']);
        if ($moved[0] == "moved") {
            $thread = get_thread($moved[1]);
        }
    }
    if (is_moderator($thread['fid'])) {
        $visible = "AND (p.visible='0' OR p.visible='1')";
    } else {
        $visible = "AND p.visible='1'";
    }
    $cutoff = 0;
    if ($mybb->settings['threadreadcut'] > 0) {
        $cutoff = TIME_NOW - $mybb->settings['threadreadcut'] * 60 * 60 * 24;
    }
    $query = $db->query("select min(p.pid) as pid from " . TABLE_PREFIX . "posts p\n        LEFT JOIN " . TABLE_PREFIX . "threadsread tr on p.tid = tr.tid and tr.uid = '{$mybb->user['uid']}'\n        where p.tid='{$thread['tid']}' and p.uid != '{$mybb->user['uid']}' and (p.dateline > tr.dateline or tr.dateline is null) and p.dateline > {$cutoff} {$visible}\n        ");
    $pid = $db->fetch_field($query, 'pid');
    if (!$pid) {
        $query = $db->query("select p.pid from " . TABLE_PREFIX . "posts p\n                             where p.tid='{$thread['tid']}' {$visible}\n                             order by p.dateline desc\n                             limit 1");
        $pid = $db->fetch_field($query, 'pid');
    }
    return get_thread_by_post_func(new xmlrpcval(array(new xmlrpcval($pid, "string"), new xmlrpcval($input['posts_per_request'], 'int'), new xmlrpcval(!!$input['return_html'], 'boolean')), 'array'));
}
Example #2
0
function testApiFunction($func, $silent = true, $all = false)
{
    global $server_param, $error;
    echo "Testing {$func}... ";
    $time = microtime(true);
    if (in_array($func, array('remove_attachment', 'upload_avatar', 'delete_conversation'))) {
        echo "Skipped.\r\n";
        return;
    }
    $resp = false;
    $pass = 0;
    if (substr($func, 0, 2) == 'm_') {
        require_once "include/moderation.php";
    } else {
        require_once "include/" . str_replace("_func", "", $server_param[$func]['function']) . ".php";
    }
    try {
        ob_start();
        $error = "";
        switch ($func) {
            case "authorize_user":
                $resp = authorize_user_func(new xmlrpcval(array(new xmlrpcval("Darkimmortal", "string"), new xmlrpcval("9989", "string")), "array"));
                break;
            case "get_board_stat":
                $resp = get_board_stat_func(new xmlrpcval(array(), "array"));
                break;
            case "get_box":
                $resp = get_box_func(new xmlrpcval(array(new xmlrpcval("0", "string"), new xmlrpcval("0", "int"), new xmlrpcval("25", "int")), "array"));
                break;
            case "get_box_info":
                $resp = get_box_info_func(new xmlrpcval(array(), "array"));
                break;
            case "get_config":
                $resp = get_config_func(new xmlrpcval(array(), "array"));
                break;
            case "get_conversation":
                $resp = get_conversation_func(new xmlrpcval(array(new xmlrpcval("2", "string"), new xmlrpcval("0", "int"), new xmlrpcval("25", "int")), "array"));
                break;
            case "get_conversations":
                $resp = get_conversations_func(new xmlrpcval(array(new xmlrpcval("0", "int"), new xmlrpcval("25", "int")), "array"));
                break;
            case "m_stick_topic":
                $resp = m_stick_topic_func(new xmlrpcval(array(new xmlrpcval("2", "int"), new xmlrpcval("2", "int")), "array"));
                break;
            case "m_ban_user":
                $resp = m_ban_user_func(new xmlrpcval(array(new xmlrpcval("another user", "string"), new xmlrpcval("1", "int"), new xmlrpcval("testing ban...", "string")), "array"));
                break;
            case "get_dashboard":
                $resp = get_dashboard_func(new xmlrpcval(array(new xmlrpcval(false, "boolean")), "array"));
                break;
            case "get_forum":
                $resp = get_forum_func(new xmlrpcval(array(), "array"));
                break;
            case "upload_attach":
                $resp = upload_attach_func(new xmlrpcval(array(new xmlrpcval("2", "string"), new xmlrpcval("", "string"), new xmlrpcval("aaaa", "string")), "array"));
                break;
            case "create_message":
                $resp = create_message_func(new xmlrpcval(array(new xmlrpcval(array(new xmlrpcval("Darkimmortal ", "string"), new xmlrpcval("another user", "string")), "array"), new xmlrpcval("test pm #" . mt_rand(0, 99999), "string"), new xmlrpcval("UNIT TEST PM #" . mt_rand(0, 99999) . " [b]lol [i]test[/i][/b]", "string"), new xmlrpcval(1, "int"), new xmlrpcval("0", "string")), "array"));
                break;
            case "get_box":
                $resp = get_box_func(new xmlrpcval(array(new xmlrpcval("1", "string"), new xmlrpcval("0", "string"), new xmlrpcval("25", "string")), "array"));
                break;
            case "get_message":
                $resp = get_message_func(new xmlrpcval(array(new xmlrpcval("5", "string"), new xmlrpcval("1", "string"), new xmlrpcval(true, "boolean")), "array"));
                break;
            case "get_quote_pm":
                $resp = get_quote_pm_func(new xmlrpcval(array(new xmlrpcval("5", "string")), "array"));
                break;
            case "delete_message":
                $resp = delete_message_func(new xmlrpcval(array(new xmlrpcval("8", "string"), new xmlrpcval("1", "string")), "array"));
                break;
            case "mark_pm_unread":
                $resp = mark_pm_unread_func(new xmlrpcval(array(new xmlrpcval("5", "string"), new xmlrpcval("1", "string")), "array"));
                break;
            case "get_box":
                $resp = get_box_info_func(new xmlrpcval(array(), "array"));
                break;
            case "get_id_by_url":
                $resp = get_id_by_url_func(new xmlrpcval(array(new xmlrpcval("http://kiririn/mybb/showthread.php?tid=3&pid=20#pid20", "string")), "array"));
                break;
            case "get_inbox_stat":
                $resp = get_inbox_stat_func(new xmlrpcval(array(new xmlrpcval("0", "string"), new xmlrpcval("0", "string")), "array"));
                break;
            case "get_latest_topic":
                $resp = get_latest_topic_func(new xmlrpcval(array(new xmlrpcval("0", "int"), new xmlrpcval("25", "int")), "array"));
                break;
            case "get_new_topic":
                $resp = get_new_topic_func(new xmlrpcval(array(new xmlrpcval("0", "int"), new xmlrpcval("25", "int")), "array"));
                break;
            case "get_online_users":
                $resp = get_online_users_func(new xmlrpcval(array(), "array"));
                break;
            case "get_participated_topic":
                $resp = get_participated_topic_func(new xmlrpcval(array(new xmlrpcval("Darkimmortal", "string"), new xmlrpcval("0", "int"), new xmlrpcval("10", "int")), "array"));
                break;
            case "get_quote_conversation":
                $resp = get_quote_conversation_func(new xmlrpcval(array(new xmlrpcval("2", "string"), new xmlrpcval("2", "string")), "array"));
                break;
            case "get_quote_post":
                $resp = get_quote_post_func(new xmlrpcval(array(new xmlrpcval("2", "string")), "array"));
                break;
            case "get_raw_post":
                $resp = get_raw_post_func(new xmlrpcval(array(new xmlrpcval("2", "string")), "array"));
                break;
            case "get_subscribed_forum":
                $resp = get_subscribed_forum_func(new xmlrpcval(array(), "array"));
                break;
            case "get_subscribed_topic":
                $resp = get_subscribed_topic_func(new xmlrpcval(array(new xmlrpcval("0", "int"), new xmlrpcval("25", "int")), "array"));
                break;
            case "get_thread":
                $resp = get_thread_func(new xmlrpcval(array(new xmlrpcval("5", "string"), new xmlrpcval("0", "int"), new xmlrpcval("25", "int"), new xmlrpcval(true, "boolean")), "array"));
                break;
            case "get_thread_by_post":
                $resp = get_thread_by_post_func(new xmlrpcval(array(new xmlrpcval("2", "string"), new xmlrpcval("20", "int"), new xmlrpcval(true, "boolean")), "array"));
                break;
            case "get_thread_by_unread":
                $resp = get_thread_by_unread_func(new xmlrpcval(array(new xmlrpcval("2", "string"), new xmlrpcval("20", "int"), new xmlrpcval(true, "boolean")), "array"));
                break;
            case "get_topic":
                $resp = get_topic_func(new xmlrpcval(array(new xmlrpcval("2", "string"), new xmlrpcval("0", "int"), new xmlrpcval("25", "int"), new xmlrpcval("", "string")), "array"));
                break;
            case "get_unread_topic":
                $resp = get_unread_topic_func(new xmlrpcval(array(new xmlrpcval("0", "int"), new xmlrpcval("25", "int"), new xmlrpcval(array("not_in" => new xmlrpcval(array(), "array"), "only_in" => new xmlrpcval(array(new xmlrpcval("2", "string")), "array")), "struct")), "array"));
                break;
            case "get_user_info":
                $resp = get_user_info_func(new xmlrpcval(array(new xmlrpcval("Darkimmortal", "string")), "array"));
                break;
            case "get_user_reply_post":
                $resp = get_user_reply_post_func(new xmlrpcval(array(new xmlrpcval("Darkimmortal", "string")), "array"));
                break;
            case "get_user_topic":
                $resp = get_user_topic_func(new xmlrpcval(array(new xmlrpcval("Darkimmortal", "string")), "array"));
                break;
            case "invite_participant":
                $resp = invite_participant_func(new xmlrpcval(array(new xmlrpcval(array(new xmlrpcval("another user", "string")), "array"), new xmlrpcval("2", "string")), "array"));
                break;
            case "like_post":
                $resp = like_post_func(new xmlrpcval(array(new xmlrpcval("39", "string")), "array"));
                break;
            case "login":
                $resp = login_func(new xmlrpcval(array(new xmlrpcval("Darkimmortal", "string"), new xmlrpcval("9989", "string")), "array"));
                break;
            case "login_forum":
                $resp = login_forum_func(new xmlrpcval(array(new xmlrpcval("5", "int"), new xmlrpcval("1", "string")), "array"));
                break;
            case "logout_user":
                if (!$all) {
                    $resp = logout_user_func(new xmlrpcval(array(), "array"));
                }
                break;
            case "mark_all_as_read":
                $resp = mark_all_as_read_func(new xmlrpcval(array(), "array"));
                break;
            case "new_conversation":
                $resp = new_conversation_func(new xmlrpcval(array(new xmlrpcval(array(new xmlrpcval("another user", "string")), "array"), new xmlrpcval("unit test conversation", "string"), new xmlrpcval("[b]lol [i]test[/i][/b]", "string")), "array"));
                break;
            case "new_topic":
                $resp = new_topic_func(new xmlrpcval(array(new xmlrpcval("2", "string"), new xmlrpcval("unit test topic #" . mt_rand(0, 99999), "string"), new xmlrpcval("[b]lol [i]test[/i][/b]", "string"), new xmlrpcval("", "string"), new xmlrpcval(array(), "array"), new xmlrpcval("", "string")), "array"));
                break;
            case "reply_conversation":
                $resp = reply_conversation_func(new xmlrpcval(array(new xmlrpcval("2", "string"), new xmlrpcval("UNIT TEST REPLY [b]lol [i]test[/i][/b]", "string")), "array"));
                break;
            case "reply_post":
                $resp = reply_post_func(new xmlrpcval(array(new xmlrpcval("2", "string"), new xmlrpcval("2", "string"), new xmlrpcval("unit test reply #" . mt_rand(0, 99999), "string"), new xmlrpcval("UNIT TEST REPLY #" . mt_rand(0, 99999) . " [b]lol [i]test[/i][/b]", "string"), new xmlrpcval(array(), "array"), new xmlrpcval("", "string"), new xmlrpcval(true, "boolean")), "array"));
                break;
            case "reply_topic":
                $resp = reply_topic_func(new xmlrpcval(array(new xmlrpcval("2", "string"), new xmlrpcval("2", "string"), new xmlrpcval("unit test reply #" . mt_rand(0, 99999), "string"), new xmlrpcval("UNIT TEST REPLY #" . mt_rand(0, 99999) . " [b]lol [i]test[/i][/b]", "string"), new xmlrpcval(array(), "array"), new xmlrpcval("", "string"), new xmlrpcval(true, "boolean")), "array"));
                break;
            case "report_pm":
                $resp = report_pm_func(new xmlrpcval(array(), "array"));
                break;
            case "report_post":
                $resp = report_post_func(new xmlrpcval(array(new xmlrpcval("2", "string"), new xmlrpcval("unit test report reason #" . mt_rand(0, 99999), "string")), "array"));
                break;
            case "save_raw_post":
                $resp = save_raw_post_func(new xmlrpcval(array(new xmlrpcval("14", "string"), new xmlrpcval("unit test edit title #" . mt_rand(0, 99999), "string"), new xmlrpcval("[color=red]unit test edit #" . mt_rand(0, 99999) . "[/color] :cool:", "string"), new xmlrpcval(true, "boolean")), "array"));
                break;
            case "search_post":
                $resp = search_post_func(new xmlrpcval(array(new xmlrpcval("test", "string"), new xmlrpcval("0", "int"), new xmlrpcval("25", "int"), new xmlrpcval("", "string")), "array"));
                break;
            case "search_topic":
                $resp = search_topic_func(new xmlrpcval(array(new xmlrpcval("test", "string"), new xmlrpcval("0", "int"), new xmlrpcval("25", "int"), new xmlrpcval("", "string")), "array"));
                break;
            case "subscribe_forum":
                $resp = subscribe_forum_func(new xmlrpcval(array(), "array"));
                break;
            case "subscribe_topic":
                $resp = subscribe_topic_func(new xmlrpcval(array(new xmlrpcval("23", "string")), "array"));
                break;
            case "unlike_post":
                $resp = unlike_post_func(new xmlrpcval(array(new xmlrpcval("39", "string")), "array"));
                break;
            case "unsubscribe_forum":
                $resp = unsubscribe_forum_func(new xmlrpcval(array(), "array"));
                break;
            case "unsubscribe_topic":
                $resp = unsubscribe_topic_func(new xmlrpcval(array(new xmlrpcval("23", "string")), "array"));
                break;
            default:
                echo "Unknown function/no unit test implemented yet.";
                $pass = 2;
        }
        //$ob = ob_get_clean();
        if ($pass < 2) {
            $pass = 1;
        }
        if (strlen($error) > 0) {
            $pass = -1;
        }
    } catch (Exception $e) {
        $pass = 0;
        echo "*FAILED*:\r\n";
        throw $e;
        echo "\r\n";
    }
    if ($pass === 1) {
        echo "Passed! (";
        echo round(microtime(true) - $time, 4);
        echo ")";
    }
    if ($pass < 1 && $resp !== false && !$silent || !$all) {
        echo "\r\n";
        var_dump($resp);
        //var_dump($ob);
    }
    if ($pass == -1) {
        echo "*FAILED*: ";
    }
    echo $error;
    echo "\r\n";
}