BxTimelineModule.php 30 KB

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