BxTimelineModule.php 218 KB

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