/** * @return AM_Handler_Temp */ public static function getInstance() { if (is_null(self::$oInstance)) { self::$oInstance = new self(); } return self::$oInstance; }
protected function _prepareSqliteAdapter() { $sDbName = AM_Handler_Temp::getInstance()->getFile(); $this->_oAdapter = Zend_Db::factory('PDO_SQLITE', array('dbname' => $sDbName)); $sSql = <<<SQL CREATE TABLE `element` ( id INTEGER NOT NULL, page_id INTEGER NOT NULL, element_type_name TEXT NOT NULL, weight INTEGER NOT NULL, content_text BLOB, PRIMARY KEY(id) ); CREATE TABLE `element_data` ( id INTEGER NOT NULL, element_id INTEGER NOT NULL, type TEXT NOT NULL, value TEXT NOT NULL, position_id INTEGER, PRIMARY KEY(id) ); CREATE TABLE `game_crossword` ( id INTEGER NOT NULL, title TEXT, grid_width INTEGER, grid_height INTEGER, PRIMARY KEY(id) ); CREATE TABLE `game_crossword_word` ( id INTEGER NOT NULL, game INTEGER NOT NULL, answer TEXT NOT NULL, question TEXT NOT NULL, length INTEGER DEFAULT NULL, direction TEXT NOT NULL, start_x INTEGER NOT NULL, start_y INTEGER NOT NULL, PRIMARY KEY(id) ); SQL; $this->_oAdapter->getConnection()->exec($sSql); $this->_oConnectionMock = $this->createZendDbConnection($this->_oAdapter, $sDbName); return $this; }
protected function _prepareSqliteAdapter() { $sDbName = AM_Handler_Temp::getInstance()->getFile(); $this->_oAdapter = Zend_Db::factory('PDO_SQLITE', array('dbname' => $sDbName)); $sSql = <<<SQL CREATE TABLE `page_horisontal` ( id INTEGER NOT NULL, name TEXT, resource TEXT, PRIMARY KEY(id) ); SQL; $this->_oAdapter->getConnection()->exec($sSql); $this->_oSqliteConnectionMock = $this->createZendDbConnection($this->_oAdapter, $sDbName); return $this; }
/** * Save zip to the file system * @return AM_Handler_Export_Package_Zip * @throws AM_Handler_Export_Package_Exception */ public function savePackage() { //Create temp file for zip $sTempZipFile = AM_Handler_Temp::getInstance()->getFile($this->getPackageName()); $oZip = new ZipArchive(); $rArchiveResource = $oZip->open($sTempZipFile, ZIPARCHIVE::CREATE); if ($rArchiveResource !== true) { throw new AM_Handler_Export_Package_Exception('I/O error. Can\'t create zip file: ' . $sTempZipFile); } //Add files to archive foreach ($this->_aFiles as $sPathReal => $sPathInPakage) { $oZip->addFile($sPathReal, $sPathInPakage); } $oZip->close(); $this->_sPackagePath = $sTempZipFile; return $this; }
protected function _prepareSqliteAdapter() { $sDbName = AM_Handler_Temp::getInstance()->getFile(); $this->_oAdapter = Zend_Db::factory('PDO_SQLITE', array('dbname' => $sDbName)); $sSql = <<<SQL CREATE TABLE `page_imposition` ( id INTEGER NOT NULL, page_id INTEGER NOT NULL, is_linked_to INTEGER NOT NULL, position_type TEXT NOT NULL, PRIMARY KEY(id) ); SQL; $this->_oAdapter->getConnection()->exec($sSql); $this->_oConnectionMock = $this->createZendDbConnection($this->_oAdapter, $sDbName); return $this; }
protected function _prepareSqliteAdapter() { $sDbName = AM_Handler_Temp::getInstance()->getFile(); $this->_oAdapter = Zend_Db::factory('PDO_SQLITE', array('dbname' => $sDbName)); $sSql = <<<SQL CREATE TABLE `page` ( id INTEGER NOT NULL, title TEXT NOT NULL, horisontal_page_id INTEGER NOT NULL DEFAULT "-1", template INTEGER NOT NULL DEFAULT "-1" , machine_name TEXT, color TEXT, PRIMARY KEY(id) ) SQL; $this->_oAdapter->getConnection()->exec($sSql); $this->_oSqliteConnectionMock = $this->createZendDbConnection($this->_oAdapter, $sDbName); return $this; }
protected function _prepareSqliteAdapter() { $sDbName = AM_Handler_Temp::getInstance()->getFile(); $this->_oAdapter = Zend_Db::factory('PDO_SQLITE', array('dbname' => $sDbName)); $sSql = <<<SQL CREATE TABLE `menu` ( id INTEGER NOT NULL, title TEXT, firstpage_id INTEGER, description TEXT, thumb_stripe TEXT, thumb_summary TEXT, color TEXT, PRIMARY KEY(id) ); SQL; $this->_oAdapter->getConnection()->exec($sSql); $this->_oSqliteConnectionMock = $this->createZendDbConnection($this->_oAdapter, $sDbName); return $this; }
protected function _prepareSqliteAdapter() { $sDbName = AM_Handler_Temp::getInstance()->getFile(); $this->_oAdapter = Zend_Db::factory('PDO_SQLITE', array('dbname' => $sDbName)); $sSql = <<<SQL CREATE TABLE `element` ( id INTEGER NOT NULL, page_id INTEGER NOT NULL, element_type_name TEXT NOT NULL, weight INTEGER NOT NULL, content_text BLOB, PRIMARY KEY(id) ); CREATE TABLE `element_data` ( id INTEGER NOT NULL, element_id INTEGER NOT NULL, type TEXT NOT NULL, value TEXT NOT NULL, position_id INTEGER, PRIMARY KEY(id) ); CREATE TABLE `element_data_position` ( id INTEGER, start_x INTEGER, start_y INTEGER, end_x INTEGER, end_y INTEGER, PRIMARY KEY(id) ); SQL; $this->_oAdapter->getConnection()->exec($sSql); $this->_oConnectionMock = $this->createZendDbConnection($this->_oAdapter, $sDbName); return $this; }
/** * Returns archive path * @return null|string */ public function getArchive() { $sZipFileName = sprintf('static-pdf-%s-%s.zip', $this->getIssue()->id, strtotime($this->getIssue()->updated)); $sZipFileDir = $this->getConfig()->temp->base . DIRECTORY_SEPARATOR . 'static-pdf'; $sZipFile = $sZipFileDir . DIRECTORY_SEPARATOR . $sZipFileName; if (!AM_Tools_Standard::getInstance()->is_file($sZipFile)) { $sTmpZipFile = AM_Handler_Temp::getInstance()->getFile($sZipFileName); $oZip = new ZipArchive(); $oZip->open($sTmpZipFile, ZIPARCHIVE::CREATE); $aFiles = $this->getFiles(); if (empty($aFiles)) { return null; } foreach ($aFiles as $sFile) { $oZip->addFile($sFile, pathinfo($sFile, PATHINFO_BASENAME)); } $oZip->close(); if (!AM_Tools_Standard::getInstance()->is_dir($sZipFileDir)) { AM_Tools_Standard::getInstance()->mkdir($sZipFileDir, 0777); } AM_Tools_Standard::getInstance()->copy($sTmpZipFile, $sZipFile); } return $sZipFile; }
/** * Resizes all horizontal pages */ protected function _resizeHorizontalPdfs() { $oQuery = AM_Model_Db_Table_Abstract::factory('page_horisontal')->select()->setIntegrityCheck(false)->from('page_horisontal')->joinInner('issue', 'issue.id = page_horisontal.id_issue')->joinInner('application', 'application.id = issue.application')->joinInner('client', 'client.id = application.client')->where('issue.deleted = ?', 'no')->where('application.deleted = ?', 'no')->where('client.deleted = ?', 'no')->where('resource IS NOT NULL')->columns(array('id' => 'page_horisontal.id'))->order('page_horisontal.id_issue ASC'); if ($this->_iFromIssueId > 0) { $oQuery->where('page_horisontal.id_issue > ?', $this->_iFromIssueId); } if ($this->_iIssueId > 0) { $oQuery->where('issue.id = ?', $this->_iIssueId); } if ($this->_iApplicationId > 0) { $oQuery->where('application.id = ?', $this->_iApplicationId); } $oPagesHorizaontal = AM_Model_Db_Table_Abstract::factory('page_horisontal')->fetchAll($oQuery); $iCounter = 0; foreach ($oPagesHorizaontal as $oPageHorizontal) { try { $this->_resizeImage($oPageHorizontal->resource, $oPageHorizontal, AM_Model_Db_PageHorisontal::RESOURCE_TYPE, $oPageHorizontal->weight); } catch (Exception $oException) { $this->_echo(sprintf('%s', $oException->getMessage()), 'error'); } if ($iCounter++ > 100) { $iCounter = 0; AM_Handler_Temp::getInstance()->end(); } } }
/** * Convert pdf to png files * @return type */ public function getAllPagesThumbnails() { $sTempDir = AM_Handler_Temp::getInstance()->getDir(); $sPdfDrawBin = $this->_getPadcmsdrawPath(); $sCmd = sprintf('nice -n 15 %s -a -r 200 -o %s/splitted-%%d.png %s > /dev/null 2>&1', $sPdfDrawBin, $sTempDir, $this->_sSourceFile); AM_Tools_Standard::getInstance()->passthru($sCmd); $aFilesPng = AM_Tools_Finder::type('file')->name('splitted-*.png')->sort_by_name()->in($sTempDir); return $aFilesPng; }
/** * http://www.imagemagick.org/Usage/crop/#crop_equal * @param string $sImageOriginal - the original image with high resolution * @param string $sImageThumbnail - the thumbnail given from original image * @param string $sArchivePath - path of the archive with cropped image * @param integer $iBlockSize - the tile size (size of the square to crop) * @param string $sImageForZoomPath Path for zoom thumbnail * @return void * @throws AM_Exception */ public static function cropImage($sImageOriginal, $sImageThumbnail, $sArchivePath, $iBlockSize = self::TILE_SIZE, $sImageForZoomPath = null) { $sTempDir = AM_Handler_Temp::getInstance()->getDir(); $aFiles = self::_cropImage($sImageThumbnail, $sTempDir, $iBlockSize); $oZip = new ZipArchive(); $rArchiveResource = $oZip->open($sArchivePath, ZIPARCHIVE::CREATE); if ($rArchiveResource !== true) { throw new AM_Exception('I/O error. Can\'t create zip file: ' . $sZipPath); } if (!is_null($sImageForZoomPath)) { $aFilesZoom = self::_cropImage($sImageForZoomPath, $sTempDir, $iBlockSize, '_2x'); $aFiles = array_merge($aFiles, $aFilesZoom); } foreach ($aFiles as $sFile) { //Optimization if ('png' == pathinfo($sFile, PATHINFO_EXTENSION)) { self::optimizePng($sFile); } $oZip->addFile($sFile, pathinfo($sFile, PATHINFO_BASENAME)); } $oZip->close(); }
/** * Returns path of the DB file * * @return string File path */ protected function _getDbFile() { if (is_null($this->_sDbFile)) { $this->_sDbFile = AM_Handler_Temp::getInstance()->getFile('revision.db'); } return $this->_sDbFile; }
/** * Resizes elements */ protected function _resizeElements() { $oQuery = AM_Model_Db_Table_Abstract::factory('element_data')->select()->setIntegrityCheck(false)->from('element_data')->joinInner('element', 'element.id = element_data.id_element')->joinInner('page', 'page.id = element.page')->joinInner('revision', 'revision.id = page.revision')->joinInner('issue', 'issue.id = revision.issue')->joinInner('application', 'application.id = issue.application')->joinInner('client', 'client.id = application.client')->where(sprintf('element_data.key_name IN ("%s", "%s", "%s")', AM_Model_Db_Element_Data_Resource::DATA_KEY_RESOURCE, AM_Model_Db_Element_Data_MiniArticle::DATA_KEY_THUMBNAIL, AM_Model_Db_Element_Data_MiniArticle::DATA_KEY_THUMBNAIL_SELECTED))->where('page.deleted = ?', 'no')->where('revision.deleted = ?', 'no')->where('issue.deleted = ?', 'no')->where('application.deleted = ?', 'no')->where('client.deleted = ?', 'no')->columns(array('id' => 'element_data.id_element'))->order('element_data.id_element ASC'); /* @var $oQuery Zend_Db_Table_Select */ if ($this->_iFromId > 0) { $oQuery->where('element_data.id_element > ?', $this->_iFromId); } if ($this->_iElementId > 0) { $oQuery->where('element_data.id_element = ?', $this->_iElementId); } if ($this->_iPageId > 0) { $oQuery->where('page.id = ?', $this->_iPageId); } if ($this->_iRevisionId > 0) { $oQuery->where('revision.id = ?', $this->_iRevisionId); } if ($this->_iIssueId > 0) { $oQuery->where('issue.id = ?', $this->_iIssueId); } if ($this->_iApplicationId > 0) { $oQuery->where('application.id = ?', $this->_iApplicationId); } $oElementDatas = AM_Model_Db_Table_Abstract::factory('element_data')->fetchAll($oQuery); $iCounter = 0; foreach ($oElementDatas as $oElementData) { try { $oData = $oElementData->getData(); $bZoom = (bool) $oElementData->getData()->getDataValue(AM_Model_Db_Element_Data_Gallery::DATA_KEY_ENABLE_ZOOM, false); if (!is_null($oData) && method_exists($oData, 'getThumbnailPresetName')) { $this->_resizeImage($oElementData->value, $oElementData->getElement(), AM_Model_Db_Element_Data_Resource::TYPE, $oElementData->key_name, $oElementData->getData()->getThumbnailPresetName(), $bZoom); $sFileExtension = strtolower(pathinfo($oElementData->value, PATHINFO_EXTENSION)); if ('pdf' == $sFileExtension && AM_Model_Db_Element_Data_Resource::DATA_KEY_RESOURCE == $oElementData->key_name) { $oData->delete(AM_Model_Db_Element_Data_Resource::PDF_INFO, false); $sFilePath = AM_Tools::getContentPath(AM_Model_Db_Element_Data_Resource::TYPE, $oElementData->getElement()->id) . DIRECTORY_SEPARATOR . AM_Model_Db_Element_Data_Resource::DATA_KEY_RESOURCE . '.' . $sFileExtension; $oResource = AM_Resource_Factory::create($sFilePath); $sPdfInfo = $oResource->getPdfInfo(); $oData->addKeyValue(AM_Model_Db_Element_Data_Resource::PDF_INFO, $sPdfInfo); } } } catch (Exception $oException) { $this->_echo(sprintf('%s', $oException->getMessage()), 'error'); } if ($iCounter++ > 100) { $iCounter = 0; AM_Handler_Temp::getInstance()->end(); } } }
/** * Create thumbnails for each source * @return AM_Handler_Thumbnail */ public function createThumbnails() { foreach ($this->_aSources as $oSource) { /* @var $oSource AM_Resource_Abstract */ $sInputFile = $oSource->getFileForThumbnail($this->getImageType()); foreach ($this->_aPresets as $sPreset) { if (!isset($this->getConfig()->{$sPreset})) { continue; } $oPresetConfig = $this->getConfig()->{$sPreset}; //Get path without 'sourceFolder' $sPathPrefix = substr($oSource->getSourceFileDir(), strlen($this->getConfig()->common->sourceFolder)); $sPathPrefix = $sPreset . DIRECTORY_SEPARATOR . trim($sPathPrefix, DIRECTORY_SEPARATOR); $this->getResourceStorage()->setPathPrefix($sPathPrefix); $sTempPath = AM_Handler_Temp::getInstance()->getDir(); if ($oSource->isImage()) { $sThumbnail = $sTempPath . DIRECTORY_SEPARATOR . $oSource->getSourceFileName() . '.' . $this->getImageType(); $sThumbnailZoom = null; if ('none' != $sPreset && $this->getZooming()) { $sThumbnailZoom = $sTempPath . DIRECTORY_SEPARATOR . $oSource->getSourceFileName() . '_2x' . '.' . $this->getImageType(); } $this->getResourceProcessor()->resizeImage($sInputFile, $sThumbnail, $oPresetConfig->width, $oPresetConfig->height, $oPresetConfig->method, $sThumbnailZoom); $this->getResourceStorage()->addResource($sThumbnail); if ('none' != $sPreset) { $iBlockSize = AM_Tools_Image::TILE_SIZE; if ($oPresetConfig->width == 1536 || $oPresetConfig->width == 2048) { $iBlockSize = AM_Tools_Image::TILE_SIZE_RETINA; } $sArchivePath = $sTempPath . DIRECTORY_SEPARATOR . $oSource->getSourceFileName() . '.zip'; $this->getResourceProcessor()->cropImage($sInputFile, $sThumbnail, $sArchivePath, $iBlockSize, $sThumbnailZoom); $this->getResourceStorage()->addResource($sArchivePath); } } else { //We have to copy not image resource only to the 'none' preset folder if ('none' == $sPreset) { $this->getResourceStorage()->addResource($sInputFile); } } $this->getResourceStorage()->save(); } } return $this; }
/** * Resizes all horizontal pages */ protected function _resizeHelpPages() { $oQuery = AM_Model_Db_Table_Abstract::factory('issue_help_page')->select()->setIntegrityCheck(false)->from('issue_help_page')->joinInner('issue', 'issue.id = issue_help_page.id_issue')->joinInner('application', 'application.id = issue.application')->joinInner('client', 'client.id = application.client')->where('issue.deleted = ?', 'no')->where('application.deleted = ?', 'no')->where('client.deleted = ?', 'no')->where('name IS NOT NULL')->columns(array('id' => 'issue.id', 'type' => 'issue_help_page.type'))->order('issue_help_page.id_issue ASC'); if ($this->_iFromIssueId > 0) { $oQuery->where('issue_help_page.id_issue > ?', $this->_iFromIssueId); } if ($this->_iIssueId > 0) { $oQuery->where('issue.id = ?', $this->_iIssueId); } if ($this->_iApplicationId > 0) { $oQuery->where('application.id = ?', $this->_iApplicationId); } $oHelpPages = AM_Model_Db_Table_Abstract::factory('issue_help_page')->fetchAll($oQuery); $iCounter = 0; /* @var $oHelpPage AM_Model_Db_IssueHelpPage */ foreach ($oHelpPages as $oHelpPage) { try { $this->_resizeImage($oHelpPage->name, $oHelpPage, $oHelpPage->getThumbnailPresetType(), $oHelpPage->type); } catch (Exception $oException) { $this->_echo(sprintf('%s', $oException->getMessage()), 'error'); } if ($iCounter++ > 100) { $iCounter = 0; AM_Handler_Temp::getInstance()->end(); } } }
/** * Resizes all TOC terms */ protected function _resizeTOC() { $oQuery = AM_Model_Db_Table_Abstract::factory('term')->select()->setIntegrityCheck(false)->from('term')->joinInner('revision', 'revision.id = term.revision')->joinInner('issue', 'issue.id = revision.issue')->joinInner('application', 'application.id = issue.application')->joinInner('client', 'client.id = application.client')->where('term.thumb_stripe IS NOT NULL OR term.thumb_summary IS NOT NULL')->where('term.deleted = ?', 'no')->where('revision.deleted = ?', 'no')->where('issue.deleted = ?', 'no')->where('application.deleted = ?', 'no')->where('client.deleted = ?', 'no')->columns(array('id' => 'term.id'))->order('term.id ASC'); /* @var $oQuery Zend_Db_Table_Select */ if ($this->_iFromId > 0) { $oQuery->where('term.id > ?', $this->_iFromId); } if ($this->_iRevisionId > 0) { $oQuery->where('revision.id = ?', $this->_iRevisionId); } if ($this->_iIssueId > 0) { $oQuery->where('issue.id = ?', $this->_iIssueId); } if ($this->_iApplicationId > 0) { $oQuery->where('application.id = ?', $this->_iApplicationId); } $oTerms = AM_Model_Db_Table_Abstract::factory('term')->fetchAll($oQuery); $iCounter = 0; foreach ($oTerms as $oTerm) { try { if (!empty($oTerm->thumb_stripe)) { $this->_resizeImage($oTerm->thumb_stripe, $oTerm, AM_Model_Db_Term_Data_Resource::TYPE, AM_Model_Db_Term_Data_Resource::RESOURCE_KEY_STRIPE); } if (!empty($oTerm->thumb_summary)) { $this->_resizeImage($oTerm->thumb_summary, $oTerm, AM_Model_Db_Term_Data_Resource::TYPE, AM_Model_Db_Term_Data_Resource::RESOURCE_KEY_SUMMARY); } } catch (Exception $oException) { $this->_echo(sprintf('%s', $oException->getMessage()), 'error'); } if ($iCounter++ > 100) { $iCounter = 0; AM_Handler_Temp::getInstance()->end(); } } }