1
0

BxTimelineModule.php 223 KB

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