BxTimelineTemplate.php 128 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226
  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 Timeline Timeline
  7. * @ingroup UnaModules
  8. *
  9. * @{
  10. */
  11. class BxTimelineTemplate extends BxBaseModNotificationsTemplate
  12. {
  13. protected static $_aMemoryCacheItems;
  14. protected static $_aMemoryCacheItemsData;
  15. protected static $_sMemoryCacheItemsKeyMask;
  16. protected static $_sTmplContentItemItem;
  17. protected static $_sTmplContentItemOutline;
  18. protected static $_sTmplContentItemOutlineSample;
  19. protected static $_sTmplContentItemTimeline;
  20. protected static $_sTmplContentItemTimelineSample;
  21. protected static $_sTmplContentItemSearch;
  22. protected static $_sTmplContentTypePost;
  23. protected static $_sTmplContentTypeRepost;
  24. protected $_aAclId2Name;
  25. function __construct(&$oConfig, &$oDb)
  26. {
  27. parent::__construct($oConfig, $oDb);
  28. $this->_aAclId2Name = array();
  29. bx_import('BxTemplAcl');
  30. $aAclLevels = BxDolAcl::getInstance()->getMemberships(false, false, false);
  31. foreach($aAclLevels as $iAclId => $sAclName)
  32. $this->_aAclId2Name[$iAclId] = str_replace('_', '-', str_replace('_adm_prm_txt_level_', '', $sAclName));
  33. }
  34. public function init()
  35. {
  36. parent::init();
  37. self::$_aMemoryCacheItems = array();
  38. self::$_aMemoryCacheItemsData = array();
  39. self::$_sMemoryCacheItemsKeyMask = "%s_%d";
  40. }
  41. public function getAddedCss($sType = '', $bDynamic = false)
  42. {
  43. $aCss = array();
  44. switch($sType) {
  45. case 'view':
  46. $aCss = array(
  47. BX_DIRECTORY_PATH_PLUGINS_PUBLIC . 'flickity/|flickity.css',
  48. 'cmts.css',
  49. 'view.css',
  50. 'view-media-tablet.css',
  51. 'view-media-desktop.css',
  52. 'repost.css',
  53. );
  54. if($this->_oConfig->isJumpTo()) {
  55. list($aCssCalendar, $aJsCalendar) = BxBaseFormView::getCssJsCalendar();
  56. $aCss = array_merge($aCss, $aCssCalendar);
  57. }
  58. break;
  59. case 'post':
  60. $aCss[] = 'post.css';
  61. break;
  62. }
  63. $mixedResult = $this->addCss($aCss, $bDynamic);
  64. if($bDynamic)
  65. return $mixedResult;
  66. }
  67. public function getAddedJs($sType = '', $bDynamic = false)
  68. {
  69. $aJs = array(
  70. 'autosize.min.js',
  71. 'jquery.anim.js',
  72. 'main.js',
  73. );
  74. switch($sType) {
  75. case 'view':
  76. $aJs = array_merge($aJs, array(
  77. 'masonry.pkgd.min.js',
  78. 'flickity/flickity.pkgd.min.js',
  79. 'embedly-player.min.js',
  80. 'BxDolCmts.js',
  81. 'view.js',
  82. 'repost.js',
  83. ));
  84. if ($this->_oConfig->isJumpTo()) {
  85. list($aCssCalendar, $aJsCalendar) = BxBaseFormView::getCssJsCalendar();
  86. $aJs = array_merge($aJs, $aJsCalendar);
  87. }
  88. break;
  89. case 'post':
  90. $aJs = array_merge($aJs, array(
  91. 'jquery.form.min.js',
  92. 'post.js',
  93. ));
  94. break;
  95. }
  96. $mixedResult = $this->addJs($aJs, $bDynamic);
  97. if($bDynamic)
  98. return $mixedResult;
  99. }
  100. public function getJsCodeView($aParams = array(), $bWrap = true, $bDynamic = false)
  101. {
  102. $aParams = array_merge([
  103. 'sObjNameMenuFeeds' => $this->_oConfig->getObject('menu_feeds'),
  104. 'bInfScroll' => $this->_oConfig->isInfiniteScroll(),
  105. 'iInfScrollAutoPreloads' => $this->_oConfig->getAutoPreloads(),
  106. 'iLimitAttachLinks' => $this->_oConfig->getLimitAttachLinks(),
  107. 'sLimitAttachLinksErr' => bx_js_string(_t('_bx_timeline_txt_err_attach_links')),
  108. 'oAttachedLinks' => []
  109. ], $aParams);
  110. return parent::getJsCode('view', $aParams, $bWrap, $bDynamic);
  111. }
  112. public function getJsCodePost($iOwnerId, $aParams = array(), $bWrap = true, $bDynamic = false)
  113. {
  114. $aGeneralParams = [];
  115. $aRequestParams = $aParams;
  116. if(isset($aParams['gparams'], $aParams['rparams'])) {
  117. $aGeneralParams = $aParams['gparams'];
  118. $aRequestParams = $aParams['rparams'];
  119. }
  120. return $this->getJsCode('post', array_merge(array(
  121. 'bAutoAttach' => $this->_oConfig->isEditorAutoAttach(),
  122. 'bMediaPriority' => $this->_oConfig->isMediaPriority(),
  123. 'iLimitAttachLinks' => $this->_oConfig->getLimitAttachLinks(),
  124. 'sLimitAttachLinksErr' => bx_js_string(_t('_bx_timeline_txt_err_attach_links')),
  125. 'oAttachedLinks' => $this->_oDb->getLinksBy(array(
  126. 'type' => 'unused',
  127. 'profile_id' => $this->getModule()->getUserId(),
  128. 'short' => true
  129. )),
  130. 'sVideosAutoplay' => $this->_oConfig->getVideosAutoplay(),
  131. 'oRequestParams' => array_merge(array(
  132. 'type' => isset($aRequestParams['type']) ? $aRequestParams['type'] : BX_TIMELINE_TYPE_DEFAULT,
  133. 'owner_id' => $iOwnerId
  134. ), $aRequestParams)
  135. ), $aGeneralParams), $bWrap, $bDynamic);
  136. }
  137. public function getPostBlock($iOwnerId, $aParams = array())
  138. {
  139. $CNF = &$this->_oConfig->CNF;
  140. $oModule = $this->getModule();
  141. $aResult = $oModule->getFormPost($aParams);
  142. if($this->_oConfig->isEditorAutoattach() && !empty($aResult['form_object'])) {
  143. $aUploadersInfo = $aResult['form_object']->getUploadersInfo($CNF['FIELD_PHOTO']);
  144. if(!empty($aUploadersInfo) && is_array($aUploadersInfo))
  145. $aParams = [
  146. 'gparams' => ['sAutoUploader' => $aUploadersInfo['name'], 'sAutoUploaderId' => $aUploadersInfo['id']],
  147. 'rparams' => $aParams
  148. ];
  149. }
  150. if(bx_is_api()) {
  151. $aType2Uri = [
  152. '' => 'get_block_post_account',
  153. 'account' => 'get_block_post_account',
  154. 'feed' => 'get_block_post_account',
  155. 'owner' => 'get_block_post_profile',
  156. 'profile' => 'get_block_post_profile',
  157. 'public' => 'get_block_post_home'
  158. ];
  159. $sType = '';
  160. if(isset($aParams['rparams']['type']))
  161. $sType = $aParams['rparams']['type'];
  162. else
  163. $sType = trim(str_replace('bx_timeline_post_add', '', $aResult['form_object']->aParams['display']), '_');
  164. $oProfileOwner = BxDolProfile::getInstance($iOwnerId);
  165. $aExt = ['request' => ['url' => $sUrl = '/api.php?r=' . $this->_oModule->getName() . '/' . $aType2Uri[$sType] . '&params[]=' . $oProfileOwner->getModule() . '&params[]=' . $oProfileOwner->getContentId(), 'immutable' => true]];
  166. if(!empty($aResult['id'])) {
  167. $aItemData = $oModule->getItemData($aResult['id']);
  168. if(is_array($aItemData) && !empty($aItemData['event']))
  169. $aExt['response'] = $this->_getPostApi($aItemData['event'], $aParams);
  170. }
  171. $aExt['name'] = 'feed';
  172. return [
  173. bx_api_get_block('form', $aResult['form_object']->getCodeAPI(), ['ext' => $aExt])
  174. ];
  175. }
  176. return $this->parseHtmlByName('block_post.html', array (
  177. 'style_prefix' => $this->_oConfig->getPrefix('style'),
  178. 'js_object' => $this->_oConfig->getJsObject('post'),
  179. 'js_content' => $this->getJsCodePost($iOwnerId, $aParams),
  180. 'form' => $aResult['form']
  181. ));
  182. }
  183. public function getViewsBlock($aParams)
  184. {
  185. $sStylePrefix = $this->_oConfig->getPrefix('style');
  186. $sJsObject = $this->_oConfig->getJsObjectView($aParams);
  187. $sType = isset($aParams['type']) ? $aParams['type'] : '';
  188. $sMenu = $this->_oConfig->getObject('menu_view');
  189. $oMenu = BxDolMenu::getObjectInstance($sMenu);
  190. $aMenuItems = $oMenu->getMenuItems();
  191. if(empty($aMenuItems) || !is_array($aMenuItems))
  192. return '';
  193. if(empty($sType)) {
  194. $aMenuItem = array_shift($aMenuItems);
  195. $sType = $aMenuItem['name'];
  196. }
  197. $oMenu->setSelected($this->_oConfig->getName(), $sType);
  198. $oMenu->addMarkers(array(
  199. 'js_object_view' => $sJsObject
  200. ));
  201. $sTitle = _t('_bx_timeline_page_block_title_views_' . $aParams['view']);
  202. if (bx_is_api())
  203. return [
  204. 'content' => [bx_api_get_block('browse', ['unit' => 'feed', 'data' => $this->getViewBlock($aParams)])],
  205. 'menu' => $oMenu->getCodeAPI()
  206. ];
  207. return [
  208. 'content' => $this->parseHtmlByName('block_views.html', [
  209. 'style_prefix' => $sStylePrefix,
  210. 'html_id' => $this->_oConfig->getHtmlIdView('views', $aParams, ['with_type' => false]),
  211. 'html_id_content' => $this->_oConfig->getHtmlIdView('views_content', $aParams, ['with_type' => false]),
  212. 'html_id_view_placeholder' => $this->_oConfig->getHtmlIdView('main', array_merge($aParams, ['type' => 'placeholder'])),
  213. 'title' => $sTitle,
  214. 'content' => $this->getViewBlock($aParams)
  215. ]),
  216. 'menu' => $oMenu
  217. ];
  218. }
  219. public function getViewsDbBlock($aParams)
  220. {
  221. $sStylePrefix = $this->_oConfig->getPrefix('style');
  222. $sJsObject = $this->_oConfig->getJsObjectView($aParams);
  223. $sJsContent = $this->getJsCodeView([
  224. 'sObjName' => $sJsObject,
  225. 'sName' => $aParams['name'],
  226. 'sView' => $aParams['view'],
  227. 'sType' => $aParams['type'],
  228. 'sVideosAutoplay' => $this->_oConfig->getVideosAutoplay(),
  229. 'oRequestParams' => $aParams
  230. ], [
  231. 'wrap' => true,
  232. 'mask_markers' => ['object' => $sJsObject]
  233. ]);
  234. return array(
  235. 'content' => $this->parseHtmlByName('block_views_db.html', array(
  236. 'style_prefix' => $sStylePrefix,
  237. 'html_id' => $this->_oConfig->getHtmlIdView('views', $aParams, array('with_type' => false)),
  238. 'html_id_content' => $this->_oConfig->getHtmlIdView('views_content', $aParams, array('with_type' => false)),
  239. 'content' => $this->getViewBlock(array_merge($aParams, ['name' => ''])),
  240. 'js_content' => $sJsContent
  241. )),
  242. 'buttons' => [
  243. ['title' => _t('_bx_timeline_txt_filters'), 'href' => 'javascript:void(0)', 'onclick' => 'javascript:' . $sJsObject . '.changeFeedFilters(this)']
  244. ]
  245. );
  246. }
  247. public function getViewFilters($aParams)
  248. {
  249. $sStylePrefix = $this->_oConfig->getPrefix('style');
  250. $sJsObject = $this->_oConfig->getJsObjectView($aParams);
  251. $aHandlers = $this->_oDb->getHandlers(['type' => 'by_type', 'value' => 'insert']);
  252. $aModules = [];
  253. foreach($aHandlers as $aHandler) {
  254. $sModule = $aHandler['alert_unit'];
  255. if(isset($aModules[$sModule]))
  256. continue;
  257. $aModule = $this->_oDb->getModuleByName($sModule);
  258. if(empty($aModule) || !is_array($aModule))
  259. continue;
  260. $sTitleKey = '_' . $sModule;
  261. $sTitleValue = _t($sTitleKey);
  262. if(strcmp($sTitleKey, $sTitleValue) == 0)
  263. $sTitleValue = $aModule['title'];
  264. $aModules[$sModule] = [
  265. 'key' => $aHandler['alert_unit'],
  266. 'value' => $sTitleValue
  267. ];
  268. }
  269. uasort($aModules, function($aV1, $aV2) {
  270. return strcmp($aV1['value'], $aV2['value']);
  271. });
  272. $aForm = [
  273. 'inputs' => [
  274. 'by_module' => [
  275. 'name' => 'by_module',
  276. 'type' => 'radio_set',
  277. 'caption' => _t('_bx_timeline_form_filters_input_by_modules'),
  278. 'values' => [
  279. ['key' => 'all', 'value' => _t('_bx_timeline_form_filters_input_by_modules_all')],
  280. ['key' => 'selected', 'value' => _t('_bx_timeline_form_filters_input_by_modules_selected')]
  281. ],
  282. 'value' => 'all',
  283. 'attrs' => ['onchange' => $sJsObject . '.onFilterByModuleChange(this)'],
  284. 'dv_thd' => 1
  285. ],
  286. 'modules' => [
  287. 'name' => 'modules',
  288. 'type' => 'checkbox_set',
  289. 'values' => array_values($aModules),
  290. 'tr_attrs' => ['class' => 'modules', 'style' => 'display:none']
  291. ],
  292. 'apply' => [
  293. 'name' => 'apply',
  294. 'type' => 'button',
  295. 'value' => _t('_bx_timeline_form_filters_input_do_apply'),
  296. 'attrs' => ['onclick' => $sJsObject . '.onFilterApply(this)']
  297. ]
  298. ]
  299. ];
  300. $oForm = new BxTemplFormView($aForm);
  301. $sViewFiltersPopupId = $this->_oConfig->getHtmlIdView('filters_popup', $aParams);
  302. $sViewFiltersPopupContent = $this->parseHtmlByName('block_view_filters.html', array(
  303. 'style_prefix' => $sStylePrefix,
  304. 'js_object' => $sJsObject,
  305. 'content' => $oForm->genRows()
  306. ));
  307. return BxTemplFunctions::getInstance()->transBox($sViewFiltersPopupId, $sViewFiltersPopupContent, true);
  308. }
  309. public function getViewBlock($aParams)
  310. {
  311. $oModule = $this->getModule();
  312. if(bx_is_api()) {
  313. if(defined('BX_API_PAGE'))
  314. return [];
  315. $oMenuActions = BxDolMenu::getObjectInstance($this->_oConfig->getObject('menu_item_actions_all'));
  316. if(!$oMenuActions)
  317. $oMenuActions = BxDolMenu::getObjectInstance($this->_oConfig->getObject('menu_item_actions'));
  318. $oMenuManage = BxDolMenu::getObjectInstance($this->_oConfig->getObject('menu_item_manage'));
  319. $aPosts = $this->getPosts(array_merge($aParams, ['return_data_type' => 'array']));
  320. foreach($aPosts as &$aPost)
  321. $aPost = $this->_getPostApi($aPost, $aParams, [
  322. 'menu_actions' => $oMenuActions,
  323. 'menu_manage' => $oMenuManage
  324. ]);
  325. return $aPosts;
  326. }
  327. list($sContent, $sLoadMore, $sBack, $sEmpty, $iEvent, $bEventsToLoad) = $this->getPosts($aParams);
  328. //--- Add live update
  329. $oModule->actionResumeLiveUpdate($aParams['type'], $aParams['owner_id']);
  330. $sModuleName = $oModule->getName();
  331. $sModuleMethod = !empty($aParams['get_live_updates']) ? $aParams['get_live_updates'] : 'get_live_update';
  332. $sService = BxDolService::getSerializedService($sModuleName, $sModuleMethod, [$aParams, $oModule->getUserId(), '{count}', '{init}']);
  333. $aLiveUpdateParams = [$this->_oConfig->getLiveUpdateKey($aParams), 1, $sService, [true, false]];
  334. if($sModuleMethod == 'get_live_update')
  335. $aLiveUpdateParams[] = $iEvent;
  336. $sLiveUpdateCode = null;
  337. bx_alert($sModuleName, 'add_live_update', 0, 0, [
  338. 'browse_params' => $aParams,
  339. 'live_update_params' => &$aLiveUpdateParams,
  340. 'override_result' => &$sLiveUpdateCode,
  341. ]);
  342. if($sLiveUpdateCode === null && ($oLiveUpdates = BxDolLiveUpdates::getInstance()) !== false)
  343. $sLiveUpdateCode = call_user_func_array([$oLiveUpdates, 'add'], $aLiveUpdateParams);
  344. //--- Add live update
  345. $sContentBefore = '';
  346. $sContentAfter = '';
  347. $sJsObject = $this->_oConfig->getJsObjectView($aParams);
  348. $sJsContent = $this->getJsCodeView(array(
  349. 'sObjName' => $sJsObject,
  350. 'sName' => $aParams['name'],
  351. 'sView' => $aParams['view'],
  352. 'sType' => $aParams['type'],
  353. 'sVideosAutoplay' => $this->_oConfig->getVideosAutoplay(),
  354. 'bEventsToLoad' => $bEventsToLoad,
  355. 'bAutoMarkAsViewed' => $this->_oConfig->isSortByUnread(),
  356. 'oRequestParams' => $aParams
  357. ), array(
  358. 'wrap' => true,
  359. 'mask_markers' => array('object' => $sJsObject)
  360. )) . $this->getJsCode('repost');
  361. bx_alert($sModuleName, 'get_view', 0, 0, array(
  362. 'params' => $aParams,
  363. 'event_first' => $iEvent,
  364. 'back' => &$sBack,
  365. 'empty' => &$sEmpty,
  366. 'content_before' => &$sContentBefore,
  367. 'content' => &$sContent,
  368. 'content_after' => &$sContentAfter,
  369. 'load_more' => &$sLoadMore,
  370. 'js_content' => &$sJsContent
  371. ));
  372. return $this->parseHtmlByName('block_view.html', array(
  373. 'style_prefix' => $this->_oConfig->getPrefix('style'),
  374. 'html_id' => $this->_oConfig->getHtmlIdView('main', $aParams),
  375. 'view' => $aParams['view'],
  376. 'back' => $sBack,
  377. 'empty' => $sEmpty,
  378. 'content_before' => $sContentBefore,
  379. 'content' => $sContent,
  380. 'content_after' => $sContentAfter,
  381. 'load_more' => $sLoadMore,
  382. 'show_more' => $this->_getShowMore($aParams),
  383. 'view_image_popup' => $this->_getImagePopup($aParams),
  384. 'live_update_code' => $sLiveUpdateCode,
  385. 'js_content' => $sJsContent
  386. ));
  387. }
  388. public function getSearchBlock($sContent)
  389. {
  390. $oModule = $this->getModule();
  391. $aParams = $oModule->getParams(BX_TIMELINE_VIEW_SEARCH);
  392. return $this->parseHtmlByName('block_search.html', array(
  393. 'style_prefix' => $this->_oConfig->getPrefix('style'),
  394. 'html_id' => $this->_oConfig->getHtmlIdView('main', $aParams),
  395. 'view' => $aParams['view'],
  396. 'content' => $sContent,
  397. 'view_image_popup' => $this->_getImagePopup($aParams),
  398. 'js_content' => $this->getJsCodeView(array(
  399. 'oRequestParams' => $aParams
  400. ))
  401. ));
  402. }
  403. public function getItemBlock($mixedId, $aBrowseParams = array())
  404. {
  405. $CNF = $this->_oConfig->CNF;
  406. $oModule = $this->getModule();
  407. if(is_numeric($mixedId))
  408. $mixedId = $oModule->getItemData($mixedId);
  409. if(empty($mixedId) || !is_array($mixedId))
  410. return array('content' => MsgBox(_t('_Empty')), 'designbox_id' => 13);
  411. if($mixedId['code'] != 0)
  412. return array('content' => MsgBox($mixedId['content']), 'designbox_id' => 13);
  413. $aEvent = $mixedId['event'];
  414. $sContent = $mixedId['content'];
  415. if(!$this->_oConfig->isSystem($aEvent['type'], $aEvent['action'])) {
  416. $mixedViews = $oModule->getViewsData($aEvent['views']);
  417. if($mixedViews !== false) {
  418. list($sSystem, $iObjectId) = $mixedViews;
  419. $oModule->getViewObject($sSystem, $iObjectId)->doView();
  420. }
  421. }
  422. $sAuthorName = $oModule->getObjectUser($aEvent['object_owner_id'])->getDisplayName();
  423. $sTitle = $sAuthorName . ' ' . _t($aEvent['sample_action'], _t($aEvent['sample']));
  424. $sDescription = $aEvent['title'];
  425. if(get_mb_substr($sDescription, 0, 1) == '_')
  426. $sDescription = _t($sDescription);
  427. $oTemplate = BxDolTemplate::getInstance();
  428. $oTemplate->setPageHeader(strip_tags($sTitle));
  429. $oTemplate->setPageDescription(strip_tags($sDescription));
  430. $oMetatags = BxDolMetatags::getObjectInstance($this->_oConfig->getObject('metatags'));
  431. if($oMetatags)
  432. $oMetatags->addPageMetaInfo($aEvent[$CNF['FIELD_ID']]);
  433. $sReferrer = '';
  434. if(isset($_SERVER['HTTP_REFERER']) && mb_stripos($_SERVER['HTTP_REFERER'], BX_DOL_URL_ROOT) === 0)
  435. $sReferrer = $_SERVER['HTTP_REFERER'];
  436. else
  437. $sReferrer = bx_absolute_url(BxDolPermalinks::getInstance()->permalink($this->_oConfig->CNF['URL_HOME']));
  438. $sJsObject = $this->_oConfig->getJsObjectView($aBrowseParams);
  439. return array('content' => $this->parseHtmlByName('block_item.html', array(
  440. 'style_prefix' => $this->_oConfig->getPrefix('style'),
  441. 'html_id' => $this->_oConfig->getHtmlIdView('main', $aBrowseParams),
  442. 'content' => $sContent,
  443. 'show_more' => $this->_getShowMore($aBrowseParams),
  444. 'view_image_popup' => $this->_getImagePopup($aBrowseParams),
  445. 'js_content' => $this->getJsCodeView(array(
  446. 'sObjName' => $sJsObject,
  447. 'sVideosAutoplay' => $this->_oConfig->getVideosAutoplay(),
  448. 'sReferrer' => $sReferrer,
  449. 'oRequestParams' => $aBrowseParams
  450. ), array(
  451. 'wrap' => true,
  452. 'mask_markers' => array('object' => $sJsObject)
  453. )) . $this->getJsCode('repost')
  454. )));
  455. }
  456. /**
  457. * Get event's content.
  458. * @param integer $iId - event ID.
  459. * @param string $sMode - 'file'/'photo'/'video' are available for now. But only images will be shown.
  460. */
  461. public function getItemBlockContent($iId, $sMode) {
  462. $oModule = $this->getModule();
  463. $sStylePrefix = $this->_oConfig->getPrefix('style');
  464. $aItemData = $oModule->getItemData($iId);
  465. if(empty($aItemData) || $aItemData['code'] != 0)
  466. return '';
  467. $aEvent = $aItemData['event'];
  468. $sKeyMain = $sKeyAttach = '';
  469. switch($sMode) {
  470. case 'file':
  471. $sKeyMain = 'files';
  472. $sKeyAttach = 'files_attach';
  473. break;
  474. case 'photo':
  475. $sKeyMain = 'images';
  476. $sKeyAttach = 'images_attach';
  477. break;
  478. case 'video':
  479. $sKeyMain = 'videos';
  480. $sKeyAttach = 'videos_attach';
  481. break;
  482. }
  483. $aImages = [];
  484. if(!empty($aEvent['content'][$sKeyMain]) && is_array($aEvent['content'][$sKeyMain]))
  485. $aImages = $aEvent['content'][$sKeyMain];
  486. else if(!empty($aEvent['content'][$sKeyAttach]) && is_array($aEvent['content'][$sKeyAttach]))
  487. $aImages = $aEvent['content'][$sKeyAttach];
  488. if(isset($aImages['total']) && isset($aImages['items']))
  489. $aImages = $aImages['items'];
  490. $bImageSingle = count($aImages) == 1;
  491. $sImageSelected = base64_decode(bx_process_input(bx_get('src')));
  492. $aTmplVarsImages = [];
  493. if(!$bImageSingle) {
  494. $iIndex = 1;
  495. foreach($aImages as $aImage) {
  496. if(!isset($aImage['src'], $aImage['src_orig']))
  497. continue;
  498. $iCurrent = $iIndex;
  499. if(strcmp($aImage['src'], $sImageSelected) == 0 || strcmp($aImage['src_orig'], $sImageSelected) == 0)
  500. $iCurrent = 0;
  501. $aTmplVarsImages[$iCurrent] = [
  502. 'style_prefix' => $sStylePrefix,
  503. 'url' => $aImage['url'],
  504. 'src' => $aImage[!empty($aImage['src_orig']) ? 'src_orig' : 'src']
  505. ];
  506. $iIndex++;
  507. }
  508. ksort($aTmplVarsImages);
  509. $aTmplVarsImages = array_values($aTmplVarsImages);
  510. }
  511. $aTmplVars = [
  512. 'style_prefix' => $sStylePrefix,
  513. 'bx_if:show_image' => [
  514. 'condition' => $bImageSingle,
  515. 'content' => [
  516. 'style_prefix' => $sStylePrefix,
  517. 'src' => $sImageSelected,
  518. ]
  519. ],
  520. 'bx_if:show_images' => [
  521. 'condition' => !$bImageSingle,
  522. 'content' => [
  523. 'style_prefix' => $sStylePrefix,
  524. 'bx_repeat:images' => $aTmplVarsImages
  525. ]
  526. ]
  527. ];
  528. return $this->parseHtmlByName('block_item_content.html', $aTmplVars);
  529. }
  530. public function getItemBlockInfo($iId) {
  531. $CNF = $this->_oConfig->CNF;
  532. $aEvent = $this->_oDb->getEvents(array('browse' => 'id', 'value' => $iId));
  533. if(empty($aEvent))
  534. return '';
  535. $aResult = $this->getDataCached($aEvent);
  536. if($aResult === false)
  537. return '';
  538. if(bx_is_api()) {
  539. $oMenuManage = BxDolMenu::getObjectInstance($this->_oConfig->getObject('menu_item_manage'));
  540. $oMenuManage->setEvent($aEvent);
  541. return [bx_api_get_block('entity_author', [
  542. 'author_data' => BxDolProfile::getData($aResult[$CNF['FIELD_OBJECT_OWNER_ID']]),
  543. 'entry_date' => !empty($aEvent[$CNF['FIELD_ADDED']]) ? $aEvent[$CNF['FIELD_ADDED']] : '',
  544. 'menu_manage' => $oMenuManage->getCodeApi()
  545. ])];
  546. }
  547. $oForm = BxDolForm::getObjectInstance($this->_oConfig->getObject('form_post'), $this->_oConfig->getObject('form_display_post_view'), $this);
  548. $oForm->initChecker($aEvent);
  549. return $this->parseHtmlByName('block_item_info.html', [
  550. 'style_prefix' => $this->_oConfig->getPrefix('style'),
  551. 'author' => $this->getModule()->getObjectUser($aResult['object_owner_id'])->getUnit(),
  552. 'fields' => $oForm->getCode()
  553. ]);
  554. }
  555. public function getItemBlockComments($iId)
  556. {
  557. $aEvent = $this->_oDb->getEvents(['browse' => 'id', 'value' => $iId]);
  558. if(empty($aEvent))
  559. return '';
  560. $aEventData = $this->getDataCached($aEvent);
  561. if($aEventData === false)
  562. return '';
  563. if(!$this->getModule()->isAllowedComment(array_merge($aEvent, $aEventData)))
  564. return '';
  565. if(bx_is_api()) {
  566. $mixedComments = $this->getModule()->getCommentsData($aEventData['comments']);
  567. if($mixedComments === false)
  568. return '';
  569. list($sSystem, $iObjectId) = $mixedComments;
  570. return [bx_srv('system', 'get_data_api', [['module' => $sSystem, 'object_id' => $iObjectId]], 'TemplCmtsServices')];
  571. }
  572. return $this->parseHtmlByName('block_item_comments.html', [
  573. 'style_prefix' => $this->_oConfig->getPrefix('style'),
  574. 'content' => $this->_getComments($aEventData['comments'])
  575. ]);
  576. }
  577. public function getUnit(&$aEvent, $aBrowseParams = array())
  578. {
  579. $oModule = $this->getModule();
  580. if(empty($aBrowseParams) || !is_array($aBrowseParams))
  581. $aBrowseParams = $oModule->getParams(BX_TIMELINE_VIEW_SEARCH);
  582. return $this->getPost($aEvent, $aBrowseParams);
  583. }
  584. public function getPost(&$aEvent, $aBrowseParams = array())
  585. {
  586. $CNF = &$this->_oConfig->CNF;
  587. $iEventId = (int)$aEvent[$CNF['FIELD_ID']];
  588. $iViewerId = isset($aBrowseParams['viewer_id']) ? (int)$aBrowseParams['viewer_id'] : bx_get_logged_profile_id();
  589. $sMemoryCacheItemsKey = sprintf(self::$_sMemoryCacheItemsKeyMask, $aBrowseParams['view'], $iEventId);
  590. if(array_key_exists($sMemoryCacheItemsKey, self::$_aMemoryCacheItems)) {
  591. if(array_key_exists($sMemoryCacheItemsKey, self::$_aMemoryCacheItemsData))
  592. $aEvent = self::$_aMemoryCacheItemsData[$sMemoryCacheItemsKey];
  593. return self::$_aMemoryCacheItems[$sMemoryCacheItemsKey];
  594. }
  595. /**
  596. * Add all items in memory cache even if they are empty.
  597. */
  598. self::$_aMemoryCacheItems[$sMemoryCacheItemsKey] = '';
  599. self::$_aMemoryCacheItemsData[$sMemoryCacheItemsKey] = array();
  600. $oPrivacy = BxDolPrivacy::getObjectInstance($this->_oConfig->getObject('privacy_view'));
  601. if($oPrivacy) {
  602. $oPrivacy->setTableFieldAuthor($this->_oConfig->isSystem($aEvent['type'], $aEvent['action']) ? 'owner_id' : 'object_id');
  603. if(!$oPrivacy->check($iEventId, $iViewerId))
  604. return '';
  605. }
  606. $aResult = $this->getDataCached($aEvent, $aBrowseParams);
  607. if($aResult === false)
  608. return '';
  609. if(isset($aResult['owner_id']))
  610. $aEvent['owner_id'] = $aResult['owner_id'];
  611. $aEvent['object_owner_id'] = $aResult['object_owner_id'];
  612. $aEvent['icon'] = !empty($aResult['icon']) ? $aResult['icon'] : '';
  613. $aEvent['sample'] = !empty($aResult['sample']) ? $aResult['sample'] : '_bx_timeline_txt_sample';
  614. $aEvent['sample_action'] = !empty($aResult['sample_action']) ? $aResult['sample_action'] : '_bx_timeline_txt_added_sample';
  615. if(isset($aResult['sample_action_custom']))
  616. $aEvent['sample_action_custom'] = $aResult['sample_action_custom'];
  617. $aEvent['content'] = $aResult['content'];
  618. $aEvent['content_type'] = !empty($aResult['content_type']) ? $aResult['content_type'] : BX_TIMELINE_PARSE_TYPE_DEFAULT;
  619. $aEvent['views'] = $aResult['views'];
  620. $aEvent['votes'] = $aResult['votes'];
  621. $aEvent['reactions'] = $aResult['reactions'];
  622. $aEvent['scores'] = $aResult['scores'];
  623. $aEvent['reports'] = $aResult['reports'];
  624. $aEvent['comments'] = $aResult['comments'];
  625. $sKey = 'allowed_view';
  626. $aEvent[$sKey] = $this->_preparePrivacy($sKey, $aEvent, $aResult);
  627. if(isset($aEvent[$sKey]) && $aEvent[$sKey] !== CHECK_ACTION_RESULT_ALLOWED)
  628. return '';
  629. self::$_aMemoryCacheItems[$sMemoryCacheItemsKey] = $this->_getPost($aEvent['content_type'], $aEvent, $aBrowseParams);
  630. self::$_aMemoryCacheItemsData[$sMemoryCacheItemsKey] = $aEvent;
  631. return self::$_aMemoryCacheItems[$sMemoryCacheItemsKey];
  632. }
  633. public function getPosts($aParams)
  634. {
  635. $bReturnArray = isset($aParams['return_data_type']) && $aParams['return_data_type'] == 'array';
  636. $bViewTimeline = $aParams['view'] == BX_TIMELINE_VIEW_TIMELINE;
  637. $iStart = $aParams['start'];
  638. $iPerPage = $aParams['per_page'];
  639. $aParamsDb = $aParams;
  640. //--- Before: Check for Next
  641. $aParamsDb['per_page'] += 1;
  642. if($this->_oConfig->isCacheTable()) {
  643. $aEvents = $this->_oDb->getEvents(array_merge($aParamsDb, ['from_cache' => true]));
  644. if(count($aEvents) < $aParamsDb['per_page'])
  645. $aEvents = $this->_oDb->getEvents(array_merge($aParamsDb, ['from_cache' => false]));
  646. }
  647. else
  648. $aEvents = $this->_oDb->getEvents($aParamsDb);
  649. //--- After: Check for Next
  650. $bNext = false;
  651. if(count($aEvents) > $iPerPage) {
  652. $aEvent = array_pop($aEvents);
  653. $bNext = true;
  654. }
  655. $sContent = '';
  656. $sContent .= $this->getSizer($aParams);
  657. $iFirst = 0;
  658. $iEvents = count($aEvents);
  659. if($iEvents > 0)
  660. $iFirst = $this->_getFirst($aEvents, $aParams);
  661. //--- Check for Visual Grouping
  662. $aGroups = array();
  663. foreach($aEvents as $iIndex => $aEvent) {
  664. $aContent = unserialize($aEvent['content']);
  665. if(!isset($aContent['timeline_group']))
  666. continue;
  667. $aGroup = $aContent['timeline_group'];
  668. $sGroup = $aGroup['by'];
  669. if(!isset($aGroups[$sGroup]))
  670. $aGroups[$sGroup] = array('field' => $aGroup['field'], 'indexes' => array(), 'processed' => false);
  671. $aGroups[$sGroup]['indexes'][] = $iIndex;
  672. }
  673. //--- Perform Visual Grouping
  674. foreach($aGroups as $sGroup => $aGroup) {
  675. if(empty($aGroup['field']) || empty($aGroup['indexes']))
  676. continue;
  677. switch($aGroup['field']) {
  678. case 'owner_id':
  679. $aOwnerIds = array();
  680. foreach($aGroup['indexes'] as $iIndex)
  681. if(!in_array($aEvents[$iIndex]['owner_id'], $aOwnerIds))
  682. $aOwnerIds[] = $aEvents[$iIndex]['owner_id'];
  683. $iGroupIndex = (int)array_shift($aGroup['indexes']);
  684. if(is_null($iGroupIndex))
  685. break;
  686. foreach($aGroup['indexes'] as $iIndex)
  687. unset($aEvents[$iIndex]);
  688. $aEvents[$iGroupIndex]['owner_id_grouped'] = $aOwnerIds;
  689. break;
  690. }
  691. }
  692. $iExtenalsEvery = $this->_oConfig->getExtenalsEvery($aParams['type']);
  693. $iEventIndex = 0;
  694. $mixedEvents = $bReturnArray ? array() : '';
  695. foreach($aEvents as $aEvent) {
  696. $iEvent = (int)$aEvent['id'];
  697. $sEvent = $this->getPost($aEvent, $aParams);
  698. if(empty($sEvent))
  699. continue;
  700. if($bReturnArray) {
  701. $mixedEvents[] = $aEvent;
  702. continue;
  703. }
  704. $mixedEvents .= $sEvent;
  705. $iEventIndex++;
  706. if($iExtenalsEvery > 0 && $iEventIndex % $iExtenalsEvery == 0) {
  707. $sExternalPost = false;
  708. bx_alert($this->_oConfig->getName(), 'get_external_post', 0, 0, array(
  709. 'params' => $aParams,
  710. 'override_result' => &$sExternalPost,
  711. ));
  712. if($sExternalPost !== false)
  713. $mixedEvents .= $sExternalPost;
  714. }
  715. }
  716. if($bReturnArray)
  717. return $mixedEvents;
  718. $sContent .= $mixedEvents;
  719. $bEvents = !empty($mixedEvents);
  720. $sBack = $this->getBack($aParams);
  721. $iPerPage = $this->_oConfig->getPerPage();
  722. $iPreloads = $this->_oConfig->getAutoPreloads();
  723. if(!$this->_oConfig->isInfiniteScroll() || (($aParams['start'] - $iPerPage * ($iPreloads - 1)) % ($iPerPage * $iPreloads) == 0))
  724. $sLoadMore = $this->getLoadMore($aParams, $bNext, $iEvents > 0 && $bEvents);
  725. else
  726. $sLoadMore = $this->getLoadMoreAuto($aParams, $bNext, $iEvents > 0 && $bEvents);
  727. $sEmpty = $this->getEmpty($iEvents <= 0 || !$bEvents);
  728. return array($sContent, $sLoadMore, $sBack, $sEmpty, $iFirst, $bNext);
  729. }
  730. public function getEmpty($bVisible)
  731. {
  732. return $this->parseHtmlByName('empty.html', array(
  733. 'style_prefix' => $this->_oConfig->getPrefix('style'),
  734. 'visible' => $bVisible ? 'block' : 'none',
  735. 'content' => MsgBox(_t('_bx_timeline_txt_msg_no_results'))
  736. ));
  737. }
  738. public function getSizer($aParams)
  739. {
  740. if($aParams['view'] != BX_TIMELINE_VIEW_OUTLINE)
  741. return '';
  742. return $this->parseHtmlByName('sizer_' . $aParams['view'] . '.html', array(
  743. 'style_prefix' => $this->_oConfig->getPrefix('style')
  744. ));
  745. }
  746. public function getBack($aParams)
  747. {
  748. $iYearSel = (int)$aParams['timeline'];
  749. if($iYearSel == 0)
  750. return '';
  751. $sStylePrefix = $this->_oConfig->getPrefix('style');
  752. $sJsObject = $this->_oConfig->getJsObjectView($aParams);
  753. $iYearNow = date('Y', time());
  754. return $this->parseHtmlByName('back.html', array(
  755. 'style_prefix' => $sStylePrefix,
  756. 'content' => $this->parseLink('javascript:void(0)', _t('_bx_timeline_txt_jump_to_recent'), array(
  757. 'title' => _t('_bx_timeline_txt_jump_to_n_year', $iYearNow),
  758. 'onclick' => 'javascript:' . $sJsObject . '.changeTimeline(this, 0)'
  759. ))
  760. ));
  761. }
  762. public function getLoadMore($aParams, $bEnabled, $bVisible = true)
  763. {
  764. $sStylePrefix = $this->_oConfig->getPrefix('style');
  765. $sJsObject = $this->_oConfig->getJsObjectView($aParams);
  766. $iStart = $aParams['start'];
  767. $iPerPage = $aParams['per_page'];
  768. $aTmplVars = array(
  769. 'style_prefix' => $sStylePrefix,
  770. 'visible' => ($aParams['view'] == BX_TIMELINE_VIEW_TIMELINE && $bVisible) || ($aParams['view'] == BX_TIMELINE_VIEW_OUTLINE && $bEnabled && $bVisible) ? 'block' : 'none',
  771. 'bx_if:is_disabled' => array(
  772. 'condition' => !$bEnabled,
  773. 'content' => array()
  774. ),
  775. 'bx_if:show_on_click' => array(
  776. 'condition' => $bEnabled,
  777. 'content' => array(
  778. 'on_click' => 'javascript:' . $sJsObject . '.changePage(this, ' . ($iStart + $iPerPage) . ', ' . $iPerPage . ')'
  779. )
  780. ),
  781. 'bx_if:show_jump_to' => array(
  782. 'condition' => $this->_oConfig->isJumpTo(),
  783. 'content' => array(
  784. 'style_prefix' => $sStylePrefix,
  785. 'content' => $this->getJumpTo($aParams)
  786. )
  787. )
  788. );
  789. return $this->parseHtmlByName('load_more.html', $aTmplVars);
  790. }
  791. public function getLoadMoreAuto($aParams, $bEnabled, $bVisible = true)
  792. {
  793. $sStylePrefix = $this->_oConfig->getPrefix('style');
  794. return $this->parseHtmlByName('load_more_auto.html', array(
  795. 'style_prefix' => $sStylePrefix,
  796. 'visible' => ($aParams['view'] == BX_TIMELINE_VIEW_TIMELINE && $bVisible) || ($aParams['view'] == BX_TIMELINE_VIEW_OUTLINE && $bEnabled && $bVisible) ? 'block' : 'none',
  797. 'loading' => _t('_bx_timeline_txt_loading' . ($bEnabled ? '' : '_complete'))
  798. ));
  799. }
  800. /**
  801. * Note. For now both List and Caledar based Jump To elements are available.
  802. * Calendar based element is used by default. List based one can be removed
  803. * later if it won't be used completely.
  804. */
  805. public function getJumpTo($aParams)
  806. {
  807. if(!$this->_oConfig->isJumpTo())
  808. return '';
  809. $bList = false;
  810. $bDynamicMode = isset($aParams['dynamic_mode']) && (bool)$aParams['dynamic_mode'] === true;
  811. if($bList && !$bDynamicMode)
  812. return '';
  813. return $this->{'_getJumpTo' . ($bList ? 'List' : 'Caledar')}($aParams);
  814. }
  815. public function getComments($sSystem, $iId, $aBrowseParams = array())
  816. {
  817. $oModule = $this->getModule();
  818. $sStylePrefix = $this->_oConfig->getPrefix('style');
  819. $oCmts = $oModule->getCmtsObject($sSystem, $iId);
  820. if($oCmts === false)
  821. return '';
  822. if (bx_is_api()){
  823. $aParams = ['mode' => 'feed', 'order_way' => 'desc', 'start_from' => 0];
  824. return [bx_srv('system', 'get_comments_api', [$oCmts, $aParams], 'TemplCmtsServices')];
  825. }
  826. $aCmtsBp = array();
  827. if(!empty($aBrowseParams['cmts_preload_number']))
  828. $aCmtsBp['init_view'] = $aBrowseParams['cmts_preload_number'];
  829. $aCmtsDp = array(
  830. 'in_designbox' => false,
  831. 'dynamic_mode' => isset($aBrowseParams['dynamic_mode']) && $aBrowseParams['dynamic_mode'] === true
  832. );
  833. if(!empty($aBrowseParams['cmts_min_post_form']))
  834. $aCmtsDp['min_post_form'] = $aBrowseParams['cmts_min_post_form'];
  835. $aComments = $oCmts->getCommentsBlock($aCmtsBp, $aCmtsDp);
  836. if(empty($aComments) || !is_array($aComments))
  837. return '';
  838. return $this->parseHtmlByName('comments.html', array(
  839. 'style_prefix' => $sStylePrefix,
  840. 'id' => $iId,
  841. 'content' => $aComments['content']
  842. ));
  843. }
  844. public function getRepostElement($iOwnerId, $sType, $sAction, $iObjectId, $aParams = [])
  845. {
  846. $aReposted = $this->_oDb->getReposted($sType, $sAction, $iObjectId);
  847. if(empty($aReposted) || !is_array($aReposted))
  848. return '';
  849. $oModule = $this->getModule();
  850. $bDisabled = $oModule->isAllowedRepost($aReposted) !== true || $this->_oDb->isReposted($aReposted['id'], $iOwnerId, $oModule->getUserId());
  851. if($bDisabled && (int)$aReposted['reposts'] == 0)
  852. return '';
  853. $sStylePrefix = $this->_oConfig->getPrefix('style');
  854. $sStylePrefixRepost = $sStylePrefix . '-repost-';
  855. $sDo = isset($aParams['do']) ? $aParams['do'] : 'repost';
  856. $bDynamicMode = isset($aParams['dynamic_mode']) && $aParams['dynamic_mode'] === true;
  857. $bShowDoRepostAsButtonSmall = isset($aParams['show_do_repost_as_button_small']) && $aParams['show_do_repost_as_button_small'] == true;
  858. $bShowDoRepostAsButton = !$bShowDoRepostAsButtonSmall && isset($aParams['show_do_repost_as_button']) && $aParams['show_do_repost_as_button'] == true;
  859. $bShowDoRepostIcon = isset($aParams['show_do_repost_icon']) && $aParams['show_do_repost_icon'] == true && !empty($aParams['icon_do_repost']);
  860. $bShowDoRepostText = isset($aParams['show_do_repost_text']) && $aParams['show_do_repost_text'] == true && !empty($aParams['text_do_repost']);
  861. $bShowCounter = isset($aParams['show_counter']) && $aParams['show_counter'] === true;
  862. //--- Do repost link ---//
  863. $sClass = $sStylePrefixRepost . 'do-repost';
  864. if($bShowDoRepostAsButton)
  865. $sClass .= ' bx-btn';
  866. else if($bShowDoRepostAsButtonSmall)
  867. $sClass .= ' bx-btn bx-btn-small';
  868. $sOnClick = '';
  869. if(!$bDisabled) {
  870. $sMethod = '_get' . bx_gen_method_name($sDo) . 'JsClick';
  871. if(!method_exists($this, $sMethod))
  872. $sMethod = '_getRepostJsClick';
  873. $sCommonPrefix = $this->_oConfig->getPrefix('common_post');
  874. if(str_replace($sCommonPrefix, '', $sType) == BX_TIMELINE_PARSE_TYPE_REPOST) {
  875. $aRepostedData = unserialize($aReposted['content']);
  876. $sOnClick = $this->$sMethod($iOwnerId, $aRepostedData['type'], $aRepostedData['action'], $aRepostedData['object_id']);
  877. }
  878. else
  879. $sOnClick = $this->$sMethod($iOwnerId, $sType, $sAction, $iObjectId);
  880. }
  881. else
  882. $sClass .= $bShowDoRepostAsButton || $bShowDoRepostAsButtonSmall ? ' bx-btn-disabled' : ' ' . $sStylePrefixRepost . 'disabled';
  883. $aOnClickAttrs = array(
  884. 'title' => _t('_bx_timeline_txt_do_' . $sDo)
  885. );
  886. if(!empty($sClass))
  887. $aOnClickAttrs['class'] = $sClass;
  888. if(!empty($sOnClick))
  889. $aOnClickAttrs['onclick'] = $sOnClick;
  890. //--- Do repost label ---//
  891. $sMethodDoRepostLabel = '';
  892. $sTemplateDoRepostLabel = '';
  893. if(!empty($aParams['template_do_repost_label'])) {
  894. $sMethodDoRepostLabel = 'parseHtmlByContent';
  895. $sTemplateDoRepostLabel = $aParams['template_do_repost_label'];
  896. }
  897. else {
  898. $sMethodDoRepostLabel = 'parseHtmlByName';
  899. $sTemplateDoRepostLabel = $aParams['template_do_repost_label_name'];
  900. }
  901. $sDoRepost = $this->$sMethodDoRepostLabel($sTemplateDoRepostLabel, array(
  902. 'style_prefix' => $sStylePrefix,
  903. 'bx_if:show_icon' => array(
  904. 'condition' => $bShowDoRepostIcon,
  905. 'content' => array(
  906. 'style_prefix' => $sStylePrefix,
  907. 'icon' => $this->getImageAuto($aParams['icon_do_' . $sDo])
  908. )
  909. ),
  910. 'bx_if:show_text' => array(
  911. 'condition' => $bShowDoRepostText,
  912. 'content' => array(
  913. 'style_prefix' => $sStylePrefix,
  914. 'text' => _t($aParams['text_do_' . $sDo])
  915. )
  916. )
  917. ));
  918. return $this->parseHtmlByName('repost_element_block.html', array(
  919. 'style_prefix' => $sStylePrefix,
  920. 'html_id' => $this->_oConfig->getHtmlIds('repost', 'main') . $aReposted['id'],
  921. 'class' => ($bShowDoRepostAsButton ? $sStylePrefixRepost . 'button' : '') . ($bShowDoRepostAsButtonSmall ? $sStylePrefixRepost . 'button-small' : ''),
  922. 'count' => $aReposted['reposts'],
  923. 'do_repost' => $this->parseLink('javascript:void(0)', $sDoRepost, $aOnClickAttrs),
  924. 'bx_if:show_counter' => array(
  925. 'condition' => $bShowCounter,
  926. 'content' => array(
  927. 'style_prefix' => $sStylePrefix,
  928. 'bx_if:show_hidden' => array(
  929. 'condition' => (int)$aReposted['reposts'] == 0,
  930. 'content' => array()
  931. ),
  932. 'counter' => $this->getRepostCounter($aReposted, array_merge($aParams, ['show_script' => false]))
  933. )
  934. ),
  935. 'script' => $this->getRepostJsScript($bDynamicMode)
  936. ));
  937. }
  938. public function getRepostCounter($aEvent, $aParams = [])
  939. {
  940. $sStylePrefix = $this->_oConfig->getPrefix('style');
  941. $sJsObject = $this->_oConfig->getJsObject('repost');
  942. $bDynamicMode = isset($aParams['dynamic_mode']) && $aParams['dynamic_mode'] === true;
  943. $bShowDoRepostAsButtonSmall = isset($aParams['show_do_repost_as_button_small']) && $aParams['show_do_repost_as_button_small'] == true;
  944. $bShowDoRepostAsButton = !$bShowDoRepostAsButtonSmall && isset($aParams['show_do_repost_as_button']) && $aParams['show_do_repost_as_button'] == true;
  945. $bShowScript = !isset($aParams['show_script']) || (bool)$aParams['show_script'] === true;
  946. $sClass = $sStylePrefix . '-repost-counter';
  947. if($bShowDoRepostAsButtonSmall)
  948. $sClass .= ' bx-btn-small-height';
  949. if($bShowDoRepostAsButton)
  950. $sClass .= ' bx-btn-height';
  951. return $this->parseHtmlByName('repost_counter.html', [
  952. 'class' => $sClass,
  953. 'bx_repeat:attrs' => [
  954. ['key' => 'id', 'value' => $this->_oConfig->getHtmlIds('repost', 'counter') . $aEvent['id']],
  955. ['key' => 'title', 'value' => _t('_bx_timeline_txt_reposted_by')],
  956. ['key' => 'href', 'value' => 'javascript:void(0)'],
  957. ['key' => 'onclick', 'value' => 'javascript:' . $sJsObject . '.toggleByPopup(this, ' . $aEvent['id'] . ')']
  958. ],
  959. 'content' => !empty($aEvent['reposts']) && (int)$aEvent['reposts'] > 0 ? $this->getRepostCounterLabel($aEvent['reposts'], $aParams) : '',
  960. 'script' => $bShowScript ? $this->getRepostJsScript($bDynamicMode) : ''
  961. ]);
  962. }
  963. public function getRepostCounterLabel($iCount, $aParams = [])
  964. {
  965. $sStylePrefix = $this->_oConfig->getPrefix('style');
  966. return $this->parseHtmlByName('repost_counter_label.html', [
  967. 'style_prefix' => $sStylePrefix,
  968. 'bx_if:show_icon' => array(
  969. 'condition' => !isset($aParams['show_counter_label_icon']) || (bool)$aParams['show_counter_label_icon'] === true,
  970. 'content' => array(
  971. 'style_prefix' => $sStylePrefix,
  972. 'icon' => $this->_getCounterIcon($aParams),
  973. )
  974. ),
  975. 'bx_if:show_text' => array(
  976. 'condition' => !isset($aParams['show_counter_label_text']) || (bool)$aParams['show_counter_label_text'] === true,
  977. 'content' => array(
  978. 'style_prefix' => $sStylePrefix,
  979. 'text' => $this->_getCounterLabel($iCount, $aParams)
  980. )
  981. )
  982. ]);
  983. }
  984. public function getRepostedBy($iId)
  985. {
  986. $aTmplUsers = array();
  987. $oModule = $this->getModule();
  988. $sStylePrefix = $this->_oConfig->getPrefix('style');
  989. $aUserIds = $this->_oDb->getRepostedBy($iId);
  990. foreach($aUserIds as $iUserId)
  991. $aTmplUsers[] = array(
  992. 'style_prefix' => $sStylePrefix,
  993. 'user_unit' => $oModule->getObjectUser($iUserId)->getUnit()
  994. );
  995. bx_alert($this->_oConfig->getName(), 'get_reposted_by', 0, 0, array(
  996. 'content_id' => $iId,
  997. 'user_ids' => $aUserIds,
  998. 'users' => &$aTmplUsers
  999. ));
  1000. if(empty($aTmplUsers))
  1001. $aTmplUsers = MsgBox(_t('_Empty'));
  1002. return $this->parseHtmlByName('repost_by_list.html', array(
  1003. 'style_prefix' => $sStylePrefix,
  1004. 'bx_repeat:list' => $aTmplUsers
  1005. ));
  1006. }
  1007. public function getRepostWith($oForm)
  1008. {
  1009. $sStylePrefix = $this->_oConfig->getPrefix('style');
  1010. $sJsObject = $this->_oConfig->getJsObject('repost');
  1011. return $this->parseHtmlByName('repost_with_popup.html', array(
  1012. 'style_prefix' => $sStylePrefix,
  1013. 'js_object' => $sJsObject,
  1014. 'form' => $oForm->getCode(),
  1015. 'form_id' => $oForm->getId()
  1016. ));
  1017. }
  1018. public function getRepostWithFieldReposted($oForm, $aInput)
  1019. {
  1020. $sStylePrefix = $this->_oConfig->getPrefix('style');
  1021. $aBrowseParams = $this->getModule()->getParams();
  1022. $aReposted = $oForm->getReposted();
  1023. $sReposted = $this->getPost($aReposted, $aBrowseParams);
  1024. $sContent = '';
  1025. if(!empty($sReposted))
  1026. $sContent = $this->_getContent($aReposted['content_type'], $aReposted, $aBrowseParams);
  1027. else
  1028. $sContent = MsgBox(_t('_Empty'));
  1029. return $this->parseHtmlByName('repost_with_reposted.html', array(
  1030. 'style_prefix' => $sStylePrefix,
  1031. 'content' => $sContent
  1032. ));
  1033. }
  1034. public function getRepostTo($oForm)
  1035. {
  1036. $sStylePrefix = $this->_oConfig->getPrefix('style');
  1037. $sJsObject = $this->_oConfig->getJsObject('repost');
  1038. return $this->parseHtmlByName('repost_to_popup.html', array(
  1039. 'style_prefix' => $sStylePrefix,
  1040. 'js_object' => $sJsObject,
  1041. 'form' => $oForm->getCode(),
  1042. 'form_id' => $oForm->getId()
  1043. ));
  1044. }
  1045. public function getRepostToFieldList($oForm, $aInput)
  1046. {
  1047. $sStylePrefix = $this->_oConfig->getPrefix('style');
  1048. $oConnection = BxDolConnection::getObjectInstance('sys_profiles_subscriptions');
  1049. if(!$oConnection)
  1050. return '';
  1051. $iProfileId = bx_get_logged_profile_id();
  1052. $aConnectedIds = $oConnection->getConnectedContent($iProfileId);
  1053. $aSelected = array();
  1054. $aTmplVarsModules = array();
  1055. if(!empty($aConnectedIds) && is_array($aConnectedIds)) {
  1056. $aCheckbox = $aInput;
  1057. $aCheckbox['type'] = 'checkbox';
  1058. $aCheckbox['name'] .= '[]';
  1059. foreach($aConnectedIds as $iConnectedId) {
  1060. $oProfile = BxDolProfile::getInstanceMagic($iConnectedId);
  1061. if(!$oProfile)
  1062. continue;
  1063. $sProfileModule = $oProfile->getModule();
  1064. if(!isset($aTmplVarsModules[$sProfileModule]))
  1065. $aTmplVarsModules[$sProfileModule] = array(
  1066. 'style_prefix' => $sStylePrefix,
  1067. 'title' => _t('_' . $sProfileModule),
  1068. 'bx_repeat:contexts' => array()
  1069. );
  1070. $aCheckbox['value'] = $iConnectedId;
  1071. $aCheckbox['checked'] = in_array($iConnectedId, $aSelected) ? 1 : 0;
  1072. $aTmplVarsModules[$sProfileModule]['bx_repeat:contexts'][] = array(
  1073. 'style_prefix' => $sStylePrefix,
  1074. 'checkbox' => $oForm->genInput($aCheckbox),
  1075. 'unit' => $oProfile->getUnit(0, array('template' => 'unit_wo_cover'))
  1076. );
  1077. }
  1078. }
  1079. return $this->parseHtmlByName('repost_to_list.html', array(
  1080. 'style_prefix' => $sStylePrefix,
  1081. 'bx_repeat:modules' => !empty($aTmplVarsModules)? array_values($aTmplVarsModules) : MsgBox(_t('_Empty'))
  1082. ));
  1083. }
  1084. public function getRepostJsScript($bDynamicMode = false)
  1085. {
  1086. $sCode = $this->getJsCode('repost', array(), array('mask' => '{object} = new {class}({params});', 'wrap' => false));
  1087. if($bDynamicMode) {
  1088. $sJsObject = $this->_oConfig->getJsObject('repost');
  1089. $sCode = "var " . $sJsObject . " = null;
  1090. $.getScript('" . bx_js_string($this->getJsUrl('main.js'), BX_ESCAPE_STR_APOS) . "', function(data, textStatus, jqxhr) {
  1091. $.getScript('" . bx_js_string($this->getJsUrl('repost.js'), BX_ESCAPE_STR_APOS) . "', function(data, textStatus, jqxhr) {
  1092. bx_get_style('" . bx_js_string($this->getCssUrl('repost.css'), BX_ESCAPE_STR_APOS) . "');
  1093. " . $sCode . "
  1094. });
  1095. }); ";
  1096. }
  1097. else {
  1098. $sCode = "var " . $sCode;
  1099. $this->addCss(array('repost.css'));
  1100. $this->addJs(array('main.js', 'repost.js'));
  1101. }
  1102. return $this->_wrapInTagJsCode($sCode);
  1103. }
  1104. public function getRepostJsClick($iOwnerId, $sType, $sAction, $iObjectId)
  1105. {
  1106. $aReposted = $this->_oDb->getReposted($sType, $sAction, $iObjectId);
  1107. if(empty($aReposted) || !is_array($aReposted))
  1108. return '';
  1109. $sResult = '';
  1110. $sCommonPrefix = $this->_oConfig->getPrefix('common_post');
  1111. if(str_replace($sCommonPrefix, '', $sType) == BX_TIMELINE_PARSE_TYPE_REPOST) {
  1112. $aRepostedData = unserialize($aReposted['content']);
  1113. $sResult = $this->_getRepostJsClick($iOwnerId, $aRepostedData['type'], $aRepostedData['action'], $aRepostedData['object_id']);
  1114. }
  1115. else
  1116. $sResult = $this->_getRepostJsClick($iOwnerId, $sType, $sAction, $iObjectId);
  1117. return $sResult;
  1118. }
  1119. public function getRepostWithJsClick($iReposterId, $sType, $sAction, $iObjectId)
  1120. {
  1121. $aReposted = $this->_oDb->getReposted($sType, $sAction, $iObjectId);
  1122. if(empty($aReposted) || !is_array($aReposted))
  1123. return '';
  1124. $sResult = '';
  1125. $sCommonPrefix = $this->_oConfig->getPrefix('common_post');
  1126. if(str_replace($sCommonPrefix, '', $sType) == BX_TIMELINE_PARSE_TYPE_REPOST) {
  1127. $aRepostedData = unserialize($aReposted['content']);
  1128. $sResult = $this->_getRepostWithJsClick($iReposterId, $aRepostedData['type'], $aRepostedData['action'], $aRepostedData['object_id']);
  1129. }
  1130. else
  1131. $sResult = $this->_getRepostWithJsClick($iReposterId, $sType, $sAction, $iObjectId);
  1132. return $sResult;
  1133. }
  1134. public function getRepostToJsClick($iReposterId, $sType, $sAction, $iObjectId)
  1135. {
  1136. $aReposted = $this->_oDb->getReposted($sType, $sAction, $iObjectId);
  1137. if(empty($aReposted) || !is_array($aReposted))
  1138. return '';
  1139. $sResult = '';
  1140. $sCommonPrefix = $this->_oConfig->getPrefix('common_post');
  1141. if(str_replace($sCommonPrefix, '', $sType) == BX_TIMELINE_PARSE_TYPE_REPOST) {
  1142. $aRepostedData = unserialize($aReposted['content']);
  1143. $sResult = $this->_getRepostToJsClick($iReposterId, $aRepostedData['type'], $aRepostedData['action'], $aRepostedData['object_id']);
  1144. }
  1145. else
  1146. $sResult = $this->_getRepostToJsClick($iReposterId, $sType, $sAction, $iObjectId);
  1147. return $sResult;
  1148. }
  1149. public function getAttachLinkForm($iEventId = 0)
  1150. {
  1151. $sStylePrefix = $this->_oConfig->getPrefix('style');
  1152. $sJsObject = $this->_oConfig->getJsObject('post');
  1153. $aForm = $this->getModule()->getFormAttachLink($iEventId);
  1154. return $this->parseHtmlByName('attach_link_form.html', array(
  1155. 'style_prefix' => $sStylePrefix,
  1156. 'js_object' => $sJsObject,
  1157. 'form_id' => $aForm['form_id'],
  1158. 'form' => $aForm['form'],
  1159. ));
  1160. }
  1161. public function getAttachLinkField($iUserId, $iEventId = 0)
  1162. {
  1163. $sStylePrefix = $this->_oConfig->getPrefix('style');
  1164. if(!$iEventId)
  1165. $aLinks = $this->_oDb->getUnusedLinks($iUserId);
  1166. else
  1167. $aLinks = $this->_oDb->getLinks($iEventId);
  1168. $sLinks = '';
  1169. foreach($aLinks as $aLink)
  1170. $sLinks .= $this->getAttachLinkItem($iUserId, $aLink);
  1171. return $this->parseHtmlByName('attach_link_form_field.html', array(
  1172. 'html_id' => $this->_oConfig->getHtmlIds('post', 'attach_link_form_field') . $iEventId,
  1173. 'style_prefix' => $sStylePrefix,
  1174. 'links' => $sLinks
  1175. ));
  1176. }
  1177. public function getAttachLinkItem($iUserId, $mixedLink)
  1178. {
  1179. $aLink = is_array($mixedLink) ? $mixedLink : $this->_oDb->getLinksBy(array('type' => 'id', 'id' => (int)$mixedLink, 'profile_id' => $iUserId));
  1180. if(empty($aLink) || !is_array($aLink))
  1181. return '';
  1182. $sLinkIdPrefix = $this->_oConfig->getHtmlIds('post', 'attach_link_item');
  1183. $sStylePrefix = $this->_oConfig->getPrefix('style');
  1184. $sClass = $sStylePrefix . '-al-item';
  1185. $sJsObject = $this->_oConfig->getJsObject('post');
  1186. $oEmbed = BxDolEmbed::getObjectInstance();
  1187. $bEmbed = $oEmbed !== false;
  1188. $sThumbnail = '';
  1189. $aLinkAttrs = array();
  1190. if(!$bEmbed) {
  1191. $aLinkAttrs = array(
  1192. 'title' => bx_html_attribute($aLink['title'])
  1193. );
  1194. if(!$this->_oConfig->isEqualUrls(BX_DOL_URL_ROOT, $aLink['url'])) {
  1195. $aLinkAttrs['target'] = '_blank';
  1196. if($this->_oDb->getParam('sys_add_nofollow') == 'on')
  1197. $aLinkAttrs['rel'] = 'nofollow';
  1198. }
  1199. if((int)$aLink['media_id'] != 0)
  1200. $sThumbnail = BxDolTranscoderImage::getObjectInstance($this->_oConfig->getObject('transcoder_photos_preview'))->getFileUrl($aLink['media_id']);
  1201. }
  1202. else
  1203. $sClass .= ' embed';
  1204. return $this->parseHtmlByName('attach_link_item.html', array(
  1205. 'html_id' => $sLinkIdPrefix . $aLink['id'],
  1206. 'style_prefix' => $sStylePrefix,
  1207. 'class' => $sClass,
  1208. 'js_object' => $sJsObject,
  1209. 'id' => $aLink['id'],
  1210. 'bx_if:show_embed_outer' => array(
  1211. 'condition' => $bEmbed,
  1212. 'content' => array(
  1213. 'style_prefix' => $sStylePrefix,
  1214. 'embed' => $bEmbed ? $oEmbed->getLinkHTML($aLink['url'], $aLink['title'], 300) : '',
  1215. )
  1216. ),
  1217. 'bx_if:show_embed_inner' => array(
  1218. 'condition' => !$bEmbed,
  1219. 'content' => array(
  1220. 'style_prefix' => $sStylePrefix,
  1221. 'bx_if:show_thumbnail' => array(
  1222. 'condition' => !empty($sThumbnail),
  1223. 'content' => array(
  1224. 'style_prefix' => $sStylePrefix,
  1225. 'thumbnail' => $sThumbnail
  1226. )
  1227. ),
  1228. 'url' => $aLink['url'],
  1229. 'link' => $this->parseLink($aLink['url'], $aLink['title'], $aLinkAttrs)
  1230. )
  1231. ),
  1232. ));
  1233. }
  1234. public function getData(&$aEvent, $aBrowseParams = array())
  1235. {
  1236. $aResult = $this->_oConfig->isSystem($aEvent['type'], $aEvent['action']) ? $this->_getSystemData($aEvent, $aBrowseParams) : $this->_getCommonData($aEvent, $aBrowseParams);
  1237. if(empty($aResult) || empty($aResult['object_owner_id']) || empty($aResult['content']))
  1238. return false;
  1239. $sSample = !empty($aResult['sample']) ? $aResult['sample'] : '_bx_timeline_txt_sample';
  1240. $aUpdate = array(
  1241. 'object_owner_id' => $aResult['object_owner_id']
  1242. );
  1243. //--- Update Title if empty.
  1244. if(empty($aEvent['title'])) {
  1245. $sTitle = !empty($aResult['title']) ? $this->_oConfig->getTitle($aResult['title']) : _t($sSample);
  1246. $aUpdate['title'] = bx_process_input(strip_tags($sTitle));
  1247. }
  1248. //--- Update Description if empty.
  1249. if(empty($aEvent['description'])) {
  1250. $sUserName = $this->getModule()->getObjectUser($aResult['object_owner_id'])->getDisplayName();
  1251. $sDescription = !empty($aResult['description']) ? $aResult['description'] : _t('_bx_timeline_txt_user_added_sample', $sUserName, _t($sSample));
  1252. if($sDescription == '' && !empty($aResult['content']['text']))
  1253. $sDescription = $aResult['content']['text'];
  1254. $aUpdate['description'] = bx_process_input(strip_tags($sDescription));
  1255. }
  1256. if(!empty($aUpdate) && is_array($aUpdate))
  1257. $this->_oDb->updateEvent($aUpdate, array('id' => $aEvent['id']));
  1258. return $aResult;
  1259. }
  1260. public function getDataCached($aEvent, $aBrowseParams = array())
  1261. {
  1262. if(!$this->_oConfig->isCacheItem() || bx_is_api())
  1263. return $this->getData($aEvent, $aBrowseParams);
  1264. /**
  1265. * For now parameters from $aBrowseParams array aren't used during data retrieving.
  1266. * If they will then the cache should be created depending on their values.
  1267. */
  1268. $sCacheKey = $this->_oConfig->getCacheItemKey($aEvent['id']);
  1269. $iCacheLifetime = $this->_oConfig->getCacheItemLifetime();
  1270. $oCache = $this->getModule()->getCacheItemObject();
  1271. $aCached = $oCache->getData($sCacheKey, $iCacheLifetime);
  1272. if(!empty($aCached))
  1273. return unserialize($aCached);
  1274. $aBrowseParams['dynamic_mode'] = true;
  1275. $aResult = $this->getData($aEvent, $aBrowseParams);
  1276. if(empty($aResult) || (isset($aResult['_cache']) && (bool)$aResult['_cache'] === false))
  1277. return $aResult;
  1278. $oCache->setData($sCacheKey, serialize($aResult), $iCacheLifetime);
  1279. return $aResult;
  1280. }
  1281. public function getVideo($aEvent, $aVideo)
  1282. {
  1283. $sVideoId = $this->_oConfig->getHtmlIds('view', 'video') . $aEvent['id'] . '-' . $aVideo['id'];
  1284. $oPlayer = BxDolPlayer::getObjectInstance();
  1285. if (!$oPlayer)
  1286. return '';
  1287. $sPlayer = $oPlayer->getCodeVideo (BX_PLAYER_EMBED, array(
  1288. 'poster' => $aVideo['src_poster'],
  1289. 'mp4' => array('sd' => $aVideo['src_mp4'], 'hd' => $aVideo['src_mp4_hd']),
  1290. 'attrs' => array('id' => $sVideoId),
  1291. ));
  1292. return $this->parseHtmlByName('video_player.html', array(
  1293. 'player' => $sPlayer,
  1294. 'html_id' => $sVideoId
  1295. ));
  1296. }
  1297. /*
  1298. * Show only one Live Update notification for all new Events.
  1299. */
  1300. function getLiveUpdate($aBrowseParams, $iProfileId, $iCountOld = 0, $iCountNew = 0)
  1301. {
  1302. $oModule = $this->getModule();
  1303. $iCount = (int)$iCountNew - (int)$iCountOld;
  1304. if($iCount < 0)
  1305. return '';
  1306. $aParams = $oModule->getParamsExt($aBrowseParams);
  1307. $aParams['start'] = 0;
  1308. $aParams['per_page'] = 1;
  1309. $aParams['newest'] = true;
  1310. $aParams['filter'] = BX_TIMELINE_FILTER_OTHER_VIEWER;
  1311. $aEvents = $this->_oDb->getEvents($aParams);
  1312. if(empty($aEvents) || !is_array($aEvents))
  1313. return '';
  1314. $aEvent = array_shift($aEvents);
  1315. if(empty($aEvent) || !is_array($aEvent))
  1316. return '';
  1317. $sJsObject = $this->_oConfig->getJsObjectView($aParams);
  1318. $sStylePrefix = $this->_oConfig->getPrefix('style');
  1319. return $this->parseHtmlByName('live_update_button.html', array(
  1320. 'style_prefix' => $sStylePrefix,
  1321. 'html_id' => $this->_oConfig->getHtmlIds('view', 'live_update_popup') . $aBrowseParams['type'],
  1322. 'onclick_show' => "javascript:" . $sJsObject . ".goToBtn(this, 'timeline-event-" . $aEvent['id'] . "', '" . $aEvent['id'] . "');",
  1323. ));
  1324. }
  1325. /*
  1326. * Show Live Update notification separately for each new Event. Popup Chain is used here.
  1327. *
  1328. * Note. This way to display live update notifications isn't used for now.
  1329. * See BxTimelineTemplate::getLiveUpdate method instead.
  1330. */
  1331. function getLiveUpdates($aBrowseParams, $iProfileId, $iCountOld = 0, $iCountNew = 0)
  1332. {
  1333. $bShowAll = true;
  1334. $bShowActions = false;
  1335. $oModule = $this->getModule();
  1336. $iCount = (int)$iCountNew - (int)$iCountOld;
  1337. if($iCount < 0)
  1338. return '';
  1339. $iCountMax = $this->_oConfig->getLiveUpdateLength();
  1340. if($iCount > $iCountMax)
  1341. $iCount = $iCountMax;
  1342. $aParams = $oModule->getParamsExt($aBrowseParams);
  1343. $aParams['start'] = 0;
  1344. $aParams['per_page'] = $iCount;
  1345. $aParams['filter'] = BX_TIMELINE_FILTER_OTHER_VIEWER;
  1346. $aEvents = $this->_oDb->getEvents($aParams);
  1347. if(empty($aEvents) || !is_array($aEvents))
  1348. return '';
  1349. $sJsObject = $this->_oConfig->getJsObjectView($aParams);
  1350. $sStylePrefix = $this->_oConfig->getPrefix('style');
  1351. $iUserId = $oModule->getUserId();
  1352. $bModerator = $oModule->isModerator();
  1353. $aEvents = array_reverse($aEvents);
  1354. $iEvents = count($aEvents);
  1355. $aTmplVarsItems = array();
  1356. foreach($aEvents as $iIndex => $aEvent) {
  1357. $aData = $this->getDataCached($aEvent);
  1358. if($aData === false)
  1359. continue;
  1360. $iEventId = $aEvent['id'];
  1361. $iEventAuthorId = $this->_oConfig->isSystem($aEvent['type'], $aEvent['action']) ? (int)$aEvent['owner_id'] : (int)$aEvent['object_id'];
  1362. if($iEventAuthorId < 0) {
  1363. if(abs($iEventAuthorId) == $iUserId)
  1364. continue;
  1365. else if($bModerator)
  1366. $iEventAuthorId *= -1;
  1367. }
  1368. $oAuthor = $oModule->getObjectUser($iEventAuthorId);
  1369. $sAuthorName = $oAuthor->getDisplayName();
  1370. $aTmplVarsItems[] = array(
  1371. 'bx_if:show_as_hidden' => array(
  1372. 'condition' => !$bShowAll && $iIndex < ($iEvents - 1),
  1373. 'content' => array(),
  1374. ),
  1375. 'item' => $this->parseHtmlByName('live_update_notification.html', array(
  1376. 'style_prefix' => $sStylePrefix,
  1377. 'onclick_show' => "javascript:" . $sJsObject . ".goTo(this, 'timeline-event-" . $iEventId . "', '" . $iEventId . "');",
  1378. 'author_link' => $oAuthor->getUrl(),
  1379. 'author_title' => bx_html_attribute($sAuthorName),
  1380. 'author_name' => $sAuthorName,
  1381. 'author_unit' => $oAuthor->getUnit(0, array('template' => 'unit_wo_info_links')),
  1382. 'text' => _t($aData['sample_action'], _t($aData['sample'])),
  1383. )),
  1384. 'bx_if:show_previous' => array(
  1385. 'condition' => $bShowActions && $iIndex > 0,
  1386. 'content' => array(
  1387. 'onclick_previous' => $sJsObject . '.previousLiveUpdate(this)'
  1388. )
  1389. ),
  1390. 'bx_if:show_close' => array(
  1391. 'condition' => $bShowActions,
  1392. 'content' => array(
  1393. 'onclick_close' => $sJsObject . '.hideLiveUpdate(this)'
  1394. )
  1395. )
  1396. );
  1397. }
  1398. return $this->parseHtmlByName('popup_chain.html', array(
  1399. 'html_id' => $this->_oConfig->getHtmlIds('view', 'live_update_popup') . $aBrowseParams['type'],
  1400. 'bx_repeat:items' => $aTmplVarsItems
  1401. ));
  1402. }
  1403. protected function _getPost($sType, $aEvent, $aBrowseParams = array())
  1404. {
  1405. $CNF = &$this->_oConfig->CNF;
  1406. $oModule = $this->getModule();
  1407. $sStylePrefix = $this->_oConfig->getPrefix('style');
  1408. $sJsObject = $this->_oConfig->getJsObjectView($aBrowseParams);
  1409. $bViewItem = isset($aBrowseParams['view']) && $aBrowseParams['view'] == BX_TIMELINE_VIEW_ITEM;
  1410. $bViewOutline = isset($aBrowseParams['view']) && $aBrowseParams['view'] == BX_TIMELINE_VIEW_OUTLINE;
  1411. $oAuthor = $oModule->getObjectUser($aEvent['object_owner_id']);
  1412. $sAuthorName = $oAuthor->getDisplayName();
  1413. $sAuthorUrl = $oAuthor->getUrl();
  1414. $sAuthorUnit = $oAuthor->getUnit(0, array('template' => 'unit_wo_info'));
  1415. $sAuthorBadges = $oAuthor->getBadges();
  1416. $sAuthorAction = '';
  1417. if(!empty($aEvent['sample_action_custom']) && is_array($aEvent['sample_action_custom'])) {
  1418. $aAuthorAction = $aEvent['sample_action_custom'];
  1419. foreach($aAuthorAction['markers'] as $iIndex => $sMarker)
  1420. if(get_mb_substr($sMarker, 0, 1) == '_')
  1421. $aAuthorAction['markers'][$iIndex] = _t($sMarker);
  1422. $sAuthorAction = bx_replace_markers(_t($aAuthorAction['content']), $aAuthorAction['markers']);
  1423. }
  1424. else
  1425. $sAuthorAction = _t($aEvent['sample_action'], _t($aEvent['sample']));
  1426. if(($bViewItem || $this->_oConfig->isCountAllViews()) && !empty($aEvent['views']) && is_array($aEvent['views']) && isset($aEvent['views']['system']))
  1427. $oModule->getViewObject($aEvent['views']['system'], $aEvent['views']['object_id'])->doView();
  1428. $aTmplVarsNote = $this->_getTmplVarsNote($aEvent);
  1429. $aTmplVarsMenuItemCounters = $this->_getTmplVarsMenuItemCounters($aEvent, $aBrowseParams);
  1430. $aTmplVarsMenuItemActions = $this->_getTmplVarsMenuItemActions($aEvent, $aBrowseParams);
  1431. $aTmplVarsMenuItemMeta = $this->_getTmplVarsMenuItemMeta($aEvent, $aBrowseParams);
  1432. $aTmplVarsManage = $this->_getTmplVarsManage($aEvent, $aBrowseParams);
  1433. $aTmplVarsTimelineOwner = $this->_getTmplVarsTimelineOwner($aEvent);
  1434. $bTmplVarsTimelineOwner = !empty($aTmplVarsTimelineOwner);
  1435. $aTmplVarsOwnerActions = $this->_getTmplVarsOwnerActions($aEvent, $aBrowseParams);
  1436. $bTmplVarsOwnerActions = !empty($aTmplVarsOwnerActions);
  1437. $bPinned = $aBrowseParams['type'] == BX_BASE_MOD_NTFS_TYPE_OWNER && (int)$aEvent['pinned'] > 0;
  1438. $bSticked = (int)$aEvent['sticked'] > 0;
  1439. $bPromoted = (int)$aEvent['promoted'] > 0;
  1440. $sClass = $sStylePrefix . '-view-sizer';
  1441. if($bViewOutline) {
  1442. $sClass = $sStylePrefix . '-grid-item-sizer';
  1443. if($bPinned || $bSticked || $bPromoted) {
  1444. $sClass .= ' ' . $sStylePrefix . '-gis';
  1445. if($bPinned)
  1446. $sClass .= '-pnd';
  1447. if($bSticked)
  1448. $sClass .= '-psd';
  1449. if($bPromoted)
  1450. $sClass .= '-pmd';
  1451. }
  1452. }
  1453. $sClass .= ' ' . $aEvent['type'] . (!empty($aEvent['action']) ? ' ' . $aEvent['action'] : '');
  1454. $aAuthorAcl = BxDolAcl::getInstance()->getMemberMembershipInfo($aEvent['object_owner_id']);
  1455. if(!empty($aAuthorAcl) && isset($this->_aAclId2Name[$aAuthorAcl['id']]))
  1456. $sClass .= ' ' . $sStylePrefix . '-aml-' . $this->_aAclId2Name[$aAuthorAcl['id']];
  1457. if(!empty($aBrowseParams['blink']) && in_array($aEvent['id'], $aBrowseParams['blink']))
  1458. $sClass .= ' ' . $sStylePrefix . '-blink';
  1459. if($bPinned)
  1460. $sClass .= ' ' . $sStylePrefix . '-pinned';
  1461. if($bSticked)
  1462. $sClass .= ' ' . $sStylePrefix . '-sticked';
  1463. if($bPromoted)
  1464. $sClass .= ' ' . $sStylePrefix . '-promoted';
  1465. $sClassOwner = $bTmplVarsOwnerActions ? $sStylePrefix . '-io-with-actions' : '';
  1466. $oMetatags = BxDolMetatags::getObjectInstance($this->_oConfig->getObject('metatags'));
  1467. $sLocation = $oMetatags->locationsString($aEvent['id']);
  1468. $sFields = '';
  1469. if(!$bViewItem) {
  1470. $oForm = BxDolForm::getObjectInstance($this->_oConfig->getObject('form_post'), $this->_oConfig->getObject('form_display_post_view'), $this, $aEvent['id']);
  1471. $oForm->initChecker($aEvent);
  1472. if(!empty($oForm->aInputs) && is_array($oForm->aInputs))
  1473. foreach($oForm->aInputs as $aInput)
  1474. if($aInput['type'] != 'hidden' && !empty($aInput['value'])) {
  1475. $sFields = $oForm->getCode();
  1476. break;
  1477. }
  1478. }
  1479. $sIcon = !empty($aEvent['icon']) ? $aEvent['icon'] : $CNF['ICON'];
  1480. $aTmplVars = array (
  1481. 'style_prefix' => $sStylePrefix,
  1482. 'js_object' => $sJsObject,
  1483. 'html_id' => $this->_oConfig->getHtmlIdView('item', $aBrowseParams, array('whole' => false)) . $aEvent['id'],
  1484. 'class' => $sClass,
  1485. 'class_owner' => $sClassOwner,
  1486. 'class_content' => $bViewItem ? 'bx-def-color-bg-block' : 'bx-def-color-bg-box',
  1487. 'id' => $aEvent['id'],
  1488. 'bx_if:show_note' => array(
  1489. 'condition' => !empty($aTmplVarsNote),
  1490. 'content' => $aTmplVarsNote
  1491. ),
  1492. 'bx_if:show_owner_actions' => array(
  1493. 'condition' => $bTmplVarsOwnerActions,
  1494. 'content' => $aTmplVarsOwnerActions
  1495. ),
  1496. 'item_icon' => $sIcon,
  1497. 'item_owner_url' => $sAuthorUrl,
  1498. 'item_owner_title' => bx_html_attribute($sAuthorName),
  1499. 'item_owner_name' => $sAuthorName,
  1500. 'item_owner_badges' => $sAuthorBadges,
  1501. 'item_owner_unit' => $sAuthorUnit,
  1502. 'item_view_url' => $this->_oConfig->getItemViewUrl($aEvent),
  1503. 'item_date' => bx_time_js($aEvent['date']),
  1504. 'bx_if:show_pinned' => array(
  1505. 'condition' => $bPinned,
  1506. 'content' => array(
  1507. 'style_prefix' => $sStylePrefix,
  1508. )
  1509. ),
  1510. 'bx_if:show_sticked' => array(
  1511. 'condition' => $bSticked,
  1512. 'content' => array(
  1513. 'style_prefix' => $sStylePrefix,
  1514. )
  1515. ),
  1516. 'bx_if:show_hot' => array(
  1517. 'condition' => $this->_oConfig->isHotEvent($aEvent['id']),
  1518. 'content' => array(
  1519. 'style_prefix' => $sStylePrefix,
  1520. )
  1521. ),
  1522. 'bx_if:show_manage' => array(
  1523. 'condition' => !empty($aTmplVarsManage),
  1524. 'content' => $aTmplVarsManage
  1525. ),
  1526. 'bx_if:show_item_action' => array(
  1527. 'condition' => $this->_oConfig->isSystem($aEvent['type'], $aEvent['action']) || $bTmplVarsTimelineOwner,
  1528. 'content' => array(
  1529. 'style_prefix' => $sStylePrefix,
  1530. 'item_icon' => $sIcon,
  1531. 'item_owner_action' => $sAuthorAction,
  1532. 'bx_if:show_timeline_owner' => array(
  1533. 'condition' => $bTmplVarsTimelineOwner,
  1534. 'content' => $aTmplVarsTimelineOwner
  1535. ),
  1536. )
  1537. ),
  1538. 'content_type' => $sType,
  1539. 'content' => is_string($aEvent['content']) ? $aEvent['content'] : $this->_getContent($sType, $aEvent, $aBrowseParams),
  1540. 'bx_if:show_location' => array(
  1541. 'condition' => !empty($sLocation),
  1542. 'content' => array(
  1543. 'style_prefix' => $sStylePrefix,
  1544. 'location' => $sLocation
  1545. )
  1546. ),
  1547. 'bx_if:show_fields' => array(
  1548. 'condition' => !empty($sFields),
  1549. 'content' => array(
  1550. 'style_prefix' => $sStylePrefix,
  1551. 'fields' => $sFields
  1552. )
  1553. ),
  1554. 'bx_if:show_menu_item_counters' => array(
  1555. 'condition' => !empty($aTmplVarsMenuItemCounters),
  1556. 'content' => $aTmplVarsMenuItemCounters
  1557. ),
  1558. 'bx_if:show_menu_item_actions' => array(
  1559. 'condition' => !empty($aTmplVarsMenuItemActions),
  1560. 'content' => $aTmplVarsMenuItemActions
  1561. ),
  1562. 'bx_if:show_menu_item_meta' => array(
  1563. 'condition' => !empty($aTmplVarsMenuItemMeta),
  1564. 'content' => $aTmplVarsMenuItemMeta
  1565. ),
  1566. 'comments' => '',
  1567. );
  1568. $iPreloadComments = $this->_oConfig->getPreloadComments();
  1569. if($iPreloadComments > 0 && $oModule->isAllowedComment($aEvent) && in_array($aBrowseParams['view'], array(BX_TIMELINE_VIEW_TIMELINE, BX_TIMELINE_VIEW_OUTLINE)))
  1570. $aTmplVars['comments'] = $this->_getComments($aEvent['comments'], array_merge($aBrowseParams, array(
  1571. 'cmts_preload_number' => $iPreloadComments,
  1572. 'cmts_min_post_form' => false
  1573. )));
  1574. $sVariable = '_sTmplContentItem' . bx_gen_method_name($aBrowseParams['view']);
  1575. if(empty(self::$$sVariable))
  1576. self::$$sVariable = $this->getHtml('item_' . $aBrowseParams['view'] . '.html');
  1577. $sTmplCode = self::$$sVariable;
  1578. bx_alert($this->_oConfig->getName(), 'get_post', 0, 0, array(
  1579. 'type' => $sType,
  1580. 'event' => $aEvent,
  1581. 'browse_params' => $aBrowseParams,
  1582. 'tmpl_code' => &$sTmplCode,
  1583. 'tmpl_vars' => &$aTmplVars
  1584. ));
  1585. return $this->parseHtmlByContent($sTmplCode, $aTmplVars);
  1586. }
  1587. public function _getPostApi(&$aEvent, $aParams = [], $aEventAdd = [])
  1588. {
  1589. $oModule = $this->getModule();
  1590. $aEvent['author_data'] = BxDolProfile::getData($aEvent['object_owner_id']);
  1591. $aEvent['author_actions'] = [];
  1592. $iInitiatorProfile = (int)bx_get_logged_profile_id();
  1593. $iContentProfile = (int)$aEvent['object_owner_id'];
  1594. $sConnection = 'sys_profiles_subscriptions';
  1595. if(($oConnection = BxDolConnection::getObjectInstance($sConnection)) !== false && $iInitiatorProfile != $iContentProfile && !$oConnection->isConnected($iInitiatorProfile, $iContentProfile)) {
  1596. $aEvent['author_actions'][] = [
  1597. 'type' => 'connections',
  1598. 'o' => $sConnection,
  1599. 'a' => 'add',
  1600. 'iid' => $iInitiatorProfile,
  1601. 'cid' => $iContentProfile,
  1602. 'title' => _t('_sys_menu_item_title_sm_subscribe'),
  1603. ];
  1604. }
  1605. $aEvent['url'] = bx_ltrim_str($aEvent['content']['url'], BX_DOL_URL_ROOT);
  1606. if(empty($aEventAdd['menu_actions'])) {
  1607. $oMenuActions = BxDolMenu::getObjectInstance($this->_oConfig->getObject('menu_item_actions_all'));
  1608. if(!$oMenuActions)
  1609. $oMenuActions = BxDolMenu::getObjectInstance($this->_oConfig->getObject('menu_item_actions'));
  1610. }
  1611. else
  1612. $oMenuActions = $aEventAdd['menu_actions'];
  1613. if($oMenuActions !== false) {
  1614. $oMenuActions->setEvent($aEvent, $aParams);
  1615. $aEvent['menu_actions'] = $oMenuActions->getCodeAPI();
  1616. }
  1617. if(empty($aEventAdd['menu_manage']))
  1618. $oMenuManage = BxDolMenu::getObjectInstance($this->_oConfig->getObject('menu_item_manage'));
  1619. else
  1620. $oMenuManage = $aEventAdd['menu_manage'];
  1621. if($oMenuManage !== false) {
  1622. $oMenuManage->setEvent($aEvent);
  1623. $aEvent['menu_manage'] = $oMenuManage->getCodeAPI();
  1624. }
  1625. $aCmts = [];
  1626. $oCmts = $oModule->getCmtsObject($aEvent['comments']['system'], $aEvent['comments']['object_id']);
  1627. if($oCmts !== false) {
  1628. $aCmtsParams = ['mode' => 'feed', 'order_way' => 'desc', 'start_from' => 0, 'per_view' => 1];
  1629. $aCmts = bx_srv('system', 'get_comments_api', [$oCmts, $aCmtsParams], 'TemplCmtsServices');
  1630. $aEvent['cmts'] = $aCmts;
  1631. $aEvent['cmts']['count'] = $aEvent['comments']['count'];
  1632. }
  1633. return $aEvent;
  1634. }
  1635. protected function _getContent($sType, $aEvent, $aBrowseParams = array())
  1636. {
  1637. $sMethod = '_getTmplVarsContent' . ucfirst($sType);
  1638. if(!method_exists($this, $sMethod))
  1639. return '';
  1640. $aTmplVars = $this->$sMethod($aEvent, $aBrowseParams);
  1641. $sVariable = '_sTmplContentType' . bx_gen_method_name($sType);
  1642. if(empty(self::$$sVariable))
  1643. self::$$sVariable = $this->getHtml('type_' . $sType . '.html');
  1644. $sTmplCode = self::$$sVariable;
  1645. bx_alert($this->_oConfig->getName(), 'get_post_content', 0, 0, array(
  1646. 'type' => $sType,
  1647. 'event' => $aEvent,
  1648. 'browse_params' => $aBrowseParams,
  1649. 'tmpl_code' => &$sTmplCode,
  1650. 'tmpl_vars' => &$aTmplVars
  1651. ));
  1652. return $this->parseHtmlByContent($sTmplCode, $aTmplVars);
  1653. }
  1654. protected function _getComments($aComments, $aBrowseParams = array())
  1655. {
  1656. $mixedComments = $this->getModule()->getCommentsData($aComments);
  1657. if($mixedComments === false)
  1658. return '';
  1659. list($sSystem, $iObjectId, $iCount) = $mixedComments;
  1660. return $this->getComments($sSystem, $iObjectId, $aBrowseParams);
  1661. }
  1662. protected function _getShowMore($aParams)
  1663. {
  1664. return $this->parseHtmlByName('show_more.html', array(
  1665. 'style_prefix' => $this->_oConfig->getPrefix('style'),
  1666. 'js_object' => $this->_oConfig->getJsObjectView($aParams),
  1667. ));
  1668. }
  1669. protected function _getImagePopup($aParams)
  1670. {
  1671. $sViewImagePopupId = $this->_oConfig->getHtmlIdView('photo_popup', $aParams);
  1672. $sViewImagePopupContent = $this->parseHtmlByName('popup_image.html', array(
  1673. 'image_url' => ''
  1674. ));
  1675. return BxTemplFunctions::getInstance()->transBox($sViewImagePopupId, $sViewImagePopupContent, true);
  1676. }
  1677. protected function _getRepostJsClick($iOwnerId, $sType, $sAction, $iObjectId)
  1678. {
  1679. $sJsObject = $this->_oConfig->getJsObject('repost');
  1680. $sFormat = "%s.repostItem(this, %d, '%s', '%s', %d);";
  1681. $iOwnerId = !empty($iOwnerId) ? (int)$iOwnerId : $this->getModule()->getUserId(); //--- in whose timeline the content will be reposted
  1682. return sprintf($sFormat, $sJsObject, $iOwnerId, $sType, $sAction, (int)$iObjectId);
  1683. }
  1684. protected function _getRepostWithJsClick($iReposterId, $sType, $sAction, $iObjectId)
  1685. {
  1686. $sJsObject = $this->_oConfig->getJsObject('repost');
  1687. $sFormat = "%s.repostItemWith(this, %d, '%s', '%s', %d);";
  1688. $iReposterId = !empty($iReposterId) ? (int)$iReposterId : $this->getModule()->getUserId();
  1689. return sprintf($sFormat, $sJsObject, $iReposterId, $sType, $sAction, (int)$iObjectId);
  1690. }
  1691. protected function _getRepostToJsClick($iReposterId, $sType, $sAction, $iObjectId)
  1692. {
  1693. $sJsObject = $this->_oConfig->getJsObject('repost');
  1694. $sFormat = "%s.repostItemTo(this, %d, '%s', '%s', %d);";
  1695. $iReposterId = !empty($iReposterId) ? (int)$iReposterId : $this->getModule()->getUserId();
  1696. return sprintf($sFormat, $sJsObject, $iReposterId, $sType, $sAction, (int)$iObjectId);
  1697. }
  1698. protected function _getJumpToList($aParams)
  1699. {
  1700. $iYearSel = (int)$aParams['timeline'];
  1701. $iYearMin = $this->_oDb->getMaxDuration($aParams);
  1702. if(empty($iYearMin))
  1703. return '';
  1704. $sStylePrefix = $this->_oConfig->getPrefix('style');
  1705. $sJsObject = $this->_oConfig->getJsObjectView($aParams);
  1706. $aYears = array();
  1707. $iYearMax = date('Y', time()) - 1;
  1708. for($i = $iYearMax; $i >= $iYearMin; $i--) {
  1709. $bCurrent = $i == $iYearSel;
  1710. $aYears[] = array(
  1711. 'style_prefix' => $sStylePrefix,
  1712. 'bx_if:show_link' => array(
  1713. 'condition' => !$bCurrent,
  1714. 'content' => array(
  1715. 'title' => _t('_bx_timeline_txt_jump_to_n_year', $i),
  1716. 'onclick' => 'javascript:' . $sJsObject . '.changeTimeline(this, \'' . $i . '-12-31\')',
  1717. 'content' => $i
  1718. )
  1719. ),
  1720. 'bx_if:show_text' => array(
  1721. 'condition' => $bCurrent,
  1722. 'content' => array(
  1723. 'content' => $i
  1724. )
  1725. ),
  1726. );
  1727. }
  1728. return $this->parseHtmlByName('jump_to.html', array(
  1729. 'bx_if:show_list' => array(
  1730. 'condition' => true,
  1731. 'content' => array(
  1732. 'style_prefix' => $sStylePrefix,
  1733. 'bx_repeat:links' => $aYears,
  1734. )
  1735. ),
  1736. 'bx_if:show_calendar' => array(
  1737. 'condition' => false,
  1738. 'content' => array()
  1739. )
  1740. ));
  1741. }
  1742. protected function _getJumpToCaledar($aParams)
  1743. {
  1744. $sStylePrefix = $this->_oConfig->getPrefix('style');
  1745. $sJsObject = $this->_oConfig->getJsObjectView($aParams);
  1746. return $this->parseHtmlByName('jump_to.html', array(
  1747. 'bx_if:show_list' => array(
  1748. 'condition' => false,
  1749. 'content' => array()
  1750. ),
  1751. 'bx_if:show_calendar' => array(
  1752. 'condition' => true,
  1753. 'content' => array(
  1754. 'style_prefix' => $sStylePrefix,
  1755. 'onclick' => 'javascript:' . $sJsObject . '.showCalendar(this)',
  1756. )
  1757. )
  1758. ));
  1759. }
  1760. protected function _getTmplVarsMenuItemActions(&$aEvent, $aBrowseParams = array())
  1761. {
  1762. $oMenu = BxDolMenu::getObjectInstance($this->_oConfig->getObject('menu_item_actions_all'));
  1763. if(!$oMenu) {
  1764. $oMenu = BxDolMenu::getObjectInstance($this->_oConfig->getObject('menu_item_actions'));
  1765. if(!$oMenu)
  1766. return array();
  1767. }
  1768. $oMenu->setEvent($aEvent, $aBrowseParams);
  1769. $oMenu->setDynamicMode(isset($aBrowseParams['dynamic_mode']) && $aBrowseParams['dynamic_mode'] === true);
  1770. $sMenu = $oMenu->getCode();
  1771. if(empty($sMenu))
  1772. return array();
  1773. return array(
  1774. 'style_prefix' => $this->_oConfig->getPrefix('style'),
  1775. 'js_object' => $this->_oConfig->getJsObjectView($aBrowseParams),
  1776. 'menu_item_actions' => $sMenu
  1777. );
  1778. }
  1779. protected function _getTmplVarsManage(&$aEvent, $aBrowseParams = array())
  1780. {
  1781. $oMenu = BxDolMenu::getObjectInstance($this->_oConfig->getObject('menu_item_actions_all'));
  1782. if($oMenu)
  1783. return array();
  1784. $oMenu = BxDolMenu::getObjectInstance($this->_oConfig->getObject('menu_item_manage'));
  1785. if(!$oMenu)
  1786. return array();
  1787. $oMenu->setEvent($aEvent, $aBrowseParams);
  1788. $oMenu->setDynamicMode(isset($aBrowseParams['dynamic_mode']) && $aBrowseParams['dynamic_mode'] === true);
  1789. if(!$oMenu->isVisible())
  1790. return array();
  1791. $sOnclick = "bx_menu_popup('bx_timeline_menu_item_manage', this, {'id':'bx_timeline_menu_item_manage_{content_id}'}, {content_id:{content_id}, name:'{name}', view:'{view}', type:'{type}'});";
  1792. $sOnclick = bx_replace_markers($sOnclick, array(
  1793. 'content_id' => (int)$aEvent['id'],
  1794. 'view' => bx_process_output($aBrowseParams['view']),
  1795. 'type' => bx_process_output($aBrowseParams['type']),
  1796. 'name' => bx_process_output($aBrowseParams['name']),
  1797. ));
  1798. return array(
  1799. 'style_prefix' => $this->_oConfig->getPrefix('style'),
  1800. 'onclick' => $sOnclick
  1801. );
  1802. }
  1803. protected function _getTmplVarsMenuItemCounters(&$aEvent, $aBrowseParams = array())
  1804. {
  1805. $oMenu = BxDolMenu::getObjectInstance($this->_oConfig->getObject('menu_item_counters'));
  1806. if(!$oMenu)
  1807. return array();
  1808. $oMenu->setEvent($aEvent, $aBrowseParams);
  1809. $oMenu->setDynamicMode(isset($aBrowseParams['dynamic_mode']) && $aBrowseParams['dynamic_mode'] === true);
  1810. $sMenu = $oMenu->getCode();
  1811. if(empty($sMenu))
  1812. return array();
  1813. return array(
  1814. 'style_prefix' => $this->_oConfig->getPrefix('style'),
  1815. 'js_object' => $this->_oConfig->getJsObjectView($aBrowseParams),
  1816. 'menu_item_counters' => $sMenu
  1817. );
  1818. }
  1819. protected function _getTmplVarsMenuItemMeta(&$aEvent, $aBrowseParams = array())
  1820. {
  1821. $oMenu = BxDolMenu::getObjectInstance($this->_oConfig->getObject('menu_item_meta'));
  1822. if(!$oMenu)
  1823. return array();
  1824. $oMenu->setEvent($aEvent);
  1825. $sMenu = $oMenu->getCode();
  1826. if(empty($sMenu))
  1827. return array();
  1828. return array(
  1829. 'style_prefix' => $this->_oConfig->getPrefix('style'),
  1830. 'meta' => $sMenu
  1831. );
  1832. }
  1833. protected function _getTmplVarsTimelineOwner(&$aEvent)
  1834. {
  1835. $sStylePrefix = $this->_oConfig->getPrefix('style');
  1836. $iUser = bx_get_logged_profile_id();
  1837. $oModule = $this->getModule();
  1838. $sConnection = $this->_oConfig->getObject('conn_subscriptions');
  1839. $oConnection = BxDolConnection::getObjectInstance($sConnection);
  1840. $sConnectionTitle = _t('_sys_menu_item_title_sm_subscribe');
  1841. $sKeyOwnerId = isset($aEvent['owner_id_grouped']) ? 'owner_id_grouped' : 'owner_id';
  1842. $aOwnerIds = is_array($aEvent[$sKeyOwnerId]) ? $aEvent[$sKeyOwnerId] : array($aEvent[$sKeyOwnerId]);
  1843. $aTmplVarsOwners = array();
  1844. foreach($aOwnerIds as $iOwnerId) {
  1845. $iOwnerId = (int)$iOwnerId;
  1846. $iObjectOwner = (int)$aEvent['object_owner_id'];
  1847. if($iObjectOwner < 0 && abs($iObjectOwner) == $iUser)
  1848. $iObjectOwner *= -1;
  1849. if($iOwnerId == 0 || $iOwnerId == $iObjectOwner)
  1850. continue;
  1851. $oOwner = $oModule->getObjectUser($iOwnerId);
  1852. $sToType = $oOwner->getModule();
  1853. $sToName = $oOwner->getDisplayName();
  1854. $sToUrl = $oOwner->getUrl();
  1855. $aTmplVarsActions = array();
  1856. if(!empty($iUser) && $iUser != $iOwnerId && $oConnection->checkAllowedConnect($iUser, $iOwnerId) === CHECK_ACTION_RESULT_ALLOWED) {
  1857. $aTmplVarsActions[] = array(
  1858. 'href' => "javascript:void(0)",
  1859. 'onclick' => "bx_conn_action(this, '" . $sConnection . "', 'add', '" . $iOwnerId . "')",
  1860. 'title' => bx_html_attribute($sConnectionTitle),
  1861. 'content' => $sConnectionTitle,
  1862. 'icon' => 'check'
  1863. );
  1864. }
  1865. $aTmplVarsOwners[] = array(
  1866. 'style_prefix' => $sStylePrefix,
  1867. 'owner_type' => _t('_' . $sToType),
  1868. 'owner_url' => $sToUrl,
  1869. 'owner_username' => $sToName,
  1870. 'bx_if:show_timeline_owner_actions' => array(
  1871. 'condition' => !empty($aTmplVarsActions),
  1872. 'content' => array(
  1873. 'style_prefix' => $sStylePrefix,
  1874. 'bx_repeat:timeline_owner_actions' => $aTmplVarsActions
  1875. )
  1876. )
  1877. );
  1878. }
  1879. if(empty($aTmplVarsOwners))
  1880. return array();
  1881. return array(
  1882. 'style_prefix' => $sStylePrefix,
  1883. 'bx_repeat:owners' => $aTmplVarsOwners
  1884. );
  1885. }
  1886. protected function _getTmplVarsContentPost(&$aEvent, $aBrowseParams = array())
  1887. {
  1888. $aContent = &$aEvent['content'];
  1889. $sStylePrefix = $this->_oConfig->getPrefix('style');
  1890. $bViewItem = isset($aBrowseParams['view']) && $aBrowseParams['view'] == BX_TIMELINE_VIEW_ITEM;
  1891. $bViewSearch = isset($aBrowseParams['view']) && $aBrowseParams['view'] == BX_TIMELINE_VIEW_SEARCH;
  1892. //--- Process Top Raw ---//
  1893. $sTopRaw = isset($aContent['top_raw']) ? $aContent['top_raw'] : '';
  1894. //--- Process Raw ---//
  1895. $sRaw = isset($aContent['raw']) ? $aContent['raw'] : '';
  1896. //--- Process Text ---//
  1897. $sUrl = isset($aContent['url']) ? bx_html_attribute($aContent['url']) : '';
  1898. $sTitle = '';
  1899. if(isset($aContent['title']))
  1900. $sTitle = bx_process_output($aContent['title']);
  1901. if(!empty($sUrl) && !empty($sTitle))
  1902. $sTitle = $this->parseLink($sUrl, $sTitle, array(
  1903. 'class' => $sStylePrefix . '-title bx-lnk-src',
  1904. 'title' => $sTitle
  1905. ));
  1906. $sMethodPrepare = '_prepareTextForOutput';
  1907. if($this->_oConfig->isBriefCards() && !$bViewItem)
  1908. $sMethodPrepare .= 'BriefCard';
  1909. $sText = isset($aContent['text']) ? $aContent['text'] : '';
  1910. $sText = $this->$sMethodPrepare($sText, $aEvent['id']);
  1911. //--- Process Links ---//
  1912. $bAddNofollow = $this->_oDb->getParam('sys_add_nofollow') == 'on';
  1913. $aTmplVarsLinks = [];
  1914. if(!empty($aContent['links']))
  1915. foreach($aContent['links'] as $aLink) {
  1916. $sLink = '';
  1917. $oEmbed = BxDolEmbed::getObjectInstance();
  1918. if ($oEmbed) {
  1919. $sLink = $this->parseHtmlByName('link_embed_provider.html', array(
  1920. 'style_prefix' => $sStylePrefix,
  1921. 'embed' => $oEmbed->getLinkHTML($aLink['url'], $aLink['title']),
  1922. ));
  1923. }
  1924. else {
  1925. $aLinkAttrs = array(
  1926. 'title' => $aLink['title']
  1927. );
  1928. if(!$this->_oConfig->isEqualUrls(BX_DOL_URL_ROOT, $aLink['url'])) {
  1929. $aLinkAttrs['target'] = '_blank';
  1930. if($bAddNofollow)
  1931. $aLinkAttrs['rel'] = 'nofollow';
  1932. }
  1933. $sLinkAttrs = '';
  1934. foreach($aLinkAttrs as $sKey => $sValue)
  1935. $sLinkAttrs .= ' ' . $sKey . '="' . bx_html_attribute($sValue) . '"';
  1936. $sLink = $this->parseHtmlByName('link_embed_common.html', array(
  1937. 'bx_if:show_thumbnail' => [
  1938. 'condition' => !empty($aLink['thumbnail']),
  1939. 'content' => [
  1940. 'style_prefix' => $sStylePrefix,
  1941. 'thumbnail' => $aLink['thumbnail'],
  1942. 'link' => !empty($aLink['url']) ? $aLink['url'] : 'javascript:void(0)',
  1943. 'attrs' => $sLinkAttrs
  1944. ]
  1945. ],
  1946. 'link' => !empty($aLink['url']) ? $aLink['url'] : 'javascript:void(0)',
  1947. 'attrs' => $sLinkAttrs,
  1948. 'content' => $aLink['title'],
  1949. 'bx_if:show_text' => [
  1950. 'condition' => !empty($aLink['text']),
  1951. 'content' => [
  1952. 'style_prefix' => $sStylePrefix,
  1953. 'text' => $aLink['text']
  1954. ]
  1955. ]
  1956. ));
  1957. }
  1958. $aTmplVarsLinks[] = [
  1959. 'style_prefix' => $sStylePrefix,
  1960. 'link' => $sLink
  1961. ];
  1962. }
  1963. /*
  1964. * View Item page and Snippet in Search Results should use Gallery layout.
  1965. */
  1966. $sAttachmentsLayout = $this->_oConfig->getAttachmentsLayout();
  1967. if($bViewItem || $bViewSearch)
  1968. $sAttachmentsLayout = BX_TIMELINE_ML_GALLERY;
  1969. $iAttachmentsTotal = 0;
  1970. $aTmplVarsImages = $aTmplVarsVideos = $aTmplVarsFiles = $aTmplVarsAttachments = $aTmplVarsAttachmentsFiles = array();
  1971. //--- Process Photos ---//
  1972. $bImages = !empty($aContent['images']) && is_array($aContent['images']);
  1973. if($bImages) {
  1974. $aImages = $this->_getTmplVarsImages($aContent['images'], true, $aEvent, $aBrowseParams);
  1975. if(!empty($aImages))
  1976. $aTmplVarsImages = array(
  1977. 'style_prefix' => $sStylePrefix,
  1978. 'display' => $aImages['display'],
  1979. 'bx_repeat:items' => $aImages['items']
  1980. );
  1981. }
  1982. $bImagesAttach = !empty($aContent['images_attach']) && is_array($aContent['images_attach']);
  1983. if($bImagesAttach) {
  1984. $aImagesAttach = $this->_getTmplVarsImages($aContent['images_attach'], ['layout' => $sAttachmentsLayout, 'first' => empty($aTmplVarsAttachments)], $aEvent, $aBrowseParams);
  1985. if(!empty($aImagesAttach)) {
  1986. $iAttachmentsTotal += $aImagesAttach['total'];
  1987. $aTmplVarsAttachments = array_merge($aTmplVarsAttachments, $aImagesAttach['items']);
  1988. }
  1989. }
  1990. //--- Add Meta Image when Item is viewed on a separate page ---//
  1991. if($bViewItem) {
  1992. $sMetaImageSrc = '';
  1993. if($bImages && !empty($aContent['images'][0]['src']))
  1994. $sMetaImageSrc = $aContent['images'][0]['src'];
  1995. else if($bImagesAttach && !empty($aContent['images_attach'][0]['src']))
  1996. $sMetaImageSrc = $aContent['images_attach'][0]['src'];
  1997. if(!empty($sMetaImageSrc))
  1998. BxDolTemplate::getInstance()->addPageMetaImage($sMetaImageSrc);
  1999. }
  2000. //--- Process Videos ---//
  2001. $bVideos = !empty($aContent['videos']) && is_array($aContent['videos']);
  2002. if($bVideos) {
  2003. $aVideos = $this->_getTmplVarsVideos($aContent['videos'], true, $aEvent, $aBrowseParams);
  2004. if(!empty($aVideos))
  2005. $aTmplVarsVideos = [
  2006. 'style_prefix' => $sStylePrefix,
  2007. 'display' => $aVideos['display'],
  2008. 'bx_repeat:items' => $aVideos['items']
  2009. ];
  2010. }
  2011. $bVideosAttach = !empty($aContent['videos_attach']) && is_array($aContent['videos_attach']);
  2012. if($bVideosAttach) {
  2013. $aVideosAttach = $this->_getTmplVarsVideos($aContent['videos_attach'], ['layout' => $sAttachmentsLayout, 'first' => empty($aTmplVarsAttachments)], $aEvent, $aBrowseParams);
  2014. if(!empty($aVideosAttach)) {
  2015. $iAttachmentsTotal += $aVideosAttach['total'];
  2016. $aTmplVarsAttachments = array_merge($aTmplVarsAttachments, $aVideosAttach['items']);
  2017. }
  2018. }
  2019. //--- Process Files ---//
  2020. $bFiles = !empty($aContent['files']) && is_array($aContent['files']);
  2021. if($bFiles) {
  2022. $aFiles = $this->_getTmplVarsFiles($aContent['files'], $aEvent, $aBrowseParams);
  2023. if(!empty($aFiles))
  2024. $aTmplVarsFiles = [
  2025. 'style_prefix' => $sStylePrefix,
  2026. 'display' => $aFiles['display'],
  2027. 'bx_repeat:items' => $aFiles['items']
  2028. ];
  2029. }
  2030. $bFilesAttach = !empty($aContent['files_attach']) && is_array($aContent['files_attach']);
  2031. if($bFilesAttach) {
  2032. $aFilesAttach = $this->_getTmplVarsFiles($aContent['files_attach'], $aEvent, $aBrowseParams);
  2033. if(!empty($aFilesAttach)) {
  2034. $aTmplVarsAttachmentsFiles = [
  2035. 'style_prefix' => $sStylePrefix,
  2036. 'display' => BX_TIMELINE_ML_GALLERY,
  2037. 'count' => count($aFilesAttach['items']),
  2038. 'bx_repeat:items' => $aFilesAttach['items']
  2039. ];
  2040. }
  2041. }
  2042. /*
  2043. * Process collected attachments in case of Showcase layout.
  2044. */
  2045. $iAttachmentsShow = 4;
  2046. $iAttachmentsCount = count($aTmplVarsAttachments);
  2047. if($sAttachmentsLayout == BX_TIMELINE_ML_SHOWCASE && $iAttachmentsCount > 0) {
  2048. $aTmplVarsAttachments[0]['class'] .= ' ' . $sStylePrefix . '-ia-first';
  2049. if($iAttachmentsCount > $iAttachmentsShow)
  2050. $aTmplVarsAttachments = array_slice($aTmplVarsAttachments, 0, $iAttachmentsShow);
  2051. if($iAttachmentsTotal > $iAttachmentsShow)
  2052. $aTmplVarsAttachments[$iAttachmentsShow - 1]['item'] .= $this->parseHtmlByName('attach_more.html', [
  2053. 'style_prefix' => $sStylePrefix,
  2054. 'link' => $this->_oConfig->getItemViewUrl($aEvent),
  2055. 'more' => $iAttachmentsTotal - $iAttachmentsShow
  2056. ]);
  2057. }
  2058. return [
  2059. 'style_prefix' => $sStylePrefix,
  2060. 'bx_if:show_title' => [
  2061. 'condition' => !empty($sTitle),
  2062. 'content' => [
  2063. 'style_prefix' => $sStylePrefix,
  2064. 'title' => $sTitle,
  2065. ]
  2066. ],
  2067. 'bx_if:show_content' => [
  2068. 'condition' => !empty($sText),
  2069. 'content' => [
  2070. 'style_prefix' => $sStylePrefix,
  2071. 'item_content' => $sText
  2072. ]
  2073. ],
  2074. 'bx_if:show_top_raw' => [
  2075. 'condition' => !empty($sTopRaw),
  2076. 'content' => [
  2077. 'style_prefix' => $sStylePrefix,
  2078. 'item_content_top_raw' => $sTopRaw
  2079. ]
  2080. ],
  2081. 'bx_if:show_raw' => [
  2082. 'condition' => !empty($sRaw),
  2083. 'content' => [
  2084. 'style_prefix' => $sStylePrefix,
  2085. 'item_content_raw' => $sRaw
  2086. ]
  2087. ],
  2088. 'bx_if:show_links' => [
  2089. 'condition' => !empty($aTmplVarsLinks),
  2090. 'content' => [
  2091. 'style_prefix' => $sStylePrefix,
  2092. 'bx_repeat:links' => $aTmplVarsLinks
  2093. ]
  2094. ],
  2095. 'bx_if:show_images' => [
  2096. 'condition' => !empty($aTmplVarsImages),
  2097. 'content' => $aTmplVarsImages
  2098. ],
  2099. 'bx_if:show_videos' => [
  2100. 'condition' => !empty($aTmplVarsVideos),
  2101. 'content' => $aTmplVarsVideos
  2102. ],
  2103. 'bx_if:show_files' => [
  2104. 'condition' => !empty($aTmplVarsFiles),
  2105. 'content' => $aTmplVarsFiles
  2106. ],
  2107. 'bx_if:show_attachments' => [
  2108. 'condition' => !empty($aTmplVarsAttachments),
  2109. 'content' => [
  2110. 'style_prefix' => $sStylePrefix,
  2111. 'display' => $sAttachmentsLayout,
  2112. 'count' => count($aTmplVarsAttachments),
  2113. 'bx_repeat:items' => $aTmplVarsAttachments
  2114. ]
  2115. ],
  2116. 'bx_if:show_attachments_files' => [
  2117. 'condition' => !empty($aTmplVarsAttachmentsFiles),
  2118. 'content' => $aTmplVarsAttachmentsFiles
  2119. ]
  2120. ];
  2121. }
  2122. protected function _getTmplVarsContentRepost(&$aEvent, $aBrowseParams = array())
  2123. {
  2124. $aContent = &$aEvent['content'];
  2125. $sStylePrefix = $this->_oConfig->getPrefix('style');
  2126. $sOwnerLink = $this->parseLink($aContent['owner_url'], $aContent['owner_name']);
  2127. $sSample = _t($aContent['sample']);
  2128. $sSampleLink = empty($aContent['url']) ? $sSample : $this->parseLink($aContent['url'], $sSample);
  2129. $aTmplVarsData = [];
  2130. if(!empty($aContent['rdata']) && is_array($aContent['rdata'])) {
  2131. $aData = $aContent['rdata'];
  2132. $aTmplVarsData['style_prefix'] = $sStylePrefix;
  2133. if(isset($aData['text']))
  2134. $aTmplVarsData['text'] = $this->_prepareTextForOutput($aData['text'], $aEvent['id']);
  2135. }
  2136. $sContent = $this->_getContent($aContent['parse_type'], $aEvent, $aBrowseParams);
  2137. return [
  2138. 'style_prefix' => $sStylePrefix,
  2139. 'item_owner_action' => _t('_bx_timeline_txt_reposted', $sOwnerLink, $sSampleLink),
  2140. 'bx_if:show_data' => [
  2141. 'condition' => !empty($aTmplVarsData),
  2142. 'content' => $aTmplVarsData
  2143. ],
  2144. 'bx_if:show_content' => [
  2145. 'condition' => !empty($sContent),
  2146. 'content' => [
  2147. 'style_prefix' => $sStylePrefix,
  2148. 'content' => $sContent,
  2149. ]
  2150. ]
  2151. ];
  2152. }
  2153. protected function _getTmplVarsNote(&$aEvent)
  2154. {
  2155. $sStylePrefix = $this->_oConfig->getPrefix('style');
  2156. $iUser = bx_get_logged_profile_id();
  2157. $iOwner = $this->_oConfig->isSystem($aEvent['type'], $aEvent['action']) ? $aEvent['owner_id'] : $aEvent['object_id'];
  2158. $aTmplVars = array();
  2159. if(!empty($iOwner) && !is_array($iOwner) && !empty($aEvent['promoted'])) {
  2160. $sConnection = $this->_oConfig->getObject('conn_subscriptions');
  2161. $oConnection = BxDolConnection::getObjectInstance($sConnection);
  2162. if(!$oConnection->isConnected($iUser, $iOwner))
  2163. $aTmplVars[] = [
  2164. 'style_prefix' => $sStylePrefix,
  2165. 'class' => '',
  2166. 'bx_if:show_note_color' => [
  2167. 'condition' => false,
  2168. 'content' => []
  2169. ],
  2170. 'item_note' => _t('_bx_timeline_txt_promoted')
  2171. ];
  2172. }
  2173. //--- Awaiting status related notes.
  2174. if($aEvent['status'] == BX_TIMELINE_STATUS_AWAITING) {
  2175. $sNote = '';
  2176. if((int)$aEvent['published'] > (int)$aEvent['date'])
  2177. $sNote = _t('_bx_timeline_txt_note_scheduled_awaiting', bx_time_js($aEvent['published'], BX_FORMAT_DATE, true));
  2178. else
  2179. $sNote = _t('_bx_timeline_txt_note_processing_awaiting');
  2180. $aTmplVars[] = [
  2181. 'style_prefix' => $sStylePrefix,
  2182. 'bx_if:show_note_color' => [
  2183. 'condition' => true,
  2184. 'content' => [
  2185. 'item_note_color' => 'red3'
  2186. ]
  2187. ],
  2188. 'item_note' => $sNote
  2189. ];
  2190. }
  2191. //--- Failed status related notes.
  2192. if($aEvent['status'] == BX_TIMELINE_STATUS_FAILED)
  2193. $aTmplVars[] = [
  2194. 'style_prefix' => $sStylePrefix,
  2195. 'bx_if:show_note_color' => [
  2196. 'condition' => true,
  2197. 'content' => [
  2198. 'item_note_color' => 'red2'
  2199. ]
  2200. ],
  2201. 'item_note' => _t('_bx_timeline_txt_note_processing_failed')
  2202. ];
  2203. //--- Pending status related notes.
  2204. if($aEvent['status_admin'] == BX_TIMELINE_STATUS_PENDING)
  2205. $aTmplVars[] = [
  2206. 'style_prefix' => $sStylePrefix,
  2207. 'bx_if:show_note_color' => [
  2208. 'condition' => true,
  2209. 'content' => [
  2210. 'item_note_color' => 'red3'
  2211. ]
  2212. ],
  2213. 'item_note' => _t('_bx_timeline_txt_note_approve_pending')
  2214. ];
  2215. return empty($aTmplVars) ? [] : [
  2216. 'style_prefix' => $sStylePrefix,
  2217. 'bx_repeat:notes' => $aTmplVars
  2218. ];
  2219. }
  2220. protected function _getTmplVarsOwnerActions(&$aEvent, $aBrowseParams = array())
  2221. {
  2222. $sStylePrefix = $this->_oConfig->getPrefix('style');
  2223. $iUser = bx_get_logged_profile_id();
  2224. $iOwner = $this->_oConfig->isSystem($aEvent['type'], $aEvent['action']) ? $aEvent['object_owner_id'] : $aEvent['object_id'];
  2225. $aTmplVarsActions = array();
  2226. if(!empty($iUser) && !empty($iOwner) && $iUser != $iOwner) {
  2227. $oOwner = BxDolProfile::getInstance($iOwner);
  2228. if($oOwner !== false && bx_srv($oOwner->getModule(), 'check_allowed_with_content', array('subscribe_add', $oOwner->getContentId())) === CHECK_ACTION_RESULT_ALLOWED) {
  2229. $sJsObject = $this->_oConfig->getJsObjectView($aBrowseParams);
  2230. $sConnection = $this->_oConfig->getObject('conn_subscriptions');
  2231. $sContent = _t('_sys_menu_item_title_sm_subscribe');
  2232. $aTmplVarsActions[] = array(
  2233. 'style_prefix' => $sStylePrefix,
  2234. 'href' => "javascript:void(0)",
  2235. 'onclick' => "bx_conn_action(this, '" . $sConnection . "', 'add', '" . $iOwner . "', false, function(oData, eElement) {" . $sJsObject . ".onConnect(eElement, oData);})",
  2236. 'title' => bx_html_attribute($sContent),
  2237. 'content' => $sContent,
  2238. 'icon' => 'check'
  2239. );
  2240. }
  2241. }
  2242. return array(
  2243. 'style_prefix' => $sStylePrefix,
  2244. 'bx_repeat:owner_actions' => $aTmplVarsActions
  2245. );
  2246. }
  2247. protected function _getTmplVarsImages($aImages, $mixedLayout, &$aEvent, &$aBrowseParams)
  2248. {
  2249. if(empty($aImages) || !is_array($aImages))
  2250. return [];
  2251. $iTotal = 0; //--- Total count of images related to the event.
  2252. if(isset($aImages['total']) && isset($aImages['items'])) {
  2253. $iTotal = (int)$aImages['total'];
  2254. $aImages = $aImages['items'];
  2255. }
  2256. else
  2257. $iTotal = count($aImages);
  2258. $sStylePrefix = $this->_oConfig->getPrefix('style');
  2259. $sJsObject = $this->_oConfig->getJsObjectView($aBrowseParams);
  2260. $bViewItem = isset($aBrowseParams['view']) && $aBrowseParams['view'] == BX_TIMELINE_VIEW_ITEM;
  2261. $sDisplay = '';
  2262. $aTmplVarsImages = [];
  2263. $sImageSrcKey = $sImageSrcKeyBig = '';
  2264. $sImageSrcKeyDefault = 'src';
  2265. if(count($aImages) == 1) {
  2266. $sDisplay = BX_TIMELINE_ML_SINGLE;
  2267. $sImageSrcKey = $bViewItem ? 'src_orig' : 'src_medium';
  2268. }
  2269. else if(is_array($mixedLayout) && !empty($mixedLayout['layout'])) {
  2270. $sDisplay = $mixedLayout['layout'];
  2271. $sImageSrcKey = 'src';
  2272. $sImageSrcKeyBig = 'src_medium';
  2273. }
  2274. else {
  2275. $sDisplay = BX_TIMELINE_ML_GALLERY;
  2276. $sImageSrcKey = 'src';
  2277. $sImageSrcKeyBig = 'src_medium';
  2278. }
  2279. $bAttachFirst = false;
  2280. if($sDisplay == BX_TIMELINE_ML_SHOWCASE)
  2281. $bAttachFirst = isset($mixedLayout['first']) && $mixedLayout['first'] === true;
  2282. $aImageFirst = reset($aImages);
  2283. $iImageFirst = isset($aImageFirst['id']) ? (int)$aImageFirst['id'] : 0;
  2284. $aImageSizes = [
  2285. 'small' => '300w',
  2286. 'medium' => '500w',
  2287. 'orig' => '1200w'
  2288. ];
  2289. foreach($aImages as $aImage) {
  2290. $sImageSrcKeyCur = $sImageSrcKey;
  2291. if(($bAttachFirst && isset($aImage['id']) && (int)$aImage['id'] == $iImageFirst) || $iTotal == 2)
  2292. $sImageSrcKeyCur = $sImageSrcKeyBig;
  2293. if (is_array($aImage))
  2294. $sImageSrc = !empty($aImage[$sImageSrcKeyCur]) ? $aImage[$sImageSrcKeyCur] : $aImage[$sImageSrcKeyDefault];
  2295. if(empty($sImageSrc))
  2296. continue;
  2297. $sImageAttrSrcset = '';
  2298. foreach($aImageSizes as $sSize => $sWidth)
  2299. if(isset($aImage['src_' . $sSize]))
  2300. $sImageAttrSrcset .= $aImage['src_' . $sSize] . ' ' . $sWidth . ', ';
  2301. $sImage = $this->parseImage($sImageSrc, array(
  2302. 'class' => $sStylePrefix . '-item-image',
  2303. 'srcset' => trim($sImageAttrSrcset, ", "),
  2304. 'sizes' => '100%'
  2305. ));
  2306. $aAttrs = array();
  2307. if(isset($aImage['onclick']))
  2308. $aAttrs['onclick'] = $aImage['onclick'];
  2309. else if(!empty($aImage['src_orig']))
  2310. $aAttrs['onclick'] = 'return ' . $sJsObject . '.showItem(this, \'' . $aEvent['id'] . '\', \'photo\', ' . json_encode(array('src' => base64_encode($aImage['src_orig']))) . ')';
  2311. $sImage = $this->parseLinkByName('image_link.html', isset($aImage['url']) ? $aImage['url'] : 'javascript:void(0)', $sImage, $aAttrs);
  2312. $aTmplVarsImages[] = array(
  2313. 'style_prefix' => $sStylePrefix,
  2314. 'class' => '',
  2315. 'item' => $sImage
  2316. );
  2317. }
  2318. return array(
  2319. 'display' => $sDisplay,
  2320. 'total' => $iTotal,
  2321. 'items' => $aTmplVarsImages
  2322. );
  2323. }
  2324. protected function _getTmplVarsVideos($aVideos, $mixedLayout, &$aEvent, &$aBrowseParams)
  2325. {
  2326. if(empty($aVideos) || !is_array($aVideos))
  2327. return array();
  2328. $iTotal = 0; //--- Total count of videos related to the event.
  2329. if(isset($aVideos['total']) && isset($aVideos['items'])) {
  2330. $iTotal = (int)$aVideos['total'];
  2331. $aVideos = $aVideos['items'];
  2332. }
  2333. else
  2334. $iTotal = count($aVideos);
  2335. $sStylePrefix = $this->_oConfig->getPrefix('style');
  2336. $sJsObject = $this->_oConfig->getJsObjectView($aBrowseParams);
  2337. $aTmplVarsVideos = array();
  2338. /*
  2339. * For now Main Section may have only one video which can use 'autoplay' feature.
  2340. */
  2341. $bMain = $mixedLayout === true;
  2342. if($bMain) {
  2343. $sDisplay = BX_TIMELINE_ML_SINGLE;
  2344. if(count($aVideos) > 1)
  2345. $aVideos = array_slice($aVideos, 0, 1);
  2346. }
  2347. else
  2348. $sDisplay = is_array($mixedLayout) && !empty($mixedLayout['layout']) ? $mixedLayout['layout'] : BX_TIMELINE_AML_DEFAULT;
  2349. /*
  2350. * Main Section: Autoplay feature is only available here.
  2351. */
  2352. $sVap = $sVapId = $sVapSrc = $sVapTmpl = '';
  2353. if($bMain) {
  2354. $sVap = $this->_oConfig->getVideosAutoplay();
  2355. if($sVap != BX_TIMELINE_VAP_OFF) {
  2356. $sVapId = $this->_oConfig->getHtmlIds('view', 'video_iframe') . $aEvent['id'] . '-';
  2357. $sVapSrc = BX_DOL_URL_ROOT . $this->_oConfig->getBaseUri() . 'video/' . $aEvent['id'] . '/';
  2358. $sVapTmpl = $this->getHtml('video_iframe.html');
  2359. }
  2360. }
  2361. /*
  2362. * Attachments Section.
  2363. */
  2364. $sAttachTmpl = '';
  2365. $bAttachFirst = false;
  2366. if($sDisplay == BX_TIMELINE_ML_SHOWCASE) {
  2367. $sAttachTmpl = $this->getHtml('attach_video_preview.html');
  2368. $bAttachFirst = isset($mixedLayout['first']) && $mixedLayout['first'] === true;
  2369. }
  2370. $iVideoFirst = reset($aVideos)['id'];
  2371. foreach($aVideos as $aVideo) {
  2372. $iVideo = (int)$aVideo['id'];
  2373. if($bMain && $sVap != BX_TIMELINE_VAP_OFF)
  2374. $aTmplVarsVideos[] = array(
  2375. 'style_prefix' => $sStylePrefix,
  2376. 'class' => '',
  2377. 'item' => $this->parseHtmlByContent($sVapTmpl, array(
  2378. 'style_prefix' => $sStylePrefix,
  2379. 'html_id' => $sVapId . $iVideo,
  2380. 'src' => $sVapSrc . $iVideo . '/'
  2381. ))
  2382. );
  2383. else {
  2384. if($bMain || $sDisplay == BX_TIMELINE_ML_GALLERY || ($bAttachFirst && $iVideo == $iVideoFirst)) {
  2385. $sItem = '';
  2386. if(isset($aVideo['src'], $aVideo['src_orig'])) {
  2387. $sItem = $this->parseImage($aVideo['src'], array(
  2388. 'class' => $sStylePrefix . '-item-image'
  2389. ));
  2390. $aAttrs = array();
  2391. if(!empty($aVideo['src_orig']))
  2392. $aAttrs['onclick'] = 'return ' . $sJsObject . '.showItem(this, \'' . $aEvent['id'] . '\', \'video\', ' . json_encode(array('src' => base64_encode($aVideo['src_orig']))) . ')';
  2393. $sItem = $this->parseLinkByName('image_link.html', isset($aVideo['url']) ? $aVideo['url'] : 'javascript:void(0)', $sItem, $aAttrs);
  2394. }
  2395. else
  2396. $sItem = BxTemplFunctions::getInstance()->videoPlayer($aVideo['src_poster'], $aVideo['src_mp4'], $aVideo['src_mp4_hd'], array(
  2397. 'preload' => $this->_oConfig->getVideosPreload(),
  2398. ), '', $aBrowseParams['dynamic_mode']);
  2399. $aTmplVarsVideos[] = array(
  2400. 'style_prefix' => $sStylePrefix,
  2401. 'class' => '',
  2402. 'item' => $sItem
  2403. );
  2404. }
  2405. else {
  2406. $bUrl = !empty($aVideo['url']);
  2407. $sUrl = $bUrl ? $aVideo['url'] : '';
  2408. $sSrc = $aVideo[isset($aVideo['src'], $aVideo['src_orig']) ? 'src' : 'src_poster'];
  2409. $bDuration = !empty($aVideo['duration']);
  2410. $sDuration = _t_format_duration($bDuration ? $aVideo['duration'] : 0);
  2411. $aTmplVarsVideos[] = array(
  2412. 'style_prefix' => $sStylePrefix,
  2413. 'class' => '',
  2414. 'item' => $this->parseHtmlByContent($sAttachTmpl, array(
  2415. 'style_prefix' => $sStylePrefix,
  2416. 'bx_if:show_link' => array(
  2417. 'condition' => $bUrl,
  2418. 'content' => array(
  2419. 'style_prefix' => $sStylePrefix,
  2420. 'url' => $sUrl,
  2421. 'src' => $sSrc,
  2422. )
  2423. ),
  2424. 'bx_if:show_non_link' => array(
  2425. 'condition' => !$bUrl,
  2426. 'content' => array(
  2427. 'style_prefix' => $sStylePrefix,
  2428. 'src' => $sSrc,
  2429. )
  2430. ),
  2431. 'bx_if:show_duration' => array(
  2432. 'condition' => $bDuration,
  2433. 'content' => array(
  2434. 'style_prefix' => $sStylePrefix,
  2435. 'duration' => $sDuration,
  2436. )
  2437. )
  2438. ))
  2439. );
  2440. }
  2441. }
  2442. }
  2443. return array(
  2444. 'display' => $sDisplay,
  2445. 'total' => $iTotal,
  2446. 'items' => $aTmplVarsVideos
  2447. );
  2448. }
  2449. protected function _getTmplVarsFiles($aFiles, &$aEvent, &$aBrowseParams)
  2450. {
  2451. if(empty($aFiles) || !is_array($aFiles))
  2452. return array();
  2453. $iTotal = 0; //--- Total count of files related to the event.
  2454. if(isset($aFiles['total']) && isset($aFiles['items'])) {
  2455. $iTotal = (int)$aFiles['total'];
  2456. $aFiles = $aFiles['items'];
  2457. }
  2458. else
  2459. $iTotal = count($aFiles);
  2460. $sStylePrefix = $this->_oConfig->getPrefix('style');
  2461. $sJsObject = $this->_oConfig->getJsObjectView($aBrowseParams);
  2462. $bViewItem = isset($aBrowseParams['view']) && $aBrowseParams['view'] == BX_TIMELINE_VIEW_ITEM;
  2463. $sDisplay = '';
  2464. $aTmplVarsFiles = array();
  2465. $sFileSrcKey = '';
  2466. $sFileSrcKeyDefault = 'src';
  2467. if(count($aFiles) == 1) {
  2468. $sDisplay = 'single';
  2469. $sFileSrcKey = $bViewItem ? 'src_orig' : 'src_medium';
  2470. }
  2471. else {
  2472. $sDisplay = 'gallery';
  2473. $sFileSrcKey = 'src';
  2474. }
  2475. foreach($aFiles as $aFile) {
  2476. $sFileSrc = !empty($aFile[$sFileSrcKey]) ? $aFile[$sFileSrcKey] : $aFile[$sFileSrcKeyDefault];
  2477. if(empty($sFileSrc))
  2478. continue;
  2479. $aAttrs = ['target' => '_blank'];
  2480. if(isset($aFile['onclick']))
  2481. $aAttrs['onclick'] = $aFile['onclick'];
  2482. else if(!$bViewItem && !empty($aFile['src_orig']))
  2483. $aAttrs['onclick'] = 'return ' . $sJsObject . '.showItem(this, \'' . $aEvent['id'] . '\', \'file\', ' . json_encode(array('src' => base64_encode($aFile['src_orig']))) . ')';
  2484. if(isset($aFile['title']))
  2485. $aAttrs['title'] = $aFile['title'];
  2486. $sAttrs = '';
  2487. foreach($aAttrs as $sKey => $sValue)
  2488. $sAttrs .= ' ' . $sKey . '="' . bx_html_attribute($sValue) . '"';
  2489. $aTmplVarsFiles[] = [
  2490. 'style_prefix' => $sStylePrefix,
  2491. 'class' => '',
  2492. 'item' => $this->parseHtmlByName('file_link.html', [
  2493. 'href' => isset($aFile['url']) ? $aFile['url'] : 'javascript:void(0)',
  2494. 'attrs' => $sAttrs,
  2495. 'icon_src' => $sFileSrc,
  2496. 'icon_class' => $sStylePrefix . '-item-file'
  2497. ])
  2498. ];
  2499. }
  2500. return array(
  2501. 'display' => $sDisplay,
  2502. 'total' => $iTotal,
  2503. 'items' => $aTmplVarsFiles
  2504. );
  2505. }
  2506. protected function _getSystemData(&$aEvent, $aBrowseParams = array())
  2507. {
  2508. $mixedResult = $this->_oConfig->getSystemData($aEvent, $aBrowseParams);
  2509. if($mixedResult === false) {
  2510. $sMethod = 'display' . bx_gen_method_name($aEvent['type'] . '_' . $aEvent['action']);
  2511. if(method_exists($this, $sMethod))
  2512. $mixedResult = $this->$sMethod($aEvent);
  2513. }
  2514. if($mixedResult === false)
  2515. return '';
  2516. $this->_preparetDataActions($aEvent, $mixedResult);
  2517. return $mixedResult;
  2518. }
  2519. protected function _getCommonData(&$aEvent, $aBrowseParams = array())
  2520. {
  2521. $CNF = $this->_oConfig->CNF;
  2522. $oModule = $this->getModule();
  2523. $sJsObject = $this->_oConfig->getJsObjectView($aBrowseParams);
  2524. $sPrefix = $this->_oConfig->getPrefix('common_post');
  2525. $sType = str_replace($sPrefix, '', $aEvent['type']);
  2526. $oObjectOwner = BxDolProfile::getInstanceMagic($aEvent['object_id']);
  2527. $iOwnerId = $aEvent['owner_id'];
  2528. if(is_array($aEvent['owner_id']))
  2529. $iOwnerId = is_numeric($aEvent['object_privacy_view']) && (int)$aEvent['object_privacy_view'] < 0 ? abs((int)$aEvent['object_privacy_view']) : (int)array_shift($aEvent['owner_id']);
  2530. $aResult = array(
  2531. 'owner_id' => $iOwnerId,
  2532. 'object_owner_id' => $aEvent['object_id'],
  2533. 'icon' => $CNF['ICON'],
  2534. 'sample' => '_bx_timeline_txt_sample_with_article',
  2535. 'sample_wo_article' => '_bx_timeline_txt_sample',
  2536. 'sample_action' => '_bx_timeline_txt_added_sample',
  2537. 'content_type' => $sType,
  2538. 'content' => array(
  2539. 'sample' => '_bx_timeline_txt_sample_with_article',
  2540. 'sample_wo_article' => '_bx_timeline_txt_sample',
  2541. 'sample_action' => '_bx_timeline_txt_added_sample',
  2542. 'url' => $this->_oConfig->getItemViewUrl($aEvent)
  2543. ), //a string to display or array to parse default template before displaying.
  2544. 'views' => '',
  2545. 'votes' => '',
  2546. 'reactions' => '',
  2547. 'scores' => '',
  2548. 'reports' => '',
  2549. 'comments' => '',
  2550. 'title' => $aEvent['title'], //may be empty.
  2551. 'description' => bx_replace_markers($aEvent['description'], array(
  2552. 'profile_name' => $oObjectOwner->getDisplayName()
  2553. )) //may be empty.
  2554. );
  2555. switch($sType) {
  2556. case BX_TIMELINE_PARSE_TYPE_POST:
  2557. if(!empty($aEvent['content']))
  2558. $aResult['content'] = array_merge($aResult['content'], unserialize($aEvent['content']));
  2559. $aResult['content']['links'] = $oModule->getEventLinks($aEvent['id']);
  2560. $aResult['content']['images_attach'] = $oModule->getEventImages($aEvent['id']);
  2561. $aResult['content']['videos_attach'] = $oModule->getEventVideos($aEvent['id']);
  2562. $aResult['content']['files_attach'] = $oModule->getEventFiles($aEvent['id']);
  2563. break;
  2564. case BX_TIMELINE_PARSE_TYPE_REPOST:
  2565. if(empty($aEvent['content']))
  2566. return array();
  2567. $aContent = unserialize($aEvent['content']);
  2568. if(!$this->_oConfig->isSystem($aContent['type'] , $aContent['action'])) {
  2569. $aEventReposted = $this->_oDb->getEvents(array('browse' => 'id', 'value' => $aContent['object_id']));
  2570. $aReposted = $this->_getCommonData($aEventReposted, $aBrowseParams);
  2571. }
  2572. else {
  2573. $aEventReposted = $this->_oDb->getEvents(array_merge(array('browse' => 'descriptor'), $aContent));
  2574. $aReposted = $this->_getSystemData($aEventReposted, $aBrowseParams);
  2575. }
  2576. if(empty($aReposted) || !is_array($aReposted))
  2577. return array();
  2578. $aEventReposted['content'] = $aReposted['content'];
  2579. $aResult['content'] = array_merge($aContent, $aReposted['content']);
  2580. $aResult['content']['parse_type'] = !empty($aReposted['content_type']) ? $aReposted['content_type'] : BX_TIMELINE_PARSE_TYPE_DEFAULT;
  2581. $sKey = 'allowed_view';
  2582. $aResult['content'][$sKey] = $this->_preparePrivacy($sKey, $aEventReposted, $aReposted);
  2583. $oObjectOwner = $oModule->getObjectUser($aReposted['object_owner_id']);
  2584. $aResult['content']['owner_id'] = $aReposted['object_owner_id'];
  2585. $aResult['content']['owner_name'] = $oObjectOwner->getDisplayName();
  2586. $aResult['content']['owner_url'] = $oObjectOwner->getUrl();
  2587. if(!empty($aReposted['sample']))
  2588. $aResult['content']['sample'] = $aReposted['sample'];
  2589. if(!empty($aReposted['sample_wo_article']))
  2590. $aResult['content']['sample'] = $aReposted['sample_wo_article'];
  2591. $sUserName = $oModule->getObjectUser($aEvent['object_id'])->getDisplayName();
  2592. $aResult['title'] = _t('_bx_timeline_txt_user_repost', $sUserName, _t($aResult['content']['sample']));
  2593. $aResult['description'] = _t('_bx_timeline_txt_user_reposted_user_sample', $sUserName, $aResult['content']['owner_name'], _t($aResult['content']['sample']));
  2594. $aResult['allowed_view'] = array(
  2595. 'module' => $this->_oConfig->getName(),
  2596. 'method' => 'get_timeline_repost_allowed_view',
  2597. );
  2598. if(!$this->_oConfig->isRepostOwnActions()) {
  2599. $aResult['views'] = $aReposted['views'];
  2600. $aResult['votes'] = $aReposted['votes'];
  2601. $aResult['reactions'] = $aReposted['reactions'];
  2602. $aResult['scores'] = $aReposted['scores'];
  2603. $aResult['reports'] = $aReposted['reports'];
  2604. $aResult['comments'] = $aReposted['comments'];
  2605. }
  2606. break;
  2607. }
  2608. $this->_preparetDataActions($aEvent, $aResult);
  2609. return $aResult;
  2610. }
  2611. protected function _getFirst($aEvents, $aParams = array())
  2612. {
  2613. $CNF = $this->_oConfig->CNF;
  2614. foreach($aEvents as $aEvent)
  2615. if((int)$aEvent[$CNF['FIELD_STICKED']] == 0)
  2616. return (int)$aEvent[$CNF['FIELD_ID']];
  2617. $aParams['start'] += $aParams['per_page'];
  2618. $aEvents = $this->_oDb->getEvents($aParams);
  2619. if(!empty($aEvents) && is_array($aEvents))
  2620. return $this->_getFirst($aEvents, $aParams);
  2621. return 0;
  2622. }
  2623. protected function _preparetDataActions(&$aEvent, &$aResult)
  2624. {
  2625. if(empty($aEvent) || !is_array($aEvent) || empty($aEvent['id']))
  2626. return;
  2627. $oModule = $this->getModule();
  2628. $sSystem = $this->_oConfig->getObject('view');
  2629. if(empty($aResult['views'])) {
  2630. $aResult['views'] = array();
  2631. if($oModule->getViewObject($sSystem, $aEvent['id']) !== false)
  2632. $aResult['views'] = array(
  2633. 'system' => $sSystem,
  2634. 'object_id' => $aEvent['id'],
  2635. 'count' => $aEvent['views']
  2636. );
  2637. }
  2638. $sSystem = $this->_oConfig->getObject('vote');
  2639. if(empty($aResult['votes'])) {
  2640. $aResult['votes'] = array();
  2641. if($oModule->getVoteObject($sSystem, $aEvent['id']) !== false)
  2642. $aResult['votes'] = array(
  2643. 'system' => $sSystem,
  2644. 'object_id' => $aEvent['id'],
  2645. 'count' => $aEvent['votes']
  2646. );
  2647. }
  2648. $sSystem = $this->_oConfig->getObject('reaction');
  2649. if(empty($aResult['reactions'])) {
  2650. $aResult['reactions'] = array();
  2651. if($oModule->getReactionObject($sSystem, $aEvent['id']) !== false)
  2652. $aResult['reactions'] = array(
  2653. 'system' => $sSystem,
  2654. 'object_id' => $aEvent['id'],
  2655. 'count' => $aEvent['rvotes']
  2656. );
  2657. }
  2658. $sSystem = $this->_oConfig->getObject('score');
  2659. if(empty($aResult['scores'])) {
  2660. $aResult['scores'] = array();
  2661. if($oModule->getScoreObject($sSystem, $aEvent['id']) !== false)
  2662. $aResult['scores'] = array(
  2663. 'system' => $sSystem,
  2664. 'object_id' => $aEvent['id'],
  2665. 'score' => $aEvent['score']
  2666. );
  2667. }
  2668. $sSystem = $this->_oConfig->getObject('report');
  2669. if(empty($aResult['reports'])) {
  2670. $aResult['reports'] = array();
  2671. if($oModule->getReportObject($sSystem, $aEvent['id']) !== false)
  2672. $aResult['reports'] = array(
  2673. 'system' => $sSystem,
  2674. 'object_id' => $aEvent['id'],
  2675. 'count' => $aEvent['reports']
  2676. );
  2677. }
  2678. $sSystem = $this->_oConfig->getObject('comment');
  2679. if(empty($aResult['comments'])) {
  2680. $aResult['comments'] = array();
  2681. if($oModule->getCmtsObject($sSystem, $aEvent['id']) !== false)
  2682. $aResult['comments'] = array(
  2683. 'system' => $sSystem,
  2684. 'object_id' => $aEvent['id'],
  2685. 'count' => $aEvent['comments']
  2686. );
  2687. }
  2688. }
  2689. protected function _prepareTextForOutputBriefCard($s, $iEventId = 0)
  2690. {
  2691. $s = strip_tags($s, $this->_oConfig->getBriefCardsTags(true));
  2692. return $this->_prepareTextForOutput($s, $iEventId = 0);
  2693. }
  2694. protected function _prepareTextForOutput($s, $iEventId = 0)
  2695. {
  2696. $s = bx_process_output($s, BX_DATA_HTML);
  2697. $oMetatags = BxDolMetatags::getObjectInstance($this->_oConfig->getObject('metatags'));
  2698. $s = $oMetatags->metaParse($iEventId, $s);
  2699. return $s;
  2700. }
  2701. protected function _preparePrivacy($sKey, $aEvent, $aEventData)
  2702. {
  2703. $iResult = CHECK_ACTION_RESULT_ALLOWED;
  2704. if(isset($aEventData[$sKey], $aEventData[$sKey]['module'], $aEventData[$sKey]['method']))
  2705. $iResult = BxDolService::call($aEventData[$sKey]['module'], $aEventData[$sKey]['method'], array($aEvent));
  2706. else if(($aHandler = $this->_oConfig->getHandler($aEvent)) !== false && BxDolRequest::serviceExists($aHandler['module_name'], 'get_timeline_post_allowed_view'))
  2707. $iResult = BxDolService::call($aHandler['module_name'], 'get_timeline_post_allowed_view', array($aEvent));
  2708. return $iResult;
  2709. }
  2710. protected function _getCounterIcon($aParams = array())
  2711. {
  2712. return $this->parseHtmlByName('repost_counter_icon.html', []);
  2713. }
  2714. protected function _getCounterLabel($iCount, $aParams = array())
  2715. {
  2716. return _t(isset($aParams['caption']) ? $aParams['caption'] : '_bx_timeline_txt_repost_counter', $iCount);
  2717. }
  2718. }
  2719. /** @} */