Esempio n. 1
0
 /**
  * @NoAdminRequired
  * @NoCSRFRequired
  * @return TemplateResponse
  */
 public function read($id)
 {
     $attachements_info = [];
     $message = $this->connect->messages()->getById((int) $id);
     $parent = $this->connect->messages()->getById((int) $message['rid']);
     if (!empty($message['attachements'])) {
         $attach = [];
         try {
             $attach = json_decode($message['attachements'], true);
         } catch (\Exception $e) {
             var_dump('Exception: ' . $e->getMessage());
         }
         foreach ($attach as $at) {
             $file = $this->connect->files()->getInfoById($at);
             $fileInfo = false;
             $filePath = str_replace('files/', '', $file['path']);
             try {
                 $fileInfo = \OC\Files\Filesystem::getFileInfo($filePath);
             } catch (\Exception $e) {
             }
             //var_dump($file);
             if (!$fileInfo) {
                 $itemSource = \OCP\Share::getItemSharedWithBySource('file', $at);
                 if (is_array($itemSource) && !empty($itemSource)) {
                     $fileInfo = \OC\Files\Filesystem::getFileInfo($itemSource['file_target']);
                     $filePath = $itemSource['file_target'];
                 }
             }
             if (!$fileInfo) {
                 continue;
             }
             $icon = '/core/img/filetypes/image.svg';
             // \OCA\Files\Helper::determineIcon($fileInfo);
             $attachements_info[] = ['preview' => $icon, 'link' => "/remote.php/webdav/{$filePath}", 'file' => $file, 'info' => \OCA\Files\Helper::formatFileInfo($fileInfo)];
         }
     }
     Helper::cookies('goto_message', $message['rid'] == 0 ? $message['id'] : $parent['id'], 0, '/');
     $data = ['menu' => 'all', 'content' => 'read', 'message' => $message, 'parent' => $parent, 'attachements_info' => $attachements_info];
     return new TemplateResponse($this->appName, 'main', $data);
 }
Esempio n. 2
0
 /**
  * @NoAdminRequired
  * @NoCSRFRequired
  * @return DataResponse
  */
 public function saveTalk()
 {
     $params = ['error' => null, 'errorinfo' => null, 'insert_id' => null, 'mail_is_send' => false];
     if (Helper::post('title') && Helper::post('message')) {
         $groupsusers = [];
         $all_users = $users = Helper::post('users', false);
         $groups = Helper::post('groups', false);
         $share_files = Helper::post('share', false);
         $attachements = [];
         $attachements_info = [];
         if (!empty($groups)) {
             $groupsusers = $this->connect->users()->getGroupsUsersList();
             foreach ($groups as $group) {
                 if (isset($groupsusers[$group]) && ($rm_arr = $groupsusers[$group])) {
                     $rm_list = array_map(function ($item) {
                         return $item['uid'];
                     }, $rm_arr);
                     $users = array_diff($users, $rm_list);
                 }
             }
         }
         if (!empty($share_files)) {
             $files_id_list = array_keys($share_files);
             foreach ($share_files as $_fid => $_file) {
                 $file = $this->connect->files()->getById($_fid);
                 if (!$file) {
                     Helper::mailParserLogerError('ERROR SaveTalk - Begin, file by ID not find: ' . $_fid);
                     continue;
                 }
                 $owner = $this->userId;
                 $shareType = $file['mimetype'] == 2 ? 'folder' : 'file';
                 $sharedWith = \OCP\Share::getUsersItemShared($shareType, $file['fileid'], $owner, false, true);
                 $isEnabled = \OCP\Share::isEnabled();
                 $isAllowed = \OCP\Share::isResharingAllowed();
                 if ($isEnabled && $isAllowed) {
                     $sharedUsers = is_array($sharedWith) ? array_values($sharedWith) : [];
                     foreach ($all_users as $_uid) {
                         if ($owner == $_uid || in_array($_uid, $sharedUsers)) {
                             # disable
                             # todo loger why users not find
                         } else {
                             try {
                                 $shareLink = $this->connect->files()->shareFile($this->userId, $_uid, $_fid);
                                 $formatFileInfo = false;
                                 $fileInfo = \OC\Files\Filesystem::getFileInfo(substr($file['path'], 6));
                                 if ($fileInfo) {
                                     $formatFileInfo = \OCA\Files\Helper::formatFileInfo($fileInfo);
                                 }
                                 $attachements_info[$shareLink] = ['info' => $formatFileInfo, 'file' => $file, 'share_ink' => $shareLink];
                             } catch (\Exception $e) {
                             }
                         }
                     }
                 }
             }
             $attachements = $files_id_list;
         }
         $data['rid'] = 0;
         $data['date'] = date("Y-m-d H:i:s", time());
         $data['title'] = strip_tags(Helper::post('title'));
         $data['text'] = addslashes(Helper::post('message'));
         $data['attachements'] = json_encode((array) $attachements);
         $data['author'] = $this->userId;
         $data['subscribers'] = json_encode(['groups' => $groups, 'users' => $users]);
         $data['hash'] = TalkMail::createHash($data['date'] . $data['title']);
         $data['status'] = TalkMail::SEND_STATUS_CREATED;
         if ($params['insert_id'] = $this->connect->messages()->insertTask($data)) {
             $data['id'] = $params['insert_id'];
             $this->mailsend($data, $all_users, $attachements_info);
         }
         $params['data'] = $data;
     }
     if ($params['insert_id']) {
         Helper::cookies('goto_message', $params['insert_id']);
         header("Location: /index.php/apps/owncollab_talks/started");
         exit;
     }
     return new DataResponse($params);
 }