Example #1
0
 /**
  * Регистрирует новое личное сообщение.
  *
  * @param int    $user_id               id пользователя-отправителя 
  * @param string $target_login          логин пользователя-получателя
  * @param string $text                  текст сообщения
  * @param array  $files                 прикрепленные файлы
  * @param int    $force                 разрешение/отказ ответа на письмо (1/0)
  * @param bool   $skip_mail             Если TRUE - не отправлять уведомление о новом сообщении на емайл.
  * @param string $attachedfiles_session ID сессии загруженных файлов
  *
  * @return mixed сообщение об ошибке и флаг ошибки в случае ее возниконовения
  */
 public function Add($user_id, $target_login, $text, $files, $force = 0, $skip_mail = false, $attachedfiles_session = null, &$message_id = 0)
 {
     require_once $_SERVER['DOCUMENT_ROOT'] . '/classes/users.php';
     require_once $_SERVER['DOCUMENT_ROOT'] . '/classes/ignor.php';
     $users = new users();
     $login = $users->GetName($user_id, $err);
     $tar_id = $users->GetUid($err, $target_login);
     if ((ignor::CheckIgnored($tar_id, $user_id) || in_array($target_login, array('admin', 'Anonymous'))) && !$force) {
         $error = 'Пользователь запретил отправлять ему сообщения';
     } else {
         if ($files) {
             if (count($files) > self::MAX_FILES) {
                 $alert[1] = 'Вы не можете прикрепить больше ' . self::MAX_FILES . ' файлов к сообщению.';
             } else {
                 $max_file_size = self::MAX_FILE_SIZE;
                 foreach ($files as $file) {
                     $ext = $file->getext();
                     $file->max_size = $max_file_size;
                     $max_file_size -= $file->size;
                     if (!in_array($ext, $GLOBALS['disallowed_array'])) {
                         $f_name = $file->MoveUploadedFile($login['login'] . '/contacts');
                         if (!isNulArray($file->error)) {
                             if ($max_file_size < 0) {
                                 $alert[1] = 'Вы превысили максимально допустимый размер файлов';
                             } else {
                                 $alert[1] = $GLOBALS['PDA'] ? 'Файл не удовлетворяет условиям загрузки' : 'Один или несколько файлов не удовлетворяют условиям загрузки.';
                             }
                             break;
                         }
                     } else {
                         $alert[1] = $GLOBALS['PDA'] ? 'Файл не удовлетворяет условиям загрузки' : 'Один или несколько файлов имеют неправильный формат.';
                     }
                 }
             }
         }
         if (empty($alert) && empty($error)) {
             $memBuff = new memBuff();
             // автоматические папки для массовых рассылок личных менеджеров
             global $aPmUserUids;
             if (in_array($tar_id, $aPmUserUids) || SERVER === 'local' || SERVER === 'beta' || SERVER === 'alpha') {
                 $DBproxy = new DB();
                 $nRecId = $DBproxy->val('SELECT mess_pm_ustf_add(?i, ?i)', $tar_id, $user_id);
                 if ($nRecId) {
                     $memBuff->delete('pmAutoFolder' . $tar_id . '_' . $nRecId);
                 }
             }
             //---------------------------------------------
             $DB = new DB();
             $f = array();
             if ($files) {
                 foreach ($files as $file) {
                     $f[] = $file->id;
                 }
             }
             require_once $_SERVER['DOCUMENT_ROOT'] . '/classes/attachedfiles.php';
             $attachedfiles = new attachedfiles($attachedfiles_session);
             $attachedfiles_files = $attachedfiles->getFiles();
             if ($attachedfiles_files) {
                 foreach ($attachedfiles_files as $attachedfiles_file) {
                     $cFile = new CFile($attachedfiles_file['id']);
                     $cFile->table = 'file';
                     $ext = $cFile->getext();
                     $tmp_dir = 'users/' . substr($login['login'], 0, 2) . '/' . $login['login'] . '/contacts/';
                     $tmp_name = $cFile->secure_tmpname($tmp_dir, '.' . $ext);
                     $tmp_name = substr_replace($tmp_name, '', 0, strlen($tmp_dir));
                     $cFile->_remoteCopy($tmp_dir . $tmp_name, true);
                     $f[] = $cFile->id;
                 }
             }
             $attachedfiles->clear();
             $aNoMod = array_merge($GLOBALS['aContactsNoMod'], $GLOBALS['aPmUserUids']);
             //$bNoMod = hasPermissions('streamnomod', $user_id) || hasPermissions('streamnomod', $tar_id) || is_pro(true, $user_id) || is_pro(true, $tar_id) || in_array($user_id, $aNoMod);
             $bNoMod = true;
             // #0022344: Убрать из потоков личку
             $message_id = $DB->val('SELECT messages_add(?i, ?i, ?, ?b, ?a, ?b)', $user_id, $tar_id, $text, $skip_mail, $f, $bNoMod);
             if ($user_id % 2 == $tar_id % 2) {
                 $memBuff->delete(self::MEMBUFF_CHAT_PREFIX . $tar_id);
             }
             if ($message_id && !$skip_mail && !QChat::active($tar_id)) {
                 $mail = new pmail();
                 $mail->NewMessage($user_id, $tar_id, stripslashes($text));
             }
             if ($message_id) {
                 require_once $_SERVER['DOCUMENT_ROOT'] . '/classes/external/base.php';
                 require_once $_SERVER['DOCUMENT_ROOT'] . '/classes/external/api/api.php';
                 require_once $_SERVER['DOCUMENT_ROOT'] . '/classes/external/api/mobile.php';
                 externalApi_Mobile::addPushMsg($tar_id, 'message', array('from_user_id' => get_uid(false), 'text' => stripslashes($text)));
             }
         }
     }
     return array($alert, $error);
 }
Example #2
0
<?php

require_once 'classes/stdf.php';
require_once 'classes/QChat.php';
header('Content-Type: text/html; charset=utf-8');
//$_POST = $_GET;
$uid = get_uid(false);
$cid = isset($_POST['cid']) ? $_POST['cid'] : '';
$ckey = isset($_POST['ckey']) ? $_POST['ckey'] : '';
$func = isset($_POST['func']) ? $_POST['func'] : '';
$attr = isset($_POST['attr']) ? $_POST['attr'] : '';
if (empty($uid) || !preg_match('/^[a-zA-Z0-9]{8}$/', $cid) || !preg_match('/^[0-9]{1,9}$/', $ckey)) {
    QChat::error(2, true);
}
$stream = '';
if (!empty($_POST['stream']) && ($_POST['stream'] == 'hold' || $_POST['stream'] == 'drop')) {
    $stream = $_POST['stream'];
}
$qChat = new QChat($uid, $cid, $ckey);
if ($stream) {
    $qChat->stream($stream);
} else {
    if ($func) {
        $attr = json_decode(stripslashes($attr));
        if (!is_null($attr)) {
            $qChat->event($func, $attr);
        }
    }
}