BxTimelineModule.php 261 KB

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