BxTimelineModule.php 251 KB

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