BxTimelineModule.php 233 KB

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