BxBaseModTextModule.php 37 KB

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