BxTimelineModule.php 38 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059
  1. <?php defined('BX_DOL') or die('hack attempt');
  2. /**
  3. * Copyright (c) BoonEx Pty Limited - http://www.boonex.com/
  4. * CC-BY License - http://creativecommons.org/licenses/by/3.0/
  5. *
  6. * @defgroup Timeline Timeline
  7. * @ingroup TridentModules
  8. *
  9. * @{
  10. */
  11. bx_import('BxDolAcl');
  12. bx_import('BxBaseModNotificationsModule');
  13. define('BX_TIMELINE_TYPE_ITEM', 'view_item');
  14. define('BX_TIMELINE_TYPE_DEFAULT', BX_BASE_MOD_NTFS_TYPE_OWNER);
  15. define('BX_TIMELINE_FILTER_ALL', 'all');
  16. define('BX_TIMELINE_FILTER_OWNER', 'owner');
  17. define('BX_TIMELINE_FILTER_OTHER', 'other');
  18. define('BX_TIMELINE_PARSE_TYPE_POST', 'post');
  19. define('BX_TIMELINE_PARSE_TYPE_SHARE', 'share');
  20. define('BX_TIMELINE_PARSE_TYPE_DEFAULT', BX_TIMELINE_PARSE_TYPE_POST);
  21. define('BX_TIMELINE_MEDIA_PHOTO', 'photo');
  22. define('BX_TIMELINE_MEDIA_VIDEO', 'video');
  23. class BxTimelineModule extends BxBaseModNotificationsModule
  24. {
  25. protected $_sJsPostObject;
  26. protected $_sJsViewObject;
  27. protected $_aPostElements;
  28. protected $_sJsOutlineObject;
  29. protected $_sDividerTemplate;
  30. protected $_sBalloonTemplate;
  31. protected $_sCmtPostTemplate;
  32. protected $_sCmtViewTemplate;
  33. protected $_sCmtTemplate;
  34. /**
  35. * Constructor
  36. */
  37. function __construct($aModule)
  38. {
  39. parent::__construct($aModule);
  40. }
  41. /**
  42. * ACTION METHODS
  43. */
  44. public function actionPost()
  45. {
  46. $sType = bx_process_input($_POST['type']);
  47. $sMethod = 'getForm' . ucfirst($sType);
  48. if(!method_exists($this, $sMethod)) {
  49. echoJson(array());
  50. return;
  51. }
  52. $this->_iOwnerId = bx_process_input(bx_get('owner_id'), BX_DATA_INT);
  53. $mixedAllowed = $this->isAllowedPost(true);
  54. if($mixedAllowed !== true) {
  55. echoJson(array('msg' => strip_tags($mixedAllowed)));
  56. return;
  57. }
  58. $aResult = $this->$sMethod();
  59. echoJson($aResult);
  60. }
  61. function actionDelete()
  62. {
  63. $this->_iOwnerId = bx_process_input(bx_get('owner_id'), BX_DATA_INT);
  64. $iId = bx_process_input(bx_get('id'), BX_DATA_INT);
  65. $aEvent = $this->_oDb->getEvents(array('browse' => 'id', 'value' => $iId));
  66. $mixedAllowed = $this->isAllowedDelete($aEvent, true);
  67. if($mixedAllowed !== true) {
  68. echoJson(array('code' => 1, 'msg' => strip_tags($mixedAllowed)));
  69. return;
  70. }
  71. if(!$this->deleteEvent($aEvent))
  72. echoJson(array('code' => 2));
  73. else
  74. echoJson(array('code' => 0, 'id' => $iId));
  75. }
  76. public function actionShare()
  77. {
  78. $iAuthorId = $this->getUserId();
  79. $iOwnerId = bx_process_input(bx_get('owner_id'), BX_DATA_INT);
  80. $aContent = array(
  81. 'type' => bx_process_input(bx_get('type'), BX_DATA_TEXT),
  82. 'action' => bx_process_input(bx_get('action'), BX_DATA_TEXT),
  83. 'object_id' => bx_process_input(bx_get('object_id'), BX_DATA_INT),
  84. );
  85. $aShared = $this->_oDb->getShared($aContent['type'], $aContent['action'], $aContent['object_id']);
  86. if(empty($aShared) || !is_array($aShared)) {
  87. echoJson(array('code' => 1, 'msg' => _t('_bx_timeline_txt_err_cannot_share')));
  88. return;
  89. }
  90. $mixedAllowed = $this->isAllowedShare($aShared, true);
  91. if($mixedAllowed !== true) {
  92. echoJson(array('code' => 2, 'msg' => strip_tags($mixedAllowed)));
  93. return;
  94. }
  95. $bShared = $this->_oDb->isShared($aShared['id'], $iOwnerId, $iAuthorId);
  96. if($bShared) {
  97. echoJson(array('code' => 3, 'msg' => _t('_bx_timeline_txt_err_already_shared')));
  98. return;
  99. }
  100. $iId = $this->_oDb->insertEvent(array(
  101. 'owner_id' => $iOwnerId,
  102. 'type' => $this->_oConfig->getPrefix('common_post') . 'share',
  103. 'action' => '',
  104. 'object_id' => $iAuthorId,
  105. 'object_privacy_view' => $this->_oConfig->getPrivacyViewDefault(),
  106. 'content' => serialize($aContent),
  107. 'title' => '',
  108. 'description' => ''
  109. ));
  110. if(empty($iId)) {
  111. echoJson(array('code' => 4, 'msg' => _t('_bx_timeline_txt_err_cannot_share')));
  112. return;
  113. }
  114. $this->onShare($iId, $aShared);
  115. $aShared = $this->_oDb->getShared($aContent['type'], $aContent['action'], $aContent['object_id']);
  116. $sCounter = $this->_oTemplate->getShareCounter($aShared);
  117. echoJson(array(
  118. 'code' => 0,
  119. 'msg' => _t('_bx_timeline_txt_msg_success_share'),
  120. 'count' => $aShared['shares'],
  121. 'counter' => $sCounter,
  122. 'disabled' => !$bShared
  123. ));
  124. }
  125. function actionGetPost()
  126. {
  127. $this->_iOwnerId = bx_process_input(bx_get('owner_id'), BX_DATA_INT);
  128. $iEvent = bx_process_input(bx_get('id'), BX_DATA_INT);
  129. $aEvent = $this->_oDb->getEvents(array('browse' => 'id', 'value' => $iEvent));
  130. echoJson(array('item' => $this->_oTemplate->getPost($aEvent, array('type' => 'owner', 'owner_id' => $this->_iOwnerId, 'dynamic_mode' => true))));
  131. }
  132. function actionGetPosts()
  133. {
  134. $aParams = $this->_prepareParamsGet();
  135. list($sItems, $sLoadMore, $sBack) = $this->_oTemplate->getPosts($aParams);
  136. echoJson(array('items' => $sItems, 'load_more' => $sLoadMore, 'back' => $sBack));
  137. }
  138. public function actionGetPostForm($sType)
  139. {
  140. $this->_iOwnerId = bx_process_input(bx_get('owner_id'), BX_DATA_INT);
  141. $sMethod = 'getForm' . ucfirst($sType);
  142. if(!method_exists($this, $sMethod)) {
  143. echoJson(array());
  144. return;
  145. }
  146. $aResult = $this->$sMethod();
  147. echoJson($aResult);
  148. }
  149. public function actionGetComments()
  150. {
  151. $this->_iOwnerId = bx_process_input(bx_get('owner_id'), BX_DATA_INT);
  152. $sSystem = bx_process_input(bx_get('system'), BX_DATA_TEXT);
  153. $iId = bx_process_input(bx_get('id'), BX_DATA_INT);
  154. $sComments = $this->_oTemplate->getComments($sSystem, $iId);
  155. echoJson(array('content' => $sComments));
  156. }
  157. public function actionAddAttachLink()
  158. {
  159. $aResult = $this->getFormAttachLink();
  160. echoJson($aResult);
  161. }
  162. public function actionDeleteAttachLink()
  163. {
  164. $iUserId = $this->getUserId();
  165. $iLinkId = bx_process_input(bx_get('id'), BX_DATA_INT);
  166. if(empty($iLinkId)) {
  167. echoJson(array());
  168. return;
  169. }
  170. $aLink = $this->_oDb->getUnusedLinks($iUserId, $iLinkId);
  171. if(empty($aLink) || !is_array($aLink)) {
  172. echoJson(array());
  173. return;
  174. }
  175. if(!empty($aLink['media_id']))
  176. BxDolStorage::getObjectInstance($this->_oConfig->getObject('storage_photos'))->deleteFile($aLink['media_id']);
  177. $aResult = array();
  178. if($this->_oDb->deleteUnusedLinks($iUserId, $iLinkId))
  179. $aResult = array('code' => 0);
  180. else
  181. $aResult = array('code' => 1, 'msg' => _t('_bx_timeline_form_post_input_link_err_delete'));
  182. echoJson($aResult);
  183. }
  184. public function actionGetAttachLinkForm()
  185. {
  186. echo $this->_oTemplate->getAttachLinkForm();
  187. }
  188. public function actionGetSharedBy()
  189. {
  190. $iSharedId = bx_process_input(bx_get('id'), BX_DATA_INT);
  191. echo $this->_oTemplate->getSharedBy($iSharedId);
  192. }
  193. function actionRss($iOwnerId)
  194. {
  195. list($sUserName) = $this->getUserInfo($iOwnerId);
  196. $sRssCaption = _t('_bx_timeline_txt_rss_caption', $sUserName);
  197. $sRssLink = $this->_oConfig->getViewUrl($iOwnerId);
  198. $aParams = $this->_prepareParams('owner', $iOwnerId, 0, $this->_oConfig->getRssLength(), '', array(), 0);
  199. $aEvents = $this->_oDb->getEvents($aParams);
  200. $aRssData = array();
  201. foreach($aEvents as $aEvent) {
  202. if(empty($aEvent['title'])) continue;
  203. $aRssData[$aEvent['id']] = array(
  204. 'UnitID' => $aEvent['id'],
  205. 'UnitTitle' => $aEvent['title'],
  206. 'UnitLink' => $this->_oConfig->getItemViewUrl($aEvent),
  207. 'UnitDesc' => $aEvent['description'],
  208. 'UnitDateTimeUTS' => $aEvent['date'],
  209. );
  210. }
  211. $oRss = new BxDolRssFactory();
  212. header('Content-Type: application/xml; charset=utf-8');
  213. echo $oRss->GenRssByData($aRssData, $sRssCaption, $sRssLink);
  214. }
  215. /**
  216. * SERVICE METHODS
  217. *
  218. * Get Post block for a separate page.
  219. */
  220. public function serviceGetBlockPost($iProfileId = 0)
  221. {
  222. if(empty($iProfileId) && bx_get('profile_id') !== false)
  223. $iProfileId = bx_process_input(bx_get('profile_id'), BX_DATA_INT);
  224. if(empty($iProfileId) && isLogged())
  225. $iProfileId = bx_get_logged_profile_id();
  226. return $this->getBlockPost($iProfileId);
  227. }
  228. public function serviceGetBlockPostProfile($sProfileModule = 'bx_persons', $iProfileContentId = 0)
  229. {
  230. if(empty($sProfileModule))
  231. return array();
  232. if(empty($iProfileContentId) && bx_get('id') !== false)
  233. $iProfileContentId = bx_process_input(bx_get('id'), BX_DATA_INT);
  234. $oProfile = BxDolProfile::getInstanceByContentAndType($iProfileContentId, $sProfileModule);
  235. if(empty($oProfile))
  236. return array();
  237. return $this->getBlockPost($oProfile->id());
  238. }
  239. /*
  240. * Get View block for a separate page. Will return a block with "Empty" message if nothing found.
  241. */
  242. public function serviceGetBlockView($iProfileId = 0)
  243. {
  244. if(empty($iProfileId) && bx_get('profile_id') !== false)
  245. $iProfileId = bx_process_input(bx_get('profile_id'), BX_DATA_INT);
  246. if(empty($iProfileId) && isLogged())
  247. $iProfileId = bx_get_logged_profile_id();
  248. $aBlock = $this->getBlockView($iProfileId);
  249. if(!empty($aBlock))
  250. return $aBlock;
  251. return array('content' => MsgBox(_t('_bx_timeline_txt_msg_no_results')));
  252. }
  253. public function serviceGetBlockViewProfile($sProfileModule = 'bx_persons', $iProfileContentId = 0, $iStart = -1, $iPerPage = -1, $sFilter = '', $aModules = array(), $iTimeline = -1)
  254. {
  255. if(empty($sProfileModule))
  256. return array();
  257. if(empty($iProfileContentId) && bx_get('id') !== false)
  258. $iProfileContentId = bx_process_input(bx_get('id'), BX_DATA_INT);
  259. $oProfile = BxDolProfile::getInstanceByContentAndType($iProfileContentId, $sProfileModule);
  260. if(empty($oProfile))
  261. return array();
  262. return $this->getBlockView($oProfile->id(), $iStart, $iPerPage, $sFilter, $aModules, $iTimeline);
  263. }
  264. public function serviceGetBlockViewAccount($iProfileId = 0, $iStart = -1, $iPerPage = -1, $iTimeline = -1, $sFilter = '', $aModules = array())
  265. {
  266. $aParams = $this->_prepareParams(BX_BASE_MOD_NTFS_TYPE_CONNECTIONS, $iProfileId, $iStart, $iPerPage, $sFilter, $aModules, $iTimeline);
  267. $aParams['per_page'] = (int)$iPerPage > 0 ? $iPerPage : $this->_oConfig->getPerPage('account');
  268. $this->_iOwnerId = $aParams['owner_id'];
  269. $sContent = $this->_oTemplate->getViewBlock($aParams);
  270. return array('content' => $sContent);
  271. }
  272. public function serviceGetBlockViewHome($iProfileId = 0, $iStart = -1, $iPerPage = -1, $iTimeline = -1, $sFilter = '', $aModules = array())
  273. {
  274. $aParams = $this->_prepareParams(BX_BASE_MOD_NTFS_TYPE_PUBLIC, $iProfileId, $iStart, $iPerPage, $sFilter, $aModules, $iTimeline);
  275. $aParams['per_page'] = (int)$iPerPage > 0 ? $iPerPage : $this->_oConfig->getPerPage('home');
  276. $this->_iOwnerId = $aParams['owner_id'];
  277. $sContent = $this->_oTemplate->getViewBlock($aParams);
  278. return array('content' => $sContent);
  279. }
  280. public function serviceGetBlockItem()
  281. {
  282. $iItemId = bx_process_input(bx_get('id'), BX_DATA_INT);
  283. if(!$iItemId)
  284. return array();
  285. return array('content' => $this->_oTemplate->getItemBlock($iItemId));
  286. }
  287. /**
  288. * Data for Notifications module
  289. */
  290. public function serviceGetNotificationsData()
  291. {
  292. $sModule = $this->_aModule['name'];
  293. return array(
  294. 'handlers' => array(
  295. array('group' => $sModule . '_object', 'type' => 'insert', 'alert_unit' => $sModule, 'alert_action' => 'post_common', 'module_name' => $sModule, 'module_method' => 'get_notifications_post', 'module_class' => 'Module'),
  296. array('group' => $sModule . '_object', 'type' => 'delete', 'alert_unit' => $sModule, 'alert_action' => 'delete'),
  297. array('group' => $sModule . '_comment', 'type' => 'insert', 'alert_unit' => $sModule, 'alert_action' => 'commentPost', 'module_name' => $sModule, 'module_method' => 'get_notifications_comment', 'module_class' => 'Module'),
  298. array('group' => $sModule . '_comment', 'type' => 'delete', 'alert_unit' => $sModule, 'alert_action' => 'commentRemoved'),
  299. array('group' => $sModule . '_vote', 'type' => 'insert', 'alert_unit' => $sModule, 'alert_action' => 'doVote', 'module_name' => $sModule, 'module_method' => 'get_notifications_vote', 'module_class' => 'Module'),
  300. array('group' => $sModule . '_vote', 'type' => 'delete', 'alert_unit' => $sModule, 'alert_action' => 'undoVote'),
  301. ),
  302. 'alerts' => array(
  303. array('unit' => $sModule, 'action' => 'post_common'),
  304. array('unit' => $sModule, 'action' => 'deleted'),
  305. array('unit' => $sModule, 'action' => 'commentPost'),
  306. array('unit' => $sModule, 'action' => 'commentRemoved'),
  307. array('unit' => $sModule, 'action' => 'doVote'),
  308. array('unit' => $sModule, 'action' => 'undoVote'),
  309. )
  310. );
  311. }
  312. public function serviceGetNotificationsPost($aEvent)
  313. {
  314. $CNF = &$this->_oConfig->CNF;
  315. $iContent = (int)$aEvent['object_id'];
  316. $aContent = $this->_oDb->getEvents(array('browse' => 'id', 'value' => $iContent));
  317. if(empty($aContent) || !is_array($aContent))
  318. return array();
  319. $sEntryCaption = !empty($aContent['title']) ? $aContent['title'] : strmaxtextlen($aContent['description'], 20, '...');
  320. return array(
  321. 'entry_sample' => _t($CNF['T']['txt_sample_single_ext']),
  322. 'entry_url' => $this->_oConfig->getItemViewUrl($aContent),
  323. 'entry_caption' => $sEntryCaption,
  324. 'entry_author' => $aContent['owner_id'],
  325. 'lang_key' => '', //may be empty or not specified. In this case the default one from Notification module will be used.
  326. );
  327. }
  328. public function serviceGetNotificationsComment($aEvent)
  329. {
  330. $CNF = &$this->_oConfig->CNF;
  331. $iContent = (int)$aEvent['object_id'];
  332. $aContent = $this->_oDb->getEvents(array('browse' => 'id', 'value' => $iContent));
  333. if(empty($aContent) || !is_array($aContent))
  334. return array();
  335. $oComment = BxDolCmts::getObjectInstance($CNF['OBJECT_COMMENTS'], $iContent);
  336. if(!$oComment || !$oComment->isEnabled())
  337. return array();
  338. $sEntryCaption = !empty($aContent['title']) ? $aContent['title'] : strmaxtextlen($aContent['description'], 20, '...');
  339. return array(
  340. 'entry_sample' => _t($CNF['T']['txt_sample_single']),
  341. 'entry_url' => $this->_oConfig->getItemViewUrl($aContent),
  342. 'entry_caption' => $sEntryCaption,
  343. 'entry_author' => $aContent['owner_id'],
  344. 'subentry_sample' => _t($CNF['T']['txt_sample_comment_single']),
  345. 'subentry_url' => $oComment->getViewUrl((int)$aEvent['subobject_id']),
  346. 'lang_key' => '', //may be empty or not specified. In this case the default one from Notification module will be used.
  347. );
  348. }
  349. public function serviceGetNotificationsVote($aEvent)
  350. {
  351. $CNF = &$this->_oConfig->CNF;
  352. $iContent = (int)$aEvent['object_id'];
  353. $aContent = $this->_oDb->getEvents(array('browse' => 'id', 'value' => $iContent));
  354. if(empty($aContent) || !is_array($aContent))
  355. return array();
  356. $oVote = BxDolVote::getObjectInstance($CNF['OBJECT_VOTES'], $iContent);
  357. if(!$oVote || !$oVote->isEnabled())
  358. return array();
  359. $sEntryCaption = !empty($aContent['title']) ? $aContent['title'] : strmaxtextlen($aContent['description'], 20, '...');
  360. return array(
  361. 'entry_sample' => _t($CNF['T']['txt_sample_single']),
  362. 'entry_url' => $this->_oConfig->getItemViewUrl($aContent),
  363. 'entry_caption' => $sEntryCaption,
  364. 'entry_author' => $aContent['owner_id'],
  365. 'subentry_sample' => _t($CNF['T']['txt_sample_vote_single']),
  366. 'lang_key' => '', //may be empty or not specified. In this case the default one from Notification module will be used.
  367. );
  368. }
  369. public function serviceGetShareElementBlock($iOwnerId, $sType, $sAction, $iObjectId, $aParams = array())
  370. {
  371. if(!$this->isEnabled())
  372. return '';
  373. $aParams = array_merge($this->_oConfig->getShareDefaults(), $aParams);
  374. return $this->_oTemplate->getShareElement($iOwnerId, $sType, $sAction, $iObjectId, $aParams);
  375. }
  376. public function serviceGetShareCounter($sType, $sAction, $iObjectId)
  377. {
  378. if(!$this->isEnabled())
  379. return '';
  380. $aShared = $this->_oDb->getShared($sType, $sAction, $iObjectId);
  381. return $this->_oTemplate->getShareCounter($aShared);
  382. }
  383. public function serviceGetShareJsScript()
  384. {
  385. if(!$this->isEnabled())
  386. return '';
  387. return $this->_oTemplate->getShareJsScript();
  388. }
  389. public function serviceGetShareJsClick($iOwnerId, $sType, $sAction, $iObjectId)
  390. {
  391. if(!$this->isEnabled())
  392. return '';
  393. return $this->_oTemplate->getShareJsClick($iOwnerId, $sType, $sAction, $iObjectId);
  394. }
  395. public function serviceGetMenuItemAddonComment($sSystem, $iObjectId)
  396. {
  397. if(empty($sSystem) || empty($iObjectId))
  398. return '';
  399. $oCmts = $this->getCmtsObject($sSystem, $iObjectId);
  400. if($oCmts === false)
  401. return '';
  402. $iCounter = (int)$oCmts->getCommentsCount();
  403. return $this->_oTemplate->parseHtmlByName('bx_a.html', array(
  404. 'href' => 'javascript:void(0)',
  405. 'title' => _t('_bx_timeline_menu_item_title_item_comment'),
  406. 'bx_repeat:attrs' => array(
  407. array('key' => 'onclick', 'value' => "javascript:" . $this->_oConfig->getJsObject('view') . ".commentItem(this, '" . $sSystem . "', " . $iObjectId . ")")
  408. ),
  409. 'content' => $iCounter > 0 ? $iCounter : ''
  410. ));
  411. }
  412. public function serviceGetSettingsCheckerHelper()
  413. {
  414. bx_import('FormCheckerHelper', $this->_aModule);
  415. return 'BxTimelineFormCheckerHelper';
  416. }
  417. /*
  418. * COMMON METHODS
  419. */
  420. public function getBlockPost($iProfileId)
  421. {
  422. if(!$iProfileId)
  423. return array();
  424. $this->_iOwnerId = $iProfileId;
  425. if($this->isAllowedPost() !== true)
  426. return array();
  427. $sContent = $this->_oTemplate->getPostBlock($this->_iOwnerId);
  428. return array('content' => $sContent);
  429. }
  430. public function getBlockView($iProfileId, $iStart = -1, $iPerPage = -1, $sFilter = '', $aModules = array(), $iTimeline = -1)
  431. {
  432. if(!$iProfileId)
  433. return array();
  434. $sJsObject = $this->_oConfig->getJsObject('view');
  435. $aParams = $this->_prepareParams(BX_BASE_MOD_NTFS_TYPE_OWNER, $iProfileId, $iStart, $iPerPage, $sFilter, $aModules, $iTimeline);
  436. $aParams['per_page'] = (int)$iPerPage > 0 ? $iPerPage : $this->_oConfig->getPerPage('profile');
  437. $this->_iOwnerId = $aParams['owner_id'];
  438. list($sUserName, $sUserUrl) = $this->getUserInfo($aParams['owner_id']);
  439. $aMenu = array(
  440. array('id' => 'timeline-view-all', 'name' => 'timeline-view-all', 'class' => '', 'link' => 'javascript:void(0)', 'onclick' => 'javascript:' . $sJsObject . '.changeFilter(this)', 'target' => '_self', 'title' => _t('_bx_timeline_menu_item_view_all'), 'active' => 1),
  441. array('id' => 'timeline-view-owner', 'name' => 'timeline-view-owner', 'class' => '', 'link' => 'javascript:void(0)', 'onclick' => 'javascript:' . $sJsObject . '.changeFilter(this)', 'target' => '_self', 'title' => _t('_bx_timeline_menu_item_view_owner', $sUserName)),
  442. array('id' => 'timeline-view-other', 'name' => 'timeline-view-other', 'class' => '', 'link' => 'javascript:void(0)', 'onclick' => 'javascript:' . $sJsObject . '.changeFilter(this)', 'target' => '_self', 'title' => _t('_bx_timeline_menu_item_view_other')),
  443. array('id' => 'timeline-get-rss', 'name' => 'timeline-get-rss', 'class' => '', 'link' => BX_DOL_URL_ROOT . $this->_oConfig->getBaseUri() . 'rss/' . $iProfileId . '/', 'target' => '_blank', 'title' => _t('_bx_timeline_menu_item_get_rss')),
  444. );
  445. $oMenu = new BxTemplMenuInteractive(array('template' => 'menu_interactive_vertical.html', 'menu_id'=> 'timeline-view-all', 'menu_items' => $aMenu));
  446. $oMenu->setSelected('', 'timeline-view-all');
  447. $sContent = $this->_oTemplate->getViewBlock($aParams);
  448. return array('content' => $sContent, 'menu' => $oMenu);
  449. }
  450. public function deleteEvent($aEvent)
  451. {
  452. if(empty($aEvent) || !is_array($aEvent) || !$this->_oDb->deleteEvent(array('id' => (int)$aEvent['id'])))
  453. return false;
  454. $this->onDelete($aEvent);
  455. return true;
  456. }
  457. public function getFormAttachLink()
  458. {
  459. $iUserId = $this->getUserId();
  460. $oForm = BxDolForm::getObjectInstance($this->_oConfig->getObject('form_attach_link'), $this->_oConfig->getObject('form_display_attach_link_add'), $this->_oTemplate);
  461. $oForm->aFormAttrs['action'] = BX_DOL_URL_ROOT . $this->_oConfig->getBaseUri() . 'add_attach_link/';
  462. $oForm->aInputs['url']['checker']['params']['preg'] = $this->_oConfig->getPregPattern('url');
  463. $oForm->initChecker();
  464. if($oForm->isSubmittedAndValid()) {
  465. $sLink = $oForm->getCleanValue('url');
  466. $aMatches = array();
  467. preg_match($this->_oConfig->getPregPattern('url'), $sLink, $aMatches);
  468. $sLink = (empty($aMatches[2]) ? 'http://' : '') . $aMatches[0];
  469. $aSiteInfo = bx_get_site_info($sLink, array(
  470. 'thumbnailUrl' => array('tag' => 'link', 'content_attr' => 'href'),
  471. 'OGImage' => array('name_attr' => 'property', 'name' => 'og:image'),
  472. ));
  473. $sTitle = !empty($aSiteInfo['title']) ? $aSiteInfo['title'] : _t('_Empty');
  474. $sDescription = !empty($aSiteInfo['description']) ? $aSiteInfo['description'] : _t('_Empty');
  475. $sMediaUrl = '';
  476. if(!empty($aSiteInfo['thumbnailUrl']))
  477. $sMediaUrl = $aSiteInfo['thumbnailUrl'];
  478. else if(!empty($aSiteInfo['OGImage']))
  479. $sMediaUrl = $aSiteInfo['OGImage'];
  480. $iMediaId = 0;
  481. $oStorage = null;
  482. if(!empty($sMediaUrl)) {
  483. $oStorage = BxDolStorage::getObjectInstance($this->_oConfig->getObject('storage_' . BX_TIMELINE_MEDIA_PHOTO . 's'));
  484. $iMediaId = $oStorage->storeFileFromUrl($sMediaUrl, true, $iUserId);
  485. }
  486. $iId = (int)$oForm->insert(array('profile_id' => $iUserId, 'media_id' => $iMediaId, 'url' => $sLink, 'title' => $sTitle, 'text' => $sDescription, 'added' => time()));
  487. if(!empty($iId)) {
  488. if(!empty($oStorage) && !empty($iMediaId))
  489. $oStorage->afterUploadCleanup($iMediaId, $iUserId);
  490. return array('item' => $this->_oTemplate->getAttachLinkItem($iUserId, $iId));
  491. }
  492. return array('msg' => _t('_bx_timeline_txt_err_cannot_perform_action'));
  493. }
  494. return array('form' => $oForm->getCode(), 'form_id' => $oForm->id);
  495. }
  496. public function getFormPost()
  497. {
  498. $iUserId = $this->getUserId();
  499. $oForm = BxDolForm::getObjectInstance($this->_oConfig->getObject('form_post'), $this->_oConfig->getObject('form_display_post_add'), $this->_oTemplate);
  500. $oForm->initChecker();
  501. if($oForm->isSubmittedAndValid()) {
  502. list($sUserName) = $this->getUserInfo($iUserId);
  503. $sType = $oForm->getCleanValue('type');
  504. $sType = $this->_oConfig->getPrefix('common_post') . $sType;
  505. BxDolForm::setSubmittedValue('type', $sType, $oForm->aFormAttrs['method']);
  506. $aContent = array();
  507. //--- Process Text ---//
  508. $sText = $oForm->getCleanValue('text');
  509. unset($oForm->aInputs['text']);
  510. $aContent['text'] = $this->_prepareTextForSave($sText);
  511. //--- Process Link ---//
  512. $aLinkIds = $oForm->getCleanValue('link');
  513. //--- Process Media ---//
  514. $aPhotoIds = $oForm->getCleanValue(BX_TIMELINE_MEDIA_PHOTO);
  515. $aVideoIds = $oForm->getCleanValue(BX_TIMELINE_MEDIA_VIDEO);
  516. $sTitle = _t('_bx_timeline_txt_user_added_sample', $sUserName, _t('_bx_timeline_txt_sample'));
  517. $sDescription = !empty($aContent['text']) ? $aContent['text'] : '';
  518. $iId = $oForm->insert(array(
  519. 'object_id' => $iUserId,
  520. 'object_privacy_view' => $this->_oConfig->getPrivacyViewDefault(),
  521. 'content' => serialize($aContent),
  522. 'title' => $sTitle,
  523. 'description' => $sDescription,
  524. 'date' => time()
  525. ));
  526. if(!empty($iId)) {
  527. $oMetatags = BxDolMetatags::getObjectInstance($this->_oConfig->getObject('metatags'));
  528. $oMetatags->keywordsAdd($iId, $aContent['text']);
  529. $oMetatags->locationsAddFromForm($iId, $this->_oConfig->CNF['FIELD_LOCATION_PREFIX']);
  530. //--- Process Link ---//
  531. if(!empty($aLinkIds) && is_array($aLinkIds))
  532. foreach($aLinkIds as $iLinkId)
  533. $this->_oDb->saveLink($iId, $iLinkId);
  534. //--- Process Media ---//
  535. $this->_saveMedia(BX_TIMELINE_MEDIA_PHOTO, $iId, $aPhotoIds);
  536. $this->_saveMedia(BX_TIMELINE_MEDIA_VIDEO, $iId, $aVideoIds);
  537. $this->onPost($iId);
  538. return array('id' => $iId);
  539. }
  540. return array('msg' => _t('_bx_timeline_txt_err_cannot_perform_action'));
  541. }
  542. return array('form' => $oForm->getCode(), 'form_id' => $oForm->id);
  543. }
  544. public function getCmtsObject($sSystem, $iId)
  545. {
  546. if(empty($sSystem) || (int)$iId == 0)
  547. return false;
  548. $oCmts = BxDolCmts::getObjectInstance($sSystem, $iId, true, $this->_oTemplate);
  549. if(!$oCmts->isEnabled())
  550. return false;
  551. return $oCmts;
  552. }
  553. public function getVoteObject($sSystem, $iId)
  554. {
  555. if(empty($sSystem) || (int)$iId == 0)
  556. return false;
  557. $oVote = BxDolVote::getObjectInstance($sSystem, $iId, true, $this->_oTemplate);
  558. if(!$oVote->isEnabled())
  559. return false;
  560. return $oVote;
  561. }
  562. public function getReportObject($sSystem, $iId)
  563. {
  564. if(empty($sSystem) || (int)$iId == 0)
  565. return false;
  566. $oReport = BxDolReport::getObjectInstance($sSystem, $iId, true, $this->_oTemplate);
  567. if(!$oReport->isEnabled())
  568. return false;
  569. return $oReport;
  570. }
  571. public function getAttachmentsMenuObject()
  572. {
  573. $oMenu = BxDolMenu::getObjectInstance($this->_oConfig->getObject('menu_post_attachments'), $this->_oTemplate);
  574. $oMenu->addMarkers(array(
  575. 'js_object' => $this->_oConfig->getJsObject('post'),
  576. ));
  577. return $oMenu;
  578. }
  579. public function getManageMenuObject()
  580. {
  581. return BxDolMenu::getObjectInstance($this->_oConfig->getObject('menu_item_manage'), $this->_oTemplate);
  582. }
  583. //--- Check permissions methods ---//
  584. public function isAllowedPost($bPerform = false)
  585. {
  586. if(isAdmin())
  587. return true;
  588. $iUserId = $this->getUserId();
  589. if($this->_iOwnerId == $this->getUserId())
  590. return true;
  591. $aCheckResult = checkActionModule($iUserId, 'post', $this->getName(), $bPerform);
  592. return $aCheckResult[CHECK_ACTION_RESULT] != CHECK_ACTION_RESULT_ALLOWED ? $aCheckResult[CHECK_ACTION_MESSAGE] : true;
  593. }
  594. public function isAllowedDelete($aEvent, $bPerform = false)
  595. {
  596. if(isAdmin())
  597. return true;
  598. $iUserId = (int)$this->getUserId();
  599. if((int)$aEvent['owner_id'] == $iUserId && $this->_oConfig->isAllowDelete())
  600. return true;
  601. $aCheckResult = checkActionModule($iUserId, 'delete', $this->getName(), $bPerform);
  602. return $aCheckResult[CHECK_ACTION_RESULT] != CHECK_ACTION_RESULT_ALLOWED ? $aCheckResult[CHECK_ACTION_MESSAGE] : true;
  603. }
  604. public function isAllowedComment($aEvent, $bPerform = false)
  605. {
  606. $mixedComments = $this->getCommentsData($aEvent['comments']);
  607. if($mixedComments === false)
  608. return false;
  609. list($sSystem, $iObjectId) = $mixedComments;
  610. $oCmts = $this->getCmtsObject($sSystem, $iObjectId);
  611. $oCmts->addCssJs();
  612. if(isAdmin())
  613. return true;
  614. return true;
  615. }
  616. public function isAllowedVote($aEvent, $bPerform = false)
  617. {
  618. $mixedVotes = $this->getVotesData($aEvent['votes']);
  619. if($mixedVotes === false)
  620. return false;
  621. list($sSystem, $iObjectId) = $mixedVotes;
  622. $oVote = $this->getVoteObject($sSystem, $iObjectId);
  623. $oVote->addCssJs();
  624. if(isAdmin())
  625. return true;
  626. return true;
  627. }
  628. public function isAllowedReport($aEvent, $bPerform = false)
  629. {
  630. $mixedReports = $this->getReportsData($aEvent['reports']);
  631. if($mixedReports === false)
  632. return false;
  633. list($sSystem, $iObjectId) = $mixedReports;
  634. $oReport = $this->getReportObject($sSystem, $iObjectId);
  635. $oReport->addCssJs();
  636. if(isAdmin())
  637. return true;
  638. return true;
  639. }
  640. public function isAllowedShare($aEvent, $bPerform = false)
  641. {
  642. if(isAdmin())
  643. return true;
  644. $iUserId = (int)$this->getUserId();
  645. if($iUserId == 0)
  646. return false;
  647. $aCheckResult = checkActionModule($iUserId, 'share', $this->getName(), $bPerform);
  648. return $aCheckResult[CHECK_ACTION_RESULT] != CHECK_ACTION_RESULT_ALLOWED ? $aCheckResult[CHECK_ACTION_MESSAGE] : true;
  649. }
  650. public function isAllowedMore($aEvent, $bPerform = false)
  651. {
  652. $oMoreMenu = $this->getManageMenuObject();
  653. $oMoreMenu->setEventId($aEvent['id']);
  654. return $oMoreMenu->isVisible();
  655. }
  656. public function onPost($iId)
  657. {
  658. $aEvent = $this->_oDb->getEvents(array('browse' => 'id', 'value' => $iId));
  659. if($this->_oConfig->isSystem($aEvent['type'], $aEvent['action'])) {
  660. $sPostType = 'system';
  661. $iSenderId = $aEvent['owner_id'];
  662. } else {
  663. $sPostType = 'common';
  664. $iSenderId = $aEvent['object_id'];
  665. }
  666. //--- Event -> Post for Alerts Engine ---//
  667. $oAlert = new BxDolAlerts($this->_oConfig->getObject('alert'), 'post_' . $sPostType, $iId, $iSenderId, array(
  668. 'object_author_id' => $aEvent['owner_id']
  669. ));
  670. $oAlert->alert();
  671. //--- Event -> Post for Alerts Engine ---//
  672. }
  673. public function onShare($iId, $aShared = array())
  674. {
  675. $aEvent = $this->_oDb->getEvents(array('browse' => 'id', 'value' => $iId));
  676. if(empty($aShared)) {
  677. $aContent = unserialize($aEvent['content']);
  678. $aShared = $this->_oDb->getShared($aContent['type'], $aContent['action'], $aContent['object_id']);
  679. if(empty($aShared) || !is_array($aShared))
  680. return;
  681. }
  682. $iUserId = $this->getUserId();
  683. $this->_oDb->insertShareTrack($aEvent['id'], $iUserId, $this->getUserIp(), $aShared['id']);
  684. $this->_oDb->updateShareCounter($aShared['id'], $aShared['shares']);
  685. //--- Timeline -> Update for Alerts Engine ---//
  686. $oAlert = new BxDolAlerts($this->_oConfig->getObject('alert'), 'share', $aShared['id'], $iUserId);
  687. $oAlert->alert();
  688. //--- Timeline -> Update for Alerts Engine ---//
  689. }
  690. public function onDelete($aEvent)
  691. {
  692. $sCommonPostPrefix = $this->_oConfig->getPrefix('common_post');
  693. //--- Delete attached photos, videos and links when common event was deleted.
  694. if($aEvent['type'] == $sCommonPostPrefix . BX_TIMELINE_PARSE_TYPE_POST) {
  695. $this->_deleteMedia(BX_TIMELINE_MEDIA_PHOTO, $aEvent['id']);
  696. $this->_deleteMedia(BX_TIMELINE_MEDIA_VIDEO, $aEvent['id']);
  697. $this->_deleteLinks($aEvent['id']);
  698. }
  699. //--- Update parent event when share event was deleted.
  700. if($aEvent['type'] == $sCommonPostPrefix . BX_TIMELINE_PARSE_TYPE_SHARE) {
  701. $this->_oDb->deleteShareTrack($aEvent['id']);
  702. $aContent = unserialize($aEvent['content']);
  703. $aShared = $this->_oDb->getShared($aContent['type'], $aContent['action'], $aContent['object_id']);
  704. if(!empty($aShared) && is_array($aShared))
  705. $this->_oDb->updateShareCounter($aShared['id'], $aShared['shares'], -1);
  706. }
  707. //--- Find and delete share events when parent event was deleted.
  708. $bSystem = $this->_oConfig->isSystem($aEvent['type'], $aEvent['action']);
  709. $aShareEvents = $this->_oDb->getEvents(array('browse' => 'shared_by_descriptor', 'type' => $aEvent['type']));
  710. foreach($aShareEvents as $aShareEvent) {
  711. $aContent = unserialize($aShareEvent['content']);
  712. 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'])))
  713. $this->_oDb->deleteEvent(array('id' => (int)$aShareEvent['id']));
  714. }
  715. //--- Delete associated meta.
  716. $oMetatags = BxDolMetatags::getObjectInstance($this->_oConfig->getObject('metatags'));
  717. $oMetatags->onDeleteContent($aEvent['id']);
  718. //--- Event -> Delete for Alerts Engine ---//
  719. $oAlert = new BxDolAlerts($this->_oConfig->getObject('alert'), 'delete', $aEvent['id'], $this->getUserId());
  720. $oAlert->alert();
  721. //--- Event -> Delete for Alerts Engine ---//
  722. }
  723. public function getVotesData(&$aVotes)
  724. {
  725. if(empty($aVotes) || !is_array($aVotes))
  726. return false;
  727. $sSystem = isset($aVotes['system']) ? $aVotes['system'] : '';
  728. $iObjectId = isset($aVotes['object_id']) ? (int)$aVotes['object_id'] : 0;
  729. $iCount = isset($aVotes['count']) ? (int)$aVotes['count'] : 0;
  730. if($sSystem == '' || $iObjectId == 0)
  731. return false;
  732. return array($sSystem, $iObjectId, $iCount);
  733. }
  734. public function getReportsData(&$aReports)
  735. {
  736. if(empty($aReports) || !is_array($aReports))
  737. return false;
  738. $sSystem = isset($aReports['system']) ? $aReports['system'] : '';
  739. $iObjectId = isset($aReports['object_id']) ? (int)$aReports['object_id'] : 0;
  740. $iCount = isset($aReports['count']) ? (int)$aReports['count'] : 0;
  741. if($sSystem == '' || $iObjectId == 0)
  742. return false;
  743. return array($sSystem, $iObjectId, $iCount);
  744. }
  745. public function getCommentsData(&$aComments)
  746. {
  747. if(empty($aComments) || !is_array($aComments))
  748. return false;
  749. $sSystem = isset($aComments['system']) ? $aComments['system'] : '';
  750. $iObjectId = isset($aComments['object_id']) ? (int)$aComments['object_id'] : 0;
  751. $iCount = isset($aComments['count']) ? (int)$aComments['count'] : 0;
  752. if($sSystem == '' || $iObjectId == 0 || ($iCount == 0 && !isLogged()))
  753. return false;
  754. return array($sSystem, $iObjectId, $iCount);
  755. }
  756. protected function _deleteLinks($iId)
  757. {
  758. $aLinks = $this->_oDb->getLinks($iId);
  759. if(empty($aLinks) || !is_array($aLinks))
  760. return;
  761. $oStorage = BxDolStorage::getObjectInstance($this->_oConfig->getObject('storage_photos'));
  762. foreach($aLinks as $aLink)
  763. if(!empty($aLink['media_id']))
  764. $oStorage->deleteFile($aLink['media_id']);
  765. $this->_oDb->deleteLinks($iId);
  766. }
  767. protected function _saveMedia($sType, $iId, $aItemIds)
  768. {
  769. if(empty($aItemIds) || !is_array($aItemIds))
  770. return;
  771. $iUserId = $this->getUserId();
  772. $oStorage = BxDolStorage::getObjectInstance($this->_oConfig->getObject('storage_' . strtolower($sType) . 's'));
  773. foreach($aItemIds as $iItemId)
  774. if($this->_oDb->saveMedia($sType, $iId, $iItemId))
  775. $oStorage->afterUploadCleanup($iItemId, $iUserId);
  776. }
  777. protected function _deleteMedia($sType, $iId)
  778. {
  779. $aItems = $this->_oDb->getMedia($sType, $iId);
  780. if(empty($aItems) || !is_array($aItems))
  781. return;
  782. $oStorage = BxDolStorage::getObjectInstance($this->_oConfig->getObject('storage_' . strtolower($sType) . 's'));
  783. foreach($aItems as $iItemId)
  784. $oStorage->deleteFile($iItemId);
  785. $this->_oDb->deleteMedia($sType, $iId);
  786. }
  787. protected function _prepareParams($sType, $iOwnerId, $iStart, $iPerPage, $sFilter, $aModules, $iTimeline)
  788. {
  789. $aParams = array();
  790. $aParams['browse'] = 'list';
  791. $aParams['type'] = !empty($sType) ? $sType : BX_TIMELINE_TYPE_DEFAULT;
  792. $aParams['owner_id'] = (int)$iOwnerId != 0 ? $iOwnerId : $this->getUserId();
  793. $aParams['start'] = (int)$iStart > 0 ? $iStart : 0;
  794. $aParams['per_page'] = (int)$iPerPage > 0 ? $iPerPage : $this->_oConfig->getPerPage();
  795. $aParams['filter'] = !empty($sFilter) ? $sFilter : BX_TIMELINE_FILTER_ALL;
  796. $aParams['modules'] = is_array($aModules) && !empty($aModules) ? $aModules : array();
  797. $aParams['timeline'] = (int)$iTimeline > 0 ? $iTimeline : 0;
  798. $aParams['active'] = 1;
  799. $aParams['hidden'] = 0;
  800. return $aParams;
  801. }
  802. protected function _prepareParamsGet()
  803. {
  804. $aParams = array();
  805. $aParams['browse'] = 'list';
  806. $aParams['dynamic_mode'] = true;
  807. $sType = bx_get('type');
  808. $aParams['type'] = $sType !== false ? bx_process_input($sType, BX_DATA_TEXT) : BX_TIMELINE_TYPE_DEFAULT;
  809. $aParams['owner_id'] = $sType !== false ? bx_process_input(bx_get('owner_id'), BX_DATA_INT) : $this->getUserId();
  810. $iStart = bx_get('start');
  811. $aParams['start'] = $iStart !== false ? bx_process_input($iStart, BX_DATA_INT) : 0;
  812. $iPerPage = bx_get('per_page');
  813. $aParams['per_page'] = $iPerPage !== false ? bx_process_input($iPerPage, BX_DATA_INT) : $this->_oConfig->getPerPage();
  814. $sFilter = bx_get('filter');
  815. $aParams['filter'] = $sFilter !== false ? bx_process_input($sFilter, BX_DATA_TEXT) : BX_TIMELINE_FILTER_ALL;
  816. $aModules = bx_get('modules');
  817. $aParams['modules'] = $aModules !== false ? bx_process_input($aModules, BX_DATA_TEXT) : array();
  818. $iTimeline = bx_get('timeline');
  819. $aParams['timeline'] = $iTimeline !== false ? bx_process_input($iTimeline, BX_DATA_INT) : 0;
  820. $aParams['active'] = 1;
  821. $aParams['hidden'] = 0;
  822. return $aParams;
  823. }
  824. protected function _prepareTextForSave($s)
  825. {
  826. return bx_process_input($s, BX_DATA_TEXT_MULTILINE);
  827. }
  828. }
  829. /** @} */