BxTimelineModule.php 252 KB

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