BxTimelineModule.php 168 KB

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