BxTimelineModule.php 144 KB

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