BxTimelineModule.php 212 KB

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