BxTimelineModule.php 220 KB

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