BxTimelineModule.php 218 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623
  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. if (bx_is_api()){
  1817. $aItemData['event']['author_data'] = BxDolProfile::getData($aItemData['event']['object_owner_id']);
  1818. return [bx_api_get_block('feed_item', $aItemData)];
  1819. }
  1820. return $this->_oTemplate->getItemBlock($aItemData, $aParams);
  1821. }
  1822. public function serviceGetBlockItemContent()
  1823. {
  1824. $iItemId = bx_process_input(bx_get('id'), BX_DATA_INT);
  1825. $sMode = bx_process_input(bx_get('mode'));
  1826. if(!$iItemId || !$sMode)
  1827. return '';
  1828. return $this->_oTemplate->getItemBlockContent($iItemId, $sMode);
  1829. }
  1830. public function serviceGetBlockItemInfo()
  1831. {
  1832. $iItemId = bx_process_input(bx_get('id'), BX_DATA_INT);
  1833. if(!$iItemId)
  1834. return '';
  1835. return $this->_oTemplate->getItemBlockInfo($iItemId);
  1836. }
  1837. public function serviceGetBlockItemComments()
  1838. {
  1839. $iItemId = bx_process_input(bx_get('id'), BX_DATA_INT);
  1840. if(!$iItemId)
  1841. return '';
  1842. return $this->_oTemplate->getItemBlockComments($iItemId);
  1843. }
  1844. public function serviceGetBlockMuted($iProfileId = 0)
  1845. {
  1846. if(!isLogged())
  1847. return MsgBox(_t('_Access denied'));
  1848. if($iProfileId == 0)
  1849. $iProfileId = $this->_iProfileId;
  1850. $oGrid = BxDolGrid::getObjectInstance($this->_oConfig->getObject('grid_mute'));
  1851. if(!$oGrid)
  1852. return MsgBox('_Empty');
  1853. $oGrid->setProfile($iProfileId);
  1854. return $oGrid->getCode();
  1855. }
  1856. public function serviceGetPost($mixedEvent, $aParams = array())
  1857. {
  1858. if(!empty($mixedEvent) && !is_array($mixedEvent))
  1859. $mixedEvent = $this->_oDb->getContentInfoById((int)$mixedEvent);
  1860. if(empty($mixedEvent) || !is_array($mixedEvent))
  1861. return '';
  1862. $aParams = $this->_prepareParams(array_merge(array(
  1863. 'view' => BX_TIMELINE_VIEW_ITEM,
  1864. 'type' => BX_TIMELINE_TYPE_ITEM
  1865. ), $aParams));
  1866. return $this->_oTemplate->getPost($mixedEvent, $aParams);
  1867. }
  1868. public function serviceGetTimelineRepostAllowedView($aEvent)
  1869. {
  1870. return isset($aEvent['content']['allowed_view']) ? $aEvent['content']['allowed_view'] : CHECK_ACTION_RESULT_ALLOWED;
  1871. }
  1872. /**
  1873. * @page service Service Calls
  1874. * @section bx_timeline Timeline
  1875. * @subsection bx_timeline-integration_notifications Integration with Notifications
  1876. * @subsubsection bx_timeline-get_notifications_data get_notifications_data
  1877. *
  1878. * @code bx_srv('bx_timeline', 'get_notifications_data', [...]); @endcode
  1879. *
  1880. * Data for Notifications module.
  1881. *
  1882. * @return an array with special format.
  1883. *
  1884. * @see BxTimelineModule::serviceGetNotificationsData
  1885. */
  1886. /**
  1887. * @ref bx_timeline-get_notifications_data "get_notifications_data"
  1888. */
  1889. public function serviceGetNotificationsData()
  1890. {
  1891. $sModule = $this->_aModule['name'];
  1892. return array(
  1893. 'handlers' => array(
  1894. array('group' => $sModule . '_object', 'type' => 'insert', 'alert_unit' => $sModule, 'alert_action' => 'post_common', 'module_name' => $sModule, 'module_method' => 'get_notifications_post', 'module_class' => 'Module'),
  1895. array('group' => $sModule . '_object', 'type' => 'delete', 'alert_unit' => $sModule, 'alert_action' => 'delete'),
  1896. 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'),
  1897. 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'),
  1898. array('group' => $sModule . '_repost', 'type' => 'insert', 'alert_unit' => $sModule, 'alert_action' => 'repost', 'module_name' => $sModule, 'module_method' => 'get_notifications_repost', 'module_class' => 'Module'),
  1899. array('group' => $sModule . '_repost', 'type' => 'delete', 'alert_unit' => $sModule, 'alert_action' => 'delete_repost'),
  1900. array('group' => $sModule . '_comment', 'type' => 'insert', 'alert_unit' => $sModule, 'alert_action' => 'commentPost', 'module_name' => $sModule, 'module_method' => 'get_notifications_comment', 'module_class' => 'Module'),
  1901. array('group' => $sModule . '_comment', 'type' => 'delete', 'alert_unit' => $sModule, 'alert_action' => 'commentRemoved'),
  1902. array('group' => $sModule . '_reply', 'type' => 'insert', 'alert_unit' => $sModule, 'alert_action' => 'replyPost', 'module_name' => $sModule, 'module_method' => 'get_notifications_reply', 'module_class' => 'Module'),
  1903. array('group' => $sModule . '_reply', 'type' => 'delete', 'alert_unit' => $sModule, 'alert_action' => 'replyRemoved'),
  1904. array('group' => $sModule . '_vote', 'type' => 'insert', 'alert_unit' => $sModule, 'alert_action' => 'doVote', 'module_name' => $sModule, 'module_method' => 'get_notifications_vote', 'module_class' => 'Module'),
  1905. array('group' => $sModule . '_vote', 'type' => 'delete', 'alert_unit' => $sModule, 'alert_action' => 'undoVote'),
  1906. array('group' => $sModule . '_reaction', 'type' => 'insert', 'alert_unit' => $sModule . '_reactions', 'alert_action' => 'doVote', 'module_name' => $sModule, 'module_method' => 'get_notifications_reaction', 'module_class' => 'Module'),
  1907. array('group' => $sModule . '_reaction', 'type' => 'delete', 'alert_unit' => $sModule . '_reactions', 'alert_action' => 'undoVote'),
  1908. 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'),
  1909. 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'),
  1910. ),
  1911. 'settings' => array(
  1912. array('group' => 'content', 'unit' => $sModule, 'action' => 'post_common', 'types' => array('personal', 'follow_member', 'follow_context')),
  1913. array('group' => 'content', 'unit' => $sModule, 'action' => 'publish_failed', 'types' => array('personal')),
  1914. array('group' => 'content', 'unit' => $sModule, 'action' => 'publish_succeeded', 'types' => array('personal')),
  1915. array('group' => 'content', 'unit' => $sModule, 'action' => 'repost', 'types' => array('personal', 'follow_member', 'follow_context')),
  1916. array('group' => 'comment', 'unit' => $sModule, 'action' => 'commentPost', 'types' => array('personal', 'follow_member', 'follow_context')),
  1917. array('group' => 'reply', 'unit' => $sModule, 'action' => 'replyPost', 'types' => array('personal')),
  1918. array('group' => 'vote', 'unit' => $sModule, 'action' => 'doVote', 'types' => array('personal', 'follow_member', 'follow_context')),
  1919. array('group' => 'vote', 'unit' => $sModule . '_reactions', 'action' => 'doVote', 'types' => array('personal', 'follow_member', 'follow_context')),
  1920. array('group' => 'score_up', 'unit' => $sModule, 'action' => 'doVoteUp', 'types' => array('personal', 'follow_member', 'follow_context')),
  1921. array('group' => 'score_down', 'unit' => $sModule, 'action' => 'doVoteDown', 'types' => array('personal', 'follow_member', 'follow_context'))
  1922. ),
  1923. 'alerts' => array(
  1924. array('unit' => $sModule, 'action' => 'post_common'),
  1925. array('unit' => $sModule, 'action' => 'publish_failed'),
  1926. array('unit' => $sModule, 'action' => 'publish_succeeded'),
  1927. array('unit' => $sModule, 'action' => 'delete'),
  1928. array('unit' => $sModule, 'action' => 'repost'),
  1929. array('unit' => $sModule, 'action' => 'delete_repost'),
  1930. array('unit' => $sModule, 'action' => 'commentPost'),
  1931. array('unit' => $sModule, 'action' => 'commentRemoved'),
  1932. array('unit' => $sModule, 'action' => 'replyPost'),
  1933. array('unit' => $sModule, 'action' => 'replyRemoved'),
  1934. array('unit' => $sModule, 'action' => 'doVote'),
  1935. array('unit' => $sModule, 'action' => 'undoVote'),
  1936. array('unit' => $sModule . '_reactions', 'action' => 'doVote'),
  1937. array('unit' => $sModule . '_reactions', 'action' => 'undoVote'),
  1938. array('unit' => $sModule, 'action' => 'doVoteUp'),
  1939. array('unit' => $sModule, 'action' => 'doVoteDown'),
  1940. )
  1941. );
  1942. }
  1943. /**
  1944. * @page service Service Calls
  1945. * @section bx_timeline Timeline
  1946. * @subsection bx_timeline-integration_notifications Integration with Notifications
  1947. * @subsubsection bx_timeline-get_notifications_repost get_notifications_repost
  1948. *
  1949. * @code bx_srv('bx_timeline', 'get_notifications_repost', [...]); @endcode
  1950. *
  1951. * Get data for Repost event to display in Notifications module.
  1952. *
  1953. * @param $aEvent an array with event description.
  1954. * @return an array with special format.
  1955. *
  1956. * @see BxTimelineModule::serviceGetNotificationsRepost
  1957. */
  1958. /**
  1959. * @ref bx_timeline-get_notifications_repost "get_notifications_repost"
  1960. */
  1961. public function serviceGetNotificationsRepost($aEvent)
  1962. {
  1963. $aResult = $this->serviceGetNotificationsPost($aEvent);
  1964. $aResult['lang_key'] = '_bx_timeline_txt_object_reposted';
  1965. return $aResult;
  1966. }
  1967. /**
  1968. * @page service Service Calls
  1969. * @section bx_timeline Timeline
  1970. * @subsection bx_timeline-integration_notifications Integration with Notifications
  1971. * @subsubsection bx_timeline-get_notifications_post get_notifications_post
  1972. *
  1973. * @code bx_srv('bx_timeline', 'get_notifications_post', [...]); @endcode
  1974. *
  1975. * Get data for Post event to display in Notifications module.
  1976. *
  1977. * @param $aEvent an array with event description.
  1978. * @return an array with special format.
  1979. *
  1980. * @see BxTimelineModule::serviceGetNotificationsPost
  1981. */
  1982. /**
  1983. * @ref bx_timeline-get_notifications_post "get_notifications_post"
  1984. */
  1985. public function serviceGetNotificationsPost($aEvent)
  1986. {
  1987. $CNF = &$this->_oConfig->CNF;
  1988. $iContent = (int)$aEvent['object_id'];
  1989. $aContent = $this->_oDb->getEvents(array('browse' => 'id', 'value' => $iContent));
  1990. if(empty($aContent) || !is_array($aContent))
  1991. return array();
  1992. if($this->_oConfig->isSystem($aContent['type'], $aContent['action']))
  1993. $iEntryAuthor = (int)$aContent['owner_id'];
  1994. else
  1995. $iEntryAuthor = (int)$aContent['object_id'];
  1996. $sEntryCaption = call_user_func_array(array($this->_oConfig, 'getTitleShort'), !empty($aContent['title']) ? array($aContent['title']) : array($aContent['description'], $aContent['object_id']));
  1997. return array(
  1998. 'entry_sample' => $CNF['T']['txt_sample_single_ext'],
  1999. 'entry_url' => bx_absolute_url($this->_oConfig->getItemViewUrl($aContent, false), '{bx_url_root}'),
  2000. 'entry_caption' => $sEntryCaption,
  2001. 'entry_author' => $iEntryAuthor,
  2002. 'lang_key' => '' //may be empty or not specified. In this case the default one from Notification module will be used.
  2003. );
  2004. }
  2005. /**
  2006. * @page service Service Calls
  2007. * @section bx_timeline Timeline
  2008. * @subsection bx_timeline-integration_notifications Integration with Notifications
  2009. * @subsubsection bx_timeline-get_notifications_comment get_notifications_comment
  2010. *
  2011. * @code bx_srv('bx_timeline', 'get_notifications_comment', [...]); @endcode
  2012. *
  2013. * Get data for Post Comment event to display in Notifications module.
  2014. *
  2015. * @param $aEvent an array with event description.
  2016. * @return an array with special format.
  2017. *
  2018. * @see BxTimelineModule::serviceGetNotificationsComment
  2019. */
  2020. /**
  2021. * @ref bx_timeline-get_notifications_comment "get_notifications_comment"
  2022. */
  2023. public function serviceGetNotificationsComment($aEvent)
  2024. {
  2025. $CNF = &$this->_oConfig->CNF;
  2026. $iContent = (int)$aEvent['object_id'];
  2027. $aContent = $this->_oDb->getEvents(array('browse' => 'id', 'value' => $iContent));
  2028. if(empty($aContent) || !is_array($aContent))
  2029. return array();
  2030. $oComment = BxDolCmts::getObjectInstance($CNF['OBJECT_COMMENTS'], $iContent);
  2031. if(!$oComment || !$oComment->isEnabled())
  2032. return array();
  2033. $sEntryCaption = call_user_func_array(array($this->_oConfig, 'getTitleShort'), !empty($aContent['title']) ? array($aContent['title']) : array($aContent['description'], $aContent['object_id']));
  2034. return array(
  2035. 'entry_sample' => $CNF['T']['txt_sample_single'],
  2036. 'entry_url' => bx_absolute_url($this->_oConfig->getItemViewUrl($aContent, false), '{bx_url_root}'),
  2037. 'entry_caption' => $sEntryCaption,
  2038. 'entry_author' => $aContent['owner_id'],
  2039. 'subentry_sample' => $CNF['T']['txt_sample_comment_single'],
  2040. 'subentry_url' => bx_absolute_url($oComment->getViewUrl((int)$aEvent['subobject_id'], false), '{bx_url_root}'),
  2041. 'lang_key' => '', //may be empty or not specified. In this case the default one from Notification module will be used.
  2042. );
  2043. }
  2044. /**
  2045. * @page service Service Calls
  2046. * @section bx_timeline Timeline
  2047. * @subsection bx_timeline-integration_notifications Integration with Notifications
  2048. * @subsubsection bx_timeline-get_notifications_reply get_notifications_reply
  2049. *
  2050. * @code bx_srv('bx_timeline', 'get_notifications_reply', [...]); @endcode
  2051. *
  2052. * Get data for Reply to Comment event to display in Notifications module.
  2053. *
  2054. * @param $aEvent an array with event description.
  2055. * @return an array with special format.
  2056. *
  2057. * @see BxTimelineModule::serviceGetNotificationsReply
  2058. */
  2059. /**
  2060. * @ref bx_timeline-get_notifications_reply "get_notifications_reply"
  2061. */
  2062. public function serviceGetNotificationsReply($aEvent)
  2063. {
  2064. $CNF = &$this->_oConfig->CNF;
  2065. $oComment = BxDolCmts::getObjectInstance($CNF['OBJECT_COMMENTS'], 0, false);
  2066. if(!$oComment || !$oComment->isEnabled())
  2067. return array();
  2068. $iParentId = (int)$aEvent['object_id'];
  2069. $aParentInfo = $oComment->getQueryObject()->getCommentsBy(array('type' => 'id', 'id' => $iParentId));
  2070. if(empty($aParentInfo) || !is_array($aParentInfo))
  2071. return array();
  2072. $iObjectId = (int)$aParentInfo['cmt_object_id'];
  2073. $oComment->init($iObjectId);
  2074. return array(
  2075. 'object_id' => $iObjectId,
  2076. 'entry_sample' => '_cmt_txt_sample_comment_single',
  2077. 'entry_url' => bx_absolute_url($oComment->getViewUrl($iParentId, false), '{bx_url_root}'),
  2078. 'entry_caption' => strmaxtextlen($aParentInfo['cmt_text'], 20, '...'),
  2079. 'entry_author' => (int)$aParentInfo['cmt_author_id'],
  2080. 'subentry_sample' => '_cmt_txt_sample_reply_to',
  2081. 'subentry_url' => bx_absolute_url($oComment->getViewUrl((int)$aEvent['subobject_id'], false), '{bx_url_root}'),
  2082. 'lang_key' => '', //may be empty or not specified. In this case the default one from Notification module will be used.
  2083. );
  2084. }
  2085. /**
  2086. * @page service Service Calls
  2087. * @section bx_timeline Timeline
  2088. * @subsection bx_timeline-integration_notifications Integration with Notifications
  2089. * @subsubsection bx_timeline-get_notifications_vote get_notifications_vote
  2090. *
  2091. * @code bx_srv('bx_timeline', 'get_notifications_vote', [...]); @endcode
  2092. *
  2093. * Get data for Vote event to display in Notifications module.
  2094. *
  2095. * @param $aEvent an array with event description.
  2096. * @return an array with special format.
  2097. *
  2098. * @see BxTimelineModule::serviceGetNotificationsVote
  2099. */
  2100. /**
  2101. * @ref bx_timeline-get_notifications_vote "get_notifications_vote"
  2102. */
  2103. public function serviceGetNotificationsVote($aEvent)
  2104. {
  2105. $CNF = &$this->_oConfig->CNF;
  2106. $iContent = (int)$aEvent['object_id'];
  2107. $aContent = $this->_oDb->getEvents(array('browse' => 'id', 'value' => $iContent));
  2108. if(empty($aContent) || !is_array($aContent))
  2109. return array();
  2110. $oVote = BxDolVote::getObjectInstance($CNF['OBJECT_VOTES'], $iContent);
  2111. if(!$oVote || !$oVote->isEnabled())
  2112. return array();
  2113. $sEntryCaption = call_user_func_array(array($this->_oConfig, 'getTitleShort'), !empty($aContent['title']) ? array($aContent['title']) : array($aContent['description'], $aContent['object_id']));
  2114. return array(
  2115. 'entry_sample' => $CNF['T']['txt_sample_single'],
  2116. 'entry_url' => bx_absolute_url($this->_oConfig->getItemViewUrl($aContent, false), '{bx_url_root}'),
  2117. 'entry_caption' => $sEntryCaption,
  2118. 'entry_author' => $aContent['owner_id'],
  2119. 'subentry_sample' => $CNF['T']['txt_sample_vote_single'],
  2120. 'lang_key' => '', //may be empty or not specified. In this case the default one from Notification module will be used.
  2121. );
  2122. }
  2123. /**
  2124. * Entry post vote for Notifications module
  2125. */
  2126. public function serviceGetNotificationsReaction($aEvent)
  2127. {
  2128. $CNF = &$this->_oConfig->CNF;
  2129. $iContent = (int)$aEvent['object_id'];
  2130. $aContent = $this->_oDb->getEvents(array('browse' => 'id', 'value' => $iContent));
  2131. if(empty($aContent) || !is_array($aContent))
  2132. return array();
  2133. $oReaction = BxDolVote::getObjectInstance($CNF['OBJECT_REACTIONS'], $iContent);
  2134. if(!$oReaction || !$oReaction->isEnabled())
  2135. return array();
  2136. $aSubentry = $oReaction->getTrackBy(array('type' => 'id', 'id' => (int)$aEvent['subobject_id']));
  2137. if(empty($aSubentry) || !is_array($aSubentry))
  2138. return array();
  2139. $aSubentrySampleParams = array();
  2140. $aReaction = $oReaction->getReaction($aSubentry['reaction']);
  2141. if(!empty($aReaction['title']))
  2142. $aSubentrySampleParams[] = $aReaction['title'];
  2143. else
  2144. $aSubentrySampleParams[] = '_undefined';
  2145. $sEntryCaption = call_user_func_array(array($this->_oConfig, 'getTitleShort'), !empty($aContent['title']) ? array($aContent['title']) : array($aContent['description'], $aContent['object_id']));
  2146. return array(
  2147. 'entry_sample' => $CNF['T']['txt_sample_single'],
  2148. 'entry_url' => bx_absolute_url($this->_oConfig->getItemViewUrl($aContent, false), '{bx_url_root}'),
  2149. 'entry_caption' => $sEntryCaption,
  2150. 'entry_author' => $aContent['owner_id'],
  2151. 'subentry_sample' => $CNF['T']['txt_sample_reaction_single'],
  2152. 'subentry_sample_params' => $aSubentrySampleParams,
  2153. 'lang_key' => '', //may be empty or not specified. In this case the default one from Notification module will be used.
  2154. );
  2155. }
  2156. /**
  2157. * @page service Service Calls
  2158. * @section bx_timeline Timeline
  2159. * @subsection bx_timeline-integration_notifications Integration with Notifications
  2160. * @subsubsection bx_timeline-get_notifications_score_up get_notifications_score_up
  2161. *
  2162. * @code bx_srv('bx_timeline', 'get_notifications_score_up', [...]); @endcode
  2163. *
  2164. * Get data for Score Up Vote event to display in Notifications module.
  2165. *
  2166. * @param $aEvent an array with event description.
  2167. * @return an array with special format.
  2168. *
  2169. * @see BxTimelineModule::serviceGetNotificationsScoreUp
  2170. */
  2171. /**
  2172. * @ref bx_timeline-get_notifications_score_up "get_notifications_score_up"
  2173. */
  2174. public function serviceGetNotificationsScoreUp($aEvent)
  2175. {
  2176. return $this->_serviceGetNotificationsScore('up', $aEvent);
  2177. }
  2178. /**
  2179. * @page service Service Calls
  2180. * @section bx_timeline Timeline
  2181. * @subsection bx_timeline-integration_notifications Integration with Notifications
  2182. * @subsubsection bx_timeline-get_notifications_score_down get_notifications_score_down
  2183. *
  2184. * @code bx_srv('bx_timeline', 'get_notifications_score_down', [...]); @endcode
  2185. *
  2186. * Get data for Score Down Vote event to display in Notifications module.
  2187. *
  2188. * @param $aEvent an array with event description.
  2189. * @return an array with special format.
  2190. *
  2191. * @see BxTimelineModule::serviceGetNotificationsScoreDown
  2192. */
  2193. /**
  2194. * @ref bx_timeline-get_notifications_score_down "get_notifications_score_down"
  2195. */
  2196. public function serviceGetNotificationsScoreDown($aEvent)
  2197. {
  2198. return $this->_serviceGetNotificationsScore('down', $aEvent);
  2199. }
  2200. protected function _serviceGetNotificationsScore($sType, $aEvent)
  2201. {
  2202. $CNF = &$this->_oConfig->CNF;
  2203. $iContent = (int)$aEvent['object_id'];
  2204. $aContent = $this->_oDb->getEvents(array('browse' => 'id', 'value' => $iContent));
  2205. if(empty($aContent) || !is_array($aContent))
  2206. return array();
  2207. $oScore = BxDolScore::getObjectInstance($CNF['OBJECT_SCORES'], $iContent);
  2208. if(!$oScore || !$oScore->isEnabled())
  2209. return array();
  2210. $sEntryCaption = call_user_func_array(array($this->_oConfig, 'getTitleShort'), !empty($aContent['title']) ? array($aContent['title']) : array($aContent['description'], $aContent['object_id']));
  2211. return array(
  2212. 'entry_sample' => $CNF['T']['txt_sample_single'],
  2213. 'entry_url' => bx_absolute_url($this->_oConfig->getItemViewUrl($aContent, false), '{bx_url_root}'),
  2214. 'entry_caption' => $sEntryCaption,
  2215. 'entry_author' => $aContent['owner_id'],
  2216. 'subentry_sample' => $CNF['T']['txt_sample_score_' . $sType . '_single'],
  2217. 'lang_key' => '', //may be empty or not specified. In this case the default one from Notification module will be used.
  2218. );
  2219. }
  2220. /**
  2221. * @page service Service Calls
  2222. * @section bx_timeline Timeline
  2223. * @subsection bx_timeline-repost Repost
  2224. * @subsubsection bx_timeline-get_repost_element_block get_repost_element_block
  2225. *
  2226. * @code bx_srv('bx_timeline', 'get_repost_element_block', [...]); @endcode
  2227. *
  2228. * Get repost element for content based modules.
  2229. *
  2230. * @param $iOwnerId integer value with owner profile ID.
  2231. * @param $sType string value with type (module name).
  2232. * @param $sAction string value with action (module action).
  2233. * @param $iObjectId integer value with object ID to be reposted.
  2234. * @param $aParams (optional) an array with additional params.
  2235. * @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.
  2236. *
  2237. * @see BxTimelineModule::serviceGetRepostElementBlock
  2238. */
  2239. /**
  2240. * @ref bx_timeline-get_repost_element_block "get_repost_element_block"
  2241. */
  2242. public function serviceGetRepostElementBlock($iOwnerId, $sType, $sAction, $iObjectId, $aParams = [])
  2243. {
  2244. if(!$this->isEnabled())
  2245. return '';
  2246. $aParams = array_merge($this->_oConfig->getRepostDefaults(), $aParams);
  2247. return $this->_oTemplate->getRepostElement($iOwnerId, $sType, $sAction, $iObjectId, $aParams);
  2248. }
  2249. /**
  2250. * @page service Service Calls
  2251. * @section bx_timeline Timeline
  2252. * @subsection bx_timeline-repost Repost
  2253. * @subsubsection bx_timeline-get_repost_element_block_api get_repost_element_block_api
  2254. *
  2255. * @code bx_srv('bx_timeline', 'get_repost_element_block_api', [...]); @endcode
  2256. *
  2257. * Get repost element for content based modules.
  2258. * Note. Response is formated to be used in API calls.
  2259. *
  2260. * @param $iOwnerId integer value with owner profile ID.
  2261. * @param $sType string value with type (module name).
  2262. * @param $sAction string value with action (module action).
  2263. * @param $iObjectId integer value with object ID to be reposted.
  2264. * @param $aParams (optional) an array with additional params.
  2265. * @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.
  2266. *
  2267. * @see BxTimelineModule::serviceGetRepostElementBlockApi
  2268. */
  2269. /**
  2270. * @ref bx_timeline-get_repost_element_block_api "get_repost_element_block_api"
  2271. * @api @ref bx_timeline-get_repost_element_block_api "get_repost_element_block_api"
  2272. */
  2273. public function serviceGetRepostElementBlockApi($iOwnerId, $sType, $sAction, $iObjectId, $aParams = [])
  2274. {
  2275. if(!bx_is_api())
  2276. return;
  2277. //TODO: Implement the functionality here.
  2278. $sClass = get_class($this);
  2279. return [
  2280. 'display_type' => 'element',
  2281. 'name' => md5($sClass),
  2282. 'title' => get_class($this)
  2283. ];
  2284. }
  2285. /**
  2286. * @page service Service Calls
  2287. * @section bx_timeline Timeline
  2288. * @subsection bx_timeline-repost Repost
  2289. * @subsubsection bx_timeline-get_repost_counter get_repost_counter
  2290. *
  2291. * @code bx_srv('bx_timeline', 'get_repost_counter', [...]); @endcode
  2292. *
  2293. * Get repost counter.
  2294. *
  2295. * @param $sType string value with type (module name).
  2296. * @param $sAction string value with action (module action).
  2297. * @param $iObjectId integer value with object ID to be reposted.
  2298. * @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.
  2299. *
  2300. * @see BxTimelineModule::serviceGetRepostCounter
  2301. */
  2302. /**
  2303. * @ref bx_timeline-get_repost_counter "get_repost_counter"
  2304. */
  2305. public function serviceGetRepostCounter($sType, $sAction, $iObjectId, $aParams = [])
  2306. {
  2307. if(!$this->isEnabled())
  2308. return '';
  2309. $aReposted = $this->_oDb->getReposted($sType, $sAction, $iObjectId);
  2310. $aParams = array_merge($this->_oConfig->getRepostDefaults(), $aParams);
  2311. return $this->_oTemplate->getRepostCounter($aReposted, $aParams);
  2312. }
  2313. /**
  2314. * @page service Service Calls
  2315. * @section bx_timeline Timeline
  2316. * @subsection bx_timeline-repost Repost
  2317. * @subsubsection bx_timeline-get_repost_js_script get_repost_js_script
  2318. *
  2319. * @code bx_srv('bx_timeline', 'get_repost_js_script', [...]); @endcode
  2320. *
  2321. * Get repost JavaScript code.
  2322. *
  2323. * @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.
  2324. *
  2325. * @see BxTimelineModule::serviceGetRepostJsScript
  2326. */
  2327. /**
  2328. * @ref bx_timeline-get_repost_js_script "get_repost_js_script"
  2329. */
  2330. public function serviceGetRepostJsScript()
  2331. {
  2332. if(!$this->isEnabled())
  2333. return '';
  2334. return $this->_oTemplate->getRepostJsScript();
  2335. }
  2336. /**
  2337. * @page service Service Calls
  2338. * @section bx_timeline Timeline
  2339. * @subsection bx_timeline-repost Repost
  2340. * @subsubsection bx_timeline-get_repost_js_click get_repost_js_click
  2341. *
  2342. * @code bx_srv('bx_timeline', 'get_repost_js_click', [...]); @endcode
  2343. *
  2344. * Get repost JavaScript code for OnClick event.
  2345. *
  2346. * @param $iOwnerId integer value with owner profile ID.
  2347. * @param $sType string value with type (module name).
  2348. * @param $sAction string value with action (module action).
  2349. * @param $iObjectId integer value with object ID to be reposted.
  2350. * @return HTML string with JavaScript code to display in OnClick events of HTML elements.
  2351. *
  2352. * @see BxTimelineModule::serviceGetRepostJsClick
  2353. */
  2354. /**
  2355. * @ref bx_timeline-get_repost_js_click "get_repost_js_click"
  2356. */
  2357. public function serviceGetRepostJsClick($iOwnerId, $sType, $sAction, $iObjectId)
  2358. {
  2359. if(!$this->isEnabled())
  2360. return '';
  2361. return $this->_oTemplate->getRepostJsClick($iOwnerId, $sType, $sAction, $iObjectId);
  2362. }
  2363. /**
  2364. * @page service Service Calls
  2365. * @section bx_timeline Timeline
  2366. * @subsection bx_timeline-repost Repost
  2367. * @subsubsection bx_timeline-get_repost_with_js_click get_repost_with_js_click
  2368. *
  2369. * @code bx_srv('bx_timeline', 'get_repost_with_js_click', [...]); @endcode
  2370. *
  2371. * Get 'repost with' JavaScript code for OnClick event.
  2372. *
  2373. * @param $iReposterId integer value with reposter profile ID.
  2374. * @param $sType string value with type (module name).
  2375. * @param $sAction string value with action (module action).
  2376. * @param $iObjectId integer value with object ID to be reposted.
  2377. * @return HTML string with JavaScript code to display in OnClick events of HTML elements.
  2378. *
  2379. * @see BxTimelineModule::serviceGetRepostWithJsClick
  2380. */
  2381. /**
  2382. * @ref bx_timeline-get_repost_with_js_click "get_repost_with_js_click"
  2383. */
  2384. public function serviceGetRepostWithJsClick($iReposterId, $sType, $sAction, $iObjectId)
  2385. {
  2386. if(!$this->isEnabled())
  2387. return '';
  2388. return $this->_oTemplate->getRepostWithJsClick($iReposterId, $sType, $sAction, $iObjectId);
  2389. }
  2390. /**
  2391. * @page service Service Calls
  2392. * @section bx_timeline Timeline
  2393. * @subsection bx_timeline-repost Repost
  2394. * @subsubsection bx_timeline-get_repost_to_js_click get_repost_to_js_click
  2395. *
  2396. * @code bx_srv('bx_timeline', 'get_repost_to_js_click', [...]); @endcode
  2397. *
  2398. * Get 'repost to' JavaScript code for OnClick event.
  2399. *
  2400. * @param $iReposterId integer value with reposter profile ID.
  2401. * @param $sType string value with type (module name).
  2402. * @param $sAction string value with action (module action).
  2403. * @param $iObjectId integer value with object ID to be reposted.
  2404. * @return HTML string with JavaScript code to display in OnClick events of HTML elements.
  2405. *
  2406. * @see BxTimelineModule::serviceGetRepostToJsClick
  2407. */
  2408. /**
  2409. * @ref bx_timeline-get_repost_to_js_click "get_repost_to_js_click"
  2410. */
  2411. public function serviceGetRepostToJsClick($iReposterId, $sType, $sAction, $iObjectId)
  2412. {
  2413. if(!$this->isEnabled())
  2414. return '';
  2415. return $this->_oTemplate->getRepostToJsClick($iReposterId, $sType, $sAction, $iObjectId);
  2416. }
  2417. /**
  2418. * @page service Service Calls
  2419. * @section bx_timeline Timeline
  2420. * @subsection bx_timeline-repost Repost
  2421. * @subsubsection bx_timeline-repost repost
  2422. *
  2423. * @code bx_srv('bx_timeline', 'repost', [...]); @endcode
  2424. *
  2425. * Perform repost action.
  2426. *
  2427. * @param $iAuthorId integer value with performer profile ID.
  2428. * @param $iOwnerId integer value with repost event owner profile ID.
  2429. * @param $sType string value with type (module name).
  2430. * @param $sAction string value with action (module action).
  2431. * @param $iObjectId integer value with object ID to be reposted.
  2432. * @parem $bForce boolean value force reposting without ACL check.
  2433. * @return an array with error (code and message) or integer with newly created repost event ID.
  2434. *
  2435. * @see BxTimelineModule::serviceRepost
  2436. */
  2437. /**
  2438. * @ref bx_timeline-repost "repost"
  2439. */
  2440. public function serviceRepost($iAuthorId, $iOwnerId, $sType, $sAction, $iObjectId, $bForce = false)
  2441. {
  2442. return $this->repost($iAuthorId, $iOwnerId, $sType, $sAction, $iObjectId, false, $bForce);
  2443. }
  2444. /**
  2445. * @page service Service Calls
  2446. * @section bx_timeline Timeline
  2447. * @subsection bx_timeline-repost Repost
  2448. * @subsubsection bx_timeline-repost_with repost_with
  2449. *
  2450. * @code bx_srv('bx_timeline', 'repost_with', [...]); @endcode
  2451. *
  2452. * Perform repost action passing additional data.
  2453. *
  2454. * @param $iAuthorId integer value with performer profile ID.
  2455. * @param $iOwnerId integer value with repost event owner profile ID.
  2456. * @param $sType string value with type (module name).
  2457. * @param $sAction string value with action (module action).
  2458. * @param $iObjectId integer value with object ID to be reposted.
  2459. * @param $mixedData array with some data to attach to repost event or false.
  2460. * @parem $bForce boolean value force reposting without ACL check.
  2461. * @return an array with error (code and message) or integer with newly created repost event ID.
  2462. *
  2463. * @see BxTimelineModule::serviceRepostWith
  2464. */
  2465. /**
  2466. * @ref bx_timeline-repost_with "repost_with"
  2467. */
  2468. public function serviceRepostWith($iAuthorId, $iOwnerId, $sType, $sAction, $iObjectId, $mixedData = false, $bForce = false)
  2469. {
  2470. return $this->repost($iAuthorId, $iOwnerId, $sType, $sAction, $iObjectId, $mixedData, $bForce);
  2471. }
  2472. /**
  2473. * @page service Service Calls
  2474. * @section bx_timeline Timeline
  2475. * @subsection bx_timeline-repost Repost
  2476. * @subsubsection bx_timeline-repost_by_id repost_by_id
  2477. *
  2478. * @code bx_srv('bx_timeline', 'repost_by_id', [...]); @endcode
  2479. *
  2480. * Perform repost action by Timeline event ID.
  2481. *
  2482. * @param $iAuthorId integer value with performer profile ID.
  2483. * @param $iOwnerId integer value with repost event owner profile ID.
  2484. * @param $iEventId integer value with event ID which will be reposted.
  2485. * @parem $bForce boolean value force reposting without ACL check.
  2486. * @return an array with error (code and message) or integer with newly created repost event ID.
  2487. *
  2488. * @see BxTimelineModule::serviceRepostById
  2489. */
  2490. /**
  2491. * @ref bx_timeline-repost_by_id "repost_by_id"
  2492. */
  2493. public function serviceRepostById($iAuthorId, $iOwnerId, $iEventId, $bForce = false)
  2494. {
  2495. $aEvent = $this->_oDb->getEntriesBy(array('type' => 'id', 'id' => $iEventId));
  2496. if(empty($aEvent) || !is_array($aEvent))
  2497. return array('code' => 1, 'message' => _t('_bx_timeline_txt_err_cannot_repost'));
  2498. $sType = $aEvent['type'];
  2499. $sAction = $aEvent['action'];
  2500. $iObjectId = $this->_oConfig->isSystem($sType, $sAction) ? $aEvent['object_id'] : $aEvent['id'];
  2501. $sCommonPrefix = $this->_oConfig->getPrefix('common_post');
  2502. if(str_replace($sCommonPrefix, '', $sType) == BX_TIMELINE_PARSE_TYPE_REPOST) {
  2503. $aReposted = $this->_oDb->getReposted($sType, $sAction, $iObjectId);
  2504. if(empty($aReposted) || !is_array($aReposted))
  2505. return array('code' => 1, 'message' => _t('_bx_timeline_txt_err_cannot_repost'));
  2506. $aRepostedData = unserialize($aEvent['content']);
  2507. $sType = $aRepostedData['type'];
  2508. $sAction = $aRepostedData['action'];
  2509. $iObjectId = $aRepostedData['object_id'];
  2510. }
  2511. return $this->repost($iAuthorId, $iOwnerId, $sType, $sAction, $iObjectId, false, $bForce);
  2512. }
  2513. public function repost($iAuthorId, $iOwnerId, $sType, $sAction, $iObjectId, $mixedData = false, $bForce = false)
  2514. {
  2515. $aReposted = $this->_oDb->getReposted($sType, $sAction, $iObjectId);
  2516. if(empty($aReposted) || !is_array($aReposted))
  2517. return array('code' => 1, 'message' => _t('_bx_timeline_txt_err_cannot_repost'));
  2518. $mixedAllowed = $this->isAllowedRepost($aReposted, true);
  2519. if(!$bForce && $mixedAllowed !== true)
  2520. return array('code' => 2, 'message' => strip_tags($mixedAllowed));
  2521. $bReposted = $this->_oDb->isReposted($aReposted['id'], $iOwnerId, $iAuthorId);
  2522. if($bReposted)
  2523. return array('code' => 3, 'message' => _t('_bx_timeline_txt_err_already_reposted'));
  2524. $iDate = time();
  2525. $iId = $this->_oDb->insertEvent([
  2526. 'owner_id' => $iOwnerId,
  2527. 'system' => 0,
  2528. 'type' => $this->_oConfig->getPrefix('common_post') . 'repost',
  2529. 'action' => '',
  2530. 'object_id' => $iAuthorId,
  2531. 'object_owner_id' => $iAuthorId,
  2532. 'object_privacy_view' => $this->_oConfig->getPrivacyViewDefault('object'),
  2533. 'content' => serialize([
  2534. 'type' => $sType,
  2535. 'action' => $sAction,
  2536. 'object_id' => $iObjectId,
  2537. 'rdata' => $mixedData
  2538. ]),
  2539. 'title' => '',
  2540. 'description' => '',
  2541. 'date' => $iDate,
  2542. 'reacted' => $iDate,
  2543. 'status_admin' => $this->getStatusAdmin()
  2544. ]);
  2545. if(empty($iId))
  2546. return array('code' => 4, 'message' => _t('_bx_timeline_txt_err_cannot_repost'));
  2547. $this->onRepost($iId, $aReposted);
  2548. return $iId;
  2549. }
  2550. /**
  2551. * @page service Service Calls
  2552. * @section bx_timeline Timeline
  2553. * @subsection bx_timeline-other Other
  2554. * @subsubsection bx_timeline-update update
  2555. *
  2556. * @code bx_srv('bx_timeline', 'update', [...]); @endcode
  2557. *
  2558. * Update timeline event by ID.
  2559. *
  2560. * @param $iEventId integer value with event ID.
  2561. * @param $aSet an array with key=>value pairs for fields which should be updated.
  2562. * @return boolean value with the result of operation.
  2563. *
  2564. * @see BxTimelineModule::serviceUpdate
  2565. */
  2566. /**
  2567. * @ref bx_timeline-update "update"
  2568. */
  2569. public function serviceUpdate($iEventId, $aSet)
  2570. {
  2571. if(empty($iEventId))
  2572. return false;
  2573. return (int)$this->_oDb->updateEvent($aSet, array('id' => $iEventId)) > 0;
  2574. }
  2575. /**
  2576. * @page service Service Calls
  2577. * @section bx_timeline Timeline
  2578. * @subsection bx_timeline-other Other
  2579. * @subsubsection bx_timeline-delete delete
  2580. *
  2581. * @code bx_srv('bx_timeline', 'delete', [...]); @endcode
  2582. *
  2583. * Delete timeline event by ID.
  2584. *
  2585. * @param $iId integer value with event ID.
  2586. * @return boolean value with the result of operation.
  2587. *
  2588. * @see BxTimelineModule::serviceDelete
  2589. */
  2590. /**
  2591. * @ref bx_timeline-delete "delete"
  2592. */
  2593. public function serviceDelete($iId)
  2594. {
  2595. $aEvent = $this->_oDb->getEvents(array('browse' => 'id', 'value' => $iId));
  2596. if(empty($aEvent) || !is_array($aEvent))
  2597. return true;
  2598. if($this->isAllowedDelete($aEvent, true) !== true || !$this->deleteEvent($aEvent))
  2599. return false;
  2600. $this->_oDb->deleteCache(array('event_id' => $iId));
  2601. return true;
  2602. }
  2603. /**
  2604. * @page service Service Calls
  2605. * @section bx_timeline Timeline
  2606. * @subsection bx_timeline-other Other
  2607. * @subsubsection bx_timeline-get_menu_item_addon_comment get_menu_item_addon_comment
  2608. *
  2609. * @code bx_srv('bx_timeline', 'get_menu_item_addon_comment', [...]); @endcode
  2610. *
  2611. * Get addon for Comment menu item.
  2612. * NOTE. The service isn't used for now because comment functionality in card was updated.
  2613. *
  2614. * @param $sSystem string value with comments engine system.
  2615. * @param $iObjectId integer value with object ID.
  2616. * @return HTML string to display in menu item.
  2617. *
  2618. * @see BxTimelineModule::serviceGetMenuItemAddonComment
  2619. */
  2620. /**
  2621. * @ref bx_timeline-get_menu_item_addon_comment "get_menu_item_addon_comment"
  2622. */
  2623. public function serviceGetMenuItemAddonComment($sSystem, $iObjectId, $aBrowseParams = array())
  2624. {
  2625. if(empty($sSystem) || empty($iObjectId))
  2626. return '';
  2627. $oCmts = $this->getCmtsObject($sSystem, $iObjectId);
  2628. if($oCmts === false)
  2629. return '';
  2630. $iCounter = (int)$oCmts->getCommentsCount();
  2631. if(empty($iCounter))
  2632. return '';
  2633. return $this->_oTemplate->parseLink('javascript:void(0)', $iCounter, array(
  2634. 'class' => 'bx-menu-item-addon',
  2635. 'title' => _t('_bx_timeline_menu_item_title_item_comment'),
  2636. 'onclick' => "javascript:" . $this->_oConfig->getJsObjectView($aBrowseParams) . ".commentItem(this, '" . $sSystem . "', " . $iObjectId . ")"
  2637. ));
  2638. }
  2639. /**
  2640. * @page service Service Calls
  2641. * @section bx_timeline Timeline
  2642. * @subsection bx_timeline-other Other
  2643. * @subsubsection bx_timeline-get_settings_checker_helper get_settings_checker_helper
  2644. *
  2645. * @code bx_srv('bx_timeline', 'get_settings_checker_helper', [...]); @endcode
  2646. *
  2647. * Get Checker Helper class name for Forms engine.
  2648. *
  2649. * @return string with Checker Helper class name.
  2650. *
  2651. * @see BxTimelineModule::serviceGetSettingsCheckerHelper
  2652. */
  2653. /**
  2654. * @ref bx_timeline-get_settings_checker_helper "get_settings_checker_helper"
  2655. */
  2656. public function serviceGetSettingsCheckerHelper()
  2657. {
  2658. bx_import('FormCheckerHelper', $this->_aModule);
  2659. return 'BxTimelineFormCheckerHelper';
  2660. }
  2661. /**
  2662. * @page service Service Calls
  2663. * @section bx_timeline Timeline
  2664. * @subsection bx_timeline-other Other
  2665. * @subsubsection bx_timeline-get_options_videos_preload get_options_videos_preload
  2666. *
  2667. * @code bx_srv('bx_timeline', 'get_options_videos_preload', [...]); @endcode
  2668. *
  2669. * Get an array with available options for 'Videos preload in Timeline' setting.
  2670. *
  2671. * @return an array with available options represented as key => value pairs.
  2672. *
  2673. * @see BxTimelineModule::serviceGetOptionsVideosPreload
  2674. */
  2675. /**
  2676. * @ref bx_timeline-get_options_videos_preload "get_options_videos_preload"
  2677. */
  2678. public function serviceGetOptionsVideosPreload()
  2679. {
  2680. $CNF = &$this->_oConfig->CNF;
  2681. $aOptions = array('auto', 'metadata', 'none');
  2682. $aResult = array();
  2683. foreach($aOptions as $sOption)
  2684. $aResult[] = array(
  2685. 'key' => $sOption,
  2686. 'value' => _t($CNF['T']['option_vp_' . $sOption])
  2687. );
  2688. return $aResult;
  2689. }
  2690. /**
  2691. * @page service Service Calls
  2692. * @section bx_timeline Timeline
  2693. * @subsection bx_timeline-other Other
  2694. * @subsubsection bx_timeline-get_options_videos_autoplay get_options_videos_autoplay
  2695. *
  2696. * @code bx_srv('bx_timeline', 'get_options_videos_autoplay', [...]); @endcode
  2697. *
  2698. * Get an array with available options for 'Videos autoplay in Timeline' setting.
  2699. *
  2700. * @return an array with available options represented as key => value pairs.
  2701. *
  2702. * @see BxTimelineModule::serviceGetOptionsVideosAutoplay
  2703. */
  2704. /**
  2705. * @ref bx_timeline-get_options_videos_autoplay "get_options_videos_autoplay"
  2706. */
  2707. public function serviceGetOptionsVideosAutoplay()
  2708. {
  2709. $CNF = &$this->_oConfig->CNF;
  2710. $aOptions = array(BX_TIMELINE_VAP_OFF, BX_TIMELINE_VAP_ON_MUTE, BX_TIMELINE_VAP_ON);
  2711. $aResult = array();
  2712. foreach($aOptions as $sOption)
  2713. $aResult[] = array(
  2714. 'key' => $sOption,
  2715. 'value' => _t($CNF['T']['option_vap_' . $sOption])
  2716. );
  2717. return $aResult;
  2718. }
  2719. /**
  2720. * @page service Service Calls
  2721. * @section bx_timeline Timeline
  2722. * @subsection bx_timeline-other Other
  2723. * @subsubsection bx_timeline-get_options_attachments_layout get_options_attachments_layout
  2724. *
  2725. * @code bx_srv('bx_timeline', 'get_options_attachments_layout', [...]); @endcode
  2726. *
  2727. * Get an array with available options for 'Show attachments as' setting.
  2728. *
  2729. * @return an array with available options represented as key => value pairs.
  2730. *
  2731. * @see BxTimelineModule::serviceGetOptionsAttachmentsLayout
  2732. */
  2733. /**
  2734. * @ref bx_timeline-get_options_attachments_layout "get_options_attachments_layout"
  2735. */
  2736. public function serviceGetOptionsAttachmentsLayout()
  2737. {
  2738. $CNF = &$this->_oConfig->CNF;
  2739. $aOptions = array(BX_TIMELINE_ML_GALLERY, BX_TIMELINE_ML_SHOWCASE);
  2740. $aResult = array();
  2741. foreach($aOptions as $sOption)
  2742. $aResult[] = array(
  2743. 'key' => $sOption,
  2744. 'value' => _t($CNF['T']['option_al_' . $sOption])
  2745. );
  2746. return $aResult;
  2747. }
  2748. /**
  2749. * @page service Service Calls
  2750. * @section bx_timeline Timeline
  2751. * @subsection bx_timeline-other Other
  2752. * @subsubsection bx_timeline-get_live_update get_live_update
  2753. *
  2754. * @code bx_srv('bx_timeline', 'get_live_update', [...]); @endcode
  2755. *
  2756. * Get an array with actual Live Update info. Only one live update notification for all new events.
  2757. *
  2758. * @return an array with Live Update info.
  2759. *
  2760. * @see BxTimelineModule::serviceGetLiveUpdate
  2761. */
  2762. /**
  2763. * @ref bx_timeline-get_live_update "get_live_update"
  2764. */
  2765. public function serviceGetLiveUpdate($aBrowseParams, $iProfileId, $iValue = 0, $iInit = 0)
  2766. {
  2767. $CNF = &$this->_oConfig->CNF;
  2768. $sKey = $this->_oConfig->getLiveUpdateKey($aBrowseParams);
  2769. bx_import('BxDolSession');
  2770. if((int)BxDolSession::getInstance()->getValue($sKey) == 1)
  2771. return false;
  2772. $aParams = $this->_prepareParams($aBrowseParams);
  2773. $aParams = array_merge($aParams, array(
  2774. 'filter' => BX_TIMELINE_FILTER_OTHER_VIEWER
  2775. ));
  2776. $aEvents = $this->_oDb->getEvents($aParams);
  2777. if(empty($aEvents) || !is_array($aEvents))
  2778. return false;
  2779. $iValueNew = 0;
  2780. foreach($aEvents as $aEvent) {
  2781. if((int)$aEvent[$CNF['FIELD_STICKED']] != 0)
  2782. continue;
  2783. $sContent = $this->_oTemplate->getPost($aEvent, $aParams);
  2784. if(empty($sContent))
  2785. continue;
  2786. $iValueNew = $aEvent['id'];
  2787. break;
  2788. }
  2789. if($iValueNew == $iValue)
  2790. return false;
  2791. if((int)$iInit != 0)
  2792. return array('count' => $iValueNew);
  2793. return array(
  2794. 'count' => $iValueNew, // required (for initialization and visualization)
  2795. 'method' => $this->_oConfig->getJsObjectView($aBrowseParams) . '.showLiveUpdate(oData)', // required (for visualization)
  2796. 'data' => array(
  2797. 'code' => $this->_oTemplate->getLiveUpdate($aBrowseParams, $iProfileId, $iValue, $iValueNew)
  2798. ), // optional, may have some additional data to be passed in JS method provided using 'method' param above.
  2799. );
  2800. }
  2801. /**
  2802. * @page service Service Calls
  2803. * @section bx_timeline Timeline
  2804. * @subsection bx_timeline-other Other
  2805. * @subsubsection bx_timeline-get_live_updates get_live_updates
  2806. *
  2807. * @code bx_srv('bx_timeline', 'get_live_updates', [...]); @endcode
  2808. *
  2809. * Get an array with actual Live Update info. Separate live update notification for each new Event.
  2810. * Note. This method isn't used for now. @see BxTimelineModule::serviceGetLiveUpdate method instead.
  2811. *
  2812. * Note. This way to display live update notifications isn't used for now.
  2813. * See BxTimelineModule::serviceGetLiveUpdate method instead.
  2814. *
  2815. * @return an array with Live Update info.
  2816. *
  2817. * @see BxTimelineModule::serviceGetLiveUpdates
  2818. */
  2819. /**
  2820. * @ref bx_timeline-get_live_updates "get_live_updates"
  2821. */
  2822. public function serviceGetLiveUpdates($aBrowseParams, $iProfileId, $iCount = 0, $iInit = 0)
  2823. {
  2824. $sKey = $this->_oConfig->getLiveUpdateKey($aBrowseParams);
  2825. bx_import('BxDolSession');
  2826. if((int)BxDolSession::getInstance()->getValue($sKey) == 1)
  2827. return false;
  2828. $aParams = $this->_prepareParams($aBrowseParams);
  2829. $aParams['filter'] = BX_TIMELINE_FILTER_OTHER_VIEWER;
  2830. $aParams['count'] = true;
  2831. $iCountNew = $this->_oDb->getEvents($aParams);
  2832. if($iCountNew == $iCount)
  2833. return false;
  2834. if((int)$iInit != 0)
  2835. return array('count' => $iCountNew);
  2836. return array(
  2837. 'count' => $iCountNew, // required (for initialization and visualization)
  2838. 'method' => $this->_oConfig->getJsObjectView($aBrowseParams) . '.showLiveUpdates(oData)', // required (for visualization)
  2839. 'data' => array(
  2840. 'code' => $this->_oTemplate->getLiveUpdates($aBrowseParams, $iProfileId, $iCount, $iCountNew)
  2841. ), // optional, may have some additional data to be passed in JS method provided using 'method' param above.
  2842. );
  2843. }
  2844. /**
  2845. * @page service Service Calls
  2846. * @section bx_timeline Accounts
  2847. * @subsection bx_timeline-other Other
  2848. * @subsubsection bx_timeline-get_menu_addon_manage_tools get_menu_addon_manage_tools
  2849. *
  2850. * @code bx_srv('bx_timeline', 'get_menu_addon_manage_tools', [...]); @endcode
  2851. *
  2852. * Get number of 'hidden' events for User End -> Dasboard page -> Manage block.
  2853. *
  2854. * @return integer number of 'hidden' events
  2855. *
  2856. * @see BxTimelineModule::serviceGetMenuAddonManageTools
  2857. */
  2858. /**
  2859. * @ref bx_timeline-get_menu_addon_manage_tools "get_menu_addon_manage_tools"
  2860. */
  2861. public function serviceGetMenuAddonManageTools()
  2862. {
  2863. $iNum1 = $this->_oDb->getEntriesNumByParams([
  2864. [
  2865. 'key' => 'status',
  2866. 'value' => BX_TIMELINE_STATUS_HIDDEN,
  2867. 'operator' => '='
  2868. ]
  2869. ]);
  2870. $iNum2 = $this->_oDb->getEntriesNumByParams([
  2871. [
  2872. 'key' => 'reports',
  2873. 'value' => '0',
  2874. 'operator' => '>'
  2875. ]
  2876. ]);
  2877. return array(
  2878. 'counter1_value' => $iNum1,
  2879. 'counter2_value' => $iNum2,
  2880. 'counter3_value' => 0
  2881. );
  2882. }
  2883. /**
  2884. * @page service Service Calls
  2885. * @section bx_timeline Accounts
  2886. * @subsection bx_timeline-other Other
  2887. * @subsubsection bx_timeline-get_menu_addon_profile_stats get_menu_addon_profile_stats
  2888. *
  2889. * @code bx_srv('bx_timeline', 'get_menu_addon_profile_stats', [...]); @endcode
  2890. *
  2891. * Get number of 'muted' events for currently logged in user. User End -> Profile Stats.
  2892. *
  2893. * @return integer number of 'muted' events
  2894. *
  2895. * @see BxTimelineModule::serviceGetMenuAddonProfileStats
  2896. */
  2897. /**
  2898. * @ref bx_timeline-get_menu_addon_profile_stats "get_menu_addon_profile_stats"
  2899. */
  2900. public function serviceGetMenuAddonProfileStats($iProfileId = 0)
  2901. {
  2902. if(empty($iProfileId))
  2903. $iProfileId = $this->_iProfileId;
  2904. return $this->getConnectionMuteObject()->getConnectedContentCount($iProfileId);
  2905. }
  2906. public function serviceGet($aParams)
  2907. {
  2908. $aParams = $this->_prepareParams($aParams);
  2909. $aParams['return_data_type'] = 'array';
  2910. return $this->_oTemplate->getPosts($aParams);
  2911. }
  2912. public function serviceAdd($aValues)
  2913. {
  2914. return $this->getFormPost(array(
  2915. 'values' => $aValues
  2916. ));
  2917. }
  2918. public function serviceEdit($iId, $aValues)
  2919. {
  2920. return $this->getFormEdit($iId, array(
  2921. 'values' => $aValues
  2922. ));
  2923. }
  2924. /**
  2925. * Delete content entry
  2926. * @param $iContentId content id
  2927. * @return error message or empty string on success
  2928. */
  2929. public function serviceDeleteEntity ($iContentId, $sFuncDelete = 'deleteData')
  2930. {
  2931. $aEvent = $this->_oDb->getEvents(array('browse' => 'id', 'value' => $iContentId));
  2932. if(empty($aEvent) || !is_array($aEvent))
  2933. return _t('_Empty');
  2934. if(!$this->deleteEvent($aEvent))
  2935. return _t('_bx_timeline_txt_err_cannot_perform_action');
  2936. return '';
  2937. }
  2938. /*
  2939. * COMMON METHODS
  2940. */
  2941. public function getStatusAdmin()
  2942. {
  2943. return $this->isModerator() || $this->_oConfig->isAutoApproveEnabled() ? BX_TIMELINE_STATUS_ACTIVE : BX_TIMELINE_STATUS_PENDING;
  2944. }
  2945. public function getItemData($iId, $aParams = array())
  2946. {
  2947. $CNF = &$this->_oConfig->CNF;
  2948. if(empty($aParams))
  2949. $aParams = $this->_prepareParams(array(
  2950. 'view' => BX_TIMELINE_VIEW_ITEM,
  2951. 'type' => BX_TIMELINE_TYPE_ITEM
  2952. ));
  2953. $aEvent = $this->_oDb->getEvents(array('browse' => 'id', 'value' => $iId));
  2954. if(empty($aEvent))
  2955. return array('code' => 1, 'content' => _t('_Empty'));
  2956. $iProfile = (int)$aEvent[$CNF['FIELD_OWNER_ID']];
  2957. if(!empty($iProfile)) {
  2958. $oProfile = BxDolProfile::getInstance($iProfile);
  2959. if(!$oProfile)
  2960. return array('code' => 1, 'content' => _t('_Empty'));
  2961. $mixedResult = $oProfile->checkAllowedProfileView();
  2962. if($mixedResult !== CHECK_ACTION_RESULT_ALLOWED)
  2963. return array('code' => 2, 'content' => $mixedResult);
  2964. }
  2965. $sContent = $this->_oTemplate->getPost($aEvent, $aParams);
  2966. if(empty($sContent))
  2967. return array('code' => 2, 'content' => _t('_Access denied'));
  2968. $sKey = 'allowed_view';
  2969. if(isset($aEvent[$sKey]) && $aEvent[$sKey] !== CHECK_ACTION_RESULT_ALLOWED)
  2970. return array('code' => 2, 'content' => $aEvent[$sKey]);
  2971. if($this->isAllowedView($aEvent) !== true)
  2972. return array('code' => 2, 'content' => _t('_Access denied'));
  2973. return array('code' => 0, 'content' => $sContent, 'event' => $aEvent);
  2974. }
  2975. public function hideEvent($aEvent)
  2976. {
  2977. if(empty($aEvent) || !is_array($aEvent) || !$this->_oDb->updateEvent(['status' => 'hidden'], ['id' => (int)$aEvent['id']]))
  2978. return false;
  2979. $this->onHide($aEvent);
  2980. return true;
  2981. }
  2982. public function deleteEvent($aEvent)
  2983. {
  2984. if(empty($aEvent) || !is_array($aEvent) || !$this->_oDb->deleteEvent(array('id' => (int)$aEvent['id'])))
  2985. return false;
  2986. $this->onDelete($aEvent);
  2987. return true;
  2988. }
  2989. public function addAttachLink($aValues, $sDisplay = false)
  2990. {
  2991. $CNF = &$this->_oConfig->CNF;
  2992. if(!$sDisplay)
  2993. $sDisplay = $this->_oConfig->getObject('form_display_attach_link_add');
  2994. $oForm = BxDolForm::getObjectInstance($this->_oConfig->getObject('form_attach_link'), $sDisplay, $this->_oTemplate);
  2995. if(!$oForm)
  2996. return array('message' => '_sys_txt_error_occured');
  2997. $oForm->aFormAttrs['method'] = BX_DOL_FORM_METHOD_SPECIFIC;
  2998. $oForm->aParams['csrf']['disable'] = true;
  2999. if(!empty($oForm->aParams['db']['submit_name'])) {
  3000. $sSubmitName = $oForm->aParams['db']['submit_name'];
  3001. if(!isset($oForm->aInputs[$sSubmitName])) {
  3002. if(isset($oForm->aInputs[$CNF['FIELD_CONTROLS']]))
  3003. foreach($oForm->aInputs[$CNF['FIELD_CONTROLS']] as $mixedIndex => $aInput) {
  3004. if(!is_numeric($mixedIndex) || empty($aInput['name']) || $aInput['name'] != $sSubmitName)
  3005. continue;
  3006. $aValues[$sSubmitName] = $aInput['value'];
  3007. }
  3008. }
  3009. else
  3010. $aValues[$sSubmitName] = $oForm->aInputs[$sSubmitName]['value'];
  3011. }
  3012. $oForm->aInputs['url']['checker']['params']['preg'] = $this->_oConfig->getPregPattern('url');
  3013. $oForm->initChecker(array(), $aValues);
  3014. if(!$oForm->isSubmittedAndValid())
  3015. return array('message' => '_sys_txt_error_occured');
  3016. return $this->_addLink($oForm);
  3017. }
  3018. public function getFormAttachLink($iEventId = 0)
  3019. {
  3020. $oForm = BxDolForm::getObjectInstance($this->_oConfig->getObject('form_attach_link'), $this->_oConfig->getObject('form_display_attach_link_add'), $this->_oTemplate);
  3021. $oForm->aFormAttrs['action'] = BX_DOL_URL_ROOT . $this->_oConfig->getBaseUri() . 'submit_attach_link_form/';
  3022. $oForm->aInputs['event_id']['value'] = $iEventId;
  3023. $oForm->aInputs['url']['checker']['params']['preg'] = $this->_oConfig->getPregPattern('url');
  3024. $oForm->initChecker();
  3025. if($oForm->isSubmittedAndValid())
  3026. return $this->_addLink($oForm);
  3027. return array('form' => $oForm->getCode(), 'form_id' => $oForm->id);
  3028. }
  3029. public function getFormPost($aParams = [])
  3030. {
  3031. $CNF = &$this->_oConfig->CNF;
  3032. $iUserId = $this->getUserId();
  3033. $oForm = $this->getFormPostObject($aParams);
  3034. $aFormInitCheckerParams = [];
  3035. $bValues = !empty($aParams['values']) && is_array($aParams['values']);
  3036. if($bValues) {
  3037. $this->_prepareFormForAutoSubmit($oForm, $aParams['values']);
  3038. $aFormInitCheckerParams = [[], $aParams['values']];
  3039. unset($aParams['values']);
  3040. }
  3041. call_user_func_array([$oForm, 'initChecker'], $aFormInitCheckerParams);
  3042. $bAjaxMode = $oForm->isAjaxMode();
  3043. $bDynamicMode = $bAjaxMode;
  3044. if($oForm->isSubmittedAndValid()) {
  3045. $sType = $oForm->getCleanValue('type');
  3046. $sType = $this->_oConfig->getPrefix('common_post') . $sType;
  3047. BxDolForm::setSubmittedValue('type', $sType, $oForm->aFormAttrs['method']);
  3048. $aContent = [];
  3049. //--- Process Text ---//
  3050. $sText = $oForm->getCleanValue('text');
  3051. $sText = $this->_prepareTextForSave($sText);
  3052. $bText = !empty($sText);
  3053. if($bText)
  3054. $aContent['text'] = $sText;
  3055. //--- Process Context and Privacy ---//
  3056. $iOwnerId = (int)$oForm->getCleanValue('owner_id');
  3057. $iObjectPrivacyView = (int)$oForm->getCleanValue('object_privacy_view');
  3058. $iObjectPrivacyViewDefault = $this->_oConfig->getPrivacyViewDefault('object');
  3059. if(empty($iObjectPrivacyView))
  3060. $iObjectPrivacyView = $iObjectPrivacyViewDefault;
  3061. else if($iObjectPrivacyView < 0)
  3062. $iOwnerId = abs($iObjectPrivacyView);
  3063. //--- Process Link ---//
  3064. $aLinkIds = $oForm->getCleanValue($CNF['FIELD_LINK']);
  3065. $bLinkIds = !empty($aLinkIds) && is_array($aLinkIds);
  3066. //--- Process Photos ---//
  3067. $aPhotoIds = $oForm->getCleanValue($CNF['FIELD_PHOTO']);
  3068. $bPhotoIds = !empty($aPhotoIds) && is_array($aPhotoIds);
  3069. //--- Process Videos ---//
  3070. $aVideoIds = $oForm->getCleanValue($CNF['FIELD_VIDEO']);
  3071. $bVideoIds = !empty($aVideoIds) && is_array($aVideoIds);
  3072. //--- Process Files ---//
  3073. $aFileIds = $oForm->getCleanValue($CNF['FIELD_FILE']);
  3074. $bFileIds = !empty($aFileIds) && is_array($aFileIds);
  3075. if(!$bText && !$bLinkIds && !$bPhotoIds && !$bVideoIds && !$bFileIds) {
  3076. $oForm->aInputs['text']['error'] = _t('_bx_timeline_txt_err_empty_post');
  3077. $oForm->setValid(false);
  3078. if (bx_is_api()){
  3079. $mixedResult['form_object'] = $oForm;
  3080. return $mixedResult;
  3081. }
  3082. return $this->_prepareResponse([
  3083. 'form' => $oForm->getCode($bDynamicMode),
  3084. 'form_id' => $oForm->id
  3085. ], $bAjaxMode);
  3086. }
  3087. $sTitle = $bText ? $this->_oConfig->getTitle($sText) : $this->_oConfig->getTitleDefault($bLinkIds, $bPhotoIds, $bVideoIds, $bFileIds);
  3088. $sDescription = _t('_bx_timeline_txt_user_added_sample', '{profile_name}', _t('_bx_timeline_txt_sample_with_article'));
  3089. /**
  3090. * Unset 'text' input because its data was already processed
  3091. * and will be saved via additional values which were passed
  3092. * to BxDolForm::insert method.
  3093. */
  3094. unset($oForm->aInputs['text']);
  3095. $iId = $oForm->insert([
  3096. 'owner_id' => $iOwnerId,
  3097. 'object_id' => $iUserId,
  3098. 'object_owner_id' => $iUserId,
  3099. 'object_privacy_view' => $iObjectPrivacyView,
  3100. 'content' => serialize($aContent),
  3101. 'title' => $sTitle,
  3102. 'description' => $sDescription,
  3103. 'status_admin' => $this->getStatusAdmin()
  3104. ]);
  3105. if(!empty($iId)) {
  3106. $this->isAllowedPost(true);
  3107. $aContent = array_merge($aContent, [
  3108. 'timeline_group' => [
  3109. 'by' => $this->getName() . '_' . $iUserId . '_' . $iId,
  3110. 'field' => 'owner_id'
  3111. ]
  3112. ]);
  3113. $this->_oDb->updateEvent(['content' => serialize($aContent)], ['id' => $iId]);
  3114. //--- Process Meta ---//
  3115. $oMetatags = BxDolMetatags::getObjectInstance($this->_oConfig->getObject('metatags'));
  3116. if($bText)
  3117. $oMetatags->metaAdd($iId, $sText);
  3118. $oMetatags->locationsAddFromForm($iId, $this->_oConfig->CNF['FIELD_LOCATION_PREFIX']);
  3119. //--- Process Link ---//
  3120. if($bLinkIds)
  3121. foreach($aLinkIds as $iLinkId)
  3122. $this->_oDb->saveLink($iId, $iLinkId);
  3123. //--- Process Media ---//
  3124. $this->_saveMedia($CNF['FIELD_PHOTO'], $iId, $aPhotoIds, $iUserId, true);
  3125. $this->_saveMedia($CNF['FIELD_VIDEO'], $iId, $aVideoIds, $iUserId, true);
  3126. $this->_saveMedia($CNF['FIELD_FILE'], $iId, $aFileIds, $iUserId, true);
  3127. $this->onPost($iId);
  3128. if (bx_is_api()){
  3129. $mixedResult['form_object'] = $oForm;
  3130. return $mixedResult;
  3131. }
  3132. return $this->_prepareResponse(['id' => $iId], $bAjaxMode, [
  3133. 'redirect' => $this->_oConfig->getItemViewUrl(['id' => $iId])
  3134. ]);
  3135. }
  3136. return $this->_prepareResponse(['message' => _t('_bx_timeline_txt_err_cannot_perform_action')], $bAjaxMode);
  3137. }
  3138. $mixedResult = $this->_prepareResponse([
  3139. 'form' => $oForm->getCode($bDynamicMode),
  3140. 'form_id' => $oForm->id
  3141. ], $bAjaxMode && $oForm->isSubmitted());
  3142. if(is_array($mixedResult) || bx_is_api())
  3143. $mixedResult['form_object'] = $oForm;
  3144. return $mixedResult;
  3145. }
  3146. public function getFormEdit($iId, $aParams = [], $aBrowseParams = [])
  3147. {
  3148. $CNF = &$this->_oConfig->CNF;
  3149. $sJsObjectView = $this->_oConfig->getJsObjectView($aBrowseParams);
  3150. $iUserId = $this->getUserId();
  3151. $aEvent = $this->_oDb->getEvents(['browse' => 'id', 'value' => $iId]);
  3152. if(empty($aEvent) || !is_array($aEvent))
  3153. return [];
  3154. if(($mixedCheck = $this->isAllowedEdit($aEvent)) !== true)
  3155. return ['message' => $mixedCheck !== false ? $mixedCheck : _t('_sys_txt_access_denied')];
  3156. $aContent = unserialize($aEvent['content']);
  3157. if(is_array($aContent) && !empty($aContent['text']))
  3158. $aEvent['text'] = $aContent['text'];
  3159. if(empty($aParams['form_object']))
  3160. $aParams['form_object'] = 'form_post';
  3161. if(empty($aParams['form_display']))
  3162. $aParams['form_display'] = 'form_display_post_edit';
  3163. $oForm = $this->getFormPostObject($aParams);
  3164. $oForm->setId($this->_oConfig->getHtmlIds('view', 'edit_form') . $iId);
  3165. $aFormInitCheckerParams = [];
  3166. $bValues = !empty($aParams['values']) && is_array($aParams['values']);
  3167. if($bValues) {
  3168. $this->_prepareFormForAutoSubmit($oForm, $aParams['values']);
  3169. $aFormInitCheckerParams = [[], array_merge($aEvent, $aParams['values'])];
  3170. unset($aParams['values']);
  3171. }
  3172. else {
  3173. $oForm->aFormAttrs['action'] = BX_DOL_URL_ROOT . $this->_oConfig->getBaseUri() . 'edit/' . $iId ;
  3174. if(!empty($aBrowseParams) && is_array($aBrowseParams))
  3175. $oForm->aFormAttrs['action'] = $this->_oConfig->addBrowseParams($oForm->aFormAttrs['action'], $aBrowseParams);
  3176. foreach($oForm->aInputs[$CNF['FIELD_CONTROLS']] as $mixedIndex => $aInput) {
  3177. if(!is_numeric($mixedIndex))
  3178. continue;
  3179. $oForm->aInputs[$CNF['FIELD_CONTROLS']][$mixedIndex]['attrs'] = bx_replace_markers($aInput['attrs'], [
  3180. 'js_object_view' => $sJsObjectView,
  3181. 'content_id' => $iId
  3182. ]);
  3183. }
  3184. $aFormInitCheckerParams = [$aEvent];
  3185. }
  3186. call_user_func_array([$oForm, 'initChecker'], $aFormInitCheckerParams);
  3187. $bAjaxMode = $oForm->isAjaxMode();
  3188. $bDynamicMode = $bAjaxMode || bx_is_dynamic_request();
  3189. $sCodeAdd = '';
  3190. if($bDynamicMode) {
  3191. $sCodeAdd .= $this->_oTemplate->getAddedJs('post', $bDynamicMode);
  3192. $sCodeAdd .= $this->_oTemplate->getJsCode('post', [], true, $bDynamicMode);
  3193. }
  3194. if($oForm->isSubmittedAndValid()) {
  3195. $aContent = [];
  3196. //--- Process Text ---//
  3197. $sText = $oForm->getCleanValue('text');
  3198. $sText = $this->_prepareTextForSave($sText);
  3199. $bText = !empty($sText);
  3200. unset($oForm->aInputs['text']);
  3201. if($bText)
  3202. $aContent['text'] = $sText;
  3203. $aValsToAdd = [
  3204. 'content' => serialize($aContent),
  3205. 'status_admin' => $this->getStatusAdmin()
  3206. ];
  3207. //--- Process Privacy ---//
  3208. if(isset($oForm->aInputs[$CNF['FIELD_OBJECT_PRIVACY_VIEW']])) {
  3209. $iObjectPrivacyView = (int)$oForm->getCleanValue('object_privacy_view');
  3210. $iObjectPrivacyViewDefault = $this->_oConfig->getPrivacyViewDefault('object');
  3211. if(empty($iObjectPrivacyView))
  3212. $aValsToAdd = array_merge($aValsToAdd, [
  3213. 'object_privacy_view' => $iObjectPrivacyViewDefault
  3214. ]);
  3215. else if($iObjectPrivacyView < 0)
  3216. $aValsToAdd = array_merge($aValsToAdd, [
  3217. 'owner_id' => abs($iObjectPrivacyView)
  3218. ]);
  3219. }
  3220. //--- Process Link ---//
  3221. $aLinkIds = $oForm->getCleanValue($CNF['FIELD_LINK']);
  3222. $bLinkIds = !empty($aLinkIds) && is_array($aLinkIds);
  3223. //--- Process Media ---//
  3224. $aPhotoIds = $oForm->getCleanValue($CNF['FIELD_PHOTO']);
  3225. $bPhotoIds = !empty($aPhotoIds) && is_array($aPhotoIds);
  3226. $aVideoIds = $oForm->getCleanValue($CNF['FIELD_VIDEO']);
  3227. $bVideoIds = !empty($aVideoIds) && is_array($aVideoIds);
  3228. if($bVideoIds)
  3229. $aValsToAdd[$CNF['FIELD_STATUS']] = 'awaiting';
  3230. $aFileIds = $oForm->getCleanValue($CNF['FIELD_FILE']);
  3231. $bFileIds = !empty($aFileIds) && is_array($aFileIds);
  3232. if(!$bText && !$bLinkIds && !$bPhotoIds && !$bVideoIds && !$bFileIds) {
  3233. $oForm->aInputs['text']['error'] = _t('_bx_timeline_txt_err_empty_post');
  3234. $oForm->setValid(false);
  3235. return $this->_prepareResponse([
  3236. 'form' => $sCodeAdd . $oForm->getCode($bDynamicMode),
  3237. 'form_id' => $oForm->id
  3238. ], $bAjaxMode);
  3239. }
  3240. if($oForm->update($iId, $aValsToAdd) === false)
  3241. return ['message' => _t('_bx_timeline_txt_err_cannot_perform_action')];
  3242. $this->isAllowedEdit($aEvent, true);
  3243. $oMetatags = BxDolMetatags::getObjectInstance($this->_oConfig->getObject('metatags'));
  3244. if($bText)
  3245. $oMetatags->metaAdd($iId, $sText);
  3246. $oMetatags->locationsAddFromForm($iId, $this->_oConfig->CNF['FIELD_LOCATION_PREFIX']);
  3247. //--- Process Link ---//
  3248. if($bLinkIds)
  3249. foreach($aLinkIds as $iLinkId)
  3250. $this->_oDb->saveLink($iId, $iLinkId);
  3251. //--- Process Media ---//
  3252. $this->_saveMedia($CNF['FIELD_PHOTO'], $iId, $aPhotoIds, $iUserId);
  3253. $this->_saveMedia($CNF['FIELD_VIDEO'], $iId, $aVideoIds, $iUserId);
  3254. $this->_saveMedia($CNF['FIELD_FILE'], $iId, $aFileIds, $iUserId);
  3255. $this->getCacheItemObject()->removeAllByPrefix($this->_oConfig->getPrefix('cache_item') . $iId);
  3256. return [
  3257. 'id' => $iId
  3258. ];
  3259. }
  3260. return [
  3261. 'id' => $iId,
  3262. 'form' => $sCodeAdd . $oForm->getCode($bDynamicMode),
  3263. 'form_id' => $oForm->id,
  3264. 'eval' => $sJsObjectView . '.onEditPost(oData)'
  3265. ];
  3266. }
  3267. public function getFormPostObject($aParams)
  3268. {
  3269. $sFormObject = !empty($aParams['form_object']) ? $aParams['form_object'] : 'form_post';
  3270. $sFormDisplay = !empty($aParams['form_display']) ? $aParams['form_display'] : 'form_display_post_add';
  3271. $oForm = BxDolForm::getObjectInstance($this->_oConfig->getObject($sFormObject), $this->_oConfig->getObject($sFormDisplay), $this->_oTemplate);
  3272. $oForm->aFormAttrs = bx_replace_markers($oForm->aFormAttrs, [
  3273. 'js_object_post' => $this->_oConfig->getJsObject('post')
  3274. ]);
  3275. /**
  3276. * Note. 'ajax_mode' parameter isn't checked because
  3277. * timeline post form works as Ajax form by default.
  3278. */
  3279. $sParamsKey = 'visibility_autoselect';
  3280. if(isset($aParams[$sParamsKey]) && (bool)$aParams[$sParamsKey] === true)
  3281. $oForm->setVisibilityAutoselect((bool)$aParams[$sParamsKey]);
  3282. $oForm->init();
  3283. return $oForm;
  3284. }
  3285. public function getCmtsObject($sSystem, $iId)
  3286. {
  3287. if(empty($sSystem) || (int)$iId == 0)
  3288. return false;
  3289. $oCmts = BxDolCmts::getObjectInstance($sSystem, $iId, true, $this->_oTemplate);
  3290. if(!$oCmts || !$oCmts->isEnabled())
  3291. return false;
  3292. return $oCmts;
  3293. }
  3294. public function getViewObject($sSystem, $iId)
  3295. {
  3296. if(empty($sSystem) || (int)$iId == 0)
  3297. return false;
  3298. $oView = BxDolView::getObjectInstance($sSystem, $iId, true, $this->_oTemplate);
  3299. if(!$oView || !$oView->isEnabled())
  3300. return false;
  3301. return $oView;
  3302. }
  3303. public function getVoteObject($sSystem, $iId)
  3304. {
  3305. if(empty($sSystem) || (int)$iId == 0)
  3306. return false;
  3307. $oVote = BxDolVote::getObjectInstance($sSystem, $iId, true, $this->_oTemplate);
  3308. if(!$oVote || !$oVote->isEnabled())
  3309. return false;
  3310. return $oVote;
  3311. }
  3312. public function getReactionObject($sSystem, $iId)
  3313. {
  3314. if(empty($sSystem) || (int)$iId == 0)
  3315. return false;
  3316. $oReaction = BxDolVote::getObjectInstance($sSystem, $iId, true, $this->_oTemplate);
  3317. if(!$oReaction || !$oReaction->isEnabled())
  3318. return false;
  3319. return $oReaction;
  3320. }
  3321. public function getScoreObject($sSystem, $iId)
  3322. {
  3323. if(empty($sSystem) || (int)$iId == 0)
  3324. return false;
  3325. $oScore = BxDolScore::getObjectInstance($sSystem, $iId, true, $this->_oTemplate);
  3326. if(!$oScore || !$oScore->isEnabled())
  3327. return false;
  3328. return $oScore;
  3329. }
  3330. public function getReportObject($sSystem, $iId)
  3331. {
  3332. if(empty($sSystem) || (int)$iId == 0)
  3333. return false;
  3334. $oReport = BxDolReport::getObjectInstance($sSystem, $iId, true, $this->_oTemplate);
  3335. if(!$oReport || !$oReport->isEnabled())
  3336. return false;
  3337. return $oReport;
  3338. }
  3339. public function getAttachmentsMenuObject()
  3340. {
  3341. return BxDolMenu::getObjectInstance($this->_oConfig->getObject('menu_post_attachments'), $this->_oTemplate);
  3342. }
  3343. public function getManageMenuObject()
  3344. {
  3345. return BxDolMenu::getObjectInstance($this->_oConfig->getObject('menu_item_manage'), $this->_oTemplate);
  3346. }
  3347. public function getCacheItemObject()
  3348. {
  3349. $oCacheEngine = bx_instance('BxDolCache' . $this->_oConfig->getCacheItemEngine());
  3350. if(!$oCacheEngine->isAvailable())
  3351. $oCacheEngine = bx_instance('BxDolCacheFile');
  3352. return $oCacheEngine;
  3353. }
  3354. public function getConnectionMuteObject()
  3355. {
  3356. return BxDolConnection::getObjectInstance($this->_oConfig->getObject('connection_mute'));
  3357. }
  3358. //--- Check permissions methods ---//
  3359. public function serviceCheckAllowedViewForProfile ($aDataEntry, $isPerformAction = false, $iProfileId = false)
  3360. {
  3361. if(!$iProfileId)
  3362. $iProfileId = $this->_iProfileId;
  3363. $CNF = &$this->_oConfig->CNF;
  3364. // moderator and owner always have access
  3365. $iOwnerId = (int)$aDataEntry['owner_id'];
  3366. if(!empty($iProfileId) && (abs($iOwnerId) == (int)$iProfileId || $this->isModerator()))
  3367. return CHECK_ACTION_RESULT_ALLOWED;
  3368. // check ACL
  3369. if($iOwnerId != 0 && ($oOwner = BxDolProfile::getInstanceMagic($iOwnerId)) !== false && !($oOwner instanceof BxDolProfileUndefined)) {
  3370. $mixedCheckResult = bx_srv($oOwner->getModule(), 'check_allowed_with_content_for_profile', ['view', $oOwner->getContentId(), $iProfileId]);
  3371. if($mixedCheckResult !== CHECK_ACTION_RESULT_ALLOWED)
  3372. return $mixedCheckResult;
  3373. }
  3374. // check privacy
  3375. if(!empty($CNF['OBJECT_PRIVACY_VIEW'])) {
  3376. $oPrivacy = BxDolPrivacy::getObjectInstance($CNF['OBJECT_PRIVACY_VIEW']);
  3377. if($oPrivacy && !$oPrivacy->check($aDataEntry[$CNF['FIELD_ID']], $iProfileId))
  3378. return _t('_sys_access_denied_to_private_content');
  3379. }
  3380. // check alert to allow custom checks
  3381. $mixedResult = null;
  3382. bx_alert('system', 'check_allowed_view', 0, 0, array('module' => $this->getName(), 'content_info' => $aDataEntry, 'profile_id' => $iProfileId, 'override_result' => &$mixedResult));
  3383. if($mixedResult !== null)
  3384. return $mixedResult;
  3385. return CHECK_ACTION_RESULT_ALLOWED;
  3386. }
  3387. public function isModerator()
  3388. {
  3389. return $this->isModeratorForProfile((int)$this->getUserId());
  3390. }
  3391. public function isModeratorForProfile($iUserId)
  3392. {
  3393. if($this->checkAllowedEditAnyEntryForProfile(false, $iUserId) === CHECK_ACTION_RESULT_ALLOWED)
  3394. return true;
  3395. if($this->checkAllowedDeleteAnyEntryForProfile(false, $iUserId) === CHECK_ACTION_RESULT_ALLOWED)
  3396. return true;
  3397. return false;
  3398. }
  3399. public function isAllowedPost($bPerform = false)
  3400. {
  3401. if(isAdmin())
  3402. return true;
  3403. $iUserId = $this->getUserId();
  3404. $aCheckResult = checkActionModule($iUserId, 'post', $this->getName(), $bPerform);
  3405. if($aCheckResult[CHECK_ACTION_RESULT] !== CHECK_ACTION_RESULT_ALLOWED)
  3406. return $aCheckResult[CHECK_ACTION_MESSAGE];
  3407. if(!empty($this->_iOwnerId) && ($oProfileOwner = BxDolProfile::getInstance($this->_iOwnerId)) !== false) {
  3408. if($oProfileOwner->checkAllowedPostInProfile($this->_iOwnerId, $this->getName()) !== CHECK_ACTION_RESULT_ALLOWED)
  3409. return _t('_sys_txt_access_denied');
  3410. bx_alert($oProfileOwner->getModule(), $this->_oConfig->getUri() . '_post', $oProfileOwner->id(), $iUserId, array('check_result' => &$aCheckResult));
  3411. }
  3412. return $aCheckResult[CHECK_ACTION_RESULT] !== CHECK_ACTION_RESULT_ALLOWED ? $aCheckResult[CHECK_ACTION_MESSAGE] : true;
  3413. }
  3414. public function isAllowedView($aEvent, $bPerform = false)
  3415. {
  3416. $CNF = $this->_oConfig->CNF;
  3417. if((int)$aEvent[$CNF['FIELD_OWNER_ID']] == 0)
  3418. return true;
  3419. $oProfileOwner = BxDolProfile::getInstance($aEvent[$CNF['FIELD_OWNER_ID']]);
  3420. if($oProfileOwner && $oProfileOwner->checkAllowedProfileView() !== CHECK_ACTION_RESULT_ALLOWED)
  3421. return false;
  3422. $oPrivacy = BxDolPrivacy::getObjectInstance($this->_oConfig->getObject('privacy_view'));
  3423. if(!$oPrivacy)
  3424. return true;
  3425. $oPrivacy->setTableFieldAuthor($this->_oConfig->isSystem($aEvent['type'], $aEvent['action']) ? 'owner_id' : 'object_id');
  3426. return $oPrivacy->check($aEvent[$CNF['FIELD_ID']]);
  3427. }
  3428. public function isAllowedEdit($aEvent, $bPerform = false)
  3429. {
  3430. if(!isLogged())
  3431. return false;
  3432. //--- System posts and Reposts cannot be edited at all.
  3433. if(!$this->_oConfig->isCommon($aEvent['type'], $aEvent['action']) || $aEvent['type'] == $this->_oConfig->getPrefix('common_post') . 'repost')
  3434. return false;
  3435. if(isAdmin())
  3436. return true;
  3437. $iUserId = (int)$this->getUserId();
  3438. $iOwnerId = (int)$aEvent['owner_id'];
  3439. $iObjectId = abs((int)$aEvent['object_id']);
  3440. if($iObjectId == $iUserId && $this->_oConfig->isAllowEdit())
  3441. return true;
  3442. $aCheckResult = checkActionModule($iUserId, 'edit', $this->getName(), $bPerform);
  3443. if(!empty($iOwnerId) && ($oProfileOwner = BxDolProfile::getInstance($iOwnerId)) !== false) {
  3444. if(BxDolService::call($oProfileOwner->getModule(), 'check_allowed_module_action_in_profile', array($oProfileOwner->getContentId(), $this->getName(), 'edit_any')) === CHECK_ACTION_RESULT_ALLOWED)
  3445. return true;
  3446. bx_alert($oProfileOwner->getModule(), $this->_oConfig->getUri() . '_edit', $oProfileOwner->id(), $iUserId, array('check_result' => &$aCheckResult));
  3447. }
  3448. return $aCheckResult[CHECK_ACTION_RESULT] !== CHECK_ACTION_RESULT_ALLOWED ? $aCheckResult[CHECK_ACTION_MESSAGE] : true;
  3449. }
  3450. public function isAllowedDelete($aEvent, $bPerform = false)
  3451. {
  3452. if(!isLogged())
  3453. return false;
  3454. if(isAdmin())
  3455. return true;
  3456. $iUserId = (int)$this->getUserId();
  3457. $iOwnerId = (int)$aEvent['owner_id'];
  3458. $iObjectId = abs((int)$aEvent['object_id']);
  3459. if((($iOwnerId == $iUserId && $this->_oConfig->isAllowDelete()) || ($this->_oConfig->isCommon($aEvent['type'], $aEvent['action']) && $iObjectId == $iUserId)))
  3460. return true;
  3461. $aCheckResult = checkActionModule($iUserId, 'delete', $this->getName(), $bPerform);
  3462. if(!empty($iOwnerId) && ($oProfileOwner = BxDolProfile::getInstance($iOwnerId)) !== false) {
  3463. if(BxDolService::call($oProfileOwner->getModule(), 'check_allowed_module_action_in_profile', array($oProfileOwner->getContentId(), $this->getName(), 'delete_any')) === CHECK_ACTION_RESULT_ALLOWED)
  3464. return true;
  3465. bx_alert($oProfileOwner->getModule(), $this->_oConfig->getUri() . '_delete', $oProfileOwner->id(), $iUserId, array('check_result' => &$aCheckResult));
  3466. }
  3467. return $aCheckResult[CHECK_ACTION_RESULT] !== CHECK_ACTION_RESULT_ALLOWED ? $aCheckResult[CHECK_ACTION_MESSAGE] : true;
  3468. }
  3469. public function isAllowedComment($aEvent, $bPerform = false)
  3470. {
  3471. $mixedComments = $this->getCommentsData($aEvent['comments']);
  3472. if($mixedComments === false)
  3473. return false;
  3474. list($sSystem, $iObjectId, $iCount) = $mixedComments;
  3475. $oCmts = $this->getCmtsObject($sSystem, $iObjectId);
  3476. if($oCmts->isViewAllowed() !== CHECK_ACTION_RESULT_ALLOWED || ($iCount == 0 && !$oCmts->isPostAllowed()))
  3477. return false;
  3478. $oCmts->addCssJs();
  3479. return true;
  3480. }
  3481. public function isAllowedViewCounter($aEvent, $bPerform = false)
  3482. {
  3483. $mixedViews = $this->getViewsData($aEvent['views']);
  3484. if($mixedViews === false)
  3485. return false;
  3486. list($sSystem, $iObjectId) = $mixedViews;
  3487. $oView = $this->getViewObject($sSystem, $iObjectId);
  3488. if(!$oView->isAllowedViewView($bPerform))
  3489. return false;
  3490. $bResult = true;
  3491. if(!empty($aEvent['owner_id']) && ($oProfileOwner = BxDolProfile::getInstance($aEvent['owner_id'])) !== false)
  3492. bx_alert($oProfileOwner->getModule(), $this->_oConfig->getUri() . '_view_counter', $oProfileOwner->id(), (int)$this->getUserId(), array('result' => &$bResult));
  3493. return $bResult;
  3494. }
  3495. public function isAllowedVote($aEvent, $bPerform = false)
  3496. {
  3497. $mixedVotes = $this->getVotesData($aEvent['votes']);
  3498. if($mixedVotes === false)
  3499. return false;
  3500. list($sSystem, $iObjectId) = $mixedVotes;
  3501. $oVote = $this->getVoteObject($sSystem, $iObjectId);
  3502. if(!$oVote->isAllowedVote($bPerform))
  3503. return false;
  3504. $bResult = true;
  3505. if(!empty($aEvent['owner_id']) && ($oProfileOwner = BxDolProfile::getInstance($aEvent['owner_id'])) !== false)
  3506. bx_alert($oProfileOwner->getModule(), $this->_oConfig->getUri() . '_vote', $oProfileOwner->id(), (int)$this->getUserId(), array('result' => &$bResult));
  3507. return $bResult;
  3508. }
  3509. public function isAllowedVoteView($aEvent, $bPerform = false)
  3510. {
  3511. $mixedVotes = $this->getVotesData($aEvent['votes']);
  3512. if($mixedVotes === false)
  3513. return false;
  3514. list($sSystem, $iObjectId) = $mixedVotes;
  3515. $oVote = $this->getVoteObject($sSystem, $iObjectId);
  3516. if(!$oVote->isAllowedVoteView($bPerform))
  3517. return false;
  3518. $bResult = true;
  3519. if(!empty($aEvent['owner_id']) && ($oProfileOwner = BxDolProfile::getInstance($aEvent['owner_id'])) !== false)
  3520. bx_alert($oProfileOwner->getModule(), $this->_oConfig->getUri() . '_vote_view', $oProfileOwner->id(), (int)$this->getUserId(), array('result' => &$bResult));
  3521. return $bResult;
  3522. }
  3523. public function isAllowedReaction($aEvent, $bPerform = false)
  3524. {
  3525. $mixedReactions = $this->getReactionsData($aEvent['reactions']);
  3526. if($mixedReactions === false)
  3527. return false;
  3528. list($sSystem, $iObjectId) = $mixedReactions;
  3529. $oReaction = $this->getReactionObject($sSystem, $iObjectId);
  3530. if(!$oReaction->isAllowedVote($bPerform))
  3531. return false;
  3532. $bResult = true;
  3533. if(!empty($aEvent['owner_id']) && ($oProfileOwner = BxDolProfile::getInstance($aEvent['owner_id'])) !== false)
  3534. bx_alert($oProfileOwner->getModule(), $this->_oConfig->getUri() . '_reaction', $oProfileOwner->id(), (int)$this->getUserId(), array('result' => &$bResult));
  3535. return $bResult;
  3536. }
  3537. public function isAllowedReactionView($aEvent, $bPerform = false)
  3538. {
  3539. $mixedReactions = $this->getReactionsData($aEvent['reactions']);
  3540. if($mixedReactions === false)
  3541. return false;
  3542. list($sSystem, $iObjectId) = $mixedReactions;
  3543. $oReaction = $this->getReactionObject($sSystem, $iObjectId);
  3544. if(!$oReaction->isAllowedVoteView($bPerform))
  3545. return false;
  3546. $bResult = true;
  3547. if(!empty($aEvent['owner_id']) && ($oProfileOwner = BxDolProfile::getInstance($aEvent['owner_id'])) !== false)
  3548. bx_alert($oProfileOwner->getModule(), $this->_oConfig->getUri() . '_reaction_view', $oProfileOwner->id(), (int)$this->getUserId(), array('result' => &$bResult));
  3549. return $bResult;
  3550. }
  3551. public function isAllowedScore($aEvent, $bPerform = false)
  3552. {
  3553. $mixedScores = $this->getScoresData($aEvent['scores']);
  3554. if($mixedScores === false)
  3555. return false;
  3556. list($sSystem, $iObjectId) = $mixedScores;
  3557. $oScore = $this->getScoreObject($sSystem, $iObjectId);
  3558. if(!$oScore->isAllowedVote($bPerform))
  3559. return false;
  3560. $bResult = true;
  3561. if(!empty($aEvent['owner_id']) && ($oProfileOwner = BxDolProfile::getInstance($aEvent['owner_id'])) !== false)
  3562. bx_alert($oProfileOwner->getModule(), $this->_oConfig->getUri() . '_score', $oProfileOwner->id(), (int)$this->getUserId(), array('result' => &$bResult));
  3563. return $bResult;
  3564. }
  3565. public function isAllowedReport($aEvent, $bPerform = false)
  3566. {
  3567. $mixedReports = $this->getReportsData($aEvent['reports']);
  3568. if($mixedReports === false)
  3569. return false;
  3570. list($sSystem, $iObjectId) = $mixedReports;
  3571. $oReport = $this->getReportObject($sSystem, $iObjectId);
  3572. if(!$oReport->isAllowedReport($bPerform))
  3573. return false;
  3574. $bResult = true;
  3575. if(!empty($aEvent['owner_id']) && ($oProfileOwner = BxDolProfile::getInstance($aEvent['owner_id'])) !== false)
  3576. bx_alert($oProfileOwner->getModule(), $this->_oConfig->getUri() . '_report', $oProfileOwner->id(), (int)$this->getUserId(), array('result' => &$bResult));
  3577. return $bResult;
  3578. }
  3579. public function isAllowedRepost($aEvent, $bPerform = false)
  3580. {
  3581. $mixedResult = $this->_isAllowedRepost($aEvent, $bPerform);
  3582. bx_alert($this->getName(), 'is_allowed_repost', 0, 0, [
  3583. 'content_info' => $aEvent,
  3584. 'override_result' => &$mixedResult
  3585. ]);
  3586. return $mixedResult;
  3587. }
  3588. public function isAllowedSend($aEvent, $bPerform = false)
  3589. {
  3590. if(!$this->_oDb->isEnabledByName('bx_convos'))
  3591. return false;
  3592. if(isAdmin())
  3593. return true;
  3594. $iUserId = (int)$this->getUserId();
  3595. if($iUserId == 0)
  3596. return false;
  3597. $aCheckResult = checkActionModule($iUserId, 'send', $this->getName(), $bPerform);
  3598. if(!empty($aEvent['owner_id']) && ($oProfileOwner = BxDolProfile::getInstance($aEvent['owner_id'])) !== false)
  3599. bx_alert($oProfileOwner->getModule(), $this->_oConfig->getUri() . '_send', $oProfileOwner->id(), $iUserId, array('check_result' => &$aCheckResult));
  3600. return $aCheckResult[CHECK_ACTION_RESULT] !== CHECK_ACTION_RESULT_ALLOWED ? $aCheckResult[CHECK_ACTION_MESSAGE] : true;
  3601. }
  3602. public function isAllowedMute($aEvent, $bPerform = false)
  3603. {
  3604. $CNF = &$this->_oConfig->CNF;
  3605. if(!empty($aEvent[$CNF['FIELD_OWNER_ID']]) && $aEvent[$CNF['FIELD_OWNER_ID']] != $this->_iProfileId)
  3606. return false;
  3607. $iAuthor = (int)$aEvent[$CNF['FIELD_OWNER_ID']];
  3608. if(!$this->_oConfig->isSystem($aEvent['type'], $aEvent['action']))
  3609. $iAuthor = (int)$aEvent[$CNF['FIELD_OBJECT_ID']];
  3610. if($this->_iProfileId == $iAuthor || $this->getConnectionMuteObject()->isConnected($this->_iProfileId, $iAuthor))
  3611. return false;
  3612. return $this->_isAllowedMute($bPerform);
  3613. }
  3614. public function isAllowedUnmute($iAuthor, $bPerform = false)
  3615. {
  3616. if(!$this->getConnectionMuteObject()->isConnected($this->_iProfileId, $iAuthor))
  3617. return false;
  3618. return $this->_isAllowedMute($bPerform);
  3619. }
  3620. /**
  3621. * Pin - "Pin here" - pin the post on Profile Timeline for profile owner.
  3622. * Can be done by profile owner for himself or by admin for profile owner to see.
  3623. * @param type $aEvent
  3624. * @param type $bPerform
  3625. * @return boolean
  3626. */
  3627. public function isAllowedPin($aEvent, $bPerform = false)
  3628. {
  3629. if((int)$aEvent['pinned'] != 0)
  3630. return false;
  3631. return $this->_isAllowedPin($aEvent, $bPerform);
  3632. }
  3633. public function isAllowedUnpin($aEvent, $bPerform = false)
  3634. {
  3635. if((int)$aEvent['pinned'] == 0)
  3636. return false;
  3637. return $this->_isAllowedPin($aEvent, $bPerform);
  3638. }
  3639. /**
  3640. * Stick - "Pin for All" - pin the post on Public Timeline for everybody to see.
  3641. * Is available for Administrators/Moderators only.
  3642. * @param type $aEvent
  3643. * @param type $bPerform
  3644. * @return boolean
  3645. */
  3646. public function isAllowedStick($aEvent, $bPerform = false)
  3647. {
  3648. if((int)$aEvent['sticked'] != 0)
  3649. return false;
  3650. return $this->_isAllowedStick($aEvent, $bPerform);
  3651. }
  3652. public function isAllowedUnstick($aEvent, $bPerform = false)
  3653. {
  3654. if((int)$aEvent['sticked'] == 0)
  3655. return false;
  3656. return $this->_isAllowedStick($aEvent, $bPerform);
  3657. }
  3658. public function isAllowedPromote($aEvent, $bPerform = false)
  3659. {
  3660. if((int)$aEvent['promoted'] != 0)
  3661. return false;
  3662. return $this->_isAllowedPromote($aEvent, $bPerform);
  3663. }
  3664. public function isAllowedUnpromote($aEvent, $bPerform = false)
  3665. {
  3666. if((int)$aEvent['promoted'] == 0)
  3667. return false;
  3668. return $this->_isAllowedPromote($aEvent, $bPerform);
  3669. }
  3670. public function isAllowedNotes($aEvent, $bPerform = false)
  3671. {
  3672. return $this->isModerator();
  3673. }
  3674. public function isAllowedMore($aEvent, $bPerform = false)
  3675. {
  3676. $oMoreMenu = $this->getManageMenuObject();
  3677. if(!$oMoreMenu)
  3678. return false;
  3679. $oMoreMenu->setEvent($aEvent);
  3680. return $oMoreMenu->isVisible();
  3681. }
  3682. public function checkAllowedView ($aContentInfo, $isPerformAction = false)
  3683. {
  3684. if(!$this->isAllowedView($aContentInfo, $isPerformAction))
  3685. return _t('_sys_txt_access_denied');
  3686. return CHECK_ACTION_RESULT_ALLOWED;
  3687. }
  3688. public function checkAllowedDelete (&$aDataEntry, $isPerformAction = false)
  3689. {
  3690. if(($mixedResult = $this->isAllowedDelete($aDataEntry, $isPerformAction)) !== true)
  3691. return is_string($mixedResult) ? $mixedResult : _t('_sys_txt_access_denied');
  3692. return CHECK_ACTION_RESULT_ALLOWED;
  3693. }
  3694. /**
  3695. * Checks if it's allowed to view a comment by checking the availability to view the content which was commented.
  3696. * Note. Don't check the related comments object for view action accessibility because this method is called from there.
  3697. */
  3698. public function checkAllowedCommentsView ($aContentInfo, $isPerformAction = false)
  3699. {
  3700. $CNF = $this->_oConfig->CNF;
  3701. $iOwner = (int)$aContentInfo[$CNF['FIELD_OWNER_ID']];
  3702. if($iOwner == 0) //--- in case of Public Timeline.
  3703. return CHECK_ACTION_RESULT_ALLOWED;
  3704. $oOwner = BxDolProfile::getInstance($iOwner);
  3705. if(!$oOwner) //--- in case of non-existed Timeline owner.
  3706. return _t('_sys_txt_access_denied');
  3707. $mixedResult = $oOwner->checkAllowedProfileView();
  3708. if($mixedResult !== CHECK_ACTION_RESULT_ALLOWED)
  3709. return $mixedResult;
  3710. return $this->checkAllowedView($aContentInfo, $isPerformAction);
  3711. }
  3712. /**
  3713. * Checks if it's allowed to post a comment by checking the availability to post anything in the context.
  3714. * Note. Don't check the related comments object for post action accessibility because this method is called from there.
  3715. */
  3716. public function checkAllowedCommentsPost ($aContentInfo, $isPerformAction = false)
  3717. {
  3718. $CNF = $this->_oConfig->CNF;
  3719. $iOwner = (int)$aContentInfo[$CNF['FIELD_OWNER_ID']];
  3720. if($iOwner == 0) //--- in case of Public Timeline.
  3721. return CHECK_ACTION_RESULT_ALLOWED;
  3722. $oOwner = BxDolProfile::getInstance($iOwner);
  3723. if(!$oOwner) //--- in case of non-existed Timeline owner.
  3724. return _t('_sys_txt_access_denied');
  3725. /*
  3726. * Disabled in accordance with #4238 ticket.
  3727. *
  3728. if(($mixedResult = $oOwner->checkAllowedPostInProfile()) !== CHECK_ACTION_RESULT_ALLOWED)
  3729. return $mixedResult;
  3730. */
  3731. return CHECK_ACTION_RESULT_ALLOWED;
  3732. }
  3733. public function checkAllowedEditAnyEntryForProfile ($isPerformAction = false, $iProfileId = false)
  3734. {
  3735. if(!$iProfileId)
  3736. $iProfileId = $this->_iProfileId;
  3737. $aCheck = checkActionModule($iProfileId, 'edit', $this->getName(), $isPerformAction);
  3738. if($aCheck[CHECK_ACTION_RESULT] === CHECK_ACTION_RESULT_ALLOWED)
  3739. return CHECK_ACTION_RESULT_ALLOWED;
  3740. return _t('_sys_txt_access_denied');
  3741. }
  3742. public function checkAllowedDeleteAnyEntryForProfile ($isPerformAction = false, $iProfileId = false)
  3743. {
  3744. if(!$iProfileId)
  3745. $iProfileId = $this->_iProfileId;
  3746. $aCheck = checkActionModule($iProfileId, 'delete', $this->getName(), $isPerformAction);
  3747. if($aCheck[CHECK_ACTION_RESULT] === CHECK_ACTION_RESULT_ALLOWED)
  3748. return CHECK_ACTION_RESULT_ALLOWED;
  3749. return _t('_sys_txt_access_denied');
  3750. }
  3751. public function onPost($iContentId)
  3752. {
  3753. $CNF = &$this->_oConfig->CNF;
  3754. $aEvent = $this->_oDb->getEvents(array('browse' => 'id', 'value' => $iContentId));
  3755. if($this->_oConfig->isSystem($aEvent['type'], $aEvent['action'])) {
  3756. //--- Request event's data from content module and update it in the Timeline DB.
  3757. $this->_oTemplate->getDataCached($aEvent);
  3758. $sPostType = 'system';
  3759. $iSenderId = $iObjectAuthorId = (int)$aEvent['owner_id'];
  3760. }
  3761. else {
  3762. $sPostType = 'common';
  3763. $iSenderId = $iObjectAuthorId = (int)$aEvent['object_id'];
  3764. }
  3765. //--- Event -> Post/Defer for Alerts Engine ---//
  3766. $sAction = ($aEvent[$CNF['FIELD_STATUS']] == BX_TIMELINE_STATUS_AWAITING ? 'defer' : 'post') . '_' . $sPostType;
  3767. bx_alert($this->_oConfig->getObject('alert'), $sAction, $iContentId, $iSenderId, array(
  3768. 'source' => $this->_oConfig->getName() . '_' . $iContentId,
  3769. 'owner_id' => $aEvent['owner_id'],
  3770. 'object_author_id' => $iObjectAuthorId,
  3771. 'privacy_view' => $aEvent['object_privacy_view'],
  3772. ));
  3773. //--- Event -> Post for Alerts Engine ---//
  3774. }
  3775. public function onPublished($iContentId)
  3776. {
  3777. //--- Clear Item cache
  3778. $this->getCacheItemObject()->removeAllByPrefix($this->_oConfig->getPrefix('cache_item') . $iContentId);
  3779. $this->onPost($iContentId);
  3780. }
  3781. public function onFailed($iContentId)
  3782. {
  3783. $aEvent = $this->_oDb->getEvents(array('browse' => 'id', 'value' => $iContentId));
  3784. //--- Clear Item cache
  3785. $this->getCacheItemObject()->removeAllByPrefix($this->_oConfig->getPrefix('cache_item') . $iContentId);
  3786. if($this->_oConfig->isSystem($aEvent['type'], $aEvent['action'])) {
  3787. //--- Request event's data from content module and update it in the Timeline DB.
  3788. $this->_oTemplate->getDataCached($aEvent);
  3789. $sPostType = 'system';
  3790. $iSenderId = $iObjectAuthorId = (int)$aEvent['owner_id'];
  3791. }
  3792. else {
  3793. $sPostType = 'common';
  3794. $iSenderId = $iObjectAuthorId = (int)$aEvent['object_id'];
  3795. }
  3796. //--- Event -> Fail for Alerts Engine ---//
  3797. bx_alert($this->_oConfig->getObject('alert'), 'fail_' . $sPostType, $iContentId, $iSenderId, array(
  3798. 'owner_id' => $aEvent['owner_id'],
  3799. 'object_author_id' => $iObjectAuthorId,
  3800. 'privacy_view' => $aEvent['object_privacy_view'],
  3801. ));
  3802. //--- Event -> Post for Alerts Engine ---//
  3803. }
  3804. public function onRepost($iContentId, $aReposted = array())
  3805. {
  3806. $CNF = &$this->_oConfig->CNF;
  3807. $aEvent = $this->_oDb->getEvents(array('browse' => 'id', 'value' => $iContentId));
  3808. if(empty($aReposted)) {
  3809. $aContent = unserialize($aEvent['content']);
  3810. $aReposted = $this->_oDb->getReposted($aContent['type'], $aContent['action'], $aContent['object_id']);
  3811. if(empty($aReposted) || !is_array($aReposted))
  3812. return;
  3813. }
  3814. $iUserId = (int)$aEvent[$CNF['FIELD_OBJECT_OWNER_ID']];
  3815. $this->_oDb->insertRepostTrack($aEvent['id'], $iUserId, $this->getUserIp(), $aReposted['id']);
  3816. $this->_oDb->updateRepostCounter($aReposted['id'], $aReposted['reposts']);
  3817. //--- Timeline -> Update for Alerts Engine ---//
  3818. bx_alert($this->_oConfig->getObject('alert'), 'repost', $aReposted['id'], $iUserId, array(
  3819. 'privacy_view' => $aEvent['object_privacy_view'],
  3820. 'object_author_id' => $aReposted['owner_id'],
  3821. 'repost_id' => $iContentId,
  3822. ));
  3823. //--- Timeline -> Update for Alerts Engine ---//
  3824. }
  3825. public function onHide($aEvent)
  3826. {
  3827. $CNF = &$this->_oConfig->CNF;
  3828. $iUserId = $this->getUserId();
  3829. $sCommonPostPrefix = $this->_oConfig->getPrefix('common_post');
  3830. //--- Update parent event when repost event was deactivated.
  3831. $bRepost = $aEvent['type'] == $sCommonPostPrefix . BX_TIMELINE_PARSE_TYPE_REPOST;
  3832. if($bRepost) {
  3833. $this->_oDb->updateRepostTrack(['active' => 0], ['event_id' => $aEvent[$CNF['FIELD_ID']]]);
  3834. $aContent = unserialize($aEvent['content']);
  3835. $aReposted = $this->_oDb->getReposted($aContent['type'], $aContent['action'], $aContent['object_id']);
  3836. if(!empty($aReposted) && is_array($aReposted))
  3837. $this->_oDb->updateRepostCounter($aReposted[$CNF['FIELD_ID']], $aReposted['reposts'], -1);
  3838. }
  3839. //--- Find and hide repost events when parent event was deactivated.
  3840. $aRepostEvents = $this->_oDb->getEvents(['browse' => 'reposted_by_track', 'value' => $aEvent[$CNF['FIELD_ID']]]);
  3841. foreach($aRepostEvents as $aRepostEvent) {
  3842. if((int)$this->_oDb->updateEvent(['active' => 0], ['id' => (int)$aRepostEvent[$CNF['FIELD_ID']]]) == 0)
  3843. continue;
  3844. $this->_oDb->updateRepostTrack(['active' => 0], ['event_id' => $aRepostEvent[$CNF['FIELD_ID']]]);
  3845. bx_alert($this->_oConfig->getObject('alert'), 'hide_repost', $aEvent[$CNF['FIELD_ID']], $iUserId, array(
  3846. 'repost_id' => $aRepostEvent[$CNF['FIELD_ID']],
  3847. ));
  3848. }
  3849. //--- Delete associated meta for Common events.
  3850. if($this->_oConfig->isCommon($aEvent['type'], $aEvent['action'])) {
  3851. $oMetatags = BxDolMetatags::getObjectInstance($this->_oConfig->getObject('metatags'));
  3852. $oMetatags->onDeleteContent($aEvent[$CNF['FIELD_ID']]);
  3853. }
  3854. //--- Delete item cache.
  3855. $sCacheItemKey = $this->_oConfig->getCacheItemKey($aEvent[$CNF['FIELD_ID']]);
  3856. $this->getCacheItemObject()->delData($sCacheItemKey);
  3857. //--- Event -> Hide for Alerts Engine ---//
  3858. if($bRepost)
  3859. bx_alert($this->_oConfig->getObject('alert'), 'hide_repost', $aReposted[$CNF['FIELD_ID']], $iUserId, array(
  3860. 'repost_id' => $aEvent[$CNF['FIELD_ID']],
  3861. ));
  3862. else
  3863. bx_alert($this->_oConfig->getObject('alert'), 'hide', $aEvent[$CNF['FIELD_ID']], $iUserId);
  3864. //--- Event -> Hide for Alerts Engine ---//
  3865. }
  3866. public function onUnhide($aEvent)
  3867. {
  3868. $CNF = &$this->_oConfig->CNF;
  3869. $iUserId = $this->getUserId();
  3870. $sCommonPostPrefix = $this->_oConfig->getPrefix('common_post');
  3871. //--- Update parent event when repost event was activated back.
  3872. $bRepost = $aEvent['type'] == $sCommonPostPrefix . BX_TIMELINE_PARSE_TYPE_REPOST;
  3873. if($bRepost) {
  3874. $this->_oDb->updateRepostTrack(['active' => 1], ['event_id' => $aEvent[$CNF['FIELD_ID']]]);
  3875. $aContent = unserialize($aEvent['content']);
  3876. $aReposted = $this->_oDb->getReposted($aContent['type'], $aContent['action'], $aContent['object_id']);
  3877. if(!empty($aReposted) && is_array($aReposted))
  3878. $this->_oDb->updateRepostCounter($aReposted[$CNF['FIELD_ID']], $aReposted['reposts'], 1);
  3879. }
  3880. //--- Find and hide repost events when parent event was activated back.
  3881. $aRepostEvents = $this->_oDb->getEvents(['browse' => 'reposted_by_track', 'value' => $aEvent[$CNF['FIELD_ID']]]);
  3882. foreach($aRepostEvents as $aRepostEvent) {
  3883. if((int)$this->_oDb->updateEvent(['active' => 1], ['id' => (int)$aRepostEvent[$CNF['FIELD_ID']]]) == 0)
  3884. continue;
  3885. $this->_oDb->updateRepostTrack(['active' => 1], ['event_id' => $aRepostEvent[$CNF['FIELD_ID']]]);
  3886. bx_alert($this->_oConfig->getObject('alert'), 'unhide_repost', $aEvent[$CNF['FIELD_ID']], $iUserId, array(
  3887. 'repost_id' => $aRepostEvent[$CNF['FIELD_ID']],
  3888. ));
  3889. }
  3890. //--- Process meta for Common events.
  3891. if($this->_oConfig->isCommon($aEvent['type'], $aEvent['action'])) {
  3892. $aContent = unserialize($aEvent['content']);
  3893. $oMetatags = BxDolMetatags::getObjectInstance($this->_oConfig->getObject('metatags'));
  3894. if(!empty($aContent['text']))
  3895. $oMetatags->metaAdd($aEvent[$CNF['FIELD_ID']], $aContent['text']);
  3896. $oMetatags->locationsAddFromForm($aEvent[$CNF['FIELD_ID']], $CNF['FIELD_LOCATION_PREFIX']);
  3897. }
  3898. //--- Event -> Unhide for Alerts Engine ---//
  3899. if($bRepost)
  3900. bx_alert($this->_oConfig->getObject('alert'), 'unhide_repost', $aReposted[$CNF['FIELD_ID']], $iUserId, array(
  3901. 'repost_id' => $aEvent[$CNF['FIELD_ID']],
  3902. ));
  3903. else
  3904. bx_alert($this->_oConfig->getObject('alert'), 'unhide', $aEvent[$CNF['FIELD_ID']], $iUserId);
  3905. //--- Event -> Unhide for Alerts Engine ---//
  3906. }
  3907. public function onDelete($aEvent)
  3908. {
  3909. $CNF = &$this->_oConfig->CNF;
  3910. $iUserId = $this->getUserId();
  3911. $sCommonPostPrefix = $this->_oConfig->getPrefix('common_post');
  3912. $sCommonPostComment = $this->_oConfig->getObject('comment');
  3913. //--- Delete comments for Common posts.
  3914. if($this->_oConfig->isCommon($aEvent['type'], $aEvent['action'])) {
  3915. $oComments = $this->getCmtsObject($sCommonPostComment, $aEvent[$CNF['FIELD_ID']]);
  3916. if($oComments !== false)
  3917. $oComments->onObjectDelete($aEvent[$CNF['FIELD_ID']]);
  3918. }
  3919. //--- Delete attached photos, videos and links when common event was deleted.
  3920. if($aEvent['type'] == $sCommonPostPrefix . BX_TIMELINE_PARSE_TYPE_POST) {
  3921. $this->_deleteMedia($CNF['FIELD_PHOTO'], $aEvent[$CNF['FIELD_ID']]);
  3922. $this->_deleteMedia($CNF['FIELD_VIDEO'], $aEvent[$CNF['FIELD_ID']]);
  3923. $this->_deleteMedia($CNF['FIELD_FILE'], $aEvent[$CNF['FIELD_ID']]);
  3924. $this->_deleteLinks($aEvent[$CNF['FIELD_ID']]);
  3925. }
  3926. //--- Update parent event when repost event was deleted.
  3927. $bRepost = $aEvent['type'] == $sCommonPostPrefix . BX_TIMELINE_PARSE_TYPE_REPOST;
  3928. if($bRepost) {
  3929. $this->_oDb->deleteRepostTrack($aEvent[$CNF['FIELD_ID']]);
  3930. $aContent = unserialize($aEvent['content']);
  3931. $aReposted = $this->_oDb->getReposted($aContent['type'], $aContent['action'], $aContent['object_id']);
  3932. if(!empty($aReposted) && is_array($aReposted))
  3933. $this->_oDb->updateRepostCounter($aReposted[$CNF['FIELD_ID']], $aReposted['reposts'], -1);
  3934. }
  3935. //--- Find and delete repost events when parent event was deleted.
  3936. $aRepostEvents = $this->_oDb->getEvents(array('browse' => 'reposted_by_track', 'value' => $aEvent[$CNF['FIELD_ID']]));
  3937. foreach($aRepostEvents as $aRepostEvent) {
  3938. if((int)$this->_oDb->deleteEvent(array('id' => (int)$aRepostEvent[$CNF['FIELD_ID']])) == 0)
  3939. continue;
  3940. $this->_oDb->deleteRepostTrack($aRepostEvent[$CNF['FIELD_ID']]);
  3941. $oComments = $this->getCmtsObject($sCommonPostComment, $aRepostEvent[$CNF['FIELD_ID']]);
  3942. if($oComments !== false)
  3943. $oComments->onObjectDelete($aRepostEvent[$CNF['FIELD_ID']]);
  3944. bx_alert($this->_oConfig->getObject('alert'), 'delete_repost', $aEvent[$CNF['FIELD_ID']], $iUserId, array(
  3945. 'repost_id' => $aRepostEvent[$CNF['FIELD_ID']],
  3946. ));
  3947. }
  3948. //--- Delete associated meta for Common events.
  3949. if($this->_oConfig->isCommon($aEvent['type'], $aEvent['action'])) {
  3950. $oMetatags = BxDolMetatags::getObjectInstance($this->_oConfig->getObject('metatags'));
  3951. $oMetatags->onDeleteContent($aEvent[$CNF['FIELD_ID']]);
  3952. }
  3953. //--- Delete item cache.
  3954. $sCacheItemKey = $this->_oConfig->getCacheItemKey($aEvent[$CNF['FIELD_ID']]);
  3955. $this->getCacheItemObject()->delData($sCacheItemKey);
  3956. //--- Event -> Delete for Alerts Engine ---//
  3957. if($bRepost)
  3958. bx_alert($this->_oConfig->getObject('alert'), 'delete_repost', $aReposted[$CNF['FIELD_ID']], $iUserId, array(
  3959. 'repost_id' => $aEvent[$CNF['FIELD_ID']],
  3960. ));
  3961. else
  3962. bx_alert($this->_oConfig->getObject('alert'), 'delete', $aEvent[$CNF['FIELD_ID']], $iUserId);
  3963. //--- Event -> Delete for Alerts Engine ---//
  3964. }
  3965. public function getParams($sView = '', $sType = '', $iOwnerId = 0, $iStart = 0, $iPerPage = 0, $sFilter = BX_TIMELINE_FILTER_ALL, $aModules = array(), $iTimeline = 0)
  3966. {
  3967. return $this->_prepareParams(array(
  3968. 'view' => $sView,
  3969. 'type' => $sType,
  3970. 'owner_id' => $iOwnerId,
  3971. 'start' => $iStart,
  3972. 'per_page' => $iPerPage,
  3973. 'timeline' => $iTimeline,
  3974. 'filter' => $sFilter,
  3975. 'modules' => $aModules
  3976. ));
  3977. }
  3978. public function getParamsExt($aParams = array())
  3979. {
  3980. return $this->_prepareParams($aParams);
  3981. }
  3982. public function getViewsData(&$aViews)
  3983. {
  3984. if(empty($aViews) || !is_array($aViews))
  3985. return false;
  3986. $sSystem = isset($aViews['system']) ? $aViews['system'] : '';
  3987. $iObjectId = isset($aViews['object_id']) ? (int)$aViews['object_id'] : 0;
  3988. $iCount = isset($aViews['count']) ? (int)$aViews['count'] : 0;
  3989. if($sSystem == '' || $iObjectId == 0)
  3990. return false;
  3991. return array($sSystem, $iObjectId, $iCount);
  3992. }
  3993. public function getVotesData(&$aVotes)
  3994. {
  3995. if(empty($aVotes) || !is_array($aVotes))
  3996. return false;
  3997. $sSystem = isset($aVotes['system']) ? $aVotes['system'] : '';
  3998. $iObjectId = isset($aVotes['object_id']) ? (int)$aVotes['object_id'] : 0;
  3999. $iCount = isset($aVotes['count']) ? (int)$aVotes['count'] : 0;
  4000. if($sSystem == '' || $iObjectId == 0)
  4001. return false;
  4002. return array($sSystem, $iObjectId, $iCount);
  4003. }
  4004. public function getReactionsData(&$aReactions)
  4005. {
  4006. if(empty($aReactions) || !is_array($aReactions))
  4007. return false;
  4008. $sSystem = isset($aReactions['system']) ? $aReactions['system'] : '';
  4009. $iObjectId = isset($aReactions['object_id']) ? (int)$aReactions['object_id'] : 0;
  4010. $iCount = isset($aReactions['count']) ? (int)$aReactions['count'] : 0;
  4011. if($sSystem == '' || $iObjectId == 0)
  4012. return false;
  4013. return array($sSystem, $iObjectId, $iCount);
  4014. }
  4015. public function getScoresData(&$aScores)
  4016. {
  4017. if(empty($aScores) || !is_array($aScores))
  4018. return false;
  4019. $sSystem = isset($aScores['system']) ? $aScores['system'] : '';
  4020. $iObjectId = isset($aScores['object_id']) ? (int)$aScores['object_id'] : 0;
  4021. $iScore = isset($aScores['score']) ? (int)$aScores['score'] : 0;
  4022. if($sSystem == '' || $iObjectId == 0)
  4023. return false;
  4024. return array($sSystem, $iObjectId, $iScore);
  4025. }
  4026. public function getReportsData(&$aReports)
  4027. {
  4028. if(empty($aReports) || !is_array($aReports))
  4029. return false;
  4030. $sSystem = isset($aReports['system']) ? $aReports['system'] : '';
  4031. $iObjectId = isset($aReports['object_id']) ? (int)$aReports['object_id'] : 0;
  4032. $iCount = isset($aReports['count']) ? (int)$aReports['count'] : 0;
  4033. if($sSystem == '' || $iObjectId == 0)
  4034. return false;
  4035. return array($sSystem, $iObjectId, $iCount);
  4036. }
  4037. public function getCommentsData(&$aComments)
  4038. {
  4039. if(empty($aComments) || !is_array($aComments))
  4040. return false;
  4041. $sSystem = isset($aComments['system']) ? $aComments['system'] : '';
  4042. $iObjectId = isset($aComments['object_id']) ? (int)$aComments['object_id'] : 0;
  4043. $iCount = isset($aComments['count']) ? (int)$aComments['count'] : 0;
  4044. if($sSystem == '' || $iObjectId == 0)
  4045. return false;
  4046. return [$sSystem, $iObjectId, $iCount];
  4047. }
  4048. public function getEventLinks($iEventId)
  4049. {
  4050. $aLinks = $this->_oDb->getLinks($iEventId);
  4051. if(empty($aLinks) || !is_array($aLinks))
  4052. return array();
  4053. $oTranscoder = BxDolTranscoderImage::getObjectInstance($this->_oConfig->getObject('transcoder_photos_preview'));
  4054. $aResult = array();
  4055. foreach($aLinks as $aLink)
  4056. $aResult[] = array(
  4057. 'url' => $aLink['url'],
  4058. 'title' => $aLink['title'],
  4059. 'text' => $aLink['text'],
  4060. 'thumbnail' => (int)$aLink['media_id'] != 0 ? $oTranscoder->getFileUrl($aLink['media_id']) : ''
  4061. );
  4062. return $aResult;
  4063. }
  4064. public function getEventImages($iEventId)
  4065. {
  4066. $CNF = &$this->_oConfig->CNF;
  4067. $aPhotos = $this->_oDb->getMedia($CNF['FIELD_PHOTO'], $iEventId);
  4068. if(empty($aPhotos) || !is_array($aPhotos))
  4069. return [];
  4070. $oTranscoderSm = BxDolTranscoderImage::getObjectInstance($this->_oConfig->getObject('transcoder_photos_view'));
  4071. $oTranscoderMd = BxDolTranscoderImage::getObjectInstance($this->_oConfig->getObject('transcoder_photos_medium'));
  4072. $oTranscoderLg = BxDolTranscoderImage::getObjectInstance($this->_oConfig->getObject('transcoder_photos_big'));
  4073. $aResult = [];
  4074. foreach($aPhotos as $iPhotoId) {
  4075. $sPhotoSrcMd = $oTranscoderMd->getFileUrl($iPhotoId);
  4076. if(empty($sPhotoSrcMd))
  4077. continue;
  4078. $sPhotoSrcSm = $oTranscoderSm->getFileUrl($iPhotoId);
  4079. if(empty($sPhotoSrcSm))
  4080. $sPhotoSrcSm = $sPhotoSrcMd;
  4081. $sPhotoSrcLg = $oTranscoderLg->getFileUrl($iPhotoId);
  4082. if(empty($sPhotoSrcLg))
  4083. $sPhotoSrcLg = $sPhotoSrcMd;
  4084. $aResult[] = [
  4085. 'id' => $iPhotoId,
  4086. 'src' => $sPhotoSrcMd,
  4087. 'src_small' => $sPhotoSrcSm,
  4088. 'src_medium' => $sPhotoSrcMd,
  4089. 'src_orig' => $sPhotoSrcLg,
  4090. ];
  4091. }
  4092. return $aResult;
  4093. }
  4094. public function getEventVideos($iEventId)
  4095. {
  4096. $CNF = &$this->_oConfig->CNF;
  4097. $aMediaIds = $this->_oDb->getMedia($CNF['FIELD_VIDEO'], $iEventId);
  4098. if(empty($aMediaIds) || !is_array($aMediaIds))
  4099. return array();
  4100. $oStorage = BxDolStorage::getObjectInstance($this->_oConfig->getObject('storage_videos'));
  4101. $oTranscoderPoster = BxDolTranscoderVideo::getObjectInstance($this->_oConfig->getObject('transcoder_videos_poster'));
  4102. $oTranscoderMp4 = BxDolTranscoderVideo::getObjectInstance($this->_oConfig->getObject('transcoder_videos_mp4'));
  4103. $oTranscoderMp4Hd = BxDolTranscoderVideo::getObjectInstance($this->_oConfig->getObject('transcoder_videos_mp4_hd'));
  4104. $oTranscoderPhoto = BxDolTranscoderImage::getObjectInstance($this->_oConfig->getObject('transcoder_videos_photo_view'));
  4105. $oTranscoderPhotoBig = BxDolTranscoderImage::getObjectInstance($this->_oConfig->getObject('transcoder_videos_photo_big'));
  4106. $aResult = array();
  4107. foreach($aMediaIds as $iMediaId) {
  4108. $aMediaFile = $oStorage->getFile($iMediaId);
  4109. $bVideoFile = strncmp('video/', $aMediaFile['mime_type'], 6) === 0 && $oTranscoderPoster->isMimeTypeSupported($aMediaFile['mime_type']);
  4110. if($bVideoFile) {
  4111. $sVideoUrlHd = '';
  4112. if (!empty($aMediaFile['dimensions']) && $oTranscoderMp4Hd->isProcessHD($aMediaFile['dimensions']))
  4113. $sVideoUrlHd = $oTranscoderMp4Hd->getFileUrl($iMediaId);
  4114. $aResult[$iMediaId] = array(
  4115. 'id' => $iMediaId,
  4116. 'src_poster' => $oTranscoderPoster->getFileUrl($iMediaId),
  4117. 'src_mp4' => $oTranscoderMp4->getFileUrl($iMediaId),
  4118. 'src_mp4_hd' => $sVideoUrlHd,
  4119. );
  4120. }
  4121. $bImageFile = strncmp('image/', $aMediaFile['mime_type'], 6) === 0 && $oTranscoderPhoto->isMimeTypeSupported($aMediaFile['mime_type']);
  4122. if($bImageFile) {
  4123. $sPhotoSrc = $oTranscoderPhoto->getFileUrl($iMediaId);
  4124. $sPhotoSrcBig = $oTranscoderPhotoBig->getFileUrl($iMediaId);
  4125. if(empty($sPhotoSrcBig) && !empty($sPhotoSrc))
  4126. $sPhotoSrcBig = $sPhotoSrc;
  4127. $aResult[$iMediaId] = array(
  4128. 'id' => $iMediaId,
  4129. 'src' => $sPhotoSrc,
  4130. 'src_orig' => $sPhotoSrcBig,
  4131. );
  4132. }
  4133. }
  4134. return $aResult;
  4135. }
  4136. public function getEventFiles($iEventId)
  4137. {
  4138. $CNF = &$this->_oConfig->CNF;
  4139. $aFiles = $this->_oDb->getMedia($CNF['FIELD_FILE'], $iEventId);
  4140. if(empty($aFiles) || !is_array($aFiles))
  4141. return [];
  4142. $oStorage = BxDolStorage::getObjectInstance($this->_oConfig->getObject('storage_files'));
  4143. $aResult = [];
  4144. foreach($aFiles as $iFileId) {
  4145. $sFileUrl = $oStorage->getFileUrlById($iFileId);
  4146. $aFileFile = $oStorage->getFile($iFileId);
  4147. $aResult[$iFileId] = [
  4148. 'id' => $iFileId,
  4149. 'src' => $this->_oTemplate->getIconUrl($oStorage->getIconNameByFileName($aFileFile['file_name'])),
  4150. 'src_medium' => '',
  4151. 'src_orig' => '',
  4152. 'url' => $sFileUrl,
  4153. 'title' => $aFileFile['file_name']
  4154. ];
  4155. }
  4156. return $aResult;
  4157. }
  4158. /**
  4159. * Protected Methods
  4160. */
  4161. protected function _serviceGetBlockView($iProfileId = 0, $aBrowseParams = array())
  4162. {
  4163. if(empty($iProfileId) && bx_get('profile_id') !== false)
  4164. $iProfileId = bx_process_input(bx_get('profile_id'), BX_DATA_INT);
  4165. if(empty($iProfileId) && isLogged())
  4166. $iProfileId = bx_get_logged_profile_id();
  4167. $aBrowseParams['owner_id'] = $iProfileId;
  4168. $aBlock = $this->_getBlockView($aBrowseParams);
  4169. if(!empty($aBlock))
  4170. return $aBlock;
  4171. return array('content' => MsgBox(_t('_bx_timeline_txt_msg_no_results')));
  4172. }
  4173. protected function _serviceGetBlockViewProfile($sProfileModule = 'bx_persons', $iProfileContentId = 0, $aBrowseParams = array())
  4174. {
  4175. if(empty($sProfileModule))
  4176. return array();
  4177. if(empty($iProfileContentId) && bx_get('id') !== false)
  4178. $iProfileContentId = bx_process_input(bx_get('id'), BX_DATA_INT);
  4179. $oProfile = BxDolProfile::getInstanceByContentAndType($iProfileContentId, $sProfileModule);
  4180. if(empty($oProfile))
  4181. return array();
  4182. $aBrowseParams['owner_id'] = $oProfile->id();
  4183. return $this->_getBlockView($aBrowseParams);
  4184. }
  4185. protected function _serviceGetBlockViews($aBrowseParams = array())
  4186. {
  4187. $aParams = $this->_prepareParams($aBrowseParams);
  4188. if(($sType = $this->_oConfig->getUserChoice('type')) !== false)
  4189. $aParams['type'] = $sType;
  4190. $this->_iOwnerId = $aParams['owner_id'];
  4191. return $this->_oTemplate->getViewsBlock($aParams);
  4192. }
  4193. protected function _serviceGetBlockViewHome($aBrowseParams = array())
  4194. {
  4195. $sRssUrl = BX_DOL_URL_ROOT . $this->_oConfig->getBaseUri() . 'rss/' . $aBrowseParams['type'] . '/';
  4196. BxDolTemplate::getInstance()->addPageRssLink(_t('_bx_timeline_page_title_view_home'), $sRssUrl);
  4197. return $this->_serviceGetBlockViewByType($aBrowseParams);
  4198. }
  4199. protected function _serviceGetBlockViewHot($aBrowseParams = array())
  4200. {
  4201. $sRssUrl = BX_DOL_URL_ROOT . $this->_oConfig->getBaseUri() . 'rss/' . $aBrowseParams['type'] . '/';
  4202. BxDolTemplate::getInstance()->addPageRssLink(_t('_bx_timeline_page_title_view_hot'), $sRssUrl);
  4203. return $this->_serviceGetBlockViewByType($aBrowseParams);
  4204. }
  4205. protected function _serviceGetBlockViewByType($aBrowseParams = array())
  4206. {
  4207. $aParams = $this->_prepareParams($aBrowseParams);
  4208. $this->_iOwnerId = $aParams['owner_id'];
  4209. return bx_is_api() ? [bx_api_get_block('browse', [
  4210. 'unit' => 'feed',
  4211. 'request_url' => '/api.php?r=bx_timeline/get_posts/&params[]=',
  4212. 'params' => $aParams,
  4213. 'data' => $this->_oTemplate->getViewBlock($aParams)]),
  4214. ] : ['content' => $this->_oTemplate->getViewBlock($aParams)];
  4215. }
  4216. protected function _getBlockPost($iProfileId, $aParams = array())
  4217. {
  4218. $this->_iOwnerId = $iProfileId;
  4219. if($this->isAllowedPost() !== true)
  4220. return array();
  4221. if (bx_is_api())
  4222. return $this->_oTemplate->getPostBlock($this->_iOwnerId, $aParams);
  4223. return array(
  4224. 'content' => $this->_oTemplate->getPostBlock($this->_iOwnerId, $aParams)
  4225. );
  4226. }
  4227. protected function _getBlockView($aBrowseParams = array())
  4228. {
  4229. if(empty($aBrowseParams['owner_id']))
  4230. return array();
  4231. $aParams = $this->_prepareParams($aBrowseParams);
  4232. if(empty($aParams['per_page']))
  4233. $aParams['per_page'] = $this->_oConfig->getPerPage('profile');
  4234. $this->_iOwnerId = $aParams['owner_id'];
  4235. $oProfileOwner = BxDolProfile::getInstance($this->_iOwnerId);
  4236. if(!$oProfileOwner)
  4237. return array();
  4238. $mixedResult = $oProfileOwner->checkAllowedProfileView();
  4239. if($mixedResult !== CHECK_ACTION_RESULT_ALLOWED) {
  4240. $this->_oTemplate->displayAccessDenied($mixedResult);
  4241. exit;
  4242. }
  4243. $sUserName = $this->getObjectUser($aParams['owner_id'])->getDisplayName();
  4244. $sView = $aParams['view'];
  4245. $sRssUrl = BX_DOL_URL_ROOT . $this->_oConfig->getBaseUri() . 'rss/' . BX_BASE_MOD_NTFS_TYPE_OWNER . '/' . $this->_iOwnerId . '/';
  4246. $sJsObject = $this->_oConfig->getJsObjectView($aParams);
  4247. $aMenu = array(
  4248. 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),
  4249. 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)),
  4250. 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')),
  4251. array('id' => $sView . '-get-rss', 'name' => $sView . '-get-rss', 'class' => '', 'link' => $sRssUrl, 'onclick' => '', 'target' => '_blank', 'title' => _t('_bx_timeline_menu_item_get_rss')),
  4252. );
  4253. $sContent = '';
  4254. bx_alert($oProfileOwner->getModule(), $this->_oConfig->getUri() . '_view', $this->_iOwnerId, $this->getUserId(), array('override_content' => &$sContent, 'params' => &$aParams, 'menu' => &$aMenu));
  4255. $oMenu = new BxTemplMenuInteractive(array('template' => 'menu_interactive_vertical.html', 'menu_id'=> $sView . '-view-all', 'menu_items' => $aMenu));
  4256. $oMenu->setSelected('', $sView . '-view-all');
  4257. if (!$sContent)
  4258. $sContent = $this->_oTemplate->getViewBlock($aParams);
  4259. if(bx_is_api())
  4260. return [bx_api_get_block('browse', [
  4261. 'unit' => 'feed',
  4262. 'request_url' => '/api.php?r=bx_timeline/get_posts/&params[]=',
  4263. 'params' => $aParams,
  4264. 'data' => $sContent
  4265. ])];
  4266. BxDolTemplate::getInstance()->addPageRssLink(_t('_bx_timeline_page_title_view'), $sRssUrl);
  4267. return array('content' => $sContent, 'menu' => $oMenu);
  4268. }
  4269. protected function _getContentForTimelinePost($aEvent, $aContentInfo, $aBrowseParams = array())
  4270. {
  4271. $CNF = &$this->_oConfig->CNF;
  4272. $iId = (int)$aContentInfo[$CNF['FIELD_ID']];
  4273. $sUrl = bx_absolute_url(BxDolPermalinks::getInstance()->permalink('page.php?i=' . $CNF['URI_VIEW_ENTRY'] . '&id=' . $iId));
  4274. $sText = '';
  4275. if(isset($aContentInfo['content'])){
  4276. $aTmp = unserialize($aContentInfo['content']);
  4277. if(isset($aTmp['text']))
  4278. $sText = $aTmp['text'];
  4279. }
  4280. if(empty($sText) && !empty($aContentInfo[$CNF['FIELD_TITLE']]))
  4281. $sText = $aContentInfo[$CNF['FIELD_TITLE']];
  4282. if(!empty($CNF['OBJECT_METATAGS']) && !empty($sText)) {
  4283. $oMetatags = BxDolMetatags::getObjectInstance($CNF['OBJECT_METATAGS']);
  4284. $sText = $oMetatags->metaParse($iId, $sText);
  4285. }
  4286. return array(
  4287. 'sample' => isset($CNF['T']['txt_sample_single_with_article']) ? $CNF['T']['txt_sample_single_with_article'] : $CNF['T']['txt_sample_single'],
  4288. 'sample_wo_article' => $CNF['T']['txt_sample_single'],
  4289. 'sample_action' => isset($CNF['T']['txt_sample_action']) ? $CNF['T']['txt_sample_action'] : '',
  4290. 'url' => $sUrl,
  4291. 'title' => '',
  4292. 'text' => $sText,
  4293. 'links' => $this->getEventLinks($iId),
  4294. 'images' => array(),
  4295. 'images_attach' => $this->getEventImages($iId),
  4296. 'videos' => array(),
  4297. 'videos_attach' => $this->getEventVideos($iId),
  4298. 'files' => array(),
  4299. 'files_attach' => $this->getEventFiles($iId)
  4300. );
  4301. }
  4302. protected function _isAllowedRepost($aEvent, $bPerform = false)
  4303. {
  4304. $iUserId = (int)$this->getUserId();
  4305. if($iUserId == 0)
  4306. return false;
  4307. $iPrivacy = (int)$aEvent['object_privacy_view'];
  4308. if($iPrivacy >= 0 && !in_array($iPrivacy, [BX_DOL_PG_ALL, BX_DOL_PG_MEMBERS]))
  4309. return false;
  4310. if(isAdmin())
  4311. return true;
  4312. $aCheckResult = checkActionModule($iUserId, 'repost', $this->getName(), $bPerform);
  4313. if(!empty($aEvent['owner_id']) && ($oProfileOwner = BxDolProfile::getInstance($aEvent['owner_id'])) !== false)
  4314. bx_alert($oProfileOwner->getModule(), $this->_oConfig->getUri() . '_repost', $oProfileOwner->id(), $iUserId, array('check_result' => &$aCheckResult));
  4315. return $aCheckResult[CHECK_ACTION_RESULT] !== CHECK_ACTION_RESULT_ALLOWED ? $aCheckResult[CHECK_ACTION_MESSAGE] : true;
  4316. }
  4317. protected function _isAllowedMute($bPerform = false)
  4318. {
  4319. if($this->_iProfileId == 0)
  4320. return false;
  4321. if(isAdmin())
  4322. return true;
  4323. $aCheckResult = checkActionModule($this->_iProfileId, 'mute', $this->getName(), $bPerform);
  4324. return $aCheckResult[CHECK_ACTION_RESULT] !== CHECK_ACTION_RESULT_ALLOWED ? $aCheckResult[CHECK_ACTION_MESSAGE] : true;
  4325. }
  4326. protected function _isAllowedPin($aEvent, $bPerform = false)
  4327. {
  4328. $iUserId = (int)$this->getUserId();
  4329. if($iUserId == 0)
  4330. return false;
  4331. if(isAdmin() || (int)$aEvent['owner_id'] == $iUserId || ((int)$aEvent['owner_id'] == 0 && $this->_oConfig->isCommon($aEvent['type'], $aEvent['action']) && (int)$aEvent['object_id'] == $iUserId))
  4332. return true;
  4333. $aCheckResult = checkActionModule($iUserId, 'pin', $this->getName(), $bPerform);
  4334. if(!empty($aEvent['owner_id']) && ($oProfileOwner = BxDolProfile::getInstance($aEvent['owner_id'])) !== false) {
  4335. if (BxDolService::call($oProfileOwner->getModule(), 'check_allowed_module_action_in_profile', array($oProfileOwner->getContentId(), $this->getName(), 'pin')) === CHECK_ACTION_RESULT_ALLOWED) {
  4336. return true;
  4337. }
  4338. bx_alert($oProfileOwner->getModule(), $this->_oConfig->getUri() . '_pin', $oProfileOwner->id(), $iUserId, array('check_result' => &$aCheckResult));
  4339. }
  4340. return $aCheckResult[CHECK_ACTION_RESULT] !== CHECK_ACTION_RESULT_ALLOWED ? $aCheckResult[CHECK_ACTION_MESSAGE] : true;
  4341. }
  4342. protected function _isAllowedStick($aEvent, $bPerform = false)
  4343. {
  4344. $iUserId = (int)$this->getUserId();
  4345. if($iUserId == 0)
  4346. return false;
  4347. if(isAdmin())
  4348. return true;
  4349. $aCheckResult = checkActionModule($iUserId, 'stick', $this->getName(), $bPerform);
  4350. if(!empty($aEvent['owner_id']) && ($oProfileOwner = BxDolProfile::getInstance($aEvent['owner_id'])) !== false)
  4351. bx_alert($oProfileOwner->getModule(), $this->_oConfig->getUri() . '_stick', $oProfileOwner->id(), $iUserId, array('check_result' => &$aCheckResult));
  4352. return $aCheckResult[CHECK_ACTION_RESULT] !== CHECK_ACTION_RESULT_ALLOWED ? $aCheckResult[CHECK_ACTION_MESSAGE] : true;
  4353. }
  4354. protected function _isAllowedPromote($aEvent, $bPerform = false)
  4355. {
  4356. if(isAdmin())
  4357. return true;
  4358. $iUserId = (int)$this->getUserId();
  4359. if($iUserId == 0)
  4360. return false;
  4361. $aCheckResult = checkActionModule($iUserId, 'promote', $this->getName(), $bPerform);
  4362. if(!empty($aEvent['owner_id']) && ($oProfileOwner = BxDolProfile::getInstance($aEvent['owner_id'])) !== false)
  4363. bx_alert($oProfileOwner->getModule(), $this->_oConfig->getUri() . '_promote', $oProfileOwner->id(), $iUserId, array('check_result' => &$aCheckResult));
  4364. return $aCheckResult[CHECK_ACTION_RESULT] !== CHECK_ACTION_RESULT_ALLOWED ? $aCheckResult[CHECK_ACTION_MESSAGE] : true;
  4365. }
  4366. protected function _addLink(&$oForm)
  4367. {
  4368. $iUserId = $this->getUserId();
  4369. $iEventId = (int)$oForm->getCleanValue('event_id');
  4370. $sLink = rtrim($oForm->getCleanValue('url'), '/');
  4371. $sHost = parse_url($sLink, PHP_URL_HOST);
  4372. if ($sHost && is_private_ip(gethostbyname($sHost)))
  4373. return array('message' => _t('_sys_txt_error_occured'));
  4374. $aMatches = array();
  4375. preg_match($this->_oConfig->getPregPattern('url'), $sLink, $aMatches);
  4376. $sLink = (empty($aMatches[2]) ? 'http://' : '') . $aMatches[0];
  4377. $aSiteInfo = bx_get_site_info($sLink, array(
  4378. 'thumbnailUrl' => array('tag' => 'link', 'content_attr' => 'href'),
  4379. 'OGImage' => array('name_attr' => 'property', 'name' => 'og:image'),
  4380. ));
  4381. $sTitle = !empty($aSiteInfo['title']) ? $aSiteInfo['title'] : _t('_Empty');
  4382. $sDescription = !empty($aSiteInfo['description']) ? $aSiteInfo['description'] : _t('_Empty');
  4383. $sMediaUrl = '';
  4384. if(!empty($aSiteInfo['thumbnailUrl']))
  4385. $sMediaUrl = $aSiteInfo['thumbnailUrl'];
  4386. else if(!empty($aSiteInfo['OGImage']))
  4387. $sMediaUrl = $aSiteInfo['OGImage'];
  4388. $iMediaId = 0;
  4389. $oStorage = null;
  4390. if(!empty($sMediaUrl)) {
  4391. $oStorage = BxDolStorage::getObjectInstance($this->_oConfig->getObject('storage_photos'));
  4392. $iMediaId = $oStorage->storeFileFromUrl($sMediaUrl, true, $iUserId);
  4393. }
  4394. $iId = (int)$oForm->insert(array('profile_id' => $iUserId, 'media_id' => $iMediaId, 'url' => $sLink, 'title' => $sTitle, 'text' => $sDescription, 'added' => time()));
  4395. if(!empty($iId)) {
  4396. if(!empty($oStorage) && !empty($iMediaId))
  4397. $oStorage->afterUploadCleanup($iMediaId, $iUserId);
  4398. return array(
  4399. 'id' => $iId,
  4400. 'event_id' => $iEventId,
  4401. 'url' => $sLink,
  4402. 'item' => $this->_oTemplate->getAttachLinkItem($iUserId, $iId)
  4403. );
  4404. }
  4405. return array('message' => _t('_bx_timeline_txt_err_cannot_perform_action'));
  4406. }
  4407. protected function _deleteLinks($iId)
  4408. {
  4409. $aLinks = $this->_oDb->getLinks($iId);
  4410. if(empty($aLinks) || !is_array($aLinks))
  4411. return;
  4412. $oStorage = BxDolStorage::getObjectInstance($this->_oConfig->getObject('storage_photos'));
  4413. foreach($aLinks as $aLink)
  4414. if(!empty($aLink['media_id']))
  4415. $oStorage->deleteFile($aLink['media_id']);
  4416. $this->_oDb->deleteLinks($iId);
  4417. }
  4418. protected function _saveMedia($sType, $iContentId, $aItemIds, $iProfileId = 0, $isAssociateWithContent = false)
  4419. {
  4420. if(empty($iContentId))
  4421. return;
  4422. if(!$isAssociateWithContent)
  4423. $this->_oDb->deleteMedia($sType, $iContentId);
  4424. if(empty($aItemIds) || !is_array($aItemIds))
  4425. return;
  4426. if(empty($iProfileId))
  4427. $iProfileId = $this->_iProfileId;
  4428. $oStorage = BxDolStorage::getObjectInstance($this->_oConfig->getObject('storage_' . strtolower($sType) . 's'));
  4429. $aGhostFiles = $oStorage->getGhosts ($iProfileId, !$isAssociateWithContent ? $iContentId : 0, true, $this->_isModerator());
  4430. if(empty($aGhostFiles) || !is_array($aGhostFiles))
  4431. return;
  4432. foreach($aGhostFiles as $aFile) {
  4433. if(is_array($aItemIds) && !in_array($aFile['id'], $aItemIds))
  4434. continue;
  4435. $iFileId = (int)$aFile['id'];
  4436. if($aFile['private'])
  4437. $oStorage->setFilePrivate($iFileId, 1);
  4438. $oStorage->updateGhostsContentId($iFileId, $iProfileId, $iContentId, $this->_isModerator());
  4439. $this->_oDb->saveMedia($sType, $iContentId, $iFileId);
  4440. }
  4441. }
  4442. protected function _deleteMedia($sType, $iContentId)
  4443. {
  4444. $aItems = $this->_oDb->getMedia($sType, $iContentId);
  4445. if(empty($aItems) || !is_array($aItems))
  4446. return;
  4447. $oStorage = BxDolStorage::getObjectInstance($this->_oConfig->getObject('storage_' . strtolower($sType) . 's'));
  4448. foreach($aItems as $iItemId)
  4449. $oStorage->deleteFile($iItemId);
  4450. $this->_oDb->deleteMedia($sType, $iContentId);
  4451. }
  4452. protected function _prepareParams($aParams)
  4453. {
  4454. if(empty($aParams['name']))
  4455. $aParams['name'] = '';
  4456. if(empty($aParams['view']))
  4457. $aParams['view'] = BX_TIMELINE_VIEW_DEFAULT;
  4458. if(empty($aParams['type']))
  4459. $aParams['type'] = BX_TIMELINE_TYPE_DEFAULT;
  4460. if(empty($aParams['owner_id']))
  4461. $aParams['owner_id'] = $this->getUserId();
  4462. if(!isset($aParams['start']) || (int)$aParams['start'] < 0)
  4463. $aParams['start'] = 0;
  4464. if(!isset($aParams['per_page']) || (int)$aParams['per_page'] <= 0)
  4465. $aParams['per_page'] = isset($aParams['per_page_default']) && (int)$aParams['per_page_default'] > 0 ? $aParams['per_page_default'] : $this->_oConfig->getPerPage();
  4466. if(empty($aParams['timeline']) || (int)$aParams['timeline'] < 0)
  4467. $aParams['timeline'] = 0;
  4468. if(empty($aParams['filter']))
  4469. $aParams['filter'] = BX_TIMELINE_FILTER_ALL;
  4470. if(empty($aParams['modules']) || !is_array($aParams['modules']))
  4471. $aParams['modules'] = array();
  4472. if(empty($aParams['context']))
  4473. $aParams['context'] = 0;
  4474. if(empty($aParams['blink']) || !is_array($aParams['blink']))
  4475. $aParams['blink'] = array();
  4476. $iViewerId = $this->getUserId();
  4477. if(empty($aParams['viewer_id']) || (int)$aParams['viewer_id'] != $iViewerId)
  4478. $aParams['viewer_id'] = $iViewerId;
  4479. $aParams = array_merge($aParams, array(
  4480. 'browse' => 'list',
  4481. 'status' => BX_TIMELINE_STATUS_ACTIVE,
  4482. 'moderator' => $this->isModeratorForProfile($aParams['viewer_id']),
  4483. 'dynamic_mode' => false,
  4484. ));
  4485. return $aParams;
  4486. }
  4487. protected function _prepareParamsGet($mParams = false)
  4488. {
  4489. $aKeys = ['name', 'view', 'type', 'owner_id', 'start', 'per_page', 'timeline', 'filter', 'modules', 'context', 'blink', 'viewer_id'];
  4490. $aParams = [];
  4491. if(!empty($mParams) && is_array($mParams))
  4492. foreach($aKeys as $sKey)
  4493. $aParams[$sKey] = isset($mParams[$sKey]) ? $mParams[$sKey] : false;
  4494. else
  4495. foreach($aKeys as $sKey)
  4496. $aParams[$sKey] = bx_get($sKey);
  4497. $aParams['name'] = $this->_oConfig->processParam($aParams['name']);
  4498. $aParams['view'] = $this->_oConfig->processParamWithDefault($aParams['view'], BX_TIMELINE_VIEW_DEFAULT);
  4499. $aParams['type'] = $this->_oConfig->processParamWithDefault($aParams['type'], BX_TIMELINE_TYPE_DEFAULT);
  4500. $aParams['owner_id'] = $aParams['owner_id'] !== false ? bx_process_input($aParams['owner_id'], BX_DATA_INT) : $this->getUserId();
  4501. $aParams['start'] = $aParams['start'] !== false ? bx_process_input($aParams['start'], BX_DATA_INT) : 0;
  4502. $aParams['per_page'] = $aParams['per_page'] !== false ? bx_process_input($aParams['per_page'], BX_DATA_INT) : $this->_oConfig->getPerPage();
  4503. $aParams['timeline'] = $aParams['timeline'] !== false ? bx_process_input($aParams['timeline']) : '';
  4504. $aParams['filter'] = $aParams['filter'] !== false ? bx_process_input($aParams['filter'], BX_DATA_TEXT) : BX_TIMELINE_FILTER_ALL;
  4505. $aParams['modules'] = $aParams['modules'] !== false ? bx_process_input($aParams['modules'], BX_DATA_TEXT) : [];
  4506. $aParams['context'] = $aParams['context'] !== false ? bx_process_input($aParams['context'], BX_DATA_INT) : 0;
  4507. if($aParams['blink'] !== false)
  4508. $aParams['blink'] = bx_process_input(is_string($aParams['blink']) ? explode(',', $aParams['blink']) : $aParams['blink'], BX_DATA_TEXT);
  4509. else
  4510. $aParams['blink'] = [];
  4511. $iViewerId = $this->getUserId();
  4512. if($aParams['viewer_id'] !== false)
  4513. $aParams['viewer_id'] = bx_process_input($aParams['viewer_id'], BX_DATA_INT);
  4514. if(!$aParams['viewer_id'] || $aParams['viewer_id'] != $iViewerId)
  4515. $aParams['viewer_id'] = $iViewerId;
  4516. $aParams = array_merge($aParams, [
  4517. 'browse' => 'list',
  4518. 'status' => BX_TIMELINE_STATUS_ACTIVE,
  4519. 'moderator' => $this->isModeratorForProfile($aParams['viewer_id']),
  4520. 'dynamic_mode' => true,
  4521. ]);
  4522. return $aParams;
  4523. }
  4524. protected function _prepareTextForSave($s)
  4525. {
  4526. return bx_process_input($s, BX_DATA_HTML);
  4527. }
  4528. protected function _prepareFormForAutoSubmit(&$oForm, &$aValues)
  4529. {
  4530. $oForm->aFormAttrs['method'] = BX_DOL_FORM_METHOD_SPECIFIC;
  4531. $oForm->aParams['csrf']['disable'] = true;
  4532. if(!empty($oForm->aParams['db']['submit_name'])) {
  4533. $sSubmitName = $sSubmitValue = false;
  4534. if(is_array($oForm->aParams['db']['submit_name'])) {
  4535. foreach ($oForm->aParams['db']['submit_name'] as $sName) {
  4536. if(isset($oForm->aInputs[$sName])) {
  4537. $sSubmitName = $sName;
  4538. $sSubmitValue = $oForm->aInputs[$sName]['value'];
  4539. break;
  4540. }
  4541. else if(isset($oForm->aInputs['controls']))
  4542. foreach($oForm->aInputs['controls'] as $mixedKey => $mixedInput)
  4543. if(is_numeric($mixedKey) && isset($mixedInput['name']) && $mixedInput['name'] == $sName) {
  4544. $sSubmitName = $sName;
  4545. $sSubmitValue = $mixedInput['value'];
  4546. break 2;
  4547. }
  4548. }
  4549. }
  4550. else {
  4551. $sName = $oForm->aParams['db']['submit_name'];
  4552. if(isset($oForm->aInputs[$sName])) {
  4553. $sSubmitName = $sName;
  4554. $sSubmitValue = $oForm->aInputs[$sName]['value'];
  4555. }
  4556. else if(isset($oForm->aInputs['controls']))
  4557. foreach($oForm->aInputs['controls'] as $mixedKey => $mixedInput)
  4558. if(is_numeric($mixedKey) && isset($mixedInput['name']) && $mixedInput['name'] == $sName) {
  4559. $sSubmitName = $sName;
  4560. $sSubmitValue = $mixedInput['value'];
  4561. break;
  4562. }
  4563. }
  4564. if($sSubmitName && $sSubmitValue)
  4565. $aValues[$sSubmitName] = $sSubmitValue;
  4566. }
  4567. }
  4568. protected function _getFieldValue($sField, $iContentId)
  4569. {
  4570. $CNF = &$this->_oConfig->CNF;
  4571. if(empty($CNF[$sField]))
  4572. return false;
  4573. $aEvent = $this->_oDb->getEvents(array('browse' => 'id', 'value' => $iContentId));
  4574. if(empty($aEvent) || empty($aEvent[$CNF[$sField]]))
  4575. return false;
  4576. return $aEvent[$CNF[$sField]];
  4577. }
  4578. /**
  4579. * Returns records for React Jot using OAuth2
  4580. * @param int $iProfileId
  4581. * @param string $sPage
  4582. * @param string $sTab
  4583. * @param int $iStart
  4584. * @param int $iPerPage
  4585. * @return array
  4586. */
  4587. public function serviceGetUserPosts($iProfileId = 0, $sPage = 'home', $sTab = 'hot', $iStart = 0, $iPerPage = 0)
  4588. {
  4589. $iProfileId = (int)$iProfileId ? (int)$iProfileId : bx_get_logged_profile_id();
  4590. if(empty($iProfileId))
  4591. return array(
  4592. 'code' => 1,
  4593. 'result' => array(),
  4594. 'message' => _t('_bx_timeline_txt_msg_no_profile_id'),
  4595. 'page' => $sPage,
  4596. 'tab' => $sTab
  4597. );
  4598. $sType = BX_TIMELINE_TYPE_OWNER_AND_CONNECTIONS;
  4599. $sView = BX_TIMELINE_VIEW_DEFAULT;
  4600. $sFilter = BX_TIMELINE_FILTER_ALL;
  4601. $aModules = array();
  4602. switch($sPage){
  4603. case 'profile':
  4604. $sType = BX_BASE_MOD_NTFS_TYPE_OWNER;
  4605. $sFilter = BX_TIMELINE_FILTER_OWNER;
  4606. break;
  4607. default:
  4608. if ($this -> _oDb -> isModuleByName($sPage))
  4609. $aModules = array($sPage);
  4610. }
  4611. switch($sTab)
  4612. {
  4613. case 'latest':
  4614. $sType = BX_BASE_MOD_NTFS_TYPE_PUBLIC;
  4615. break;
  4616. case 'popular':
  4617. $sType = BX_TIMELINE_TYPE_HOT;
  4618. break;
  4619. case 'feed':
  4620. $sType = BX_TIMELINE_TYPE_OWNER_AND_CONNECTIONS;
  4621. break;
  4622. default:
  4623. if ($this -> _oDb -> isModuleByName($sTab))
  4624. $aModules = array($sTab);
  4625. }
  4626. $aParams = $this->getParams($sView, $sType, $iProfileId, $iStart, $iPerPage, $sFilter, $aModules);
  4627. $aEvents = $this->_oDb->getEvents($aParams);
  4628. $iCount = $this->_oDb->getEvents(array_merge($aParams, array('count' => true)));
  4629. if(empty($aEvents) || !is_array($aEvents))
  4630. return array(
  4631. 'code' => 0,
  4632. 'result' => array(),
  4633. 'message' => _t('_bx_timeline_txt_msg_no_results'),
  4634. 'page' => $sPage,
  4635. 'tab' => $sTab
  4636. );
  4637. $aBrowseParams = array();
  4638. $aItems = array();
  4639. foreach($aEvents as $aEvent) {
  4640. $aResult = $this->_oTemplate->getData($aEvent, $aBrowseParams);
  4641. if($aResult === false)
  4642. continue;
  4643. $oOwnerProfile = BxDolProfile::getInstance($aResult['owner_id']);
  4644. $aFiles = array();
  4645. $aContent = &$aResult['content'];
  4646. if (!empty($aContent['image']))
  4647. $aFiles['images'] = array_values($aContent['images']);
  4648. if (!empty($aContent['images_attach']))
  4649. $aFiles['images'] = array_values($aContent['images_attach']);
  4650. if (!empty($aContent['videos']))
  4651. $aFiles['videos'] = array_values($aContent['videos']);
  4652. else
  4653. if (!empty($aContent['videos_attach']))
  4654. $aFiles['videos'] = array_values($aContent['videos_attach']);
  4655. if (!empty($aContent['files']))
  4656. $aFiles['files'] = array_values($aContent['files']);
  4657. else
  4658. if (!empty($aContent['files_attach']))
  4659. $aFiles['files'] = array_values($aContent['files_attach']);
  4660. $aItems[$aEvent['id']] = array_merge(array(
  4661. 'owner' => array(
  4662. 'icon' => $oOwnerProfile -> getThumb(),
  4663. 'name' => $oOwnerProfile -> getDisplayName(),
  4664. 'url' => $oOwnerProfile -> getUrl()
  4665. ),
  4666. 'sample' => !empty($aResult['sample']) ? _t($aResult['sample']) : _t('_bx_timeline_txt_sample'),
  4667. 'sample_action' => !empty($aResult['sample_action']) ? _t($aResult['sample_action']) : _t('_bx_timeline_txt_added_sample'),
  4668. 'url' => isset($aResult['url']) ? $aResult['url'] : '',
  4669. 'raw' => isset($aContent['raw']) ? strip_tags($aContent['raw']) : '',
  4670. 'text' => isset($aContent['text']) ? strip_tags($aContent['text']) : '',
  4671. 'views' => isset($aResult['views']['count']) ? (int)$aResult['views']['count'] : 0,
  4672. 'votes' => isset($aResult['votes']['count']) ? (int)$aResult['votes']['count'] : 0,
  4673. 'reactions' => isset($aResult['reactions']['count']) ? (int)$aResult['reactions']['count'] : 0,
  4674. 'scores' => isset($aResult['scores']['count']) ? (int)$aResult['scores']['count'] : 0,
  4675. 'reports' => isset($aResult['reports']['count']) ? (int)$aResult['reports']['count'] : 0,
  4676. 'comments' => isset($aResult['comments']['count']) ? (int)$aResult['comments']['count'] : 0,
  4677. 'date' => isset($aResult['date']) ? $aResult['date'] : $aEvent['date'],
  4678. 'type' => stripos($aEvent['type'], 'timeline') !== false ? 'bx_timeline' : $aEvent['type'],
  4679. 'event_type' => $aEvent['type'],
  4680. 'id' => $aEvent['id'],
  4681. 'content' => $aResult['content'],
  4682. 'title' => isset($aResult['title']) ? _t($aResult['title']) : '',
  4683. 'description' => isset($aResult['description']) ? $aResult['description'] : ''
  4684. ), $aFiles);
  4685. }
  4686. return array(
  4687. 'result' => $aItems,
  4688. 'code' => 0,
  4689. 'message' => '',
  4690. 'page' => $sPage,
  4691. 'tab' => $sTab,
  4692. 'total' => $iCount,
  4693. 'start' => (int)$iStart
  4694. );
  4695. }
  4696. }
  4697. /** @} */