1
0

BxBaseModTextModule.php 41 KB

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