BxTimelineModule.php 233 KB

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