BxTimelineModule.php 176 KB

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