BxBaseModTextModule.php 37 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989
  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 BaseText Base classes for text modules
  7. * @ingroup UnaModules
  8. *
  9. * @{
  10. */
  11. define('BX_BASE_MOD_TEXT_STATUS_ACTIVE', 'active');
  12. define('BX_BASE_MOD_TEXT_STATUS_HIDDEN', 'hidden');
  13. define('BX_BASE_MOD_TEXT_STATUS_AWAITING', 'awaiting');
  14. /**
  15. * Saved for backward compatibility.
  16. * Can be removed in future releases of UNA 13.
  17. */
  18. define('BX_BASE_MOD_TEXT_STATUS_PENDING', 'pending');
  19. /**
  20. * Base module class for text based modules
  21. */
  22. class BxBaseModTextModule extends BxBaseModGeneralModule implements iBxDolContentInfoService
  23. {
  24. function __construct(&$aModule)
  25. {
  26. parent::__construct($aModule);
  27. }
  28. // ====== ACTIONS METHODS
  29. public function actionFileEmbedVideo($iFileId)
  30. {
  31. $this->_oTemplate->embedVideo($iFileId);
  32. }
  33. public function actionFileEmbedSound($iFileId)
  34. {
  35. $this->_oTemplate->embedSound($iFileId);
  36. }
  37. // ====== SERVICE METHODS
  38. public function serviceGetSafeServices()
  39. {
  40. $a = parent::serviceGetSafeServices();
  41. return array_merge($a, array (
  42. 'GetBlockPollAnswers' => '',
  43. 'GetBlockPollResults' => '',
  44. 'GetMenuAddonManageToolsProfileStats' => '',
  45. 'BrowsePublic' => '',
  46. 'BrowsePopular' => '',
  47. 'BrowseTop' => '',
  48. 'BrowseUpdated' => '',
  49. 'BrowseAuthor' => '',
  50. 'CategoriesMultiListContext' => ''
  51. ));
  52. }
  53. public function serviceModuleSample ()
  54. {
  55. return parent::serviceModuleSample() ?: '_sys_sample_content';
  56. }
  57. public function serviceManageTools($sType = 'common')
  58. {
  59. $this->_oTemplate->addJs(['modules/base/text/js/|manage_tools.js']);
  60. return parent::serviceManageTools($sType);
  61. }
  62. /**
  63. * @page service Service Calls
  64. * @section bx_base_text Base Text
  65. * @subsection bx_base_general-page_blocks Page Blocks
  66. * @subsubsection bx_base_general-categories_multi_list_context categories_multi_list_context
  67. *
  68. * @code bx_srv('bx_posts', 'categories_multi_list_context', [...]); @endcode
  69. *
  70. * Display multi-categorories block with number of posts in each category for current context
  71. * @param $bDisplayEmptyCats display empty categories
  72. *
  73. * @see BxBaseModGeneralModule::serviceCategoriesMultiListContext
  74. */
  75. /**
  76. * @ref bx_base_general-categories_multi_list_context "categories_multi_list_context"
  77. */
  78. public function serviceCategoriesMultiListContext($iProfileId = 0, $bDisplayEmptyCats = true)
  79. {
  80. if ($iProfileId == 0)
  81. $iProfileId = bx_process_input(bx_get('profile_id'), BX_DATA_INT);
  82. $oCategories = BxDolCategories::getInstance();
  83. $aCats = $oCategories->getData([
  84. 'type' => 'by_module&context_with_num',
  85. 'module' => $this->getName(),
  86. 'context_id' => $iProfileId
  87. ]
  88. );
  89. $aVars = array('bx_repeat:cats' => array());
  90. foreach ($aCats as $oCat) {
  91. $sValue = $oCat['value'];
  92. $iNum = $oCat['num'];
  93. $aVars['bx_repeat:cats'][] = array(
  94. 'url' => $oCategories->getUrl($this->getName(), $sValue, '&context_id=' . $iProfileId),
  95. 'name' => _t($sValue),
  96. 'value' => $sValue,
  97. 'num' => $iNum,
  98. );
  99. }
  100. if (!$aVars['bx_repeat:cats'])
  101. return '';
  102. return $this->_oTemplate->parseHtmlByName('category_list_multi.html', $aVars);
  103. }
  104. /**
  105. * Display media EXIF information.
  106. * @param $iMediaId media ID, if it's omitted then it's taken from 'id' GET variable.
  107. * @return HTML string with EXIF info. On error empty string is returned.
  108. */
  109. public function serviceMediaExif ($iMediaId = 0)
  110. {
  111. $CNF = &$this->_oConfig->CNF;
  112. return $this->_serviceTemplateFunc ('mediaExif', $iMediaId, $CNF['FUNCTION_FOR_GET_ITEM_INFO']);
  113. }
  114. public function serviceGetThumb ($iContentId, $sTranscoder = '')
  115. {
  116. $CNF = &$this->_oConfig->CNF;
  117. if(bx_is_api()){
  118. $aContentInfo = $this->_oDb->getContentInfoById($iContentId);
  119. if (isset($CNF['FIELD_THUMB']))
  120. return bx_api_get_image($CNF['OBJECT_STORAGE'], $aContentInfo[$CNF['FIELD_THUMB']]);
  121. }
  122. if(empty($sTranscoder) && !empty($CNF['OBJECT_IMAGES_TRANSCODER_GALLERY']))
  123. $sTranscoder = $CNF['OBJECT_IMAGES_TRANSCODER_GALLERY'];
  124. $mixedResult = $this->_getFieldValueThumb('FIELD_THUMB', $iContentId, $sTranscoder);
  125. return $mixedResult !== false ? $mixedResult : '';
  126. }
  127. public function serviceGetMenuAddonManageTools()
  128. {
  129. $CNF = &$this->_oConfig->CNF;
  130. $iNumTotal = $this->_oDb->getEntriesNumByParams();
  131. $iNum1 = $this->_oDb->getEntriesNumByParams([
  132. [
  133. 'key' => $CNF['FIELD_STATUS'],
  134. 'value' => 'hidden',
  135. 'operator' => '='
  136. ]
  137. ]);
  138. $iNum2 = 0;
  139. if (isset($CNF['OBJECT_REPORTS'])){
  140. $iNum2 = $this->_oDb->getEntriesNumByParams([
  141. [
  142. 'key' => 'reports',
  143. 'value' => '0',
  144. 'operator' => '>'
  145. ]
  146. ]);
  147. }
  148. return array('counter1_value' => $iNum1, 'counter2_value' => $iNum2, 'counter3_value' => $iNumTotal );
  149. }
  150. /**
  151. * @page service Service Calls
  152. * @section bx_base_text Base Text
  153. * @subsection bx_base_text-other Other
  154. * @subsubsection bx_base_text-get_menu_addon_manage_tools_profile_stats get_menu_addon_manage_tools_profile_stats
  155. *
  156. * @code bx_srv('bx_posts', 'get_menu_addon_manage_tools_profile_stats', []); @endcode
  157. *
  158. * Get number of posts for currently logged in user
  159. *
  160. * @see BxBaseModTextModule::serviceGetMenuAddonManageToolsProfileStats
  161. */
  162. /**
  163. * @ref bx_base_text-get_menu_addon_manage_tools_profile_stats "get_menu_addon_manage_tools_profile_stats"
  164. */
  165. public function serviceGetMenuAddonManageToolsProfileStats($iProfileId = 0)
  166. {
  167. if(!$iProfileId)
  168. $iProfileId = bx_get_logged_profile_id();
  169. bx_import('SearchResult', $this->_aModule);
  170. $sClass = $this->_aModule['class_prefix'] . 'SearchResult';
  171. $o = new $sClass();
  172. $o->fillFilters([
  173. 'author' => $iProfileId
  174. ]);
  175. $o->unsetPaginate();
  176. return $o->getNum();
  177. }
  178. /**
  179. * @page service Service Calls
  180. * @section bx_base_text Base Text
  181. * @subsection bx_base_text-browse Browse
  182. * @subsubsection bx_base_text-browse_public browse_public
  183. *
  184. * @code bx_srv('bx_posts', 'browse_public', [...]); @endcode
  185. *
  186. * Display public posts
  187. * @param $sUnitView unit view, such as: full, extended, gallery, showcase
  188. * @param $bEmptyMessage display or not "empty" message when there is no content
  189. * @param $bAjaxPaginate use AJAX paginate or not
  190. *
  191. * @see BxBaseModTextModule::serviceBrowsePublic
  192. */
  193. /**
  194. * @ref bx_base_text-browse_public "browse_public"
  195. */
  196. public function serviceBrowsePublic ($sUnitView = false, $bEmptyMessage = true, $bAjaxPaginate = true)
  197. {
  198. return $this->_serviceBrowse ('public', $sUnitView ? array('unit_view' => $sUnitView) : false, BX_DB_PADDING_DEF, $bEmptyMessage, $bAjaxPaginate);
  199. }
  200. /**
  201. * @page service Service Calls
  202. * @section bx_base_text Base Text
  203. * @subsection bx_base_text-browse Browse
  204. * @subsubsection bx_base_text-browse_popular browse_popular
  205. *
  206. * @code bx_srv('bx_posts', 'browse_popular', [...]); @endcode
  207. *
  208. * Display popular posts
  209. * @param $sUnitView unit view, such as: full, extended, gallery, showcase
  210. * @param $bEmptyMessage display or not "empty" message when there is no content
  211. * @param $bAjaxPaginate use AJAX paginate or not
  212. *
  213. * @see BxBaseModTextModule::serviceBrowsePopular
  214. */
  215. /**
  216. * @ref bx_base_text-browse_popular "browse_popular"
  217. */
  218. public function serviceBrowsePopular ($sUnitView = false, $bEmptyMessage = true, $bAjaxPaginate = true)
  219. {
  220. return $this->_serviceBrowse ('popular', $sUnitView ? array('unit_view' => $sUnitView) : false, BX_DB_PADDING_DEF, $bEmptyMessage, $bAjaxPaginate);
  221. }
  222. /**
  223. * @page service Service Calls
  224. * @section bx_base_text Base Text
  225. * @subsection bx_base_text-browse Browse
  226. * @subsubsection bx_base_text-browse_top browse_top
  227. *
  228. * @code bx_srv('bx_posts', 'browse_top', [...]); @endcode
  229. *
  230. * Display top posts
  231. * @param $sUnitView unit view, such as: full, extended, gallery, showcase
  232. * @param $bEmptyMessage display or not "empty" message when there is no content
  233. * @param $bAjaxPaginate use AJAX paginate or not
  234. *
  235. * @see BxBaseModTextModule::serviceBrowseTop
  236. */
  237. /**
  238. * @ref bx_base_text-browse_top "browse_top"
  239. */
  240. public function serviceBrowseTop ($sUnitView = false, $bEmptyMessage = true, $bAjaxPaginate = true)
  241. {
  242. return $this->_serviceBrowse ('top', $sUnitView ? array('unit_view' => $sUnitView) : false, BX_DB_PADDING_DEF, $bEmptyMessage, $bAjaxPaginate);
  243. }
  244. /**
  245. * @page service Service Calls
  246. * @section bx_base_text Base Text
  247. * @subsection bx_base_text-browse Browse
  248. * @subsubsection bx_base_text-browse_updated browse_updated
  249. *
  250. * @code bx_srv('bx_posts', 'browse_updated', [...]); @endcode
  251. *
  252. * Display recently updated posts
  253. * @param $sUnitView unit view, such as: full, extended, gallery, showcase
  254. * @param $bEmptyMessage display or not "empty" message when there is no content
  255. * @param $bAjaxPaginate use AJAX paginate or not
  256. *
  257. * @see BxBaseModTextModule::serviceBrowseUpdated
  258. */
  259. /**
  260. * @ref bx_base_text-browse_updated "browse_updated"
  261. */
  262. public function serviceBrowseUpdated ($sUnitView = false, $bEmptyMessage = true, $bAjaxPaginate = true)
  263. {
  264. return $this->_serviceBrowse ('updated', $sUnitView ? array('unit_view' => $sUnitView) : false, BX_DB_PADDING_DEF, $bEmptyMessage, $bAjaxPaginate);
  265. }
  266. /**
  267. * @page service Service Calls
  268. * @section bx_base_text Base Text
  269. * @subsection bx_base_text-browse Browse
  270. * @subsubsection bx_base_text-browse_author browse_author
  271. *
  272. * @code bx_srv('bx_posts', 'browse_author', [...]); @endcode
  273. *
  274. * Display posts of specified author
  275. * @param $iProfileId profile ID
  276. * @param $aParams additional params, see BxBaseModGeneralModule::serviceBrowse
  277. *
  278. * @see BxBaseModTextModule::serviceBrowseAuthor
  279. */
  280. /**
  281. * @ref bx_base_text-browse_author "browse_author"
  282. */
  283. public function serviceBrowseAuthor ($iProfileId = 0, $aParams = array())
  284. {
  285. return $this->_serviceBrowseWithParam ('author', 'profile_id', $iProfileId, $aParams);
  286. }
  287. /**
  288. * @page service Service Calls
  289. * @section bx_base_text Base Text
  290. * @subsection bx_base_text-page_blocks Page Blocks
  291. * @subsubsection bx_base_text-entity_author entity_author
  292. *
  293. * @code bx_srv('bx_posts', 'entity_author', [...]); @endcode
  294. *
  295. * Display author block for the specified post
  296. * @param $iContentId content ID
  297. *
  298. * @see BxBaseModTextModule::serviceEntityAuthor
  299. */
  300. /**
  301. * @ref bx_base_text-entity_author "entity_author"
  302. */
  303. public function serviceEntityAuthor ($iContentId = 0)
  304. {
  305. return $this->_serviceTemplateFunc ('entryAuthor', $iContentId);
  306. }
  307. /**
  308. * @page service Service Calls
  309. * @section bx_base_text Base Text
  310. * @subsection bx_base_text-page_blocks Page Blocks
  311. * @subsubsection bx_base_text-entity_breadcrumb entity_breadcrumb
  312. *
  313. * @code bx_srv('bx_forum', 'entity_breadcrumb', [...]); @endcode
  314. *
  315. * Display breadcrumb for the specified post
  316. * @param $iContentId content ID
  317. *
  318. * @see BxBaseModTextModule::serviceEntityBreadcrumb
  319. */
  320. /**
  321. * @ref bx_base_text-entity_breadcrumb "entity_breadcrumb"
  322. */
  323. public function serviceEntityBreadcrumb ($iContentId = 0)
  324. {
  325. return $this->_serviceTemplateFunc ('entryBreadcrumb', $iContentId);
  326. }
  327. /**
  328. * Delete all content by profile
  329. * @param $iProfileId profile id
  330. * @return number of deleted items
  331. */
  332. public function serviceDeleteEntitiesByAuthor ($iProfileId)
  333. {
  334. $a = $this->_oDb->getEntriesByAuthor((int)$iProfileId);
  335. if (!$a)
  336. return 0;
  337. $iCount = 0;
  338. foreach ($a as $aContentInfo)
  339. $iCount += ('' == $this->serviceDeleteEntity($aContentInfo[$this->_oConfig->CNF['FIELD_ID']]) ? 1 : 0);
  340. return $iCount;
  341. }
  342. // ====== PERMISSION METHODS
  343. /**
  344. * @return CHECK_ACTION_RESULT_ALLOWED if access is granted or error message if access is forbidden. So make sure to make strict(===) checking.
  345. */
  346. public function checkAllowedSetThumb ($iContentId = 0)
  347. {
  348. // check ACL
  349. $aCheck = checkActionModule($this->_iProfileId, 'set thumb', $this->getName(), false);
  350. if ($aCheck[CHECK_ACTION_RESULT] !== CHECK_ACTION_RESULT_ALLOWED)
  351. return $aCheck[CHECK_ACTION_MESSAGE];
  352. return CHECK_ACTION_RESULT_ALLOWED;
  353. }
  354. public function isAllowedApprove($mixedContent, $isPerformAction = false)
  355. {
  356. return $this->checkAllowedApprove($mixedContent, $isPerformAction) === CHECK_ACTION_RESULT_ALLOWED;
  357. }
  358. public function checkAllowedApprove($mixedContent, $isPerformAction = false)
  359. {
  360. $CNF = &$this->_oConfig->CNF;
  361. $sTxtError = '_sys_txt_access_denied';
  362. $iProfileId = bx_get_logged_profile_id();
  363. if(!is_array($mixedContent))
  364. $mixedContent = $this->_oDb->getContentInfoById((int)$mixedContent);
  365. if(empty($mixedContent) || !is_array($mixedContent))
  366. return _t($sTxtError);
  367. if(!isset($CNF['FIELD_STATUS_ADMIN']) || $mixedContent[$CNF['FIELD_STATUS_ADMIN']] != BX_BASE_MOD_GENERAL_STATUS_PENDING)
  368. return _t($sTxtError);
  369. if($this->_isModerator())
  370. return CHECK_ACTION_RESULT_ALLOWED;
  371. if(!empty($CNF['FIELD_ALLOW_VIEW_TO']) && (int)$mixedContent[$CNF['FIELD_ALLOW_VIEW_TO']] < 0) {
  372. $iContextProfileId = abs((int)$mixedContent[$CNF['FIELD_ALLOW_VIEW_TO']]);
  373. $oContextProfile = BxDolProfile::getInstance($iContextProfileId);
  374. $aAdmins = bx_srv($oContextProfile->getModule(), 'get_admins_to_manage_content', [$iContextProfileId]);
  375. if(!empty($aAdmins) && in_array($iProfileId, $aAdmins))
  376. return CHECK_ACTION_RESULT_ALLOWED;
  377. }
  378. return _t($sTxtError);
  379. }
  380. // ====== COMMON METHODS
  381. public function deleteAttachLinks($iId)
  382. {
  383. if(!$this->_oConfig->isAttachLinks())
  384. return;
  385. $CNF = &$this->_oConfig->CNF;
  386. $aLinks = $this->_oDb->getLinks($iId);
  387. if(empty($aLinks) || !is_array($aLinks))
  388. return;
  389. $oStorage = BxDolStorage::getObjectInstance($CNF['OBJECT_STORAGE_PHOTOS']);
  390. foreach($aLinks as $aLink)
  391. if(!empty($aLink['media_id']))
  392. $oStorage->deleteFile($aLink['media_id']);
  393. $this->_oDb->deleteLinks($iId);
  394. }
  395. public function deleteAttachLinksUnused($iProfileId)
  396. {
  397. if(!$this->_oConfig->isAttachLinks())
  398. return;
  399. $CNF = &$this->_oConfig->CNF;
  400. $aLinks = $this->_oDb->getUnusedLinks($iProfileId);
  401. if(empty($aLinks) || !is_array($aLinks))
  402. return;
  403. $oStorage = BxDolStorage::getObjectInstance($CNF['OBJECT_STORAGE_PHOTOS']);
  404. foreach($aLinks as $aLink)
  405. if(!empty($aLink['media_id']))
  406. $oStorage->deleteFile($aLink['media_id']);
  407. $this->_oDb->deleteUnusedLinks($iProfileId);
  408. }
  409. public function onApprove($mixedContent)
  410. {
  411. $CNF = &$this->_oConfig->CNF;
  412. if(!is_array($mixedContent))
  413. $mixedContent = $this->_oDb->getContentInfoById((int)$mixedContent);
  414. $this->alertAfterApprove($mixedContent);
  415. $this->onPublished($mixedContent[$CNF['FIELD_ID']]);
  416. }
  417. public function alertAfterAdd($aContentInfo)
  418. {
  419. $CNF = &$this->_oConfig->CNF;
  420. $iId = (int)$aContentInfo[$CNF['FIELD_ID']];
  421. $iAuthorId = (int)$aContentInfo[$CNF['FIELD_AUTHOR']];
  422. $sAction = 'added';
  423. if(isset($CNF['FIELD_STATUS']) && isset($aContentInfo[$CNF['FIELD_STATUS']]) && $aContentInfo[$CNF['FIELD_STATUS']] == BX_BASE_MOD_TEXT_STATUS_AWAITING)
  424. $sAction = 'deferred';
  425. else if(isset($CNF['FIELD_STATUS_ADMIN']) && isset($aContentInfo[$CNF['FIELD_STATUS_ADMIN']]) && $aContentInfo[$CNF['FIELD_STATUS_ADMIN']] == BX_BASE_MOD_GENERAL_STATUS_PENDING)
  426. $sAction = 'deferred';
  427. $aParams = $this->_alertParamsAdd($aContentInfo);
  428. /**
  429. * @hooks
  430. * @hookdef hook-system-prepare_alert_params 'system', 'prepare_alert_params' - hook to override alert (hook) params
  431. * - $unit_name - equals `system`
  432. * - $action - equals `prepare_alert_params`
  433. * - $object_id - not used
  434. * - $sender_id - not used
  435. * - $extra_params - array of additional params with the following array keys:
  436. * - `unit` - [string] unit name
  437. * - `action` - [string] by ref, action, can be overridden in hook processing
  438. * - `object_id` - [int] by ref, object id, can be overridden in hook processing
  439. * - `sender_id` - [int] by ref, action performer profile id, can be overridden in hook processing
  440. * - `extras` - [array] by ref, extra params array as key&value pairs, can be overridden in hook processing
  441. * @hook @ref hook-system-prepare_alert_params
  442. */
  443. bx_alert('system', 'prepare_alert_params', 0, 0, [
  444. 'unit'=> $this->getName(),
  445. 'action' => &$sAction,
  446. 'object_id' => &$iId,
  447. 'sender_id' => &$iAuthorId,
  448. 'extras' => &$aParams,
  449. 'action_ref' => &$sAction,
  450. 'object_id_ref' => &$iId,
  451. 'sender_id_ref' => &$iAuthorId,
  452. 'extras_ref' => &$aParams
  453. ]);
  454. /**
  455. * @hooks
  456. * @hookdef hook-bx_base_text-added '{module_name}', 'added' - hook after content was added (published)
  457. * - $unit_name - module name
  458. * - $action - equals `added`
  459. * - $object_id - content id
  460. * - $sender_id - content author profile id
  461. * - $extra_params - array of additional params with the following array keys:
  462. * - `status` - [string] content status
  463. * - `status_admin` - [string] content admin status
  464. * - `privacy_view` - [int] or [string] privacy for view content action, @see BxDolPrivacy
  465. * - `cf` - [int] content's audience filter value
  466. * @hook @ref hook-bx_base_text-added
  467. */
  468. /**
  469. * @hooks
  470. * @hookdef hook-bx_base_text-deferred '{module_name}', 'deferred' - hook after content was added with pending approval status
  471. * It's equivalent to @ref hook-bx_base_text-added
  472. * @hook @ref hook-bx_base_text-deferred
  473. */
  474. bx_alert($this->getName(), $sAction, $iId, $iAuthorId, $aParams);
  475. $this->_processModerationNotifications($aContentInfo);
  476. }
  477. public function alertAfterEdit($aContentInfo)
  478. {
  479. $CNF = &$this->_oConfig->CNF;
  480. $iId = (int)$aContentInfo[$CNF['FIELD_ID']];
  481. $aParams = $this->_alertParamsEdit($aContentInfo);
  482. /**
  483. * @hooks
  484. * @hookdef hook-bx_base_text-edited '{module_name}', 'edited' - hook after content was changed
  485. * It's equivalent to @ref hook-bx_base_text-added
  486. * @hook @ref hook-bx_base_text-edited
  487. */
  488. bx_alert($this->getName(), 'edited', $iId, false, $aParams);
  489. }
  490. /**
  491. * Get array of params to be passed in Add/Edit Alert.
  492. */
  493. protected function _alertParams($aContentInfo)
  494. {
  495. $aParams = parent::_alertParams($aContentInfo);
  496. $CNF = &$this->_oConfig->CNF;
  497. if(!empty($CNF['FIELD_STATUS']) && isset($aContentInfo[$CNF['FIELD_STATUS']]))
  498. $aParams['status'] = $aContentInfo[$CNF['FIELD_STATUS']];
  499. if(!empty($CNF['FIELD_STATUS_ADMIN']) && isset($aContentInfo[$CNF['FIELD_STATUS_ADMIN']]))
  500. $aParams['status_admin'] = $aContentInfo[$CNF['FIELD_STATUS_ADMIN']];
  501. if(!empty($CNF['FIELD_ALLOW_VIEW_TO']) && isset($aContentInfo[$CNF['FIELD_ALLOW_VIEW_TO']]))
  502. $aParams['privacy_view'] = $aContentInfo[$CNF['FIELD_ALLOW_VIEW_TO']];
  503. if(!empty($CNF['FIELD_CF']) && isset($aContentInfo[$CNF['FIELD_CF']]))
  504. $aParams['cf'] = $aContentInfo[$CNF['FIELD_CF']];
  505. return $aParams;
  506. }
  507. protected function _alertParamsAdd($aContentInfo)
  508. {
  509. $aParams = $this->_alertParams($aContentInfo);
  510. $CNF = &$this->_oConfig->CNF;
  511. if(!empty($CNF['OBJECT_METATAGS']))
  512. $aParams['timeline_group'] = $this->_getAlertParamTimelineGroup($aContentInfo);
  513. return $aParams;
  514. }
  515. protected function _alertParamsEdit($aContentInfo)
  516. {
  517. $aParams = $this->_alertParams($aContentInfo);
  518. $CNF = &$this->_oConfig->CNF;
  519. if(!empty($CNF['OBJECT_METATAGS']))
  520. $aParams['timeline_group'] = $this->_getAlertParamTimelineGroup($aContentInfo);
  521. return $aParams;
  522. }
  523. protected function _getAlertParamTimelineGroup($aContentInfo)
  524. {
  525. $CNF = &$this->_oConfig->CNF;
  526. return [
  527. 'by' => $this->getName() . '_' . abs((int)$aContentInfo[$CNF['FIELD_AUTHOR']]) . '_' . (int)$aContentInfo[$CNF['FIELD_ID']],
  528. 'field' => 'owner_id'
  529. ];
  530. }
  531. public function getEntryImageData($aContentInfo, $sField = 'FIELD_THUMB', $aTranscoders = array())
  532. {
  533. $CNF = &$this->_oConfig->CNF;
  534. $mResult = parent::getEntryImageData($aContentInfo, $sField, $aTranscoders);
  535. if ($mResult === false && isset($CNF['PARAM_USE_GALERY_AS_COVER']) && getParam($CNF['PARAM_USE_GALERY_AS_COVER']) == 'on'){
  536. if(!empty($CNF['OBJECT_STORAGE_PHOTOS']) && !empty($CNF['OBJECT_IMAGES_TRANSCODER_PREVIEW_PHOTOS'])){
  537. $sStorage = $CNF['OBJECT_STORAGE_PHOTOS'];
  538. $oStorage = BxDolStorage::getObjectInstance($sStorage);
  539. $aGhostFiles = $oStorage->getGhosts ($this->serviceGetContentOwnerProfileId($aContentInfo[$CNF['FIELD_ID']]), $aContentInfo[$CNF['FIELD_ID']]);
  540. if ($aGhostFiles){
  541. foreach ($aGhostFiles as $k => $a) {
  542. return array('id' => $a['id'], 'transcoder' => $CNF['OBJECT_IMAGES_TRANSCODER_PREVIEW_PHOTOS']);
  543. }
  544. }
  545. }
  546. }
  547. return $mResult;
  548. }
  549. public function decodeDataAPI($aData, $aParams = [])
  550. {
  551. $CNF = &$this->_oConfig->CNF;
  552. $sModule = $this->getName();
  553. $iId = (int)$aData[$CNF['FIELD_ID']];
  554. if(($mixedCheckResult = $this->checkAllowedView($aData)) !== CHECK_ACTION_RESULT_ALLOWED)
  555. return [
  556. 'id' => $iId,
  557. 'module' => 'sys_private',
  558. 'module_src' => $sModule,
  559. 'title' => _t('_sys_private_content'),
  560. ];
  561. $sSummary = '';
  562. if(!empty($CNF['PARAM_CHARS_SUMMARY_PLAIN'])) {
  563. $sSummary = $this->_oTemplate->getText($aData);
  564. $sSummary = BxTemplFunctions::getInstance()->getStringWithLimitedLength(strip_tags($sSummary), (int)getParam($CNF['PARAM_CHARS_SUMMARY_PLAIN']));
  565. }
  566. $aResult = [
  567. 'id' => $iId,
  568. 'module' => $sModule,
  569. 'module_title' => _t($CNF['T']['txt_sample_single']),
  570. 'added' => $aData[$CNF['FIELD_ADDED']],
  571. 'author' => $aData[$CNF['FIELD_AUTHOR']],
  572. 'author_data' => !empty($aData[$CNF['FIELD_AUTHOR']]) ? BxDolProfile::getData($aData[$CNF['FIELD_AUTHOR']]) : '',
  573. 'title' => $aData[$CNF['FIELD_TITLE']],
  574. 'url' => bx_api_get_relative_url($this->serviceGetLink($iId)),
  575. 'image' => $this->serviceGetThumb($iId),
  576. 'summary_plain' => $sSummary,
  577. ];
  578. if(isset($aParams['extended']) && $aParams['extended'] === true)
  579. $aResult['text'] = $aData[$CNF['FIELD_TEXT']];
  580. if(!empty($CNF['OBJECT_MENU_SNIPPET_META']) && ($oMetaMenu = BxDolMenu::getObjectInstance($CNF['OBJECT_MENU_SNIPPET_META'], $this->_oTemplate)) !== false) {
  581. $oMetaMenu->setContentId($iId);
  582. $aResult['meta'] = $oMetaMenu->getCodeAPI();
  583. }
  584. $this->decodeDataAPICommonFields($aResult, $aData, $aParams);
  585. return $aResult;
  586. }
  587. // ====== PROTECTED METHODS
  588. protected function _getImagesForTimelinePost($aEvent, $aContentInfo, $sUrl, $aBrowseParams = array())
  589. {
  590. $CNF = &$this->_oConfig->CNF;
  591. $aResults = parent::_getImagesForTimelinePost($aEvent, $aContentInfo, $sUrl, $aBrowseParams);
  592. if (bx_is_api())
  593. return $aResults;
  594. if (count($aResults) == 0 && isset($CNF['PARAM_USE_GALERY_AS_COVER']) && getParam($CNF['PARAM_USE_GALERY_AS_COVER']) == 'on'){
  595. $aResults = $this->_getImagesForTimelinePostAttachInner($aEvent, $aContentInfo, $sUrl, $aBrowseParams);
  596. if (count($aResults) > 1){
  597. $aResults = array_slice($aResults, 0, 1);
  598. }
  599. }
  600. return $aResults;
  601. }
  602. protected function _getImagesForTimelinePostAttach($aEvent, $aContentInfo, $sUrl, $aBrowseParams = array())
  603. {
  604. $CNF = &$this->_oConfig->CNF;
  605. $aTmp = parent::_getImagesForTimelinePost($aEvent, $aContentInfo, $sUrl, $aBrowseParams);
  606. $aResults = $this->_getImagesForTimelinePostAttachInner($aEvent, $aContentInfo, $sUrl, $aBrowseParams);
  607. if (bx_is_api())
  608. return $aResults;
  609. if (count($aTmp) == 0 && count($aResults) > 0 && isset($CNF['PARAM_USE_GALERY_AS_COVER']) && getParam($CNF['PARAM_USE_GALERY_AS_COVER']) == 'on'){
  610. $aResults = array_slice($aResults, 1);
  611. }
  612. return $aResults;
  613. }
  614. protected function _getImagesForTimelinePostAttachInner($aEvent, $aContentInfo, $sUrl, $aBrowseParams = array())
  615. {
  616. $CNF = &$this->_oConfig->CNF;
  617. $aResults = parent::_getImagesForTimelinePostAttach($aEvent, $aContentInfo, $sUrl, $aBrowseParams);
  618. if(!$this->_oConfig->isAttachmentsInTimeline() || empty($CNF['OBJECT_STORAGE_PHOTOS']) || empty($CNF['OBJECT_IMAGES_TRANSCODER_GALLERY_PHOTOS']))
  619. return $aResults;
  620. $iContentId = (int)$aContentInfo[$CNF['FIELD_ID']];
  621. $oStorage = BxDolStorage::getObjectInstance($CNF['OBJECT_STORAGE_PHOTOS']);
  622. $aGhostFiles = $oStorage->getGhosts($this->serviceGetContentOwnerProfileId($iContentId), $iContentId);
  623. if(!$aGhostFiles)
  624. return [];
  625. $oTranscoderSm = false;
  626. if(!empty($CNF['OBJECT_IMAGES_TRANSCODER_MINIATURE_PHOTOS']))
  627. $oTranscoderSm = BxDolTranscoderImage::getObjectInstance($CNF['OBJECT_IMAGES_TRANSCODER_MINIATURE_PHOTOS']);
  628. $oTranscoderMd = BxDolTranscoderImage::getObjectInstance($CNF['OBJECT_IMAGES_TRANSCODER_GALLERY_PHOTOS']);
  629. $oTranscoderXl = false;
  630. if(!empty($CNF['OBJECT_IMAGES_TRANSCODER_VIEW_PHOTOS']))
  631. $oTranscoderXl = BxDolTranscoderImage::getObjectInstance($CNF['OBJECT_IMAGES_TRANSCODER_VIEW_PHOTOS']);
  632. foreach($aGhostFiles as $k => $a) {
  633. $sPhotoSrcMd = $oTranscoderMd->getFileUrl($a['id']);
  634. if(empty($sPhotoSrcMd))
  635. continue;
  636. $sPhotoSrcSm = $oTranscoderSm !== false ? $oTranscoderSm->getFileUrl($a['id']) : '';
  637. if(!$sPhotoSrcSm)
  638. $sPhotoSrcSm = $sPhotoSrcMd;
  639. $sPhotoSrcXl = $oTranscoderXl !== false ? $oTranscoderXl->getFileUrl($a['id']) : $oStorage->getFileUrlById($a['id']);
  640. if(!$sPhotoSrcXl)
  641. $sPhotoSrcXl = $sPhotoSrcMd;
  642. if (bx_is_api()){
  643. $aResults[] = bx_api_get_image($CNF['OBJECT_STORAGE_PHOTOS'], (int)$a['id']);
  644. }
  645. else{
  646. $aResults[] = [
  647. 'id' => $a['id'],
  648. 'src' => $sPhotoSrcMd,
  649. 'src_small' => $sPhotoSrcSm,
  650. 'src_medium' => $sPhotoSrcMd,
  651. 'src_orig' => $sPhotoSrcXl,
  652. ];
  653. }
  654. }
  655. return $aResults;
  656. }
  657. protected function _getVideosForTimelinePostAttach($aEvent, $aContentInfo, $sUrl, $aBrowseParams = array())
  658. {
  659. $CNF = &$this->_oConfig->CNF;
  660. $aResults = parent::_getVideosForTimelinePostAttach($aEvent, $aContentInfo, $sUrl, $aBrowseParams);
  661. if(!$this->_oConfig->isAttachmentsInTimeline() || empty($CNF['OBJECT_STORAGE_VIDEOS']) || empty($CNF['OBJECT_VIDEOS_TRANSCODERS']))
  662. return $aResults;
  663. $iContentId = (int)$aContentInfo[$CNF['FIELD_ID']];
  664. $oStorage = BxDolStorage::getObjectInstance($CNF['OBJECT_STORAGE_VIDEOS']);
  665. $aGhostFiles = $oStorage->getGhosts($this->serviceGetContentOwnerProfileId($iContentId), $iContentId);
  666. if(!$aGhostFiles)
  667. return array();
  668. $oTcPoster = BxDolTranscoderVideo::getObjectInstance($CNF['OBJECT_VIDEOS_TRANSCODERS']['poster']);
  669. $oTcMp4 = BxDolTranscoderVideo::getObjectInstance($CNF['OBJECT_VIDEOS_TRANSCODERS']['mp4']);
  670. $oTcMp4Hd = BxDolTranscoderVideo::getObjectInstance($CNF['OBJECT_VIDEOS_TRANSCODERS']['mp4_hd']);
  671. if(!$oTcPoster || !$oTcMp4 || !$oTcMp4Hd)
  672. return array();
  673. $aResults = array();
  674. foreach ($aGhostFiles as $k => $a) {
  675. $sVideoUrl = $oStorage->getFileUrlById($a['id']);
  676. $aVideoFile = $oStorage->getFile($a['id']);
  677. $sVideoUrlHd = '';
  678. if (!empty($aVideoFile['dimensions']) && $oTcMp4Hd->isProcessHD($aVideoFile['dimensions']))
  679. $sVideoUrlHd = $oTcMp4Hd->getFileUrl($a['id']);
  680. $aResults[$a['id']] = array(
  681. 'id' => $a['id'],
  682. 'src_poster' => $oTcPoster->getFileUrl($a['id']),
  683. 'src_mp4' => $oTcMp4->getFileUrl($a['id']),
  684. 'src_mp4_hd' => $sVideoUrlHd,
  685. );
  686. }
  687. return $aResults;
  688. }
  689. protected function _getFilesForTimelinePostAttach($aEvent, $aContentInfo, $sUrl, $aBrowseParams = array())
  690. {
  691. $CNF = &$this->_oConfig->CNF;
  692. $aResults = parent::_getFilesForTimelinePostAttach($aEvent, $aContentInfo, $sUrl, $aBrowseParams);
  693. if(!$this->_oConfig->isAttachmentsInTimeline() || empty($CNF['OBJECT_STORAGE_FILES']))
  694. return $aResults;
  695. $iContentId = (int)$aContentInfo[$CNF['FIELD_ID']];
  696. $oStorage = BxDolStorage::getObjectInstance($CNF['OBJECT_STORAGE_FILES']);
  697. $aGhostFiles = $oStorage->getGhosts($this->serviceGetContentOwnerProfileId($iContentId), $iContentId);
  698. if(!$aGhostFiles)
  699. return array();
  700. $oTranscoder = null;
  701. if(!empty($CNF['OBJECT_IMAGES_TRANSCODER_GALLERY_FILES']))
  702. $oTranscoder = BxDolTranscoderImage::getObjectInstance($CNF['OBJECT_IMAGES_TRANSCODER_GALLERY_FILES']);
  703. foreach ($aGhostFiles as $k => $a) {
  704. $bImage = in_array($a['ext'], array('jpg', 'jpeg', 'png', 'gif'));
  705. $sPhotoSrc = '';
  706. if($bImage && $oTranscoder)
  707. $sPhotoSrc = $oTranscoder->getFileUrl($a['id']);
  708. if(empty($sPhotoSrc) && $oStorage)
  709. $sPhotoSrc = $this->_oTemplate->getIconUrl($oStorage->getIconNameByFileName($a['file_name']));
  710. $sUrl = $oStorage->getFileUrlById($a['id']);
  711. $aResults[] = array(
  712. 'id' => $a['id'],
  713. 'src' => $sPhotoSrc,
  714. 'src_medium' => $sPhotoSrc,
  715. 'src_orig' => $bImage ? $sUrl : '',
  716. 'url' => !$bImage ? $sUrl : ''
  717. );
  718. }
  719. return $aResults;
  720. }
  721. protected function _getContentForTimelinePost($aEvent, $aContentInfo, $aBrowseParams = array())
  722. {
  723. $aResult = parent::_getContentForTimelinePost($aEvent, $aContentInfo, $aBrowseParams);
  724. if(!$this->_oConfig->isAttachmentsInTimeline())
  725. return $aResult;
  726. $CNF = &$this->_oConfig->CNF;
  727. $bDynamic = isset($aBrowseParams['dynamic_mode']) && (bool)$aBrowseParams['dynamic_mode'] === true;
  728. if(!empty($CNF['PARAM_POLL_ENABLED']) && $CNF['PARAM_POLL_ENABLED'] == true)
  729. $aPolls = $this->_oDb->getPolls(array('type' => 'content_id', 'content_id' => (int)$aContentInfo[$CNF['FIELD_ID']]));
  730. if(!empty($aPolls) && is_array($aPolls)) {
  731. $sInclude = $this->_oTemplate->addCss(array('polls.css'), $bDynamic);
  732. $aResult['raw'] = ($bDynamic ? $sInclude : '') . $this->_oTemplate->parseHtmlByName('poll_items_embed.html', array(
  733. 'embed_url' => BX_DOL_URL_ROOT . bx_append_url_params($this->_oConfig->getBaseUri() . 'embed_polls/', array(
  734. 'id' => (int)$aContentInfo[$CNF['FIELD_ID']],
  735. 'param_switch_menu' => 0,
  736. 'param_showcase' => 1
  737. ))
  738. ));
  739. /*
  740. if((!empty($aResult['videos']) && is_array($aResult['videos'])) || (!empty($aResult['videos_attach']) && is_array($aResult['videos_attach'])))
  741. $aResult['_cache'] = false;
  742. */
  743. }
  744. return $aResult;
  745. }
  746. protected function _buildRssParams($sMode, $aArgs)
  747. {
  748. $aParams = array ();
  749. $sMode = bx_process_input($sMode);
  750. switch ($sMode) {
  751. case 'author':
  752. $aParams = array('author' => isset($aArgs[0]) ? (int)$aArgs[0] : '');
  753. break;
  754. }
  755. return $aParams;
  756. }
  757. public function serviceIsAllowedPostInContext()
  758. {
  759. return true;
  760. }
  761. /**
  762. * Delete file and story association, also file views, votes, comments, meta data are also deleted
  763. * For using in selected modules only
  764. * @param $iFileId file ID
  765. * @return true on success of false on error
  766. */
  767. protected function _serviceDeleteFileAssociations($iFileId, $aMediaInfo)
  768. {
  769. $CNF = &$this->_oConfig->CNF;
  770. if (!$this->_oDb->deassociateFileWithContent(0, $iFileId))
  771. return false;
  772. $aContentInfo = $this->_oDb->getContentInfoById($aMediaInfo['content_id']);
  773. $iSender = isLogged() ? bx_get_logged_profile_id() : $aMediaInfo['author'];
  774. $iAuthor = isset($aContentInfo[$CNF['FIELD_AUTHOR']]) ? $aContentInfo[$CNF['FIELD_AUTHOR']] : $aMediaInfo['author'];
  775. /**
  776. * @hooks
  777. * @hookdef hook-bx_base_text-media_deleted 'bx_base_text', 'media_deleted' - hook on new media deleted from story
  778. * - $unit_name - module name `bx_stories` or `bx_albums`
  779. * - $action - equals `media_deleted`
  780. * - $object_id - story_id
  781. * - $sender_id - author's profile_id
  782. * - $extra_params - array of additional params with the following array keys:
  783. * - `object_author_id` - [int] confirmation type can be none/phone/email/email_and_phone/email_or_phone
  784. * - `subobject_id` - [int] id for added media
  785. * - `media_id` - [int] id for added media
  786. * - `media_info` - [array] media info
  787. * @hook @ref hook-bx_base_text-media_deleted
  788. */
  789. bx_alert($this->getName(), 'media_deleted', $aMediaInfo['content_id'], $iSender, array(
  790. 'object_author_id' => $iAuthor,
  791. 'subobject_id' => $aMediaInfo['id'],
  792. 'media_id' => $aMediaInfo['id'],
  793. 'media_info' => $aMediaInfo,
  794. ));
  795. bx_alert($this->getName() . '_media', 'deleted', $aMediaInfo['id'], $iSender, array(
  796. 'object_id' => $aMediaInfo['content_id'],
  797. 'object_author_id' => $iAuthor,
  798. 'media_info' => $aMediaInfo,
  799. ));
  800. if (!empty($CNF['OBJECT_VIEWS_MEDIA'])) {
  801. $o = BxDolView::getObjectInstance($CNF['OBJECT_VIEWS_MEDIA'], $aMediaInfo['id']);
  802. if ($o) $o->onObjectDelete();
  803. }
  804. if (!empty($CNF['OBJECT_VOTES_MEDIA'])) {
  805. $o = BxDolVote::getObjectInstance($CNF['OBJECT_VOTES_MEDIA'], $aMediaInfo['id']);
  806. if ($o) $o->onObjectDelete();
  807. }
  808. if (!empty($CNF['OBJECT_SCORES_MEDIA'])) {
  809. $o = BxDolScore::getObjectInstance($CNF['OBJECT_SCORES_MEDIA'], $aMediaInfo['id']);
  810. if ($o) $o->onObjectDelete();
  811. }
  812. if (!empty($CNF['OBJECT_COMMENTS_MEDIA'])) {
  813. $o = BxDolCmts::getObjectInstance($CNF['OBJECT_COMMENTS_MEDIA'], $aMediaInfo['id']);
  814. if ($o) $o->onObjectDelete();
  815. }
  816. return true;
  817. }
  818. }
  819. /** @} */