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()
  323. {
  324. bx_import('SearchResult', $this->_aModule);
  325. $sClass = $this->_aModule['class_prefix'] . 'SearchResult';
  326. $o = new $sClass();
  327. $o->fillFilters(array(
  328. 'author' => bx_get_logged_profile_id()
  329. ));
  330. $o->unsetPaginate();
  331. return $o->getNum();
  332. }
  333. /**
  334. * @page service Service Calls
  335. * @section bx_base_text Base Text
  336. * @subsection bx_base_text-browse Browse
  337. * @subsubsection bx_base_text-browse_public browse_public
  338. *
  339. * @code bx_srv('bx_posts', 'browse_public', [...]); @endcode
  340. *
  341. * Display public posts
  342. * @param $sUnitView unit view, such as: full, extended, gallery, showcase
  343. * @param $bEmptyMessage display or not "empty" message when there is no content
  344. * @param $bAjaxPaginate use AJAX paginate or not
  345. *
  346. * @see BxBaseModTextModule::serviceBrowsePublic
  347. */
  348. /**
  349. * @ref bx_base_text-browse_public "browse_public"
  350. */
  351. public function serviceBrowsePublic ($sUnitView = false, $bEmptyMessage = true, $bAjaxPaginate = true)
  352. {
  353. return $this->_serviceBrowse ('public', $sUnitView ? array('unit_view' => $sUnitView) : false, BX_DB_PADDING_DEF, $bEmptyMessage, $bAjaxPaginate);
  354. }
  355. /**
  356. * @page service Service Calls
  357. * @section bx_base_text Base Text
  358. * @subsection bx_base_text-browse Browse
  359. * @subsubsection bx_base_text-browse_popular browse_popular
  360. *
  361. * @code bx_srv('bx_posts', 'browse_popular', [...]); @endcode
  362. *
  363. * Display popular posts
  364. * @param $sUnitView unit view, such as: full, extended, gallery, showcase
  365. * @param $bEmptyMessage display or not "empty" message when there is no content
  366. * @param $bAjaxPaginate use AJAX paginate or not
  367. *
  368. * @see BxBaseModTextModule::serviceBrowsePopular
  369. */
  370. /**
  371. * @ref bx_base_text-browse_popular "browse_popular"
  372. */
  373. public function serviceBrowsePopular ($sUnitView = false, $bEmptyMessage = true, $bAjaxPaginate = true)
  374. {
  375. return $this->_serviceBrowse ('popular', $sUnitView ? array('unit_view' => $sUnitView) : false, BX_DB_PADDING_DEF, $bEmptyMessage, $bAjaxPaginate);
  376. }
  377. /**
  378. * @page service Service Calls
  379. * @section bx_base_text Base Text
  380. * @subsection bx_base_text-browse Browse
  381. * @subsubsection bx_base_text-browse_top browse_top
  382. *
  383. * @code bx_srv('bx_posts', 'browse_top', [...]); @endcode
  384. *
  385. * Display top posts
  386. * @param $sUnitView unit view, such as: full, extended, gallery, showcase
  387. * @param $bEmptyMessage display or not "empty" message when there is no content
  388. * @param $bAjaxPaginate use AJAX paginate or not
  389. *
  390. * @see BxBaseModTextModule::serviceBrowseTop
  391. */
  392. /**
  393. * @ref bx_base_text-browse_top "browse_top"
  394. */
  395. public function serviceBrowseTop ($sUnitView = false, $bEmptyMessage = true, $bAjaxPaginate = true)
  396. {
  397. return $this->_serviceBrowse ('top', $sUnitView ? array('unit_view' => $sUnitView) : false, BX_DB_PADDING_DEF, $bEmptyMessage, $bAjaxPaginate);
  398. }
  399. /**
  400. * @page service Service Calls
  401. * @section bx_base_text Base Text
  402. * @subsection bx_base_text-browse Browse
  403. * @subsubsection bx_base_text-browse_updated browse_updated
  404. *
  405. * @code bx_srv('bx_posts', 'browse_updated', [...]); @endcode
  406. *
  407. * Display recently updated posts
  408. * @param $sUnitView unit view, such as: full, extended, gallery, showcase
  409. * @param $bEmptyMessage display or not "empty" message when there is no content
  410. * @param $bAjaxPaginate use AJAX paginate or not
  411. *
  412. * @see BxBaseModTextModule::serviceBrowseUpdated
  413. */
  414. /**
  415. * @ref bx_base_text-browse_updated "browse_updated"
  416. */
  417. public function serviceBrowseUpdated ($sUnitView = false, $bEmptyMessage = true, $bAjaxPaginate = true)
  418. {
  419. return $this->_serviceBrowse ('updated', $sUnitView ? array('unit_view' => $sUnitView) : false, BX_DB_PADDING_DEF, $bEmptyMessage, $bAjaxPaginate);
  420. }
  421. /**
  422. * @page service Service Calls
  423. * @section bx_base_text Base Text
  424. * @subsection bx_base_text-browse Browse
  425. * @subsubsection bx_base_text-browse_author browse_author
  426. *
  427. * @code bx_srv('bx_posts', 'browse_author', [...]); @endcode
  428. *
  429. * Display posts of specified author
  430. * @param $iProfileId profile ID
  431. * @param $aParams additional params, see BxBaseModGeneralModule::serviceBrowse
  432. *
  433. * @see BxBaseModTextModule::serviceBrowseAuthor
  434. */
  435. /**
  436. * @ref bx_base_text-browse_author "browse_author"
  437. */
  438. public function serviceBrowseAuthor ($iProfileId = 0, $aParams = array())
  439. {
  440. return $this->_serviceBrowseWithParam ('author', 'profile_id', $iProfileId, $aParams);
  441. }
  442. /**
  443. * @page service Service Calls
  444. * @section bx_base_text Base Text
  445. * @subsection bx_base_text-page_blocks Page Blocks
  446. * @subsubsection bx_base_text-entity_author entity_author
  447. *
  448. * @code bx_srv('bx_posts', 'entity_author', [...]); @endcode
  449. *
  450. * Display author block for the specified post
  451. * @param $iContentId content ID
  452. *
  453. * @see BxBaseModTextModule::serviceEntityAuthor
  454. */
  455. /**
  456. * @ref bx_base_text-entity_author "entity_author"
  457. */
  458. public function serviceEntityAuthor ($iContentId = 0)
  459. {
  460. return $this->_serviceTemplateFunc ('entryAuthor', $iContentId);
  461. }
  462. /**
  463. * @page service Service Calls
  464. * @section bx_base_text Base Text
  465. * @subsection bx_base_text-page_blocks Page Blocks
  466. * @subsubsection bx_base_text-entity_polls entity_polls
  467. *
  468. * @code bx_srv('bx_posts', 'entity_polls', [...]); @endcode
  469. *
  470. * Display polls for the specified post
  471. * @param $iContentId content ID
  472. *
  473. * @see BxBaseModTextModule::serviceEntityPolls
  474. */
  475. /**
  476. * @ref bx_base_text-entity_polls "entity_polls"
  477. */
  478. public function serviceEntityPolls ($iContentId = 0)
  479. {
  480. return $this->_serviceTemplateFunc ('entryPolls', $iContentId);
  481. }
  482. /**
  483. * @page service Service Calls
  484. * @section bx_base_text Base Text
  485. * @subsection bx_base_text-page_blocks Page Blocks
  486. * @subsubsection bx_base_text-entity_breadcrumb entity_breadcrumb
  487. *
  488. * @code bx_srv('bx_forum', 'entity_breadcrumb', [...]); @endcode
  489. *
  490. * Display breadcrumb for the specified post
  491. * @param $iContentId content ID
  492. *
  493. * @see BxBaseModTextModule::serviceEntityBreadcrumb
  494. */
  495. /**
  496. * @ref bx_base_text-entity_breadcrumb "entity_breadcrumb"
  497. */
  498. public function serviceEntityBreadcrumb ($iContentId = 0)
  499. {
  500. return $this->_serviceTemplateFunc ('entryBreadcrumb', $iContentId);
  501. }
  502. /**
  503. * Delete all content by profile
  504. * @param $iProfileId profile id
  505. * @return number of deleted items
  506. */
  507. public function serviceDeleteEntitiesByAuthor ($iProfileId)
  508. {
  509. $a = $this->_oDb->getEntriesByAuthor((int)$iProfileId);
  510. if (!$a)
  511. return 0;
  512. $iCount = 0;
  513. foreach ($a as $aContentInfo)
  514. $iCount += ('' == $this->serviceDeleteEntity($aContentInfo[$this->_oConfig->CNF['FIELD_ID']]) ? 1 : 0);
  515. return $iCount;
  516. }
  517. // ====== PERMISSION METHODS
  518. /**
  519. * @return CHECK_ACTION_RESULT_ALLOWED if access is granted or error message if access is forbidden. So make sure to make strict(===) checking.
  520. */
  521. public function checkAllowedSetThumb ($iContentId = 0)
  522. {
  523. // check ACL
  524. $aCheck = checkActionModule($this->_iProfileId, 'set thumb', $this->getName(), false);
  525. if ($aCheck[CHECK_ACTION_RESULT] !== CHECK_ACTION_RESULT_ALLOWED)
  526. return $aCheck[CHECK_ACTION_MESSAGE];
  527. return CHECK_ACTION_RESULT_ALLOWED;
  528. }
  529. public function isAllowedApprove($mixedContent, $isPerformAction = false)
  530. {
  531. return $this->checkAllowedApprove($mixedContent, $isPerformAction) === CHECK_ACTION_RESULT_ALLOWED;
  532. }
  533. public function checkAllowedApprove($mixedContent, $isPerformAction = false)
  534. {
  535. $CNF = &$this->_oConfig->CNF;
  536. $sTxtError = '_sys_txt_access_denied';
  537. $iProfileId = bx_get_logged_profile_id();
  538. if(!is_array($mixedContent))
  539. $mixedContent = $this->_oDb->getContentInfoById((int)$mixedContent);
  540. if(empty($mixedContent) || !is_array($mixedContent))
  541. return _t($sTxtError);
  542. if(!isset($CNF['FIELD_STATUS_ADMIN']) || $mixedContent[$CNF['FIELD_STATUS_ADMIN']] != BX_BASE_MOD_GENERAL_STATUS_PENDING)
  543. return _t($sTxtError);
  544. if($this->_isModerator())
  545. return CHECK_ACTION_RESULT_ALLOWED;
  546. if(!empty($CNF['FIELD_ALLOW_VIEW_TO']) && (int)$mixedContent[$CNF['FIELD_ALLOW_VIEW_TO']] < 0) {
  547. $iContextProfileId = abs((int)$mixedContent[$CNF['FIELD_ALLOW_VIEW_TO']]);
  548. $oContextProfile = BxDolProfile::getInstance($iContextProfileId);
  549. $aAdmins = bx_srv($oContextProfile->getModule(), 'get_admins_to_manage_content', [$iContextProfileId]);
  550. if(in_array($iProfileId, $aAdmins))
  551. return CHECK_ACTION_RESULT_ALLOWED;
  552. }
  553. return _t($sTxtError);
  554. }
  555. public function isPollPerformed($iObjectId, $iAuthorId = 0, $iAuthorIp = 0)
  556. {
  557. if(empty($iAuthorId)) {
  558. $iAuthorId = bx_get_logged_profile_id();
  559. $iAuthorIp = bx_get_ip_hash(getVisitorIP());
  560. }
  561. return $this->_oDb->isPollPerformed($iObjectId, $iAuthorId, $iAuthorIp);
  562. }
  563. // ====== COMMON METHODS
  564. public function addAttachLink($aValues, $sDisplay = false)
  565. {
  566. $CNF = &$this->_oConfig->CNF;
  567. if(!$sDisplay)
  568. $sDisplay = $CNF['OBJECT_FORM_DISPLAY_ATTACH_LINK_ADD'];
  569. $oForm = BxDolForm::getObjectInstance($CNF['OBJECT_FORM_ATTACH_LINK'], $sDisplay, $this->_oTemplate);
  570. if(!$oForm)
  571. return array('message' => '_sys_txt_error_occured');
  572. $oForm->aFormAttrs['method'] = BX_DOL_FORM_METHOD_SPECIFIC;
  573. $oForm->aParams['csrf']['disable'] = true;
  574. if(!empty($oForm->aParams['db']['submit_name'])) {
  575. $sSubmitName = $oForm->aParams['db']['submit_name'];
  576. if(!isset($oForm->aInputs[$sSubmitName])) {
  577. if(isset($oForm->aInputs[$CNF['FIELD_ATTACH_LINK_CONTROLS']]))
  578. foreach($oForm->aInputs[$CNF['FIELD_ATTACH_LINK_CONTROLS']] as $mixedIndex => $aInput) {
  579. if(!is_numeric($mixedIndex) || empty($aInput['name']) || $aInput['name'] != $sSubmitName)
  580. continue;
  581. $aValues[$sSubmitName] = $aInput['value'];
  582. }
  583. }
  584. else
  585. $aValues[$sSubmitName] = $oForm->aInputs[$sSubmitName]['value'];
  586. }
  587. $oForm->aInputs['url']['checker']['params']['preg'] = $this->_oConfig->getPregPattern('url');
  588. $oForm->initChecker(array(), $aValues);
  589. if(!$oForm->isSubmittedAndValid())
  590. return array('message' => '_sys_txt_error_occured');
  591. return $this->_addLink($oForm);
  592. }
  593. public function getFormAttachLink($iContentId = 0)
  594. {
  595. $CNF = &$this->_oConfig->CNF;
  596. $oForm = BxDolForm::getObjectInstance($CNF['OBJECT_FORM_ATTACH_LINK'], $CNF['OBJECT_FORM_DISPLAY_ATTACH_LINK_ADD'], $this->_oTemplate);
  597. $oForm->aFormAttrs['action'] = BX_DOL_URL_ROOT . $this->_oConfig->getBaseUri() . 'submit_attach_link_form/';
  598. $oForm->aInputs['content_id']['value'] = $iContentId;
  599. $oForm->aInputs['url']['checker']['params']['preg'] = $this->_oConfig->getPregPattern('url');
  600. $oForm->initChecker();
  601. if($oForm->isSubmittedAndValid())
  602. return $this->_addLink($oForm);
  603. return array('form' => $oForm->getCode(), 'form_id' => $oForm->id);
  604. }
  605. protected function _addLink(&$oForm)
  606. {
  607. $CNF = &$this->_oConfig->CNF;
  608. $iUserId = $this->getUserId();
  609. $iContentId = (int)$oForm->getCleanValue('content_id');
  610. $sLink = rtrim($oForm->getCleanValue('url'), '/');
  611. $sHost = parse_url($sLink, PHP_URL_HOST);
  612. if (is_private_ip(gethostbyname($sHost)))
  613. return array('message' => _t('_sys_txt_error_occured'));
  614. $aMatches = array();
  615. preg_match($this->_oConfig->getPregPattern('url'), $sLink, $aMatches);
  616. $sLink = (empty($aMatches[2]) ? 'http://' : '') . $aMatches[0];
  617. $aSiteInfo = bx_get_site_info($sLink, array(
  618. 'thumbnailUrl' => array('tag' => 'link', 'content_attr' => 'href'),
  619. 'OGImage' => array('name_attr' => 'property', 'name' => 'og:image'),
  620. ));
  621. $sTitle = !empty($aSiteInfo['title']) ? $aSiteInfo['title'] : _t('_Empty');
  622. $sDescription = !empty($aSiteInfo['description']) ? $aSiteInfo['description'] : _t('_Empty');
  623. $sMediaUrl = '';
  624. if(!empty($aSiteInfo['thumbnailUrl']))
  625. $sMediaUrl = $aSiteInfo['thumbnailUrl'];
  626. else if(!empty($aSiteInfo['OGImage']))
  627. $sMediaUrl = $aSiteInfo['OGImage'];
  628. $iMediaId = 0;
  629. $oStorage = null;
  630. if(!empty($sMediaUrl)) {
  631. $oStorage = BxDolStorage::getObjectInstance($CNF['OBJECT_STORAGE_PHOTOS']);
  632. $iMediaId = $oStorage->storeFileFromUrl($sMediaUrl, true, $iUserId);
  633. }
  634. $iId = (int)$oForm->insert(array('profile_id' => $iUserId, 'media_id' => $iMediaId, 'url' => $sLink, 'title' => $sTitle, 'text' => $sDescription, 'added' => time()));
  635. if(!empty($iId)) {
  636. if(!empty($oStorage) && !empty($iMediaId))
  637. $oStorage->afterUploadCleanup($iMediaId, $iUserId);
  638. return array(
  639. 'id' => $iId,
  640. 'content_id' => $iContentId,
  641. 'url' => $sLink,
  642. 'item' => $this->_oTemplate->getAttachLinkItem($iUserId, $iId)
  643. );
  644. }
  645. return array('message' => _t('_bx_timeline_txt_err_cannot_perform_action'));
  646. }
  647. public function onApprove($mixedContent)
  648. {
  649. $CNF = &$this->_oConfig->CNF;
  650. if(!is_array($mixedContent))
  651. $mixedContent = $this->_oDb->getContentInfoById((int)$mixedContent);
  652. $this->alertAfterApprove($mixedContent);
  653. $this->onPublished($mixedContent[$CNF['FIELD_ID']]);
  654. }
  655. public function alertAfterAdd($aContentInfo)
  656. {
  657. $CNF = &$this->_oConfig->CNF;
  658. $iId = (int)$aContentInfo[$CNF['FIELD_ID']];
  659. $iAuthorId = (int)$aContentInfo[$CNF['FIELD_AUTHOR']];
  660. $sAction = 'added';
  661. if(isset($CNF['FIELD_STATUS']) && isset($aContentInfo[$CNF['FIELD_STATUS']]) && $aContentInfo[$CNF['FIELD_STATUS']] == BX_BASE_MOD_TEXT_STATUS_AWAITING)
  662. $sAction = 'deferred';
  663. else if(isset($CNF['FIELD_STATUS_ADMIN']) && isset($aContentInfo[$CNF['FIELD_STATUS_ADMIN']]) && $aContentInfo[$CNF['FIELD_STATUS_ADMIN']] == BX_BASE_MOD_GENERAL_STATUS_PENDING)
  664. $sAction = 'deferred';
  665. $aParams = $this->_alertParamsAdd($aContentInfo);
  666. bx_alert('system', 'prepare_alert_params', 0, 0, array('unit'=> $this->getName(), 'action' => &$sAction, 'object_id' => &$iId, 'sender_id' => &$iAuthorId, 'extras' => &$aParams));
  667. bx_alert($this->getName(), $sAction, $iId, $iAuthorId, $aParams);
  668. $this->_processModerationNotifications($aContentInfo);
  669. }
  670. public function alertAfterEdit($aContentInfo)
  671. {
  672. $CNF = &$this->_oConfig->CNF;
  673. $iId = (int)$aContentInfo[$CNF['FIELD_ID']];
  674. $aParams = $this->_alertParams($aContentInfo);
  675. bx_alert($this->getName(), 'edited', $iId, false, $aParams);
  676. }
  677. /**
  678. * Get array of params to be passed in Add/Edit Alert.
  679. */
  680. protected function _alertParams($aContentInfo)
  681. {
  682. $aParams = parent::_alertParams($aContentInfo);
  683. $CNF = &$this->_oConfig->CNF;
  684. if(!empty($CNF['FIELD_STATUS']) && isset($aContentInfo[$CNF['FIELD_STATUS']]))
  685. $aParams['status'] = $aContentInfo[$CNF['FIELD_STATUS']];
  686. if(!empty($CNF['FIELD_STATUS_ADMIN']) && isset($aContentInfo[$CNF['FIELD_STATUS_ADMIN']]))
  687. $aParams['status_admin'] = $aContentInfo[$CNF['FIELD_STATUS_ADMIN']];
  688. if(!empty($CNF['FIELD_ALLOW_VIEW_TO']) && isset($aContentInfo[$CNF['FIELD_ALLOW_VIEW_TO']]))
  689. $aParams['privacy_view'] = $aContentInfo[$CNF['FIELD_ALLOW_VIEW_TO']];
  690. if(!empty($CNF['FIELD_CF']) && isset($aContentInfo[$CNF['FIELD_CF']]))
  691. $aParams['cf'] = $aContentInfo[$CNF['FIELD_CF']];
  692. return $aParams;
  693. }
  694. protected function _alertParamsAdd($aContentInfo)
  695. {
  696. $aParams = $this->_alertParams($aContentInfo);
  697. $CNF = &$this->_oConfig->CNF;
  698. if(!empty($CNF['OBJECT_METATAGS']))
  699. $aParams['timeline_group'] = array(
  700. 'by' => $this->getName() . '_' . (int)$aContentInfo[$CNF['FIELD_AUTHOR']] . '_' . (int)$aContentInfo[$CNF['FIELD_ID']],
  701. 'field' => 'owner_id'
  702. );
  703. return $aParams;
  704. }
  705. public function getPollForm()
  706. {
  707. $CNF = &$this->_oConfig->CNF;
  708. if(empty($CNF['OBJECT_FORM_POLL']))
  709. return array('code' => 1, 'message' => '_sys_txt_error_occured');
  710. $iProfileId = bx_get_logged_profile_id();
  711. $oForm = BxDolForm::getObjectInstance($CNF['OBJECT_FORM_POLL'], $CNF['OBJECT_FORM_POLL_DISPLAY_ADD'], $this->_oTemplate);
  712. $oForm->aFormAttrs['action'] = BX_DOL_URL_ROOT . $this->_oConfig->getBaseUri() . 'submit_poll_form/';
  713. $oForm->initChecker();
  714. if($oForm->isSubmittedAndValid()) {
  715. $iId = $oForm->insert();
  716. if($iId)
  717. return array('code' => 0, 'id' => $iId, 'item' => $this->_oTemplate->getPollItem($iId, $iProfileId, array(
  718. 'manage' => true
  719. )));
  720. else
  721. return array('code' => 2, 'message' => '_sys_txt_error_entry_creation');
  722. }
  723. return array('form' => $oForm->getCode(), 'form_id' => $oForm->id);
  724. }
  725. public function getEntryImageData($aContentInfo, $sField = 'FIELD_THUMB', $aTranscoders = array())
  726. {
  727. $CNF = &$this->_oConfig->CNF;
  728. $mResult = parent::getEntryImageData($aContentInfo, $sField, $aTranscoders);
  729. if ($mResult === false && isset($CNF['PARAM_USE_GALERY_AS_COVER']) && getParam($CNF['PARAM_USE_GALERY_AS_COVER']) == 'on'){
  730. if(!empty($CNF['OBJECT_STORAGE_PHOTOS']) && !empty($CNF['OBJECT_IMAGES_TRANSCODER_PREVIEW_PHOTOS'])){
  731. $sStorage = $CNF['OBJECT_STORAGE_PHOTOS'];
  732. $oStorage = BxDolStorage::getObjectInstance($sStorage);
  733. $aGhostFiles = $oStorage->getGhosts ($this->serviceGetContentOwnerProfileId($aContentInfo[$CNF['FIELD_ID']]), $aContentInfo[$CNF['FIELD_ID']]);
  734. if ($aGhostFiles){
  735. foreach ($aGhostFiles as $k => $a) {
  736. return array('id' => $a['id'], 'transcoder' => $CNF['OBJECT_IMAGES_TRANSCODER_PREVIEW_PHOTOS']);
  737. }
  738. }
  739. }
  740. }
  741. return $mResult;
  742. }
  743. public function decodeDataAPI($aData, $aParams = [])
  744. {
  745. $CNF = &$this->_oConfig->CNF;
  746. $iId = (int)$aData[$CNF['FIELD_ID']];
  747. $sSummary = '';
  748. if(!empty($CNF['PARAM_CHARS_SUMMARY_PLAIN'])) {
  749. $sSummary = $this->_oTemplate->getText($aData);
  750. $sSummary = BxTemplFunctions::getInstance()->getStringWithLimitedLength(strip_tags($sSummary), (int)getParam($CNF['PARAM_CHARS_SUMMARY_PLAIN']));
  751. }
  752. $aResult = [
  753. 'id' => $iId,
  754. 'added' => $aData[$CNF['FIELD_ADDED']],
  755. 'author' => $aData[$CNF['FIELD_AUTHOR']],
  756. 'author_data' => !empty($aData[$CNF['FIELD_AUTHOR']]) ? BxDolProfile::getData($aData[$CNF['FIELD_AUTHOR']]) : '',
  757. 'title' => $aData[$CNF['FIELD_TITLE']],
  758. 'url' => bx_api_get_relative_url($this->serviceGetLink($iId)),
  759. 'image' => $this->serviceGetThumb($iId),
  760. 'summary_plain' => $sSummary
  761. ];
  762. if(isset($aParams['extended']) && $aParams['extended'] === true)
  763. $aResult['text'] = $aData[$CNF['FIELD_TEXT']];
  764. /**
  765. * Disabled for now, because Author is used only.
  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. */
  771. return $aResult;
  772. }
  773. // ====== PROTECTED METHODS
  774. protected function _getImagesForTimelinePost($aEvent, $aContentInfo, $sUrl, $aBrowseParams = array())
  775. {
  776. $CNF = &$this->_oConfig->CNF;
  777. $aResults = parent::_getImagesForTimelinePost($aEvent, $aContentInfo, $sUrl, $aBrowseParams);
  778. if (bx_is_api())
  779. return $aResults;
  780. if (count($aResults) == 0 && isset($CNF['PARAM_USE_GALERY_AS_COVER']) && getParam($CNF['PARAM_USE_GALERY_AS_COVER']) == 'on'){
  781. $aResults = $this->_getImagesForTimelinePostAttachInner($aEvent, $aContentInfo, $sUrl, $aBrowseParams);
  782. if (count($aResults) > 1){
  783. $aResults = array_slice($aResults, 0, 1);
  784. }
  785. }
  786. return $aResults;
  787. }
  788. protected function _getImagesForTimelinePostAttach($aEvent, $aContentInfo, $sUrl, $aBrowseParams = array())
  789. {
  790. $CNF = &$this->_oConfig->CNF;
  791. $aTmp = parent::_getImagesForTimelinePost($aEvent, $aContentInfo, $sUrl, $aBrowseParams);
  792. $aResults = $this->_getImagesForTimelinePostAttachInner($aEvent, $aContentInfo, $sUrl, $aBrowseParams);
  793. if (bx_is_api())
  794. return $aResults;
  795. if (count($aTmp) == 0 && count($aResults) > 0 && isset($CNF['PARAM_USE_GALERY_AS_COVER']) && getParam($CNF['PARAM_USE_GALERY_AS_COVER']) == 'on'){
  796. $aResults = array_slice($aResults, 1);
  797. }
  798. return $aResults;
  799. }
  800. protected function _getImagesForTimelinePostAttachInner($aEvent, $aContentInfo, $sUrl, $aBrowseParams = array())
  801. {
  802. $CNF = &$this->_oConfig->CNF;
  803. $aResults = parent::_getImagesForTimelinePostAttach($aEvent, $aContentInfo, $sUrl, $aBrowseParams);
  804. if(!$this->_oConfig->isAttachmentsInTimeline() || empty($CNF['OBJECT_STORAGE_PHOTOS']) || empty($CNF['OBJECT_IMAGES_TRANSCODER_GALLERY_PHOTOS']))
  805. return $aResults;
  806. $iContentId = (int)$aContentInfo[$CNF['FIELD_ID']];
  807. $oStorage = BxDolStorage::getObjectInstance($CNF['OBJECT_STORAGE_PHOTOS']);
  808. $aGhostFiles = $oStorage->getGhosts($this->serviceGetContentOwnerProfileId($iContentId), $iContentId);
  809. if(!$aGhostFiles)
  810. return [];
  811. $oTranscoderSm = false;
  812. if(!empty($CNF['OBJECT_IMAGES_TRANSCODER_MINIATURE_PHOTOS']))
  813. $oTranscoderSm = BxDolTranscoderImage::getObjectInstance($CNF['OBJECT_IMAGES_TRANSCODER_MINIATURE_PHOTOS']);
  814. $oTranscoderMd = BxDolTranscoderImage::getObjectInstance($CNF['OBJECT_IMAGES_TRANSCODER_GALLERY_PHOTOS']);
  815. $oTranscoderXl = false;
  816. if(!empty($CNF['OBJECT_IMAGES_TRANSCODER_VIEW_PHOTOS']))
  817. $oTranscoderXl = BxDolTranscoderImage::getObjectInstance($CNF['OBJECT_IMAGES_TRANSCODER_VIEW_PHOTOS']);
  818. foreach($aGhostFiles as $k => $a) {
  819. $sPhotoSrcMd = $oTranscoderMd->getFileUrl($a['id']);
  820. if(empty($sPhotoSrcMd))
  821. continue;
  822. $sPhotoSrcSm = $oTranscoderSm !== false ? $oTranscoderSm->getFileUrl($a['id']) : '';
  823. if(!$sPhotoSrcSm)
  824. $sPhotoSrcSm = $sPhotoSrcMd;
  825. $sPhotoSrcXl = $oTranscoderXl !== false ? $oTranscoderXl->getFileUrl($a['id']) : $oStorage->getFileUrlById($a['id']);
  826. if(!$sPhotoSrcXl)
  827. $sPhotoSrcXl = $sPhotoSrcMd;
  828. if (bx_is_api()){
  829. $aResults[] = bx_api_get_image($CNF['OBJECT_STORAGE_PHOTOS'], (int)$a['id']);
  830. }
  831. else{
  832. $aResults[] = [
  833. 'id' => $a['id'],
  834. 'src' => $sPhotoSrcMd,
  835. 'src_small' => $sPhotoSrcSm,
  836. 'src_medium' => $sPhotoSrcMd,
  837. 'src_orig' => $sPhotoSrcXl,
  838. ];
  839. }
  840. }
  841. return $aResults;
  842. }
  843. protected function _getVideosForTimelinePostAttach($aEvent, $aContentInfo, $sUrl, $aBrowseParams = array())
  844. {
  845. $CNF = &$this->_oConfig->CNF;
  846. $aResults = parent::_getVideosForTimelinePostAttach($aEvent, $aContentInfo, $sUrl, $aBrowseParams);
  847. if(!$this->_oConfig->isAttachmentsInTimeline() || empty($CNF['OBJECT_STORAGE_VIDEOS']) || empty($CNF['OBJECT_VIDEOS_TRANSCODERS']))
  848. return $aResults;
  849. $iContentId = (int)$aContentInfo[$CNF['FIELD_ID']];
  850. $oStorage = BxDolStorage::getObjectInstance($CNF['OBJECT_STORAGE_VIDEOS']);
  851. $aGhostFiles = $oStorage->getGhosts($this->serviceGetContentOwnerProfileId($iContentId), $iContentId);
  852. if(!$aGhostFiles)
  853. return array();
  854. $oTcPoster = BxDolTranscoderVideo::getObjectInstance($CNF['OBJECT_VIDEOS_TRANSCODERS']['poster']);
  855. $oTcMp4 = BxDolTranscoderVideo::getObjectInstance($CNF['OBJECT_VIDEOS_TRANSCODERS']['mp4']);
  856. $oTcMp4Hd = BxDolTranscoderVideo::getObjectInstance($CNF['OBJECT_VIDEOS_TRANSCODERS']['mp4_hd']);
  857. if(!$oTcPoster || !$oTcMp4 || !$oTcMp4Hd)
  858. return array();
  859. $aResults = array();
  860. foreach ($aGhostFiles as $k => $a) {
  861. $sVideoUrl = $oStorage->getFileUrlById($a['id']);
  862. $aVideoFile = $oStorage->getFile($a['id']);
  863. $sVideoUrlHd = '';
  864. if (!empty($aVideoFile['dimensions']) && $oTcMp4Hd->isProcessHD($aVideoFile['dimensions']))
  865. $sVideoUrlHd = $oTcMp4Hd->getFileUrl($a['id']);
  866. $aResults[$a['id']] = array(
  867. 'id' => $a['id'],
  868. 'src_poster' => $oTcPoster->getFileUrl($a['id']),
  869. 'src_mp4' => $oTcMp4->getFileUrl($a['id']),
  870. 'src_mp4_hd' => $sVideoUrlHd,
  871. );
  872. }
  873. return $aResults;
  874. }
  875. protected function _getFilesForTimelinePostAttach($aEvent, $aContentInfo, $sUrl, $aBrowseParams = array())
  876. {
  877. $CNF = &$this->_oConfig->CNF;
  878. $aResults = parent::_getFilesForTimelinePostAttach($aEvent, $aContentInfo, $sUrl, $aBrowseParams);
  879. if(!$this->_oConfig->isAttachmentsInTimeline() || empty($CNF['OBJECT_STORAGE_FILES']))
  880. return $aResults;
  881. $iContentId = (int)$aContentInfo[$CNF['FIELD_ID']];
  882. $oStorage = BxDolStorage::getObjectInstance($CNF['OBJECT_STORAGE_FILES']);
  883. $aGhostFiles = $oStorage->getGhosts($this->serviceGetContentOwnerProfileId($iContentId), $iContentId);
  884. if(!$aGhostFiles)
  885. return array();
  886. $oTranscoder = null;
  887. if(!empty($CNF['OBJECT_IMAGES_TRANSCODER_GALLERY_FILES']))
  888. $oTranscoder = BxDolTranscoderImage::getObjectInstance($CNF['OBJECT_IMAGES_TRANSCODER_GALLERY_FILES']);
  889. foreach ($aGhostFiles as $k => $a) {
  890. $bImage = in_array($a['ext'], array('jpg', 'jpeg', 'png', 'gif'));
  891. $sPhotoSrc = '';
  892. if($bImage && $oTranscoder)
  893. $sPhotoSrc = $oTranscoder->getFileUrl($a['id']);
  894. if(empty($sPhotoSrc) && $oStorage)
  895. $sPhotoSrc = $this->_oTemplate->getIconUrl($oStorage->getIconNameByFileName($a['file_name']));
  896. $sUrl = $oStorage->getFileUrlById($a['id']);
  897. $aResults[] = array(
  898. 'id' => $a['id'],
  899. 'src' => $sPhotoSrc,
  900. 'src_medium' => $sPhotoSrc,
  901. 'src_orig' => $bImage ? $sUrl : '',
  902. 'url' => !$bImage ? $sUrl : ''
  903. );
  904. }
  905. return $aResults;
  906. }
  907. protected function _getContentForTimelinePost($aEvent, $aContentInfo, $aBrowseParams = array())
  908. {
  909. $aResult = parent::_getContentForTimelinePost($aEvent, $aContentInfo, $aBrowseParams);
  910. if(!$this->_oConfig->isAttachmentsInTimeline())
  911. return $aResult;
  912. $CNF = &$this->_oConfig->CNF;
  913. $bDynamic = isset($aBrowseParams['dynamic_mode']) && (bool)$aBrowseParams['dynamic_mode'] === true;
  914. if(!empty($CNF['PARAM_POLL_ENABLED']) && $CNF['PARAM_POLL_ENABLED'] == true)
  915. $aPolls = $this->_oDb->getPolls(array('type' => 'content_id', 'content_id' => (int)$aContentInfo[$CNF['FIELD_ID']]));
  916. if(!empty($aPolls) && is_array($aPolls)) {
  917. $sInclude = $this->_oTemplate->addCss(array('polls.css'), $bDynamic);
  918. $aResult['raw'] = ($bDynamic ? $sInclude : '') . $this->_oTemplate->parseHtmlByName('poll_items_embed.html', array(
  919. 'embed_url' => BX_DOL_URL_ROOT . bx_append_url_params($this->_oConfig->getBaseUri() . 'embed_polls/', array(
  920. 'id' => (int)$aContentInfo[$CNF['FIELD_ID']],
  921. 'param_switch_menu' => 0,
  922. 'param_showcase' => 1
  923. ))
  924. ));
  925. /*
  926. if((!empty($aResult['videos']) && is_array($aResult['videos'])) || (!empty($aResult['videos_attach']) && is_array($aResult['videos_attach'])))
  927. $aResult['_cache'] = false;
  928. */
  929. }
  930. return $aResult;
  931. }
  932. protected function _buildRssParams($sMode, $aArgs)
  933. {
  934. $aParams = array ();
  935. $sMode = bx_process_input($sMode);
  936. switch ($sMode) {
  937. case 'author':
  938. $aParams = array('author' => isset($aArgs[0]) ? (int)$aArgs[0] : '');
  939. break;
  940. }
  941. return $aParams;
  942. }
  943. public function serviceIsAllowedPostInContext()
  944. {
  945. return true;
  946. }
  947. }
  948. /** @} */