1
0

BxBaseUploaderServices.php 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. <?php defined('BX_DOL') or die('hack attempt');
  2. /**
  3. * Copyright (c) UNA, Inc - https://una.io
  4. * MIT License - https://opensource.org/licenses/MIT
  5. *
  6. * @defgroup UnaBaseView UNA Base Representation Classes
  7. * @{
  8. */
  9. /**
  10. * System services related to Comments.
  11. */
  12. class BxBaseUploaderServices extends BxDol
  13. {
  14. public function __construct()
  15. {
  16. parent::__construct();
  17. }
  18. /**
  19. * @page service Service Calls
  20. * @section bx_system_cmts System Services
  21. * @subsection bx_system_cmts-general General
  22. * @subsubsection bx_system_cmts-get_data_api get_data_api
  23. *
  24. * @code bx_srv('system', 'get_data_api', [], 'TemplCmtsServices'); @endcode
  25. *
  26. * Get comments data
  27. * @param $aParams array with paramenters :
  28. * "module":"bx_posts","object_id":3,"start_from":5,"order_way":"desc","is_form":false
  29. *
  30. * @see TemplCmtsServices::serviceGetDataApi
  31. */
  32. /**
  33. * @ref bx_system_cmts-get_data_api "get_data_api"
  34. * @api @ref bx_system_cmts-get_data_api "get_data_api"
  35. */
  36. public function serviceGetDataApi($aParams = [])
  37. {
  38. $sUploaderObject = bx_process_input(bx_get('uo'));
  39. $sStorageObject = bx_process_input(bx_get('so'));
  40. $sUniqId = preg_match("/^[\d\w]+$/", bx_get('uid')) ? bx_get('uid') : '';
  41. $isMultiple = bx_get('m') ? true : false;
  42. $sFormat = bx_process_input(bx_get('f'));
  43. if ($sFormat != 'html' && $sFormat != 'json')
  44. $sFormat = 'html';
  45. $iContentId = bx_get('c');
  46. if (false === $iContentId || '' === $iContentId)
  47. $iContentId = false;
  48. else
  49. $iContentId = bx_process_input($iContentId, BX_DATA_INT);
  50. $isPrivate = (int)bx_get('p') ? 1 : 0;
  51. $oUploader = BxDolUploader::getObjectInstance($sUploaderObject, $sStorageObject, $sUniqId);
  52. $sAction = bx_process_input(bx_get('a'));
  53. switch ($sAction) {
  54. case 'restore_ghosts':
  55. $sImagesTranscoder = bx_process_input(bx_get('img_trans'));
  56. $oData = $oUploader->getGhostsWithOrder((int)bx_get_logged_profile_id(), $sFormat, $sImagesTranscoder, $iContentId);
  57. $aRv = isset($oData['g']) ? [$oData['g'], $oData['o']] : [];
  58. return $aRv;
  59. break;
  60. case 'delete':
  61. header('Content-type: text/html; charset=utf-8');
  62. $iFileId = bx_process_input(bx_get('id'), BX_DATA_INT);
  63. return $oUploader->deleteGhost($iFileId, bx_get_logged_profile_id());
  64. break;
  65. case 'upload':
  66. $iProfileId = (int)bx_get_logged_profile_id();
  67. $aResult = $oUploader->handleUploads($iProfileId, isset($_FILES['f']) ? $_FILES['f'] : null, $isMultiple, $iContentId, $isPrivate);
  68. if(isset($aResult['id']) && ($iId = (int)$aResult['id']) && ($sImagesTranscoder = bx_get('img_trans')) !== false) {
  69. $aGhosts = $oUploader->getGhosts($iProfileId, 'array', bx_process_input($sImagesTranscoder), $iContentId);
  70. if(isset($aGhosts[$iId]))
  71. $aResult['ghost'] = $aGhosts[$iId];
  72. }
  73. return $aResult;
  74. break;
  75. case 'upload_inline':
  76. $sStorageObject = bx_process_input(bx_get('o'));
  77. $sFile = bx_process_input(bx_get('f'));
  78. $oStorage = BxDolStorage::getObjectInstance($sStorageObject);
  79. $iProfileId = bx_get_logged_profile_id();
  80. if (!($iId = $oStorage->storeFileFromForm($_FILES['file'], false, $iProfileId))) {
  81. return array('error' => '1');
  82. exit;
  83. }
  84. $oStorage->afterUploadCleanup($iId, $iProfileId);
  85. $aFileInfo = $oStorage->getFile($iId);
  86. if ($aFileInfo && in_array($aFileInfo['ext'], array('jpg', 'jpeg', 'jpe', 'png'))) {
  87. $oTranscoder = BxDolTranscoderImage::getObjectInstance(bx_get('t'));
  88. $sUrl = $oTranscoder->getFileUrl($iId);
  89. }
  90. else {
  91. $sUrl = $oStorage->getFileUrlById($iId);
  92. }
  93. return ['link' => $sUrl];
  94. break;
  95. }
  96. }
  97. }
  98. /** @} */