BxTimelineModule.php 260 KB

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