Exemple #1
0
 */
// require_once "../lib/init.php";
use Kiki\Comment;
if ($_POST) {
    $errors = array();
    list($dummy, $objectId, $last) = explode("_", $_POST['last']);
    if (!$user->id()) {
        $errors[] = "Je bent niet ingelogd.";
    }
    if (!($body = $_POST['comment'])) {
        $errors[] = "Je kunt geen leeg berichtje opslaan!";
    }
    if (!count($errors)) {
        $comment = new Comment();
        $comment->setInReplyToId($objectId);
        $comment->setUserId($user->id());
        $comment->setBody($body);
        $comment->setIpAddr($_SERVER['REMOTE_ADDR']);
        $comment->save();
    }
    if ($_POST['json']) {
        $response = array();
        $response['formId'] = $_POST['formId'];
        $response['objectId'] = $objectId;
        $response['comments'] = Comments::show($objectId, $last);
        $response['errors'] = $errors;
        header('Content-type: application/json');
        echo json_encode($response);
        exit;
    }
    Router::redirect($_SERVER['HTTP_REFERER'], 303);
        // Object ID for replies to replies
        if (!$objectId) {
            $objectId = isset($replyObjectIds[$tweet->in_reply_to_status_id]) ? $replyObjectIds[$tweet->in_reply_to_status_id] : 0;
        }
        $q = $db->buildQuery("SELECT id FROM connections WHERE external_id=%d", $twUser->externalId());
        $tweetConnectionId = $db->getSingleValue($q);
        // Find comment
        $q = $db->buildQuery("SELECT id FROM comments WHERE user_connection_id=%d AND external_id='%s'", $tweetConnectionId, $tweet->id);
        $commentId = $db->getSingleValue($q);
        if ($commentId) {
            continue;
        }
        // Store comment
        $comment = new Comment();
        $comment->setInReplyToId($objectId);
        $comment->setUserId($localUser->id());
        $comment->setConnectionId($tweetConnectionId);
        $comment->setExternalId($tweet->id);
        $comment->setBody($tweet->text);
        $comment->setCtime($ctime);
        $comment->save();
        // TODO: also store object_id, not doing so flattens all comments and all nesting/threading information is lost
        $replyObjectIds[$tweet->id] = $objectId ? $objectId : $comment->objectId();
        printf("%s commented on %d:%s%s%s", $twUser->name(), $objectId, PHP_EOL, $tweet->text, PHP_EOL . PHP_EOL);
    } else {
        if (isset($tweet->retweeted_status) && $tweet->user->id != $connectionId) {
            // TODO: store quoted retweet
            // echo "==== retweet ====". print_r($tweet,true). "==== end retweet ====". PHP_EOL;
        }
    }
}