BxTimelineModule.php 252 KB

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