BxTimelineModule.php 262 KB

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