BxTimelineModule.php 196 KB

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