BxTimelineModule.php 196 KB

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