BxTimelineModule.php 203 KB

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