1
0

BxTimelineModule.php 265 KB

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