/** * Post upload trigger * @param type $sDestination * @return AM_Model_Db_Term_Data_Resource */ protected function _postUpload($sDestination) { if (AM_Tools::isAllowedImageExtension($sDestination)) { $oThumbnailerHandler = AM_Handler_Locator::getInstance()->getHandler('thumbnail'); /* @var $oThumbnailerHandler AM_Handler_Thumbnail */ $oThumbnailerHandler->clearSources()->setImageType($this->getImageType())->addSourceFile($sDestination)->loadAllPresets(self::TYPE)->createThumbnails(); } return $this; }
/** * Editor toc-upload * Upload stripe ans summary for TOC's term * @return JSON */ public function tocUploadAction() { $aMessage = array('status' => 0); try { $iRevisionId = intval($this->_getParam('rid')); $iTocItemId = intval($this->_getParam('id')); $sKey = trim($this->_getParam('key')); if (!AM_Model_Db_Table_Abstract::factory('term')->checkAccess($iTocItemId, $this->_aUserInfo) || empty($sKey)) { throw new AM_Controller_Exception_BadRequest('Error. Invalid params were given'); } $oRevision = AM_Model_Db_Table_Abstract::factory('revision')->findOneBy('id', $iRevisionId); /* @var $oRevision AM_Model_Db_Revision */ if (is_null($oRevision)) { throw new AM_Controller_Exception_Forbidden('Access denied'); } $oTerm = AM_Model_Db_Table_Abstract::factory('term')->findOneBy('id', $iTocItemId); /* @var $oTerm AM_Model_Db_Term */ if (is_null($oTerm)) { throw new AM_Controller_Exception_Forbidden('Access denied'); } $oTerm->getResources()->upload($sKey); $sField = 'thumb_' . $sKey; $sResourceFile = $oTerm->{$sField}; $aFileInfo = pathinfo($sResourceFile); $sFileName = $aFileInfo['filename']; $sFileExtension = $aFileInfo['extension']; $aResourceFileViewInfo = array(); $aResourceFileViewInfo['name'] = $sFileName . '.' . $sFileExtension; $aResourceFileViewInfo['nameShort'] = $this->getHelper('String')->cut($sFileName) . '.' . $sFileExtension; $sFileName = $sKey . '.' . $oTerm->getResources()->getImageType(); if (AM_Tools::isAllowedImageExtension($sResourceFile)) { $uniq = '?' . strtotime($oTerm->updated); $aResourceFileViewInfo['smallUri'] = AM_Tools::getImageUrl('toc-' . $sKey, 'toc', $oTerm->id, $sFileName) . $uniq; $aResourceFileViewInfo['bigUri'] = AM_Tools::getImageUrl('none', 'toc', $oTerm->id, $sFileName) . $uniq; } else { $aResourceFileViewInfo['smallUri'] = AM_Tools::getIconForNonImageFile($sFileName); } $oRevision->exportRevision(); $aMessage['file'] = $aResourceFileViewInfo; $aMessage['status'] = 1; } catch (Exception $oException) { $aMessage['message'] = $this->__('Error. Can\'t upload file') . PHP_EOL . $oException->getMessage(); } return $this->sendJsonAsPlainText($aMessage); }
/** * Post upload trigger * @param string $sDestination * @return AM_Model_Db_IssueHelpPage_Data_Resource */ protected function _postUpload($sDestination) { if (AM_Tools::isAllowedImageExtension($sDestination)) { $oThumbnailerHandler = AM_Handler_Locator::getInstance()->getHandler('thumbnail'); /* @var $oThumbnailerHandler AM_Handler_Thumbnail */ $oThumbnailerHandler->clearSources()->addSourceFile($sDestination)->setImageType($this->getImageType())->loadAllPresets($this->_getIssueHelpPage()->getThumbnailPresetType(), true)->createThumbnails(); $oTask = new AM_Task_Worker_Thumbnail_Create(); $oTask->setOptions(array('resource' => $sDestination, 'image_type' => $this->getImageType(), 'zooming' => false, 'resource_type' => $this->_getIssueHelpPage()->getThumbnailPresetType()))->create(); } return $this; }
/** * Prepares vew data for resource * @param AM_Model_Db_Element $oElement * @param string $sResourceKeyName * @return array */ protected function _getResourceViewData(AM_Model_Db_Element $oElement, $sResourceKeyName = AM_Model_Db_Element_Data_Resource::DATA_KEY_RESOURCE) { $sFile = $oElement->getResources()->getDataValue($sResourceKeyName); $aElementView = array(); if ($sFile) { $aFileInfo = pathinfo($sFile); $sFileName = $aFileInfo['filename']; $sFileExtension = $oElement->getResources()->getImageType(); $aElementView['fileName'] = $sFileName . '.' . $aFileInfo['extension']; $aElementView['fileNameShort'] = $this->getHelper('String')->cut($sFileName) . '.' . $aFileInfo['extension']; $sResourceFileName = $sResourceKeyName . '.' . $sFileExtension; if (AM_Tools::isAllowedImageExtension($sFile)) { $sUniq = '?' . strtotime($oElement->updated); $aElementView['smallUri'] = AM_Tools::getImageUrl($this->_getThumbnailPresetName(), 'element', $oElement->id, $sResourceFileName) . $sUniq; $aElementView['bigUri'] = AM_Tools::getImageUrl('none', 'element', $oElement->id, $sResourceFileName) . $sUniq; } else { $aElementView['smallUri'] = AM_Tools::getIconForNonImageFile($sResourceFileName); } $aElementView['originUri'] = '/content/element/' . AM_Tools_String::generatePathFromId(intval($oElement->id), '/') . "/{$sResourceKeyName}.{$aFileInfo['extension']}"; } return $aElementView; }
/** * Upload resource */ public function uploadAction() { try { $aMessage = array('status' => 0); if (!$this->_iPageId || !$this->_iFieldId) { throw new AM_Exception('Invalid params'); } $oField = AM_Model_Db_Table_Abstract::factory('field')->findOneBy('id', $this->_iFieldId); /* @var $oField AM_Model_Db_Field */ if (is_null($oField)) { throw new AM_Exception(sprintf('Field with id "%d" not found.', $this->_iFieldId)); } $oPage = AM_Model_Db_Table_Abstract::factory('page')->findOneBy('id', $this->_iPageId); /* @var $oPage AM_Model_Db_Page */ if (is_null($oPage)) { throw new AM_Exception(sprintf('Page with id "%d" not found.', $this->_iPageId)); } $oElement = $oPage->getElementForField($oField); /* @var $oElement AM_Model_Db_Element */ $oElement->uploadResource(); $this->_postUpload($oElement); $sResourceFile = $oElement->getResources()->getDataValue(AM_Model_Db_Element_Data_Resource::DATA_KEY_RESOURCE); $sResourceImageType = $oElement->getResources()->getDataValue(AM_Model_Db_Element_Data_Resource::DATA_KEY_IMAGE_TYPE); $aFileInfo = pathinfo($sResourceFile); $sFileName = $aFileInfo['filename']; $sFileExtension = empty($sResourceImageType) ? $aFileInfo['extension'] : $sResourceImageType; $aResourceFileViewInfo = array(); $aResourceFileViewInfo['fileName'] = $sFileName . '.' . $aFileInfo['extension']; $aResourceFileViewInfo['fileNameShort'] = $this->getHelper('String')->cut($sFileName) . '.' . $aFileInfo['extension']; $sResourceFileName = AM_Model_Db_Element_Data_Resource::DATA_KEY_RESOURCE . '.' . $sFileExtension; if (AM_Tools::isAllowedImageExtension($sResourceFile)) { $sOrientation = $oPage->getOrientation(); if (AM_Model_Db_Template::TPL_SCROLLING_PAGE_HORIZONTAL == $oPage->template) { $sOrientation = AM_Model_Db_Issue::ORIENTATION_HORIZONTAL; } $sUniq = '?' . strtotime($oElement->updated); $aResourceFileViewInfo['smallUri'] = AM_Tools::getImageUrl(AM_Handler_Thumbnail_Interface::PRESET_FIELD . '-' . $sOrientation, 'element', $oElement->id, $sResourceFileName) . $sUniq; $aResourceFileViewInfo['bigUri'] = AM_Tools::getImageUrl('none', 'element', $oElement->id, $sResourceFileName) . $sUniq; } else { $aResourceFileViewInfo['smallUri'] = AM_Tools::getIconForNonImageFile($sResourceFileName); } $oPage->setUpdated(); $aMessage['fieldTypeTitle'] = $oField->getFieldType()->title; $aMessage['background'] = $oPage->getPageBackgroundUri(); $aMessage['element'] = $oElement->id; $aMessage['file'] = $aResourceFileViewInfo; $aMessage['status'] = 1; } catch (Exception $e) { $aMessage["message"] = $this->__('Error. Can\'t upload file') . PHP_EOL . $e->getMessage(); } return $this->sendJsonAsPlainText($aMessage); }
/** * Compile static pdf * @return AM_Handler_HorisontalPdf * @throws AM_Handler_HorisontalPdf_Exception */ public function compile() { AM_Model_Db_Table_Abstract::factory('page')->resetHorizontalPdf($this->getIssue()); AM_Model_Db_Table_Abstract::factory('page_horisontal')->deleteBy(array('id_issue' => $this->getIssue()->id)); AM_Tools::clearContent(AM_Model_Db_StaticPdf_Data_Abstract::TYPE_CACHE, $this->getIssue()->id); AM_Tools::clearResizerCache(AM_Model_Db_StaticPdf_Data_Abstract::TYPE_CACHE, AM_Model_Db_StaticPdf_Data_Abstract::TYPE_CACHE, $this->getIssue()->id); if (!count($this->getIssue()->getHorizontalPdfs())) { return $this; } switch ($this->getIssue()->static_pdf_mode) { case AM_Model_Db_Issue::HORISONTAL_MODE_PAGE: //Get first pages of all pdfs and glue them $aFiles = (array) $this->_compilePageVersion(); break; case AM_Model_Db_Issue::HORISONTAL_MODE_ISSUE: //Get pdf's first pages and glue them $aFiles = (array) $this->_compileIssueVersion(); break; case AM_Model_Db_Issue::HORISONTAL_MODE_2PAGES: //Get all pdf's pages and glue them $aFiles = (array) $this->_compile2PagesVersion(); break; } $sCachePath = $this->_getFilesPath(); if (!empty($aFiles)) { if (!AM_Tools_Standard::getInstance()->is_dir($sCachePath)) { if (!AM_Tools_Standard::getInstance()->mkdir($sCachePath, 0777, true)) { throw new AM_Handler_HorisontalPdf_Exception('I/O error while create cache dir'); } } $oThumbnailer = AM_Handler_Locator::getInstance()->getHandler('thumbnail'); /* @var $oThumbnailer AM_Handler_Thumbnail */ $oThumbnailer->clearSources()->loadAllPresets(AM_Model_Db_StaticPdf_Data_Abstract::TYPE_CACHE)->setImageType(AM_Handler_Thumbnail::IMAGE_TYPE_JPEG); foreach ($aFiles as $sFile) { $sFilename = pathinfo($sFile, PATHINFO_BASENAME); $sNewFilePath = $sCachePath . DIRECTORY_SEPARATOR . $sFilename; if (!AM_Tools_Standard::getInstance()->rename($sFile, $sNewFilePath)) { throw new AM_Handler_HorisontalPdf_Exception('I/O error while copy file'); } AM_Tools_Standard::getInstance()->chmod($sNewFilePath, 0666); if (AM_Tools::isAllowedImageExtension($sNewFilePath)) { $oThumbnailer->addSourceFile($sNewFilePath); } $oPageHorisontal = new AM_Model_Db_PageHorisontal(); $oPageHorisontal->id_issue = $this->getIssue()->id; $oPageHorisontal->resource = $sFilename; $oPageHorisontal->weight = pathinfo($sFile, PATHINFO_FILENAME); $oPageHorisontal->save(); } $oThumbnailer->createThumbnails(); } return $this; }