BxTimelineModule.php 204 KB

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