Exemple #1
0
 public function getData($id = false)
 {
     $rez = array('success' => true, 'data' => array());
     parent::getData($id);
     $o = $this->getObjectClass();
     if (empty($o)) {
         return $rez;
     }
     $data = $o->getData();
     //dont display thumb for images less then 1MB
     $maxDisplaySize = Util\coalesce(Config::get('images_display_size'), 1024 * 1024);
     if (substr($data['content_type'], 0, 5) == 'image' && $data['size'] < $maxDisplaySize) {
         $preview = Files::generatePreview($data['id']);
         if (!empty($preview['filename'])) {
             $fn = Config::get('files_preview_dir') . $preview['filename'];
             $rez['data']['html'] = $fn;
             if (file_exists($fn)) {
                 $rez['data']['html'] = str_replace('fit-img', 'click fit-img', file_get_contents($fn));
             }
         }
     } else {
         $rez['data']['cls'] = 'pr-th-' . \CB\Files::getExtension($data['name']);
     }
     return $rez;
 }
Exemple #2
0
 /**
  * method for laoding core config
  * @param  array $cfg default configuration
  * @return array throw an exception if core is not defined in db
  */
 public static function load($cfg = array())
 {
     $instance = static::getInstance();
     // merging configs from platform, from casebox database and from core itself
     $cfg = array_merge($cfg, static::getPlatformDBConfig());
     $cfg = array_merge($cfg, static::getPlatformConfigForCore($cfg['core_name']));
     $coreDBConfig = static::getCoreDBConfig();
     $propertiesToMerge = array('files');
     //detect available languages
     $languages = empty($coreDBConfig['languages']) ? $cfg['languages'] : $coreDBConfig['languages'];
     //prepare language properties to be decoded and merged
     $languages = explode(',', $languages);
     foreach ($languages as $l) {
         $l = 'language_' . $l;
         if (isset($cfg[$l])) {
             $cfg[$l] = Util\toJSONArray($cfg[$l]);
         }
         if (isset($coreDBConfig[$l])) {
             $coreDBConfig[$l] = Util\toJSONArray($coreDBConfig[$l]);
         }
         $propertiesToMerge[] = $l;
     }
     $cfg = static::mergeConfigs($cfg, $coreDBConfig, $propertiesToMerge);
     static::$config = static::adjustConfig($cfg);
     static::$environmentVars = static::getEnvironmentVars(static::$config);
     // add core path to include path
     set_include_path(INCLUDE_PATH . PATH_SEPARATOR . static::$environmentVars['core_dir']);
     // set max file version count
     if (isset(static::$config['files']['max_versions'])) {
         __autoload('CB\\Files');
         Files::setMFVC(static::$config['files']['max_versions']);
     } elseif (isset(static::$config['max_files_version_count'])) {
         //backward compatibility check
         __autoload('CB\\Files');
         Files::setMFVC(static::$config['max_files_version_count']);
     }
     // set temp upload directory
     ini_set('upload_tmp_dir', static::$environmentVars['upload_temp_dir']);
     ini_set('error_log', static::$environmentVars['error_log']);
     return static::$config;
 }
Exemple #3
0
 public static function getMFVC($filename)
 {
     $ext = Files::getExtension($filename);
     if (empty($ext)) {
         $ext = mb_strtolower($filename);
     }
     $ext = trim($ext);
     $rez = 0;
     $mfvc = Config::get('mfvc');
     if (empty($mfvc)) {
         return $rez;
     }
     $ext = mb_strtolower($ext);
     if (isset($mfvc[$ext])) {
         return $mfvc[$ext];
     }
     if (isset($mfvc['*'])) {
         return $mfvc['*'];
     }
     return $rez;
 }
Exemple #4
0
 public static function createCaseboxFile($pid, $name, $data = null)
 {
     $path = \CB\Config::get('incomming_files_dir') . $name;
     file_put_contents($path, $data);
     $action = 'newversion';
     //check if file exists and its size is 0
     $id = \CB\Files::getFileId($pid, $name);
     if (!empty($id)) {
         if (\CB\Files::getSize($id) <= 1) {
             $action = 'replace';
         }
     }
     $param = array('pid' => $pid, 'title' => $name, 'localFile' => $path, 'owner' => $_SESSION['user']['id'], 'tmplId' => \CB\Config::get('default_file_template'), 'fileExistAction' => $action);
     $fl = new \CB\Api\Files();
     $fl->upload($param);
     \CB\Solr\Client::runCron();
 }
Exemple #5
0
 /**
  * detect object icon by analizing it's data
  *
  * object data could have set a custom iconCls in cfg property of the data,
  * otherwise the icon is determined from it's template
  * TODO: think about shortcuts
  * @param  array   $data object data
  * @return varchar iconCls
  */
 public static function getIcon(&$data)
 {
     if (!empty($data['cfg']) && !empty($data['cfg']['iconCls'])) {
         return $data['cfg']['iconCls'];
     }
     if (empty($data['template_id'])) {
         return 'icon-none';
     }
     $templates = Templates\SingletonCollection::getInstance();
     $templateData = $templates->getTemplate($data['template_id'])->getData();
     if (!empty($templateData['iconCls'])) {
         return $templateData['iconCls'];
     }
     switch ($templateData['type']) {
         case 'object':
             if (in_array($data['template_id'], Config::get('folder_templates'))) {
                 return 'icon-folder';
             }
             break;
         case 2:
             return 'icon-shortcut';
             //case
             break;
         case 'file':
             return Files::getIcon($data['name']);
             break;
         case 'task':
             if (@$d['status'] == 3) {
                 return 'icon-task-completed';
             }
             return 'icon-task';
             //task
             break;
         case 'email':
             return 'icon-mail';
             //Message (email)
             break;
     }
     return 'icon-none';
 }
Exemple #6
0
 /**
  * get link to a file to be displayed in comments
  * @param  array   $file
  * @return varchar
  */
 protected static function getFileLink($file)
 {
     $rez = '';
     if (substr($file['type'], 0, 5) == 'image') {
         $rez = '<a class="click obj-ref" itemid="' . $file['id'] . '" templateid= "' . $file['template_id'] . '" title="' . $file['name'] . '"><img class="fit-img" src="/' . Config::get('core_name') . '/download/' . $file['id'] . '/" /></a>';
     } else {
         $rez = '<a class="click obj-ref icon-padding ' . \CB\Files::getIcon($file['name']) . '" itemid="' . $file['id'] . '" templateid= "' . $file['template_id'] . '">' . $file['name'] . '</a>';
     }
     return $rez;
 }
Exemple #7
0
 /**
  * download a file
  *
  * outputs file content and set corresponding header params
  *
  * @param  int  $id file id
  * @return void
  */
 public function download($id, $asAttachment = true)
 {
     \CB\Files::download($id, null, $asAttachment);
 }