BxTimelineModule.php 161 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123
  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. bx_import('BxDolAcl');
  12. bx_import('BxBaseModNotificationsModule');
  13. define('BX_TIMELINE_TYPE_ITEM', 'view_item');
  14. define('BX_TIMELINE_TYPE_OWNER_AND_CONNECTIONS', 'owner_and_connections');
  15. define('BX_TIMELINE_TYPE_CHANNELS', 'channels'); //--- Followed channels only.
  16. define('BX_TIMELINE_TYPE_FEED', 'feed'); //--- Owner and folloved contexts excluding channels.
  17. define('BX_TIMELINE_TYPE_HOT', 'hot'); //--- Aggrigated hot content.
  18. define('BX_TIMELINE_TYPE_DEFAULT', BX_BASE_MOD_NTFS_TYPE_OWNER);
  19. define('BX_TIMELINE_VIEW_ITEM', 'item');
  20. define('BX_TIMELINE_VIEW_TIMELINE', 'timeline');
  21. define('BX_TIMELINE_VIEW_OUTLINE', 'outline');
  22. define('BX_TIMELINE_VIEW_SEARCH', 'search');
  23. define('BX_TIMELINE_VIEW_DEFAULT', BX_TIMELINE_VIEW_OUTLINE);
  24. define('BX_TIMELINE_FILTER_ALL', 'all');
  25. define('BX_TIMELINE_FILTER_OWNER', 'owner');
  26. define('BX_TIMELINE_FILTER_OTHER', 'other');
  27. define('BX_TIMELINE_FILTER_OTHER_VIEWER', 'other_viewer');
  28. define('BX_TIMELINE_PARSE_TYPE_POST', 'post');
  29. define('BX_TIMELINE_PARSE_TYPE_REPOST', 'repost');
  30. define('BX_TIMELINE_PARSE_TYPE_DEFAULT', BX_TIMELINE_PARSE_TYPE_POST);
  31. define('BX_TIMELINE_STATUS_ACTIVE', 'active');
  32. define('BX_TIMELINE_STATUS_AWAITING', 'awaiting');
  33. define('BX_TIMELINE_STATUS_FAILED', 'failed');
  34. define('BX_TIMELINE_STATUS_HIDDEN', 'hidden');
  35. define('BX_TIMELINE_STATUS_DELETED', 'deleted');
  36. define('BX_TIMELINE_MEDIA_PHOTO', 'photo');
  37. define('BX_TIMELINE_MEDIA_VIDEO', 'video');
  38. //--- Video Auto Play
  39. define('BX_TIMELINE_VAP_OFF', 'off');
  40. define('BX_TIMELINE_VAP_ON_MUTE', 'on_mute');
  41. define('BX_TIMELINE_VAP_ON', 'on');
  42. //--- Media Layouts
  43. define('BX_TIMELINE_ML_SINGLE', 'single');
  44. define('BX_TIMELINE_ML_GALLERY', 'gallery');
  45. define('BX_TIMELINE_ML_SHOWCASE', 'showcase');
  46. //--- Default Attachments Media Layout
  47. define('BX_TIMELINE_AML_DEFAULT', BX_TIMELINE_ML_GALLERY);
  48. class BxTimelineModule extends BxBaseModNotificationsModule implements iBxDolContentInfoService
  49. {
  50. protected $_sJsPostObject;
  51. protected $_sJsViewObject;
  52. protected $_aPostElements;
  53. protected $_sJsOutlineObject;
  54. protected $_sDividerTemplate;
  55. protected $_sBalloonTemplate;
  56. protected $_sCmtPostTemplate;
  57. protected $_sCmtViewTemplate;
  58. protected $_sCmtTemplate;
  59. /**
  60. * Constructor
  61. */
  62. function __construct($aModule)
  63. {
  64. parent::__construct($aModule);
  65. }
  66. /**
  67. * ACTION METHODS
  68. */
  69. public function actionVideo($iEventId, $iVideoId)
  70. {
  71. $aEvent = $this->_oDb->getEvents(array('browse' => 'id', 'value' => $iEventId));
  72. if(empty($aEvent) || !is_array($aEvent))
  73. return;
  74. $aData = $this->_oTemplate->getDataCached($aEvent);
  75. if($aData === false || !isset($aData['content']['videos'][$iVideoId]))
  76. return;
  77. $oTemplate = BxDolTemplate::getInstance();
  78. $oTemplate->addJs(array(
  79. 'embedly-player.min.js'
  80. ));
  81. $oTemplate->setPageNameIndex (BX_PAGE_EMBED);
  82. $oTemplate->setPageContent ('page_main_code', $this->_oTemplate->getVideo($aEvent, $aData['content']['videos'][$iVideoId]));
  83. $oTemplate->getPageCode();
  84. }
  85. public function actionPost()
  86. {
  87. $this->_iOwnerId = bx_process_input(bx_get('owner_id'), BX_DATA_INT);
  88. $mixedAllowed = $this->isAllowedPost(true);
  89. if($mixedAllowed !== true)
  90. return echoJson(array('message' => strip_tags($mixedAllowed)));
  91. echoJson($this->getFormPost());
  92. }
  93. public function actionEdit($iId)
  94. {
  95. $this->_iOwnerId = bx_process_input(bx_get('owner_id'), BX_DATA_INT);
  96. $aBrowseParams = array();
  97. if(bx_get('bp') !== false)
  98. $aBrowseParams = $this->_oConfig->getBrowseParams(bx_process_input(bx_get('bp')));
  99. $mixedAllowed = $this->isAllowedPost(true);
  100. if($mixedAllowed !== true)
  101. return echoJson(array('message' => strip_tags($mixedAllowed)));
  102. echoJson($this->getFormEdit($iId, array('dynamic_mode' => true), $aBrowseParams));
  103. }
  104. function actionPin()
  105. {
  106. $iId = bx_process_input(bx_get('id'), BX_DATA_INT);
  107. $aEvent = $this->_oDb->getEvents(array('browse' => 'id', 'value' => $iId));
  108. if(empty($aEvent) || !is_array($aEvent))
  109. return echoJson(array('code' => 1));
  110. $aParams = $this->_prepareParamsGet();
  111. $this->_iOwnerId = $aParams['owner_id'];
  112. $mixedAllowed = $this->{'isAllowed' . ((int)$aEvent['pinned'] == 0 ? 'Pin' : 'Unpin')}($aEvent, true);
  113. if($mixedAllowed !== true)
  114. return echoJson(array('code' => 2, 'message' => strip_tags($mixedAllowed)));
  115. $aEvent['pinned'] = (int)$aEvent['pinned'] == 0 ? time() : 0;
  116. if(!$this->_oDb->updateEvent(array('pinned' => $aEvent['pinned']), array('id' => $iId)))
  117. return echoJson(array('code' => 3));
  118. $this->_oDb->deleteCache(array('context_id' => $this->_iOwnerId)); //--- Delete cache for context
  119. echoJson(array(
  120. 'code' => 0,
  121. 'id' => $iId,
  122. 'eval' => $this->_oConfig->getJsObjectView($aParams) . '.onPinPost(oData)'
  123. ));
  124. }
  125. function actionStick()
  126. {
  127. $iId = bx_process_input(bx_get('id'), BX_DATA_INT);
  128. $aEvent = $this->_oDb->getEvents(array('browse' => 'id', 'value' => $iId));
  129. if(empty($aEvent) || !is_array($aEvent))
  130. return echoJson(array('code' => 1));
  131. $aParams = $this->_prepareParamsGet();
  132. $this->_iOwnerId = $aParams['owner_id'];
  133. $mixedAllowed = $this->{'isAllowed' . ((int)$aEvent['sticked'] == 0 ? 'Stick' : 'Unstick')}($aEvent, true);
  134. if($mixedAllowed !== true)
  135. return echoJson(array('code' => 2, 'message' => strip_tags($mixedAllowed)));
  136. $aEvent['sticked'] = (int)$aEvent['sticked'] == 0 ? time() : 0;
  137. if(!$this->_oDb->updateEvent(array('sticked' => $aEvent['sticked']), array('id' => $iId)))
  138. return echoJson(array('code' => 3));
  139. $this->_oDb->deleteCache(array('context_id' => 0)); //--- Delete cache for Public feed
  140. $this->_oDb->deleteCache(array('context_id' => $this->_iOwnerId)); //--- Delete cache for context
  141. bx_audit(
  142. $iId,
  143. $this->getName(),
  144. '_sys_audit_action_' . ((int)$aEvent['sticked'] == 0 ? 'stick' : 'unstick'),
  145. $this->_prepareAuditParams($aEvent, false)
  146. );
  147. echoJson(array(
  148. 'code' => 0,
  149. 'id' => $iId,
  150. 'eval' => $this->_oConfig->getJsObjectView($aParams) . '.onStickPost(oData)'
  151. ));
  152. }
  153. function actionPromote()
  154. {
  155. $this->_iOwnerId = bx_process_input(bx_get('owner_id'), BX_DATA_INT);
  156. $iId = bx_process_input(bx_get('id'), BX_DATA_INT);
  157. $aEvent = $this->_oDb->getEvents(array('browse' => 'id', 'value' => $iId));
  158. $sAction = (int)$aEvent['promoted'] == 0 ? 'promote' : 'unpromote';
  159. $mixedAllowed = $this->{'isAllowed' . ucfirst($sAction)}($aEvent, true);
  160. if($mixedAllowed !== true)
  161. return echoJson(array('code' => 1, 'message' => strip_tags($mixedAllowed)));
  162. $aEvent['promoted'] = (int)$aEvent['promoted'] == 0 ? time() : 0;
  163. if(!$this->_oDb->updateEvent(array('promoted' => $aEvent['promoted']), array('id' => $iId)))
  164. return echoJson(array('code' => 2));
  165. $this->_oDb->deleteCache(array('context_id' => 0)); //--- Delete cache for Public feed
  166. $this->_oDb->deleteCache(array('context_id' => $this->_iOwnerId)); //--- Delete cache for context
  167. bx_alert($this->_oConfig->getObject('alert'), $sAction . 'd', $iId, (int)$this->getUserId(), array(
  168. 'owner_id' => $aEvent['owner_id'],
  169. 'object_id' => $aEvent['object_id'],
  170. 'object_author_id' => $this->_oConfig->isSystem($aEvent['type'], $aEvent['action']) ? $aEvent['owner_id'] : $aEvent['object_id']
  171. ));
  172. bx_audit(
  173. $iId,
  174. $this->getName(),
  175. '_sys_audit_action_' . ((int)$aEvent['promoted'] == 0 ? 'promote' : 'unpromote'),
  176. $this->_prepareAuditParams($aEvent, false)
  177. );
  178. echoJson(array(
  179. 'code' => 0,
  180. 'message' => _t('_bx_timeline_txt_msg_performed_action')
  181. ));
  182. }
  183. function actionDelete()
  184. {
  185. $iId = bx_process_input(bx_get('id'), BX_DATA_INT);
  186. $aEvent = $this->_oDb->getEvents(array('browse' => 'id', 'value' => $iId));
  187. if(empty($aEvent) || !is_array($aEvent))
  188. return echoJson(array('code' => 1));
  189. $aParams = $this->_prepareParamsGet();
  190. $this->_iOwnerId = $aParams['owner_id'];
  191. $mixedAllowed = $this->isAllowedDelete($aEvent, true);
  192. if($mixedAllowed !== true)
  193. return echoJson(array('code' => 2, 'message' => strip_tags($mixedAllowed)));
  194. if(!$this->deleteEvent($aEvent))
  195. return echoJson(array('code' => 3));
  196. $this->_oDb->deleteCache(array('event_id' => $iId));
  197. echoJson(array(
  198. 'code' => 0,
  199. 'id' => $aEvent['id'],
  200. 'eval' => $this->_oConfig->getJsObjectView($aParams) . '.onDeletePost(oData)'
  201. ));
  202. }
  203. public function actionRepost()
  204. {
  205. $iAuthorId = $this->getUserId();
  206. $iOwnerId = bx_process_input(bx_get('owner_id'), BX_DATA_INT);
  207. $sType = bx_process_input(bx_get('type'), BX_DATA_TEXT);
  208. $sAction = bx_process_input(bx_get('action'), BX_DATA_TEXT);
  209. $iObjectId = bx_process_input(bx_get('object_id'), BX_DATA_INT);
  210. $aResult = $this->serviceRepost($iAuthorId, $iOwnerId, $sType, $sAction, $iObjectId);
  211. if(!empty($aResult) && is_array($aResult))
  212. return echoJson($aResult);
  213. $aReposted = $this->_oDb->getReposted($sType, $sAction, $iObjectId);
  214. $sCounter = $this->_oTemplate->getRepostCounter($aReposted);
  215. echoJson(array(
  216. 'code' => 0,
  217. 'message' => _t('_bx_timeline_txt_msg_success_repost'),
  218. 'count' => $aReposted['reposts'],
  219. 'countf' => (int)$aReposted['reposts'] > 0 ? $this->_oTemplate->getRepostCounterLabel($aReposted['reposts']) : '',
  220. 'counter' => $sCounter,
  221. 'disabled' => true
  222. ));
  223. }
  224. function actionGetView()
  225. {
  226. $aParams = $this->_prepareParamsGet();
  227. $sConten = $this->_oTemplate->getViewBlock($aParams);
  228. if(empty($sConten))
  229. return echoJson(array());
  230. echoJson(array(
  231. 'code' => 0,
  232. 'content' => $sConten,
  233. ));
  234. }
  235. function actionGetPost()
  236. {
  237. $aParams = $this->_prepareParamsGet();
  238. $aParams['dynamic_mode'] = true;
  239. $this->_iOwnerId = $aParams['owner_id'];
  240. $sJsObject = '';
  241. if(bx_get('js_object') !== false)
  242. $sJsObject = bx_process_input(bx_get('js_object'));
  243. if(empty($sJsObject))
  244. $sJsObject = $this->_oConfig->getJsObject('post');
  245. $aEvent = $this->_oDb->getEvents(array('browse' => 'id', 'value' => bx_process_input(bx_get('id'), BX_DATA_INT)));
  246. if(empty($aEvent) || !is_array($aEvent))
  247. return echoJson(array());
  248. /**
  249. * Note. Disabled for now, because Own posts on Timelines of Following members
  250. * became visible on posts' author Dashboard Timeline.
  251. */
  252. /*
  253. $bAfpsLoading = (int)bx_get('afps_loading') === 1;
  254. if($bAfpsLoading && $this->_iOwnerId != $aEvent['owner_id'])
  255. return echoJson(array('message' => _t('_bx_timeline_txt_msg_posted')));
  256. */
  257. echoJson(array(
  258. 'id' => $aEvent['id'],
  259. 'name' => $aParams['name'],
  260. 'view' => $aParams['view'],
  261. 'type' => $aParams['type'],
  262. 'item' => $this->_oTemplate->getPost($aEvent, $aParams),
  263. 'eval' => $sJsObject . "._onGetPost(oData)"
  264. ));
  265. }
  266. function actionGetPosts()
  267. {
  268. $aParams = $this->_prepareParamsGet();
  269. list($sItems, $sLoadMore, $sBack, $sEmpty) = $this->_oTemplate->getPosts($aParams);
  270. echoJson(array(
  271. 'view' => $aParams['view'],
  272. 'items' => $sItems,
  273. 'load_more' => $sLoadMore,
  274. 'back' => $sBack,
  275. 'empty' => $sEmpty,
  276. 'eval' => $this->_oConfig->getJsObjectView($aParams) . "._onGetPosts(oData)"
  277. ));
  278. }
  279. public function actionGetPostForm()
  280. {
  281. $this->_iOwnerId = bx_process_input(bx_get('owner_id'), BX_DATA_INT);
  282. $sType = bx_process_input(bx_get('type'));
  283. echoJson($this->getFormPost(array(
  284. 'type' => $sType,
  285. 'form_display' => $this->_oConfig->getPostFormDisplay($sType)
  286. )));
  287. }
  288. public function actionGetEditForm($iId)
  289. {
  290. $aParams = $this->_prepareParamsGet();
  291. $this->_iOwnerId = $aParams['owner_id'];
  292. echoJson($this->getFormEdit($iId, array('dynamic_mode' => true), $aParams));
  293. }
  294. public function actionGetComments()
  295. {
  296. $this->_iOwnerId = bx_process_input(bx_get('owner_id'), BX_DATA_INT);
  297. $sSystem = bx_process_input(bx_get('system'), BX_DATA_TEXT);
  298. $iId = bx_process_input(bx_get('id'), BX_DATA_INT);
  299. $sComments = $this->_oTemplate->getComments($sSystem, $iId, array('dynamic_mode' => true));
  300. echoJson(array('content' => $sComments));
  301. }
  302. public function actionAddAttachLink()
  303. {
  304. $sUrl = bx_process_input(bx_get('url'));
  305. if(empty($sUrl))
  306. return echoJson(array());
  307. echoJson($this->addAttachLink(array(
  308. 'url' => $sUrl
  309. )));
  310. }
  311. public function actionDeleteAttachLink()
  312. {
  313. $iUserId = $this->getUserId();
  314. $iLinkId = bx_process_input(bx_get('id'), BX_DATA_INT);
  315. if(empty($iLinkId)) {
  316. echoJson(array());
  317. return;
  318. }
  319. $aLink = $this->_oDb->getUnusedLinks($iUserId, $iLinkId);
  320. if(empty($aLink) || !is_array($aLink)) {
  321. echoJson(array());
  322. return;
  323. }
  324. if(!empty($aLink['media_id']))
  325. BxDolStorage::getObjectInstance($this->_oConfig->getObject('storage_photos'))->deleteFile($aLink['media_id']);
  326. $aResult = array();
  327. if($this->_oDb->deleteUnusedLinks($iUserId, $iLinkId))
  328. $aResult = array('code' => 0);
  329. else
  330. $aResult = array('code' => 1, 'message' => _t('_bx_timeline_form_post_input_link_err_delete'));
  331. echoJson($aResult);
  332. }
  333. public function actionGetAttachLinkForm()
  334. {
  335. echo $this->_oTemplate->getAttachLinkForm();
  336. }
  337. public function actionSubmitAttachLinkForm()
  338. {
  339. echoJson($this->getFormAttachLink());
  340. }
  341. public function actionGetRepostedBy()
  342. {
  343. $iRepostedId = bx_process_input(bx_get('id'), BX_DATA_INT);
  344. echo $this->_oTemplate->getRepostedBy($iRepostedId);
  345. }
  346. public function actionGetItemBrief()
  347. {
  348. $iEvent = bx_process_input(bx_get('id'), BX_DATA_INT);
  349. $aEvent = $this->_oDb->getEvents(array('browse' => 'id', 'value' => $iEvent));
  350. if(empty($aEvent) || !is_array($aEvent)) {
  351. echo MsgBox(_t('_Empty'));
  352. return;
  353. }
  354. if(!$this->isAllowedView($aEvent)) {
  355. echo MsgBox(_t('_sys_access_denied_to_private_content'));
  356. return;
  357. }
  358. echo BxDolPage::getObjectInstance($this->_oConfig->getObject('page_item_brief'), $this->_oTemplate)->getCodeDynamic();
  359. }
  360. public function actionGetJumpTo()
  361. {
  362. $aParams = $this->_prepareParamsGet();
  363. $this->_iOwnerId = $aParams['owner_id'];
  364. $sJsObjectView = $this->_oConfig->getJsObjectView($aParams);
  365. echoJson(array(
  366. 'content' => $this->_oTemplate->getJumpTo($aParams),
  367. 'eval' => $sJsObjectView . '.onGetJumpTo(oData)'
  368. ));
  369. }
  370. public function actionResumeLiveUpdate()
  371. {
  372. $aParams = $this->_prepareParamsGet();
  373. $sKey = $this->_oConfig->getLiveUpdateKey($aParams);
  374. bx_import('BxDolSession');
  375. BxDolSession::getInstance()->unsetValue($sKey);
  376. }
  377. public function actionPauseLiveUpdate()
  378. {
  379. $aParams = $this->_prepareParamsGet();
  380. $sKey = $this->_oConfig->getLiveUpdateKey($aParams);
  381. bx_import('BxDolSession');
  382. BxDolSession::getInstance()->setValue($sKey, 1);
  383. }
  384. function actionRss()
  385. {
  386. $CNF = &$this->_oConfig->CNF;
  387. $aArgs = func_get_args();
  388. $sType = array_shift($aArgs);
  389. $iOwnerId = 0;
  390. switch($sType) {
  391. case BX_BASE_MOD_NTFS_TYPE_OWNER:
  392. $iOwnerId = array_shift($aArgs);
  393. list($sUserName) = $this->getUserInfo($iOwnerId);
  394. $sRssCaption = _t('_bx_timeline_txt_rss_caption', $sUserName);
  395. $sRssLink = $this->_oConfig->getViewUrl($iOwnerId);
  396. break;
  397. case BX_BASE_MOD_NTFS_TYPE_PUBLIC:
  398. $sRssCaption = _t('_bx_timeline_page_title_view_home');
  399. $sRssLink = $this->_oConfig->getHomeViewUrl();
  400. break;
  401. }
  402. $aParams = $this->_prepareParams(array(
  403. 'view' => BX_TIMELINE_VIEW_DEFAULT,
  404. 'type' => $sType,
  405. 'owner_id' => $iOwnerId,
  406. 'start' => 0,
  407. 'per_page' => $this->_oConfig->getRssLength(),
  408. 'timeline' => 0,
  409. 'filter' => '',
  410. 'modules' => array()
  411. ));
  412. $aEvents = $this->_oDb->getEvents($aParams);
  413. $oPrivacy = BxDolPrivacy::getObjectInstance($this->_oConfig->getObject('privacy_view'));
  414. $aRssData = array();
  415. foreach($aEvents as $aEvent) {
  416. if(empty($aEvent['title']))
  417. continue;
  418. $iEventId = (int)$aEvent[$CNF['FIELD_ID']];
  419. $sEventFieldAuthor = $this->_oConfig->isSystem($aEvent['type'], $aEvent['action']) ? 'owner_id' : 'object_id';
  420. if($oPrivacy) {
  421. $oPrivacy->setTableFieldAuthor($sEventFieldAuthor);
  422. if(!$oPrivacy->check($iEventId))
  423. continue;
  424. }
  425. $iOwner = $aEvent[$sEventFieldAuthor];
  426. $oOwner = BxDolProfile::getInstanceMagic($iOwner);
  427. $aRssData[$iEventId] = array(
  428. 'UnitID' => $iEventId,
  429. 'UnitTitle' => $aEvent['title'],
  430. 'UnitLink' => $this->_oConfig->getItemViewUrl($aEvent),
  431. 'UnitDesc' => bx_replace_markers($aEvent['description'], array(
  432. 'profile_name' => $oOwner->getDisplayName()
  433. )),
  434. 'UnitDateTimeUTS' => $aEvent['date'],
  435. );
  436. }
  437. $oRss = new BxDolRssFactory();
  438. header('Content-Type: application/xml; charset=utf-8');
  439. echo $oRss->GenRssByData($aRssData, $sRssCaption, $sRssLink);
  440. }
  441. /**
  442. * SERVICE METHODS
  443. */
  444. public function serviceGetSafeServices()
  445. {
  446. $a = parent::serviceGetSafeServices();
  447. return array_merge($a, array (
  448. 'GetCreatePostForm' => '',
  449. 'GetSearchResultUnit' => '',
  450. 'GetBlockPost' => '',
  451. 'GetBlockPostProfile' => '',
  452. 'GetBlockPostHome' => '',
  453. 'GetBlockPostAccount' => '',
  454. 'GetBlockView' => '',
  455. 'GetBlockViewOutline' => '',
  456. 'GetBlockViewProfile' => '',
  457. 'GetBlockViewProfileOutline' => '',
  458. 'GetBlockViewsTimeline' => '',
  459. 'GetBlockViewsOutline' => '',
  460. 'GetBlockViewHome' => '',
  461. 'GetBlockViewHomeOutline' => '',
  462. 'GetBlockViewHot' => '',
  463. 'GetBlockViewHotOutline' => '',
  464. 'GetBlockViewAccount' => '',
  465. 'GetBlockViewAccountOutline' => '',
  466. ));
  467. }
  468. /**
  469. * @page service Service Calls
  470. * @section bx_timeline Timeline
  471. * @subsection bx_timeline-other Other
  472. * @subsubsection bx_timeline-get_content_owner_profile_id get_content_owner_profile_id
  473. *
  474. * @code bx_srv('bx_timeline', 'get_content_owner_profile_id', [...]); @endcode
  475. *
  476. * Get event's owner profile id.
  477. *
  478. * @param $mixedEvent integer value with event ID or an array with event info.
  479. * @return event's owner profile id.
  480. *
  481. * @see BxTimelineModule::serviceGetContentOwnerProfileId
  482. */
  483. /**
  484. * @ref bx_timeline-get_content_owner_profile_id "get_content_owner_profile_id"
  485. */
  486. public function serviceGetContentOwnerProfileId($mixedEvent)
  487. {
  488. $CNF = &$this->_oConfig->CNF;
  489. $iProfile = (int)bx_get_logged_profile_id();
  490. if(empty($mixedEvent))
  491. return $iProfile;
  492. if(!is_array($mixedEvent))
  493. $mixedEvent = $this->_oDb->getContentInfoById((int)$mixedEvent);
  494. if(empty($mixedEvent) || !is_array($mixedEvent) || !isset($mixedEvent[$CNF['FIELD_SYSTEM']]))
  495. return $iProfile;
  496. if((int)$mixedEvent[$CNF['FIELD_SYSTEM']] == 0)
  497. return (int)$mixedEvent[$CNF['FIELD_OBJECT_ID']];
  498. if(!empty($mixedEvent['object_owner_id']))
  499. return (int)$mixedEvent['object_owner_id'];
  500. if(!empty($mixedEvent['content'])) {
  501. $aContent = unserialize($mixedEvent['content']);
  502. if(!empty($aContent) && is_array($aContent) && !empty($aContent['object_author_id']))
  503. return (int)$aContent['object_author_id'];
  504. }
  505. $aEventData = $this->_oTemplate->getData($mixedEvent);
  506. if(!empty($aEventData) && is_array($aEventData) && !empty($aEventData['object_owner_id']))
  507. return (int)$aEventData['object_owner_id'];
  508. return $iProfile;
  509. }
  510. /**
  511. * @page service Service Calls
  512. * @section bx_timeline Timeline
  513. * @subsection bx_timeline-other Other
  514. * @subsubsection bx_timeline-get_create_post_form get_create_post_form
  515. *
  516. * @code bx_srv('bx_timeline', 'get_create_post_form', [...]); @endcode
  517. *
  518. * Get form code for add content. Is needed for United Post Form.
  519. *
  520. * @param $aParams optional array with parameters(display name, etc)
  521. * @return form code or error
  522. *
  523. * @see BxTimelineModule::serviceGetCreatePostForm
  524. */
  525. /**
  526. * @ref bx_timeline-get_create_post_form "get_create_post_form"
  527. */
  528. public function serviceGetCreatePostForm($aParams = array())
  529. {
  530. $aParams = array_merge($this->_aFormParams, $aParams);
  531. $bContext = $aParams['context_id'] !== false;
  532. $this->_iOwnerId = $bContext ? abs($aParams['context_id']) : 0;
  533. $oForm = $this->serviceGetObjectForm('add', $aParams);
  534. if(!$oForm)
  535. return '';
  536. $aParams['type'] = BX_BASE_MOD_NTFS_TYPE_PUBLIC;
  537. $aParams['form_display'] = 'form_display_post_add_public';
  538. if($bContext) {
  539. if($aParams['context_id'] < 0) {
  540. $aParams['type'] = BX_BASE_MOD_NTFS_TYPE_OWNER;
  541. $aParams['form_display'] = 'form_display_post_add_profile';
  542. }
  543. else {
  544. $aParams['type'] = BX_TIMELINE_TYPE_FEED;
  545. $aParams['form_display'] = 'form_display_post_add';
  546. }
  547. }
  548. if(!empty($aParams['display']))
  549. $aParams['form_display'] = $aParams['display'];
  550. $aResult = $this->getFormPost($aParams);
  551. if(!empty($aResult['form'])) {
  552. $bDynamicMode = isset($aParams['dynamic_mode']) && $aParams['dynamic_mode'];
  553. $sCode = '';
  554. $sCode .= $this->_oTemplate->getJsCodePost($this->_iOwnerId, $aParams, true, $bDynamicMode);
  555. $sCode .= $aResult['form'];
  556. return $sCode;
  557. }
  558. if(!empty($aResult['message']))
  559. return $aResult['message'];
  560. return '';
  561. }
  562. /**
  563. * @page service Service Calls
  564. * @section bx_timeline Timeline
  565. * @subsection bx_timeline-other Other
  566. * @subsubsection bx_timeline-get_object_form get_object_form
  567. *
  568. * @code bx_srv('bx_timeline', 'get_object_form', [...]); @endcode
  569. *
  570. * Get form object for add, edit, view or delete the content.
  571. *
  572. * @param $sType 'add' is supported only
  573. * @param $aParams optional array with parameters(display name, etc)
  574. * @return form object or false on error
  575. *
  576. * @see BxTimelineModule::serviceGetObjectForm
  577. */
  578. /**
  579. * @ref bx_timeline-get_object_form "get_object_form"
  580. */
  581. public function serviceGetObjectForm ($sType, $aParams = array())
  582. {
  583. if(!in_array($sType, array('add')))
  584. return false;
  585. $bContext = $aParams['context_id'] !== false;
  586. if($bContext && ($oContextProfile = BxDolProfile::getInstance(abs($aParams['context_id']))) !== false)
  587. if($oContextProfile->checkAllowedPostInProfile() !== CHECK_ACTION_RESULT_ALLOWED)
  588. return false;
  589. $aParams['type'] = BX_BASE_MOD_NTFS_TYPE_PUBLIC;
  590. $aParams['form_display'] = 'form_display_post_add_public';
  591. if($bContext) {
  592. if($aParams['context_id'] < 0) {
  593. $aParams['type'] = BX_BASE_MOD_NTFS_TYPE_OWNER;
  594. $aParams['form_display'] = 'form_display_post_add_profile';
  595. }
  596. else {
  597. $aParams['type'] = BX_TIMELINE_TYPE_OWNER_AND_CONNECTIONS;
  598. $aParams['form_display'] = 'form_display_post_add';
  599. }
  600. }
  601. if(!empty($aParams['display']))
  602. $aParams['form_display'] = $aParams['display'];
  603. $oForm = $this->getFormPostObject($aParams);
  604. bx_alert('system', 'get_object_form', 0, 0, array(
  605. 'module' => $this->_oConfig->getName(),
  606. 'type' => $sType,
  607. 'params' => $aParams,
  608. 'form' => &$oForm
  609. ));
  610. return $oForm;
  611. }
  612. /**
  613. * @page service Service Calls
  614. * @section bx_timeline Timeline
  615. * @subsection get_timeline_post
  616. * @see BxTimelineModule::serviceGetTimelinePost
  617. *
  618. * Get Timeline post. It's needed for Timeline module.
  619. *
  620. * @param $aEvent timeline event array from Timeline module
  621. * @return array in special format which is needed specifically for Timeline module to display the data.
  622. */
  623. public function serviceGetTimelinePost($aEvent, $aBrowseParams = array())
  624. {
  625. $aContentInfo = $this->_oDb->getContentInfoById($aEvent['object_id']);
  626. if(empty($aContentInfo) || !is_array($aContentInfo))
  627. return false;
  628. $aEvent = array_merge($aEvent, array(
  629. 'owner_id' => $aContentInfo['owner_id'],
  630. 'object_privacy_view' => $aContentInfo['object_privacy_view']
  631. ));
  632. /*
  633. * Note. For 'Direct Timeline Posts' FIELD_OBJECT_ID contains post's author profile ID.
  634. */
  635. $this->_oConfig->CNF['FIELD_AUTHOR'] = $this->_oConfig->CNF['FIELD_OBJECT_ID'];
  636. return parent::serviceGetTimelinePost($aEvent, $aBrowseParams);
  637. }
  638. /**
  639. * @page service Service Calls
  640. * @section bx_timeline Timeline
  641. * @subsection get_timeline_post
  642. * @see BxTimelineModule::serviceGetTimelinePostAllowedView
  643. *
  644. * Check Timeline post's visibility. It's needed for Timeline module, when its events
  645. * are accessed and checked from outside. For example, when they are referenced
  646. * from Channels module.
  647. *
  648. * @param $aEvent timeline event array from Timeline module
  649. * @return mixed value: CHECK_ACTION_RESULT_ALLOWED or text of some error message.
  650. */
  651. public function serviceGetTimelinePostAllowedView($aEvent)
  652. {
  653. $CNF = &$this->_oConfig->CNF;
  654. $iOwnerId = (int)$aEvent[$CNF['FIELD_OWNER_ID']];
  655. if($iOwnerId == 0)
  656. return CHECK_ACTION_RESULT_ALLOWED;
  657. $oOwner = BxDolProfile::getInstance($iOwnerId);
  658. if(!$oOwner)
  659. return CHECK_ACTION_RESULT_ALLOWED;
  660. $sModule = $oOwner->getModule();
  661. $aOwnerInfo = BxDolService::call($sModule, 'get_info', array($oOwner->getContentId(), false));
  662. if(empty($aOwnerInfo) || !is_array($aOwnerInfo))
  663. return CHECK_ACTION_RESULT_ALLOWED;
  664. return BxDolService::call($sModule, 'check_allowed_view_for_profile', array($aOwnerInfo));
  665. }
  666. /**
  667. * @page service Service Calls
  668. * @section bx_timeline Timeline
  669. * @subsection bx_timeline-other Other
  670. * @subsubsection bx_timeline-get_author get_author
  671. *
  672. * @code bx_srv('bx_timeline', 'get_author', [...]); @endcode
  673. *
  674. * Get author ID from content info by content ID. Is used in "Content Info Objects" system.
  675. *
  676. * @param $iContentId integer value with content ID.
  677. * @return integer value with author ID.
  678. *
  679. * @see BxTimelineModule::serviceGetAuthor
  680. */
  681. /**
  682. * @ref bx_timeline-get_author "get_author"
  683. */
  684. public function serviceGetAuthor ($iContentId)
  685. {
  686. $aEvent = $this->_oDb->getEvents(array('browse' => 'id', 'value' => $iContentId));
  687. if(empty($aEvent) || !is_array($aEvent))
  688. return 0;
  689. return $this->_oConfig->isSystem($aEvent['type'], $aEvent['action']) ? (int)$aEvent['owner_id'] : (int)$aEvent['object_id'];
  690. }
  691. /**
  692. * @page service Service Calls
  693. * @section bx_timeline Timeline
  694. * @subsection bx_timeline-other Other
  695. * @subsubsection bx_timeline-get_date_changed get_date_changed
  696. *
  697. * @code bx_srv('bx_timeline', 'get_date_changed', [...]); @endcode
  698. *
  699. * Get date when the content was changed last time. Is used in "Content Info Objects" system.
  700. * Note. In case of Timeline event 0 is returned everytime.
  701. *
  702. * @param $iContentId integer value with content ID.
  703. * @return integer value with changing date.
  704. *
  705. * @see BxTimelineModule::serviceGetDateChanged
  706. */
  707. /**
  708. * @ref bx_timeline-get_date_changed "get_date_changed"
  709. */
  710. public function serviceGetDateChanged ($iContentId)
  711. {
  712. return 0;
  713. }
  714. /**
  715. * @page service Service Calls
  716. * @section bx_timeline Timeline
  717. * @subsection bx_timeline-other Other
  718. * @subsubsection bx_timeline-get_link get_link
  719. *
  720. * @code bx_srv('bx_timeline', 'get_link', [...]); @endcode
  721. *
  722. * Get content view page link. Is used in "Content Info Objects" system.
  723. *
  724. * @param $iContentId integer value with content ID.
  725. * @return string value with view page link.
  726. *
  727. * @see BxTimelineModule::serviceGetLink
  728. */
  729. /**
  730. * @ref bx_timeline-get_link "get_link"
  731. */
  732. public function serviceGetLink ($iContentId)
  733. {
  734. $aEvent = $this->_oDb->getEvents(array('browse' => 'id', 'value' => $iContentId));
  735. if(empty($aEvent) || !is_array($aEvent))
  736. return '';
  737. return $this->_oConfig->getItemViewUrl($aEvent);
  738. }
  739. /**
  740. * @page service Service Calls
  741. * @section bx_timeline Timeline
  742. * @subsection bx_timeline-other Other
  743. * @subsubsection bx_timeline-get_thumb get_thumb
  744. *
  745. * @code bx_srv('bx_timeline', 'get_thumb', [...]); @endcode
  746. *
  747. * Get content thumbnail link. Is used in "Content Info Objects" system.
  748. * Note. In case of Timeline event an empty string is returned everytime.
  749. *
  750. * @param $iContentId integer value with content ID.
  751. * @param $sTranscoder (optional) string value with transcoder name which should be applied to thumbnail image.
  752. * @return string value with thumbnail link.
  753. *
  754. * @see BxTimelineModule::serviceGetThumb
  755. */
  756. /**
  757. * @ref bx_timeline-get_thumb "get_thumb"
  758. */
  759. public function serviceGetThumb ($iContentId, $sTranscoder = '')
  760. {
  761. return '';
  762. }
  763. /**
  764. * @page service Service Calls
  765. * @section bx_timeline Timeline
  766. * @subsection bx_timeline-other Other
  767. * @subsubsection bx_timeline-get_info get_info
  768. *
  769. * @code bx_srv('bx_timeline', 'get_info', [...]); @endcode
  770. *
  771. * Get content info by content ID. Is used in "Content Info Objects" system.
  772. *
  773. * @param $iContentId integer value with content ID.
  774. * @param $bSearchableFieldsOnly (optional) boolean value determining all info or "searchable fields" only will be returned.
  775. * @return an array with content info. Empty array is returned if something is wrong.
  776. *
  777. * @see BxTimelineModule::serviceGetInfo
  778. */
  779. /**
  780. * @ref bx_timeline-get_info "get_info"
  781. */
  782. public function serviceGetInfo ($iContentId, $bSearchableFieldsOnly = true)
  783. {
  784. $aContentInfo = $this->_oDb->getEvents(array(
  785. 'browse' => 'id',
  786. 'value' => $iContentId)
  787. );
  788. return BxDolContentInfo::formatFields($aContentInfo);
  789. }
  790. /**
  791. * @page service Service Calls
  792. * @section bx_timeline Timeline
  793. * @subsection bx_timeline-other Other
  794. * @subsubsection bx_timeline-get_search_result_unit get_search_result_unit
  795. *
  796. * @code bx_srv('bx_timeline', 'get_search_result_unit', [...]); @endcode
  797. *
  798. * Get search result unit by content ID. Is used in "Content Info Objects" system.
  799. *
  800. * @param $iContentId integer value with content ID.
  801. * @param $sUnitTemplate (optional) string value with template name.
  802. * @return HTML string with search result unit. Empty string is returned if something is wrong.
  803. *
  804. * @see BxTimelineModule::serviceGetSearchResultUnit
  805. */
  806. /**
  807. * @ref bx_timeline-get_search_result_unit "get_search_result_unit"
  808. */
  809. public function serviceGetSearchResultUnit ($iContentId, $sUnitTemplate = '')
  810. {
  811. $aEvent = $this->_oDb->getEvents(array('browse' => 'id', 'value' => $iContentId));
  812. if(empty($aEvent) || !is_array($aEvent))
  813. return '';
  814. if(empty($sUnitTemplate))
  815. $sUnitTemplate = 'unit.html';
  816. return $this->_oTemplate->unit($aEvent, true, $sUnitTemplate);
  817. }
  818. /**
  819. * @page service Service Calls
  820. * @section bx_timeline Timeline
  821. * @subsection bx_timeline-page_blocks Page Blocks
  822. * @subsubsection bx_timeline-get_block_post get_block_post
  823. *
  824. * @code bx_srv('bx_timeline', 'get_block_post', [...]); @endcode
  825. *
  826. * Get Post block for a separate page.
  827. *
  828. * @param $iProfileId (optional) profile ID. If empty value is provided, an attempt to get it from GET/POST arrays will be performed.
  829. * @return an array describing a block to display on the site. All necessary CSS and JS files are automatically added to the HEAD section of the site HTML.
  830. *
  831. * @see BxTimelineModule::serviceGetBlockPost
  832. */
  833. /**
  834. * @ref bx_timeline-get_block_post "get_block_post"
  835. */
  836. public function serviceGetBlockPost($iProfileId = 0)
  837. {
  838. if(empty($iProfileId) && bx_get('profile_id') !== false)
  839. $iProfileId = bx_process_input(bx_get('profile_id'), BX_DATA_INT);
  840. if(empty($iProfileId) && isLogged())
  841. $iProfileId = bx_get_logged_profile_id();
  842. if(!$iProfileId)
  843. return array();
  844. $sType = BX_BASE_MOD_NTFS_TYPE_OWNER;
  845. return $this->_getBlockPost($iProfileId, array(
  846. 'type' => $sType,
  847. 'form_display' => $this->_oConfig->getPostFormDisplay($sType)
  848. ));
  849. }
  850. /**
  851. * @page service Service Calls
  852. * @section bx_timeline Timeline
  853. * @subsection bx_timeline-page_blocks Page Blocks
  854. * @subsubsection bx_timeline-get_block_post_profile get_block_post_profile
  855. *
  856. * @code bx_srv('bx_timeline', 'get_block_post_profile', [...]); @endcode
  857. *
  858. * Get Post block for the Profile page.
  859. *
  860. * @param $sProfileModule (optional) string value with profile based module name. Persons module is used by default.
  861. * @param $iProfileContentId (optional) profile's content ID. If empty value is provided, an attempt to get it from GET/POST arrays will be performed.
  862. * @return an array describing a block to display on the site. All necessary CSS and JS files are automatically added to the HEAD section of the site HTML.
  863. *
  864. * @see BxTimelineModule::serviceGetBlockPostProfile
  865. */
  866. /**
  867. * @ref bx_timeline-get_block_post_profile "get_block_post_profile"
  868. */
  869. public function serviceGetBlockPostProfile($sProfileModule = 'bx_persons', $iProfileContentId = 0)
  870. {
  871. if(empty($sProfileModule))
  872. return array();
  873. if(empty($iProfileContentId) && bx_get('id') !== false)
  874. $iProfileContentId = bx_process_input(bx_get('id'), BX_DATA_INT);
  875. $oProfile = BxDolProfile::getInstanceByContentAndType($iProfileContentId, $sProfileModule);
  876. if(empty($oProfile))
  877. return array();
  878. $iProfileId = $oProfile->id();
  879. $sType = BX_BASE_MOD_NTFS_TYPE_OWNER;
  880. return $this->_getBlockPost($iProfileId, array(
  881. 'type' => $sType,
  882. 'form_display' => $this->_oConfig->getPostFormDisplay($sType)
  883. ));
  884. }
  885. /**
  886. * @page service Service Calls
  887. * @section bx_timeline Timeline
  888. * @subsection bx_timeline-page_blocks Page Blocks
  889. * @subsubsection bx_timeline-get_block_post_home get_block_post_home
  890. *
  891. * @code bx_srv('bx_timeline', 'get_block_post_home', [...]); @endcode
  892. *
  893. * Get Post block for site's Home page.
  894. *
  895. * @return an array describing a block to display on the site. All necessary CSS and JS files are automatically added to the HEAD section of the site HTML.
  896. *
  897. * @see BxTimelineModule::serviceGetBlockPostHome
  898. */
  899. /**
  900. * @ref bx_timeline-get_block_post_home "get_block_post_home"
  901. */
  902. public function serviceGetBlockPostHome()
  903. {
  904. $iProfileId = 0;
  905. $sType = BX_BASE_MOD_NTFS_TYPE_PUBLIC;
  906. return $this->_getBlockPost($iProfileId, array(
  907. 'type' => $sType,
  908. 'form_display' => $this->_oConfig->getPostFormDisplay($sType)
  909. ));
  910. }
  911. /**
  912. * @page service Service Calls
  913. * @section bx_timeline Timeline
  914. * @subsection bx_timeline-page_blocks Page Blocks
  915. * @subsubsection bx_timeline-get_block_post_account get_block_post_account
  916. *
  917. * @code bx_srv('bx_timeline', 'get_block_post_account', [...]); @endcode
  918. *
  919. * Get Post block for the Dashboard page.
  920. *
  921. * @return an array describing a block to display on the site. All necessary CSS and JS files are automatically added to the HEAD section of the site HTML.
  922. *
  923. * @see BxTimelineModule::serviceGetBlockPostAccount
  924. */
  925. /**
  926. * @ref bx_timeline-get_block_post_account "get_block_post_account"
  927. */
  928. public function serviceGetBlockPostAccount()
  929. {
  930. if(!isLogged())
  931. return '';
  932. $iProfileId = $this->getProfileId();
  933. $sType = BX_TIMELINE_TYPE_FEED;
  934. return $this->_getBlockPost($iProfileId, array(
  935. 'type' => $sType,
  936. 'form_display' => $this->_oConfig->getPostFormDisplay($sType)
  937. ));
  938. }
  939. /**
  940. * @page service Service Calls
  941. * @section bx_timeline Timeline
  942. * @subsection bx_timeline-page_blocks Page Blocks
  943. * @subsubsection bx_timeline-get_block_view get_block_view
  944. *
  945. * @code bx_srv('bx_timeline', 'get_block_view', [...]); @endcode
  946. *
  947. * Get Timeline View block for a separate page.
  948. *
  949. * @param $iProfileId (optional) profile ID. If empty value is provided, an attempt to get it from GET/POST arrays will be performed.
  950. * @return an array describing a block to display on the site. All necessary CSS and JS files are automatically added to the HEAD section of the site HTML.
  951. *
  952. * @see BxTimelineModule::serviceGetBlockView
  953. */
  954. /**
  955. * @ref bx_timeline-get_block_view "get_block_view"
  956. */
  957. public function serviceGetBlockView($iProfileId = 0)
  958. {
  959. return $this->_serviceGetBlockView($iProfileId, array(
  960. 'view' => BX_TIMELINE_VIEW_TIMELINE,
  961. 'type' => BX_BASE_MOD_NTFS_TYPE_OWNER,
  962. 'start' => -1,
  963. 'per_page' => -1,
  964. 'per_page_default' => $this->_oConfig->getPerPage('profile'),
  965. 'timeline' => -1,
  966. 'filter' => '',
  967. 'modules' => array()
  968. ));
  969. }
  970. /**
  971. * @page service Service Calls
  972. * @section bx_timeline Timeline
  973. * @subsection bx_timeline-page_blocks Page Blocks
  974. * @subsubsection bx_timeline-get_block_view_outline get_block_view_outline
  975. *
  976. * @code bx_srv('bx_timeline', 'get_block_view_outline', [...]); @endcode
  977. *
  978. * Get Outline View block for a separate page.
  979. *
  980. * @param $iProfileId (optional) profile ID. If empty value is provided, an attempt to get it from GET/POST arrays will be performed.
  981. * @return an array describing a block to display on the site. All necessary CSS and JS files are automatically added to the HEAD section of the site HTML.
  982. *
  983. * @see BxTimelineModule::serviceGetBlockViewOutline
  984. */
  985. /**
  986. * @ref bx_timeline-get_block_view_outline "get_block_view_outline"
  987. */
  988. public function serviceGetBlockViewOutline($iProfileId = 0)
  989. {
  990. return $this->_serviceGetBlockView($iProfileId, array(
  991. 'view' => BX_TIMELINE_VIEW_OUTLINE,
  992. 'type' => BX_BASE_MOD_NTFS_TYPE_OWNER,
  993. 'start' => -1,
  994. 'per_page' => -1,
  995. 'per_page_default' => $this->_oConfig->getPerPage('profile'),
  996. 'timeline' => -1,
  997. 'filter' => '',
  998. 'modules' => array()
  999. ));
  1000. }
  1001. /**
  1002. * @page service Service Calls
  1003. * @section bx_timeline Timeline
  1004. * @subsection bx_timeline-page_blocks Page Blocks
  1005. * @subsubsection bx_timeline-get_block_view_profile get_block_view_profile
  1006. *
  1007. * @code bx_srv('bx_timeline', 'get_block_view_profile', [...]); @endcode
  1008. *
  1009. * Get Timeline View block for the Profile page.
  1010. *
  1011. * @param $sProfileModule (optional) string value with profile based module name. Persons module is used by default.
  1012. * @param $iProfileContentId (optional) profile's content ID. If empty value is provided, an attempt to get it from GET/POST arrays will be performed.
  1013. * @param $iStart (optional) integer value with a page number. Is used in pagination.
  1014. * @param $iPerPage (optional) integer value with a number of items per page. Is used in pagination.
  1015. * @param $sFilter (optional) string value with filter name.
  1016. * @param $aModules (optional) an array of modules from which the events should be displayed. All available modules are used by default.
  1017. * @param $iTimeline (optional) integer value determining whether the timeline should be displayed or not.
  1018. * @return an array describing a block to display on the site. All necessary CSS and JS files are automatically added to the HEAD section of the site HTML.
  1019. *
  1020. * @see BxTimelineModule::serviceGetBlockViewProfile
  1021. */
  1022. /**
  1023. * @ref bx_timeline-get_block_view_profile "get_block_view_profile"
  1024. */
  1025. public function serviceGetBlockViewProfile($sProfileModule = 'bx_persons', $iProfileContentId = 0, $iStart = -1, $iPerPage = -1, $sFilter = '', $aModules = array(), $iTimeline = -1)
  1026. {
  1027. return $this->_serviceGetBlockViewProfile($sProfileModule, $iProfileContentId, array(
  1028. 'view' => BX_TIMELINE_VIEW_TIMELINE,
  1029. 'type' => BX_BASE_MOD_NTFS_TYPE_OWNER,
  1030. 'start' => $iStart,
  1031. 'per_page' => $iPerPage,
  1032. 'per_page_default' => $this->_oConfig->getPerPage('profile'),
  1033. 'timeline' => $iTimeline,
  1034. 'filter' => $sFilter,
  1035. 'modules' => $aModules
  1036. ));
  1037. }
  1038. /**
  1039. * @page service Service Calls
  1040. * @section bx_timeline Timeline
  1041. * @subsection bx_timeline-page_blocks Page Blocks
  1042. * @subsubsection bx_timeline-get_block_view_profile_outline get_block_view_profile_outline
  1043. *
  1044. * @code bx_srv('bx_timeline', 'get_block_view_profile_outline', [...]); @endcode
  1045. *
  1046. * Get Outline View block for the Profile page.
  1047. *
  1048. * @param $sProfileModule (optional) string value with profile based module name. Persons module is used by default.
  1049. * @param $iProfileContentId (optional) profile's content ID. If empty value is provided, an attempt to get it from GET/POST arrays will be performed.
  1050. * @param $iStart (optional) integer value with a page number. Is used in pagination.
  1051. * @param $iPerPage (optional) integer value with a number of items per page. Is used in pagination.
  1052. * @param $sFilter (optional) string value with filter name.
  1053. * @param $aModules (optional) an array of modules from which the events should be displayed. All available modules are used by default.
  1054. * @param $iTimeline (optional) integer value determining whether the timeline should be displayed or not.
  1055. * @return an array describing a block to display on the site. All necessary CSS and JS files are automatically added to the HEAD section of the site HTML.
  1056. *
  1057. * @see BxTimelineModule::serviceGetBlockViewProfileOutline
  1058. */
  1059. /**
  1060. * @ref bx_timeline-get_block_view_profile_outline "get_block_view_profile_outline"
  1061. */
  1062. public function serviceGetBlockViewProfileOutline($sProfileModule = 'bx_persons', $iProfileContentId = 0, $iStart = -1, $iPerPage = -1, $sFilter = '', $aModules = array(), $iTimeline = -1)
  1063. {
  1064. return $this->_serviceGetBlockViewProfile($sProfileModule, $iProfileContentId, array(
  1065. 'view' => BX_TIMELINE_VIEW_OUTLINE,
  1066. 'type' => BX_BASE_MOD_NTFS_TYPE_OWNER,
  1067. 'start' => $iStart,
  1068. 'per_page' => $iPerPage,
  1069. 'per_page_default' => $this->_oConfig->getPerPage('profile'),
  1070. 'timeline' => $iTimeline,
  1071. 'filter' => $sFilter,
  1072. 'modules' => $aModules
  1073. ));
  1074. }
  1075. public function serviceGetBlockViewsTimeline($sType = BX_BASE_MOD_NTFS_TYPE_PUBLIC, $iProfileId = 0, $iStart = -1, $iPerPage = -1, $iTimeline = -1, $sFilter = '', $aModules = array())
  1076. {
  1077. return $this->_serviceGetBlockViews(array(
  1078. 'view' => BX_TIMELINE_VIEW_TIMELINE,
  1079. 'type' => $sType,
  1080. 'owner_id' => $iProfileId,
  1081. 'start' => $iStart,
  1082. 'per_page' => $iPerPage,
  1083. 'per_page_default' => $this->_oConfig->getPerPage(),
  1084. 'timeline' => $iTimeline,
  1085. 'filter' => $sFilter,
  1086. 'modules' => $aModules
  1087. ));
  1088. }
  1089. public function serviceGetBlockViewsOutline($sType = BX_BASE_MOD_NTFS_TYPE_PUBLIC, $iProfileId = 0, $iStart = -1, $iPerPage = -1, $iTimeline = -1, $sFilter = '', $aModules = array())
  1090. {
  1091. return $this->_serviceGetBlockViews(array(
  1092. 'view' => BX_TIMELINE_VIEW_OUTLINE,
  1093. 'type' => $sType,
  1094. 'owner_id' => $iProfileId,
  1095. 'start' => $iStart,
  1096. 'per_page' => $iPerPage,
  1097. 'per_page_default' => $this->_oConfig->getPerPage(),
  1098. 'timeline' => $iTimeline,
  1099. 'filter' => $sFilter,
  1100. 'modules' => $aModules
  1101. ));
  1102. }
  1103. /**
  1104. * @page service Service Calls
  1105. * @section bx_timeline Timeline
  1106. * @subsection bx_timeline-page_blocks Page Blocks
  1107. * @subsubsection bx_timeline-get_block_view_home get_block_view_home
  1108. *
  1109. * @code bx_srv('bx_timeline', 'get_block_view_home', [...]); @endcode
  1110. *
  1111. * Get Timeline View block for site's Home page.
  1112. *
  1113. * @param $iProfileId (optional) profile ID. 0 should be used here.
  1114. * @param $iStart (optional) integer value with a page number. Is used in pagination.
  1115. * @param $iPerPage (optional) integer value with a number of items per page. Is used in pagination.
  1116. * @param $iTimeline (optional) integer value determining whether the timeline should be displayed or not.
  1117. * @param $sFilter (optional) string value with filter name.
  1118. * @param $aModules (optional) an array of modules from which the events should be displayed. All available modules are used by default.
  1119. * @return an array describing a block to display on the site. All necessary CSS and JS files are automatically added to the HEAD section of the site HTML.
  1120. *
  1121. * @see BxTimelineModule::serviceGetBlockViewHome
  1122. */
  1123. /**
  1124. * @ref bx_timeline-get_block_view_home "get_block_view_home"
  1125. */
  1126. public function serviceGetBlockViewHome($iProfileId = 0, $iStart = -1, $iPerPage = -1, $iTimeline = -1, $sFilter = '', $aModules = array())
  1127. {
  1128. return $this->_serviceGetBlockViewHome(array(
  1129. 'view' => BX_TIMELINE_VIEW_TIMELINE,
  1130. 'type' => BX_BASE_MOD_NTFS_TYPE_PUBLIC,
  1131. 'owner_id' => $iProfileId,
  1132. 'start' => $iStart,
  1133. 'per_page' => $iPerPage,
  1134. 'per_page_default' => $this->_oConfig->getPerPage('home'),
  1135. 'timeline' => $iTimeline,
  1136. 'filter' => $sFilter,
  1137. 'modules' => $aModules
  1138. ));
  1139. }
  1140. /**
  1141. * @page service Service Calls
  1142. * @section bx_timeline Timeline
  1143. * @subsection bx_timeline-page_blocks Page Blocks
  1144. * @subsubsection bx_timeline-get_block_view_home_outline get_block_view_home_outline
  1145. *
  1146. * @code bx_srv('bx_timeline', 'get_block_view_home_outline', [...]); @endcode
  1147. *
  1148. * Get Outline View block for site's Home page.
  1149. *
  1150. * @param $iProfileId (optional) profile ID. 0 should be used here.
  1151. * @param $iStart (optional) integer value with a page number. Is used in pagination.
  1152. * @param $iPerPage (optional) integer value with a number of items per page. Is used in pagination.
  1153. * @param $iTimeline (optional) integer value determining whether the timeline should be displayed or not.
  1154. * @param $sFilter (optional) string value with filter name.
  1155. * @param $aModules (optional) an array of modules from which the events should be displayed. All available modules are used by default.
  1156. * @return an array describing a block to display on the site. All necessary CSS and JS files are automatically added to the HEAD section of the site HTML.
  1157. *
  1158. * @see BxTimelineModule::serviceGetBlockViewHomeOutline
  1159. */
  1160. /**
  1161. * @ref bx_timeline-get_block_view_home_outline "get_block_view_home_outline"
  1162. */
  1163. public function serviceGetBlockViewHomeOutline($iProfileId = 0, $iStart = -1, $iPerPage = -1, $iTimeline = -1, $sFilter = '', $aModules = array())
  1164. {
  1165. return $this->_serviceGetBlockViewHome(array(
  1166. 'view' => BX_TIMELINE_VIEW_OUTLINE,
  1167. 'type' => BX_BASE_MOD_NTFS_TYPE_PUBLIC,
  1168. 'owner_id' => $iProfileId,
  1169. 'start' => $iStart,
  1170. 'per_page' => $iPerPage,
  1171. 'per_page_default' => $this->_oConfig->getPerPage('home'),
  1172. 'timeline' => $iTimeline,
  1173. 'filter' => $sFilter,
  1174. 'modules' => $aModules
  1175. ));
  1176. }
  1177. /**
  1178. * @page service Service Calls
  1179. * @section bx_timeline Timeline
  1180. * @subsection bx_timeline-page_blocks Page Blocks
  1181. * @subsubsection bx_timeline-get_block_view_hot get_block_view_hot
  1182. *
  1183. * @code bx_srv('bx_timeline', 'get_block_view_hot', [...]); @endcode
  1184. *
  1185. * Get Timeline View block with Hot public events.
  1186. *
  1187. * @param $iProfileId (optional) profile ID. 0 should be used here.
  1188. * @param $iStart (optional) integer value with a page number. Is used in pagination.
  1189. * @param $iPerPage (optional) integer value with a number of items per page. Is used in pagination.
  1190. * @param $iTimeline (optional) integer value determining whether the timeline should be displayed or not.
  1191. * @param $sFilter (optional) string value with filter name.
  1192. * @param $aModules (optional) an array of modules from which the events should be displayed. All available modules are used by default.
  1193. * @return an array describing a block to display on the site. All necessary CSS and JS files are automatically added to the HEAD section of the site HTML.
  1194. *
  1195. * @see BxTimelineModule::serviceGetBlockViewHot
  1196. */
  1197. /**
  1198. * @ref bx_timeline-get_block_view_hot "get_block_view_hot"
  1199. */
  1200. public function serviceGetBlockViewHot($iProfileId = 0, $iStart = -1, $iPerPage = -1, $iTimeline = -1, $sFilter = '', $aModules = array())
  1201. {
  1202. return $this->_serviceGetBlockViewHot(array(
  1203. 'view' => BX_TIMELINE_VIEW_TIMELINE,
  1204. 'type' => BX_TIMELINE_TYPE_HOT,
  1205. 'owner_id' => $iProfileId,
  1206. 'start' => $iStart,
  1207. 'per_page' => $iPerPage,
  1208. 'per_page_default' => $this->_oConfig->getPerPage('home'),
  1209. 'timeline' => $iTimeline,
  1210. 'filter' => $sFilter,
  1211. 'modules' => $aModules
  1212. ));
  1213. }
  1214. /**
  1215. * @page service Service Calls
  1216. * @section bx_timeline Timeline
  1217. * @subsection bx_timeline-page_blocks Page Blocks
  1218. * @subsubsection bx_timeline-get_block_view_hot_outline get_block_view_hot_outline
  1219. *
  1220. * @code bx_srv('bx_timeline', 'get_block_view_hot_outline', [...]); @endcode
  1221. *
  1222. * Get Outline View block with Hot public events.
  1223. *
  1224. * @param $iProfileId (optional) profile ID. 0 should be used here.
  1225. * @param $iStart (optional) integer value with a page number. Is used in pagination.
  1226. * @param $iPerPage (optional) integer value with a number of items per page. Is used in pagination.
  1227. * @param $iTimeline (optional) integer value determining whether the timeline should be displayed or not.
  1228. * @param $sFilter (optional) string value with filter name.
  1229. * @param $aModules (optional) an array of modules from which the events should be displayed. All available modules are used by default.
  1230. * @return an array describing a block to display on the site. All necessary CSS and JS files are automatically added to the HEAD section of the site HTML.
  1231. *
  1232. * @see BxTimelineModule::serviceGetBlockViewHotOutline
  1233. */
  1234. /**
  1235. * @ref bx_timeline-get_block_view_hot_outline "get_block_view_hot_outline"
  1236. */
  1237. public function serviceGetBlockViewHotOutline($iProfileId = 0, $iStart = -1, $iPerPage = -1, $iTimeline = -1, $sFilter = '', $aModules = array())
  1238. {
  1239. return $this->_serviceGetBlockViewHot(array(
  1240. 'view' => BX_TIMELINE_VIEW_OUTLINE,
  1241. 'type' => BX_TIMELINE_TYPE_HOT,
  1242. 'owner_id' => $iProfileId,
  1243. 'start' => $iStart,
  1244. 'per_page' => $iPerPage,
  1245. 'per_page_default' => $this->_oConfig->getPerPage('home'),
  1246. 'timeline' => $iTimeline,
  1247. 'filter' => $sFilter,
  1248. 'modules' => $aModules
  1249. ));
  1250. }
  1251. /**
  1252. * @page service Service Calls
  1253. * @section bx_timeline Timeline
  1254. * @subsection bx_timeline-page_blocks Page Blocks
  1255. * @subsubsection bx_timeline-get_block_view_account get_block_view_account
  1256. *
  1257. * @code bx_srv('bx_timeline', 'get_block_view_account', [...]); @endcode
  1258. *
  1259. * Get Timeline View block for the Dashboard page.
  1260. *
  1261. * @param $iProfileId (optional) profile ID. 0 should be used here.
  1262. * @param $iStart (optional) integer value with a page number. Is used in pagination.
  1263. * @param $iPerPage (optional) integer value with a number of items per page. Is used in pagination.
  1264. * @param $iTimeline (optional) integer value determining whether the timeline should be displayed or not.
  1265. * @param $sFilter (optional) string value with filter name.
  1266. * @param $aModules (optional) an array of modules from which the events should be displayed. All available modules are used by default.
  1267. * @return an array describing a block to display on the site. All necessary CSS and JS files are automatically added to the HEAD section of the site HTML.
  1268. *
  1269. * @see BxTimelineModule::serviceGetBlockViewAccount
  1270. */
  1271. /**
  1272. * @ref bx_timeline-get_block_view_account "get_block_view_account"
  1273. */
  1274. public function serviceGetBlockViewAccount($iProfileId = 0, $iStart = -1, $iPerPage = -1, $iTimeline = -1, $sFilter = '', $aModules = array())
  1275. {
  1276. if(!isLogged())
  1277. return '';
  1278. return $this->_serviceGetBlockViewByType(array(
  1279. 'view' => BX_TIMELINE_VIEW_TIMELINE,
  1280. 'type' => BX_TIMELINE_TYPE_OWNER_AND_CONNECTIONS,
  1281. 'owner_id' => $iProfileId,
  1282. 'start' => $iStart,
  1283. 'per_page' => $iPerPage,
  1284. 'per_page_default' => $this->_oConfig->getPerPage('account'),
  1285. 'timeline' => $iTimeline,
  1286. 'filter' => $sFilter,
  1287. 'modules' => $aModules
  1288. ));
  1289. }
  1290. /**
  1291. * @page service Service Calls
  1292. * @section bx_timeline Timeline
  1293. * @subsection bx_timeline-page_blocks Page Blocks
  1294. * @subsubsection bx_timeline-get_block_view_account_outline get_block_view_account_outline
  1295. *
  1296. * @code bx_srv('bx_timeline', 'get_block_view_account_outline', [...]); @endcode
  1297. *
  1298. * Get Outline View block for the Dashboard page.
  1299. *
  1300. * @param $iProfileId (optional) profile ID. 0 should be used here.
  1301. * @param $iStart (optional) integer value with a page number. Is used in pagination.
  1302. * @param $iPerPage (optional) integer value with a number of items per page. Is used in pagination.
  1303. * @param $iTimeline (optional) integer value determining whether the timeline should be displayed or not.
  1304. * @param $sFilter (optional) string value with filter name.
  1305. * @param $aModules (optional) an array of modules from which the events should be displayed. All available modules are used by default.
  1306. * @return an array describing a block to display on the site. All necessary CSS and JS files are automatically added to the HEAD section of the site HTML.
  1307. *
  1308. * @see BxTimelineModule::serviceGetBlockViewAccountOutline
  1309. */
  1310. /**
  1311. * @ref bx_timeline-get_block_view_account_outline "get_block_view_account_outline"
  1312. */
  1313. public function serviceGetBlockViewAccountOutline($iProfileId = 0, $iStart = -1, $iPerPage = -1, $iTimeline = -1, $sFilter = '', $aModules = array())
  1314. {
  1315. if(!isLogged())
  1316. return '';
  1317. return $this->_serviceGetBlockViewByType(array(
  1318. 'view' => BX_TIMELINE_VIEW_OUTLINE,
  1319. 'type' => BX_TIMELINE_TYPE_OWNER_AND_CONNECTIONS,
  1320. 'owner_id' => $iProfileId,
  1321. 'start' => $iStart,
  1322. 'per_page' => $iPerPage,
  1323. 'per_page_default' => $this->_oConfig->getPerPage('account'),
  1324. 'timeline' => $iTimeline,
  1325. 'filter' => $sFilter,
  1326. 'modules' => $aModules
  1327. ));
  1328. }
  1329. /**
  1330. * @page service Service Calls
  1331. * @section bx_timeline Timeline
  1332. * @subsection bx_timeline-page_blocks Page Blocks
  1333. * @subsubsection bx_timeline-get_block_view_custom get_block_view_custom
  1334. *
  1335. * @code bx_srv('bx_timeline', 'get_block_view_custom', [...]); @endcode
  1336. *
  1337. * Get custom Timeline View block.
  1338. *
  1339. * @param $aParams (optional) an array with block parameneters.
  1340. * @return an array describing a block to display on the site. All necessary CSS and JS files are automatically added to the HEAD section of the site HTML.
  1341. *
  1342. * @see BxTimelineModule::serviceGetBlockViewCustom
  1343. */
  1344. /**
  1345. * @ref bx_timeline-get_block_view_custom "get_block_view_custom"
  1346. */
  1347. public function serviceGetBlockViewCustom($aParams = array())
  1348. {
  1349. return $this->_serviceGetBlockViewByType($aParams);
  1350. }
  1351. /**
  1352. * @page service Service Calls
  1353. * @section bx_timeline Timeline
  1354. * @subsection bx_timeline-page_blocks Page Blocks
  1355. * @subsubsection bx_timeline-get_block_item get_block_item
  1356. *
  1357. * @code bx_srv('bx_timeline', 'get_block_item', [...]); @endcode
  1358. *
  1359. * Get View Item block.
  1360. *
  1361. * @return an array describing a block to display on the site. All necessary CSS and JS files are automatically added to the HEAD section of the site HTML.
  1362. *
  1363. * @see BxTimelineModule::serviceGetBlockItem
  1364. */
  1365. /**
  1366. * @ref bx_timeline-get_block_item "get_block_item"
  1367. */
  1368. public function serviceGetBlockItem()
  1369. {
  1370. $iItemId = bx_process_input(bx_get('id'), BX_DATA_INT);
  1371. if(!$iItemId)
  1372. return array();
  1373. $aParams = array(
  1374. 'view' => BX_TIMELINE_VIEW_ITEM,
  1375. 'type' => BX_TIMELINE_TYPE_ITEM
  1376. );
  1377. $aParams = $this->_prepareParams($aParams);
  1378. return $this->_oTemplate->getItemBlock($iItemId, $aParams);
  1379. }
  1380. public function serviceGetBlockItemContent()
  1381. {
  1382. $iItemId = bx_process_input(bx_get('id'), BX_DATA_INT);
  1383. $sMode = bx_process_input(bx_get('mode'));
  1384. if(!$iItemId || !$sMode)
  1385. return '';
  1386. return $this->_oTemplate->getItemBlockContent($iItemId, $sMode);
  1387. }
  1388. public function serviceGetBlockItemInfo()
  1389. {
  1390. $iItemId = bx_process_input(bx_get('id'), BX_DATA_INT);
  1391. if(!$iItemId)
  1392. return '';
  1393. return $this->_oTemplate->getItemBlockInfo($iItemId);
  1394. }
  1395. public function serviceGetBlockItemComments()
  1396. {
  1397. $iItemId = bx_process_input(bx_get('id'), BX_DATA_INT);
  1398. if(!$iItemId)
  1399. return '';
  1400. return $this->_oTemplate->getItemBlockComments($iItemId);
  1401. }
  1402. /**
  1403. * @page service Service Calls
  1404. * @section bx_timeline Timeline
  1405. * @subsection bx_timeline-integration_notifications Integration with Notifications
  1406. * @subsubsection bx_timeline-get_notifications_data get_notifications_data
  1407. *
  1408. * @code bx_srv('bx_timeline', 'get_notifications_data', [...]); @endcode
  1409. *
  1410. * Data for Notifications module.
  1411. *
  1412. * @return an array with special format.
  1413. *
  1414. * @see BxTimelineModule::serviceGetNotificationsData
  1415. */
  1416. /**
  1417. * @ref bx_timeline-get_notifications_data "get_notifications_data"
  1418. */
  1419. public function serviceGetNotificationsData()
  1420. {
  1421. $sModule = $this->_aModule['name'];
  1422. return array(
  1423. 'handlers' => array(
  1424. array('group' => $sModule . '_object', 'type' => 'insert', 'alert_unit' => $sModule, 'alert_action' => 'post_common', 'module_name' => $sModule, 'module_method' => 'get_notifications_post', 'module_class' => 'Module'),
  1425. array('group' => $sModule . '_object', 'type' => 'delete', 'alert_unit' => $sModule, 'alert_action' => 'delete'),
  1426. array('group' => $sModule . '_object_publish_failed', 'type' => 'insert', 'alert_unit' => $sModule, 'alert_action' => 'publish_failed', 'module_name' => $sModule, 'module_method' => 'get_notifications_post_publish_failed', 'module_class' => 'Module'),
  1427. array('group' => $sModule . '_object_publish_succeeded', 'type' => 'insert', 'alert_unit' => $sModule, 'alert_action' => 'publish_succeeded', 'module_name' => $sModule, 'module_method' => 'get_notifications_post_publish_succeeded', 'module_class' => 'Module'),
  1428. array('group' => $sModule . '_repost', 'type' => 'insert', 'alert_unit' => $sModule, 'alert_action' => 'repost', 'module_name' => $sModule, 'module_method' => 'get_notifications_repost', 'module_class' => 'Module'),
  1429. array('group' => $sModule . '_repost', 'type' => 'delete', 'alert_unit' => $sModule, 'alert_action' => 'delete_repost'),
  1430. array('group' => $sModule . '_comment', 'type' => 'insert', 'alert_unit' => $sModule, 'alert_action' => 'commentPost', 'module_name' => $sModule, 'module_method' => 'get_notifications_comment', 'module_class' => 'Module'),
  1431. array('group' => $sModule . '_comment', 'type' => 'delete', 'alert_unit' => $sModule, 'alert_action' => 'commentRemoved'),
  1432. array('group' => $sModule . '_vote', 'type' => 'insert', 'alert_unit' => $sModule, 'alert_action' => 'doVote', 'module_name' => $sModule, 'module_method' => 'get_notifications_vote', 'module_class' => 'Module'),
  1433. array('group' => $sModule . '_vote', 'type' => 'delete', 'alert_unit' => $sModule, 'alert_action' => 'undoVote'),
  1434. array('group' => $sModule . '_reaction', 'type' => 'insert', 'alert_unit' => $sModule . '_reactions', 'alert_action' => 'doVote', 'module_name' => $sModule, 'module_method' => 'get_notifications_reaction', 'module_class' => 'Module'),
  1435. array('group' => $sModule . '_reaction', 'type' => 'delete', 'alert_unit' => $sModule . '_reactions', 'alert_action' => 'undoVote'),
  1436. array('group' => $sModule . '_score_up', 'type' => 'insert', 'alert_unit' => $sModule, 'alert_action' => 'doVoteUp', 'module_name' => $sModule, 'module_method' => 'get_notifications_score_up', 'module_class' => 'Module'),
  1437. array('group' => $sModule . '_score_down', 'type' => 'insert', 'alert_unit' => $sModule, 'alert_action' => 'doVoteDown', 'module_name' => $sModule, 'module_method' => 'get_notifications_score_down', 'module_class' => 'Module'),
  1438. ),
  1439. 'settings' => array(
  1440. array('group' => 'content', 'unit' => $sModule, 'action' => 'post_common', 'types' => array('personal', 'follow_member', 'follow_context')),
  1441. array('group' => 'content', 'unit' => $sModule, 'action' => 'publish_failed', 'types' => array('personal')),
  1442. array('group' => 'content', 'unit' => $sModule, 'action' => 'publish_succeeded', 'types' => array('personal')),
  1443. array('group' => 'content', 'unit' => $sModule, 'action' => 'repost', 'types' => array('follow_member', 'follow_context')),
  1444. array('group' => 'comment', 'unit' => $sModule, 'action' => 'commentPost', 'types' => array('personal', 'follow_member', 'follow_context')),
  1445. array('group' => 'vote', 'unit' => $sModule, 'action' => 'doVote', 'types' => array('personal', 'follow_member', 'follow_context')),
  1446. array('group' => 'vote', 'unit' => $sModule . '_reactions', 'action' => 'doVote', 'types' => array('personal', 'follow_member', 'follow_context')),
  1447. array('group' => 'score_up', 'unit' => $sModule, 'action' => 'doVoteUp', 'types' => array('personal', 'follow_member', 'follow_context')),
  1448. array('group' => 'score_down', 'unit' => $sModule, 'action' => 'doVoteDown', 'types' => array('personal', 'follow_member', 'follow_context'))
  1449. ),
  1450. 'alerts' => array(
  1451. array('unit' => $sModule, 'action' => 'post_common'),
  1452. array('unit' => $sModule, 'action' => 'publish_failed'),
  1453. array('unit' => $sModule, 'action' => 'publish_succeeded'),
  1454. array('unit' => $sModule, 'action' => 'delete'),
  1455. array('unit' => $sModule, 'action' => 'repost'),
  1456. array('unit' => $sModule, 'action' => 'delete_repost'),
  1457. array('unit' => $sModule, 'action' => 'commentPost'),
  1458. array('unit' => $sModule, 'action' => 'commentRemoved'),
  1459. array('unit' => $sModule, 'action' => 'doVote'),
  1460. array('unit' => $sModule, 'action' => 'undoVote'),
  1461. array('unit' => $sModule . '_reactions', 'action' => 'doVote'),
  1462. array('unit' => $sModule . '_reactions', 'action' => 'undoVote'),
  1463. array('unit' => $sModule, 'action' => 'doVoteUp'),
  1464. array('unit' => $sModule, 'action' => 'doVoteDown'),
  1465. )
  1466. );
  1467. }
  1468. /**
  1469. * @page service Service Calls
  1470. * @section bx_timeline Timeline
  1471. * @subsection bx_timeline-integration_notifications Integration with Notifications
  1472. * @subsubsection bx_timeline-get_notifications_repost get_notifications_repost
  1473. *
  1474. * @code bx_srv('bx_timeline', 'get_notifications_repost', [...]); @endcode
  1475. *
  1476. * Get data for Repost event to display in Notifications module.
  1477. *
  1478. * @param $aEvent an array with event description.
  1479. * @return an array with special format.
  1480. *
  1481. * @see BxTimelineModule::serviceGetNotificationsRepost
  1482. */
  1483. /**
  1484. * @ref bx_timeline-get_notifications_repost "get_notifications_repost"
  1485. */
  1486. public function serviceGetNotificationsRepost($aEvent)
  1487. {
  1488. $aResult = $this->serviceGetNotificationsPost($aEvent);
  1489. $aResult['lang_key'] = '_bx_timeline_txt_object_reposted';
  1490. return $aResult;
  1491. }
  1492. /**
  1493. * @page service Service Calls
  1494. * @section bx_timeline Timeline
  1495. * @subsection bx_timeline-integration_notifications Integration with Notifications
  1496. * @subsubsection bx_timeline-get_notifications_post get_notifications_post
  1497. *
  1498. * @code bx_srv('bx_timeline', 'get_notifications_post', [...]); @endcode
  1499. *
  1500. * Get data for Post event to display in Notifications module.
  1501. *
  1502. * @param $aEvent an array with event description.
  1503. * @return an array with special format.
  1504. *
  1505. * @see BxTimelineModule::serviceGetNotificationsPost
  1506. */
  1507. /**
  1508. * @ref bx_timeline-get_notifications_post "get_notifications_post"
  1509. */
  1510. public function serviceGetNotificationsPost($aEvent)
  1511. {
  1512. $CNF = &$this->_oConfig->CNF;
  1513. $iContent = (int)$aEvent['object_id'];
  1514. $aContent = $this->_oDb->getEvents(array('browse' => 'id', 'value' => $iContent));
  1515. if(empty($aContent) || !is_array($aContent))
  1516. return array();
  1517. if($this->_oConfig->isSystem($aContent['type'], $aContent['action']))
  1518. $iEntryAuthor = (int)$aContent['owner_id'];
  1519. else
  1520. $iEntryAuthor = (int)$aContent['object_id'];
  1521. $sEntryCaption = call_user_func_array(array($this->_oConfig, 'getTitleShort'), !empty($aContent['title']) ? array($aContent['title']) : array($aContent['description'], $aContent['object_id']));
  1522. return array(
  1523. 'entry_sample' => $CNF['T']['txt_sample_single_ext'],
  1524. 'entry_url' => $this->_oConfig->getItemViewUrl($aContent),
  1525. 'entry_caption' => $sEntryCaption,
  1526. 'entry_author' => $iEntryAuthor,
  1527. 'lang_key' => '' //may be empty or not specified. In this case the default one from Notification module will be used.
  1528. );
  1529. }
  1530. /**
  1531. * @page service Service Calls
  1532. * @section bx_timeline Timeline
  1533. * @subsection bx_timeline-integration_notifications Integration with Notifications
  1534. * @subsubsection bx_timeline-get_notifications_comment get_notifications_comment
  1535. *
  1536. * @code bx_srv('bx_timeline', 'get_notifications_comment', [...]); @endcode
  1537. *
  1538. * Get data for Post Comment event to display in Notifications module.
  1539. *
  1540. * @param $aEvent an array with event description.
  1541. * @return an array with special format.
  1542. *
  1543. * @see BxTimelineModule::serviceGetNotificationsComment
  1544. */
  1545. /**
  1546. * @ref bx_timeline-get_notifications_comment "get_notifications_comment"
  1547. */
  1548. public function serviceGetNotificationsComment($aEvent)
  1549. {
  1550. $CNF = &$this->_oConfig->CNF;
  1551. $iContent = (int)$aEvent['object_id'];
  1552. $aContent = $this->_oDb->getEvents(array('browse' => 'id', 'value' => $iContent));
  1553. if(empty($aContent) || !is_array($aContent))
  1554. return array();
  1555. $oComment = BxDolCmts::getObjectInstance($CNF['OBJECT_COMMENTS'], $iContent);
  1556. if(!$oComment || !$oComment->isEnabled())
  1557. return array();
  1558. $sEntryCaption = call_user_func_array(array($this->_oConfig, 'getTitleShort'), !empty($aContent['title']) ? array($aContent['title']) : array($aContent['description'], $aContent['object_id']));
  1559. return array(
  1560. 'entry_sample' => $CNF['T']['txt_sample_single'],
  1561. 'entry_url' => $this->_oConfig->getItemViewUrl($aContent),
  1562. 'entry_caption' => $sEntryCaption,
  1563. 'entry_author' => $aContent['owner_id'],
  1564. 'subentry_sample' => $CNF['T']['txt_sample_comment_single'],
  1565. 'subentry_url' => $oComment->getViewUrl((int)$aEvent['subobject_id']),
  1566. 'lang_key' => '', //may be empty or not specified. In this case the default one from Notification module will be used.
  1567. );
  1568. }
  1569. /**
  1570. * @page service Service Calls
  1571. * @section bx_timeline Timeline
  1572. * @subsection bx_timeline-integration_notifications Integration with Notifications
  1573. * @subsubsection bx_timeline-get_notifications_vote get_notifications_vote
  1574. *
  1575. * @code bx_srv('bx_timeline', 'get_notifications_vote', [...]); @endcode
  1576. *
  1577. * Get data for Vote event to display in Notifications module.
  1578. *
  1579. * @param $aEvent an array with event description.
  1580. * @return an array with special format.
  1581. *
  1582. * @see BxTimelineModule::serviceGetNotificationsVote
  1583. */
  1584. /**
  1585. * @ref bx_timeline-get_notifications_vote "get_notifications_vote"
  1586. */
  1587. public function serviceGetNotificationsVote($aEvent)
  1588. {
  1589. $CNF = &$this->_oConfig->CNF;
  1590. $iContent = (int)$aEvent['object_id'];
  1591. $aContent = $this->_oDb->getEvents(array('browse' => 'id', 'value' => $iContent));
  1592. if(empty($aContent) || !is_array($aContent))
  1593. return array();
  1594. $oVote = BxDolVote::getObjectInstance($CNF['OBJECT_VOTES'], $iContent);
  1595. if(!$oVote || !$oVote->isEnabled())
  1596. return array();
  1597. $sEntryCaption = call_user_func_array(array($this->_oConfig, 'getTitleShort'), !empty($aContent['title']) ? array($aContent['title']) : array($aContent['description'], $aContent['object_id']));
  1598. return array(
  1599. 'entry_sample' => $CNF['T']['txt_sample_single'],
  1600. 'entry_url' => $this->_oConfig->getItemViewUrl($aContent),
  1601. 'entry_caption' => $sEntryCaption,
  1602. 'entry_author' => $aContent['owner_id'],
  1603. 'subentry_sample' => $CNF['T']['txt_sample_vote_single'],
  1604. 'lang_key' => '', //may be empty or not specified. In this case the default one from Notification module will be used.
  1605. );
  1606. }
  1607. /**
  1608. * Entry post vote for Notifications module
  1609. */
  1610. public function serviceGetNotificationsReaction($aEvent)
  1611. {
  1612. $CNF = &$this->_oConfig->CNF;
  1613. $iContent = (int)$aEvent['object_id'];
  1614. $aContent = $this->_oDb->getEvents(array('browse' => 'id', 'value' => $iContent));
  1615. if(empty($aContent) || !is_array($aContent))
  1616. return array();
  1617. $oReaction = BxDolVote::getObjectInstance($CNF['OBJECT_REACTIONS'], $iContent);
  1618. if(!$oReaction || !$oReaction->isEnabled())
  1619. return array();
  1620. $aSubentry = $oReaction->getTrackBy(array('type' => 'id', 'id' => (int)$aEvent['subobject_id']));
  1621. if(empty($aSubentry) || !is_array($aSubentry))
  1622. return array();
  1623. $aSubentrySampleParams = array();
  1624. $aReaction = $oReaction->getReaction($aSubentry['reaction']);
  1625. if(!empty($aReaction['title']))
  1626. $aSubentrySampleParams[] = $aReaction['title'];
  1627. else
  1628. $aSubentrySampleParams[] = '_undefined';
  1629. $sEntryCaption = call_user_func_array(array($this->_oConfig, 'getTitleShort'), !empty($aContent['title']) ? array($aContent['title']) : array($aContent['description'], $aContent['object_id']));
  1630. return array(
  1631. 'entry_sample' => $CNF['T']['txt_sample_single'],
  1632. 'entry_url' => $this->_oConfig->getItemViewUrl($aContent),
  1633. 'entry_caption' => $sEntryCaption,
  1634. 'entry_author' => $aContent['owner_id'],
  1635. 'subentry_sample' => $CNF['T']['txt_sample_reaction_single'],
  1636. 'subentry_sample_params' => $aSubentrySampleParams,
  1637. 'lang_key' => '', //may be empty or not specified. In this case the default one from Notification module will be used.
  1638. );
  1639. }
  1640. /**
  1641. * @page service Service Calls
  1642. * @section bx_timeline Timeline
  1643. * @subsection bx_timeline-integration_notifications Integration with Notifications
  1644. * @subsubsection bx_timeline-get_notifications_score_up get_notifications_score_up
  1645. *
  1646. * @code bx_srv('bx_timeline', 'get_notifications_score_up', [...]); @endcode
  1647. *
  1648. * Get data for Score Up Vote event to display in Notifications module.
  1649. *
  1650. * @param $aEvent an array with event description.
  1651. * @return an array with special format.
  1652. *
  1653. * @see BxTimelineModule::serviceGetNotificationsScoreUp
  1654. */
  1655. /**
  1656. * @ref bx_timeline-get_notifications_score_up "get_notifications_score_up"
  1657. */
  1658. public function serviceGetNotificationsScoreUp($aEvent)
  1659. {
  1660. return $this->_serviceGetNotificationsScore('up', $aEvent);
  1661. }
  1662. /**
  1663. * @page service Service Calls
  1664. * @section bx_timeline Timeline
  1665. * @subsection bx_timeline-integration_notifications Integration with Notifications
  1666. * @subsubsection bx_timeline-get_notifications_score_down get_notifications_score_down
  1667. *
  1668. * @code bx_srv('bx_timeline', 'get_notifications_score_down', [...]); @endcode
  1669. *
  1670. * Get data for Score Down Vote event to display in Notifications module.
  1671. *
  1672. * @param $aEvent an array with event description.
  1673. * @return an array with special format.
  1674. *
  1675. * @see BxTimelineModule::serviceGetNotificationsScoreDown
  1676. */
  1677. /**
  1678. * @ref bx_timeline-get_notifications_score_down "get_notifications_score_down"
  1679. */
  1680. public function serviceGetNotificationsScoreDown($aEvent)
  1681. {
  1682. return $this->_serviceGetNotificationsScore('down', $aEvent);
  1683. }
  1684. protected function _serviceGetNotificationsScore($sType, $aEvent)
  1685. {
  1686. $CNF = &$this->_oConfig->CNF;
  1687. $iContent = (int)$aEvent['object_id'];
  1688. $aContent = $this->_oDb->getEvents(array('browse' => 'id', 'value' => $iContent));
  1689. if(empty($aContent) || !is_array($aContent))
  1690. return array();
  1691. $oScore = BxDolScore::getObjectInstance($CNF['OBJECT_SCORES'], $iContent);
  1692. if(!$oScore || !$oScore->isEnabled())
  1693. return array();
  1694. $sEntryCaption = call_user_func_array(array($this->_oConfig, 'getTitleShort'), !empty($aContent['title']) ? array($aContent['title']) : array($aContent['description'], $aContent['object_id']));
  1695. return array(
  1696. 'entry_sample' => $CNF['T']['txt_sample_single'],
  1697. 'entry_url' => $this->_oConfig->getItemViewUrl($aContent),
  1698. 'entry_caption' => $sEntryCaption,
  1699. 'entry_author' => $aContent['owner_id'],
  1700. 'subentry_sample' => $CNF['T']['txt_sample_score_' . $sType . '_single'],
  1701. 'lang_key' => '', //may be empty or not specified. In this case the default one from Notification module will be used.
  1702. );
  1703. }
  1704. /**
  1705. * @page service Service Calls
  1706. * @section bx_timeline Timeline
  1707. * @subsection bx_timeline-repost Repost
  1708. * @subsubsection bx_timeline-get_repost_element_block get_repost_element_block
  1709. *
  1710. * @code bx_srv('bx_timeline', 'get_repost_element_block', [...]); @endcode
  1711. *
  1712. * Get repost element for content based modules.
  1713. *
  1714. * @param $iOwnerId integer value with owner profile ID.
  1715. * @param $sType string value with type (module name).
  1716. * @param $sAction string value with action (module action).
  1717. * @param $iObjectId integer value with object ID to be reposted.
  1718. * @param $aParams (optional) an array with additional params.
  1719. * @return HTML string with repost element to display on the site, all necessary CSS and JS files are automatically added to the HEAD section of the site HTML.
  1720. *
  1721. * @see BxTimelineModule::serviceGetRepostElementBlock
  1722. */
  1723. /**
  1724. * @ref bx_timeline-get_repost_element_block "get_repost_element_block"
  1725. */
  1726. public function serviceGetRepostElementBlock($iOwnerId, $sType, $sAction, $iObjectId, $aParams = array())
  1727. {
  1728. if(!$this->isEnabled())
  1729. return '';
  1730. $aParams = array_merge($this->_oConfig->getRepostDefaults(), $aParams);
  1731. return $this->_oTemplate->getRepostElement($iOwnerId, $sType, $sAction, $iObjectId, $aParams);
  1732. }
  1733. /**
  1734. * @page service Service Calls
  1735. * @section bx_timeline Timeline
  1736. * @subsection bx_timeline-repost Repost
  1737. * @subsubsection bx_timeline-get_repost_counter get_repost_counter
  1738. *
  1739. * @code bx_srv('bx_timeline', 'get_repost_counter', [...]); @endcode
  1740. *
  1741. * Get repost counter.
  1742. *
  1743. * @param $sType string value with type (module name).
  1744. * @param $sAction string value with action (module action).
  1745. * @param $iObjectId integer value with object ID to be reposted.
  1746. * @return HTML string with repost counter to display on the site, all necessary CSS and JS files are automatically added to the HEAD section of the site HTML.
  1747. *
  1748. * @see BxTimelineModule::serviceGetRepostCounter
  1749. */
  1750. /**
  1751. * @ref bx_timeline-get_repost_counter "get_repost_counter"
  1752. */
  1753. public function serviceGetRepostCounter($sType, $sAction, $iObjectId)
  1754. {
  1755. if(!$this->isEnabled())
  1756. return '';
  1757. $aReposted = $this->_oDb->getReposted($sType, $sAction, $iObjectId);
  1758. return $this->_oTemplate->getRepostCounter($aReposted);
  1759. }
  1760. /**
  1761. * @page service Service Calls
  1762. * @section bx_timeline Timeline
  1763. * @subsection bx_timeline-repost Repost
  1764. * @subsubsection bx_timeline-get_repost_js_script get_repost_js_script
  1765. *
  1766. * @code bx_srv('bx_timeline', 'get_repost_js_script', [...]); @endcode
  1767. *
  1768. * Get repost JavaScript code.
  1769. *
  1770. * @return HTML string with JavaScript code to display on the site, all necessary CSS and JS files are automatically added to the HEAD section of the site HTML.
  1771. *
  1772. * @see BxTimelineModule::serviceGetRepostJsScript
  1773. */
  1774. /**
  1775. * @ref bx_timeline-get_repost_js_script "get_repost_js_script"
  1776. */
  1777. public function serviceGetRepostJsScript()
  1778. {
  1779. if(!$this->isEnabled())
  1780. return '';
  1781. return $this->_oTemplate->getRepostJsScript();
  1782. }
  1783. /**
  1784. * @page service Service Calls
  1785. * @section bx_timeline Timeline
  1786. * @subsection bx_timeline-repost Repost
  1787. * @subsubsection bx_timeline-get_repost_js_click get_repost_js_click
  1788. *
  1789. * @code bx_srv('bx_timeline', 'get_repost_js_click', [...]); @endcode
  1790. *
  1791. * Get repost JavaScript code for OnClick event.
  1792. *
  1793. * @param $iOwnerId integer value with owner profile ID.
  1794. * @param $sType string value with type (module name).
  1795. * @param $sAction string value with action (module action).
  1796. * @param $iObjectId integer value with object ID to be reposted.
  1797. * @return HTML string with JavaScript code to display in OnClick events of HTML elements.
  1798. *
  1799. * @see BxTimelineModule::serviceGetRepostJsClick
  1800. */
  1801. /**
  1802. * @ref bx_timeline-get_repost_js_click "get_repost_js_click"
  1803. */
  1804. public function serviceGetRepostJsClick($iOwnerId, $sType, $sAction, $iObjectId)
  1805. {
  1806. if(!$this->isEnabled())
  1807. return '';
  1808. return $this->_oTemplate->getRepostJsClick($iOwnerId, $sType, $sAction, $iObjectId);
  1809. }
  1810. /**
  1811. * @page service Service Calls
  1812. * @section bx_timeline Timeline
  1813. * @subsection bx_timeline-repost Repost
  1814. * @subsubsection bx_timeline-repost repost
  1815. *
  1816. * @code bx_srv('bx_timeline', 'repost', [...]); @endcode
  1817. *
  1818. * Perform repost action.
  1819. *
  1820. * @param $iAuthorId integer value with performer profile ID.
  1821. * @param $iOwnerId integer value with repost event owner profile ID.
  1822. * @param $sType string value with type (module name).
  1823. * @param $sAction string value with action (module action).
  1824. * @param $iObjectId integer value with object ID to be reposted.
  1825. * @parem $bForce boolean value force reposting without ACL check.
  1826. * @return an array with error (code and message) or integer with newly created repost event ID.
  1827. *
  1828. * @see BxTimelineModule::serviceRepost
  1829. */
  1830. /**
  1831. * @ref bx_timeline-repost "repost"
  1832. */
  1833. public function serviceRepost($iAuthorId, $iOwnerId, $sType, $sAction, $iObjectId, $bForce = false)
  1834. {
  1835. $aReposted = $this->_oDb->getReposted($sType, $sAction, $iObjectId);
  1836. if(empty($aReposted) || !is_array($aReposted))
  1837. return array('code' => 1, 'message' => _t('_bx_timeline_txt_err_cannot_repost'));
  1838. $mixedAllowed = $this->isAllowedRepost($aReposted, true);
  1839. if(!$bForce && $mixedAllowed !== true)
  1840. return array('code' => 2, 'message' => strip_tags($mixedAllowed));
  1841. $bReposted = $this->_oDb->isReposted($aReposted['id'], $iOwnerId, $iAuthorId);
  1842. if($bReposted)
  1843. return array('code' => 3, 'message' => _t('_bx_timeline_txt_err_already_reposted'));
  1844. $iId = $this->_oDb->insertEvent(array(
  1845. 'owner_id' => $iOwnerId,
  1846. 'system' => 0,
  1847. 'type' => $this->_oConfig->getPrefix('common_post') . 'repost',
  1848. 'action' => '',
  1849. 'object_id' => $iAuthorId,
  1850. 'object_privacy_view' => $this->_oConfig->getPrivacyViewDefault('object'),
  1851. 'content' => serialize(array(
  1852. 'type' => $sType,
  1853. 'action' => $sAction,
  1854. 'object_id' => $iObjectId,
  1855. )),
  1856. 'title' => '',
  1857. 'description' => ''
  1858. ));
  1859. if(empty($iId))
  1860. return array('code' => 4, 'message' => _t('_bx_timeline_txt_err_cannot_repost'));
  1861. $this->onRepost($iId, $aReposted);
  1862. return $iId;
  1863. }
  1864. /**
  1865. * @page service Service Calls
  1866. * @section bx_timeline Timeline
  1867. * @subsection bx_timeline-repost Repost
  1868. * @subsubsection bx_timeline-repost_by_id repost_by_id
  1869. *
  1870. * @code bx_srv('bx_timeline', 'repost_by_id', [...]); @endcode
  1871. *
  1872. * Perform repost action by Timeline event ID.
  1873. *
  1874. * @param $iAuthorId integer value with performer profile ID.
  1875. * @param $iOwnerId integer value with repost event owner profile ID.
  1876. * @param $iEventId integer value with event ID which will be reposted.
  1877. * @parem $bForce boolean value force reposting without ACL check.
  1878. * @return an array with error (code and message) or integer with newly created repost event ID.
  1879. *
  1880. * @see BxTimelineModule::serviceRepostById
  1881. */
  1882. /**
  1883. * @ref bx_timeline-repost_by_id "repost_by_id"
  1884. */
  1885. public function serviceRepostById($iAuthorId, $iOwnerId, $iEventId, $bForce = false)
  1886. {
  1887. $aEvent = $this->_oDb->getEntriesBy(array('type' => 'id', 'id' => $iEventId));
  1888. if(empty($aEvent) || !is_array($aEvent))
  1889. return array('code' => 1, 'message' => _t('_bx_timeline_txt_err_cannot_repost'));
  1890. $sType = $aEvent['type'];
  1891. $sAction = $aEvent['action'];
  1892. $iObjectId = $this->_oConfig->isSystem($sType, $sAction) ? $aEvent['object_id'] : $aEvent['id'];
  1893. $sCommonPrefix = $this->_oConfig->getPrefix('common_post');
  1894. if(str_replace($sCommonPrefix, '', $sType) == BX_TIMELINE_PARSE_TYPE_REPOST) {
  1895. $aReposted = $this->_oDb->getReposted($sType, $sAction, $iObjectId);
  1896. if(empty($aReposted) || !is_array($aReposted))
  1897. return array('code' => 1, 'message' => _t('_bx_timeline_txt_err_cannot_repost'));
  1898. $aRepostedData = unserialize($aEvent['content']);
  1899. $sType = $aRepostedData['type'];
  1900. $sAction = $aRepostedData['action'];
  1901. $iObjectId = $aRepostedData['object_id'];
  1902. }
  1903. return $this->serviceRepost($iAuthorId, $iOwnerId, $sType, $sAction, $iObjectId, $bForce);
  1904. }
  1905. /**
  1906. * @page service Service Calls
  1907. * @section bx_timeline Timeline
  1908. * @subsection bx_timeline-other Other
  1909. * @subsubsection bx_timeline-update update
  1910. *
  1911. * @code bx_srv('bx_timeline', 'update', [...]); @endcode
  1912. *
  1913. * Update timeline event by ID.
  1914. *
  1915. * @param $iEventId integer value with event ID.
  1916. * @param $aSet an array with key=>value pairs for fields which should be updated.
  1917. * @return boolean value with the result of operation.
  1918. *
  1919. * @see BxTimelineModule::serviceUpdate
  1920. */
  1921. /**
  1922. * @ref bx_timeline-update "update"
  1923. */
  1924. public function serviceUpdate($iEventId, $aSet)
  1925. {
  1926. if(empty($iEventId))
  1927. return false;
  1928. return (int)$this->_oDb->updateEvent($aSet, array('id' => $iEventId)) > 0;
  1929. }
  1930. /**
  1931. * @page service Service Calls
  1932. * @section bx_timeline Timeline
  1933. * @subsection bx_timeline-other Other
  1934. * @subsubsection bx_timeline-get_menu_item_addon_comment get_menu_item_addon_comment
  1935. *
  1936. * @code bx_srv('bx_timeline', 'get_menu_item_addon_comment', [...]); @endcode
  1937. *
  1938. * Get addon for Comment menu item.
  1939. * NOTE. The service isn't used for now because comment functionality in card was updated.
  1940. *
  1941. * @param $sSystem string value with comments engine system.
  1942. * @param $iObjectId integer value with object ID.
  1943. * @return HTML string to display in menu item.
  1944. *
  1945. * @see BxTimelineModule::serviceGetMenuItemAddonComment
  1946. */
  1947. /**
  1948. * @ref bx_timeline-get_menu_item_addon_comment "get_menu_item_addon_comment"
  1949. */
  1950. public function serviceGetMenuItemAddonComment($sSystem, $iObjectId, $aBrowseParams = array())
  1951. {
  1952. if(empty($sSystem) || empty($iObjectId))
  1953. return '';
  1954. $oCmts = $this->getCmtsObject($sSystem, $iObjectId);
  1955. if($oCmts === false)
  1956. return '';
  1957. $iCounter = (int)$oCmts->getCommentsCount();
  1958. if(empty($iCounter))
  1959. return '';
  1960. return $this->_oTemplate->parseLink('javascript:void(0)', $iCounter, array(
  1961. 'class' => 'bx-menu-item-addon',
  1962. 'title' => _t('_bx_timeline_menu_item_title_item_comment'),
  1963. 'onclick' => "javascript:" . $this->_oConfig->getJsObjectView($aBrowseParams) . ".commentItem(this, '" . $sSystem . "', " . $iObjectId . ")"
  1964. ));
  1965. }
  1966. /**
  1967. * @page service Service Calls
  1968. * @section bx_timeline Timeline
  1969. * @subsection bx_timeline-other Other
  1970. * @subsubsection bx_timeline-get_settings_checker_helper get_settings_checker_helper
  1971. *
  1972. * @code bx_srv('bx_timeline', 'get_settings_checker_helper', [...]); @endcode
  1973. *
  1974. * Get Checker Helper class name for Forms engine.
  1975. *
  1976. * @return string with Checker Helper class name.
  1977. *
  1978. * @see BxTimelineModule::serviceGetSettingsCheckerHelper
  1979. */
  1980. /**
  1981. * @ref bx_timeline-get_settings_checker_helper "get_settings_checker_helper"
  1982. */
  1983. public function serviceGetSettingsCheckerHelper()
  1984. {
  1985. bx_import('FormCheckerHelper', $this->_aModule);
  1986. return 'BxTimelineFormCheckerHelper';
  1987. }
  1988. /**
  1989. * @page service Service Calls
  1990. * @section bx_timeline Timeline
  1991. * @subsection bx_timeline-other Other
  1992. * @subsubsection bx_timeline-get_options_videos_autoplay get_options_videos_autoplay
  1993. *
  1994. * @code bx_srv('bx_timeline', 'get_options_videos_autoplay', [...]); @endcode
  1995. *
  1996. * Get an array with available options for 'Videos autoplay in Timeline' setting.
  1997. *
  1998. * @return an array with available options represented as key => value pairs.
  1999. *
  2000. * @see BxTimelineModule::serviceGetOptionsVideosAutoplay
  2001. */
  2002. /**
  2003. * @ref bx_timeline-get_options_videos_autoplay "get_options_videos_autoplay"
  2004. */
  2005. public function serviceGetOptionsVideosAutoplay()
  2006. {
  2007. $CNF = &$this->_oConfig->CNF;
  2008. $aOptions = array(BX_TIMELINE_VAP_OFF, BX_TIMELINE_VAP_ON_MUTE, BX_TIMELINE_VAP_ON);
  2009. $aResult = array();
  2010. foreach($aOptions as $sOption)
  2011. $aResult[] = array(
  2012. 'key' => $sOption,
  2013. 'value' => _t($CNF['T']['option_vap_' . $sOption])
  2014. );
  2015. return $aResult;
  2016. }
  2017. /**
  2018. * @page service Service Calls
  2019. * @section bx_timeline Timeline
  2020. * @subsection bx_timeline-other Other
  2021. * @subsubsection bx_timeline-get_options_attachments_layout get_options_attachments_layout
  2022. *
  2023. * @code bx_srv('bx_timeline', 'get_options_attachments_layout', [...]); @endcode
  2024. *
  2025. * Get an array with available options for 'Show attachments as' setting.
  2026. *
  2027. * @return an array with available options represented as key => value pairs.
  2028. *
  2029. * @see BxTimelineModule::serviceGetOptionsAttachmentsLayout
  2030. */
  2031. /**
  2032. * @ref bx_timeline-get_options_attachments_layout "get_options_attachments_layout"
  2033. */
  2034. public function serviceGetOptionsAttachmentsLayout()
  2035. {
  2036. $CNF = &$this->_oConfig->CNF;
  2037. $aOptions = array(BX_TIMELINE_ML_GALLERY, BX_TIMELINE_ML_SHOWCASE);
  2038. $aResult = array();
  2039. foreach($aOptions as $sOption)
  2040. $aResult[] = array(
  2041. 'key' => $sOption,
  2042. 'value' => _t($CNF['T']['option_al_' . $sOption])
  2043. );
  2044. return $aResult;
  2045. }
  2046. /**
  2047. * @page service Service Calls
  2048. * @section bx_timeline Timeline
  2049. * @subsection bx_timeline-other Other
  2050. * @subsubsection bx_timeline-get_live_update get_live_update
  2051. *
  2052. * @code bx_srv('bx_timeline', 'get_live_update', [...]); @endcode
  2053. *
  2054. * Get an array with actual Live Update info. Only one live update notification for all new events.
  2055. *
  2056. * @return an array with Live Update info.
  2057. *
  2058. * @see BxTimelineModule::serviceGetLiveUpdate
  2059. */
  2060. /**
  2061. * @ref bx_timeline-get_live_update "get_live_update"
  2062. */
  2063. public function serviceGetLiveUpdate($aBrowseParams, $iProfileId, $iValue = 0, $iInit = 0)
  2064. {
  2065. $sKey = $this->_oConfig->getLiveUpdateKey($aBrowseParams);
  2066. bx_import('BxDolSession');
  2067. if((int)BxDolSession::getInstance()->getValue($sKey) == 1)
  2068. return false;
  2069. $aParams = $this->_prepareParams($aBrowseParams);
  2070. $aParams = array_merge($aParams, array(
  2071. 'per_page' => 1,
  2072. 'filter' => BX_TIMELINE_FILTER_OTHER_VIEWER
  2073. ));
  2074. $aEvents = $this->_oDb->getEvents($aParams);
  2075. if(empty($aEvents) || !is_array($aEvents) || count($aEvents) != 1)
  2076. return false;
  2077. $iValueNew = $aEvents[0]['id'];
  2078. if($iValueNew == $iValue)
  2079. return false;
  2080. if((int)$iInit != 0)
  2081. return array('count' => $iValueNew);
  2082. return array(
  2083. 'count' => $iValueNew, // required (for initialization and visualization)
  2084. 'method' => $this->_oConfig->getJsObjectView($aBrowseParams) . '.showLiveUpdate(oData)', // required (for visualization)
  2085. 'data' => array(
  2086. 'code' => $this->_oTemplate->getLiveUpdate($aBrowseParams, $iProfileId, $iValue, $iValueNew)
  2087. ), // optional, may have some additional data to be passed in JS method provided using 'method' param above.
  2088. );
  2089. }
  2090. /**
  2091. * @page service Service Calls
  2092. * @section bx_timeline Timeline
  2093. * @subsection bx_timeline-other Other
  2094. * @subsubsection bx_timeline-get_live_updates get_live_updates
  2095. *
  2096. * @code bx_srv('bx_timeline', 'get_live_updates', [...]); @endcode
  2097. *
  2098. * Get an array with actual Live Update info. Separate live update notification for each new Event.
  2099. *
  2100. * Note. This way to display live update notifications isn't used for now.
  2101. * See BxTimelineModule::serviceGetLiveUpdate method instead.
  2102. *
  2103. * @return an array with Live Update info.
  2104. *
  2105. * @see BxTimelineModule::serviceGetLiveUpdates
  2106. */
  2107. /**
  2108. * @ref bx_timeline-get_live_updates "get_live_updates"
  2109. */
  2110. public function serviceGetLiveUpdates($aBrowseParams, $iProfileId, $iCount = 0, $iInit = 0)
  2111. {
  2112. $sKey = $this->_oConfig->getLiveUpdateKey($aBrowseParams);
  2113. bx_import('BxDolSession');
  2114. if((int)BxDolSession::getInstance()->getValue($sKey) == 1)
  2115. return false;
  2116. $aParams = $this->_prepareParams($aBrowseParams);
  2117. $aParams['filter'] = BX_TIMELINE_FILTER_OTHER_VIEWER;
  2118. $aParams['count'] = true;
  2119. $iCountNew = $this->_oDb->getEvents($aParams);
  2120. if($iCountNew == $iCount)
  2121. return false;
  2122. if((int)$iInit != 0)
  2123. return array('count' => $iCountNew);
  2124. return array(
  2125. 'count' => $iCountNew, // required (for initialization and visualization)
  2126. 'method' => $this->_oConfig->getJsObjectView($aBrowseParams) . '.showLiveUpdates(oData)', // required (for visualization)
  2127. 'data' => array(
  2128. 'code' => $this->_oTemplate->getLiveUpdates($aBrowseParams, $iProfileId, $iCount, $iCountNew)
  2129. ), // optional, may have some additional data to be passed in JS method provided using 'method' param above.
  2130. );
  2131. }
  2132. /**
  2133. * @page service Service Calls
  2134. * @section bx_timeline Accounts
  2135. * @subsection bx_timeline-other Other
  2136. * @subsubsection bx_timeline-get_menu_addon_manage_tools get_menu_addon_manage_tools
  2137. *
  2138. * @code bx_srv('bx_timeline', 'get_menu_addon_manage_tools', [...]); @endcode
  2139. *
  2140. * Get number of 'hidden' events for User End -> Dasboard page -> Manage block.
  2141. *
  2142. * @return integer number of 'hidden' events
  2143. *
  2144. * @see BxTimelineModule::serviceGetMenuAddonManageTools
  2145. */
  2146. /**
  2147. * @ref bx_timeline-get_menu_addon_manage_tools "get_menu_addon_manage_tools"
  2148. */
  2149. public function serviceGetMenuAddonManageTools()
  2150. {
  2151. bx_import('SearchResult', $this->_aModule);
  2152. $sClass = $this->_aModule['class_prefix'] . 'SearchResult';
  2153. $oSearch = new $sClass();
  2154. $oSearch->fillFilters(array(
  2155. 'status' => BX_TIMELINE_STATUS_HIDDEN
  2156. ));
  2157. $oSearch->unsetPaginate();
  2158. return $oSearch->getNum();
  2159. }
  2160. /*
  2161. * COMMON METHODS
  2162. */
  2163. public function deleteEvent($aEvent)
  2164. {
  2165. if(empty($aEvent) || !is_array($aEvent) || !$this->_oDb->deleteEvent(array('id' => (int)$aEvent['id'])))
  2166. return false;
  2167. $this->onDelete($aEvent);
  2168. return true;
  2169. }
  2170. public function addAttachLink($aValues, $sDisplay = false)
  2171. {
  2172. $CNF = &$this->_oConfig->CNF;
  2173. if(!$sDisplay)
  2174. $sDisplay = $this->_oConfig->getObject('form_display_attach_link_add');
  2175. $oForm = BxDolForm::getObjectInstance($this->_oConfig->getObject('form_attach_link'), $sDisplay, $this->_oTemplate);
  2176. if(!$oForm)
  2177. return array('message' => '_sys_txt_error_occured');
  2178. $oForm->aFormAttrs['method'] = BX_DOL_FORM_METHOD_SPECIFIC;
  2179. $oForm->aParams['csrf']['disable'] = true;
  2180. if(!empty($oForm->aParams['db']['submit_name'])) {
  2181. $sSubmitName = $oForm->aParams['db']['submit_name'];
  2182. if(!isset($oForm->aInputs[$sSubmitName])) {
  2183. if(isset($oForm->aInputs[$CNF['FIELD_CONTROLS']]))
  2184. foreach($oForm->aInputs[$CNF['FIELD_CONTROLS']] as $mixedIndex => $aInput) {
  2185. if(!is_numeric($mixedIndex) || empty($aInput['name']) || $aInput['name'] != $sSubmitName)
  2186. continue;
  2187. $aValues[$sSubmitName] = $aInput['value'];
  2188. }
  2189. }
  2190. else
  2191. $aValues[$sSubmitName] = $oForm->aInputs[$sSubmitName]['value'];
  2192. }
  2193. $oForm->aInputs['url']['checker']['params']['preg'] = $this->_oConfig->getPregPattern('url');
  2194. $oForm->initChecker(array(), $aValues);
  2195. if(!$oForm->isSubmittedAndValid())
  2196. return array('message' => '_sys_txt_error_occured');
  2197. return $this->_addLink($oForm);
  2198. }
  2199. public function getFormAttachLink()
  2200. {
  2201. $oForm = BxDolForm::getObjectInstance($this->_oConfig->getObject('form_attach_link'), $this->_oConfig->getObject('form_display_attach_link_add'), $this->_oTemplate);
  2202. $oForm->aFormAttrs['action'] = BX_DOL_URL_ROOT . $this->_oConfig->getBaseUri() . 'submit_attach_link_form/';
  2203. $oForm->aInputs['url']['checker']['params']['preg'] = $this->_oConfig->getPregPattern('url');
  2204. $oForm->initChecker();
  2205. if($oForm->isSubmittedAndValid())
  2206. return $this->_addLink($oForm);
  2207. return array('form' => $oForm->getCode(), 'form_id' => $oForm->id);
  2208. }
  2209. public function getFormPost($aParams = array())
  2210. {
  2211. $iUserId = $this->getUserId();
  2212. $oForm = $this->getFormPostObject($aParams);
  2213. $oForm->initChecker();
  2214. $bAjaxMode = $oForm->isAjaxMode();
  2215. $bDynamicMode = $bAjaxMode;
  2216. if($oForm->isSubmittedAndValid()) {
  2217. list($sUserName) = $this->getUserInfo($iUserId);
  2218. $sType = $oForm->getCleanValue('type');
  2219. $sType = $this->_oConfig->getPrefix('common_post') . $sType;
  2220. BxDolForm::setSubmittedValue('type', $sType, $oForm->aFormAttrs['method']);
  2221. $aContent = array();
  2222. //--- Process Text ---//
  2223. $sText = $oForm->getCleanValue('text');
  2224. $sText = $this->_prepareTextForSave($sText);
  2225. $bText = !empty($sText);
  2226. if($bText)
  2227. $aContent['text'] = $sText;
  2228. //--- Process Context and Privacy ---//
  2229. $iOwnerId = (int)$oForm->getCleanValue('owner_id');
  2230. $iObjectPrivacyView = (int)$oForm->getCleanValue('object_privacy_view');
  2231. $iObjectPrivacyViewDefault = $this->_oConfig->getPrivacyViewDefault('object');
  2232. if(empty($iObjectPrivacyView))
  2233. $iObjectPrivacyView = $iObjectPrivacyViewDefault;
  2234. else if($iObjectPrivacyView < 0)
  2235. $iOwnerId = abs($iObjectPrivacyView);
  2236. //--- Process Link ---//
  2237. $aLinkIds = $oForm->getCleanValue('link');
  2238. $bLinkIds = !empty($aLinkIds) && is_array($aLinkIds);
  2239. //--- Process Media ---//
  2240. $aPhotoIds = $oForm->getCleanValue(BX_TIMELINE_MEDIA_PHOTO);
  2241. $bPhotoIds = !empty($aPhotoIds) && is_array($aPhotoIds);
  2242. $aVideoIds = $oForm->getCleanValue(BX_TIMELINE_MEDIA_VIDEO);
  2243. $bVideoIds = !empty($aVideoIds) && is_array($aVideoIds);
  2244. if(!$bText && !$bLinkIds && !$bPhotoIds && !$bVideoIds) {
  2245. $oForm->aInputs['text']['error'] = _t('_bx_timeline_txt_err_empty_post');
  2246. $oForm->setValid(false);
  2247. return $this->_prepareResponse(array('form' => $oForm->getCode($bDynamicMode), 'form_id' => $oForm->id), $bAjaxMode);
  2248. }
  2249. $sTitle = $bText ? $this->_oConfig->getTitle($sText) : $this->_oConfig->getTitleDefault($bLinkIds, $bPhotoIds, $bVideoIds);
  2250. $sDescription = _t('_bx_timeline_txt_user_added_sample', '{profile_name}', _t('_bx_timeline_txt_sample_with_article'));
  2251. /**
  2252. * Unset 'text' input because its data was already processed
  2253. * and will be saved via additional values which were passed
  2254. * to BxDolForm::insert method.
  2255. */
  2256. unset($oForm->aInputs['text']);
  2257. $iId = $oForm->insert(array(
  2258. 'owner_id' => $iOwnerId,
  2259. 'object_id' => $iUserId,
  2260. 'object_privacy_view' => $iObjectPrivacyView,
  2261. 'content' => serialize($aContent),
  2262. 'title' => $sTitle,
  2263. 'description' => $sDescription
  2264. ));
  2265. if(!empty($iId)) {
  2266. $aContent = array_merge($aContent, array(
  2267. 'timeline_group' => array(
  2268. 'by' => $this->getName() . '_' . $iUserId . '_' . $iId,
  2269. 'field' => 'owner_id'
  2270. )
  2271. ));
  2272. $this->_oDb->updateEvent(array('content' => serialize($aContent)), array('id' => $iId));
  2273. //--- Process Meta ---//
  2274. $oMetatags = BxDolMetatags::getObjectInstance($this->_oConfig->getObject('metatags'));
  2275. if($bText)
  2276. $oMetatags->metaAdd($iId, $sText);
  2277. $oMetatags->locationsAddFromForm($iId, $this->_oConfig->CNF['FIELD_LOCATION_PREFIX']);
  2278. //--- Process Link ---//
  2279. if($bLinkIds)
  2280. foreach($aLinkIds as $iLinkId)
  2281. $this->_oDb->saveLink($iId, $iLinkId);
  2282. //--- Process Media ---//
  2283. if($bPhotoIds)
  2284. $this->_saveMedia(BX_TIMELINE_MEDIA_PHOTO, $iId, $aPhotoIds);
  2285. if($bVideoIds)
  2286. $this->_saveMedia(BX_TIMELINE_MEDIA_VIDEO, $iId, $aVideoIds);
  2287. $this->onPost($iId);
  2288. return $this->_prepareResponse(array('id' => $iId), $bAjaxMode, array(
  2289. 'redirect' => $this->_oConfig->getItemViewUrl(array('id' => $iId))
  2290. ));
  2291. }
  2292. return $this->_prepareResponse(array('message' => _t('_bx_timeline_txt_err_cannot_perform_action')), $bAjaxMode);
  2293. }
  2294. return $this->_prepareResponse(array('form' => $oForm->getCode($bDynamicMode), 'form_id' => $oForm->id), $bAjaxMode && $oForm->isSubmitted());
  2295. }
  2296. public function getFormEdit($iId, $aParams = array(), $aBrowseParams = array())
  2297. {
  2298. $CNF = &$this->_oConfig->CNF;
  2299. $sJsObjectView = $this->_oConfig->getJsObjectView($aBrowseParams);
  2300. $aEvent = $this->_oDb->getEvents(array('browse' => 'id', 'value' => $iId));
  2301. if(empty($aEvent) || !is_array($aEvent))
  2302. return array();
  2303. $aContent = unserialize($aEvent['content']);
  2304. if(is_array($aContent) && !empty($aContent['text']))
  2305. $aEvent['text'] = $aContent['text'];
  2306. $bDynamicMode = isset($aParams['dynamic_mode']) ? (bool)$aParams['dynamic_mode'] : false;
  2307. $sFormObject = !empty($aParams['form_object']) ? $aParams['form_object'] : 'form_post';
  2308. $sFormDisplay = !empty($aParams['form_display']) ? $aParams['form_display'] : 'form_display_post_edit';
  2309. $oForm = BxDolForm::getObjectInstance($this->_oConfig->getObject($sFormObject), $this->_oConfig->getObject($sFormDisplay), $this->_oTemplate);
  2310. $oForm->setId($this->_oConfig->getHtmlIds('view', 'edit_form') . $iId);
  2311. $oForm->aFormAttrs['action'] = BX_DOL_URL_ROOT . $this->_oConfig->getBaseUri() . 'edit/' . $iId ;
  2312. if(!empty($aBrowseParams) && is_array($aBrowseParams))
  2313. $oForm->aFormAttrs['action'] = $this->_oConfig->addBrowseParams($oForm->aFormAttrs['action'], $aBrowseParams);
  2314. foreach($oForm->aInputs[$CNF['FIELD_CONTROLS']] as $mixedIndex => $aInput) {
  2315. if(!is_numeric($mixedIndex))
  2316. continue;
  2317. $oForm->aInputs[$CNF['FIELD_CONTROLS']][$mixedIndex]['attrs'] = bx_replace_markers($aInput['attrs'], array(
  2318. 'js_object_view' => $sJsObjectView,
  2319. 'content_id' => $iId
  2320. ));
  2321. }
  2322. $oForm->initChecker($aEvent);
  2323. if($oForm->isSubmittedAndValid()) {
  2324. $aContent = array();
  2325. //--- Process Text ---//
  2326. $sText = $oForm->getCleanValue('text');
  2327. $sText = $this->_prepareTextForSave($sText);
  2328. $bText = !empty($sText);
  2329. unset($oForm->aInputs['text']);
  2330. if($bText)
  2331. $aContent['text'] = $sText;
  2332. $aValsToAdd = array(
  2333. 'content' => serialize($aContent)
  2334. );
  2335. //--- Process Privacy ---//
  2336. $iObjectPrivacyView = (int)$oForm->getCleanValue('object_privacy_view');
  2337. $iObjectPrivacyViewDefault = $this->_oConfig->getPrivacyViewDefault('object');
  2338. if(empty($iObjectPrivacyView))
  2339. $aValsToAdd = array_merge($aValsToAdd, array(
  2340. 'object_privacy_view' => $iObjectPrivacyViewDefault
  2341. ));
  2342. else if($iObjectPrivacyView < 0)
  2343. $aValsToAdd = array_merge($aValsToAdd, array(
  2344. 'owner_id' => abs($iObjectPrivacyView),
  2345. 'object_privacy_view' => $iObjectPrivacyViewDefault
  2346. ));
  2347. if(!$oForm->update($iId, $aValsToAdd))
  2348. return array('message' => _t('_bx_timeline_txt_err_cannot_perform_action'));
  2349. $oMetatags = BxDolMetatags::getObjectInstance($this->_oConfig->getObject('metatags'));
  2350. if($bText)
  2351. $oMetatags->metaAdd($iId, $sText);
  2352. $oMetatags->locationsAddFromForm($iId, $this->_oConfig->CNF['FIELD_LOCATION_PREFIX']);
  2353. $this->getCacheItemObject()->removeAllByPrefix($this->_oConfig->getPrefix('cache_item') . $iId);
  2354. $this->_oDb->deleteCache(array('event_id' => $iId));
  2355. return array(
  2356. 'id' => $iId
  2357. );
  2358. }
  2359. return array(
  2360. 'id' => $iId,
  2361. 'form' => $oForm->getCode($bDynamicMode),
  2362. 'form_id' => $oForm->id,
  2363. 'eval' => $sJsObjectView . '.onEditPost(oData)'
  2364. );
  2365. }
  2366. public function getFormPostObject($aParams)
  2367. {
  2368. $sFormObject = !empty($aParams['form_object']) ? $aParams['form_object'] : 'form_post';
  2369. $sFormDisplay = !empty($aParams['form_display']) ? $aParams['form_display'] : 'form_display_post_add';
  2370. $oForm = BxDolForm::getObjectInstance($this->_oConfig->getObject($sFormObject), $this->_oConfig->getObject($sFormDisplay), $this->_oTemplate);
  2371. /**
  2372. * Note. 'ajax_mode' parameter isn't checked because
  2373. * timeline post form works as Ajax form by default.
  2374. */
  2375. $sParamsKey = 'visibility_autoselect';
  2376. if(isset($aParams[$sParamsKey]) && (bool)$aParams[$sParamsKey] === true)
  2377. $oForm->setVisibilityAutoselect((bool)$aParams[$sParamsKey]);
  2378. $oForm->init();
  2379. return $oForm;
  2380. }
  2381. public function getCmtsObject($sSystem, $iId)
  2382. {
  2383. if(empty($sSystem) || (int)$iId == 0)
  2384. return false;
  2385. $oCmts = BxDolCmts::getObjectInstance($sSystem, $iId, true, $this->_oTemplate);
  2386. if(!$oCmts || !$oCmts->isEnabled())
  2387. return false;
  2388. return $oCmts;
  2389. }
  2390. public function getViewObject($sSystem, $iId)
  2391. {
  2392. if(empty($sSystem) || (int)$iId == 0)
  2393. return false;
  2394. $oView = BxDolView::getObjectInstance($sSystem, $iId, true, $this->_oTemplate);
  2395. if(!$oView || !$oView->isEnabled())
  2396. return false;
  2397. return $oView;
  2398. }
  2399. public function getVoteObject($sSystem, $iId)
  2400. {
  2401. if(empty($sSystem) || (int)$iId == 0)
  2402. return false;
  2403. $oVote = BxDolVote::getObjectInstance($sSystem, $iId, true, $this->_oTemplate);
  2404. if(!$oVote || !$oVote->isEnabled())
  2405. return false;
  2406. return $oVote;
  2407. }
  2408. public function getReactionObject($sSystem, $iId)
  2409. {
  2410. if(empty($sSystem) || (int)$iId == 0)
  2411. return false;
  2412. $oReaction = BxDolVote::getObjectInstance($sSystem, $iId, true, $this->_oTemplate);
  2413. if(!$oReaction || !$oReaction->isEnabled())
  2414. return false;
  2415. return $oReaction;
  2416. }
  2417. public function getScoreObject($sSystem, $iId)
  2418. {
  2419. if(empty($sSystem) || (int)$iId == 0)
  2420. return false;
  2421. $oScore = BxDolScore::getObjectInstance($sSystem, $iId, true, $this->_oTemplate);
  2422. if(!$oScore || !$oScore->isEnabled())
  2423. return false;
  2424. return $oScore;
  2425. }
  2426. public function getReportObject($sSystem, $iId)
  2427. {
  2428. if(empty($sSystem) || (int)$iId == 0)
  2429. return false;
  2430. $oReport = BxDolReport::getObjectInstance($sSystem, $iId, true, $this->_oTemplate);
  2431. if(!$oReport || !$oReport->isEnabled())
  2432. return false;
  2433. return $oReport;
  2434. }
  2435. public function getAttachmentsMenuObject()
  2436. {
  2437. $oMenu = BxDolMenu::getObjectInstance($this->_oConfig->getObject('menu_post_attachments'), $this->_oTemplate);
  2438. $oMenu->addMarkers(array(
  2439. 'js_object' => $this->_oConfig->getJsObject('post'),
  2440. ));
  2441. return $oMenu;
  2442. }
  2443. public function getManageMenuObject()
  2444. {
  2445. return BxDolMenu::getObjectInstance($this->_oConfig->getObject('menu_item_manage'), $this->_oTemplate);
  2446. }
  2447. public function getCacheItemObject()
  2448. {
  2449. $oCacheEngine = bx_instance('BxDolCache' . $this->_oConfig->getCacheItemEngine());
  2450. if(!$oCacheEngine->isAvailable())
  2451. $oCacheEngine = bx_instance('BxDolCacheFile');
  2452. return $oCacheEngine;
  2453. }
  2454. //--- Check permissions methods ---//
  2455. public function serviceCheckAllowedViewForProfile ($aDataEntry, $isPerformAction = false, $iProfileId = false)
  2456. {
  2457. if(!$iProfileId)
  2458. $iProfileId = $this->_iProfileId;
  2459. $CNF = &$this->_oConfig->CNF;
  2460. // moderator and owner always have access
  2461. $iOwnerId = (int)$aDataEntry['owner_id'];
  2462. if(!empty($iProfileId) && (abs($iOwnerId) == (int)$iProfileId || $this->isModerator()))
  2463. return CHECK_ACTION_RESULT_ALLOWED;
  2464. // check ACL
  2465. if($iOwnerId != 0 && ($oOwner = BxDolProfile::getInstanceMagic($iOwnerId)) !== false) {
  2466. $mixedCheckResult = BxDolService::call($oOwner->getModule(), 'check_allowed_with_content_for_profile', array('view', $oOwner->getContentId(), $iProfileId));
  2467. if($mixedCheckResult !== CHECK_ACTION_RESULT_ALLOWED)
  2468. return $mixedCheckResult;
  2469. }
  2470. // check privacy
  2471. if(!empty($CNF['OBJECT_PRIVACY_VIEW'])) {
  2472. $oPrivacy = BxDolPrivacy::getObjectInstance($CNF['OBJECT_PRIVACY_VIEW']);
  2473. if($oPrivacy && !$oPrivacy->check($aDataEntry[$CNF['FIELD_ID']], $iProfileId))
  2474. return _t('_sys_access_denied_to_private_content');
  2475. }
  2476. // check alert to allow custom checks
  2477. $mixedResult = null;
  2478. bx_alert('system', 'check_allowed_view', 0, 0, array('module' => $this->getName(), 'content_info' => $aDataEntry, 'profile_id' => $iProfileId, 'override_result' => &$mixedResult));
  2479. if($mixedResult !== null)
  2480. return $mixedResult;
  2481. return CHECK_ACTION_RESULT_ALLOWED;
  2482. }
  2483. public function isModerator()
  2484. {
  2485. $sModule = $this->getName();
  2486. $iUserId = (int)$this->getUserId();
  2487. $aCheckResult = checkActionModule($iUserId, 'edit', $sModule);
  2488. if($aCheckResult[CHECK_ACTION_RESULT] === CHECK_ACTION_RESULT_ALLOWED)
  2489. return true;
  2490. $aCheckResult = checkActionModule($iUserId, 'delete', $sModule);
  2491. if($aCheckResult[CHECK_ACTION_RESULT] === CHECK_ACTION_RESULT_ALLOWED)
  2492. return true;
  2493. return false;
  2494. }
  2495. public function isAllowedPost($bPerform = false)
  2496. {
  2497. if(isAdmin())
  2498. return true;
  2499. $iUserId = $this->getUserId();
  2500. $aCheckResult = checkActionModule($iUserId, 'post', $this->getName(), $bPerform);
  2501. if($aCheckResult[CHECK_ACTION_RESULT] !== CHECK_ACTION_RESULT_ALLOWED)
  2502. return $aCheckResult[CHECK_ACTION_MESSAGE];
  2503. if(!empty($this->_iOwnerId) && ($oProfileOwner = BxDolProfile::getInstance($this->_iOwnerId)) !== false) {
  2504. if($oProfileOwner->checkAllowedPostInProfile() !== CHECK_ACTION_RESULT_ALLOWED)
  2505. return _t('_sys_txt_access_denied');
  2506. bx_alert($oProfileOwner->getModule(), $this->_oConfig->getUri() . '_post', $oProfileOwner->id(), $iUserId, array('check_result' => &$aCheckResult));
  2507. }
  2508. return $aCheckResult[CHECK_ACTION_RESULT] !== CHECK_ACTION_RESULT_ALLOWED ? $aCheckResult[CHECK_ACTION_MESSAGE] : true;
  2509. }
  2510. public function isAllowedView($aEvent, $bPerform = false)
  2511. {
  2512. $CNF = $this->_oConfig->CNF;
  2513. if((int)$aEvent[$CNF['FIELD_OWNER_ID']] == 0)
  2514. return true;
  2515. $oProfileOwner = BxDolProfile::getInstance($aEvent[$CNF['FIELD_OWNER_ID']]);
  2516. if($oProfileOwner && $oProfileOwner->checkAllowedProfileView() !== CHECK_ACTION_RESULT_ALLOWED)
  2517. return false;
  2518. return true;
  2519. }
  2520. public function isAllowedEdit($aEvent, $bPerform = false)
  2521. {
  2522. if(!isLogged())
  2523. return false;
  2524. //--- System posts and Reposts cannot be edited at all.
  2525. if(!$this->_oConfig->isCommon($aEvent['type'], $aEvent['action']) || $aEvent['type'] == $this->_oConfig->getPrefix('common_post') . 'repost')
  2526. return false;
  2527. if(isAdmin())
  2528. return true;
  2529. $iUserId = (int)$this->getUserId();
  2530. $iOwnerId = (int)$aEvent['owner_id'];
  2531. $iObjectId = abs((int)$aEvent['object_id']);
  2532. if($iObjectId == $iUserId && $this->_oConfig->isAllowEdit())
  2533. return true;
  2534. $aCheckResult = checkActionModule($iUserId, 'edit', $this->getName(), $bPerform);
  2535. if(!empty($iOwnerId) && ($oProfileOwner = BxDolProfile::getInstance($iOwnerId)) !== false)
  2536. bx_alert($oProfileOwner->getModule(), $this->_oConfig->getUri() . '_edit', $oProfileOwner->id(), $iUserId, array('check_result' => &$aCheckResult));
  2537. return $aCheckResult[CHECK_ACTION_RESULT] !== CHECK_ACTION_RESULT_ALLOWED ? $aCheckResult[CHECK_ACTION_MESSAGE] : true;
  2538. }
  2539. public function isAllowedDelete($aEvent, $bPerform = false)
  2540. {
  2541. if(!isLogged())
  2542. return false;
  2543. if(isAdmin())
  2544. return true;
  2545. $iUserId = (int)$this->getUserId();
  2546. $iOwnerId = (int)$aEvent['owner_id'];
  2547. $iObjectId = abs((int)$aEvent['object_id']);
  2548. if((($iOwnerId == $iUserId && $this->_oConfig->isAllowDelete()) || ($this->_oConfig->isCommon($aEvent['type'], $aEvent['action']) && $iObjectId == $iUserId)))
  2549. return true;
  2550. $aCheckResult = checkActionModule($iUserId, 'delete', $this->getName(), $bPerform);
  2551. if(!empty($iOwnerId) && ($oProfileOwner = BxDolProfile::getInstance($iOwnerId)) !== false)
  2552. bx_alert($oProfileOwner->getModule(), $this->_oConfig->getUri() . '_delete', $oProfileOwner->id(), $iUserId, array('check_result' => &$aCheckResult));
  2553. return $aCheckResult[CHECK_ACTION_RESULT] !== CHECK_ACTION_RESULT_ALLOWED ? $aCheckResult[CHECK_ACTION_MESSAGE] : true;
  2554. }
  2555. public function isAllowedComment($aEvent, $bPerform = false)
  2556. {
  2557. $mixedComments = $this->getCommentsData($aEvent['comments']);
  2558. if($mixedComments === false)
  2559. return false;
  2560. list($sSystem, $iObjectId) = $mixedComments;
  2561. $oCmts = $this->getCmtsObject($sSystem, $iObjectId);
  2562. if($oCmts->isViewAllowed() !== CHECK_ACTION_RESULT_ALLOWED)
  2563. return false;
  2564. $oCmts->addCssJs();
  2565. $bResult = true;
  2566. if(!empty($aEvent['owner_id']) && $this->_oConfig->isCommon($aEvent['type'], $aEvent['action'])) {
  2567. $oProfileOwner = BxDolProfile::getInstance($aEvent['owner_id']);
  2568. if($oProfileOwner !== false) {
  2569. if($oProfileOwner->checkAllowedPostInProfile() !== CHECK_ACTION_RESULT_ALLOWED)
  2570. return false;
  2571. bx_alert($oProfileOwner->getModule(), $this->_oConfig->getUri() . '_comment', $oProfileOwner->id(), (int)$this->getUserId(), array('result' => &$bResult));
  2572. }
  2573. }
  2574. return $bResult;
  2575. }
  2576. public function isAllowedViewCounter($aEvent, $bPerform = false)
  2577. {
  2578. $mixedViews = $this->getViewsData($aEvent['views']);
  2579. if($mixedViews === false)
  2580. return false;
  2581. list($sSystem, $iObjectId) = $mixedViews;
  2582. $oView = $this->getViewObject($sSystem, $iObjectId);
  2583. if(!$oView->isAllowedViewView($bPerform))
  2584. return false;
  2585. $bResult = true;
  2586. if(!empty($aEvent['owner_id']) && ($oProfileOwner = BxDolProfile::getInstance($aEvent['owner_id'])) !== false)
  2587. bx_alert($oProfileOwner->getModule(), $this->_oConfig->getUri() . '_view_counter', $oProfileOwner->id(), (int)$this->getUserId(), array('result' => &$bResult));
  2588. return $bResult;
  2589. }
  2590. public function isAllowedVote($aEvent, $bPerform = false)
  2591. {
  2592. $mixedVotes = $this->getVotesData($aEvent['votes']);
  2593. if($mixedVotes === false)
  2594. return false;
  2595. list($sSystem, $iObjectId) = $mixedVotes;
  2596. $oVote = $this->getVoteObject($sSystem, $iObjectId);
  2597. if(!$oVote->isAllowedVote($bPerform))
  2598. return false;
  2599. $bResult = true;
  2600. if(!empty($aEvent['owner_id']) && ($oProfileOwner = BxDolProfile::getInstance($aEvent['owner_id'])) !== false)
  2601. bx_alert($oProfileOwner->getModule(), $this->_oConfig->getUri() . '_vote', $oProfileOwner->id(), (int)$this->getUserId(), array('result' => &$bResult));
  2602. return $bResult;
  2603. }
  2604. public function isAllowedReaction($aEvent, $bPerform = false)
  2605. {
  2606. $mixedReactions = $this->getReactionsData($aEvent['reactions']);
  2607. if($mixedReactions === false)
  2608. return false;
  2609. list($sSystem, $iObjectId) = $mixedReactions;
  2610. $oReaction = $this->getReactionObject($sSystem, $iObjectId);
  2611. if(!$oReaction->isAllowedVote($bPerform))
  2612. return false;
  2613. $bResult = true;
  2614. if(!empty($aEvent['owner_id']) && ($oProfileOwner = BxDolProfile::getInstance($aEvent['owner_id'])) !== false)
  2615. bx_alert($oProfileOwner->getModule(), $this->_oConfig->getUri() . '_reaction', $oProfileOwner->id(), (int)$this->getUserId(), array('result' => &$bResult));
  2616. return $bResult;
  2617. }
  2618. public function isAllowedScore($aEvent, $bPerform = false)
  2619. {
  2620. $mixedScores = $this->getScoresData($aEvent['scores']);
  2621. if($mixedScores === false)
  2622. return false;
  2623. list($sSystem, $iObjectId) = $mixedScores;
  2624. $oScore = $this->getScoreObject($sSystem, $iObjectId);
  2625. if(!$oScore->isAllowedVote($bPerform))
  2626. return false;
  2627. $bResult = true;
  2628. if(!empty($aEvent['owner_id']) && ($oProfileOwner = BxDolProfile::getInstance($aEvent['owner_id'])) !== false)
  2629. bx_alert($oProfileOwner->getModule(), $this->_oConfig->getUri() . '_score', $oProfileOwner->id(), (int)$this->getUserId(), array('result' => &$bResult));
  2630. return $bResult;
  2631. }
  2632. public function isAllowedReport($aEvent, $bPerform = false)
  2633. {
  2634. $mixedReports = $this->getReportsData($aEvent['reports']);
  2635. if($mixedReports === false)
  2636. return false;
  2637. list($sSystem, $iObjectId) = $mixedReports;
  2638. $oReport = $this->getReportObject($sSystem, $iObjectId);
  2639. if(!$oReport->isAllowedReport($bPerform))
  2640. return false;
  2641. $bResult = true;
  2642. if(!empty($aEvent['owner_id']) && ($oProfileOwner = BxDolProfile::getInstance($aEvent['owner_id'])) !== false)
  2643. bx_alert($oProfileOwner->getModule(), $this->_oConfig->getUri() . '_report', $oProfileOwner->id(), (int)$this->getUserId(), array('result' => &$bResult));
  2644. return $bResult;
  2645. }
  2646. public function isAllowedRepost($aEvent, $bPerform = false)
  2647. {
  2648. $iUserId = (int)$this->getUserId();
  2649. if($iUserId == 0)
  2650. return false;
  2651. $iPrivacy = (int)$aEvent['object_privacy_view'];
  2652. if($iPrivacy >= 0 && !in_array($iPrivacy, array(BX_DOL_PG_ALL, BX_DOL_PG_MEMBERS)))
  2653. return false;
  2654. if(isAdmin())
  2655. return true;
  2656. $aCheckResult = checkActionModule($iUserId, 'repost', $this->getName(), $bPerform);
  2657. if(!empty($aEvent['owner_id']) && ($oProfileOwner = BxDolProfile::getInstance($aEvent['owner_id'])) !== false)
  2658. bx_alert($oProfileOwner->getModule(), $this->_oConfig->getUri() . '_repost', $oProfileOwner->id(), $iUserId, array('check_result' => &$aCheckResult));
  2659. return $aCheckResult[CHECK_ACTION_RESULT] !== CHECK_ACTION_RESULT_ALLOWED ? $aCheckResult[CHECK_ACTION_MESSAGE] : true;
  2660. }
  2661. public function isAllowedSend($aEvent, $bPerform = false)
  2662. {
  2663. if(!$this->_oDb->isEnabledByName('bx_convos'))
  2664. return false;
  2665. if(isAdmin())
  2666. return true;
  2667. $iUserId = (int)$this->getUserId();
  2668. if($iUserId == 0)
  2669. return false;
  2670. $aCheckResult = checkActionModule($iUserId, 'send', $this->getName(), $bPerform);
  2671. if(!empty($aEvent['owner_id']) && ($oProfileOwner = BxDolProfile::getInstance($aEvent['owner_id'])) !== false)
  2672. bx_alert($oProfileOwner->getModule(), $this->_oConfig->getUri() . '_send', $oProfileOwner->id(), $iUserId, array('check_result' => &$aCheckResult));
  2673. return $aCheckResult[CHECK_ACTION_RESULT] !== CHECK_ACTION_RESULT_ALLOWED ? $aCheckResult[CHECK_ACTION_MESSAGE] : true;
  2674. }
  2675. /**
  2676. * Pin - "Pin here" - pin the post on Profile Timeline for profile owner.
  2677. * Can be done by profile owner for himself or by admin for profile owner to see.
  2678. * @param type $aEvent
  2679. * @param type $bPerform
  2680. * @return boolean
  2681. */
  2682. public function isAllowedPin($aEvent, $bPerform = false)
  2683. {
  2684. if((int)$aEvent['pinned'] != 0)
  2685. return false;
  2686. return $this->_isAllowedPin($aEvent, $bPerform);
  2687. }
  2688. public function isAllowedUnpin($aEvent, $bPerform = false)
  2689. {
  2690. if((int)$aEvent['pinned'] == 0)
  2691. return false;
  2692. return $this->_isAllowedPin($aEvent, $bPerform);
  2693. }
  2694. /**
  2695. * Stick - "Pin for All" - pin the post on Public Timeline for everybody to see.
  2696. * Is available for Administrators/Moderators only.
  2697. * @param type $aEvent
  2698. * @param type $bPerform
  2699. * @return boolean
  2700. */
  2701. public function isAllowedStick($aEvent, $bPerform = false)
  2702. {
  2703. if((int)$aEvent['sticked'] != 0)
  2704. return false;
  2705. return $this->_isAllowedStick($aEvent, $bPerform);
  2706. }
  2707. public function isAllowedUnstick($aEvent, $bPerform = false)
  2708. {
  2709. if((int)$aEvent['sticked'] == 0)
  2710. return false;
  2711. return $this->_isAllowedStick($aEvent, $bPerform);
  2712. }
  2713. public function isAllowedPromote($aEvent, $bPerform = false)
  2714. {
  2715. if((int)$aEvent['promoted'] != 0)
  2716. return false;
  2717. return $this->_isAllowedPromote($aEvent, $bPerform);
  2718. }
  2719. public function isAllowedUnpromote($aEvent, $bPerform = false)
  2720. {
  2721. if((int)$aEvent['promoted'] == 0)
  2722. return false;
  2723. return $this->_isAllowedPromote($aEvent, $bPerform);
  2724. }
  2725. public function isAllowedMore($aEvent, $bPerform = false)
  2726. {
  2727. $oMoreMenu = $this->getManageMenuObject();
  2728. $oMoreMenu->setEvent($aEvent);
  2729. return $oMoreMenu->isVisible();
  2730. }
  2731. public function checkAllowedView ($aContentInfo, $isPerformAction = false)
  2732. {
  2733. if(!$this->isAllowedView($aContentInfo, $isPerformAction))
  2734. return _t('_sys_txt_access_denied');
  2735. return CHECK_ACTION_RESULT_ALLOWED;
  2736. }
  2737. public function checkAllowedCommentsView ($aContentInfo, $isPerformAction = false)
  2738. {
  2739. $CNF = $this->_oConfig->CNF;
  2740. $iOwner = (int)$aContentInfo[$CNF['FIELD_OWNER_ID']];
  2741. if($iOwner == 0) //--- in case of Public Timeline.
  2742. return CHECK_ACTION_RESULT_ALLOWED;
  2743. $oOwner = BxDolProfile::getInstance($iOwner);
  2744. if(!$oOwner) //--- in case of non-existed Timeline owner.
  2745. return _t('_sys_txt_access_denied');
  2746. $mixedResult = $oOwner->checkAllowedProfileView();
  2747. if($mixedResult !== CHECK_ACTION_RESULT_ALLOWED)
  2748. return $mixedResult;
  2749. return CHECK_ACTION_RESULT_ALLOWED;
  2750. }
  2751. public function checkAllowedCommentsPost ($aContentInfo, $isPerformAction = false)
  2752. {
  2753. $sError = '_sys_txt_access_denied';
  2754. $aContentInfo = array_merge($aContentInfo, $this->_oTemplate->getDataCached($aContentInfo));
  2755. if($aContentInfo === false)
  2756. return _t($sError);
  2757. if(!$this->isAllowedComment($aContentInfo, $isPerformAction))
  2758. return _t($sError);
  2759. return CHECK_ACTION_RESULT_ALLOWED;
  2760. }
  2761. public function onPost($iContentId)
  2762. {
  2763. $CNF = &$this->_oConfig->CNF;
  2764. $aEvent = $this->_oDb->getEvents(array('browse' => 'id', 'value' => $iContentId));
  2765. if($this->_oConfig->isSystem($aEvent['type'], $aEvent['action'])) {
  2766. //--- Request event's data from content module and update it in the Timeline DB.
  2767. $this->_oTemplate->getDataCached($aEvent);
  2768. $sPostType = 'system';
  2769. $iSenderId = $iObjectAuthorId = (int)$aEvent['owner_id'];
  2770. }
  2771. else {
  2772. $sPostType = 'common';
  2773. $iSenderId = $iObjectAuthorId = (int)$aEvent['object_id'];
  2774. }
  2775. //--- Event -> Post/Defer for Alerts Engine ---//
  2776. $sAction = ($aEvent[$CNF['FIELD_STATUS']] == BX_TIMELINE_STATUS_AWAITING ? 'defer' : 'post') . '_' . $sPostType;
  2777. bx_alert($this->_oConfig->getObject('alert'), $sAction, $iContentId, $iSenderId, array(
  2778. 'owner_id' => $aEvent['owner_id'],
  2779. 'object_author_id' => $iObjectAuthorId,
  2780. 'privacy_view' => $aEvent['object_privacy_view'],
  2781. ));
  2782. //--- Event -> Post for Alerts Engine ---//
  2783. }
  2784. public function onPublished($iContentId)
  2785. {
  2786. $CNF = &$this->_oConfig->CNF;
  2787. $aEvent = $this->_oDb->getEvents(array('browse' => 'id', 'value' => $iContentId));
  2788. //--- Clear Item cache
  2789. $this->getCacheItemObject()->removeAllByPrefix($this->_oConfig->getPrefix('cache_item') . $iContentId);
  2790. //--- Clear Feed cache
  2791. $this->_oDb->deleteCache(array('context_id' => $aEvent[$CNF['FIELD_OWNER_ID']]));
  2792. $this->onPost($iContentId);
  2793. }
  2794. public function onFailed($iContentId)
  2795. {
  2796. $aEvent = $this->_oDb->getEvents(array('browse' => 'id', 'value' => $iContentId));
  2797. //--- Clear Item cache
  2798. $this->getCacheItemObject()->removeAllByPrefix($this->_oConfig->getPrefix('cache_item') . $iContentId);
  2799. if($this->_oConfig->isSystem($aEvent['type'], $aEvent['action'])) {
  2800. //--- Request event's data from content module and update it in the Timeline DB.
  2801. $this->_oTemplate->getDataCached($aEvent);
  2802. $sPostType = 'system';
  2803. $iSenderId = $iObjectAuthorId = (int)$aEvent['owner_id'];
  2804. }
  2805. else {
  2806. $sPostType = 'common';
  2807. $iSenderId = $iObjectAuthorId = (int)$aEvent['object_id'];
  2808. }
  2809. //--- Event -> Fail for Alerts Engine ---//
  2810. bx_alert($this->_oConfig->getObject('alert'), 'fail_' . $sPostType, $iContentId, $iSenderId, array(
  2811. 'owner_id' => $aEvent['owner_id'],
  2812. 'object_author_id' => $iObjectAuthorId,
  2813. 'privacy_view' => $aEvent['object_privacy_view'],
  2814. ));
  2815. //--- Event -> Post for Alerts Engine ---//
  2816. }
  2817. public function onRepost($iContentId, $aReposted = array())
  2818. {
  2819. $aEvent = $this->_oDb->getEvents(array('browse' => 'id', 'value' => $iContentId));
  2820. if(empty($aReposted)) {
  2821. $aContent = unserialize($aEvent['content']);
  2822. $aReposted = $this->_oDb->getReposted($aContent['type'], $aContent['action'], $aContent['object_id']);
  2823. if(empty($aReposted) || !is_array($aReposted))
  2824. return;
  2825. }
  2826. $iUserId = $this->getUserId();
  2827. $this->_oDb->insertRepostTrack($aEvent['id'], $iUserId, $this->getUserIp(), $aReposted['id']);
  2828. $this->_oDb->updateRepostCounter($aReposted['id'], $aReposted['reposts']);
  2829. //--- Timeline -> Update for Alerts Engine ---//
  2830. bx_alert($this->_oConfig->getObject('alert'), 'repost', $aReposted['id'], $iUserId, array(
  2831. 'privacy_view' => $aEvent['object_privacy_view'],
  2832. 'object_author_id' => $aReposted['owner_id'],
  2833. 'repost_id' => $iContentId,
  2834. ));
  2835. //--- Timeline -> Update for Alerts Engine ---//
  2836. }
  2837. public function onDelete($aEvent)
  2838. {
  2839. $CNF = &$this->_oConfig->CNF;
  2840. $iUserId = $this->getUserId();
  2841. $sCommonPostPrefix = $this->_oConfig->getPrefix('common_post');
  2842. $sCommonPostComment = $this->_oConfig->getObject('comment');
  2843. //--- Delete comments for Common posts.
  2844. if($this->_oConfig->isCommon($aEvent['type'], $aEvent['action'])) {
  2845. $oComments = $this->getCmtsObject($sCommonPostComment, $aEvent[$CNF['FIELD_ID']]);
  2846. if($oComments !== false)
  2847. $oComments->onObjectDelete($aEvent[$CNF['FIELD_ID']]);
  2848. }
  2849. //--- Delete attached photos, videos and links when common event was deleted.
  2850. if($aEvent['type'] == $sCommonPostPrefix . BX_TIMELINE_PARSE_TYPE_POST) {
  2851. $this->_deleteMedia(BX_TIMELINE_MEDIA_PHOTO, $aEvent[$CNF['FIELD_ID']]);
  2852. $this->_deleteMedia(BX_TIMELINE_MEDIA_VIDEO, $aEvent[$CNF['FIELD_ID']]);
  2853. $this->_deleteLinks($aEvent[$CNF['FIELD_ID']]);
  2854. }
  2855. //--- Update parent event when repost event was deleted.
  2856. $bRepost = $aEvent['type'] == $sCommonPostPrefix . BX_TIMELINE_PARSE_TYPE_REPOST;
  2857. if($bRepost) {
  2858. $this->_oDb->deleteRepostTrack($aEvent[$CNF['FIELD_ID']]);
  2859. $aContent = unserialize($aEvent['content']);
  2860. $aReposted = $this->_oDb->getReposted($aContent['type'], $aContent['action'], $aContent['object_id']);
  2861. if(!empty($aReposted) && is_array($aReposted))
  2862. $this->_oDb->updateRepostCounter($aReposted[$CNF['FIELD_ID']], $aReposted['reposts'], -1);
  2863. }
  2864. //--- Find and delete repost events when parent event was deleted.
  2865. $bSystem = $this->_oConfig->isSystem($aEvent['type'], $aEvent['action']);
  2866. $aRepostEvents = $this->_oDb->getEvents(array('browse' => 'reposted_by_descriptor', 'type' => $aEvent['type']));
  2867. foreach($aRepostEvents as $aRepostEvent) {
  2868. $aContent = unserialize($aRepostEvent['content']);
  2869. if(isset($aContent['type']) && $aContent['type'] == $aEvent['type'] && isset($aContent['object_id']) && (($bSystem && (int)$aContent['object_id'] == (int)$aEvent['object_id']) || (!$bSystem && (int)$aContent['object_id'] == (int)$aEvent[$CNF['FIELD_ID']])) && (int)$this->_oDb->deleteEvent(array('id' => (int)$aRepostEvent[$CNF['FIELD_ID']])) > 0) {
  2870. $oComments = $this->getCmtsObject($sCommonPostComment, $aRepostEvent[$CNF['FIELD_ID']]);
  2871. if($oComments !== false)
  2872. $oComments->onObjectDelete($aRepostEvent[$CNF['FIELD_ID']]);
  2873. bx_alert($this->_oConfig->getObject('alert'), 'delete_repost', $aEvent[$CNF['FIELD_ID']], $iUserId, array(
  2874. 'repost_id' => $aRepostEvent[$CNF['FIELD_ID']],
  2875. ));
  2876. }
  2877. }
  2878. //--- Delete associated meta.
  2879. $oMetatags = BxDolMetatags::getObjectInstance($this->_oConfig->getObject('metatags'));
  2880. $oMetatags->onDeleteContent($aEvent[$CNF['FIELD_ID']]);
  2881. //--- Delete feed cache.
  2882. $this->_oDb->deleteCache(array('event_id' => $aEvent[$CNF['FIELD_ID']]));
  2883. //--- Delete item cache.
  2884. $sCacheItemKey = $this->_oConfig->getCacheItemKey($aEvent[$CNF['FIELD_ID']]);
  2885. $this->getCacheItemObject()->delData($sCacheItemKey);
  2886. //--- Event -> Delete for Alerts Engine ---//
  2887. if($bRepost)
  2888. bx_alert($this->_oConfig->getObject('alert'), 'delete_repost', $aReposted[$CNF['FIELD_ID']], $iUserId, array(
  2889. 'repost_id' => $aEvent[$CNF['FIELD_ID']],
  2890. ));
  2891. else
  2892. bx_alert($this->_oConfig->getObject('alert'), 'delete', $aEvent[$CNF['FIELD_ID']], $iUserId);
  2893. //--- Event -> Delete for Alerts Engine ---//
  2894. }
  2895. public function getParams($sView = '', $sType = '', $iOwnerId = 0, $iStart = 0, $iPerPage = 0, $sFilter = BX_TIMELINE_FILTER_ALL, $aModules = array(), $iTimeline = 0)
  2896. {
  2897. return $this->_prepareParams(array(
  2898. 'view' => $sView,
  2899. 'type' => $sType,
  2900. 'owner_id' => $iOwnerId,
  2901. 'start' => $iStart,
  2902. 'per_page' => $iPerPage,
  2903. 'timeline' => $iTimeline,
  2904. 'filter' => $sFilter,
  2905. 'modules' => $aModules
  2906. ));
  2907. }
  2908. public function getParamsExt($aParams = array())
  2909. {
  2910. return $this->_prepareParams($aParams);
  2911. }
  2912. public function getViewsData(&$aViews)
  2913. {
  2914. if(empty($aViews) || !is_array($aViews))
  2915. return false;
  2916. $sSystem = isset($aViews['system']) ? $aViews['system'] : '';
  2917. $iObjectId = isset($aViews['object_id']) ? (int)$aViews['object_id'] : 0;
  2918. $iCount = isset($aViews['count']) ? (int)$aViews['count'] : 0;
  2919. if($sSystem == '' || $iObjectId == 0)
  2920. return false;
  2921. return array($sSystem, $iObjectId, $iCount);
  2922. }
  2923. public function getVotesData(&$aVotes)
  2924. {
  2925. if(empty($aVotes) || !is_array($aVotes))
  2926. return false;
  2927. $sSystem = isset($aVotes['system']) ? $aVotes['system'] : '';
  2928. $iObjectId = isset($aVotes['object_id']) ? (int)$aVotes['object_id'] : 0;
  2929. $iCount = isset($aVotes['count']) ? (int)$aVotes['count'] : 0;
  2930. if($sSystem == '' || $iObjectId == 0)
  2931. return false;
  2932. return array($sSystem, $iObjectId, $iCount);
  2933. }
  2934. public function getReactionsData(&$aReactions)
  2935. {
  2936. if(empty($aReactions) || !is_array($aReactions))
  2937. return false;
  2938. $sSystem = isset($aReactions['system']) ? $aReactions['system'] : '';
  2939. $iObjectId = isset($aReactions['object_id']) ? (int)$aReactions['object_id'] : 0;
  2940. $iCount = isset($aReactions['count']) ? (int)$aReactions['count'] : 0;
  2941. if($sSystem == '' || $iObjectId == 0)
  2942. return false;
  2943. return array($sSystem, $iObjectId, $iCount);
  2944. }
  2945. public function getScoresData(&$aScores)
  2946. {
  2947. if(empty($aScores) || !is_array($aScores))
  2948. return false;
  2949. $sSystem = isset($aScores['system']) ? $aScores['system'] : '';
  2950. $iObjectId = isset($aScores['object_id']) ? (int)$aScores['object_id'] : 0;
  2951. $iScore = isset($aScores['score']) ? (int)$aScores['score'] : 0;
  2952. if($sSystem == '' || $iObjectId == 0)
  2953. return false;
  2954. return array($sSystem, $iObjectId, $iScore);
  2955. }
  2956. public function getReportsData(&$aReports)
  2957. {
  2958. if(empty($aReports) || !is_array($aReports))
  2959. return false;
  2960. $sSystem = isset($aReports['system']) ? $aReports['system'] : '';
  2961. $iObjectId = isset($aReports['object_id']) ? (int)$aReports['object_id'] : 0;
  2962. $iCount = isset($aReports['count']) ? (int)$aReports['count'] : 0;
  2963. if($sSystem == '' || $iObjectId == 0)
  2964. return false;
  2965. return array($sSystem, $iObjectId, $iCount);
  2966. }
  2967. public function getCommentsData(&$aComments)
  2968. {
  2969. if(empty($aComments) || !is_array($aComments))
  2970. return false;
  2971. $sSystem = isset($aComments['system']) ? $aComments['system'] : '';
  2972. $iObjectId = isset($aComments['object_id']) ? (int)$aComments['object_id'] : 0;
  2973. $iCount = isset($aComments['count']) ? (int)$aComments['count'] : 0;
  2974. if($sSystem == '' || $iObjectId == 0 || ($iCount == 0 && !isLogged()))
  2975. return false;
  2976. return array($sSystem, $iObjectId, $iCount);
  2977. }
  2978. public function getUserInfo($iUserId = 0)
  2979. {
  2980. $iLoggedId = $this->getUserId();
  2981. $iUserId = (int)$iUserId;
  2982. return parent::getUserInfo($iUserId);
  2983. }
  2984. public function getUserInfoWithBadges($iUserId = 0)
  2985. {
  2986. $iLoggedId = $this->getUserId();
  2987. $iUserId = (int)$iUserId;
  2988. return parent::getUserInfoWithBadges($iUserId);
  2989. }
  2990. public function getEventImages($iEventId)
  2991. {
  2992. $aPhotos = $this->_oDb->getMedia(BX_TIMELINE_MEDIA_PHOTO, $iEventId);
  2993. if(empty($aPhotos) || !is_array($aPhotos))
  2994. return array();
  2995. $oTranscoder = BxDolTranscoderImage::getObjectInstance($this->_oConfig->getObject('transcoder_photos_view'));
  2996. $oTranscoderMedium = BxDolTranscoderImage::getObjectInstance($this->_oConfig->getObject('transcoder_photos_medium'));
  2997. $oTranscoderBig = BxDolTranscoderImage::getObjectInstance($this->_oConfig->getObject('transcoder_photos_big'));
  2998. $aResult = array();
  2999. foreach($aPhotos as $iPhotoId) {
  3000. $sPhotoSrc = $oTranscoder->getFileUrl($iPhotoId);
  3001. $sPhotoSrcMedium = $oTranscoderMedium->getFileUrl($iPhotoId);
  3002. $sPhotoSrcBig = $oTranscoderBig->getFileUrl($iPhotoId);
  3003. if(empty($sPhotoSrcMedium) && !empty($sPhotoSrc))
  3004. $sPhotoSrcMedium = $sPhotoSrc;
  3005. if(empty($sPhotoSrcBig) && !empty($sPhotoSrcMedium))
  3006. $sPhotoSrcBig = $sPhotoSrcMedium;
  3007. $aResult[] = array(
  3008. 'id' => $iPhotoId,
  3009. 'src' => $sPhotoSrc,
  3010. 'src_medium' => $sPhotoSrcMedium,
  3011. 'src_orig' => $sPhotoSrcBig,
  3012. );
  3013. }
  3014. return $aResult;
  3015. }
  3016. public function getEventVideos($iEventId)
  3017. {
  3018. $aVideos = $this->_oDb->getMedia(BX_TIMELINE_MEDIA_VIDEO, $iEventId);
  3019. if(empty($aVideos) || !is_array($aVideos))
  3020. return array();
  3021. $oStorage = BxDolStorage::getObjectInstance($this->_oConfig->getObject('storage_videos'));
  3022. $oTranscoderPoster = BxDolTranscoderVideo::getObjectInstance($this->_oConfig->getObject('transcoder_videos_poster'));
  3023. $oTranscoderMp4 = BxDolTranscoderVideo::getObjectInstance($this->_oConfig->getObject('transcoder_videos_mp4'));
  3024. $oTranscoderMp4Hd = BxDolTranscoderVideo::getObjectInstance($this->_oConfig->getObject('transcoder_videos_mp4_hd'));
  3025. $aResult = array();
  3026. foreach($aVideos as $iVideoId) {
  3027. $sVideoUrl = $oStorage->getFileUrlById($iVideoId);
  3028. $aVideoSize = $oTranscoderMp4Hd->getVideoSize($sVideoUrl);
  3029. $sVideoUrlHd = '';
  3030. if(!empty($aVideoSize) && is_array($aVideoSize) && (int)$aVideoSize['h'] >= 720)
  3031. $sVideoUrlHd = $oTranscoderMp4Hd->getFileUrl($iVideoId);
  3032. $aResult[$iVideoId] = array(
  3033. 'id' => $iVideoId,
  3034. 'src_poster' => $oTranscoderPoster->getFileUrl($iVideoId),
  3035. 'src_mp4' => $oTranscoderMp4->getFileUrl($iVideoId),
  3036. 'src_mp4_hd' => $sVideoUrlHd,
  3037. );
  3038. }
  3039. return $aResult;
  3040. }
  3041. /**
  3042. * Protected Methods
  3043. */
  3044. protected function _serviceGetBlockView($iProfileId = 0, $aBrowseParams = array())
  3045. {
  3046. if(empty($iProfileId) && bx_get('profile_id') !== false)
  3047. $iProfileId = bx_process_input(bx_get('profile_id'), BX_DATA_INT);
  3048. if(empty($iProfileId) && isLogged())
  3049. $iProfileId = bx_get_logged_profile_id();
  3050. $aBrowseParams['owner_id'] = $iProfileId;
  3051. $aBlock = $this->_getBlockView($aBrowseParams);
  3052. if(!empty($aBlock))
  3053. return $aBlock;
  3054. return array('content' => MsgBox(_t('_bx_timeline_txt_msg_no_results')));
  3055. }
  3056. protected function _serviceGetBlockViewProfile($sProfileModule = 'bx_persons', $iProfileContentId = 0, $aBrowseParams = array())
  3057. {
  3058. if(empty($sProfileModule))
  3059. return array();
  3060. if(empty($iProfileContentId) && bx_get('id') !== false)
  3061. $iProfileContentId = bx_process_input(bx_get('id'), BX_DATA_INT);
  3062. $oProfile = BxDolProfile::getInstanceByContentAndType($iProfileContentId, $sProfileModule);
  3063. if(empty($oProfile))
  3064. return array();
  3065. $aBrowseParams['owner_id'] = $oProfile->id();
  3066. return $this->_getBlockView($aBrowseParams);
  3067. }
  3068. protected function _serviceGetBlockViews($aBrowseParams = array())
  3069. {
  3070. $aParams = $this->_prepareParams($aBrowseParams);
  3071. $this->_iOwnerId = $aParams['owner_id'];
  3072. return array(
  3073. 'content' => $this->_oTemplate->getViewsBlock($aParams)
  3074. );
  3075. }
  3076. protected function _serviceGetBlockViewHome($aBrowseParams = array())
  3077. {
  3078. $sRssUrl = BX_DOL_URL_ROOT . $this->_oConfig->getBaseUri() . 'rss/' . $aBrowseParams['type'] . '/';
  3079. BxDolTemplate::getInstance()->addPageRssLink(_t('_bx_timeline_page_title_view_home'), $sRssUrl);
  3080. return $this->_serviceGetBlockViewByType($aBrowseParams);
  3081. }
  3082. protected function _serviceGetBlockViewHot($aBrowseParams = array())
  3083. {
  3084. $sRssUrl = BX_DOL_URL_ROOT . $this->_oConfig->getBaseUri() . 'rss/' . $aBrowseParams['type'] . '/';
  3085. BxDolTemplate::getInstance()->addPageRssLink(_t('_bx_timeline_page_title_view_hot'), $sRssUrl);
  3086. return $this->_serviceGetBlockViewByType($aBrowseParams);
  3087. }
  3088. protected function _serviceGetBlockViewByType($aBrowseParams = array())
  3089. {
  3090. $aParams = $this->_prepareParams($aBrowseParams);
  3091. $this->_iOwnerId = $aParams['owner_id'];
  3092. return array(
  3093. 'content' => $this->_oTemplate->getViewBlock($aParams)
  3094. );
  3095. }
  3096. protected function _getBlockPost($iProfileId, $aParams = array())
  3097. {
  3098. $this->_iOwnerId = $iProfileId;
  3099. if($this->isAllowedPost() !== true)
  3100. return array();
  3101. return array(
  3102. 'content' => $this->_oTemplate->getPostBlock($this->_iOwnerId, $aParams)
  3103. );
  3104. }
  3105. protected function _getBlockView($aBrowseParams = array())
  3106. {
  3107. if(empty($aBrowseParams['owner_id']))
  3108. return array();
  3109. $aParams = $this->_prepareParams($aBrowseParams);
  3110. if(empty($aParams['per_page']))
  3111. $aParams['per_page'] = $this->_oConfig->getPerPage('profile');
  3112. $this->_iOwnerId = $aParams['owner_id'];
  3113. $oProfileOwner = BxDolProfile::getInstance($this->_iOwnerId);
  3114. $mixedResult = $oProfileOwner->checkAllowedProfileView();
  3115. if($mixedResult !== CHECK_ACTION_RESULT_ALLOWED)
  3116. return array('content' => MsgBox($mixedResult));
  3117. list($sUserName) = $this->getUserInfo($aParams['owner_id']);
  3118. $sView = $aParams['view'];
  3119. $sRssUrl = BX_DOL_URL_ROOT . $this->_oConfig->getBaseUri() . 'rss/' . BX_BASE_MOD_NTFS_TYPE_OWNER . '/' . $this->_iOwnerId . '/';
  3120. $sJsObject = $this->_oConfig->getJsObjectView($aParams);
  3121. $aMenu = array(
  3122. array('id' => $sView . '-view-all', 'name' => $sView . '-view-all', 'class' => '', 'link' => 'javascript:void(0)', 'onclick' => 'javascript:' . $sJsObject . '.changeFilter(this)', 'target' => '_self', 'title' => _t('_bx_timeline_menu_item_view_all'), 'active' => 1),
  3123. array('id' => $sView . '-view-owner', 'name' => $sView . '-view-owner', 'class' => '', 'link' => 'javascript:void(0)', 'onclick' => 'javascript:' . $sJsObject . '.changeFilter(this)', 'target' => '_self', 'title' => _t('_bx_timeline_menu_item_view_owner', $sUserName)),
  3124. array('id' => $sView . '-view-other', 'name' => $sView . '-view-other', 'class' => '', 'link' => 'javascript:void(0)', 'onclick' => 'javascript:' . $sJsObject . '.changeFilter(this)', 'target' => '_self', 'title' => _t('_bx_timeline_menu_item_view_other')),
  3125. array('id' => $sView . '-get-rss', 'name' => $sView . '-get-rss', 'class' => '', 'link' => $sRssUrl, 'onclick' => '', 'target' => '_blank', 'title' => _t('_bx_timeline_menu_item_get_rss')),
  3126. );
  3127. $sContent = '';
  3128. bx_alert($oProfileOwner->getModule(), $this->_oConfig->getUri() . '_view', $this->_iOwnerId, $this->getUserId(), array('override_content' => &$sContent, 'params' => &$aParams, 'menu' => &$aMenu));
  3129. $oMenu = new BxTemplMenuInteractive(array('template' => 'menu_interactive_vertical.html', 'menu_id'=> $sView . '-view-all', 'menu_items' => $aMenu));
  3130. $oMenu->setSelected('', $sView . '-view-all');
  3131. if (!$sContent)
  3132. $sContent = $this->_oTemplate->getViewBlock($aParams);
  3133. BxDolTemplate::getInstance()->addPageRssLink(_t('_bx_timeline_page_title_view'), $sRssUrl);
  3134. return array('content' => $sContent, 'menu' => $oMenu);
  3135. }
  3136. protected function _getContentForTimelinePost($aEvent, $aContentInfo, $aBrowseParams = array())
  3137. {
  3138. $CNF = &$this->_oConfig->CNF;
  3139. $iId = (int)$aContentInfo[$CNF['FIELD_ID']];
  3140. $sUrl = BX_DOL_URL_ROOT . BxDolPermalinks::getInstance()->permalink('page.php?i=' . $CNF['URI_VIEW_ENTRY'] . '&id=' . $iId);
  3141. $sText = '';
  3142. if(isset($aContentInfo['content'])){
  3143. $aTmp = unserialize($aContentInfo['content']);
  3144. if(isset($aTmp['text']))
  3145. $sText = $aTmp['text'];
  3146. }
  3147. if(empty($sText) && !empty($aContentInfo[$CNF['FIELD_TITLE']]))
  3148. $sText = $aContentInfo[$CNF['FIELD_TITLE']];
  3149. if(!empty($CNF['OBJECT_METATAGS']) && !empty($sText)) {
  3150. $oMetatags = BxDolMetatags::getObjectInstance($CNF['OBJECT_METATAGS']);
  3151. $sText = $oMetatags->metaParse($iId, $sText);
  3152. }
  3153. return array(
  3154. 'sample' => isset($CNF['T']['txt_sample_single_with_article']) ? $CNF['T']['txt_sample_single_with_article'] : $CNF['T']['txt_sample_single'],
  3155. 'sample_wo_article' => $CNF['T']['txt_sample_single'],
  3156. 'sample_action' => isset($CNF['T']['txt_sample_action']) ? $CNF['T']['txt_sample_action'] : '',
  3157. 'url' => $sUrl,
  3158. 'title' => '',
  3159. 'text' => $sText,
  3160. 'images' => array(),
  3161. 'images_attach' => $this->getEventImages($iId),
  3162. 'videos' => array(),
  3163. 'videos_attach' => $this->getEventVideos($iId),
  3164. 'files' => array(),
  3165. 'files_attach' => array()
  3166. );
  3167. }
  3168. protected function _isAllowedPin($aEvent, $bPerform = false)
  3169. {
  3170. $iUserId = (int)$this->getUserId();
  3171. if($iUserId == 0)
  3172. return false;
  3173. if(isAdmin() || (int)$aEvent['owner_id'] == $iUserId || ((int)$aEvent['owner_id'] == 0 && $this->_oConfig->isCommon($aEvent['type'], $aEvent['action']) && (int)$aEvent['object_id'] == $iUserId))
  3174. return true;
  3175. $aCheckResult = checkActionModule($iUserId, 'pin', $this->getName(), $bPerform);
  3176. if(!empty($aEvent['owner_id']) && ($oProfileOwner = BxDolProfile::getInstance($aEvent['owner_id'])) !== false)
  3177. bx_alert($oProfileOwner->getModule(), $this->_oConfig->getUri() . '_pin', $oProfileOwner->id(), $iUserId, array('check_result' => &$aCheckResult));
  3178. return $aCheckResult[CHECK_ACTION_RESULT] !== CHECK_ACTION_RESULT_ALLOWED ? $aCheckResult[CHECK_ACTION_MESSAGE] : true;
  3179. }
  3180. protected function _isAllowedStick($aEvent, $bPerform = false)
  3181. {
  3182. $iUserId = (int)$this->getUserId();
  3183. if($iUserId == 0)
  3184. return false;
  3185. if(isAdmin())
  3186. return true;
  3187. $aCheckResult = checkActionModule($iUserId, 'stick', $this->getName(), $bPerform);
  3188. if(!empty($aEvent['owner_id']) && ($oProfileOwner = BxDolProfile::getInstance($aEvent['owner_id'])) !== false)
  3189. bx_alert($oProfileOwner->getModule(), $this->_oConfig->getUri() . '_stick', $oProfileOwner->id(), $iUserId, array('check_result' => &$aCheckResult));
  3190. return $aCheckResult[CHECK_ACTION_RESULT] !== CHECK_ACTION_RESULT_ALLOWED ? $aCheckResult[CHECK_ACTION_MESSAGE] : true;
  3191. }
  3192. protected function _isAllowedPromote($aEvent, $bPerform = false)
  3193. {
  3194. if(isAdmin())
  3195. return true;
  3196. $iUserId = (int)$this->getUserId();
  3197. if($iUserId == 0)
  3198. return false;
  3199. $aCheckResult = checkActionModule($iUserId, 'promote', $this->getName(), $bPerform);
  3200. if(!empty($aEvent['owner_id']) && ($oProfileOwner = BxDolProfile::getInstance($aEvent['owner_id'])) !== false)
  3201. bx_alert($oProfileOwner->getModule(), $this->_oConfig->getUri() . '_promote', $oProfileOwner->id(), $iUserId, array('check_result' => &$aCheckResult));
  3202. return $aCheckResult[CHECK_ACTION_RESULT] !== CHECK_ACTION_RESULT_ALLOWED ? $aCheckResult[CHECK_ACTION_MESSAGE] : true;
  3203. }
  3204. protected function _addLink(&$oForm)
  3205. {
  3206. $iUserId = $this->getUserId();
  3207. $sLink = $oForm->getCleanValue('url');
  3208. $aMatches = array();
  3209. preg_match($this->_oConfig->getPregPattern('url'), $sLink, $aMatches);
  3210. $sLink = (empty($aMatches[2]) ? 'http://' : '') . $aMatches[0];
  3211. $aSiteInfo = bx_get_site_info($sLink, array(
  3212. 'thumbnailUrl' => array('tag' => 'link', 'content_attr' => 'href'),
  3213. 'OGImage' => array('name_attr' => 'property', 'name' => 'og:image'),
  3214. ));
  3215. $sTitle = !empty($aSiteInfo['title']) ? $aSiteInfo['title'] : _t('_Empty');
  3216. $sDescription = !empty($aSiteInfo['description']) ? $aSiteInfo['description'] : _t('_Empty');
  3217. $sMediaUrl = '';
  3218. if(!empty($aSiteInfo['thumbnailUrl']))
  3219. $sMediaUrl = $aSiteInfo['thumbnailUrl'];
  3220. else if(!empty($aSiteInfo['OGImage']))
  3221. $sMediaUrl = $aSiteInfo['OGImage'];
  3222. $iMediaId = 0;
  3223. $oStorage = null;
  3224. if(!empty($sMediaUrl)) {
  3225. $oStorage = BxDolStorage::getObjectInstance($this->_oConfig->getObject('storage_' . BX_TIMELINE_MEDIA_PHOTO . 's'));
  3226. $iMediaId = $oStorage->storeFileFromUrl($sMediaUrl, true, $iUserId);
  3227. }
  3228. $iId = (int)$oForm->insert(array('profile_id' => $iUserId, 'media_id' => $iMediaId, 'url' => $sLink, 'title' => $sTitle, 'text' => $sDescription, 'added' => time()));
  3229. if(!empty($iId)) {
  3230. if(!empty($oStorage) && !empty($iMediaId))
  3231. $oStorage->afterUploadCleanup($iMediaId, $iUserId);
  3232. return array('id' => $iId, 'item' => $this->_oTemplate->getAttachLinkItem($iUserId, $iId));
  3233. }
  3234. return array('message' => _t('_bx_timeline_txt_err_cannot_perform_action'));
  3235. }
  3236. protected function _deleteLinks($iId)
  3237. {
  3238. $aLinks = $this->_oDb->getLinks($iId);
  3239. if(empty($aLinks) || !is_array($aLinks))
  3240. return;
  3241. $oStorage = BxDolStorage::getObjectInstance($this->_oConfig->getObject('storage_photos'));
  3242. foreach($aLinks as $aLink)
  3243. if(!empty($aLink['media_id']))
  3244. $oStorage->deleteFile($aLink['media_id']);
  3245. $this->_oDb->deleteLinks($iId);
  3246. }
  3247. protected function _saveMedia($sType, $iId, $aItemIds)
  3248. {
  3249. if(empty($aItemIds) || !is_array($aItemIds))
  3250. return;
  3251. $iUserId = $this->getUserId();
  3252. $oStorage = BxDolStorage::getObjectInstance($this->_oConfig->getObject('storage_' . strtolower($sType) . 's'));
  3253. foreach($aItemIds as $iItemId)
  3254. if($this->_oDb->saveMedia($sType, $iId, $iItemId))
  3255. $oStorage->afterUploadCleanup($iItemId, $iUserId);
  3256. }
  3257. protected function _deleteMedia($sType, $iId)
  3258. {
  3259. $aItems = $this->_oDb->getMedia($sType, $iId);
  3260. if(empty($aItems) || !is_array($aItems))
  3261. return;
  3262. $oStorage = BxDolStorage::getObjectInstance($this->_oConfig->getObject('storage_' . strtolower($sType) . 's'));
  3263. foreach($aItems as $iItemId)
  3264. $oStorage->deleteFile($iItemId);
  3265. $this->_oDb->deleteMedia($sType, $iId);
  3266. }
  3267. protected function _prepareParams($aParams)
  3268. {
  3269. if(empty($aParams['name']))
  3270. $aParams['name'] = '';
  3271. if(empty($aParams['view']))
  3272. $aParams['view'] = BX_TIMELINE_VIEW_DEFAULT;
  3273. if(empty($aParams['type']))
  3274. $aParams['type'] = BX_TIMELINE_TYPE_DEFAULT;
  3275. if(empty($aParams['owner_id']))
  3276. $aParams['owner_id'] = $this->getUserId();
  3277. if(!isset($aParams['start']) || (int)$aParams['start'] < 0)
  3278. $aParams['start'] = 0;
  3279. if(!isset($aParams['per_page']) || (int)$aParams['per_page'] <= 0)
  3280. $aParams['per_page'] = isset($aParams['per_page_default']) && (int)$aParams['per_page_default'] > 0 ? $aParams['per_page_default'] : $this->_oConfig->getPerPage();
  3281. if(empty($aParams['timeline']) || (int)$aParams['timeline'] < 0)
  3282. $aParams['timeline'] = 0;
  3283. if(empty($aParams['filter']))
  3284. $aParams['filter'] = BX_TIMELINE_FILTER_ALL;
  3285. if(empty($aParams['modules']) || !is_array($aParams['modules']))
  3286. $aParams['modules'] = array();
  3287. if(empty($aParams['blink']) || !is_array($aParams['blink']))
  3288. $aParams['blink'] = array();
  3289. if($this->_oConfig->isHot())
  3290. $aParams['hot'] = $this->_oDb->getHot();
  3291. $aParams = array_merge($aParams, array(
  3292. 'browse' => 'list',
  3293. 'status' => BX_TIMELINE_STATUS_ACTIVE,
  3294. 'dynamic_mode' => false,
  3295. ));
  3296. return $aParams;
  3297. }
  3298. protected function _prepareParamsGet()
  3299. {
  3300. $aParams = array();
  3301. $aParams['name'] = bx_get('name');
  3302. $aParams['name'] = $aParams['name'] !== false ? bx_process_input($aParams['name'], BX_DATA_TEXT) : '';
  3303. $aParams['view'] = bx_get('view');
  3304. $aParams['view'] = $aParams['view'] !== false ? bx_process_input($aParams['view'], BX_DATA_TEXT) : BX_TIMELINE_VIEW_DEFAULT;
  3305. $aParams['type'] = bx_get('type');
  3306. $aParams['type'] = $aParams['type'] !== false ? bx_process_input($aParams['type'], BX_DATA_TEXT) : BX_TIMELINE_TYPE_DEFAULT;
  3307. $aParams['owner_id'] = bx_get('owner_id');
  3308. $aParams['owner_id'] = $aParams['owner_id'] !== false ? bx_process_input($aParams['owner_id'], BX_DATA_INT) : $this->getUserId();
  3309. $aParams['start'] = bx_get('start');
  3310. $aParams['start'] = $aParams['start'] !== false ? bx_process_input($aParams['start'], BX_DATA_INT) : 0;
  3311. $aParams['per_page'] = bx_get('per_page');
  3312. $aParams['per_page'] = $aParams['per_page'] !== false ? bx_process_input($aParams['per_page'], BX_DATA_INT) : $this->_oConfig->getPerPage();
  3313. $aParams['timeline'] = bx_get('timeline');
  3314. $aParams['timeline'] = $aParams['timeline'] !== false ? bx_process_input($aParams['timeline']) : '';
  3315. $aParams['filter'] = bx_get('filter');
  3316. $aParams['filter'] = $aParams['filter'] !== false ? bx_process_input($aParams['filter'], BX_DATA_TEXT) : BX_TIMELINE_FILTER_ALL;
  3317. $aParams['modules'] = bx_get('modules');
  3318. $aParams['modules'] = $aParams['modules'] !== false ? bx_process_input($aParams['modules'], BX_DATA_TEXT) : array();
  3319. $aParams['blink'] = bx_get('blink');
  3320. $aParams['blink'] = $aParams['blink'] !== false ? explode(',', bx_process_input($aParams['blink'], BX_DATA_TEXT)) : array();
  3321. if($this->_oConfig->isHot())
  3322. $aParams['hot'] = $this->_oDb->getHot();
  3323. $aParams = array_merge($aParams, array(
  3324. 'browse' => 'list',
  3325. 'status' => BX_TIMELINE_STATUS_ACTIVE,
  3326. 'dynamic_mode' => true,
  3327. ));
  3328. return $aParams;
  3329. }
  3330. protected function _prepareTextForSave($s)
  3331. {
  3332. return bx_process_input($s, BX_DATA_HTML);
  3333. }
  3334. protected function _getFieldValue($sField, $iContentId)
  3335. {
  3336. $CNF = &$this->_oConfig->CNF;
  3337. if(empty($CNF[$sField]))
  3338. return false;
  3339. $aEvent = $this->_oDb->getEvents(array('browse' => 'id', 'value' => $iContentId));
  3340. if(empty($aEvent) || empty($aEvent[$CNF[$sField]]))
  3341. return false;
  3342. return $aEvent[$CNF[$sField]];
  3343. }
  3344. /**
  3345. * Returns records for React Jot using OAuth2
  3346. * @param int $iProfileId
  3347. * @param string $sPage
  3348. * @param string $sTab
  3349. * @param int $iStart
  3350. * @param int $iPerPage
  3351. * @return array
  3352. */
  3353. public function serviceGetUserPosts($iProfileId = 0, $sPage = 'home', $sTab = 'hot', $iStart = 0, $iPerPage = 0)
  3354. {
  3355. $iProfileId = (int)$iProfileId ? (int)$iProfileId : bx_get_logged_profile_id();
  3356. if(empty($iProfileId))
  3357. return array(
  3358. 'code' => 1,
  3359. 'result' => array(),
  3360. 'message' => _t('_bx_timeline_txt_msg_no_profile_id'),
  3361. 'page' => $sPage,
  3362. 'tab' => $sTab
  3363. );
  3364. $sType = BX_TIMELINE_TYPE_OWNER_AND_CONNECTIONS;
  3365. $sView = BX_TIMELINE_VIEW_DEFAULT;
  3366. $sFilter = BX_TIMELINE_FILTER_ALL;
  3367. $aModules = array();
  3368. switch($sPage){
  3369. case 'profile':
  3370. $sType = BX_BASE_MOD_NTFS_TYPE_OWNER;
  3371. $sFilter = BX_TIMELINE_FILTER_OWNER;
  3372. break;
  3373. default:
  3374. if ($this -> _oDb -> isModuleByName($sPage))
  3375. $aModules = array($sPage);
  3376. }
  3377. switch($sTab)
  3378. {
  3379. case 'latest':
  3380. $sType = BX_BASE_MOD_NTFS_TYPE_PUBLIC;
  3381. break;
  3382. case 'popular':
  3383. $sType = BX_TIMELINE_TYPE_HOT;
  3384. break;
  3385. case 'feed':
  3386. $sType = BX_TIMELINE_TYPE_OWNER_AND_CONNECTIONS;
  3387. break;
  3388. default:
  3389. if ($this -> _oDb -> isModuleByName($sTab))
  3390. $aModules = array($sTab);
  3391. }
  3392. $aParams = $this->getParams($sView, $sType, $iProfileId, $iStart, $iPerPage, $sFilter, $aModules);
  3393. $aData = $this->_oDb->getEvents($aParams, true);
  3394. list($aEvents, $iCount) = $aData;
  3395. if(empty($aEvents) || !is_array($aEvents))
  3396. return array(
  3397. 'code' => 0,
  3398. 'result' => array(),
  3399. 'message' => _t('_bx_timeline_txt_msg_no_results'),
  3400. 'page' => $sPage,
  3401. 'tab' => $sTab
  3402. );
  3403. $aBrowseParams = array();
  3404. $aItems = array();
  3405. foreach($aEvents as $aEvent) {
  3406. $aResult = $this->_oTemplate->getData($aEvent, $aBrowseParams);
  3407. if($aResult === false)
  3408. continue;
  3409. $oOwnerProfile = BxDolProfile::getInstance($aResult['owner_id']);
  3410. $aFiles = array();
  3411. $aContent = &$aResult['content'];
  3412. if (!empty($aContent['image']))
  3413. $aFiles['images'] = array_values($aContent['images']);
  3414. if (!empty($aContent['images_attach']))
  3415. $aFiles['images'] = array_values($aContent['images_attach']);
  3416. if (!empty($aContent['videos']))
  3417. $aFiles['videos'] = array_values($aContent['videos']);
  3418. else
  3419. if (!empty($aContent['videos_attach']))
  3420. $aFiles['videos'] = array_values($aContent['videos_attach']);
  3421. if (!empty($aContent['files']))
  3422. $aFiles['files'] = array_values($aContent['files']);
  3423. else
  3424. if (!empty($aContent['files_attach']))
  3425. $aFiles['files'] = array_values($aContent['files_attach']);
  3426. $aItems[$aEvent['id']] = array_merge(array(
  3427. 'owner' => array(
  3428. 'icon' => $oOwnerProfile -> getThumb(),
  3429. 'name' => $oOwnerProfile -> getDisplayName(),
  3430. 'url' => $oOwnerProfile -> getUrl()
  3431. ),
  3432. 'sample' => !empty($aResult['sample']) ? _t($aResult['sample']) : _t('_bx_timeline_txt_sample'),
  3433. 'sample_action' => !empty($aResult['sample_action']) ? _t($aResult['sample_action']) : _t('_bx_timeline_txt_added_sample'),
  3434. 'url' => isset($aResult['url']) ? $aResult['url'] : '',
  3435. 'raw' => isset($aContent['raw']) ? strip_tags($aContent['raw']) : '',
  3436. 'text' => isset($aContent['text']) ? strip_tags($aContent['text']) : '',
  3437. 'views' => isset($aResult['views']['count']) ? (int)$aResult['views']['count'] : 0,
  3438. 'votes' => isset($aResult['votes']['count']) ? (int)$aResult['votes']['count'] : 0,
  3439. 'reactions' => isset($aResult['reactions']['count']) ? (int)$aResult['reactions']['count'] : 0,
  3440. 'scores' => isset($aResult['scores']['count']) ? (int)$aResult['scores']['count'] : 0,
  3441. 'reports' => isset($aResult['reports']['count']) ? (int)$aResult['reports']['count'] : 0,
  3442. 'comments' => isset($aResult['comments']['count']) ? (int)$aResult['comments']['count'] : 0,
  3443. 'date' => isset($aResult['date']) ? $aResult['date'] : $aEvent['date'],
  3444. 'type' => stripos($aEvent['type'], 'timeline') !== false ? 'bx_timeline' : $aEvent['type'],
  3445. 'event_type' => $aEvent['type'],
  3446. 'id' => $aEvent['id'],
  3447. 'content' => $aResult['content'],
  3448. 'title' => isset($aResult['title']) ? _t($aResult['title']) : '',
  3449. 'description' => isset($aResult['description']) ? $aResult['description'] : ''
  3450. ), $aFiles);
  3451. }
  3452. return array(
  3453. 'result' => $aItems,
  3454. 'code' => 0,
  3455. 'message' => '',
  3456. 'page' => $sPage,
  3457. 'tab' => $sTab,
  3458. 'total' => $iCount,
  3459. 'start' => (int)$iStart
  3460. );
  3461. }
  3462. }
  3463. /** @} */