/** * Get project thumbnail source * * @return string */ public function getThumbSrc() { if (!$this->model->exists()) { return false; } $src = ''; $path = PATH_APP . DS . trim($this->config->get('imagepath', '/site/projects'), DS) . DS . $this->model->get('alias') . DS . 'images'; if (file_exists($path . DS . 'thumb.png')) { return $path . DS . 'thumb.png'; } if ($this->model->get('picture')) { $thumb = Helpers\Html::createThumbName($this->model->get('picture')); $src = $thumb && file_exists($path . DS . $thumb) ? $path . DS . $thumb : NULL; } if (!$src) { $path = trim($this->config->get('defaultpic', 'components/com_projects/site/assets/img/project.png'), DS); if ($path == 'components/com_projects/assets/img/project.png') { $path = 'components/com_projects/site/assets/img/project.png'; } $src = PATH_CORE . DS . $path; } return $src; }
/** * Get preview image * * @return mixed */ public function getPreview($model, $hash = '', $get = 'name', $render = '', $hashed = NULL) { if (!$model instanceof Project) { return false; } $image = NULL; if (!$hashed) { $hash = $hash ? $hash : $this->get('hash'); $hash = $hash ? substr($hash, 0, 10) : ''; // Determine name and size switch ($render) { case 'medium': $hashed = md5($this->get('name') . '-' . $hash) . '.png'; $maxWidth = 600; $maxHeight = 600; break; case 'thumb': $hashed = $hash ? Helpers\Html::createThumbName($this->get('name'), '-' . $hash, 'png') : NULL; $maxWidth = 80; $maxHeight = 80; break; default: $hashed = $hash ? Helpers\Html::createThumbName($this->get('name'), '-' . $hash . '-thumb', 'png') : NULL; $maxWidth = 180; $maxHeight = 180; break; } } // Target directory $target = PATH_APP . DS . trim($model->config()->get('imagepath', '/site/projects'), DS); $target .= DS . strtolower($model->get('alias')) . DS . 'preview'; $remoteThumb = NULL; if ($this->get('remoteId') && $this->get('modified')) { $remoteThumb = substr($this->get('remoteId'), 0, 20) . '_' . strtotime($this->get('modified')) . '.png'; } if ($hashed && is_file($target . DS . $hashed)) { // First check locally generated thumbnail $image = $target . DS . $hashed; } elseif ($remoteThumb && is_file($target . DS . $remoteThumb)) { // Check remotely generated thumbnail $image = $target . DS . $remoteThumb; // Copy this over as local thumb if ($hashed && Filesystem::copy($target . DS . $remoteThumb, $target . DS . $hashed)) { Filesystem::delete($target . DS . $remoteThumb); } } else { // Generate thumbnail locally if (!file_exists($target)) { Filesystem::makeDirectory($target, 0755, true, true); } // Make sure it's an image file if (!$this->isImage() || !is_file($this->get('fullPath'))) { return false; } if (!Filesystem::copy($this->get('fullPath'), $target . DS . $hashed)) { return false; } // Resize the image if necessary $hi = new \Hubzero\Image\Processor($target . DS . $hashed); $square = $render == 'thumb' ? true : false; $hi->resize($maxWidth, false, false, $square); $hi->save($target . DS . $hashed); $image = $target . DS . $hashed; } // Return image if ($get == 'localPath') { return str_replace(PATH_APP, '', $image); } elseif ($get == 'fullPath') { return $image; } elseif ($get == 'url') { return Route::url('index.php?option=com_projects&alias=' . $model->get('alias') . '&controller=media&media=' . urlencode(basename($image))); } return basename($image); }
* THE SOFTWARE. * */ // No direct access defined('_HZEXEC_') or die; $data = $this->data; $pub = $data->get('pub'); $details = $data->get('localPath'); $details .= $data->getSize() ? ' | ' . $data->getSize('formatted') : ''; if ($data->get('viewer') != 'freeze') { $details .= !$data->exists() ? ' | ' . Lang::txt('PLG_PROJECTS_PUBLICATIONS_MISSING_FILE') : ''; } // Get settings $suffix = isset($this->config->params->thumbSuffix) && $this->config->params->thumbSuffix ? $this->config->params->thumbSuffix : '-tn'; $format = isset($this->config->params->thumbFormat) && $this->config->params->thumbFormat ? $this->config->params->thumbFormat : 'png'; $thumbName = \Components\Projects\Helpers\Html::createThumbName(basename($data->get('fpath')), $suffix, $format); $filePath = Route::url($pub->link('versionid')) . '/Image:' . urlencode(basename($data->get('fpath'))); $thumbSrc = Route::url($pub->link('versionid')) . '/Image:' . urlencode($thumbName); // Is this image used for publication thumbail? $class = $data->get('pubThumb') == 1 ? ' starred' : ''; $over = $data->get('pubThumb') == 1 ? ' title="' . Lang::txt('PLG_PROJECTS_PUBLICATIONS_IMAGE_DEFAULT') . '"' : ''; ?> <li class="image-container"> <span class="item-options"> <?php if ($data->get('viewer') == 'edit') { ?> <span> <?php if (!$data->get('pubThumb')) { ?>