BxTimelineModule.php 252 KB

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