BxTimelineModule.php 185 KB

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