BxTimelineModule.php 211 KB

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