1
0

BxBaseModTextModule.php 32 KB

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