BxTimelineModule.php 30 KB

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