/** * Publish supporting database files * * @param object $objPD * * @return boolean or error */ public function publishDataFiles($objPD, $configs) { if (!$objPD->id) { return false; } // Get data definition $dd = json_decode($objPD->data_definition, true); $files = array(); $columns = array(); foreach ($dd['cols'] as $colname => $col) { if (isset($col['linktype']) && $col['linktype'] == "repofiles") { $dir = ''; if (isset($col['linkpath']) && $col['linkpath'] != '') { $dir = $col['linkpath']; } $columns[$col['idx']] = $dir; } } // No files to publish if (empty($columns)) { return false; } $repoPath = $objPD->source_dir ? $configs->path . DS . $objPD->source_dir : $configs->path; $csv = $repoPath . DS . $objPD->source_file; if (file_exists($csv) && ($handle = fopen($csv, "r")) !== FALSE) { // Check if expert mode CSV $expert_mode = false; $col_labels = fgetcsv($handle); $col_prop = fgetcsv($handle); $data_start = fgetcsv($handle); if (isset($data_start[0]) && $data_start[0] == 'DATASTART') { $expert_mode = true; } while ($r = fgetcsv($handle)) { for ($i = 0; $i < count($col_labels); $i++) { if (isset($columns[$i])) { if (isset($r[$i]) && $r[$i] != '') { $file = $columns[$i] ? $columns[$i] . DS . trim($r[$i]) : trim($r[$i]); if (file_exists($repoPath . DS . $file)) { $files[] = $file; } } } } } } // Copy files from repo to published location if (!empty($files)) { foreach ($files as $file) { if (!file_exists($repoPath . DS . $file)) { continue; } // If parent dir does not exist, we must create it if (!file_exists(dirname($configs->dataPath . DS . $file))) { Filesystem::makeDirectory(dirname($configs->dataPath . DS . $file), 0755, true, true); } if (Filesystem::copy($repoPath . DS . $file, $configs->dataPath . DS . $file)) { // Generate thumbnail $thumb = \Components\Publications\Helpers\Html::createThumbName($file, '_tn', $extension = 'gif'); Filesystem::copy($repoPath . DS . $file, $configs->dataPath . DS . $thumb); $hi = new \Hubzero\Image\Processor($configs->dataPath . DS . $thumb); if (count($hi->getErrors()) == 0) { $hi->resize(180, false, false, false); $hi->save($configs->dataPath . DS . $thumb); } else { return false; } // Generate medium image $med = \Components\Publications\Helpers\Html::createThumbName($file, '_medium', $extension = 'gif'); Filesystem::copy($repoPath . DS . $file, $configs->dataPath . DS . $med); $hi = new \Hubzero\Image\Processor($configs->dataPath . DS . $med); if (count($hi->getErrors()) == 0) { $hi->resize(800, false, false, false); $hi->save($configs->dataPath . DS . $med); } else { return false; } } } } }
/** * Make thumb * * @return void */ public function makeThumbnail($row, $pub, $configs) { // Make sure we got config if (!$this->_config) { $this->getConfig(); } $fpath = $this->getFilePath($row->path, $row->id, $configs, $row->params); $thumbName = \Components\Publications\Helpers\Html::createThumbName(basename($fpath), $this->_config->params->thumbSuffix, $this->_config->params->thumbFormat); $thumbPath = $configs->pubPath . DS . $thumbName; // No file found if (!is_file($fpath)) { return; } // Check if image if (!getimagesize($fpath)) { return false; } $md5 = hash_file('sha256', $fpath); // Create/update thumb if doesn't exist or file changed if (!is_file($thumbPath) || $md5 != $row->content_hash) { Filesystem::copy($fpath, $thumbPath); $hi = new \Hubzero\Image\Processor($thumbPath); if (count($hi->getErrors()) == 0) { $hi->resize($this->_config->params->thumbWidth, false, true, true); $hi->save($thumbPath); } else { return false; } } return true; }