Exemplo n.º 1
0
 /**
  * Add/edit file attachment
  *
  *
  * @return     boolean or error
  */
 public function addAttachment($filePath, $pub, $configs, $uid, $elementId, $element, $ordering = 1)
 {
     // Need to check against allowed types
     if ($configs->check) {
         if (!$this->checkAllowed(array($filePath), $element->typeParams->allowed_ext)) {
             return false;
         }
     }
     // Get latest Git hash
     $vcs_hash = $this->_git->gitLog($filePath, '', 'hash');
     $new = 0;
     $update = 0;
     $objPA = new \Components\Publications\Tables\Attachment($this->_parent->_db);
     if ($objPA->loadElementAttachment($pub->version_id, array('path' => $filePath), $elementId, $this->_name, $element->role)) {
         // Update if new hash
         if ($vcs_hash && $vcs_hash != $objPA->vcs_hash) {
             $objPA->vcs_hash = $vcs_hash;
             $objPA->modified_by = $uid;
             $objPA->modified = Date::toSql();
             $update = 1;
             // Copy file again (new version)
             // Reflect the update in curation record
             $this->_parent->set('_update', 1);
         }
     } else {
         $new = 1;
         $objPA->publication_id = $pub->id;
         $objPA->publication_version_id = $pub->version_id;
         $objPA->path = $filePath;
         $objPA->type = $this->_name;
         $objPA->vcs_hash = $vcs_hash;
         $objPA->created_by = $uid;
         $objPA->created = Date::toSql();
         $objPA->role = $element->role;
         // Reflect the update in curation record
         $this->_parent->set('_update', 1);
     }
     $objPA->element_id = $elementId;
     $objPA->ordering = $ordering;
     // Copy file from project repo into publication directory
     if ($objPA->store()) {
         // Check for conflict in file name
         if ($new == 1) {
             $suffix = $this->checkForDuplicate($configs->path . DS . $filePath, $objPA, $configs);
             if ($suffix) {
                 $pa = new \Components\Publications\Tables\Attachment($this->_parent->_db);
                 $pa->saveParam($objPA, 'suffix', $suffix);
             }
         }
         // Copy file over to where to belongs
         if (!$this->publishAttachment($objPA, $pub, $configs, $update)) {
             return false;
         }
         // Make default image (if applicable)
         if ($configs->handler && $configs->handler->getName() == 'imageviewer') {
             $currentDefault = new \Components\Publications\Tables\Attachment($this->_parent->_db);
             if (!$currentDefault->getDefault($pub->version_id)) {
                 $configs->handler->makeDefault($objPA, $pub, $configs);
             }
         }
         return true;
     }
     return false;
 }
Exemplo n.º 2
0
 /**
  * Process file data
  *
  * @access public
  * @return void
  */
 public function processFileData($fileRecord, $pub, $version)
 {
     $attachment = $fileRecord['attachment'];
     $vid = $pub->version_id;
     $pid = $pub->id;
     // Get latest Git hash
     $vcs_hash = $this->_git->gitLog($attachment->path, '', 'hash');
     // Create attachment record
     if ($this->curationModel || $fileRecord['type'] != 'gallery') {
         $attachment->publication_id = $pid;
         $attachment->publication_version_id = $vid;
         $attachment->vcs_hash = $vcs_hash;
         $attachment->created_by = $this->_uid;
         $attachment->created = Date::toSql();
         $attachment->store();
     }
     // Copy files to the right location
     if ($this->curationModel) {
         // Get attachment type model
         $attModel = new Models\Attachments($this->database);
         $fileAttach = $attModel->loadAttach('file');
         // Get element manifest
         $elements = $this->curationModel->getElements($attachment->role);
         if (!$elements) {
             return false;
         }
         $element = $elements[0];
         // Set configs
         $configs = $fileAttach->getConfigs($element->manifest->params, $element->id, $pub, $element->block);
         // Check if names is already used
         $suffix = $fileAttach->checkForDuplicate($configs->path . DS . $attachment->path, $attachment, $configs);
         // Save params if applicable
         if ($suffix) {
             $pa = new \Components\Publications\Tables\Attachment($this->database);
             $pa->saveParam($attachment, 'suffix', $suffix);
         }
         // Copy file into the right spot
         $fileAttach->publishAttachment($attachment, $pub, $configs);
     }
 }
Exemplo n.º 3
0
 /**
  * Make image default for publication
  *
  * @return  void
  */
 public function makeDefault($row, $pub, $configs)
 {
     // Make sure we got config
     if (!$this->_config) {
         $this->getConfig();
     }
     // TBD - to come from component configs
     $defaultMasterName = 'master.png';
     $defaultThumbName = 'thumb.gif';
     $path = $this->getFilePath($row->path, $row->id, $configs, $row->params);
     // No file found
     if (!is_file($path)) {
         return false;
     }
     // Check if image
     if (!getimagesize($path)) {
         return false;
     }
     $copyToThumb = $configs->pubBase . DS . $defaultThumbName;
     $copyToMaster = $configs->pubBase . DS . $defaultMasterName;
     $thumbName = \Components\Publications\Helpers\Html::createThumbName(basename($path), $this->_config->params->thumbSuffix, $this->_config->params->thumbFormat);
     $thumbPath = dirname($path) . DS . $thumbName;
     // Copy to master
     if (is_file($path)) {
         Filesystem::copy($path, $copyToMaster);
         // Create/update thumb
         Filesystem::copy($path, $copyToThumb);
         $hi = new \Hubzero\Image\Processor($copyToThumb);
         if (count($hi->getErrors()) == 0) {
             $hi->resize(100, false, true, true);
             $hi->save($copyToThumb);
         }
     } else {
         return false;
     }
     // Get current default
     $currentDefault = new \Components\Publications\Tables\Attachment($this->_parent->_db);
     $currentDefault->getDefault($row->publication_version_id);
     // Unmark as default
     if ($currentDefault->id) {
         $currentDefault->saveParam($currentDefault, 'pubThumb', '');
     }
     // Mark this image as default
     $currentDefault->saveParam($row, 'pubThumb', '1');
     return true;
 }