BxDolTranscoder.php 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692
  1. <?php defined('BX_DOL') or die('hack attempt');
  2. /**
  3. * Copyright (c) BoonEx Pty Limited - http://www.boonex.com/
  4. * CC-BY License - http://creativecommons.org/licenses/by/3.0/
  5. *
  6. * @defgroup DolphinCore Dolphin Core
  7. * @{
  8. */
  9. bx_import('BxDolStorage');
  10. bx_import('BxDolTranscoder');
  11. bx_import('BxDolTranscoderQuery');
  12. define('BX_DOL_QUEUE_PENDING', 'pending'); ///< file is pending processing
  13. define('BX_DOL_QUEUE_PROCESSING', 'processing'); ///< file is in process
  14. define('BX_DOL_QUEUE_COMPLETE', 'complete'); ///< file is processed
  15. define('BX_DOL_QUEUE_FAILED', 'failed'); ///< file processing failed
  16. /**
  17. * Base class for video and image transcoders
  18. */
  19. class BxDolTranscoder extends BxDol implements iBxDolFactoryObject
  20. {
  21. protected $_sLog = ''; ///< file conversion log
  22. protected $_aObject; ///< object properties
  23. protected $_oStorage; ///< storage object, transcoded files are stored here
  24. protected $_oDb; ///< database queries object
  25. protected $_sRetinaSuffix = '@2x'; ///< handler suffix for retina image file
  26. protected $_sQueueTable = ''; ///< table with queued files for transcoding
  27. protected $_sQueueStorage = ''; ///< storage object to storage temporary files
  28. /**
  29. * constructor
  30. */
  31. protected function __construct($aObject, $oStorage)
  32. {
  33. parent::__construct();
  34. $this->_aObject = $aObject;
  35. $this->_oStorage = $oStorage;
  36. $this->_oDb = new BxDolTranscoderImageQuery($aObject, false);
  37. $this->_sQueueTable = $this->_oDb->getQueueTable();
  38. }
  39. /**
  40. * Get transcode object instance.
  41. * @param $sObject - name of transcode object.
  42. * @return false on error or instance of transcoder class.
  43. */
  44. public static function getObjectInstance($sObject)
  45. {
  46. if (isset($GLOBALS['bxDolClasses'][__CLASS__ . '!' . $sObject]))
  47. return $GLOBALS['bxDolClasses'][__CLASS__ . '!'.$sObject];
  48. // get transcode object
  49. $aObject = BxDolTranscoderQuery::getTranscoderObject($sObject);
  50. if (!$aObject || !is_array($aObject))
  51. return false;
  52. if ($aObject['source_params'])
  53. $aObject['source_params'] = unserialize($aObject['source_params']);
  54. $aObject['filters'] = false; // filters are initialized on demand
  55. // create storage object to store transcoded data
  56. $oStorage = BxDolStorage::getObjectInstance($aObject['storage_object']);
  57. if (!$oStorage)
  58. return false;
  59. // create instance
  60. $sClass = $aObject['override_class_name'] ? $aObject['override_class_name'] : 'BxDolTranscoderImage';
  61. if (!empty($aObject['override_class_file']))
  62. require_once(BX_DIRECTORY_PATH_ROOT . $aObject['override_class_file']);
  63. else
  64. bx_import($sClass);
  65. $o = new $sClass ($aObject, $oStorage);
  66. return ($GLOBALS['bxDolClasses'][__CLASS__ . '!' . $sObject] = $o);
  67. }
  68. /**
  69. * Delete outdated transcoed data from all transcoeeed objects, by last access time.
  70. * It called on cron, usually every day.
  71. * @return total number of pruned/deleted files
  72. */
  73. static public function pruning ()
  74. {
  75. $iCount = 0;
  76. $aObjects = self::getTranscoderObjects();
  77. foreach ($aObjects as $aObject) {
  78. if (!$aObject['atime_tracking'] || !$aObject['atime_pruning'])
  79. continue;
  80. $oTranscoder = self::getObjectInstance($aObject['object']);
  81. if (!$oTranscoder)
  82. continue;
  83. $iCount += $oTranscoder->prune();
  84. }
  85. return $iCount;
  86. }
  87. /**
  88. * Get transcoder objects array
  89. * @return array
  90. */
  91. static protected function getTranscoderObjects ()
  92. {
  93. return BxDolTranscoderQuery::getTranscoderObjects ();
  94. }
  95. /**
  96. * process files queued for transcoding
  97. */
  98. static public function processQueue ($bQueuePruning = true)
  99. {
  100. if ($bQueuePruning)
  101. BxDolTranscoderQuery::queuePruning ();
  102. $a = BxDolTranscoderQuery::getNextInQueue (gethostname());
  103. foreach ($a as $r) {
  104. $o = self::getObjectInstance($r['transcoder_object']);
  105. $aQueue = $o->getDb()->getFromQueue($r['file_id_source']);
  106. if ($aQueue['status'] != 'pending')
  107. continue;
  108. $o->transcode($aQueue['file_id_source'], $aQueue['profile_id']);
  109. }
  110. }
  111. /**
  112. * Register handlers array
  113. * It can be called upon module enable event.
  114. * @param $mixed array of transcoders objects, or just one object
  115. */
  116. static public function registerHandlersArray ($mixed)
  117. {
  118. self::_callFuncForObjectsArray ($mixed, 'registerHandlers');
  119. }
  120. /**
  121. * Unregister handlers array
  122. * It can be called upon module disbale event.
  123. * @param $mixed array of transcoders objects, or just one object
  124. */
  125. static public function unregisterHandlersArray ($mixed)
  126. {
  127. self::_callFuncForObjectsArray ($mixed, 'unregisterHandlers');
  128. }
  129. /**
  130. * Cleanup (queue for deletion all resized files)
  131. * It can be called upon module disbale event.
  132. * @param $mixed array of transcoders objects, or just one object
  133. */
  134. static public function cleanupObjectsArray ($mixed)
  135. {
  136. self::_callFuncForObjectsArray ($mixed, 'cleanup');
  137. }
  138. /**
  139. * Called automatically, upon local(transcoded) file deletetion.
  140. */
  141. static public function onAlertResponseFileDeleteLocal ($oAlert, $sObject)
  142. {
  143. $oTranscoder = self::getObjectInstance($sObject);
  144. if (!$oTranscoder)
  145. return;
  146. if ($oAlert->sAction != 'file_deleted')
  147. return;
  148. $oTranscoder->onDeleteFileLocal($oAlert->iObject);
  149. }
  150. /**
  151. * Called automatically, upon original file deletetion.
  152. */
  153. static public function onAlertResponseFileDeleteOrig ($oAlert, $sObject)
  154. {
  155. $oTranscoder = self::getObjectInstance($sObject);
  156. if (!$oTranscoder)
  157. return;
  158. if ($oAlert->sAction != 'file_deleted')
  159. return;
  160. $oTranscoder->onDeleteFileOrig($oAlert->iObject);
  161. }
  162. /**
  163. * Called automatically, upon local(transcoded) file deletetion.
  164. */
  165. public function onDeleteFileLocal($iFileId)
  166. {
  167. return $this->_oDb->deleteFileTraces($iFileId);
  168. }
  169. /**
  170. * Called automatically, upon original file deletetion.
  171. */
  172. public function onDeleteFileOrig($mixedHandler)
  173. {
  174. // delete main file
  175. $iFileId = $this->_oDb->getFileIdByHandler($mixedHandler);
  176. if (!$iFileId)
  177. return false;
  178. if (!$this->_oStorage->deleteFile($iFileId))
  179. return false;
  180. // delete retina file
  181. $iFileId = $this->_oDb->getFileIdByHandler($mixedHandler . $this->_sRetinaSuffix);
  182. if ($iFileId)
  183. $this->_oStorage->deleteFile($iFileId);
  184. return true;
  185. }
  186. /**
  187. * Register necessary alert handlers for automatic deletetion of transcoded data if source file is deleted.
  188. * Make sure that you call it once, before first usage, for example upon module installation.
  189. */
  190. public function registerHandlers ()
  191. {
  192. if (!$this->_oDb->registerHandlers ())
  193. return false;
  194. return $this->clearCacheDB();
  195. }
  196. /**
  197. * Unregister alert handlers for automatic deletetion of transcoded data if source file is deleted.
  198. * Make sure that you call it once, for example upon module uninstallation.
  199. */
  200. public function unregisterHandlers ()
  201. {
  202. if (!$this->_oDb->unregisterHandlers ())
  203. return false;
  204. return $this->clearCacheDB();
  205. }
  206. /**
  207. * Delete (queue for deletion) all resized files for the current object
  208. */
  209. public function cleanup ()
  210. {
  211. return $this->_oStorage->queueFilesForDeletionFromObject();
  212. }
  213. /**
  214. * Get storage object where transcoded data is stored
  215. */
  216. public function getStorage()
  217. {
  218. return $this->_oStorage;
  219. }
  220. /**
  221. * Get database object instance
  222. */
  223. public function getDb()
  224. {
  225. return $this->_oDb;
  226. }
  227. /**
  228. * Get transcoded file url.
  229. * If transcoded file is ready then direct url to the file is returned.
  230. * If there is no transcoded data available, then special url is returned, upon opening this url image is transcoded automatically and redirects to the ready transcoed image.
  231. * @params $mixedHandler - file handler
  232. * @return file url, or false on error.
  233. */
  234. public function getFileUrl($mixedHandler)
  235. {
  236. if ($this->isFileReady($mixedHandler)) {
  237. $mixedHandler = $this->processHandlerForRetinaDevice($mixedHandler);
  238. $iFileId = $this->_oDb->getFileIdByHandler($mixedHandler);
  239. if (!$iFileId)
  240. return false;
  241. $aFile = $this->_oStorage->getFile($iFileId);
  242. if (!$aFile)
  243. return false;
  244. if ($this->_aObject['atime_tracking'])
  245. $this->_oDb->updateAccessTime($mixedHandler);
  246. return $this->_oStorage->getFileUrlById($iFileId);
  247. }
  248. if ($this->_sQueueTable && !$this->addToQueue($mixedHandler)) // add file to queue (when queue is enabled) if it isn't transcoded yet
  249. return false;
  250. return $this->getFileUrlNotReady($mixedHandler);
  251. }
  252. /**
  253. * Check if transcoded data is available. No need to call it directly, it is called automatically when it is needed.
  254. * @params $mixedHandler - file handler
  255. * @params $isCheckOutdated - check if transcoded file is outdated
  256. * @return false if there is no ready transcoded file is available or it is outdated, true if file is ready
  257. */
  258. public function isFileReady ($mixedHandler, $isCheckOutdated = true)
  259. {
  260. $sMethodFileReady = 'isFileReady_' . $this->_aObject['source_type'];
  261. return $this->$sMethodFileReady($mixedHandler, $isCheckOutdated);
  262. }
  263. /**
  264. * Transcode file, no need to call it directly, it is called automatically when it is needed.
  265. * @params $mixedHandler - file handler
  266. * @params $iProfileId - optional profile id, to assign transcoded file ownership to, usually it is NOT assigned to any particular profile, so just leave it default
  267. * @return true on success, false on error
  268. */
  269. public function transcode ($mixedHandler, $iProfileId = 0)
  270. {
  271. $sExtChange = false;
  272. $this->_oDb->updateQueueStatus($mixedHandler, BX_DOL_QUEUE_PROCESSING, '', gethostname());
  273. // create tmp file locally
  274. $sSuffix = $this->_sQueueStorage ? 'Queue' : $this->_aObject['source_type'];
  275. $sMethodStoreFile = 'storeFileLocally_' . $sSuffix;
  276. $sTmpFile = $this->$sMethodStoreFile($mixedHandler);
  277. if (!$sTmpFile) {
  278. $this->_oDb->updateQueueStatus($mixedHandler, BX_DOL_QUEUE_FAILED, "store local tmp file failed ($sMethodStoreFile)");
  279. return false;
  280. }
  281. // appply filters to tmp file
  282. $this->initFilters ();
  283. foreach ($this->_aObject['filters'] as $aParams) {
  284. $this->clearLog();
  285. $sMethodFilter = 'applyFilter_' . $aParams['filter'];
  286. if (!method_exists($this, $sMethodFilter))
  287. continue;
  288. if (!$this->$sMethodFilter($sTmpFile, $aParams['filter_params'])) {
  289. unlink($sTmpFile);
  290. $this->_oDb->updateQueueStatus($mixedHandler, BX_DOL_QUEUE_FAILED, "filter failed: $sMethodFilter\n" . $this->getLog());
  291. return false;
  292. }
  293. if (!empty($aParams['filter_params']['force_type'])) {
  294. switch ($aParams['filter_params']['force_type']) {
  295. case 'jpeg':
  296. case 'jpg':
  297. $sExtChange = 'jpg';
  298. break;
  299. default:
  300. $sExtChange = $aParams['filter_params']['force_type'];
  301. }
  302. }
  303. }
  304. if ($sExtChange && false !== ($iDotPos = strrpos($sTmpFile, '.'))) {
  305. $sExtOld = substr($sTmpFile, $iDotPos+1);
  306. if ($sExtOld != $sExtChange) {
  307. $sTmpFileOld = $sTmpFile;
  308. $sTmpFile = substr_replace ($sTmpFile, $sExtChange, $iDotPos+1, strlen($sExtOld));
  309. if (!rename($sTmpFileOld, $sTmpFile)) {
  310. @unlink($sTmpFileOld);
  311. $this->_oDb->updateQueueStatus($mixedHandler, BX_DOL_QUEUE_FAILED, "change file extension failed: $sTmpFileOld => $sTmpFile");
  312. return false;
  313. }
  314. }
  315. }
  316. $mixedHandler = $this->processHandlerForRetinaDevice($mixedHandler);
  317. $bRet = true;
  318. if ($this->_sQueueStorage) {
  319. // TODO: store in tmp storage
  320. $this->_oDb->updateQueueStatus($mixedHandler, BX_DOL_QUEUE_COMPLETE);
  321. } else {
  322. $bRet = $this->storeTranscodedFile($mixedHandler, $sTmpFile, $iProfileId);
  323. @unlink($sTmpFile);
  324. if ($bRet)
  325. $this->_oDb->deleteFromQueue($mixedHandler);
  326. else
  327. $this->_oDb->updateQueueStatus($mixedHandler, BX_DOL_QUEUE_FAILED, 'store file failed');
  328. }
  329. return $bRet;
  330. }
  331. /**
  332. * Delete outdated files by last access time.
  333. * @return number of pruned/deleted files
  334. */
  335. public function prune ()
  336. {
  337. $aFiles = $this->_oDb->getFilesForPruning();
  338. if (!$aFiles)
  339. return false;
  340. $iCount = 0;
  341. foreach ($aFiles as $r)
  342. $iCount += $this->_oStorage->deleteFile($r['file_id']) ? 1 : 0;
  343. return $iCount;
  344. }
  345. public function getDevicePixelRatio ()
  346. {
  347. if (isset($_COOKIE['devicePixelRatio']) && (!isset($this->_aObject['source_params']['disable_retina']) || !$this->_aObject['source_params']['disable_retina'])) {
  348. $iDevicePixelRatio = intval($_COOKIE['devicePixelRatio']);
  349. if ($iDevicePixelRatio >= 2)
  350. return 2;
  351. }
  352. return 1;
  353. }
  354. public function getOrigFileUrl ($mixedHandler)
  355. {
  356. $sMethodStoreFile = 'getOrigFileUrl_' . $this->_aObject['source_type'];
  357. return $this->$sMethodStoreFile($mixedHandler);
  358. }
  359. /**
  360. * Get file url when file isn't transcoded yet
  361. */
  362. public function getFileUrlNotReady($mixedHandler)
  363. {
  364. return false;
  365. }
  366. public function clearLog()
  367. {
  368. $this->_sLog = '';
  369. }
  370. public function addToLog($s)
  371. {
  372. $this->_sLog .= $s;
  373. }
  374. public function getLog()
  375. {
  376. return $this->_sLog;
  377. }
  378. protected function storeTranscodedFile ($mixedHandler, $sTmpFile, $iProfileId)
  379. {
  380. $sMethodIsPrivate = 'isPrivate_' . $this->_aObject['source_type'];
  381. $isPrivate = $this->$sMethodIsPrivate($mixedHandler);
  382. $iFileId = $this->_oStorage->storeFileFromPath ($sTmpFile, $isPrivate, $iProfileId);
  383. if (!$iFileId)
  384. return false;
  385. if (!$this->_oDb->updateHandler($iFileId, $mixedHandler)) {
  386. $this->_oStorage->deleteFile($iFileId);
  387. return false;
  388. }
  389. $this->_oStorage->afterUploadCleanup($iFileId, $iProfileId);
  390. return true;
  391. }
  392. protected function addToQueue($mixedHandler, $iProfileId = 0)
  393. {
  394. if ($this->_oDb->getFromQueue($mixedHandler))
  395. return true;
  396. $sFileUrl = $this->getOrigFileUrl($mixedHandler);
  397. return $this->_oDb->addToQueue ($mixedHandler, $sFileUrl, $iProfileId);
  398. }
  399. protected function isFileReady_Folder ($mixedHandlerOrig, $isCheckOutdated = true)
  400. {
  401. $mixedHandler = $this->processHandlerForRetinaDevice($mixedHandlerOrig);
  402. $iFileId = $this->_oDb->getFileIdByHandler($mixedHandler);
  403. if (!$iFileId)
  404. return false;
  405. $aFile = $this->_oStorage->getFile($iFileId);
  406. if (!$aFile)
  407. return false;
  408. if ($isCheckOutdated) { // warning, $isCheckOutdated is partially supported for Folder source type - file modification is not checked
  409. if ($this->_aObject['ts'] > $aFile['modified'] || !$this->getFilePath_Folder($mixedHandlerOrig)) { // if we changed transcoder object params or original file is deleted
  410. // delete file, so it will be recreated next time
  411. if ($this->_oStorage->deleteFile($aFile['id']))
  412. return false;
  413. }
  414. }
  415. return true;
  416. }
  417. protected function isFileReady_Storage ($mixedHandlerOrig, $isCheckOutdated = true)
  418. {
  419. $mixedHandler = $this->processHandlerForRetinaDevice($mixedHandlerOrig);
  420. $iFileId = $this->_oDb->getFileIdByHandler($mixedHandler);
  421. if (!$iFileId)
  422. return false;
  423. $aFile = $this->_oStorage->getFile($iFileId);
  424. if (!$aFile)
  425. return false;
  426. if ($isCheckOutdated) {
  427. $oStorageOriginal = BxDolStorage::getObjectInstance($this->_aObject['source_params']['object']);
  428. if ($oStorageOriginal) {
  429. $aFileOriginal = $oStorageOriginal->getFile($mixedHandlerOrig);
  430. if (!$aFileOriginal || $aFileOriginal['modified'] > $aFile['modified'] || $this->_aObject['ts'] > $aFile['modified']) { // if original file was changed OR we changed transcoder object params
  431. // delete file, so it will be recreated next time
  432. if ($this->_oStorage->deleteFile($aFile['id']))
  433. return false;
  434. }
  435. }
  436. }
  437. return true;
  438. }
  439. protected function isPrivate_Folder ($mixedHandler)
  440. {
  441. if ('no' == $this->_aObject['private'])
  442. return false;
  443. return true;
  444. }
  445. protected function isPrivate_Storage ($mixedHandler)
  446. {
  447. switch ($this->_aObject['private']) {
  448. case 'no':
  449. return false;
  450. case 'yes':
  451. return true;
  452. default:
  453. case 'auto':
  454. $oStorageOriginal = BxDolStorage::getObjectInstance($this->_aObject['source_params']['object']);
  455. if (!$oStorageOriginal)
  456. return true; // in case of error - make sure that file is not public accidentally
  457. $aFile = $oStorageOriginal->getFile($mixedHandler);
  458. return $oStorageOriginal->isFilePrivate($aFile['id']);
  459. }
  460. }
  461. protected function getFilePath_Folder ($mixedHandler)
  462. {
  463. $sPath = $this->_aObject['source_params']['path'] . $mixedHandler;
  464. if (!file_exists($sPath))
  465. $sPath = BX_DIRECTORY_PATH_ROOT . $sPath;
  466. if (!file_exists($sPath))
  467. return false;
  468. return $sPath;
  469. }
  470. protected function storeFileLocally_Folder ($mixedHandler)
  471. {
  472. $sPath = $this->getFilePath_Folder($mixedHandler);
  473. if (!$sPath)
  474. return false;
  475. $sTmpFile = $this->getTmpFilename ($mixedHandler);
  476. if (!copy($sPath, $sTmpFile))
  477. return false;
  478. return $sTmpFile;
  479. }
  480. protected function storeFileLocally_Storage ($mixedHandler)
  481. {
  482. $oStorageOriginal = BxDolStorage::getObjectInstance($this->_aObject['source_params']['object']);
  483. if (!$oStorageOriginal)
  484. return false;
  485. $aFile = $oStorageOriginal->getFile($mixedHandler);
  486. if (!$aFile)
  487. return false;
  488. $sUrl = $oStorageOriginal->getFileUrlById($mixedHandler);
  489. if (!$sUrl)
  490. return false;
  491. $sFileData = bx_file_get_contents ($sUrl);
  492. if (false === $sFileData)
  493. return false;
  494. $sTmpFile = $this->getTmpFilename ($aFile['file_name']);
  495. if (!file_put_contents($sTmpFile, $sFileData))
  496. return false;
  497. return $sTmpFile;
  498. }
  499. protected function storeFileLocally_Queue ($mixedHandler)
  500. {
  501. $sMethodStoreFile = 'storeFileLocally_' . $this->_aObject['source_type'];
  502. $sTmpFile = $this->$sMethodStoreFile($mixedHandler);
  503. if ($sTmpFile)
  504. return $sTmpFile;
  505. $aQueue = $o->getDb->getFromQueue($r['file_id_source']);
  506. if (!$aQueue || !$aQueue['file_url_source'])
  507. return false;
  508. $sFileData = bx_file_get_contents ($aQueue['file_url_source']);
  509. if (false === $sFileData)
  510. return false;
  511. $sTmpFile = $this->getTmpFilename ($mixedHandler);
  512. if (!file_put_contents($sTmpFile, $sFileData))
  513. return false;
  514. return $sTmpFile;
  515. }
  516. protected function getOrigFileUrl_Folder ($mixedHandler)
  517. {
  518. $sPath = $this->_aObject['source_params']['path'] . $mixedHandler;
  519. if (!file_exists(BX_DIRECTORY_PATH_ROOT . $sPath))
  520. return false;
  521. return BX_DOL_URL_ROOT . $sPath;
  522. }
  523. protected function getOrigFileUrl_Storage ($mixedHandler)
  524. {
  525. $oStorageOriginal = BxDolStorage::getObjectInstance($this->_aObject['source_params']['object']);
  526. if (!$oStorageOriginal)
  527. return false;
  528. return $oStorageOriginal->getFileUrlById($mixedHandler);
  529. }
  530. protected function getTmpFilename ($sOverrideName = false)
  531. {
  532. if ($sOverrideName)
  533. return BX_DIRECTORY_PATH_TMP . rand(10000, 99999) . $sOverrideName;
  534. return tempnam(BX_DIRECTORY_PATH_TMP, $this->_aObject['object']);
  535. }
  536. protected function initFilters ()
  537. {
  538. if (false !== $this->_aObject['filters']) // filters are already initilized
  539. return;
  540. // get transcoder filters
  541. $aFilters = $this->_oDb->getTranscoderFilters();
  542. $this->_aObject['filters'] = array();
  543. foreach ($aFilters as $aFilter) {
  544. if ($aFilter['filter_params'])
  545. $aFilter['filter_params'] = unserialize($aFilter['filter_params']);
  546. $this->_aObject['filters'][] = $aFilter;
  547. }
  548. }
  549. protected function clearCacheDB()
  550. {
  551. $oCacheDb = $this->_oDb->getDbCacheObject();
  552. return $oCacheDb->removeAllByPrefix('db_');
  553. }
  554. public function getDevicePixelRatioHandlerSuffix ()
  555. {
  556. $iDevicePixelRatio = $this->getDevicePixelRatio ();
  557. if ($iDevicePixelRatio >= 2)
  558. return $this->_sRetinaSuffix;
  559. return '';
  560. }
  561. protected function processHandlerForRetinaDevice ($mixedHandler)
  562. {
  563. return '' . $mixedHandler . $this->getDevicePixelRatioHandlerSuffix ();
  564. }
  565. static protected function _callFuncForObjectsArray ($mixed, $sFunc)
  566. {
  567. if (!is_array($mixed))
  568. $mixed = array($mixed);
  569. foreach ($mixed as $sObject) {
  570. $oTranscoder = self::getObjectInstance($sObject);
  571. if ($oTranscoder)
  572. $oTranscoder->$sFunc();
  573. }
  574. }
  575. }
  576. /** @} */