BxBaseModTextModule.php 33 KB

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