BxTimelineModule.php 262 KB

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