BxTimelineModule.php 168 KB

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