BxTimelineModule.php 107 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776
  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_MEDIA_PHOTO', 'photo');
  30. define('BX_TIMELINE_MEDIA_VIDEO', 'video');
  31. //--- Video Auto Play
  32. define('BX_TIMELINE_VAP_OFF', 'off');
  33. define('BX_TIMELINE_VAP_ON_MUTE', 'on_mute');
  34. define('BX_TIMELINE_VAP_ON', 'on');
  35. class BxTimelineModule extends BxBaseModNotificationsModule implements iBxDolContentInfoService
  36. {
  37. protected $_sJsPostObject;
  38. protected $_sJsViewObject;
  39. protected $_aPostElements;
  40. protected $_sJsOutlineObject;
  41. protected $_sDividerTemplate;
  42. protected $_sBalloonTemplate;
  43. protected $_sCmtPostTemplate;
  44. protected $_sCmtViewTemplate;
  45. protected $_sCmtTemplate;
  46. /**
  47. * Constructor
  48. */
  49. function __construct($aModule)
  50. {
  51. parent::__construct($aModule);
  52. }
  53. /**
  54. * ACTION METHODS
  55. */
  56. public function actionVideo($iEventId, $iVideoId)
  57. {
  58. $aEvent = $this->_oDb->getEvents(array('browse' => 'id', 'value' => $iEventId));
  59. if(empty($aEvent) || !is_array($aEvent))
  60. return;
  61. $aData = $this->_oTemplate->getData($aEvent);
  62. if($aData === false || !isset($aData['content']['videos'][$iVideoId]))
  63. return;
  64. $oTemplate = $this->_oTemplate;
  65. $oTemplate->setPageNameIndex (BX_PAGE_CLEAR);
  66. $oTemplate->setPageContent ('page_main_code', $this->_oTemplate->getVideo($aEvent, $aData['content']['videos'][$iVideoId]));
  67. $oTemplate->getPageCode();
  68. }
  69. public function actionPost()
  70. {
  71. $this->_iOwnerId = bx_process_input(bx_get('owner_id'), BX_DATA_INT);
  72. $mixedAllowed = $this->isAllowedPost(true);
  73. if($mixedAllowed !== true)
  74. return echoJson(array('message' => strip_tags($mixedAllowed)));
  75. echoJson($this->getFormPost());
  76. }
  77. public function actionEdit($iId)
  78. {
  79. $this->_iOwnerId = bx_process_input(bx_get('owner_id'), BX_DATA_INT);
  80. $mixedAllowed = $this->isAllowedPost(true);
  81. if($mixedAllowed !== true)
  82. return echoJson(array('message' => strip_tags($mixedAllowed)));
  83. echoJson($this->getFormEdit($iId, array('dynamic_mode' => true)));
  84. }
  85. function actionPin()
  86. {
  87. $this->_iOwnerId = bx_process_input(bx_get('owner_id'), BX_DATA_INT);
  88. $iId = bx_process_input(bx_get('id'), BX_DATA_INT);
  89. $aEvent = $this->_oDb->getEvents(array('browse' => 'id', 'value' => $iId));
  90. $mixedAllowed = $this->{'isAllowed' . ((int)$aEvent['pinned'] == 0 ? 'Pin' : 'Unpin')}($aEvent, true);
  91. if($mixedAllowed !== true)
  92. return echoJson(array('code' => 1, 'message' => strip_tags($mixedAllowed)));
  93. $aEvent['pinned'] = (int)$aEvent['pinned'] == 0 ? time() : 0;
  94. if(!$this->_oDb->updateEvent(array('pinned' => $aEvent['pinned']), array('id' => $iId)))
  95. return echoJson(array('code' => 2));
  96. echoJson(array(
  97. 'code' => 0,
  98. 'id' => $iId,
  99. 'eval' => $this->_oConfig->getJsObject('view') . '.onPinPost(oData)'
  100. ));
  101. }
  102. function actionPromote()
  103. {
  104. $this->_iOwnerId = bx_process_input(bx_get('owner_id'), BX_DATA_INT);
  105. $iId = bx_process_input(bx_get('id'), BX_DATA_INT);
  106. $aEvent = $this->_oDb->getEvents(array('browse' => 'id', 'value' => $iId));
  107. $mixedAllowed = $this->{'isAllowed' . ((int)$aEvent['promoted'] == 0 ? 'Promote' : 'Unpromote')}($aEvent, true);
  108. if($mixedAllowed !== true)
  109. return echoJson(array('code' => 1, 'message' => strip_tags($mixedAllowed)));
  110. $aEvent['promoted'] = (int)$aEvent['promoted'] == 0 ? time() : 0;
  111. if(!$this->_oDb->updateEvent(array('promoted' => $aEvent['promoted']), array('id' => $iId)))
  112. return echoJson(array('code' => 2));
  113. echoJson(array(
  114. 'code' => 0,
  115. 'message' => _t('_bx_timeline_txt_msg_performed_action')
  116. ));
  117. }
  118. function actionDelete()
  119. {
  120. $this->_iOwnerId = bx_process_input(bx_get('owner_id'), BX_DATA_INT);
  121. $aEvent = $this->_oDb->getEvents(array('browse' => 'id', 'value' => bx_process_input(bx_get('id'), BX_DATA_INT)));
  122. $mixedAllowed = $this->isAllowedDelete($aEvent, true);
  123. if($mixedAllowed !== true)
  124. return echoJson(array('code' => 1, 'message' => strip_tags($mixedAllowed)));
  125. if(!$this->deleteEvent($aEvent))
  126. return echoJson(array('code' => 2));
  127. echoJson(array(
  128. 'code' => 0,
  129. 'id' => $aEvent['id'],
  130. 'eval' => $this->_oConfig->getJsObject('view') . '.onDeletePost(oData)'
  131. ));
  132. }
  133. public function actionRepost()
  134. {
  135. $iAuthorId = $this->getUserId();
  136. $iOwnerId = bx_process_input(bx_get('owner_id'), BX_DATA_INT);
  137. $aContent = array(
  138. 'type' => bx_process_input(bx_get('type'), BX_DATA_TEXT),
  139. 'action' => bx_process_input(bx_get('action'), BX_DATA_TEXT),
  140. 'object_id' => bx_process_input(bx_get('object_id'), BX_DATA_INT),
  141. );
  142. $aReposted = $this->_oDb->getReposted($aContent['type'], $aContent['action'], $aContent['object_id']);
  143. if(empty($aReposted) || !is_array($aReposted)) {
  144. echoJson(array('code' => 1, 'message' => _t('_bx_timeline_txt_err_cannot_repost')));
  145. return;
  146. }
  147. $mixedAllowed = $this->isAllowedRepost($aReposted, true);
  148. if($mixedAllowed !== true) {
  149. echoJson(array('code' => 2, 'message' => strip_tags($mixedAllowed)));
  150. return;
  151. }
  152. $bReposted = $this->_oDb->isReposted($aReposted['id'], $iOwnerId, $iAuthorId);
  153. if($bReposted) {
  154. echoJson(array('code' => 3, 'message' => _t('_bx_timeline_txt_err_already_reposted')));
  155. return;
  156. }
  157. $iId = $this->_oDb->insertEvent(array(
  158. 'owner_id' => $iOwnerId,
  159. 'type' => $this->_oConfig->getPrefix('common_post') . 'repost',
  160. 'action' => '',
  161. 'object_id' => $iAuthorId,
  162. 'object_privacy_view' => $this->_oConfig->getPrivacyViewDefault('object'),
  163. 'content' => serialize($aContent),
  164. 'title' => '',
  165. 'description' => ''
  166. ));
  167. if(empty($iId)) {
  168. echoJson(array('code' => 4, 'message' => _t('_bx_timeline_txt_err_cannot_repost')));
  169. return;
  170. }
  171. $this->onRepost($iId, $aReposted);
  172. $aReposted = $this->_oDb->getReposted($aContent['type'], $aContent['action'], $aContent['object_id']);
  173. $sCounter = $this->_oTemplate->getRepostCounter($aReposted);
  174. echoJson(array(
  175. 'code' => 0,
  176. 'message' => _t('_bx_timeline_txt_msg_success_repost'),
  177. 'count' => $aReposted['reposts'],
  178. 'counter' => $sCounter,
  179. 'disabled' => !$bReposted
  180. ));
  181. }
  182. function actionGetPost()
  183. {
  184. $this->_iOwnerId = bx_process_input(bx_get('owner_id'), BX_DATA_INT);
  185. $sJsObject = bx_process_input(bx_get('js_object'));
  186. if(empty($sJsObject))
  187. $sJsObject = $this->_oConfig->getJsObject('post');
  188. $sView = bx_process_input(bx_get('view'));
  189. $sType = bx_process_input(bx_get('type'));
  190. $iId = bx_process_input(bx_get('id'), BX_DATA_INT);
  191. $bAfpsLoading = (int)bx_get('afps_loading') === 1;
  192. $aEvent = $this->_oDb->getEvents(array('browse' => 'id', 'value' => $iId));
  193. if(empty($aEvent) || !is_array($aEvent))
  194. return echoJson(array());
  195. /**
  196. * Note. Disabled for now, because Own posts on Timelines of Following members
  197. * became visible on posts' author Dashboard Timeline.
  198. */
  199. //if($bAfpsLoading && $this->_iOwnerId != $aEvent['owner_id'])
  200. // return echoJson(array('message' => _t('_bx_timeline_txt_msg_posted')));
  201. echoJson(array(
  202. 'id' => $aEvent['id'],
  203. 'view' => $sView,
  204. 'item' => $this->_oTemplate->getPost($aEvent, array(
  205. 'view' => $sView,
  206. 'type' => !empty($sType) ? $sType : BX_TIMELINE_TYPE_DEFAULT,
  207. 'owner_id' => $this->_iOwnerId,
  208. 'dynamic_mode' => true
  209. )),
  210. 'eval' => $sJsObject . "._onGetPost(oData)"
  211. ));
  212. }
  213. function actionGetPosts()
  214. {
  215. $aParams = $this->_prepareParamsGet();
  216. list($sItems, $sLoadMore, $sBack, $sEmpty) = $this->_oTemplate->getPosts($aParams);
  217. echoJson(array(
  218. 'view' => $aParams['view'],
  219. 'items' => $sItems,
  220. 'load_more' => $sLoadMore,
  221. 'back' => $sBack,
  222. 'empty' => $sEmpty,
  223. 'eval' => $this->_oConfig->getJsObject('view') . "._onGetPosts(oData)"
  224. ));
  225. }
  226. public function actionGetPostForm()
  227. {
  228. $this->_iOwnerId = bx_process_input(bx_get('owner_id'), BX_DATA_INT);
  229. $sType = bx_process_input(bx_get('type'));
  230. echoJson($this->getFormPost(array(
  231. 'type' => $sType,
  232. 'form_display' => $this->_oConfig->getPostFormDisplay($sType)
  233. )));
  234. }
  235. public function actionGetEditForm($iId)
  236. {
  237. $this->_iOwnerId = bx_process_input(bx_get('owner_id'), BX_DATA_INT);
  238. echoJson($this->getFormEdit($iId, array('dynamic_mode' => true)));
  239. }
  240. public function actionGetComments()
  241. {
  242. $this->_iOwnerId = bx_process_input(bx_get('owner_id'), BX_DATA_INT);
  243. $sSystem = bx_process_input(bx_get('system'), BX_DATA_TEXT);
  244. $iId = bx_process_input(bx_get('id'), BX_DATA_INT);
  245. $sComments = $this->_oTemplate->getComments($sSystem, $iId, true);
  246. echoJson(array('content' => $sComments));
  247. }
  248. public function actionAddAttachLink()
  249. {
  250. $sUrl = bx_process_input(bx_get('url'));
  251. if(empty($sUrl))
  252. return echoJson(array());
  253. echoJson($this->addAttachLink(array(
  254. 'url' => $sUrl
  255. )));
  256. }
  257. public function actionDeleteAttachLink()
  258. {
  259. $iUserId = $this->getUserId();
  260. $iLinkId = bx_process_input(bx_get('id'), BX_DATA_INT);
  261. if(empty($iLinkId)) {
  262. echoJson(array());
  263. return;
  264. }
  265. $aLink = $this->_oDb->getUnusedLinks($iUserId, $iLinkId);
  266. if(empty($aLink) || !is_array($aLink)) {
  267. echoJson(array());
  268. return;
  269. }
  270. if(!empty($aLink['media_id']))
  271. BxDolStorage::getObjectInstance($this->_oConfig->getObject('storage_photos'))->deleteFile($aLink['media_id']);
  272. $aResult = array();
  273. if($this->_oDb->deleteUnusedLinks($iUserId, $iLinkId))
  274. $aResult = array('code' => 0);
  275. else
  276. $aResult = array('code' => 1, 'message' => _t('_bx_timeline_form_post_input_link_err_delete'));
  277. echoJson($aResult);
  278. }
  279. public function actionGetAttachLinkForm()
  280. {
  281. echo $this->_oTemplate->getAttachLinkForm();
  282. }
  283. public function actionSubmitAttachLinkForm()
  284. {
  285. echoJson($this->getFormAttachLink());
  286. }
  287. public function actionGetRepostedBy()
  288. {
  289. $iRepostedId = bx_process_input(bx_get('id'), BX_DATA_INT);
  290. echo $this->_oTemplate->getRepostedBy($iRepostedId);
  291. }
  292. public function actionGetItemBrief()
  293. {
  294. echo BxDolPage::getObjectInstance($this->_oConfig->getObject('page_item_brief'), $this->_oTemplate)->getCode();
  295. }
  296. public function actionResumeLiveUpdate($sType, $iOwnerId)
  297. {
  298. $sKey = $this->_oConfig->getLiveUpdateKey($sType, $iOwnerId);
  299. bx_import('BxDolSession');
  300. BxDolSession::getInstance()->unsetValue($sKey, $iOwnerId);
  301. }
  302. public function actionPauseLiveUpdate($sType, $iOwnerId)
  303. {
  304. $sKey = $this->_oConfig->getLiveUpdateKey($sType, $iOwnerId);
  305. bx_import('BxDolSession');
  306. BxDolSession::getInstance()->setValue($sKey, 1);
  307. }
  308. function actionRss()
  309. {
  310. $aArgs = func_get_args();
  311. $sType = array_shift($aArgs);
  312. $iOwnerId = 0;
  313. switch($sType) {
  314. case BX_BASE_MOD_NTFS_TYPE_OWNER:
  315. $iOwnerId = array_shift($aArgs);
  316. list($sUserName) = $this->getUserInfo($iOwnerId);
  317. $sRssCaption = _t('_bx_timeline_txt_rss_caption', $sUserName);
  318. $sRssLink = $this->_oConfig->getViewUrl($iOwnerId);
  319. break;
  320. case BX_BASE_MOD_NTFS_TYPE_PUBLIC:
  321. $sRssCaption = _t('_bx_timeline_page_title_view_home');
  322. $sRssLink = $this->_oConfig->getHomeViewUrl();
  323. break;
  324. }
  325. $aParams = $this->_prepareParams(BX_TIMELINE_VIEW_DEFAULT, $sType, $iOwnerId, 0, $this->_oConfig->getRssLength(), '', array(), 0);
  326. $aEvents = $this->_oDb->getEvents($aParams);
  327. $aRssData = array();
  328. foreach($aEvents as $aEvent) {
  329. if(empty($aEvent['title'])) continue;
  330. $aRssData[$aEvent['id']] = array(
  331. 'UnitID' => $aEvent['id'],
  332. 'UnitTitle' => $aEvent['title'],
  333. 'UnitLink' => $this->_oConfig->getItemViewUrl($aEvent),
  334. 'UnitDesc' => $aEvent['description'],
  335. 'UnitDateTimeUTS' => $aEvent['date'],
  336. );
  337. }
  338. $oRss = new BxDolRssFactory();
  339. header('Content-Type: application/xml; charset=utf-8');
  340. echo $oRss->GenRssByData($aRssData, $sRssCaption, $sRssLink);
  341. }
  342. /**
  343. * SERVICE METHODS
  344. */
  345. /**
  346. * @page service Service Calls
  347. * @section bx_timeline Timeline
  348. * @subsection bx_timeline-other Other
  349. * @subsubsection bx_timeline-get_create_post_form get_create_post_form
  350. *
  351. * @code bx_srv('bx_timeline', 'get_create_post_form', [...]); @endcode
  352. *
  353. * Get form code for add content. Is needed for United Post Form.
  354. *
  355. * @param $aParams optional array with parameters(display name, etc)
  356. * @return form code or error
  357. *
  358. * @see BxTimelineModule::serviceGetCreatePostForm
  359. */
  360. /**
  361. * @ref bx_timeline-get_create_post_form "get_create_post_form"
  362. */
  363. public function serviceGetCreatePostForm($aParams = array())
  364. {
  365. $aParams = array_merge($this->_aFormParams, $aParams);
  366. $oForm = $this->serviceGetObjectForm('add', $aParams);
  367. if(!$oForm)
  368. return '';
  369. if(!empty($aParams['display']))
  370. $aParams['form_display'] = $aParams['display'];
  371. $aResult = $this->getFormPost($aParams);
  372. if(!empty($aResult['form']))
  373. return $aResult['form'];
  374. if(!empty($aResult['message']))
  375. return $aResult['message'];
  376. return '';
  377. }
  378. /**
  379. * @page service Service Calls
  380. * @section bx_timeline Timeline
  381. * @subsection bx_timeline-other Other
  382. * @subsubsection bx_timeline-get_object_form get_object_form
  383. *
  384. * @code bx_srv('bx_timeline', 'get_object_form', [...]); @endcode
  385. *
  386. * Get form object for add, edit, view or delete the content.
  387. *
  388. * @param $sType 'add' is supported only
  389. * @param $aParams optional array with parameters(display name, etc)
  390. * @return form object or false on error
  391. *
  392. * @see BxTimelineModule::serviceGetObjectForm
  393. */
  394. /**
  395. * @ref bx_timeline-get_object_form "get_object_form"
  396. */
  397. public function serviceGetObjectForm ($sType, $aParams = array())
  398. {
  399. if (!in_array($sType, array('add')))
  400. return false;
  401. $CNF = &$this->_oConfig->CNF;
  402. if(!empty($aParams['display']))
  403. $aParams['form_display'] = $aParams['display'];
  404. $oForm = $this->getFormPostObject($aParams);
  405. $sParamsKey = 'ajax_mode';
  406. if(isset($aParams[$sParamsKey]) && is_bool($aParams[$sParamsKey]))
  407. $oForm->setAjaxMode((bool)$aParams[$sParamsKey]);
  408. $sKey = 'FIELD_OBJECT_PRIVACY_VIEW';
  409. if(!empty($aParams['context_id']) && !empty($CNF[$sKey]) && !empty($oForm->aInputs[$CNF[$sKey]])) {
  410. foreach($oForm->aInputs[$CNF[$sKey]]['values'] as $aValue)
  411. if(isset($aValue['key']) && (int)$aValue['key'] == -(int)$aParams['context_id']) {
  412. $oForm->aInputs[$CNF[$sKey]]['value'] = -(int)$aParams['context_id'];
  413. $oForm->aInputs[$CNF[$sKey]]['type'] = 'hidden';
  414. break;
  415. }
  416. }
  417. return $oForm;
  418. }
  419. /**
  420. * @page service Service Calls
  421. * @section bx_timeline Timeline
  422. * @subsection bx_timeline-other Other
  423. * @subsubsection bx_timeline-get_author get_author
  424. *
  425. * @code bx_srv('bx_timeline', 'get_author', [...]); @endcode
  426. *
  427. * Get author ID from content info by content ID. Is used in "Content Info Objects" system.
  428. *
  429. * @param $iContentId integer value with content ID.
  430. * @return integer value with author ID.
  431. *
  432. * @see BxTimelineModule::serviceGetAuthor
  433. */
  434. /**
  435. * @ref bx_timeline-get_author "get_author"
  436. */
  437. public function serviceGetAuthor ($iContentId)
  438. {
  439. $aEvent = $this->_oDb->getEvents(array('browse' => 'id', 'value' => $iContentId));
  440. if(empty($aEvent) || !is_array($aEvent))
  441. return 0;
  442. return $this->_oConfig->isSystem($aEvent['type'], $aEvent['action']) ? (int)$aEvent['owner_id'] : (int)$aEvent['object_id'];
  443. }
  444. /**
  445. * @page service Service Calls
  446. * @section bx_timeline Timeline
  447. * @subsection bx_timeline-other Other
  448. * @subsubsection bx_timeline-get_date_changed get_date_changed
  449. *
  450. * @code bx_srv('bx_timeline', 'get_date_changed', [...]); @endcode
  451. *
  452. * Get date when the content was changed last time. Is used in "Content Info Objects" system.
  453. * Note. In case of Timeline event 0 is returned everytime.
  454. *
  455. * @param $iContentId integer value with content ID.
  456. * @return integer value with changing date.
  457. *
  458. * @see BxTimelineModule::serviceGetDateChanged
  459. */
  460. /**
  461. * @ref bx_timeline-get_date_changed "get_date_changed"
  462. */
  463. public function serviceGetDateChanged ($iContentId)
  464. {
  465. return 0;
  466. }
  467. /**
  468. * @page service Service Calls
  469. * @section bx_timeline Timeline
  470. * @subsection bx_timeline-other Other
  471. * @subsubsection bx_timeline-get_link get_link
  472. *
  473. * @code bx_srv('bx_timeline', 'get_link', [...]); @endcode
  474. *
  475. * Get content view page link. Is used in "Content Info Objects" system.
  476. *
  477. * @param $iContentId integer value with content ID.
  478. * @return string value with view page link.
  479. *
  480. * @see BxTimelineModule::serviceGetLink
  481. */
  482. /**
  483. * @ref bx_timeline-get_link "get_link"
  484. */
  485. public function serviceGetLink ($iContentId)
  486. {
  487. $aEvent = $this->_oDb->getEvents(array('browse' => 'id', 'value' => $iContentId));
  488. if(empty($aEvent) || !is_array($aEvent))
  489. return '';
  490. return $this->_oConfig->getItemViewUrl($aEvent);
  491. }
  492. /**
  493. * @page service Service Calls
  494. * @section bx_timeline Timeline
  495. * @subsection bx_timeline-other Other
  496. * @subsubsection bx_timeline-get_thumb get_thumb
  497. *
  498. * @code bx_srv('bx_timeline', 'get_thumb', [...]); @endcode
  499. *
  500. * Get content thumbnail link. Is used in "Content Info Objects" system.
  501. * Note. In case of Timeline event an empty string is returned everytime.
  502. *
  503. * @param $iContentId integer value with content ID.
  504. * @param $sTranscoder (optional) string value with transcoder name which should be applied to thumbnail image.
  505. * @return string value with thumbnail link.
  506. *
  507. * @see BxTimelineModule::serviceGetThumb
  508. */
  509. /**
  510. * @ref bx_timeline-get_thumb "get_thumb"
  511. */
  512. public function serviceGetThumb ($iContentId, $sTranscoder = '')
  513. {
  514. return '';
  515. }
  516. /**
  517. * @page service Service Calls
  518. * @section bx_timeline Timeline
  519. * @subsection bx_timeline-other Other
  520. * @subsubsection bx_timeline-get_info get_info
  521. *
  522. * @code bx_srv('bx_timeline', 'get_info', [...]); @endcode
  523. *
  524. * Get content info by content ID. Is used in "Content Info Objects" system.
  525. *
  526. * @param $iContentId integer value with content ID.
  527. * @param $bSearchableFieldsOnly (optional) boolean value determining all info or "searchable fields" only will be returned.
  528. * @return an array with content info. Empty array is returned if something is wrong.
  529. *
  530. * @see BxTimelineModule::serviceGetInfo
  531. */
  532. /**
  533. * @ref bx_timeline-get_info "get_info"
  534. */
  535. public function serviceGetInfo ($iContentId, $bSearchableFieldsOnly = true)
  536. {
  537. $aContentInfo = $this->_oDb->getEvents(array(
  538. 'browse' => 'id',
  539. 'value' => $iContentId)
  540. );
  541. return BxDolContentInfo::formatFields($aContentInfo);
  542. }
  543. /**
  544. * @page service Service Calls
  545. * @section bx_timeline Timeline
  546. * @subsection bx_timeline-other Other
  547. * @subsubsection bx_timeline-get_search_result_unit get_search_result_unit
  548. *
  549. * @code bx_srv('bx_timeline', 'get_search_result_unit', [...]); @endcode
  550. *
  551. * Get search result unit by content ID. Is used in "Content Info Objects" system.
  552. *
  553. * @param $iContentId integer value with content ID.
  554. * @param $sUnitTemplate (optional) string value with template name.
  555. * @return HTML string with search result unit. Empty string is returned if something is wrong.
  556. *
  557. * @see BxTimelineModule::serviceGetSearchResultUnit
  558. */
  559. /**
  560. * @ref bx_timeline-get_search_result_unit "get_search_result_unit"
  561. */
  562. public function serviceGetSearchResultUnit ($iContentId, $sUnitTemplate = '')
  563. {
  564. $aEvent = $this->_oDb->getEvents(array('browse' => 'id', 'value' => $iContentId));
  565. if(empty($aEvent) || !is_array($aEvent))
  566. return '';
  567. if(empty($sUnitTemplate))
  568. $sUnitTemplate = 'unit.html';
  569. return $this->_oTemplate->unit($aEvent, true, $sUnitTemplate);
  570. }
  571. /**
  572. * @page service Service Calls
  573. * @section bx_timeline Timeline
  574. * @subsection bx_timeline-page_blocks Page Blocks
  575. * @subsubsection bx_timeline-get_block_post get_block_post
  576. *
  577. * @code bx_srv('bx_timeline', 'get_block_post', [...]); @endcode
  578. *
  579. * Get Post block for a separate page.
  580. *
  581. * @param $iProfileId (optional) profile ID. If empty value is provided, an attempt to get it from GET/POST arrays will be performed.
  582. * @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.
  583. *
  584. * @see BxTimelineModule::serviceGetBlockPost
  585. */
  586. /**
  587. * @ref bx_timeline-get_block_post "get_block_post"
  588. */
  589. public function serviceGetBlockPost($iProfileId = 0)
  590. {
  591. if(empty($iProfileId) && bx_get('profile_id') !== false)
  592. $iProfileId = bx_process_input(bx_get('profile_id'), BX_DATA_INT);
  593. if(empty($iProfileId) && isLogged())
  594. $iProfileId = bx_get_logged_profile_id();
  595. if(!$iProfileId)
  596. return array();
  597. $sType = BX_BASE_MOD_NTFS_TYPE_OWNER;
  598. return $this->_getBlockPost($iProfileId, array(
  599. 'type' => $sType,
  600. 'form_display' => $this->_oConfig->getPostFormDisplay($sType)
  601. ));
  602. }
  603. /**
  604. * @page service Service Calls
  605. * @section bx_timeline Timeline
  606. * @subsection bx_timeline-page_blocks Page Blocks
  607. * @subsubsection bx_timeline-get_block_post_profile get_block_post_profile
  608. *
  609. * @code bx_srv('bx_timeline', 'get_block_post_profile', [...]); @endcode
  610. *
  611. * Get Post block for the Profile page.
  612. *
  613. * @param $sProfileModule (optional) string value with profile based module name. Persons module is used by default.
  614. * @param $iProfileContentId (optional) profile's content ID. If empty value is provided, an attempt to get it from GET/POST arrays will be performed.
  615. * @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.
  616. *
  617. * @see BxTimelineModule::serviceGetBlockPostProfile
  618. */
  619. /**
  620. * @ref bx_timeline-get_block_post_profile "get_block_post_profile"
  621. */
  622. public function serviceGetBlockPostProfile($sProfileModule = 'bx_persons', $iProfileContentId = 0)
  623. {
  624. if(empty($sProfileModule))
  625. return array();
  626. if(empty($iProfileContentId) && bx_get('id') !== false)
  627. $iProfileContentId = bx_process_input(bx_get('id'), BX_DATA_INT);
  628. $oProfile = BxDolProfile::getInstanceByContentAndType($iProfileContentId, $sProfileModule);
  629. if(empty($oProfile))
  630. return array();
  631. $iProfileId = $oProfile->id();
  632. $sType = BX_BASE_MOD_NTFS_TYPE_OWNER;
  633. return $this->_getBlockPost($iProfileId, array(
  634. 'type' => $sType,
  635. 'form_display' => $this->_oConfig->getPostFormDisplay($sType)
  636. ));
  637. }
  638. /**
  639. * @page service Service Calls
  640. * @section bx_timeline Timeline
  641. * @subsection bx_timeline-page_blocks Page Blocks
  642. * @subsubsection bx_timeline-get_block_post_home get_block_post_home
  643. *
  644. * @code bx_srv('bx_timeline', 'get_block_post_home', [...]); @endcode
  645. *
  646. * Get Post block for site's Home page.
  647. *
  648. * @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.
  649. *
  650. * @see BxTimelineModule::serviceGetBlockPostHome
  651. */
  652. /**
  653. * @ref bx_timeline-get_block_post_home "get_block_post_home"
  654. */
  655. public function serviceGetBlockPostHome()
  656. {
  657. $iProfileId = 0;
  658. $sType = BX_BASE_MOD_NTFS_TYPE_PUBLIC;
  659. return $this->_getBlockPost($iProfileId, array(
  660. 'type' => $sType,
  661. 'form_display' => $this->_oConfig->getPostFormDisplay($sType)
  662. ));
  663. }
  664. /**
  665. * @page service Service Calls
  666. * @section bx_timeline Timeline
  667. * @subsection bx_timeline-page_blocks Page Blocks
  668. * @subsubsection bx_timeline-get_block_post_account get_block_post_account
  669. *
  670. * @code bx_srv('bx_timeline', 'get_block_post_account', [...]); @endcode
  671. *
  672. * Get Post block for the Dashboard page.
  673. *
  674. * @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.
  675. *
  676. * @see BxTimelineModule::serviceGetBlockPostAccount
  677. */
  678. /**
  679. * @ref bx_timeline-get_block_post_account "get_block_post_account"
  680. */
  681. public function serviceGetBlockPostAccount()
  682. {
  683. if(!isLogged())
  684. return '';
  685. $iProfileId = $this->getProfileId();
  686. $sType = BX_TIMELINE_TYPE_OWNER_AND_CONNECTIONS;
  687. return $this->_getBlockPost($iProfileId, array(
  688. 'type' => $sType,
  689. 'form_display' => $this->_oConfig->getPostFormDisplay($sType)
  690. ));
  691. }
  692. /**
  693. * @page service Service Calls
  694. * @section bx_timeline Timeline
  695. * @subsection bx_timeline-page_blocks Page Blocks
  696. * @subsubsection bx_timeline-get_block_view get_block_view
  697. *
  698. * @code bx_srv('bx_timeline', 'get_block_view', [...]); @endcode
  699. *
  700. * Get Timeline View block for a separate page.
  701. *
  702. * @param $iProfileId (optional) profile ID. If empty value is provided, an attempt to get it from GET/POST arrays will be performed.
  703. * @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.
  704. *
  705. * @see BxTimelineModule::serviceGetBlockView
  706. */
  707. /**
  708. * @ref bx_timeline-get_block_view "get_block_view"
  709. */
  710. public function serviceGetBlockView($iProfileId = 0)
  711. {
  712. return $this->_serviceGetBlockView($iProfileId, BX_TIMELINE_VIEW_TIMELINE);
  713. }
  714. /**
  715. * @page service Service Calls
  716. * @section bx_timeline Timeline
  717. * @subsection bx_timeline-page_blocks Page Blocks
  718. * @subsubsection bx_timeline-get_block_view_outline get_block_view_outline
  719. *
  720. * @code bx_srv('bx_timeline', 'get_block_view_outline', [...]); @endcode
  721. *
  722. * Get Outline View block for a separate page.
  723. *
  724. * @param $iProfileId (optional) profile ID. If empty value is provided, an attempt to get it from GET/POST arrays will be performed.
  725. * @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.
  726. *
  727. * @see BxTimelineModule::serviceGetBlockViewOutline
  728. */
  729. /**
  730. * @ref bx_timeline-get_block_view_outline "get_block_view_outline"
  731. */
  732. public function serviceGetBlockViewOutline($iProfileId = 0)
  733. {
  734. return $this->_serviceGetBlockView($iProfileId, BX_TIMELINE_VIEW_OUTLINE);
  735. }
  736. /**
  737. * @page service Service Calls
  738. * @section bx_timeline Timeline
  739. * @subsection bx_timeline-page_blocks Page Blocks
  740. * @subsubsection bx_timeline-get_block_view_profile get_block_view_profile
  741. *
  742. * @code bx_srv('bx_timeline', 'get_block_view_profile', [...]); @endcode
  743. *
  744. * Get Timeline View block for the Profile page.
  745. *
  746. * @param $sProfileModule (optional) string value with profile based module name. Persons module is used by default.
  747. * @param $iProfileContentId (optional) profile's content ID. If empty value is provided, an attempt to get it from GET/POST arrays will be performed.
  748. * @param $iStart (optional) integer value with a page number. Is used in pagination.
  749. * @param $iPerPage (optional) integer value with a number of items per page. Is used in pagination.
  750. * @param $sFilter (optional) string value with filter name.
  751. * @param $aModules (optional) an array of modules from which the events should be displayed. All available modules are used by default.
  752. * @param $iTimeline (optional) integer value determining whether the timeline should be displayed or not.
  753. * @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.
  754. *
  755. * @see BxTimelineModule::serviceGetBlockViewProfile
  756. */
  757. /**
  758. * @ref bx_timeline-get_block_view_profile "get_block_view_profile"
  759. */
  760. public function serviceGetBlockViewProfile($sProfileModule = 'bx_persons', $iProfileContentId = 0, $iStart = -1, $iPerPage = -1, $sFilter = '', $aModules = array(), $iTimeline = -1)
  761. {
  762. $sView = BX_TIMELINE_VIEW_TIMELINE;
  763. return $this->_serviceGetBlockViewProfile($sProfileModule, $iProfileContentId, $sView, $iStart, $iPerPage, $sFilter, $aModules, $iTimeline);
  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_profile_outline get_block_view_profile_outline
  770. *
  771. * @code bx_srv('bx_timeline', 'get_block_view_profile_outline', [...]); @endcode
  772. *
  773. * Get Outline View block for the Profile page.
  774. *
  775. * @param $sProfileModule (optional) string value with profile based module name. Persons module is used by default.
  776. * @param $iProfileContentId (optional) profile's content ID. If empty value is provided, an attempt to get it from GET/POST arrays will be performed.
  777. * @param $iStart (optional) integer value with a page number. Is used in pagination.
  778. * @param $iPerPage (optional) integer value with a number of items per page. Is used in pagination.
  779. * @param $sFilter (optional) string value with filter name.
  780. * @param $aModules (optional) an array of modules from which the events should be displayed. All available modules are used by default.
  781. * @param $iTimeline (optional) integer value determining whether the timeline should be displayed or not.
  782. * @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.
  783. *
  784. * @see BxTimelineModule::serviceGetBlockViewProfileOutline
  785. */
  786. /**
  787. * @ref bx_timeline-get_block_view_profile_outline "get_block_view_profile_outline"
  788. */
  789. public function serviceGetBlockViewProfileOutline($sProfileModule = 'bx_persons', $iProfileContentId = 0, $iStart = -1, $iPerPage = -1, $sFilter = '', $aModules = array(), $iTimeline = -1)
  790. {
  791. $sView = BX_TIMELINE_VIEW_OUTLINE;
  792. return $this->_serviceGetBlockViewProfile($sProfileModule, $iProfileContentId, $sView, $iStart, $iPerPage, $sFilter, $aModules, $iTimeline);
  793. }
  794. /**
  795. * @page service Service Calls
  796. * @section bx_timeline Timeline
  797. * @subsection bx_timeline-page_blocks Page Blocks
  798. * @subsubsection bx_timeline-get_block_view_home get_block_view_home
  799. *
  800. * @code bx_srv('bx_timeline', 'get_block_view_home', [...]); @endcode
  801. *
  802. * Get Timeline View block for site's Home page.
  803. *
  804. * @param $iProfileId (optional) profile ID. 0 should be used here.
  805. * @param $iStart (optional) integer value with a page number. Is used in pagination.
  806. * @param $iPerPage (optional) integer value with a number of items per page. Is used in pagination.
  807. * @param $iTimeline (optional) integer value determining whether the timeline should be displayed or not.
  808. * @param $sFilter (optional) string value with filter name.
  809. * @param $aModules (optional) an array of modules from which the events should be displayed. All available modules are used by default.
  810. * @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.
  811. *
  812. * @see BxTimelineModule::serviceGetBlockViewHome
  813. */
  814. /**
  815. * @ref bx_timeline-get_block_view_home "get_block_view_home"
  816. */
  817. public function serviceGetBlockViewHome($iProfileId = 0, $iStart = -1, $iPerPage = -1, $iTimeline = -1, $sFilter = '', $aModules = array())
  818. {
  819. return $this->_serviceGetBlockViewHome($iProfileId, BX_TIMELINE_VIEW_TIMELINE, $iStart, $iPerPage, $this->_oConfig->getPerPage('home'), $iTimeline, $sFilter, $aModules);
  820. }
  821. /**
  822. * @page service Service Calls
  823. * @section bx_timeline Timeline
  824. * @subsection bx_timeline-page_blocks Page Blocks
  825. * @subsubsection bx_timeline-get_block_view_home_outline get_block_view_home_outline
  826. *
  827. * @code bx_srv('bx_timeline', 'get_block_view_home_outline', [...]); @endcode
  828. *
  829. * Get Outline View block for site's Home page.
  830. *
  831. * @param $iProfileId (optional) profile ID. 0 should be used here.
  832. * @param $iStart (optional) integer value with a page number. Is used in pagination.
  833. * @param $iPerPage (optional) integer value with a number of items per page. Is used in pagination.
  834. * @param $iTimeline (optional) integer value determining whether the timeline should be displayed or not.
  835. * @param $sFilter (optional) string value with filter name.
  836. * @param $aModules (optional) an array of modules from which the events should be displayed. All available modules are used by default.
  837. * @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.
  838. *
  839. * @see BxTimelineModule::serviceGetBlockViewHomeOutline
  840. */
  841. /**
  842. * @ref bx_timeline-get_block_view_home_outline "get_block_view_home_outline"
  843. */
  844. public function serviceGetBlockViewHomeOutline($iProfileId = 0, $iStart = -1, $iPerPage = -1, $iTimeline = -1, $sFilter = '', $aModules = array())
  845. {
  846. return $this->_serviceGetBlockViewHome($iProfileId, BX_TIMELINE_VIEW_OUTLINE, $iStart, $iPerPage, $this->_oConfig->getPerPage('home'), $iTimeline, $sFilter, $aModules);
  847. }
  848. /**
  849. * @page service Service Calls
  850. * @section bx_timeline Timeline
  851. * @subsection bx_timeline-page_blocks Page Blocks
  852. * @subsubsection bx_timeline-get_block_view_hot get_block_view_hot
  853. *
  854. * @code bx_srv('bx_timeline', 'get_block_view_hot', [...]); @endcode
  855. *
  856. * Get Timeline View block with Hot public events.
  857. *
  858. * @param $iProfileId (optional) profile ID. 0 should be used here.
  859. * @param $iStart (optional) integer value with a page number. Is used in pagination.
  860. * @param $iPerPage (optional) integer value with a number of items per page. Is used in pagination.
  861. * @param $iTimeline (optional) integer value determining whether the timeline should be displayed or not.
  862. * @param $sFilter (optional) string value with filter name.
  863. * @param $aModules (optional) an array of modules from which the events should be displayed. All available modules are used by default.
  864. * @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.
  865. *
  866. * @see BxTimelineModule::serviceGetBlockViewHot
  867. */
  868. /**
  869. * @ref bx_timeline-get_block_view_hot "get_block_view_hot"
  870. */
  871. public function serviceGetBlockViewHot($iProfileId = 0, $iStart = -1, $iPerPage = -1, $iTimeline = -1, $sFilter = '', $aModules = array())
  872. {
  873. return $this->_serviceGetBlockViewHot($iProfileId, BX_TIMELINE_VIEW_TIMELINE, $iStart, $iPerPage, $this->_oConfig->getPerPage('home'), $iTimeline, $sFilter, $aModules);
  874. }
  875. /**
  876. * @page service Service Calls
  877. * @section bx_timeline Timeline
  878. * @subsection bx_timeline-page_blocks Page Blocks
  879. * @subsubsection bx_timeline-get_block_view_hot_outline get_block_view_hot_outline
  880. *
  881. * @code bx_srv('bx_timeline', 'get_block_view_hot_outline', [...]); @endcode
  882. *
  883. * Get Outline View block with Hot public events.
  884. *
  885. * @param $iProfileId (optional) profile ID. 0 should be used here.
  886. * @param $iStart (optional) integer value with a page number. Is used in pagination.
  887. * @param $iPerPage (optional) integer value with a number of items per page. Is used in pagination.
  888. * @param $iTimeline (optional) integer value determining whether the timeline should be displayed or not.
  889. * @param $sFilter (optional) string value with filter name.
  890. * @param $aModules (optional) an array of modules from which the events should be displayed. All available modules are used by default.
  891. * @return an array describing a block to display on the site. All necessary CSS and JS files are automatically added to the HEAD section of the site HTML.
  892. *
  893. * @see BxTimelineModule::serviceGetBlockViewHotOutline
  894. */
  895. /**
  896. * @ref bx_timeline-get_block_view_hot_outline "get_block_view_hot_outline"
  897. */
  898. public function serviceGetBlockViewHotOutline($iProfileId = 0, $iStart = -1, $iPerPage = -1, $iTimeline = -1, $sFilter = '', $aModules = array())
  899. {
  900. return $this->_serviceGetBlockViewHot($iProfileId, BX_TIMELINE_VIEW_OUTLINE, $iStart, $iPerPage, $this->_oConfig->getPerPage('home'), $iTimeline, $sFilter, $aModules);
  901. }
  902. /**
  903. * @page service Service Calls
  904. * @section bx_timeline Timeline
  905. * @subsection bx_timeline-page_blocks Page Blocks
  906. * @subsubsection bx_timeline-get_block_view_account get_block_view_account
  907. *
  908. * @code bx_srv('bx_timeline', 'get_block_view_account', [...]); @endcode
  909. *
  910. * Get Timeline View block for the Dashboard page.
  911. *
  912. * @param $iProfileId (optional) profile ID. 0 should be used here.
  913. * @param $iStart (optional) integer value with a page number. Is used in pagination.
  914. * @param $iPerPage (optional) integer value with a number of items per page. Is used in pagination.
  915. * @param $iTimeline (optional) integer value determining whether the timeline should be displayed or not.
  916. * @param $sFilter (optional) string value with filter name.
  917. * @param $aModules (optional) an array of modules from which the events should be displayed. All available modules are used by default.
  918. * @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.
  919. *
  920. * @see BxTimelineModule::serviceGetBlockViewAccount
  921. */
  922. /**
  923. * @ref bx_timeline-get_block_view_account "get_block_view_account"
  924. */
  925. public function serviceGetBlockViewAccount($iProfileId = 0, $iStart = -1, $iPerPage = -1, $iTimeline = -1, $sFilter = '', $aModules = array())
  926. {
  927. if(!isLogged())
  928. return '';
  929. return $this->_serviceGetBlockViewByType($iProfileId, BX_TIMELINE_VIEW_TIMELINE, BX_TIMELINE_TYPE_OWNER_AND_CONNECTIONS, $iStart, $iPerPage, $this->_oConfig->getPerPage('account'), $iTimeline, $sFilter, $aModules);
  930. }
  931. /**
  932. * @page service Service Calls
  933. * @section bx_timeline Timeline
  934. * @subsection bx_timeline-page_blocks Page Blocks
  935. * @subsubsection bx_timeline-get_block_view_account_outline get_block_view_account_outline
  936. *
  937. * @code bx_srv('bx_timeline', 'get_block_view_account_outline', [...]); @endcode
  938. *
  939. * Get Outline View block for the Dashboard page.
  940. *
  941. * @param $iProfileId (optional) profile ID. 0 should be used here.
  942. * @param $iStart (optional) integer value with a page number. Is used in pagination.
  943. * @param $iPerPage (optional) integer value with a number of items per page. Is used in pagination.
  944. * @param $iTimeline (optional) integer value determining whether the timeline should be displayed or not.
  945. * @param $sFilter (optional) string value with filter name.
  946. * @param $aModules (optional) an array of modules from which the events should be displayed. All available modules are used by default.
  947. * @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.
  948. *
  949. * @see BxTimelineModule::serviceGetBlockViewAccountOutline
  950. */
  951. /**
  952. * @ref bx_timeline-get_block_view_account_outline "get_block_view_account_outline"
  953. */
  954. public function serviceGetBlockViewAccountOutline($iProfileId = 0, $iStart = -1, $iPerPage = -1, $iTimeline = -1, $sFilter = '', $aModules = array())
  955. {
  956. if(!isLogged())
  957. return '';
  958. return $this->_serviceGetBlockViewByType($iProfileId, BX_TIMELINE_VIEW_OUTLINE, BX_TIMELINE_TYPE_OWNER_AND_CONNECTIONS, $iStart, $iPerPage, $this->_oConfig->getPerPage('account'), $iTimeline, $sFilter, $aModules);
  959. }
  960. /**
  961. * @page service Service Calls
  962. * @section bx_timeline Timeline
  963. * @subsection bx_timeline-page_blocks Page Blocks
  964. * @subsubsection bx_timeline-get_block_item get_block_item
  965. *
  966. * @code bx_srv('bx_timeline', 'get_block_item', [...]); @endcode
  967. *
  968. * Get View Item block.
  969. *
  970. * @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.
  971. *
  972. * @see BxTimelineModule::serviceGetBlockItem
  973. */
  974. /**
  975. * @ref bx_timeline-get_block_item "get_block_item"
  976. */
  977. public function serviceGetBlockItem()
  978. {
  979. $iItemId = bx_process_input(bx_get('id'), BX_DATA_INT);
  980. if(!$iItemId)
  981. return array();
  982. return $this->_oTemplate->getItemBlock($iItemId);
  983. }
  984. public function serviceGetBlockItemContent()
  985. {
  986. $iItemId = bx_process_input(bx_get('id'), BX_DATA_INT);
  987. $sMode = bx_process_input(bx_get('mode'));
  988. if(!$iItemId || !$sMode)
  989. return '';
  990. return $this->_oTemplate->getItemBlockContent($iItemId, $sMode);
  991. }
  992. public function serviceGetBlockItemInfo()
  993. {
  994. $iItemId = bx_process_input(bx_get('id'), BX_DATA_INT);
  995. if(!$iItemId)
  996. return '';
  997. return $this->_oTemplate->getItemBlockInfo($iItemId);
  998. }
  999. public function serviceGetBlockItemComments()
  1000. {
  1001. $iItemId = bx_process_input(bx_get('id'), BX_DATA_INT);
  1002. if(!$iItemId)
  1003. return '';
  1004. return $this->_oTemplate->getItemBlockComments($iItemId);
  1005. }
  1006. /**
  1007. * @page service Service Calls
  1008. * @section bx_timeline Timeline
  1009. * @subsection bx_timeline-integration_notifications Integration with Notifications
  1010. * @subsubsection bx_timeline-get_notifications_data get_notifications_data
  1011. *
  1012. * @code bx_srv('bx_timeline', 'get_notifications_data', [...]); @endcode
  1013. *
  1014. * Data for Notifications module.
  1015. *
  1016. * @return an array with special format.
  1017. *
  1018. * @see BxTimelineModule::serviceGetNotificationsData
  1019. */
  1020. /**
  1021. * @ref bx_timeline-get_notifications_data "get_notifications_data"
  1022. */
  1023. public function serviceGetNotificationsData()
  1024. {
  1025. $sModule = $this->_aModule['name'];
  1026. return array(
  1027. 'handlers' => array(
  1028. array('group' => $sModule . '_object', 'type' => 'insert', 'alert_unit' => $sModule, 'alert_action' => 'post_common', 'module_name' => $sModule, 'module_method' => 'get_notifications_post', 'module_class' => 'Module'),
  1029. array('group' => $sModule . '_object', 'type' => 'delete', 'alert_unit' => $sModule, 'alert_action' => 'delete'),
  1030. array('group' => $sModule . '_repost', 'type' => 'insert', 'alert_unit' => $sModule, 'alert_action' => 'repost', 'module_name' => $sModule, 'module_method' => 'get_notifications_repost', 'module_class' => 'Module'),
  1031. array('group' => $sModule . '_repost', 'type' => 'delete', 'alert_unit' => $sModule, 'alert_action' => 'delete_repost'),
  1032. array('group' => $sModule . '_comment', 'type' => 'insert', 'alert_unit' => $sModule, 'alert_action' => 'commentPost', 'module_name' => $sModule, 'module_method' => 'get_notifications_comment', 'module_class' => 'Module'),
  1033. array('group' => $sModule . '_comment', 'type' => 'delete', 'alert_unit' => $sModule, 'alert_action' => 'commentRemoved'),
  1034. array('group' => $sModule . '_vote', 'type' => 'insert', 'alert_unit' => $sModule, 'alert_action' => 'doVote', 'module_name' => $sModule, 'module_method' => 'get_notifications_vote', 'module_class' => 'Module'),
  1035. array('group' => $sModule . '_vote', 'type' => 'delete', 'alert_unit' => $sModule, 'alert_action' => 'undoVote'),
  1036. ),
  1037. 'alerts' => array(
  1038. array('unit' => $sModule, 'action' => 'post_common'),
  1039. array('unit' => $sModule, 'action' => 'delete'),
  1040. array('unit' => $sModule, 'action' => 'repost'),
  1041. array('unit' => $sModule, 'action' => 'delete_repost'),
  1042. array('unit' => $sModule, 'action' => 'commentPost'),
  1043. array('unit' => $sModule, 'action' => 'commentRemoved'),
  1044. array('unit' => $sModule, 'action' => 'doVote'),
  1045. array('unit' => $sModule, 'action' => 'undoVote'),
  1046. )
  1047. );
  1048. }
  1049. /**
  1050. * @page service Service Calls
  1051. * @section bx_timeline Timeline
  1052. * @subsection bx_timeline-integration_notifications Integration with Notifications
  1053. * @subsubsection bx_timeline-get_notifications_repost get_notifications_repost
  1054. *
  1055. * @code bx_srv('bx_timeline', 'get_notifications_repost', [...]); @endcode
  1056. *
  1057. * Get data for Repost event to display in Notifications module.
  1058. *
  1059. * @param $aEvent an array with event description.
  1060. * @return an array with special format.
  1061. *
  1062. * @see BxTimelineModule::serviceGetNotificationsRepost
  1063. */
  1064. /**
  1065. * @ref bx_timeline-get_notifications_repost "get_notifications_repost"
  1066. */
  1067. public function serviceGetNotificationsRepost($aEvent)
  1068. {
  1069. $aResult = $this->serviceGetNotificationsPost($aEvent);
  1070. $aResult['lang_key'] = '_bx_timeline_txt_object_reposted';
  1071. return $aResult;
  1072. }
  1073. /**
  1074. * @page service Service Calls
  1075. * @section bx_timeline Timeline
  1076. * @subsection bx_timeline-integration_notifications Integration with Notifications
  1077. * @subsubsection bx_timeline-get_notifications_post get_notifications_post
  1078. *
  1079. * @code bx_srv('bx_timeline', 'get_notifications_post', [...]); @endcode
  1080. *
  1081. * Get data for Post event to display in Notifications module.
  1082. *
  1083. * @param $aEvent an array with event description.
  1084. * @return an array with special format.
  1085. *
  1086. * @see BxTimelineModule::serviceGetNotificationsPost
  1087. */
  1088. /**
  1089. * @ref bx_timeline-get_notifications_post "get_notifications_post"
  1090. */
  1091. public function serviceGetNotificationsPost($aEvent)
  1092. {
  1093. $CNF = &$this->_oConfig->CNF;
  1094. $iContent = (int)$aEvent['object_id'];
  1095. $aContent = $this->_oDb->getEvents(array('browse' => 'id', 'value' => $iContent));
  1096. if(empty($aContent) || !is_array($aContent))
  1097. return array();
  1098. $sEntryCaption = !empty($aContent['title']) ? $aContent['title'] : $this->_oConfig->getTitle($aContent['description']);
  1099. return array(
  1100. 'entry_sample' => $CNF['T']['txt_sample_single_ext'],
  1101. 'entry_url' => $this->_oConfig->getItemViewUrl($aContent),
  1102. 'entry_caption' => $sEntryCaption,
  1103. 'entry_author' => $aContent['owner_id'],
  1104. 'lang_key' => '_bx_timeline_ntfs_txt_object_added', //may be empty or not specified. In this case the default one from Notification module will be used.
  1105. );
  1106. }
  1107. /**
  1108. * @page service Service Calls
  1109. * @section bx_timeline Timeline
  1110. * @subsection bx_timeline-integration_notifications Integration with Notifications
  1111. * @subsubsection bx_timeline-get_notifications_comment get_notifications_comment
  1112. *
  1113. * @code bx_srv('bx_timeline', 'get_notifications_comment', [...]); @endcode
  1114. *
  1115. * Get data for Post Comment event to display in Notifications module.
  1116. *
  1117. * @param $aEvent an array with event description.
  1118. * @return an array with special format.
  1119. *
  1120. * @see BxTimelineModule::serviceGetNotificationsComment
  1121. */
  1122. /**
  1123. * @ref bx_timeline-get_notifications_comment "get_notifications_comment"
  1124. */
  1125. public function serviceGetNotificationsComment($aEvent)
  1126. {
  1127. $CNF = &$this->_oConfig->CNF;
  1128. $iContent = (int)$aEvent['object_id'];
  1129. $aContent = $this->_oDb->getEvents(array('browse' => 'id', 'value' => $iContent));
  1130. if(empty($aContent) || !is_array($aContent))
  1131. return array();
  1132. $oComment = BxDolCmts::getObjectInstance($CNF['OBJECT_COMMENTS'], $iContent);
  1133. if(!$oComment || !$oComment->isEnabled())
  1134. return array();
  1135. $sEntryCaption = !empty($aContent['title']) ? $aContent['title'] : $this->_oConfig->getTitle($aContent['description']);
  1136. return array(
  1137. 'entry_sample' => $CNF['T']['txt_sample_single'],
  1138. 'entry_url' => $this->_oConfig->getItemViewUrl($aContent),
  1139. 'entry_caption' => $sEntryCaption,
  1140. 'entry_author' => $aContent['owner_id'],
  1141. 'subentry_sample' => $CNF['T']['txt_sample_comment_single'],
  1142. 'subentry_url' => $oComment->getViewUrl((int)$aEvent['subobject_id']),
  1143. 'lang_key' => '', //may be empty or not specified. In this case the default one from Notification module will be used.
  1144. );
  1145. }
  1146. /**
  1147. * @page service Service Calls
  1148. * @section bx_timeline Timeline
  1149. * @subsection bx_timeline-integration_notifications Integration with Notifications
  1150. * @subsubsection bx_timeline-get_notifications_vote get_notifications_vote
  1151. *
  1152. * @code bx_srv('bx_timeline', 'get_notifications_vote', [...]); @endcode
  1153. *
  1154. * Get data for Vote event to display in Notifications module.
  1155. *
  1156. * @param $aEvent an array with event description.
  1157. * @return an array with special format.
  1158. *
  1159. * @see BxTimelineModule::serviceGetNotificationsVote
  1160. */
  1161. /**
  1162. * @ref bx_timeline-get_notifications_vote "get_notifications_vote"
  1163. */
  1164. public function serviceGetNotificationsVote($aEvent)
  1165. {
  1166. $CNF = &$this->_oConfig->CNF;
  1167. $iContent = (int)$aEvent['object_id'];
  1168. $aContent = $this->_oDb->getEvents(array('browse' => 'id', 'value' => $iContent));
  1169. if(empty($aContent) || !is_array($aContent))
  1170. return array();
  1171. $oVote = BxDolVote::getObjectInstance($CNF['OBJECT_VOTES'], $iContent);
  1172. if(!$oVote || !$oVote->isEnabled())
  1173. return array();
  1174. $sEntryCaption = !empty($aContent['title']) ? $aContent['title'] : $this->_oConfig->getTitle($aContent['description']);
  1175. return array(
  1176. 'entry_sample' => $CNF['T']['txt_sample_single'],
  1177. 'entry_url' => $this->_oConfig->getItemViewUrl($aContent),
  1178. 'entry_caption' => $sEntryCaption,
  1179. 'entry_author' => $aContent['owner_id'],
  1180. 'subentry_sample' => $CNF['T']['txt_sample_vote_single'],
  1181. 'lang_key' => '', //may be empty or not specified. In this case the default one from Notification module will be used.
  1182. );
  1183. }
  1184. /**
  1185. * @page service Service Calls
  1186. * @section bx_timeline Timeline
  1187. * @subsection bx_timeline-repost Repost
  1188. * @subsubsection bx_timeline-get_repost_element_block get_repost_element_block
  1189. *
  1190. * @code bx_srv('bx_timeline', 'get_repost_element_block', [...]); @endcode
  1191. *
  1192. * Get repost element for content based modules.
  1193. *
  1194. * @param $iOwnerId integer value with owner profile ID.
  1195. * @param $sType string value with type (module name).
  1196. * @param $sAction string value with action (module action).
  1197. * @param $iObjectId integer value with object ID to be reposted.
  1198. * @param $aParams (optional) an array with additional params.
  1199. * @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.
  1200. *
  1201. * @see BxTimelineModule::serviceGetRepostElementBlock
  1202. */
  1203. /**
  1204. * @ref bx_timeline-get_repost_element_block "get_repost_element_block"
  1205. */
  1206. public function serviceGetRepostElementBlock($iOwnerId, $sType, $sAction, $iObjectId, $aParams = array())
  1207. {
  1208. if(!$this->isEnabled())
  1209. return '';
  1210. $aParams = array_merge($this->_oConfig->getRepostDefaults(), $aParams);
  1211. return $this->_oTemplate->getRepostElement($iOwnerId, $sType, $sAction, $iObjectId, $aParams);
  1212. }
  1213. /**
  1214. * @page service Service Calls
  1215. * @section bx_timeline Timeline
  1216. * @subsection bx_timeline-repost Repost
  1217. * @subsubsection bx_timeline-get_repost_counter get_repost_counter
  1218. *
  1219. * @code bx_srv('bx_timeline', 'get_repost_counter', [...]); @endcode
  1220. *
  1221. * Get repost counter.
  1222. *
  1223. * @param $sType string value with type (module name).
  1224. * @param $sAction string value with action (module action).
  1225. * @param $iObjectId integer value with object ID to be reposted.
  1226. * @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.
  1227. *
  1228. * @see BxTimelineModule::serviceGetRepostCounter
  1229. */
  1230. /**
  1231. * @ref bx_timeline-get_repost_counter "get_repost_counter"
  1232. */
  1233. public function serviceGetRepostCounter($sType, $sAction, $iObjectId)
  1234. {
  1235. if(!$this->isEnabled())
  1236. return '';
  1237. $aReposted = $this->_oDb->getReposted($sType, $sAction, $iObjectId);
  1238. return $this->_oTemplate->getRepostCounter($aReposted);
  1239. }
  1240. /**
  1241. * @page service Service Calls
  1242. * @section bx_timeline Timeline
  1243. * @subsection bx_timeline-repost Repost
  1244. * @subsubsection bx_timeline-get_repost_js_script get_repost_js_script
  1245. *
  1246. * @code bx_srv('bx_timeline', 'get_repost_js_script', [...]); @endcode
  1247. *
  1248. * Get repost JavaScript code.
  1249. *
  1250. * @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.
  1251. *
  1252. * @see BxTimelineModule::serviceGetRepostJsScript
  1253. */
  1254. /**
  1255. * @ref bx_timeline-get_repost_js_script "get_repost_js_script"
  1256. */
  1257. public function serviceGetRepostJsScript()
  1258. {
  1259. if(!$this->isEnabled())
  1260. return '';
  1261. return $this->_oTemplate->getRepostJsScript();
  1262. }
  1263. /**
  1264. * @page service Service Calls
  1265. * @section bx_timeline Timeline
  1266. * @subsection bx_timeline-repost Repost
  1267. * @subsubsection bx_timeline-get_repost_js_click get_repost_js_click
  1268. *
  1269. * @code bx_srv('bx_timeline', 'get_repost_js_click', [...]); @endcode
  1270. *
  1271. * Get repost JavaScript code for OnClick event.
  1272. *
  1273. * @param $iOwnerId integer value with owner profile ID.
  1274. * @param $sType string value with type (module name).
  1275. * @param $sAction string value with action (module action).
  1276. * @param $iObjectId integer value with object ID to be reposted.
  1277. * @return HTML string with JavaScript code to display in OnClick events of HTML elements.
  1278. *
  1279. * @see BxTimelineModule::serviceGetRepostJsClick
  1280. */
  1281. /**
  1282. * @ref bx_timeline-get_repost_js_click "get_repost_js_click"
  1283. */
  1284. public function serviceGetRepostJsClick($iOwnerId, $sType, $sAction, $iObjectId)
  1285. {
  1286. if(!$this->isEnabled())
  1287. return '';
  1288. return $this->_oTemplate->getRepostJsClick($iOwnerId, $sType, $sAction, $iObjectId);
  1289. }
  1290. /**
  1291. * @page service Service Calls
  1292. * @section bx_timeline Timeline
  1293. * @subsection bx_timeline-other Other
  1294. * @subsubsection bx_timeline-get_menu_item_addon_comment get_menu_item_addon_comment
  1295. *
  1296. * @code bx_srv('bx_timeline', 'get_menu_item_addon_comment', [...]); @endcode
  1297. *
  1298. * Get addon for Comment menu item.
  1299. *
  1300. * @param $sSystem string value with comments engine system.
  1301. * @param $iObjectId integer value with object ID.
  1302. * @return HTML string to display in menu item.
  1303. *
  1304. * @see BxTimelineModule::serviceGetMenuItemAddonComment
  1305. */
  1306. /**
  1307. * @ref bx_timeline-get_menu_item_addon_comment "get_menu_item_addon_comment"
  1308. */
  1309. public function serviceGetMenuItemAddonComment($sSystem, $iObjectId)
  1310. {
  1311. if(empty($sSystem) || empty($iObjectId))
  1312. return '';
  1313. $oCmts = $this->getCmtsObject($sSystem, $iObjectId);
  1314. if($oCmts === false)
  1315. return '';
  1316. $iCounter = (int)$oCmts->getCommentsCount();
  1317. return $this->_oTemplate->parseLink('javascript:void(0)', $iCounter > 0 ? $iCounter : '', array(
  1318. 'title' => _t('_bx_timeline_menu_item_title_item_comment'),
  1319. 'onclick' => "javascript:" . $this->_oConfig->getJsObject('view') . ".commentItem(this, '" . $sSystem . "', " . $iObjectId . ")"
  1320. ));
  1321. }
  1322. /**
  1323. * @page service Service Calls
  1324. * @section bx_timeline Timeline
  1325. * @subsection bx_timeline-other Other
  1326. * @subsubsection bx_timeline-get_settings_checker_helper get_settings_checker_helper
  1327. *
  1328. * @code bx_srv('bx_timeline', 'get_settings_checker_helper', [...]); @endcode
  1329. *
  1330. * Get Checker Helper class name for Forms engine.
  1331. *
  1332. * @return string with Checker Helper class name.
  1333. *
  1334. * @see BxTimelineModule::serviceGetSettingsCheckerHelper
  1335. */
  1336. /**
  1337. * @ref bx_timeline-get_settings_checker_helper "get_settings_checker_helper"
  1338. */
  1339. public function serviceGetSettingsCheckerHelper()
  1340. {
  1341. bx_import('FormCheckerHelper', $this->_aModule);
  1342. return 'BxTimelineFormCheckerHelper';
  1343. }
  1344. /**
  1345. * @page service Service Calls
  1346. * @section bx_timeline Timeline
  1347. * @subsection bx_timeline-other Other
  1348. * @subsubsection bx_timeline-get_options_videos_autoplay get_options_videos_autoplay
  1349. *
  1350. * @code bx_srv('bx_timeline', 'get_options_videos_autoplay', [...]); @endcode
  1351. *
  1352. * Get an array with available options for 'Videos autoplay in Timeline' setting.
  1353. *
  1354. * @return an array with available options represented as key => value pairs.
  1355. *
  1356. * @see BxTimelineModule::serviceGetOptionsVideosAutoplay
  1357. */
  1358. /**
  1359. * @ref bx_timeline-get_options_videos_autoplay "get_options_videos_autoplay"
  1360. */
  1361. public function serviceGetOptionsVideosAutoplay()
  1362. {
  1363. $aOptions = array(BX_TIMELINE_VAP_OFF, BX_TIMELINE_VAP_ON_MUTE, BX_TIMELINE_VAP_ON);
  1364. $aResult = array();
  1365. foreach($aOptions as $sOption)
  1366. $aResult[] = array(
  1367. 'key' => $sOption,
  1368. 'value' => _t('_bx_timeline_option_videos_autoplay_' . $sOption)
  1369. );
  1370. return $aResult;
  1371. }
  1372. /**
  1373. * @page service Service Calls
  1374. * @section bx_timeline Timeline
  1375. * @subsection bx_timeline-other Other
  1376. * @subsubsection bx_timeline-get_live_updates get_live_updates
  1377. *
  1378. * @code bx_srv('bx_timeline', 'get_live_updates', [...]); @endcode
  1379. *
  1380. * Get an array with actual Live Update info.
  1381. *
  1382. * @return an array with Live Update info.
  1383. *
  1384. * @see BxTimelineModule::serviceGetLiveUpdates
  1385. */
  1386. /**
  1387. * @ref bx_timeline-get_live_updates "get_live_updates"
  1388. */
  1389. public function serviceGetLiveUpdates($sType, $iOwnerId, $iProfileId, $iCount = 0, $iInit = 0)
  1390. {
  1391. $sKey = $this->_oConfig->getLiveUpdateKey($sType, $iOwnerId);
  1392. bx_import('BxDolSession');
  1393. if((int)BxDolSession::getInstance()->getValue($sKey) == 1)
  1394. return false;
  1395. $aParams = $this->_prepareParams(BX_TIMELINE_VIEW_DEFAULT, $sType, $iOwnerId, false, false, BX_TIMELINE_FILTER_OTHER_VIEWER);
  1396. $aParams['count'] = true;
  1397. $iCountNew = $this->_oDb->getEvents($aParams);
  1398. if($iCountNew == $iCount)
  1399. return false;
  1400. if((int)$iInit != 0)
  1401. return array('count' => $iCountNew);
  1402. return array(
  1403. 'count' => $iCountNew, // required (for initialization and visualization)
  1404. 'method' => $this->_oConfig->getJsObject('view') . '.showLiveUpdate(oData)', // required (for visualization)
  1405. 'data' => array(
  1406. 'code' => $this->_oTemplate->getLiveUpdateNotification($sType, $iOwnerId, $iProfileId, $iCount, $iCountNew)
  1407. ), // optional, may have some additional data to be passed in JS method provided using 'method' param above.
  1408. );
  1409. }
  1410. /**
  1411. * @page service Service Calls
  1412. * @section bx_timeline Accounts
  1413. * @subsection bx_timeline-other Other
  1414. * @subsubsection bx_timeline-get_menu_addon_manage_tools get_menu_addon_manage_tools
  1415. *
  1416. * @code bx_srv('bx_timeline', 'get_menu_addon_manage_tools', [...]); @endcode
  1417. *
  1418. * Get number of 'hidden' events for User End -> Dasboard page -> Manage block.
  1419. *
  1420. * @return integer number of 'hidden' events
  1421. *
  1422. * @see BxTimelineModule::serviceGetMenuAddonManageTools
  1423. */
  1424. /**
  1425. * @ref bx_timeline-get_menu_addon_manage_tools "get_menu_addon_manage_tools"
  1426. */
  1427. public function serviceGetMenuAddonManageTools()
  1428. {
  1429. bx_import('SearchResult', $this->_aModule);
  1430. $sClass = $this->_aModule['class_prefix'] . 'SearchResult';
  1431. $o = new $sClass();
  1432. $o->fillFilters(array(
  1433. 'active' => 0
  1434. ));
  1435. $o->unsetPaginate();
  1436. return $o->getNum();
  1437. }
  1438. /*
  1439. * COMMON METHODS
  1440. */
  1441. public function deleteEvent($aEvent)
  1442. {
  1443. if(empty($aEvent) || !is_array($aEvent) || !$this->_oDb->deleteEvent(array('id' => (int)$aEvent['id'])))
  1444. return false;
  1445. $this->onDelete($aEvent);
  1446. return true;
  1447. }
  1448. public function addAttachLink($aValues, $sDisplay = false)
  1449. {
  1450. $CNF = &$this->_oConfig->CNF;
  1451. if(!$sDisplay)
  1452. $sDisplay = $this->_oConfig->getObject('form_display_attach_link_add');
  1453. $oForm = BxDolForm::getObjectInstance($this->_oConfig->getObject('form_attach_link'), $sDisplay, $this->_oTemplate);
  1454. if(!$oForm)
  1455. return array('message' => '_sys_txt_error_occured');
  1456. $oForm->aFormAttrs['method'] = BX_DOL_FORM_METHOD_SPECIFIC;
  1457. $oForm->aParams['csrf']['disable'] = true;
  1458. if(!empty($oForm->aParams['db']['submit_name'])) {
  1459. $sSubmitName = $oForm->aParams['db']['submit_name'];
  1460. if(!isset($oForm->aInputs[$sSubmitName])) {
  1461. if(isset($oForm->aInputs[$CNF['FIELD_CONTROLS']]))
  1462. foreach($oForm->aInputs[$CNF['FIELD_CONTROLS']] as $mixedIndex => $aInput) {
  1463. if(!is_numeric($mixedIndex) || empty($aInput['name']) || $aInput['name'] != $sSubmitName)
  1464. continue;
  1465. $aValues[$sSubmitName] = $aInput['value'];
  1466. }
  1467. }
  1468. else
  1469. $aValues[$sSubmitName] = $oForm->aInputs[$sSubmitName]['value'];
  1470. }
  1471. $oForm->aInputs['url']['checker']['params']['preg'] = $this->_oConfig->getPregPattern('url');
  1472. $oForm->initChecker(array(), $aValues);
  1473. if(!$oForm->isSubmittedAndValid())
  1474. return array('message' => '_sys_txt_error_occured');
  1475. return $this->_addLink($oForm);
  1476. }
  1477. public function getFormAttachLink()
  1478. {
  1479. $oForm = BxDolForm::getObjectInstance($this->_oConfig->getObject('form_attach_link'), $this->_oConfig->getObject('form_display_attach_link_add'), $this->_oTemplate);
  1480. $oForm->aFormAttrs['action'] = BX_DOL_URL_ROOT . $this->_oConfig->getBaseUri() . 'submit_attach_link_form/';
  1481. $oForm->aInputs['url']['checker']['params']['preg'] = $this->_oConfig->getPregPattern('url');
  1482. $oForm->initChecker();
  1483. if($oForm->isSubmittedAndValid())
  1484. return $this->_addLink($oForm);
  1485. return array('form' => $oForm->getCode(), 'form_id' => $oForm->id);
  1486. }
  1487. public function getFormPost($aParams = array())
  1488. {
  1489. $iUserId = $this->getUserId();
  1490. $oForm = $this->getFormPostObject($aParams);
  1491. $oForm->initChecker();
  1492. $bAjaxMode = $oForm->isAjaxMode();
  1493. $bDynamicMode = $bAjaxMode;
  1494. if($oForm->isSubmittedAndValid()) {
  1495. list($sUserName) = $this->getUserInfo($iUserId);
  1496. $sType = $oForm->getCleanValue('type');
  1497. $sType = $this->_oConfig->getPrefix('common_post') . $sType;
  1498. BxDolForm::setSubmittedValue('type', $sType, $oForm->aFormAttrs['method']);
  1499. $aContent = array();
  1500. //--- Process Text ---//
  1501. $sText = $oForm->getCleanValue('text');
  1502. $sText = $this->_prepareTextForSave($sText);
  1503. $bText = !empty($sText);
  1504. unset($oForm->aInputs['text']);
  1505. if($bText)
  1506. $aContent['text'] = $sText;
  1507. //--- Process Context and Privacy ---//
  1508. $iOwnerId = (int)$oForm->getCleanValue('owner_id');
  1509. $iObjectPrivacyView = (int)$oForm->getCleanValue('object_privacy_view');
  1510. $iObjectPrivacyViewDefault = $this->_oConfig->getPrivacyViewDefault('object');
  1511. if(empty($iObjectPrivacyView))
  1512. $iObjectPrivacyView = $iObjectPrivacyViewDefault;
  1513. else if($iObjectPrivacyView < 0)
  1514. $iOwnerId = abs($iObjectPrivacyView);
  1515. //--- Process Link ---//
  1516. $aLinkIds = $oForm->getCleanValue('link');
  1517. $bLinkIds = !empty($aLinkIds) && is_array($aLinkIds);
  1518. //--- Process Media ---//
  1519. $aPhotoIds = $oForm->getCleanValue(BX_TIMELINE_MEDIA_PHOTO);
  1520. $bPhotoIds = !empty($aPhotoIds) && is_array($aPhotoIds);
  1521. $aVideoIds = $oForm->getCleanValue(BX_TIMELINE_MEDIA_VIDEO);
  1522. $bVideoIds = !empty($aVideoIds) && is_array($aVideoIds);
  1523. if(!$bText && !$bLinkIds && !$bPhotoIds && !$bVideoIds)
  1524. return array('message' => _t('_bx_timeline_txt_err_empty_post'));
  1525. $sTitle = $bText ? $this->_oConfig->getTitle($sText) : $this->_oTemplate->getItemIcon($bText, $bLinkIds, $bPhotoIds, $bVideoIds);
  1526. $sDescription = _t('_bx_timeline_txt_user_added_sample', $sUserName, _t('_bx_timeline_txt_sample_with_article'));
  1527. //--- Process Date ---//
  1528. $iDate = 0;
  1529. if(isset($oForm->aInputs['date']))
  1530. $iDate = $oForm->getCleanValue('date');
  1531. if(empty($iDate))
  1532. $iDate = time();
  1533. $iId = $oForm->insert(array(
  1534. 'owner_id' => $iOwnerId,
  1535. 'object_id' => $iUserId,
  1536. 'object_privacy_view' => $iObjectPrivacyView,
  1537. 'content' => serialize($aContent),
  1538. 'title' => $sTitle,
  1539. 'description' => $sDescription,
  1540. 'date' => $iDate
  1541. ));
  1542. if(!empty($iId)) {
  1543. $oMetatags = BxDolMetatags::getObjectInstance($this->_oConfig->getObject('metatags'));
  1544. if($bText)
  1545. $oMetatags->metaAdd($iId, $sText);
  1546. $oMetatags->locationsAddFromForm($iId, $this->_oConfig->CNF['FIELD_LOCATION_PREFIX']);
  1547. //--- Process Link ---//
  1548. if($bLinkIds)
  1549. foreach($aLinkIds as $iLinkId)
  1550. $this->_oDb->saveLink($iId, $iLinkId);
  1551. //--- Process Media ---//
  1552. if($bPhotoIds)
  1553. $this->_saveMedia(BX_TIMELINE_MEDIA_PHOTO, $iId, $aPhotoIds);
  1554. if($bVideoIds)
  1555. $this->_saveMedia(BX_TIMELINE_MEDIA_VIDEO, $iId, $aVideoIds);
  1556. $this->onPost($iId);
  1557. return $this->_prepareResponse(array('id' => $iId), $bAjaxMode, array(
  1558. 'redirect' => $this->_oConfig->getItemViewUrl(array('id' => $iId))
  1559. ));
  1560. }
  1561. return $this->_prepareResponse(array('message' => _t('_bx_timeline_txt_err_cannot_perform_action')), $bAjaxMode);
  1562. }
  1563. return $this->_prepareResponse(array('form' => $oForm->getCode($bDynamicMode), 'form_id' => $oForm->id), $bAjaxMode && $oForm->isSubmitted());
  1564. }
  1565. public function getFormEdit($iId, $aParams = array())
  1566. {
  1567. $CNF = &$this->_oConfig->CNF;
  1568. $aEvent = $this->_oDb->getEvents(array('browse' => 'id', 'value' => $iId));
  1569. if(empty($aEvent) || !is_array($aEvent))
  1570. return array();
  1571. $aContent = unserialize($aEvent['content']);
  1572. if(is_array($aContent) && !empty($aContent['text']))
  1573. $aEvent['text'] = $aContent['text'];
  1574. $bDynamicMode = isset($aParams['dynamic_mode']) ? (bool)$aParams['dynamic_mode'] : false;
  1575. $sFormObject = !empty($aParams['form_object']) ? $aParams['form_object'] : 'form_post';
  1576. $sFormDisplay = !empty($aParams['form_display']) ? $aParams['form_display'] : 'form_display_post_edit';
  1577. $oForm = BxDolForm::getObjectInstance($this->_oConfig->getObject($sFormObject), $this->_oConfig->getObject($sFormDisplay), $this->_oTemplate);
  1578. $oForm->setId($this->_oConfig->getHtmlIds('view', 'edit_form') . $iId);
  1579. $oForm->aFormAttrs['action'] = BX_DOL_URL_ROOT . $this->_oConfig->getBaseUri() . 'edit/' . $iId ;
  1580. foreach($oForm->aInputs[$CNF['FIELD_CONTROLS']] as $mixedIndex => $aInput) {
  1581. if(!is_numeric($mixedIndex))
  1582. continue;
  1583. $oForm->aInputs[$CNF['FIELD_CONTROLS']][$mixedIndex]['attrs'] = bx_replace_markers($aInput['attrs'], array(
  1584. 'js_object_view' => $this->_oConfig->getJsObject('view'),
  1585. 'content_id' => $iId
  1586. ));
  1587. }
  1588. $oForm->initChecker($aEvent);
  1589. if($oForm->isSubmittedAndValid()) {
  1590. $aContent = array();
  1591. //--- Process Text ---//
  1592. $sText = $oForm->getCleanValue('text');
  1593. $sText = $this->_prepareTextForSave($sText);
  1594. $bText = !empty($sText);
  1595. unset($oForm->aInputs['text']);
  1596. if($bText)
  1597. $aContent['text'] = $sText;
  1598. $aValsToAdd = array(
  1599. 'content' => serialize($aContent)
  1600. );
  1601. //--- Process Privacy ---//
  1602. $iObjectPrivacyView = (int)$oForm->getCleanValue('object_privacy_view');
  1603. $iObjectPrivacyViewDefault = $this->_oConfig->getPrivacyViewDefault('object');
  1604. if(empty($iObjectPrivacyView))
  1605. $aValsToAdd = array_merge($aValsToAdd, array(
  1606. 'object_privacy_view' => $iObjectPrivacyViewDefault
  1607. ));
  1608. else if($iObjectPrivacyView < 0)
  1609. $aValsToAdd = array_merge($aValsToAdd, array(
  1610. 'owner_id' => abs($iObjectPrivacyView),
  1611. 'object_privacy_view' => $iObjectPrivacyViewDefault
  1612. ));
  1613. //--- Process Date ---//
  1614. if(isset($oForm->aInputs['date'])) {
  1615. $iDate = $oForm->getCleanValue('date');
  1616. if(empty($iDate))
  1617. $iDate = time();
  1618. $aValsToAdd['date'] = $iDate;
  1619. }
  1620. if(!$oForm->update($iId, $aValsToAdd))
  1621. return array('message' => _t('_bx_timeline_txt_err_cannot_perform_action'));
  1622. $oMetatags = BxDolMetatags::getObjectInstance($this->_oConfig->getObject('metatags'));
  1623. if($bText)
  1624. $oMetatags->metaAdd($iId, $sText);
  1625. $oMetatags->locationsAddFromForm($iId, $this->_oConfig->CNF['FIELD_LOCATION_PREFIX']);
  1626. return array(
  1627. 'id' => $iId,
  1628. 'eval' => $this->_oConfig->getJsObject('view') . '.onEditPostSubmit(oData)'
  1629. );
  1630. }
  1631. return array(
  1632. 'id' => $iId,
  1633. 'form' => $oForm->getCode($bDynamicMode),
  1634. 'form_id' => $oForm->id,
  1635. 'eval' => $this->_oConfig->getJsObject('view') . '.onEditPost(oData)'
  1636. );
  1637. }
  1638. public function getFormPostObject($aParams)
  1639. {
  1640. $sFormObject = !empty($aParams['form_object']) ? $aParams['form_object'] : 'form_post';
  1641. $sFormDisplay = !empty($aParams['form_display']) ? $aParams['form_display'] : 'form_display_post_add';
  1642. return BxDolForm::getObjectInstance($this->_oConfig->getObject($sFormObject), $this->_oConfig->getObject($sFormDisplay), $this->_oTemplate);
  1643. }
  1644. public function getCmtsObject($sSystem, $iId)
  1645. {
  1646. if(empty($sSystem) || (int)$iId == 0)
  1647. return false;
  1648. $oCmts = BxDolCmts::getObjectInstance($sSystem, $iId, true, $this->_oTemplate);
  1649. if(!$oCmts || !$oCmts->isEnabled())
  1650. return false;
  1651. return $oCmts;
  1652. }
  1653. public function getViewObject($sSystem, $iId)
  1654. {
  1655. if(empty($sSystem) || (int)$iId == 0)
  1656. return false;
  1657. $oView = BxDolView::getObjectInstance($sSystem, $iId, true, $this->_oTemplate);
  1658. if(!$oView || !$oView->isEnabled())
  1659. return false;
  1660. return $oView;
  1661. }
  1662. public function getVoteObject($sSystem, $iId)
  1663. {
  1664. if(empty($sSystem) || (int)$iId == 0)
  1665. return false;
  1666. $oVote = BxDolVote::getObjectInstance($sSystem, $iId, true, $this->_oTemplate);
  1667. if(!$oVote || !$oVote->isEnabled())
  1668. return false;
  1669. return $oVote;
  1670. }
  1671. public function getScoreObject($sSystem, $iId)
  1672. {
  1673. if(empty($sSystem) || (int)$iId == 0)
  1674. return false;
  1675. $oScore = BxDolScore::getObjectInstance($sSystem, $iId, true, $this->_oTemplate);
  1676. if(!$oScore || !$oScore->isEnabled())
  1677. return false;
  1678. return $oScore;
  1679. }
  1680. public function getReportObject($sSystem, $iId)
  1681. {
  1682. if(empty($sSystem) || (int)$iId == 0)
  1683. return false;
  1684. $oReport = BxDolReport::getObjectInstance($sSystem, $iId, true, $this->_oTemplate);
  1685. if(!$oReport || !$oReport->isEnabled())
  1686. return false;
  1687. return $oReport;
  1688. }
  1689. public function getAttachmentsMenuObject()
  1690. {
  1691. $oMenu = BxDolMenu::getObjectInstance($this->_oConfig->getObject('menu_post_attachments'), $this->_oTemplate);
  1692. $oMenu->addMarkers(array(
  1693. 'js_object' => $this->_oConfig->getJsObject('post'),
  1694. ));
  1695. return $oMenu;
  1696. }
  1697. public function getManageMenuObject()
  1698. {
  1699. return BxDolMenu::getObjectInstance($this->_oConfig->getObject('menu_item_manage'), $this->_oTemplate);
  1700. }
  1701. //--- Check permissions methods ---//
  1702. public function isAllowedPost($bPerform = false)
  1703. {
  1704. if(isAdmin())
  1705. return true;
  1706. $iUserId = $this->getUserId();
  1707. $aCheckResult = checkActionModule($iUserId, 'post', $this->getName(), $bPerform);
  1708. $oProfileOwner = BxDolProfile::getInstance($this->_iOwnerId);
  1709. if($oProfileOwner !== false) {
  1710. if($oProfileOwner->checkAllowedPostInProfile() !== CHECK_ACTION_RESULT_ALLOWED)
  1711. return _t('_sys_txt_access_denied');
  1712. bx_alert($oProfileOwner->getModule(), $this->_oConfig->getUri() . '_post', $oProfileOwner->id(), $iUserId, array('check_result' => &$aCheckResult));
  1713. }
  1714. return $aCheckResult[CHECK_ACTION_RESULT] !== CHECK_ACTION_RESULT_ALLOWED ? $aCheckResult[CHECK_ACTION_MESSAGE] : true;
  1715. }
  1716. public function isAllowedView($aEvent, $bPerform = false)
  1717. {
  1718. $CNF = $this->_oConfig->CNF;
  1719. $mixedResult = BxDolProfile::getInstance($aEvent[$CNF['FIELD_OWNER_ID']])->checkAllowedProfileView();
  1720. if($mixedResult !== CHECK_ACTION_RESULT_ALLOWED)
  1721. return false;
  1722. return true;
  1723. }
  1724. public function isAllowedEdit($aEvent, $bPerform = false)
  1725. {
  1726. if(!isLogged())
  1727. return false;
  1728. //--- System posts and Reposts cannot be edited at all.
  1729. if(!$this->_oConfig->isCommon($aEvent['type'], $aEvent['action']) || $aEvent['type'] == $this->_oConfig->getPrefix('common_post') . 'repost')
  1730. return false;
  1731. if(isAdmin())
  1732. return true;
  1733. $iUserId = (int)$this->getUserId();
  1734. $iOwnerId = (int)$aEvent['owner_id'];
  1735. $iObjectId = (int)$aEvent['object_id'];
  1736. if($iObjectId == $iUserId && $this->_oConfig->isAllowEdit())
  1737. return true;
  1738. $aCheckResult = checkActionModule($iUserId, 'edit', $this->getName(), $bPerform);
  1739. $oProfileOwner = BxDolProfile::getInstance($iOwnerId);
  1740. if($oProfileOwner !== false)
  1741. bx_alert($oProfileOwner->getModule(), $this->_oConfig->getUri() . '_edit', $oProfileOwner->id(), $iUserId, array('check_result' => &$aCheckResult));
  1742. return $aCheckResult[CHECK_ACTION_RESULT] !== CHECK_ACTION_RESULT_ALLOWED ? $aCheckResult[CHECK_ACTION_MESSAGE] : true;
  1743. }
  1744. public function isAllowedDelete($aEvent, $bPerform = false)
  1745. {
  1746. if(!isLogged())
  1747. return false;
  1748. if(isAdmin())
  1749. return true;
  1750. $iUserId = (int)$this->getUserId();
  1751. $iOwnerId = (int)$aEvent['owner_id'];
  1752. $iObjectId = (int)$aEvent['object_id'];
  1753. if((($iOwnerId == $iUserId && $this->_oConfig->isAllowDelete()) || ($this->_oConfig->isCommon($aEvent['type'], $aEvent['action']) && $iObjectId == $iUserId)))
  1754. return true;
  1755. $aCheckResult = checkActionModule($iUserId, 'delete', $this->getName(), $bPerform);
  1756. $oProfileOwner = BxDolProfile::getInstance($iOwnerId);
  1757. if($oProfileOwner !== false)
  1758. bx_alert($oProfileOwner->getModule(), $this->_oConfig->getUri() . '_delete', $oProfileOwner->id(), $iUserId, array('check_result' => &$aCheckResult));
  1759. return $aCheckResult[CHECK_ACTION_RESULT] !== CHECK_ACTION_RESULT_ALLOWED ? $aCheckResult[CHECK_ACTION_MESSAGE] : true;
  1760. }
  1761. public function isAllowedComment($aEvent, $bPerform = false)
  1762. {
  1763. $mixedComments = $this->getCommentsData($aEvent['comments']);
  1764. if($mixedComments === false)
  1765. return false;
  1766. list($sSystem, $iObjectId) = $mixedComments;
  1767. $oCmts = $this->getCmtsObject($sSystem, $iObjectId);
  1768. $oCmts->addCssJs();
  1769. $bResult = true;
  1770. $oProfileOwner = BxDolProfile::getInstance($aEvent['owner_id']);
  1771. if($oProfileOwner !== false) {
  1772. if($oProfileOwner->checkAllowedPostInProfile() !== CHECK_ACTION_RESULT_ALLOWED)
  1773. return false;
  1774. bx_alert($oProfileOwner->getModule(), $this->_oConfig->getUri() . '_comment', $oProfileOwner->id(), (int)$this->getUserId(), array('result' => &$bResult));
  1775. }
  1776. return $bResult;
  1777. }
  1778. public function isAllowedViewCounter($aEvent, $bPerform = false)
  1779. {
  1780. $mixedViews = $this->getViewsData($aEvent['views']);
  1781. if($mixedViews === false)
  1782. return false;
  1783. list($sSystem, $iObjectId) = $mixedViews;
  1784. $oView = $this->getViewObject($sSystem, $iObjectId);
  1785. if(!$oView->isAllowedViewView($bPerform))
  1786. return false;
  1787. $bResult = true;
  1788. $oProfileOwner = BxDolProfile::getInstance($aEvent['owner_id']);
  1789. if($oProfileOwner !== false)
  1790. bx_alert($oProfileOwner->getModule(), $this->_oConfig->getUri() . '_view_counter', $oProfileOwner->id(), (int)$this->getUserId(), array('result' => &$bResult));
  1791. return $bResult;
  1792. }
  1793. public function isAllowedVote($aEvent, $bPerform = false)
  1794. {
  1795. $mixedVotes = $this->getVotesData($aEvent['votes']);
  1796. if($mixedVotes === false)
  1797. return false;
  1798. list($sSystem, $iObjectId) = $mixedVotes;
  1799. $oVote = $this->getVoteObject($sSystem, $iObjectId);
  1800. if(!$oVote->isAllowedVote($bPerform))
  1801. return false;
  1802. $bResult = true;
  1803. $oProfileOwner = BxDolProfile::getInstance($aEvent['owner_id']);
  1804. if($oProfileOwner !== false)
  1805. bx_alert($oProfileOwner->getModule(), $this->_oConfig->getUri() . '_vote', $oProfileOwner->id(), (int)$this->getUserId(), array('result' => &$bResult));
  1806. return $bResult;
  1807. }
  1808. public function isAllowedScore($aEvent, $bPerform = false)
  1809. {
  1810. $mixedScores = $this->getScoresData($aEvent['scores']);
  1811. if($mixedScores === false)
  1812. return false;
  1813. list($sSystem, $iObjectId) = $mixedScores;
  1814. $oScore = $this->getScoreObject($sSystem, $iObjectId);
  1815. if(!$oScore->isAllowedVote($bPerform))
  1816. return false;
  1817. $bResult = true;
  1818. $oProfileOwner = BxDolProfile::getInstance($aEvent['owner_id']);
  1819. if($oProfileOwner !== false)
  1820. bx_alert($oProfileOwner->getModule(), $this->_oConfig->getUri() . '_score', $oProfileOwner->id(), (int)$this->getUserId(), array('result' => &$bResult));
  1821. return $bResult;
  1822. }
  1823. public function isAllowedReport($aEvent, $bPerform = false)
  1824. {
  1825. $mixedReports = $this->getReportsData($aEvent['reports']);
  1826. if($mixedReports === false)
  1827. return false;
  1828. list($sSystem, $iObjectId) = $mixedReports;
  1829. $oReport = $this->getReportObject($sSystem, $iObjectId);
  1830. if(!$oReport->isAllowedReport($bPerform))
  1831. return false;
  1832. $bResult = true;
  1833. $oProfileOwner = BxDolProfile::getInstance($aEvent['owner_id']);
  1834. if($oProfileOwner !== false)
  1835. bx_alert($oProfileOwner->getModule(), $this->_oConfig->getUri() . '_report', $oProfileOwner->id(), (int)$this->getUserId(), array('result' => &$bResult));
  1836. return $bResult;
  1837. }
  1838. public function isAllowedRepost($aEvent, $bPerform = false)
  1839. {
  1840. if(isAdmin())
  1841. return true;
  1842. $iUserId = (int)$this->getUserId();
  1843. if($iUserId == 0)
  1844. return false;
  1845. $aCheckResult = checkActionModule($iUserId, 'repost', $this->getName(), $bPerform);
  1846. $oProfileOwner = BxDolProfile::getInstance($aEvent['owner_id']);
  1847. if($oProfileOwner !== false)
  1848. bx_alert($oProfileOwner->getModule(), $this->_oConfig->getUri() . '_repost', $oProfileOwner->id(), $iUserId, array('check_result' => &$aCheckResult));
  1849. return $aCheckResult[CHECK_ACTION_RESULT] !== CHECK_ACTION_RESULT_ALLOWED ? $aCheckResult[CHECK_ACTION_MESSAGE] : true;
  1850. }
  1851. public function isAllowedSend($aEvent, $bPerform = false)
  1852. {
  1853. if(!$this->_oDb->isEnabledByName('bx_convos'))
  1854. return false;
  1855. if(isAdmin())
  1856. return true;
  1857. $iUserId = (int)$this->getUserId();
  1858. if($iUserId == 0)
  1859. return false;
  1860. $aCheckResult = checkActionModule($iUserId, 'send', $this->getName(), $bPerform);
  1861. $oProfileOwner = BxDolProfile::getInstance($aEvent['owner_id']);
  1862. if($oProfileOwner !== false)
  1863. bx_alert($oProfileOwner->getModule(), $this->_oConfig->getUri() . '_send', $oProfileOwner->id(), $iUserId, array('check_result' => &$aCheckResult));
  1864. return $aCheckResult[CHECK_ACTION_RESULT] !== CHECK_ACTION_RESULT_ALLOWED ? $aCheckResult[CHECK_ACTION_MESSAGE] : true;
  1865. }
  1866. public function isAllowedPin($aEvent, $bPerform = false)
  1867. {
  1868. if((int)$aEvent['pinned'] != 0)
  1869. return false;
  1870. return $this->_isAllowedPin($aEvent, $bPerform);
  1871. }
  1872. public function isAllowedUnpin($aEvent, $bPerform = false)
  1873. {
  1874. if((int)$aEvent['pinned'] == 0)
  1875. return false;
  1876. return $this->_isAllowedPin($aEvent, $bPerform);
  1877. }
  1878. public function isAllowedPromote($aEvent, $bPerform = false)
  1879. {
  1880. if((int)$aEvent['promoted'] != 0)
  1881. return false;
  1882. return $this->_isAllowedPromote($aEvent, $bPerform);
  1883. }
  1884. public function isAllowedUnpromote($aEvent, $bPerform = false)
  1885. {
  1886. if((int)$aEvent['promoted'] == 0)
  1887. return false;
  1888. return $this->_isAllowedPromote($aEvent, $bPerform);
  1889. }
  1890. public function isAllowedMore($aEvent, $bPerform = false)
  1891. {
  1892. $oMoreMenu = $this->getManageMenuObject();
  1893. $oMoreMenu->setEventById($aEvent['id']);
  1894. return $oMoreMenu->isVisible();
  1895. }
  1896. public function checkAllowedView ($aContentInfo, $isPerformAction = false)
  1897. {
  1898. if(!$this->isAllowedView($aContentInfo, $isPerformAction))
  1899. return _t('_sys_txt_access_denied');
  1900. return CHECK_ACTION_RESULT_ALLOWED;
  1901. }
  1902. public function checkAllowedCommentsView ($aContentInfo, $isPerformAction = false)
  1903. {
  1904. $CNF = $this->_oConfig->CNF;
  1905. $mixedResult = BxDolProfile::getInstance($aContentInfo[$CNF['FIELD_OWNER_ID']])->checkAllowedProfileView();
  1906. if($mixedResult !== CHECK_ACTION_RESULT_ALLOWED)
  1907. return $mixedResult;
  1908. return CHECK_ACTION_RESULT_ALLOWED;
  1909. }
  1910. public function checkAllowedCommentsPost ($aContentInfo, $isPerformAction = false)
  1911. {
  1912. $sError = '_sys_txt_access_denied';
  1913. $aContentInfo = $this->_oTemplate->getData($aContentInfo);
  1914. if($aContentInfo === false)
  1915. return _t($sError);
  1916. if(!$this->isAllowedComment($aContentInfo, $isPerformAction))
  1917. return _t($sError);
  1918. return CHECK_ACTION_RESULT_ALLOWED;
  1919. }
  1920. public function onPost($iId)
  1921. {
  1922. $aEvent = $this->_oDb->getEvents(array('browse' => 'id', 'value' => $iId));
  1923. if($this->_oConfig->isSystem($aEvent['type'], $aEvent['action'])) {
  1924. //--- Request event's data from content module and update it in the Timeline DB.
  1925. $this->_oTemplate->getData($aEvent);
  1926. $sPostType = 'system';
  1927. $iSenderId = $aEvent['owner_id'];
  1928. } else {
  1929. $sPostType = 'common';
  1930. $iSenderId = $aEvent['object_id'];
  1931. }
  1932. //--- Event -> Post for Alerts Engine ---//
  1933. $oAlert = new BxDolAlerts($this->_oConfig->getObject('alert'), 'post_' . $sPostType, $iId, $iSenderId, array(
  1934. 'privacy_view' => $aEvent['object_privacy_view'],
  1935. 'object_author_id' => $aEvent['owner_id'],
  1936. ));
  1937. $oAlert->alert();
  1938. //--- Event -> Post for Alerts Engine ---//
  1939. }
  1940. public function onRepost($iId, $aReposted = array())
  1941. {
  1942. $aEvent = $this->_oDb->getEvents(array('browse' => 'id', 'value' => $iId));
  1943. if(empty($aReposted)) {
  1944. $aContent = unserialize($aEvent['content']);
  1945. $aReposted = $this->_oDb->getReposted($aContent['type'], $aContent['action'], $aContent['object_id']);
  1946. if(empty($aReposted) || !is_array($aReposted))
  1947. return;
  1948. }
  1949. $iUserId = $this->getUserId();
  1950. $this->_oDb->insertRepostTrack($aEvent['id'], $iUserId, $this->getUserIp(), $aReposted['id']);
  1951. $this->_oDb->updateRepostCounter($aReposted['id'], $aReposted['reposts']);
  1952. //--- Timeline -> Update for Alerts Engine ---//
  1953. $oAlert = new BxDolAlerts($this->_oConfig->getObject('alert'), 'repost', $aReposted['id'], $iUserId, array(
  1954. 'privacy_view' => $aEvent['object_privacy_view'],
  1955. 'object_author_id' => $aReposted['owner_id'],
  1956. 'repost_id' => $iId,
  1957. ));
  1958. $oAlert->alert();
  1959. //--- Timeline -> Update for Alerts Engine ---//
  1960. }
  1961. public function onDelete($aEvent)
  1962. {
  1963. $iUserId = $this->getUserId();
  1964. $sCommonPostPrefix = $this->_oConfig->getPrefix('common_post');
  1965. $sCommonPostComment = $this->_oConfig->getObject('comment');
  1966. //--- Delete comments for Common posts.
  1967. if($this->_oConfig->isCommon($aEvent['type'], $aEvent['action'])) {
  1968. $oComments = $this->getCmtsObject($sCommonPostComment, $aEvent['id']);
  1969. if($oComments !== false)
  1970. $oComments->onObjectDelete($aEvent['id']);
  1971. }
  1972. //--- Delete attached photos, videos and links when common event was deleted.
  1973. if($aEvent['type'] == $sCommonPostPrefix . BX_TIMELINE_PARSE_TYPE_POST) {
  1974. $this->_deleteMedia(BX_TIMELINE_MEDIA_PHOTO, $aEvent['id']);
  1975. $this->_deleteMedia(BX_TIMELINE_MEDIA_VIDEO, $aEvent['id']);
  1976. $this->_deleteLinks($aEvent['id']);
  1977. }
  1978. //--- Update parent event when repost event was deleted.
  1979. $bRepost = $aEvent['type'] == $sCommonPostPrefix . BX_TIMELINE_PARSE_TYPE_REPOST;
  1980. if($bRepost) {
  1981. $this->_oDb->deleteRepostTrack($aEvent['id']);
  1982. $aContent = unserialize($aEvent['content']);
  1983. $aReposted = $this->_oDb->getReposted($aContent['type'], $aContent['action'], $aContent['object_id']);
  1984. if(!empty($aReposted) && is_array($aReposted))
  1985. $this->_oDb->updateRepostCounter($aReposted['id'], $aReposted['reposts'], -1);
  1986. }
  1987. //--- Find and delete repost events when parent event was deleted.
  1988. $bSystem = $this->_oConfig->isSystem($aEvent['type'], $aEvent['action']);
  1989. $aRepostEvents = $this->_oDb->getEvents(array('browse' => 'reposted_by_descriptor', 'type' => $aEvent['type']));
  1990. foreach($aRepostEvents as $aRepostEvent) {
  1991. $aContent = unserialize($aRepostEvent['content']);
  1992. if(isset($aContent['type']) && $aContent['type'] == $aEvent['type'] && isset($aContent['object_id']) && (($bSystem && (int)$aContent['object_id'] == (int)$aEvent['object_id']) || (!$bSystem && (int)$aContent['object_id'] == (int)$aEvent['id'])) && (int)$this->_oDb->deleteEvent(array('id' => (int)$aRepostEvent['id'])) > 0) {
  1993. $oComments = $this->getCmtsObject($sCommonPostComment, $aRepostEvent['id']);
  1994. if($oComments !== false)
  1995. $oComments->onObjectDelete($aRepostEvent['id']);
  1996. bx_alert($this->_oConfig->getObject('alert'), 'delete_repost', $aEvent['id'], $iUserId, array(
  1997. 'repost_id' => $aRepostEvent['id'],
  1998. ));
  1999. }
  2000. }
  2001. //--- Delete associated meta.
  2002. $oMetatags = BxDolMetatags::getObjectInstance($this->_oConfig->getObject('metatags'));
  2003. $oMetatags->onDeleteContent($aEvent['id']);
  2004. //--- Event -> Delete for Alerts Engine ---//
  2005. if($bRepost)
  2006. bx_alert($this->_oConfig->getObject('alert'), 'delete_repost', $aReposted['id'], $iUserId, array(
  2007. 'repost_id' => $aEvent['id'],
  2008. ));
  2009. else
  2010. bx_alert($this->_oConfig->getObject('alert'), 'delete', $aEvent['id'], $iUserId);
  2011. //--- Event -> Delete for Alerts Engine ---//
  2012. }
  2013. public function getParams($sView = '', $sType = '', $iOwnerId = 0, $iStart = 0, $iPerPage = 0, $sFilter = BX_TIMELINE_FILTER_ALL, $aModules = array(), $iTimeline = 0)
  2014. {
  2015. return $this->_prepareParams($sView, $sType, $iOwnerId, $iStart, $iPerPage, $sFilter, $aModules, $iTimeline);
  2016. }
  2017. public function getViewsData(&$aViews)
  2018. {
  2019. if(empty($aViews) || !is_array($aViews))
  2020. return false;
  2021. $sSystem = isset($aViews['system']) ? $aViews['system'] : '';
  2022. $iObjectId = isset($aViews['object_id']) ? (int)$aViews['object_id'] : 0;
  2023. $iCount = isset($aViews['count']) ? (int)$aViews['count'] : 0;
  2024. if($sSystem == '' || $iObjectId == 0)
  2025. return false;
  2026. return array($sSystem, $iObjectId, $iCount);
  2027. }
  2028. public function getVotesData(&$aVotes)
  2029. {
  2030. if(empty($aVotes) || !is_array($aVotes))
  2031. return false;
  2032. $sSystem = isset($aVotes['system']) ? $aVotes['system'] : '';
  2033. $iObjectId = isset($aVotes['object_id']) ? (int)$aVotes['object_id'] : 0;
  2034. $iCount = isset($aVotes['count']) ? (int)$aVotes['count'] : 0;
  2035. if($sSystem == '' || $iObjectId == 0)
  2036. return false;
  2037. return array($sSystem, $iObjectId, $iCount);
  2038. }
  2039. public function getScoresData(&$aScores)
  2040. {
  2041. if(empty($aScores) || !is_array($aScores))
  2042. return false;
  2043. $sSystem = isset($aScores['system']) ? $aScores['system'] : '';
  2044. $iObjectId = isset($aScores['object_id']) ? (int)$aScores['object_id'] : 0;
  2045. $iScore = isset($aScores['score']) ? (int)$aScores['score'] : 0;
  2046. if($sSystem == '' || $iObjectId == 0)
  2047. return false;
  2048. return array($sSystem, $iObjectId, $iScore);
  2049. }
  2050. public function getReportsData(&$aReports)
  2051. {
  2052. if(empty($aReports) || !is_array($aReports))
  2053. return false;
  2054. $sSystem = isset($aReports['system']) ? $aReports['system'] : '';
  2055. $iObjectId = isset($aReports['object_id']) ? (int)$aReports['object_id'] : 0;
  2056. $iCount = isset($aReports['count']) ? (int)$aReports['count'] : 0;
  2057. if($sSystem == '' || $iObjectId == 0)
  2058. return false;
  2059. return array($sSystem, $iObjectId, $iCount);
  2060. }
  2061. public function getCommentsData(&$aComments)
  2062. {
  2063. if(empty($aComments) || !is_array($aComments))
  2064. return false;
  2065. $sSystem = isset($aComments['system']) ? $aComments['system'] : '';
  2066. $iObjectId = isset($aComments['object_id']) ? (int)$aComments['object_id'] : 0;
  2067. $iCount = isset($aComments['count']) ? (int)$aComments['count'] : 0;
  2068. if($sSystem == '' || $iObjectId == 0 || ($iCount == 0 && !isLogged()))
  2069. return false;
  2070. return array($sSystem, $iObjectId, $iCount);
  2071. }
  2072. /**
  2073. * Protected Methods
  2074. */
  2075. protected function _serviceGetBlockView($iProfileId = 0, $sView = BX_TIMELINE_VIEW_DEFAULT)
  2076. {
  2077. if(empty($iProfileId) && bx_get('profile_id') !== false)
  2078. $iProfileId = bx_process_input(bx_get('profile_id'), BX_DATA_INT);
  2079. if(empty($iProfileId) && isLogged())
  2080. $iProfileId = bx_get_logged_profile_id();
  2081. $aBlock = $this->_getBlockView($iProfileId, $sView);
  2082. if(!empty($aBlock))
  2083. return $aBlock;
  2084. return array('content' => MsgBox(_t('_bx_timeline_txt_msg_no_results')));
  2085. }
  2086. protected function _serviceGetBlockViewProfile($sProfileModule = 'bx_persons', $iProfileContentId = 0, $sView = BX_TIMELINE_VIEW_DEFAULT, $iStart = -1, $iPerPage = -1, $sFilter = '', $aModules = array(), $iTimeline = -1)
  2087. {
  2088. if(empty($sProfileModule))
  2089. return array();
  2090. if(empty($iProfileContentId) && bx_get('id') !== false)
  2091. $iProfileContentId = bx_process_input(bx_get('id'), BX_DATA_INT);
  2092. $oProfile = BxDolProfile::getInstanceByContentAndType($iProfileContentId, $sProfileModule);
  2093. if(empty($oProfile))
  2094. return array();
  2095. return $this->_getBlockView($oProfile->id(), $sView, $iStart, $iPerPage, $sFilter, $aModules, $iTimeline);
  2096. }
  2097. protected function _serviceGetBlockViewHome($iProfileId = 0, $sView = BX_TIMELINE_VIEW_DEFAULT, $iStart = -1, $iPerPage = -1, $iPerPageDefault = -1, $iTimeline = -1, $sFilter = '', $aModules = array())
  2098. {
  2099. $sRssUrl = BX_DOL_URL_ROOT . $this->_oConfig->getBaseUri() . 'rss/' . BX_BASE_MOD_NTFS_TYPE_PUBLIC . '/';
  2100. BxDolTemplate::getInstance()->addPageRssLink(_t('_bx_timeline_page_title_view_home'), $sRssUrl);
  2101. return $this->_serviceGetBlockViewByType($iProfileId, $sView, BX_BASE_MOD_NTFS_TYPE_PUBLIC, $iStart, $iPerPage, $iPerPageDefault, $iTimeline, $sFilter, $aModules);
  2102. }
  2103. protected function _serviceGetBlockViewHot($iProfileId = 0, $sView = BX_TIMELINE_VIEW_DEFAULT, $iStart = -1, $iPerPage = -1, $iPerPageDefault = -1, $iTimeline = -1, $sFilter = '', $aModules = array())
  2104. {
  2105. $sRssUrl = BX_DOL_URL_ROOT . $this->_oConfig->getBaseUri() . 'rss/' . BX_TIMELINE_TYPE_HOT . '/';
  2106. BxDolTemplate::getInstance()->addPageRssLink(_t('_bx_timeline_page_title_view_hot'), $sRssUrl);
  2107. return $this->_serviceGetBlockViewByType($iProfileId, $sView, BX_TIMELINE_TYPE_HOT, $iStart, $iPerPage, $iPerPageDefault, $iTimeline, $sFilter, $aModules);
  2108. }
  2109. protected function _serviceGetBlockViewByType($iProfileId = 0, $sView = BX_TIMELINE_VIEW_DEFAULT, $sType = BX_TIMELINE_TYPE_DEFAULT, $iStart = -1, $iPerPage = -1, $iPerPageDefault = -1, $iTimeline = -1, $sFilter = '', $aModules = array())
  2110. {
  2111. $aParams = $this->_prepareParams($sView, $sType, $iProfileId, $iStart, $iPerPage, $sFilter, $aModules, $iTimeline);
  2112. $aParams['view'] = $sView;
  2113. $aParams['per_page'] = (int)$iPerPage > 0 ? $iPerPage : ((int)$iPerPageDefault > 0 ? $iPerPageDefault : $this->_oConfig->getPerPage());
  2114. $this->_iOwnerId = $aParams['owner_id'];
  2115. $sContent = $this->_oTemplate->getViewBlock($aParams);
  2116. return array('content' => $sContent);
  2117. }
  2118. protected function _getBlockPost($iProfileId, $aParams = array())
  2119. {
  2120. $this->_iOwnerId = $iProfileId;
  2121. if($this->isAllowedPost() !== true)
  2122. return array();
  2123. $sContent = $this->_oTemplate->getPostBlock($this->_iOwnerId, $aParams);
  2124. return array('content' => $sContent);
  2125. }
  2126. protected function _getBlockView($iProfileId, $sView = BX_TIMELINE_VIEW_DEFAULT, $iStart = -1, $iPerPage = -1, $sFilter = '', $aModules = array(), $iTimeline = -1)
  2127. {
  2128. if(!$iProfileId)
  2129. return array();
  2130. $aParams = $this->_prepareParams($sView, BX_BASE_MOD_NTFS_TYPE_OWNER, $iProfileId, $iStart, $iPerPage, $sFilter, $aModules, $iTimeline);
  2131. $aParams['view'] = $sView;
  2132. $aParams['per_page'] = (int)$iPerPage > 0 ? $iPerPage : $this->_oConfig->getPerPage('profile');
  2133. $this->_iOwnerId = $aParams['owner_id'];
  2134. $oProfileOwner = BxDolProfile::getInstance($this->_iOwnerId);
  2135. $mixedResult = $oProfileOwner->checkAllowedProfileView();
  2136. if($mixedResult !== CHECK_ACTION_RESULT_ALLOWED)
  2137. return array('content' => MsgBox($mixedResult));
  2138. list($sUserName, $sUserUrl) = $this->getUserInfo($aParams['owner_id']);
  2139. $sRssUrl = BX_DOL_URL_ROOT . $this->_oConfig->getBaseUri() . 'rss/' . BX_BASE_MOD_NTFS_TYPE_OWNER . '/' . $iProfileId . '/';
  2140. $sJsObject = $this->_oConfig->getJsObject('view');
  2141. $aMenu = array(
  2142. 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),
  2143. 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)),
  2144. 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')),
  2145. array('id' => $sView . '-get-rss', 'name' => $sView . '-get-rss', 'class' => '', 'link' => $sRssUrl, 'target' => '_blank', 'title' => _t('_bx_timeline_menu_item_get_rss')),
  2146. );
  2147. $sContent = '';
  2148. bx_alert($oProfileOwner->getModule(), $this->_oConfig->getUri() . '_view', $this->_iOwnerId, $this->getUserId(), array('override_content' => &$sContent, 'params' => &$aParams, 'menu' => &$aMenu));
  2149. $oMenu = new BxTemplMenuInteractive(array('template' => 'menu_interactive_vertical.html', 'menu_id'=> $sView . '-view-all', 'menu_items' => $aMenu));
  2150. $oMenu->setSelected('', $sView . '-view-all');
  2151. if (!$sContent)
  2152. $sContent = $this->_oTemplate->getViewBlock($aParams);
  2153. BxDolTemplate::getInstance()->addPageRssLink(_t('_bx_timeline_page_title_view'), $sRssUrl);
  2154. return array('content' => $sContent, 'menu' => $oMenu);
  2155. }
  2156. protected function _isAllowedPin($aEvent, $bPerform = false)
  2157. {
  2158. if(isAdmin())
  2159. return true;
  2160. $iUserId = (int)$this->getUserId();
  2161. if($iUserId == 0)
  2162. return false;
  2163. if((int)$aEvent['owner_id'] == $iUserId)
  2164. return true;
  2165. $aCheckResult = checkActionModule($iUserId, 'pin', $this->getName(), $bPerform);
  2166. $oProfileOwner = BxDolProfile::getInstance($aEvent['owner_id']);
  2167. if($oProfileOwner !== false)
  2168. bx_alert($oProfileOwner->getModule(), $this->_oConfig->getUri() . '_pin', $oProfileOwner->id(), $iUserId, array('check_result' => &$aCheckResult));
  2169. return $aCheckResult[CHECK_ACTION_RESULT] !== CHECK_ACTION_RESULT_ALLOWED ? $aCheckResult[CHECK_ACTION_MESSAGE] : true;
  2170. }
  2171. protected function _isAllowedPromote($aEvent, $bPerform = false)
  2172. {
  2173. if(isAdmin())
  2174. return true;
  2175. $iUserId = (int)$this->getUserId();
  2176. if($iUserId == 0)
  2177. return false;
  2178. $aCheckResult = checkActionModule($iUserId, 'promote', $this->getName(), $bPerform);
  2179. $oProfileOwner = BxDolProfile::getInstance($aEvent['owner_id']);
  2180. if($oProfileOwner !== false)
  2181. bx_alert($oProfileOwner->getModule(), $this->_oConfig->getUri() . '_promote', $oProfileOwner->id(), $iUserId, array('check_result' => &$aCheckResult));
  2182. return $aCheckResult[CHECK_ACTION_RESULT] !== CHECK_ACTION_RESULT_ALLOWED ? $aCheckResult[CHECK_ACTION_MESSAGE] : true;
  2183. }
  2184. protected function _addLink(&$oForm)
  2185. {
  2186. $iUserId = $this->getUserId();
  2187. $sLink = $oForm->getCleanValue('url');
  2188. $aMatches = array();
  2189. preg_match($this->_oConfig->getPregPattern('url'), $sLink, $aMatches);
  2190. $sLink = (empty($aMatches[2]) ? 'http://' : '') . $aMatches[0];
  2191. $aSiteInfo = bx_get_site_info($sLink, array(
  2192. 'thumbnailUrl' => array('tag' => 'link', 'content_attr' => 'href'),
  2193. 'OGImage' => array('name_attr' => 'property', 'name' => 'og:image'),
  2194. ));
  2195. $sTitle = !empty($aSiteInfo['title']) ? $aSiteInfo['title'] : _t('_Empty');
  2196. $sDescription = !empty($aSiteInfo['description']) ? $aSiteInfo['description'] : _t('_Empty');
  2197. $sMediaUrl = '';
  2198. if(!empty($aSiteInfo['thumbnailUrl']))
  2199. $sMediaUrl = $aSiteInfo['thumbnailUrl'];
  2200. else if(!empty($aSiteInfo['OGImage']))
  2201. $sMediaUrl = $aSiteInfo['OGImage'];
  2202. $iMediaId = 0;
  2203. $oStorage = null;
  2204. if(!empty($sMediaUrl)) {
  2205. $oStorage = BxDolStorage::getObjectInstance($this->_oConfig->getObject('storage_' . BX_TIMELINE_MEDIA_PHOTO . 's'));
  2206. $iMediaId = $oStorage->storeFileFromUrl($sMediaUrl, true, $iUserId);
  2207. }
  2208. $iId = (int)$oForm->insert(array('profile_id' => $iUserId, 'media_id' => $iMediaId, 'url' => $sLink, 'title' => $sTitle, 'text' => $sDescription, 'added' => time()));
  2209. if(!empty($iId)) {
  2210. if(!empty($oStorage) && !empty($iMediaId))
  2211. $oStorage->afterUploadCleanup($iMediaId, $iUserId);
  2212. return array('id' => $iId, 'item' => $this->_oTemplate->getAttachLinkItem($iUserId, $iId));
  2213. }
  2214. return array('message' => _t('_bx_timeline_txt_err_cannot_perform_action'));
  2215. }
  2216. protected function _deleteLinks($iId)
  2217. {
  2218. $aLinks = $this->_oDb->getLinks($iId);
  2219. if(empty($aLinks) || !is_array($aLinks))
  2220. return;
  2221. $oStorage = BxDolStorage::getObjectInstance($this->_oConfig->getObject('storage_photos'));
  2222. foreach($aLinks as $aLink)
  2223. if(!empty($aLink['media_id']))
  2224. $oStorage->deleteFile($aLink['media_id']);
  2225. $this->_oDb->deleteLinks($iId);
  2226. }
  2227. protected function _saveMedia($sType, $iId, $aItemIds)
  2228. {
  2229. if(empty($aItemIds) || !is_array($aItemIds))
  2230. return;
  2231. $iUserId = $this->getUserId();
  2232. $oStorage = BxDolStorage::getObjectInstance($this->_oConfig->getObject('storage_' . strtolower($sType) . 's'));
  2233. foreach($aItemIds as $iItemId)
  2234. if($this->_oDb->saveMedia($sType, $iId, $iItemId))
  2235. $oStorage->afterUploadCleanup($iItemId, $iUserId);
  2236. }
  2237. protected function _deleteMedia($sType, $iId)
  2238. {
  2239. $aItems = $this->_oDb->getMedia($sType, $iId);
  2240. if(empty($aItems) || !is_array($aItems))
  2241. return;
  2242. $oStorage = BxDolStorage::getObjectInstance($this->_oConfig->getObject('storage_' . strtolower($sType) . 's'));
  2243. foreach($aItems as $iItemId)
  2244. $oStorage->deleteFile($iItemId);
  2245. $this->_oDb->deleteMedia($sType, $iId);
  2246. }
  2247. protected function _prepareParams($sView, $sType, $iOwnerId, $iStart, $iPerPage, $sFilter = BX_TIMELINE_FILTER_ALL, $aModules = array(), $iTimeline = 0, $aBlink = array())
  2248. {
  2249. $aParams = array(
  2250. 'view' => !empty($sView) ? $sView : BX_TIMELINE_VIEW_DEFAULT,
  2251. 'browse' => 'list',
  2252. 'type' => !empty($sType) ? $sType : BX_TIMELINE_TYPE_DEFAULT,
  2253. 'owner_id' => (int)$iOwnerId != 0 ? $iOwnerId : $this->getUserId(),
  2254. 'filter' => !empty($sFilter) ? $sFilter : BX_TIMELINE_FILTER_ALL,
  2255. 'modules' => is_array($aModules) && !empty($aModules) ? $aModules : array(),
  2256. 'timeline' => (int)$iTimeline > 0 ? $iTimeline : 0,
  2257. 'blink' => is_array($aBlink) && !empty($aBlink) ? $aBlink : array(),
  2258. 'active' => 1,
  2259. 'hidden' => 0
  2260. );
  2261. if($iStart !== false)
  2262. $aParams['start'] = (int)$iStart > 0 ? $iStart : 0;
  2263. if($iPerPage !== false)
  2264. $aParams['per_page'] = (int)$iPerPage > 0 ? $iPerPage : $this->_oConfig->getPerPage();
  2265. if($this->_oConfig->isHot())
  2266. $aParams['hot'] = $this->_oDb->getHot();
  2267. return $aParams;
  2268. }
  2269. protected function _prepareParamsGet()
  2270. {
  2271. $aParams = array(
  2272. 'browse' => 'list',
  2273. 'dynamic_mode' => true,
  2274. );
  2275. $aParams['view'] = bx_get('view');
  2276. $aParams['view'] = $aParams['view'] !== false ? bx_process_input($aParams['view'], BX_DATA_TEXT) : BX_TIMELINE_VIEW_DEFAULT;
  2277. $aParams['type'] = bx_get('type');
  2278. $aParams['type'] = $aParams['type'] !== false ? bx_process_input($aParams['type'], BX_DATA_TEXT) : BX_TIMELINE_TYPE_DEFAULT;
  2279. $aParams['owner_id'] = bx_get('owner_id');
  2280. $aParams['owner_id'] = $aParams['owner_id'] !== false ? bx_process_input($aParams['owner_id'], BX_DATA_INT) : $this->getUserId();
  2281. $aParams['start'] = bx_get('start');
  2282. $aParams['start'] = $aParams['start'] !== false ? bx_process_input($aParams['start'], BX_DATA_INT) : 0;
  2283. $aParams['per_page'] = bx_get('per_page');
  2284. $aParams['per_page'] = $aParams['per_page'] !== false ? bx_process_input($aParams['per_page'], BX_DATA_INT) : $this->_oConfig->getPerPage();
  2285. $aParams['filter'] = bx_get('filter');
  2286. $aParams['filter'] = $aParams['filter'] !== false ? bx_process_input($aParams['filter'], BX_DATA_TEXT) : BX_TIMELINE_FILTER_ALL;
  2287. $aParams['modules'] = bx_get('modules');
  2288. $aParams['modules'] = $aParams['modules'] !== false ? bx_process_input($aParams['modules'], BX_DATA_TEXT) : array();
  2289. $aParams['timeline'] = bx_get('timeline');
  2290. $aParams['timeline'] = $aParams['timeline'] !== false ? bx_process_input($aParams['timeline'], BX_DATA_INT) : 0;
  2291. $aParams['blink'] = bx_get('blink');
  2292. $aParams['blink'] = $aParams['blink'] !== false ? explode(',', bx_process_input($aParams['blink'], BX_DATA_TEXT)) : array();
  2293. $aParams['active'] = 1;
  2294. $aParams['hidden'] = 0;
  2295. if($this->_oConfig->isHot())
  2296. $aParams['hot'] = $this->_oDb->getHot();
  2297. return $aParams;
  2298. }
  2299. protected function _prepareTextForSave($s)
  2300. {
  2301. return bx_process_input($s, BX_DATA_HTML);
  2302. }
  2303. protected function _getFieldValue($sField, $iContentId)
  2304. {
  2305. $CNF = &$this->_oConfig->CNF;
  2306. if(empty($CNF[$sField]))
  2307. return false;
  2308. $aEvent = $this->_oDb->getEvents(array('browse' => 'id', 'value' => $iContentId));
  2309. if(empty($aEvent) || empty($aEvent[$CNF[$sField]]))
  2310. return false;
  2311. return $aEvent[$CNF[$sField]];
  2312. }
  2313. }
  2314. /** @} */