BxTimelineModule.php 35 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982
  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_HANDLER_TYPE_INSERT', 'insert');
  15. define('BX_TIMELINE_HANDLER_TYPE_UPDATE', 'update');
  16. define('BX_TIMELINE_HANDLER_TYPE_DELETE', 'delete');
  17. define('BX_TIMELINE_FILTER_ALL', 'all');
  18. define('BX_TIMELINE_FILTER_OWNER', 'owner');
  19. define('BX_TIMELINE_FILTER_OTHER', 'other');
  20. define('BX_TIMELINE_DIVIDER_ID', ',');
  21. define('BX_TIMELINE_PARSE_TYPE_TEXT', 'text');
  22. define('BX_TIMELINE_PARSE_TYPE_LINK', 'link');
  23. define('BX_TIMELINE_PARSE_TYPE_PHOTO', 'photo');
  24. define('BX_TIMELINE_PARSE_TYPE_DEFAULT', BX_TIMELINE_PARSE_TYPE_TEXT);
  25. class BxTimelineModule extends BxDolModule
  26. {
  27. var $_iOwnerId;
  28. var $_sJsPostObject;
  29. var $_sJsViewObject;
  30. var $_aPostElements;
  31. var $_sJsOutlineObject;
  32. var $_sDividerTemplate;
  33. var $_sBalloonTemplate;
  34. var $_sCmtPostTemplate;
  35. var $_sCmtViewTemplate;
  36. var $_sCmtTemplate;
  37. /**
  38. * Constructor
  39. */
  40. function __construct($aModule)
  41. {
  42. parent::BxDolModule($aModule);
  43. $this->_oConfig->init($this->_oDb);
  44. $this->_iOwnerId = 0;
  45. }
  46. /**
  47. * ACTION METHODS
  48. */
  49. public function actionPost()
  50. {
  51. $sType = bx_process_input($_POST['type']);
  52. $sMethod = 'getForm' . ucfirst($sType);
  53. if(!method_exists($this, $sMethod)) {
  54. $this->_echoResultJson(array());
  55. return;
  56. }
  57. $this->_iOwnerId = bx_process_input(bx_get('owner_id'), BX_DATA_INT);
  58. if (!$this->isAllowedPost(true)) {
  59. $this->_echoResultJson(array('msg' => bx_js_string(_t('_bx_timeline_txt_msg_not_allowed_post'))));
  60. return;
  61. }
  62. $aResult = $this->$sMethod();
  63. $this->_echoResultJson($aResult);
  64. }
  65. function actionDelete()
  66. {
  67. $this->_iOwnerId = bx_process_input(bx_get('owner_id'), BX_DATA_INT);
  68. if(!$this->isAllowedDelete(true)) {
  69. $this->_echoResultJson(array('code' => 1));
  70. return;
  71. }
  72. $iPostId = bx_process_input(bx_get('post_id'), BX_DATA_INT);
  73. if(!$this->_oDb->deleteEvent(array('id' => $iPostId))) {
  74. $this->_echoResultJson(array('code' => 2));
  75. return;
  76. }
  77. $aPhotos = $this->_oDb->getPhotos($iPostId);
  78. if(is_array($aPhotos) && !empty($aPhotos)) {
  79. bx_import('BxDolStorage');
  80. $oStorage = BxDolStorage::getObjectInstance($this->_oConfig->getObject('storage'));
  81. foreach($aPhotos as $aPhoto)
  82. $oStorage->deleteFile($aPhoto['id']);
  83. $this->_oDb->deletePhotos($iPostId);
  84. }
  85. //--- Event -> Delete for Alerts Engine ---//
  86. bx_import('BxDolAlerts');
  87. $oAlert = new BxDolAlerts($this->_oConfig->getSystemName('alert'), 'delete', $iPostId, $this->getUserId());
  88. $oAlert->alert();
  89. //--- Event -> Delete for Alerts Engine ---//
  90. $this->_echoResultJson(array('code' => 0, 'id' => $iPostId));
  91. }
  92. function actionGetPost()
  93. {
  94. $this->_oConfig->setJsMode(true);
  95. $this->_iOwnerId = bx_process_input(bx_get('owner_id'), BX_DATA_INT);
  96. $aEvent = $this->_oDb->getEvents(array('type' => 'id', 'object_id' => bx_process_input(bx_get('post_id'), BX_DATA_INT)));
  97. $this->_echoResultJson(array('item' => $this->_oTemplate->getCommon($aEvent, array('type' => 'owner', 'owner_id' => $this->_iOwnerId))));
  98. }
  99. function actionGetPosts()
  100. {
  101. $this->_oConfig->setJsMode(true);
  102. list($iStart, $iPerPage, $sFilter, $iTimeline, $aModules) = $this->_prepareParams();
  103. list($sItems, $sLoadMore) = $this->_oTemplate->getPosts(array(
  104. 'type' => 'owner',
  105. 'owner_id' => $this->_iOwnerId,
  106. 'order' => 'desc',
  107. 'start' => $iStart,
  108. 'per_page' => $iPerPage,
  109. 'filter' => $sFilter,
  110. 'timeline' => $iTimeline,
  111. 'modules' => $aModules
  112. ));
  113. $this->_echoResultJson(array('items' => $sItems, 'load_more' => $sLoadMore));
  114. }
  115. public function actionGetPostForm($sType)
  116. {
  117. $this->_oConfig->setJsMode(true);
  118. $this->_iOwnerId = bx_process_input(bx_get('owner_id'), BX_DATA_INT);
  119. $sMethod = 'getForm' . ucfirst($sType);
  120. if(!method_exists($this, $sMethod)) {
  121. $this->_echoResultJson(array());
  122. return;
  123. }
  124. $aResult = $this->$sMethod();
  125. $this->_echoResultJson($aResult);
  126. }
  127. public function actionGetTimeline()
  128. {
  129. $this->_oConfig->setJsMode(true);
  130. list($iStart, $iPerPage, $sFilter, $iTimeline, $aModules) = $this->_prepareParams();
  131. $sTimeline = $this->_oTemplate->getTimeline($this->_iOwnerId, $iStart, $iPerPage, $sFilter, $iTimeline, $aModules);
  132. $this->_echoResultJson(array('timeline' => $sTimeline));
  133. }
  134. public function actionGetComments()
  135. {
  136. $this->_iOwnerId = bx_process_input(bx_get('owner_id'), BX_DATA_INT);
  137. $sSystem = bx_process_input(bx_get('system'), BX_DATA_TEXT);
  138. $iId = bx_process_input(bx_get('id'), BX_DATA_INT);
  139. $aComments = $this->_oTemplate->getComments($sSystem, $iId);
  140. $this->_echoResultJson($aComments);
  141. }
  142. /**
  143. * SERVICE METHODS
  144. */
  145. public function serviceAddHandlers($sModuleUri = 'all')
  146. {
  147. $this->_updateHandlers($sModuleUri, true);
  148. }
  149. public function serviceDeleteHandlers($sModuleUri = 'all')
  150. {
  151. $this->_updateHandlers($sModuleUri, false);
  152. }
  153. function serviceGetActionsChecklist()
  154. {
  155. $aHandlers = $this->_oConfig->getHandlers();
  156. $aResults = array();
  157. foreach($aHandlers as $aHandler) {
  158. if($aHandler['type'] != BX_TIMELINE_HANDLER_TYPE_INSERT)
  159. continue;
  160. $aModule = $this->_oDb->getModuleByName($aHandler['module_name']);
  161. if(empty($aModule))
  162. $aModule['title'] = _t('_bx_timeline_alert_module_' . $aHandler['alert_unit']);
  163. $aResults[$aHandler['id']] = $aModule['title'] . ' (' . _t('_bx_timeline_alert_action_' . $aHandler['alert_action']) . ')';
  164. }
  165. asort($aResults);
  166. return $aResults;
  167. }
  168. public function serviceResponse($oAlert)
  169. {
  170. bx_import('Response', $this->_aModule);
  171. $oResponse = new BxTimelineResponse($this);
  172. $oResponse->response($oAlert);
  173. }
  174. public function serviceGetBlockPostProfile($iProfileId = 0)
  175. {
  176. if (!$iProfileId && bx_get('id') !== false) {
  177. $iProfileId = bx_process_input(bx_get('id'), BX_DATA_INT);
  178. $iProfileId = BxDolProfile::getInstanceByContentAndType($iProfileId, 'bx_persons')->id();
  179. }
  180. if (!$iProfileId)
  181. return array();
  182. $this->_iOwnerId = $iProfileId;
  183. list($sUserName, $sUserUrl) = $this->getUserInfo($iProfileId);
  184. if($this->_iOwnerId != $this->getUserId() && !$this->isAllowedPost())
  185. return array();
  186. $sJsObject = $this->_oConfig->getJsObject('post');
  187. $aMenu = array(
  188. array('id' => 'timeline-ptype-text', 'name' => 'timeline-ptype-text', 'class' => '', 'link' => 'javascript:void(0)', 'onclick' => "javascript:" . $sJsObject . ".changePostType(this, 'text')", 'target' => '_self', 'title' => _t('_bx_timeline_menu_item_write')),
  189. array('id' => 'timeline-ptype-link', 'name' => 'timeline-ptype-link', 'class' => '', 'link' => 'javascript:void(0)', 'onclick' => "javascript:" . $sJsObject . ".changePostType(this, 'link')", 'target' => '_self', 'title' => _t('_bx_timeline_menu_item_share_link')),
  190. array('id' => 'timeline-ptype-photo', 'name' => 'timeline-ptype-photo', 'class' => '', 'link' => 'javascript:void(0)', 'onclick' => "javascript:" . $sJsObject . ".changePostType(this, 'photo')", 'target' => '_self', 'title' => _t('_bx_timeline_menu_item_add_photo'))
  191. );
  192. if($this->_oDb->isModule('sounds'))
  193. $aMenu[] = array('id' => 'timeline-ptype-sound', 'name' => 'timeline-ptype-sound', 'class' => '', 'link' => 'javascript:void(0)', 'onclick' => "javascript:" . $sJsObject . ".changePostType(this, 'sound')", 'target' => '_self', 'title' => _t('_bx_timeline_menu_item_add_music'));
  194. if($this->_oDb->isModule('videos'))
  195. $aMenu[] = array('id' => 'timeline-ptype-video', 'name' => 'timeline-ptype-video', 'class' => '', 'link' => 'javascript:void(0)', 'onclick' => "javascript:" . $sJsObject . ".changePostType(this, 'video')", 'target' => '_self', 'title' => _t('_bx_timeline_menu_item_add_video'));
  196. bx_import('BxTemplMenuInteractive');
  197. $oMenu = new BxTemplMenuInteractive(array('template' => 'menu_interactive_vertical.html', 'menu_id'=> 'timeline-post-menu', 'menu_items' => $aMenu));
  198. $oMenu->setSelected('', 'timeline-ptype-text');
  199. $sContent = $this->_oTemplate->getPostBlock($this->_iOwnerId);
  200. return array('content' => $sContent, 'menu' => $oMenu);
  201. }
  202. public function serviceGetBlockViewProfile($iProfileId = 0, $iStart = -1, $iPerPage = -1, $iTimeline = -1, $sFilter = '', $aModules = array())
  203. {
  204. if (!$iProfileId) {
  205. $iProfileId = bx_process_input(bx_get('id'), BX_DATA_INT);
  206. $iProfileId = BxDolProfile::getInstanceByContentAndType($iProfileId, 'bx_persons')->id();
  207. }
  208. if (!$iProfileId)
  209. return array();
  210. $this->_iOwnerId = $iProfileId;
  211. list($sUserName, $sUserUrl) = $this->getUserInfo($iProfileId);
  212. $sJsObject = $this->_oConfig->getJsObject('view');
  213. $aMenu = array(
  214. 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),
  215. 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)),
  216. 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')),
  217. //array('id' => 'timeline-get-rss', 'name' => 'timeline-get-rss', 'class' => '', 'link' => BX_DOL_URL_ROOT . $this->_oConfig->getBaseUri() . 'rss/' . $iProfileId . '/', 'target' => '_self', 'title' => _t('_bx_timeline_menu_item_get_rss')),
  218. );
  219. bx_import('BxTemplMenuInteractive');
  220. $oMenu = new BxTemplMenuInteractive(array('template' => 'menu_interactive_vertical.html', 'menu_id'=> 'timeline-view-all', 'menu_items' => $aMenu));
  221. $oMenu->setSelected('', 'timeline-view-all');
  222. $sContent = $this->_oTemplate->getViewBlock($this->_iOwnerId, $iStart, $iPerPage, $sFilter, $iTimeline, $aModules);
  223. return array('content' => $sContent, 'menu' => $oMenu);
  224. }
  225. /*
  226. * COMMON METHODS
  227. */
  228. public function getFormText()
  229. {
  230. bx_import('BxDolForm');
  231. $oForm = BxDolForm::getObjectInstance('mod_tml_text', 'mod_tml_text_add');
  232. $oForm->aFormAttrs['action'] = BX_DOL_URL_ROOT . $this->_oConfig->getBaseUri() . 'post/';
  233. $oForm->aInputs['owner_id']['value'] = $this->_iOwnerId;
  234. $oForm->initChecker();
  235. if($oForm->isSubmittedAndValid()) {
  236. $iUserId = $this->getUserId();
  237. list($sUserName) = $this->getUserInfo($iUserId);
  238. $sType = $oForm->getCleanValue('type');
  239. $sType = $this->_oConfig->getPrefix('common_post') . $sType;
  240. BxDolForm::setSubmittedValue('type', $sType, $oForm->aFormAttrs['method']);
  241. $sContent = $sDescription = $oForm->getCleanValue('content');
  242. $sContent = serialize(array('text' => $sContent));
  243. BxDolForm::setSubmittedValue('content', $sContent, $oForm->aFormAttrs['method']);
  244. bx_import('BxDolPrivacy');
  245. $iId = $oForm->insert(array(
  246. 'object_id' => $iUserId,
  247. 'object_privacy_view' => BX_DOL_PG_ALL,
  248. 'title' => bx_process_input($sUserName . ' ' . _t('_bx_timeline_txt_wrote')),
  249. 'description' => $sDescription,
  250. 'date' => time()
  251. ));
  252. if($iId != 0) {
  253. $this->_onPost($iId, $iUserId);
  254. return array('id' => $iId);
  255. }
  256. return array('msg' => _t('_bx_timeline_txt_err_cannot_perform_action'));
  257. }
  258. return array('form' => $oForm->getCode(), 'form_id' => $oForm->id);
  259. }
  260. public function getFormLink()
  261. {
  262. bx_import('BxDolForm');
  263. $oForm = BxDolForm::getObjectInstance('mod_tml_link', 'mod_tml_link_add');
  264. $oForm->aFormAttrs['action'] = BX_DOL_URL_ROOT . $this->_oConfig->getBaseUri() . 'post/';
  265. $oForm->aInputs['owner_id']['value'] = $this->_iOwnerId;
  266. $oForm->initChecker();
  267. if($oForm->isSubmittedAndValid()) {
  268. $iUserId = $this->getUserId();
  269. list($sUserName) = $this->getUserInfo($iUserId);
  270. $sType = $oForm->getCleanValue('type');
  271. $sType = $this->_oConfig->getPrefix('common_post') . $sType;
  272. BxDolForm::setSubmittedValue('type', $sType, $oForm->aFormAttrs['method']);
  273. $sUrl = $oForm->getCleanValue('content');
  274. $sContent = bx_file_get_contents($sUrl);
  275. preg_match("/<title>(.*)<\/title>/", $sContent, $aMatch);
  276. $sTitle = $aMatch ? $aMatch[1] : '';
  277. preg_match("/<meta.*name[='\" ]+description['\"].*content[='\" ]+(.*)['\"].*><\/meta>/", $sContent, $aMatch);
  278. $sDescription = $aMatch ? $aMatch[1] : '';
  279. $sContent = serialize(array(
  280. 'url' => strpos($sUrl, 'http://') === false && strpos($sUrl, 'https://') === false ? 'http://' . $sUrl : $sUrl,
  281. 'title' => $sTitle,
  282. 'text' => $sDescription
  283. ));
  284. BxDolForm::setSubmittedValue('content', $sContent, $oForm->aFormAttrs['method']);
  285. bx_import('BxDolPrivacy');
  286. $iId = $oForm->insert(array(
  287. 'object_id' => $iUserId,
  288. 'object_privacy_view' => BX_DOL_PG_ALL,
  289. 'title' => bx_process_input($sUserName . ' ' . _t('_bx_timeline_txt_shared_link')),
  290. 'description' => bx_process_input($sUrl . ' - ' . $sTitle),
  291. 'date' => time()
  292. ));
  293. if($iId != 0) {
  294. $this->_onPost($iId, $iUserId);
  295. return array('id' => $iId);
  296. }
  297. return array('msg' => _t('_bx_timeline_txt_err_cannot_perform_action'));
  298. }
  299. return array('form' => $oForm->getCode(), 'form_id' => $oForm->id);
  300. }
  301. public function getFormPhoto()
  302. {
  303. $aFormNested = array(
  304. 'inputs' => array(
  305. 'file_title' => array(
  306. 'type' => 'text',
  307. 'name' => 'file_title[]',
  308. 'value' => '{file_title}',
  309. 'caption' => _t('_bx_timeline_form_photo_input_title'),
  310. 'required' => true,
  311. 'checker' => array(
  312. 'func' => 'length',
  313. 'params' => array(1, 150),
  314. 'error' => _t('_bx_timeline_form_photo_input_err_title')
  315. ),
  316. 'db' => array (
  317. 'pass' => 'Xss',
  318. ),
  319. ),
  320. 'file_text' => array(
  321. 'type' => 'textarea',
  322. 'name' => 'file_text[]',
  323. 'caption' => _t('_bx_timeline_form_photo_input_description'),
  324. 'required' => true,
  325. 'checker' => array(
  326. 'func' => 'length',
  327. 'params' => array(10, 5000),
  328. 'error' => _t('_bx_timeline_form_photo_input_err_description')
  329. ),
  330. 'db' => array (
  331. 'pass' => 'Xss',
  332. ),
  333. ),
  334. ),
  335. );
  336. bx_import('BxDolForm');
  337. $oForm = BxDolForm::getObjectInstance('mod_tml_photo', 'mod_tml_photo_add');
  338. $oForm->aFormAttrs['action'] = BX_DOL_URL_ROOT . $this->_oConfig->getBaseUri() . 'post/';
  339. $oForm->aInputs['owner_id']['value'] = $this->_iOwnerId;
  340. bx_import('BxDolFormNested');
  341. $oFormNested = new BxDolFormNested('content', $aFormNested, 'do_submit');
  342. $oForm->aInputs['content']['storage_object'] = $this->_oConfig->getObject('storage');
  343. $oForm->aInputs['content']['images_transcoder'] = $this->_oConfig->getObject('transcoder_preview');
  344. $oForm->aInputs['content']['uploaders'] = $this->_oConfig->getUploaders('image');
  345. $oForm->aInputs['content']['multiple'] = false;
  346. $oForm->aInputs['content']['ghost_template'] = $oFormNested;
  347. $oForm->initChecker();
  348. if($oForm->isSubmittedAndValid()) {
  349. $iUserId = $this->getUserId();
  350. list($sUserName) = $this->getUserInfo($iUserId);
  351. $sType = $oForm->getCleanValue('type');
  352. $sType = $this->_oConfig->getPrefix('common_post') . $sType;
  353. BxDolForm::setSubmittedValue('type', $sType, $oForm->aFormAttrs['method']);
  354. $aPhIds = $oForm->getCleanValue('content');
  355. BxDolForm::setSubmittedValue('content', serialize(array()), $oForm->aFormAttrs['method']);
  356. bx_import('BxDolPrivacy');
  357. $iId = $oForm->insert(array(
  358. 'object_id' => $iUserId,
  359. 'object_privacy_view' => BX_DOL_PG_ALL,
  360. 'title' => bx_process_input($sUserName . ' ' . _t('_bx_timeline_txt_added_photo')),
  361. 'description' => '',
  362. 'date' => time()
  363. ));
  364. if($iId != 0) {
  365. $iPhIds = count($aPhIds);
  366. if($iPhIds > 0) {
  367. $aPhTitles = $oForm->getCleanValue('file_title');
  368. $aPhTexts = $oForm->getCleanValue('file_text');
  369. bx_import('BxDolStorage');
  370. $oStorage = BxDolStorage::getObjectInstance($this->_oConfig->getObject('storage'));
  371. for($i = 0; $i < $iPhIds; $i++)
  372. if($this->_oDb->savePhoto($iId, $aPhIds[$i], $aPhTitles[$i], $aPhTexts[$i]))
  373. $oStorage->afterUploadCleanup($aPhIds[$i], $iUserId);
  374. }
  375. $this->_onPost($iId, $iUserId);
  376. return array('id' => $iId);
  377. }
  378. return array('msg' => _t('_bx_timeline_txt_err_cannot_perform_action'));
  379. }
  380. return array('form' => $oForm->getCode(), 'form_id' => $oForm->id);
  381. }
  382. public function getCmtsObject($sSystem, $iId)
  383. {
  384. bx_import('BxDolCmts');
  385. $oCmts = BxDolCmts::getObjectInstance($sSystem, $iId);
  386. if(!$oCmts->isEnabled())
  387. return false;
  388. return $oCmts;
  389. }
  390. public function getUserId()
  391. {
  392. return isLogged() ? bx_get_logged_profile_id() : 0;
  393. }
  394. public function getUserInfo($iUserId = 0)
  395. {
  396. bx_import('BxDolProfile');
  397. $oProfile = BxDolProfile::getInstance($iUserId);
  398. if (!$oProfile) {
  399. bx_import('BxDolProfileUndefined');
  400. $oProfile = BxDolProfileUndefined::getInstance();
  401. }
  402. return array(
  403. $oProfile->getDisplayName(),
  404. $oProfile->getUrl(),
  405. $oProfile->getIcon(),
  406. $oProfile->getUnit()
  407. );
  408. }
  409. public function isAllowedPost($bPerform = false)
  410. {
  411. if(isAdmin())
  412. return true;
  413. $iUserId = $this->getUserId();
  414. if($iUserId == 0 && $this->_oConfig->isAllowGuestComments())
  415. return true;
  416. $aCheckResult = checkActionModule($iUserId, 'post', $this->getName(), $bPerform);
  417. return $aCheckResult[CHECK_ACTION_RESULT] == CHECK_ACTION_RESULT_ALLOWED;
  418. }
  419. public function isAllowedDelete($bPerform = false)
  420. {
  421. if(isAdmin())
  422. return true;
  423. $iUserId = (int)$this->getUserId();
  424. if($this->_iOwnerId == $iUserId)
  425. return true;
  426. $aCheckResult = checkActionModule($iUserId, 'delete', $this->getName(), $bPerform);
  427. return $aCheckResult[CHECK_ACTION_RESULT] == CHECK_ACTION_RESULT_ALLOWED;
  428. }
  429. public function isAllowedComment($bPerform = false)
  430. {
  431. if(isAdmin())
  432. return true;
  433. $iUserId = $this->getUserId();
  434. if($iUserId == 0 && $this->_oConfig->isAllowGuestComments())
  435. return true;
  436. $aCheckResult = checkActionModule($iUserId, 'comment', $this->getName(), $bPerform);
  437. return $aCheckResult[CHECK_ACTION_RESULT] == CHECK_ACTION_RESULT_ALLOWED;
  438. }
  439. protected function _prepareParams()
  440. {
  441. $this->_iOwnerId = bx_process_input(bx_get('owner_id'), BX_DATA_INT);
  442. if(strpos($this->_iOwnerId, BX_TIMELINE_DIVIDER_ID) !== false)
  443. $this->_iOwnerId = explode(BX_TIMELINE_DIVIDER_ID, $this->_iOwnerId);
  444. $iStart = bx_get('start');
  445. $iStart = $iStart !== false ? bx_process_input($iStart, BX_DATA_INT) : 0;
  446. $iPerPage = bx_get('per_page');
  447. $iPerPage = $iPerPage !== false ? bx_process_input($iPerPage, BX_DATA_INT) : $this->_oConfig->getPerPage();
  448. $sFilter = bx_get('filter');
  449. $sFilter = $sFilter !== false ? bx_process_input($sFilter, BX_DATA_TEXT) : BX_TIMELINE_FILTER_ALL;
  450. $iTimeline = bx_get('timeline');
  451. $iTimeline = $iTimeline !== false ? bx_process_input($iTimeline, BX_DATA_INT) : 0;
  452. $aModules = bx_get('modules');
  453. $aModules = $aModules !== false ? bx_process_input($aModules, BX_DATA_TEXT) : array();
  454. return array($iStart, $iPerPage, $sFilter, $iTimeline, $aModules);
  455. }
  456. protected function _updateHandlers($sModuleUri = 'all', $bInstall = true)
  457. {
  458. $aModules = $sModuleUri == 'all' ? $this->_oDb->getModules() : array($this->_oDb->getModuleByUri($sModuleUri));
  459. foreach($aModules as $aModule) {
  460. if(!BxDolRequest::serviceExists($aModule, 'get_timeline_data'))
  461. continue;
  462. $aData = BxDolService::call($aModule['name'], 'get_timeline_data');
  463. if(empty($aData) || !is_array($aData))
  464. continue;
  465. if($bInstall)
  466. $this->_oDb->insertData($aData);
  467. else
  468. $this->_oDb->deleteData($aData);
  469. }
  470. BxDolAlerts::cache();
  471. }
  472. protected function _onPost($iId, $iUserId)
  473. {
  474. //--- Event -> Post for Alerts Engine ---//
  475. bx_import('BxDolAlerts');
  476. $oAlert = new BxDolAlerts($this->_oConfig->getSystemName('alert'), 'post', $iId, $iUserId);
  477. $oAlert->alert();
  478. //--- Event -> Post for Alerts Engine ---//
  479. }
  480. protected function _echoResultJson($a, $isAutoWrapForFormFileSubmit = false) {
  481. header('Content-type: text/html; charset=utf-8');
  482. require_once(BX_DIRECTORY_PATH_PLUGINS . 'Services_JSON.php');
  483. $oParser = new Services_JSON();
  484. $s = $oParser->encode($a);
  485. if ($isAutoWrapForFormFileSubmit && !empty($_FILES))
  486. $s = '<textarea>' . $s . '</textarea>'; // http://jquery.malsup.com/form/#file-upload
  487. echo $s;
  488. }
  489. /**
  490. * Get photo uploading form.
  491. *
  492. * @return string with form.
  493. */
  494. function actionGetPhotoUploaders($iOwnerId)
  495. {
  496. $this->_iOwnerId = $iOwnerId;
  497. header('Content-Type: text/html; charset=utf-8');
  498. return BxDolService::call('photos', 'get_uploader_form', array(array('mode' => 'single', 'category' => 'wall', 'album'=>_t('_wall_photo_album', getNickName(getLoggedId())), 'albumPrivacy' => BX_DOL_PG_ALL, 'from_wall' => 1, 'owner_id' => $this->_iOwnerId)), 'Uploader');
  499. }
  500. /**
  501. * Get music uploading form.
  502. *
  503. * @return srting with form.
  504. */
  505. function actionGetMusicUploaders($iOwnerId)
  506. {
  507. $this->_iOwnerId = $iOwnerId;
  508. header('Content-Type: text/html; charset=utf-8');
  509. return BxDolService::call('sounds', 'get_uploader_form', array(array('mode' => 'single', 'category' => 'wall', 'album'=>_t('_wall_sound_album', getNickName(getLoggedId())), 'albumPrivacy' => BX_DOL_PG_ALL, 'from_wall' => 1, 'owner_id' => $this->_iOwnerId)), 'Uploader');
  510. }
  511. /**
  512. * Get video uploading form.
  513. *
  514. * @return string with form.
  515. */
  516. function actionGetVideoUploaders($iOwnerId)
  517. {
  518. $this->_iOwnerId = $iOwnerId;
  519. header('Content-Type: text/html; charset=utf-8');
  520. return BxDolService::call('videos', 'get_uploader_form', array(array('mode' => 'single', 'category' => 'wall', 'album'=>_t('_wall_video_album', getNickName(getLoggedId())), 'albumPrivacy' => BX_DOL_PG_ALL, 'from_wall' => 1, 'owner_id' => $this->_iOwnerId)), 'Uploader');
  521. }
  522. /**
  523. * Get RSS for specified owner.
  524. *
  525. * @param string $sUsername wall owner username
  526. * @return string with RSS.
  527. */
  528. function actionRss($sUsername)
  529. {
  530. $aOwner = $this->_oDb->getUser($sUsername, 'username');
  531. $aEvents = $this->_oDb->getEvents(array(
  532. 'type' => 'owner',
  533. 'owner_id' => $aOwner['id'],
  534. 'order' => 'desc',
  535. 'start' => 0,
  536. 'count' => $this->_oConfig->getRssLength(),
  537. 'filter' => ''
  538. ));
  539. $sRssBaseUrl = $this->_oConfig->getBaseUri() . 'index/' . $aOwner['username'] . '/';
  540. $aRssData = array();
  541. foreach($aEvents as $aEvent) {
  542. if(empty($aEvent['title'])) continue;
  543. $aRssData[$aEvent['id']] = array(
  544. 'UnitID' => $aEvent['id'],
  545. 'OwnerID' => $aOwner['id'],
  546. 'UnitTitle' => $aEvent['title'],
  547. 'UnitLink' => BX_DOL_URL_ROOT . $sRssBaseUrl . '#wall-event-' . $aEvent['id'],
  548. 'UnitDesc' => $aEvent['description'],
  549. 'UnitDateTimeUTS' => $aEvent['date'],
  550. 'UnitIcon' => ''
  551. );
  552. }
  553. $oRss = new BxDolRssFactory();
  554. header('Content-Type: text/html; charset=utf-8');
  555. return $oRss->GenRssByData($aRssData, $aOwner['username'] . ' ' . _t('_wall_rss_caption'), $sRssBaseUrl);
  556. }
  557. /**
  558. * Display Post block on profile page.
  559. *
  560. * @param integer $mixed - owner ID or Username.
  561. * @return array containing block info.
  562. */
  563. function serviceViewBlockAccount($mixed, $iStart = -1, $iPerPage = -1, $sFilter = '', $sTimeline = '', $sType = 'id', $aModules = array())
  564. {
  565. $sContent = '';
  566. $aOwner = $this->_oDb->getUser($mixed, $sType);
  567. $this->_iOwnerId = $aOwner['id'];
  568. $aFriends = getMyFriendsEx($this->_iOwnerId, '', '', 'LIMIT 20');
  569. if(empty($aFriends))
  570. return $this->_oTemplate->getEmpty(true);
  571. $this->_iOwnerId = array_keys($aFriends);
  572. if($iStart == -1)
  573. $iStart = 0;
  574. if($iPerPage == -1)
  575. $iPerPage = $this->_oConfig->getPerPage('account');
  576. if(empty($sFilter))
  577. $sFilter = BX_WALL_FILTER_ALL;
  578. //--- Prepare JavaScript paramaters ---//
  579. $oJson = new Services_JSON();
  580. $sOwnerId = implode(BX_TIMELINE_DIVIDER_ID, $this->_iOwnerId);
  581. ob_start();
  582. ?>
  583. var <?=$this->_sJsViewObject; ?> = new BxTimelineView({
  584. sActionUrl: '<?php echo BX_DOL_URL_ROOT . $this->_oConfig->getBaseUri(); ?>',
  585. sObjName: '<?php echo $this->_sJsViewObject; ?>',
  586. iOwnerId: '<?php echo $sOwnerId; ?>',
  587. sAnimationEffect: '<?php echo $this->_oConfig->getAnimationEffect(); ?>',
  588. iAnimationSpeed: '<?php echo $this->_oConfig->getAnimationSpeed(); ?>',
  589. oRequestParams: <?php echo $oJson->encode(array('WallOwnerId' => $sOwnerId, 'WallStart' => $iStart, 'WallPerPage' => $iPerPage, 'WallFilter' => $sFilter, 'WallTimeline' => $sTimeline, 'WallModules' => $aModules)); ?>
  590. });
  591. <?php
  592. $sJsContent = ob_get_clean();
  593. //--- Is used with common Pagination
  594. //$oPaginate = $this->_getPaginate($sFilter, $sTimeline, $aModules);
  595. $aVariables = array(
  596. 'timeline' => $this->_getTimeline($iStart, $iPerPage, $sFilter, $sTimeline, $aModules),
  597. 'content' => $this->_getPosts('desc', $iStart, $iPerPage, $sFilter, $sTimeline, $aModules),
  598. 'view_js_content' => $sJsContent,
  599. //--- Is used with common Pagination
  600. //'paginate' => $oPaginate->getPaginate()
  601. );
  602. bx_import('BxTemplFormView');
  603. $oForm = new BxTemplFormView(array());
  604. $oForm->addCssJs(true, true);
  605. $this->_oTemplate->addCss(array('forms_adv.css', 'view.css'));
  606. $this->_oTemplate->addJs(array('main.js', 'view.js'));
  607. return array($this->_oTemplate->parseHtmlByName('view.html', $aVariables), array(), LoadingBox('bx-wall-view-loading'), false, 'getBlockCaptionMenu');
  608. }
  609. function serviceViewBlockIndex($iStart = -1, $iPerPage = -1, $sFilter = '', $aModules = array())
  610. {
  611. $sContent = '';
  612. $this->_iOwnerId = 0;
  613. if($iStart == -1)
  614. $iStart = 0;
  615. if($iPerPage == -1)
  616. $iPerPage = $this->_oConfig->getPerPage('index');
  617. if(empty($sFilter))
  618. $sFilter = BX_WALL_FILTER_ALL;
  619. //--- Prepare JavaScript paramaters ---//
  620. $oJson = new Services_JSON();
  621. ob_start();
  622. ?>
  623. var <?=$this->_sJsOutlineObject; ?> = new BxTimelineOutline({
  624. sActionUrl: '<?=BX_DOL_URL_ROOT . $this->_oConfig->getBaseUri(); ?>',
  625. sObjName: '<?=$this->_sJsOutlineObject; ?>',
  626. iOwnerId: '0',
  627. sAnimationEffect: '<?php echo $this->_oConfig->getAnimationEffect(); ?>',
  628. iAnimationSpeed: '<?php echo $this->_oConfig->getAnimationSpeed(); ?>',
  629. oRequestParams: <?php echo $oJson->encode(array('WallFilter' => $sFilter, 'WallModules' => $aModules)); ?>
  630. });
  631. <?php
  632. $sJsContent = ob_get_clean();
  633. list($sContent, $sPaginate) = $this->_getPostsOutline('desc', $iStart, $iPerPage, $sFilter, $aModules);
  634. if(empty($sContent))
  635. return;
  636. $aTmplVars = array(
  637. 'outline_js_content' => $sJsContent,
  638. 'content' => $sContent,
  639. 'paginate' => $sPaginate
  640. );
  641. $this->_oTemplate->addCss(array('outline.css'));
  642. $this->_oTemplate->addJs(array('jquery.masonry.min.js', 'main.js', 'outline.js'));
  643. return array($this->_oTemplate->parseHtmlByName('outline.html', $aTmplVars), array(), LoadingBox('bx-wall-view-loading'), true, 'getBlockCaptionMenu');
  644. }
  645. function serviceGetMemberMenuItem()
  646. {
  647. $oMemberMenu = bx_instance('BxDolMemberMenu');
  648. $aLanguageKeys = array(
  649. 'wall' => _t( '_wall_pc_view' ),
  650. );
  651. // fill all necessary data;
  652. $aLinkInfo = array(
  653. 'item_img_src' => 'time',
  654. 'item_img_alt' => $aLanguageKeys['wall'],
  655. 'item_link' => BX_DOL_URL_ROOT . $this -> _oConfig -> getBaseUri(),
  656. 'item_onclick' => null,
  657. 'item_title' => $aLanguageKeys['wall'],
  658. 'extra_info' => null,
  659. );
  660. return $oMemberMenu -> getGetExtraMenuLink($aLinkInfo);
  661. }
  662. /**
  663. * Private Methods
  664. * Is used for content displaying
  665. */
  666. function _getPostsOutline($sOrder, $iStart, $iPerPage, $sFilter, $aModules)
  667. {
  668. $iStartEv = $iStart;
  669. $iPerPageEv = $iPerPage;
  670. //--- Check for Next
  671. $iPerPageEv += 1;
  672. $aEvents = $this->_oDb->getEvents(array(
  673. 'type' => 'outline',
  674. 'order' => $sOrder,
  675. 'start' => $iStartEv,
  676. 'count' => $iPerPageEv,
  677. 'filter' => $sFilter,
  678. 'modules' => $aModules
  679. ));
  680. //--- Check for Next
  681. $bNext = false;
  682. if(count($aEvents) > $iPerPage) {
  683. $aEvent = array_pop($aEvents);
  684. $bNext = true;
  685. }
  686. $iEvents = count($aEvents);
  687. foreach($aEvents as $aEvent) {
  688. if(empty($aEvent['action']))
  689. continue;
  690. $aEvent['content'] = $this->_oTemplate->getSystem($aEvent, BX_WALL_VIEW_OUTLINE);
  691. if(empty($aEvent['content']))
  692. continue;
  693. $sContent .= $aEvent['content'];
  694. }
  695. $sPaginate = $this->_getLoadMoreOutline($iStart, $iPerPage, $bNext, $iEvents > 0);
  696. return array($sContent, $sPaginate);
  697. }
  698. /*
  699. function _getLoadMoreOutline($iStart, $iPerPage, $bEnabled = true, $bVisible = true)
  700. {
  701. return $this->_oTemplate->getLoadMoreOutline($iStart, $iPerPage, $bEnabled, $bVisible);
  702. }
  703. function _getPaginate($sFilter, $sTimeline, $aModules)
  704. {
  705. return new BxDolPaginate(array(
  706. 'page_url' => 'javascript:void(0);',
  707. 'start' => 0,
  708. 'count' => $this->_oDb->getEventsCount($this->_iOwnerId, $sFilter, $sTimeline, $aModules),
  709. 'per_page' => $this->_oConfig->getPerPage(),
  710. 'on_change_page' => $this->_sJsViewObject . '.changePage({start}, {per_page})',
  711. 'on_change_per_page' => $this->_sJsViewObject . '.changePerPage(this)',
  712. 'page_reloader' => true
  713. ));
  714. }
  715. function _addHidden($sPostType = "photos", $sContentType = "upload", $sAction = "post")
  716. {
  717. return array(
  718. 'WallOwnerId' => array (
  719. 'type' => 'hidden',
  720. 'name' => 'WallOwnerId',
  721. 'value' => $this->_iOwnerId,
  722. ),
  723. 'WallPostAction' => array (
  724. 'type' => 'hidden',
  725. 'name' => 'WallPostAction',
  726. 'value' => $sAction,
  727. ),
  728. 'WallPostType' => array (
  729. 'type' => 'hidden',
  730. 'name' => 'WallPostType',
  731. 'value' => $sPostType,
  732. ),
  733. 'WallContentType' => array (
  734. 'type' => 'hidden',
  735. 'name' => 'WallContentType',
  736. 'value' => $sContentType,
  737. ),
  738. );
  739. }
  740. function serviceGetSubscriptionParams($sUnit, $sAction, $iObjectId)
  741. {
  742. $sUnit = str_replace('bx_', '_', $sUnit);
  743. if(empty($sAction))
  744. $sAction = 'main';
  745. $aProfileInfo = getProfileInfo($iObjectId);
  746. return array(
  747. 'template' => array(
  748. 'Subscription' => _t($sUnit . '_sbs_' . $sAction, $aProfileInfo['NickName']),
  749. 'ViewLink' => BX_DOL_URL_ROOT . $this->_oConfig->getBaseUri() . 'index/' . $aProfileInfo['NickName']
  750. )
  751. );
  752. }
  753. function serviceGetSpyData()
  754. {
  755. $AlertName = $this->_oConfig->getAlertSystemName();
  756. return array(
  757. 'handlers' => array(
  758. array('alert_unit' => $AlertName, 'alert_action' => 'post', 'module_uri' => $this->_oConfig->getUri(), 'module_class' => 'Module', 'module_method' => 'get_spy_post'),
  759. array('alert_unit' => $AlertName, 'alert_action' => 'commentPost', 'module_uri' => $this->_oConfig->getUri(), 'module_class' => 'Module', 'module_method' => 'get_spy_post'),
  760. ),
  761. 'alerts' => array(
  762. array('unit' => $AlertName, 'action' => 'post'),
  763. array('unit' => $AlertName, 'action' => 'delete'),
  764. array('unit' => $AlertName, 'action' => 'commentPost'),
  765. array('unit' => $AlertName, 'action' => 'commentRemoved')
  766. )
  767. );
  768. }
  769. function serviceGetSpyPost($sAction, $iObjectId = 0, $iSenderId = 0, $aExtraParams = array())
  770. {
  771. $aEvent = $this->_oDb->getEvents(array('type' => 'id', 'object_id' => $iObjectId));
  772. $aEvent = array_shift($aEvent);
  773. $sLangKey = '';
  774. switch ($sAction) {
  775. case 'post':
  776. $sLangKey = '_wall_spy_post';
  777. break;
  778. case 'commentPost':
  779. $sLangKey = '_wall_spy_post_comment';
  780. break;
  781. }
  782. return array(
  783. 'params' => array(
  784. 'profile_link' => getProfileLink($iSenderId),
  785. 'profile_nick' => getNickName($iSenderId),
  786. 'recipient_p_link' => getProfileLink($aEvent['owner_id']),
  787. 'recipient_p_nick' => getNickName($aEvent['owner_id']),
  788. ),
  789. 'recipient_id' => $aEvent['owner_id'],
  790. 'lang_key' => $sLangKey
  791. );
  792. }
  793. */
  794. }
  795. /** @} */