Example #1
0
         respond(array('status' => 'bad_request'));
     }
     if (isset($commenterData['public_id'])) {
         $privateRecipientInThread = $commenterData['public_id'];
     }
 }
 // save the comment
 $commentTime = time();
 $commentFields = "message_id, user_id, text_encrypted, comment_secret, time_inserted";
 $commentValues = intval($messageID) . ", " . intval($userID) . ", " . Database::escape($textEncrypted) . ", " . Database::escape($commentSecret) . ", " . $commentTime;
 if (isset($privateToUser)) {
     $commentFields .= ", private_to_user";
     $commentValues .= ", " . intval($privateToUser);
 }
 Database::insert("INSERT INTO comments (" . $commentFields . ") VALUES (" . $commentValues . ")");
 $commentID = Database::getLastInsertID();
 // for private comments
 if (isset($privateToUser)) {
     // update the date of the latest activity
     Database::update("UPDATE messages SET time_active = " . time() . " WHERE id = " . intval($messageID));
 } else {
     // increase the comments count by one, update the score and update the date of the latest activity
     Database::update("UPDATE messages SET comments_count = comments_count+1, score = " . getScoreUpdateSQL() . ", time_active = " . time() . " WHERE id = " . intval($messageID));
 }
 // get the existing degree (if any) or 3 (default)
 $degree = getDegree($userID, $messageID);
 // subscribe to the comments thread (if not done already)
 Database::insert("INSERT IGNORE INTO subscriptions (message_id, user_id, degree) VALUES (" . intval($messageID) . ", " . intval($userID) . ", " . intval($degree) . ")");
 // if this is a private reply
 if (isset($privateToUser)) {
     // notify the recipient of the private reply that there is a new comment
Example #2
0
                     $messageValues .= ", " . floatval($_POST['location']['lat']) . ", " . floatval($_POST['location']['long']);
                 }
             }
             if ($_POST['visibility'] == VISIBILITY_FRIENDS_AND_PUBLIC) {
                 // send the message to all friends' feeds
                 $messageFields .= ", dispatched";
                 $messageValues .= ", 0";
             } elseif ($_POST['visibility'] == VISIBILITY_PUBLIC_ONLY) {
                 // do not send the message to any friend's feeds
                 $messageFields .= ", dispatched";
                 $messageValues .= ", 1";
             } else {
                 respond(array('status' => 'bad_request'));
             }
             Database::insert("INSERT INTO messages (" . $messageFields . ") VALUES (" . $messageValues . ")");
             $messageID = Database::getLastInsertID();
             // unless the authenticating user is an admin user
             if (!$isAdmin) {
                 // add the message to the author's feed
                 Database::insert("INSERT INTO feeds (user_id, message_id, degree) VALUES (" . intval($userID) . ", " . intval($messageID) . ", 0)");
             }
             // subscribe to the comments thread
             Database::insert("INSERT IGNORE INTO subscriptions (message_id, user_id, degree) VALUES (" . intval($messageID) . ", " . intval($userID) . ", 0)");
             respond(array('status' => 'ok', 'messageID' => base64_encode($messageID), 'messageTime' => $timePublished));
         } else {
             respond(array('status' => 'bad_request'));
         }
     } else {
         respond(array('status' => 'bad_request'));
     }
 } else {