BxTimelineModule.php 220 KB

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