BxTimelineModule.php 227 KB

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