BxTimelineModule.php 28 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847
  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 DolphinModules
  8. *
  9. * @{
  10. */
  11. bx_import('BxDolAcl');
  12. bx_import('BxDolModule');
  13. require_once( BX_DIRECTORY_PATH_PLUGINS . 'Services_JSON.php' );
  14. define('BX_TIMELINE_TYPE_OWNER', 'owner');
  15. define('BX_TIMELINE_TYPE_CONNECTIONS', 'connections');
  16. define('BX_TIMELINE_HANDLER_TYPE_INSERT', 'insert');
  17. define('BX_TIMELINE_HANDLER_TYPE_UPDATE', 'update');
  18. define('BX_TIMELINE_HANDLER_TYPE_DELETE', 'delete');
  19. define('BX_TIMELINE_FILTER_ALL', 'all');
  20. define('BX_TIMELINE_FILTER_OWNER', 'owner');
  21. define('BX_TIMELINE_FILTER_OTHER', 'other');
  22. define('BX_TIMELINE_PARSE_TYPE_TEXT', 'text');
  23. define('BX_TIMELINE_PARSE_TYPE_LINK', 'link');
  24. define('BX_TIMELINE_PARSE_TYPE_PHOTO', 'photo');
  25. define('BX_TIMELINE_PARSE_TYPE_SHARE', 'share');
  26. define('BX_TIMELINE_PARSE_TYPE_DEFAULT', BX_TIMELINE_PARSE_TYPE_TEXT);
  27. class BxTimelineModule extends BxDolModule
  28. {
  29. var $_iOwnerId;
  30. var $_sJsPostObject;
  31. var $_sJsViewObject;
  32. var $_aPostElements;
  33. var $_sJsOutlineObject;
  34. var $_sDividerTemplate;
  35. var $_sBalloonTemplate;
  36. var $_sCmtPostTemplate;
  37. var $_sCmtViewTemplate;
  38. var $_sCmtTemplate;
  39. /**
  40. * Constructor
  41. */
  42. function __construct($aModule)
  43. {
  44. parent::BxDolModule($aModule);
  45. $this->_oConfig->init($this->_oDb);
  46. $this->_oTemplate->init();
  47. $this->_iOwnerId = 0;
  48. }
  49. /**
  50. * ACTION METHODS
  51. */
  52. public function actionPost()
  53. {
  54. $sType = bx_process_input($_POST['type']);
  55. $sMethod = 'getForm' . ucfirst($sType);
  56. if(!method_exists($this, $sMethod)) {
  57. $this->_echoResultJson(array());
  58. return;
  59. }
  60. $this->_iOwnerId = bx_process_input(bx_get('owner_id'), BX_DATA_INT);
  61. if (!$this->isAllowedPost(true)) {
  62. $this->_echoResultJson(array('msg' => bx_js_string(_t('_bx_timeline_txt_msg_not_allowed_post'))));
  63. return;
  64. }
  65. $aResult = $this->$sMethod();
  66. $this->_echoResultJson($aResult);
  67. }
  68. function actionDelete()
  69. {
  70. $this->_iOwnerId = bx_process_input(bx_get('owner_id'), BX_DATA_INT);
  71. if(!$this->isAllowedDelete(true)) {
  72. $this->_echoResultJson(array('code' => 1));
  73. return;
  74. }
  75. $iId = bx_process_input(bx_get('id'), BX_DATA_INT);
  76. $aEvent = $this->_oDb->getEvents(array('browse' => 'id', 'value' => $iId));
  77. if(!$this->_oDb->deleteEvent(array('id' => $iId))) {
  78. $this->_echoResultJson(array('code' => 2));
  79. return;
  80. }
  81. $this->onDelete($aEvent);
  82. $this->_echoResultJson(array('code' => 0, 'id' => $iId));
  83. }
  84. public function actionShare()
  85. {
  86. $iOwnerId = bx_process_input(bx_get('owner_id'), BX_DATA_INT);
  87. $aContent = array(
  88. 'type' => bx_process_input(bx_get('type'), BX_DATA_TEXT),
  89. 'action' => bx_process_input(bx_get('action'), BX_DATA_TEXT),
  90. 'object_id' => bx_process_input(bx_get('object_id'), BX_DATA_INT),
  91. );
  92. $iId = $this->_oDb->insertEvent(array(
  93. 'owner_id' => $iOwnerId,
  94. 'type' => $this->_oConfig->getPrefix('common_post') . 'share',
  95. 'action' => '',
  96. 'object_id' => $this->getUserId(),
  97. 'object_privacy_view' => $this->_oConfig->getPrivacyViewDefault(),
  98. 'content' => serialize($aContent),
  99. 'title' => '',
  100. 'description' => ''
  101. ));
  102. if(!empty($iId)) {
  103. $this->onShare($iId);
  104. $this->_echoResultJson(array('msg' => _t('_bx_timeline_txt_msg_success_share')));
  105. return;
  106. }
  107. $this->_echoResultJson(array('msg' => _t('_bx_timeline_txt_err_cannot_share')));
  108. }
  109. function actionGetPost()
  110. {
  111. $this->_oConfig->setJsMode(true);
  112. $this->_iOwnerId = bx_process_input(bx_get('owner_id'), BX_DATA_INT);
  113. $iEvent = bx_process_input(bx_get('id'), BX_DATA_INT);
  114. $aEvent = $this->_oDb->getEvents(array('browse' => 'id', 'value' => $iEvent));
  115. $this->_echoResultJson(array('item' => $this->_oTemplate->getPost($aEvent, array('type' => 'owner', 'owner_id' => $this->_iOwnerId))));
  116. }
  117. function actionGetPosts()
  118. {
  119. $this->_oConfig->setJsMode(true);
  120. $aParams = $this->_prepareParamsGet();
  121. list($sItems, $sLoadMore, $sBack) = $this->_oTemplate->getPosts($aParams);
  122. $this->_echoResultJson(array('items' => $sItems, 'load_more' => $sLoadMore, 'back' => $sBack));
  123. }
  124. public function actionGetPostForm($sType)
  125. {
  126. $this->_iOwnerId = bx_process_input(bx_get('owner_id'), BX_DATA_INT);
  127. $sMethod = 'getForm' . ucfirst($sType);
  128. if(!method_exists($this, $sMethod)) {
  129. $this->_echoResultJson(array());
  130. return;
  131. }
  132. $aResult = $this->$sMethod();
  133. $this->_echoResultJson($aResult);
  134. }
  135. public function actionGetComments()
  136. {
  137. $this->_iOwnerId = bx_process_input(bx_get('owner_id'), BX_DATA_INT);
  138. $sSystem = bx_process_input(bx_get('system'), BX_DATA_TEXT);
  139. $iId = bx_process_input(bx_get('id'), BX_DATA_INT);
  140. $sComments = $this->_oTemplate->getComments($sSystem, $iId);
  141. $this->_echoResultJson(array('content' => $sComments));
  142. }
  143. public function actionGetPostPopup()
  144. {
  145. $iItemId = bx_process_input(bx_get('id'), BX_DATA_INT);
  146. if(!$iItemId) {
  147. $this->_echoResultJson(array());
  148. return;
  149. }
  150. $this->_echoResultJson(array(
  151. 'popup' => $this->_oTemplate->getViewItemPopup($iItemId)
  152. ));
  153. }
  154. function actionRss($iOwnerId)
  155. {
  156. list($sUserName) = $this->getUserInfo($iOwnerId);
  157. $sRssCaption = _t('_bx_timeline_txt_rss_caption', $sUserName);
  158. $sRssLink = $this->_oConfig->getViewUrl($iOwnerId);
  159. $aParams = $this->_prepareParams('owner', $iOwnerId, 0, $this->_oConfig->getRssLength(), '', array(), 0);
  160. $aEvents = $this->_oDb->getEvents($aParams);
  161. $aRssData = array();
  162. foreach($aEvents as $aEvent) {
  163. if(empty($aEvent['title'])) continue;
  164. $aRssData[$aEvent['id']] = array(
  165. 'UnitID' => $aEvent['id'],
  166. 'UnitTitle' => $aEvent['title'],
  167. 'UnitLink' => $this->_oConfig->getItemViewUrl($aEvent),
  168. 'UnitDesc' => $aEvent['description'],
  169. 'UnitDateTimeUTS' => $aEvent['date'],
  170. );
  171. }
  172. bx_import('BxDolRssFactory');
  173. $oRss = new BxDolRssFactory();
  174. header('Content-Type: text/html; charset=utf-8');
  175. echo $oRss->GenRssByData($aRssData, $sRssCaption, $sRssLink);
  176. }
  177. /**
  178. * SERVICE METHODS
  179. */
  180. public function serviceAddHandlers($sModuleUri = 'all')
  181. {
  182. $this->_updateHandlers($sModuleUri, true);
  183. }
  184. public function serviceDeleteHandlers($sModuleUri = 'all')
  185. {
  186. $this->_updateHandlers($sModuleUri, false);
  187. }
  188. function serviceGetActionsChecklist()
  189. {
  190. $aHandlers = $this->_oConfig->getHandlers();
  191. $aResults = array();
  192. foreach($aHandlers as $aHandler) {
  193. if($aHandler['type'] != BX_TIMELINE_HANDLER_TYPE_INSERT)
  194. continue;
  195. $aModule = $this->_oDb->getModuleByName($aHandler['module_name']);
  196. if(empty($aModule))
  197. $aModule['title'] = _t('_bx_timeline_alert_module_' . $aHandler['alert_unit']);
  198. $aResults[$aHandler['id']] = $aModule['title'] . ' (' . _t('_bx_timeline_alert_action_' . $aHandler['alert_action']) . ')';
  199. }
  200. asort($aResults);
  201. return $aResults;
  202. }
  203. public function serviceResponse($oAlert)
  204. {
  205. bx_import('Response', $this->_aModule);
  206. $oResponse = new BxTimelineResponse($this);
  207. $oResponse->response($oAlert);
  208. }
  209. public function serviceGetBlockPost($iProfileId = 0)
  210. {
  211. return $this->serviceGetBlockPostProfile($iProfileId);
  212. }
  213. public function serviceGetBlockPostProfile($iProfileId = 0)
  214. {
  215. if(!$iProfileId && bx_get('id') !== false) {
  216. $oProfile = BxDolProfile::getInstanceByContentAndType(bx_process_input(bx_get('id'), BX_DATA_INT), 'bx_persons');
  217. if(!empty($oProfile))
  218. $iProfileId = $oProfile->id();
  219. }
  220. if (!$iProfileId)
  221. return array();
  222. $this->_iOwnerId = $iProfileId;
  223. list($sUserName, $sUserUrl) = $this->getUserInfo($iProfileId);
  224. if($this->_iOwnerId != $this->getUserId() && !$this->isAllowedPost())
  225. return array();
  226. bx_import('BxDolMenu');
  227. $oMenu = BxDolMenu::getObjectInstance($this->_oConfig->getObject('menu_post'));
  228. $oMenu->setMenuId('timeline-post-menu');
  229. $oMenu->setSelected($this->getName(), 'post-text');
  230. $sContent = $this->_oTemplate->getPostBlock($this->_iOwnerId);
  231. return array('content' => $sContent, 'menu' => $oMenu);
  232. }
  233. public function serviceGetBlockView($iProfileId = 0)
  234. {
  235. $aBlock = $this->serviceGetBlockViewProfile($iProfileId);
  236. if(!empty($aBlock))
  237. return $aBlock;
  238. return array('content' => MsgBox(_t('_bx_timeline_txt_msg_no_results')));
  239. }
  240. public function serviceGetBlockViewProfile($iProfileId = 0, $iStart = -1, $iPerPage = -1, $sFilter = '', $aModules = array(), $iTimeline = -1)
  241. {
  242. if(!$iProfileId && bx_get('id') !== false) {
  243. $oProfile = BxDolProfile::getInstanceByContentAndType(bx_process_input(bx_get('id'), BX_DATA_INT), 'bx_persons');
  244. if(!empty($oProfile))
  245. $iProfileId = $oProfile->id();
  246. }
  247. if (!$iProfileId)
  248. return array();
  249. $sJsObject = $this->_oConfig->getJsObject('view');
  250. $aParams = $this->_prepareParams('owner', $iProfileId, $iStart, $iPerPage, $sFilter, $aModules, $iTimeline);
  251. $this->_iOwnerId = $aParams['owner_id'];
  252. list($sUserName, $sUserUrl) = $this->getUserInfo($aParams['owner_id']);
  253. $aMenu = array(
  254. 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),
  255. 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)),
  256. 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')),
  257. 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')),
  258. );
  259. bx_import('BxTemplMenuInteractive');
  260. $oMenu = new BxTemplMenuInteractive(array('template' => 'menu_interactive_vertical.html', 'menu_id'=> 'timeline-view-all', 'menu_items' => $aMenu));
  261. $oMenu->setSelected('', 'timeline-view-all');
  262. $sContent = $this->_oTemplate->getViewBlock($aParams);
  263. return array('content' => $sContent, 'menu' => $oMenu);
  264. }
  265. public function serviceGetBlockViewAccount($iProfileId = 0, $iStart = -1, $iPerPage = -1, $iTimeline = -1, $sFilter = '', $aModules = array())
  266. {
  267. $aParams = $this->_prepareParams('connections', $iProfileId, $iStart, $iPerPage, $sFilter, $aModules, $iTimeline);
  268. $this->_iOwnerId = $aParams['owner_id'];
  269. $sContent = $this->_oTemplate->getViewBlock($aParams);
  270. return array('content' => $sContent);
  271. }
  272. public function serviceGetBlockItem()
  273. {
  274. $iItemId = bx_process_input(bx_get('id'), BX_DATA_INT);
  275. if(!$iItemId)
  276. return array();
  277. return array('content' => $this->_oTemplate->getViewItemBlock($iItemId));
  278. }
  279. public function serviceGetShareOnclick($iOwnerId, $sType, $sAction, $iObjectId)
  280. {
  281. $sJsObject = $this->_oConfig->getJsObject('view');
  282. $sFormat = "%s.shareItem(this, %d, '%s', '%s', %d);";
  283. $iOwnerId = !empty($iOwnerId) ? (int)$iOwnerId : $this->getUserId(); //--- in whose timeline the content will be shared
  284. return sprintf($sFormat, $sJsObject, $iOwnerId, $sType, $sAction, (int)$iObjectId);
  285. }
  286. /*
  287. * COMMON METHODS
  288. */
  289. public function getFormText()
  290. {
  291. bx_import('BxDolForm');
  292. $oForm = BxDolForm::getObjectInstance('mod_tml_text', 'mod_tml_text_add');
  293. $oForm->aFormAttrs['action'] = BX_DOL_URL_ROOT . $this->_oConfig->getBaseUri() . 'post/';
  294. $oForm->aInputs['owner_id']['value'] = $this->_iOwnerId;
  295. $oForm->initChecker();
  296. if($oForm->isSubmittedAndValid()) {
  297. $iUserId = $this->getUserId();
  298. list($sUserName) = $this->getUserInfo($iUserId);
  299. $sType = $oForm->getCleanValue('type');
  300. $sType = $this->_oConfig->getPrefix('common_post') . $sType;
  301. BxDolForm::setSubmittedValue('type', $sType, $oForm->aFormAttrs['method']);
  302. $sContent = $sDescription = $oForm->getCleanValue('content');
  303. $sContent = serialize(array('text' => $sContent));
  304. BxDolForm::setSubmittedValue('content', $sContent, $oForm->aFormAttrs['method']);
  305. $iId = $oForm->insert(array(
  306. 'object_id' => $iUserId,
  307. 'object_privacy_view' => $this->_oConfig->getPrivacyViewDefault(),
  308. 'title' => bx_process_input($sUserName . ' ' . _t('_bx_timeline_txt_wrote')),
  309. 'description' => $sDescription,
  310. 'date' => time()
  311. ));
  312. if(!empty($iId)) {
  313. $this->onPost($iId);
  314. return array('id' => $iId);
  315. }
  316. return array('msg' => _t('_bx_timeline_txt_err_cannot_perform_action'));
  317. }
  318. return array('form' => $oForm->getCode(), 'form_id' => $oForm->id);
  319. }
  320. public function getFormLink()
  321. {
  322. bx_import('BxDolForm');
  323. $oForm = BxDolForm::getObjectInstance('mod_tml_link', 'mod_tml_link_add');
  324. $oForm->aFormAttrs['action'] = BX_DOL_URL_ROOT . $this->_oConfig->getBaseUri() . 'post/';
  325. $oForm->aInputs['owner_id']['value'] = $this->_iOwnerId;
  326. $oForm->initChecker();
  327. if($oForm->isSubmittedAndValid()) {
  328. $iUserId = $this->getUserId();
  329. list($sUserName) = $this->getUserInfo($iUserId);
  330. $sType = $oForm->getCleanValue('type');
  331. $sType = $this->_oConfig->getPrefix('common_post') . $sType;
  332. BxDolForm::setSubmittedValue('type', $sType, $oForm->aFormAttrs['method']);
  333. $sUrl = $oForm->getCleanValue('content');
  334. $sContent = bx_file_get_contents($sUrl);
  335. preg_match("/<title>(.*)<\/title>/", $sContent, $aMatch);
  336. $sTitle = $aMatch ? $aMatch[1] : '';
  337. preg_match("/<meta.*name[='\" ]+description['\"].*content[='\" ]+(.*)['\"].*><\/meta>/", $sContent, $aMatch);
  338. $sDescription = $aMatch ? $aMatch[1] : '';
  339. $sContent = serialize(array(
  340. 'url' => strpos($sUrl, 'http://') === false && strpos($sUrl, 'https://') === false ? 'http://' . $sUrl : $sUrl,
  341. 'title' => $sTitle,
  342. 'text' => $sDescription
  343. ));
  344. BxDolForm::setSubmittedValue('content', $sContent, $oForm->aFormAttrs['method']);
  345. $iId = $oForm->insert(array(
  346. 'object_id' => $iUserId,
  347. 'object_privacy_view' => $this->_oConfig->getPrivacyViewDefault(),
  348. 'title' => bx_process_input($sUserName . ' ' . _t('_bx_timeline_txt_shared_link')),
  349. 'description' => bx_process_input($sUrl . ' - ' . $sTitle),
  350. 'date' => time()
  351. ));
  352. if(!empty($iId)) {
  353. $this->onPost($iId);
  354. return array('id' => $iId);
  355. }
  356. return array('msg' => _t('_bx_timeline_txt_err_cannot_perform_action'));
  357. }
  358. return array('form' => $oForm->getCode(), 'form_id' => $oForm->id);
  359. }
  360. public function getFormPhoto()
  361. {
  362. $aFormNested = array(
  363. 'inputs' => array(
  364. 'file_title' => array(
  365. 'type' => 'text',
  366. 'name' => 'file_title[]',
  367. 'value' => '{file_title}',
  368. 'caption' => _t('_bx_timeline_form_photo_input_title'),
  369. 'required' => true,
  370. 'checker' => array(
  371. 'func' => 'length',
  372. 'params' => array(1, 150),
  373. 'error' => _t('_bx_timeline_form_photo_input_err_title')
  374. ),
  375. 'db' => array (
  376. 'pass' => 'Xss',
  377. ),
  378. ),
  379. 'file_text' => array(
  380. 'type' => 'textarea',
  381. 'name' => 'file_text[]',
  382. 'caption' => _t('_bx_timeline_form_photo_input_description'),
  383. 'required' => true,
  384. 'checker' => array(
  385. 'func' => 'length',
  386. 'params' => array(10, 5000),
  387. 'error' => _t('_bx_timeline_form_photo_input_err_description')
  388. ),
  389. 'db' => array (
  390. 'pass' => 'Xss',
  391. ),
  392. ),
  393. ),
  394. );
  395. bx_import('BxDolForm');
  396. $oForm = BxDolForm::getObjectInstance('mod_tml_photo', 'mod_tml_photo_add');
  397. $oForm->aFormAttrs['action'] = BX_DOL_URL_ROOT . $this->_oConfig->getBaseUri() . 'post/';
  398. $oForm->aInputs['owner_id']['value'] = $this->_iOwnerId;
  399. bx_import('BxDolFormNested');
  400. $oFormNested = new BxDolFormNested('content', $aFormNested, 'do_submit');
  401. $oForm->aInputs['content']['storage_object'] = $this->_oConfig->getObject('storage');
  402. $oForm->aInputs['content']['images_transcoder'] = $this->_oConfig->getObject('transcoder_preview');
  403. $oForm->aInputs['content']['uploaders'] = $this->_oConfig->getUploaders('image');
  404. $oForm->aInputs['content']['multiple'] = false;
  405. $oForm->aInputs['content']['ghost_template'] = $oFormNested;
  406. $oForm->initChecker();
  407. if($oForm->isSubmittedAndValid()) {
  408. $iUserId = $this->getUserId();
  409. list($sUserName) = $this->getUserInfo($iUserId);
  410. $sType = $oForm->getCleanValue('type');
  411. $sType = $this->_oConfig->getPrefix('common_post') . $sType;
  412. BxDolForm::setSubmittedValue('type', $sType, $oForm->aFormAttrs['method']);
  413. $aPhIds = $oForm->getCleanValue('content');
  414. BxDolForm::setSubmittedValue('content', serialize(array()), $oForm->aFormAttrs['method']);
  415. $iPhIds = count($aPhIds);
  416. $iId = $oForm->insert(array(
  417. 'object_id' => $iUserId,
  418. 'object_privacy_view' => $this->_oConfig->getPrivacyViewDefault(),
  419. 'title' => bx_process_input($sUserName . ' ' . _t('_bx_timeline_txt_added_photo' . ($iPhIds > 1 ? 's' : ''))),
  420. 'description' => '',
  421. 'date' => time()
  422. ));
  423. if(!empty($iId)) {
  424. if($iPhIds > 0) {
  425. $aPhTitles = $oForm->getCleanValue('file_title');
  426. $aPhTexts = $oForm->getCleanValue('file_text');
  427. bx_import('BxDolStorage');
  428. $oStorage = BxDolStorage::getObjectInstance($this->_oConfig->getObject('storage'));
  429. for($i = 0; $i < $iPhIds; $i++)
  430. if($this->_oDb->savePhoto($iId, $aPhIds[$i], $aPhTitles[$i], $aPhTexts[$i]))
  431. $oStorage->afterUploadCleanup($aPhIds[$i], $iUserId);
  432. }
  433. $this->onPost($iId);
  434. return array('id' => $iId);
  435. }
  436. return array('msg' => _t('_bx_timeline_txt_err_cannot_perform_action'));
  437. }
  438. return array('form' => $oForm->getCode(), 'form_id' => $oForm->id);
  439. }
  440. public function getCmtsObject($sSystem, $iId)
  441. {
  442. if(empty($sSystem) || (int)$iId == 0)
  443. return false;
  444. bx_import('BxDolCmts');
  445. $oCmts = BxDolCmts::getObjectInstance($sSystem, $iId);
  446. if(!$oCmts->isEnabled())
  447. return false;
  448. return $oCmts;
  449. }
  450. public function getVoteObject($sSystem, $iId)
  451. {
  452. if(empty($sSystem) || (int)$iId == 0)
  453. return false;
  454. bx_import('BxDolVote');
  455. $oVote = BxDolVote::getObjectInstance($sSystem, $iId);
  456. if(!$oVote->isEnabled())
  457. return false;
  458. return $oVote;
  459. }
  460. public function getUserId()
  461. {
  462. return isLogged() ? bx_get_logged_profile_id() : 0;
  463. }
  464. public function getUserInfo($iUserId = 0)
  465. {
  466. bx_import('BxDolProfile');
  467. $oProfile = BxDolProfile::getInstance($iUserId);
  468. if (!$oProfile) {
  469. bx_import('BxDolProfileUndefined');
  470. $oProfile = BxDolProfileUndefined::getInstance();
  471. }
  472. return array(
  473. $oProfile->getDisplayName(),
  474. $oProfile->getUrl(),
  475. $oProfile->getThumb(),
  476. $oProfile->getUnit()
  477. );
  478. }
  479. public function isAllowedPost($bPerform = false)
  480. {
  481. if(isAdmin())
  482. return true;
  483. $iUserId = $this->getUserId();
  484. if($iUserId == 0 && $this->_oConfig->isAllowGuestComments())
  485. return true;
  486. $aCheckResult = checkActionModule($iUserId, 'post', $this->getName(), $bPerform);
  487. return $aCheckResult[CHECK_ACTION_RESULT] == CHECK_ACTION_RESULT_ALLOWED;
  488. }
  489. public function isAllowedDelete($aEvent, $bPerform = false)
  490. {
  491. if(isAdmin())
  492. return true;
  493. $iUserId = (int)$this->getUserId();
  494. if((int)$aEvent['owner_id'] == $iUserId)
  495. return true;
  496. $aCheckResult = checkActionModule($iUserId, 'delete', $this->getName(), $bPerform);
  497. return $aCheckResult[CHECK_ACTION_RESULT] == CHECK_ACTION_RESULT_ALLOWED;
  498. }
  499. public function isAllowedComment($aEvent, $bPerform = false)
  500. {
  501. $mixedComments = $this->getCommentsData($aEvent['comments']);
  502. if($mixedComments === false)
  503. return false;
  504. list($sSystem, $iObjectId) = $mixedComments;
  505. $oCmts = $this->getCmtsObject($sSystem, $iObjectId);
  506. $oCmts->addCssJs();
  507. $iUserId = (int)$this->getUserId();
  508. if($iUserId == 0)
  509. return false;
  510. if(isAdmin())
  511. return true;
  512. return $oCmts->isPostReplyAllowed($bPerform);
  513. }
  514. public function isAllowedVote($aEvent, $bPerform = false)
  515. {
  516. $mixedVotes = $this->getVotesData($aEvent['votes']);
  517. if($mixedVotes === false)
  518. return false;
  519. list($sSystem, $iObjectId) = $mixedVotes;
  520. $oVote = $this->getVoteObject($sSystem, $iObjectId);
  521. $oVote->addCssJs();
  522. $iUserId = (int)$this->getUserId();
  523. if($iUserId == 0)
  524. return false;
  525. if(isAdmin())
  526. return true;
  527. return $oVote->isAllowedVote($bPerform);
  528. }
  529. public function isAllowedShare($aEvent, $bPerform = false)
  530. {
  531. $iUserId = (int)$this->getUserId();
  532. if($iUserId == 0)
  533. return false;
  534. if(isAdmin())
  535. return true;
  536. $aCheckResult = checkActionModule($iUserId, 'share', $this->getName(), $bPerform);
  537. return $aCheckResult[CHECK_ACTION_RESULT] == CHECK_ACTION_RESULT_ALLOWED;
  538. }
  539. public function onPost($iId)
  540. {
  541. $aEvent = $this->_oDb->getEvents(array('browse' => 'id', 'value' => $iId));
  542. if($this->_oConfig->isSystem($aEvent['type'], $aEvent['action'])) {
  543. $sPostType = 'system';
  544. $iSenderId = $aEvent['owner_id'];
  545. }
  546. else {
  547. $sPostType = 'common';
  548. $iSenderId = $aEvent['object_id'];
  549. }
  550. //--- Event -> Post for Alerts Engine ---//
  551. bx_import('BxDolAlerts');
  552. $oAlert = new BxDolAlerts($this->_oConfig->getSystemName('alert'), 'post_' . $sPostType, $iId, $iSenderId);
  553. $oAlert->alert();
  554. //--- Event -> Post for Alerts Engine ---//
  555. }
  556. public function onShare($iId)
  557. {
  558. $aEvent = $this->_oDb->getEvents(array('browse' => 'id', 'value' => $iId));
  559. $aContent = unserialize($aEvent['content']);
  560. $iSharedId = $this->_oDb->updateSharesCounter($aContent['type'], $aContent['action'], $aContent['object_id']);
  561. //--- Timeline -> Update for Alerts Engine ---//
  562. bx_import('BxDolAlerts');
  563. $oAlert = new BxDolAlerts($this->_oConfig->getSystemName('alert'), 'share', $iSharedId, $aEvent['object_id']);
  564. $oAlert->alert();
  565. //--- Timeline -> Update for Alerts Engine ---//
  566. }
  567. public function onDelete($aEvent)
  568. {
  569. $aPhotos = $this->_oDb->getPhotos($aEvent['id']);
  570. if(is_array($aPhotos) && !empty($aPhotos)) {
  571. bx_import('BxDolStorage');
  572. $oStorage = BxDolStorage::getObjectInstance($this->_oConfig->getObject('storage'));
  573. foreach($aPhotos as $aPhoto)
  574. $oStorage->deleteFile($aPhoto['id']);
  575. $this->_oDb->deletePhotos($aEvent['id']);
  576. }
  577. if($aEvent['type'] == $this->_oConfig->getPrefix('common_post') . BX_TIMELINE_PARSE_TYPE_SHARE) {
  578. $aContent = unserialize($aEvent['content']);
  579. $this->_oDb->updateSharesCounter($aContent['type'], $aContent['action'], $aContent['object_id'], -1);
  580. }
  581. //--- Event -> Delete for Alerts Engine ---//
  582. bx_import('BxDolAlerts');
  583. $oAlert = new BxDolAlerts($this->_oConfig->getSystemName('alert'), 'delete', $aEvent['id'], $this->getUserId());
  584. $oAlert->alert();
  585. //--- Event -> Delete for Alerts Engine ---//
  586. }
  587. public function getVotesData(&$aVotes)
  588. {
  589. if(empty($aVotes) || !is_array($aVotes))
  590. return false;
  591. $sSystem = isset($aVotes['system']) ? $aVotes['system'] : '';
  592. $iObjectId = isset($aVotes['object_id']) ? (int)$aVotes['object_id'] : 0;
  593. $iCount = isset($aVotes['count']) ? (int)$aVotes['count'] : 0;
  594. if($sSystem == '' || $iObjectId == 0)
  595. return false;
  596. return array($sSystem, $iObjectId, $iCount);
  597. }
  598. public function getCommentsData(&$aComments)
  599. {
  600. if(empty($aComments) || !is_array($aComments))
  601. return false;
  602. $sSystem = isset($aComments['system']) ? $aComments['system'] : '';
  603. $iObjectId = isset($aComments['object_id']) ? (int)$aComments['object_id'] : 0;
  604. $iCount = isset($aComments['count']) ? (int)$aComments['count'] : 0;
  605. if($sSystem == '' || $iObjectId == 0 || ($iCount == 0 && !isLogged()))
  606. return false;
  607. return array($sSystem, $iObjectId, $iCount);
  608. }
  609. protected function _prepareParams($sType, $iOwnerId, $iStart, $iPerPage, $sFilter, $aModules, $iTimeline)
  610. {
  611. $aParams = array();
  612. $aParams['browse'] = 'list';
  613. $aParams['type'] = !empty($sType) ? $sType : BX_TIMELINE_TYPE_OWNER;
  614. $aParams['owner_id'] = (int)$iOwnerId != 0 ? $iOwnerId : $this->getUserId();
  615. $aParams['start'] = (int)$iStart > 0 ? $iStart : 0;
  616. $aParams['per_page'] = (int)$iPerPage > 0 ? $iPerPage : $this->_oConfig->getPerPage();
  617. $aParams['filter'] = !empty($sFilter) ? $sFilter : BX_TIMELINE_FILTER_ALL;
  618. $aParams['modules'] = is_array($aModules) && !empty($aModules) ? $aModules : array();
  619. $aParams['timeline'] = (int)$iTimeline > 0 ? $iTimeline : 0;
  620. return $aParams;
  621. }
  622. protected function _prepareParamsGet()
  623. {
  624. $aParams = array();
  625. $aParams['browse'] = 'list';
  626. $sType = bx_get('type');
  627. $aParams['type'] = $sType !== false ? bx_process_input($sType, BX_DATA_TEXT) : BX_TIMELINE_TYPE_OWNER;
  628. $iOwnerId = bx_get('owner_id');
  629. $aParams['owner_id'] = $sType !== false ? bx_process_input(bx_get('owner_id'), BX_DATA_INT) : $this->getUserId();
  630. $iStart = bx_get('start');
  631. $aParams['start'] = $iStart !== false ? bx_process_input($iStart, BX_DATA_INT) : 0;
  632. $iPerPage = bx_get('per_page');
  633. $aParams['per_page'] = $iPerPage !== false ? bx_process_input($iPerPage, BX_DATA_INT) : $this->_oConfig->getPerPage();
  634. $sFilter = bx_get('filter');
  635. $aParams['filter'] = $sFilter !== false ? bx_process_input($sFilter, BX_DATA_TEXT) : BX_TIMELINE_FILTER_ALL;
  636. $aModules = bx_get('modules');
  637. $aParams['modules'] = $aModules !== false ? bx_process_input($aModules, BX_DATA_TEXT) : array();
  638. $iTimeline = bx_get('timeline');
  639. $aParams['timeline'] = $iTimeline !== false ? bx_process_input($iTimeline, BX_DATA_INT) : 0;
  640. return $aParams;
  641. }
  642. protected function _updateHandlers($sModuleUri = 'all', $bInstall = true)
  643. {
  644. $aModules = $sModuleUri == 'all' ? $this->_oDb->getModules() : array($this->_oDb->getModuleByUri($sModuleUri));
  645. foreach($aModules as $aModule) {
  646. if(!BxDolRequest::serviceExists($aModule, 'get_timeline_data'))
  647. continue;
  648. $aData = BxDolService::call($aModule['name'], 'get_timeline_data');
  649. if(empty($aData) || !is_array($aData))
  650. continue;
  651. if($bInstall)
  652. $this->_oDb->insertData($aData);
  653. else
  654. $this->_oDb->deleteData($aData);
  655. }
  656. BxDolAlerts::cache();
  657. }
  658. protected function _echoResultJson($a, $isAutoWrapForFormFileSubmit = false) {
  659. header('Content-type: text/html; charset=utf-8');
  660. require_once(BX_DIRECTORY_PATH_PLUGINS . 'Services_JSON.php');
  661. $oParser = new Services_JSON();
  662. $s = $oParser->encode($a);
  663. if ($isAutoWrapForFormFileSubmit && !empty($_FILES))
  664. $s = '<textarea>' . $s . '</textarea>'; // http://jquery.malsup.com/form/#file-upload
  665. echo $s;
  666. }
  667. }
  668. /** @} */