BxDolTranscoder.php 22 KB

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