1
0

BxBaseModTextModule.php 41 KB

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