BxTimelineModule.php 103 KB

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