BxTimelineModule.php 167 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295
  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. list($sUserName) = $this->getUserInfo($iOwnerId);
  395. $sRssCaption = _t('_bx_timeline_txt_rss_caption', $sUserName);
  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. /**
  1413. * @page service Service Calls
  1414. * @section bx_timeline Timeline
  1415. * @subsection bx_timeline-integration_notifications Integration with Notifications
  1416. * @subsubsection bx_timeline-get_notifications_data get_notifications_data
  1417. *
  1418. * @code bx_srv('bx_timeline', 'get_notifications_data', [...]); @endcode
  1419. *
  1420. * Data for Notifications module.
  1421. *
  1422. * @return an array with special format.
  1423. *
  1424. * @see BxTimelineModule::serviceGetNotificationsData
  1425. */
  1426. /**
  1427. * @ref bx_timeline-get_notifications_data "get_notifications_data"
  1428. */
  1429. public function serviceGetNotificationsData()
  1430. {
  1431. $sModule = $this->_aModule['name'];
  1432. return array(
  1433. 'handlers' => array(
  1434. array('group' => $sModule . '_object', 'type' => 'insert', 'alert_unit' => $sModule, 'alert_action' => 'post_common', 'module_name' => $sModule, 'module_method' => 'get_notifications_post', 'module_class' => 'Module'),
  1435. array('group' => $sModule . '_object', 'type' => 'delete', 'alert_unit' => $sModule, 'alert_action' => 'delete'),
  1436. 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'),
  1437. 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'),
  1438. array('group' => $sModule . '_repost', 'type' => 'insert', 'alert_unit' => $sModule, 'alert_action' => 'repost', 'module_name' => $sModule, 'module_method' => 'get_notifications_repost', 'module_class' => 'Module'),
  1439. array('group' => $sModule . '_repost', 'type' => 'delete', 'alert_unit' => $sModule, 'alert_action' => 'delete_repost'),
  1440. array('group' => $sModule . '_comment', 'type' => 'insert', 'alert_unit' => $sModule, 'alert_action' => 'commentPost', 'module_name' => $sModule, 'module_method' => 'get_notifications_comment', 'module_class' => 'Module'),
  1441. array('group' => $sModule . '_comment', 'type' => 'delete', 'alert_unit' => $sModule, 'alert_action' => 'commentRemoved'),
  1442. array('group' => $sModule . '_vote', 'type' => 'insert', 'alert_unit' => $sModule, 'alert_action' => 'doVote', 'module_name' => $sModule, 'module_method' => 'get_notifications_vote', 'module_class' => 'Module'),
  1443. array('group' => $sModule . '_vote', 'type' => 'delete', 'alert_unit' => $sModule, 'alert_action' => 'undoVote'),
  1444. array('group' => $sModule . '_reaction', 'type' => 'insert', 'alert_unit' => $sModule . '_reactions', 'alert_action' => 'doVote', 'module_name' => $sModule, 'module_method' => 'get_notifications_reaction', 'module_class' => 'Module'),
  1445. array('group' => $sModule . '_reaction', 'type' => 'delete', 'alert_unit' => $sModule . '_reactions', 'alert_action' => 'undoVote'),
  1446. 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'),
  1447. 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'),
  1448. ),
  1449. 'settings' => array(
  1450. array('group' => 'content', 'unit' => $sModule, 'action' => 'post_common', 'types' => array('personal', 'follow_member', 'follow_context')),
  1451. array('group' => 'content', 'unit' => $sModule, 'action' => 'publish_failed', 'types' => array('personal')),
  1452. array('group' => 'content', 'unit' => $sModule, 'action' => 'publish_succeeded', 'types' => array('personal')),
  1453. array('group' => 'content', 'unit' => $sModule, 'action' => 'repost', 'types' => array('follow_member', 'follow_context')),
  1454. array('group' => 'comment', 'unit' => $sModule, 'action' => 'commentPost', 'types' => array('personal', 'follow_member', 'follow_context')),
  1455. array('group' => 'vote', 'unit' => $sModule, 'action' => 'doVote', 'types' => array('personal', 'follow_member', 'follow_context')),
  1456. array('group' => 'vote', 'unit' => $sModule . '_reactions', 'action' => 'doVote', 'types' => array('personal', 'follow_member', 'follow_context')),
  1457. array('group' => 'score_up', 'unit' => $sModule, 'action' => 'doVoteUp', 'types' => array('personal', 'follow_member', 'follow_context')),
  1458. array('group' => 'score_down', 'unit' => $sModule, 'action' => 'doVoteDown', 'types' => array('personal', 'follow_member', 'follow_context'))
  1459. ),
  1460. 'alerts' => array(
  1461. array('unit' => $sModule, 'action' => 'post_common'),
  1462. array('unit' => $sModule, 'action' => 'publish_failed'),
  1463. array('unit' => $sModule, 'action' => 'publish_succeeded'),
  1464. array('unit' => $sModule, 'action' => 'delete'),
  1465. array('unit' => $sModule, 'action' => 'repost'),
  1466. array('unit' => $sModule, 'action' => 'delete_repost'),
  1467. array('unit' => $sModule, 'action' => 'commentPost'),
  1468. array('unit' => $sModule, 'action' => 'commentRemoved'),
  1469. array('unit' => $sModule, 'action' => 'doVote'),
  1470. array('unit' => $sModule, 'action' => 'undoVote'),
  1471. array('unit' => $sModule . '_reactions', 'action' => 'doVote'),
  1472. array('unit' => $sModule . '_reactions', 'action' => 'undoVote'),
  1473. array('unit' => $sModule, 'action' => 'doVoteUp'),
  1474. array('unit' => $sModule, 'action' => 'doVoteDown'),
  1475. )
  1476. );
  1477. }
  1478. /**
  1479. * @page service Service Calls
  1480. * @section bx_timeline Timeline
  1481. * @subsection bx_timeline-integration_notifications Integration with Notifications
  1482. * @subsubsection bx_timeline-get_notifications_repost get_notifications_repost
  1483. *
  1484. * @code bx_srv('bx_timeline', 'get_notifications_repost', [...]); @endcode
  1485. *
  1486. * Get data for Repost event to display in Notifications module.
  1487. *
  1488. * @param $aEvent an array with event description.
  1489. * @return an array with special format.
  1490. *
  1491. * @see BxTimelineModule::serviceGetNotificationsRepost
  1492. */
  1493. /**
  1494. * @ref bx_timeline-get_notifications_repost "get_notifications_repost"
  1495. */
  1496. public function serviceGetNotificationsRepost($aEvent)
  1497. {
  1498. $aResult = $this->serviceGetNotificationsPost($aEvent);
  1499. $aResult['lang_key'] = '_bx_timeline_txt_object_reposted';
  1500. return $aResult;
  1501. }
  1502. /**
  1503. * @page service Service Calls
  1504. * @section bx_timeline Timeline
  1505. * @subsection bx_timeline-integration_notifications Integration with Notifications
  1506. * @subsubsection bx_timeline-get_notifications_post get_notifications_post
  1507. *
  1508. * @code bx_srv('bx_timeline', 'get_notifications_post', [...]); @endcode
  1509. *
  1510. * Get data for Post event to display in Notifications module.
  1511. *
  1512. * @param $aEvent an array with event description.
  1513. * @return an array with special format.
  1514. *
  1515. * @see BxTimelineModule::serviceGetNotificationsPost
  1516. */
  1517. /**
  1518. * @ref bx_timeline-get_notifications_post "get_notifications_post"
  1519. */
  1520. public function serviceGetNotificationsPost($aEvent)
  1521. {
  1522. $CNF = &$this->_oConfig->CNF;
  1523. $iContent = (int)$aEvent['object_id'];
  1524. $aContent = $this->_oDb->getEvents(array('browse' => 'id', 'value' => $iContent));
  1525. if(empty($aContent) || !is_array($aContent))
  1526. return array();
  1527. if($this->_oConfig->isSystem($aContent['type'], $aContent['action']))
  1528. $iEntryAuthor = (int)$aContent['owner_id'];
  1529. else
  1530. $iEntryAuthor = (int)$aContent['object_id'];
  1531. $sEntryCaption = call_user_func_array(array($this->_oConfig, 'getTitleShort'), !empty($aContent['title']) ? array($aContent['title']) : array($aContent['description'], $aContent['object_id']));
  1532. return array(
  1533. 'entry_sample' => $CNF['T']['txt_sample_single_ext'],
  1534. 'entry_url' => $this->_oConfig->getItemViewUrl($aContent),
  1535. 'entry_caption' => $sEntryCaption,
  1536. 'entry_author' => $iEntryAuthor,
  1537. 'lang_key' => '' //may be empty or not specified. In this case the default one from Notification module will be used.
  1538. );
  1539. }
  1540. /**
  1541. * @page service Service Calls
  1542. * @section bx_timeline Timeline
  1543. * @subsection bx_timeline-integration_notifications Integration with Notifications
  1544. * @subsubsection bx_timeline-get_notifications_comment get_notifications_comment
  1545. *
  1546. * @code bx_srv('bx_timeline', 'get_notifications_comment', [...]); @endcode
  1547. *
  1548. * Get data for Post Comment event to display in Notifications module.
  1549. *
  1550. * @param $aEvent an array with event description.
  1551. * @return an array with special format.
  1552. *
  1553. * @see BxTimelineModule::serviceGetNotificationsComment
  1554. */
  1555. /**
  1556. * @ref bx_timeline-get_notifications_comment "get_notifications_comment"
  1557. */
  1558. public function serviceGetNotificationsComment($aEvent)
  1559. {
  1560. $CNF = &$this->_oConfig->CNF;
  1561. $iContent = (int)$aEvent['object_id'];
  1562. $aContent = $this->_oDb->getEvents(array('browse' => 'id', 'value' => $iContent));
  1563. if(empty($aContent) || !is_array($aContent))
  1564. return array();
  1565. $oComment = BxDolCmts::getObjectInstance($CNF['OBJECT_COMMENTS'], $iContent);
  1566. if(!$oComment || !$oComment->isEnabled())
  1567. return array();
  1568. $sEntryCaption = call_user_func_array(array($this->_oConfig, 'getTitleShort'), !empty($aContent['title']) ? array($aContent['title']) : array($aContent['description'], $aContent['object_id']));
  1569. return array(
  1570. 'entry_sample' => $CNF['T']['txt_sample_single'],
  1571. 'entry_url' => $this->_oConfig->getItemViewUrl($aContent),
  1572. 'entry_caption' => $sEntryCaption,
  1573. 'entry_author' => $aContent['owner_id'],
  1574. 'subentry_sample' => $CNF['T']['txt_sample_comment_single'],
  1575. 'subentry_url' => $oComment->getViewUrl((int)$aEvent['subobject_id']),
  1576. 'lang_key' => '', //may be empty or not specified. In this case the default one from Notification module will be used.
  1577. );
  1578. }
  1579. /**
  1580. * @page service Service Calls
  1581. * @section bx_timeline Timeline
  1582. * @subsection bx_timeline-integration_notifications Integration with Notifications
  1583. * @subsubsection bx_timeline-get_notifications_vote get_notifications_vote
  1584. *
  1585. * @code bx_srv('bx_timeline', 'get_notifications_vote', [...]); @endcode
  1586. *
  1587. * Get data for Vote event to display in Notifications module.
  1588. *
  1589. * @param $aEvent an array with event description.
  1590. * @return an array with special format.
  1591. *
  1592. * @see BxTimelineModule::serviceGetNotificationsVote
  1593. */
  1594. /**
  1595. * @ref bx_timeline-get_notifications_vote "get_notifications_vote"
  1596. */
  1597. public function serviceGetNotificationsVote($aEvent)
  1598. {
  1599. $CNF = &$this->_oConfig->CNF;
  1600. $iContent = (int)$aEvent['object_id'];
  1601. $aContent = $this->_oDb->getEvents(array('browse' => 'id', 'value' => $iContent));
  1602. if(empty($aContent) || !is_array($aContent))
  1603. return array();
  1604. $oVote = BxDolVote::getObjectInstance($CNF['OBJECT_VOTES'], $iContent);
  1605. if(!$oVote || !$oVote->isEnabled())
  1606. return array();
  1607. $sEntryCaption = call_user_func_array(array($this->_oConfig, 'getTitleShort'), !empty($aContent['title']) ? array($aContent['title']) : array($aContent['description'], $aContent['object_id']));
  1608. return array(
  1609. 'entry_sample' => $CNF['T']['txt_sample_single'],
  1610. 'entry_url' => $this->_oConfig->getItemViewUrl($aContent),
  1611. 'entry_caption' => $sEntryCaption,
  1612. 'entry_author' => $aContent['owner_id'],
  1613. 'subentry_sample' => $CNF['T']['txt_sample_vote_single'],
  1614. 'lang_key' => '', //may be empty or not specified. In this case the default one from Notification module will be used.
  1615. );
  1616. }
  1617. /**
  1618. * Entry post vote for Notifications module
  1619. */
  1620. public function serviceGetNotificationsReaction($aEvent)
  1621. {
  1622. $CNF = &$this->_oConfig->CNF;
  1623. $iContent = (int)$aEvent['object_id'];
  1624. $aContent = $this->_oDb->getEvents(array('browse' => 'id', 'value' => $iContent));
  1625. if(empty($aContent) || !is_array($aContent))
  1626. return array();
  1627. $oReaction = BxDolVote::getObjectInstance($CNF['OBJECT_REACTIONS'], $iContent);
  1628. if(!$oReaction || !$oReaction->isEnabled())
  1629. return array();
  1630. $aSubentry = $oReaction->getTrackBy(array('type' => 'id', 'id' => (int)$aEvent['subobject_id']));
  1631. if(empty($aSubentry) || !is_array($aSubentry))
  1632. return array();
  1633. $aSubentrySampleParams = array();
  1634. $aReaction = $oReaction->getReaction($aSubentry['reaction']);
  1635. if(!empty($aReaction['title']))
  1636. $aSubentrySampleParams[] = $aReaction['title'];
  1637. else
  1638. $aSubentrySampleParams[] = '_undefined';
  1639. $sEntryCaption = call_user_func_array(array($this->_oConfig, 'getTitleShort'), !empty($aContent['title']) ? array($aContent['title']) : array($aContent['description'], $aContent['object_id']));
  1640. return array(
  1641. 'entry_sample' => $CNF['T']['txt_sample_single'],
  1642. 'entry_url' => $this->_oConfig->getItemViewUrl($aContent),
  1643. 'entry_caption' => $sEntryCaption,
  1644. 'entry_author' => $aContent['owner_id'],
  1645. 'subentry_sample' => $CNF['T']['txt_sample_reaction_single'],
  1646. 'subentry_sample_params' => $aSubentrySampleParams,
  1647. 'lang_key' => '', //may be empty or not specified. In this case the default one from Notification module will be used.
  1648. );
  1649. }
  1650. /**
  1651. * @page service Service Calls
  1652. * @section bx_timeline Timeline
  1653. * @subsection bx_timeline-integration_notifications Integration with Notifications
  1654. * @subsubsection bx_timeline-get_notifications_score_up get_notifications_score_up
  1655. *
  1656. * @code bx_srv('bx_timeline', 'get_notifications_score_up', [...]); @endcode
  1657. *
  1658. * Get data for Score Up Vote event to display in Notifications module.
  1659. *
  1660. * @param $aEvent an array with event description.
  1661. * @return an array with special format.
  1662. *
  1663. * @see BxTimelineModule::serviceGetNotificationsScoreUp
  1664. */
  1665. /**
  1666. * @ref bx_timeline-get_notifications_score_up "get_notifications_score_up"
  1667. */
  1668. public function serviceGetNotificationsScoreUp($aEvent)
  1669. {
  1670. return $this->_serviceGetNotificationsScore('up', $aEvent);
  1671. }
  1672. /**
  1673. * @page service Service Calls
  1674. * @section bx_timeline Timeline
  1675. * @subsection bx_timeline-integration_notifications Integration with Notifications
  1676. * @subsubsection bx_timeline-get_notifications_score_down get_notifications_score_down
  1677. *
  1678. * @code bx_srv('bx_timeline', 'get_notifications_score_down', [...]); @endcode
  1679. *
  1680. * Get data for Score Down Vote event to display in Notifications module.
  1681. *
  1682. * @param $aEvent an array with event description.
  1683. * @return an array with special format.
  1684. *
  1685. * @see BxTimelineModule::serviceGetNotificationsScoreDown
  1686. */
  1687. /**
  1688. * @ref bx_timeline-get_notifications_score_down "get_notifications_score_down"
  1689. */
  1690. public function serviceGetNotificationsScoreDown($aEvent)
  1691. {
  1692. return $this->_serviceGetNotificationsScore('down', $aEvent);
  1693. }
  1694. protected function _serviceGetNotificationsScore($sType, $aEvent)
  1695. {
  1696. $CNF = &$this->_oConfig->CNF;
  1697. $iContent = (int)$aEvent['object_id'];
  1698. $aContent = $this->_oDb->getEvents(array('browse' => 'id', 'value' => $iContent));
  1699. if(empty($aContent) || !is_array($aContent))
  1700. return array();
  1701. $oScore = BxDolScore::getObjectInstance($CNF['OBJECT_SCORES'], $iContent);
  1702. if(!$oScore || !$oScore->isEnabled())
  1703. return array();
  1704. $sEntryCaption = call_user_func_array(array($this->_oConfig, 'getTitleShort'), !empty($aContent['title']) ? array($aContent['title']) : array($aContent['description'], $aContent['object_id']));
  1705. return array(
  1706. 'entry_sample' => $CNF['T']['txt_sample_single'],
  1707. 'entry_url' => $this->_oConfig->getItemViewUrl($aContent),
  1708. 'entry_caption' => $sEntryCaption,
  1709. 'entry_author' => $aContent['owner_id'],
  1710. 'subentry_sample' => $CNF['T']['txt_sample_score_' . $sType . '_single'],
  1711. 'lang_key' => '', //may be empty or not specified. In this case the default one from Notification module will be used.
  1712. );
  1713. }
  1714. /**
  1715. * @page service Service Calls
  1716. * @section bx_timeline Timeline
  1717. * @subsection bx_timeline-repost Repost
  1718. * @subsubsection bx_timeline-get_repost_element_block get_repost_element_block
  1719. *
  1720. * @code bx_srv('bx_timeline', 'get_repost_element_block', [...]); @endcode
  1721. *
  1722. * Get repost element for content based modules.
  1723. *
  1724. * @param $iOwnerId integer value with owner profile ID.
  1725. * @param $sType string value with type (module name).
  1726. * @param $sAction string value with action (module action).
  1727. * @param $iObjectId integer value with object ID to be reposted.
  1728. * @param $aParams (optional) an array with additional params.
  1729. * @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.
  1730. *
  1731. * @see BxTimelineModule::serviceGetRepostElementBlock
  1732. */
  1733. /**
  1734. * @ref bx_timeline-get_repost_element_block "get_repost_element_block"
  1735. */
  1736. public function serviceGetRepostElementBlock($iOwnerId, $sType, $sAction, $iObjectId, $aParams = array())
  1737. {
  1738. if(!$this->isEnabled())
  1739. return '';
  1740. $aParams = array_merge($this->_oConfig->getRepostDefaults(), $aParams);
  1741. return $this->_oTemplate->getRepostElement($iOwnerId, $sType, $sAction, $iObjectId, $aParams);
  1742. }
  1743. /**
  1744. * @page service Service Calls
  1745. * @section bx_timeline Timeline
  1746. * @subsection bx_timeline-repost Repost
  1747. * @subsubsection bx_timeline-get_repost_counter get_repost_counter
  1748. *
  1749. * @code bx_srv('bx_timeline', 'get_repost_counter', [...]); @endcode
  1750. *
  1751. * Get repost counter.
  1752. *
  1753. * @param $sType string value with type (module name).
  1754. * @param $sAction string value with action (module action).
  1755. * @param $iObjectId integer value with object ID to be reposted.
  1756. * @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.
  1757. *
  1758. * @see BxTimelineModule::serviceGetRepostCounter
  1759. */
  1760. /**
  1761. * @ref bx_timeline-get_repost_counter "get_repost_counter"
  1762. */
  1763. public function serviceGetRepostCounter($sType, $sAction, $iObjectId)
  1764. {
  1765. if(!$this->isEnabled())
  1766. return '';
  1767. $aReposted = $this->_oDb->getReposted($sType, $sAction, $iObjectId);
  1768. return $this->_oTemplate->getRepostCounter($aReposted);
  1769. }
  1770. /**
  1771. * @page service Service Calls
  1772. * @section bx_timeline Timeline
  1773. * @subsection bx_timeline-repost Repost
  1774. * @subsubsection bx_timeline-get_repost_js_script get_repost_js_script
  1775. *
  1776. * @code bx_srv('bx_timeline', 'get_repost_js_script', [...]); @endcode
  1777. *
  1778. * Get repost JavaScript code.
  1779. *
  1780. * @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.
  1781. *
  1782. * @see BxTimelineModule::serviceGetRepostJsScript
  1783. */
  1784. /**
  1785. * @ref bx_timeline-get_repost_js_script "get_repost_js_script"
  1786. */
  1787. public function serviceGetRepostJsScript()
  1788. {
  1789. if(!$this->isEnabled())
  1790. return '';
  1791. return $this->_oTemplate->getRepostJsScript();
  1792. }
  1793. /**
  1794. * @page service Service Calls
  1795. * @section bx_timeline Timeline
  1796. * @subsection bx_timeline-repost Repost
  1797. * @subsubsection bx_timeline-get_repost_js_click get_repost_js_click
  1798. *
  1799. * @code bx_srv('bx_timeline', 'get_repost_js_click', [...]); @endcode
  1800. *
  1801. * Get repost JavaScript code for OnClick event.
  1802. *
  1803. * @param $iOwnerId integer value with owner profile ID.
  1804. * @param $sType string value with type (module name).
  1805. * @param $sAction string value with action (module action).
  1806. * @param $iObjectId integer value with object ID to be reposted.
  1807. * @return HTML string with JavaScript code to display in OnClick events of HTML elements.
  1808. *
  1809. * @see BxTimelineModule::serviceGetRepostJsClick
  1810. */
  1811. /**
  1812. * @ref bx_timeline-get_repost_js_click "get_repost_js_click"
  1813. */
  1814. public function serviceGetRepostJsClick($iOwnerId, $sType, $sAction, $iObjectId)
  1815. {
  1816. if(!$this->isEnabled())
  1817. return '';
  1818. return $this->_oTemplate->getRepostJsClick($iOwnerId, $sType, $sAction, $iObjectId);
  1819. }
  1820. /**
  1821. * @page service Service Calls
  1822. * @section bx_timeline Timeline
  1823. * @subsection bx_timeline-repost Repost
  1824. * @subsubsection bx_timeline-repost repost
  1825. *
  1826. * @code bx_srv('bx_timeline', 'repost', [...]); @endcode
  1827. *
  1828. * Perform repost action.
  1829. *
  1830. * @param $iAuthorId integer value with performer profile ID.
  1831. * @param $iOwnerId integer value with repost event owner profile ID.
  1832. * @param $sType string value with type (module name).
  1833. * @param $sAction string value with action (module action).
  1834. * @param $iObjectId integer value with object ID to be reposted.
  1835. * @parem $bForce boolean value force reposting without ACL check.
  1836. * @return an array with error (code and message) or integer with newly created repost event ID.
  1837. *
  1838. * @see BxTimelineModule::serviceRepost
  1839. */
  1840. /**
  1841. * @ref bx_timeline-repost "repost"
  1842. */
  1843. public function serviceRepost($iAuthorId, $iOwnerId, $sType, $sAction, $iObjectId, $bForce = false)
  1844. {
  1845. $aReposted = $this->_oDb->getReposted($sType, $sAction, $iObjectId);
  1846. if(empty($aReposted) || !is_array($aReposted))
  1847. return array('code' => 1, 'message' => _t('_bx_timeline_txt_err_cannot_repost'));
  1848. $mixedAllowed = $this->isAllowedRepost($aReposted, true);
  1849. if(!$bForce && $mixedAllowed !== true)
  1850. return array('code' => 2, 'message' => strip_tags($mixedAllowed));
  1851. $bReposted = $this->_oDb->isReposted($aReposted['id'], $iOwnerId, $iAuthorId);
  1852. if($bReposted)
  1853. return array('code' => 3, 'message' => _t('_bx_timeline_txt_err_already_reposted'));
  1854. $iId = $this->_oDb->insertEvent(array(
  1855. 'owner_id' => $iOwnerId,
  1856. 'system' => 0,
  1857. 'type' => $this->_oConfig->getPrefix('common_post') . 'repost',
  1858. 'action' => '',
  1859. 'object_id' => $iAuthorId,
  1860. 'object_privacy_view' => $this->_oConfig->getPrivacyViewDefault('object'),
  1861. 'content' => serialize(array(
  1862. 'type' => $sType,
  1863. 'action' => $sAction,
  1864. 'object_id' => $iObjectId,
  1865. )),
  1866. 'title' => '',
  1867. 'description' => ''
  1868. ));
  1869. if(empty($iId))
  1870. return array('code' => 4, 'message' => _t('_bx_timeline_txt_err_cannot_repost'));
  1871. $this->onRepost($iId, $aReposted);
  1872. return $iId;
  1873. }
  1874. /**
  1875. * @page service Service Calls
  1876. * @section bx_timeline Timeline
  1877. * @subsection bx_timeline-repost Repost
  1878. * @subsubsection bx_timeline-repost_by_id repost_by_id
  1879. *
  1880. * @code bx_srv('bx_timeline', 'repost_by_id', [...]); @endcode
  1881. *
  1882. * Perform repost action by Timeline event ID.
  1883. *
  1884. * @param $iAuthorId integer value with performer profile ID.
  1885. * @param $iOwnerId integer value with repost event owner profile ID.
  1886. * @param $iEventId integer value with event ID which will be reposted.
  1887. * @parem $bForce boolean value force reposting without ACL check.
  1888. * @return an array with error (code and message) or integer with newly created repost event ID.
  1889. *
  1890. * @see BxTimelineModule::serviceRepostById
  1891. */
  1892. /**
  1893. * @ref bx_timeline-repost_by_id "repost_by_id"
  1894. */
  1895. public function serviceRepostById($iAuthorId, $iOwnerId, $iEventId, $bForce = false)
  1896. {
  1897. $aEvent = $this->_oDb->getEntriesBy(array('type' => 'id', 'id' => $iEventId));
  1898. if(empty($aEvent) || !is_array($aEvent))
  1899. return array('code' => 1, 'message' => _t('_bx_timeline_txt_err_cannot_repost'));
  1900. $sType = $aEvent['type'];
  1901. $sAction = $aEvent['action'];
  1902. $iObjectId = $this->_oConfig->isSystem($sType, $sAction) ? $aEvent['object_id'] : $aEvent['id'];
  1903. $sCommonPrefix = $this->_oConfig->getPrefix('common_post');
  1904. if(str_replace($sCommonPrefix, '', $sType) == BX_TIMELINE_PARSE_TYPE_REPOST) {
  1905. $aReposted = $this->_oDb->getReposted($sType, $sAction, $iObjectId);
  1906. if(empty($aReposted) || !is_array($aReposted))
  1907. return array('code' => 1, 'message' => _t('_bx_timeline_txt_err_cannot_repost'));
  1908. $aRepostedData = unserialize($aEvent['content']);
  1909. $sType = $aRepostedData['type'];
  1910. $sAction = $aRepostedData['action'];
  1911. $iObjectId = $aRepostedData['object_id'];
  1912. }
  1913. return $this->serviceRepost($iAuthorId, $iOwnerId, $sType, $sAction, $iObjectId, $bForce);
  1914. }
  1915. /**
  1916. * @page service Service Calls
  1917. * @section bx_timeline Timeline
  1918. * @subsection bx_timeline-other Other
  1919. * @subsubsection bx_timeline-update update
  1920. *
  1921. * @code bx_srv('bx_timeline', 'update', [...]); @endcode
  1922. *
  1923. * Update timeline event by ID.
  1924. *
  1925. * @param $iEventId integer value with event ID.
  1926. * @param $aSet an array with key=>value pairs for fields which should be updated.
  1927. * @return boolean value with the result of operation.
  1928. *
  1929. * @see BxTimelineModule::serviceUpdate
  1930. */
  1931. /**
  1932. * @ref bx_timeline-update "update"
  1933. */
  1934. public function serviceUpdate($iEventId, $aSet)
  1935. {
  1936. if(empty($iEventId))
  1937. return false;
  1938. return (int)$this->_oDb->updateEvent($aSet, array('id' => $iEventId)) > 0;
  1939. }
  1940. /**
  1941. * @page service Service Calls
  1942. * @section bx_timeline Timeline
  1943. * @subsection bx_timeline-other Other
  1944. * @subsubsection bx_timeline-get_menu_item_addon_comment get_menu_item_addon_comment
  1945. *
  1946. * @code bx_srv('bx_timeline', 'get_menu_item_addon_comment', [...]); @endcode
  1947. *
  1948. * Get addon for Comment menu item.
  1949. * NOTE. The service isn't used for now because comment functionality in card was updated.
  1950. *
  1951. * @param $sSystem string value with comments engine system.
  1952. * @param $iObjectId integer value with object ID.
  1953. * @return HTML string to display in menu item.
  1954. *
  1955. * @see BxTimelineModule::serviceGetMenuItemAddonComment
  1956. */
  1957. /**
  1958. * @ref bx_timeline-get_menu_item_addon_comment "get_menu_item_addon_comment"
  1959. */
  1960. public function serviceGetMenuItemAddonComment($sSystem, $iObjectId, $aBrowseParams = array())
  1961. {
  1962. if(empty($sSystem) || empty($iObjectId))
  1963. return '';
  1964. $oCmts = $this->getCmtsObject($sSystem, $iObjectId);
  1965. if($oCmts === false)
  1966. return '';
  1967. $iCounter = (int)$oCmts->getCommentsCount();
  1968. if(empty($iCounter))
  1969. return '';
  1970. return $this->_oTemplate->parseLink('javascript:void(0)', $iCounter, array(
  1971. 'class' => 'bx-menu-item-addon',
  1972. 'title' => _t('_bx_timeline_menu_item_title_item_comment'),
  1973. 'onclick' => "javascript:" . $this->_oConfig->getJsObjectView($aBrowseParams) . ".commentItem(this, '" . $sSystem . "', " . $iObjectId . ")"
  1974. ));
  1975. }
  1976. /**
  1977. * @page service Service Calls
  1978. * @section bx_timeline Timeline
  1979. * @subsection bx_timeline-other Other
  1980. * @subsubsection bx_timeline-get_settings_checker_helper get_settings_checker_helper
  1981. *
  1982. * @code bx_srv('bx_timeline', 'get_settings_checker_helper', [...]); @endcode
  1983. *
  1984. * Get Checker Helper class name for Forms engine.
  1985. *
  1986. * @return string with Checker Helper class name.
  1987. *
  1988. * @see BxTimelineModule::serviceGetSettingsCheckerHelper
  1989. */
  1990. /**
  1991. * @ref bx_timeline-get_settings_checker_helper "get_settings_checker_helper"
  1992. */
  1993. public function serviceGetSettingsCheckerHelper()
  1994. {
  1995. bx_import('FormCheckerHelper', $this->_aModule);
  1996. return 'BxTimelineFormCheckerHelper';
  1997. }
  1998. /**
  1999. * @page service Service Calls
  2000. * @section bx_timeline Timeline
  2001. * @subsection bx_timeline-other Other
  2002. * @subsubsection bx_timeline-get_options_videos_autoplay get_options_videos_autoplay
  2003. *
  2004. * @code bx_srv('bx_timeline', 'get_options_videos_autoplay', [...]); @endcode
  2005. *
  2006. * Get an array with available options for 'Videos autoplay in Timeline' setting.
  2007. *
  2008. * @return an array with available options represented as key => value pairs.
  2009. *
  2010. * @see BxTimelineModule::serviceGetOptionsVideosAutoplay
  2011. */
  2012. /**
  2013. * @ref bx_timeline-get_options_videos_autoplay "get_options_videos_autoplay"
  2014. */
  2015. public function serviceGetOptionsVideosAutoplay()
  2016. {
  2017. $CNF = &$this->_oConfig->CNF;
  2018. $aOptions = array(BX_TIMELINE_VAP_OFF, BX_TIMELINE_VAP_ON_MUTE, BX_TIMELINE_VAP_ON);
  2019. $aResult = array();
  2020. foreach($aOptions as $sOption)
  2021. $aResult[] = array(
  2022. 'key' => $sOption,
  2023. 'value' => _t($CNF['T']['option_vap_' . $sOption])
  2024. );
  2025. return $aResult;
  2026. }
  2027. /**
  2028. * @page service Service Calls
  2029. * @section bx_timeline Timeline
  2030. * @subsection bx_timeline-other Other
  2031. * @subsubsection bx_timeline-get_options_attachments_layout get_options_attachments_layout
  2032. *
  2033. * @code bx_srv('bx_timeline', 'get_options_attachments_layout', [...]); @endcode
  2034. *
  2035. * Get an array with available options for 'Show attachments as' setting.
  2036. *
  2037. * @return an array with available options represented as key => value pairs.
  2038. *
  2039. * @see BxTimelineModule::serviceGetOptionsAttachmentsLayout
  2040. */
  2041. /**
  2042. * @ref bx_timeline-get_options_attachments_layout "get_options_attachments_layout"
  2043. */
  2044. public function serviceGetOptionsAttachmentsLayout()
  2045. {
  2046. $CNF = &$this->_oConfig->CNF;
  2047. $aOptions = array(BX_TIMELINE_ML_GALLERY, BX_TIMELINE_ML_SHOWCASE);
  2048. $aResult = array();
  2049. foreach($aOptions as $sOption)
  2050. $aResult[] = array(
  2051. 'key' => $sOption,
  2052. 'value' => _t($CNF['T']['option_al_' . $sOption])
  2053. );
  2054. return $aResult;
  2055. }
  2056. /**
  2057. * @page service Service Calls
  2058. * @section bx_timeline Timeline
  2059. * @subsection bx_timeline-other Other
  2060. * @subsubsection bx_timeline-get_live_update get_live_update
  2061. *
  2062. * @code bx_srv('bx_timeline', 'get_live_update', [...]); @endcode
  2063. *
  2064. * Get an array with actual Live Update info. Only one live update notification for all new events.
  2065. *
  2066. * @return an array with Live Update info.
  2067. *
  2068. * @see BxTimelineModule::serviceGetLiveUpdate
  2069. */
  2070. /**
  2071. * @ref bx_timeline-get_live_update "get_live_update"
  2072. */
  2073. public function serviceGetLiveUpdate($aBrowseParams, $iProfileId, $iValue = 0, $iInit = 0)
  2074. {
  2075. $sKey = $this->_oConfig->getLiveUpdateKey($aBrowseParams);
  2076. bx_import('BxDolSession');
  2077. if((int)BxDolSession::getInstance()->getValue($sKey) == 1)
  2078. return false;
  2079. $aParams = $this->_prepareParams($aBrowseParams);
  2080. $aParams = array_merge($aParams, array(
  2081. 'filter' => BX_TIMELINE_FILTER_OTHER_VIEWER
  2082. ));
  2083. $aEvents = $this->_oDb->getEvents($aParams);
  2084. if(empty($aEvents) || !is_array($aEvents))
  2085. return false;
  2086. $iValueNew = 0;
  2087. foreach($aEvents as $aEvent) {
  2088. $sContent = $this->_oTemplate->getPost($aEvent, $aParams);
  2089. if(!empty($sContent)) {
  2090. $iValueNew = $aEvent['id'];
  2091. break;
  2092. }
  2093. }
  2094. if($iValueNew == $iValue)
  2095. return false;
  2096. if((int)$iInit != 0)
  2097. return array('count' => $iValueNew);
  2098. return array(
  2099. 'count' => $iValueNew, // required (for initialization and visualization)
  2100. 'method' => $this->_oConfig->getJsObjectView($aBrowseParams) . '.showLiveUpdate(oData)', // required (for visualization)
  2101. 'data' => array(
  2102. 'code' => $this->_oTemplate->getLiveUpdate($aBrowseParams, $iProfileId, $iValue, $iValueNew)
  2103. ), // optional, may have some additional data to be passed in JS method provided using 'method' param above.
  2104. );
  2105. }
  2106. /**
  2107. * @page service Service Calls
  2108. * @section bx_timeline Timeline
  2109. * @subsection bx_timeline-other Other
  2110. * @subsubsection bx_timeline-get_live_updates get_live_updates
  2111. *
  2112. * @code bx_srv('bx_timeline', 'get_live_updates', [...]); @endcode
  2113. *
  2114. * Get an array with actual Live Update info. Separate live update notification for each new Event.
  2115. *
  2116. * Note. This way to display live update notifications isn't used for now.
  2117. * See BxTimelineModule::serviceGetLiveUpdate method instead.
  2118. *
  2119. * @return an array with Live Update info.
  2120. *
  2121. * @see BxTimelineModule::serviceGetLiveUpdates
  2122. */
  2123. /**
  2124. * @ref bx_timeline-get_live_updates "get_live_updates"
  2125. */
  2126. public function serviceGetLiveUpdates($aBrowseParams, $iProfileId, $iCount = 0, $iInit = 0)
  2127. {
  2128. $sKey = $this->_oConfig->getLiveUpdateKey($aBrowseParams);
  2129. bx_import('BxDolSession');
  2130. if((int)BxDolSession::getInstance()->getValue($sKey) == 1)
  2131. return false;
  2132. $aParams = $this->_prepareParams($aBrowseParams);
  2133. $aParams['filter'] = BX_TIMELINE_FILTER_OTHER_VIEWER;
  2134. $aParams['count'] = true;
  2135. $iCountNew = $this->_oDb->getEvents($aParams);
  2136. if($iCountNew == $iCount)
  2137. return false;
  2138. if((int)$iInit != 0)
  2139. return array('count' => $iCountNew);
  2140. return array(
  2141. 'count' => $iCountNew, // required (for initialization and visualization)
  2142. 'method' => $this->_oConfig->getJsObjectView($aBrowseParams) . '.showLiveUpdates(oData)', // required (for visualization)
  2143. 'data' => array(
  2144. 'code' => $this->_oTemplate->getLiveUpdates($aBrowseParams, $iProfileId, $iCount, $iCountNew)
  2145. ), // optional, may have some additional data to be passed in JS method provided using 'method' param above.
  2146. );
  2147. }
  2148. /**
  2149. * @page service Service Calls
  2150. * @section bx_timeline Accounts
  2151. * @subsection bx_timeline-other Other
  2152. * @subsubsection bx_timeline-get_menu_addon_manage_tools get_menu_addon_manage_tools
  2153. *
  2154. * @code bx_srv('bx_timeline', 'get_menu_addon_manage_tools', [...]); @endcode
  2155. *
  2156. * Get number of 'hidden' events for User End -> Dasboard page -> Manage block.
  2157. *
  2158. * @return integer number of 'hidden' events
  2159. *
  2160. * @see BxTimelineModule::serviceGetMenuAddonManageTools
  2161. */
  2162. /**
  2163. * @ref bx_timeline-get_menu_addon_manage_tools "get_menu_addon_manage_tools"
  2164. */
  2165. public function serviceGetMenuAddonManageTools()
  2166. {
  2167. bx_import('SearchResult', $this->_aModule);
  2168. $sClass = $this->_aModule['class_prefix'] . 'SearchResult';
  2169. $oSearch = new $sClass();
  2170. $oSearch->fillFilters(array(
  2171. 'status' => BX_TIMELINE_STATUS_HIDDEN
  2172. ));
  2173. $oSearch->unsetPaginate();
  2174. return $oSearch->getNum();
  2175. }
  2176. public function serviceGet($aParams)
  2177. {
  2178. $aParams = $this->_prepareParams($aParams);
  2179. $aParams['return_data_type'] = 'array';
  2180. return $this->_oTemplate->getPosts($aParams);
  2181. }
  2182. public function serviceAdd($aValues)
  2183. {
  2184. return $this->getFormPost(array(
  2185. 'values' => $aValues
  2186. ));
  2187. }
  2188. public function serviceEdit($iId, $aValues)
  2189. {
  2190. return $this->getFormEdit($iId, array(
  2191. 'values' => $aValues
  2192. ));
  2193. }
  2194. /*
  2195. * COMMON METHODS
  2196. */
  2197. public function getItemData($iId, $aParams = array())
  2198. {
  2199. $CNF = &$this->_oConfig->CNF;
  2200. if(empty($aParams))
  2201. $aParams = $this->_prepareParams(array(
  2202. 'view' => BX_TIMELINE_VIEW_ITEM,
  2203. 'type' => BX_TIMELINE_TYPE_ITEM
  2204. ));
  2205. $aEvent = $this->_oDb->getEvents(array('browse' => 'id', 'value' => $iId));
  2206. if(empty($aEvent))
  2207. return array('code' => 1, 'content' => _t('_Empty'));
  2208. $iProfile = (int)$aEvent[$CNF['FIELD_OWNER_ID']];
  2209. if(!empty($iProfile)) {
  2210. $oProfile = BxDolProfile::getInstance($iProfile);
  2211. if(!$oProfile)
  2212. return array('code' => 1, 'content' => _t('_Empty'));
  2213. $mixedResult = $oProfile->checkAllowedProfileView();
  2214. if($mixedResult !== CHECK_ACTION_RESULT_ALLOWED)
  2215. return array('code' => 2, 'content' => $mixedResult);
  2216. }
  2217. $sContent = $this->_oTemplate->getPost($aEvent, $aParams);
  2218. if(empty($sContent))
  2219. return array('code' => 2, 'content' => _t('_Access denied'));
  2220. $sKey = 'allowed_view';
  2221. if(isset($aEvent[$sKey]) && $aEvent[$sKey] !== CHECK_ACTION_RESULT_ALLOWED)
  2222. return array('code' => 2, 'content' => $aEvent[$sKey]);
  2223. if($this->isAllowedView($aEvent) !== true)
  2224. return array('code' => 2, 'content' => _t('_Access denied'));
  2225. return array('code' => 0, 'content' => $sContent, 'event' => $aEvent);
  2226. }
  2227. public function deleteEvent($aEvent)
  2228. {
  2229. if(empty($aEvent) || !is_array($aEvent) || !$this->_oDb->deleteEvent(array('id' => (int)$aEvent['id'])))
  2230. return false;
  2231. $this->onDelete($aEvent);
  2232. return true;
  2233. }
  2234. public function addAttachLink($aValues, $sDisplay = false)
  2235. {
  2236. $CNF = &$this->_oConfig->CNF;
  2237. if(!$sDisplay)
  2238. $sDisplay = $this->_oConfig->getObject('form_display_attach_link_add');
  2239. $oForm = BxDolForm::getObjectInstance($this->_oConfig->getObject('form_attach_link'), $sDisplay, $this->_oTemplate);
  2240. if(!$oForm)
  2241. return array('message' => '_sys_txt_error_occured');
  2242. $oForm->aFormAttrs['method'] = BX_DOL_FORM_METHOD_SPECIFIC;
  2243. $oForm->aParams['csrf']['disable'] = true;
  2244. if(!empty($oForm->aParams['db']['submit_name'])) {
  2245. $sSubmitName = $oForm->aParams['db']['submit_name'];
  2246. if(!isset($oForm->aInputs[$sSubmitName])) {
  2247. if(isset($oForm->aInputs[$CNF['FIELD_CONTROLS']]))
  2248. foreach($oForm->aInputs[$CNF['FIELD_CONTROLS']] as $mixedIndex => $aInput) {
  2249. if(!is_numeric($mixedIndex) || empty($aInput['name']) || $aInput['name'] != $sSubmitName)
  2250. continue;
  2251. $aValues[$sSubmitName] = $aInput['value'];
  2252. }
  2253. }
  2254. else
  2255. $aValues[$sSubmitName] = $oForm->aInputs[$sSubmitName]['value'];
  2256. }
  2257. $oForm->aInputs['url']['checker']['params']['preg'] = $this->_oConfig->getPregPattern('url');
  2258. $oForm->initChecker(array(), $aValues);
  2259. if(!$oForm->isSubmittedAndValid())
  2260. return array('message' => '_sys_txt_error_occured');
  2261. return $this->_addLink($oForm);
  2262. }
  2263. public function getFormAttachLink()
  2264. {
  2265. $oForm = BxDolForm::getObjectInstance($this->_oConfig->getObject('form_attach_link'), $this->_oConfig->getObject('form_display_attach_link_add'), $this->_oTemplate);
  2266. $oForm->aFormAttrs['action'] = BX_DOL_URL_ROOT . $this->_oConfig->getBaseUri() . 'submit_attach_link_form/';
  2267. $oForm->aInputs['url']['checker']['params']['preg'] = $this->_oConfig->getPregPattern('url');
  2268. $oForm->initChecker();
  2269. if($oForm->isSubmittedAndValid())
  2270. return $this->_addLink($oForm);
  2271. return array('form' => $oForm->getCode(), 'form_id' => $oForm->id);
  2272. }
  2273. public function getFormPost($aParams = array())
  2274. {
  2275. $iUserId = $this->getUserId();
  2276. $oForm = $this->getFormPostObject($aParams);
  2277. $aFormInitCheckerParams = array();
  2278. $bValues = !empty($aParams['values']) && is_array($aParams['values']);
  2279. if($bValues) {
  2280. $this->_prepareFormForAutoSubmit($oForm, $aParams['values']);
  2281. $aFormInitCheckerParams = array(array(), $aParams['values']);
  2282. unset($aParams['values']);
  2283. }
  2284. call_user_func_array(array($oForm, 'initChecker'), $aFormInitCheckerParams);
  2285. $bAjaxMode = $oForm->isAjaxMode();
  2286. $bDynamicMode = $bAjaxMode;
  2287. if($oForm->isSubmittedAndValid()) {
  2288. list($sUserName) = $this->getUserInfo($iUserId);
  2289. $sType = $oForm->getCleanValue('type');
  2290. $sType = $this->_oConfig->getPrefix('common_post') . $sType;
  2291. BxDolForm::setSubmittedValue('type', $sType, $oForm->aFormAttrs['method']);
  2292. $aContent = array();
  2293. //--- Process Text ---//
  2294. $sText = $oForm->getCleanValue('text');
  2295. $sText = $this->_prepareTextForSave($sText);
  2296. $bText = !empty($sText);
  2297. if($bText)
  2298. $aContent['text'] = $sText;
  2299. //--- Process Context and Privacy ---//
  2300. $iOwnerId = (int)$oForm->getCleanValue('owner_id');
  2301. $iObjectPrivacyView = (int)$oForm->getCleanValue('object_privacy_view');
  2302. $iObjectPrivacyViewDefault = $this->_oConfig->getPrivacyViewDefault('object');
  2303. if(empty($iObjectPrivacyView))
  2304. $iObjectPrivacyView = $iObjectPrivacyViewDefault;
  2305. else if($iObjectPrivacyView < 0)
  2306. $iOwnerId = abs($iObjectPrivacyView);
  2307. //--- Process Link ---//
  2308. $aLinkIds = $oForm->getCleanValue('link');
  2309. $bLinkIds = !empty($aLinkIds) && is_array($aLinkIds);
  2310. //--- Process Media ---//
  2311. $aPhotoIds = $oForm->getCleanValue(BX_TIMELINE_MEDIA_PHOTO);
  2312. $bPhotoIds = !empty($aPhotoIds) && is_array($aPhotoIds);
  2313. $aVideoIds = $oForm->getCleanValue(BX_TIMELINE_MEDIA_VIDEO);
  2314. $bVideoIds = !empty($aVideoIds) && is_array($aVideoIds);
  2315. if(!$bText && !$bLinkIds && !$bPhotoIds && !$bVideoIds) {
  2316. $oForm->aInputs['text']['error'] = _t('_bx_timeline_txt_err_empty_post');
  2317. $oForm->setValid(false);
  2318. return $this->_prepareResponse(array('form' => $oForm->getCode($bDynamicMode), 'form_id' => $oForm->id), $bAjaxMode);
  2319. }
  2320. $sTitle = $bText ? $this->_oConfig->getTitle($sText) : $this->_oConfig->getTitleDefault($bLinkIds, $bPhotoIds, $bVideoIds);
  2321. $sDescription = _t('_bx_timeline_txt_user_added_sample', '{profile_name}', _t('_bx_timeline_txt_sample_with_article'));
  2322. /**
  2323. * Unset 'text' input because its data was already processed
  2324. * and will be saved via additional values which were passed
  2325. * to BxDolForm::insert method.
  2326. */
  2327. unset($oForm->aInputs['text']);
  2328. $iId = $oForm->insert(array(
  2329. 'owner_id' => $iOwnerId,
  2330. 'object_id' => $iUserId,
  2331. 'object_owner_id' => $iUserId,
  2332. 'object_privacy_view' => $iObjectPrivacyView,
  2333. 'content' => serialize($aContent),
  2334. 'title' => $sTitle,
  2335. 'description' => $sDescription
  2336. ));
  2337. if(!empty($iId)) {
  2338. $aContent = array_merge($aContent, array(
  2339. 'timeline_group' => array(
  2340. 'by' => $this->getName() . '_' . $iUserId . '_' . $iId,
  2341. 'field' => 'owner_id'
  2342. )
  2343. ));
  2344. $this->_oDb->updateEvent(array('content' => serialize($aContent)), array('id' => $iId));
  2345. //--- Process Meta ---//
  2346. $oMetatags = BxDolMetatags::getObjectInstance($this->_oConfig->getObject('metatags'));
  2347. if($bText)
  2348. $oMetatags->metaAdd($iId, $sText);
  2349. $oMetatags->locationsAddFromForm($iId, $this->_oConfig->CNF['FIELD_LOCATION_PREFIX']);
  2350. //--- Process Link ---//
  2351. if($bLinkIds)
  2352. foreach($aLinkIds as $iLinkId)
  2353. $this->_oDb->saveLink($iId, $iLinkId);
  2354. //--- Process Media ---//
  2355. if($bPhotoIds)
  2356. $this->_saveMedia(BX_TIMELINE_MEDIA_PHOTO, $iId, $aPhotoIds);
  2357. if($bVideoIds)
  2358. $this->_saveMedia(BX_TIMELINE_MEDIA_VIDEO, $iId, $aVideoIds);
  2359. $this->onPost($iId);
  2360. return $this->_prepareResponse(array('id' => $iId), $bAjaxMode, array(
  2361. 'redirect' => $this->_oConfig->getItemViewUrl(array('id' => $iId))
  2362. ));
  2363. }
  2364. return $this->_prepareResponse(array('message' => _t('_bx_timeline_txt_err_cannot_perform_action')), $bAjaxMode);
  2365. }
  2366. return $this->_prepareResponse(array('form' => $oForm->getCode($bDynamicMode), 'form_id' => $oForm->id), $bAjaxMode && $oForm->isSubmitted());
  2367. }
  2368. public function getFormEdit($iId, $aParams = array(), $aBrowseParams = array())
  2369. {
  2370. $CNF = &$this->_oConfig->CNF;
  2371. $sJsObjectView = $this->_oConfig->getJsObjectView($aBrowseParams);
  2372. $aEvent = $this->_oDb->getEvents(array('browse' => 'id', 'value' => $iId));
  2373. if(empty($aEvent) || !is_array($aEvent))
  2374. return array();
  2375. $aContent = unserialize($aEvent['content']);
  2376. if(is_array($aContent) && !empty($aContent['text']))
  2377. $aEvent['text'] = $aContent['text'];
  2378. $bDynamicMode = isset($aParams['dynamic_mode']) ? (bool)$aParams['dynamic_mode'] : false;
  2379. $sFormObject = !empty($aParams['form_object']) ? $aParams['form_object'] : 'form_post';
  2380. $sFormDisplay = !empty($aParams['form_display']) ? $aParams['form_display'] : 'form_display_post_edit';
  2381. $oForm = BxDolForm::getObjectInstance($this->_oConfig->getObject($sFormObject), $this->_oConfig->getObject($sFormDisplay), $this->_oTemplate);
  2382. $oForm->setId($this->_oConfig->getHtmlIds('view', 'edit_form') . $iId);
  2383. $aFormInitCheckerParams = array();
  2384. $bValues = !empty($aParams['values']) && is_array($aParams['values']);
  2385. if($bValues) {
  2386. $this->_prepareFormForAutoSubmit($oForm, $aParams['values']);
  2387. $aFormInitCheckerParams = array(array(), array_merge($aEvent, $aParams['values']));
  2388. unset($aParams['values']);
  2389. }
  2390. else {
  2391. $oForm->aFormAttrs['action'] = BX_DOL_URL_ROOT . $this->_oConfig->getBaseUri() . 'edit/' . $iId ;
  2392. if(!empty($aBrowseParams) && is_array($aBrowseParams))
  2393. $oForm->aFormAttrs['action'] = $this->_oConfig->addBrowseParams($oForm->aFormAttrs['action'], $aBrowseParams);
  2394. foreach($oForm->aInputs[$CNF['FIELD_CONTROLS']] as $mixedIndex => $aInput) {
  2395. if(!is_numeric($mixedIndex))
  2396. continue;
  2397. $oForm->aInputs[$CNF['FIELD_CONTROLS']][$mixedIndex]['attrs'] = bx_replace_markers($aInput['attrs'], array(
  2398. 'js_object_view' => $sJsObjectView,
  2399. 'content_id' => $iId
  2400. ));
  2401. }
  2402. $aFormInitCheckerParams = array($aEvent);
  2403. }
  2404. call_user_func_array(array($oForm, 'initChecker'), $aFormInitCheckerParams);
  2405. if($oForm->isSubmittedAndValid()) {
  2406. $aContent = array();
  2407. //--- Process Text ---//
  2408. $sText = $oForm->getCleanValue('text');
  2409. $sText = $this->_prepareTextForSave($sText);
  2410. $bText = !empty($sText);
  2411. unset($oForm->aInputs['text']);
  2412. if($bText)
  2413. $aContent['text'] = $sText;
  2414. $aValsToAdd = array(
  2415. 'content' => serialize($aContent)
  2416. );
  2417. //--- Process Privacy ---//
  2418. $iObjectPrivacyView = (int)$oForm->getCleanValue('object_privacy_view');
  2419. $iObjectPrivacyViewDefault = $this->_oConfig->getPrivacyViewDefault('object');
  2420. if(empty($iObjectPrivacyView))
  2421. $aValsToAdd = array_merge($aValsToAdd, array(
  2422. 'object_privacy_view' => $iObjectPrivacyViewDefault
  2423. ));
  2424. else if($iObjectPrivacyView < 0)
  2425. $aValsToAdd = array_merge($aValsToAdd, array(
  2426. 'owner_id' => abs($iObjectPrivacyView),
  2427. 'object_privacy_view' => $iObjectPrivacyViewDefault
  2428. ));
  2429. if(!$oForm->update($iId, $aValsToAdd))
  2430. return array('message' => _t('_bx_timeline_txt_err_cannot_perform_action'));
  2431. $oMetatags = BxDolMetatags::getObjectInstance($this->_oConfig->getObject('metatags'));
  2432. if($bText)
  2433. $oMetatags->metaAdd($iId, $sText);
  2434. $oMetatags->locationsAddFromForm($iId, $this->_oConfig->CNF['FIELD_LOCATION_PREFIX']);
  2435. $this->getCacheItemObject()->removeAllByPrefix($this->_oConfig->getPrefix('cache_item') . $iId);
  2436. $this->_oDb->deleteCache(array('event_id' => $iId));
  2437. return array(
  2438. 'id' => $iId
  2439. );
  2440. }
  2441. return array(
  2442. 'id' => $iId,
  2443. 'form' => $oForm->getCode($bDynamicMode),
  2444. 'form_id' => $oForm->id,
  2445. 'eval' => $sJsObjectView . '.onEditPost(oData)'
  2446. );
  2447. }
  2448. public function getFormPostObject($aParams)
  2449. {
  2450. $sFormObject = !empty($aParams['form_object']) ? $aParams['form_object'] : 'form_post';
  2451. $sFormDisplay = !empty($aParams['form_display']) ? $aParams['form_display'] : 'form_display_post_add';
  2452. $oForm = BxDolForm::getObjectInstance($this->_oConfig->getObject($sFormObject), $this->_oConfig->getObject($sFormDisplay), $this->_oTemplate);
  2453. /**
  2454. * Note. 'ajax_mode' parameter isn't checked because
  2455. * timeline post form works as Ajax form by default.
  2456. */
  2457. $sParamsKey = 'visibility_autoselect';
  2458. if(isset($aParams[$sParamsKey]) && (bool)$aParams[$sParamsKey] === true)
  2459. $oForm->setVisibilityAutoselect((bool)$aParams[$sParamsKey]);
  2460. $oForm->init();
  2461. return $oForm;
  2462. }
  2463. public function getCmtsObject($sSystem, $iId)
  2464. {
  2465. if(empty($sSystem) || (int)$iId == 0)
  2466. return false;
  2467. $oCmts = BxDolCmts::getObjectInstance($sSystem, $iId, true, $this->_oTemplate);
  2468. if(!$oCmts || !$oCmts->isEnabled())
  2469. return false;
  2470. return $oCmts;
  2471. }
  2472. public function getViewObject($sSystem, $iId)
  2473. {
  2474. if(empty($sSystem) || (int)$iId == 0)
  2475. return false;
  2476. $oView = BxDolView::getObjectInstance($sSystem, $iId, true, $this->_oTemplate);
  2477. if(!$oView || !$oView->isEnabled())
  2478. return false;
  2479. return $oView;
  2480. }
  2481. public function getVoteObject($sSystem, $iId)
  2482. {
  2483. if(empty($sSystem) || (int)$iId == 0)
  2484. return false;
  2485. $oVote = BxDolVote::getObjectInstance($sSystem, $iId, true, $this->_oTemplate);
  2486. if(!$oVote || !$oVote->isEnabled())
  2487. return false;
  2488. return $oVote;
  2489. }
  2490. public function getReactionObject($sSystem, $iId)
  2491. {
  2492. if(empty($sSystem) || (int)$iId == 0)
  2493. return false;
  2494. $oReaction = BxDolVote::getObjectInstance($sSystem, $iId, true, $this->_oTemplate);
  2495. if(!$oReaction || !$oReaction->isEnabled())
  2496. return false;
  2497. return $oReaction;
  2498. }
  2499. public function getScoreObject($sSystem, $iId)
  2500. {
  2501. if(empty($sSystem) || (int)$iId == 0)
  2502. return false;
  2503. $oScore = BxDolScore::getObjectInstance($sSystem, $iId, true, $this->_oTemplate);
  2504. if(!$oScore || !$oScore->isEnabled())
  2505. return false;
  2506. return $oScore;
  2507. }
  2508. public function getReportObject($sSystem, $iId)
  2509. {
  2510. if(empty($sSystem) || (int)$iId == 0)
  2511. return false;
  2512. $oReport = BxDolReport::getObjectInstance($sSystem, $iId, true, $this->_oTemplate);
  2513. if(!$oReport || !$oReport->isEnabled())
  2514. return false;
  2515. return $oReport;
  2516. }
  2517. public function getAttachmentsMenuObject()
  2518. {
  2519. $oMenu = BxDolMenu::getObjectInstance($this->_oConfig->getObject('menu_post_attachments'), $this->_oTemplate);
  2520. $oMenu->addMarkers(array(
  2521. 'js_object' => $this->_oConfig->getJsObject('post'),
  2522. ));
  2523. return $oMenu;
  2524. }
  2525. public function getManageMenuObject()
  2526. {
  2527. return BxDolMenu::getObjectInstance($this->_oConfig->getObject('menu_item_manage'), $this->_oTemplate);
  2528. }
  2529. public function getCacheItemObject()
  2530. {
  2531. $oCacheEngine = bx_instance('BxDolCache' . $this->_oConfig->getCacheItemEngine());
  2532. if(!$oCacheEngine->isAvailable())
  2533. $oCacheEngine = bx_instance('BxDolCacheFile');
  2534. return $oCacheEngine;
  2535. }
  2536. //--- Check permissions methods ---//
  2537. public function serviceCheckAllowedViewForProfile ($aDataEntry, $isPerformAction = false, $iProfileId = false)
  2538. {
  2539. if(!$iProfileId)
  2540. $iProfileId = $this->_iProfileId;
  2541. $CNF = &$this->_oConfig->CNF;
  2542. // moderator and owner always have access
  2543. $iOwnerId = (int)$aDataEntry['owner_id'];
  2544. if(!empty($iProfileId) && (abs($iOwnerId) == (int)$iProfileId || $this->isModerator()))
  2545. return CHECK_ACTION_RESULT_ALLOWED;
  2546. // check ACL
  2547. if($iOwnerId != 0 && ($oOwner = BxDolProfile::getInstanceMagic($iOwnerId)) !== false) {
  2548. $mixedCheckResult = BxDolService::call($oOwner->getModule(), 'check_allowed_with_content_for_profile', array('view', $oOwner->getContentId(), $iProfileId));
  2549. if($mixedCheckResult !== CHECK_ACTION_RESULT_ALLOWED)
  2550. return $mixedCheckResult;
  2551. }
  2552. // check privacy
  2553. if(!empty($CNF['OBJECT_PRIVACY_VIEW'])) {
  2554. $oPrivacy = BxDolPrivacy::getObjectInstance($CNF['OBJECT_PRIVACY_VIEW']);
  2555. if($oPrivacy && !$oPrivacy->check($aDataEntry[$CNF['FIELD_ID']], $iProfileId))
  2556. return _t('_sys_access_denied_to_private_content');
  2557. }
  2558. // check alert to allow custom checks
  2559. $mixedResult = null;
  2560. bx_alert('system', 'check_allowed_view', 0, 0, array('module' => $this->getName(), 'content_info' => $aDataEntry, 'profile_id' => $iProfileId, 'override_result' => &$mixedResult));
  2561. if($mixedResult !== null)
  2562. return $mixedResult;
  2563. return CHECK_ACTION_RESULT_ALLOWED;
  2564. }
  2565. public function isModerator()
  2566. {
  2567. $sModule = $this->getName();
  2568. $iUserId = (int)$this->getUserId();
  2569. $aCheckResult = checkActionModule($iUserId, 'edit', $sModule);
  2570. if($aCheckResult[CHECK_ACTION_RESULT] === CHECK_ACTION_RESULT_ALLOWED)
  2571. return true;
  2572. $aCheckResult = checkActionModule($iUserId, 'delete', $sModule);
  2573. if($aCheckResult[CHECK_ACTION_RESULT] === CHECK_ACTION_RESULT_ALLOWED)
  2574. return true;
  2575. return false;
  2576. }
  2577. public function isAllowedPost($bPerform = false)
  2578. {
  2579. if(isAdmin())
  2580. return true;
  2581. $iUserId = $this->getUserId();
  2582. $aCheckResult = checkActionModule($iUserId, 'post', $this->getName(), $bPerform);
  2583. if($aCheckResult[CHECK_ACTION_RESULT] !== CHECK_ACTION_RESULT_ALLOWED)
  2584. return $aCheckResult[CHECK_ACTION_MESSAGE];
  2585. if(!empty($this->_iOwnerId) && ($oProfileOwner = BxDolProfile::getInstance($this->_iOwnerId)) !== false) {
  2586. if($oProfileOwner->checkAllowedPostInProfile() !== CHECK_ACTION_RESULT_ALLOWED)
  2587. return _t('_sys_txt_access_denied');
  2588. bx_alert($oProfileOwner->getModule(), $this->_oConfig->getUri() . '_post', $oProfileOwner->id(), $iUserId, array('check_result' => &$aCheckResult));
  2589. }
  2590. return $aCheckResult[CHECK_ACTION_RESULT] !== CHECK_ACTION_RESULT_ALLOWED ? $aCheckResult[CHECK_ACTION_MESSAGE] : true;
  2591. }
  2592. public function isAllowedView($aEvent, $bPerform = false)
  2593. {
  2594. $CNF = $this->_oConfig->CNF;
  2595. if((int)$aEvent[$CNF['FIELD_OWNER_ID']] == 0)
  2596. return true;
  2597. $oProfileOwner = BxDolProfile::getInstance($aEvent[$CNF['FIELD_OWNER_ID']]);
  2598. if($oProfileOwner && $oProfileOwner->checkAllowedProfileView() !== CHECK_ACTION_RESULT_ALLOWED)
  2599. return false;
  2600. $oPrivacy = BxDolPrivacy::getObjectInstance($this->_oConfig->getObject('privacy_view'));
  2601. if(!$oPrivacy)
  2602. return true;
  2603. $oPrivacy->setTableFieldAuthor($this->_oConfig->isSystem($aEvent['type'], $aEvent['action']) ? 'owner_id' : 'object_id');
  2604. return $oPrivacy->check($aEvent[$CNF['FIELD_ID']]);
  2605. }
  2606. public function isAllowedEdit($aEvent, $bPerform = false)
  2607. {
  2608. if(!isLogged())
  2609. return false;
  2610. //--- System posts and Reposts cannot be edited at all.
  2611. if(!$this->_oConfig->isCommon($aEvent['type'], $aEvent['action']) || $aEvent['type'] == $this->_oConfig->getPrefix('common_post') . 'repost')
  2612. return false;
  2613. if(isAdmin())
  2614. return true;
  2615. $iUserId = (int)$this->getUserId();
  2616. $iOwnerId = (int)$aEvent['owner_id'];
  2617. $iObjectId = abs((int)$aEvent['object_id']);
  2618. if($iObjectId == $iUserId && $this->_oConfig->isAllowEdit())
  2619. return true;
  2620. $aCheckResult = checkActionModule($iUserId, 'edit', $this->getName(), $bPerform);
  2621. if(!empty($iOwnerId) && ($oProfileOwner = BxDolProfile::getInstance($iOwnerId)) !== false)
  2622. bx_alert($oProfileOwner->getModule(), $this->_oConfig->getUri() . '_edit', $oProfileOwner->id(), $iUserId, array('check_result' => &$aCheckResult));
  2623. return $aCheckResult[CHECK_ACTION_RESULT] !== CHECK_ACTION_RESULT_ALLOWED ? $aCheckResult[CHECK_ACTION_MESSAGE] : true;
  2624. }
  2625. public function isAllowedDelete($aEvent, $bPerform = false)
  2626. {
  2627. if(!isLogged())
  2628. return false;
  2629. if(isAdmin())
  2630. return true;
  2631. $iUserId = (int)$this->getUserId();
  2632. $iOwnerId = (int)$aEvent['owner_id'];
  2633. $iObjectId = abs((int)$aEvent['object_id']);
  2634. if((($iOwnerId == $iUserId && $this->_oConfig->isAllowDelete()) || ($this->_oConfig->isCommon($aEvent['type'], $aEvent['action']) && $iObjectId == $iUserId)))
  2635. return true;
  2636. $aCheckResult = checkActionModule($iUserId, 'delete', $this->getName(), $bPerform);
  2637. if(!empty($iOwnerId) && ($oProfileOwner = BxDolProfile::getInstance($iOwnerId)) !== false)
  2638. bx_alert($oProfileOwner->getModule(), $this->_oConfig->getUri() . '_delete', $oProfileOwner->id(), $iUserId, array('check_result' => &$aCheckResult));
  2639. return $aCheckResult[CHECK_ACTION_RESULT] !== CHECK_ACTION_RESULT_ALLOWED ? $aCheckResult[CHECK_ACTION_MESSAGE] : true;
  2640. }
  2641. public function isAllowedComment($aEvent, $bPerform = false)
  2642. {
  2643. $mixedComments = $this->getCommentsData($aEvent['comments']);
  2644. if($mixedComments === false)
  2645. return false;
  2646. list($sSystem, $iObjectId) = $mixedComments;
  2647. $oCmts = $this->getCmtsObject($sSystem, $iObjectId);
  2648. if($oCmts->isViewAllowed() !== CHECK_ACTION_RESULT_ALLOWED)
  2649. return false;
  2650. $oCmts->addCssJs();
  2651. $bResult = true;
  2652. if(!empty($aEvent['owner_id']) && $this->_oConfig->isCommon($aEvent['type'], $aEvent['action'])) {
  2653. $oProfileOwner = BxDolProfile::getInstance($aEvent['owner_id']);
  2654. if($oProfileOwner !== false) {
  2655. if($oProfileOwner->checkAllowedPostInProfile() !== CHECK_ACTION_RESULT_ALLOWED)
  2656. return false;
  2657. bx_alert($oProfileOwner->getModule(), $this->_oConfig->getUri() . '_comment', $oProfileOwner->id(), (int)$this->getUserId(), array('result' => &$bResult));
  2658. }
  2659. }
  2660. return $bResult;
  2661. }
  2662. public function isAllowedViewCounter($aEvent, $bPerform = false)
  2663. {
  2664. $mixedViews = $this->getViewsData($aEvent['views']);
  2665. if($mixedViews === false)
  2666. return false;
  2667. list($sSystem, $iObjectId) = $mixedViews;
  2668. $oView = $this->getViewObject($sSystem, $iObjectId);
  2669. if(!$oView->isAllowedViewView($bPerform))
  2670. return false;
  2671. $bResult = true;
  2672. if(!empty($aEvent['owner_id']) && ($oProfileOwner = BxDolProfile::getInstance($aEvent['owner_id'])) !== false)
  2673. bx_alert($oProfileOwner->getModule(), $this->_oConfig->getUri() . '_view_counter', $oProfileOwner->id(), (int)$this->getUserId(), array('result' => &$bResult));
  2674. return $bResult;
  2675. }
  2676. public function isAllowedVote($aEvent, $bPerform = false)
  2677. {
  2678. $mixedVotes = $this->getVotesData($aEvent['votes']);
  2679. if($mixedVotes === false)
  2680. return false;
  2681. list($sSystem, $iObjectId) = $mixedVotes;
  2682. $oVote = $this->getVoteObject($sSystem, $iObjectId);
  2683. if(!$oVote->isAllowedVote($bPerform))
  2684. return false;
  2685. $bResult = true;
  2686. if(!empty($aEvent['owner_id']) && ($oProfileOwner = BxDolProfile::getInstance($aEvent['owner_id'])) !== false)
  2687. bx_alert($oProfileOwner->getModule(), $this->_oConfig->getUri() . '_vote', $oProfileOwner->id(), (int)$this->getUserId(), array('result' => &$bResult));
  2688. return $bResult;
  2689. }
  2690. public function isAllowedReaction($aEvent, $bPerform = false)
  2691. {
  2692. $mixedReactions = $this->getReactionsData($aEvent['reactions']);
  2693. if($mixedReactions === false)
  2694. return false;
  2695. list($sSystem, $iObjectId) = $mixedReactions;
  2696. $oReaction = $this->getReactionObject($sSystem, $iObjectId);
  2697. if(!$oReaction->isAllowedVote($bPerform))
  2698. return false;
  2699. $bResult = true;
  2700. if(!empty($aEvent['owner_id']) && ($oProfileOwner = BxDolProfile::getInstance($aEvent['owner_id'])) !== false)
  2701. bx_alert($oProfileOwner->getModule(), $this->_oConfig->getUri() . '_reaction', $oProfileOwner->id(), (int)$this->getUserId(), array('result' => &$bResult));
  2702. return $bResult;
  2703. }
  2704. public function isAllowedScore($aEvent, $bPerform = false)
  2705. {
  2706. $mixedScores = $this->getScoresData($aEvent['scores']);
  2707. if($mixedScores === false)
  2708. return false;
  2709. list($sSystem, $iObjectId) = $mixedScores;
  2710. $oScore = $this->getScoreObject($sSystem, $iObjectId);
  2711. if(!$oScore->isAllowedVote($bPerform))
  2712. return false;
  2713. $bResult = true;
  2714. if(!empty($aEvent['owner_id']) && ($oProfileOwner = BxDolProfile::getInstance($aEvent['owner_id'])) !== false)
  2715. bx_alert($oProfileOwner->getModule(), $this->_oConfig->getUri() . '_score', $oProfileOwner->id(), (int)$this->getUserId(), array('result' => &$bResult));
  2716. return $bResult;
  2717. }
  2718. public function isAllowedReport($aEvent, $bPerform = false)
  2719. {
  2720. $mixedReports = $this->getReportsData($aEvent['reports']);
  2721. if($mixedReports === false)
  2722. return false;
  2723. list($sSystem, $iObjectId) = $mixedReports;
  2724. $oReport = $this->getReportObject($sSystem, $iObjectId);
  2725. if(!$oReport->isAllowedReport($bPerform))
  2726. return false;
  2727. $bResult = true;
  2728. if(!empty($aEvent['owner_id']) && ($oProfileOwner = BxDolProfile::getInstance($aEvent['owner_id'])) !== false)
  2729. bx_alert($oProfileOwner->getModule(), $this->_oConfig->getUri() . '_report', $oProfileOwner->id(), (int)$this->getUserId(), array('result' => &$bResult));
  2730. return $bResult;
  2731. }
  2732. public function isAllowedRepost($aEvent, $bPerform = false)
  2733. {
  2734. $iUserId = (int)$this->getUserId();
  2735. if($iUserId == 0)
  2736. return false;
  2737. $iPrivacy = (int)$aEvent['object_privacy_view'];
  2738. if($iPrivacy >= 0 && !in_array($iPrivacy, array(BX_DOL_PG_ALL, BX_DOL_PG_MEMBERS)))
  2739. return false;
  2740. if(isAdmin())
  2741. return true;
  2742. $aCheckResult = checkActionModule($iUserId, 'repost', $this->getName(), $bPerform);
  2743. if(!empty($aEvent['owner_id']) && ($oProfileOwner = BxDolProfile::getInstance($aEvent['owner_id'])) !== false)
  2744. bx_alert($oProfileOwner->getModule(), $this->_oConfig->getUri() . '_repost', $oProfileOwner->id(), $iUserId, array('check_result' => &$aCheckResult));
  2745. return $aCheckResult[CHECK_ACTION_RESULT] !== CHECK_ACTION_RESULT_ALLOWED ? $aCheckResult[CHECK_ACTION_MESSAGE] : true;
  2746. }
  2747. public function isAllowedSend($aEvent, $bPerform = false)
  2748. {
  2749. if(!$this->_oDb->isEnabledByName('bx_convos'))
  2750. return false;
  2751. if(isAdmin())
  2752. return true;
  2753. $iUserId = (int)$this->getUserId();
  2754. if($iUserId == 0)
  2755. return false;
  2756. $aCheckResult = checkActionModule($iUserId, 'send', $this->getName(), $bPerform);
  2757. if(!empty($aEvent['owner_id']) && ($oProfileOwner = BxDolProfile::getInstance($aEvent['owner_id'])) !== false)
  2758. bx_alert($oProfileOwner->getModule(), $this->_oConfig->getUri() . '_send', $oProfileOwner->id(), $iUserId, array('check_result' => &$aCheckResult));
  2759. return $aCheckResult[CHECK_ACTION_RESULT] !== CHECK_ACTION_RESULT_ALLOWED ? $aCheckResult[CHECK_ACTION_MESSAGE] : true;
  2760. }
  2761. /**
  2762. * Pin - "Pin here" - pin the post on Profile Timeline for profile owner.
  2763. * Can be done by profile owner for himself or by admin for profile owner to see.
  2764. * @param type $aEvent
  2765. * @param type $bPerform
  2766. * @return boolean
  2767. */
  2768. public function isAllowedPin($aEvent, $bPerform = false)
  2769. {
  2770. if((int)$aEvent['pinned'] != 0)
  2771. return false;
  2772. return $this->_isAllowedPin($aEvent, $bPerform);
  2773. }
  2774. public function isAllowedUnpin($aEvent, $bPerform = false)
  2775. {
  2776. if((int)$aEvent['pinned'] == 0)
  2777. return false;
  2778. return $this->_isAllowedPin($aEvent, $bPerform);
  2779. }
  2780. /**
  2781. * Stick - "Pin for All" - pin the post on Public Timeline for everybody to see.
  2782. * Is available for Administrators/Moderators only.
  2783. * @param type $aEvent
  2784. * @param type $bPerform
  2785. * @return boolean
  2786. */
  2787. public function isAllowedStick($aEvent, $bPerform = false)
  2788. {
  2789. if((int)$aEvent['sticked'] != 0)
  2790. return false;
  2791. return $this->_isAllowedStick($aEvent, $bPerform);
  2792. }
  2793. public function isAllowedUnstick($aEvent, $bPerform = false)
  2794. {
  2795. if((int)$aEvent['sticked'] == 0)
  2796. return false;
  2797. return $this->_isAllowedStick($aEvent, $bPerform);
  2798. }
  2799. public function isAllowedPromote($aEvent, $bPerform = false)
  2800. {
  2801. if((int)$aEvent['promoted'] != 0)
  2802. return false;
  2803. return $this->_isAllowedPromote($aEvent, $bPerform);
  2804. }
  2805. public function isAllowedUnpromote($aEvent, $bPerform = false)
  2806. {
  2807. if((int)$aEvent['promoted'] == 0)
  2808. return false;
  2809. return $this->_isAllowedPromote($aEvent, $bPerform);
  2810. }
  2811. public function isAllowedMore($aEvent, $bPerform = false)
  2812. {
  2813. $oMoreMenu = $this->getManageMenuObject();
  2814. $oMoreMenu->setEvent($aEvent);
  2815. return $oMoreMenu->isVisible();
  2816. }
  2817. public function checkAllowedView ($aContentInfo, $isPerformAction = false)
  2818. {
  2819. if(!$this->isAllowedView($aContentInfo, $isPerformAction))
  2820. return _t('_sys_txt_access_denied');
  2821. return CHECK_ACTION_RESULT_ALLOWED;
  2822. }
  2823. public function checkAllowedCommentsView ($aContentInfo, $isPerformAction = false)
  2824. {
  2825. $CNF = $this->_oConfig->CNF;
  2826. $iOwner = (int)$aContentInfo[$CNF['FIELD_OWNER_ID']];
  2827. if($iOwner == 0) //--- in case of Public Timeline.
  2828. return CHECK_ACTION_RESULT_ALLOWED;
  2829. $oOwner = BxDolProfile::getInstance($iOwner);
  2830. if(!$oOwner) //--- in case of non-existed Timeline owner.
  2831. return _t('_sys_txt_access_denied');
  2832. $mixedResult = $oOwner->checkAllowedProfileView();
  2833. if($mixedResult !== CHECK_ACTION_RESULT_ALLOWED)
  2834. return $mixedResult;
  2835. return $this->checkAllowedView($aContentInfo, $isPerformAction);
  2836. }
  2837. public function checkAllowedCommentsPost ($aContentInfo, $isPerformAction = false)
  2838. {
  2839. $sError = '_sys_txt_access_denied';
  2840. $aContentInfo = array_merge($aContentInfo, $this->_oTemplate->getDataCached($aContentInfo));
  2841. if($aContentInfo === false)
  2842. return _t($sError);
  2843. if(!$this->isAllowedComment($aContentInfo, $isPerformAction))
  2844. return _t($sError);
  2845. return CHECK_ACTION_RESULT_ALLOWED;
  2846. }
  2847. public function onPost($iContentId)
  2848. {
  2849. $CNF = &$this->_oConfig->CNF;
  2850. $aEvent = $this->_oDb->getEvents(array('browse' => 'id', 'value' => $iContentId));
  2851. if($this->_oConfig->isSystem($aEvent['type'], $aEvent['action'])) {
  2852. //--- Request event's data from content module and update it in the Timeline DB.
  2853. $this->_oTemplate->getDataCached($aEvent);
  2854. $sPostType = 'system';
  2855. $iSenderId = $iObjectAuthorId = (int)$aEvent['owner_id'];
  2856. }
  2857. else {
  2858. $sPostType = 'common';
  2859. $iSenderId = $iObjectAuthorId = (int)$aEvent['object_id'];
  2860. }
  2861. //--- Event -> Post/Defer for Alerts Engine ---//
  2862. $sAction = ($aEvent[$CNF['FIELD_STATUS']] == BX_TIMELINE_STATUS_AWAITING ? 'defer' : 'post') . '_' . $sPostType;
  2863. bx_alert($this->_oConfig->getObject('alert'), $sAction, $iContentId, $iSenderId, array(
  2864. 'owner_id' => $aEvent['owner_id'],
  2865. 'object_author_id' => $iObjectAuthorId,
  2866. 'privacy_view' => $aEvent['object_privacy_view'],
  2867. ));
  2868. //--- Event -> Post for Alerts Engine ---//
  2869. }
  2870. public function onPublished($iContentId)
  2871. {
  2872. $CNF = &$this->_oConfig->CNF;
  2873. $aEvent = $this->_oDb->getEvents(array('browse' => 'id', 'value' => $iContentId));
  2874. //--- Clear Item cache
  2875. $this->getCacheItemObject()->removeAllByPrefix($this->_oConfig->getPrefix('cache_item') . $iContentId);
  2876. //--- Clear Feed cache
  2877. $this->_oDb->deleteCache(array('context_id' => $aEvent[$CNF['FIELD_OWNER_ID']]));
  2878. $this->onPost($iContentId);
  2879. }
  2880. public function onFailed($iContentId)
  2881. {
  2882. $aEvent = $this->_oDb->getEvents(array('browse' => 'id', 'value' => $iContentId));
  2883. //--- Clear Item cache
  2884. $this->getCacheItemObject()->removeAllByPrefix($this->_oConfig->getPrefix('cache_item') . $iContentId);
  2885. if($this->_oConfig->isSystem($aEvent['type'], $aEvent['action'])) {
  2886. //--- Request event's data from content module and update it in the Timeline DB.
  2887. $this->_oTemplate->getDataCached($aEvent);
  2888. $sPostType = 'system';
  2889. $iSenderId = $iObjectAuthorId = (int)$aEvent['owner_id'];
  2890. }
  2891. else {
  2892. $sPostType = 'common';
  2893. $iSenderId = $iObjectAuthorId = (int)$aEvent['object_id'];
  2894. }
  2895. //--- Event -> Fail for Alerts Engine ---//
  2896. bx_alert($this->_oConfig->getObject('alert'), 'fail_' . $sPostType, $iContentId, $iSenderId, array(
  2897. 'owner_id' => $aEvent['owner_id'],
  2898. 'object_author_id' => $iObjectAuthorId,
  2899. 'privacy_view' => $aEvent['object_privacy_view'],
  2900. ));
  2901. //--- Event -> Post for Alerts Engine ---//
  2902. }
  2903. public function onRepost($iContentId, $aReposted = array())
  2904. {
  2905. $aEvent = $this->_oDb->getEvents(array('browse' => 'id', 'value' => $iContentId));
  2906. if(empty($aReposted)) {
  2907. $aContent = unserialize($aEvent['content']);
  2908. $aReposted = $this->_oDb->getReposted($aContent['type'], $aContent['action'], $aContent['object_id']);
  2909. if(empty($aReposted) || !is_array($aReposted))
  2910. return;
  2911. }
  2912. $iUserId = $this->getUserId();
  2913. $this->_oDb->insertRepostTrack($aEvent['id'], $iUserId, $this->getUserIp(), $aReposted['id']);
  2914. $this->_oDb->updateRepostCounter($aReposted['id'], $aReposted['reposts']);
  2915. //--- Timeline -> Update for Alerts Engine ---//
  2916. bx_alert($this->_oConfig->getObject('alert'), 'repost', $aReposted['id'], $iUserId, array(
  2917. 'privacy_view' => $aEvent['object_privacy_view'],
  2918. 'object_author_id' => $aReposted['owner_id'],
  2919. 'repost_id' => $iContentId,
  2920. ));
  2921. //--- Timeline -> Update for Alerts Engine ---//
  2922. }
  2923. public function onDelete($aEvent)
  2924. {
  2925. $CNF = &$this->_oConfig->CNF;
  2926. $iUserId = $this->getUserId();
  2927. $sCommonPostPrefix = $this->_oConfig->getPrefix('common_post');
  2928. $sCommonPostComment = $this->_oConfig->getObject('comment');
  2929. //--- Delete comments for Common posts.
  2930. if($this->_oConfig->isCommon($aEvent['type'], $aEvent['action'])) {
  2931. $oComments = $this->getCmtsObject($sCommonPostComment, $aEvent[$CNF['FIELD_ID']]);
  2932. if($oComments !== false)
  2933. $oComments->onObjectDelete($aEvent[$CNF['FIELD_ID']]);
  2934. }
  2935. //--- Delete attached photos, videos and links when common event was deleted.
  2936. if($aEvent['type'] == $sCommonPostPrefix . BX_TIMELINE_PARSE_TYPE_POST) {
  2937. $this->_deleteMedia(BX_TIMELINE_MEDIA_PHOTO, $aEvent[$CNF['FIELD_ID']]);
  2938. $this->_deleteMedia(BX_TIMELINE_MEDIA_VIDEO, $aEvent[$CNF['FIELD_ID']]);
  2939. $this->_deleteLinks($aEvent[$CNF['FIELD_ID']]);
  2940. }
  2941. //--- Update parent event when repost event was deleted.
  2942. $bRepost = $aEvent['type'] == $sCommonPostPrefix . BX_TIMELINE_PARSE_TYPE_REPOST;
  2943. if($bRepost) {
  2944. $this->_oDb->deleteRepostTrack($aEvent[$CNF['FIELD_ID']]);
  2945. $aContent = unserialize($aEvent['content']);
  2946. $aReposted = $this->_oDb->getReposted($aContent['type'], $aContent['action'], $aContent['object_id']);
  2947. if(!empty($aReposted) && is_array($aReposted))
  2948. $this->_oDb->updateRepostCounter($aReposted[$CNF['FIELD_ID']], $aReposted['reposts'], -1);
  2949. }
  2950. //--- Find and delete repost events when parent event was deleted.
  2951. $bSystem = $this->_oConfig->isSystem($aEvent['type'], $aEvent['action']);
  2952. $aRepostEvents = $this->_oDb->getEvents(array('browse' => 'reposted_by_descriptor', 'type' => $aEvent['type']));
  2953. foreach($aRepostEvents as $aRepostEvent) {
  2954. $aContent = unserialize($aRepostEvent['content']);
  2955. 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) {
  2956. $oComments = $this->getCmtsObject($sCommonPostComment, $aRepostEvent[$CNF['FIELD_ID']]);
  2957. if($oComments !== false)
  2958. $oComments->onObjectDelete($aRepostEvent[$CNF['FIELD_ID']]);
  2959. bx_alert($this->_oConfig->getObject('alert'), 'delete_repost', $aEvent[$CNF['FIELD_ID']], $iUserId, array(
  2960. 'repost_id' => $aRepostEvent[$CNF['FIELD_ID']],
  2961. ));
  2962. }
  2963. }
  2964. //--- Delete associated meta.
  2965. $oMetatags = BxDolMetatags::getObjectInstance($this->_oConfig->getObject('metatags'));
  2966. $oMetatags->onDeleteContent($aEvent[$CNF['FIELD_ID']]);
  2967. //--- Delete feed cache.
  2968. $this->_oDb->deleteCache(array('event_id' => $aEvent[$CNF['FIELD_ID']]));
  2969. //--- Delete item cache.
  2970. $sCacheItemKey = $this->_oConfig->getCacheItemKey($aEvent[$CNF['FIELD_ID']]);
  2971. $this->getCacheItemObject()->delData($sCacheItemKey);
  2972. //--- Event -> Delete for Alerts Engine ---//
  2973. if($bRepost)
  2974. bx_alert($this->_oConfig->getObject('alert'), 'delete_repost', $aReposted[$CNF['FIELD_ID']], $iUserId, array(
  2975. 'repost_id' => $aEvent[$CNF['FIELD_ID']],
  2976. ));
  2977. else
  2978. bx_alert($this->_oConfig->getObject('alert'), 'delete', $aEvent[$CNF['FIELD_ID']], $iUserId);
  2979. //--- Event -> Delete for Alerts Engine ---//
  2980. }
  2981. public function getParams($sView = '', $sType = '', $iOwnerId = 0, $iStart = 0, $iPerPage = 0, $sFilter = BX_TIMELINE_FILTER_ALL, $aModules = array(), $iTimeline = 0)
  2982. {
  2983. return $this->_prepareParams(array(
  2984. 'view' => $sView,
  2985. 'type' => $sType,
  2986. 'owner_id' => $iOwnerId,
  2987. 'start' => $iStart,
  2988. 'per_page' => $iPerPage,
  2989. 'timeline' => $iTimeline,
  2990. 'filter' => $sFilter,
  2991. 'modules' => $aModules
  2992. ));
  2993. }
  2994. public function getParamsExt($aParams = array())
  2995. {
  2996. return $this->_prepareParams($aParams);
  2997. }
  2998. public function getViewsData(&$aViews)
  2999. {
  3000. if(empty($aViews) || !is_array($aViews))
  3001. return false;
  3002. $sSystem = isset($aViews['system']) ? $aViews['system'] : '';
  3003. $iObjectId = isset($aViews['object_id']) ? (int)$aViews['object_id'] : 0;
  3004. $iCount = isset($aViews['count']) ? (int)$aViews['count'] : 0;
  3005. if($sSystem == '' || $iObjectId == 0)
  3006. return false;
  3007. return array($sSystem, $iObjectId, $iCount);
  3008. }
  3009. public function getVotesData(&$aVotes)
  3010. {
  3011. if(empty($aVotes) || !is_array($aVotes))
  3012. return false;
  3013. $sSystem = isset($aVotes['system']) ? $aVotes['system'] : '';
  3014. $iObjectId = isset($aVotes['object_id']) ? (int)$aVotes['object_id'] : 0;
  3015. $iCount = isset($aVotes['count']) ? (int)$aVotes['count'] : 0;
  3016. if($sSystem == '' || $iObjectId == 0)
  3017. return false;
  3018. return array($sSystem, $iObjectId, $iCount);
  3019. }
  3020. public function getReactionsData(&$aReactions)
  3021. {
  3022. if(empty($aReactions) || !is_array($aReactions))
  3023. return false;
  3024. $sSystem = isset($aReactions['system']) ? $aReactions['system'] : '';
  3025. $iObjectId = isset($aReactions['object_id']) ? (int)$aReactions['object_id'] : 0;
  3026. $iCount = isset($aReactions['count']) ? (int)$aReactions['count'] : 0;
  3027. if($sSystem == '' || $iObjectId == 0)
  3028. return false;
  3029. return array($sSystem, $iObjectId, $iCount);
  3030. }
  3031. public function getScoresData(&$aScores)
  3032. {
  3033. if(empty($aScores) || !is_array($aScores))
  3034. return false;
  3035. $sSystem = isset($aScores['system']) ? $aScores['system'] : '';
  3036. $iObjectId = isset($aScores['object_id']) ? (int)$aScores['object_id'] : 0;
  3037. $iScore = isset($aScores['score']) ? (int)$aScores['score'] : 0;
  3038. if($sSystem == '' || $iObjectId == 0)
  3039. return false;
  3040. return array($sSystem, $iObjectId, $iScore);
  3041. }
  3042. public function getReportsData(&$aReports)
  3043. {
  3044. if(empty($aReports) || !is_array($aReports))
  3045. return false;
  3046. $sSystem = isset($aReports['system']) ? $aReports['system'] : '';
  3047. $iObjectId = isset($aReports['object_id']) ? (int)$aReports['object_id'] : 0;
  3048. $iCount = isset($aReports['count']) ? (int)$aReports['count'] : 0;
  3049. if($sSystem == '' || $iObjectId == 0)
  3050. return false;
  3051. return array($sSystem, $iObjectId, $iCount);
  3052. }
  3053. public function getCommentsData(&$aComments)
  3054. {
  3055. if(empty($aComments) || !is_array($aComments))
  3056. return false;
  3057. $sSystem = isset($aComments['system']) ? $aComments['system'] : '';
  3058. $iObjectId = isset($aComments['object_id']) ? (int)$aComments['object_id'] : 0;
  3059. $iCount = isset($aComments['count']) ? (int)$aComments['count'] : 0;
  3060. if($sSystem == '' || $iObjectId == 0 || ($iCount == 0 && !isLogged()))
  3061. return false;
  3062. return array($sSystem, $iObjectId, $iCount);
  3063. }
  3064. public function getUserInfo($iUserId = 0)
  3065. {
  3066. $iLoggedId = $this->getUserId();
  3067. $iUserId = (int)$iUserId;
  3068. return parent::getUserInfo($iUserId);
  3069. }
  3070. public function getUserInfoWithBadges($iUserId = 0)
  3071. {
  3072. $iLoggedId = $this->getUserId();
  3073. $iUserId = (int)$iUserId;
  3074. return parent::getUserInfoWithBadges($iUserId);
  3075. }
  3076. public function getEventLinks($iEventId)
  3077. {
  3078. $aLinks = $this->_oDb->getLinks($iEventId);
  3079. if(empty($aLinks) || !is_array($aLinks))
  3080. return array();
  3081. $oTranscoder = BxDolTranscoderImage::getObjectInstance($this->_oConfig->getObject('transcoder_photos_preview'));
  3082. $aResult = array();
  3083. foreach($aLinks as $aLink)
  3084. $aResult[] = array(
  3085. 'url' => $aLink['url'],
  3086. 'title' => $aLink['title'],
  3087. 'text' => $aLink['text'],
  3088. 'thumbnail' => (int)$aLink['media_id'] != 0 ? $oTranscoder->getFileUrl($aLink['media_id']) : ''
  3089. );
  3090. return $aResult;
  3091. }
  3092. public function getEventImages($iEventId)
  3093. {
  3094. $aPhotos = $this->_oDb->getMedia(BX_TIMELINE_MEDIA_PHOTO, $iEventId);
  3095. if(empty($aPhotos) || !is_array($aPhotos))
  3096. return array();
  3097. $oTranscoder = BxDolTranscoderImage::getObjectInstance($this->_oConfig->getObject('transcoder_photos_view'));
  3098. $oTranscoderMedium = BxDolTranscoderImage::getObjectInstance($this->_oConfig->getObject('transcoder_photos_medium'));
  3099. $oTranscoderBig = BxDolTranscoderImage::getObjectInstance($this->_oConfig->getObject('transcoder_photos_big'));
  3100. $aResult = array();
  3101. foreach($aPhotos as $iPhotoId) {
  3102. $sPhotoSrc = $oTranscoder->getFileUrl($iPhotoId);
  3103. $sPhotoSrcMedium = $oTranscoderMedium->getFileUrl($iPhotoId);
  3104. $sPhotoSrcBig = $oTranscoderBig->getFileUrl($iPhotoId);
  3105. if(empty($sPhotoSrcMedium) && !empty($sPhotoSrc))
  3106. $sPhotoSrcMedium = $sPhotoSrc;
  3107. if(empty($sPhotoSrcBig) && !empty($sPhotoSrcMedium))
  3108. $sPhotoSrcBig = $sPhotoSrcMedium;
  3109. $aResult[] = array(
  3110. 'id' => $iPhotoId,
  3111. 'src' => $sPhotoSrc,
  3112. 'src_medium' => $sPhotoSrcMedium,
  3113. 'src_orig' => $sPhotoSrcBig,
  3114. );
  3115. }
  3116. return $aResult;
  3117. }
  3118. public function getEventVideos($iEventId)
  3119. {
  3120. $aVideos = $this->_oDb->getMedia(BX_TIMELINE_MEDIA_VIDEO, $iEventId);
  3121. if(empty($aVideos) || !is_array($aVideos))
  3122. return array();
  3123. $oStorage = BxDolStorage::getObjectInstance($this->_oConfig->getObject('storage_videos'));
  3124. $oTranscoderPoster = BxDolTranscoderVideo::getObjectInstance($this->_oConfig->getObject('transcoder_videos_poster'));
  3125. $oTranscoderMp4 = BxDolTranscoderVideo::getObjectInstance($this->_oConfig->getObject('transcoder_videos_mp4'));
  3126. $oTranscoderMp4Hd = BxDolTranscoderVideo::getObjectInstance($this->_oConfig->getObject('transcoder_videos_mp4_hd'));
  3127. $aResult = array();
  3128. foreach($aVideos as $iVideoId) {
  3129. $sVideoUrl = $oStorage->getFileUrlById($iVideoId);
  3130. $aVideoSize = $oTranscoderMp4Hd->getVideoSize($sVideoUrl);
  3131. $sVideoUrlHd = '';
  3132. if(!empty($aVideoSize) && is_array($aVideoSize) && (int)$aVideoSize['h'] >= 720)
  3133. $sVideoUrlHd = $oTranscoderMp4Hd->getFileUrl($iVideoId);
  3134. $aResult[$iVideoId] = array(
  3135. 'id' => $iVideoId,
  3136. 'src_poster' => $oTranscoderPoster->getFileUrl($iVideoId),
  3137. 'src_mp4' => $oTranscoderMp4->getFileUrl($iVideoId),
  3138. 'src_mp4_hd' => $sVideoUrlHd,
  3139. );
  3140. }
  3141. return $aResult;
  3142. }
  3143. /**
  3144. * Protected Methods
  3145. */
  3146. protected function _serviceGetBlockView($iProfileId = 0, $aBrowseParams = array())
  3147. {
  3148. if(empty($iProfileId) && bx_get('profile_id') !== false)
  3149. $iProfileId = bx_process_input(bx_get('profile_id'), BX_DATA_INT);
  3150. if(empty($iProfileId) && isLogged())
  3151. $iProfileId = bx_get_logged_profile_id();
  3152. $aBrowseParams['owner_id'] = $iProfileId;
  3153. $aBlock = $this->_getBlockView($aBrowseParams);
  3154. if(!empty($aBlock))
  3155. return $aBlock;
  3156. return array('content' => MsgBox(_t('_bx_timeline_txt_msg_no_results')));
  3157. }
  3158. protected function _serviceGetBlockViewProfile($sProfileModule = 'bx_persons', $iProfileContentId = 0, $aBrowseParams = array())
  3159. {
  3160. if(empty($sProfileModule))
  3161. return array();
  3162. if(empty($iProfileContentId) && bx_get('id') !== false)
  3163. $iProfileContentId = bx_process_input(bx_get('id'), BX_DATA_INT);
  3164. $oProfile = BxDolProfile::getInstanceByContentAndType($iProfileContentId, $sProfileModule);
  3165. if(empty($oProfile))
  3166. return array();
  3167. $aBrowseParams['owner_id'] = $oProfile->id();
  3168. return $this->_getBlockView($aBrowseParams);
  3169. }
  3170. protected function _serviceGetBlockViews($aBrowseParams = array())
  3171. {
  3172. $aParams = $this->_prepareParams($aBrowseParams);
  3173. $this->_iOwnerId = $aParams['owner_id'];
  3174. return array(
  3175. 'content' => $this->_oTemplate->getViewsBlock($aParams)
  3176. );
  3177. }
  3178. protected function _serviceGetBlockViewHome($aBrowseParams = array())
  3179. {
  3180. $sRssUrl = BX_DOL_URL_ROOT . $this->_oConfig->getBaseUri() . 'rss/' . $aBrowseParams['type'] . '/';
  3181. BxDolTemplate::getInstance()->addPageRssLink(_t('_bx_timeline_page_title_view_home'), $sRssUrl);
  3182. return $this->_serviceGetBlockViewByType($aBrowseParams);
  3183. }
  3184. protected function _serviceGetBlockViewHot($aBrowseParams = array())
  3185. {
  3186. $sRssUrl = BX_DOL_URL_ROOT . $this->_oConfig->getBaseUri() . 'rss/' . $aBrowseParams['type'] . '/';
  3187. BxDolTemplate::getInstance()->addPageRssLink(_t('_bx_timeline_page_title_view_hot'), $sRssUrl);
  3188. return $this->_serviceGetBlockViewByType($aBrowseParams);
  3189. }
  3190. protected function _serviceGetBlockViewByType($aBrowseParams = array())
  3191. {
  3192. $aParams = $this->_prepareParams($aBrowseParams);
  3193. $this->_iOwnerId = $aParams['owner_id'];
  3194. return array(
  3195. 'content' => $this->_oTemplate->getViewBlock($aParams)
  3196. );
  3197. }
  3198. protected function _getBlockPost($iProfileId, $aParams = array())
  3199. {
  3200. $this->_iOwnerId = $iProfileId;
  3201. if($this->isAllowedPost() !== true)
  3202. return array();
  3203. return array(
  3204. 'content' => $this->_oTemplate->getPostBlock($this->_iOwnerId, $aParams)
  3205. );
  3206. }
  3207. protected function _getBlockView($aBrowseParams = array())
  3208. {
  3209. if(empty($aBrowseParams['owner_id']))
  3210. return array();
  3211. $aParams = $this->_prepareParams($aBrowseParams);
  3212. if(empty($aParams['per_page']))
  3213. $aParams['per_page'] = $this->_oConfig->getPerPage('profile');
  3214. $this->_iOwnerId = $aParams['owner_id'];
  3215. $oProfileOwner = BxDolProfile::getInstance($this->_iOwnerId);
  3216. $mixedResult = $oProfileOwner->checkAllowedProfileView();
  3217. if($mixedResult !== CHECK_ACTION_RESULT_ALLOWED)
  3218. return array('content' => MsgBox($mixedResult));
  3219. list($sUserName) = $this->getUserInfo($aParams['owner_id']);
  3220. $sView = $aParams['view'];
  3221. $sRssUrl = BX_DOL_URL_ROOT . $this->_oConfig->getBaseUri() . 'rss/' . BX_BASE_MOD_NTFS_TYPE_OWNER . '/' . $this->_iOwnerId . '/';
  3222. $sJsObject = $this->_oConfig->getJsObjectView($aParams);
  3223. $aMenu = array(
  3224. 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),
  3225. 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)),
  3226. 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')),
  3227. array('id' => $sView . '-get-rss', 'name' => $sView . '-get-rss', 'class' => '', 'link' => $sRssUrl, 'onclick' => '', 'target' => '_blank', 'title' => _t('_bx_timeline_menu_item_get_rss')),
  3228. );
  3229. $sContent = '';
  3230. bx_alert($oProfileOwner->getModule(), $this->_oConfig->getUri() . '_view', $this->_iOwnerId, $this->getUserId(), array('override_content' => &$sContent, 'params' => &$aParams, 'menu' => &$aMenu));
  3231. $oMenu = new BxTemplMenuInteractive(array('template' => 'menu_interactive_vertical.html', 'menu_id'=> $sView . '-view-all', 'menu_items' => $aMenu));
  3232. $oMenu->setSelected('', $sView . '-view-all');
  3233. if (!$sContent)
  3234. $sContent = $this->_oTemplate->getViewBlock($aParams);
  3235. BxDolTemplate::getInstance()->addPageRssLink(_t('_bx_timeline_page_title_view'), $sRssUrl);
  3236. return array('content' => $sContent, 'menu' => $oMenu);
  3237. }
  3238. protected function _getContentForTimelinePost($aEvent, $aContentInfo, $aBrowseParams = array())
  3239. {
  3240. $CNF = &$this->_oConfig->CNF;
  3241. $iId = (int)$aContentInfo[$CNF['FIELD_ID']];
  3242. $sUrl = BX_DOL_URL_ROOT . BxDolPermalinks::getInstance()->permalink('page.php?i=' . $CNF['URI_VIEW_ENTRY'] . '&id=' . $iId);
  3243. $sText = '';
  3244. if(isset($aContentInfo['content'])){
  3245. $aTmp = unserialize($aContentInfo['content']);
  3246. if(isset($aTmp['text']))
  3247. $sText = $aTmp['text'];
  3248. }
  3249. if(empty($sText) && !empty($aContentInfo[$CNF['FIELD_TITLE']]))
  3250. $sText = $aContentInfo[$CNF['FIELD_TITLE']];
  3251. if(!empty($CNF['OBJECT_METATAGS']) && !empty($sText)) {
  3252. $oMetatags = BxDolMetatags::getObjectInstance($CNF['OBJECT_METATAGS']);
  3253. $sText = $oMetatags->metaParse($iId, $sText);
  3254. }
  3255. return array(
  3256. 'sample' => isset($CNF['T']['txt_sample_single_with_article']) ? $CNF['T']['txt_sample_single_with_article'] : $CNF['T']['txt_sample_single'],
  3257. 'sample_wo_article' => $CNF['T']['txt_sample_single'],
  3258. 'sample_action' => isset($CNF['T']['txt_sample_action']) ? $CNF['T']['txt_sample_action'] : '',
  3259. 'url' => $sUrl,
  3260. 'title' => '',
  3261. 'text' => $sText,
  3262. 'links' => $this->getEventLinks($iId),
  3263. 'images' => array(),
  3264. 'images_attach' => $this->getEventImages($iId),
  3265. 'videos' => array(),
  3266. 'videos_attach' => $this->getEventVideos($iId),
  3267. 'files' => array(),
  3268. 'files_attach' => array()
  3269. );
  3270. }
  3271. protected function _isAllowedPin($aEvent, $bPerform = false)
  3272. {
  3273. $iUserId = (int)$this->getUserId();
  3274. if($iUserId == 0)
  3275. return false;
  3276. if(isAdmin() || (int)$aEvent['owner_id'] == $iUserId || ((int)$aEvent['owner_id'] == 0 && $this->_oConfig->isCommon($aEvent['type'], $aEvent['action']) && (int)$aEvent['object_id'] == $iUserId))
  3277. return true;
  3278. $aCheckResult = checkActionModule($iUserId, 'pin', $this->getName(), $bPerform);
  3279. if(!empty($aEvent['owner_id']) && ($oProfileOwner = BxDolProfile::getInstance($aEvent['owner_id'])) !== false)
  3280. bx_alert($oProfileOwner->getModule(), $this->_oConfig->getUri() . '_pin', $oProfileOwner->id(), $iUserId, array('check_result' => &$aCheckResult));
  3281. return $aCheckResult[CHECK_ACTION_RESULT] !== CHECK_ACTION_RESULT_ALLOWED ? $aCheckResult[CHECK_ACTION_MESSAGE] : true;
  3282. }
  3283. protected function _isAllowedStick($aEvent, $bPerform = false)
  3284. {
  3285. $iUserId = (int)$this->getUserId();
  3286. if($iUserId == 0)
  3287. return false;
  3288. if(isAdmin())
  3289. return true;
  3290. $aCheckResult = checkActionModule($iUserId, 'stick', $this->getName(), $bPerform);
  3291. if(!empty($aEvent['owner_id']) && ($oProfileOwner = BxDolProfile::getInstance($aEvent['owner_id'])) !== false)
  3292. bx_alert($oProfileOwner->getModule(), $this->_oConfig->getUri() . '_stick', $oProfileOwner->id(), $iUserId, array('check_result' => &$aCheckResult));
  3293. return $aCheckResult[CHECK_ACTION_RESULT] !== CHECK_ACTION_RESULT_ALLOWED ? $aCheckResult[CHECK_ACTION_MESSAGE] : true;
  3294. }
  3295. protected function _isAllowedPromote($aEvent, $bPerform = false)
  3296. {
  3297. if(isAdmin())
  3298. return true;
  3299. $iUserId = (int)$this->getUserId();
  3300. if($iUserId == 0)
  3301. return false;
  3302. $aCheckResult = checkActionModule($iUserId, 'promote', $this->getName(), $bPerform);
  3303. if(!empty($aEvent['owner_id']) && ($oProfileOwner = BxDolProfile::getInstance($aEvent['owner_id'])) !== false)
  3304. bx_alert($oProfileOwner->getModule(), $this->_oConfig->getUri() . '_promote', $oProfileOwner->id(), $iUserId, array('check_result' => &$aCheckResult));
  3305. return $aCheckResult[CHECK_ACTION_RESULT] !== CHECK_ACTION_RESULT_ALLOWED ? $aCheckResult[CHECK_ACTION_MESSAGE] : true;
  3306. }
  3307. protected function _addLink(&$oForm)
  3308. {
  3309. $iUserId = $this->getUserId();
  3310. $sLink = $oForm->getCleanValue('url');
  3311. $aMatches = array();
  3312. preg_match($this->_oConfig->getPregPattern('url'), $sLink, $aMatches);
  3313. $sLink = (empty($aMatches[2]) ? 'http://' : '') . $aMatches[0];
  3314. $aSiteInfo = bx_get_site_info($sLink, array(
  3315. 'thumbnailUrl' => array('tag' => 'link', 'content_attr' => 'href'),
  3316. 'OGImage' => array('name_attr' => 'property', 'name' => 'og:image'),
  3317. ));
  3318. $sTitle = !empty($aSiteInfo['title']) ? $aSiteInfo['title'] : _t('_Empty');
  3319. $sDescription = !empty($aSiteInfo['description']) ? $aSiteInfo['description'] : _t('_Empty');
  3320. $sMediaUrl = '';
  3321. if(!empty($aSiteInfo['thumbnailUrl']))
  3322. $sMediaUrl = $aSiteInfo['thumbnailUrl'];
  3323. else if(!empty($aSiteInfo['OGImage']))
  3324. $sMediaUrl = $aSiteInfo['OGImage'];
  3325. $iMediaId = 0;
  3326. $oStorage = null;
  3327. if(!empty($sMediaUrl)) {
  3328. $oStorage = BxDolStorage::getObjectInstance($this->_oConfig->getObject('storage_' . BX_TIMELINE_MEDIA_PHOTO . 's'));
  3329. $iMediaId = $oStorage->storeFileFromUrl($sMediaUrl, true, $iUserId);
  3330. }
  3331. $iId = (int)$oForm->insert(array('profile_id' => $iUserId, 'media_id' => $iMediaId, 'url' => $sLink, 'title' => $sTitle, 'text' => $sDescription, 'added' => time()));
  3332. if(!empty($iId)) {
  3333. if(!empty($oStorage) && !empty($iMediaId))
  3334. $oStorage->afterUploadCleanup($iMediaId, $iUserId);
  3335. return array('id' => $iId, 'item' => $this->_oTemplate->getAttachLinkItem($iUserId, $iId));
  3336. }
  3337. return array('message' => _t('_bx_timeline_txt_err_cannot_perform_action'));
  3338. }
  3339. protected function _deleteLinks($iId)
  3340. {
  3341. $aLinks = $this->_oDb->getLinks($iId);
  3342. if(empty($aLinks) || !is_array($aLinks))
  3343. return;
  3344. $oStorage = BxDolStorage::getObjectInstance($this->_oConfig->getObject('storage_photos'));
  3345. foreach($aLinks as $aLink)
  3346. if(!empty($aLink['media_id']))
  3347. $oStorage->deleteFile($aLink['media_id']);
  3348. $this->_oDb->deleteLinks($iId);
  3349. }
  3350. protected function _saveMedia($sType, $iId, $aItemIds)
  3351. {
  3352. if(empty($aItemIds) || !is_array($aItemIds))
  3353. return;
  3354. $iUserId = $this->getUserId();
  3355. $oStorage = BxDolStorage::getObjectInstance($this->_oConfig->getObject('storage_' . strtolower($sType) . 's'));
  3356. foreach($aItemIds as $iItemId)
  3357. if($this->_oDb->saveMedia($sType, $iId, $iItemId))
  3358. $oStorage->afterUploadCleanup($iItemId, $iUserId);
  3359. }
  3360. protected function _deleteMedia($sType, $iId)
  3361. {
  3362. $aItems = $this->_oDb->getMedia($sType, $iId);
  3363. if(empty($aItems) || !is_array($aItems))
  3364. return;
  3365. $oStorage = BxDolStorage::getObjectInstance($this->_oConfig->getObject('storage_' . strtolower($sType) . 's'));
  3366. foreach($aItems as $iItemId)
  3367. $oStorage->deleteFile($iItemId);
  3368. $this->_oDb->deleteMedia($sType, $iId);
  3369. }
  3370. protected function _prepareParams($aParams)
  3371. {
  3372. if(empty($aParams['name']))
  3373. $aParams['name'] = '';
  3374. if(empty($aParams['view']))
  3375. $aParams['view'] = BX_TIMELINE_VIEW_DEFAULT;
  3376. if(empty($aParams['type']))
  3377. $aParams['type'] = BX_TIMELINE_TYPE_DEFAULT;
  3378. if(empty($aParams['owner_id']))
  3379. $aParams['owner_id'] = $this->getUserId();
  3380. if(!isset($aParams['start']) || (int)$aParams['start'] < 0)
  3381. $aParams['start'] = 0;
  3382. if(!isset($aParams['per_page']) || (int)$aParams['per_page'] <= 0)
  3383. $aParams['per_page'] = isset($aParams['per_page_default']) && (int)$aParams['per_page_default'] > 0 ? $aParams['per_page_default'] : $this->_oConfig->getPerPage();
  3384. if(empty($aParams['timeline']) || (int)$aParams['timeline'] < 0)
  3385. $aParams['timeline'] = 0;
  3386. if(empty($aParams['filter']))
  3387. $aParams['filter'] = BX_TIMELINE_FILTER_ALL;
  3388. if(empty($aParams['modules']) || !is_array($aParams['modules']))
  3389. $aParams['modules'] = array();
  3390. if(empty($aParams['blink']) || !is_array($aParams['blink']))
  3391. $aParams['blink'] = array();
  3392. if($this->_oConfig->isHot())
  3393. $aParams['hot'] = $this->_oDb->getHot();
  3394. $aParams = array_merge($aParams, array(
  3395. 'browse' => 'list',
  3396. 'status' => BX_TIMELINE_STATUS_ACTIVE,
  3397. 'dynamic_mode' => false,
  3398. ));
  3399. return $aParams;
  3400. }
  3401. protected function _prepareParamsGet()
  3402. {
  3403. $aParams = array();
  3404. $aParams['name'] = bx_get('name');
  3405. $aParams['name'] = $aParams['name'] !== false ? bx_process_input($aParams['name'], BX_DATA_TEXT) : '';
  3406. $aParams['view'] = bx_get('view');
  3407. $aParams['view'] = $aParams['view'] !== false ? bx_process_input($aParams['view'], BX_DATA_TEXT) : BX_TIMELINE_VIEW_DEFAULT;
  3408. $aParams['type'] = bx_get('type');
  3409. $aParams['type'] = $aParams['type'] !== false ? bx_process_input($aParams['type'], BX_DATA_TEXT) : BX_TIMELINE_TYPE_DEFAULT;
  3410. $aParams['owner_id'] = bx_get('owner_id');
  3411. $aParams['owner_id'] = $aParams['owner_id'] !== false ? bx_process_input($aParams['owner_id'], BX_DATA_INT) : $this->getUserId();
  3412. $aParams['start'] = bx_get('start');
  3413. $aParams['start'] = $aParams['start'] !== false ? bx_process_input($aParams['start'], BX_DATA_INT) : 0;
  3414. $aParams['per_page'] = bx_get('per_page');
  3415. $aParams['per_page'] = $aParams['per_page'] !== false ? bx_process_input($aParams['per_page'], BX_DATA_INT) : $this->_oConfig->getPerPage();
  3416. $aParams['timeline'] = bx_get('timeline');
  3417. $aParams['timeline'] = $aParams['timeline'] !== false ? bx_process_input($aParams['timeline']) : '';
  3418. $aParams['filter'] = bx_get('filter');
  3419. $aParams['filter'] = $aParams['filter'] !== false ? bx_process_input($aParams['filter'], BX_DATA_TEXT) : BX_TIMELINE_FILTER_ALL;
  3420. $aParams['modules'] = bx_get('modules');
  3421. $aParams['modules'] = $aParams['modules'] !== false ? bx_process_input($aParams['modules'], BX_DATA_TEXT) : array();
  3422. $aParams['blink'] = bx_get('blink');
  3423. $aParams['blink'] = $aParams['blink'] !== false ? explode(',', bx_process_input($aParams['blink'], BX_DATA_TEXT)) : array();
  3424. if($this->_oConfig->isHot())
  3425. $aParams['hot'] = $this->_oDb->getHot();
  3426. $aParams = array_merge($aParams, array(
  3427. 'browse' => 'list',
  3428. 'status' => BX_TIMELINE_STATUS_ACTIVE,
  3429. 'dynamic_mode' => true,
  3430. ));
  3431. return $aParams;
  3432. }
  3433. protected function _prepareTextForSave($s)
  3434. {
  3435. return bx_process_input($s, BX_DATA_HTML);
  3436. }
  3437. protected function _prepareFormForAutoSubmit(&$oForm, &$aValues)
  3438. {
  3439. $oForm->aFormAttrs['method'] = BX_DOL_FORM_METHOD_SPECIFIC;
  3440. $oForm->aParams['csrf']['disable'] = true;
  3441. if(!empty($oForm->aParams['db']['submit_name'])) {
  3442. $sSubmitName = $sSubmitValue = false;
  3443. if(is_array($oForm->aParams['db']['submit_name'])) {
  3444. foreach ($oForm->aParams['db']['submit_name'] as $sName) {
  3445. if(isset($oForm->aInputs[$sName])) {
  3446. $sSubmitName = $sName;
  3447. $sSubmitValue = $oForm->aInputs[$sName]['value'];
  3448. break;
  3449. }
  3450. else if(isset($oForm->aInputs['controls']))
  3451. foreach($oForm->aInputs['controls'] as $mixedKey => $mixedInput)
  3452. if(is_numeric($mixedKey) && isset($mixedInput['name']) && $mixedInput['name'] == $sName) {
  3453. $sSubmitName = $sName;
  3454. $sSubmitValue = $mixedInput['value'];
  3455. break 2;
  3456. }
  3457. }
  3458. }
  3459. else {
  3460. $sName = $oForm->aParams['db']['submit_name'];
  3461. if(isset($oForm->aInputs[$sName])) {
  3462. $sSubmitName = $sName;
  3463. $sSubmitValue = $oForm->aInputs[$sName]['value'];
  3464. }
  3465. else if(isset($oForm->aInputs['controls']))
  3466. foreach($oForm->aInputs['controls'] as $mixedKey => $mixedInput)
  3467. if(is_numeric($mixedKey) && isset($mixedInput['name']) && $mixedInput['name'] == $sName) {
  3468. $sSubmitName = $sName;
  3469. $sSubmitValue = $mixedInput['value'];
  3470. break;
  3471. }
  3472. }
  3473. if($sSubmitName && $sSubmitValue)
  3474. $aValues[$sSubmitName] = $sSubmitValue;
  3475. }
  3476. }
  3477. protected function _getFieldValue($sField, $iContentId)
  3478. {
  3479. $CNF = &$this->_oConfig->CNF;
  3480. if(empty($CNF[$sField]))
  3481. return false;
  3482. $aEvent = $this->_oDb->getEvents(array('browse' => 'id', 'value' => $iContentId));
  3483. if(empty($aEvent) || empty($aEvent[$CNF[$sField]]))
  3484. return false;
  3485. return $aEvent[$CNF[$sField]];
  3486. }
  3487. /**
  3488. * Returns records for React Jot using OAuth2
  3489. * @param int $iProfileId
  3490. * @param string $sPage
  3491. * @param string $sTab
  3492. * @param int $iStart
  3493. * @param int $iPerPage
  3494. * @return array
  3495. */
  3496. public function serviceGetUserPosts($iProfileId = 0, $sPage = 'home', $sTab = 'hot', $iStart = 0, $iPerPage = 0)
  3497. {
  3498. $iProfileId = (int)$iProfileId ? (int)$iProfileId : bx_get_logged_profile_id();
  3499. if(empty($iProfileId))
  3500. return array(
  3501. 'code' => 1,
  3502. 'result' => array(),
  3503. 'message' => _t('_bx_timeline_txt_msg_no_profile_id'),
  3504. 'page' => $sPage,
  3505. 'tab' => $sTab
  3506. );
  3507. $sType = BX_TIMELINE_TYPE_OWNER_AND_CONNECTIONS;
  3508. $sView = BX_TIMELINE_VIEW_DEFAULT;
  3509. $sFilter = BX_TIMELINE_FILTER_ALL;
  3510. $aModules = array();
  3511. switch($sPage){
  3512. case 'profile':
  3513. $sType = BX_BASE_MOD_NTFS_TYPE_OWNER;
  3514. $sFilter = BX_TIMELINE_FILTER_OWNER;
  3515. break;
  3516. default:
  3517. if ($this -> _oDb -> isModuleByName($sPage))
  3518. $aModules = array($sPage);
  3519. }
  3520. switch($sTab)
  3521. {
  3522. case 'latest':
  3523. $sType = BX_BASE_MOD_NTFS_TYPE_PUBLIC;
  3524. break;
  3525. case 'popular':
  3526. $sType = BX_TIMELINE_TYPE_HOT;
  3527. break;
  3528. case 'feed':
  3529. $sType = BX_TIMELINE_TYPE_OWNER_AND_CONNECTIONS;
  3530. break;
  3531. default:
  3532. if ($this -> _oDb -> isModuleByName($sTab))
  3533. $aModules = array($sTab);
  3534. }
  3535. $aParams = $this->getParams($sView, $sType, $iProfileId, $iStart, $iPerPage, $sFilter, $aModules);
  3536. $aEvents = $this->_oDb->getEvents($aParams);
  3537. $iCount = $this->_oDb->getEvents(array_merge($aParams, array('count' => true)));
  3538. if(empty($aEvents) || !is_array($aEvents))
  3539. return array(
  3540. 'code' => 0,
  3541. 'result' => array(),
  3542. 'message' => _t('_bx_timeline_txt_msg_no_results'),
  3543. 'page' => $sPage,
  3544. 'tab' => $sTab
  3545. );
  3546. $aBrowseParams = array();
  3547. $aItems = array();
  3548. foreach($aEvents as $aEvent) {
  3549. $aResult = $this->_oTemplate->getData($aEvent, $aBrowseParams);
  3550. if($aResult === false)
  3551. continue;
  3552. $oOwnerProfile = BxDolProfile::getInstance($aResult['owner_id']);
  3553. $aFiles = array();
  3554. $aContent = &$aResult['content'];
  3555. if (!empty($aContent['image']))
  3556. $aFiles['images'] = array_values($aContent['images']);
  3557. if (!empty($aContent['images_attach']))
  3558. $aFiles['images'] = array_values($aContent['images_attach']);
  3559. if (!empty($aContent['videos']))
  3560. $aFiles['videos'] = array_values($aContent['videos']);
  3561. else
  3562. if (!empty($aContent['videos_attach']))
  3563. $aFiles['videos'] = array_values($aContent['videos_attach']);
  3564. if (!empty($aContent['files']))
  3565. $aFiles['files'] = array_values($aContent['files']);
  3566. else
  3567. if (!empty($aContent['files_attach']))
  3568. $aFiles['files'] = array_values($aContent['files_attach']);
  3569. $aItems[$aEvent['id']] = array_merge(array(
  3570. 'owner' => array(
  3571. 'icon' => $oOwnerProfile -> getThumb(),
  3572. 'name' => $oOwnerProfile -> getDisplayName(),
  3573. 'url' => $oOwnerProfile -> getUrl()
  3574. ),
  3575. 'sample' => !empty($aResult['sample']) ? _t($aResult['sample']) : _t('_bx_timeline_txt_sample'),
  3576. 'sample_action' => !empty($aResult['sample_action']) ? _t($aResult['sample_action']) : _t('_bx_timeline_txt_added_sample'),
  3577. 'url' => isset($aResult['url']) ? $aResult['url'] : '',
  3578. 'raw' => isset($aContent['raw']) ? strip_tags($aContent['raw']) : '',
  3579. 'text' => isset($aContent['text']) ? strip_tags($aContent['text']) : '',
  3580. 'views' => isset($aResult['views']['count']) ? (int)$aResult['views']['count'] : 0,
  3581. 'votes' => isset($aResult['votes']['count']) ? (int)$aResult['votes']['count'] : 0,
  3582. 'reactions' => isset($aResult['reactions']['count']) ? (int)$aResult['reactions']['count'] : 0,
  3583. 'scores' => isset($aResult['scores']['count']) ? (int)$aResult['scores']['count'] : 0,
  3584. 'reports' => isset($aResult['reports']['count']) ? (int)$aResult['reports']['count'] : 0,
  3585. 'comments' => isset($aResult['comments']['count']) ? (int)$aResult['comments']['count'] : 0,
  3586. 'date' => isset($aResult['date']) ? $aResult['date'] : $aEvent['date'],
  3587. 'type' => stripos($aEvent['type'], 'timeline') !== false ? 'bx_timeline' : $aEvent['type'],
  3588. 'event_type' => $aEvent['type'],
  3589. 'id' => $aEvent['id'],
  3590. 'content' => $aResult['content'],
  3591. 'title' => isset($aResult['title']) ? _t($aResult['title']) : '',
  3592. 'description' => isset($aResult['description']) ? $aResult['description'] : ''
  3593. ), $aFiles);
  3594. }
  3595. return array(
  3596. 'result' => $aItems,
  3597. 'code' => 0,
  3598. 'message' => '',
  3599. 'page' => $sPage,
  3600. 'tab' => $sTab,
  3601. 'total' => $iCount,
  3602. 'start' => (int)$iStart
  3603. );
  3604. }
  3605. }
  3606. /** @} */