BxTimelineModule.php 220 KB

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