1
0

BxBaseModTextModule.php 45 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256
  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. $this->_oTemplate->addJs(['modules/base/text/js/|manage_tools.js']);
  171. return parent::serviceManageTools($sType);
  172. }
  173. /**
  174. * @page service Service Calls
  175. * @section bx_base_text Base Text
  176. * @subsection bx_base_general-page_blocks Page Blocks
  177. * @subsubsection bx_base_general-categories_multi_list_context categories_multi_list_context
  178. *
  179. * @code bx_srv('bx_posts', 'categories_multi_list_context', [...]); @endcode
  180. *
  181. * Display multi-categorories block with number of posts in each category for current context
  182. * @param $bDisplayEmptyCats display empty categories
  183. *
  184. * @see BxBaseModGeneralModule::serviceCategoriesMultiListContext
  185. */
  186. /**
  187. * @ref bx_base_general-categories_multi_list_context "categories_multi_list_context"
  188. */
  189. public function serviceCategoriesMultiListContext($iProfileId = 0, $bDisplayEmptyCats = true)
  190. {
  191. if ($iProfileId == 0)
  192. $iProfileId = bx_process_input(bx_get('profile_id'), BX_DATA_INT);
  193. $oCategories = BxDolCategories::getInstance();
  194. $aCats = $oCategories->getData([
  195. 'type' => 'by_module&context_with_num',
  196. 'module' => $this->getName(),
  197. 'context_id' => $iProfileId
  198. ]
  199. );
  200. $aVars = array('bx_repeat:cats' => array());
  201. foreach ($aCats as $oCat) {
  202. $sValue = $oCat['value'];
  203. $iNum = $oCat['num'];
  204. $aVars['bx_repeat:cats'][] = array(
  205. 'url' => $oCategories->getUrl($this->getName(), $sValue, '&context_id=' . $iProfileId),
  206. 'name' => _t($sValue),
  207. 'value' => $sValue,
  208. 'num' => $iNum,
  209. );
  210. }
  211. if (!$aVars['bx_repeat:cats'])
  212. return '';
  213. return $this->_oTemplate->parseHtmlByName('category_list_multi.html', $aVars);
  214. }
  215. /**
  216. * @page service Service Calls
  217. * @section bx_base_text Base Text
  218. * @subsection bx_base_text-polls Polls Blocks
  219. * @subsubsection bx_base_text-get_block_poll_answers get_block_poll_answers
  220. *
  221. * @code bx_srv('bx_posts', 'get_block_poll_answers', [...]); @endcode
  222. *
  223. * Get block with poll answers
  224. * @param $iPollId poll ID
  225. *
  226. * @see BxBaseModTextModule::serviceGetBlockPollAnswers
  227. */
  228. /**
  229. * @ref bx_base_text-get_block_poll_answers "get_block_poll_answers"
  230. */
  231. public function serviceGetBlockPollAnswers($iPollId, $bForceDisplay = false)
  232. {
  233. if(!$iPollId)
  234. return false;
  235. if(!$bForceDisplay && $this->isPollPerformed($iPollId))
  236. return $this->serviceGetBlockPollResults($iPollId);
  237. return $this->_serviceTemplateFunc('entryPollAnswers', $iPollId, 'getPollInfoById');
  238. }
  239. /**
  240. * @page service Service Calls
  241. * @section bx_base_text Base Text
  242. * @subsection bx_base_text-polls Polls Blocks
  243. * @subsubsection bx_base_text-get_block_poll_results get_block_poll_results
  244. *
  245. * @code bx_srv('bx_posts', 'get_block_poll_results', [...]); @endcode
  246. *
  247. * Get block with poll results
  248. * @param $iPollId poll ID
  249. *
  250. * @see BxBaseModTextModule::serviceGetBlockPollResults
  251. */
  252. /**
  253. * @ref bx_base_text-get_block_poll_results "get_block_poll_results"
  254. */
  255. public function serviceGetBlockPollResults($iPollId)
  256. {
  257. return $this->_serviceTemplateFunc('entryPollResults', $iPollId, 'getPollInfoById');
  258. }
  259. /**
  260. * Display media EXIF information.
  261. * @param $iMediaId media ID, if it's omitted then it's taken from 'id' GET variable.
  262. * @return HTML string with EXIF info. On error empty string is returned.
  263. */
  264. public function serviceMediaExif ($iMediaId = 0)
  265. {
  266. $CNF = &$this->_oConfig->CNF;
  267. return $this->_serviceTemplateFunc ('mediaExif', $iMediaId, $CNF['FUNCTION_FOR_GET_ITEM_INFO']);
  268. }
  269. public function serviceGetThumb ($iContentId, $sTranscoder = '')
  270. {
  271. $CNF = &$this->_oConfig->CNF;
  272. if(bx_is_api()){
  273. $aContentInfo = $this->_oDb->getContentInfoById($iContentId);
  274. if (isset($CNF['FIELD_THUMB']))
  275. return bx_api_get_image($CNF['OBJECT_STORAGE'], $aContentInfo[$CNF['FIELD_THUMB']]);
  276. }
  277. if(empty($sTranscoder) && !empty($CNF['OBJECT_IMAGES_TRANSCODER_GALLERY']))
  278. $sTranscoder = $CNF['OBJECT_IMAGES_TRANSCODER_GALLERY'];
  279. $mixedResult = $this->_getFieldValueThumb('FIELD_THUMB', $iContentId, $sTranscoder);
  280. return $mixedResult !== false ? $mixedResult : '';
  281. }
  282. public function serviceGetMenuAddonManageTools()
  283. {
  284. $CNF = &$this->_oConfig->CNF;
  285. $iNumTotal = $this->_oDb->getEntriesNumByParams();
  286. $iNum1 = $this->_oDb->getEntriesNumByParams([
  287. [
  288. 'key' => $CNF['FIELD_STATUS'],
  289. 'value' => 'hidden',
  290. 'operator' => '='
  291. ]
  292. ]);
  293. $iNum2 = 0;
  294. if (isset($CNF['OBJECT_REPORTS'])){
  295. $iNum2 = $this->_oDb->getEntriesNumByParams([
  296. [
  297. 'key' => 'reports',
  298. 'value' => '0',
  299. 'operator' => '>'
  300. ]
  301. ]);
  302. }
  303. return array('counter1_value' => $iNum1, 'counter2_value' => $iNum2, 'counter3_value' => $iNumTotal );
  304. }
  305. /**
  306. * @page service Service Calls
  307. * @section bx_base_text Base Text
  308. * @subsection bx_base_text-other Other
  309. * @subsubsection bx_base_text-get_menu_addon_manage_tools_profile_stats get_menu_addon_manage_tools_profile_stats
  310. *
  311. * @code bx_srv('bx_posts', 'get_menu_addon_manage_tools_profile_stats', []); @endcode
  312. *
  313. * Get number of posts for currently logged in user
  314. *
  315. * @see BxBaseModTextModule::serviceGetMenuAddonManageToolsProfileStats
  316. */
  317. /**
  318. * @ref bx_base_text-get_menu_addon_manage_tools_profile_stats "get_menu_addon_manage_tools_profile_stats"
  319. */
  320. public function serviceGetMenuAddonManageToolsProfileStats($iProfileId = 0)
  321. {
  322. if(!$iProfileId)
  323. $iProfileId = bx_get_logged_profile_id();
  324. bx_import('SearchResult', $this->_aModule);
  325. $sClass = $this->_aModule['class_prefix'] . 'SearchResult';
  326. $o = new $sClass();
  327. $o->fillFilters([
  328. 'author' => $iProfileId
  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(!empty($aAdmins) && 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 deleteAttachLinks($iId)
  594. {
  595. if(!$this->_oConfig->isAttachLinks())
  596. return;
  597. $CNF = &$this->_oConfig->CNF;
  598. $aLinks = $this->_oDb->getLinks($iId);
  599. if(empty($aLinks) || !is_array($aLinks))
  600. return;
  601. $oStorage = BxDolStorage::getObjectInstance($CNF['OBJECT_STORAGE_PHOTOS']);
  602. foreach($aLinks as $aLink)
  603. if(!empty($aLink['media_id']))
  604. $oStorage->deleteFile($aLink['media_id']);
  605. $this->_oDb->deleteLinks($iId);
  606. }
  607. public function deleteAttachLinksUnused($iProfileId)
  608. {
  609. if(!$this->_oConfig->isAttachLinks())
  610. return;
  611. $CNF = &$this->_oConfig->CNF;
  612. $aLinks = $this->_oDb->getUnusedLinks($iProfileId);
  613. if(empty($aLinks) || !is_array($aLinks))
  614. return;
  615. $oStorage = BxDolStorage::getObjectInstance($CNF['OBJECT_STORAGE_PHOTOS']);
  616. foreach($aLinks as $aLink)
  617. if(!empty($aLink['media_id']))
  618. $oStorage->deleteFile($aLink['media_id']);
  619. $this->_oDb->deleteUnusedLinks($iProfileId);
  620. }
  621. public function getFormAttachLink($iContentId = 0)
  622. {
  623. $CNF = &$this->_oConfig->CNF;
  624. $oForm = BxDolForm::getObjectInstance($CNF['OBJECT_FORM_ATTACH_LINK'], $CNF['OBJECT_FORM_DISPLAY_ATTACH_LINK_ADD'], $this->_oTemplate);
  625. $oForm->aFormAttrs['action'] = BX_DOL_URL_ROOT . $this->_oConfig->getBaseUri() . 'submit_attach_link_form/';
  626. $oForm->aInputs['content_id']['value'] = $iContentId;
  627. $oForm->aInputs['url']['checker']['params']['preg'] = $this->_oConfig->getPregPattern('url');
  628. $oForm->initChecker();
  629. if($oForm->isSubmittedAndValid())
  630. return $this->_addLink($oForm);
  631. return array('form' => $oForm->getCode(), 'form_id' => $oForm->id);
  632. }
  633. protected function _addLink(&$oForm)
  634. {
  635. $CNF = &$this->_oConfig->CNF;
  636. $iUserId = $this->getUserId();
  637. $iContentId = (int)$oForm->getCleanValue('content_id');
  638. $sLink = rtrim($oForm->getCleanValue('url'), '/');
  639. $sHost = parse_url($sLink, PHP_URL_HOST);
  640. if (is_private_ip(gethostbyname($sHost)))
  641. return array('message' => _t('_sys_txt_error_occured'));
  642. $aMatches = array();
  643. preg_match($this->_oConfig->getPregPattern('url'), $sLink, $aMatches);
  644. $sLink = (empty($aMatches[2]) ? 'http://' : '') . $aMatches[0];
  645. $aSiteInfo = bx_get_site_info($sLink, array(
  646. 'thumbnailUrl' => array('tag' => 'link', 'content_attr' => 'href'),
  647. 'OGImage' => array('name_attr' => 'property', 'name' => 'og:image'),
  648. ));
  649. $sTitle = !empty($aSiteInfo['title']) ? $aSiteInfo['title'] : $sHost;
  650. $sDescription = !empty($aSiteInfo['description']) ? $aSiteInfo['description'] : '';
  651. $sMediaUrl = '';
  652. if(!empty($aSiteInfo['thumbnailUrl']))
  653. $sMediaUrl = $aSiteInfo['thumbnailUrl'];
  654. else if(!empty($aSiteInfo['OGImage']))
  655. $sMediaUrl = $aSiteInfo['OGImage'];
  656. $iMediaId = 0;
  657. $oStorage = null;
  658. if(!empty($sMediaUrl)) {
  659. $oStorage = BxDolStorage::getObjectInstance($CNF['OBJECT_STORAGE_PHOTOS']);
  660. $iMediaId = $oStorage->storeFileFromUrl($sMediaUrl, true, $iUserId);
  661. }
  662. $iId = (int)$oForm->insert(array('profile_id' => $iUserId, 'media_id' => $iMediaId, 'url' => $sLink, 'title' => $sTitle, 'text' => $sDescription, 'added' => time()));
  663. if(!empty($iId)) {
  664. if(!empty($oStorage) && !empty($iMediaId))
  665. $oStorage->afterUploadCleanup($iMediaId, $iUserId);
  666. return array(
  667. 'id' => $iId,
  668. 'content_id' => $iContentId,
  669. 'url' => $sLink,
  670. 'item' => $this->_oTemplate->getAttachLinkItem($iUserId, $iId)
  671. );
  672. }
  673. return array('message' => _t('_bx_timeline_txt_err_cannot_perform_action'));
  674. }
  675. public function onApprove($mixedContent)
  676. {
  677. $CNF = &$this->_oConfig->CNF;
  678. if(!is_array($mixedContent))
  679. $mixedContent = $this->_oDb->getContentInfoById((int)$mixedContent);
  680. $this->alertAfterApprove($mixedContent);
  681. $this->onPublished($mixedContent[$CNF['FIELD_ID']]);
  682. }
  683. public function alertAfterAdd($aContentInfo)
  684. {
  685. $CNF = &$this->_oConfig->CNF;
  686. $iId = (int)$aContentInfo[$CNF['FIELD_ID']];
  687. $iAuthorId = (int)$aContentInfo[$CNF['FIELD_AUTHOR']];
  688. $sAction = 'added';
  689. if(isset($CNF['FIELD_STATUS']) && isset($aContentInfo[$CNF['FIELD_STATUS']]) && $aContentInfo[$CNF['FIELD_STATUS']] == BX_BASE_MOD_TEXT_STATUS_AWAITING)
  690. $sAction = 'deferred';
  691. else if(isset($CNF['FIELD_STATUS_ADMIN']) && isset($aContentInfo[$CNF['FIELD_STATUS_ADMIN']]) && $aContentInfo[$CNF['FIELD_STATUS_ADMIN']] == BX_BASE_MOD_GENERAL_STATUS_PENDING)
  692. $sAction = 'deferred';
  693. $aParams = $this->_alertParamsAdd($aContentInfo);
  694. /**
  695. * @hooks
  696. * @hookdef hook-system-prepare_alert_params 'system', 'prepare_alert_params' - hook to override alert (hook) params
  697. * - $unit_name - equals `system`
  698. * - $action - equals `prepare_alert_params`
  699. * - $object_id - not used
  700. * - $sender_id - not used
  701. * - $extra_params - array of additional params with the following array keys:
  702. * - `unit` - [string] unit name
  703. * - `action` - [string] by ref, action, can be overridden in hook processing
  704. * - `object_id` - [int] by ref, object id, can be overridden in hook processing
  705. * - `sender_id` - [int] by ref, action performer profile id, can be overridden in hook processing
  706. * - `extras` - [array] by ref, extra params array as key&value pairs, can be overridden in hook processing
  707. * @hook @ref hook-system-prepare_alert_params
  708. */
  709. bx_alert('system', 'prepare_alert_params', 0, 0, [
  710. 'unit'=> $this->getName(),
  711. 'action' => &$sAction,
  712. 'object_id' => &$iId,
  713. 'sender_id' => &$iAuthorId,
  714. 'extras' => &$aParams
  715. ]);
  716. /**
  717. * @hooks
  718. * @hookdef hook-bx_base_text-added '{module_name}', 'added' - hook after content was added (published)
  719. * - $unit_name - module name
  720. * - $action - equals `added`
  721. * - $object_id - content id
  722. * - $sender_id - content author profile id
  723. * - $extra_params - array of additional params with the following array keys:
  724. * - `status` - [string] content status
  725. * - `status_admin` - [string] content admin status
  726. * - `privacy_view` - [int] or [string] privacy for view content action, @see BxDolPrivacy
  727. * - `cf` - [int] content's audience filter value
  728. * @hook @ref hook-bx_base_text-added
  729. */
  730. /**
  731. * @hooks
  732. * @hookdef hook-bx_base_text-deferred '{module_name}', 'deferred' - hook after content was added with pending approval status
  733. * It's equivalent to @ref hook-bx_base_text-added
  734. * @hook @ref hook-bx_base_text-deferred
  735. */
  736. bx_alert($this->getName(), $sAction, $iId, $iAuthorId, $aParams);
  737. $this->_processModerationNotifications($aContentInfo);
  738. }
  739. public function alertAfterEdit($aContentInfo)
  740. {
  741. $CNF = &$this->_oConfig->CNF;
  742. $iId = (int)$aContentInfo[$CNF['FIELD_ID']];
  743. $aParams = $this->_alertParamsEdit($aContentInfo);
  744. /**
  745. * @hooks
  746. * @hookdef hook-bx_base_text-edited '{module_name}', 'edited' - hook after content was changed
  747. * It's equivalent to @ref hook-bx_base_text-added
  748. * @hook @ref hook-bx_base_text-edited
  749. */
  750. bx_alert($this->getName(), 'edited', $iId, false, $aParams);
  751. }
  752. /**
  753. * Get array of params to be passed in Add/Edit Alert.
  754. */
  755. protected function _alertParams($aContentInfo)
  756. {
  757. $aParams = parent::_alertParams($aContentInfo);
  758. $CNF = &$this->_oConfig->CNF;
  759. if(!empty($CNF['FIELD_STATUS']) && isset($aContentInfo[$CNF['FIELD_STATUS']]))
  760. $aParams['status'] = $aContentInfo[$CNF['FIELD_STATUS']];
  761. if(!empty($CNF['FIELD_STATUS_ADMIN']) && isset($aContentInfo[$CNF['FIELD_STATUS_ADMIN']]))
  762. $aParams['status_admin'] = $aContentInfo[$CNF['FIELD_STATUS_ADMIN']];
  763. if(!empty($CNF['FIELD_ALLOW_VIEW_TO']) && isset($aContentInfo[$CNF['FIELD_ALLOW_VIEW_TO']]))
  764. $aParams['privacy_view'] = $aContentInfo[$CNF['FIELD_ALLOW_VIEW_TO']];
  765. if(!empty($CNF['FIELD_CF']) && isset($aContentInfo[$CNF['FIELD_CF']]))
  766. $aParams['cf'] = $aContentInfo[$CNF['FIELD_CF']];
  767. return $aParams;
  768. }
  769. protected function _alertParamsAdd($aContentInfo)
  770. {
  771. $aParams = $this->_alertParams($aContentInfo);
  772. $CNF = &$this->_oConfig->CNF;
  773. if(!empty($CNF['OBJECT_METATAGS']))
  774. $aParams['timeline_group'] = $this->_getAlertParamTimelineGroup($aContentInfo);
  775. return $aParams;
  776. }
  777. protected function _alertParamsEdit($aContentInfo)
  778. {
  779. $aParams = $this->_alertParams($aContentInfo);
  780. $CNF = &$this->_oConfig->CNF;
  781. if(!empty($CNF['OBJECT_METATAGS']))
  782. $aParams['timeline_group'] = $this->_getAlertParamTimelineGroup($aContentInfo);
  783. return $aParams;
  784. }
  785. protected function _getAlertParamTimelineGroup($aContentInfo)
  786. {
  787. $CNF = &$this->_oConfig->CNF;
  788. return [
  789. 'by' => $this->getName() . '_' . abs((int)$aContentInfo[$CNF['FIELD_AUTHOR']]) . '_' . (int)$aContentInfo[$CNF['FIELD_ID']],
  790. 'field' => 'owner_id'
  791. ];
  792. }
  793. public function getPollForm()
  794. {
  795. $CNF = &$this->_oConfig->CNF;
  796. if(empty($CNF['OBJECT_FORM_POLL']))
  797. return array('code' => 1, 'message' => '_sys_txt_error_occured');
  798. $iProfileId = bx_get_logged_profile_id();
  799. $oForm = BxDolForm::getObjectInstance($CNF['OBJECT_FORM_POLL'], $CNF['OBJECT_FORM_POLL_DISPLAY_ADD'], $this->_oTemplate);
  800. $oForm->aFormAttrs['action'] = BX_DOL_URL_ROOT . $this->_oConfig->getBaseUri() . 'submit_poll_form/';
  801. $oForm->initChecker();
  802. if($oForm->isSubmittedAndValid()) {
  803. $iId = $oForm->insert();
  804. if($iId)
  805. return array('code' => 0, 'id' => $iId, 'item' => $this->_oTemplate->getPollItem($iId, $iProfileId, array(
  806. 'manage' => true
  807. )));
  808. else
  809. return array('code' => 2, 'message' => '_sys_txt_error_entry_creation');
  810. }
  811. return array('form' => $oForm->getCode(), 'form_id' => $oForm->id);
  812. }
  813. public function getEntryImageData($aContentInfo, $sField = 'FIELD_THUMB', $aTranscoders = array())
  814. {
  815. $CNF = &$this->_oConfig->CNF;
  816. $mResult = parent::getEntryImageData($aContentInfo, $sField, $aTranscoders);
  817. if ($mResult === false && isset($CNF['PARAM_USE_GALERY_AS_COVER']) && getParam($CNF['PARAM_USE_GALERY_AS_COVER']) == 'on'){
  818. if(!empty($CNF['OBJECT_STORAGE_PHOTOS']) && !empty($CNF['OBJECT_IMAGES_TRANSCODER_PREVIEW_PHOTOS'])){
  819. $sStorage = $CNF['OBJECT_STORAGE_PHOTOS'];
  820. $oStorage = BxDolStorage::getObjectInstance($sStorage);
  821. $aGhostFiles = $oStorage->getGhosts ($this->serviceGetContentOwnerProfileId($aContentInfo[$CNF['FIELD_ID']]), $aContentInfo[$CNF['FIELD_ID']]);
  822. if ($aGhostFiles){
  823. foreach ($aGhostFiles as $k => $a) {
  824. return array('id' => $a['id'], 'transcoder' => $CNF['OBJECT_IMAGES_TRANSCODER_PREVIEW_PHOTOS']);
  825. }
  826. }
  827. }
  828. }
  829. return $mResult;
  830. }
  831. public function decodeDataAPI($aData, $aParams = [])
  832. {
  833. $CNF = &$this->_oConfig->CNF;
  834. $sModule = $this->getName();
  835. $iId = (int)$aData[$CNF['FIELD_ID']];
  836. $sSummary = '';
  837. if(!empty($CNF['PARAM_CHARS_SUMMARY_PLAIN'])) {
  838. $sSummary = $this->_oTemplate->getText($aData);
  839. $sSummary = BxTemplFunctions::getInstance()->getStringWithLimitedLength(strip_tags($sSummary), (int)getParam($CNF['PARAM_CHARS_SUMMARY_PLAIN']));
  840. }
  841. $aResult = [
  842. 'id' => $iId,
  843. 'module' => $sModule,
  844. 'module_title' => _t($CNF['T']['txt_sample_single']),
  845. 'added' => $aData[$CNF['FIELD_ADDED']],
  846. 'author' => $aData[$CNF['FIELD_AUTHOR']],
  847. 'author_data' => !empty($aData[$CNF['FIELD_AUTHOR']]) ? BxDolProfile::getData($aData[$CNF['FIELD_AUTHOR']]) : '',
  848. 'title' => $aData[$CNF['FIELD_TITLE']],
  849. 'url' => bx_api_get_relative_url($this->serviceGetLink($iId)),
  850. 'image' => $this->serviceGetThumb($iId),
  851. 'summary_plain' => $sSummary
  852. ];
  853. if(isset($aParams['extended']) && $aParams['extended'] === true)
  854. $aResult['text'] = $aData[$CNF['FIELD_TEXT']];
  855. if(!empty($CNF['OBJECT_MENU_SNIPPET_META']) && ($oMetaMenu = BxDolMenu::getObjectInstance($CNF['OBJECT_MENU_SNIPPET_META'], $this->_oTemplate)) !== false) {
  856. $oMetaMenu->setContentId($iId);
  857. $aResult['meta'] = $oMetaMenu->getCodeAPI();
  858. }
  859. return $aResult;
  860. }
  861. // ====== PROTECTED METHODS
  862. protected function _getImagesForTimelinePost($aEvent, $aContentInfo, $sUrl, $aBrowseParams = array())
  863. {
  864. $CNF = &$this->_oConfig->CNF;
  865. $aResults = parent::_getImagesForTimelinePost($aEvent, $aContentInfo, $sUrl, $aBrowseParams);
  866. if (bx_is_api())
  867. return $aResults;
  868. if (count($aResults) == 0 && isset($CNF['PARAM_USE_GALERY_AS_COVER']) && getParam($CNF['PARAM_USE_GALERY_AS_COVER']) == 'on'){
  869. $aResults = $this->_getImagesForTimelinePostAttachInner($aEvent, $aContentInfo, $sUrl, $aBrowseParams);
  870. if (count($aResults) > 1){
  871. $aResults = array_slice($aResults, 0, 1);
  872. }
  873. }
  874. return $aResults;
  875. }
  876. protected function _getImagesForTimelinePostAttach($aEvent, $aContentInfo, $sUrl, $aBrowseParams = array())
  877. {
  878. $CNF = &$this->_oConfig->CNF;
  879. $aTmp = parent::_getImagesForTimelinePost($aEvent, $aContentInfo, $sUrl, $aBrowseParams);
  880. $aResults = $this->_getImagesForTimelinePostAttachInner($aEvent, $aContentInfo, $sUrl, $aBrowseParams);
  881. if (bx_is_api())
  882. return $aResults;
  883. if (count($aTmp) == 0 && count($aResults) > 0 && isset($CNF['PARAM_USE_GALERY_AS_COVER']) && getParam($CNF['PARAM_USE_GALERY_AS_COVER']) == 'on'){
  884. $aResults = array_slice($aResults, 1);
  885. }
  886. return $aResults;
  887. }
  888. protected function _getImagesForTimelinePostAttachInner($aEvent, $aContentInfo, $sUrl, $aBrowseParams = array())
  889. {
  890. $CNF = &$this->_oConfig->CNF;
  891. $aResults = parent::_getImagesForTimelinePostAttach($aEvent, $aContentInfo, $sUrl, $aBrowseParams);
  892. if(!$this->_oConfig->isAttachmentsInTimeline() || empty($CNF['OBJECT_STORAGE_PHOTOS']) || empty($CNF['OBJECT_IMAGES_TRANSCODER_GALLERY_PHOTOS']))
  893. return $aResults;
  894. $iContentId = (int)$aContentInfo[$CNF['FIELD_ID']];
  895. $oStorage = BxDolStorage::getObjectInstance($CNF['OBJECT_STORAGE_PHOTOS']);
  896. $aGhostFiles = $oStorage->getGhosts($this->serviceGetContentOwnerProfileId($iContentId), $iContentId);
  897. if(!$aGhostFiles)
  898. return [];
  899. $oTranscoderSm = false;
  900. if(!empty($CNF['OBJECT_IMAGES_TRANSCODER_MINIATURE_PHOTOS']))
  901. $oTranscoderSm = BxDolTranscoderImage::getObjectInstance($CNF['OBJECT_IMAGES_TRANSCODER_MINIATURE_PHOTOS']);
  902. $oTranscoderMd = BxDolTranscoderImage::getObjectInstance($CNF['OBJECT_IMAGES_TRANSCODER_GALLERY_PHOTOS']);
  903. $oTranscoderXl = false;
  904. if(!empty($CNF['OBJECT_IMAGES_TRANSCODER_VIEW_PHOTOS']))
  905. $oTranscoderXl = BxDolTranscoderImage::getObjectInstance($CNF['OBJECT_IMAGES_TRANSCODER_VIEW_PHOTOS']);
  906. foreach($aGhostFiles as $k => $a) {
  907. $sPhotoSrcMd = $oTranscoderMd->getFileUrl($a['id']);
  908. if(empty($sPhotoSrcMd))
  909. continue;
  910. $sPhotoSrcSm = $oTranscoderSm !== false ? $oTranscoderSm->getFileUrl($a['id']) : '';
  911. if(!$sPhotoSrcSm)
  912. $sPhotoSrcSm = $sPhotoSrcMd;
  913. $sPhotoSrcXl = $oTranscoderXl !== false ? $oTranscoderXl->getFileUrl($a['id']) : $oStorage->getFileUrlById($a['id']);
  914. if(!$sPhotoSrcXl)
  915. $sPhotoSrcXl = $sPhotoSrcMd;
  916. if (bx_is_api()){
  917. $aResults[] = bx_api_get_image($CNF['OBJECT_STORAGE_PHOTOS'], (int)$a['id']);
  918. }
  919. else{
  920. $aResults[] = [
  921. 'id' => $a['id'],
  922. 'src' => $sPhotoSrcMd,
  923. 'src_small' => $sPhotoSrcSm,
  924. 'src_medium' => $sPhotoSrcMd,
  925. 'src_orig' => $sPhotoSrcXl,
  926. ];
  927. }
  928. }
  929. return $aResults;
  930. }
  931. protected function _getVideosForTimelinePostAttach($aEvent, $aContentInfo, $sUrl, $aBrowseParams = array())
  932. {
  933. $CNF = &$this->_oConfig->CNF;
  934. $aResults = parent::_getVideosForTimelinePostAttach($aEvent, $aContentInfo, $sUrl, $aBrowseParams);
  935. if(!$this->_oConfig->isAttachmentsInTimeline() || empty($CNF['OBJECT_STORAGE_VIDEOS']) || empty($CNF['OBJECT_VIDEOS_TRANSCODERS']))
  936. return $aResults;
  937. $iContentId = (int)$aContentInfo[$CNF['FIELD_ID']];
  938. $oStorage = BxDolStorage::getObjectInstance($CNF['OBJECT_STORAGE_VIDEOS']);
  939. $aGhostFiles = $oStorage->getGhosts($this->serviceGetContentOwnerProfileId($iContentId), $iContentId);
  940. if(!$aGhostFiles)
  941. return array();
  942. $oTcPoster = BxDolTranscoderVideo::getObjectInstance($CNF['OBJECT_VIDEOS_TRANSCODERS']['poster']);
  943. $oTcMp4 = BxDolTranscoderVideo::getObjectInstance($CNF['OBJECT_VIDEOS_TRANSCODERS']['mp4']);
  944. $oTcMp4Hd = BxDolTranscoderVideo::getObjectInstance($CNF['OBJECT_VIDEOS_TRANSCODERS']['mp4_hd']);
  945. if(!$oTcPoster || !$oTcMp4 || !$oTcMp4Hd)
  946. return array();
  947. $aResults = array();
  948. foreach ($aGhostFiles as $k => $a) {
  949. $sVideoUrl = $oStorage->getFileUrlById($a['id']);
  950. $aVideoFile = $oStorage->getFile($a['id']);
  951. $sVideoUrlHd = '';
  952. if (!empty($aVideoFile['dimensions']) && $oTcMp4Hd->isProcessHD($aVideoFile['dimensions']))
  953. $sVideoUrlHd = $oTcMp4Hd->getFileUrl($a['id']);
  954. $aResults[$a['id']] = array(
  955. 'id' => $a['id'],
  956. 'src_poster' => $oTcPoster->getFileUrl($a['id']),
  957. 'src_mp4' => $oTcMp4->getFileUrl($a['id']),
  958. 'src_mp4_hd' => $sVideoUrlHd,
  959. );
  960. }
  961. return $aResults;
  962. }
  963. protected function _getFilesForTimelinePostAttach($aEvent, $aContentInfo, $sUrl, $aBrowseParams = array())
  964. {
  965. $CNF = &$this->_oConfig->CNF;
  966. $aResults = parent::_getFilesForTimelinePostAttach($aEvent, $aContentInfo, $sUrl, $aBrowseParams);
  967. if(!$this->_oConfig->isAttachmentsInTimeline() || empty($CNF['OBJECT_STORAGE_FILES']))
  968. return $aResults;
  969. $iContentId = (int)$aContentInfo[$CNF['FIELD_ID']];
  970. $oStorage = BxDolStorage::getObjectInstance($CNF['OBJECT_STORAGE_FILES']);
  971. $aGhostFiles = $oStorage->getGhosts($this->serviceGetContentOwnerProfileId($iContentId), $iContentId);
  972. if(!$aGhostFiles)
  973. return array();
  974. $oTranscoder = null;
  975. if(!empty($CNF['OBJECT_IMAGES_TRANSCODER_GALLERY_FILES']))
  976. $oTranscoder = BxDolTranscoderImage::getObjectInstance($CNF['OBJECT_IMAGES_TRANSCODER_GALLERY_FILES']);
  977. foreach ($aGhostFiles as $k => $a) {
  978. $bImage = in_array($a['ext'], array('jpg', 'jpeg', 'png', 'gif'));
  979. $sPhotoSrc = '';
  980. if($bImage && $oTranscoder)
  981. $sPhotoSrc = $oTranscoder->getFileUrl($a['id']);
  982. if(empty($sPhotoSrc) && $oStorage)
  983. $sPhotoSrc = $this->_oTemplate->getIconUrl($oStorage->getIconNameByFileName($a['file_name']));
  984. $sUrl = $oStorage->getFileUrlById($a['id']);
  985. $aResults[] = array(
  986. 'id' => $a['id'],
  987. 'src' => $sPhotoSrc,
  988. 'src_medium' => $sPhotoSrc,
  989. 'src_orig' => $bImage ? $sUrl : '',
  990. 'url' => !$bImage ? $sUrl : ''
  991. );
  992. }
  993. return $aResults;
  994. }
  995. protected function _getContentForTimelinePost($aEvent, $aContentInfo, $aBrowseParams = array())
  996. {
  997. $aResult = parent::_getContentForTimelinePost($aEvent, $aContentInfo, $aBrowseParams);
  998. if(!$this->_oConfig->isAttachmentsInTimeline())
  999. return $aResult;
  1000. $CNF = &$this->_oConfig->CNF;
  1001. $bDynamic = isset($aBrowseParams['dynamic_mode']) && (bool)$aBrowseParams['dynamic_mode'] === true;
  1002. if(!empty($CNF['PARAM_POLL_ENABLED']) && $CNF['PARAM_POLL_ENABLED'] == true)
  1003. $aPolls = $this->_oDb->getPolls(array('type' => 'content_id', 'content_id' => (int)$aContentInfo[$CNF['FIELD_ID']]));
  1004. if(!empty($aPolls) && is_array($aPolls)) {
  1005. $sInclude = $this->_oTemplate->addCss(array('polls.css'), $bDynamic);
  1006. $aResult['raw'] = ($bDynamic ? $sInclude : '') . $this->_oTemplate->parseHtmlByName('poll_items_embed.html', array(
  1007. 'embed_url' => BX_DOL_URL_ROOT . bx_append_url_params($this->_oConfig->getBaseUri() . 'embed_polls/', array(
  1008. 'id' => (int)$aContentInfo[$CNF['FIELD_ID']],
  1009. 'param_switch_menu' => 0,
  1010. 'param_showcase' => 1
  1011. ))
  1012. ));
  1013. /*
  1014. if((!empty($aResult['videos']) && is_array($aResult['videos'])) || (!empty($aResult['videos_attach']) && is_array($aResult['videos_attach'])))
  1015. $aResult['_cache'] = false;
  1016. */
  1017. }
  1018. return $aResult;
  1019. }
  1020. protected function _buildRssParams($sMode, $aArgs)
  1021. {
  1022. $aParams = array ();
  1023. $sMode = bx_process_input($sMode);
  1024. switch ($sMode) {
  1025. case 'author':
  1026. $aParams = array('author' => isset($aArgs[0]) ? (int)$aArgs[0] : '');
  1027. break;
  1028. }
  1029. return $aParams;
  1030. }
  1031. public function serviceIsAllowedPostInContext()
  1032. {
  1033. return true;
  1034. }
  1035. }
  1036. /** @} */