1
0

BxBaseModTextModule.php 43 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208
  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(!empty($CNF['txt_link_form_err_delete']) ? $CNF['txt_link_form_err_delete'] : $this->getName() . '_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(!empty($aAdmins) && 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 deleteAttachLinks($iId)
  596. {
  597. if(!$this->_oConfig->isAttachLinks())
  598. return;
  599. $CNF = &$this->_oConfig->CNF;
  600. $aLinks = $this->_oDb->getLinks($iId);
  601. if(empty($aLinks) || !is_array($aLinks))
  602. return;
  603. $oStorage = BxDolStorage::getObjectInstance($CNF['OBJECT_STORAGE_PHOTOS']);
  604. foreach($aLinks as $aLink)
  605. if(!empty($aLink['media_id']))
  606. $oStorage->deleteFile($aLink['media_id']);
  607. $this->_oDb->deleteLinks($iId);
  608. }
  609. public function deleteAttachLinksUnused($iProfileId)
  610. {
  611. if(!$this->_oConfig->isAttachLinks())
  612. return;
  613. $CNF = &$this->_oConfig->CNF;
  614. $aLinks = $this->_oDb->getUnusedLinks($iProfileId);
  615. if(empty($aLinks) || !is_array($aLinks))
  616. return;
  617. $oStorage = BxDolStorage::getObjectInstance($CNF['OBJECT_STORAGE_PHOTOS']);
  618. foreach($aLinks as $aLink)
  619. if(!empty($aLink['media_id']))
  620. $oStorage->deleteFile($aLink['media_id']);
  621. $this->_oDb->deleteUnusedLinks($iProfileId);
  622. }
  623. public function getFormAttachLink($iContentId = 0)
  624. {
  625. $CNF = &$this->_oConfig->CNF;
  626. $oForm = BxDolForm::getObjectInstance($CNF['OBJECT_FORM_ATTACH_LINK'], $CNF['OBJECT_FORM_DISPLAY_ATTACH_LINK_ADD'], $this->_oTemplate);
  627. $oForm->aFormAttrs['action'] = BX_DOL_URL_ROOT . $this->_oConfig->getBaseUri() . 'submit_attach_link_form/';
  628. $oForm->aInputs['content_id']['value'] = $iContentId;
  629. $oForm->aInputs['url']['checker']['params']['preg'] = $this->_oConfig->getPregPattern('url');
  630. $oForm->initChecker();
  631. if($oForm->isSubmittedAndValid())
  632. return $this->_addLink($oForm);
  633. return array('form' => $oForm->getCode(), 'form_id' => $oForm->id);
  634. }
  635. protected function _addLink(&$oForm)
  636. {
  637. $CNF = &$this->_oConfig->CNF;
  638. $iUserId = $this->getUserId();
  639. $iContentId = (int)$oForm->getCleanValue('content_id');
  640. $sLink = rtrim($oForm->getCleanValue('url'), '/');
  641. $sHost = parse_url($sLink, PHP_URL_HOST);
  642. if (is_private_ip(gethostbyname($sHost)))
  643. return array('message' => _t('_sys_txt_error_occured'));
  644. $aMatches = array();
  645. preg_match($this->_oConfig->getPregPattern('url'), $sLink, $aMatches);
  646. $sLink = (empty($aMatches[2]) ? 'http://' : '') . $aMatches[0];
  647. $aSiteInfo = bx_get_site_info($sLink, array(
  648. 'thumbnailUrl' => array('tag' => 'link', 'content_attr' => 'href'),
  649. 'OGImage' => array('name_attr' => 'property', 'name' => 'og:image'),
  650. ));
  651. $sTitle = !empty($aSiteInfo['title']) ? $aSiteInfo['title'] : $sHost;
  652. $sDescription = !empty($aSiteInfo['description']) ? $aSiteInfo['description'] : '';
  653. $sMediaUrl = '';
  654. if(!empty($aSiteInfo['thumbnailUrl']))
  655. $sMediaUrl = $aSiteInfo['thumbnailUrl'];
  656. else if(!empty($aSiteInfo['OGImage']))
  657. $sMediaUrl = $aSiteInfo['OGImage'];
  658. $iMediaId = 0;
  659. $oStorage = null;
  660. if(!empty($sMediaUrl)) {
  661. $oStorage = BxDolStorage::getObjectInstance($CNF['OBJECT_STORAGE_PHOTOS']);
  662. $iMediaId = $oStorage->storeFileFromUrl($sMediaUrl, true, $iUserId);
  663. }
  664. $iId = (int)$oForm->insert(array('profile_id' => $iUserId, 'media_id' => $iMediaId, 'url' => $sLink, 'title' => $sTitle, 'text' => $sDescription, 'added' => time()));
  665. if(!empty($iId)) {
  666. if(!empty($oStorage) && !empty($iMediaId))
  667. $oStorage->afterUploadCleanup($iMediaId, $iUserId);
  668. return array(
  669. 'id' => $iId,
  670. 'content_id' => $iContentId,
  671. 'url' => $sLink,
  672. 'item' => $this->_oTemplate->getAttachLinkItem($iUserId, $iId)
  673. );
  674. }
  675. return array('message' => _t('_bx_timeline_txt_err_cannot_perform_action'));
  676. }
  677. public function onApprove($mixedContent)
  678. {
  679. $CNF = &$this->_oConfig->CNF;
  680. if(!is_array($mixedContent))
  681. $mixedContent = $this->_oDb->getContentInfoById((int)$mixedContent);
  682. $this->alertAfterApprove($mixedContent);
  683. $this->onPublished($mixedContent[$CNF['FIELD_ID']]);
  684. }
  685. public function alertAfterAdd($aContentInfo)
  686. {
  687. $CNF = &$this->_oConfig->CNF;
  688. $iId = (int)$aContentInfo[$CNF['FIELD_ID']];
  689. $iAuthorId = (int)$aContentInfo[$CNF['FIELD_AUTHOR']];
  690. $sAction = 'added';
  691. if(isset($CNF['FIELD_STATUS']) && isset($aContentInfo[$CNF['FIELD_STATUS']]) && $aContentInfo[$CNF['FIELD_STATUS']] == BX_BASE_MOD_TEXT_STATUS_AWAITING)
  692. $sAction = 'deferred';
  693. else if(isset($CNF['FIELD_STATUS_ADMIN']) && isset($aContentInfo[$CNF['FIELD_STATUS_ADMIN']]) && $aContentInfo[$CNF['FIELD_STATUS_ADMIN']] == BX_BASE_MOD_GENERAL_STATUS_PENDING)
  694. $sAction = 'deferred';
  695. $aParams = $this->_alertParamsAdd($aContentInfo);
  696. bx_alert('system', 'prepare_alert_params', 0, 0, array('unit'=> $this->getName(), 'action' => &$sAction, 'object_id' => &$iId, 'sender_id' => &$iAuthorId, 'extras' => &$aParams));
  697. bx_alert($this->getName(), $sAction, $iId, $iAuthorId, $aParams);
  698. $this->_processModerationNotifications($aContentInfo);
  699. }
  700. public function alertAfterEdit($aContentInfo)
  701. {
  702. $CNF = &$this->_oConfig->CNF;
  703. $iId = (int)$aContentInfo[$CNF['FIELD_ID']];
  704. $aParams = $this->_alertParamsEdit($aContentInfo);
  705. bx_alert($this->getName(), 'edited', $iId, false, $aParams);
  706. }
  707. /**
  708. * Get array of params to be passed in Add/Edit Alert.
  709. */
  710. protected function _alertParams($aContentInfo)
  711. {
  712. $aParams = parent::_alertParams($aContentInfo);
  713. $CNF = &$this->_oConfig->CNF;
  714. if(!empty($CNF['FIELD_STATUS']) && isset($aContentInfo[$CNF['FIELD_STATUS']]))
  715. $aParams['status'] = $aContentInfo[$CNF['FIELD_STATUS']];
  716. if(!empty($CNF['FIELD_STATUS_ADMIN']) && isset($aContentInfo[$CNF['FIELD_STATUS_ADMIN']]))
  717. $aParams['status_admin'] = $aContentInfo[$CNF['FIELD_STATUS_ADMIN']];
  718. if(!empty($CNF['FIELD_ALLOW_VIEW_TO']) && isset($aContentInfo[$CNF['FIELD_ALLOW_VIEW_TO']]))
  719. $aParams['privacy_view'] = $aContentInfo[$CNF['FIELD_ALLOW_VIEW_TO']];
  720. if(!empty($CNF['FIELD_CF']) && isset($aContentInfo[$CNF['FIELD_CF']]))
  721. $aParams['cf'] = $aContentInfo[$CNF['FIELD_CF']];
  722. return $aParams;
  723. }
  724. protected function _alertParamsAdd($aContentInfo)
  725. {
  726. $aParams = $this->_alertParams($aContentInfo);
  727. $CNF = &$this->_oConfig->CNF;
  728. if(!empty($CNF['OBJECT_METATAGS']))
  729. $aParams['timeline_group'] = $this->_getAlertParamTimelineGroup($aContentInfo);
  730. return $aParams;
  731. }
  732. protected function _alertParamsEdit($aContentInfo)
  733. {
  734. $aParams = $this->_alertParams($aContentInfo);
  735. $CNF = &$this->_oConfig->CNF;
  736. if(!empty($CNF['OBJECT_METATAGS']))
  737. $aParams['timeline_group'] = $this->_getAlertParamTimelineGroup($aContentInfo);
  738. return $aParams;
  739. }
  740. protected function _getAlertParamTimelineGroup($aContentInfo)
  741. {
  742. $CNF = &$this->_oConfig->CNF;
  743. return [
  744. 'by' => $this->getName() . '_' . abs((int)$aContentInfo[$CNF['FIELD_AUTHOR']]) . '_' . (int)$aContentInfo[$CNF['FIELD_ID']],
  745. 'field' => 'owner_id'
  746. ];
  747. }
  748. public function getPollForm()
  749. {
  750. $CNF = &$this->_oConfig->CNF;
  751. if(empty($CNF['OBJECT_FORM_POLL']))
  752. return array('code' => 1, 'message' => '_sys_txt_error_occured');
  753. $iProfileId = bx_get_logged_profile_id();
  754. $oForm = BxDolForm::getObjectInstance($CNF['OBJECT_FORM_POLL'], $CNF['OBJECT_FORM_POLL_DISPLAY_ADD'], $this->_oTemplate);
  755. $oForm->aFormAttrs['action'] = BX_DOL_URL_ROOT . $this->_oConfig->getBaseUri() . 'submit_poll_form/';
  756. $oForm->initChecker();
  757. if($oForm->isSubmittedAndValid()) {
  758. $iId = $oForm->insert();
  759. if($iId)
  760. return array('code' => 0, 'id' => $iId, 'item' => $this->_oTemplate->getPollItem($iId, $iProfileId, array(
  761. 'manage' => true
  762. )));
  763. else
  764. return array('code' => 2, 'message' => '_sys_txt_error_entry_creation');
  765. }
  766. return array('form' => $oForm->getCode(), 'form_id' => $oForm->id);
  767. }
  768. public function getEntryImageData($aContentInfo, $sField = 'FIELD_THUMB', $aTranscoders = array())
  769. {
  770. $CNF = &$this->_oConfig->CNF;
  771. $mResult = parent::getEntryImageData($aContentInfo, $sField, $aTranscoders);
  772. if ($mResult === false && isset($CNF['PARAM_USE_GALERY_AS_COVER']) && getParam($CNF['PARAM_USE_GALERY_AS_COVER']) == 'on'){
  773. if(!empty($CNF['OBJECT_STORAGE_PHOTOS']) && !empty($CNF['OBJECT_IMAGES_TRANSCODER_PREVIEW_PHOTOS'])){
  774. $sStorage = $CNF['OBJECT_STORAGE_PHOTOS'];
  775. $oStorage = BxDolStorage::getObjectInstance($sStorage);
  776. $aGhostFiles = $oStorage->getGhosts ($this->serviceGetContentOwnerProfileId($aContentInfo[$CNF['FIELD_ID']]), $aContentInfo[$CNF['FIELD_ID']]);
  777. if ($aGhostFiles){
  778. foreach ($aGhostFiles as $k => $a) {
  779. return array('id' => $a['id'], 'transcoder' => $CNF['OBJECT_IMAGES_TRANSCODER_PREVIEW_PHOTOS']);
  780. }
  781. }
  782. }
  783. }
  784. return $mResult;
  785. }
  786. public function decodeDataAPI($aData, $aParams = [])
  787. {
  788. $CNF = &$this->_oConfig->CNF;
  789. $sModule = $this->getName();
  790. $iId = (int)$aData[$CNF['FIELD_ID']];
  791. $sSummary = '';
  792. if(!empty($CNF['PARAM_CHARS_SUMMARY_PLAIN'])) {
  793. $sSummary = $this->_oTemplate->getText($aData);
  794. $sSummary = BxTemplFunctions::getInstance()->getStringWithLimitedLength(strip_tags($sSummary), (int)getParam($CNF['PARAM_CHARS_SUMMARY_PLAIN']));
  795. }
  796. $aResult = [
  797. 'id' => $iId,
  798. 'module' => $sModule,
  799. 'module_title' => _t($CNF['T']['txt_sample_single']),
  800. 'added' => $aData[$CNF['FIELD_ADDED']],
  801. 'author' => $aData[$CNF['FIELD_AUTHOR']],
  802. 'author_data' => !empty($aData[$CNF['FIELD_AUTHOR']]) ? BxDolProfile::getData($aData[$CNF['FIELD_AUTHOR']]) : '',
  803. 'title' => $aData[$CNF['FIELD_TITLE']],
  804. 'url' => bx_api_get_relative_url($this->serviceGetLink($iId)),
  805. 'image' => $this->serviceGetThumb($iId),
  806. 'summary_plain' => $sSummary
  807. ];
  808. if(isset($aParams['extended']) && $aParams['extended'] === true)
  809. $aResult['text'] = $aData[$CNF['FIELD_TEXT']];
  810. if(!empty($CNF['OBJECT_MENU_SNIPPET_META']) && ($oMetaMenu = BxDolMenu::getObjectInstance($CNF['OBJECT_MENU_SNIPPET_META'], $this->_oTemplate)) !== false) {
  811. $oMetaMenu->setContentId($iId);
  812. $aResult['meta'] = $oMetaMenu->getCodeAPI();
  813. }
  814. return $aResult;
  815. }
  816. // ====== PROTECTED METHODS
  817. protected function _getImagesForTimelinePost($aEvent, $aContentInfo, $sUrl, $aBrowseParams = array())
  818. {
  819. $CNF = &$this->_oConfig->CNF;
  820. $aResults = parent::_getImagesForTimelinePost($aEvent, $aContentInfo, $sUrl, $aBrowseParams);
  821. if (bx_is_api())
  822. return $aResults;
  823. if (count($aResults) == 0 && isset($CNF['PARAM_USE_GALERY_AS_COVER']) && getParam($CNF['PARAM_USE_GALERY_AS_COVER']) == 'on'){
  824. $aResults = $this->_getImagesForTimelinePostAttachInner($aEvent, $aContentInfo, $sUrl, $aBrowseParams);
  825. if (count($aResults) > 1){
  826. $aResults = array_slice($aResults, 0, 1);
  827. }
  828. }
  829. return $aResults;
  830. }
  831. protected function _getImagesForTimelinePostAttach($aEvent, $aContentInfo, $sUrl, $aBrowseParams = array())
  832. {
  833. $CNF = &$this->_oConfig->CNF;
  834. $aTmp = parent::_getImagesForTimelinePost($aEvent, $aContentInfo, $sUrl, $aBrowseParams);
  835. $aResults = $this->_getImagesForTimelinePostAttachInner($aEvent, $aContentInfo, $sUrl, $aBrowseParams);
  836. if (bx_is_api())
  837. return $aResults;
  838. if (count($aTmp) == 0 && count($aResults) > 0 && isset($CNF['PARAM_USE_GALERY_AS_COVER']) && getParam($CNF['PARAM_USE_GALERY_AS_COVER']) == 'on'){
  839. $aResults = array_slice($aResults, 1);
  840. }
  841. return $aResults;
  842. }
  843. protected function _getImagesForTimelinePostAttachInner($aEvent, $aContentInfo, $sUrl, $aBrowseParams = array())
  844. {
  845. $CNF = &$this->_oConfig->CNF;
  846. $aResults = parent::_getImagesForTimelinePostAttach($aEvent, $aContentInfo, $sUrl, $aBrowseParams);
  847. if(!$this->_oConfig->isAttachmentsInTimeline() || empty($CNF['OBJECT_STORAGE_PHOTOS']) || empty($CNF['OBJECT_IMAGES_TRANSCODER_GALLERY_PHOTOS']))
  848. return $aResults;
  849. $iContentId = (int)$aContentInfo[$CNF['FIELD_ID']];
  850. $oStorage = BxDolStorage::getObjectInstance($CNF['OBJECT_STORAGE_PHOTOS']);
  851. $aGhostFiles = $oStorage->getGhosts($this->serviceGetContentOwnerProfileId($iContentId), $iContentId);
  852. if(!$aGhostFiles)
  853. return [];
  854. $oTranscoderSm = false;
  855. if(!empty($CNF['OBJECT_IMAGES_TRANSCODER_MINIATURE_PHOTOS']))
  856. $oTranscoderSm = BxDolTranscoderImage::getObjectInstance($CNF['OBJECT_IMAGES_TRANSCODER_MINIATURE_PHOTOS']);
  857. $oTranscoderMd = BxDolTranscoderImage::getObjectInstance($CNF['OBJECT_IMAGES_TRANSCODER_GALLERY_PHOTOS']);
  858. $oTranscoderXl = false;
  859. if(!empty($CNF['OBJECT_IMAGES_TRANSCODER_VIEW_PHOTOS']))
  860. $oTranscoderXl = BxDolTranscoderImage::getObjectInstance($CNF['OBJECT_IMAGES_TRANSCODER_VIEW_PHOTOS']);
  861. foreach($aGhostFiles as $k => $a) {
  862. $sPhotoSrcMd = $oTranscoderMd->getFileUrl($a['id']);
  863. if(empty($sPhotoSrcMd))
  864. continue;
  865. $sPhotoSrcSm = $oTranscoderSm !== false ? $oTranscoderSm->getFileUrl($a['id']) : '';
  866. if(!$sPhotoSrcSm)
  867. $sPhotoSrcSm = $sPhotoSrcMd;
  868. $sPhotoSrcXl = $oTranscoderXl !== false ? $oTranscoderXl->getFileUrl($a['id']) : $oStorage->getFileUrlById($a['id']);
  869. if(!$sPhotoSrcXl)
  870. $sPhotoSrcXl = $sPhotoSrcMd;
  871. if (bx_is_api()){
  872. $aResults[] = bx_api_get_image($CNF['OBJECT_STORAGE_PHOTOS'], (int)$a['id']);
  873. }
  874. else{
  875. $aResults[] = [
  876. 'id' => $a['id'],
  877. 'src' => $sPhotoSrcMd,
  878. 'src_small' => $sPhotoSrcSm,
  879. 'src_medium' => $sPhotoSrcMd,
  880. 'src_orig' => $sPhotoSrcXl,
  881. ];
  882. }
  883. }
  884. return $aResults;
  885. }
  886. protected function _getVideosForTimelinePostAttach($aEvent, $aContentInfo, $sUrl, $aBrowseParams = array())
  887. {
  888. $CNF = &$this->_oConfig->CNF;
  889. $aResults = parent::_getVideosForTimelinePostAttach($aEvent, $aContentInfo, $sUrl, $aBrowseParams);
  890. if(!$this->_oConfig->isAttachmentsInTimeline() || empty($CNF['OBJECT_STORAGE_VIDEOS']) || empty($CNF['OBJECT_VIDEOS_TRANSCODERS']))
  891. return $aResults;
  892. $iContentId = (int)$aContentInfo[$CNF['FIELD_ID']];
  893. $oStorage = BxDolStorage::getObjectInstance($CNF['OBJECT_STORAGE_VIDEOS']);
  894. $aGhostFiles = $oStorage->getGhosts($this->serviceGetContentOwnerProfileId($iContentId), $iContentId);
  895. if(!$aGhostFiles)
  896. return array();
  897. $oTcPoster = BxDolTranscoderVideo::getObjectInstance($CNF['OBJECT_VIDEOS_TRANSCODERS']['poster']);
  898. $oTcMp4 = BxDolTranscoderVideo::getObjectInstance($CNF['OBJECT_VIDEOS_TRANSCODERS']['mp4']);
  899. $oTcMp4Hd = BxDolTranscoderVideo::getObjectInstance($CNF['OBJECT_VIDEOS_TRANSCODERS']['mp4_hd']);
  900. if(!$oTcPoster || !$oTcMp4 || !$oTcMp4Hd)
  901. return array();
  902. $aResults = array();
  903. foreach ($aGhostFiles as $k => $a) {
  904. $sVideoUrl = $oStorage->getFileUrlById($a['id']);
  905. $aVideoFile = $oStorage->getFile($a['id']);
  906. $sVideoUrlHd = '';
  907. if (!empty($aVideoFile['dimensions']) && $oTcMp4Hd->isProcessHD($aVideoFile['dimensions']))
  908. $sVideoUrlHd = $oTcMp4Hd->getFileUrl($a['id']);
  909. $aResults[$a['id']] = array(
  910. 'id' => $a['id'],
  911. 'src_poster' => $oTcPoster->getFileUrl($a['id']),
  912. 'src_mp4' => $oTcMp4->getFileUrl($a['id']),
  913. 'src_mp4_hd' => $sVideoUrlHd,
  914. );
  915. }
  916. return $aResults;
  917. }
  918. protected function _getFilesForTimelinePostAttach($aEvent, $aContentInfo, $sUrl, $aBrowseParams = array())
  919. {
  920. $CNF = &$this->_oConfig->CNF;
  921. $aResults = parent::_getFilesForTimelinePostAttach($aEvent, $aContentInfo, $sUrl, $aBrowseParams);
  922. if(!$this->_oConfig->isAttachmentsInTimeline() || empty($CNF['OBJECT_STORAGE_FILES']))
  923. return $aResults;
  924. $iContentId = (int)$aContentInfo[$CNF['FIELD_ID']];
  925. $oStorage = BxDolStorage::getObjectInstance($CNF['OBJECT_STORAGE_FILES']);
  926. $aGhostFiles = $oStorage->getGhosts($this->serviceGetContentOwnerProfileId($iContentId), $iContentId);
  927. if(!$aGhostFiles)
  928. return array();
  929. $oTranscoder = null;
  930. if(!empty($CNF['OBJECT_IMAGES_TRANSCODER_GALLERY_FILES']))
  931. $oTranscoder = BxDolTranscoderImage::getObjectInstance($CNF['OBJECT_IMAGES_TRANSCODER_GALLERY_FILES']);
  932. foreach ($aGhostFiles as $k => $a) {
  933. $bImage = in_array($a['ext'], array('jpg', 'jpeg', 'png', 'gif'));
  934. $sPhotoSrc = '';
  935. if($bImage && $oTranscoder)
  936. $sPhotoSrc = $oTranscoder->getFileUrl($a['id']);
  937. if(empty($sPhotoSrc) && $oStorage)
  938. $sPhotoSrc = $this->_oTemplate->getIconUrl($oStorage->getIconNameByFileName($a['file_name']));
  939. $sUrl = $oStorage->getFileUrlById($a['id']);
  940. $aResults[] = array(
  941. 'id' => $a['id'],
  942. 'src' => $sPhotoSrc,
  943. 'src_medium' => $sPhotoSrc,
  944. 'src_orig' => $bImage ? $sUrl : '',
  945. 'url' => !$bImage ? $sUrl : ''
  946. );
  947. }
  948. return $aResults;
  949. }
  950. protected function _getContentForTimelinePost($aEvent, $aContentInfo, $aBrowseParams = array())
  951. {
  952. $aResult = parent::_getContentForTimelinePost($aEvent, $aContentInfo, $aBrowseParams);
  953. if(!$this->_oConfig->isAttachmentsInTimeline())
  954. return $aResult;
  955. $CNF = &$this->_oConfig->CNF;
  956. $bDynamic = isset($aBrowseParams['dynamic_mode']) && (bool)$aBrowseParams['dynamic_mode'] === true;
  957. if(!empty($CNF['PARAM_POLL_ENABLED']) && $CNF['PARAM_POLL_ENABLED'] == true)
  958. $aPolls = $this->_oDb->getPolls(array('type' => 'content_id', 'content_id' => (int)$aContentInfo[$CNF['FIELD_ID']]));
  959. if(!empty($aPolls) && is_array($aPolls)) {
  960. $sInclude = $this->_oTemplate->addCss(array('polls.css'), $bDynamic);
  961. $aResult['raw'] = ($bDynamic ? $sInclude : '') . $this->_oTemplate->parseHtmlByName('poll_items_embed.html', array(
  962. 'embed_url' => BX_DOL_URL_ROOT . bx_append_url_params($this->_oConfig->getBaseUri() . 'embed_polls/', array(
  963. 'id' => (int)$aContentInfo[$CNF['FIELD_ID']],
  964. 'param_switch_menu' => 0,
  965. 'param_showcase' => 1
  966. ))
  967. ));
  968. /*
  969. if((!empty($aResult['videos']) && is_array($aResult['videos'])) || (!empty($aResult['videos_attach']) && is_array($aResult['videos_attach'])))
  970. $aResult['_cache'] = false;
  971. */
  972. }
  973. return $aResult;
  974. }
  975. protected function _buildRssParams($sMode, $aArgs)
  976. {
  977. $aParams = array ();
  978. $sMode = bx_process_input($sMode);
  979. switch ($sMode) {
  980. case 'author':
  981. $aParams = array('author' => isset($aArgs[0]) ? (int)$aArgs[0] : '');
  982. break;
  983. }
  984. return $aParams;
  985. }
  986. public function serviceIsAllowedPostInContext()
  987. {
  988. return true;
  989. }
  990. }
  991. /** @} */