Пример #1
0
 public function create($p)
 {
     $rez = array('succes' => false, 'data' => array());
     if (empty($p['node_id']) || empty($p['data'])) {
         return $rez;
     }
     $data = array('name' => Purify::filename($p['data']['name']), 'path' => $p['data']['path'], 'pathText' => empty($p['data']['pathText']) ? '' : $p['data']['pathText']);
     if (is_numeric($p['node_id'])) {
         $data['template_id'] = Objects::getTemplateId($p['node_id']);
         $data['iconCls'] = Browser::getIcon($data);
     } elseif (!empty($p['data']['iconCls'])) {
         $data['iconCls'] = $p['data']['iconCls'];
     }
     $d = array('user_id' => User::getId(), 'node_id' => $p['node_id'], 'data' => Util\jsonEncode($data));
     $id = DM\Favorites::create($d);
     $rez = array('success' => true, 'data' => array('id' => $id, 'node_id' => $d['node_id'], 'data' => $data));
     return $rez;
 }
Пример #2
0
 /**
  * download files
  *
  * outputs file content and set corresponding header params
  *
  * @param  int  $id file id
  * @return void
  */
 public static function download($id, $versionId = null, $asAttachment = true, $forUseId = false)
 {
     $r = empty($versionId) ? DM\Files::read($id) : DM\FilesVersions::read($versionId);
     if (!empty($r)) {
         $content = DM\FilesContent::read($r['content_id']);
         //check if can download file
         if (!Security::canDownload($r['id'], $forUseId)) {
             throw new \Exception(L\get('Access_denied'));
         }
         header('Content-Description: File Transfer');
         header('Content-Type: ' . $content['type'] . '; charset=UTF-8');
         if ($asAttachment || $content['type'] !== 'application/pdf') {
             //purify filename for cases when we have a wrong filename in the system already
             header('Content-Disposition: attachment; filename="' . Purify::filename($r['name']) . '"');
         }
         header('Content-Transfer-Encoding: binary');
         header('Expires: 0');
         header('Cache-Control: must-revalidate');
         header('Pragma: public');
         header('Content-Length: ' . $content['size']);
         readfile(Config::get('files_dir') . $content['path'] . DIRECTORY_SEPARATOR . $content['id']);
     } else {
         throw new \Exception(L\get('Object_not_found'));
     }
 }
Пример #3
0
 /**
  * change theme for currently loged user
  * @param  int   $id language id
  * @return array json responce
  */
 public function setTheme($id)
 {
     $id = Purify::filename($id);
     $_SESSION['user']['cfg']['theme'] = $id;
     $cfg = $this->getUserConfig();
     $cfg['theme'] = $id;
     $this->setUserConfig($cfg);
     return array('success' => true);
 }
Пример #4
0
 /**
  * download files
  *
  * outputs file content and set corresponding header params
  *
  * @param  int  $id file id
  * @return void
  */
 public static function download($id, $versionId = null, $asAttachment = true, $forUseId = false)
 {
     $sql = empty($versionId) ? 'SELECT f.id
             ,f.content_id
             ,c.path
             ,f.name
             ,c.`type`
             ,c.size
         FROM files f
         LEFT JOIN files_content c ON f.content_id = c.id
         WHERE f.id = $1' : 'SELECT f.file_id `id`
             ,f.id `version_id`
             ,f.content_id
             ,c.path
             ,f.name
             ,c.`type`
             ,c.size
         FROM files_versions f
         LEFT JOIN files_content c ON f.content_id = c.id
         WHERE f.id = $1';
     $res = DB\dbQuery($sql, Util\coalesce($versionId, $id)) or die(DB\dbQueryError());
     if ($r = $res->fetch_assoc()) {
         //check if can download file
         if (!Security::canDownload($r['id'], $forUseId)) {
             throw new \Exception(L\get('Access_denied'));
         }
         header('Content-Description: File Transfer');
         header('Content-Type: ' . $r['type'] . '; charset=UTF-8');
         if ($asAttachment || $r['type'] !== 'application/pdf') {
             //purify filename for cases when we have a wrong filename in the system already
             header('Content-Disposition: attachment; filename="' . Purify::filename($r['name']) . '"');
         }
         header('Content-Transfer-Encoding: binary');
         header('Expires: 0');
         header('Cache-Control: must-revalidate');
         header('Pragma: public');
         header('Content-Length: ' . $r['size']);
         readfile(Config::get('files_dir') . $r['path'] . DIRECTORY_SEPARATOR . $r['content_id']);
     } else {
         throw new \Exception(L\get('Object_not_found'));
     }
     $res->close();
 }
Пример #5
0
 public function confirmUploadRequest($p)
 {
     //if cancel then delete all uploaded files from incomming
     $files = new Files();
     $a = $files->getUploadParams();
     $a['response'] = $p['response'];
     switch ($p['response']) {
         case 'rename':
             $a['newName'] = Purify::filename($p['newName']);
             //check if the new name does not also exist
             if (empty($a['response'])) {
                 return array('success' => false, 'msg' => L\get('FilenameCannotBeEmpty'));
             }
             reset($a['files']);
             $k = key($a['files']);
             $a['files'][$k]['name'] = $a['newName'];
             if ($files->fileExists($a['pid'], $a['newName'])) {
                 $files->saveUploadParams($a);
                 return array('success' => false, 'type' => 'filesexist', 'allow_new_version' => Files::getMFVC($a['newName']) > 0, 'suggestedFilename' => Objects::getAvailableName($a['pid'], $a['newName']), 'msg' => str_replace('{filename}', '"' . $a['newName'] . '"', L\get('FilenameExistsInTarget')));
             }
             // $files->storeFiles($a);
             // break;
         // $files->storeFiles($a);
         // break;
         case 'newversion':
         case 'replace':
         case 'autorename':
             $files->storeFiles($a);
             break;
         default:
             //cancel
             $files->removeIncomingFiles($a['files']);
             return array('success' => true, 'data' => array());
             break;
     }
     Solr\Client::runCron();
     $rez = array('success' => true, 'data' => array('pid' => $a['pid']));
     $files->attachPostUploadInfo($a['files'], $rez);
     return $rez;
 }