BxTimelineModule.php 82 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119
  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_DEFAULT', BX_BASE_MOD_NTFS_TYPE_OWNER);
  16. define('BX_TIMELINE_VIEW_ITEM', 'item');
  17. define('BX_TIMELINE_VIEW_TIMELINE', 'timeline');
  18. define('BX_TIMELINE_VIEW_OUTLINE', 'outline');
  19. define('BX_TIMELINE_VIEW_SEARCH', 'search');
  20. define('BX_TIMELINE_VIEW_DEFAULT', BX_TIMELINE_VIEW_OUTLINE);
  21. define('BX_TIMELINE_FILTER_ALL', 'all');
  22. define('BX_TIMELINE_FILTER_OWNER', 'owner');
  23. define('BX_TIMELINE_FILTER_OTHER', 'other');
  24. define('BX_TIMELINE_PARSE_TYPE_POST', 'post');
  25. define('BX_TIMELINE_PARSE_TYPE_REPOST', 'repost');
  26. define('BX_TIMELINE_PARSE_TYPE_DEFAULT', BX_TIMELINE_PARSE_TYPE_POST);
  27. define('BX_TIMELINE_MEDIA_PHOTO', 'photo');
  28. define('BX_TIMELINE_MEDIA_VIDEO', 'video');
  29. class BxTimelineModule extends BxBaseModNotificationsModule implements iBxDolContentInfoService
  30. {
  31. protected $_sJsPostObject;
  32. protected $_sJsViewObject;
  33. protected $_aPostElements;
  34. protected $_sJsOutlineObject;
  35. protected $_sDividerTemplate;
  36. protected $_sBalloonTemplate;
  37. protected $_sCmtPostTemplate;
  38. protected $_sCmtViewTemplate;
  39. protected $_sCmtTemplate;
  40. /**
  41. * Constructor
  42. */
  43. function __construct($aModule)
  44. {
  45. parent::__construct($aModule);
  46. }
  47. /**
  48. * ACTION METHODS
  49. */
  50. public function actionPost()
  51. {
  52. $sType = bx_process_input($_POST['type']);
  53. $sMethod = 'getForm' . ucfirst($sType);
  54. if(!method_exists($this, $sMethod)) {
  55. echoJson(array());
  56. return;
  57. }
  58. $this->_iOwnerId = bx_process_input(bx_get('owner_id'), BX_DATA_INT);
  59. $mixedAllowed = $this->isAllowedPost(true);
  60. if($mixedAllowed !== true) {
  61. echoJson(array('message' => strip_tags($mixedAllowed)));
  62. return;
  63. }
  64. $aResult = $this->$sMethod();
  65. echoJson($aResult);
  66. }
  67. function actionPin()
  68. {
  69. $this->_iOwnerId = bx_process_input(bx_get('owner_id'), BX_DATA_INT);
  70. $iId = bx_process_input(bx_get('id'), BX_DATA_INT);
  71. $aEvent = $this->_oDb->getEvents(array('browse' => 'id', 'value' => $iId));
  72. $mixedAllowed = $this->{'isAllowed' . ((int)$aEvent['pinned'] == 0 ? 'Pin' : 'Unpin')}($aEvent, true);
  73. if($mixedAllowed !== true)
  74. return echoJson(array('code' => 1, 'message' => strip_tags($mixedAllowed)));
  75. $aEvent['pinned'] = (int)$aEvent['pinned'] == 0 ? time() : 0;
  76. if(!$this->_oDb->updateEvent(array('pinned' => $aEvent['pinned']), array('id' => $iId)))
  77. return echoJson(array('code' => 2));
  78. echoJson(array(
  79. 'code' => 0,
  80. 'id' => $iId,
  81. 'eval' => $this->_oConfig->getJsObject('view') . '.onPinPost(oData)'
  82. ));
  83. }
  84. function actionDelete()
  85. {
  86. $this->_iOwnerId = bx_process_input(bx_get('owner_id'), BX_DATA_INT);
  87. $aEvent = $this->_oDb->getEvents(array('browse' => 'id', 'value' => bx_process_input(bx_get('id'), BX_DATA_INT)));
  88. $mixedAllowed = $this->isAllowedDelete($aEvent, true);
  89. if($mixedAllowed !== true)
  90. return echoJson(array('code' => 1, 'message' => strip_tags($mixedAllowed)));
  91. if(!$this->deleteEvent($aEvent))
  92. return echoJson(array('code' => 2));
  93. echoJson(array(
  94. 'code' => 0,
  95. 'id' => $aEvent['id'],
  96. 'eval' => $this->_oConfig->getJsObject('view') . '.onDeletePost(oData)'
  97. ));
  98. }
  99. public function actionRepost()
  100. {
  101. $iAuthorId = $this->getUserId();
  102. $iOwnerId = bx_process_input(bx_get('owner_id'), BX_DATA_INT);
  103. $aContent = array(
  104. 'type' => bx_process_input(bx_get('type'), BX_DATA_TEXT),
  105. 'action' => bx_process_input(bx_get('action'), BX_DATA_TEXT),
  106. 'object_id' => bx_process_input(bx_get('object_id'), BX_DATA_INT),
  107. );
  108. $aReposted = $this->_oDb->getReposted($aContent['type'], $aContent['action'], $aContent['object_id']);
  109. if(empty($aReposted) || !is_array($aReposted)) {
  110. echoJson(array('code' => 1, 'message' => _t('_bx_timeline_txt_err_cannot_repost')));
  111. return;
  112. }
  113. $mixedAllowed = $this->isAllowedRepost($aReposted, true);
  114. if($mixedAllowed !== true) {
  115. echoJson(array('code' => 2, 'message' => strip_tags($mixedAllowed)));
  116. return;
  117. }
  118. $bReposted = $this->_oDb->isReposted($aReposted['id'], $iOwnerId, $iAuthorId);
  119. if($bReposted) {
  120. echoJson(array('code' => 3, 'message' => _t('_bx_timeline_txt_err_already_reposted')));
  121. return;
  122. }
  123. $iId = $this->_oDb->insertEvent(array(
  124. 'owner_id' => $iOwnerId,
  125. 'type' => $this->_oConfig->getPrefix('common_post') . 'repost',
  126. 'action' => '',
  127. 'object_id' => $iAuthorId,
  128. 'object_privacy_view' => $this->_oConfig->getPrivacyViewDefault('object'),
  129. 'content' => serialize($aContent),
  130. 'title' => '',
  131. 'description' => ''
  132. ));
  133. if(empty($iId)) {
  134. echoJson(array('code' => 4, 'message' => _t('_bx_timeline_txt_err_cannot_repost')));
  135. return;
  136. }
  137. $this->onRepost($iId, $aReposted);
  138. $aReposted = $this->_oDb->getReposted($aContent['type'], $aContent['action'], $aContent['object_id']);
  139. $sCounter = $this->_oTemplate->getRepostCounter($aReposted);
  140. echoJson(array(
  141. 'code' => 0,
  142. 'message' => _t('_bx_timeline_txt_msg_success_repost'),
  143. 'count' => $aReposted['reposts'],
  144. 'counter' => $sCounter,
  145. 'disabled' => !$bReposted
  146. ));
  147. }
  148. function actionGetPost()
  149. {
  150. $sView = bx_process_input(bx_get('view'));
  151. $this->_iOwnerId = bx_process_input(bx_get('owner_id'), BX_DATA_INT);
  152. $aEvent = $this->_oDb->getEvents(array('browse' => 'id', 'value' => bx_process_input(bx_get('id'), BX_DATA_INT)));
  153. if(empty($aEvent) || !is_array($aEvent))
  154. return echoJson(array());
  155. echoJson(array(
  156. 'id' => $aEvent['id'],
  157. 'view' => $sView,
  158. 'item' => $this->_oTemplate->getPost($aEvent, array(
  159. 'view' => $sView,
  160. 'type' => 'owner',
  161. 'owner_id' => $this->_iOwnerId,
  162. 'dynamic_mode' => true
  163. )),
  164. 'eval' => $this->_oConfig->getJsObject('post') . "._onGetPost(oData)"
  165. ));
  166. }
  167. function actionGetPosts()
  168. {
  169. $aParams = $this->_prepareParamsGet();
  170. list($sItems, $sLoadMore, $sBack, $sEmpty) = $this->_oTemplate->getPosts($aParams);
  171. echoJson(array(
  172. 'view' => $aParams['view'],
  173. 'items' => $sItems,
  174. 'load_more' => $sLoadMore,
  175. 'back' => $sBack,
  176. 'empty' => $sEmpty,
  177. 'eval' => $this->_oConfig->getJsObject('view') . "._onGetPosts(oData)"
  178. ));
  179. }
  180. public function actionGetPostForm($sType)
  181. {
  182. $this->_iOwnerId = bx_process_input(bx_get('owner_id'), BX_DATA_INT);
  183. $sMethod = 'getForm' . ucfirst($sType);
  184. if(!method_exists($this, $sMethod)) {
  185. echoJson(array());
  186. return;
  187. }
  188. $aResult = $this->$sMethod();
  189. echoJson($aResult);
  190. }
  191. public function actionGetComments()
  192. {
  193. $this->_iOwnerId = bx_process_input(bx_get('owner_id'), BX_DATA_INT);
  194. $sSystem = bx_process_input(bx_get('system'), BX_DATA_TEXT);
  195. $iId = bx_process_input(bx_get('id'), BX_DATA_INT);
  196. $sComments = $this->_oTemplate->getComments($sSystem, $iId, true);
  197. echoJson(array('content' => $sComments));
  198. }
  199. public function actionAddAttachLink()
  200. {
  201. $aResult = $this->getFormAttachLink();
  202. echoJson($aResult);
  203. }
  204. public function actionDeleteAttachLink()
  205. {
  206. $iUserId = $this->getUserId();
  207. $iLinkId = bx_process_input(bx_get('id'), BX_DATA_INT);
  208. if(empty($iLinkId)) {
  209. echoJson(array());
  210. return;
  211. }
  212. $aLink = $this->_oDb->getUnusedLinks($iUserId, $iLinkId);
  213. if(empty($aLink) || !is_array($aLink)) {
  214. echoJson(array());
  215. return;
  216. }
  217. if(!empty($aLink['media_id']))
  218. BxDolStorage::getObjectInstance($this->_oConfig->getObject('storage_photos'))->deleteFile($aLink['media_id']);
  219. $aResult = array();
  220. if($this->_oDb->deleteUnusedLinks($iUserId, $iLinkId))
  221. $aResult = array('code' => 0);
  222. else
  223. $aResult = array('code' => 1, 'message' => _t('_bx_timeline_form_post_input_link_err_delete'));
  224. echoJson($aResult);
  225. }
  226. public function actionGetAttachLinkForm()
  227. {
  228. echo $this->_oTemplate->getAttachLinkForm();
  229. }
  230. public function actionGetRepostedBy()
  231. {
  232. $iRepostedId = bx_process_input(bx_get('id'), BX_DATA_INT);
  233. echo $this->_oTemplate->getRepostedBy($iRepostedId);
  234. }
  235. public function actionGetItemBrief()
  236. {
  237. echo BxDolPage::getObjectInstance($this->_oConfig->getObject('page_item_brief'), $this->_oTemplate)->getCode();
  238. }
  239. function actionRss()
  240. {
  241. $aArgs = func_get_args();
  242. $sType = array_shift($aArgs);
  243. $iOwnerId = 0;
  244. switch($sType) {
  245. case BX_BASE_MOD_NTFS_TYPE_OWNER:
  246. $iOwnerId = array_shift($aArgs);
  247. list($sUserName) = $this->getUserInfo($iOwnerId);
  248. $sRssCaption = _t('_bx_timeline_txt_rss_caption', $sUserName);
  249. $sRssLink = $this->_oConfig->getViewUrl($iOwnerId);
  250. break;
  251. case BX_BASE_MOD_NTFS_TYPE_PUBLIC:
  252. $sRssCaption = _t('_bx_timeline_page_title_view_home');
  253. $sRssLink = $this->_oConfig->getHomeViewUrl();
  254. break;
  255. }
  256. $aParams = $this->_prepareParams(BX_TIMELINE_VIEW_DEFAULT, $sType, $iOwnerId, 0, $this->_oConfig->getRssLength(), '', array(), 0);
  257. $aEvents = $this->_oDb->getEvents($aParams);
  258. $aRssData = array();
  259. foreach($aEvents as $aEvent) {
  260. if(empty($aEvent['title'])) continue;
  261. $aRssData[$aEvent['id']] = array(
  262. 'UnitID' => $aEvent['id'],
  263. 'UnitTitle' => $aEvent['title'],
  264. 'UnitLink' => $this->_oConfig->getItemViewUrl($aEvent),
  265. 'UnitDesc' => $aEvent['description'],
  266. 'UnitDateTimeUTS' => $aEvent['date'],
  267. );
  268. }
  269. $oRss = new BxDolRssFactory();
  270. header('Content-Type: application/xml; charset=utf-8');
  271. echo $oRss->GenRssByData($aRssData, $sRssCaption, $sRssLink);
  272. }
  273. /**
  274. * SERVICE METHODS
  275. */
  276. /**
  277. * @page service Service Calls
  278. * @section bx_timeline Timeline
  279. * @subsection bx_timeline-other Other
  280. * @subsubsection bx_timeline-get_author get_author
  281. *
  282. * @code bx_srv('bx_timeline', 'get_author', [...]); @endcode
  283. *
  284. * Get author ID from content info by content ID. Is used in "Content Info Objects" system.
  285. *
  286. * @param $iContentId integer value with content ID.
  287. * @return integer value with author ID.
  288. *
  289. * @see BxTimelineModule::serviceGetAuthor
  290. */
  291. /**
  292. * @ref bx_timeline-get_author "get_author"
  293. */
  294. public function serviceGetAuthor ($iContentId)
  295. {
  296. $aEvent = $this->_oDb->getEvents(array('browse' => 'id', 'value' => $iContentId));
  297. if(empty($aEvent) || !is_array($aEvent))
  298. return 0;
  299. return $this->_oConfig->isSystem($aEvent['type'], $aEvent['action']) ? (int)$aEvent['owner_id'] : (int)$aEvent['object_id'];
  300. }
  301. /**
  302. * @page service Service Calls
  303. * @section bx_timeline Timeline
  304. * @subsection bx_timeline-other Other
  305. * @subsubsection bx_timeline-get_date_changed get_date_changed
  306. *
  307. * @code bx_srv('bx_timeline', 'get_date_changed', [...]); @endcode
  308. *
  309. * Get date when the content was changed last time. Is used in "Content Info Objects" system.
  310. * Note. In case of Timeline event 0 is returned everytime.
  311. *
  312. * @param $iContentId integer value with content ID.
  313. * @return integer value with changing date.
  314. *
  315. * @see BxTimelineModule::serviceGetDateChanged
  316. */
  317. /**
  318. * @ref bx_timeline-get_date_changed "get_date_changed"
  319. */
  320. public function serviceGetDateChanged ($iContentId)
  321. {
  322. return 0;
  323. }
  324. /**
  325. * @page service Service Calls
  326. * @section bx_timeline Timeline
  327. * @subsection bx_timeline-other Other
  328. * @subsubsection bx_timeline-get_link get_link
  329. *
  330. * @code bx_srv('bx_timeline', 'get_link', [...]); @endcode
  331. *
  332. * Get content view page link. Is used in "Content Info Objects" system.
  333. *
  334. * @param $iContentId integer value with content ID.
  335. * @return string value with view page link.
  336. *
  337. * @see BxTimelineModule::serviceGetLink
  338. */
  339. /**
  340. * @ref bx_timeline-get_link "get_link"
  341. */
  342. public function serviceGetLink ($iContentId)
  343. {
  344. $aEvent = $this->_oDb->getEvents(array('browse' => 'id', 'value' => $iContentId));
  345. if(empty($aEvent) || !is_array($aEvent))
  346. return '';
  347. return $this->_oConfig->getItemViewUrl($aEvent);
  348. }
  349. /**
  350. * @page service Service Calls
  351. * @section bx_timeline Timeline
  352. * @subsection bx_timeline-other Other
  353. * @subsubsection bx_timeline-get_thumb get_thumb
  354. *
  355. * @code bx_srv('bx_timeline', 'get_thumb', [...]); @endcode
  356. *
  357. * Get content thumbnail link. Is used in "Content Info Objects" system.
  358. * Note. In case of Timeline event an empty string is returned everytime.
  359. *
  360. * @param $iContentId integer value with content ID.
  361. * @param $sTranscoder (optional) string value with transcoder name which should be applied to thumbnail image.
  362. * @return string value with thumbnail link.
  363. *
  364. * @see BxTimelineModule::serviceGetThumb
  365. */
  366. /**
  367. * @ref bx_timeline-get_thumb "get_thumb"
  368. */
  369. public function serviceGetThumb ($iContentId, $sTranscoder = '')
  370. {
  371. return '';
  372. }
  373. /**
  374. * @page service Service Calls
  375. * @section bx_timeline Timeline
  376. * @subsection bx_timeline-other Other
  377. * @subsubsection bx_timeline-get_info get_info
  378. *
  379. * @code bx_srv('bx_timeline', 'get_info', [...]); @endcode
  380. *
  381. * Get content info by content ID. Is used in "Content Info Objects" system.
  382. *
  383. * @param $iContentId integer value with content ID.
  384. * @param $bSearchableFieldsOnly (optional) boolean value determining all info or "searchable fields" only will be returned.
  385. * @return an array with content info. Empty array is returned if something is wrong.
  386. *
  387. * @see BxTimelineModule::serviceGetInfo
  388. */
  389. /**
  390. * @ref bx_timeline-get_info "get_info"
  391. */
  392. public function serviceGetInfo ($iContentId, $bSearchableFieldsOnly = true)
  393. {
  394. $aContentInfo = $this->_oDb->getEvents(array(
  395. 'browse' => 'id',
  396. 'value' => $iContentId)
  397. );
  398. return BxDolContentInfo::formatFields($aContentInfo);
  399. }
  400. /**
  401. * @page service Service Calls
  402. * @section bx_timeline Timeline
  403. * @subsection bx_timeline-other Other
  404. * @subsubsection bx_timeline-get_search_result_unit get_search_result_unit
  405. *
  406. * @code bx_srv('bx_timeline', 'get_search_result_unit', [...]); @endcode
  407. *
  408. * Get search result unit by content ID. Is used in "Content Info Objects" system.
  409. *
  410. * @param $iContentId integer value with content ID.
  411. * @param $sUnitTemplate (optional) string value with template name.
  412. * @return HTML string with search result unit. Empty string is returned if something is wrong.
  413. *
  414. * @see BxTimelineModule::serviceGetSearchResultUnit
  415. */
  416. /**
  417. * @ref bx_timeline-get_search_result_unit "get_search_result_unit"
  418. */
  419. public function serviceGetSearchResultUnit ($iContentId, $sUnitTemplate = '')
  420. {
  421. $aEvent = $this->_oDb->getEvents(array('browse' => 'id', 'value' => $iContentId));
  422. if(empty($aEvent) || !is_array($aEvent))
  423. return '';
  424. if(empty($sUnitTemplate))
  425. $sUnitTemplate = 'unit.html';
  426. return $this->_oTemplate->unit($aEvent, true, $sUnitTemplate);
  427. }
  428. /**
  429. * @page service Service Calls
  430. * @section bx_timeline Timeline
  431. * @subsection bx_timeline-page_blocks Page Blocks
  432. * @subsubsection bx_timeline-get_block_post get_block_post
  433. *
  434. * @code bx_srv('bx_timeline', 'get_block_post', [...]); @endcode
  435. *
  436. * Get Post block for a separate page.
  437. *
  438. * @param $iProfileId (optional) profile ID. If empty value is provided, an attempt to get it from GET/POST arrays will be performed.
  439. * @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.
  440. *
  441. * @see BxTimelineModule::serviceGetBlockPost
  442. */
  443. /**
  444. * @ref bx_timeline-get_block_post "get_block_post"
  445. */
  446. public function serviceGetBlockPost($iProfileId = 0)
  447. {
  448. if(empty($iProfileId) && bx_get('profile_id') !== false)
  449. $iProfileId = bx_process_input(bx_get('profile_id'), BX_DATA_INT);
  450. if(empty($iProfileId) && isLogged())
  451. $iProfileId = bx_get_logged_profile_id();
  452. if(!$iProfileId)
  453. return array();
  454. return $this->_getBlockPost($iProfileId);
  455. }
  456. /**
  457. * @page service Service Calls
  458. * @section bx_timeline Timeline
  459. * @subsection bx_timeline-page_blocks Page Blocks
  460. * @subsubsection bx_timeline-get_block_post_profile get_block_post_profile
  461. *
  462. * @code bx_srv('bx_timeline', 'get_block_post_profile', [...]); @endcode
  463. *
  464. * Get Post block for the Profile page.
  465. *
  466. * @param $sProfileModule (optional) string value with profile based module name. Persons module is used by default.
  467. * @param $iProfileContentId (optional) profile's content ID. If empty value is provided, an attempt to get it from GET/POST arrays will be performed.
  468. * @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.
  469. *
  470. * @see BxTimelineModule::serviceGetBlockPostProfile
  471. */
  472. /**
  473. * @ref bx_timeline-get_block_post_profile "get_block_post_profile"
  474. */
  475. public function serviceGetBlockPostProfile($sProfileModule = 'bx_persons', $iProfileContentId = 0)
  476. {
  477. if(empty($sProfileModule))
  478. return array();
  479. if(empty($iProfileContentId) && bx_get('id') !== false)
  480. $iProfileContentId = bx_process_input(bx_get('id'), BX_DATA_INT);
  481. $oProfile = BxDolProfile::getInstanceByContentAndType($iProfileContentId, $sProfileModule);
  482. if(empty($oProfile))
  483. return array();
  484. return $this->_getBlockPost($oProfile->id());
  485. }
  486. /**
  487. * @page service Service Calls
  488. * @section bx_timeline Timeline
  489. * @subsection bx_timeline-page_blocks Page Blocks
  490. * @subsubsection bx_timeline-get_block_post_home get_block_post_home
  491. *
  492. * @code bx_srv('bx_timeline', 'get_block_post_home', [...]); @endcode
  493. *
  494. * Get Post block for site's Home page.
  495. *
  496. * @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.
  497. *
  498. * @see BxTimelineModule::serviceGetBlockPostHome
  499. */
  500. /**
  501. * @ref bx_timeline-get_block_post_home "get_block_post_home"
  502. */
  503. public function serviceGetBlockPostHome()
  504. {
  505. $iProfileId = 0;
  506. return $this->_getBlockPost($iProfileId, array(
  507. 'form_display' => 'form_display_post_add_public'
  508. ));
  509. }
  510. /**
  511. * @page service Service Calls
  512. * @section bx_timeline Timeline
  513. * @subsection bx_timeline-page_blocks Page Blocks
  514. * @subsubsection bx_timeline-get_block_post_account get_block_post_account
  515. *
  516. * @code bx_srv('bx_timeline', 'get_block_post_account', [...]); @endcode
  517. *
  518. * Get Post block for the Dashboard page.
  519. *
  520. * @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.
  521. *
  522. * @see BxTimelineModule::serviceGetBlockPostAccount
  523. */
  524. /**
  525. * @ref bx_timeline-get_block_post_account "get_block_post_account"
  526. */
  527. public function serviceGetBlockPostAccount()
  528. {
  529. if(!isLogged())
  530. return '';
  531. $iProfileId = $this->getProfileId();
  532. return $this->_getBlockPost($iProfileId);
  533. }
  534. /**
  535. * @page service Service Calls
  536. * @section bx_timeline Timeline
  537. * @subsection bx_timeline-page_blocks Page Blocks
  538. * @subsubsection bx_timeline-get_block_view get_block_view
  539. *
  540. * @code bx_srv('bx_timeline', 'get_block_view', [...]); @endcode
  541. *
  542. * Get Timeline View block for a separate page.
  543. *
  544. * @param $iProfileId (optional) profile ID. If empty value is provided, an attempt to get it from GET/POST arrays will be performed.
  545. * @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.
  546. *
  547. * @see BxTimelineModule::serviceGetBlockView
  548. */
  549. /**
  550. * @ref bx_timeline-get_block_view "get_block_view"
  551. */
  552. public function serviceGetBlockView($iProfileId = 0)
  553. {
  554. return $this->_serviceGetBlockView($iProfileId, BX_TIMELINE_VIEW_TIMELINE);
  555. }
  556. /**
  557. * @page service Service Calls
  558. * @section bx_timeline Timeline
  559. * @subsection bx_timeline-page_blocks Page Blocks
  560. * @subsubsection bx_timeline-get_block_view_outline get_block_view_outline
  561. *
  562. * @code bx_srv('bx_timeline', 'get_block_view_outline', [...]); @endcode
  563. *
  564. * Get Outline View block for a separate page.
  565. *
  566. * @param $iProfileId (optional) profile ID. If empty value is provided, an attempt to get it from GET/POST arrays will be performed.
  567. * @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.
  568. *
  569. * @see BxTimelineModule::serviceGetBlockViewOutline
  570. */
  571. /**
  572. * @ref bx_timeline-get_block_view_outline "get_block_view_outline"
  573. */
  574. public function serviceGetBlockViewOutline($iProfileId = 0)
  575. {
  576. return $this->_serviceGetBlockView($iProfileId, BX_TIMELINE_VIEW_OUTLINE);
  577. }
  578. /**
  579. * @page service Service Calls
  580. * @section bx_timeline Timeline
  581. * @subsection bx_timeline-page_blocks Page Blocks
  582. * @subsubsection bx_timeline-get_block_view_profile get_block_view_profile
  583. *
  584. * @code bx_srv('bx_timeline', 'get_block_view_profile', [...]); @endcode
  585. *
  586. * Get Timeline View block for the Profile page.
  587. *
  588. * @param $sProfileModule (optional) string value with profile based module name. Persons module is used by default.
  589. * @param $iProfileContentId (optional) profile's content ID. If empty value is provided, an attempt to get it from GET/POST arrays will be performed.
  590. * @param $iStart (optional) integer value with a page number. Is used in pagination.
  591. * @param $iPerPage (optional) integer value with a number of items per page. Is used in pagination.
  592. * @param $sFilter (optional) string value with filter name.
  593. * @param $aModules (optional) an array of modules from which the events should be displayed. All available modules are used by default.
  594. * @param $iTimeline (optional) integer value determining whether the timeline should be displayed or not.
  595. * @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.
  596. *
  597. * @see BxTimelineModule::serviceGetBlockViewProfile
  598. */
  599. /**
  600. * @ref bx_timeline-get_block_view_profile "get_block_view_profile"
  601. */
  602. public function serviceGetBlockViewProfile($sProfileModule = 'bx_persons', $iProfileContentId = 0, $iStart = -1, $iPerPage = -1, $sFilter = '', $aModules = array(), $iTimeline = -1)
  603. {
  604. $sView = BX_TIMELINE_VIEW_TIMELINE;
  605. return $this->_serviceGetBlockViewProfile($sProfileModule, $iProfileContentId, $sView, $iStart, $iPerPage, $sFilter, $aModules, $iTimeline);
  606. }
  607. /**
  608. * @page service Service Calls
  609. * @section bx_timeline Timeline
  610. * @subsection bx_timeline-page_blocks Page Blocks
  611. * @subsubsection bx_timeline-get_block_view_profile_outline get_block_view_profile_outline
  612. *
  613. * @code bx_srv('bx_timeline', 'get_block_view_profile_outline', [...]); @endcode
  614. *
  615. * Get Outline View block for the Profile page.
  616. *
  617. * @param $sProfileModule (optional) string value with profile based module name. Persons module is used by default.
  618. * @param $iProfileContentId (optional) profile's content ID. If empty value is provided, an attempt to get it from GET/POST arrays will be performed.
  619. * @param $iStart (optional) integer value with a page number. Is used in pagination.
  620. * @param $iPerPage (optional) integer value with a number of items per page. Is used in pagination.
  621. * @param $sFilter (optional) string value with filter name.
  622. * @param $aModules (optional) an array of modules from which the events should be displayed. All available modules are used by default.
  623. * @param $iTimeline (optional) integer value determining whether the timeline should be displayed or not.
  624. * @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.
  625. *
  626. * @see BxTimelineModule::serviceGetBlockViewProfileOutline
  627. */
  628. /**
  629. * @ref bx_timeline-get_block_view_profile_outline "get_block_view_profile_outline"
  630. */
  631. public function serviceGetBlockViewProfileOutline($sProfileModule = 'bx_persons', $iProfileContentId = 0, $iStart = -1, $iPerPage = -1, $sFilter = '', $aModules = array(), $iTimeline = -1)
  632. {
  633. $sView = BX_TIMELINE_VIEW_OUTLINE;
  634. return $this->_serviceGetBlockViewProfile($sProfileModule, $iProfileContentId, $sView, $iStart, $iPerPage, $sFilter, $aModules, $iTimeline);
  635. }
  636. /**
  637. * @page service Service Calls
  638. * @section bx_timeline Timeline
  639. * @subsection bx_timeline-page_blocks Page Blocks
  640. * @subsubsection bx_timeline-get_block_view_home get_block_view_home
  641. *
  642. * @code bx_srv('bx_timeline', 'get_block_view_home', [...]); @endcode
  643. *
  644. * Get Timeline View block for site's Home page.
  645. *
  646. * @param $iProfileId (optional) profile ID. 0 should be used here.
  647. * @param $iStart (optional) integer value with a page number. Is used in pagination.
  648. * @param $iPerPage (optional) integer value with a number of items per page. Is used in pagination.
  649. * @param $iTimeline (optional) integer value determining whether the timeline should be displayed or not.
  650. * @param $sFilter (optional) string value with filter name.
  651. * @param $aModules (optional) an array of modules from which the events should be displayed. All available modules are used by default.
  652. * @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.
  653. *
  654. * @see BxTimelineModule::serviceGetBlockViewHome
  655. */
  656. /**
  657. * @ref bx_timeline-get_block_view_home "get_block_view_home"
  658. */
  659. public function serviceGetBlockViewHome($iProfileId = 0, $iStart = -1, $iPerPage = -1, $iTimeline = -1, $sFilter = '', $aModules = array())
  660. {
  661. return $this->_serviceGetBlockViewHome($iProfileId, BX_TIMELINE_VIEW_TIMELINE, $iStart, $iPerPage, $this->_oConfig->getPerPage('home'), $iTimeline, $sFilter, $aModules);
  662. }
  663. /**
  664. * @page service Service Calls
  665. * @section bx_timeline Timeline
  666. * @subsection bx_timeline-page_blocks Page Blocks
  667. * @subsubsection bx_timeline-get_block_view_home_outline get_block_view_home_outline
  668. *
  669. * @code bx_srv('bx_timeline', 'get_block_view_home_outline', [...]); @endcode
  670. *
  671. * Get Outline View block for site's Home page.
  672. *
  673. * @param $iProfileId (optional) profile ID. 0 should be used here.
  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 $iTimeline (optional) integer value determining whether the timeline should be displayed or not.
  677. * @param $sFilter (optional) string value with filter name.
  678. * @param $aModules (optional) an array of modules from which the events should be displayed. All available modules are used by default.
  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::serviceGetBlockViewHomeOutline
  682. */
  683. /**
  684. * @ref bx_timeline-get_block_view_home_outline "get_block_view_home_outline"
  685. */
  686. public function serviceGetBlockViewHomeOutline($iProfileId = 0, $iStart = -1, $iPerPage = -1, $iTimeline = -1, $sFilter = '', $aModules = array())
  687. {
  688. return $this->_serviceGetBlockViewHome($iProfileId, BX_TIMELINE_VIEW_OUTLINE, $iStart, $iPerPage, $this->_oConfig->getPerPage('home'), $iTimeline, $sFilter, $aModules);
  689. }
  690. /**
  691. * @page service Service Calls
  692. * @section bx_timeline Timeline
  693. * @subsection bx_timeline-page_blocks Page Blocks
  694. * @subsubsection bx_timeline-get_block_view_account get_block_view_account
  695. *
  696. * @code bx_srv('bx_timeline', 'get_block_view_account', [...]); @endcode
  697. *
  698. * Get Timeline View block for the Dashboard page.
  699. *
  700. * @param $iProfileId (optional) profile ID. 0 should be used here.
  701. * @param $iStart (optional) integer value with a page number. Is used in pagination.
  702. * @param $iPerPage (optional) integer value with a number of items per page. Is used in pagination.
  703. * @param $iTimeline (optional) integer value determining whether the timeline should be displayed or not.
  704. * @param $sFilter (optional) string value with filter name.
  705. * @param $aModules (optional) an array of modules from which the events should be displayed. All available modules are used by default.
  706. * @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.
  707. *
  708. * @see BxTimelineModule::serviceGetBlockViewAccount
  709. */
  710. /**
  711. * @ref bx_timeline-get_block_view_account "get_block_view_account"
  712. */
  713. public function serviceGetBlockViewAccount($iProfileId = 0, $iStart = -1, $iPerPage = -1, $iTimeline = -1, $sFilter = '', $aModules = array())
  714. {
  715. if(!isLogged())
  716. return '';
  717. return $this->_serviceGetBlockViewByType($iProfileId, BX_TIMELINE_VIEW_TIMELINE, BX_TIMELINE_TYPE_OWNER_AND_CONNECTIONS, $iStart, $iPerPage, $this->_oConfig->getPerPage('account'), $iTimeline, $sFilter, $aModules);
  718. }
  719. /**
  720. * @page service Service Calls
  721. * @section bx_timeline Timeline
  722. * @subsection bx_timeline-page_blocks Page Blocks
  723. * @subsubsection bx_timeline-get_block_view_account_outline get_block_view_account_outline
  724. *
  725. * @code bx_srv('bx_timeline', 'get_block_view_account_outline', [...]); @endcode
  726. *
  727. * Get Outline View block for the Dashboard page.
  728. *
  729. * @param $iProfileId (optional) profile ID. 0 should be used here.
  730. * @param $iStart (optional) integer value with a page number. Is used in pagination.
  731. * @param $iPerPage (optional) integer value with a number of items per page. Is used in pagination.
  732. * @param $iTimeline (optional) integer value determining whether the timeline should be displayed or not.
  733. * @param $sFilter (optional) string value with filter name.
  734. * @param $aModules (optional) an array of modules from which the events should be displayed. All available modules are used by default.
  735. * @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.
  736. *
  737. * @see BxTimelineModule::serviceGetBlockViewAccountOutline
  738. */
  739. /**
  740. * @ref bx_timeline-get_block_view_account_outline "get_block_view_account_outline"
  741. */
  742. public function serviceGetBlockViewAccountOutline($iProfileId = 0, $iStart = -1, $iPerPage = -1, $iTimeline = -1, $sFilter = '', $aModules = array())
  743. {
  744. if(!isLogged())
  745. return '';
  746. return $this->_serviceGetBlockViewByType($iProfileId, BX_TIMELINE_VIEW_OUTLINE, BX_TIMELINE_TYPE_OWNER_AND_CONNECTIONS, $iStart, $iPerPage, $this->_oConfig->getPerPage('account'), $iTimeline, $sFilter, $aModules);
  747. }
  748. /**
  749. * @page service Service Calls
  750. * @section bx_timeline Timeline
  751. * @subsection bx_timeline-page_blocks Page Blocks
  752. * @subsubsection bx_timeline-get_block_item get_block_item
  753. *
  754. * @code bx_srv('bx_timeline', 'get_block_item', [...]); @endcode
  755. *
  756. * Get View Item block.
  757. *
  758. * @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.
  759. *
  760. * @see BxTimelineModule::serviceGetBlockItem
  761. */
  762. /**
  763. * @ref bx_timeline-get_block_item "get_block_item"
  764. */
  765. public function serviceGetBlockItem()
  766. {
  767. $iItemId = bx_process_input(bx_get('id'), BX_DATA_INT);
  768. if(!$iItemId)
  769. return array();
  770. return $this->_oTemplate->getItemBlock($iItemId);
  771. }
  772. public function serviceGetBlockItemContent()
  773. {
  774. $iItemId = bx_process_input(bx_get('id'), BX_DATA_INT);
  775. $sMode = bx_process_input(bx_get('mode'));
  776. if(!$iItemId || !$sMode)
  777. return '';
  778. return $this->_oTemplate->getItemBlockContent($iItemId, $sMode);
  779. }
  780. public function serviceGetBlockItemInfo()
  781. {
  782. $iItemId = bx_process_input(bx_get('id'), BX_DATA_INT);
  783. if(!$iItemId)
  784. return '';
  785. return $this->_oTemplate->getItemBlockInfo($iItemId);
  786. }
  787. public function serviceGetBlockItemComments()
  788. {
  789. $iItemId = bx_process_input(bx_get('id'), BX_DATA_INT);
  790. if(!$iItemId)
  791. return '';
  792. return $this->_oTemplate->getItemBlockComments($iItemId);
  793. }
  794. /**
  795. * @page service Service Calls
  796. * @section bx_timeline Timeline
  797. * @subsection bx_timeline-integration_notifications Integration with Notifications
  798. * @subsubsection bx_timeline-get_notifications_data get_notifications_data
  799. *
  800. * @code bx_srv('bx_timeline', 'get_notifications_data', [...]); @endcode
  801. *
  802. * Data for Notifications module.
  803. *
  804. * @return an array with special format.
  805. *
  806. * @see BxTimelineModule::serviceGetNotificationsData
  807. */
  808. /**
  809. * @ref bx_timeline-get_notifications_data "get_notifications_data"
  810. */
  811. public function serviceGetNotificationsData()
  812. {
  813. $sModule = $this->_aModule['name'];
  814. return array(
  815. 'handlers' => array(
  816. array('group' => $sModule . '_object', 'type' => 'insert', 'alert_unit' => $sModule, 'alert_action' => 'post_common', 'module_name' => $sModule, 'module_method' => 'get_notifications_post', 'module_class' => 'Module'),
  817. array('group' => $sModule . '_object', 'type' => 'delete', 'alert_unit' => $sModule, 'alert_action' => 'delete'),
  818. array('group' => $sModule . '_repost', 'type' => 'insert', 'alert_unit' => $sModule, 'alert_action' => 'repost', 'module_name' => $sModule, 'module_method' => 'get_notifications_repost', 'module_class' => 'Module'),
  819. array('group' => $sModule . '_repost', 'type' => 'delete', 'alert_unit' => $sModule, 'alert_action' => 'delete_repost'),
  820. array('group' => $sModule . '_comment', 'type' => 'insert', 'alert_unit' => $sModule, 'alert_action' => 'commentPost', 'module_name' => $sModule, 'module_method' => 'get_notifications_comment', 'module_class' => 'Module'),
  821. array('group' => $sModule . '_comment', 'type' => 'delete', 'alert_unit' => $sModule, 'alert_action' => 'commentRemoved'),
  822. array('group' => $sModule . '_vote', 'type' => 'insert', 'alert_unit' => $sModule, 'alert_action' => 'doVote', 'module_name' => $sModule, 'module_method' => 'get_notifications_vote', 'module_class' => 'Module'),
  823. array('group' => $sModule . '_vote', 'type' => 'delete', 'alert_unit' => $sModule, 'alert_action' => 'undoVote'),
  824. ),
  825. 'alerts' => array(
  826. array('unit' => $sModule, 'action' => 'post_common'),
  827. array('unit' => $sModule, 'action' => 'delete'),
  828. array('unit' => $sModule, 'action' => 'repost'),
  829. array('unit' => $sModule, 'action' => 'delete_repost'),
  830. array('unit' => $sModule, 'action' => 'commentPost'),
  831. array('unit' => $sModule, 'action' => 'commentRemoved'),
  832. array('unit' => $sModule, 'action' => 'doVote'),
  833. array('unit' => $sModule, 'action' => 'undoVote'),
  834. )
  835. );
  836. }
  837. /**
  838. * @page service Service Calls
  839. * @section bx_timeline Timeline
  840. * @subsection bx_timeline-integration_notifications Integration with Notifications
  841. * @subsubsection bx_timeline-get_notifications_repost get_notifications_repost
  842. *
  843. * @code bx_srv('bx_timeline', 'get_notifications_repost', [...]); @endcode
  844. *
  845. * Get data for Repost event to display in Notifications module.
  846. *
  847. * @param $aEvent an array with event description.
  848. * @return an array with special format.
  849. *
  850. * @see BxTimelineModule::serviceGetNotificationsRepost
  851. */
  852. /**
  853. * @ref bx_timeline-get_notifications_repost "get_notifications_repost"
  854. */
  855. public function serviceGetNotificationsRepost($aEvent)
  856. {
  857. $aResult = $this->serviceGetNotificationsPost($aEvent);
  858. $aResult['lang_key'] = '_bx_timeline_txt_object_reposted';
  859. return $aResult;
  860. }
  861. /**
  862. * @page service Service Calls
  863. * @section bx_timeline Timeline
  864. * @subsection bx_timeline-integration_notifications Integration with Notifications
  865. * @subsubsection bx_timeline-get_notifications_post get_notifications_post
  866. *
  867. * @code bx_srv('bx_timeline', 'get_notifications_post', [...]); @endcode
  868. *
  869. * Get data for Post event to display in Notifications module.
  870. *
  871. * @param $aEvent an array with event description.
  872. * @return an array with special format.
  873. *
  874. * @see BxTimelineModule::serviceGetNotificationsPost
  875. */
  876. /**
  877. * @ref bx_timeline-get_notifications_post "get_notifications_post"
  878. */
  879. public function serviceGetNotificationsPost($aEvent)
  880. {
  881. $CNF = &$this->_oConfig->CNF;
  882. $iContent = (int)$aEvent['object_id'];
  883. $aContent = $this->_oDb->getEvents(array('browse' => 'id', 'value' => $iContent));
  884. if(empty($aContent) || !is_array($aContent))
  885. return array();
  886. $sEntryCaption = !empty($aContent['title']) ? $aContent['title'] : $this->_oConfig->getTitle($aContent['description']);
  887. return array(
  888. 'entry_sample' => $CNF['T']['txt_sample_single_ext'],
  889. 'entry_url' => $this->_oConfig->getItemViewUrl($aContent),
  890. 'entry_caption' => $sEntryCaption,
  891. 'entry_author' => $aContent['owner_id'],
  892. '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.
  893. );
  894. }
  895. /**
  896. * @page service Service Calls
  897. * @section bx_timeline Timeline
  898. * @subsection bx_timeline-integration_notifications Integration with Notifications
  899. * @subsubsection bx_timeline-get_notifications_comment get_notifications_comment
  900. *
  901. * @code bx_srv('bx_timeline', 'get_notifications_comment', [...]); @endcode
  902. *
  903. * Get data for Post Comment event to display in Notifications module.
  904. *
  905. * @param $aEvent an array with event description.
  906. * @return an array with special format.
  907. *
  908. * @see BxTimelineModule::serviceGetNotificationsComment
  909. */
  910. /**
  911. * @ref bx_timeline-get_notifications_comment "get_notifications_comment"
  912. */
  913. public function serviceGetNotificationsComment($aEvent)
  914. {
  915. $CNF = &$this->_oConfig->CNF;
  916. $iContent = (int)$aEvent['object_id'];
  917. $aContent = $this->_oDb->getEvents(array('browse' => 'id', 'value' => $iContent));
  918. if(empty($aContent) || !is_array($aContent))
  919. return array();
  920. $oComment = BxDolCmts::getObjectInstance($CNF['OBJECT_COMMENTS'], $iContent);
  921. if(!$oComment || !$oComment->isEnabled())
  922. return array();
  923. $sEntryCaption = !empty($aContent['title']) ? $aContent['title'] : $this->_oConfig->getTitle($aContent['description']);
  924. return array(
  925. 'entry_sample' => $CNF['T']['txt_sample_single'],
  926. 'entry_url' => $this->_oConfig->getItemViewUrl($aContent),
  927. 'entry_caption' => $sEntryCaption,
  928. 'entry_author' => $aContent['owner_id'],
  929. 'subentry_sample' => $CNF['T']['txt_sample_comment_single'],
  930. 'subentry_url' => $oComment->getViewUrl((int)$aEvent['subobject_id']),
  931. 'lang_key' => '', //may be empty or not specified. In this case the default one from Notification module will be used.
  932. );
  933. }
  934. /**
  935. * @page service Service Calls
  936. * @section bx_timeline Timeline
  937. * @subsection bx_timeline-integration_notifications Integration with Notifications
  938. * @subsubsection bx_timeline-get_notifications_vote get_notifications_vote
  939. *
  940. * @code bx_srv('bx_timeline', 'get_notifications_vote', [...]); @endcode
  941. *
  942. * Get data for Vote event to display in Notifications module.
  943. *
  944. * @param $aEvent an array with event description.
  945. * @return an array with special format.
  946. *
  947. * @see BxTimelineModule::serviceGetNotificationsVote
  948. */
  949. /**
  950. * @ref bx_timeline-get_notifications_vote "get_notifications_vote"
  951. */
  952. public function serviceGetNotificationsVote($aEvent)
  953. {
  954. $CNF = &$this->_oConfig->CNF;
  955. $iContent = (int)$aEvent['object_id'];
  956. $aContent = $this->_oDb->getEvents(array('browse' => 'id', 'value' => $iContent));
  957. if(empty($aContent) || !is_array($aContent))
  958. return array();
  959. $oVote = BxDolVote::getObjectInstance($CNF['OBJECT_VOTES'], $iContent);
  960. if(!$oVote || !$oVote->isEnabled())
  961. return array();
  962. $sEntryCaption = !empty($aContent['title']) ? $aContent['title'] : $this->_oConfig->getTitle($aContent['description']);
  963. return array(
  964. 'entry_sample' => $CNF['T']['txt_sample_single'],
  965. 'entry_url' => $this->_oConfig->getItemViewUrl($aContent),
  966. 'entry_caption' => $sEntryCaption,
  967. 'entry_author' => $aContent['owner_id'],
  968. 'subentry_sample' => $CNF['T']['txt_sample_vote_single'],
  969. 'lang_key' => '', //may be empty or not specified. In this case the default one from Notification module will be used.
  970. );
  971. }
  972. /**
  973. * @page service Service Calls
  974. * @section bx_timeline Timeline
  975. * @subsection bx_timeline-repost Repost
  976. * @subsubsection bx_timeline-get_repost_element_block get_repost_element_block
  977. *
  978. * @code bx_srv('bx_timeline', 'get_repost_element_block', [...]); @endcode
  979. *
  980. * Get repost element for content based modules.
  981. *
  982. * @param $iOwnerId integer value with owner profile ID.
  983. * @param $sType string value with type (module name).
  984. * @param $sAction string value with action (module action).
  985. * @param $iObjectId integer value with object ID to be reposted.
  986. * @param $aParams (optional) an array with additional params.
  987. * @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.
  988. *
  989. * @see BxTimelineModule::serviceGetRepostElementBlock
  990. */
  991. /**
  992. * @ref bx_timeline-get_repost_element_block "get_repost_element_block"
  993. */
  994. public function serviceGetRepostElementBlock($iOwnerId, $sType, $sAction, $iObjectId, $aParams = array())
  995. {
  996. if(!$this->isEnabled())
  997. return '';
  998. $aParams = array_merge($this->_oConfig->getRepostDefaults(), $aParams);
  999. return $this->_oTemplate->getRepostElement($iOwnerId, $sType, $sAction, $iObjectId, $aParams);
  1000. }
  1001. /**
  1002. * @page service Service Calls
  1003. * @section bx_timeline Timeline
  1004. * @subsection bx_timeline-repost Repost
  1005. * @subsubsection bx_timeline-get_repost_counter get_repost_counter
  1006. *
  1007. * @code bx_srv('bx_timeline', 'get_repost_counter', [...]); @endcode
  1008. *
  1009. * Get repost counter.
  1010. *
  1011. * @param $sType string value with type (module name).
  1012. * @param $sAction string value with action (module action).
  1013. * @param $iObjectId integer value with object ID to be reposted.
  1014. * @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.
  1015. *
  1016. * @see BxTimelineModule::serviceGetRepostCounter
  1017. */
  1018. /**
  1019. * @ref bx_timeline-get_repost_counter "get_repost_counter"
  1020. */
  1021. public function serviceGetRepostCounter($sType, $sAction, $iObjectId)
  1022. {
  1023. if(!$this->isEnabled())
  1024. return '';
  1025. $aReposted = $this->_oDb->getReposted($sType, $sAction, $iObjectId);
  1026. return $this->_oTemplate->getRepostCounter($aReposted);
  1027. }
  1028. /**
  1029. * @page service Service Calls
  1030. * @section bx_timeline Timeline
  1031. * @subsection bx_timeline-repost Repost
  1032. * @subsubsection bx_timeline-get_repost_js_script get_repost_js_script
  1033. *
  1034. * @code bx_srv('bx_timeline', 'get_repost_js_script', [...]); @endcode
  1035. *
  1036. * Get repost JavaScript code.
  1037. *
  1038. * @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.
  1039. *
  1040. * @see BxTimelineModule::serviceGetRepostJsScript
  1041. */
  1042. /**
  1043. * @ref bx_timeline-get_repost_js_script "get_repost_js_script"
  1044. */
  1045. public function serviceGetRepostJsScript()
  1046. {
  1047. if(!$this->isEnabled())
  1048. return '';
  1049. return $this->_oTemplate->getRepostJsScript();
  1050. }
  1051. /**
  1052. * @page service Service Calls
  1053. * @section bx_timeline Timeline
  1054. * @subsection bx_timeline-repost Repost
  1055. * @subsubsection bx_timeline-get_repost_js_click get_repost_js_click
  1056. *
  1057. * @code bx_srv('bx_timeline', 'get_repost_js_click', [...]); @endcode
  1058. *
  1059. * Get repost JavaScript code for OnClick event.
  1060. *
  1061. * @param $iOwnerId integer value with owner profile ID.
  1062. * @param $sType string value with type (module name).
  1063. * @param $sAction string value with action (module action).
  1064. * @param $iObjectId integer value with object ID to be reposted.
  1065. * @return HTML string with JavaScript code to display in OnClick events of HTML elements.
  1066. *
  1067. * @see BxTimelineModule::serviceGetRepostJsClick
  1068. */
  1069. /**
  1070. * @ref bx_timeline-get_repost_js_click "get_repost_js_click"
  1071. */
  1072. public function serviceGetRepostJsClick($iOwnerId, $sType, $sAction, $iObjectId)
  1073. {
  1074. if(!$this->isEnabled())
  1075. return '';
  1076. return $this->_oTemplate->getRepostJsClick($iOwnerId, $sType, $sAction, $iObjectId);
  1077. }
  1078. /**
  1079. * @page service Service Calls
  1080. * @section bx_timeline Timeline
  1081. * @subsection bx_timeline-other Other
  1082. * @subsubsection bx_timeline-get_menu_item_addon_comment get_menu_item_addon_comment
  1083. *
  1084. * @code bx_srv('bx_timeline', 'get_menu_item_addon_comment', [...]); @endcode
  1085. *
  1086. * Get addon for Comment menu item.
  1087. *
  1088. * @param $sSystem string value with comments engine system.
  1089. * @param $iObjectId integer value with object ID.
  1090. * @return HTML string to display in menu item.
  1091. *
  1092. * @see BxTimelineModule::serviceGetMenuItemAddonComment
  1093. */
  1094. /**
  1095. * @ref bx_timeline-get_menu_item_addon_comment "get_menu_item_addon_comment"
  1096. */
  1097. public function serviceGetMenuItemAddonComment($sSystem, $iObjectId)
  1098. {
  1099. if(empty($sSystem) || empty($iObjectId))
  1100. return '';
  1101. $oCmts = $this->getCmtsObject($sSystem, $iObjectId);
  1102. if($oCmts === false)
  1103. return '';
  1104. $iCounter = (int)$oCmts->getCommentsCount();
  1105. return $this->_oTemplate->parseLink('javascript:void(0)', $iCounter > 0 ? $iCounter : '', array(
  1106. 'title' => _t('_bx_timeline_menu_item_title_item_comment'),
  1107. 'onclick' => "javascript:" . $this->_oConfig->getJsObject('view') . ".commentItem(this, '" . $sSystem . "', " . $iObjectId . ")"
  1108. ));
  1109. }
  1110. /**
  1111. * @page service Service Calls
  1112. * @section bx_timeline Timeline
  1113. * @subsection bx_timeline-other Other
  1114. * @subsubsection bx_timeline-get_settings_checker_helper get_settings_checker_helper
  1115. *
  1116. * @code bx_srv('bx_timeline', 'get_settings_checker_helper', [...]); @endcode
  1117. *
  1118. * Get Checker Helper class name for Forms engine.
  1119. *
  1120. * @return string with Checker Helper class name.
  1121. *
  1122. * @see BxTimelineModule::serviceGetSettingsCheckerHelper
  1123. */
  1124. /**
  1125. * @ref bx_timeline-get_settings_checker_helper "get_settings_checker_helper"
  1126. */
  1127. public function serviceGetSettingsCheckerHelper()
  1128. {
  1129. bx_import('FormCheckerHelper', $this->_aModule);
  1130. return 'BxTimelineFormCheckerHelper';
  1131. }
  1132. /*
  1133. * COMMON METHODS
  1134. */
  1135. public function deleteEvent($aEvent)
  1136. {
  1137. if(empty($aEvent) || !is_array($aEvent) || !$this->_oDb->deleteEvent(array('id' => (int)$aEvent['id'])))
  1138. return false;
  1139. $this->onDelete($aEvent);
  1140. return true;
  1141. }
  1142. public function getFormAttachLink()
  1143. {
  1144. $iUserId = $this->getUserId();
  1145. $oForm = BxDolForm::getObjectInstance($this->_oConfig->getObject('form_attach_link'), $this->_oConfig->getObject('form_display_attach_link_add'), $this->_oTemplate);
  1146. $oForm->aFormAttrs['action'] = BX_DOL_URL_ROOT . $this->_oConfig->getBaseUri() . 'add_attach_link/';
  1147. $oForm->aInputs['url']['checker']['params']['preg'] = $this->_oConfig->getPregPattern('url');
  1148. $oForm->initChecker();
  1149. if($oForm->isSubmittedAndValid()) {
  1150. $sLink = $oForm->getCleanValue('url');
  1151. $aMatches = array();
  1152. preg_match($this->_oConfig->getPregPattern('url'), $sLink, $aMatches);
  1153. $sLink = (empty($aMatches[2]) ? 'http://' : '') . $aMatches[0];
  1154. $aSiteInfo = bx_get_site_info($sLink, array(
  1155. 'thumbnailUrl' => array('tag' => 'link', 'content_attr' => 'href'),
  1156. 'OGImage' => array('name_attr' => 'property', 'name' => 'og:image'),
  1157. ));
  1158. $sTitle = !empty($aSiteInfo['title']) ? $aSiteInfo['title'] : _t('_Empty');
  1159. $sDescription = !empty($aSiteInfo['description']) ? $aSiteInfo['description'] : _t('_Empty');
  1160. $sMediaUrl = '';
  1161. if(!empty($aSiteInfo['thumbnailUrl']))
  1162. $sMediaUrl = $aSiteInfo['thumbnailUrl'];
  1163. else if(!empty($aSiteInfo['OGImage']))
  1164. $sMediaUrl = $aSiteInfo['OGImage'];
  1165. $iMediaId = 0;
  1166. $oStorage = null;
  1167. if(!empty($sMediaUrl)) {
  1168. $oStorage = BxDolStorage::getObjectInstance($this->_oConfig->getObject('storage_' . BX_TIMELINE_MEDIA_PHOTO . 's'));
  1169. $iMediaId = $oStorage->storeFileFromUrl($sMediaUrl, true, $iUserId);
  1170. }
  1171. $iId = (int)$oForm->insert(array('profile_id' => $iUserId, 'media_id' => $iMediaId, 'url' => $sLink, 'title' => $sTitle, 'text' => $sDescription, 'added' => time()));
  1172. if(!empty($iId)) {
  1173. if(!empty($oStorage) && !empty($iMediaId))
  1174. $oStorage->afterUploadCleanup($iMediaId, $iUserId);
  1175. return array('item' => $this->_oTemplate->getAttachLinkItem($iUserId, $iId));
  1176. }
  1177. return array('message' => _t('_bx_timeline_txt_err_cannot_perform_action'));
  1178. }
  1179. return array('form' => $oForm->getCode(), 'form_id' => $oForm->id);
  1180. }
  1181. public function getFormPost($aParams = array())
  1182. {
  1183. $iUserId = $this->getUserId();
  1184. $sFormObject = !empty($aParams['form_object']) ? $aParams['form_object'] : 'form_post';
  1185. $sFormDisplay = !empty($aParams['form_display']) ? $aParams['form_display'] : 'form_display_post_add';
  1186. $oForm = BxDolForm::getObjectInstance($this->_oConfig->getObject($sFormObject), $this->_oConfig->getObject($sFormDisplay), $this->_oTemplate);
  1187. $oForm->initChecker();
  1188. if($oForm->isSubmittedAndValid()) {
  1189. list($sUserName) = $this->getUserInfo($iUserId);
  1190. $sType = $oForm->getCleanValue('type');
  1191. $sType = $this->_oConfig->getPrefix('common_post') . $sType;
  1192. BxDolForm::setSubmittedValue('type', $sType, $oForm->aFormAttrs['method']);
  1193. $aContent = array();
  1194. //--- Process Text ---//
  1195. $sText = $oForm->getCleanValue('text');
  1196. $sText = $this->_prepareTextForSave($sText);
  1197. $bText = !empty($sText);
  1198. unset($oForm->aInputs['text']);
  1199. if($bText)
  1200. $aContent['text'] = $sText;
  1201. //--- Process Privacy ---//
  1202. $iObjectPrivacyView = (int)$oForm->getCleanValue('object_privacy_view');
  1203. if(empty($iObjectPrivacyView))
  1204. $iObjectPrivacyView = $this->_oConfig->getPrivacyViewDefault('object');
  1205. //--- Process Link ---//
  1206. $aLinkIds = $oForm->getCleanValue('link');
  1207. $bLinkIds = !empty($aLinkIds) && is_array($aLinkIds);
  1208. //--- Process Media ---//
  1209. $aPhotoIds = $oForm->getCleanValue(BX_TIMELINE_MEDIA_PHOTO);
  1210. $bPhotoIds = !empty($aPhotoIds) && is_array($aPhotoIds);
  1211. $aVideoIds = $oForm->getCleanValue(BX_TIMELINE_MEDIA_VIDEO);
  1212. $bVideoIds = !empty($aVideoIds) && is_array($aVideoIds);
  1213. if(!$bText && !$bLinkIds && !$bPhotoIds && !$bVideoIds)
  1214. return array('message' => _t('_bx_timeline_txt_err_empty_post'));
  1215. $sTitle = $bText ? $this->_oConfig->getTitle($sText) : $this->_oTemplate->getItemIcon($bText, $bLinkIds, $bPhotoIds, $bVideoIds);
  1216. $sDescription = _t('_bx_timeline_txt_user_added_sample', $sUserName, _t('_bx_timeline_txt_sample_with_article'));
  1217. $iId = $oForm->insert(array(
  1218. 'object_id' => $iUserId,
  1219. 'object_privacy_view' => $iObjectPrivacyView,
  1220. 'content' => serialize($aContent),
  1221. 'title' => $sTitle,
  1222. 'description' => $sDescription,
  1223. 'date' => time()
  1224. ));
  1225. if(!empty($iId)) {
  1226. $oMetatags = BxDolMetatags::getObjectInstance($this->_oConfig->getObject('metatags'));
  1227. if($bText)
  1228. $oMetatags->metaAdd($iId, $sText);
  1229. $oMetatags->locationsAddFromForm($iId, $this->_oConfig->CNF['FIELD_LOCATION_PREFIX']);
  1230. //--- Process Link ---//
  1231. if($bLinkIds)
  1232. foreach($aLinkIds as $iLinkId)
  1233. $this->_oDb->saveLink($iId, $iLinkId);
  1234. //--- Process Media ---//
  1235. if($bPhotoIds)
  1236. $this->_saveMedia(BX_TIMELINE_MEDIA_PHOTO, $iId, $aPhotoIds);
  1237. if($bVideoIds)
  1238. $this->_saveMedia(BX_TIMELINE_MEDIA_VIDEO, $iId, $aVideoIds);
  1239. $this->onPost($iId);
  1240. return array('id' => $iId);
  1241. }
  1242. return array('message' => _t('_bx_timeline_txt_err_cannot_perform_action'));
  1243. }
  1244. return array('form' => $oForm->getCode(), 'form_id' => $oForm->id);
  1245. }
  1246. public function getCmtsObject($sSystem, $iId)
  1247. {
  1248. if(empty($sSystem) || (int)$iId == 0)
  1249. return false;
  1250. $oCmts = BxDolCmts::getObjectInstance($sSystem, $iId, true, $this->_oTemplate);
  1251. if(!$oCmts || !$oCmts->isEnabled())
  1252. return false;
  1253. return $oCmts;
  1254. }
  1255. public function getViewObject($sSystem, $iId)
  1256. {
  1257. if(empty($sSystem) || (int)$iId == 0)
  1258. return false;
  1259. $oView = BxDolView::getObjectInstance($sSystem, $iId, true, $this->_oTemplate);
  1260. if(!$oView || !$oView->isEnabled())
  1261. return false;
  1262. return $oView;
  1263. }
  1264. public function getVoteObject($sSystem, $iId)
  1265. {
  1266. if(empty($sSystem) || (int)$iId == 0)
  1267. return false;
  1268. $oVote = BxDolVote::getObjectInstance($sSystem, $iId, true, $this->_oTemplate);
  1269. if(!$oVote || !$oVote->isEnabled())
  1270. return false;
  1271. return $oVote;
  1272. }
  1273. public function getReportObject($sSystem, $iId)
  1274. {
  1275. if(empty($sSystem) || (int)$iId == 0)
  1276. return false;
  1277. $oReport = BxDolReport::getObjectInstance($sSystem, $iId, true, $this->_oTemplate);
  1278. if(!$oReport || !$oReport->isEnabled())
  1279. return false;
  1280. return $oReport;
  1281. }
  1282. public function getAttachmentsMenuObject()
  1283. {
  1284. $oMenu = BxDolMenu::getObjectInstance($this->_oConfig->getObject('menu_post_attachments'), $this->_oTemplate);
  1285. $oMenu->addMarkers(array(
  1286. 'js_object' => $this->_oConfig->getJsObject('post'),
  1287. ));
  1288. return $oMenu;
  1289. }
  1290. public function getManageMenuObject()
  1291. {
  1292. return BxDolMenu::getObjectInstance($this->_oConfig->getObject('menu_item_manage'), $this->_oTemplate);
  1293. }
  1294. //--- Check permissions methods ---//
  1295. public function isAllowedPost($bPerform = false)
  1296. {
  1297. if(isAdmin())
  1298. return true;
  1299. $iUserId = $this->getUserId();
  1300. $aCheckResult = checkActionModule($iUserId, 'post', $this->getName(), $bPerform);
  1301. $oProfileOwner = BxDolProfile::getInstance($this->_iOwnerId);
  1302. if($oProfileOwner !== false) {
  1303. if($oProfileOwner->checkAllowedPostInProfile() !== CHECK_ACTION_RESULT_ALLOWED)
  1304. return _t('_sys_txt_access_denied');
  1305. bx_alert($oProfileOwner->getModule(), $this->_oConfig->getUri() . '_post', $oProfileOwner->id(), $iUserId, array('check_result' => &$aCheckResult));
  1306. }
  1307. return $aCheckResult[CHECK_ACTION_RESULT] !== CHECK_ACTION_RESULT_ALLOWED ? $aCheckResult[CHECK_ACTION_MESSAGE] : true;
  1308. }
  1309. public function isAllowedView($aEvent, $bPerform = false)
  1310. {
  1311. $CNF = $this->_oConfig->CNF;
  1312. $mixedResult = BxDolProfile::getInstance($aEvent[$CNF['FIELD_OWNER_ID']])->checkAllowedProfileView();
  1313. if($mixedResult !== CHECK_ACTION_RESULT_ALLOWED)
  1314. return false;
  1315. return true;
  1316. }
  1317. public function isAllowedDelete($aEvent, $bPerform = false)
  1318. {
  1319. if(!isLogged())
  1320. return false;
  1321. if(isAdmin())
  1322. return true;
  1323. $iUserId = (int)$this->getUserId();
  1324. $iOwnerId = (int)$aEvent['owner_id'];
  1325. $iObjectId = (int)$aEvent['object_id'];
  1326. if((($iOwnerId == $iUserId) || ($iOwnerId == 0 && $this->_oConfig->isCommon($aEvent['type'], $aEvent['action']) && $iObjectId == $iUserId)) && $this->_oConfig->isAllowDelete())
  1327. return true;
  1328. $aCheckResult = checkActionModule($iUserId, 'delete', $this->getName(), $bPerform);
  1329. $oProfileOwner = BxDolProfile::getInstance($iOwnerId);
  1330. if($oProfileOwner !== false)
  1331. bx_alert($oProfileOwner->getModule(), $this->_oConfig->getUri() . '_delete', $oProfileOwner->id(), $iUserId, array('check_result' => &$aCheckResult));
  1332. return $aCheckResult[CHECK_ACTION_RESULT] !== CHECK_ACTION_RESULT_ALLOWED ? $aCheckResult[CHECK_ACTION_MESSAGE] : true;
  1333. }
  1334. public function isAllowedComment($aEvent, $bPerform = false)
  1335. {
  1336. $mixedComments = $this->getCommentsData($aEvent['comments']);
  1337. if($mixedComments === false)
  1338. return false;
  1339. list($sSystem, $iObjectId) = $mixedComments;
  1340. $oCmts = $this->getCmtsObject($sSystem, $iObjectId);
  1341. $oCmts->addCssJs();
  1342. $bResult = true;
  1343. $oProfileOwner = BxDolProfile::getInstance($aEvent['owner_id']);
  1344. if($oProfileOwner !== false) {
  1345. if($oProfileOwner->checkAllowedPostInProfile() !== CHECK_ACTION_RESULT_ALLOWED)
  1346. return false;
  1347. bx_alert($oProfileOwner->getModule(), $this->_oConfig->getUri() . '_comment', $oProfileOwner->id(), (int)$this->getUserId(), array('result' => &$bResult));
  1348. }
  1349. return $bResult;
  1350. }
  1351. public function isAllowedViewCounter($aEvent, $bPerform = false)
  1352. {
  1353. $mixedViews = $this->getViewsData($aEvent['views']);
  1354. if($mixedViews === false)
  1355. return false;
  1356. list($sSystem, $iObjectId) = $mixedViews;
  1357. $oView = $this->getViewObject($sSystem, $iObjectId);
  1358. $bResult = true;
  1359. $oProfileOwner = BxDolProfile::getInstance($aEvent['owner_id']);
  1360. if($oProfileOwner !== false)
  1361. bx_alert($oProfileOwner->getModule(), $this->_oConfig->getUri() . '_view_counter', $oProfileOwner->id(), (int)$this->getUserId(), array('result' => &$bResult));
  1362. return $bResult;
  1363. }
  1364. public function isAllowedVote($aEvent, $bPerform = false)
  1365. {
  1366. $mixedVotes = $this->getVotesData($aEvent['votes']);
  1367. if($mixedVotes === false)
  1368. return false;
  1369. list($sSystem, $iObjectId) = $mixedVotes;
  1370. $oVote = $this->getVoteObject($sSystem, $iObjectId);
  1371. $oVote->addCssJs();
  1372. $bResult = true;
  1373. $oProfileOwner = BxDolProfile::getInstance($aEvent['owner_id']);
  1374. if($oProfileOwner !== false)
  1375. bx_alert($oProfileOwner->getModule(), $this->_oConfig->getUri() . '_vote', $oProfileOwner->id(), (int)$this->getUserId(), array('result' => &$bResult));
  1376. return $bResult;
  1377. }
  1378. public function isAllowedReport($aEvent, $bPerform = false)
  1379. {
  1380. $mixedReports = $this->getReportsData($aEvent['reports']);
  1381. if($mixedReports === false)
  1382. return false;
  1383. list($sSystem, $iObjectId) = $mixedReports;
  1384. $oReport = $this->getReportObject($sSystem, $iObjectId);
  1385. $oReport->addCssJs();
  1386. $bResult = true;
  1387. $oProfileOwner = BxDolProfile::getInstance($aEvent['owner_id']);
  1388. if($oProfileOwner !== false)
  1389. bx_alert($oProfileOwner->getModule(), $this->_oConfig->getUri() . '_report', $oProfileOwner->id(), (int)$this->getUserId(), array('result' => &$bResult));
  1390. return $bResult;
  1391. }
  1392. public function isAllowedRepost($aEvent, $bPerform = false)
  1393. {
  1394. if(isAdmin())
  1395. return true;
  1396. $iUserId = (int)$this->getUserId();
  1397. if($iUserId == 0)
  1398. return false;
  1399. $aCheckResult = checkActionModule($iUserId, 'repost', $this->getName(), $bPerform);
  1400. $oProfileOwner = BxDolProfile::getInstance($aEvent['owner_id']);
  1401. if($oProfileOwner !== false)
  1402. bx_alert($oProfileOwner->getModule(), $this->_oConfig->getUri() . '_repost', $oProfileOwner->id(), $iUserId, array('check_result' => &$aCheckResult));
  1403. return $aCheckResult[CHECK_ACTION_RESULT] !== CHECK_ACTION_RESULT_ALLOWED ? $aCheckResult[CHECK_ACTION_MESSAGE] : true;
  1404. }
  1405. public function isAllowedSend($aEvent, $bPerform = false)
  1406. {
  1407. if(!$this->_oDb->isEnabledByName('bx_convos'))
  1408. return false;
  1409. if(isAdmin())
  1410. return true;
  1411. $iUserId = (int)$this->getUserId();
  1412. if($iUserId == 0)
  1413. return false;
  1414. $aCheckResult = checkActionModule($iUserId, 'send', $this->getName(), $bPerform);
  1415. $oProfileOwner = BxDolProfile::getInstance($aEvent['owner_id']);
  1416. if($oProfileOwner !== false)
  1417. bx_alert($oProfileOwner->getModule(), $this->_oConfig->getUri() . '_send', $oProfileOwner->id(), $iUserId, array('check_result' => &$aCheckResult));
  1418. return $aCheckResult[CHECK_ACTION_RESULT] !== CHECK_ACTION_RESULT_ALLOWED ? $aCheckResult[CHECK_ACTION_MESSAGE] : true;
  1419. }
  1420. public function isAllowedPin($aEvent, $bPerform = false)
  1421. {
  1422. if((int)$aEvent['pinned'] != 0)
  1423. return false;
  1424. return $this->_isAllowedPin($aEvent, $bPerform);
  1425. }
  1426. public function isAllowedUnpin($aEvent, $bPerform = false)
  1427. {
  1428. if((int)$aEvent['pinned'] == 0)
  1429. return false;
  1430. return $this->_isAllowedPin($aEvent, $bPerform);
  1431. }
  1432. public function isAllowedMore($aEvent, $bPerform = false)
  1433. {
  1434. $oMoreMenu = $this->getManageMenuObject();
  1435. $oMoreMenu->setEventId($aEvent['id']);
  1436. return $oMoreMenu->isVisible();
  1437. }
  1438. public function checkAllowedView ($aContentInfo, $isPerformAction = false)
  1439. {
  1440. if(!$this->isAllowedView($aContentInfo, $isPerformAction))
  1441. return _t('_sys_txt_access_denied');
  1442. return CHECK_ACTION_RESULT_ALLOWED;
  1443. }
  1444. public function checkAllowedCommentsView ($aContentInfo, $isPerformAction = false)
  1445. {
  1446. $CNF = $this->_oConfig->CNF;
  1447. $mixedResult = BxDolProfile::getInstance($aContentInfo[$CNF['FIELD_OWNER_ID']])->checkAllowedProfileView();
  1448. if($mixedResult !== CHECK_ACTION_RESULT_ALLOWED)
  1449. return $mixedResult;
  1450. return CHECK_ACTION_RESULT_ALLOWED;
  1451. }
  1452. public function checkAllowedCommentsPost ($aContentInfo, $isPerformAction = false)
  1453. {
  1454. $sError = '_sys_txt_access_denied';
  1455. $aContentInfo = $this->_oTemplate->getData($aContentInfo);
  1456. if($aContentInfo === false)
  1457. return _t($sError);
  1458. if(!$this->isAllowedComment($aContentInfo, $isPerformAction))
  1459. return _t($sError);
  1460. return CHECK_ACTION_RESULT_ALLOWED;
  1461. }
  1462. public function onPost($iId)
  1463. {
  1464. $aEvent = $this->_oDb->getEvents(array('browse' => 'id', 'value' => $iId));
  1465. if($this->_oConfig->isSystem($aEvent['type'], $aEvent['action'])) {
  1466. //--- Request event's data from content module and update it in the Timeline DB.
  1467. $this->_oTemplate->getData($aEvent);
  1468. $sPostType = 'system';
  1469. $iSenderId = $aEvent['owner_id'];
  1470. } else {
  1471. $sPostType = 'common';
  1472. $iSenderId = $aEvent['object_id'];
  1473. }
  1474. //--- Event -> Post for Alerts Engine ---//
  1475. $oAlert = new BxDolAlerts($this->_oConfig->getObject('alert'), 'post_' . $sPostType, $iId, $iSenderId, array(
  1476. 'privacy_view' => $aEvent['object_privacy_view'],
  1477. 'object_author_id' => $aEvent['owner_id'],
  1478. ));
  1479. $oAlert->alert();
  1480. //--- Event -> Post for Alerts Engine ---//
  1481. }
  1482. public function onRepost($iId, $aReposted = array())
  1483. {
  1484. $aEvent = $this->_oDb->getEvents(array('browse' => 'id', 'value' => $iId));
  1485. if(empty($aReposted)) {
  1486. $aContent = unserialize($aEvent['content']);
  1487. $aReposted = $this->_oDb->getReposted($aContent['type'], $aContent['action'], $aContent['object_id']);
  1488. if(empty($aReposted) || !is_array($aReposted))
  1489. return;
  1490. }
  1491. $iUserId = $this->getUserId();
  1492. $this->_oDb->insertRepostTrack($aEvent['id'], $iUserId, $this->getUserIp(), $aReposted['id']);
  1493. $this->_oDb->updateRepostCounter($aReposted['id'], $aReposted['reposts']);
  1494. //--- Timeline -> Update for Alerts Engine ---//
  1495. $oAlert = new BxDolAlerts($this->_oConfig->getObject('alert'), 'repost', $aReposted['id'], $iUserId, array(
  1496. 'privacy_view' => $aEvent['object_privacy_view'],
  1497. 'object_author_id' => $aReposted['owner_id'],
  1498. 'repost_id' => $iId,
  1499. ));
  1500. $oAlert->alert();
  1501. //--- Timeline -> Update for Alerts Engine ---//
  1502. }
  1503. public function onDelete($aEvent)
  1504. {
  1505. $iUserId = $this->getUserId();
  1506. $sCommonPostPrefix = $this->_oConfig->getPrefix('common_post');
  1507. //--- Delete attached photos, videos and links when common event was deleted.
  1508. if($aEvent['type'] == $sCommonPostPrefix . BX_TIMELINE_PARSE_TYPE_POST) {
  1509. $this->_deleteMedia(BX_TIMELINE_MEDIA_PHOTO, $aEvent['id']);
  1510. $this->_deleteMedia(BX_TIMELINE_MEDIA_VIDEO, $aEvent['id']);
  1511. $this->_deleteLinks($aEvent['id']);
  1512. }
  1513. //--- Update parent event when repost event was deleted.
  1514. $bRepost = $aEvent['type'] == $sCommonPostPrefix . BX_TIMELINE_PARSE_TYPE_REPOST;
  1515. if($bRepost) {
  1516. $this->_oDb->deleteRepostTrack($aEvent['id']);
  1517. $aContent = unserialize($aEvent['content']);
  1518. $aReposted = $this->_oDb->getReposted($aContent['type'], $aContent['action'], $aContent['object_id']);
  1519. if(!empty($aReposted) && is_array($aReposted))
  1520. $this->_oDb->updateRepostCounter($aReposted['id'], $aReposted['reposts'], -1);
  1521. }
  1522. //--- Find and delete repost events when parent event was deleted.
  1523. $bSystem = $this->_oConfig->isSystem($aEvent['type'], $aEvent['action']);
  1524. $aRepostEvents = $this->_oDb->getEvents(array('browse' => 'reposted_by_descriptor', 'type' => $aEvent['type']));
  1525. foreach($aRepostEvents as $aRepostEvent) {
  1526. $aContent = unserialize($aRepostEvent['content']);
  1527. 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) {
  1528. $oAlert = new BxDolAlerts($this->_oConfig->getObject('alert'), 'delete_repost', $aEvent['id'], $iUserId, array(
  1529. 'repost_id' => $aRepostEvent['id'],
  1530. ));
  1531. $oAlert->alert();
  1532. }
  1533. }
  1534. //--- Delete associated meta.
  1535. $oMetatags = BxDolMetatags::getObjectInstance($this->_oConfig->getObject('metatags'));
  1536. $oMetatags->onDeleteContent($aEvent['id']);
  1537. //--- Event -> Delete for Alerts Engine ---//
  1538. if($bRepost)
  1539. $oAlert = new BxDolAlerts($this->_oConfig->getObject('alert'), 'delete_repost', $aReposted['id'], $iUserId, array(
  1540. 'repost_id' => $aEvent['id'],
  1541. ));
  1542. else
  1543. $oAlert = new BxDolAlerts($this->_oConfig->getObject('alert'), 'delete', $aEvent['id'], $iUserId);
  1544. $oAlert->alert();
  1545. //--- Event -> Delete for Alerts Engine ---//
  1546. }
  1547. public function getParams($sView = '', $sType = '', $iOwnerId = 0, $iStart = 0, $iPerPage = 0, $sFilter = '', $aModules = array(), $iTimeline = 0)
  1548. {
  1549. return $this->_prepareParams($sView, $sType, $iOwnerId, $iStart, $iPerPage, $sFilter, $aModules, $iTimeline);
  1550. }
  1551. public function getViewsData(&$aViews)
  1552. {
  1553. if(empty($aViews) || !is_array($aViews))
  1554. return false;
  1555. $sSystem = isset($aViews['system']) ? $aViews['system'] : '';
  1556. $iObjectId = isset($aViews['object_id']) ? (int)$aViews['object_id'] : 0;
  1557. $iCount = isset($aViews['count']) ? (int)$aViews['count'] : 0;
  1558. if($sSystem == '' || $iObjectId == 0)
  1559. return false;
  1560. return array($sSystem, $iObjectId, $iCount);
  1561. }
  1562. public function getVotesData(&$aVotes)
  1563. {
  1564. if(empty($aVotes) || !is_array($aVotes))
  1565. return false;
  1566. $sSystem = isset($aVotes['system']) ? $aVotes['system'] : '';
  1567. $iObjectId = isset($aVotes['object_id']) ? (int)$aVotes['object_id'] : 0;
  1568. $iCount = isset($aVotes['count']) ? (int)$aVotes['count'] : 0;
  1569. if($sSystem == '' || $iObjectId == 0)
  1570. return false;
  1571. return array($sSystem, $iObjectId, $iCount);
  1572. }
  1573. public function getReportsData(&$aReports)
  1574. {
  1575. if(empty($aReports) || !is_array($aReports))
  1576. return false;
  1577. $sSystem = isset($aReports['system']) ? $aReports['system'] : '';
  1578. $iObjectId = isset($aReports['object_id']) ? (int)$aReports['object_id'] : 0;
  1579. $iCount = isset($aReports['count']) ? (int)$aReports['count'] : 0;
  1580. if($sSystem == '' || $iObjectId == 0)
  1581. return false;
  1582. return array($sSystem, $iObjectId, $iCount);
  1583. }
  1584. public function getCommentsData(&$aComments)
  1585. {
  1586. if(empty($aComments) || !is_array($aComments))
  1587. return false;
  1588. $sSystem = isset($aComments['system']) ? $aComments['system'] : '';
  1589. $iObjectId = isset($aComments['object_id']) ? (int)$aComments['object_id'] : 0;
  1590. $iCount = isset($aComments['count']) ? (int)$aComments['count'] : 0;
  1591. if($sSystem == '' || $iObjectId == 0 || ($iCount == 0 && !isLogged()))
  1592. return false;
  1593. return array($sSystem, $iObjectId, $iCount);
  1594. }
  1595. /**
  1596. * Protected Methods
  1597. */
  1598. protected function _serviceGetBlockView($iProfileId = 0, $sView = BX_TIMELINE_VIEW_DEFAULT)
  1599. {
  1600. if(empty($iProfileId) && bx_get('profile_id') !== false)
  1601. $iProfileId = bx_process_input(bx_get('profile_id'), BX_DATA_INT);
  1602. if(empty($iProfileId) && isLogged())
  1603. $iProfileId = bx_get_logged_profile_id();
  1604. $aBlock = $this->_getBlockView($iProfileId, $sView);
  1605. if(!empty($aBlock))
  1606. return $aBlock;
  1607. return array('content' => MsgBox(_t('_bx_timeline_txt_msg_no_results')));
  1608. }
  1609. protected function _serviceGetBlockViewProfile($sProfileModule = 'bx_persons', $iProfileContentId = 0, $sView = BX_TIMELINE_VIEW_DEFAULT, $iStart = -1, $iPerPage = -1, $sFilter = '', $aModules = array(), $iTimeline = -1)
  1610. {
  1611. if(empty($sProfileModule))
  1612. return array();
  1613. if(empty($iProfileContentId) && bx_get('id') !== false)
  1614. $iProfileContentId = bx_process_input(bx_get('id'), BX_DATA_INT);
  1615. $oProfile = BxDolProfile::getInstanceByContentAndType($iProfileContentId, $sProfileModule);
  1616. if(empty($oProfile))
  1617. return array();
  1618. return $this->_getBlockView($oProfile->id(), $sView, $iStart, $iPerPage, $sFilter, $aModules, $iTimeline);
  1619. }
  1620. protected function _serviceGetBlockViewHome($iProfileId = 0, $sView = BX_TIMELINE_VIEW_DEFAULT, $iStart = -1, $iPerPage = -1, $iPerPageDefault = -1, $iTimeline = -1, $sFilter = '', $aModules = array())
  1621. {
  1622. $sRssUrl = BX_DOL_URL_ROOT . $this->_oConfig->getBaseUri() . 'rss/' . BX_BASE_MOD_NTFS_TYPE_PUBLIC . '/';
  1623. BxDolTemplate::getInstance()->addPageRssLink(_t('_bx_timeline_page_title_view_home'), $sRssUrl);
  1624. return $this->_serviceGetBlockViewByType($iProfileId, $sView, BX_BASE_MOD_NTFS_TYPE_PUBLIC, $iStart, $iPerPage, $this->_oConfig->getPerPage('home'), $iTimeline, $sFilter, $aModules);
  1625. }
  1626. 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())
  1627. {
  1628. $aParams = $this->_prepareParams($sView, $sType, $iProfileId, $iStart, $iPerPage, $sFilter, $aModules, $iTimeline);
  1629. $aParams['view'] = $sView;
  1630. $aParams['per_page'] = (int)$iPerPage > 0 ? $iPerPage : ((int)$iPerPageDefault > 0 ? $iPerPageDefault : $this->_oConfig->getPerPage());
  1631. $this->_iOwnerId = $aParams['owner_id'];
  1632. $sContent = $this->_oTemplate->getViewBlock($aParams);
  1633. return array('content' => $sContent);
  1634. }
  1635. protected function _getBlockPost($iProfileId, $aParams = array())
  1636. {
  1637. $this->_iOwnerId = $iProfileId;
  1638. if($this->isAllowedPost() !== true)
  1639. return array();
  1640. $sContent = $this->_oTemplate->getPostBlock($this->_iOwnerId, $aParams);
  1641. return array('content' => $sContent);
  1642. }
  1643. protected function _getBlockView($iProfileId, $sView = BX_TIMELINE_VIEW_DEFAULT, $iStart = -1, $iPerPage = -1, $sFilter = '', $aModules = array(), $iTimeline = -1)
  1644. {
  1645. if(!$iProfileId)
  1646. return array();
  1647. $aParams = $this->_prepareParams($sView, BX_BASE_MOD_NTFS_TYPE_OWNER, $iProfileId, $iStart, $iPerPage, $sFilter, $aModules, $iTimeline);
  1648. $aParams['view'] = $sView;
  1649. $aParams['per_page'] = (int)$iPerPage > 0 ? $iPerPage : $this->_oConfig->getPerPage('profile');
  1650. $this->_iOwnerId = $aParams['owner_id'];
  1651. $oProfileOwner = BxDolProfile::getInstance($this->_iOwnerId);
  1652. $mixedResult = $oProfileOwner->checkAllowedProfileView();
  1653. if($mixedResult !== CHECK_ACTION_RESULT_ALLOWED)
  1654. return array('content' => MsgBox($mixedResult));
  1655. list($sUserName, $sUserUrl) = $this->getUserInfo($aParams['owner_id']);
  1656. $sRssUrl = BX_DOL_URL_ROOT . $this->_oConfig->getBaseUri() . 'rss/' . BX_BASE_MOD_NTFS_TYPE_OWNER . '/' . $iProfileId . '/';
  1657. $sJsObject = $this->_oConfig->getJsObject('view');
  1658. $aMenu = array(
  1659. 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),
  1660. 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)),
  1661. 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')),
  1662. array('id' => $sView . '-get-rss', 'name' => $sView . '-get-rss', 'class' => '', 'link' => $sRssUrl, 'target' => '_blank', 'title' => _t('_bx_timeline_menu_item_get_rss')),
  1663. );
  1664. $sContent = '';
  1665. bx_alert($oProfileOwner->getModule(), $this->_oConfig->getUri() . '_view', $this->_iOwnerId, $this->getUserId(), array('override_content' => &$sContent, 'params' => &$aParams, 'menu' => &$aMenu));
  1666. $oMenu = new BxTemplMenuInteractive(array('template' => 'menu_interactive_vertical.html', 'menu_id'=> $sView . '-view-all', 'menu_items' => $aMenu));
  1667. $oMenu->setSelected('', $sView . '-view-all');
  1668. if (!$sContent)
  1669. $sContent = $this->_oTemplate->getViewBlock($aParams);
  1670. BxDolTemplate::getInstance()->addPageRssLink(_t('_bx_timeline_page_title_view'), $sRssUrl);
  1671. return array('content' => $sContent, 'menu' => $oMenu);
  1672. }
  1673. protected function _isAllowedPin($aEvent, $bPerform = false)
  1674. {
  1675. if(isAdmin())
  1676. return true;
  1677. $iUserId = (int)$this->getUserId();
  1678. if($iUserId == 0)
  1679. return false;
  1680. if((int)$aEvent['owner_id'] == $iUserId)
  1681. return true;
  1682. $aCheckResult = checkActionModule($iUserId, 'pin', $this->getName(), $bPerform);
  1683. $oProfileOwner = BxDolProfile::getInstance($aEvent['owner_id']);
  1684. if($oProfileOwner !== false)
  1685. bx_alert($oProfileOwner->getModule(), $this->_oConfig->getUri() . '_pin', $oProfileOwner->id(), $iUserId, array('check_result' => &$aCheckResult));
  1686. return $aCheckResult[CHECK_ACTION_RESULT] !== CHECK_ACTION_RESULT_ALLOWED ? $aCheckResult[CHECK_ACTION_MESSAGE] : true;
  1687. }
  1688. protected function _deleteLinks($iId)
  1689. {
  1690. $aLinks = $this->_oDb->getLinks($iId);
  1691. if(empty($aLinks) || !is_array($aLinks))
  1692. return;
  1693. $oStorage = BxDolStorage::getObjectInstance($this->_oConfig->getObject('storage_photos'));
  1694. foreach($aLinks as $aLink)
  1695. if(!empty($aLink['media_id']))
  1696. $oStorage->deleteFile($aLink['media_id']);
  1697. $this->_oDb->deleteLinks($iId);
  1698. }
  1699. protected function _saveMedia($sType, $iId, $aItemIds)
  1700. {
  1701. if(empty($aItemIds) || !is_array($aItemIds))
  1702. return;
  1703. $iUserId = $this->getUserId();
  1704. $oStorage = BxDolStorage::getObjectInstance($this->_oConfig->getObject('storage_' . strtolower($sType) . 's'));
  1705. foreach($aItemIds as $iItemId)
  1706. if($this->_oDb->saveMedia($sType, $iId, $iItemId))
  1707. $oStorage->afterUploadCleanup($iItemId, $iUserId);
  1708. }
  1709. protected function _deleteMedia($sType, $iId)
  1710. {
  1711. $aItems = $this->_oDb->getMedia($sType, $iId);
  1712. if(empty($aItems) || !is_array($aItems))
  1713. return;
  1714. $oStorage = BxDolStorage::getObjectInstance($this->_oConfig->getObject('storage_' . strtolower($sType) . 's'));
  1715. foreach($aItems as $iItemId)
  1716. $oStorage->deleteFile($iItemId);
  1717. $this->_oDb->deleteMedia($sType, $iId);
  1718. }
  1719. protected function _prepareParams($sView, $sType, $iOwnerId, $iStart, $iPerPage, $sFilter, $aModules, $iTimeline)
  1720. {
  1721. return array(
  1722. 'view' => !empty($sView) ? $sView : BX_TIMELINE_VIEW_DEFAULT,
  1723. 'browse' => 'list',
  1724. 'type' => !empty($sType) ? $sType : BX_TIMELINE_TYPE_DEFAULT,
  1725. 'owner_id' => (int)$iOwnerId != 0 ? $iOwnerId : $this->getUserId(),
  1726. 'filter' => !empty($sFilter) ? $sFilter : BX_TIMELINE_FILTER_ALL,
  1727. 'modules' => is_array($aModules) && !empty($aModules) ? $aModules : array(),
  1728. 'timeline' => (int)$iTimeline > 0 ? $iTimeline : 0,
  1729. 'active' => 1,
  1730. 'hidden' => 0,
  1731. 'start' => (int)$iStart > 0 ? $iStart : 0,
  1732. 'per_page' => (int)$iPerPage > 0 ? $iPerPage : $this->_oConfig->getPerPage(),
  1733. );
  1734. }
  1735. protected function _prepareParamsGet()
  1736. {
  1737. $aParams = array(
  1738. 'browse' => 'list',
  1739. 'dynamic_mode' => true,
  1740. );
  1741. $aParams['view'] = bx_get('view');
  1742. $aParams['view'] = $aParams['view'] !== false ? bx_process_input($aParams['view'], BX_DATA_TEXT) : BX_TIMELINE_VIEW_DEFAULT;
  1743. $aParams['type'] = bx_get('type');
  1744. $aParams['type'] = $aParams['type'] !== false ? bx_process_input($aParams['type'], BX_DATA_TEXT) : BX_TIMELINE_TYPE_DEFAULT;
  1745. $aParams['owner_id'] = bx_get('owner_id');
  1746. $aParams['owner_id'] = $aParams['owner_id'] !== false ? bx_process_input($aParams['owner_id'], BX_DATA_INT) : $this->getUserId();
  1747. $aParams['start'] = bx_get('start');
  1748. $aParams['start'] = $aParams['start'] !== false ? bx_process_input($aParams['start'], BX_DATA_INT) : 0;
  1749. $aParams['per_page'] = bx_get('per_page');
  1750. $aParams['per_page'] = $aParams['per_page'] !== false ? bx_process_input($aParams['per_page'], BX_DATA_INT) : $this->_oConfig->getPerPage();
  1751. $aParams['filter'] = bx_get('filter');
  1752. $aParams['filter'] = $aParams['filter'] !== false ? bx_process_input($aParams['filter'], BX_DATA_TEXT) : BX_TIMELINE_FILTER_ALL;
  1753. $aParams['modules'] = bx_get('modules');
  1754. $aParams['modules'] = $aParams['modules'] !== false ? bx_process_input($aParams['modules'], BX_DATA_TEXT) : array();
  1755. $aParams['timeline'] = bx_get('timeline');
  1756. $aParams['timeline'] = $aParams['timeline'] !== false ? bx_process_input($aParams['timeline'], BX_DATA_INT) : 0;
  1757. $aParams['active'] = 1;
  1758. $aParams['hidden'] = 0;
  1759. return $aParams;
  1760. }
  1761. protected function _prepareTextForSave($s)
  1762. {
  1763. return bx_process_input($s, BX_DATA_HTML);
  1764. }
  1765. protected function _getFieldValue($sField, $iContentId)
  1766. {
  1767. $CNF = &$this->_oConfig->CNF;
  1768. if(empty($CNF[$sField]))
  1769. return false;
  1770. $aEvent = $this->_oDb->getEvents(array('browse' => 'id', 'value' => $iContentId));
  1771. if(empty($aEvent) || empty($aEvent[$CNF[$sField]]))
  1772. return false;
  1773. return $aEvent[$CNF[$sField]];
  1774. }
  1775. }
  1776. /** @} */