transcoder_custom.php 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  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 TridentCore Trident Core
  7. * @{
  8. */
  9. /**
  10. * @page samples
  11. * @section transcoder_images_custom Custom Images Transcoder
  12. */
  13. require_once('./../inc/header.inc.php');
  14. require_once(BX_DIRECTORY_PATH_INC . "design.inc.php");
  15. bx_import('BxDolLanguages');
  16. bx_import('BxDolTemplate');
  17. bx_import('BxTemplFunctions');
  18. $oTemplate = BxDolTemplate::getInstance();
  19. $oTemplate->setPageNameIndex (BX_PAGE_DEFAULT);
  20. $oTemplate->setPageHeader ("Custom images transcoder");
  21. $oTemplate->setPageContent ('page_main_code', PageCompMainCode());
  22. $oTemplate->getPageCode();
  23. /**
  24. * page code function
  25. */
  26. function PageCompMainCode()
  27. {
  28. ob_start();
  29. $sTranscoderObject = 'sys_custom_images';
  30. $sStorageObjectOrig = 'sys_images_custom';
  31. $iProfileId = bx_get_logged_profile_id();
  32. if (!isAdmin()) {
  33. echo "You aren't operator.";
  34. exit;
  35. }
  36. bx_import('BxDolTranscoderImage');
  37. $iPrunedFiles = BxDolTranscoder::pruning();
  38. if ($iPrunedFiles) {
  39. echo "iPrunedFiles: $iPrunedFiles";
  40. exit;
  41. }
  42. $oTranscoderObject = BxDolTranscoderImage::getObjectInstance($sTranscoderObject);
  43. if (!$oTranscoderObject) {
  44. echo "Transcoder object is not available: " . $sTranscoderObject;
  45. exit;
  46. }
  47. //echo "registerHandlers: [" . $oTranscoderObject->registerHandlers() . "] <br />\n";
  48. bx_import('BxDolStorage');
  49. $oStorageOrig = BxDolStorage::getObjectInstance($sStorageObjectOrig);
  50. if (!$oStorageOrig) {
  51. echo "Storage object is not available: " . $sStorageObjectOrig;
  52. exit;
  53. }
  54. if (isset($_POST['upload'])) {
  55. $iId = $oStorageOrig->storeFileFromForm($_FILES['file'], true, $iProfileId);
  56. if ($iId) {
  57. $iCount = $oStorageOrig->afterUploadCleanup($iId, $iProfileId);
  58. echo "<h2>Uploaded file id: " . $iId . "(deleted ghosts:" . $iCount . ") </h2>";
  59. } else {
  60. echo "<h2>Error uploading file: " . $oStorage->getErrorString() . '</h2><hr class="bx-def-hr" />';
  61. }
  62. }
  63. elseif (isset($_POST['delete'])) {
  64. foreach ($_POST['file_id'] as $iFileId) {
  65. $bRet = $oStorageOrig->deleteFile($iFileId, $iProfileId);
  66. if ($bRet)
  67. echo "<h2>Deleted file id: " . $iFileId . '</h2><hr class="bx-def-hr" />';
  68. else
  69. echo "<h2>File deleting error: " . $oStorageOrig->getErrorString() . '</h2><hr class="bx-def-hr" />';
  70. }
  71. }
  72. else {
  73. $a = $oStorageOrig->getFilesAll();
  74. foreach ($a as $r) {
  75. $sUrlImage = $oTranscoderObject->getFileUrl($r['id']);
  76. ?>
  77. <div class="bx-def-font-h2 bx-def-margin-sec-topbottom"><?=$r['file_name']; ?></div>
  78. Size: <input id="size-<?=$r['id']; ?>" type="text" class="bx-def-font-inputs bx-form-input-text bx-def-margin-sec-bottom bx-transcoder-custom-images-size" placeholder="320x240" />
  79. Copy&amp;paste URL: <input id="input-<?=$r['id']; ?>" type="text" value="<?=$oTranscoderObject->getFileUrlNotReady($r['id']); ?>" class="bx-def-font-inputs bx-form-input-text bx-def-margin-sec-bottom" /> <br />
  80. <img src="<?=$sUrlImage; ?>" style="height:200px; width:auto;" />
  81. <hr class="bx-def-hr" />
  82. <?php
  83. }
  84. }
  85. $a = $oStorageOrig->getFilesAll();
  86. ?>
  87. <h2>Files List</h2>
  88. <form method="POST">
  89. <?php foreach ($a as $r): ?>
  90. <input type="checkbox" name="file_id[]" value="<?=$r['id'] ?>" />
  91. <?=$r['file_name'] ?>
  92. <br />
  93. <?php endforeach; ?>
  94. <input type="submit" name="delete" value="Delete" class="bx-btn bx-btn-small bx-def-margin-sec-top" style="float:none;" />
  95. </form>
  96. <hr class="bx-def-hr" />
  97. <h2>Upload</h2>
  98. <form enctype="multipart/form-data" method="POST">
  99. <input type="file" name="file" />
  100. <br />
  101. <input type="submit" name="upload" value="Upload" class="bx-btn bx-btn-small bx-def-margin-sec-top" style="float:none;" />
  102. </form>
  103. <script>
  104. $(document).ready(function () {
  105. $('.bx-transcoder-custom-images-size').on('change input', function () {
  106. var sId = $(this).attr('id').replace('size-', '');
  107. var a = $('#input-' + sId).val().split('&');
  108. var aSize = this.value.split('x');
  109. var s = '';
  110. for (var i in a) {
  111. if (-1 == a[i].indexOf('t=') && -1 == a[i].indexOf('x=') && -1 == a[i].indexOf('y='))
  112. s += a[i] + '&';
  113. }
  114. s = s.replace(/&$/, '');
  115. if (parseInt(aSize[0]) > 0)
  116. s = bx_append_url_params(s, 'x=' + aSize[0]);
  117. if (parseInt(aSize[1]) > 0)
  118. s = bx_append_url_params(s, 'y=' + aSize[1]);
  119. $('#input-' + sId).val(s);
  120. });
  121. });
  122. </script>
  123. <?php
  124. $s = ob_get_clean();
  125. return DesignBoxContent("Custom images transcoder", $s, BX_DB_PADDING_DEF);
  126. }
  127. /** @} */