BxTimelineModule.php 191 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954
  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_view get_block_view
  1157. *
  1158. * @code bx_srv('bx_timeline', 'get_block_view', [...]); @endcode
  1159. *
  1160. * Get Timeline View block for a separate page.
  1161. *
  1162. * @param $iProfileId (optional) profile ID. If empty value is provided, an attempt to get it from GET/POST arrays will be performed.
  1163. * @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.
  1164. *
  1165. * @see BxTimelineModule::serviceGetBlockView
  1166. */
  1167. /**
  1168. * @ref bx_timeline-get_block_view "get_block_view"
  1169. */
  1170. public function serviceGetBlockView($iProfileId = 0)
  1171. {
  1172. return $this->_serviceGetBlockView($iProfileId, array(
  1173. 'view' => BX_TIMELINE_VIEW_TIMELINE,
  1174. 'type' => BX_BASE_MOD_NTFS_TYPE_OWNER,
  1175. 'start' => -1,
  1176. 'per_page' => -1,
  1177. 'per_page_default' => $this->_oConfig->getPerPage('profile'),
  1178. 'timeline' => -1,
  1179. 'filter' => '',
  1180. 'modules' => array()
  1181. ));
  1182. }
  1183. /**
  1184. * @page service Service Calls
  1185. * @section bx_timeline Timeline
  1186. * @subsection bx_timeline-page_blocks Page Blocks
  1187. * @subsubsection bx_timeline-get_block_view_outline get_block_view_outline
  1188. *
  1189. * @code bx_srv('bx_timeline', 'get_block_view_outline', [...]); @endcode
  1190. *
  1191. * Get Outline View block for a separate page.
  1192. *
  1193. * @param $iProfileId (optional) profile ID. If empty value is provided, an attempt to get it from GET/POST arrays will be performed.
  1194. * @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.
  1195. *
  1196. * @see BxTimelineModule::serviceGetBlockViewOutline
  1197. */
  1198. /**
  1199. * @ref bx_timeline-get_block_view_outline "get_block_view_outline"
  1200. */
  1201. public function serviceGetBlockViewOutline($iProfileId = 0)
  1202. {
  1203. return $this->_serviceGetBlockView($iProfileId, array(
  1204. 'view' => BX_TIMELINE_VIEW_OUTLINE,
  1205. 'type' => BX_BASE_MOD_NTFS_TYPE_OWNER,
  1206. 'start' => -1,
  1207. 'per_page' => -1,
  1208. 'per_page_default' => $this->_oConfig->getPerPage('profile'),
  1209. 'timeline' => -1,
  1210. 'filter' => '',
  1211. 'modules' => array()
  1212. ));
  1213. }
  1214. /**
  1215. * @page service Service Calls
  1216. * @section bx_timeline Timeline
  1217. * @subsection bx_timeline-page_blocks Page Blocks
  1218. * @subsubsection bx_timeline-get_block_view_profile get_block_view_profile
  1219. *
  1220. * @code bx_srv('bx_timeline', 'get_block_view_profile', [...]); @endcode
  1221. *
  1222. * Get Timeline View block for the Profile page.
  1223. *
  1224. * @param $sProfileModule (optional) string value with profile based module name. Persons module is used by default.
  1225. * @param $iProfileContentId (optional) profile's content ID. If empty value is provided, an attempt to get it from GET/POST arrays will be performed.
  1226. * @param $iStart (optional) integer value with a page number. Is used in pagination.
  1227. * @param $iPerPage (optional) integer value with a number of items per page. Is used in pagination.
  1228. * @param $sFilter (optional) string value with filter name.
  1229. * @param $aModules (optional) an array of modules from which the events should be displayed. All available modules are used by default.
  1230. * @param $iTimeline (optional) integer value determining whether the timeline should be displayed or not.
  1231. * @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.
  1232. *
  1233. * @see BxTimelineModule::serviceGetBlockViewProfile
  1234. */
  1235. /**
  1236. * @ref bx_timeline-get_block_view_profile "get_block_view_profile"
  1237. */
  1238. public function serviceGetBlockViewProfile($sProfileModule = 'bx_persons', $iProfileContentId = 0, $iStart = -1, $iPerPage = -1, $sFilter = '', $aModules = array(), $iTimeline = -1)
  1239. {
  1240. return $this->_serviceGetBlockViewProfile($sProfileModule, $iProfileContentId, array(
  1241. 'view' => BX_TIMELINE_VIEW_TIMELINE,
  1242. 'type' => BX_BASE_MOD_NTFS_TYPE_OWNER,
  1243. 'start' => $iStart,
  1244. 'per_page' => $iPerPage,
  1245. 'per_page_default' => $this->_oConfig->getPerPage('profile'),
  1246. 'timeline' => $iTimeline,
  1247. 'filter' => $sFilter,
  1248. 'modules' => $aModules
  1249. ));
  1250. }
  1251. /**
  1252. * @page service Service Calls
  1253. * @section bx_timeline Timeline
  1254. * @subsection bx_timeline-page_blocks Page Blocks
  1255. * @subsubsection bx_timeline-get_block_view_profile_outline get_block_view_profile_outline
  1256. *
  1257. * @code bx_srv('bx_timeline', 'get_block_view_profile_outline', [...]); @endcode
  1258. *
  1259. * Get Outline View block for the Profile page.
  1260. *
  1261. * @param $sProfileModule (optional) string value with profile based module name. Persons module is used by default.
  1262. * @param $iProfileContentId (optional) profile's content ID. If empty value is provided, an attempt to get it from GET/POST arrays will be performed.
  1263. * @param $iStart (optional) integer value with a page number. Is used in pagination.
  1264. * @param $iPerPage (optional) integer value with a number of items per page. Is used in pagination.
  1265. * @param $sFilter (optional) string value with filter name.
  1266. * @param $aModules (optional) an array of modules from which the events should be displayed. All available modules are used by default.
  1267. * @param $iTimeline (optional) integer value determining whether the timeline should be displayed or not.
  1268. * @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.
  1269. *
  1270. * @see BxTimelineModule::serviceGetBlockViewProfileOutline
  1271. */
  1272. /**
  1273. * @ref bx_timeline-get_block_view_profile_outline "get_block_view_profile_outline"
  1274. */
  1275. public function serviceGetBlockViewProfileOutline($sProfileModule = 'bx_persons', $iProfileContentId = 0, $iStart = -1, $iPerPage = -1, $sFilter = '', $aModules = array(), $iTimeline = -1)
  1276. {
  1277. return $this->_serviceGetBlockViewProfile($sProfileModule, $iProfileContentId, array(
  1278. 'view' => BX_TIMELINE_VIEW_OUTLINE,
  1279. 'type' => BX_BASE_MOD_NTFS_TYPE_OWNER,
  1280. 'start' => $iStart,
  1281. 'per_page' => $iPerPage,
  1282. 'per_page_default' => $this->_oConfig->getPerPage('profile'),
  1283. 'timeline' => $iTimeline,
  1284. 'filter' => $sFilter,
  1285. 'modules' => $aModules
  1286. ));
  1287. }
  1288. public function serviceGetBlockViewsCustom($aParams = array())
  1289. {
  1290. $aParams = array_merge(array(
  1291. 'view' => BX_TIMELINE_VIEW_TIMELINE,
  1292. 'type' => BX_BASE_MOD_NTFS_TYPE_PUBLIC,
  1293. 'owner_id' => 0,
  1294. ), $aParams);
  1295. return $this->_serviceGetBlockViews($aParams);
  1296. }
  1297. public function serviceGetBlockViewsTimeline($sType = BX_BASE_MOD_NTFS_TYPE_PUBLIC, $iProfileId = 0, $iStart = -1, $iPerPage = -1, $iTimeline = -1, $sFilter = '', $aModules = array())
  1298. {
  1299. return $this->_serviceGetBlockViews(array(
  1300. 'view' => BX_TIMELINE_VIEW_TIMELINE,
  1301. 'type' => $sType,
  1302. 'owner_id' => $iProfileId,
  1303. 'start' => $iStart,
  1304. 'per_page' => $iPerPage,
  1305. 'per_page_default' => $this->_oConfig->getPerPage(),
  1306. 'timeline' => $iTimeline,
  1307. 'filter' => $sFilter,
  1308. 'modules' => $aModules
  1309. ));
  1310. }
  1311. public function serviceGetBlockViewsOutline($sType = BX_BASE_MOD_NTFS_TYPE_PUBLIC, $iProfileId = 0, $iStart = -1, $iPerPage = -1, $iTimeline = -1, $sFilter = '', $aModules = array())
  1312. {
  1313. return $this->_serviceGetBlockViews(array(
  1314. 'view' => BX_TIMELINE_VIEW_OUTLINE,
  1315. 'type' => $sType,
  1316. 'owner_id' => $iProfileId,
  1317. 'start' => $iStart,
  1318. 'per_page' => $iPerPage,
  1319. 'per_page_default' => $this->_oConfig->getPerPage(),
  1320. 'timeline' => $iTimeline,
  1321. 'filter' => $sFilter,
  1322. 'modules' => $aModules
  1323. ));
  1324. }
  1325. /**
  1326. * @page service Service Calls
  1327. * @section bx_timeline Timeline
  1328. * @subsection bx_timeline-page_blocks Page Blocks
  1329. * @subsubsection bx_timeline-get_block_view_home get_block_view_home
  1330. *
  1331. * @code bx_srv('bx_timeline', 'get_block_view_home', [...]); @endcode
  1332. *
  1333. * Get Timeline View block for site's Home page.
  1334. *
  1335. * @param $iProfileId (optional) profile ID. 0 should be used here.
  1336. * @param $iStart (optional) integer value with a page number. Is used in pagination.
  1337. * @param $iPerPage (optional) integer value with a number of items per page. Is used in pagination.
  1338. * @param $iTimeline (optional) integer value determining whether the timeline should be displayed or not.
  1339. * @param $sFilter (optional) string value with filter name.
  1340. * @param $aModules (optional) an array of modules from which the events should be displayed. All available modules are used by default.
  1341. * @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.
  1342. *
  1343. * @see BxTimelineModule::serviceGetBlockViewHome
  1344. */
  1345. /**
  1346. * @ref bx_timeline-get_block_view_home "get_block_view_home"
  1347. */
  1348. public function serviceGetBlockViewHome($iProfileId = 0, $iStart = -1, $iPerPage = -1, $iTimeline = -1, $sFilter = '', $aModules = array())
  1349. {
  1350. return $this->_serviceGetBlockViewHome(array(
  1351. 'view' => BX_TIMELINE_VIEW_TIMELINE,
  1352. 'type' => BX_BASE_MOD_NTFS_TYPE_PUBLIC,
  1353. 'owner_id' => $iProfileId,
  1354. 'start' => $iStart,
  1355. 'per_page' => $iPerPage,
  1356. 'per_page_default' => $this->_oConfig->getPerPage('home'),
  1357. 'timeline' => $iTimeline,
  1358. 'filter' => $sFilter,
  1359. 'modules' => $aModules
  1360. ));
  1361. }
  1362. /**
  1363. * @page service Service Calls
  1364. * @section bx_timeline Timeline
  1365. * @subsection bx_timeline-page_blocks Page Blocks
  1366. * @subsubsection bx_timeline-get_block_view_home_outline get_block_view_home_outline
  1367. *
  1368. * @code bx_srv('bx_timeline', 'get_block_view_home_outline', [...]); @endcode
  1369. *
  1370. * Get Outline View block for site's Home page.
  1371. *
  1372. * @param $iProfileId (optional) profile ID. 0 should be used here.
  1373. * @param $iStart (optional) integer value with a page number. Is used in pagination.
  1374. * @param $iPerPage (optional) integer value with a number of items per page. Is used in pagination.
  1375. * @param $iTimeline (optional) integer value determining whether the timeline should be displayed or not.
  1376. * @param $sFilter (optional) string value with filter name.
  1377. * @param $aModules (optional) an array of modules from which the events should be displayed. All available modules are used by default.
  1378. * @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.
  1379. *
  1380. * @see BxTimelineModule::serviceGetBlockViewHomeOutline
  1381. */
  1382. /**
  1383. * @ref bx_timeline-get_block_view_home_outline "get_block_view_home_outline"
  1384. */
  1385. public function serviceGetBlockViewHomeOutline($iProfileId = 0, $iStart = -1, $iPerPage = -1, $iTimeline = -1, $sFilter = '', $aModules = array())
  1386. {
  1387. return $this->_serviceGetBlockViewHome(array(
  1388. 'view' => BX_TIMELINE_VIEW_OUTLINE,
  1389. 'type' => BX_BASE_MOD_NTFS_TYPE_PUBLIC,
  1390. 'owner_id' => $iProfileId,
  1391. 'start' => $iStart,
  1392. 'per_page' => $iPerPage,
  1393. 'per_page_default' => $this->_oConfig->getPerPage('home'),
  1394. 'timeline' => $iTimeline,
  1395. 'filter' => $sFilter,
  1396. 'modules' => $aModules
  1397. ));
  1398. }
  1399. /**
  1400. * @page service Service Calls
  1401. * @section bx_timeline Timeline
  1402. * @subsection bx_timeline-page_blocks Page Blocks
  1403. * @subsubsection bx_timeline-get_block_view_hot get_block_view_hot
  1404. *
  1405. * @code bx_srv('bx_timeline', 'get_block_view_hot', [...]); @endcode
  1406. *
  1407. * Get Timeline View block with Hot public events.
  1408. *
  1409. * @param $iProfileId (optional) profile ID. 0 should be used here.
  1410. * @param $iStart (optional) integer value with a page number. Is used in pagination.
  1411. * @param $iPerPage (optional) integer value with a number of items per page. Is used in pagination.
  1412. * @param $iTimeline (optional) integer value determining whether the timeline should be displayed or not.
  1413. * @param $sFilter (optional) string value with filter name.
  1414. * @param $aModules (optional) an array of modules from which the events should be displayed. All available modules are used by default.
  1415. * @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.
  1416. *
  1417. * @see BxTimelineModule::serviceGetBlockViewHot
  1418. */
  1419. /**
  1420. * @ref bx_timeline-get_block_view_hot "get_block_view_hot"
  1421. */
  1422. public function serviceGetBlockViewHot($iProfileId = 0, $iStart = -1, $iPerPage = -1, $iTimeline = -1, $sFilter = '', $aModules = array())
  1423. {
  1424. return $this->_serviceGetBlockViewHot(array(
  1425. 'view' => BX_TIMELINE_VIEW_TIMELINE,
  1426. 'type' => BX_TIMELINE_TYPE_HOT,
  1427. 'owner_id' => $iProfileId,
  1428. 'start' => $iStart,
  1429. 'per_page' => $iPerPage,
  1430. 'per_page_default' => $this->_oConfig->getPerPage('home'),
  1431. 'timeline' => $iTimeline,
  1432. 'filter' => $sFilter,
  1433. 'modules' => $aModules
  1434. ));
  1435. }
  1436. /**
  1437. * @page service Service Calls
  1438. * @section bx_timeline Timeline
  1439. * @subsection bx_timeline-page_blocks Page Blocks
  1440. * @subsubsection bx_timeline-get_block_view_hot_outline get_block_view_hot_outline
  1441. *
  1442. * @code bx_srv('bx_timeline', 'get_block_view_hot_outline', [...]); @endcode
  1443. *
  1444. * Get Outline View block with Hot public events.
  1445. *
  1446. * @param $iProfileId (optional) profile ID. 0 should be used here.
  1447. * @param $iStart (optional) integer value with a page number. Is used in pagination.
  1448. * @param $iPerPage (optional) integer value with a number of items per page. Is used in pagination.
  1449. * @param $iTimeline (optional) integer value determining whether the timeline should be displayed or not.
  1450. * @param $sFilter (optional) string value with filter name.
  1451. * @param $aModules (optional) an array of modules from which the events should be displayed. All available modules are used by default.
  1452. * @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.
  1453. *
  1454. * @see BxTimelineModule::serviceGetBlockViewHotOutline
  1455. */
  1456. /**
  1457. * @ref bx_timeline-get_block_view_hot_outline "get_block_view_hot_outline"
  1458. */
  1459. public function serviceGetBlockViewHotOutline($iProfileId = 0, $iStart = -1, $iPerPage = -1, $iTimeline = -1, $sFilter = '', $aModules = array())
  1460. {
  1461. return $this->_serviceGetBlockViewHot(array(
  1462. 'view' => BX_TIMELINE_VIEW_OUTLINE,
  1463. 'type' => BX_TIMELINE_TYPE_HOT,
  1464. 'owner_id' => $iProfileId,
  1465. 'start' => $iStart,
  1466. 'per_page' => $iPerPage,
  1467. 'per_page_default' => $this->_oConfig->getPerPage('home'),
  1468. 'timeline' => $iTimeline,
  1469. 'filter' => $sFilter,
  1470. 'modules' => $aModules
  1471. ));
  1472. }
  1473. /**
  1474. * @page service Service Calls
  1475. * @section bx_timeline Timeline
  1476. * @subsection bx_timeline-page_blocks Page Blocks
  1477. * @subsubsection bx_timeline-get_block_view_account get_block_view_account
  1478. *
  1479. * @code bx_srv('bx_timeline', 'get_block_view_account', [...]); @endcode
  1480. *
  1481. * Get Timeline View block for the Dashboard page.
  1482. *
  1483. * @param $iProfileId (optional) profile ID. 0 should be used here.
  1484. * @param $iStart (optional) integer value with a page number. Is used in pagination.
  1485. * @param $iPerPage (optional) integer value with a number of items per page. Is used in pagination.
  1486. * @param $iTimeline (optional) integer value determining whether the timeline should be displayed or not.
  1487. * @param $sFilter (optional) string value with filter name.
  1488. * @param $aModules (optional) an array of modules from which the events should be displayed. All available modules are used by default.
  1489. * @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.
  1490. *
  1491. * @see BxTimelineModule::serviceGetBlockViewAccount
  1492. */
  1493. /**
  1494. * @ref bx_timeline-get_block_view_account "get_block_view_account"
  1495. */
  1496. public function serviceGetBlockViewAccount($iProfileId = 0, $iStart = -1, $iPerPage = -1, $iTimeline = -1, $sFilter = '', $aModules = array())
  1497. {
  1498. if(!isLogged())
  1499. return '';
  1500. return $this->_serviceGetBlockViewByType(array(
  1501. 'view' => BX_TIMELINE_VIEW_TIMELINE,
  1502. 'type' => BX_TIMELINE_TYPE_FEED,
  1503. 'owner_id' => $iProfileId,
  1504. 'start' => $iStart,
  1505. 'per_page' => $iPerPage,
  1506. 'per_page_default' => $this->_oConfig->getPerPage('account'),
  1507. 'timeline' => $iTimeline,
  1508. 'filter' => $sFilter,
  1509. 'modules' => $aModules
  1510. ));
  1511. }
  1512. /**
  1513. * @page service Service Calls
  1514. * @section bx_timeline Timeline
  1515. * @subsection bx_timeline-page_blocks Page Blocks
  1516. * @subsubsection bx_timeline-get_block_view_account_outline get_block_view_account_outline
  1517. *
  1518. * @code bx_srv('bx_timeline', 'get_block_view_account_outline', [...]); @endcode
  1519. *
  1520. * Get Outline View block for the Dashboard page.
  1521. *
  1522. * @param $iProfileId (optional) profile ID. 0 should be used here.
  1523. * @param $iStart (optional) integer value with a page number. Is used in pagination.
  1524. * @param $iPerPage (optional) integer value with a number of items per page. Is used in pagination.
  1525. * @param $iTimeline (optional) integer value determining whether the timeline should be displayed or not.
  1526. * @param $sFilter (optional) string value with filter name.
  1527. * @param $aModules (optional) an array of modules from which the events should be displayed. All available modules are used by default.
  1528. * @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.
  1529. *
  1530. * @see BxTimelineModule::serviceGetBlockViewAccountOutline
  1531. */
  1532. /**
  1533. * @ref bx_timeline-get_block_view_account_outline "get_block_view_account_outline"
  1534. */
  1535. public function serviceGetBlockViewAccountOutline($iProfileId = 0, $iStart = -1, $iPerPage = -1, $iTimeline = -1, $sFilter = '', $aModules = array())
  1536. {
  1537. if(!isLogged())
  1538. return '';
  1539. return $this->_serviceGetBlockViewByType(array(
  1540. 'view' => BX_TIMELINE_VIEW_OUTLINE,
  1541. 'type' => BX_TIMELINE_TYPE_FEED,
  1542. 'owner_id' => $iProfileId,
  1543. 'start' => $iStart,
  1544. 'per_page' => $iPerPage,
  1545. 'per_page_default' => $this->_oConfig->getPerPage('account'),
  1546. 'timeline' => $iTimeline,
  1547. 'filter' => $sFilter,
  1548. 'modules' => $aModules
  1549. ));
  1550. }
  1551. /**
  1552. * @page service Service Calls
  1553. * @section bx_timeline Timeline
  1554. * @subsection bx_timeline-page_blocks Page Blocks
  1555. * @subsubsection bx_timeline-get_block_view_custom get_block_view_custom
  1556. *
  1557. * @code bx_srv('bx_timeline', 'get_block_view_custom', [...]); @endcode
  1558. *
  1559. * Get custom Timeline View block.
  1560. *
  1561. * @param $aParams (optional) an array with block parameneters.
  1562. * @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.
  1563. *
  1564. * @see BxTimelineModule::serviceGetBlockViewCustom
  1565. */
  1566. /**
  1567. * @ref bx_timeline-get_block_view_custom "get_block_view_custom"
  1568. */
  1569. public function serviceGetBlockViewCustom($aParams = array())
  1570. {
  1571. return $this->_serviceGetBlockViewByType($aParams);
  1572. }
  1573. public function serviceGetBlockMenuDb($aParams = array())
  1574. {
  1575. $aParams = $this->_prepareParams(array_merge($aParams, [
  1576. 'name' => BX_TIMELINE_NAME_VIEWS_DB,
  1577. 'view' => BX_TIMELINE_VIEW_TIMELINE,
  1578. 'type' => BX_TIMELINE_TYPE_FEED,
  1579. 'owner_id' => $this->getProfileId()
  1580. ]));
  1581. if(($sType = $this->_oConfig->getUserChoice('type')) !== false)
  1582. $aParams['type'] = $sType;
  1583. $sMenu = $this->_oConfig->getObject('menu_feeds');
  1584. $oMenu = BxDolMenu::getObjectInstance($sMenu);
  1585. if(!$oMenu)
  1586. return '';
  1587. $sSelectedModule = $this->getName();
  1588. $sSelectedName = $aParams['type'];
  1589. if(($aModule = $this->_oDb->getModuleByName($aParams['type']))) {
  1590. $sSelectedModule = $aModule['name'];
  1591. $sSelectedName = $aModule['uri'];
  1592. }
  1593. $oMenu->setSelected($sSelectedModule, $sSelectedName);
  1594. $oMenu->setBrowseParams($aParams);
  1595. return $oMenu->getCode();
  1596. }
  1597. public function serviceGetBlockViewsDb($aParams = [])
  1598. {
  1599. $aParams = $this->_prepareParams(array_merge($aParams, [
  1600. 'name' => BX_TIMELINE_NAME_VIEWS_DB,
  1601. 'view' => BX_TIMELINE_VIEW_TIMELINE,
  1602. 'type' => BX_TIMELINE_TYPE_FEED,
  1603. 'owner_id' => $this->getProfileId()
  1604. ]));
  1605. if(($sType = $this->_oConfig->getUserChoice('type')) !== false)
  1606. $aParams['type'] = $sType;
  1607. $this->_iOwnerId = $aParams['owner_id'];
  1608. return $this->_oTemplate->getViewsDbBlock($aParams);
  1609. }
  1610. /**
  1611. * @page service Service Calls
  1612. * @section bx_timeline Timeline
  1613. * @subsection bx_timeline-page_blocks Page Blocks
  1614. * @subsubsection bx_timeline-get_block_item get_block_item
  1615. *
  1616. * @code bx_srv('bx_timeline', 'get_block_item', [...]); @endcode
  1617. *
  1618. * Get View Item block.
  1619. *
  1620. * @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.
  1621. *
  1622. * @see BxTimelineModule::serviceGetBlockItem
  1623. */
  1624. /**
  1625. * @ref bx_timeline-get_block_item "get_block_item"
  1626. */
  1627. public function serviceGetBlockItem()
  1628. {
  1629. $iItemId = bx_process_input(bx_get('id'), BX_DATA_INT);
  1630. if(!$iItemId)
  1631. return array();
  1632. $aParams = $this->_prepareParams(array(
  1633. 'view' => BX_TIMELINE_VIEW_ITEM,
  1634. 'type' => BX_TIMELINE_TYPE_ITEM
  1635. ));
  1636. $aItemData = $this->getItemData($iItemId, $aParams);
  1637. return $this->_oTemplate->getItemBlock($aItemData, $aParams);
  1638. }
  1639. public function serviceGetBlockItemContent()
  1640. {
  1641. $iItemId = bx_process_input(bx_get('id'), BX_DATA_INT);
  1642. $sMode = bx_process_input(bx_get('mode'));
  1643. if(!$iItemId || !$sMode)
  1644. return '';
  1645. return $this->_oTemplate->getItemBlockContent($iItemId, $sMode);
  1646. }
  1647. public function serviceGetBlockItemInfo()
  1648. {
  1649. $iItemId = bx_process_input(bx_get('id'), BX_DATA_INT);
  1650. if(!$iItemId)
  1651. return '';
  1652. return $this->_oTemplate->getItemBlockInfo($iItemId);
  1653. }
  1654. public function serviceGetBlockItemComments()
  1655. {
  1656. $iItemId = bx_process_input(bx_get('id'), BX_DATA_INT);
  1657. if(!$iItemId)
  1658. return '';
  1659. return $this->_oTemplate->getItemBlockComments($iItemId);
  1660. }
  1661. public function serviceGetBlockMuted($iProfileId = 0)
  1662. {
  1663. if(!isLogged())
  1664. return MsgBox(_t('_Access denied'));
  1665. if($iProfileId == 0)
  1666. $iProfileId = $this->_iProfileId;
  1667. $oGrid = BxDolGrid::getObjectInstance($this->_oConfig->getObject('grid_mute'));
  1668. if(!$oGrid)
  1669. return MsgBox('_Empty');
  1670. $oGrid->setProfile($iProfileId);
  1671. return $oGrid->getCode();
  1672. }
  1673. public function serviceGetPost($mixedEvent, $aParams = array())
  1674. {
  1675. if(!empty($mixedEvent) && !is_array($mixedEvent))
  1676. $mixedEvent = $this->_oDb->getContentInfoById((int)$mixedEvent);
  1677. if(empty($mixedEvent) || !is_array($mixedEvent))
  1678. return '';
  1679. $aParams = $this->_prepareParams(array_merge(array(
  1680. 'view' => BX_TIMELINE_VIEW_ITEM,
  1681. 'type' => BX_TIMELINE_TYPE_ITEM
  1682. ), $aParams));
  1683. return $this->_oTemplate->getPost($mixedEvent, $aParams);
  1684. }
  1685. public function serviceGetTimelineRepostAllowedView($aEvent)
  1686. {
  1687. return isset($aEvent['content']['allowed_view']) ? $aEvent['content']['allowed_view'] : CHECK_ACTION_RESULT_ALLOWED;
  1688. }
  1689. /**
  1690. * @page service Service Calls
  1691. * @section bx_timeline Timeline
  1692. * @subsection bx_timeline-integration_notifications Integration with Notifications
  1693. * @subsubsection bx_timeline-get_notifications_data get_notifications_data
  1694. *
  1695. * @code bx_srv('bx_timeline', 'get_notifications_data', [...]); @endcode
  1696. *
  1697. * Data for Notifications module.
  1698. *
  1699. * @return an array with special format.
  1700. *
  1701. * @see BxTimelineModule::serviceGetNotificationsData
  1702. */
  1703. /**
  1704. * @ref bx_timeline-get_notifications_data "get_notifications_data"
  1705. */
  1706. public function serviceGetNotificationsData()
  1707. {
  1708. $sModule = $this->_aModule['name'];
  1709. return array(
  1710. 'handlers' => array(
  1711. array('group' => $sModule . '_object', 'type' => 'insert', 'alert_unit' => $sModule, 'alert_action' => 'post_common', 'module_name' => $sModule, 'module_method' => 'get_notifications_post', 'module_class' => 'Module'),
  1712. array('group' => $sModule . '_object', 'type' => 'delete', 'alert_unit' => $sModule, 'alert_action' => 'delete'),
  1713. 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'),
  1714. 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'),
  1715. array('group' => $sModule . '_repost', 'type' => 'insert', 'alert_unit' => $sModule, 'alert_action' => 'repost', 'module_name' => $sModule, 'module_method' => 'get_notifications_repost', 'module_class' => 'Module'),
  1716. array('group' => $sModule . '_repost', 'type' => 'delete', 'alert_unit' => $sModule, 'alert_action' => 'delete_repost'),
  1717. array('group' => $sModule . '_comment', 'type' => 'insert', 'alert_unit' => $sModule, 'alert_action' => 'commentPost', 'module_name' => $sModule, 'module_method' => 'get_notifications_comment', 'module_class' => 'Module'),
  1718. array('group' => $sModule . '_comment', 'type' => 'delete', 'alert_unit' => $sModule, 'alert_action' => 'commentRemoved'),
  1719. array('group' => $sModule . '_vote', 'type' => 'insert', 'alert_unit' => $sModule, 'alert_action' => 'doVote', 'module_name' => $sModule, 'module_method' => 'get_notifications_vote', 'module_class' => 'Module'),
  1720. array('group' => $sModule . '_vote', 'type' => 'delete', 'alert_unit' => $sModule, 'alert_action' => 'undoVote'),
  1721. array('group' => $sModule . '_reaction', 'type' => 'insert', 'alert_unit' => $sModule . '_reactions', 'alert_action' => 'doVote', 'module_name' => $sModule, 'module_method' => 'get_notifications_reaction', 'module_class' => 'Module'),
  1722. array('group' => $sModule . '_reaction', 'type' => 'delete', 'alert_unit' => $sModule . '_reactions', 'alert_action' => 'undoVote'),
  1723. 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'),
  1724. 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'),
  1725. ),
  1726. 'settings' => array(
  1727. array('group' => 'content', 'unit' => $sModule, 'action' => 'post_common', 'types' => array('personal', 'follow_member', 'follow_context')),
  1728. array('group' => 'content', 'unit' => $sModule, 'action' => 'publish_failed', 'types' => array('personal')),
  1729. array('group' => 'content', 'unit' => $sModule, 'action' => 'publish_succeeded', 'types' => array('personal')),
  1730. array('group' => 'content', 'unit' => $sModule, 'action' => 'repost', 'types' => array('follow_member', 'follow_context')),
  1731. array('group' => 'comment', 'unit' => $sModule, 'action' => 'commentPost', 'types' => array('personal', 'follow_member', 'follow_context')),
  1732. array('group' => 'vote', 'unit' => $sModule, 'action' => 'doVote', 'types' => array('personal', 'follow_member', 'follow_context')),
  1733. array('group' => 'vote', 'unit' => $sModule . '_reactions', 'action' => 'doVote', 'types' => array('personal', 'follow_member', 'follow_context')),
  1734. array('group' => 'score_up', 'unit' => $sModule, 'action' => 'doVoteUp', 'types' => array('personal', 'follow_member', 'follow_context')),
  1735. array('group' => 'score_down', 'unit' => $sModule, 'action' => 'doVoteDown', 'types' => array('personal', 'follow_member', 'follow_context'))
  1736. ),
  1737. 'alerts' => array(
  1738. array('unit' => $sModule, 'action' => 'post_common'),
  1739. array('unit' => $sModule, 'action' => 'publish_failed'),
  1740. array('unit' => $sModule, 'action' => 'publish_succeeded'),
  1741. array('unit' => $sModule, 'action' => 'delete'),
  1742. array('unit' => $sModule, 'action' => 'repost'),
  1743. array('unit' => $sModule, 'action' => 'delete_repost'),
  1744. array('unit' => $sModule, 'action' => 'commentPost'),
  1745. array('unit' => $sModule, 'action' => 'commentRemoved'),
  1746. array('unit' => $sModule, 'action' => 'doVote'),
  1747. array('unit' => $sModule, 'action' => 'undoVote'),
  1748. array('unit' => $sModule . '_reactions', 'action' => 'doVote'),
  1749. array('unit' => $sModule . '_reactions', 'action' => 'undoVote'),
  1750. array('unit' => $sModule, 'action' => 'doVoteUp'),
  1751. array('unit' => $sModule, 'action' => 'doVoteDown'),
  1752. )
  1753. );
  1754. }
  1755. /**
  1756. * @page service Service Calls
  1757. * @section bx_timeline Timeline
  1758. * @subsection bx_timeline-integration_notifications Integration with Notifications
  1759. * @subsubsection bx_timeline-get_notifications_repost get_notifications_repost
  1760. *
  1761. * @code bx_srv('bx_timeline', 'get_notifications_repost', [...]); @endcode
  1762. *
  1763. * Get data for Repost event to display in Notifications module.
  1764. *
  1765. * @param $aEvent an array with event description.
  1766. * @return an array with special format.
  1767. *
  1768. * @see BxTimelineModule::serviceGetNotificationsRepost
  1769. */
  1770. /**
  1771. * @ref bx_timeline-get_notifications_repost "get_notifications_repost"
  1772. */
  1773. public function serviceGetNotificationsRepost($aEvent)
  1774. {
  1775. $aResult = $this->serviceGetNotificationsPost($aEvent);
  1776. $aResult['lang_key'] = '_bx_timeline_txt_object_reposted';
  1777. return $aResult;
  1778. }
  1779. /**
  1780. * @page service Service Calls
  1781. * @section bx_timeline Timeline
  1782. * @subsection bx_timeline-integration_notifications Integration with Notifications
  1783. * @subsubsection bx_timeline-get_notifications_post get_notifications_post
  1784. *
  1785. * @code bx_srv('bx_timeline', 'get_notifications_post', [...]); @endcode
  1786. *
  1787. * Get data for Post event to display in Notifications module.
  1788. *
  1789. * @param $aEvent an array with event description.
  1790. * @return an array with special format.
  1791. *
  1792. * @see BxTimelineModule::serviceGetNotificationsPost
  1793. */
  1794. /**
  1795. * @ref bx_timeline-get_notifications_post "get_notifications_post"
  1796. */
  1797. public function serviceGetNotificationsPost($aEvent)
  1798. {
  1799. $CNF = &$this->_oConfig->CNF;
  1800. $iContent = (int)$aEvent['object_id'];
  1801. $aContent = $this->_oDb->getEvents(array('browse' => 'id', 'value' => $iContent));
  1802. if(empty($aContent) || !is_array($aContent))
  1803. return array();
  1804. if($this->_oConfig->isSystem($aContent['type'], $aContent['action']))
  1805. $iEntryAuthor = (int)$aContent['owner_id'];
  1806. else
  1807. $iEntryAuthor = (int)$aContent['object_id'];
  1808. $sEntryCaption = call_user_func_array(array($this->_oConfig, 'getTitleShort'), !empty($aContent['title']) ? array($aContent['title']) : array($aContent['description'], $aContent['object_id']));
  1809. return array(
  1810. 'entry_sample' => $CNF['T']['txt_sample_single_ext'],
  1811. 'entry_url' => $this->_oConfig->getItemViewUrl($aContent),
  1812. 'entry_caption' => $sEntryCaption,
  1813. 'entry_author' => $iEntryAuthor,
  1814. 'lang_key' => '' //may be empty or not specified. In this case the default one from Notification module will be used.
  1815. );
  1816. }
  1817. /**
  1818. * @page service Service Calls
  1819. * @section bx_timeline Timeline
  1820. * @subsection bx_timeline-integration_notifications Integration with Notifications
  1821. * @subsubsection bx_timeline-get_notifications_comment get_notifications_comment
  1822. *
  1823. * @code bx_srv('bx_timeline', 'get_notifications_comment', [...]); @endcode
  1824. *
  1825. * Get data for Post Comment event to display in Notifications module.
  1826. *
  1827. * @param $aEvent an array with event description.
  1828. * @return an array with special format.
  1829. *
  1830. * @see BxTimelineModule::serviceGetNotificationsComment
  1831. */
  1832. /**
  1833. * @ref bx_timeline-get_notifications_comment "get_notifications_comment"
  1834. */
  1835. public function serviceGetNotificationsComment($aEvent)
  1836. {
  1837. $CNF = &$this->_oConfig->CNF;
  1838. $iContent = (int)$aEvent['object_id'];
  1839. $aContent = $this->_oDb->getEvents(array('browse' => 'id', 'value' => $iContent));
  1840. if(empty($aContent) || !is_array($aContent))
  1841. return array();
  1842. $oComment = BxDolCmts::getObjectInstance($CNF['OBJECT_COMMENTS'], $iContent);
  1843. if(!$oComment || !$oComment->isEnabled())
  1844. return array();
  1845. $sEntryCaption = call_user_func_array(array($this->_oConfig, 'getTitleShort'), !empty($aContent['title']) ? array($aContent['title']) : array($aContent['description'], $aContent['object_id']));
  1846. return array(
  1847. 'entry_sample' => $CNF['T']['txt_sample_single'],
  1848. 'entry_url' => $this->_oConfig->getItemViewUrl($aContent),
  1849. 'entry_caption' => $sEntryCaption,
  1850. 'entry_author' => $aContent['owner_id'],
  1851. 'subentry_sample' => $CNF['T']['txt_sample_comment_single'],
  1852. 'subentry_url' => $oComment->getViewUrl((int)$aEvent['subobject_id']),
  1853. 'lang_key' => '', //may be empty or not specified. In this case the default one from Notification module will be used.
  1854. );
  1855. }
  1856. /**
  1857. * @page service Service Calls
  1858. * @section bx_timeline Timeline
  1859. * @subsection bx_timeline-integration_notifications Integration with Notifications
  1860. * @subsubsection bx_timeline-get_notifications_vote get_notifications_vote
  1861. *
  1862. * @code bx_srv('bx_timeline', 'get_notifications_vote', [...]); @endcode
  1863. *
  1864. * Get data for Vote event to display in Notifications module.
  1865. *
  1866. * @param $aEvent an array with event description.
  1867. * @return an array with special format.
  1868. *
  1869. * @see BxTimelineModule::serviceGetNotificationsVote
  1870. */
  1871. /**
  1872. * @ref bx_timeline-get_notifications_vote "get_notifications_vote"
  1873. */
  1874. public function serviceGetNotificationsVote($aEvent)
  1875. {
  1876. $CNF = &$this->_oConfig->CNF;
  1877. $iContent = (int)$aEvent['object_id'];
  1878. $aContent = $this->_oDb->getEvents(array('browse' => 'id', 'value' => $iContent));
  1879. if(empty($aContent) || !is_array($aContent))
  1880. return array();
  1881. $oVote = BxDolVote::getObjectInstance($CNF['OBJECT_VOTES'], $iContent);
  1882. if(!$oVote || !$oVote->isEnabled())
  1883. return array();
  1884. $sEntryCaption = call_user_func_array(array($this->_oConfig, 'getTitleShort'), !empty($aContent['title']) ? array($aContent['title']) : array($aContent['description'], $aContent['object_id']));
  1885. return array(
  1886. 'entry_sample' => $CNF['T']['txt_sample_single'],
  1887. 'entry_url' => $this->_oConfig->getItemViewUrl($aContent),
  1888. 'entry_caption' => $sEntryCaption,
  1889. 'entry_author' => $aContent['owner_id'],
  1890. 'subentry_sample' => $CNF['T']['txt_sample_vote_single'],
  1891. 'lang_key' => '', //may be empty or not specified. In this case the default one from Notification module will be used.
  1892. );
  1893. }
  1894. /**
  1895. * Entry post vote for Notifications module
  1896. */
  1897. public function serviceGetNotificationsReaction($aEvent)
  1898. {
  1899. $CNF = &$this->_oConfig->CNF;
  1900. $iContent = (int)$aEvent['object_id'];
  1901. $aContent = $this->_oDb->getEvents(array('browse' => 'id', 'value' => $iContent));
  1902. if(empty($aContent) || !is_array($aContent))
  1903. return array();
  1904. $oReaction = BxDolVote::getObjectInstance($CNF['OBJECT_REACTIONS'], $iContent);
  1905. if(!$oReaction || !$oReaction->isEnabled())
  1906. return array();
  1907. $aSubentry = $oReaction->getTrackBy(array('type' => 'id', 'id' => (int)$aEvent['subobject_id']));
  1908. if(empty($aSubentry) || !is_array($aSubentry))
  1909. return array();
  1910. $aSubentrySampleParams = array();
  1911. $aReaction = $oReaction->getReaction($aSubentry['reaction']);
  1912. if(!empty($aReaction['title']))
  1913. $aSubentrySampleParams[] = $aReaction['title'];
  1914. else
  1915. $aSubentrySampleParams[] = '_undefined';
  1916. $sEntryCaption = call_user_func_array(array($this->_oConfig, 'getTitleShort'), !empty($aContent['title']) ? array($aContent['title']) : array($aContent['description'], $aContent['object_id']));
  1917. return array(
  1918. 'entry_sample' => $CNF['T']['txt_sample_single'],
  1919. 'entry_url' => $this->_oConfig->getItemViewUrl($aContent),
  1920. 'entry_caption' => $sEntryCaption,
  1921. 'entry_author' => $aContent['owner_id'],
  1922. 'subentry_sample' => $CNF['T']['txt_sample_reaction_single'],
  1923. 'subentry_sample_params' => $aSubentrySampleParams,
  1924. 'lang_key' => '', //may be empty or not specified. In this case the default one from Notification module will be used.
  1925. );
  1926. }
  1927. /**
  1928. * @page service Service Calls
  1929. * @section bx_timeline Timeline
  1930. * @subsection bx_timeline-integration_notifications Integration with Notifications
  1931. * @subsubsection bx_timeline-get_notifications_score_up get_notifications_score_up
  1932. *
  1933. * @code bx_srv('bx_timeline', 'get_notifications_score_up', [...]); @endcode
  1934. *
  1935. * Get data for Score Up Vote event to display in Notifications module.
  1936. *
  1937. * @param $aEvent an array with event description.
  1938. * @return an array with special format.
  1939. *
  1940. * @see BxTimelineModule::serviceGetNotificationsScoreUp
  1941. */
  1942. /**
  1943. * @ref bx_timeline-get_notifications_score_up "get_notifications_score_up"
  1944. */
  1945. public function serviceGetNotificationsScoreUp($aEvent)
  1946. {
  1947. return $this->_serviceGetNotificationsScore('up', $aEvent);
  1948. }
  1949. /**
  1950. * @page service Service Calls
  1951. * @section bx_timeline Timeline
  1952. * @subsection bx_timeline-integration_notifications Integration with Notifications
  1953. * @subsubsection bx_timeline-get_notifications_score_down get_notifications_score_down
  1954. *
  1955. * @code bx_srv('bx_timeline', 'get_notifications_score_down', [...]); @endcode
  1956. *
  1957. * Get data for Score Down Vote event to display in Notifications module.
  1958. *
  1959. * @param $aEvent an array with event description.
  1960. * @return an array with special format.
  1961. *
  1962. * @see BxTimelineModule::serviceGetNotificationsScoreDown
  1963. */
  1964. /**
  1965. * @ref bx_timeline-get_notifications_score_down "get_notifications_score_down"
  1966. */
  1967. public function serviceGetNotificationsScoreDown($aEvent)
  1968. {
  1969. return $this->_serviceGetNotificationsScore('down', $aEvent);
  1970. }
  1971. protected function _serviceGetNotificationsScore($sType, $aEvent)
  1972. {
  1973. $CNF = &$this->_oConfig->CNF;
  1974. $iContent = (int)$aEvent['object_id'];
  1975. $aContent = $this->_oDb->getEvents(array('browse' => 'id', 'value' => $iContent));
  1976. if(empty($aContent) || !is_array($aContent))
  1977. return array();
  1978. $oScore = BxDolScore::getObjectInstance($CNF['OBJECT_SCORES'], $iContent);
  1979. if(!$oScore || !$oScore->isEnabled())
  1980. return array();
  1981. $sEntryCaption = call_user_func_array(array($this->_oConfig, 'getTitleShort'), !empty($aContent['title']) ? array($aContent['title']) : array($aContent['description'], $aContent['object_id']));
  1982. return array(
  1983. 'entry_sample' => $CNF['T']['txt_sample_single'],
  1984. 'entry_url' => $this->_oConfig->getItemViewUrl($aContent),
  1985. 'entry_caption' => $sEntryCaption,
  1986. 'entry_author' => $aContent['owner_id'],
  1987. 'subentry_sample' => $CNF['T']['txt_sample_score_' . $sType . '_single'],
  1988. 'lang_key' => '', //may be empty or not specified. In this case the default one from Notification module will be used.
  1989. );
  1990. }
  1991. /**
  1992. * @page service Service Calls
  1993. * @section bx_timeline Timeline
  1994. * @subsection bx_timeline-repost Repost
  1995. * @subsubsection bx_timeline-get_repost_element_block get_repost_element_block
  1996. *
  1997. * @code bx_srv('bx_timeline', 'get_repost_element_block', [...]); @endcode
  1998. *
  1999. * Get repost element for content based modules.
  2000. *
  2001. * @param $iOwnerId integer value with owner profile ID.
  2002. * @param $sType string value with type (module name).
  2003. * @param $sAction string value with action (module action).
  2004. * @param $iObjectId integer value with object ID to be reposted.
  2005. * @param $aParams (optional) an array with additional params.
  2006. * @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.
  2007. *
  2008. * @see BxTimelineModule::serviceGetRepostElementBlock
  2009. */
  2010. /**
  2011. * @ref bx_timeline-get_repost_element_block "get_repost_element_block"
  2012. */
  2013. public function serviceGetRepostElementBlock($iOwnerId, $sType, $sAction, $iObjectId, $aParams = array())
  2014. {
  2015. if(!$this->isEnabled())
  2016. return '';
  2017. $aParams = array_merge($this->_oConfig->getRepostDefaults(), $aParams);
  2018. return $this->_oTemplate->getRepostElement($iOwnerId, $sType, $sAction, $iObjectId, $aParams);
  2019. }
  2020. /**
  2021. * @page service Service Calls
  2022. * @section bx_timeline Timeline
  2023. * @subsection bx_timeline-repost Repost
  2024. * @subsubsection bx_timeline-get_repost_counter get_repost_counter
  2025. *
  2026. * @code bx_srv('bx_timeline', 'get_repost_counter', [...]); @endcode
  2027. *
  2028. * Get repost counter.
  2029. *
  2030. * @param $sType string value with type (module name).
  2031. * @param $sAction string value with action (module action).
  2032. * @param $iObjectId integer value with object ID to be reposted.
  2033. * @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.
  2034. *
  2035. * @see BxTimelineModule::serviceGetRepostCounter
  2036. */
  2037. /**
  2038. * @ref bx_timeline-get_repost_counter "get_repost_counter"
  2039. */
  2040. public function serviceGetRepostCounter($sType, $sAction, $iObjectId)
  2041. {
  2042. if(!$this->isEnabled())
  2043. return '';
  2044. $aReposted = $this->_oDb->getReposted($sType, $sAction, $iObjectId);
  2045. return $this->_oTemplate->getRepostCounter($aReposted);
  2046. }
  2047. /**
  2048. * @page service Service Calls
  2049. * @section bx_timeline Timeline
  2050. * @subsection bx_timeline-repost Repost
  2051. * @subsubsection bx_timeline-get_repost_js_script get_repost_js_script
  2052. *
  2053. * @code bx_srv('bx_timeline', 'get_repost_js_script', [...]); @endcode
  2054. *
  2055. * Get repost JavaScript code.
  2056. *
  2057. * @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.
  2058. *
  2059. * @see BxTimelineModule::serviceGetRepostJsScript
  2060. */
  2061. /**
  2062. * @ref bx_timeline-get_repost_js_script "get_repost_js_script"
  2063. */
  2064. public function serviceGetRepostJsScript()
  2065. {
  2066. if(!$this->isEnabled())
  2067. return '';
  2068. return $this->_oTemplate->getRepostJsScript();
  2069. }
  2070. /**
  2071. * @page service Service Calls
  2072. * @section bx_timeline Timeline
  2073. * @subsection bx_timeline-repost Repost
  2074. * @subsubsection bx_timeline-get_repost_js_click get_repost_js_click
  2075. *
  2076. * @code bx_srv('bx_timeline', 'get_repost_js_click', [...]); @endcode
  2077. *
  2078. * Get repost JavaScript code for OnClick event.
  2079. *
  2080. * @param $iOwnerId integer value with owner profile ID.
  2081. * @param $sType string value with type (module name).
  2082. * @param $sAction string value with action (module action).
  2083. * @param $iObjectId integer value with object ID to be reposted.
  2084. * @return HTML string with JavaScript code to display in OnClick events of HTML elements.
  2085. *
  2086. * @see BxTimelineModule::serviceGetRepostJsClick
  2087. */
  2088. /**
  2089. * @ref bx_timeline-get_repost_js_click "get_repost_js_click"
  2090. */
  2091. public function serviceGetRepostJsClick($iOwnerId, $sType, $sAction, $iObjectId)
  2092. {
  2093. if(!$this->isEnabled())
  2094. return '';
  2095. return $this->_oTemplate->getRepostJsClick($iOwnerId, $sType, $sAction, $iObjectId);
  2096. }
  2097. /**
  2098. * @page service Service Calls
  2099. * @section bx_timeline Timeline
  2100. * @subsection bx_timeline-repost Repost
  2101. * @subsubsection bx_timeline-get_repost_to_js_click get_repost_to_js_click
  2102. *
  2103. * @code bx_srv('bx_timeline', 'get_repost_to_js_click', [...]); @endcode
  2104. *
  2105. * Get 'repost to' JavaScript code for OnClick event.
  2106. *
  2107. * @param $iReposterId integer value with reposter profile ID.
  2108. * @param $sType string value with type (module name).
  2109. * @param $sAction string value with action (module action).
  2110. * @param $iObjectId integer value with object ID to be reposted.
  2111. * @return HTML string with JavaScript code to display in OnClick events of HTML elements.
  2112. *
  2113. * @see BxTimelineModule::serviceGetRepostToJsClick
  2114. */
  2115. /**
  2116. * @ref bx_timeline-get_repost_to_js_click "get_repost_to_js_click"
  2117. */
  2118. public function serviceGetRepostToJsClick($iReposterId, $sType, $sAction, $iObjectId)
  2119. {
  2120. if(!$this->isEnabled())
  2121. return '';
  2122. return $this->_oTemplate->getRepostToJsClick($iReposterId, $sType, $sAction, $iObjectId);
  2123. }
  2124. /**
  2125. * @page service Service Calls
  2126. * @section bx_timeline Timeline
  2127. * @subsection bx_timeline-repost Repost
  2128. * @subsubsection bx_timeline-repost repost
  2129. *
  2130. * @code bx_srv('bx_timeline', 'repost', [...]); @endcode
  2131. *
  2132. * Perform repost action.
  2133. *
  2134. * @param $iAuthorId integer value with performer profile ID.
  2135. * @param $iOwnerId integer value with repost event owner profile ID.
  2136. * @param $sType string value with type (module name).
  2137. * @param $sAction string value with action (module action).
  2138. * @param $iObjectId integer value with object ID to be reposted.
  2139. * @parem $bForce boolean value force reposting without ACL check.
  2140. * @return an array with error (code and message) or integer with newly created repost event ID.
  2141. *
  2142. * @see BxTimelineModule::serviceRepost
  2143. */
  2144. /**
  2145. * @ref bx_timeline-repost "repost"
  2146. */
  2147. public function serviceRepost($iAuthorId, $iOwnerId, $sType, $sAction, $iObjectId, $bForce = false)
  2148. {
  2149. $aReposted = $this->_oDb->getReposted($sType, $sAction, $iObjectId);
  2150. if(empty($aReposted) || !is_array($aReposted))
  2151. return array('code' => 1, 'message' => _t('_bx_timeline_txt_err_cannot_repost'));
  2152. $mixedAllowed = $this->isAllowedRepost($aReposted, true);
  2153. if(!$bForce && $mixedAllowed !== true)
  2154. return array('code' => 2, 'message' => strip_tags($mixedAllowed));
  2155. $bReposted = $this->_oDb->isReposted($aReposted['id'], $iOwnerId, $iAuthorId);
  2156. if($bReposted)
  2157. return array('code' => 3, 'message' => _t('_bx_timeline_txt_err_already_reposted'));
  2158. $iId = $this->_oDb->insertEvent(array(
  2159. 'owner_id' => $iOwnerId,
  2160. 'system' => 0,
  2161. 'type' => $this->_oConfig->getPrefix('common_post') . 'repost',
  2162. 'action' => '',
  2163. 'object_id' => $iAuthorId,
  2164. 'object_owner_id' => $iAuthorId,
  2165. 'object_privacy_view' => $this->_oConfig->getPrivacyViewDefault('object'),
  2166. 'content' => serialize(array(
  2167. 'type' => $sType,
  2168. 'action' => $sAction,
  2169. 'object_id' => $iObjectId,
  2170. )),
  2171. 'title' => '',
  2172. 'description' => ''
  2173. ));
  2174. if(empty($iId))
  2175. return array('code' => 4, 'message' => _t('_bx_timeline_txt_err_cannot_repost'));
  2176. $this->onRepost($iId, $aReposted);
  2177. return $iId;
  2178. }
  2179. /**
  2180. * @page service Service Calls
  2181. * @section bx_timeline Timeline
  2182. * @subsection bx_timeline-repost Repost
  2183. * @subsubsection bx_timeline-repost_by_id repost_by_id
  2184. *
  2185. * @code bx_srv('bx_timeline', 'repost_by_id', [...]); @endcode
  2186. *
  2187. * Perform repost action by Timeline event ID.
  2188. *
  2189. * @param $iAuthorId integer value with performer profile ID.
  2190. * @param $iOwnerId integer value with repost event owner profile ID.
  2191. * @param $iEventId integer value with event ID which will be reposted.
  2192. * @parem $bForce boolean value force reposting without ACL check.
  2193. * @return an array with error (code and message) or integer with newly created repost event ID.
  2194. *
  2195. * @see BxTimelineModule::serviceRepostById
  2196. */
  2197. /**
  2198. * @ref bx_timeline-repost_by_id "repost_by_id"
  2199. */
  2200. public function serviceRepostById($iAuthorId, $iOwnerId, $iEventId, $bForce = false)
  2201. {
  2202. $aEvent = $this->_oDb->getEntriesBy(array('type' => 'id', 'id' => $iEventId));
  2203. if(empty($aEvent) || !is_array($aEvent))
  2204. return array('code' => 1, 'message' => _t('_bx_timeline_txt_err_cannot_repost'));
  2205. $sType = $aEvent['type'];
  2206. $sAction = $aEvent['action'];
  2207. $iObjectId = $this->_oConfig->isSystem($sType, $sAction) ? $aEvent['object_id'] : $aEvent['id'];
  2208. $sCommonPrefix = $this->_oConfig->getPrefix('common_post');
  2209. if(str_replace($sCommonPrefix, '', $sType) == BX_TIMELINE_PARSE_TYPE_REPOST) {
  2210. $aReposted = $this->_oDb->getReposted($sType, $sAction, $iObjectId);
  2211. if(empty($aReposted) || !is_array($aReposted))
  2212. return array('code' => 1, 'message' => _t('_bx_timeline_txt_err_cannot_repost'));
  2213. $aRepostedData = unserialize($aEvent['content']);
  2214. $sType = $aRepostedData['type'];
  2215. $sAction = $aRepostedData['action'];
  2216. $iObjectId = $aRepostedData['object_id'];
  2217. }
  2218. return $this->serviceRepost($iAuthorId, $iOwnerId, $sType, $sAction, $iObjectId, $bForce);
  2219. }
  2220. /**
  2221. * @page service Service Calls
  2222. * @section bx_timeline Timeline
  2223. * @subsection bx_timeline-other Other
  2224. * @subsubsection bx_timeline-update update
  2225. *
  2226. * @code bx_srv('bx_timeline', 'update', [...]); @endcode
  2227. *
  2228. * Update timeline event by ID.
  2229. *
  2230. * @param $iEventId integer value with event ID.
  2231. * @param $aSet an array with key=>value pairs for fields which should be updated.
  2232. * @return boolean value with the result of operation.
  2233. *
  2234. * @see BxTimelineModule::serviceUpdate
  2235. */
  2236. /**
  2237. * @ref bx_timeline-update "update"
  2238. */
  2239. public function serviceUpdate($iEventId, $aSet)
  2240. {
  2241. if(empty($iEventId))
  2242. return false;
  2243. return (int)$this->_oDb->updateEvent($aSet, array('id' => $iEventId)) > 0;
  2244. }
  2245. /**
  2246. * @page service Service Calls
  2247. * @section bx_timeline Timeline
  2248. * @subsection bx_timeline-other Other
  2249. * @subsubsection bx_timeline-get_menu_item_addon_comment get_menu_item_addon_comment
  2250. *
  2251. * @code bx_srv('bx_timeline', 'get_menu_item_addon_comment', [...]); @endcode
  2252. *
  2253. * Get addon for Comment menu item.
  2254. * NOTE. The service isn't used for now because comment functionality in card was updated.
  2255. *
  2256. * @param $sSystem string value with comments engine system.
  2257. * @param $iObjectId integer value with object ID.
  2258. * @return HTML string to display in menu item.
  2259. *
  2260. * @see BxTimelineModule::serviceGetMenuItemAddonComment
  2261. */
  2262. /**
  2263. * @ref bx_timeline-get_menu_item_addon_comment "get_menu_item_addon_comment"
  2264. */
  2265. public function serviceGetMenuItemAddonComment($sSystem, $iObjectId, $aBrowseParams = array())
  2266. {
  2267. if(empty($sSystem) || empty($iObjectId))
  2268. return '';
  2269. $oCmts = $this->getCmtsObject($sSystem, $iObjectId);
  2270. if($oCmts === false)
  2271. return '';
  2272. $iCounter = (int)$oCmts->getCommentsCount();
  2273. if(empty($iCounter))
  2274. return '';
  2275. return $this->_oTemplate->parseLink('javascript:void(0)', $iCounter, array(
  2276. 'class' => 'bx-menu-item-addon',
  2277. 'title' => _t('_bx_timeline_menu_item_title_item_comment'),
  2278. 'onclick' => "javascript:" . $this->_oConfig->getJsObjectView($aBrowseParams) . ".commentItem(this, '" . $sSystem . "', " . $iObjectId . ")"
  2279. ));
  2280. }
  2281. /**
  2282. * @page service Service Calls
  2283. * @section bx_timeline Timeline
  2284. * @subsection bx_timeline-other Other
  2285. * @subsubsection bx_timeline-get_settings_checker_helper get_settings_checker_helper
  2286. *
  2287. * @code bx_srv('bx_timeline', 'get_settings_checker_helper', [...]); @endcode
  2288. *
  2289. * Get Checker Helper class name for Forms engine.
  2290. *
  2291. * @return string with Checker Helper class name.
  2292. *
  2293. * @see BxTimelineModule::serviceGetSettingsCheckerHelper
  2294. */
  2295. /**
  2296. * @ref bx_timeline-get_settings_checker_helper "get_settings_checker_helper"
  2297. */
  2298. public function serviceGetSettingsCheckerHelper()
  2299. {
  2300. bx_import('FormCheckerHelper', $this->_aModule);
  2301. return 'BxTimelineFormCheckerHelper';
  2302. }
  2303. /**
  2304. * @page service Service Calls
  2305. * @section bx_timeline Timeline
  2306. * @subsection bx_timeline-other Other
  2307. * @subsubsection bx_timeline-get_options_videos_preload get_options_videos_preload
  2308. *
  2309. * @code bx_srv('bx_timeline', 'get_options_videos_preload', [...]); @endcode
  2310. *
  2311. * Get an array with available options for 'Videos preload in Timeline' setting.
  2312. *
  2313. * @return an array with available options represented as key => value pairs.
  2314. *
  2315. * @see BxTimelineModule::serviceGetOptionsVideosPreload
  2316. */
  2317. /**
  2318. * @ref bx_timeline-get_options_videos_preload "get_options_videos_preload"
  2319. */
  2320. public function serviceGetOptionsVideosPreload()
  2321. {
  2322. $CNF = &$this->_oConfig->CNF;
  2323. $aOptions = array('auto', 'metadata', 'none');
  2324. $aResult = array();
  2325. foreach($aOptions as $sOption)
  2326. $aResult[] = array(
  2327. 'key' => $sOption,
  2328. 'value' => _t($CNF['T']['option_vp_' . $sOption])
  2329. );
  2330. return $aResult;
  2331. }
  2332. /**
  2333. * @page service Service Calls
  2334. * @section bx_timeline Timeline
  2335. * @subsection bx_timeline-other Other
  2336. * @subsubsection bx_timeline-get_options_videos_autoplay get_options_videos_autoplay
  2337. *
  2338. * @code bx_srv('bx_timeline', 'get_options_videos_autoplay', [...]); @endcode
  2339. *
  2340. * Get an array with available options for 'Videos autoplay in Timeline' setting.
  2341. *
  2342. * @return an array with available options represented as key => value pairs.
  2343. *
  2344. * @see BxTimelineModule::serviceGetOptionsVideosAutoplay
  2345. */
  2346. /**
  2347. * @ref bx_timeline-get_options_videos_autoplay "get_options_videos_autoplay"
  2348. */
  2349. public function serviceGetOptionsVideosAutoplay()
  2350. {
  2351. $CNF = &$this->_oConfig->CNF;
  2352. $aOptions = array(BX_TIMELINE_VAP_OFF, BX_TIMELINE_VAP_ON_MUTE, BX_TIMELINE_VAP_ON);
  2353. $aResult = array();
  2354. foreach($aOptions as $sOption)
  2355. $aResult[] = array(
  2356. 'key' => $sOption,
  2357. 'value' => _t($CNF['T']['option_vap_' . $sOption])
  2358. );
  2359. return $aResult;
  2360. }
  2361. /**
  2362. * @page service Service Calls
  2363. * @section bx_timeline Timeline
  2364. * @subsection bx_timeline-other Other
  2365. * @subsubsection bx_timeline-get_options_attachments_layout get_options_attachments_layout
  2366. *
  2367. * @code bx_srv('bx_timeline', 'get_options_attachments_layout', [...]); @endcode
  2368. *
  2369. * Get an array with available options for 'Show attachments as' setting.
  2370. *
  2371. * @return an array with available options represented as key => value pairs.
  2372. *
  2373. * @see BxTimelineModule::serviceGetOptionsAttachmentsLayout
  2374. */
  2375. /**
  2376. * @ref bx_timeline-get_options_attachments_layout "get_options_attachments_layout"
  2377. */
  2378. public function serviceGetOptionsAttachmentsLayout()
  2379. {
  2380. $CNF = &$this->_oConfig->CNF;
  2381. $aOptions = array(BX_TIMELINE_ML_GALLERY, BX_TIMELINE_ML_SHOWCASE);
  2382. $aResult = array();
  2383. foreach($aOptions as $sOption)
  2384. $aResult[] = array(
  2385. 'key' => $sOption,
  2386. 'value' => _t($CNF['T']['option_al_' . $sOption])
  2387. );
  2388. return $aResult;
  2389. }
  2390. /**
  2391. * @page service Service Calls
  2392. * @section bx_timeline Timeline
  2393. * @subsection bx_timeline-other Other
  2394. * @subsubsection bx_timeline-get_live_update get_live_update
  2395. *
  2396. * @code bx_srv('bx_timeline', 'get_live_update', [...]); @endcode
  2397. *
  2398. * Get an array with actual Live Update info. Only one live update notification for all new events.
  2399. *
  2400. * @return an array with Live Update info.
  2401. *
  2402. * @see BxTimelineModule::serviceGetLiveUpdate
  2403. */
  2404. /**
  2405. * @ref bx_timeline-get_live_update "get_live_update"
  2406. */
  2407. public function serviceGetLiveUpdate($aBrowseParams, $iProfileId, $iValue = 0, $iInit = 0)
  2408. {
  2409. $CNF = &$this->_oConfig->CNF;
  2410. $sKey = $this->_oConfig->getLiveUpdateKey($aBrowseParams);
  2411. bx_import('BxDolSession');
  2412. if((int)BxDolSession::getInstance()->getValue($sKey) == 1)
  2413. return false;
  2414. $aParams = $this->_prepareParams($aBrowseParams);
  2415. $aParams = array_merge($aParams, array(
  2416. 'filter' => BX_TIMELINE_FILTER_OTHER_VIEWER
  2417. ));
  2418. $aEvents = $this->_oDb->getEvents($aParams);
  2419. if(empty($aEvents) || !is_array($aEvents))
  2420. return false;
  2421. $iValueNew = 0;
  2422. foreach($aEvents as $aEvent) {
  2423. if((int)$aEvent[$CNF['FIELD_STICKED']] != 0)
  2424. continue;
  2425. $sContent = $this->_oTemplate->getPost($aEvent, $aParams);
  2426. if(empty($sContent))
  2427. continue;
  2428. $iValueNew = $aEvent['id'];
  2429. break;
  2430. }
  2431. if($iValueNew == $iValue)
  2432. return false;
  2433. if((int)$iInit != 0)
  2434. return array('count' => $iValueNew);
  2435. return array(
  2436. 'count' => $iValueNew, // required (for initialization and visualization)
  2437. 'method' => $this->_oConfig->getJsObjectView($aBrowseParams) . '.showLiveUpdate(oData)', // required (for visualization)
  2438. 'data' => array(
  2439. 'code' => $this->_oTemplate->getLiveUpdate($aBrowseParams, $iProfileId, $iValue, $iValueNew)
  2440. ), // optional, may have some additional data to be passed in JS method provided using 'method' param above.
  2441. );
  2442. }
  2443. /**
  2444. * @page service Service Calls
  2445. * @section bx_timeline Timeline
  2446. * @subsection bx_timeline-other Other
  2447. * @subsubsection bx_timeline-get_live_updates get_live_updates
  2448. *
  2449. * @code bx_srv('bx_timeline', 'get_live_updates', [...]); @endcode
  2450. *
  2451. * Get an array with actual Live Update info. Separate live update notification for each new Event.
  2452. * Note. This method isn't used for now. @see BxTimelineModule::serviceGetLiveUpdate method instead.
  2453. *
  2454. * Note. This way to display live update notifications isn't used for now.
  2455. * See BxTimelineModule::serviceGetLiveUpdate method instead.
  2456. *
  2457. * @return an array with Live Update info.
  2458. *
  2459. * @see BxTimelineModule::serviceGetLiveUpdates
  2460. */
  2461. /**
  2462. * @ref bx_timeline-get_live_updates "get_live_updates"
  2463. */
  2464. public function serviceGetLiveUpdates($aBrowseParams, $iProfileId, $iCount = 0, $iInit = 0)
  2465. {
  2466. $sKey = $this->_oConfig->getLiveUpdateKey($aBrowseParams);
  2467. bx_import('BxDolSession');
  2468. if((int)BxDolSession::getInstance()->getValue($sKey) == 1)
  2469. return false;
  2470. $aParams = $this->_prepareParams($aBrowseParams);
  2471. $aParams['filter'] = BX_TIMELINE_FILTER_OTHER_VIEWER;
  2472. $aParams['count'] = true;
  2473. $iCountNew = $this->_oDb->getEvents($aParams);
  2474. if($iCountNew == $iCount)
  2475. return false;
  2476. if((int)$iInit != 0)
  2477. return array('count' => $iCountNew);
  2478. return array(
  2479. 'count' => $iCountNew, // required (for initialization and visualization)
  2480. 'method' => $this->_oConfig->getJsObjectView($aBrowseParams) . '.showLiveUpdates(oData)', // required (for visualization)
  2481. 'data' => array(
  2482. 'code' => $this->_oTemplate->getLiveUpdates($aBrowseParams, $iProfileId, $iCount, $iCountNew)
  2483. ), // optional, may have some additional data to be passed in JS method provided using 'method' param above.
  2484. );
  2485. }
  2486. /**
  2487. * @page service Service Calls
  2488. * @section bx_timeline Accounts
  2489. * @subsection bx_timeline-other Other
  2490. * @subsubsection bx_timeline-get_menu_addon_manage_tools get_menu_addon_manage_tools
  2491. *
  2492. * @code bx_srv('bx_timeline', 'get_menu_addon_manage_tools', [...]); @endcode
  2493. *
  2494. * Get number of 'hidden' events for User End -> Dasboard page -> Manage block.
  2495. *
  2496. * @return integer number of 'hidden' events
  2497. *
  2498. * @see BxTimelineModule::serviceGetMenuAddonManageTools
  2499. */
  2500. /**
  2501. * @ref bx_timeline-get_menu_addon_manage_tools "get_menu_addon_manage_tools"
  2502. */
  2503. public function serviceGetMenuAddonManageTools()
  2504. {
  2505. $CNF = &$this->_oConfig->CNF;
  2506. bx_import('SearchResult', $this->_aModule);
  2507. $sClass = $this->_aModule['class_prefix'] . 'SearchResult';
  2508. $oSearch = new $sClass();
  2509. $oSearch->unsetPaginate();
  2510. $oSearch->fillFilters(array('status' => BX_TIMELINE_STATUS_HIDDEN));
  2511. $iNum1 = $oSearch->getNum();
  2512. $oSearch->fillFilters(array('status' => ''));
  2513. $oSearch->fillFiltersByObjects(array('reported' => array('value' => '0', 'field' => 'reports', 'operator' => '>')));
  2514. $iNum2 = $oSearch->getNum();
  2515. return array(
  2516. 'counter1_value' => $iNum1,
  2517. 'counter2_value' => $iNum2,
  2518. 'counter3_value' => 0
  2519. );
  2520. }
  2521. /**
  2522. * @page service Service Calls
  2523. * @section bx_timeline Accounts
  2524. * @subsection bx_timeline-other Other
  2525. * @subsubsection bx_timeline-get_menu_addon_profile_stats get_menu_addon_profile_stats
  2526. *
  2527. * @code bx_srv('bx_timeline', 'get_menu_addon_profile_stats', [...]); @endcode
  2528. *
  2529. * Get number of 'muted' events for currently logged in user. User End -> Profile Stats.
  2530. *
  2531. * @return integer number of 'muted' events
  2532. *
  2533. * @see BxTimelineModule::serviceGetMenuAddonProfileStats
  2534. */
  2535. /**
  2536. * @ref bx_timeline-get_menu_addon_profile_stats "get_menu_addon_profile_stats"
  2537. */
  2538. public function serviceGetMenuAddonProfileStats($iProfileId = 0)
  2539. {
  2540. if(empty($iProfileId))
  2541. $iProfileId = $this->_iProfileId;
  2542. return $this->getConnectionMuteObject()->getConnectedContentCount($iProfileId);
  2543. }
  2544. public function serviceGet($aParams)
  2545. {
  2546. $aParams = $this->_prepareParams($aParams);
  2547. $aParams['return_data_type'] = 'array';
  2548. return $this->_oTemplate->getPosts($aParams);
  2549. }
  2550. public function serviceAdd($aValues)
  2551. {
  2552. return $this->getFormPost(array(
  2553. 'values' => $aValues
  2554. ));
  2555. }
  2556. public function serviceEdit($iId, $aValues)
  2557. {
  2558. return $this->getFormEdit($iId, array(
  2559. 'values' => $aValues
  2560. ));
  2561. }
  2562. /**
  2563. * Delete content entry
  2564. * @param $iContentId content id
  2565. * @return error message or empty string on success
  2566. */
  2567. public function serviceDeleteEntity ($iContentId, $sFuncDelete = 'deleteData')
  2568. {
  2569. $aEvent = $this->_oDb->getEvents(array('browse' => 'id', 'value' => $iContentId));
  2570. if(empty($aEvent) || !is_array($aEvent))
  2571. return _t('_Empty');
  2572. if(!$this->deleteEvent($aEvent))
  2573. return _t('_bx_timeline_txt_err_cannot_perform_action');
  2574. return '';
  2575. }
  2576. /*
  2577. * COMMON METHODS
  2578. */
  2579. public function getItemData($iId, $aParams = array())
  2580. {
  2581. $CNF = &$this->_oConfig->CNF;
  2582. if(empty($aParams))
  2583. $aParams = $this->_prepareParams(array(
  2584. 'view' => BX_TIMELINE_VIEW_ITEM,
  2585. 'type' => BX_TIMELINE_TYPE_ITEM
  2586. ));
  2587. $aEvent = $this->_oDb->getEvents(array('browse' => 'id', 'value' => $iId));
  2588. if(empty($aEvent))
  2589. return array('code' => 1, 'content' => _t('_Empty'));
  2590. $iProfile = (int)$aEvent[$CNF['FIELD_OWNER_ID']];
  2591. if(!empty($iProfile)) {
  2592. $oProfile = BxDolProfile::getInstance($iProfile);
  2593. if(!$oProfile)
  2594. return array('code' => 1, 'content' => _t('_Empty'));
  2595. $mixedResult = $oProfile->checkAllowedProfileView();
  2596. if($mixedResult !== CHECK_ACTION_RESULT_ALLOWED)
  2597. return array('code' => 2, 'content' => $mixedResult);
  2598. }
  2599. $sContent = $this->_oTemplate->getPost($aEvent, $aParams);
  2600. if(empty($sContent))
  2601. return array('code' => 2, 'content' => _t('_Access denied'));
  2602. $sKey = 'allowed_view';
  2603. if(isset($aEvent[$sKey]) && $aEvent[$sKey] !== CHECK_ACTION_RESULT_ALLOWED)
  2604. return array('code' => 2, 'content' => $aEvent[$sKey]);
  2605. if($this->isAllowedView($aEvent) !== true)
  2606. return array('code' => 2, 'content' => _t('_Access denied'));
  2607. return array('code' => 0, 'content' => $sContent, 'event' => $aEvent);
  2608. }
  2609. public function deleteEvent($aEvent)
  2610. {
  2611. if(empty($aEvent) || !is_array($aEvent) || !$this->_oDb->deleteEvent(array('id' => (int)$aEvent['id'])))
  2612. return false;
  2613. $this->onDelete($aEvent);
  2614. return true;
  2615. }
  2616. public function addAttachLink($aValues, $sDisplay = false)
  2617. {
  2618. $CNF = &$this->_oConfig->CNF;
  2619. if(!$sDisplay)
  2620. $sDisplay = $this->_oConfig->getObject('form_display_attach_link_add');
  2621. $oForm = BxDolForm::getObjectInstance($this->_oConfig->getObject('form_attach_link'), $sDisplay, $this->_oTemplate);
  2622. if(!$oForm)
  2623. return array('message' => '_sys_txt_error_occured');
  2624. $oForm->aFormAttrs['method'] = BX_DOL_FORM_METHOD_SPECIFIC;
  2625. $oForm->aParams['csrf']['disable'] = true;
  2626. if(!empty($oForm->aParams['db']['submit_name'])) {
  2627. $sSubmitName = $oForm->aParams['db']['submit_name'];
  2628. if(!isset($oForm->aInputs[$sSubmitName])) {
  2629. if(isset($oForm->aInputs[$CNF['FIELD_CONTROLS']]))
  2630. foreach($oForm->aInputs[$CNF['FIELD_CONTROLS']] as $mixedIndex => $aInput) {
  2631. if(!is_numeric($mixedIndex) || empty($aInput['name']) || $aInput['name'] != $sSubmitName)
  2632. continue;
  2633. $aValues[$sSubmitName] = $aInput['value'];
  2634. }
  2635. }
  2636. else
  2637. $aValues[$sSubmitName] = $oForm->aInputs[$sSubmitName]['value'];
  2638. }
  2639. $oForm->aInputs['url']['checker']['params']['preg'] = $this->_oConfig->getPregPattern('url');
  2640. $oForm->initChecker(array(), $aValues);
  2641. if(!$oForm->isSubmittedAndValid())
  2642. return array('message' => '_sys_txt_error_occured');
  2643. return $this->_addLink($oForm);
  2644. }
  2645. public function getFormAttachLink($iEventId = 0)
  2646. {
  2647. $oForm = BxDolForm::getObjectInstance($this->_oConfig->getObject('form_attach_link'), $this->_oConfig->getObject('form_display_attach_link_add'), $this->_oTemplate);
  2648. $oForm->aFormAttrs['action'] = BX_DOL_URL_ROOT . $this->_oConfig->getBaseUri() . 'submit_attach_link_form/';
  2649. $oForm->aInputs['event_id']['value'] = $iEventId;
  2650. $oForm->aInputs['url']['checker']['params']['preg'] = $this->_oConfig->getPregPattern('url');
  2651. $oForm->initChecker();
  2652. if($oForm->isSubmittedAndValid())
  2653. return $this->_addLink($oForm);
  2654. return array('form' => $oForm->getCode(), 'form_id' => $oForm->id);
  2655. }
  2656. public function getFormPost($aParams = array())
  2657. {
  2658. $CNF = &$this->_oConfig->CNF;
  2659. $iUserId = $this->getUserId();
  2660. $oForm = $this->getFormPostObject($aParams);
  2661. $aFormInitCheckerParams = array();
  2662. $bValues = !empty($aParams['values']) && is_array($aParams['values']);
  2663. if($bValues) {
  2664. $this->_prepareFormForAutoSubmit($oForm, $aParams['values']);
  2665. $aFormInitCheckerParams = array(array(), $aParams['values']);
  2666. unset($aParams['values']);
  2667. }
  2668. call_user_func_array(array($oForm, 'initChecker'), $aFormInitCheckerParams);
  2669. $bAjaxMode = $oForm->isAjaxMode();
  2670. $bDynamicMode = $bAjaxMode;
  2671. if($oForm->isSubmittedAndValid()) {
  2672. $sType = $oForm->getCleanValue('type');
  2673. $sType = $this->_oConfig->getPrefix('common_post') . $sType;
  2674. BxDolForm::setSubmittedValue('type', $sType, $oForm->aFormAttrs['method']);
  2675. $aContent = array();
  2676. //--- Process Text ---//
  2677. $sText = $oForm->getCleanValue('text');
  2678. $sText = $this->_prepareTextForSave($sText);
  2679. $bText = !empty($sText);
  2680. if($bText)
  2681. $aContent['text'] = $sText;
  2682. //--- Process Context and Privacy ---//
  2683. $iOwnerId = (int)$oForm->getCleanValue('owner_id');
  2684. $iObjectPrivacyView = (int)$oForm->getCleanValue('object_privacy_view');
  2685. $iObjectPrivacyViewDefault = $this->_oConfig->getPrivacyViewDefault('object');
  2686. if(empty($iObjectPrivacyView))
  2687. $iObjectPrivacyView = $iObjectPrivacyViewDefault;
  2688. else if($iObjectPrivacyView < 0)
  2689. $iOwnerId = abs($iObjectPrivacyView);
  2690. //--- Process Link ---//
  2691. $aLinkIds = $oForm->getCleanValue($CNF['FIELD_LINK']);
  2692. $bLinkIds = !empty($aLinkIds) && is_array($aLinkIds);
  2693. //--- Process Photos ---//
  2694. $aPhotoIds = $oForm->getCleanValue($CNF['FIELD_PHOTO']);
  2695. $bPhotoIds = !empty($aPhotoIds) && is_array($aPhotoIds);
  2696. //--- Process Videos ---//
  2697. $aVideoIds = $oForm->getCleanValue($CNF['FIELD_VIDEO']);
  2698. $bVideoIds = !empty($aVideoIds) && is_array($aVideoIds);
  2699. //--- Process Files ---//
  2700. $aFileIds = $oForm->getCleanValue($CNF['FIELD_FILE']);
  2701. $bFileIds = !empty($aFileIds) && is_array($aFileIds);
  2702. if(!$bText && !$bLinkIds && !$bPhotoIds && !$bVideoIds && !$bFileIds) {
  2703. $oForm->aInputs['text']['error'] = _t('_bx_timeline_txt_err_empty_post');
  2704. $oForm->setValid(false);
  2705. return $this->_prepareResponse(array('form' => $oForm->getCode($bDynamicMode), 'form_id' => $oForm->id), $bAjaxMode);
  2706. }
  2707. $sTitle = $bText ? $this->_oConfig->getTitle($sText) : $this->_oConfig->getTitleDefault($bLinkIds, $bPhotoIds, $bVideoIds, $bFileIds);
  2708. $sDescription = _t('_bx_timeline_txt_user_added_sample', '{profile_name}', _t('_bx_timeline_txt_sample_with_article'));
  2709. /**
  2710. * Unset 'text' input because its data was already processed
  2711. * and will be saved via additional values which were passed
  2712. * to BxDolForm::insert method.
  2713. */
  2714. unset($oForm->aInputs['text']);
  2715. $iId = $oForm->insert(array(
  2716. 'owner_id' => $iOwnerId,
  2717. 'object_id' => $iUserId,
  2718. 'object_owner_id' => $iUserId,
  2719. 'object_privacy_view' => $iObjectPrivacyView,
  2720. 'content' => serialize($aContent),
  2721. 'title' => $sTitle,
  2722. 'description' => $sDescription
  2723. ));
  2724. if(!empty($iId)) {
  2725. $aContent = array_merge($aContent, array(
  2726. 'timeline_group' => array(
  2727. 'by' => $this->getName() . '_' . $iUserId . '_' . $iId,
  2728. 'field' => 'owner_id'
  2729. )
  2730. ));
  2731. $this->_oDb->updateEvent(array('content' => serialize($aContent)), array('id' => $iId));
  2732. //--- Process Meta ---//
  2733. $oMetatags = BxDolMetatags::getObjectInstance($this->_oConfig->getObject('metatags'));
  2734. if($bText)
  2735. $oMetatags->metaAdd($iId, $sText);
  2736. $oMetatags->locationsAddFromForm($iId, $this->_oConfig->CNF['FIELD_LOCATION_PREFIX']);
  2737. //--- Process Link ---//
  2738. if($bLinkIds)
  2739. foreach($aLinkIds as $iLinkId)
  2740. $this->_oDb->saveLink($iId, $iLinkId);
  2741. //--- Process Media ---//
  2742. $this->_saveMedia($CNF['FIELD_PHOTO'], $iId, $aPhotoIds, $iUserId, true);
  2743. $this->_saveMedia($CNF['FIELD_VIDEO'], $iId, $aVideoIds, $iUserId, true);
  2744. $this->_saveMedia($CNF['FIELD_FILE'], $iId, $aFileIds, $iUserId, true);
  2745. $this->onPost($iId);
  2746. return $this->_prepareResponse(array('id' => $iId), $bAjaxMode, array(
  2747. 'redirect' => $this->_oConfig->getItemViewUrl(array('id' => $iId))
  2748. ));
  2749. }
  2750. return $this->_prepareResponse(array('message' => _t('_bx_timeline_txt_err_cannot_perform_action')), $bAjaxMode);
  2751. }
  2752. $mixedResult = $this->_prepareResponse(array('form' => $oForm->getCode($bDynamicMode), 'form_id' => $oForm->id), $bAjaxMode && $oForm->isSubmitted());
  2753. if(is_array($mixedResult))
  2754. $mixedResult['form_object'] = $oForm;
  2755. return $mixedResult;
  2756. }
  2757. public function getFormEdit($iId, $aParams = array(), $aBrowseParams = array())
  2758. {
  2759. $CNF = &$this->_oConfig->CNF;
  2760. $sJsObjectView = $this->_oConfig->getJsObjectView($aBrowseParams);
  2761. $iUserId = $this->getUserId();
  2762. $aEvent = $this->_oDb->getEvents(array('browse' => 'id', 'value' => $iId));
  2763. if(empty($aEvent) || !is_array($aEvent))
  2764. return array();
  2765. $aContent = unserialize($aEvent['content']);
  2766. if(is_array($aContent) && !empty($aContent['text']))
  2767. $aEvent['text'] = $aContent['text'];
  2768. if(empty($aParams['form_object']))
  2769. $aParams['form_object'] = 'form_post';
  2770. if(empty($aParams['form_display']))
  2771. $aParams['form_display'] = 'form_display_post_edit';
  2772. $oForm = $this->getFormPostObject($aParams);
  2773. $oForm->setId($this->_oConfig->getHtmlIds('view', 'edit_form') . $iId);
  2774. $aFormInitCheckerParams = array();
  2775. $bValues = !empty($aParams['values']) && is_array($aParams['values']);
  2776. if($bValues) {
  2777. $this->_prepareFormForAutoSubmit($oForm, $aParams['values']);
  2778. $aFormInitCheckerParams = array(array(), array_merge($aEvent, $aParams['values']));
  2779. unset($aParams['values']);
  2780. }
  2781. else {
  2782. $oForm->aFormAttrs['action'] = BX_DOL_URL_ROOT . $this->_oConfig->getBaseUri() . 'edit/' . $iId ;
  2783. if(!empty($aBrowseParams) && is_array($aBrowseParams))
  2784. $oForm->aFormAttrs['action'] = $this->_oConfig->addBrowseParams($oForm->aFormAttrs['action'], $aBrowseParams);
  2785. foreach($oForm->aInputs[$CNF['FIELD_CONTROLS']] as $mixedIndex => $aInput) {
  2786. if(!is_numeric($mixedIndex))
  2787. continue;
  2788. $oForm->aInputs[$CNF['FIELD_CONTROLS']][$mixedIndex]['attrs'] = bx_replace_markers($aInput['attrs'], array(
  2789. 'js_object_view' => $sJsObjectView,
  2790. 'content_id' => $iId
  2791. ));
  2792. }
  2793. $aFormInitCheckerParams = array($aEvent);
  2794. }
  2795. call_user_func_array(array($oForm, 'initChecker'), $aFormInitCheckerParams);
  2796. $bAjaxMode = $oForm->isAjaxMode();
  2797. $bDynamicMode = $bAjaxMode || bx_is_dynamic_request();
  2798. $sCodeAdd = '';
  2799. if($bDynamicMode) {
  2800. $sCodeAdd .= $this->_oTemplate->getAddedJs('post', $bDynamicMode);
  2801. $sCodeAdd .= $this->_oTemplate->getJsCode('post', array(), true, $bDynamicMode);
  2802. }
  2803. if($oForm->isSubmittedAndValid()) {
  2804. $aContent = array();
  2805. //--- Process Text ---//
  2806. $sText = $oForm->getCleanValue('text');
  2807. $sText = $this->_prepareTextForSave($sText);
  2808. $bText = !empty($sText);
  2809. unset($oForm->aInputs['text']);
  2810. if($bText)
  2811. $aContent['text'] = $sText;
  2812. $aValsToAdd = array(
  2813. 'content' => serialize($aContent)
  2814. );
  2815. //--- Process Privacy ---//
  2816. if(isset($oForm->aInputs[$CNF['FIELD_OBJECT_PRIVACY_VIEW']])) {
  2817. $iObjectPrivacyView = (int)$oForm->getCleanValue('object_privacy_view');
  2818. $iObjectPrivacyViewDefault = $this->_oConfig->getPrivacyViewDefault('object');
  2819. if(empty($iObjectPrivacyView))
  2820. $aValsToAdd = array_merge($aValsToAdd, array(
  2821. 'object_privacy_view' => $iObjectPrivacyViewDefault
  2822. ));
  2823. else if($iObjectPrivacyView < 0)
  2824. $aValsToAdd = array_merge($aValsToAdd, array(
  2825. 'owner_id' => abs($iObjectPrivacyView)
  2826. ));
  2827. }
  2828. //--- Process Link ---//
  2829. $aLinkIds = $oForm->getCleanValue($CNF['FIELD_LINK']);
  2830. $bLinkIds = !empty($aLinkIds) && is_array($aLinkIds);
  2831. //--- Process Media ---//
  2832. $aPhotoIds = $oForm->getCleanValue($CNF['FIELD_PHOTO']);
  2833. $bPhotoIds = !empty($aPhotoIds) && is_array($aPhotoIds);
  2834. $aVideoIds = $oForm->getCleanValue($CNF['FIELD_VIDEO']);
  2835. $bVideoIds = !empty($aVideoIds) && is_array($aVideoIds);
  2836. if($bVideoIds)
  2837. $aValsToAdd[$CNF['FIELD_STATUS']] = 'awaiting';
  2838. $aFileIds = $oForm->getCleanValue($CNF['FIELD_FILE']);
  2839. $bFileIds = !empty($aFileIds) && is_array($aFileIds);
  2840. if(!$bText && !$bLinkIds && !$bPhotoIds && !$bVideoIds && !$bFileIds) {
  2841. $oForm->aInputs['text']['error'] = _t('_bx_timeline_txt_err_empty_post');
  2842. $oForm->setValid(false);
  2843. return $this->_prepareResponse(array('form' => $sCodeAdd . $oForm->getCode($bDynamicMode), 'form_id' => $oForm->id), $bAjaxMode);
  2844. }
  2845. if($oForm->update($iId, $aValsToAdd) === false)
  2846. return array('message' => _t('_bx_timeline_txt_err_cannot_perform_action'));
  2847. $oMetatags = BxDolMetatags::getObjectInstance($this->_oConfig->getObject('metatags'));
  2848. if($bText)
  2849. $oMetatags->metaAdd($iId, $sText);
  2850. $oMetatags->locationsAddFromForm($iId, $this->_oConfig->CNF['FIELD_LOCATION_PREFIX']);
  2851. //--- Process Link ---//
  2852. if($bLinkIds)
  2853. foreach($aLinkIds as $iLinkId)
  2854. $this->_oDb->saveLink($iId, $iLinkId);
  2855. //--- Process Media ---//
  2856. $this->_saveMedia($CNF['FIELD_PHOTO'], $iId, $aPhotoIds, $iUserId);
  2857. $this->_saveMedia($CNF['FIELD_VIDEO'], $iId, $aVideoIds, $iUserId);
  2858. $this->_saveMedia($CNF['FIELD_FILE'], $iId, $aFileIds, $iUserId);
  2859. $this->getCacheItemObject()->removeAllByPrefix($this->_oConfig->getPrefix('cache_item') . $iId);
  2860. return array(
  2861. 'id' => $iId
  2862. );
  2863. }
  2864. return array(
  2865. 'id' => $iId,
  2866. 'form' => $sCodeAdd . $oForm->getCode($bDynamicMode),
  2867. 'form_id' => $oForm->id,
  2868. 'eval' => $sJsObjectView . '.onEditPost(oData)'
  2869. );
  2870. }
  2871. public function getFormPostObject($aParams)
  2872. {
  2873. $sFormObject = !empty($aParams['form_object']) ? $aParams['form_object'] : 'form_post';
  2874. $sFormDisplay = !empty($aParams['form_display']) ? $aParams['form_display'] : 'form_display_post_add';
  2875. $oForm = BxDolForm::getObjectInstance($this->_oConfig->getObject($sFormObject), $this->_oConfig->getObject($sFormDisplay), $this->_oTemplate);
  2876. /**
  2877. * Note. 'ajax_mode' parameter isn't checked because
  2878. * timeline post form works as Ajax form by default.
  2879. */
  2880. $sParamsKey = 'visibility_autoselect';
  2881. if(isset($aParams[$sParamsKey]) && (bool)$aParams[$sParamsKey] === true)
  2882. $oForm->setVisibilityAutoselect((bool)$aParams[$sParamsKey]);
  2883. $oForm->init();
  2884. return $oForm;
  2885. }
  2886. public function getCmtsObject($sSystem, $iId)
  2887. {
  2888. if(empty($sSystem) || (int)$iId == 0)
  2889. return false;
  2890. $oCmts = BxDolCmts::getObjectInstance($sSystem, $iId, true, $this->_oTemplate);
  2891. if(!$oCmts || !$oCmts->isEnabled())
  2892. return false;
  2893. return $oCmts;
  2894. }
  2895. public function getViewObject($sSystem, $iId)
  2896. {
  2897. if(empty($sSystem) || (int)$iId == 0)
  2898. return false;
  2899. $oView = BxDolView::getObjectInstance($sSystem, $iId, true, $this->_oTemplate);
  2900. if(!$oView || !$oView->isEnabled())
  2901. return false;
  2902. return $oView;
  2903. }
  2904. public function getVoteObject($sSystem, $iId)
  2905. {
  2906. if(empty($sSystem) || (int)$iId == 0)
  2907. return false;
  2908. $oVote = BxDolVote::getObjectInstance($sSystem, $iId, true, $this->_oTemplate);
  2909. if(!$oVote || !$oVote->isEnabled())
  2910. return false;
  2911. return $oVote;
  2912. }
  2913. public function getReactionObject($sSystem, $iId)
  2914. {
  2915. if(empty($sSystem) || (int)$iId == 0)
  2916. return false;
  2917. $oReaction = BxDolVote::getObjectInstance($sSystem, $iId, true, $this->_oTemplate);
  2918. if(!$oReaction || !$oReaction->isEnabled())
  2919. return false;
  2920. return $oReaction;
  2921. }
  2922. public function getScoreObject($sSystem, $iId)
  2923. {
  2924. if(empty($sSystem) || (int)$iId == 0)
  2925. return false;
  2926. $oScore = BxDolScore::getObjectInstance($sSystem, $iId, true, $this->_oTemplate);
  2927. if(!$oScore || !$oScore->isEnabled())
  2928. return false;
  2929. return $oScore;
  2930. }
  2931. public function getReportObject($sSystem, $iId)
  2932. {
  2933. if(empty($sSystem) || (int)$iId == 0)
  2934. return false;
  2935. $oReport = BxDolReport::getObjectInstance($sSystem, $iId, true, $this->_oTemplate);
  2936. if(!$oReport || !$oReport->isEnabled())
  2937. return false;
  2938. return $oReport;
  2939. }
  2940. public function getAttachmentsMenuObject()
  2941. {
  2942. return BxDolMenu::getObjectInstance($this->_oConfig->getObject('menu_post_attachments'), $this->_oTemplate);
  2943. }
  2944. public function getManageMenuObject()
  2945. {
  2946. return BxDolMenu::getObjectInstance($this->_oConfig->getObject('menu_item_manage'), $this->_oTemplate);
  2947. }
  2948. public function getCacheItemObject()
  2949. {
  2950. $oCacheEngine = bx_instance('BxDolCache' . $this->_oConfig->getCacheItemEngine());
  2951. if(!$oCacheEngine->isAvailable())
  2952. $oCacheEngine = bx_instance('BxDolCacheFile');
  2953. return $oCacheEngine;
  2954. }
  2955. public function getConnectionMuteObject()
  2956. {
  2957. return BxDolConnection::getObjectInstance($this->_oConfig->getObject('connection_mute'));
  2958. }
  2959. //--- Check permissions methods ---//
  2960. public function serviceCheckAllowedViewForProfile ($aDataEntry, $isPerformAction = false, $iProfileId = false)
  2961. {
  2962. if(!$iProfileId)
  2963. $iProfileId = $this->_iProfileId;
  2964. $CNF = &$this->_oConfig->CNF;
  2965. // moderator and owner always have access
  2966. $iOwnerId = (int)$aDataEntry['owner_id'];
  2967. if(!empty($iProfileId) && (abs($iOwnerId) == (int)$iProfileId || $this->isModerator()))
  2968. return CHECK_ACTION_RESULT_ALLOWED;
  2969. // check ACL
  2970. if($iOwnerId != 0 && ($oOwner = BxDolProfile::getInstanceMagic($iOwnerId)) !== false) {
  2971. $mixedCheckResult = BxDolService::call($oOwner->getModule(), 'check_allowed_with_content_for_profile', array('view', $oOwner->getContentId(), $iProfileId));
  2972. if($mixedCheckResult !== CHECK_ACTION_RESULT_ALLOWED)
  2973. return $mixedCheckResult;
  2974. }
  2975. // check privacy
  2976. if(!empty($CNF['OBJECT_PRIVACY_VIEW'])) {
  2977. $oPrivacy = BxDolPrivacy::getObjectInstance($CNF['OBJECT_PRIVACY_VIEW']);
  2978. if($oPrivacy && !$oPrivacy->check($aDataEntry[$CNF['FIELD_ID']], $iProfileId))
  2979. return _t('_sys_access_denied_to_private_content');
  2980. }
  2981. // check alert to allow custom checks
  2982. $mixedResult = null;
  2983. bx_alert('system', 'check_allowed_view', 0, 0, array('module' => $this->getName(), 'content_info' => $aDataEntry, 'profile_id' => $iProfileId, 'override_result' => &$mixedResult));
  2984. if($mixedResult !== null)
  2985. return $mixedResult;
  2986. return CHECK_ACTION_RESULT_ALLOWED;
  2987. }
  2988. public function isModerator()
  2989. {
  2990. $sModule = $this->getName();
  2991. $iUserId = (int)$this->getUserId();
  2992. $aCheckResult = checkActionModule($iUserId, 'edit', $sModule);
  2993. if($aCheckResult[CHECK_ACTION_RESULT] === CHECK_ACTION_RESULT_ALLOWED)
  2994. return true;
  2995. $aCheckResult = checkActionModule($iUserId, 'delete', $sModule);
  2996. if($aCheckResult[CHECK_ACTION_RESULT] === CHECK_ACTION_RESULT_ALLOWED)
  2997. return true;
  2998. return false;
  2999. }
  3000. public function isAllowedPost($bPerform = false)
  3001. {
  3002. if(isAdmin())
  3003. return true;
  3004. $iUserId = $this->getUserId();
  3005. $aCheckResult = checkActionModule($iUserId, 'post', $this->getName(), $bPerform);
  3006. if($aCheckResult[CHECK_ACTION_RESULT] !== CHECK_ACTION_RESULT_ALLOWED)
  3007. return $aCheckResult[CHECK_ACTION_MESSAGE];
  3008. if(!empty($this->_iOwnerId) && ($oProfileOwner = BxDolProfile::getInstance($this->_iOwnerId)) !== false) {
  3009. if($oProfileOwner->checkAllowedPostInProfile($this->_iOwnerId, $this->getName()) !== CHECK_ACTION_RESULT_ALLOWED)
  3010. return _t('_sys_txt_access_denied');
  3011. bx_alert($oProfileOwner->getModule(), $this->_oConfig->getUri() . '_post', $oProfileOwner->id(), $iUserId, array('check_result' => &$aCheckResult));
  3012. }
  3013. return $aCheckResult[CHECK_ACTION_RESULT] !== CHECK_ACTION_RESULT_ALLOWED ? $aCheckResult[CHECK_ACTION_MESSAGE] : true;
  3014. }
  3015. public function isAllowedView($aEvent, $bPerform = false)
  3016. {
  3017. $CNF = $this->_oConfig->CNF;
  3018. if((int)$aEvent[$CNF['FIELD_OWNER_ID']] == 0)
  3019. return true;
  3020. $oProfileOwner = BxDolProfile::getInstance($aEvent[$CNF['FIELD_OWNER_ID']]);
  3021. if($oProfileOwner && $oProfileOwner->checkAllowedProfileView() !== CHECK_ACTION_RESULT_ALLOWED)
  3022. return false;
  3023. $oPrivacy = BxDolPrivacy::getObjectInstance($this->_oConfig->getObject('privacy_view'));
  3024. if(!$oPrivacy)
  3025. return true;
  3026. $oPrivacy->setTableFieldAuthor($this->_oConfig->isSystem($aEvent['type'], $aEvent['action']) ? 'owner_id' : 'object_id');
  3027. return $oPrivacy->check($aEvent[$CNF['FIELD_ID']]);
  3028. }
  3029. public function isAllowedEdit($aEvent, $bPerform = false)
  3030. {
  3031. if(!isLogged())
  3032. return false;
  3033. //--- System posts and Reposts cannot be edited at all.
  3034. if(!$this->_oConfig->isCommon($aEvent['type'], $aEvent['action']) || $aEvent['type'] == $this->_oConfig->getPrefix('common_post') . 'repost')
  3035. return false;
  3036. if(isAdmin())
  3037. return true;
  3038. $iUserId = (int)$this->getUserId();
  3039. $iOwnerId = (int)$aEvent['owner_id'];
  3040. $iObjectId = abs((int)$aEvent['object_id']);
  3041. if($iObjectId == $iUserId && $this->_oConfig->isAllowEdit())
  3042. return true;
  3043. $aCheckResult = checkActionModule($iUserId, 'edit', $this->getName(), $bPerform);
  3044. if(!empty($iOwnerId) && ($oProfileOwner = BxDolProfile::getInstance($iOwnerId)) !== false) {
  3045. if (BxDolService::call($oProfileOwner->getModule(), 'check_allowed_module_action_in_profile', array($oProfileOwner->getContentId(), $this->getName(), 'edit_any')) === CHECK_ACTION_RESULT_ALLOWED) {
  3046. return true;
  3047. }
  3048. bx_alert($oProfileOwner->getModule(), $this->_oConfig->getUri() . '_edit', $oProfileOwner->id(), $iUserId, array('check_result' => &$aCheckResult));
  3049. }
  3050. return $aCheckResult[CHECK_ACTION_RESULT] !== CHECK_ACTION_RESULT_ALLOWED ? $aCheckResult[CHECK_ACTION_MESSAGE] : true;
  3051. }
  3052. public function isAllowedDelete($aEvent, $bPerform = false)
  3053. {
  3054. if(!isLogged())
  3055. return false;
  3056. if(isAdmin())
  3057. return true;
  3058. $iUserId = (int)$this->getUserId();
  3059. $iOwnerId = (int)$aEvent['owner_id'];
  3060. $iObjectId = abs((int)$aEvent['object_id']);
  3061. if((($iOwnerId == $iUserId && $this->_oConfig->isAllowDelete()) || ($this->_oConfig->isCommon($aEvent['type'], $aEvent['action']) && $iObjectId == $iUserId)))
  3062. return true;
  3063. $aCheckResult = checkActionModule($iUserId, 'delete', $this->getName(), $bPerform);
  3064. if(!empty($iOwnerId) && ($oProfileOwner = BxDolProfile::getInstance($iOwnerId)) !== false) {
  3065. if (BxDolService::call($oProfileOwner->getModule(), 'check_allowed_module_action_in_profile', array($oProfileOwner->getContentId(), $this->getName(), 'delete_any')) === CHECK_ACTION_RESULT_ALLOWED) {
  3066. return true;
  3067. }
  3068. bx_alert($oProfileOwner->getModule(), $this->_oConfig->getUri() . '_delete', $oProfileOwner->id(), $iUserId, array('check_result' => &$aCheckResult));
  3069. }
  3070. return $aCheckResult[CHECK_ACTION_RESULT] !== CHECK_ACTION_RESULT_ALLOWED ? $aCheckResult[CHECK_ACTION_MESSAGE] : true;
  3071. }
  3072. public function isAllowedComment($aEvent, $bPerform = false)
  3073. {
  3074. $mixedComments = $this->getCommentsData($aEvent['comments']);
  3075. if($mixedComments === false)
  3076. return false;
  3077. list($sSystem, $iObjectId) = $mixedComments;
  3078. $oCmts = $this->getCmtsObject($sSystem, $iObjectId);
  3079. if($oCmts->isViewAllowed() !== CHECK_ACTION_RESULT_ALLOWED)
  3080. return false;
  3081. $oCmts->addCssJs();
  3082. return true;
  3083. }
  3084. public function isAllowedViewCounter($aEvent, $bPerform = false)
  3085. {
  3086. $mixedViews = $this->getViewsData($aEvent['views']);
  3087. if($mixedViews === false)
  3088. return false;
  3089. list($sSystem, $iObjectId) = $mixedViews;
  3090. $oView = $this->getViewObject($sSystem, $iObjectId);
  3091. if(!$oView->isAllowedViewView($bPerform))
  3092. return false;
  3093. $bResult = true;
  3094. if(!empty($aEvent['owner_id']) && ($oProfileOwner = BxDolProfile::getInstance($aEvent['owner_id'])) !== false)
  3095. bx_alert($oProfileOwner->getModule(), $this->_oConfig->getUri() . '_view_counter', $oProfileOwner->id(), (int)$this->getUserId(), array('result' => &$bResult));
  3096. return $bResult;
  3097. }
  3098. public function isAllowedVote($aEvent, $bPerform = false)
  3099. {
  3100. $mixedVotes = $this->getVotesData($aEvent['votes']);
  3101. if($mixedVotes === false)
  3102. return false;
  3103. list($sSystem, $iObjectId) = $mixedVotes;
  3104. $oVote = $this->getVoteObject($sSystem, $iObjectId);
  3105. if(!$oVote->isAllowedVote($bPerform))
  3106. return false;
  3107. $bResult = true;
  3108. if(!empty($aEvent['owner_id']) && ($oProfileOwner = BxDolProfile::getInstance($aEvent['owner_id'])) !== false)
  3109. bx_alert($oProfileOwner->getModule(), $this->_oConfig->getUri() . '_vote', $oProfileOwner->id(), (int)$this->getUserId(), array('result' => &$bResult));
  3110. return $bResult;
  3111. }
  3112. public function isAllowedVoteView($aEvent, $bPerform = false)
  3113. {
  3114. $mixedVotes = $this->getVotesData($aEvent['votes']);
  3115. if($mixedVotes === false)
  3116. return false;
  3117. list($sSystem, $iObjectId) = $mixedVotes;
  3118. $oVote = $this->getVoteObject($sSystem, $iObjectId);
  3119. if(!$oVote->isAllowedVoteView($bPerform))
  3120. return false;
  3121. $bResult = true;
  3122. if(!empty($aEvent['owner_id']) && ($oProfileOwner = BxDolProfile::getInstance($aEvent['owner_id'])) !== false)
  3123. bx_alert($oProfileOwner->getModule(), $this->_oConfig->getUri() . '_vote_view', $oProfileOwner->id(), (int)$this->getUserId(), array('result' => &$bResult));
  3124. return $bResult;
  3125. }
  3126. public function isAllowedReaction($aEvent, $bPerform = false)
  3127. {
  3128. $mixedReactions = $this->getReactionsData($aEvent['reactions']);
  3129. if($mixedReactions === false)
  3130. return false;
  3131. list($sSystem, $iObjectId) = $mixedReactions;
  3132. $oReaction = $this->getReactionObject($sSystem, $iObjectId);
  3133. if(!$oReaction->isAllowedVote($bPerform))
  3134. return false;
  3135. $bResult = true;
  3136. if(!empty($aEvent['owner_id']) && ($oProfileOwner = BxDolProfile::getInstance($aEvent['owner_id'])) !== false)
  3137. bx_alert($oProfileOwner->getModule(), $this->_oConfig->getUri() . '_reaction', $oProfileOwner->id(), (int)$this->getUserId(), array('result' => &$bResult));
  3138. return $bResult;
  3139. }
  3140. public function isAllowedReactionView($aEvent, $bPerform = false)
  3141. {
  3142. $mixedReactions = $this->getReactionsData($aEvent['reactions']);
  3143. if($mixedReactions === false)
  3144. return false;
  3145. list($sSystem, $iObjectId) = $mixedReactions;
  3146. $oReaction = $this->getReactionObject($sSystem, $iObjectId);
  3147. if(!$oReaction->isAllowedVoteView($bPerform))
  3148. return false;
  3149. $bResult = true;
  3150. if(!empty($aEvent['owner_id']) && ($oProfileOwner = BxDolProfile::getInstance($aEvent['owner_id'])) !== false)
  3151. bx_alert($oProfileOwner->getModule(), $this->_oConfig->getUri() . '_reaction_view', $oProfileOwner->id(), (int)$this->getUserId(), array('result' => &$bResult));
  3152. return $bResult;
  3153. }
  3154. public function isAllowedScore($aEvent, $bPerform = false)
  3155. {
  3156. $mixedScores = $this->getScoresData($aEvent['scores']);
  3157. if($mixedScores === false)
  3158. return false;
  3159. list($sSystem, $iObjectId) = $mixedScores;
  3160. $oScore = $this->getScoreObject($sSystem, $iObjectId);
  3161. if(!$oScore->isAllowedVote($bPerform))
  3162. return false;
  3163. $bResult = true;
  3164. if(!empty($aEvent['owner_id']) && ($oProfileOwner = BxDolProfile::getInstance($aEvent['owner_id'])) !== false)
  3165. bx_alert($oProfileOwner->getModule(), $this->_oConfig->getUri() . '_score', $oProfileOwner->id(), (int)$this->getUserId(), array('result' => &$bResult));
  3166. return $bResult;
  3167. }
  3168. public function isAllowedReport($aEvent, $bPerform = false)
  3169. {
  3170. $mixedReports = $this->getReportsData($aEvent['reports']);
  3171. if($mixedReports === false)
  3172. return false;
  3173. list($sSystem, $iObjectId) = $mixedReports;
  3174. $oReport = $this->getReportObject($sSystem, $iObjectId);
  3175. if(!$oReport->isAllowedReport($bPerform))
  3176. return false;
  3177. $bResult = true;
  3178. if(!empty($aEvent['owner_id']) && ($oProfileOwner = BxDolProfile::getInstance($aEvent['owner_id'])) !== false)
  3179. bx_alert($oProfileOwner->getModule(), $this->_oConfig->getUri() . '_report', $oProfileOwner->id(), (int)$this->getUserId(), array('result' => &$bResult));
  3180. return $bResult;
  3181. }
  3182. public function isAllowedRepost($aEvent, $bPerform = false)
  3183. {
  3184. $iUserId = (int)$this->getUserId();
  3185. if($iUserId == 0)
  3186. return false;
  3187. $iPrivacy = (int)$aEvent['object_privacy_view'];
  3188. if($iPrivacy >= 0 && !in_array($iPrivacy, array(BX_DOL_PG_ALL, BX_DOL_PG_MEMBERS)))
  3189. return false;
  3190. if(isAdmin())
  3191. return true;
  3192. $aCheckResult = checkActionModule($iUserId, 'repost', $this->getName(), $bPerform);
  3193. if(!empty($aEvent['owner_id']) && ($oProfileOwner = BxDolProfile::getInstance($aEvent['owner_id'])) !== false)
  3194. bx_alert($oProfileOwner->getModule(), $this->_oConfig->getUri() . '_repost', $oProfileOwner->id(), $iUserId, array('check_result' => &$aCheckResult));
  3195. return $aCheckResult[CHECK_ACTION_RESULT] !== CHECK_ACTION_RESULT_ALLOWED ? $aCheckResult[CHECK_ACTION_MESSAGE] : true;
  3196. }
  3197. public function isAllowedSend($aEvent, $bPerform = false)
  3198. {
  3199. if(!$this->_oDb->isEnabledByName('bx_convos'))
  3200. return false;
  3201. if(isAdmin())
  3202. return true;
  3203. $iUserId = (int)$this->getUserId();
  3204. if($iUserId == 0)
  3205. return false;
  3206. $aCheckResult = checkActionModule($iUserId, 'send', $this->getName(), $bPerform);
  3207. if(!empty($aEvent['owner_id']) && ($oProfileOwner = BxDolProfile::getInstance($aEvent['owner_id'])) !== false)
  3208. bx_alert($oProfileOwner->getModule(), $this->_oConfig->getUri() . '_send', $oProfileOwner->id(), $iUserId, array('check_result' => &$aCheckResult));
  3209. return $aCheckResult[CHECK_ACTION_RESULT] !== CHECK_ACTION_RESULT_ALLOWED ? $aCheckResult[CHECK_ACTION_MESSAGE] : true;
  3210. }
  3211. public function isAllowedMute($aEvent, $bPerform = false)
  3212. {
  3213. $CNF = &$this->_oConfig->CNF;
  3214. if(!empty($aEvent[$CNF['FIELD_OWNER_ID']]) && $aEvent[$CNF['FIELD_OWNER_ID']] != $this->_iProfileId)
  3215. return false;
  3216. $iAuthor = (int)$aEvent[$CNF['FIELD_OWNER_ID']];
  3217. if(!$this->_oConfig->isSystem($aEvent['type'], $aEvent['action']))
  3218. $iAuthor = (int)$aEvent[$CNF['FIELD_OBJECT_ID']];
  3219. if($this->_iProfileId == $iAuthor || $this->getConnectionMuteObject()->isConnected($this->_iProfileId, $iAuthor))
  3220. return false;
  3221. return $this->_isAllowedMute($bPerform);
  3222. }
  3223. public function isAllowedUnmute($iAuthor, $bPerform = false)
  3224. {
  3225. if(!$this->getConnectionMuteObject()->isConnected($this->_iProfileId, $iAuthor))
  3226. return false;
  3227. return $this->_isAllowedMute($bPerform);
  3228. }
  3229. /**
  3230. * Pin - "Pin here" - pin the post on Profile Timeline for profile owner.
  3231. * Can be done by profile owner for himself or by admin for profile owner to see.
  3232. * @param type $aEvent
  3233. * @param type $bPerform
  3234. * @return boolean
  3235. */
  3236. public function isAllowedPin($aEvent, $bPerform = false)
  3237. {
  3238. if((int)$aEvent['pinned'] != 0)
  3239. return false;
  3240. return $this->_isAllowedPin($aEvent, $bPerform);
  3241. }
  3242. public function isAllowedUnpin($aEvent, $bPerform = false)
  3243. {
  3244. if((int)$aEvent['pinned'] == 0)
  3245. return false;
  3246. return $this->_isAllowedPin($aEvent, $bPerform);
  3247. }
  3248. /**
  3249. * Stick - "Pin for All" - pin the post on Public Timeline for everybody to see.
  3250. * Is available for Administrators/Moderators only.
  3251. * @param type $aEvent
  3252. * @param type $bPerform
  3253. * @return boolean
  3254. */
  3255. public function isAllowedStick($aEvent, $bPerform = false)
  3256. {
  3257. if((int)$aEvent['sticked'] != 0)
  3258. return false;
  3259. return $this->_isAllowedStick($aEvent, $bPerform);
  3260. }
  3261. public function isAllowedUnstick($aEvent, $bPerform = false)
  3262. {
  3263. if((int)$aEvent['sticked'] == 0)
  3264. return false;
  3265. return $this->_isAllowedStick($aEvent, $bPerform);
  3266. }
  3267. public function isAllowedPromote($aEvent, $bPerform = false)
  3268. {
  3269. if((int)$aEvent['promoted'] != 0)
  3270. return false;
  3271. return $this->_isAllowedPromote($aEvent, $bPerform);
  3272. }
  3273. public function isAllowedUnpromote($aEvent, $bPerform = false)
  3274. {
  3275. if((int)$aEvent['promoted'] == 0)
  3276. return false;
  3277. return $this->_isAllowedPromote($aEvent, $bPerform);
  3278. }
  3279. public function isAllowedMore($aEvent, $bPerform = false)
  3280. {
  3281. $oMoreMenu = $this->getManageMenuObject();
  3282. if(!$oMoreMenu)
  3283. return false;
  3284. $oMoreMenu->setEvent($aEvent);
  3285. return $oMoreMenu->isVisible();
  3286. }
  3287. public function checkAllowedView ($aContentInfo, $isPerformAction = false)
  3288. {
  3289. if(!$this->isAllowedView($aContentInfo, $isPerformAction))
  3290. return _t('_sys_txt_access_denied');
  3291. return CHECK_ACTION_RESULT_ALLOWED;
  3292. }
  3293. public function checkAllowedCommentsView ($aContentInfo, $isPerformAction = false)
  3294. {
  3295. $CNF = $this->_oConfig->CNF;
  3296. $iOwner = (int)$aContentInfo[$CNF['FIELD_OWNER_ID']];
  3297. if($iOwner == 0) //--- in case of Public Timeline.
  3298. return CHECK_ACTION_RESULT_ALLOWED;
  3299. $oOwner = BxDolProfile::getInstance($iOwner);
  3300. if(!$oOwner) //--- in case of non-existed Timeline owner.
  3301. return _t('_sys_txt_access_denied');
  3302. $mixedResult = $oOwner->checkAllowedProfileView();
  3303. if($mixedResult !== CHECK_ACTION_RESULT_ALLOWED)
  3304. return $mixedResult;
  3305. return $this->checkAllowedView($aContentInfo, $isPerformAction);
  3306. }
  3307. public function checkAllowedCommentsPost ($aContentInfo, $isPerformAction = false)
  3308. {
  3309. $sError = '_sys_txt_access_denied';
  3310. $aContentInfo = array_merge($aContentInfo, $this->_oTemplate->getDataCached($aContentInfo));
  3311. if($aContentInfo === false)
  3312. return _t($sError);
  3313. if(!$this->isAllowedComment($aContentInfo, $isPerformAction))
  3314. return _t($sError);
  3315. return CHECK_ACTION_RESULT_ALLOWED;
  3316. }
  3317. public function checkAllowedEditAnyEntryForProfile ($isPerformAction = false, $iProfileId = false)
  3318. {
  3319. if(!$iProfileId)
  3320. $iProfileId = $this->_iProfileId;
  3321. $aCheck = checkActionModule($iProfileId, 'edit', $this->getName(), $isPerformAction);
  3322. if($aCheck[CHECK_ACTION_RESULT] === CHECK_ACTION_RESULT_ALLOWED)
  3323. return CHECK_ACTION_RESULT_ALLOWED;
  3324. return _t('_sys_txt_access_denied');
  3325. }
  3326. public function onPost($iContentId)
  3327. {
  3328. $CNF = &$this->_oConfig->CNF;
  3329. $aEvent = $this->_oDb->getEvents(array('browse' => 'id', 'value' => $iContentId));
  3330. if($this->_oConfig->isSystem($aEvent['type'], $aEvent['action'])) {
  3331. //--- Request event's data from content module and update it in the Timeline DB.
  3332. $this->_oTemplate->getDataCached($aEvent);
  3333. $sPostType = 'system';
  3334. $iSenderId = $iObjectAuthorId = (int)$aEvent['owner_id'];
  3335. }
  3336. else {
  3337. $sPostType = 'common';
  3338. $iSenderId = $iObjectAuthorId = (int)$aEvent['object_id'];
  3339. }
  3340. //--- Event -> Post/Defer for Alerts Engine ---//
  3341. $sAction = ($aEvent[$CNF['FIELD_STATUS']] == BX_TIMELINE_STATUS_AWAITING ? 'defer' : 'post') . '_' . $sPostType;
  3342. bx_alert($this->_oConfig->getObject('alert'), $sAction, $iContentId, $iSenderId, array(
  3343. 'owner_id' => $aEvent['owner_id'],
  3344. 'object_author_id' => $iObjectAuthorId,
  3345. 'privacy_view' => $aEvent['object_privacy_view'],
  3346. ));
  3347. //--- Event -> Post for Alerts Engine ---//
  3348. }
  3349. public function onPublished($iContentId)
  3350. {
  3351. //--- Clear Item cache
  3352. $this->getCacheItemObject()->removeAllByPrefix($this->_oConfig->getPrefix('cache_item') . $iContentId);
  3353. $this->onPost($iContentId);
  3354. }
  3355. public function onFailed($iContentId)
  3356. {
  3357. $aEvent = $this->_oDb->getEvents(array('browse' => 'id', 'value' => $iContentId));
  3358. //--- Clear Item cache
  3359. $this->getCacheItemObject()->removeAllByPrefix($this->_oConfig->getPrefix('cache_item') . $iContentId);
  3360. if($this->_oConfig->isSystem($aEvent['type'], $aEvent['action'])) {
  3361. //--- Request event's data from content module and update it in the Timeline DB.
  3362. $this->_oTemplate->getDataCached($aEvent);
  3363. $sPostType = 'system';
  3364. $iSenderId = $iObjectAuthorId = (int)$aEvent['owner_id'];
  3365. }
  3366. else {
  3367. $sPostType = 'common';
  3368. $iSenderId = $iObjectAuthorId = (int)$aEvent['object_id'];
  3369. }
  3370. //--- Event -> Fail for Alerts Engine ---//
  3371. bx_alert($this->_oConfig->getObject('alert'), 'fail_' . $sPostType, $iContentId, $iSenderId, array(
  3372. 'owner_id' => $aEvent['owner_id'],
  3373. 'object_author_id' => $iObjectAuthorId,
  3374. 'privacy_view' => $aEvent['object_privacy_view'],
  3375. ));
  3376. //--- Event -> Post for Alerts Engine ---//
  3377. }
  3378. public function onRepost($iContentId, $aReposted = array())
  3379. {
  3380. $CNF = &$this->_oConfig->CNF;
  3381. $aEvent = $this->_oDb->getEvents(array('browse' => 'id', 'value' => $iContentId));
  3382. if(empty($aReposted)) {
  3383. $aContent = unserialize($aEvent['content']);
  3384. $aReposted = $this->_oDb->getReposted($aContent['type'], $aContent['action'], $aContent['object_id']);
  3385. if(empty($aReposted) || !is_array($aReposted))
  3386. return;
  3387. }
  3388. $iUserId = (int)$aEvent[$CNF['FIELD_OBJECT_OWNER_ID']];
  3389. $this->_oDb->insertRepostTrack($aEvent['id'], $iUserId, $this->getUserIp(), $aReposted['id']);
  3390. $this->_oDb->updateRepostCounter($aReposted['id'], $aReposted['reposts']);
  3391. //--- Timeline -> Update for Alerts Engine ---//
  3392. bx_alert($this->_oConfig->getObject('alert'), 'repost', $aReposted['id'], $iUserId, array(
  3393. 'privacy_view' => $aEvent['object_privacy_view'],
  3394. 'object_author_id' => $aReposted['owner_id'],
  3395. 'repost_id' => $iContentId,
  3396. ));
  3397. //--- Timeline -> Update for Alerts Engine ---//
  3398. }
  3399. public function onDelete($aEvent)
  3400. {
  3401. $CNF = &$this->_oConfig->CNF;
  3402. $iUserId = $this->getUserId();
  3403. $sCommonPostPrefix = $this->_oConfig->getPrefix('common_post');
  3404. $sCommonPostComment = $this->_oConfig->getObject('comment');
  3405. //--- Delete comments for Common posts.
  3406. if($this->_oConfig->isCommon($aEvent['type'], $aEvent['action'])) {
  3407. $oComments = $this->getCmtsObject($sCommonPostComment, $aEvent[$CNF['FIELD_ID']]);
  3408. if($oComments !== false)
  3409. $oComments->onObjectDelete($aEvent[$CNF['FIELD_ID']]);
  3410. }
  3411. //--- Delete attached photos, videos and links when common event was deleted.
  3412. if($aEvent['type'] == $sCommonPostPrefix . BX_TIMELINE_PARSE_TYPE_POST) {
  3413. $this->_deleteMedia($CNF['FIELD_PHOTO'], $aEvent[$CNF['FIELD_ID']]);
  3414. $this->_deleteMedia($CNF['FIELD_VIDEO'], $aEvent[$CNF['FIELD_ID']]);
  3415. $this->_deleteMedia($CNF['FIELD_FILE'], $aEvent[$CNF['FIELD_ID']]);
  3416. $this->_deleteLinks($aEvent[$CNF['FIELD_ID']]);
  3417. }
  3418. //--- Update parent event when repost event was deleted.
  3419. $bRepost = $aEvent['type'] == $sCommonPostPrefix . BX_TIMELINE_PARSE_TYPE_REPOST;
  3420. if($bRepost) {
  3421. $this->_oDb->deleteRepostTrack($aEvent[$CNF['FIELD_ID']]);
  3422. $aContent = unserialize($aEvent['content']);
  3423. $aReposted = $this->_oDb->getReposted($aContent['type'], $aContent['action'], $aContent['object_id']);
  3424. if(!empty($aReposted) && is_array($aReposted))
  3425. $this->_oDb->updateRepostCounter($aReposted[$CNF['FIELD_ID']], $aReposted['reposts'], -1);
  3426. }
  3427. //--- Find and delete repost events when parent event was deleted.
  3428. $bSystem = $this->_oConfig->isSystem($aEvent['type'], $aEvent['action']);
  3429. $aRepostEvents = $this->_oDb->getEvents(array('browse' => 'reposted_by_track', 'value' => $aEvent[$CNF['FIELD_ID']]));
  3430. foreach($aRepostEvents as $aRepostEvent) {
  3431. if((int)$this->_oDb->deleteEvent(array('id' => (int)$aRepostEvent[$CNF['FIELD_ID']])) == 0)
  3432. continue;
  3433. $this->_oDb->deleteRepostTrack($aRepostEvent[$CNF['FIELD_ID']]);
  3434. $oComments = $this->getCmtsObject($sCommonPostComment, $aRepostEvent[$CNF['FIELD_ID']]);
  3435. if($oComments !== false)
  3436. $oComments->onObjectDelete($aRepostEvent[$CNF['FIELD_ID']]);
  3437. bx_alert($this->_oConfig->getObject('alert'), 'delete_repost', $aEvent[$CNF['FIELD_ID']], $iUserId, array(
  3438. 'repost_id' => $aRepostEvent[$CNF['FIELD_ID']],
  3439. ));
  3440. }
  3441. //--- Delete associated meta.
  3442. $oMetatags = BxDolMetatags::getObjectInstance($this->_oConfig->getObject('metatags'));
  3443. $oMetatags->onDeleteContent($aEvent[$CNF['FIELD_ID']]);
  3444. //--- Delete item cache.
  3445. $sCacheItemKey = $this->_oConfig->getCacheItemKey($aEvent[$CNF['FIELD_ID']]);
  3446. $this->getCacheItemObject()->delData($sCacheItemKey);
  3447. //--- Event -> Delete for Alerts Engine ---//
  3448. if($bRepost)
  3449. bx_alert($this->_oConfig->getObject('alert'), 'delete_repost', $aReposted[$CNF['FIELD_ID']], $iUserId, array(
  3450. 'repost_id' => $aEvent[$CNF['FIELD_ID']],
  3451. ));
  3452. else
  3453. bx_alert($this->_oConfig->getObject('alert'), 'delete', $aEvent[$CNF['FIELD_ID']], $iUserId);
  3454. //--- Event -> Delete for Alerts Engine ---//
  3455. }
  3456. public function getParams($sView = '', $sType = '', $iOwnerId = 0, $iStart = 0, $iPerPage = 0, $sFilter = BX_TIMELINE_FILTER_ALL, $aModules = array(), $iTimeline = 0)
  3457. {
  3458. return $this->_prepareParams(array(
  3459. 'view' => $sView,
  3460. 'type' => $sType,
  3461. 'owner_id' => $iOwnerId,
  3462. 'start' => $iStart,
  3463. 'per_page' => $iPerPage,
  3464. 'timeline' => $iTimeline,
  3465. 'filter' => $sFilter,
  3466. 'modules' => $aModules
  3467. ));
  3468. }
  3469. public function getParamsExt($aParams = array())
  3470. {
  3471. return $this->_prepareParams($aParams);
  3472. }
  3473. public function getViewsData(&$aViews)
  3474. {
  3475. if(empty($aViews) || !is_array($aViews))
  3476. return false;
  3477. $sSystem = isset($aViews['system']) ? $aViews['system'] : '';
  3478. $iObjectId = isset($aViews['object_id']) ? (int)$aViews['object_id'] : 0;
  3479. $iCount = isset($aViews['count']) ? (int)$aViews['count'] : 0;
  3480. if($sSystem == '' || $iObjectId == 0)
  3481. return false;
  3482. return array($sSystem, $iObjectId, $iCount);
  3483. }
  3484. public function getVotesData(&$aVotes)
  3485. {
  3486. if(empty($aVotes) || !is_array($aVotes))
  3487. return false;
  3488. $sSystem = isset($aVotes['system']) ? $aVotes['system'] : '';
  3489. $iObjectId = isset($aVotes['object_id']) ? (int)$aVotes['object_id'] : 0;
  3490. $iCount = isset($aVotes['count']) ? (int)$aVotes['count'] : 0;
  3491. if($sSystem == '' || $iObjectId == 0)
  3492. return false;
  3493. return array($sSystem, $iObjectId, $iCount);
  3494. }
  3495. public function getReactionsData(&$aReactions)
  3496. {
  3497. if(empty($aReactions) || !is_array($aReactions))
  3498. return false;
  3499. $sSystem = isset($aReactions['system']) ? $aReactions['system'] : '';
  3500. $iObjectId = isset($aReactions['object_id']) ? (int)$aReactions['object_id'] : 0;
  3501. $iCount = isset($aReactions['count']) ? (int)$aReactions['count'] : 0;
  3502. if($sSystem == '' || $iObjectId == 0)
  3503. return false;
  3504. return array($sSystem, $iObjectId, $iCount);
  3505. }
  3506. public function getScoresData(&$aScores)
  3507. {
  3508. if(empty($aScores) || !is_array($aScores))
  3509. return false;
  3510. $sSystem = isset($aScores['system']) ? $aScores['system'] : '';
  3511. $iObjectId = isset($aScores['object_id']) ? (int)$aScores['object_id'] : 0;
  3512. $iScore = isset($aScores['score']) ? (int)$aScores['score'] : 0;
  3513. if($sSystem == '' || $iObjectId == 0)
  3514. return false;
  3515. return array($sSystem, $iObjectId, $iScore);
  3516. }
  3517. public function getReportsData(&$aReports)
  3518. {
  3519. if(empty($aReports) || !is_array($aReports))
  3520. return false;
  3521. $sSystem = isset($aReports['system']) ? $aReports['system'] : '';
  3522. $iObjectId = isset($aReports['object_id']) ? (int)$aReports['object_id'] : 0;
  3523. $iCount = isset($aReports['count']) ? (int)$aReports['count'] : 0;
  3524. if($sSystem == '' || $iObjectId == 0)
  3525. return false;
  3526. return array($sSystem, $iObjectId, $iCount);
  3527. }
  3528. public function getCommentsData(&$aComments)
  3529. {
  3530. if(empty($aComments) || !is_array($aComments))
  3531. return false;
  3532. $sSystem = isset($aComments['system']) ? $aComments['system'] : '';
  3533. $iObjectId = isset($aComments['object_id']) ? (int)$aComments['object_id'] : 0;
  3534. $iCount = isset($aComments['count']) ? (int)$aComments['count'] : 0;
  3535. if($sSystem == '' || $iObjectId == 0 || ($iCount == 0 && !isLogged()))
  3536. return false;
  3537. return array($sSystem, $iObjectId, $iCount);
  3538. }
  3539. public function getEventLinks($iEventId)
  3540. {
  3541. $aLinks = $this->_oDb->getLinks($iEventId);
  3542. if(empty($aLinks) || !is_array($aLinks))
  3543. return array();
  3544. $oTranscoder = BxDolTranscoderImage::getObjectInstance($this->_oConfig->getObject('transcoder_photos_preview'));
  3545. $aResult = array();
  3546. foreach($aLinks as $aLink)
  3547. $aResult[] = array(
  3548. 'url' => $aLink['url'],
  3549. 'title' => $aLink['title'],
  3550. 'text' => $aLink['text'],
  3551. 'thumbnail' => (int)$aLink['media_id'] != 0 ? $oTranscoder->getFileUrl($aLink['media_id']) : ''
  3552. );
  3553. return $aResult;
  3554. }
  3555. public function getEventImages($iEventId)
  3556. {
  3557. $CNF = &$this->_oConfig->CNF;
  3558. $aPhotos = $this->_oDb->getMedia($CNF['FIELD_PHOTO'], $iEventId);
  3559. if(empty($aPhotos) || !is_array($aPhotos))
  3560. return array();
  3561. $oTranscoder = BxDolTranscoderImage::getObjectInstance($this->_oConfig->getObject('transcoder_photos_view'));
  3562. $oTranscoderMedium = BxDolTranscoderImage::getObjectInstance($this->_oConfig->getObject('transcoder_photos_medium'));
  3563. $oTranscoderBig = BxDolTranscoderImage::getObjectInstance($this->_oConfig->getObject('transcoder_photos_big'));
  3564. $aResult = array();
  3565. foreach($aPhotos as $iPhotoId) {
  3566. $sPhotoSrc = $oTranscoder->getFileUrl($iPhotoId);
  3567. $sPhotoSrcMedium = $oTranscoderMedium->getFileUrl($iPhotoId);
  3568. $sPhotoSrcBig = $oTranscoderBig->getFileUrl($iPhotoId);
  3569. if(empty($sPhotoSrcMedium) && !empty($sPhotoSrc))
  3570. $sPhotoSrcMedium = $sPhotoSrc;
  3571. if(empty($sPhotoSrcBig) && !empty($sPhotoSrcMedium))
  3572. $sPhotoSrcBig = $sPhotoSrcMedium;
  3573. $aResult[] = array(
  3574. 'id' => $iPhotoId,
  3575. 'src' => $sPhotoSrc,
  3576. 'src_medium' => $sPhotoSrcMedium,
  3577. 'src_orig' => $sPhotoSrcBig,
  3578. );
  3579. }
  3580. return $aResult;
  3581. }
  3582. public function getEventVideos($iEventId)
  3583. {
  3584. $CNF = &$this->_oConfig->CNF;
  3585. $aVideos = $this->_oDb->getMedia($CNF['FIELD_VIDEO'], $iEventId);
  3586. if(empty($aVideos) || !is_array($aVideos))
  3587. return array();
  3588. $oStorage = BxDolStorage::getObjectInstance($this->_oConfig->getObject('storage_videos'));
  3589. $oTranscoderPoster = BxDolTranscoderVideo::getObjectInstance($this->_oConfig->getObject('transcoder_videos_poster'));
  3590. $oTranscoderMp4 = BxDolTranscoderVideo::getObjectInstance($this->_oConfig->getObject('transcoder_videos_mp4'));
  3591. $oTranscoderMp4Hd = BxDolTranscoderVideo::getObjectInstance($this->_oConfig->getObject('transcoder_videos_mp4_hd'));
  3592. $aResult = array();
  3593. foreach($aVideos as $iVideoId) {
  3594. $sVideoUrl = $oStorage->getFileUrlById($iVideoId);
  3595. $aVideoFile = $oStorage->getFile($iVideoId);
  3596. $sVideoUrlHd = '';
  3597. if (!empty($aVideoFile['dimensions']) && $oTranscoderMp4Hd->isProcessHD($aVideoFile['dimensions']))
  3598. $sVideoUrlHd = $oTranscoderMp4Hd->getFileUrl($iVideoId);
  3599. $aResult[$iVideoId] = array(
  3600. 'id' => $iVideoId,
  3601. 'src_poster' => $oTranscoderPoster->getFileUrl($iVideoId),
  3602. 'src_mp4' => $oTranscoderMp4->getFileUrl($iVideoId),
  3603. 'src_mp4_hd' => $sVideoUrlHd,
  3604. );
  3605. }
  3606. return $aResult;
  3607. }
  3608. public function getEventFiles($iEventId)
  3609. {
  3610. $CNF = &$this->_oConfig->CNF;
  3611. $aFiles = $this->_oDb->getMedia($CNF['FIELD_FILE'], $iEventId);
  3612. if(empty($aFiles) || !is_array($aFiles))
  3613. return [];
  3614. $oStorage = BxDolStorage::getObjectInstance($this->_oConfig->getObject('storage_files'));
  3615. $aResult = [];
  3616. foreach($aFiles as $iFileId) {
  3617. $sFileUrl = $oStorage->getFileUrlById($iFileId);
  3618. $aFileFile = $oStorage->getFile($iFileId);
  3619. $aResult[$iFileId] = [
  3620. 'id' => $iFileId,
  3621. 'src' => $this->_oTemplate->getIconUrl($oStorage->getIconNameByFileName($aFileFile['file_name'])),
  3622. 'src_medium' => '',
  3623. 'src_orig' => '',
  3624. 'url' => $sFileUrl,
  3625. 'title' => $aFileFile['file_name']
  3626. ];
  3627. }
  3628. return $aResult;
  3629. }
  3630. /**
  3631. * Protected Methods
  3632. */
  3633. protected function _serviceGetBlockView($iProfileId = 0, $aBrowseParams = array())
  3634. {
  3635. if(empty($iProfileId) && bx_get('profile_id') !== false)
  3636. $iProfileId = bx_process_input(bx_get('profile_id'), BX_DATA_INT);
  3637. if(empty($iProfileId) && isLogged())
  3638. $iProfileId = bx_get_logged_profile_id();
  3639. $aBrowseParams['owner_id'] = $iProfileId;
  3640. $aBlock = $this->_getBlockView($aBrowseParams);
  3641. if(!empty($aBlock))
  3642. return $aBlock;
  3643. return array('content' => MsgBox(_t('_bx_timeline_txt_msg_no_results')));
  3644. }
  3645. protected function _serviceGetBlockViewProfile($sProfileModule = 'bx_persons', $iProfileContentId = 0, $aBrowseParams = array())
  3646. {
  3647. if(empty($sProfileModule))
  3648. return array();
  3649. if(empty($iProfileContentId) && bx_get('id') !== false)
  3650. $iProfileContentId = bx_process_input(bx_get('id'), BX_DATA_INT);
  3651. $oProfile = BxDolProfile::getInstanceByContentAndType($iProfileContentId, $sProfileModule);
  3652. if(empty($oProfile))
  3653. return array();
  3654. $aBrowseParams['owner_id'] = $oProfile->id();
  3655. return $this->_getBlockView($aBrowseParams);
  3656. }
  3657. protected function _serviceGetBlockViews($aBrowseParams = array())
  3658. {
  3659. $aParams = $this->_prepareParams($aBrowseParams);
  3660. if(($sType = $this->_oConfig->getUserChoice('type')) !== false)
  3661. $aParams['type'] = $sType;
  3662. $this->_iOwnerId = $aParams['owner_id'];
  3663. return $this->_oTemplate->getViewsBlock($aParams);
  3664. }
  3665. protected function _serviceGetBlockViewHome($aBrowseParams = array())
  3666. {
  3667. $sRssUrl = BX_DOL_URL_ROOT . $this->_oConfig->getBaseUri() . 'rss/' . $aBrowseParams['type'] . '/';
  3668. BxDolTemplate::getInstance()->addPageRssLink(_t('_bx_timeline_page_title_view_home'), $sRssUrl);
  3669. return $this->_serviceGetBlockViewByType($aBrowseParams);
  3670. }
  3671. protected function _serviceGetBlockViewHot($aBrowseParams = array())
  3672. {
  3673. $sRssUrl = BX_DOL_URL_ROOT . $this->_oConfig->getBaseUri() . 'rss/' . $aBrowseParams['type'] . '/';
  3674. BxDolTemplate::getInstance()->addPageRssLink(_t('_bx_timeline_page_title_view_hot'), $sRssUrl);
  3675. return $this->_serviceGetBlockViewByType($aBrowseParams);
  3676. }
  3677. protected function _serviceGetBlockViewByType($aBrowseParams = array())
  3678. {
  3679. $aParams = $this->_prepareParams($aBrowseParams);
  3680. $this->_iOwnerId = $aParams['owner_id'];
  3681. return array(
  3682. 'content' => $this->_oTemplate->getViewBlock($aParams)
  3683. );
  3684. }
  3685. protected function _getBlockPost($iProfileId, $aParams = array())
  3686. {
  3687. $this->_iOwnerId = $iProfileId;
  3688. if($this->isAllowedPost() !== true)
  3689. return array();
  3690. return array(
  3691. 'content' => $this->_oTemplate->getPostBlock($this->_iOwnerId, $aParams)
  3692. );
  3693. }
  3694. protected function _getBlockView($aBrowseParams = array())
  3695. {
  3696. if(empty($aBrowseParams['owner_id']))
  3697. return array();
  3698. $aParams = $this->_prepareParams($aBrowseParams);
  3699. if(empty($aParams['per_page']))
  3700. $aParams['per_page'] = $this->_oConfig->getPerPage('profile');
  3701. $this->_iOwnerId = $aParams['owner_id'];
  3702. $oProfileOwner = BxDolProfile::getInstance($this->_iOwnerId);
  3703. if(!$oProfileOwner)
  3704. return array();
  3705. $mixedResult = $oProfileOwner->checkAllowedProfileView();
  3706. if($mixedResult !== CHECK_ACTION_RESULT_ALLOWED) {
  3707. $this->_oTemplate->displayAccessDenied($mixedResult);
  3708. exit;
  3709. }
  3710. $sUserName = $this->getObjectUser($aParams['owner_id'])->getDisplayName();
  3711. $sView = $aParams['view'];
  3712. $sRssUrl = BX_DOL_URL_ROOT . $this->_oConfig->getBaseUri() . 'rss/' . BX_BASE_MOD_NTFS_TYPE_OWNER . '/' . $this->_iOwnerId . '/';
  3713. $sJsObject = $this->_oConfig->getJsObjectView($aParams);
  3714. $aMenu = array(
  3715. 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),
  3716. 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)),
  3717. 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')),
  3718. array('id' => $sView . '-get-rss', 'name' => $sView . '-get-rss', 'class' => '', 'link' => $sRssUrl, 'onclick' => '', 'target' => '_blank', 'title' => _t('_bx_timeline_menu_item_get_rss')),
  3719. );
  3720. $sContent = '';
  3721. bx_alert($oProfileOwner->getModule(), $this->_oConfig->getUri() . '_view', $this->_iOwnerId, $this->getUserId(), array('override_content' => &$sContent, 'params' => &$aParams, 'menu' => &$aMenu));
  3722. $oMenu = new BxTemplMenuInteractive(array('template' => 'menu_interactive_vertical.html', 'menu_id'=> $sView . '-view-all', 'menu_items' => $aMenu));
  3723. $oMenu->setSelected('', $sView . '-view-all');
  3724. if (!$sContent)
  3725. $sContent = $this->_oTemplate->getViewBlock($aParams);
  3726. BxDolTemplate::getInstance()->addPageRssLink(_t('_bx_timeline_page_title_view'), $sRssUrl);
  3727. return array('content' => $sContent, 'menu' => $oMenu);
  3728. }
  3729. protected function _getContentForTimelinePost($aEvent, $aContentInfo, $aBrowseParams = array())
  3730. {
  3731. $CNF = &$this->_oConfig->CNF;
  3732. $iId = (int)$aContentInfo[$CNF['FIELD_ID']];
  3733. $sUrl = BX_DOL_URL_ROOT . BxDolPermalinks::getInstance()->permalink('page.php?i=' . $CNF['URI_VIEW_ENTRY'] . '&id=' . $iId);
  3734. $sText = '';
  3735. if(isset($aContentInfo['content'])){
  3736. $aTmp = unserialize($aContentInfo['content']);
  3737. if(isset($aTmp['text']))
  3738. $sText = $aTmp['text'];
  3739. }
  3740. if(empty($sText) && !empty($aContentInfo[$CNF['FIELD_TITLE']]))
  3741. $sText = $aContentInfo[$CNF['FIELD_TITLE']];
  3742. if(!empty($CNF['OBJECT_METATAGS']) && !empty($sText)) {
  3743. $oMetatags = BxDolMetatags::getObjectInstance($CNF['OBJECT_METATAGS']);
  3744. $sText = $oMetatags->metaParse($iId, $sText);
  3745. }
  3746. return array(
  3747. 'sample' => isset($CNF['T']['txt_sample_single_with_article']) ? $CNF['T']['txt_sample_single_with_article'] : $CNF['T']['txt_sample_single'],
  3748. 'sample_wo_article' => $CNF['T']['txt_sample_single'],
  3749. 'sample_action' => isset($CNF['T']['txt_sample_action']) ? $CNF['T']['txt_sample_action'] : '',
  3750. 'url' => $sUrl,
  3751. 'title' => '',
  3752. 'text' => $sText,
  3753. 'links' => $this->getEventLinks($iId),
  3754. 'images' => array(),
  3755. 'images_attach' => $this->getEventImages($iId),
  3756. 'videos' => array(),
  3757. 'videos_attach' => $this->getEventVideos($iId),
  3758. 'files' => array(),
  3759. 'files_attach' => $this->getEventFiles($iId)
  3760. );
  3761. }
  3762. protected function _isAllowedMute($bPerform = false)
  3763. {
  3764. if($this->_iProfileId == 0)
  3765. return false;
  3766. if(isAdmin())
  3767. return true;
  3768. $aCheckResult = checkActionModule($this->_iProfileId, 'mute', $this->getName(), $bPerform);
  3769. return $aCheckResult[CHECK_ACTION_RESULT] !== CHECK_ACTION_RESULT_ALLOWED ? $aCheckResult[CHECK_ACTION_MESSAGE] : true;
  3770. }
  3771. protected function _isAllowedPin($aEvent, $bPerform = false)
  3772. {
  3773. $iUserId = (int)$this->getUserId();
  3774. if($iUserId == 0)
  3775. return false;
  3776. if(isAdmin() || (int)$aEvent['owner_id'] == $iUserId || ((int)$aEvent['owner_id'] == 0 && $this->_oConfig->isCommon($aEvent['type'], $aEvent['action']) && (int)$aEvent['object_id'] == $iUserId))
  3777. return true;
  3778. $aCheckResult = checkActionModule($iUserId, 'pin', $this->getName(), $bPerform);
  3779. if(!empty($aEvent['owner_id']) && ($oProfileOwner = BxDolProfile::getInstance($aEvent['owner_id'])) !== false) {
  3780. if (BxDolService::call($oProfileOwner->getModule(), 'check_allowed_module_action_in_profile', array($oProfileOwner->getContentId(), $this->getName(), 'pin')) === CHECK_ACTION_RESULT_ALLOWED) {
  3781. return true;
  3782. }
  3783. bx_alert($oProfileOwner->getModule(), $this->_oConfig->getUri() . '_pin', $oProfileOwner->id(), $iUserId, array('check_result' => &$aCheckResult));
  3784. }
  3785. return $aCheckResult[CHECK_ACTION_RESULT] !== CHECK_ACTION_RESULT_ALLOWED ? $aCheckResult[CHECK_ACTION_MESSAGE] : true;
  3786. }
  3787. protected function _isAllowedStick($aEvent, $bPerform = false)
  3788. {
  3789. $iUserId = (int)$this->getUserId();
  3790. if($iUserId == 0)
  3791. return false;
  3792. if(isAdmin())
  3793. return true;
  3794. $aCheckResult = checkActionModule($iUserId, 'stick', $this->getName(), $bPerform);
  3795. if(!empty($aEvent['owner_id']) && ($oProfileOwner = BxDolProfile::getInstance($aEvent['owner_id'])) !== false)
  3796. bx_alert($oProfileOwner->getModule(), $this->_oConfig->getUri() . '_stick', $oProfileOwner->id(), $iUserId, array('check_result' => &$aCheckResult));
  3797. return $aCheckResult[CHECK_ACTION_RESULT] !== CHECK_ACTION_RESULT_ALLOWED ? $aCheckResult[CHECK_ACTION_MESSAGE] : true;
  3798. }
  3799. protected function _isAllowedPromote($aEvent, $bPerform = false)
  3800. {
  3801. if(isAdmin())
  3802. return true;
  3803. $iUserId = (int)$this->getUserId();
  3804. if($iUserId == 0)
  3805. return false;
  3806. $aCheckResult = checkActionModule($iUserId, 'promote', $this->getName(), $bPerform);
  3807. if(!empty($aEvent['owner_id']) && ($oProfileOwner = BxDolProfile::getInstance($aEvent['owner_id'])) !== false)
  3808. bx_alert($oProfileOwner->getModule(), $this->_oConfig->getUri() . '_promote', $oProfileOwner->id(), $iUserId, array('check_result' => &$aCheckResult));
  3809. return $aCheckResult[CHECK_ACTION_RESULT] !== CHECK_ACTION_RESULT_ALLOWED ? $aCheckResult[CHECK_ACTION_MESSAGE] : true;
  3810. }
  3811. protected function _addLink(&$oForm)
  3812. {
  3813. $iUserId = $this->getUserId();
  3814. $iEventId = (int)$oForm->getCleanValue('event_id');
  3815. $sLink = rtrim($oForm->getCleanValue('url'), '/');
  3816. $aMatches = array();
  3817. preg_match($this->_oConfig->getPregPattern('url'), $sLink, $aMatches);
  3818. $sLink = (empty($aMatches[2]) ? 'http://' : '') . $aMatches[0];
  3819. $aSiteInfo = bx_get_site_info($sLink, array(
  3820. 'thumbnailUrl' => array('tag' => 'link', 'content_attr' => 'href'),
  3821. 'OGImage' => array('name_attr' => 'property', 'name' => 'og:image'),
  3822. ));
  3823. $sTitle = !empty($aSiteInfo['title']) ? $aSiteInfo['title'] : _t('_Empty');
  3824. $sDescription = !empty($aSiteInfo['description']) ? $aSiteInfo['description'] : _t('_Empty');
  3825. $sMediaUrl = '';
  3826. if(!empty($aSiteInfo['thumbnailUrl']))
  3827. $sMediaUrl = $aSiteInfo['thumbnailUrl'];
  3828. else if(!empty($aSiteInfo['OGImage']))
  3829. $sMediaUrl = $aSiteInfo['OGImage'];
  3830. $iMediaId = 0;
  3831. $oStorage = null;
  3832. if(!empty($sMediaUrl)) {
  3833. $oStorage = BxDolStorage::getObjectInstance($this->_oConfig->getObject('storage_photos'));
  3834. $iMediaId = $oStorage->storeFileFromUrl($sMediaUrl, true, $iUserId);
  3835. }
  3836. $iId = (int)$oForm->insert(array('profile_id' => $iUserId, 'media_id' => $iMediaId, 'url' => $sLink, 'title' => $sTitle, 'text' => $sDescription, 'added' => time()));
  3837. if(!empty($iId)) {
  3838. if(!empty($oStorage) && !empty($iMediaId))
  3839. $oStorage->afterUploadCleanup($iMediaId, $iUserId);
  3840. return array(
  3841. 'id' => $iId,
  3842. 'event_id' => $iEventId,
  3843. 'url' => $sLink,
  3844. 'item' => $this->_oTemplate->getAttachLinkItem($iUserId, $iId)
  3845. );
  3846. }
  3847. return array('message' => _t('_bx_timeline_txt_err_cannot_perform_action'));
  3848. }
  3849. protected function _deleteLinks($iId)
  3850. {
  3851. $aLinks = $this->_oDb->getLinks($iId);
  3852. if(empty($aLinks) || !is_array($aLinks))
  3853. return;
  3854. $oStorage = BxDolStorage::getObjectInstance($this->_oConfig->getObject('storage_photos'));
  3855. foreach($aLinks as $aLink)
  3856. if(!empty($aLink['media_id']))
  3857. $oStorage->deleteFile($aLink['media_id']);
  3858. $this->_oDb->deleteLinks($iId);
  3859. }
  3860. protected function _saveMedia($sType, $iContentId, $aItemIds, $iProfileId = 0, $isAssociateWithContent = false)
  3861. {
  3862. if(empty($iContentId))
  3863. return;
  3864. if(!$isAssociateWithContent)
  3865. $this->_oDb->deleteMedia($sType, $iContentId);
  3866. if(empty($aItemIds) || !is_array($aItemIds))
  3867. return;
  3868. if(empty($iProfileId))
  3869. $iProfileId = $this->_iProfileId;
  3870. $oStorage = BxDolStorage::getObjectInstance($this->_oConfig->getObject('storage_' . strtolower($sType) . 's'));
  3871. $aGhostFiles = $oStorage->getGhosts ($iProfileId, !$isAssociateWithContent ? $iContentId : 0, true, $this->_isModerator());
  3872. if(empty($aGhostFiles) || !is_array($aGhostFiles))
  3873. return;
  3874. foreach($aGhostFiles as $aFile) {
  3875. if(is_array($aItemIds) && !in_array($aFile['id'], $aItemIds))
  3876. continue;
  3877. $iFileId = (int)$aFile['id'];
  3878. if($aFile['private'])
  3879. $oStorage->setFilePrivate($iFileId, 1);
  3880. $oStorage->updateGhostsContentId($iFileId, $iProfileId, $iContentId, $this->_isModerator());
  3881. $this->_oDb->saveMedia($sType, $iContentId, $iFileId);
  3882. }
  3883. }
  3884. protected function _deleteMedia($sType, $iContentId)
  3885. {
  3886. $aItems = $this->_oDb->getMedia($sType, $iContentId);
  3887. if(empty($aItems) || !is_array($aItems))
  3888. return;
  3889. $oStorage = BxDolStorage::getObjectInstance($this->_oConfig->getObject('storage_' . strtolower($sType) . 's'));
  3890. foreach($aItems as $iItemId)
  3891. $oStorage->deleteFile($iItemId);
  3892. $this->_oDb->deleteMedia($sType, $iContentId);
  3893. }
  3894. protected function _prepareParams($aParams)
  3895. {
  3896. if(empty($aParams['name']))
  3897. $aParams['name'] = '';
  3898. if(empty($aParams['view']))
  3899. $aParams['view'] = BX_TIMELINE_VIEW_DEFAULT;
  3900. if(empty($aParams['type']))
  3901. $aParams['type'] = BX_TIMELINE_TYPE_DEFAULT;
  3902. if(empty($aParams['owner_id']))
  3903. $aParams['owner_id'] = $this->getUserId();
  3904. if(!isset($aParams['start']) || (int)$aParams['start'] < 0)
  3905. $aParams['start'] = 0;
  3906. if(!isset($aParams['per_page']) || (int)$aParams['per_page'] <= 0)
  3907. $aParams['per_page'] = isset($aParams['per_page_default']) && (int)$aParams['per_page_default'] > 0 ? $aParams['per_page_default'] : $this->_oConfig->getPerPage();
  3908. if(empty($aParams['timeline']) || (int)$aParams['timeline'] < 0)
  3909. $aParams['timeline'] = 0;
  3910. if(empty($aParams['filter']))
  3911. $aParams['filter'] = BX_TIMELINE_FILTER_ALL;
  3912. if(empty($aParams['modules']) || !is_array($aParams['modules']))
  3913. $aParams['modules'] = array();
  3914. if(empty($aParams['blink']) || !is_array($aParams['blink']))
  3915. $aParams['blink'] = array();
  3916. $aParams = array_merge($aParams, array(
  3917. 'browse' => 'list',
  3918. 'status' => BX_TIMELINE_STATUS_ACTIVE,
  3919. 'dynamic_mode' => false,
  3920. ));
  3921. return $aParams;
  3922. }
  3923. protected function _prepareParamsGet()
  3924. {
  3925. $aParams = array();
  3926. $aParams['name'] = bx_get('name');
  3927. $aParams['name'] = $aParams['name'] !== false ? bx_process_input($aParams['name'], BX_DATA_TEXT) : '';
  3928. $aParams['view'] = bx_get('view');
  3929. $aParams['view'] = $aParams['view'] !== false ? bx_process_input($aParams['view'], BX_DATA_TEXT) : BX_TIMELINE_VIEW_DEFAULT;
  3930. $aParams['type'] = bx_get('type');
  3931. $aParams['type'] = $aParams['type'] !== false ? bx_process_input($aParams['type'], BX_DATA_TEXT) : BX_TIMELINE_TYPE_DEFAULT;
  3932. $aParams['owner_id'] = bx_get('owner_id');
  3933. $aParams['owner_id'] = $aParams['owner_id'] !== false ? bx_process_input($aParams['owner_id'], BX_DATA_INT) : $this->getUserId();
  3934. $aParams['start'] = bx_get('start');
  3935. $aParams['start'] = $aParams['start'] !== false ? bx_process_input($aParams['start'], BX_DATA_INT) : 0;
  3936. $aParams['per_page'] = bx_get('per_page');
  3937. $aParams['per_page'] = $aParams['per_page'] !== false ? bx_process_input($aParams['per_page'], BX_DATA_INT) : $this->_oConfig->getPerPage();
  3938. $aParams['timeline'] = bx_get('timeline');
  3939. $aParams['timeline'] = $aParams['timeline'] !== false ? bx_process_input($aParams['timeline']) : '';
  3940. $aParams['filter'] = bx_get('filter');
  3941. $aParams['filter'] = $aParams['filter'] !== false ? bx_process_input($aParams['filter'], BX_DATA_TEXT) : BX_TIMELINE_FILTER_ALL;
  3942. $aParams['modules'] = bx_get('modules');
  3943. $aParams['modules'] = $aParams['modules'] !== false ? bx_process_input($aParams['modules'], BX_DATA_TEXT) : array();
  3944. $aParams['blink'] = bx_get('blink');
  3945. $aParams['blink'] = $aParams['blink'] !== false ? explode(',', bx_process_input($aParams['blink'], BX_DATA_TEXT)) : array();
  3946. $aParams = array_merge($aParams, array(
  3947. 'browse' => 'list',
  3948. 'status' => BX_TIMELINE_STATUS_ACTIVE,
  3949. 'dynamic_mode' => true,
  3950. ));
  3951. return $aParams;
  3952. }
  3953. protected function _prepareTextForSave($s)
  3954. {
  3955. return bx_process_input($s, BX_DATA_HTML);
  3956. }
  3957. protected function _prepareFormForAutoSubmit(&$oForm, &$aValues)
  3958. {
  3959. $oForm->aFormAttrs['method'] = BX_DOL_FORM_METHOD_SPECIFIC;
  3960. $oForm->aParams['csrf']['disable'] = true;
  3961. if(!empty($oForm->aParams['db']['submit_name'])) {
  3962. $sSubmitName = $sSubmitValue = false;
  3963. if(is_array($oForm->aParams['db']['submit_name'])) {
  3964. foreach ($oForm->aParams['db']['submit_name'] as $sName) {
  3965. if(isset($oForm->aInputs[$sName])) {
  3966. $sSubmitName = $sName;
  3967. $sSubmitValue = $oForm->aInputs[$sName]['value'];
  3968. break;
  3969. }
  3970. else if(isset($oForm->aInputs['controls']))
  3971. foreach($oForm->aInputs['controls'] as $mixedKey => $mixedInput)
  3972. if(is_numeric($mixedKey) && isset($mixedInput['name']) && $mixedInput['name'] == $sName) {
  3973. $sSubmitName = $sName;
  3974. $sSubmitValue = $mixedInput['value'];
  3975. break 2;
  3976. }
  3977. }
  3978. }
  3979. else {
  3980. $sName = $oForm->aParams['db']['submit_name'];
  3981. if(isset($oForm->aInputs[$sName])) {
  3982. $sSubmitName = $sName;
  3983. $sSubmitValue = $oForm->aInputs[$sName]['value'];
  3984. }
  3985. else if(isset($oForm->aInputs['controls']))
  3986. foreach($oForm->aInputs['controls'] as $mixedKey => $mixedInput)
  3987. if(is_numeric($mixedKey) && isset($mixedInput['name']) && $mixedInput['name'] == $sName) {
  3988. $sSubmitName = $sName;
  3989. $sSubmitValue = $mixedInput['value'];
  3990. break;
  3991. }
  3992. }
  3993. if($sSubmitName && $sSubmitValue)
  3994. $aValues[$sSubmitName] = $sSubmitValue;
  3995. }
  3996. }
  3997. protected function _getFieldValue($sField, $iContentId)
  3998. {
  3999. $CNF = &$this->_oConfig->CNF;
  4000. if(empty($CNF[$sField]))
  4001. return false;
  4002. $aEvent = $this->_oDb->getEvents(array('browse' => 'id', 'value' => $iContentId));
  4003. if(empty($aEvent) || empty($aEvent[$CNF[$sField]]))
  4004. return false;
  4005. return $aEvent[$CNF[$sField]];
  4006. }
  4007. /**
  4008. * Returns records for React Jot using OAuth2
  4009. * @param int $iProfileId
  4010. * @param string $sPage
  4011. * @param string $sTab
  4012. * @param int $iStart
  4013. * @param int $iPerPage
  4014. * @return array
  4015. */
  4016. public function serviceGetUserPosts($iProfileId = 0, $sPage = 'home', $sTab = 'hot', $iStart = 0, $iPerPage = 0)
  4017. {
  4018. $iProfileId = (int)$iProfileId ? (int)$iProfileId : bx_get_logged_profile_id();
  4019. if(empty($iProfileId))
  4020. return array(
  4021. 'code' => 1,
  4022. 'result' => array(),
  4023. 'message' => _t('_bx_timeline_txt_msg_no_profile_id'),
  4024. 'page' => $sPage,
  4025. 'tab' => $sTab
  4026. );
  4027. $sType = BX_TIMELINE_TYPE_OWNER_AND_CONNECTIONS;
  4028. $sView = BX_TIMELINE_VIEW_DEFAULT;
  4029. $sFilter = BX_TIMELINE_FILTER_ALL;
  4030. $aModules = array();
  4031. switch($sPage){
  4032. case 'profile':
  4033. $sType = BX_BASE_MOD_NTFS_TYPE_OWNER;
  4034. $sFilter = BX_TIMELINE_FILTER_OWNER;
  4035. break;
  4036. default:
  4037. if ($this -> _oDb -> isModuleByName($sPage))
  4038. $aModules = array($sPage);
  4039. }
  4040. switch($sTab)
  4041. {
  4042. case 'latest':
  4043. $sType = BX_BASE_MOD_NTFS_TYPE_PUBLIC;
  4044. break;
  4045. case 'popular':
  4046. $sType = BX_TIMELINE_TYPE_HOT;
  4047. break;
  4048. case 'feed':
  4049. $sType = BX_TIMELINE_TYPE_OWNER_AND_CONNECTIONS;
  4050. break;
  4051. default:
  4052. if ($this -> _oDb -> isModuleByName($sTab))
  4053. $aModules = array($sTab);
  4054. }
  4055. $aParams = $this->getParams($sView, $sType, $iProfileId, $iStart, $iPerPage, $sFilter, $aModules);
  4056. $aEvents = $this->_oDb->getEvents($aParams);
  4057. $iCount = $this->_oDb->getEvents(array_merge($aParams, array('count' => true)));
  4058. if(empty($aEvents) || !is_array($aEvents))
  4059. return array(
  4060. 'code' => 0,
  4061. 'result' => array(),
  4062. 'message' => _t('_bx_timeline_txt_msg_no_results'),
  4063. 'page' => $sPage,
  4064. 'tab' => $sTab
  4065. );
  4066. $aBrowseParams = array();
  4067. $aItems = array();
  4068. foreach($aEvents as $aEvent) {
  4069. $aResult = $this->_oTemplate->getData($aEvent, $aBrowseParams);
  4070. if($aResult === false)
  4071. continue;
  4072. $oOwnerProfile = BxDolProfile::getInstance($aResult['owner_id']);
  4073. $aFiles = array();
  4074. $aContent = &$aResult['content'];
  4075. if (!empty($aContent['image']))
  4076. $aFiles['images'] = array_values($aContent['images']);
  4077. if (!empty($aContent['images_attach']))
  4078. $aFiles['images'] = array_values($aContent['images_attach']);
  4079. if (!empty($aContent['videos']))
  4080. $aFiles['videos'] = array_values($aContent['videos']);
  4081. else
  4082. if (!empty($aContent['videos_attach']))
  4083. $aFiles['videos'] = array_values($aContent['videos_attach']);
  4084. if (!empty($aContent['files']))
  4085. $aFiles['files'] = array_values($aContent['files']);
  4086. else
  4087. if (!empty($aContent['files_attach']))
  4088. $aFiles['files'] = array_values($aContent['files_attach']);
  4089. $aItems[$aEvent['id']] = array_merge(array(
  4090. 'owner' => array(
  4091. 'icon' => $oOwnerProfile -> getThumb(),
  4092. 'name' => $oOwnerProfile -> getDisplayName(),
  4093. 'url' => $oOwnerProfile -> getUrl()
  4094. ),
  4095. 'sample' => !empty($aResult['sample']) ? _t($aResult['sample']) : _t('_bx_timeline_txt_sample'),
  4096. 'sample_action' => !empty($aResult['sample_action']) ? _t($aResult['sample_action']) : _t('_bx_timeline_txt_added_sample'),
  4097. 'url' => isset($aResult['url']) ? $aResult['url'] : '',
  4098. 'raw' => isset($aContent['raw']) ? strip_tags($aContent['raw']) : '',
  4099. 'text' => isset($aContent['text']) ? strip_tags($aContent['text']) : '',
  4100. 'views' => isset($aResult['views']['count']) ? (int)$aResult['views']['count'] : 0,
  4101. 'votes' => isset($aResult['votes']['count']) ? (int)$aResult['votes']['count'] : 0,
  4102. 'reactions' => isset($aResult['reactions']['count']) ? (int)$aResult['reactions']['count'] : 0,
  4103. 'scores' => isset($aResult['scores']['count']) ? (int)$aResult['scores']['count'] : 0,
  4104. 'reports' => isset($aResult['reports']['count']) ? (int)$aResult['reports']['count'] : 0,
  4105. 'comments' => isset($aResult['comments']['count']) ? (int)$aResult['comments']['count'] : 0,
  4106. 'date' => isset($aResult['date']) ? $aResult['date'] : $aEvent['date'],
  4107. 'type' => stripos($aEvent['type'], 'timeline') !== false ? 'bx_timeline' : $aEvent['type'],
  4108. 'event_type' => $aEvent['type'],
  4109. 'id' => $aEvent['id'],
  4110. 'content' => $aResult['content'],
  4111. 'title' => isset($aResult['title']) ? _t($aResult['title']) : '',
  4112. 'description' => isset($aResult['description']) ? $aResult['description'] : ''
  4113. ), $aFiles);
  4114. }
  4115. return array(
  4116. 'result' => $aItems,
  4117. 'code' => 0,
  4118. 'message' => '',
  4119. 'page' => $sPage,
  4120. 'tab' => $sTab,
  4121. 'total' => $iCount,
  4122. 'start' => (int)$iStart
  4123. );
  4124. }
  4125. }
  4126. /** @} */