Beispiel #1
0
<?php

date_default_timezone_set('Asia/Kolkata');
require '../vendor/autoload.php';
require 'controllers.php';
//ForLogging - AccessLogs
$log = new \Slim\LogWriter(fopen('../logs/access.log', 'a'));
$app = new \Slim\Slim(array('mode' => 'development', 'log.writer' => $log, 'log.level' => \Slim\Log::DEBUG, 'log.enabled' => true, 'http.version' => '1.1', 'contentType' => 'application/json'));
$app->setName('HIND');
// TEST GET route
$app->get('/hello', function () use($app) {
    $request = $app->request;
    $response = $app->response;
    $response->write(json_encode("API Application is Up and Running :) by " . $app->getName()));
    $app->log->info('RequestIP: ' . $request->getIp() . ',TimeStamp: ' . date('Y-m-d h:i:s') . ',RequestPath: /api/v1' . $request->getPathInfo() . ',ResponseCode: ' . $response->getStatus() . ',Response: ' . $response->getBody());
    $app->log->info('-----------------------------------------------------------------------------------------------------------------------');
});
//GET ROUTES
$app->get('/categories', 'getCategories');
$app->get('/users/count', 'getUsersCount');
$app->get('/threads/count', 'getThreadsCount');
$app->get('/view/profile/:username', function ($username) {
    getProfile($username);
});
$app->get('/view/:deal_category/:thread_type/:thread_state', function ($deal_category, $thread_type, $thread_state) {
    getThread($deal_category, $thread_type, $thread_state);
});
//POST ROUTES
$app->post('/submit/misc', 'postMiscellaneous');
$app->post('/submit/deal', 'postDeal');
$app->run();
Beispiel #2
0
<?session_start();
if(!isset($_GET['id'])){
  header('Location: header.php');
  exit();
}
require_once('database/view_thread.php');
?>

<!DOCTYPE html>

<html>
  <head>
    <?require_once('includes.php');?>
    <script type="text/javascript" src="scripts/ajaxComments.js" ></script>
    <link rel="stylesheet" type="text/css" href="stylesheets/thread.css" >

  </head>
  <body>
  <? require_once('templates/header.php'); ?>
  <?getThread($_GET['id']);?>
</html>
Beispiel #3
0
}
/* Perform the correct action based on the parsed request array */
if ($request[0] == "POST") {
    // if something sent via POST
    if ($id) {
        // if the ID is provided, it's supposed to be a reply to a thread
        $results = postToThread($id, $_POST);
    } else {
        // otherwise it's new thread
        $results = postNewThread($_POST);
    }
} elseif ($request[0] == "GET") {
    // else if something via GET
    if ($id) {
        // id set, fetch certain thread
        $results = getThread($id);
    } else {
        // otherwise fetch them all
        $results = getAllThreads();
    }
} else {
    // if method is not "GET" nor "POST", it should not be allowed
    die("Invalid API Call: This method is not allowed");
}
if (!$results) {
    // if $results is NULL something is wrong, show error
    die("Invalid API Call: Internal error");
} else {
    echo json_encode($results);
}
// otherwise JSON the results
Beispiel #4
0
                                            $resultBlock->execute($dataBlock);
                                        } catch (PDOException $e) {
                                            print "<div class='error'>" . $e->getMessage() . "</div>";
                                        }
                                        while ($rowBlock = $resultBlock->fetch()) {
                                            print "<h5 style='font-size: 85%'>" . $rowBlock["title"] . "</h5>";
                                            print "<p>";
                                            print "<b>" . _('Type') . "</b>: " . $rowBlock["type"] . "<br/>";
                                            print "<b>" . _('Length') . "</b>: " . $rowBlock["length"] . "<br/>";
                                            print "<b>" . _('Contents') . "</b>: " . $rowBlock["contents"] . "<br/>";
                                            if ($rowBlock["teachersNotes"] != "") {
                                                print "<div style='background-color: #F6CECB; padding: 0px 3px 10px 3px; width: 98%; text-align: justify; border-bottom: 1px solid #ddd'><p style='margin-bottom: 0px'><b>" . _("Teacher's Notes") . ":</b></p> " . $rowBlock["teachersNotes"] . "</div>";
                                            }
                                            print "</p>";
                                        }
                                        //Print chats
                                        print "<h5 style='font-size: 85%'>" . _("Chat") . "</h5>";
                                        print getThread($guid, $connection2, $rowLessons["gibbonPlannerEntryID"], NULL, 0, NULL, NULL, NULL, NULL, NULL, $class[1], $_SESSION[$guid]["gibbonPersonID"], "Teacher", FALSE);
                                    }
                                }
                                print "</div>";
                                $classCount++;
                            }
                            print "</div>";
                        }
                    }
                }
            }
        }
    }
}
Beispiel #5
0
            echo "Something went wrong";
        }
    }
} elseif (!(array_key_exists('tid', $_GET) || array_key_exists('fid', $_GET) || array_key_exists('pid', $_GET))) {
    echo "Forum or thread not defined";
} else {
    $content = "";
    if (array_key_exists('tid', $_GET)) {
        $tid = $_GET['tid'];
        $title = "Re: " . getTopicTitle($tid);
        $fid = getParent($tid);
        $legend = "New post in {$title}";
        $button = "Post";
    } elseif (array_key_exists('pid', $_GET)) {
        $pid = $_GET['pid'];
        $tid = getThread($pid);
        $title = getTopicTitle($tid);
        $fid = getParent($tid);
        $content = getPost($pid)->content;
        $legend = "Edit Post";
        $button = "Edit";
    } else {
        $title = "";
        $tid = "";
        $fid = $_GET['fid'];
        $legend = "New Thread";
        $button = "Create Thread";
    }
    ?>

<!-- Temporary link to profile, should link to thread page -->
Beispiel #6
0
     }
     interests_option($interests_option);
     break;
 case "load_recent_category_topics":
     $categoryid = "";
     if (isset($_REQUEST['categoryid'])) {
         $categoryid = $_REQUEST['categoryid'];
     }
     loadRecentCategoryTopics($categoryid);
     break;
 case "get_thread":
     $threadid = "";
     if (isset($_REQUEST['threadid'])) {
         $threadid = $_REQUEST['threadid'];
     }
     getThread($threadid);
     break;
 case "thread_selected":
     $forum = "";
     if (isset($_REQUEST['forum'])) {
         $forum = $_REQUEST['forum'];
     }
     $threadid = "";
     if (isset($_REQUEST['threadid'])) {
         $threadid = $_REQUEST['threadid'];
     }
     threadSelected($forum, $threadid);
     break;
 case "get_forum_details":
     $forum = "";
     if (isset($_REQUEST['forum'])) {
                        } else {
                            $linkText = _("Draft") . $rowWork["count"];
                        }
                        if ($rowWork["type"] == "File") {
                            print "<span title='" . $rowWork["version"] . ". Submitted at " . substr($rowWork["timestamp"], 11, 5) . " on " . dateConvertBack($guid, substr($rowWork["timestamp"], 0, 10)) . "'><a href='" . $_SESSION[$guid]["absoluteURL"] . "/" . $rowWork["location"] . "'>{$linkText}</a></span>";
                        } else {
                            print "<span title='" . $rowWork["version"] . ". Submitted at " . substr($rowWork["timestamp"], 11, 5) . " on " . dateConvertBack($guid, substr($rowWork["timestamp"], 0, 10)) . "'><a target='_blank' href='" . $rowWork["location"] . "'>{$linkText}</a></span>";
                        }
                        print "</td>";
                        print "<td style='width: 34%; vertical-align: top'>";
                        print "<span style='font-size: 115%; font-weight: bold'>Like Count</span><br/>";
                        $likesTotal = countLikesByContext($connection2, "Crowd Assessment", "gibbonPlannerEntryHomeworkID", $rowWork["gibbonPlannerEntryHomeworkID"]);
                        print " x " . $likesTotal;
                        print "</td>";
                        print "</tr>";
                        print "</table>";
                        print "<div style='margin: 0px' class='linkTop'>";
                        print "<a href='" . $_SESSION[$guid]["absoluteURL"] . "/index.php?q=/modules/" . $_SESSION[$guid]["module"] . "/crowdAssess_view_discuss_post.php&gibbonPersonID={$gibbonPersonID}&gibbonPlannerEntryID={$gibbonPlannerEntryID}&gibbonPlannerEntryHomeworkID={$gibbonPlannerEntryHomeworkID}'>" . _('Add') . "<img style='margin-left: 5px' title='" . _('Add') . "' src='./themes/" . $_SESSION[$guid]["gibbonThemeName"] . "/img/page_new.png'/></a>";
                        print "</div>";
                        print "<div style='margin-bottom: 0px' class='success'>";
                        print sprintf(_('Items in %1$sred%2$s are new since your last login. Items in green are older.'), " <span style='color: #c00'>", "</span>");
                        print "</div>";
                        //Get discussion
                        print getThread($guid, $connection2, $rowWork["gibbonPlannerEntryHomeworkID"], NULL, 0, NULL, $gibbonPersonID, $gibbonPlannerEntryID);
                        print "<br/><br/>";
                    }
                }
            }
        }
    }
}
     }
 }
 print "</table>";
 print "<a name='chat'></a>";
 print "<h2 style='padding-top: 30px'>" . _('Chat') . "</h2>";
 print "<table class='smallIntBorder' cellspacing='0' style='width: 100%;'>";
 print "<tr>";
 print "<td style='text-align: justify; padding-top: 5px; width: 33%; vertical-align: top; max-width: 752px!important;' colspan=3>";
 print "<div style='margin: 0px' class='linkTop'>";
 print "<a href='" . $_SESSION[$guid]["absoluteURL"] . "/index.php?q=/modules/" . getModuleName($_GET["q"]) . "/planner_view_full.php{$params}#chat'>" . _('Refresh') . "<img style='margin-left: 5px' title='" . _('Refresh') . "' src='./themes/" . $_SESSION[$guid]["gibbonThemeName"] . "/img/refresh.png'/></a> <a href='" . $_SESSION[$guid]["absoluteURL"] . "/index.php?q=/modules/Planner/planner_view_full_post.php&gibbonPlannerEntryID={$gibbonPlannerEntryID}&viewBy={$viewBy}&subView={$subView}&gibbonCourseClassID={$gibbonCourseClassID}&date={$date}&search=" . $gibbonPersonID . "'>" . _('Add') . "<img style='margin-left: 5px' title='" . _('Add') . "' src='./themes/" . $_SESSION[$guid]["gibbonThemeName"] . "/img/page_new.png'/></a> ";
 print "</div>";
 print "<div style='margin-bottom: 0px' class='success'>";
 print sprintf(_('Items in %1$sred%2$s are new since your last login. Items in green are older.'), "<span style='color: #c00'>", "</span>");
 print "</div>";
 //Get discussion
 print getThread($guid, $connection2, $gibbonPlannerEntryID, NULL, 0, NULL, $viewBy, $subView, $date, $class, $gibbonCourseClassID, $gibbonPersonID, $row["role"]);
 print "</td>";
 print "</tr>";
 print "</table>";
 //Unit resources
 if ($row["gibbonUnitID"] != "") {
     try {
         $dataResources = array("gibbonUnitID" => $row["gibbonUnitID"]);
         $sqlResources = "SELECT * FROM gibbonUnit WHERE gibbonUnitID=:gibbonUnitID";
         $resultResources = $connection2->prepare($sqlResources);
         $resultResources->execute($dataResources);
     } catch (PDOException $e) {
         print "<div class='error'>" . $e->getMessage() . "</div>";
     }
     if ($resultResources->rowCount() > 0) {
         $rowResources = $resultResources->fetch();
Beispiel #9
0
function getThread($guid, $connection2, $gibbonPlannerEntryHomeworkID, $parent, $level, $self, $gibbonPersonID, $gibbonPlannerEntryID)
{
    $output = "";
    try {
        if ($parent == NULL) {
            $dataDiscuss = array("gibbonPlannerEntryHomeworkID" => $gibbonPlannerEntryHomeworkID);
            $sqlDiscuss = "SELECT gibbonCrowdAssessDiscuss.*, title, surname, preferredName, category FROM gibbonCrowdAssessDiscuss JOIN gibbonPerson ON (gibbonCrowdAssessDiscuss.gibbonPersonID=gibbonPerson.gibbonPersonID) JOIN gibbonRole ON (gibbonPerson.gibbonRoleIDPrimary=gibbonRole.gibbonRoleID) WHERE gibbonPlannerEntryHomeworkID=:gibbonPlannerEntryHomeworkID AND gibbonCrowdAssessDiscussIDReplyTo IS NULL ORDER BY timestamp";
        } else {
            $dataDiscuss = array("gibbonPlannerEntryHomeworkID" => $gibbonPlannerEntryHomeworkID, "parent" => $parent, "self" => $self);
            $sqlDiscuss = "SELECT gibbonCrowdAssessDiscuss.*, title, surname, preferredName, category FROM gibbonCrowdAssessDiscuss JOIN gibbonPerson ON (gibbonCrowdAssessDiscuss.gibbonPersonID=gibbonPerson.gibbonPersonID) JOIN gibbonRole ON (gibbonPerson.gibbonRoleIDPrimary=gibbonRole.gibbonRoleID) WHERE gibbonPlannerEntryHomeworkID=:gibbonPlannerEntryHomeworkID AND gibbonCrowdAssessDiscussIDReplyTo=:parent AND gibbonCrowdAssessDiscussID=:self ORDER BY timestamp";
        }
        $resultDiscuss = $connection2->prepare($sqlDiscuss);
        $resultDiscuss->execute($dataDiscuss);
    } catch (PDOException $e) {
        $output .= "<div class='error'>" . $e->getMessage() . "</div>";
    }
    if ($level == 0 and $resultDiscuss->rowCount() == 0) {
        $output .= "<div class='error'>";
        $output .= _("This conversation has not yet begun!");
        $output .= "</div>";
    } else {
        while ($rowDiscuss = $resultDiscuss->fetch()) {
            $classExtra = "";
            if ($level == 0) {
                $classExtra = "chatBoxFirst";
            }
            $output .= "<a name='" . $rowDiscuss["gibbonCrowdAssessDiscussID"] . "'></a>";
            $output .= "<table class='noIntBorder chatBox {$classExtra}' cellspacing='0' style='width: " . (755 - $level * 15) . "px; margin-left: " . $level * 15 . "px'>";
            $output .= "<tr>";
            $output .= "<td><i>" . formatName($rowDiscuss["title"], $rowDiscuss["preferredName"], $rowDiscuss["surname"], $rowDiscuss["category"]) . " said</i>:</td>";
            $output .= "<td style='text-align: right'><i>Posted at <b>" . substr($rowDiscuss["timestamp"], 11, 5) . "</b> on <b>" . dateConvertBack($guid, substr($rowDiscuss["timestamp"], 0, 10)) . "</b></i></td>";
            $output .= "</tr>";
            $output .= "<tr>";
            $output .= "<td style='padding: 1px 4px' colspan=2><b>" . $rowDiscuss["comment"] . "</b></td>";
            $output .= "</tr>";
            $output .= "<tr>";
            $output .= "<td style='text-align: right' colspan=2><a href='" . $_SESSION[$guid]["absoluteURL"] . "/index.php?q=/modules/" . $_SESSION[$guid]["module"] . "/crowdAssess_view_discuss_post.php&gibbonPersonID={$gibbonPersonID}&gibbonPlannerEntryID={$gibbonPlannerEntryID}&gibbonPlannerEntryHomeworkID={$gibbonPlannerEntryHomeworkID}&replyTo=" . $rowDiscuss["gibbonCrowdAssessDiscussID"] . "'>Reply</a></td>";
            $output .= "</tr>";
            $output .= "</table>";
            //Get any replies
            try {
                $dataReplies = array("gibbonPlannerEntryHomeworkID" => $gibbonPlannerEntryHomeworkID, "gibbonCrowdAssessDiscussID" => $rowDiscuss["gibbonCrowdAssessDiscussID"]);
                $sqlReplies = "SELECT gibbonCrowdAssessDiscuss.*, title, surname, preferredName FROM gibbonCrowdAssessDiscuss JOIN gibbonPerson ON (gibbonCrowdAssessDiscuss.gibbonPersonID=gibbonPerson.gibbonPersonID) WHERE gibbonPlannerEntryHomeworkID=:gibbonPlannerEntryHomeworkID AND gibbonCrowdAssessDiscussIDReplyTo=:gibbonCrowdAssessDiscussID ORDER BY timestamp";
                $resultReplies = $connection2->prepare($sqlReplies);
                $resultReplies->execute($dataReplies);
            } catch (PDOException $e) {
                $output .= "<div class='error'>" . $e->getMessage() . "</div>";
            }
            while ($rowReplies = $resultReplies->fetch()) {
                $output .= getThread($guid, $connection2, $gibbonPlannerEntryHomeworkID, $rowDiscuss["gibbonCrowdAssessDiscussID"], $level + 1, $rowReplies["gibbonCrowdAssessDiscussID"], $gibbonPersonID, $gibbonPlannerEntryID);
            }
        }
    }
    return $output;
}
Beispiel #10
0
function getThread($guid, $connection2, $gibbonPlannerEntryID, $parent, $level, $self, $viewBy, $subView, $date, $class, $gibbonCourseClassID, $search, $role, $links = TRUE, $narrow = FALSE)
{
    $output = "";
    try {
        if ($parent == NULL) {
            $dataDiscuss = array("gibbonPlannerEntryID" => $gibbonPlannerEntryID);
            $sqlDiscuss = "SELECT gibbonPlannerEntryDiscuss.*, title, surname, preferredName, category FROM gibbonPlannerEntryDiscuss JOIN gibbonPerson ON (gibbonPlannerEntryDiscuss.gibbonPersonID=gibbonPerson.gibbonPersonID) JOIN gibbonRole ON (gibbonPerson.gibbonRoleIDPrimary=gibbonRole.gibbonRoleID) WHERE gibbonPlannerEntryID=:gibbonPlannerEntryID AND gibbonPlannerEntryDiscussIDReplyTo IS NULL ORDER BY timestamp";
        } else {
            $dataDiscuss = array("gibbonPlannerEntryID" => $gibbonPlannerEntryID, "gibbonPlannerEntryDiscussIDReplyTo" => $parent, "gibbonPlannerEntryDiscussID" => $self);
            $sqlDiscuss = "SELECT gibbonPlannerEntryDiscuss.*, title, surname, preferredName, category FROM gibbonPlannerEntryDiscuss JOIN gibbonPerson ON (gibbonPlannerEntryDiscuss.gibbonPersonID=gibbonPerson.gibbonPersonID) JOIN gibbonRole ON (gibbonPerson.gibbonRoleIDPrimary=gibbonRole.gibbonRoleID) WHERE gibbonPlannerEntryID=:gibbonPlannerEntryID AND gibbonPlannerEntryDiscussIDReplyTo=:gibbonPlannerEntryDiscussIDReplyTo AND gibbonPlannerEntryDiscussID=:gibbonPlannerEntryDiscussID ORDER BY timestamp";
        }
        $resultDiscuss = $connection2->prepare($sqlDiscuss);
        $resultDiscuss->execute($dataDiscuss);
    } catch (PDOException $e) {
        $output .= "<div class='error'>" . $e->getMessage() . "</div>";
    }
    if ($level == 0 and $resultDiscuss->rowCount() == 0) {
        $output .= "<div class='error'>";
        $output .= _("There are no records to display.");
        $output .= "</div>";
    } else {
        while ($rowDiscuss = $resultDiscuss->fetch()) {
            $classExtra = "";
            if ($level == 0) {
                $classExtra = "chatBoxFirst";
            }
            $output .= "<a name='" . $rowDiscuss["gibbonPlannerEntryDiscussID"] . "'></a>";
            $width = 752 - $level * 15;
            if ($narrow) {
                $width = 705 - $level * 15;
            }
            $output .= "<table class='noIntBorder chatBox {$classExtra}' cellspacing='0' style='width: " . $width . "px; margin-left: " . $level * 15 . "px'>";
            $output .= "<tr>";
            $output .= "<td><i>" . formatName($rowDiscuss["title"], $rowDiscuss["preferredName"], $rowDiscuss["surname"], $rowDiscuss["category"]) . " " . _('said') . "</i>:</td>";
            $output .= "<td style='text-align: right'><i>" . _('Posted at') . " <b>" . substr($rowDiscuss["timestamp"], 11, 5) . "</b> on <b>" . dateConvertBack($guid, substr($rowDiscuss["timestamp"], 0, 10)) . "</b></i></td>";
            $output .= "</tr>";
            $output .= "<tr>";
            $output .= "<td style='max-width: " . (700 - $level * 15) . "px;' colspan=2><b>" . $rowDiscuss["comment"] . "</b></td>";
            $output .= "</tr>";
            $output .= "<tr>";
            if ($links == TRUE) {
                $output .= "<td style='text-align: right' colspan=2><a href='" . $_SESSION[$guid]["absoluteURL"] . "/index.php?q=/modules/Planner/planner_view_full_post.php&gibbonPlannerEntryID={$gibbonPlannerEntryID}&viewBy={$viewBy}&subView={$subView}&gibbonCourseClassID={$gibbonCourseClassID}&date={$date}&width=1000&height=550&replyTo=" . $rowDiscuss["gibbonPlannerEntryDiscussID"] . "&search={$search}'>Reply</a> ";
                if ($role == "Teacher") {
                    $output .= " | <a href='" . $_SESSION[$guid]["absoluteURL"] . "/modules/Planner/planner_view_full_post_deleteProcess.php?gibbonPlannerEntryID={$gibbonPlannerEntryID}&viewBy={$viewBy}&subView={$subView}&gibbonCourseClassID={$gibbonCourseClassID}&date={$date}&width=1000&height=550&search={$search}&gibbonPlannerEntryDiscussID=" . $rowDiscuss["gibbonPlannerEntryDiscussID"] . "'>Delete</a>";
                }
                $output .= "</td>";
            }
            $output .= "</tr>";
            $output .= "</table>";
            //Get any replies
            $replies = true;
            try {
                $dataReplies = array("gibbonPlannerEntryID" => $gibbonPlannerEntryID, "gibbonPlannerEntryDiscussIDReplyTo" => $rowDiscuss["gibbonPlannerEntryDiscussID"]);
                $sqlReplies = "SELECT gibbonPlannerEntryDiscuss.*, title, surname, preferredName FROM gibbonPlannerEntryDiscuss JOIN gibbonPerson ON (gibbonPlannerEntryDiscuss.gibbonPersonID=gibbonPerson.gibbonPersonID) WHERE gibbonPlannerEntryID=:gibbonPlannerEntryID AND gibbonPlannerEntryDiscussIDReplyTo=:gibbonPlannerEntryDiscussIDReplyTo ORDER BY timestamp";
                $resultReplies = $connection2->prepare($sqlReplies);
                $resultReplies->execute($dataReplies);
            } catch (PDOException $e) {
                $replies = false;
                $output .= (print "<div class='error'>" . $e->getMessage() . "</div>");
            }
            if ($replies) {
                while ($rowReplies = $resultReplies->fetch()) {
                    $output .= getThread($guid, $connection2, $gibbonPlannerEntryID, $rowDiscuss["gibbonPlannerEntryDiscussID"], $level + 1, $rowReplies["gibbonPlannerEntryDiscussID"], $viewBy, $subView, $date, $class, $gibbonCourseClassID, $search, $role, $links);
                }
            }
        }
    }
    return $output;
}
<?php

include "../../include/functions.php";
include "../../include/dbcon.inc.php";
include "../../include/pm_functions.inc.php";
header('Content-Type: application/json');
$user_id = getUserIdFromToken($con, @$_POST["token"]);
if ($user_id == 0) {
    die;
}
$response = getThread($user_id, $con);
echo json_encode($response);
Beispiel #12
0
/**
    Types of Disqus searches
    1. Context: postid
    2. Search: email,username,user,string
    3. Scope: identity, thread
    4. List of postids: commands, rule posts

    Results are processes but not acted upon (only marked and get ruleid, watch, etc set)

    Issues:
    Separate searches for children, level and parents? If not - then we must preserve ids in the table. How do we know that ids need rewriting?
    Answer: each row containst context information: one of [queue, level, child, parent], tab_id, view, identity. Each search deletes all the previous
    rows first.

    A: Create a table of postid/parentid to fetch old contexts from disqus  qwp_post_index. Also should have a field to indicate if came alone or with the full thread.
    If the postid is not present in qwp_post_index (with the context) then get parents but put a pseudo post as a sibling into level grid explaining the issue and offering to fetch the entire
    old thread. This will also put the context into a tear-away tab if not already there. When the thread is loaded the context is rebuilt and the pseudo-post gone.

    B: Need to have stale post indication. WHen the local post is present, calculate first if is stale or not before going to discus. Formula should be 
    age of the post devided by the interval since last update < 2. Also means adding updatedAt field.


    Update: add last:nnn search



    **/
function backgroundSearch($scope, $ct, $cv, $search, $tab_id)
{
    //this is slow version of loadQueueItems. First it does same as loadQueue saving postids, then goes to disqus and gets the same posts.
    //Then compares the ids, if same only updates text and generates change tick, if new = new posts tick for the specific tab
    // $posts=loadPosts($scope,$ct,$cv,$search,$tab_id);
    /**
            1. Determine the type of request
                a. search
                b. all posts for identity
                c. all posts for thread
                d. ids (commands or rule)
                e. context:level
                f: context:child
            **/
    global $control;
    global $access_token;
    global $unDataService;
    global $nmDataService;
    global $global_username;
    global $logService;
    global $view;
    global $queueType;
    global $global_emailHash;
    if ($queueType == "queue" && empty($search) && empty($ct) && empty($cv)) {
        echo json_encode(array("success" => true, "total" => 0, "posts" => 0));
        return;
    }
    if ($scope == 'watch' && !$control['watch'] || $scope == 'deleted' && !$control['deleted']) {
        echo json_encode(array("success" => true, "total" => 0, "posts" => 0));
        return;
    }
    if ($scope == 'watch' || $scope == 'deleted' || $scope == 'approved' || $scope == 'unconfirmed') {
        echo json_encode(array("success" => true, "total" => 0, "posts" => 0));
        return;
    }
    $forumid = $control['forumid'];
    $ds = $nmDataService->getForumHubDataService($forumid);
    $fdata = $nmDataService->getForumData($forumid);
    $disqus_forumid = $fdata['external_id'];
    if ($scope == 'all' && !$control['deleted']) {
        $scope = 'working';
    }
    $context = 'queue';
    if (strpos($queueType, ':') !== FALSE) {
        $exp = explode(':', $queueType);
        $queueType = $exp[0];
        $context = $exp[1];
    }
    if ($context == 'queue') {
        $type = 'queue';
    } else {
        $type = 'post';
    }
    if ($ct == "thread") {
        $context = 'root';
        $type = 'root';
    }
    $selfsearch = false;
    if ($search == 'rself') {
        $search = '';
        $selfsearch = true;
    }
    $source = "type=" . $type . ";" . "scope=" . $scope . ";" . "constraint_type=" . $ct . ";" . "constraint_value=" . $cv . ";" . "tab_id=" . $tab_id . ";" . "search=" . $search;
    $logService->log('DEBUG', '@@@backgroundSearch', 'source::' . $source, $global_username);
    if ($context == 'queue' && $scope == 'all' && !empty($ct) && $ct == 'identity') {
        //b.
        $username = $ds->getUsernameByIdentity($cv, $forumid);
        $search = "user:"******"success" => false, "msg" => "ERROR1: Exception:" + var_log($x)));
            exit;
        }
    } else {
        if ($type == 'root' && !empty($ct) && $ct == 'thread') {
            //c.
            $thread = $cv;
            $search_to_show = "thread:" . $thread;
            if ($selfsearch) {
                $search = $source;
            }
            // $logService->log('DEBUG','###backgroundSearch','direct_source(search)::'.$search.'::$search_to_show::'.$search_to_show,$global_username);
            /* $ispresent=$ds->getThreadTitle($thread,$forumid);   
               if($ispresent) {
                    echo json_encode(array(
                   "success" => true,
                   "total" => 0,
                   "posts" => 0
                   ));
                   return;
               }*/
            $isload = $ds->getThreadSearch($thread, $forumid);
            if (!$isload) {
                $go = $ds->startServerSearch($tab_id, $scope, 'thread', 'all', $forumid, $search_to_show, $search);
                // the search param has the primary source of the search that created the pseudo post
                if ($go) {
                    try {
                        set_time_limit(0);
                        $ds->startThreadSearch($thread, $forumid);
                        $ds->updateThreadPseudoPosts($thread, $forumid);
                        getThread($ds, $fdata, $forumid, $access_token, $disqus_forumid, $thread, $go);
                        $ds->removeThreadPseudoPosts($thread, $forumid);
                        $ds->completeServerSearch($tab_id, $scope, 'thread', 'all', $forumid, $search_to_show);
                        $ds->completeThreadSearch($thread, $forumid);
                        set_time_limit(30);
                    } catch (Exception $x) {
                        set_time_limit(30);
                        $ds->completeServerSearch($tab_id, $scope, 'thread', 'all', $forumid, $search_to_show);
                        $logService->log('ERROR', 'backgroundSearch', fe($x), $forumid);
                        echo json_encode(array("success" => false, "msg" => "ERROR2: Exception:" + $x->getMessage()));
                        exit;
                    }
                }
            }
        } else {
            if ($context == 'queue' && $scope == 'commands') {
                //d.1
                //get list of postids
                $posts = array();
                $username = $ds->getUsernameByIdentity($cv, $forumid);
                $search = "user:"******"success" => false, "msg" => "ERROR2: Exception:" + var_log($x)));
                            exit;
                        }
                    }
                }
            } else {
                if ($context == 'queue' && $scope == 'rules' && !empty($ct) && $ct == 'rule') {
                    //d.2
                    //get list of postids
                    $posts = array();
                    $username = $ds->getUsernameByIdentity($cv, $forumid);
                    $search = "rules:" . $username;
                    // this is for nice display purpose only
                    if ($ct == 'rule') {
                        $posts = $ds->getRulePostids($cv, $forumid);
                        if ($posts) {
                            $go = $ds->startServerSearch($tab_id, $scope, 'rule', 'posts', $forumid, $search, $source);
                            try {
                                if ($go) {
                                    set_time_limit(0);
                                    foreach ((array) $posts as $post) {
                                        $postid = $post['postid'];
                                        getPost($ds, $fdata, $forumid, $access_token, $disqus_forumid, $postid, $go);
                                    }
                                    $ds->completeServerSearch($tab_id, $scope, 'rule', 'posts', $forumid, $search);
                                    set_time_limit(30);
                                }
                            } catch (Exception $x) {
                                set_time_limit(30);
                                if ($go) {
                                    $ds->completeServerSearch($tab_id, $scope, 'rule', 'posts', $forumid, $search);
                                }
                                $logService->log('ERROR', 'backgroundSearch', fe($x), $forumid);
                                echo json_encode(array("success" => false, "msg" => "ERROR4: Exception:" + var_log($x)));
                                exit;
                            }
                        }
                    }
                } else {
                    if ($context == 'level' && !empty($ct) && $ct == 'post') {
                        //e - also need to get parent
                        /**
                                A.Parent processing:
                                    1. Get all parent context postids from qwp_post_index. Find all the postids that are either missing from tab_posts or are stale.
                                    Get them from disqus. If any were missing - send updateparent tick to UI.
                                    2. If the index does not have a complete chain - get a context (in disqus terms) from discus. Send updateparent tick to UI.
                                B. Level processing:
                                    1. Check if the post has context. If yes - get all the level postids from index, compare them to tab_posts and check if any are stale. For missing or stale get from disqus.
                                    No ticks - the new and changed messages will be handled routinely by crawler processPosts.
                                    2. If no context send a tick to put a pseudo post up inviting user to get the complete thread loaded if they want to see the full context.
                        
                        **/
                        /**
                            Archiving refactoring 4/1/2015
                                    if parent==-1 and thread.state==2 get the thread from archive (restoreThread())
                                    else
                                    walk index, if(thread.state==2) for each index with missing post get it from archive, only else go to Disqus for a copy
                        
                            The queue search on background will also search archive and restore found posts, without their threads and will not change the state of the thread        
                        
                        
                        **/
                        $username = $ds->getUsernameByIdentity($cv, $forumid);
                        $search = "post:" . $cv;
                        // this is for nice display purpose only
                        $postid = $cv;
                        $hasparent = false;
                        $go = $ds->startServerSearch($tab_id, $scope, 'post', 'context', $forumid, $search, $source);
                        if ($go) {
                            set_time_limit(0);
                            try {
                                $index_postids = $ds->getParentPostidsFromIndex($cv, $forumid);
                                //check if it is complete chain
                                $len = sizeof($index_postids);
                                $last_post = null;
                                if ($len >= 1) {
                                    $last_post = $index_postids[$len - 1];
                                }
                                $now = time();
                                if ($last_post && $last_post['parentid'] == -1) {
                                    //complete chain
                                    if ($last_post['postid'] != $postid) {
                                        $hasparent = true;
                                    } else {
                                        /**  4/1/2015   **/
                                        $ds->restoreThreadIfArchived($last_post['thread'], $forumid);
                                    }
                                    //$logService->log('DEBUG','backgroundSearch','Parent chain (size='.$len.') is present locally in index for postid='.$cv,$forumid);
                                    $local_postids = $ds->getPostsByMissingPostids($index_postids, $forumid);
                                    $skip_ids = array();
                                    foreach ((array) $local_postids as $lp) {
                                        //stale calculations
                                        $age = $now - $lp['createdat'];
                                        $sinceupdate = $now - $lp['updatedat'];
                                        if ($sinceupdate != 0 && $age / $sinceupdate > 2) {
                                            //fresh enough
                                            $skip_ids[] = $lp['postid'];
                                        }
                                    }
                                    $sent = false;
                                    foreach ($index_postids as $post) {
                                        //  $logService->log('DEBUG','backgroundSearch','Inside index_postids loop for postid='.$cv,$forumid);
                                        $postid = $post['postid'];
                                        if (in_array($post['postid'], $skip_ids)) {
                                            continue;
                                        }
                                        $updatedat = $ds->getPostUpdatedat($forumid, $postid);
                                        if ($updatedat > $now) {
                                            //another thread updated the post meanwhile
                                            continue;
                                        }
                                        // $logService->log('DEBUG','backgroundSearch','Calling getPost for postid='.$cv,$forumid);
                                        /** first try archive 4/1/2015   **/
                                        getPost($ds, $fdata, $forumid, $access_token, $disqus_forumid, $postid, $go);
                                        $sent = true;
                                    }
                                } else {
                                    // get a complete disqus context for potid
                                    $logService->log('DEBUG', 'backgroundSearch:level', 'Getting complete disqusus context for postid=' . $cv, $forumid);
                                    getContext($ds, $fdata, $forumid, $access_token, $disqus_forumid, $postid, $go);
                                    // $logService->log('DEBUG',' after backgroundSearch:level','Getting complete disqusus context for postid='.$cv,$global_username);
                                }
                                //B: Level processing
                                $postid = $cv;
                                //check if in context
                                // $logService->log('DEBUG','begin:level','',$global_username);
                                $has_context = $ds->checkHasContextonIndex($postid, $forumid);
                                if ($has_context) {
                                    /**
                                                                3/8/2015
                                                                Thread archiving refactoring. If has context the thread coule be archived
                                    
                                    
                                                            **/
                                    if ($hasparent) {
                                        $index_postids = $ds->getLevelPostidsFromIndex($postid, $forumid);
                                        // $logService->log('DEBUG',' getLevelPostidsFromIndex:level',var_log($local_postids,'$index_postids'),$global_username);
                                        $now = time();
                                        $local_postids = $ds->getPostsByMissingPostids($index_postids, $forumid);
                                        //$local_postids=$ds->getPostidsFromTabPosts($global_emailHash,$view,$tab_id,'level');
                                        //  $logService->log('DEBUG',' aftergetPostidsFromTabPosts:level',var_log($local_postids,'$local_postids'),$global_username);
                                        $skip_ids = array();
                                        foreach ((array) $local_postids as $lp) {
                                            //stale calculations
                                            $age = $now - $lp['createdat'];
                                            $sinceupdate = $now - $lp['updatedat'];
                                            if ($sinceupdate) {
                                                if ($age / $sinceupdate > 2) {
                                                    //fresh enough
                                                    $skip_ids[] = $lp['postid'];
                                                }
                                            }
                                        }
                                        foreach ($index_postids as $post) {
                                            $postid = $post['postid'];
                                            if (in_array($post['postid'], $skip_ids)) {
                                                continue;
                                            }
                                            $updatedat = $ds->getPostUpdatedat($forumid, $postid);
                                            if ($updatedat > $now) {
                                                //another thread updated the post meanwhile
                                                continue;
                                            }
                                            // $logService->log('DEBUG',' calling getPost:level',$postid,$global_username);
                                            /** first try archive 4/1/2015   **/
                                            getPost($ds, $fdata, $forumid, $access_token, $disqus_forumid, $postid, $go);
                                        }
                                    } else {
                                        //just this one post if at the top level
                                        getPost($ds, $fdata, $forumid, $access_token, $disqus_forumid, $postid, $go);
                                    }
                                } else {
                                    //insert a pseudopost
                                    // $logService->log('DEBUG','before insert pseudopost:level','',$global_username);
                                    $ds->insertPseudopost($tab_id, "level", $postid, $forumid, $source);
                                    //  $logService->log('DEBUG','after insert pseudopost:level','',$global_username);
                                }
                                $ds->completeServerSearch($tab_id, $scope, 'post', 'context', $forumid, $search);
                                set_time_limit(30);
                                // $logService->log('DEBUG','exit backgroundSearch:level','',$global_username);
                            } catch (Exception $x) {
                                set_time_limit(30);
                                $ds->completeServerSearch($tab_id, $scope, 'post', 'context', $forumid, $search);
                                $logService->log('ERROR', 'backgroundSearch', fe($x), $forumid);
                                echo json_encode(array("success" => false, "msg" => "ERROR3: Exception:" + var_log($x)));
                                exit;
                            }
                        }
                    } else {
                        if ($context == 'child' && !empty($ct) && $ct == 'post') {
                            //f
                            /**
                            
                                    C. Child processing: same as level except no pseudo post needed    
                                        **/
                            $username = $ds->getUsernameByIdentity($cv, $forumid);
                            $search = "post:" . $cv;
                            // this is for nice display purpose only
                            $postid = $cv;
                            $go = $ds->startServerSearch($tab_id, $scope, 'post', 'children', $forumid, $search, $source);
                            if ($go) {
                                set_time_limit(0);
                                try {
                                    $has_context = $ds->checkHasContextonIndex($cv, $forumid);
                                    $postid = $cv;
                                    if ($has_context) {
                                        $index_postids = $ds->getChildPostidsFromIndex($postid, $forumid);
                                        $now = time();
                                        $local_postids = $ds->getPostsByMissingPostids($index_postids, $forumid);
                                        //$local_postids=$ds->getPostidsFromTabPosts($global_emailHash,$view,$tab_id,'child');
                                        $skip_ids = array();
                                        foreach ((array) $local_postids as $lp) {
                                            //stale calculations
                                            $age = $now - $lp['createdat'];
                                            $sinceupdate = $now - $lp['updatedat'];
                                            //$logService->log('DEBUG','backgroundSearch:child stale calc','$age='.$age.';$sinceupdate='.$sinceupdate,$global_username);
                                            if ($sinceupdate) {
                                                if ($age / $sinceupdate > 2) {
                                                    //fresh enough
                                                    $skip_ids[] = $lp['postid'];
                                                }
                                            }
                                        }
                                        foreach ($index_postids as $post) {
                                            $postid = $post['postid'];
                                            if (in_array($post['postid'], $skip_ids)) {
                                                continue;
                                            }
                                            getPost($ds, $fdata, $forumid, $access_token, $disqus_forumid, $postid, $go);
                                        }
                                    }
                                    $ds->completeServerSearch($tab_id, $scope, 'post', 'children', $forumid, $search);
                                    set_time_limit(30);
                                    // $logService->log('DEBUG','exit backgroundSearch:child','',$global_username);
                                } catch (Exception $x) {
                                    set_time_limit(30);
                                    $ds->completeServerSearch($tab_id, $scope, 'post', 'children', $forumid, $search);
                                    $logService->log('ERROR', 'backgroundSearch:children', fe($x), $forumid);
                                    echo json_encode(array("success" => false, "msg" => "ERROR3: Exception:" + var_log($x)));
                                    exit;
                                }
                            }
                        } else {
                            if ($context == 'queue') {
                                //a.
                                $go = false;
                                try {
                                    $go = $ds->startServerSearch($tab_id, $scope, $ct, $cv, $forumid, $search, $source);
                                    if ($go) {
                                        set_time_limit(0);
                                        $ds->archiveSearch($forumid, $scope, $ct, $cv, $search, $context);
                                        $posts = disqus_search($ds, $fdata, $forumid, $access_token, $disqus_forumid, $search, 300, $go);
                                        // limit free form search to 300 posts
                                        set_time_limit(30);
                                        //
                                        // $logService->log('DEBUG','backgroundSearch','search::'.$search,$forumid);
                                        if (strpos($search, 'last:') !== FALSE || strpos($search, 'days:') !== FALSE) {
                                            // init load
                                            // $logService->log('DEBUG','backgroundSearch 2','search::'.$search,$forumid);
                                            $tabs = $ds->loadUserForumTabs($control, $view);
                                            //$logService->log('DEBUG','backgroundSearch 3','tabs::'.var_log($tabs),$forumid);
                                            foreach ($tabs as $tab) {
                                                $tab_id2 = $tab['tab_id'];
                                                // $logService->log('DEBUG','Dispatch tick',' TabPosts backgroundSearch tab_id='.$tab_id,$forumid);
                                            }
                                        }
                                        //$logService->log('DEBUG','Dispatch tick',' ServerSearchLog backgroundSearch ',$forumid);
                                        $ds->completeServerSearch($tab_id, $scope, $ct, $cv, $forumid, $search);
                                    }
                                } catch (Exception $x) {
                                    if ($go) {
                                        $ds->completeServerSearch($tab_id, $scope, $ct, $cv, $forumid, $search);
                                    }
                                    $logService->log('ERROR', 'backgroundSearch', fe($x), $forumid);
                                    echo json_encode(array("success" => false, "msg" => "ERROR: Exception:" + var_log($x)));
                                    exit;
                                }
                            }
                        }
                    }
                }
            }
        }
    }
    echo json_encode(array("success" => true, "total" => 0, "posts" => 0));
}