BxTimelineModule.php 206 KB

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