transcoder_custom.php 4.9 KB

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