1
0

BxTimelineModule.php 189 KB

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