/** * Remove entity. If entity has been removed, delete related file. * * @access public * @return boolean * @since 1.0.0-alpha * @version 1.0.0-alpha */ public function remove() { $bRemoved = parent::remove(); if ($bRemoved) { // set path to file $sPath = $this->getPath() . DS . $this->getNameWithExt(); // if it's an image, remove all its styles if (in_array($this->getExt(), ['jpg', 'jpeg', 'gif', 'png', 'tiff'])) { ImageStyles::removeStyledImgCache($sPath); } // remove file \FileManager::delete($sPath); } return $bRemoved; }
/** * Get user image styled by "UserLogo" style. * * @access public * @return string * @since 2.1.2-dev * @version 2.1.2-dev */ public function getImageStyled() { $imgStyles = \Plethora\ImageStyles::factory(); $styled = $imgStyles->useStyle('UserLogo', $this->getImagePath()); return \Plethora\Router::getBase() . '/' . $styled; }
/** * Make some operations related to this field before Model Entity will be * completely removed. * * @access public * @param ModelCore $oModel * @param mixed $mValue * @return boolean * @since 1.0.0-alpha * @version 1.0.0-alpha */ public function whenRemovingEntity(ModelCore $oModel, $mValue) { parent::whenRemovingEntity($oModel, $mValue); if (empty($mValue)) { return FALSE; } $aValues = []; if (!is_array($mValue)) { $aValues[] = $mValue; } foreach ($aValues as $oFileBroker) { /* @var $oFileBroker \Plethora\ModelCore\FileBroker */ $oFile = $oFileBroker->getFile(); /* @var $oFile \Model\File */ \Plethora\ImageStyles::removeStyledImgCache($oFile->getPath() . DS . $oFile->getNameWithExt()); } }
/** * Format value. * * @access public * @param ModelCore\FileBroker $oImageBroker * @return string * @since 1.0.0-alpha * @version 1.0.0-alpha */ public function format($oImageBroker) { $sOutput = ''; if ($oImageBroker instanceof ModelCore\FileBroker && $oImageBroker->getFile() instanceof \Model\File) { $oAttributes = Helper\Attributes::factory(); $oField = $this->getField(); /* @var $oField \Plethora\View\ViewField */ $oFile = $oImageBroker->getFile(); /* @var $oFile \Model\File */ // set proper ALT if (!empty($this->sImageAltPattern)) { $oModel = $oField->getEntity()->getModel(); $aFields = $oModel->getMetadata()->getFieldNames(); if ($oModel->hasLocales()) { $aFields = array_merge($aFields, $oModel->getLocalesMetadata()->getFieldNames()); } $sAlt = $this->sImageAltPattern; foreach ($aFields as $sField) { if (strpos($sAlt, ':' . $sField) !== FALSE) { $sAlt = str_replace(':' . $sField, $oModel->{$sField}, $sAlt); } if (strpos($sAlt, ':') === FALSE) { break; } } $oAttributes->addToAttribute('alt', $sAlt); } // get image path $sFieldName = $oField->getName(); $oFormField = $oField->getEntity()->getModel()->getConfig()->getField($sFieldName); /* @var $oFormField \Plethora\Form\Field\ImageModel */ $sImagePath = $oFile->getFullPath(); if (empty($sImagePath) && $oFormField->getDefaultImage() === NULL) { return NULL; } elseif (empty($sImagePath) && $oFormField->getDefaultImage() !== NULL) { $sImagePath = $oFormField->getDefaultImage(); } // stylize image if (!empty($this->sImageStyle)) { $sImagePath = ImageStyles::useStyle($this->sImageStyle, $sImagePath); } $oAttributes->addToAttribute('src', Router::getBase() . '/' . $sImagePath); $sOutput = '<img ' . $oAttributes->renderAttributes() . ' />'; // if this image should be linked to it's original-sized equivalent if ($this->bLinkToOriginalSize) { $sImagePathOriginal = '/' . $oFormField->getUploadPath(TRUE) . '/' . $oFile->getNameWithExt(); $oAttributes = Helper\Attributes::factory()->setAttributes($this->aLinkAttributes); $sOutput = Helper\Html::a($sImagePathOriginal, $sOutput, $oAttributes); } } // return final output return $this->sPrefix . $sOutput . $this->sSuffix; }
if ($oFileToShow instanceof \Model\File) { ?> <?php $sWholeFileURL = Router::getBase() . '/' . $oFileToShow->getFullPath(); ?> <?php if (file_exists($oFileToShow->getFullPath())) { ?> <p> <a href="<?php echo $sWholeFileURL; ?> " title=""> <img src="<?php echo Router::getBase() . '/' . ImageStyles::useStyle('admin_preview', $oFileToShow->getFullPath()); ?> " alt=""/> </a> </p> <?php } else { ?> <div class="file_doest_not_exists alert alert-danger"><?php echo __('File does not exists (path: ":path").', ['path' => $sWholeFileURL]); ?> </div> <?php } } ?>