예제 #1
0
 public function addComment($commenter_id, $text_id, $comment, $writer_id)
 {
     $db = JFactory::getDbo();
     $tagged_users = ideary::getTaggedUsersFromComment($comment);
     $text_notification_type_comment = 5;
     $text_notification_type_comment_commented_text = 8;
     $escaped_comment = mysql_escape_string($comment);
     $query = "\n\t\t\tINSERT INTO #__comments ( text_id, commenter_id, comment, date )\n            VALUES ({$text_id}, {$commenter_id}, '{$escaped_comment}', now() )\n\t\t\t";
     $db->setQuery($query);
     $success = $db->query();
     $commentId = ideary::getLastInsertedCommentId();
     // Notify the author
     if ($commenter_id != $writer_id && !in_array($writer_id, $tagged_users)) {
         $query = "\n\t\t\t\tINSERT INTO text_notifications (user_id, notified_id, text_id, notification_type_id, created_at, saw, comment_id) \n\t\t\t\tVALUES ({$commenter_id}, {$writer_id}, {$text_id}, {$text_notification_type_comment}, now(), 0, {$db->insertid()})\n\t\t\t\t";
         $db->setQuery($query);
         $db->query();
     }
     // Notify other commenters
     $query = "SELECT DISTINCT commenter_id FROM text_comments WHERE text_id = {$text_id}";
     $db->setQuery($query);
     $textCommenters = $db->loadObjectList();
     foreach ($textCommenters as $textCommenter) {
         if ($commenter_id == $textCommenter->commenter_id) {
             continue;
         }
         if ($writer_id == $textCommenter->commenter_id) {
             continue;
         }
         if (in_array($textCommenter->commenter_id, $tagged_users)) {
             continue;
         }
         $query = "\n\t\t\t\t\tINSERT INTO text_notifications (user_id, notified_id, text_id, notification_type_id, created_at, saw)\n\t\t\t\t\tVALUES ({$commenter_id}, {$textCommenter->commenter_id}, {$text_id}, {$text_notification_type_comment_commented_text}, NOW(), FALSE)\n\t\t\t\t\t";
         $db->setQuery($query);
         $db->query();
     }
     // Notify tagged users
     foreach ($tagged_users as $tagged_user) {
         if ($commenter_id == $tagged_user) {
             continue;
         }
         $query = "\n\t\t\t\tINSERT INTO text_notifications (user_id, notified_id, text_id, notification_type_id, created_at, saw, comment_id) \n\t\t\t\tVALUES ({$commenter_id}, {$tagged_user}, {$text_id}, 10, NOW(), FALSE, {$commentId});\n\t\t\t\t";
         $db->setQuery($query);
         $db->query();
     }
     if (!empty($tagged_users)) {
         ideary::logUserExperience(UserExperience::CommentTagging, $commenter_id, 1);
     }
     return $success;
 }
예제 #2
0
 public function comment_text()
 {
     // Get the application object.
     $app = JFactory::getApplication();
     $comment = JRequest::getString("comment", "", "default", 2);
     $commenter_id = JRequest::getInt("commenter_id");
     $text_id = JRequest::getInt("text_id");
     $writer_id = JRequest::getInt("writer_id");
     $success = ideary::addComment($commenter_id, $text_id, $comment, $writer_id);
     $commentId = ideary::getLastInsertedCommentId();
     echo json_encode(array('success' => $success, 'comment_id' => $commentId));
     $app->close();
 }