BxTimelineModule.php 265 KB

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