BxTimelineModule.php 31 KB

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