BxTimelineModule.php 141 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649
  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)->getCodeDynamic();
  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. $CNF = &$this->_oConfig->CNF;
  2513. $iUserId = $this->getUserId();
  2514. $sCommonPostPrefix = $this->_oConfig->getPrefix('common_post');
  2515. $sCommonPostComment = $this->_oConfig->getObject('comment');
  2516. //--- Delete comments for Common posts.
  2517. if($this->_oConfig->isCommon($aEvent['type'], $aEvent['action'])) {
  2518. $oComments = $this->getCmtsObject($sCommonPostComment, $aEvent[$CNF['FIELD_ID']]);
  2519. if($oComments !== false)
  2520. $oComments->onObjectDelete($aEvent[$CNF['FIELD_ID']]);
  2521. }
  2522. //--- Delete attached photos, videos and links when common event was deleted.
  2523. if($aEvent['type'] == $sCommonPostPrefix . BX_TIMELINE_PARSE_TYPE_POST) {
  2524. $this->_deleteMedia(BX_TIMELINE_MEDIA_PHOTO, $aEvent[$CNF['FIELD_ID']]);
  2525. $this->_deleteMedia(BX_TIMELINE_MEDIA_VIDEO, $aEvent[$CNF['FIELD_ID']]);
  2526. $this->_deleteLinks($aEvent[$CNF['FIELD_ID']]);
  2527. }
  2528. //--- Update parent event when repost event was deleted.
  2529. $bRepost = $aEvent['type'] == $sCommonPostPrefix . BX_TIMELINE_PARSE_TYPE_REPOST;
  2530. if($bRepost) {
  2531. $this->_oDb->deleteRepostTrack($aEvent[$CNF['FIELD_ID']]);
  2532. $aContent = unserialize($aEvent['content']);
  2533. $aReposted = $this->_oDb->getReposted($aContent['type'], $aContent['action'], $aContent['object_id']);
  2534. if(!empty($aReposted) && is_array($aReposted))
  2535. $this->_oDb->updateRepostCounter($aReposted[$CNF['FIELD_ID']], $aReposted['reposts'], -1);
  2536. }
  2537. //--- Find and delete repost events when parent event was deleted.
  2538. $bSystem = $this->_oConfig->isSystem($aEvent['type'], $aEvent['action']);
  2539. $aRepostEvents = $this->_oDb->getEvents(array('browse' => 'reposted_by_descriptor', 'type' => $aEvent['type']));
  2540. foreach($aRepostEvents as $aRepostEvent) {
  2541. $aContent = unserialize($aRepostEvent['content']);
  2542. if(isset($aContent['type']) && $aContent['type'] == $aEvent['type'] && isset($aContent['object_id']) && (($bSystem && (int)$aContent['object_id'] == (int)$aEvent['object_id']) || (!$bSystem && (int)$aContent['object_id'] == (int)$aEvent[$CNF['FIELD_ID']])) && (int)$this->_oDb->deleteEvent(array('id' => (int)$aRepostEvent[$CNF['FIELD_ID']])) > 0) {
  2543. $oComments = $this->getCmtsObject($sCommonPostComment, $aRepostEvent[$CNF['FIELD_ID']]);
  2544. if($oComments !== false)
  2545. $oComments->onObjectDelete($aRepostEvent[$CNF['FIELD_ID']]);
  2546. bx_alert($this->_oConfig->getObject('alert'), 'delete_repost', $aEvent[$CNF['FIELD_ID']], $iUserId, array(
  2547. 'repost_id' => $aRepostEvent[$CNF['FIELD_ID']],
  2548. ));
  2549. }
  2550. }
  2551. //--- Delete associated meta.
  2552. $oMetatags = BxDolMetatags::getObjectInstance($this->_oConfig->getObject('metatags'));
  2553. $oMetatags->onDeleteContent($aEvent[$CNF['FIELD_ID']]);
  2554. //--- Delete feed cache.
  2555. $this->_oDb->deleteCache(array('event_id' => $aEvent[$CNF['FIELD_ID']]));
  2556. //--- Delete item cache.
  2557. $sCacheItemKey = $this->_oConfig->getCacheItemKey($aEvent[$CNF['FIELD_ID']]);
  2558. $this->getCacheItemObject()->delData($sCacheItemKey);
  2559. //--- Event -> Delete for Alerts Engine ---//
  2560. if($bRepost)
  2561. bx_alert($this->_oConfig->getObject('alert'), 'delete_repost', $aReposted[$CNF['FIELD_ID']], $iUserId, array(
  2562. 'repost_id' => $aEvent[$CNF['FIELD_ID']],
  2563. ));
  2564. else
  2565. bx_alert($this->_oConfig->getObject('alert'), 'delete', $aEvent[$CNF['FIELD_ID']], $iUserId);
  2566. //--- Event -> Delete for Alerts Engine ---//
  2567. }
  2568. public function getParams($sView = '', $sType = '', $iOwnerId = 0, $iStart = 0, $iPerPage = 0, $sFilter = BX_TIMELINE_FILTER_ALL, $aModules = array(), $iTimeline = 0)
  2569. {
  2570. return $this->_prepareParams(array(
  2571. 'view' => $sView,
  2572. 'type' => $sType,
  2573. 'owner_id' => $iOwnerId,
  2574. 'start' => $iStart,
  2575. 'per_page' => $iPerPage,
  2576. 'timeline' => $iTimeline,
  2577. 'filter' => $sFilter,
  2578. 'modules' => $aModules
  2579. ));
  2580. }
  2581. public function getParamsExt($aParams = array())
  2582. {
  2583. return $this->_prepareParams($aParams);
  2584. }
  2585. public function getViewsData(&$aViews)
  2586. {
  2587. if(empty($aViews) || !is_array($aViews))
  2588. return false;
  2589. $sSystem = isset($aViews['system']) ? $aViews['system'] : '';
  2590. $iObjectId = isset($aViews['object_id']) ? (int)$aViews['object_id'] : 0;
  2591. $iCount = isset($aViews['count']) ? (int)$aViews['count'] : 0;
  2592. if($sSystem == '' || $iObjectId == 0)
  2593. return false;
  2594. return array($sSystem, $iObjectId, $iCount);
  2595. }
  2596. public function getVotesData(&$aVotes)
  2597. {
  2598. if(empty($aVotes) || !is_array($aVotes))
  2599. return false;
  2600. $sSystem = isset($aVotes['system']) ? $aVotes['system'] : '';
  2601. $iObjectId = isset($aVotes['object_id']) ? (int)$aVotes['object_id'] : 0;
  2602. $iCount = isset($aVotes['count']) ? (int)$aVotes['count'] : 0;
  2603. if($sSystem == '' || $iObjectId == 0)
  2604. return false;
  2605. return array($sSystem, $iObjectId, $iCount);
  2606. }
  2607. public function getReactionsData(&$aReactions)
  2608. {
  2609. if(empty($aReactions) || !is_array($aReactions))
  2610. return false;
  2611. $sSystem = isset($aReactions['system']) ? $aReactions['system'] : '';
  2612. $iObjectId = isset($aReactions['object_id']) ? (int)$aReactions['object_id'] : 0;
  2613. $iCount = isset($aReactions['count']) ? (int)$aReactions['count'] : 0;
  2614. if($sSystem == '' || $iObjectId == 0)
  2615. return false;
  2616. return array($sSystem, $iObjectId, $iCount);
  2617. }
  2618. public function getScoresData(&$aScores)
  2619. {
  2620. if(empty($aScores) || !is_array($aScores))
  2621. return false;
  2622. $sSystem = isset($aScores['system']) ? $aScores['system'] : '';
  2623. $iObjectId = isset($aScores['object_id']) ? (int)$aScores['object_id'] : 0;
  2624. $iScore = isset($aScores['score']) ? (int)$aScores['score'] : 0;
  2625. if($sSystem == '' || $iObjectId == 0)
  2626. return false;
  2627. return array($sSystem, $iObjectId, $iScore);
  2628. }
  2629. public function getReportsData(&$aReports)
  2630. {
  2631. if(empty($aReports) || !is_array($aReports))
  2632. return false;
  2633. $sSystem = isset($aReports['system']) ? $aReports['system'] : '';
  2634. $iObjectId = isset($aReports['object_id']) ? (int)$aReports['object_id'] : 0;
  2635. $iCount = isset($aReports['count']) ? (int)$aReports['count'] : 0;
  2636. if($sSystem == '' || $iObjectId == 0)
  2637. return false;
  2638. return array($sSystem, $iObjectId, $iCount);
  2639. }
  2640. public function getCommentsData(&$aComments)
  2641. {
  2642. if(empty($aComments) || !is_array($aComments))
  2643. return false;
  2644. $sSystem = isset($aComments['system']) ? $aComments['system'] : '';
  2645. $iObjectId = isset($aComments['object_id']) ? (int)$aComments['object_id'] : 0;
  2646. $iCount = isset($aComments['count']) ? (int)$aComments['count'] : 0;
  2647. if($sSystem == '' || $iObjectId == 0 || ($iCount == 0 && !isLogged()))
  2648. return false;
  2649. return array($sSystem, $iObjectId, $iCount);
  2650. }
  2651. public function getUserInfo($iUserId = 0)
  2652. {
  2653. $iLoggedId = $this->getUserId();
  2654. $iUserId = (int)$iUserId;
  2655. return parent::getUserInfo($iUserId);
  2656. }
  2657. /**
  2658. * Protected Methods
  2659. */
  2660. protected function _serviceGetBlockView($iProfileId = 0, $aBrowseParams = array())
  2661. {
  2662. if(empty($iProfileId) && bx_get('profile_id') !== false)
  2663. $iProfileId = bx_process_input(bx_get('profile_id'), BX_DATA_INT);
  2664. if(empty($iProfileId) && isLogged())
  2665. $iProfileId = bx_get_logged_profile_id();
  2666. $aBrowseParams['owner_id'] = $iProfileId;
  2667. $aBlock = $this->_getBlockView($aBrowseParams);
  2668. if(!empty($aBlock))
  2669. return $aBlock;
  2670. return array('content' => MsgBox(_t('_bx_timeline_txt_msg_no_results')));
  2671. }
  2672. protected function _serviceGetBlockViewProfile($sProfileModule = 'bx_persons', $iProfileContentId = 0, $aBrowseParams = array())
  2673. {
  2674. if(empty($sProfileModule))
  2675. return array();
  2676. if(empty($iProfileContentId) && bx_get('id') !== false)
  2677. $iProfileContentId = bx_process_input(bx_get('id'), BX_DATA_INT);
  2678. $oProfile = BxDolProfile::getInstanceByContentAndType($iProfileContentId, $sProfileModule);
  2679. if(empty($oProfile))
  2680. return array();
  2681. $aBrowseParams['owner_id'] = $oProfile->id();
  2682. return $this->_getBlockView($aBrowseParams);
  2683. }
  2684. protected function _serviceGetBlockViewHome($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_home'), $sRssUrl);
  2688. return $this->_serviceGetBlockViewByType($aBrowseParams);
  2689. }
  2690. protected function _serviceGetBlockViewHot($aBrowseParams = array())
  2691. {
  2692. $sRssUrl = BX_DOL_URL_ROOT . $this->_oConfig->getBaseUri() . 'rss/' . $aBrowseParams['type'] . '/';
  2693. BxDolTemplate::getInstance()->addPageRssLink(_t('_bx_timeline_page_title_view_hot'), $sRssUrl);
  2694. return $this->_serviceGetBlockViewByType($aBrowseParams);
  2695. }
  2696. protected function _serviceGetBlockViewByType($aBrowseParams = array())
  2697. {
  2698. $aParams = $this->_prepareParams($aBrowseParams);
  2699. $this->_iOwnerId = $aParams['owner_id'];
  2700. return array(
  2701. 'content' => $this->_oTemplate->getViewBlock($aParams)
  2702. );
  2703. }
  2704. protected function _getBlockPost($iProfileId, $aParams = array())
  2705. {
  2706. $this->_iOwnerId = $iProfileId;
  2707. if($this->isAllowedPost() !== true)
  2708. return array();
  2709. return array(
  2710. 'content' => $this->_oTemplate->getPostBlock($this->_iOwnerId, $aParams)
  2711. );
  2712. }
  2713. protected function _getBlockView($aBrowseParams = array())
  2714. {
  2715. if(empty($aBrowseParams['owner_id']))
  2716. return array();
  2717. $aParams = $this->_prepareParams($aBrowseParams);
  2718. if(empty($aParams['per_page']))
  2719. $aParams['per_page'] = $this->_oConfig->getPerPage('profile');
  2720. $this->_iOwnerId = $aParams['owner_id'];
  2721. $oProfileOwner = BxDolProfile::getInstance($this->_iOwnerId);
  2722. $mixedResult = $oProfileOwner->checkAllowedProfileView();
  2723. if($mixedResult !== CHECK_ACTION_RESULT_ALLOWED)
  2724. return array('content' => MsgBox($mixedResult));
  2725. list($sUserName) = $this->getUserInfo($aParams['owner_id']);
  2726. $sView = $aParams['view'];
  2727. $sRssUrl = BX_DOL_URL_ROOT . $this->_oConfig->getBaseUri() . 'rss/' . BX_BASE_MOD_NTFS_TYPE_OWNER . '/' . $this->_iOwnerId . '/';
  2728. $sJsObject = $this->_oConfig->getJsObjectView($aParams);
  2729. $aMenu = array(
  2730. 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),
  2731. 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)),
  2732. 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')),
  2733. array('id' => $sView . '-get-rss', 'name' => $sView . '-get-rss', 'class' => '', 'link' => $sRssUrl, 'onclick' => '', 'target' => '_blank', 'title' => _t('_bx_timeline_menu_item_get_rss')),
  2734. );
  2735. $sContent = '';
  2736. bx_alert($oProfileOwner->getModule(), $this->_oConfig->getUri() . '_view', $this->_iOwnerId, $this->getUserId(), array('override_content' => &$sContent, 'params' => &$aParams, 'menu' => &$aMenu));
  2737. $oMenu = new BxTemplMenuInteractive(array('template' => 'menu_interactive_vertical.html', 'menu_id'=> $sView . '-view-all', 'menu_items' => $aMenu));
  2738. $oMenu->setSelected('', $sView . '-view-all');
  2739. if (!$sContent)
  2740. $sContent = $this->_oTemplate->getViewBlock($aParams);
  2741. BxDolTemplate::getInstance()->addPageRssLink(_t('_bx_timeline_page_title_view'), $sRssUrl);
  2742. return array('content' => $sContent, 'menu' => $oMenu);
  2743. }
  2744. protected function _getContentForTimelinePost($aEvent, $aContentInfo, $aBrowseParams = array())
  2745. {
  2746. $CNF = &$this->_oConfig->CNF;
  2747. $sUrl = BX_DOL_URL_ROOT . BxDolPermalinks::getInstance()->permalink('page.php?i=' . $CNF['URI_VIEW_ENTRY'] . '&id=' . $aContentInfo[$CNF['FIELD_ID']]);
  2748. $sText = '';
  2749. if(isset($aContentInfo['content'])){
  2750. $aTmp = unserialize($aContentInfo['content']);
  2751. if(isset($aTmp['text']))
  2752. $sText = $aTmp['text'];
  2753. }
  2754. if(empty($sText) && !empty($aContentInfo[$CNF['FIELD_TITLE']]))
  2755. $sText = $aContentInfo[$CNF['FIELD_TITLE']];
  2756. if(!empty($CNF['OBJECT_METATAGS']) && !empty($sText)) {
  2757. $oMetatags = BxDolMetatags::getObjectInstance($CNF['OBJECT_METATAGS']);
  2758. $sText = $oMetatags->metaParse($aContentInfo[$CNF['FIELD_ID']], $sText);
  2759. }
  2760. return array(
  2761. 'sample' => isset($CNF['T']['txt_sample_single_with_article']) ? $CNF['T']['txt_sample_single_with_article'] : $CNF['T']['txt_sample_single'],
  2762. 'sample_wo_article' => $CNF['T']['txt_sample_single'],
  2763. 'sample_action' => isset($CNF['T']['txt_sample_action']) ? $CNF['T']['txt_sample_action'] : '',
  2764. 'url' => $sUrl,
  2765. 'title' => '',
  2766. 'text' => $sText,
  2767. 'images' => array(),
  2768. 'videos' => array()
  2769. );
  2770. }
  2771. protected function _isAllowedPin($aEvent, $bPerform = false)
  2772. {
  2773. $iUserId = (int)$this->getUserId();
  2774. if($iUserId == 0)
  2775. return false;
  2776. if(isAdmin() || (int)$aEvent['owner_id'] == $iUserId || ((int)$aEvent['owner_id'] == 0 && $this->_oConfig->isCommon($aEvent['type'], $aEvent['action']) && (int)$aEvent['object_id'] == $iUserId))
  2777. return true;
  2778. $aCheckResult = checkActionModule($iUserId, 'pin', $this->getName(), $bPerform);
  2779. if(!empty($aEvent['owner_id']) && ($oProfileOwner = BxDolProfile::getInstance($aEvent['owner_id'])) !== false)
  2780. bx_alert($oProfileOwner->getModule(), $this->_oConfig->getUri() . '_pin', $oProfileOwner->id(), $iUserId, array('check_result' => &$aCheckResult));
  2781. return $aCheckResult[CHECK_ACTION_RESULT] !== CHECK_ACTION_RESULT_ALLOWED ? $aCheckResult[CHECK_ACTION_MESSAGE] : true;
  2782. }
  2783. protected function _isAllowedStick($aEvent, $bPerform = false)
  2784. {
  2785. $iUserId = (int)$this->getUserId();
  2786. if($iUserId == 0)
  2787. return false;
  2788. if(isAdmin())
  2789. return true;
  2790. $aCheckResult = checkActionModule($iUserId, 'stick', $this->getName(), $bPerform);
  2791. if(!empty($aEvent['owner_id']) && ($oProfileOwner = BxDolProfile::getInstance($aEvent['owner_id'])) !== false)
  2792. bx_alert($oProfileOwner->getModule(), $this->_oConfig->getUri() . '_stick', $oProfileOwner->id(), $iUserId, array('check_result' => &$aCheckResult));
  2793. return $aCheckResult[CHECK_ACTION_RESULT] !== CHECK_ACTION_RESULT_ALLOWED ? $aCheckResult[CHECK_ACTION_MESSAGE] : true;
  2794. }
  2795. protected function _isAllowedPromote($aEvent, $bPerform = false)
  2796. {
  2797. if(isAdmin())
  2798. return true;
  2799. $iUserId = (int)$this->getUserId();
  2800. if($iUserId == 0)
  2801. return false;
  2802. $aCheckResult = checkActionModule($iUserId, 'promote', $this->getName(), $bPerform);
  2803. if(!empty($aEvent['owner_id']) && ($oProfileOwner = BxDolProfile::getInstance($aEvent['owner_id'])) !== false)
  2804. bx_alert($oProfileOwner->getModule(), $this->_oConfig->getUri() . '_promote', $oProfileOwner->id(), $iUserId, array('check_result' => &$aCheckResult));
  2805. return $aCheckResult[CHECK_ACTION_RESULT] !== CHECK_ACTION_RESULT_ALLOWED ? $aCheckResult[CHECK_ACTION_MESSAGE] : true;
  2806. }
  2807. protected function _addLink(&$oForm)
  2808. {
  2809. $iUserId = $this->getUserId();
  2810. $sLink = $oForm->getCleanValue('url');
  2811. $aMatches = array();
  2812. preg_match($this->_oConfig->getPregPattern('url'), $sLink, $aMatches);
  2813. $sLink = (empty($aMatches[2]) ? 'http://' : '') . $aMatches[0];
  2814. $aSiteInfo = bx_get_site_info($sLink, array(
  2815. 'thumbnailUrl' => array('tag' => 'link', 'content_attr' => 'href'),
  2816. 'OGImage' => array('name_attr' => 'property', 'name' => 'og:image'),
  2817. ));
  2818. $sTitle = !empty($aSiteInfo['title']) ? $aSiteInfo['title'] : _t('_Empty');
  2819. $sDescription = !empty($aSiteInfo['description']) ? $aSiteInfo['description'] : _t('_Empty');
  2820. $sMediaUrl = '';
  2821. if(!empty($aSiteInfo['thumbnailUrl']))
  2822. $sMediaUrl = $aSiteInfo['thumbnailUrl'];
  2823. else if(!empty($aSiteInfo['OGImage']))
  2824. $sMediaUrl = $aSiteInfo['OGImage'];
  2825. $iMediaId = 0;
  2826. $oStorage = null;
  2827. if(!empty($sMediaUrl)) {
  2828. $oStorage = BxDolStorage::getObjectInstance($this->_oConfig->getObject('storage_' . BX_TIMELINE_MEDIA_PHOTO . 's'));
  2829. $iMediaId = $oStorage->storeFileFromUrl($sMediaUrl, true, $iUserId);
  2830. }
  2831. $iId = (int)$oForm->insert(array('profile_id' => $iUserId, 'media_id' => $iMediaId, 'url' => $sLink, 'title' => $sTitle, 'text' => $sDescription, 'added' => time()));
  2832. if(!empty($iId)) {
  2833. if(!empty($oStorage) && !empty($iMediaId))
  2834. $oStorage->afterUploadCleanup($iMediaId, $iUserId);
  2835. return array('id' => $iId, 'item' => $this->_oTemplate->getAttachLinkItem($iUserId, $iId));
  2836. }
  2837. return array('message' => _t('_bx_timeline_txt_err_cannot_perform_action'));
  2838. }
  2839. protected function _deleteLinks($iId)
  2840. {
  2841. $aLinks = $this->_oDb->getLinks($iId);
  2842. if(empty($aLinks) || !is_array($aLinks))
  2843. return;
  2844. $oStorage = BxDolStorage::getObjectInstance($this->_oConfig->getObject('storage_photos'));
  2845. foreach($aLinks as $aLink)
  2846. if(!empty($aLink['media_id']))
  2847. $oStorage->deleteFile($aLink['media_id']);
  2848. $this->_oDb->deleteLinks($iId);
  2849. }
  2850. protected function _saveMedia($sType, $iId, $aItemIds)
  2851. {
  2852. if(empty($aItemIds) || !is_array($aItemIds))
  2853. return;
  2854. $iUserId = $this->getUserId();
  2855. $oStorage = BxDolStorage::getObjectInstance($this->_oConfig->getObject('storage_' . strtolower($sType) . 's'));
  2856. foreach($aItemIds as $iItemId)
  2857. if($this->_oDb->saveMedia($sType, $iId, $iItemId))
  2858. $oStorage->afterUploadCleanup($iItemId, $iUserId);
  2859. }
  2860. protected function _deleteMedia($sType, $iId)
  2861. {
  2862. $aItems = $this->_oDb->getMedia($sType, $iId);
  2863. if(empty($aItems) || !is_array($aItems))
  2864. return;
  2865. $oStorage = BxDolStorage::getObjectInstance($this->_oConfig->getObject('storage_' . strtolower($sType) . 's'));
  2866. foreach($aItems as $iItemId)
  2867. $oStorage->deleteFile($iItemId);
  2868. $this->_oDb->deleteMedia($sType, $iId);
  2869. }
  2870. protected function _prepareParams($aParams)
  2871. {
  2872. if(empty($aParams['name']))
  2873. $aParams['name'] = '';
  2874. if(empty($aParams['view']))
  2875. $aParams['view'] = BX_TIMELINE_VIEW_DEFAULT;
  2876. if(empty($aParams['type']))
  2877. $aParams['type'] = BX_TIMELINE_TYPE_DEFAULT;
  2878. if(empty($aParams['owner_id']))
  2879. $aParams['owner_id'] = $this->getUserId();
  2880. if(!isset($aParams['start']) || (int)$aParams['start'] < 0)
  2881. $aParams['start'] = 0;
  2882. if(!isset($aParams['per_page']) || (int)$aParams['per_page'] <= 0)
  2883. $aParams['per_page'] = isset($aParams['per_page_default']) && (int)$aParams['per_page_default'] > 0 ? $aParams['per_page_default'] : $this->_oConfig->getPerPage();
  2884. if(empty($aParams['timeline']) || (int)$aParams['timeline'] < 0)
  2885. $aParams['timeline'] = 0;
  2886. if(empty($aParams['filter']))
  2887. $aParams['filter'] = BX_TIMELINE_FILTER_ALL;
  2888. if(empty($aParams['modules']) || !is_array($aParams['modules']))
  2889. $aParams['modules'] = array();
  2890. if(empty($aParams['blink']) || !is_array($aParams['blink']))
  2891. $aParams['blink'] = array();
  2892. if($this->_oConfig->isHot())
  2893. $aParams['hot'] = $this->_oDb->getHot();
  2894. $aParams = array_merge($aParams, array(
  2895. 'browse' => 'list',
  2896. 'status' => BX_TIMELINE_STATUS_ACTIVE
  2897. ));
  2898. return $aParams;
  2899. }
  2900. protected function _prepareParamsGet()
  2901. {
  2902. $aParams = array();
  2903. $aParams['name'] = bx_get('name');
  2904. $aParams['name'] = $aParams['name'] !== false ? bx_process_input($aParams['name'], BX_DATA_TEXT) : '';
  2905. $aParams['view'] = bx_get('view');
  2906. $aParams['view'] = $aParams['view'] !== false ? bx_process_input($aParams['view'], BX_DATA_TEXT) : BX_TIMELINE_VIEW_DEFAULT;
  2907. $aParams['type'] = bx_get('type');
  2908. $aParams['type'] = $aParams['type'] !== false ? bx_process_input($aParams['type'], BX_DATA_TEXT) : BX_TIMELINE_TYPE_DEFAULT;
  2909. $aParams['owner_id'] = bx_get('owner_id');
  2910. $aParams['owner_id'] = $aParams['owner_id'] !== false ? bx_process_input($aParams['owner_id'], BX_DATA_INT) : $this->getUserId();
  2911. $aParams['start'] = bx_get('start');
  2912. $aParams['start'] = $aParams['start'] !== false ? bx_process_input($aParams['start'], BX_DATA_INT) : 0;
  2913. $aParams['per_page'] = bx_get('per_page');
  2914. $aParams['per_page'] = $aParams['per_page'] !== false ? bx_process_input($aParams['per_page'], BX_DATA_INT) : $this->_oConfig->getPerPage();
  2915. $aParams['timeline'] = bx_get('timeline');
  2916. $aParams['timeline'] = $aParams['timeline'] !== false ? bx_process_input($aParams['timeline'], BX_DATA_INT) : 0;
  2917. $aParams['filter'] = bx_get('filter');
  2918. $aParams['filter'] = $aParams['filter'] !== false ? bx_process_input($aParams['filter'], BX_DATA_TEXT) : BX_TIMELINE_FILTER_ALL;
  2919. $aParams['modules'] = bx_get('modules');
  2920. $aParams['modules'] = $aParams['modules'] !== false ? bx_process_input($aParams['modules'], BX_DATA_TEXT) : array();
  2921. $aParams['blink'] = bx_get('blink');
  2922. $aParams['blink'] = $aParams['blink'] !== false ? explode(',', bx_process_input($aParams['blink'], BX_DATA_TEXT)) : array();
  2923. if($this->_oConfig->isHot())
  2924. $aParams['hot'] = $this->_oDb->getHot();
  2925. $aParams = array_merge($aParams, array(
  2926. 'browse' => 'list',
  2927. 'status' => BX_TIMELINE_STATUS_ACTIVE,
  2928. 'dynamic_mode' => true,
  2929. ));
  2930. return $aParams;
  2931. }
  2932. protected function _prepareTextForSave($s)
  2933. {
  2934. return bx_process_input($s, BX_DATA_HTML);
  2935. }
  2936. protected function _getFieldValue($sField, $iContentId)
  2937. {
  2938. $CNF = &$this->_oConfig->CNF;
  2939. if(empty($CNF[$sField]))
  2940. return false;
  2941. $aEvent = $this->_oDb->getEvents(array('browse' => 'id', 'value' => $iContentId));
  2942. if(empty($aEvent) || empty($aEvent[$CNF[$sField]]))
  2943. return false;
  2944. return $aEvent[$CNF[$sField]];
  2945. }
  2946. /**
  2947. * Returns records for React Jot using OAuth2
  2948. * @param int $iProfileId
  2949. * @param string $sPage
  2950. * @param string $sTab
  2951. * @param int $iStart
  2952. * @param int $iPerPage
  2953. * @return array
  2954. */
  2955. public function serviceGetUserPosts($iProfileId = 0, $sPage = 'home', $sTab = 'hot', $iStart = 0, $iPerPage = 0)
  2956. {
  2957. $iProfileId = (int)$iProfileId ? (int)$iProfileId : bx_get_logged_profile_id();
  2958. if(empty($iProfileId))
  2959. return array(
  2960. 'code' => 1,
  2961. 'result' => array(),
  2962. 'message' => _t('_bx_timeline_txt_msg_no_profile_id'),
  2963. 'page' => $sPage,
  2964. 'tab' => $sTab
  2965. );
  2966. $sType = BX_TIMELINE_TYPE_OWNER_AND_CONNECTIONS;
  2967. $sView = BX_TIMELINE_VIEW_DEFAULT;
  2968. $sFilter = BX_TIMELINE_FILTER_ALL;
  2969. $aModules = array();
  2970. switch($sPage){
  2971. case 'profile':
  2972. $sType = BX_BASE_MOD_NTFS_TYPE_OWNER;
  2973. $sFilter = BX_TIMELINE_FILTER_OWNER;
  2974. break;
  2975. default:
  2976. if ($this -> _oDb -> isModuleByName($sPage))
  2977. $aModules = array($sPage);
  2978. }
  2979. switch($sTab)
  2980. {
  2981. case 'latest':
  2982. $sType = BX_BASE_MOD_NTFS_TYPE_PUBLIC;
  2983. break;
  2984. case 'popular':
  2985. $sType = BX_TIMELINE_TYPE_HOT;
  2986. break;
  2987. case 'feed':
  2988. $sType = BX_TIMELINE_TYPE_OWNER_AND_CONNECTIONS;
  2989. break;
  2990. default:
  2991. if ($this -> _oDb -> isModuleByName($sTab))
  2992. $aModules = array($sTab);
  2993. }
  2994. $aParams = $this->getParams($sView, $sType, $iProfileId, $iStart, $iPerPage, $sFilter, $aModules);
  2995. $aData = $this->_oDb->getEvents($aParams, true);
  2996. list($aEvents, $iCount) = $aData;
  2997. if(empty($aEvents) || !is_array($aEvents))
  2998. return array(
  2999. 'code' => 0,
  3000. 'result' => array(),
  3001. 'message' => _t('_bx_timeline_txt_msg_no_results'),
  3002. 'page' => $sPage,
  3003. 'tab' => $sTab
  3004. );
  3005. $aBrowseParams = array();
  3006. $aItems = array();
  3007. foreach($aEvents as $aEvent) {
  3008. $aResult = $this->_oTemplate->getData($aEvent, $aBrowseParams);
  3009. if($aResult === false)
  3010. continue;
  3011. $oOwnerProfile = BxDolProfile::getInstance($aResult['owner_id']);
  3012. $aFiles = array();
  3013. $aContent = &$aResult['content'];
  3014. if (!empty($aContent['image']))
  3015. $aFiles['images'] = array_values($aContent['images']);
  3016. if (!empty($aContent['images_attach']))
  3017. $aFiles['images'] = array_values($aContent['images_attach']);
  3018. if (!empty($aContent['videos']))
  3019. $aFiles['videos'] = array_values($aContent['videos']);
  3020. else
  3021. if (!empty($aContent['videos_attach']))
  3022. $aFiles['videos'] = array_values($aContent['videos_attach']);
  3023. if (!empty($aContent['files']))
  3024. $aFiles['files'] = array_values($aContent['files']);
  3025. else
  3026. if (!empty($aContent['files_attach']))
  3027. $aFiles['files'] = array_values($aContent['files_attach']);
  3028. $aItems[$aEvent['id']] = array_merge(array(
  3029. 'owner' => array(
  3030. 'icon' => $oOwnerProfile -> getThumb(),
  3031. 'name' => $oOwnerProfile -> getDisplayName(),
  3032. 'url' => $oOwnerProfile -> getUrl()
  3033. ),
  3034. 'sample' => !empty($aResult['sample']) ? _t($aResult['sample']) : _t('_bx_timeline_txt_sample'),
  3035. 'sample_action' => !empty($aResult['sample_action']) ? _t($aResult['sample_action']) : _t('_bx_timeline_txt_added_sample'),
  3036. 'url' => isset($aResult['url']) ? $aResult['url'] : '',
  3037. 'raw' => isset($aContent['raw']) ? strip_tags($aContent['raw']) : '',
  3038. 'text' => isset($aContent['text']) ? strip_tags($aContent['text']) : '',
  3039. 'views' => isset($aResult['views']['count']) ? (int)$aResult['views']['count'] : 0,
  3040. 'votes' => isset($aResult['votes']['count']) ? (int)$aResult['votes']['count'] : 0,
  3041. 'reactions' => isset($aResult['reactions']['count']) ? (int)$aResult['reactions']['count'] : 0,
  3042. 'scores' => isset($aResult['scores']['count']) ? (int)$aResult['scores']['count'] : 0,
  3043. 'reports' => isset($aResult['reports']['count']) ? (int)$aResult['reports']['count'] : 0,
  3044. 'comments' => isset($aResult['comments']['count']) ? (int)$aResult['comments']['count'] : 0,
  3045. 'date' => isset($aResult['date']) ? $aResult['date'] : $aEvent['date'],
  3046. 'type' => stripos($aEvent['type'], 'timeline') !== FALSE ? 'bx_timeline' : $aEvent['type'],
  3047. 'event_type' => $aEvent['type'],
  3048. 'id' => $aEvent['id'],
  3049. 'content' => $aResult['content'],
  3050. 'title' => isset($aResult['title']) ? _t($aResult['title']) : '',
  3051. 'description' => isset($aResult['description']) ? $aResult['description'] : ''
  3052. ), $aFiles);
  3053. }
  3054. return array(
  3055. 'result' => $aItems,
  3056. 'code' => 0,
  3057. 'message' => '',
  3058. 'page' => $sPage,
  3059. 'tab' => $sTab,
  3060. 'total' => $iCount,
  3061. 'start' => (int)$iStart
  3062. );
  3063. }
  3064. }
  3065. /** @} */