BxTimelineModule.php 141 KB

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