BxTimelineModule.php 227 KB

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