BxTimelineModule.php 261 KB

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