Beispiel #1
0
 /**
  * Parse a post/comment body for quotes and notify all quoted users that have quote notifications enabled.
  * @param string $Body
  * @param int $PostID
  * @param string $Page
  * @param int $PageID
  */
 public static function quote_notify($Body, $PostID, $Page, $PageID)
 {
     $QueryID = G::$DB->get_query_id();
     /*
      * Explanation of the parameters PageID and Page: Page contains where
      * this quote comes from and can be forums, artist, collages, requests
      * or torrents. The PageID contains the additional value that is
      * necessary for the users_notify_quoted table. The PageIDs for the
      * different Page are: forums: TopicID artist: ArtistID collages:
      * CollageID requests: RequestID torrents: GroupID
      */
     $Matches = array();
     preg_match_all('/\\[quote(?:=(.*)(?:\\|.*)?)?]|\\[\\/quote]/iU', $Body, $Matches, PREG_SET_ORDER);
     if (count($Matches)) {
         $Usernames = array();
         $Level = 0;
         foreach ($Matches as $M) {
             if ($M[0] != '[/quote]') {
                 if ($Level == 0 && isset($M[1]) && strlen($M[1]) > 0 && preg_match(USERNAME_REGEX, $M[1])) {
                     $Usernames[] = preg_replace('/(^[.,]*)|([.,]*$)/', '', $M[1]);
                     // wut?
                 }
                 ++$Level;
             } else {
                 --$Level;
             }
         }
     }
     // remove any dupes in the array (the fast way)
     $Usernames = array_flip(array_flip($Usernames));
     G::$DB->query("\n\t\t\tSELECT m.ID\n\t\t\tFROM users_main AS m\n\t\t\t\tLEFT JOIN users_info AS i ON i.UserID = m.ID\n\t\t\tWHERE m.Username IN ('" . implode("', '", $Usernames) . "')\n\t\t\t\tAND i.NotifyOnQuote = '1'\n\t\t\t\tAND i.UserID != " . G::$LoggedUser['ID']);
     $Results = G::$DB->to_array();
     foreach ($Results as $Result) {
         $UserID = db_string($Result['ID']);
         $QuoterID = db_string(G::$LoggedUser['ID']);
         $Page = db_string($Page);
         $PageID = db_string($PageID);
         $PostID = db_string($PostID);
         G::$DB->query("\n\t\t\t\tINSERT IGNORE INTO users_notify_quoted\n\t\t\t\t\t(UserID, QuoterID, Page, PageID, PostID, Date)\n\t\t\t\tVALUES\n\t\t\t\t\t('{$UserID}', '{$QuoterID}', '{$Page}', '{$PageID}', '{$PostID}', '" . sqltime() . "')");
         G::$Cache->delete_value("notify_quoted_{$UserID}");
         if ($Page == 'forums') {
             $URL = site_url() . "forums.php?action=viewthread&postid={$PostID}";
         } else {
             $URL = site_url() . "comments.php?action=jump&postid={$PostID}";
         }
         NotificationsManager::send_push($UserID, 'New Quote!', 'Quoted by ' . G::$LoggedUser['Username'] . " {$URL}", $URL, NotificationsManager::QUOTES);
     }
     G::$DB->set_query_id($QueryID);
 }
Beispiel #2
0
 /**
  * Sends a PM from $FromId to $ToId.
  *
  * @param string $ToID ID of user to send PM to. If $ToID is an array and $ConvID is empty, a message will be sent to multiple users.
  * @param string $FromID ID of user to send PM from, 0 to send from system
  * @param string $Subject
  * @param string $Body
  * @param int $ConvID The conversation the message goes in. Leave blank to start a new conversation.
  * @return
  */
 public static function send_pm($ToID, $FromID, $Subject, $Body, $ConvID = '')
 {
     global $Time;
     $UnescapedSubject = $Subject;
     $UnescapedBody = $Body;
     $Subject = db_string($Subject);
     $Body = db_string($Body);
     if ($ToID == 0 || $ToID == $FromID) {
         // Don't allow users to send messages to the system or themselves
         return;
     }
     $QueryID = G::$DB->get_query_id();
     if ($ConvID == '') {
         // Create a new conversation.
         G::$DB->query("\n\t\t\t\tINSERT INTO pm_conversations (Subject)\n\t\t\t\tVALUES ('{$Subject}')");
         $ConvID = G::$DB->inserted_id();
         G::$DB->query("\n\t\t\t\tINSERT INTO pm_conversations_users\n\t\t\t\t\t(UserID, ConvID, InInbox, InSentbox, SentDate, ReceivedDate, UnRead)\n\t\t\t\tVALUES\n\t\t\t\t\t('{$ToID}', '{$ConvID}', '1','0','" . sqltime() . "', '" . sqltime() . "', '1')");
         if ($FromID != 0) {
             G::$DB->query("\n\t\t\t\t\tINSERT INTO pm_conversations_users\n\t\t\t\t\t\t(UserID, ConvID, InInbox, InSentbox, SentDate, ReceivedDate, UnRead)\n\t\t\t\t\tVALUES\n\t\t\t\t\t\t('{$FromID}', '{$ConvID}', '0','1','" . sqltime() . "', '" . sqltime() . "', '0')");
         }
         $ToID = array($ToID);
     } else {
         // Update the pre-existing conversations.
         G::$DB->query("\n\t\t\t\tUPDATE pm_conversations_users\n\t\t\t\tSET\n\t\t\t\t\tInInbox = '1',\n\t\t\t\t\tUnRead = '1',\n\t\t\t\t\tReceivedDate = '" . sqltime() . "'\n\t\t\t\tWHERE UserID IN (" . implode(',', $ToID) . ")\n\t\t\t\t\tAND ConvID = '{$ConvID}'");
         G::$DB->query("\n\t\t\t\tUPDATE pm_conversations_users\n\t\t\t\tSET\n\t\t\t\t\tInSentbox = '1',\n\t\t\t\t\tSentDate = '" . sqltime() . "'\n\t\t\t\tWHERE UserID = '{$FromID}'\n\t\t\t\t\tAND ConvID = '{$ConvID}'");
     }
     // Now that we have a $ConvID for sure, send the message.
     G::$DB->query("\n\t\t\tINSERT INTO pm_messages\n\t\t\t\t(SenderID, ConvID, SentDate, Body)\n\t\t\tVALUES\n\t\t\t\t('{$FromID}', '{$ConvID}', '" . sqltime() . "', '{$Body}')");
     // Update the cached new message count.
     foreach ($ToID as $ID) {
         G::$DB->query("\n\t\t\t\tSELECT COUNT(ConvID)\n\t\t\t\tFROM pm_conversations_users\n\t\t\t\tWHERE UnRead = '1'\n\t\t\t\t\tAND UserID = '{$ID}'\n\t\t\t\t\tAND InInbox = '1'");
         list($UnRead) = G::$DB->next_record();
         G::$Cache->cache_value("inbox_new_{$ID}", $UnRead);
     }
     G::$DB->query("\n\t\t\tSELECT Username\n\t\t\tFROM users_main\n\t\t\tWHERE ID = '{$FromID}'");
     list($SenderName) = G::$DB->next_record();
     foreach ($ToID as $ID) {
         G::$DB->query("\n\t\t\t\tSELECT COUNT(ConvID)\n\t\t\t\tFROM pm_conversations_users\n\t\t\t\tWHERE UnRead = '1'\n\t\t\t\t\tAND UserID = '{$ID}'\n\t\t\t\t\tAND InInbox = '1'");
         list($UnRead) = G::$DB->next_record();
         G::$Cache->cache_value("inbox_new_{$ID}", $UnRead);
         NotificationsManager::send_push($ID, "Message from {$SenderName}, Subject: {$UnescapedSubject}", $UnescapedBody, site_url() . 'inbox.php', NotificationsManager::INBOX);
     }
     G::$DB->set_query_id($QueryID);
     return $ConvID;
 }
Beispiel #3
0
                } else {
                    $ThreadID = Misc::create_thread(ANNOUNCEMENT_FORUM_ID, $LoggedUser[ID], $Title, $Body);
                    if ($ThreadID < 1) {
                        error(0);
                    }
                }
                $DB->query("\n\t\t\t\t\tINSERT INTO blog\n\t\t\t\t\t\t(UserID, Title, Body, Time, ThreadID, Important)\n\t\t\t\t\tVALUES\n\t\t\t\t\t\t('" . $LoggedUser['ID'] . "',\n\t\t\t\t\t\t'" . db_string($_POST['title']) . "',\n\t\t\t\t\t\t'" . db_string($_POST['body']) . "',\n\t\t\t\t\t\t'" . sqltime() . "',\n\t\t\t\t\t\t{$ThreadID},\n\t\t\t\t\t\t'" . ($_POST['important'] == '1' ? '1' : '0') . "')");
                $Cache->delete_value('blog');
                if ($_POST['important'] == '1') {
                    $Cache->delete_value('blog_latest_id');
                }
                if (isset($_POST['subscribe'])) {
                    $DB->query("\n\t\t\t\t\t\tINSERT IGNORE INTO users_subscriptions\n\t\t\t\t\t\tVALUES ('{$LoggedUser['ID']}', {$ThreadID})");
                    $Cache->delete_value('subscriptions_user_' . $LoggedUser['ID']);
                }
                NotificationsManager::send_push(NotificationsManager::get_push_enabled_users(), $_POST['title'], $_POST['body'], site_url() . 'index.php', NotificationsManager::BLOG);
                header('Location: blog.php');
                break;
        }
    }
    ?>
		<div class="box thin">
			<div class="head">
				<?php 
    echo empty($_GET['action']) ? 'Create a blog post' : 'Edit blog post';
    ?>
			</div>
			<form class="<?php 
    echo empty($_GET['action']) ? 'create_form' : 'edit_form';
    ?>
" name="blog_post" action="blog.php" method="post">
Beispiel #4
0
<?php

authorize();
if (!check_perms('users_mod') && $_GET['userid'] != $LoggedUser['ID']) {
    error(403);
}
$UserID = db_string($_GET['userid']);
NotificationsManager::send_push($UserID, 'Push!', 'You\'ve been pushed by ' . $LoggedUser['Username']);
header('Location: user.php?action=edit&userid=' . $UserID . "");