transcoder.php 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. <?php
  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 Samples
  7. * @{
  8. */
  9. /**
  10. * @page samples
  11. * @section transcoder_images Transcoder Images
  12. *
  13. * This sample shows how transcoder can be used for the folder with images.
  14. *
  15. * @code
  16. *
  17. * CREATE TABLE IF NOT EXISTS `bx_resizer_files` (
  18. * `id` int(11) NOT NULL AUTO_INCREMENT,
  19. * `profile_id` int(10) unsigned NOT NULL,
  20. * `remote_id` varchar(255) COLLATE utf8_unicode_ci NOT NULL,
  21. * `path` varchar(255) COLLATE utf8_unicode_ci NOT NULL,
  22. * `file_name` varchar(255) COLLATE utf8_unicode_ci NOT NULL,
  23. * `mime_type` varchar(128) COLLATE utf8_unicode_ci NOT NULL,
  24. * `ext` varchar(32) COLLATE utf8_unicode_ci NOT NULL,
  25. * `size` int(11) NOT NULL,
  26. * `added` int(11) NOT NULL,
  27. * `modified` int(11) NOT NULL,
  28. * `private` int(11) NOT NULL,
  29. * PRIMARY KEY (`id`),
  30. * UNIQUE KEY `remote_id` (`remote_id`)
  31. * );
  32. *
  33. * INSERT INTO `sys_objects_storage` (`object`, `engine`, `params`, `token_life`, `cache_control`, `levels`, `table_files`, `ext_mode`, `ext_allow`, `ext_deny`, `quota_size`, `current_size`, `quota_number`, `current_number`, `max_file_size`, `ts`) VALUES
  34. * ('resizer', 'Local', '', 360, 84000, 0, 'bx_resizer_files', 'deny-allow', '', 'exe,com,bat,pif,scr', 1000000000, 0, 100, 0, 300000000, 0);
  35. *
  36. * INSERT INTO `sys_objects_transcoder_images` (`object`, `storage_object`, `source_type`, `source_params`, `private`, `atime_tracking`, `atime_pruning`, `ts`) VALUES
  37. * ('sample', 'resizer', 'Folder', 'a:1:{s:4:"path";s:12:"samples/img/";}', 'no', 0, 0, 0);
  38. *
  39. * INSERT INTO `sys_transcoder_images_filters` (`transcoder_object`, `filter`, `filter_params`, `order`) VALUES
  40. * ('sample', 'Resize', 'a:3:{s:1:"w";i:100;s:1:"h";i:100;s:13:"square_resize";i:0;}', 1),
  41. * ('sample', 'Grayscale', '', 2);
  42. *
  43. * @endcode
  44. *
  45. */
  46. require_once('./../inc/header.inc.php');
  47. require_once(BX_DIRECTORY_PATH_INC . "design.inc.php");
  48. bx_import('BxDolLanguages');
  49. bx_import('BxDolTemplate');
  50. $oTemplate = BxDolTemplate::getInstance();
  51. $oTemplate->setPageNameIndex (BX_PAGE_DEFAULT);
  52. $oTemplate->setPageHeader ("Sample transcoder");
  53. $oTemplate->setPageContent ('page_main_code', PageCompMainCode());
  54. $oTemplate->getPageCode();
  55. /**
  56. * page code function
  57. */
  58. function PageCompMainCode() {
  59. ob_start();
  60. $iProfileId = 123;
  61. bx_import('BxDolImageTranscoder');
  62. $oTranscoder = BxDolImageTranscoder::getObjectInstance('sample');
  63. if (!$oTranscoder)
  64. die('Transcoder object isn\'t defined');
  65. echo "registerHandlers: [" . $oTranscoder->registerHandlers() . "] <hr />\n";
  66. echo "
  67. <script>
  68. $(document).ready(function () {
  69. $('img').on('load', function () {
  70. $(this).after(' <span>size: <b>' + $(this).width() + 'x' + $(this).height() + '</b></span>')
  71. });
  72. });
  73. </script>
  74. ";
  75. $oStorage = $oTranscoder->getStorage();
  76. if (isset($_POST['delete'])) {
  77. foreach ($_POST['file_id'] as $iFileId) {
  78. $bRet = $oStorage->deleteFile($iFileId, $iProfileId);
  79. if ($bRet)
  80. echo "<hr />deleted file id: " . $iFileId . "<hr />";
  81. else
  82. echo "<hr />file deleting error: " . $oStorage->getErrorString() . "<hr />";
  83. }
  84. } else {
  85. $sPath = BX_DIRECTORY_PATH_ROOT . 'samples/img/';
  86. $h = opendir($sPath);
  87. while (false !== ($sFile = readdir($h))) {
  88. if ('.' == $sFile[0] || !is_file($sPath . $sFile))
  89. continue;
  90. $sUrl = $oTranscoder->getImageUrl($sFile);
  91. echo $sFile . ' : <img src="' . $sUrl . '" /> <br /> ' . $sUrl . ' <hr />';
  92. }
  93. }
  94. $a = $oStorage->getFilesAll();
  95. echo "<hr /> <h2>Files List:</h2>";
  96. echo '<form method="POST">';
  97. foreach ($a as $r)
  98. echo '<input type="checkbox" name="file_id[]" value="' . $r['id'] . '" /> ' . $r['file_name'] . '<br />';
  99. echo '<input type="submit" name="delete" value="Delete" />';
  100. echo '</form>';
  101. $s = ob_get_clean();
  102. return DesignBoxContent("Sample transcoder", $s, BX_DB_PADDING_DEF);
  103. }