BxTimelineModule.php 224 KB

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