BxBaseModTextModule.php 37 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040
  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. }
  647. public function alertAfterEdit($aContentInfo)
  648. {
  649. $CNF = &$this->_oConfig->CNF;
  650. $iId = (int)$aContentInfo[$CNF['FIELD_ID']];
  651. $aParams = $this->_alertParams($aContentInfo);
  652. bx_alert($this->getName(), 'edited', $iId, false, $aParams);
  653. }
  654. /**
  655. * Get array of params to be passed in Add/Edit Alert.
  656. */
  657. protected function _alertParams($aContentInfo)
  658. {
  659. $aParams = parent::_alertParams($aContentInfo);
  660. $CNF = &$this->_oConfig->CNF;
  661. if(!empty($CNF['FIELD_ALLOW_VIEW_TO']) && isset($aContentInfo[$CNF['FIELD_ALLOW_VIEW_TO']]))
  662. $aParams['privacy_view'] = $aContentInfo[$CNF['FIELD_ALLOW_VIEW_TO']];
  663. if(!empty($CNF['FIELD_CF']) && isset($aContentInfo[$CNF['FIELD_CF']]))
  664. $aParams['cf'] = $aContentInfo[$CNF['FIELD_CF']];
  665. return $aParams;
  666. }
  667. protected function _alertParamsAdd($aContentInfo)
  668. {
  669. $aParams = $this->_alertParams($aContentInfo);
  670. $CNF = &$this->_oConfig->CNF;
  671. if(!empty($CNF['OBJECT_METATAGS']))
  672. $aParams['timeline_group'] = array(
  673. 'by' => $this->getName() . '_' . (int)$aContentInfo[$CNF['FIELD_AUTHOR']] . '_' . (int)$aContentInfo[$CNF['FIELD_ID']],
  674. 'field' => 'owner_id'
  675. );
  676. return $aParams;
  677. }
  678. public function getPollForm()
  679. {
  680. $CNF = &$this->_oConfig->CNF;
  681. if(empty($CNF['OBJECT_FORM_POLL']))
  682. return array('code' => 1, 'message' => '_sys_txt_error_occured');
  683. $iProfileId = bx_get_logged_profile_id();
  684. $oForm = BxDolForm::getObjectInstance($CNF['OBJECT_FORM_POLL'], $CNF['OBJECT_FORM_POLL_DISPLAY_ADD'], $this->_oTemplate);
  685. $oForm->aFormAttrs['action'] = BX_DOL_URL_ROOT . $this->_oConfig->getBaseUri() . 'submit_poll_form/';
  686. $oForm->initChecker();
  687. if($oForm->isSubmittedAndValid()) {
  688. $iId = $oForm->insert();
  689. if($iId)
  690. return array('code' => 0, 'id' => $iId, 'item' => $this->_oTemplate->getPollItem($iId, $iProfileId, array(
  691. 'manage' => true
  692. )));
  693. else
  694. return array('code' => 2, 'message' => '_sys_txt_error_entry_creation');
  695. }
  696. return array('form' => $oForm->getCode(), 'form_id' => $oForm->id);
  697. }
  698. public function getEntryImageData($aContentInfo, $sField = 'FIELD_THUMB', $aTranscoders = array())
  699. {
  700. $CNF = &$this->_oConfig->CNF;
  701. $mResult = parent::getEntryImageData($aContentInfo, $sField, $aTranscoders);
  702. if ($mResult === false && isset($CNF['PARAM_USE_GALERY_AS_COVER']) && getParam($CNF['PARAM_USE_GALERY_AS_COVER']) == 'on'){
  703. if(!empty($CNF['OBJECT_STORAGE_PHOTOS']) && !empty($CNF['OBJECT_IMAGES_TRANSCODER_PREVIEW_PHOTOS'])){
  704. $sStorage = $CNF['OBJECT_STORAGE_PHOTOS'];
  705. $oStorage = BxDolStorage::getObjectInstance($sStorage);
  706. $aGhostFiles = $oStorage->getGhosts ($this->serviceGetContentOwnerProfileId($aContentInfo[$CNF['FIELD_ID']]), $aContentInfo[$CNF['FIELD_ID']]);
  707. if ($aGhostFiles){
  708. foreach ($aGhostFiles as $k => $a) {
  709. return array('id' => $a['id'], 'transcoder' => $CNF['OBJECT_IMAGES_TRANSCODER_PREVIEW_PHOTOS']);
  710. }
  711. }
  712. }
  713. }
  714. return $mResult;
  715. }
  716. // ====== PROTECTED METHODS
  717. protected function _getImagesForTimelinePost($aEvent, $aContentInfo, $sUrl, $aBrowseParams = array())
  718. {
  719. $CNF = &$this->_oConfig->CNF;
  720. $aResults = parent::_getImagesForTimelinePost($aEvent, $aContentInfo, $sUrl, $aBrowseParams);
  721. if (count($aResults) == 0 && isset($CNF['PARAM_USE_GALERY_AS_COVER']) && getParam($CNF['PARAM_USE_GALERY_AS_COVER']) == 'on'){
  722. $aResults = $this->_getImagesForTimelinePostAttachInner($aEvent, $aContentInfo, $sUrl, $aBrowseParams);
  723. if (count($aResults) > 1){
  724. $aResults = array_slice($aResults, 0, 1);
  725. }
  726. }
  727. return $aResults;
  728. }
  729. protected function _getImagesForTimelinePostAttach($aEvent, $aContentInfo, $sUrl, $aBrowseParams = array())
  730. {
  731. $CNF = &$this->_oConfig->CNF;
  732. $aTmp = parent::_getImagesForTimelinePost($aEvent, $aContentInfo, $sUrl, $aBrowseParams);
  733. $aResults = $this->_getImagesForTimelinePostAttachInner($aEvent, $aContentInfo, $sUrl, $aBrowseParams);
  734. if (count($aTmp) == 0 && count($aResults) > 0 && isset($CNF['PARAM_USE_GALERY_AS_COVER']) && getParam($CNF['PARAM_USE_GALERY_AS_COVER']) == 'on'){
  735. $aResults = array_slice($aResults, 1);
  736. }
  737. return $aResults;
  738. }
  739. protected function _getImagesForTimelinePostAttachInner($aEvent, $aContentInfo, $sUrl, $aBrowseParams = array())
  740. {
  741. $CNF = &$this->_oConfig->CNF;
  742. $aResults = parent::_getImagesForTimelinePostAttach($aEvent, $aContentInfo, $sUrl, $aBrowseParams);
  743. if(!$this->_oConfig->isAttachmentsInTimeline() || empty($CNF['OBJECT_STORAGE_PHOTOS']) || empty($CNF['OBJECT_IMAGES_TRANSCODER_GALLERY_PHOTOS']))
  744. return $aResults;
  745. $iContentId = (int)$aContentInfo[$CNF['FIELD_ID']];
  746. $oStorage = BxDolStorage::getObjectInstance($CNF['OBJECT_STORAGE_PHOTOS']);
  747. $aGhostFiles = $oStorage->getGhosts($this->serviceGetContentOwnerProfileId($iContentId), $iContentId);
  748. if(!$aGhostFiles)
  749. return array();
  750. $oTranscoder = BxDolTranscoderImage::getObjectInstance($CNF['OBJECT_IMAGES_TRANSCODER_GALLERY_PHOTOS']);
  751. foreach ($aGhostFiles as $k => $a) {
  752. $sPhotoSrc = $oTranscoder->getFileUrl($a['id']);
  753. if(empty($sPhotoSrc))
  754. continue;
  755. $aResults[] = array(
  756. 'id' => $a['id'],
  757. 'src' => $sPhotoSrc,
  758. 'src_medium' => $sPhotoSrc,
  759. 'src_orig' => $oStorage->getFileUrlById($a['id']),
  760. );
  761. }
  762. return $aResults;
  763. }
  764. protected function _getVideosForTimelinePostAttach($aEvent, $aContentInfo, $sUrl, $aBrowseParams = array())
  765. {
  766. $CNF = &$this->_oConfig->CNF;
  767. $aResults = parent::_getVideosForTimelinePostAttach($aEvent, $aContentInfo, $sUrl, $aBrowseParams);
  768. if(!$this->_oConfig->isAttachmentsInTimeline() || empty($CNF['OBJECT_STORAGE_VIDEOS']) || empty($CNF['OBJECT_VIDEOS_TRANSCODERS']))
  769. return $aResults;
  770. $iContentId = (int)$aContentInfo[$CNF['FIELD_ID']];
  771. $oStorage = BxDolStorage::getObjectInstance($CNF['OBJECT_STORAGE_VIDEOS']);
  772. $aGhostFiles = $oStorage->getGhosts($this->serviceGetContentOwnerProfileId($iContentId), $iContentId);
  773. if(!$aGhostFiles)
  774. return array();
  775. $oTcPoster = BxDolTranscoderVideo::getObjectInstance($CNF['OBJECT_VIDEOS_TRANSCODERS']['poster']);
  776. $oTcMp4 = BxDolTranscoderVideo::getObjectInstance($CNF['OBJECT_VIDEOS_TRANSCODERS']['mp4']);
  777. $oTcMp4Hd = BxDolTranscoderVideo::getObjectInstance($CNF['OBJECT_VIDEOS_TRANSCODERS']['mp4_hd']);
  778. if(!$oTcPoster || !$oTcMp4 || !$oTcMp4Hd)
  779. return array();
  780. $aResults = array();
  781. foreach ($aGhostFiles as $k => $a) {
  782. $sVideoUrl = $oStorage->getFileUrlById($a['id']);
  783. $aVideoFile = $oStorage->getFile($a['id']);
  784. $sVideoUrlHd = '';
  785. if (!empty($aVideoFile['dimensions']) && $oTcMp4Hd->isProcessHD($aVideoFile['dimensions']))
  786. $sVideoUrlHd = $oTcMp4Hd->getFileUrl($a['id']);
  787. $aResults[$a['id']] = array(
  788. 'id' => $a['id'],
  789. 'src_poster' => $oTcPoster->getFileUrl($a['id']),
  790. 'src_mp4' => $oTcMp4->getFileUrl($a['id']),
  791. 'src_mp4_hd' => $sVideoUrlHd,
  792. );
  793. }
  794. return $aResults;
  795. }
  796. protected function _getFilesForTimelinePostAttach($aEvent, $aContentInfo, $sUrl, $aBrowseParams = array())
  797. {
  798. $CNF = &$this->_oConfig->CNF;
  799. $aResults = parent::_getFilesForTimelinePostAttach($aEvent, $aContentInfo, $sUrl, $aBrowseParams);
  800. if(!$this->_oConfig->isAttachmentsInTimeline() || empty($CNF['OBJECT_STORAGE_FILES']))
  801. return $aResults;
  802. $iContentId = (int)$aContentInfo[$CNF['FIELD_ID']];
  803. $oStorage = BxDolStorage::getObjectInstance($CNF['OBJECT_STORAGE_FILES']);
  804. $aGhostFiles = $oStorage->getGhosts($this->serviceGetContentOwnerProfileId($iContentId), $iContentId);
  805. if(!$aGhostFiles)
  806. return array();
  807. $oTranscoder = null;
  808. if(!empty($CNF['OBJECT_IMAGES_TRANSCODER_GALLERY_FILES']))
  809. $oTranscoder = BxDolTranscoderImage::getObjectInstance($CNF['OBJECT_IMAGES_TRANSCODER_GALLERY_FILES']);
  810. foreach ($aGhostFiles as $k => $a) {
  811. $bImage = in_array($a['ext'], array('jpg', 'jpeg', 'png', 'gif'));
  812. $sPhotoSrc = '';
  813. if($bImage && $oTranscoder)
  814. $sPhotoSrc = $oTranscoder->getFileUrl($a['id']);
  815. if(empty($sPhotoSrc) && $oStorage)
  816. $sPhotoSrc = $this->_oTemplate->getIconUrl($oStorage->getIconNameByFileName($a['file_name']));
  817. $sUrl = $oStorage->getFileUrlById($a['id']);
  818. $aResults[] = array(
  819. 'id' => $a['id'],
  820. 'src' => $sPhotoSrc,
  821. 'src_medium' => $sPhotoSrc,
  822. 'src_orig' => $bImage ? $sUrl : '',
  823. 'url' => !$bImage ? $sUrl : ''
  824. );
  825. }
  826. return $aResults;
  827. }
  828. protected function _getContentForTimelinePost($aEvent, $aContentInfo, $aBrowseParams = array())
  829. {
  830. $aResult = parent::_getContentForTimelinePost($aEvent, $aContentInfo, $aBrowseParams);
  831. if(!$this->_oConfig->isAttachmentsInTimeline())
  832. return $aResult;
  833. $CNF = &$this->_oConfig->CNF;
  834. $bDynamic = isset($aBrowseParams['dynamic_mode']) && (bool)$aBrowseParams['dynamic_mode'] === true;
  835. if(!empty($CNF['PARAM_POLL_ENABLED']) && $CNF['PARAM_POLL_ENABLED'] == true)
  836. $aPolls = $this->_oDb->getPolls(array('type' => 'content_id', 'content_id' => (int)$aContentInfo[$CNF['FIELD_ID']]));
  837. if(!empty($aPolls) && is_array($aPolls)) {
  838. $sInclude = $this->_oTemplate->addCss(array('polls.css'), $bDynamic);
  839. $aResult['raw'] = ($bDynamic ? $sInclude : '') . $this->_oTemplate->parseHtmlByName('poll_items_embed.html', array(
  840. 'embed_url' => BX_DOL_URL_ROOT . bx_append_url_params($this->_oConfig->getBaseUri() . 'embed_polls/', array(
  841. 'id' => (int)$aContentInfo[$CNF['FIELD_ID']],
  842. 'param_switch_menu' => 0,
  843. 'param_showcase' => 1
  844. ))
  845. ));
  846. /*
  847. if((!empty($aResult['videos']) && is_array($aResult['videos'])) || (!empty($aResult['videos_attach']) && is_array($aResult['videos_attach'])))
  848. $aResult['_cache'] = false;
  849. */
  850. }
  851. return $aResult;
  852. }
  853. protected function _buildRssParams($sMode, $aArgs)
  854. {
  855. $aParams = array ();
  856. $sMode = bx_process_input($sMode);
  857. switch ($sMode) {
  858. case 'author':
  859. $aParams = array('author' => isset($aArgs[0]) ? (int)$aArgs[0] : '');
  860. break;
  861. }
  862. return $aParams;
  863. }
  864. }
  865. /** @} */