BxTimelineModule.php 176 KB

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