Exemple #1
0
 protected function handle_file_upload($uploaded_file, $name, $size, $type, $error, $index = null, $content_range = null)
 {
     $matches = array();
     if (strpos($name, '.') === false && preg_match('/^image\\/(gif|jpe?g|png)/', $type, $matches)) {
         $name = $uploadFileName = 'clipboard.' . $matches[1];
     } else {
         $uploadFileName = $name;
     }
     if (!preg_match($this->options['accept_file_types_lhc'], $uploadFileName)) {
         $file->error = $this->get_error_message('accept_file_types');
         return false;
     }
     $file = parent::handle_file_upload($uploaded_file, $name, $size, $type, $error, $index, $content_range);
     if (empty($file->error)) {
         $fileUpload = new erLhcoreClassModelChatFile();
         $fileUpload->size = $file->size;
         $fileUpload->type = $file->type;
         $fileUpload->name = $file->name;
         $fileUpload->date = time();
         $fileUpload->user_id = isset($this->options['user_id']) ? $this->options['user_id'] : 0;
         $fileUpload->upload_name = $name;
         $fileUpload->file_path = $this->options['upload_dir'];
         if (isset($this->options['chat']) && $this->options['chat'] instanceof erLhcoreClassModelChat) {
             $fileUpload->chat_id = $this->options['chat']->id;
         } elseif (isset($this->options['online_user']) && $this->options['online_user'] instanceof erLhcoreClassModelChatOnlineUser) {
             $fileUpload->online_user_id = $this->options['online_user']->id;
         }
         $matches = array();
         if (strpos($name, '.') === false && preg_match('/^image\\/(gif|jpe?g|png)/', $fileUpload->type, $matches)) {
             $fileUpload->extension = $matches[1];
         } else {
             $partsFile = explode('.', $fileUpload->upload_name);
             $fileUpload->extension = end($partsFile);
         }
         $fileUpload->saveThis();
         $file->id = $fileUpload->id;
         if (isset($this->options['chat']) && $this->options['chat'] instanceof erLhcoreClassModelChat) {
             // Chat assign
             $chat = $this->options['chat'];
             // Format message
             $msg = new erLhcoreClassModelmsg();
             $msg->msg = '[file=' . $file->id . '_' . md5($fileUpload->name . '_' . $fileUpload->chat_id) . ']';
             $msg->chat_id = $chat->id;
             $msg->user_id = isset($this->options['user_id']) ? $this->options['user_id'] : 0;
             if ($msg->user_id > 0 && isset($this->options['name_support'])) {
                 $msg->name_support = (string) $this->options['name_support'];
             }
             $chat->last_user_msg_time = $msg->time = time();
             erLhcoreClassChat::getSession()->save($msg);
             // Set last message ID
             if ($chat->last_msg_id < $msg->id) {
                 $chat->last_msg_id = $msg->id;
             }
             $chat->has_unread_messages = 1;
             $chat->updateThis();
         }
         $this->uploadedFile = $fileUpload;
     }
     return $file;
 }
 protected function handle_file_upload($uploaded_file, $name, $size, $type, $error, $index = null, $content_range = null)
 {
     $matches = array();
     if (strpos($name, '.') === false && preg_match('/^image\\/(gif|jpe?g|png)/', $type, $matches)) {
         $name = $uploadFileName = 'clipboard.' . $matches[1];
     } else {
         $uploadFileName = $name;
     }
     if (!preg_match($this->options['accept_file_types_lhc'], $uploadFileName)) {
         throw new Exception($this->get_error_message('accept_file_types'));
         return false;
     }
     $file = parent::handle_file_upload_parent($uploaded_file, $name, $size, $type, $error, $index, $content_range);
     if (empty($file->error)) {
         $fileUpload = new erLhcoreClassModelChatFile();
         $fileUpload->size = $file->size;
         $fileUpload->type = $file->type;
         $fileUpload->name = $file->name;
         $fileUpload->date = time();
         $fileUpload->user_id = isset($this->options['user_id']) ? $this->options['user_id'] : 0;
         $fileUpload->upload_name = isset($this->options['file_name_manual']) && $this->options['file_name_manual'] != '' ? $this->options['file_name_manual'] . ' - ' . $name : $name;
         $fileUpload->file_path = $this->options['upload_dir'];
         $fileUpload->chat_id = 0;
         $matches = array();
         if (strpos($name, '.') === false && preg_match('/^image\\/(gif|jpe?g|png)/', $fileUpload->type, $matches)) {
             $fileUpload->extension = $matches[1];
         } else {
             $partsFile = explode('.', $name);
             $fileUpload->extension = end($partsFile);
         }
         $fileUpload->saveThis();
         $this->uploadedFile = $fileUpload;
     } else {
         throw new Exception($file->error);
     }
     return $file;
 }
 }
 $fileUpload = new erLhcoreClassModelChatFile();
 $fileUpload->size = strlen($imgData);
 $fileUpload->type = 'image/png';
 $fileUpload->name = $fileNameHash;
 $fileUpload->date = time();
 $fileUpload->user_id = 0;
 $fileUpload->upload_name = 'screenshot.png';
 $fileUpload->file_path = $path;
 if ($chat !== false) {
     $fileUpload->chat_id = $chat->id;
 } else {
     $fileUpload->chat_id = 0;
 }
 $fileUpload->extension = 'png';
 $fileUpload->saveThis();
 erLhcoreClassChatEventDispatcher::getInstance()->dispatch('file.storescreenshot.store', array('chat_file' => &$fileUpload));
 if ($chat !== false) {
     $chat->user_typing_txt = erTranslationClassLhTranslation::getInstance()->getTranslation('chat/screenshot', 'Screenshot ready...');
     $chat->user_typing = time();
     $chat->screenshot_id = $fileUpload->id;
     $chat->updateThis();
 }
 if ($chat !== false && $chat->online_user !== false) {
     $chat->online_user->screenshot_id = $fileUpload->id;
     $chat->online_user->saveThis();
 } elseif (is_object($vid)) {
     $vid->screenshot_id = $fileUpload->id;
     $vid->saveThis();
 }
 $db->commit();