BxBaseModTextModule.php 33 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919
  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_PENDING', 'pending');
  14. /**
  15. * Base module class for text based modules
  16. */
  17. class BxBaseModTextModule extends BxBaseModGeneralModule implements iBxDolContentInfoService
  18. {
  19. function __construct(&$aModule)
  20. {
  21. parent::__construct($aModule);
  22. }
  23. // ====== ACTIONS METHODS
  24. public function actionEmbedPoll($iPollId = 0)
  25. {
  26. if(empty($iPollId) && bx_get('poll_id') !== false)
  27. $iPollId = (int)bx_get('poll_id');
  28. $aParams = bx_get_with_prefix('param');
  29. array_walk($aParams, function(&$sValue) {
  30. $sValue = bx_process_input($sValue);
  31. });
  32. $this->_oTemplate->embedPollItem($iPollId, $aParams);
  33. }
  34. public function actionEmbedPolls($iId = 0)
  35. {
  36. list($iContentId, $aContentInfo) = $this->_getContent($iId);
  37. if($iContentId === false)
  38. return;
  39. $aParams = bx_get_with_prefix('param');
  40. array_walk($aParams, function(&$sValue) {
  41. $sValue = bx_process_input($sValue);
  42. });
  43. $this->_oTemplate->embedPollItems($aContentInfo, $aParams);
  44. }
  45. public function actionGetPoll()
  46. {
  47. $iPollId = (int)bx_get('poll_id');
  48. $sView = bx_process_input(bx_get('view'));
  49. $sMethod = 'serviceGetBlockPoll' . bx_gen_method_name($sView);
  50. if(!method_exists($this, $sMethod))
  51. return echoJson(array());
  52. $aBlock = $this->$sMethod($iPollId, true);
  53. if(empty($aBlock) || !is_array($aBlock))
  54. return echoJson(array());
  55. return echoJson(array(
  56. 'content' => $aBlock['content']
  57. ));
  58. }
  59. public function actionDeletePoll()
  60. {
  61. $CNF = &$this->_oConfig->CNF;
  62. $iId = bx_process_input(bx_get('id'), BX_DATA_INT);
  63. if(empty($iId))
  64. return echoJson(array());
  65. $aResult = array();
  66. if($this->_oDb->deletePolls(array($CNF['FIELD_POLL_ID'] => $iId)))
  67. $aResult = array('code' => 0);
  68. else
  69. $aResult = array('code' => 1, 'message' => _t($CNF['txt_err_cannot_perform_action']));
  70. echoJson($aResult);
  71. }
  72. public function actionGetPollForm()
  73. {
  74. echo $this->_oTemplate->getPollForm();
  75. }
  76. public function actionSubmitPollForm()
  77. {
  78. echoJson($this->getPollForm());
  79. }
  80. public function actionFileEmbedVideo($iFileId)
  81. {
  82. $this->_oTemplate->embedVideo($iFileId);
  83. }
  84. public function actionFileEmbedSound($iFileId)
  85. {
  86. $this->_oTemplate->embedSound($iFileId);
  87. }
  88. public function actionApprove()
  89. {
  90. $CNF = &$this->_oConfig->CNF;
  91. if(!isset($CNF['FIELD_STATUS_ADMIN']))
  92. return echoJson(array());
  93. $iContentId = (int)bx_get('content_id');
  94. $aContentInfo = $this->_oDb->getContentInfoById($iContentId);
  95. if(empty($aContentInfo) || !is_array($aContentInfo) || $aContentInfo[$CNF['FIELD_STATUS_ADMIN']] != BX_BASE_MOD_TEXT_STATUS_PENDING)
  96. return echoJson(array());
  97. $oForm = $this->_getApproveForm($iContentId, $aContentInfo);
  98. $oForm->initChecker();
  99. if(!$oForm->isSubmitted() || !$oForm->isValid()) {
  100. $sPopupId = $this->getName() . '_approve_' . $iContentId;
  101. $sPopupTitle = !empty($CNF['T']['txt_approve_popup_title']) ? $CNF['T']['txt_approve_popup_title'] : '_sys_manage_popup_approve_title';
  102. return echoJson(array('popup' => BxTemplFunctions::getInstance()->popupBox($sPopupId, _t($sPopupTitle), $oForm->getCode(true))));
  103. }
  104. if($oForm->getCleanValue('do_send')) {
  105. $aResult = array();
  106. if($this->_sendApproveMessage($iContentId, $aContentInfo, $oForm))
  107. $aResult = array('msg' => _t('_sys_manage_txt_sent'));
  108. else
  109. $aResult = array('msg' => _t('_sys_manage_err_cannot_perform_action'));
  110. return echoJson($aResult);
  111. }
  112. if($oForm->getCleanValue('do_submit')) {
  113. $aResult = array();
  114. if($this->_oDb->updateEntriesBy(array($CNF['FIELD_STATUS_ADMIN'] => BX_BASE_MOD_TEXT_STATUS_ACTIVE), array($CNF['FIELD_ID'] => $iContentId))) {
  115. $this->onApprove($aContentInfo);
  116. $aResult = array('msg' => _t('_sys_manage_txt_approved'), 'reload' => 1);
  117. }
  118. else
  119. $aResult = array('msg' => _t('_sys_manage_err_cannot_perform_action'));
  120. return echoJson($aResult);
  121. }
  122. }
  123. // ====== SERVICE METHODS
  124. public function serviceGetSafeServices()
  125. {
  126. $a = parent::serviceGetSafeServices();
  127. return array_merge($a, array (
  128. 'GetBlockPollAnswers' => '',
  129. 'GetBlockPollResults' => '',
  130. 'GetMenuAddonManageToolsProfileStats' => '',
  131. 'BrowsePublic' => '',
  132. 'BrowsePopular' => '',
  133. 'BrowseTop' => '',
  134. 'BrowseUpdated' => '',
  135. 'BrowseAuthor' => '',
  136. 'CategoriesMultiList' => ''
  137. ));
  138. }
  139. /**
  140. * @page service Service Calls
  141. * @section bx_base_text Base Text
  142. * @subsection bx_base_text-polls Polls Blocks
  143. * @subsubsection bx_base_text-get_block_poll_answers get_block_poll_answers
  144. *
  145. * @code bx_srv('bx_posts', 'get_block_poll_answers', [...]); @endcode
  146. *
  147. * Get block with poll answers
  148. * @param $iPollId poll ID
  149. *
  150. * @see BxBaseModTextModule::serviceGetBlockPollAnswers
  151. */
  152. /**
  153. * @ref bx_base_text-get_block_poll_answers "get_block_poll_answers"
  154. */
  155. public function serviceGetBlockPollAnswers($iPollId, $bForceDisplay = false)
  156. {
  157. if(!$iPollId)
  158. return false;
  159. if(!$bForceDisplay && $this->isPollPerformed($iPollId))
  160. return $this->serviceGetBlockPollResults($iPollId);
  161. return $this->_serviceTemplateFunc('entryPollAnswers', $iPollId, 'getPollInfoById');
  162. }
  163. /**
  164. * @page service Service Calls
  165. * @section bx_base_text Base Text
  166. * @subsection bx_base_text-polls Polls Blocks
  167. * @subsubsection bx_base_text-get_block_poll_results get_block_poll_results
  168. *
  169. * @code bx_srv('bx_posts', 'get_block_poll_results', [...]); @endcode
  170. *
  171. * Get block with poll results
  172. * @param $iPollId poll ID
  173. *
  174. * @see BxBaseModTextModule::serviceGetBlockPollResults
  175. */
  176. /**
  177. * @ref bx_base_text-get_block_poll_results "get_block_poll_results"
  178. */
  179. public function serviceGetBlockPollResults($iPollId)
  180. {
  181. return $this->_serviceTemplateFunc('entryPollResults', $iPollId, 'getPollInfoById');
  182. }
  183. /**
  184. * Display media EXIF information.
  185. * @param $iMediaId media ID, if it's omitted then it's taken from 'id' GET variable.
  186. * @return HTML string with EXIF info. On error empty string is returned.
  187. */
  188. public function serviceMediaExif ($iMediaId = 0)
  189. {
  190. $CNF = &$this->_oConfig->CNF;
  191. return $this->_serviceTemplateFunc ('mediaExif', $iMediaId, $CNF['FUNCTION_FOR_GET_ITEM_INFO']);
  192. }
  193. public function serviceGetThumb ($iContentId, $sTranscoder = '')
  194. {
  195. $CNF = &$this->_oConfig->CNF;
  196. if(empty($sTranscoder) && !empty($CNF['OBJECT_IMAGES_TRANSCODER_GALLERY']))
  197. $sTranscoder = $CNF['OBJECT_IMAGES_TRANSCODER_GALLERY'];
  198. $mixedResult = $this->_getFieldValueThumb('FIELD_THUMB', $iContentId, $sTranscoder);
  199. return $mixedResult !== false ? $mixedResult : '';
  200. }
  201. public function serviceGetMenuAddonManageTools()
  202. {
  203. bx_import('SearchResult', $this->_aModule);
  204. $sClass = $this->_aModule['class_prefix'] . 'SearchResult';
  205. $o = new $sClass();
  206. $o->unsetPaginate();
  207. $iNumTotal = $o->getNum();
  208. $o->fillFilters(array(
  209. 'status' => 'hidden'
  210. ));
  211. $iNum1 = $o->getNum();
  212. $iNum2 = 0;
  213. $CNF = &$this->_oConfig->CNF;
  214. if (isset($CNF['OBJECT_REPORTS'])){
  215. $o->fillFilters(array('status' => ''));
  216. $o->fillFiltersByObjects(array('reported' => array('value' => '0', 'field' => 'reports', 'operator' => '>')));
  217. $iNum2 = $o->getNum();
  218. }
  219. return array('counter1_value' => $iNum1, 'counter2_value' => $iNum2, 'counter3_value' => $iNumTotal );
  220. }
  221. /**
  222. * @page service Service Calls
  223. * @section bx_base_text Base Text
  224. * @subsection bx_base_text-other Other
  225. * @subsubsection bx_base_text-get_menu_addon_manage_tools_profile_stats get_menu_addon_manage_tools_profile_stats
  226. *
  227. * @code bx_srv('bx_posts', 'get_menu_addon_manage_tools_profile_stats', []); @endcode
  228. *
  229. * Get number of posts for currently logged in user
  230. *
  231. * @see BxBaseModTextModule::serviceGetMenuAddonManageToolsProfileStats
  232. */
  233. /**
  234. * @ref bx_base_text-get_menu_addon_manage_tools_profile_stats "get_menu_addon_manage_tools_profile_stats"
  235. */
  236. public function serviceGetMenuAddonManageToolsProfileStats()
  237. {
  238. bx_import('SearchResult', $this->_aModule);
  239. $sClass = $this->_aModule['class_prefix'] . 'SearchResult';
  240. $o = new $sClass();
  241. $o->fillFilters(array(
  242. 'author' => bx_get_logged_profile_id()
  243. ));
  244. $o->unsetPaginate();
  245. return $o->getNum();
  246. }
  247. /**
  248. * @page service Service Calls
  249. * @section bx_base_text Base Text
  250. * @subsection bx_base_text-browse Browse
  251. * @subsubsection bx_base_text-browse_public browse_public
  252. *
  253. * @code bx_srv('bx_posts', 'browse_public', [...]); @endcode
  254. *
  255. * Display public posts
  256. * @param $sUnitView unit view, such as: full, extended, gallery, showcase
  257. * @param $bEmptyMessage display or not "empty" message when there is no content
  258. * @param $bAjaxPaginate use AJAX paginate or not
  259. *
  260. * @see BxBaseModTextModule::serviceBrowsePublic
  261. */
  262. /**
  263. * @ref bx_base_text-browse_public "browse_public"
  264. */
  265. public function serviceBrowsePublic ($sUnitView = false, $bEmptyMessage = true, $bAjaxPaginate = true)
  266. {
  267. return $this->_serviceBrowse ('public', $sUnitView ? array('unit_view' => $sUnitView) : false, BX_DB_PADDING_DEF, $bEmptyMessage, $bAjaxPaginate);
  268. }
  269. /**
  270. * @page service Service Calls
  271. * @section bx_base_text Base Text
  272. * @subsection bx_base_text-browse Browse
  273. * @subsubsection bx_base_text-browse_popular browse_popular
  274. *
  275. * @code bx_srv('bx_posts', 'browse_popular', [...]); @endcode
  276. *
  277. * Display popular posts
  278. * @param $sUnitView unit view, such as: full, extended, gallery, showcase
  279. * @param $bEmptyMessage display or not "empty" message when there is no content
  280. * @param $bAjaxPaginate use AJAX paginate or not
  281. *
  282. * @see BxBaseModTextModule::serviceBrowsePopular
  283. */
  284. /**
  285. * @ref bx_base_text-browse_popular "browse_popular"
  286. */
  287. public function serviceBrowsePopular ($sUnitView = false, $bEmptyMessage = true, $bAjaxPaginate = true)
  288. {
  289. return $this->_serviceBrowse ('popular', $sUnitView ? array('unit_view' => $sUnitView) : false, BX_DB_PADDING_DEF, $bEmptyMessage, $bAjaxPaginate);
  290. }
  291. /**
  292. * @page service Service Calls
  293. * @section bx_base_text Base Text
  294. * @subsection bx_base_text-browse Browse
  295. * @subsubsection bx_base_text-browse_top browse_top
  296. *
  297. * @code bx_srv('bx_posts', 'browse_top', [...]); @endcode
  298. *
  299. * Display top posts
  300. * @param $sUnitView unit view, such as: full, extended, gallery, showcase
  301. * @param $bEmptyMessage display or not "empty" message when there is no content
  302. * @param $bAjaxPaginate use AJAX paginate or not
  303. *
  304. * @see BxBaseModTextModule::serviceBrowseTop
  305. */
  306. /**
  307. * @ref bx_base_text-browse_top "browse_top"
  308. */
  309. public function serviceBrowseTop ($sUnitView = false, $bEmptyMessage = true, $bAjaxPaginate = true)
  310. {
  311. return $this->_serviceBrowse ('top', $sUnitView ? array('unit_view' => $sUnitView) : false, BX_DB_PADDING_DEF, $bEmptyMessage, $bAjaxPaginate);
  312. }
  313. /**
  314. * @page service Service Calls
  315. * @section bx_base_text Base Text
  316. * @subsection bx_base_text-browse Browse
  317. * @subsubsection bx_base_text-browse_updated browse_updated
  318. *
  319. * @code bx_srv('bx_posts', 'browse_updated', [...]); @endcode
  320. *
  321. * Display recently updated posts
  322. * @param $sUnitView unit view, such as: full, extended, gallery, showcase
  323. * @param $bEmptyMessage display or not "empty" message when there is no content
  324. * @param $bAjaxPaginate use AJAX paginate or not
  325. *
  326. * @see BxBaseModTextModule::serviceBrowseUpdated
  327. */
  328. /**
  329. * @ref bx_base_text-browse_updated "browse_updated"
  330. */
  331. public function serviceBrowseUpdated ($sUnitView = false, $bEmptyMessage = true, $bAjaxPaginate = true)
  332. {
  333. return $this->_serviceBrowse ('updated', $sUnitView ? array('unit_view' => $sUnitView) : false, BX_DB_PADDING_DEF, $bEmptyMessage, $bAjaxPaginate);
  334. }
  335. /**
  336. * @page service Service Calls
  337. * @section bx_base_text Base Text
  338. * @subsection bx_base_text-browse Browse
  339. * @subsubsection bx_base_text-browse_author browse_author
  340. *
  341. * @code bx_srv('bx_posts', 'browse_author', [...]); @endcode
  342. *
  343. * Display posts of specified author
  344. * @param $iProfileId profile ID
  345. * @param $aParams additional params, see BxBaseModGeneralModule::serviceBrowse
  346. *
  347. * @see BxBaseModTextModule::serviceBrowseAuthor
  348. */
  349. /**
  350. * @ref bx_base_text-browse_author "browse_author"
  351. */
  352. public function serviceBrowseAuthor ($iProfileId = 0, $aParams = array())
  353. {
  354. return $this->_serviceBrowseWithParam ('author', 'profile_id', $iProfileId, $aParams);
  355. }
  356. /**
  357. * @page service Service Calls
  358. * @section bx_base_text Base Text
  359. * @subsection bx_base_text-page_blocks Page Blocks
  360. * @subsubsection bx_base_text-entity_author entity_author
  361. *
  362. * @code bx_srv('bx_posts', 'entity_author', [...]); @endcode
  363. *
  364. * Display author block for the specified post
  365. * @param $iContentId content ID
  366. *
  367. * @see BxBaseModTextModule::serviceEntityAuthor
  368. */
  369. /**
  370. * @ref bx_base_text-entity_author "entity_author"
  371. */
  372. public function serviceEntityAuthor ($iContentId = 0)
  373. {
  374. return $this->_serviceTemplateFunc ('entryAuthor', $iContentId);
  375. }
  376. /**
  377. * @page service Service Calls
  378. * @section bx_base_text Base Text
  379. * @subsection bx_base_text-page_blocks Page Blocks
  380. * @subsubsection bx_base_text-entity_polls entity_polls
  381. *
  382. * @code bx_srv('bx_posts', 'entity_polls', [...]); @endcode
  383. *
  384. * Display polls for the specified post
  385. * @param $iContentId content ID
  386. *
  387. * @see BxBaseModTextModule::serviceEntityPolls
  388. */
  389. /**
  390. * @ref bx_base_text-entity_polls "entity_polls"
  391. */
  392. public function serviceEntityPolls ($iContentId = 0)
  393. {
  394. return $this->_serviceTemplateFunc ('entryPolls', $iContentId);
  395. }
  396. /**
  397. * @page service Service Calls
  398. * @section bx_base_text Base Text
  399. * @subsection bx_base_text-page_blocks Page Blocks
  400. * @subsubsection bx_base_text-entity_breadcrumb entity_breadcrumb
  401. *
  402. * @code bx_srv('bx_forum', 'entity_breadcrumb', [...]); @endcode
  403. *
  404. * Display breadcrumb for the specified post
  405. * @param $iContentId content ID
  406. *
  407. * @see BxBaseModTextModule::serviceEntityBreadcrumb
  408. */
  409. /**
  410. * @ref bx_base_text-entity_breadcrumb "entity_breadcrumb"
  411. */
  412. public function serviceEntityBreadcrumb ($iContentId = 0)
  413. {
  414. return $this->_serviceTemplateFunc ('entryBreadcrumb', $iContentId);
  415. }
  416. /**
  417. * Delete all content by profile
  418. * @param $iProfileId profile id
  419. * @return number of deleted items
  420. */
  421. public function serviceDeleteEntitiesByAuthor ($iProfileId)
  422. {
  423. $a = $this->_oDb->getEntriesByAuthor((int)$iProfileId);
  424. if (!$a)
  425. return 0;
  426. $iCount = 0;
  427. foreach ($a as $aContentInfo)
  428. $iCount += ('' == $this->serviceDeleteEntity($aContentInfo[$this->_oConfig->CNF['FIELD_ID']]) ? 1 : 0);
  429. return $iCount;
  430. }
  431. // ====== PERMISSION METHODS
  432. /**
  433. * @return CHECK_ACTION_RESULT_ALLOWED if access is granted or error message if access is forbidden. So make sure to make strict(===) checking.
  434. */
  435. public function checkAllowedSetThumb ($iContentId = 0)
  436. {
  437. // check ACL
  438. $aCheck = checkActionModule($this->_iProfileId, 'set thumb', $this->getName(), false);
  439. if ($aCheck[CHECK_ACTION_RESULT] !== CHECK_ACTION_RESULT_ALLOWED)
  440. return $aCheck[CHECK_ACTION_MESSAGE];
  441. return CHECK_ACTION_RESULT_ALLOWED;
  442. }
  443. public function isAllowedApprove($mixedContent, $isPerformAction = false)
  444. {
  445. return $this->checkAllowedApprove($mixedContent, $isPerformAction) === CHECK_ACTION_RESULT_ALLOWED;
  446. }
  447. public function checkAllowedApprove($mixedContent, $isPerformAction = false)
  448. {
  449. $CNF = &$this->_oConfig->CNF;
  450. $sTxtError = '_sys_txt_access_denied';
  451. if(!is_array($mixedContent))
  452. $mixedContent = $this->_oDb->getContentInfoById((int)$mixedContent);
  453. if(empty($mixedContent) || !is_array($mixedContent))
  454. return _t($sTxtError);
  455. if(!isset($CNF['FIELD_STATUS_ADMIN']) || $mixedContent[$CNF['FIELD_STATUS_ADMIN']] != BX_BASE_MOD_TEXT_STATUS_PENDING)
  456. return _t($sTxtError);
  457. if($this->_isModerator())
  458. return CHECK_ACTION_RESULT_ALLOWED;
  459. return _t($sTxtError);
  460. }
  461. public function isPollPerformed($iObjectId, $iAuthorId = 0, $iAuthorIp = 0)
  462. {
  463. if(empty($iAuthorId)) {
  464. $iAuthorId = bx_get_logged_profile_id();
  465. $iAuthorIp = ip2long(getVisitorIP());
  466. }
  467. return $this->_oDb->isPollPerformed($iObjectId, $iAuthorId, $iAuthorIp);
  468. }
  469. // ====== COMMON METHODS
  470. public function onApprove($mixedContent)
  471. {
  472. if(!is_array($mixedContent))
  473. $mixedContent = $this->_oDb->getContentInfoById((int)$mixedContent);
  474. $this->alertAfterApprove($mixedContent);
  475. }
  476. public function alertAfterAdd($aContentInfo)
  477. {
  478. $CNF = &$this->_oConfig->CNF;
  479. $iId = (int)$aContentInfo[$CNF['FIELD_ID']];
  480. $iAuthorId = (int)$aContentInfo[$CNF['FIELD_AUTHOR']];
  481. $sAction = 'added';
  482. if(isset($CNF['FIELD_STATUS']) && isset($aContentInfo[$CNF['FIELD_STATUS']]) && $aContentInfo[$CNF['FIELD_STATUS']] == 'awaiting')
  483. $sAction = 'deferred';
  484. $aParams = $this->_alertParamsAdd($aContentInfo);
  485. bx_alert('system', 'prepare_alert_params', 0, 0, array('unit'=> $this->getName(), 'action' => $sAction, 'object_id' => $iId, 'sender_id' => $iAuthorId, 'extras' => &$aParams));
  486. bx_alert($this->getName(), $sAction, $iId, $iAuthorId, $aParams);
  487. }
  488. public function alertAfterEdit($aContentInfo)
  489. {
  490. $CNF = &$this->_oConfig->CNF;
  491. $iId = (int)$aContentInfo[$CNF['FIELD_ID']];
  492. $aParams = $this->_alertParams($aContentInfo);
  493. bx_alert($this->getName(), 'edited', $iId, false, $aParams);
  494. }
  495. public function alertAfterApprove($aContentInfo)
  496. {
  497. $CNF = &$this->_oConfig->CNF;
  498. $iId = (int)$aContentInfo[$CNF['FIELD_ID']];
  499. $aParams = $this->_alertParams($aContentInfo);
  500. bx_alert($this->getName(), 'approved', $iId, false, $aParams);
  501. }
  502. /**
  503. * Get array of params to be passed in Add/Edit Alert.
  504. */
  505. protected function _alertParams($aContentInfo)
  506. {
  507. $aParams = parent::_alertParams($aContentInfo);
  508. $CNF = &$this->_oConfig->CNF;
  509. if(!empty($CNF['FIELD_ALLOW_VIEW_TO']) && isset($aContentInfo[$CNF['FIELD_ALLOW_VIEW_TO']]))
  510. $aParams['privacy_view'] = $aContentInfo[$CNF['FIELD_ALLOW_VIEW_TO']];
  511. return $aParams;
  512. }
  513. protected function _alertParamsAdd($aContentInfo)
  514. {
  515. $aParams = $this->_alertParams($aContentInfo);
  516. $CNF = &$this->_oConfig->CNF;
  517. if(!empty($CNF['OBJECT_METATAGS']))
  518. $aParams['timeline_group'] = array(
  519. 'by' => $this->getName() . '_' . (int)$aContentInfo[$CNF['FIELD_AUTHOR']] . '_' . (int)$aContentInfo[$CNF['FIELD_ID']],
  520. 'field' => 'owner_id'
  521. );
  522. return $aParams;
  523. }
  524. public function isEntryActive($aContentInfo)
  525. {
  526. $CNF = &$this->_oConfig->CNF;
  527. if($aContentInfo[$CNF['FIELD_AUTHOR']] == bx_get_logged_profile_id() || $this->_isModerator())
  528. return true;
  529. if(isset($CNF['FIELD_STATUS']) && $aContentInfo[$CNF['FIELD_STATUS']] != 'active')
  530. return false;
  531. if(isset($CNF['FIELD_STATUS_ADMIN']) && $aContentInfo[$CNF['FIELD_STATUS_ADMIN']] != 'active')
  532. return false;
  533. return true;
  534. }
  535. public function getPollForm()
  536. {
  537. $CNF = &$this->_oConfig->CNF;
  538. if(empty($CNF['OBJECT_FORM_POLL']))
  539. return array('code' => 1, 'message' => '_sys_txt_error_occured');
  540. $iProfileId = bx_get_logged_profile_id();
  541. $oForm = BxDolForm::getObjectInstance($CNF['OBJECT_FORM_POLL'], $CNF['OBJECT_FORM_POLL_DISPLAY_ADD'], $this->_oTemplate);
  542. $oForm->aFormAttrs['action'] = BX_DOL_URL_ROOT . $this->_oConfig->getBaseUri() . 'submit_poll_form/';
  543. $oForm->initChecker();
  544. if($oForm->isSubmittedAndValid()) {
  545. $iId = $oForm->insert();
  546. if($iId)
  547. return array('code' => 0, 'id' => $iId, 'item' => $this->_oTemplate->getPollItem($iId, $iProfileId, array(
  548. 'manage' => true
  549. )));
  550. else
  551. return array('code' => 2, 'message' => '_sys_txt_error_entry_creation');
  552. }
  553. return array('form' => $oForm->getCode(), 'form_id' => $oForm->id);
  554. }
  555. public function getEntryImageData($aContentInfo, $sField = 'FIELD_THUMB', $aTranscoders = array())
  556. {
  557. $CNF = &$this->_oConfig->CNF;
  558. $mResult = parent::getEntryImageData($aContentInfo, $sField, $aTranscoders);
  559. if ($mResult === false && isset($CNF['PARAM_USE_GALERY_AS_COVER']) && getParam($CNF['PARAM_USE_GALERY_AS_COVER']) == 'on'){
  560. if(!empty($CNF['OBJECT_STORAGE_PHOTOS']) && !empty($CNF['OBJECT_IMAGES_TRANSCODER_PREVIEW_PHOTOS'])){
  561. $sStorage = $CNF['OBJECT_STORAGE_PHOTOS'];
  562. $oStorage = BxDolStorage::getObjectInstance($sStorage);
  563. $aGhostFiles = $oStorage->getGhosts ($this->serviceGetContentOwnerProfileId($aContentInfo[$CNF['FIELD_ID']]), $aContentInfo[$CNF['FIELD_ID']]);
  564. if ($aGhostFiles){
  565. foreach ($aGhostFiles as $k => $a) {
  566. return array('id' => $a['id'], 'transcoder' => $CNF['OBJECT_IMAGES_TRANSCODER_PREVIEW_PHOTOS']);
  567. }
  568. }
  569. }
  570. }
  571. return $mResult;
  572. }
  573. // ====== PROTECTED METHODS
  574. protected function _getApproveForm($iContentId, $aContentInfo)
  575. {
  576. $CNF = &$this->_oConfig->CNF;
  577. $sForm = 'sys_manage';
  578. if(!empty($CNF['OBJECT_FORM_MANAGE']))
  579. $sForm = $CNF['OBJECT_FORM_MANAGE'];
  580. $sFormDisplay = 'sys_manage_approve';
  581. if(!empty($CNF['OBJECT_FORM_MANAGE_APPROVE']))
  582. $sFormDisplay = $CNF['OBJECT_FORM_MANAGE_APPROVE'];
  583. $oForm = BxTemplFormView::getObjectInstance($sForm, $sFormDisplay);
  584. $oForm->aFormAttrs['action'] = BX_DOL_URL_ROOT . $this->_oConfig->getBaseUri() . 'approve';
  585. $oForm->aInputs['content_id']['value'] = $iContentId;
  586. foreach($oForm->aInputs['controls'] as $iKey => $mixedValue)
  587. if(is_numeric($iKey) && isset($mixedValue['name']) && $mixedValue['name'] == 'do_submit')
  588. $oForm->aInputs['controls'][$iKey]['value'] = _t('_sys_form_manage_input_do_submit_approve');
  589. bx_alert($this->_oConfig->getName(), 'get_approve_form', 0, 0, array(
  590. 'content_id' => $iContentId,
  591. 'content_info' => $aContentInfo,
  592. 'override_result' => &$oForm
  593. ));
  594. return $oForm;
  595. }
  596. protected function _sendApproveMessage($iContentId, $aContentInfo, &$oForm)
  597. {
  598. $CNF = &$this->_oConfig->CNF;
  599. $sETemplate = 't_ManageApprove';
  600. if(!empty($CNF['ETEMPLATE_MANAGE_APPROVE']))
  601. $sETemplate = $CNF['ETEMPLATE_MANAGE_APPROVE'];
  602. $aEParams = array(
  603. 'content_title' => !empty($CNF['FIELD_TITLE']) && !empty($aContentInfo[$CNF['FIELD_TITLE']]) ? $aContentInfo[$CNF['FIELD_TITLE']] : '',
  604. 'notes' => $oForm->getCleanValue('notes'),
  605. );
  606. bx_alert($this->_oConfig->getName(), 'get_approve_message', 0, 0, array(
  607. 'content_id' => $iContentId,
  608. 'content_info' => $aContentInfo,
  609. 'form' => $oForm,
  610. 'email_template' => &$sETemplate,
  611. 'email_params' => &$aEParams
  612. ));
  613. return sendMailTemplate($sETemplate, 0, $aContentInfo[$CNF['FIELD_AUTHOR']], $aEParams);
  614. }
  615. protected function _getImagesForTimelinePost($aEvent, $aContentInfo, $sUrl, $aBrowseParams = array())
  616. {
  617. $CNF = &$this->_oConfig->CNF;
  618. $aResults = parent::_getImagesForTimelinePost($aEvent, $aContentInfo, $sUrl, $aBrowseParams);
  619. if (count($aResults) == 0 && isset($CNF['PARAM_USE_GALERY_AS_COVER']) && getParam($CNF['PARAM_USE_GALERY_AS_COVER']) == 'on'){
  620. $aResults = $this->_getImagesForTimelinePostAttachInner($aEvent, $aContentInfo, $sUrl, $aBrowseParams);
  621. if (count($aResults) > 1){
  622. $aResults = array_slice($aResults, 0, 1);
  623. }
  624. }
  625. return $aResults;
  626. }
  627. protected function _getImagesForTimelinePostAttach($aEvent, $aContentInfo, $sUrl, $aBrowseParams = array())
  628. {
  629. $CNF = &$this->_oConfig->CNF;
  630. $aTmp = parent::_getImagesForTimelinePost($aEvent, $aContentInfo, $sUrl, $aBrowseParams);
  631. $aResults = $this->_getImagesForTimelinePostAttachInner($aEvent, $aContentInfo, $sUrl, $aBrowseParams);
  632. if (count($aTmp) == 0 && count($aResults) > 0 && isset($CNF['PARAM_USE_GALERY_AS_COVER']) && getParam($CNF['PARAM_USE_GALERY_AS_COVER']) == 'on'){
  633. $aResults = array_slice($aResults, 1);
  634. }
  635. return $aResults;
  636. }
  637. protected function _getImagesForTimelinePostAttachInner($aEvent, $aContentInfo, $sUrl, $aBrowseParams = array())
  638. {
  639. $CNF = &$this->_oConfig->CNF;
  640. $aResults = parent::_getImagesForTimelinePostAttach($aEvent, $aContentInfo, $sUrl, $aBrowseParams);
  641. if(!$this->_oConfig->isAttachmentsInTimeline() || empty($CNF['OBJECT_STORAGE_PHOTOS']) || empty($CNF['OBJECT_IMAGES_TRANSCODER_GALLERY_PHOTOS']))
  642. return $aResults;
  643. $iContentId = (int)$aContentInfo[$CNF['FIELD_ID']];
  644. $oStorage = BxDolStorage::getObjectInstance($CNF['OBJECT_STORAGE_PHOTOS']);
  645. $aGhostFiles = $oStorage->getGhosts($this->serviceGetContentOwnerProfileId($iContentId), $iContentId);
  646. if(!$aGhostFiles)
  647. return array();
  648. $oTranscoder = BxDolTranscoderImage::getObjectInstance($CNF['OBJECT_IMAGES_TRANSCODER_GALLERY_PHOTOS']);
  649. foreach ($aGhostFiles as $k => $a) {
  650. $sPhotoSrc = $oTranscoder->getFileUrl($a['id']);
  651. if(empty($sPhotoSrc))
  652. continue;
  653. $aResults[] = array(
  654. 'id' => $a['id'],
  655. 'src' => $sPhotoSrc,
  656. 'src_medium' => $sPhotoSrc,
  657. 'src_orig' => $oStorage->getFileUrlById($a['id']),
  658. );
  659. }
  660. return $aResults;
  661. }
  662. protected function _getVideosForTimelinePostAttach($aEvent, $aContentInfo, $sUrl, $aBrowseParams = array())
  663. {
  664. $CNF = &$this->_oConfig->CNF;
  665. $aResults = parent::_getVideosForTimelinePostAttach($aEvent, $aContentInfo, $sUrl, $aBrowseParams);
  666. if(!$this->_oConfig->isAttachmentsInTimeline() || empty($CNF['OBJECT_STORAGE_VIDEOS']) || empty($CNF['OBJECT_VIDEOS_TRANSCODERS']))
  667. return $aResults;
  668. $iContentId = (int)$aContentInfo[$CNF['FIELD_ID']];
  669. $oStorage = BxDolStorage::getObjectInstance($CNF['OBJECT_STORAGE_VIDEOS']);
  670. $aGhostFiles = $oStorage->getGhosts($this->serviceGetContentOwnerProfileId($iContentId), $iContentId);
  671. if(!$aGhostFiles)
  672. return array();
  673. $oTcPoster = BxDolTranscoderVideo::getObjectInstance($CNF['OBJECT_VIDEOS_TRANSCODERS']['poster']);
  674. $oTcMp4 = BxDolTranscoderVideo::getObjectInstance($CNF['OBJECT_VIDEOS_TRANSCODERS']['mp4']);
  675. $oTcMp4Hd = BxDolTranscoderVideo::getObjectInstance($CNF['OBJECT_VIDEOS_TRANSCODERS']['mp4_hd']);
  676. if(!$oTcPoster || !$oTcMp4 || !$oTcMp4Hd)
  677. return array();
  678. $aResults = array();
  679. foreach ($aGhostFiles as $k => $a) {
  680. $sVideoUrl = $oStorage->getFileUrlById($a['id']);
  681. $aVideoFile = $oStorage->getFile($a['id']);
  682. $sVideoUrlHd = '';
  683. if (!empty($aVideoFile['dimensions']) && $oTcMp4Hd->isProcessHD($aVideoFile['dimensions']))
  684. $sVideoUrlHd = $oTcMp4Hd->getFileUrl($a['id']);
  685. $aResults[$a['id']] = array(
  686. 'id' => $a['id'],
  687. 'src_poster' => $oTcPoster->getFileUrl($a['id']),
  688. 'src_mp4' => $oTcMp4->getFileUrl($a['id']),
  689. 'src_mp4_hd' => $sVideoUrlHd,
  690. );
  691. }
  692. return $aResults;
  693. }
  694. protected function _getFilesForTimelinePostAttach($aEvent, $aContentInfo, $sUrl, $aBrowseParams = array())
  695. {
  696. $CNF = &$this->_oConfig->CNF;
  697. $aResults = parent::_getFilesForTimelinePostAttach($aEvent, $aContentInfo, $sUrl, $aBrowseParams);
  698. if(!$this->_oConfig->isAttachmentsInTimeline() || empty($CNF['OBJECT_STORAGE_FILES']))
  699. return $aResults;
  700. $iContentId = (int)$aContentInfo[$CNF['FIELD_ID']];
  701. $oStorage = BxDolStorage::getObjectInstance($CNF['OBJECT_STORAGE_FILES']);
  702. $aGhostFiles = $oStorage->getGhosts($this->serviceGetContentOwnerProfileId($iContentId), $iContentId);
  703. if(!$aGhostFiles)
  704. return array();
  705. $oTranscoder = null;
  706. if(!empty($CNF['OBJECT_IMAGES_TRANSCODER_GALLERY_FILES']))
  707. $oTranscoder = BxDolTranscoderImage::getObjectInstance($CNF['OBJECT_IMAGES_TRANSCODER_GALLERY_FILES']);
  708. foreach ($aGhostFiles as $k => $a) {
  709. $bImage = in_array($a['ext'], array('jpg', 'jpeg', 'png', 'gif'));
  710. $sPhotoSrc = '';
  711. if($bImage && $oTranscoder)
  712. $sPhotoSrc = $oTranscoder->getFileUrl($a['id']);
  713. if(empty($sPhotoSrc) && $oStorage)
  714. $sPhotoSrc = $this->_oTemplate->getIconUrl($oStorage->getIconNameByFileName($a['file_name']));
  715. $sUrl = $oStorage->getFileUrlById($a['id']);
  716. $aResults[] = array(
  717. 'id' => $a['id'],
  718. 'src' => $sPhotoSrc,
  719. 'src_medium' => $sPhotoSrc,
  720. 'src_orig' => $bImage ? $sUrl : '',
  721. 'url' => !$bImage ? $sUrl : ''
  722. );
  723. }
  724. return $aResults;
  725. }
  726. protected function _getContentForTimelinePost($aEvent, $aContentInfo, $aBrowseParams = array())
  727. {
  728. $aResult = parent::_getContentForTimelinePost($aEvent, $aContentInfo, $aBrowseParams);
  729. if(!$this->_oConfig->isAttachmentsInTimeline())
  730. return $aResult;
  731. $CNF = &$this->_oConfig->CNF;
  732. $bDynamic = isset($aBrowseParams['dynamic_mode']) && (bool)$aBrowseParams['dynamic_mode'] === true;
  733. if(!empty($CNF['PARAM_POLL_ENABLED']) && $CNF['PARAM_POLL_ENABLED'] == true)
  734. $aPolls = $this->_oDb->getPolls(array('type' => 'content_id', 'content_id' => (int)$aContentInfo[$CNF['FIELD_ID']]));
  735. if(!empty($aPolls) && is_array($aPolls)) {
  736. $sInclude = $this->_oTemplate->addCss(array('polls.css'), $bDynamic);
  737. $aResult['raw'] = ($bDynamic ? $sInclude : '') . $this->_oTemplate->parseHtmlByName('poll_items_embed.html', array(
  738. 'embed_url' => BX_DOL_URL_ROOT . bx_append_url_params($this->_oConfig->getBaseUri() . 'embed_polls/', array(
  739. 'id' => (int)$aContentInfo[$CNF['FIELD_ID']],
  740. 'param_switch_menu' => 0,
  741. 'param_showcase' => 1
  742. ))
  743. ));
  744. /*
  745. if((!empty($aResult['videos']) && is_array($aResult['videos'])) || (!empty($aResult['videos_attach']) && is_array($aResult['videos_attach'])))
  746. $aResult['_cache'] = false;
  747. */
  748. }
  749. return $aResult;
  750. }
  751. protected function _buildRssParams($sMode, $aArgs)
  752. {
  753. $aParams = array ();
  754. $sMode = bx_process_input($sMode);
  755. switch ($sMode) {
  756. case 'author':
  757. $aParams = array('author' => isset($aArgs[0]) ? (int)$aArgs[0] : '');
  758. break;
  759. }
  760. return $aParams;
  761. }
  762. }
  763. /** @} */