BxTimelineModule.php 261 KB

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