BxTimelineModule.php 31 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862
  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. bx_import('BxDolCmts');
  295. $oCmts = BxDolCmts::getObjectInstance($this->_oConfig->getSystemName('comment'), $iId);
  296. if(!$oCmts->isEnabled())
  297. return false;
  298. return $oCmts;
  299. }
  300. public function getUserId()
  301. {
  302. return isLogged() ? bx_get_logged_profile_id() : 0;
  303. }
  304. public function getUserInfo($iUserId = 0)
  305. {
  306. bx_import('BxDolProfile');
  307. $oProfile = BxDolProfile::getInstance($iUserId);
  308. if (!$oProfile) {
  309. bx_import('BxDolProfileUndefined');
  310. $oProfile = BxDolProfileUndefined::getInstance();
  311. }
  312. return array(
  313. $oProfile->getDisplayName(),
  314. $oProfile->getUrl(),
  315. $oProfile->getIcon(),
  316. $oProfile->getUnit()
  317. );
  318. }
  319. public function isAllowedPost($bPerform = false)
  320. {
  321. if(isAdmin())
  322. return true;
  323. $iUserId = $this->getUserId();
  324. if($iUserId == 0 && $this->_oConfig->isAllowGuestComments())
  325. return true;
  326. $aCheckResult = checkActionModule($iUserId, 'post', $this->getName(), $bPerform);
  327. return $aCheckResult[CHECK_ACTION_RESULT] == CHECK_ACTION_RESULT_ALLOWED;
  328. }
  329. public function isAllowedDelete($bPerform = false)
  330. {
  331. if(isAdmin())
  332. return true;
  333. $iUserId = (int)$this->getUserId();
  334. if($this->_iOwnerId == $iUserId)
  335. return true;
  336. $aCheckResult = checkActionModule($iUserId, 'delete', $this->getName(), $bPerform);
  337. return $aCheckResult[CHECK_ACTION_RESULT] == CHECK_ACTION_RESULT_ALLOWED;
  338. }
  339. public function isAllowedComment($bPerform = false)
  340. {
  341. if(isAdmin())
  342. return true;
  343. $iUserId = $this->getUserId();
  344. if($iUserId == 0 && $this->_oConfig->isAllowGuestComments())
  345. return true;
  346. $aCheckResult = checkActionModule($iUserId, 'comment', $this->getName(), $bPerform);
  347. return $aCheckResult[CHECK_ACTION_RESULT] == CHECK_ACTION_RESULT_ALLOWED;
  348. }
  349. protected function _prepareParams()
  350. {
  351. $this->_iOwnerId = bx_process_input(bx_get('owner_id'), BX_DATA_INT);
  352. if(strpos($this->_iOwnerId, BX_TIMELINE_DIVIDER_ID) !== false)
  353. $this->_iOwnerId = explode(BX_TIMELINE_DIVIDER_ID, $this->_iOwnerId);
  354. $iStart = bx_get('start');
  355. $iStart = $iStart !== false ? bx_process_input($iStart, BX_DATA_INT) : 0;
  356. $iPerPage = bx_get('per_page');
  357. $iPerPage = $iPerPage !== false ? bx_process_input($iPerPage, BX_DATA_INT) : $this->_oConfig->getPerPage();
  358. $sFilter = bx_get('filter');
  359. $sFilter = $sFilter !== false ? bx_process_input($sFilter, BX_DATA_TEXT) : BX_TIMELINE_FILTER_ALL;
  360. $iTimeline = bx_get('timeline');
  361. $iTimeline = $iTimeline !== false ? bx_process_input($iTimeline, BX_DATA_INT) : 0;
  362. $aModules = bx_get('modules');
  363. $aModules = $aModules !== false ? bx_process_input($aModules, BX_DATA_TEXT) : array();
  364. return array($iStart, $iPerPage, $sFilter, $iTimeline, $aModules);
  365. }
  366. protected function _updateHandlers($sModuleUri = 'all', $bInstall = true)
  367. {
  368. $aModules = $sModuleUri == 'all' ? $this->_oDb->getModules() : array($this->_oDb->getModuleByUri($sModuleUri));
  369. foreach($aModules as $aModule) {
  370. if(!BxDolRequest::serviceExists($aModule, 'get_timeline_data'))
  371. continue;
  372. $aData = BxDolService::call($aModule['name'], 'get_timeline_data');
  373. if(empty($aData) || !is_array($aData))
  374. continue;
  375. if($bInstall)
  376. $this->_oDb->insertData($aData);
  377. else
  378. $this->_oDb->deleteData($aData);
  379. }
  380. BxDolAlerts::cache();
  381. }
  382. protected function _echoResultJson($a, $isAutoWrapForFormFileSubmit = false) {
  383. header('Content-type: text/html; charset=utf-8');
  384. require_once(BX_DIRECTORY_PATH_PLUGINS . 'Services_JSON.php');
  385. $oParser = new Services_JSON();
  386. $s = $oParser->encode($a);
  387. if ($isAutoWrapForFormFileSubmit && !empty($_FILES))
  388. $s = '<textarea>' . $s . '</textarea>'; // http://jquery.malsup.com/form/#file-upload
  389. echo $s;
  390. }
  391. /**
  392. * Get photo uploading form.
  393. *
  394. * @return string with form.
  395. */
  396. function actionGetPhotoUploaders($iOwnerId)
  397. {
  398. $this->_iOwnerId = $iOwnerId;
  399. header('Content-Type: text/html; charset=utf-8');
  400. 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');
  401. }
  402. /**
  403. * Get music uploading form.
  404. *
  405. * @return srting with form.
  406. */
  407. function actionGetMusicUploaders($iOwnerId)
  408. {
  409. $this->_iOwnerId = $iOwnerId;
  410. header('Content-Type: text/html; charset=utf-8');
  411. 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');
  412. }
  413. /**
  414. * Get video uploading form.
  415. *
  416. * @return string with form.
  417. */
  418. function actionGetVideoUploaders($iOwnerId)
  419. {
  420. $this->_iOwnerId = $iOwnerId;
  421. header('Content-Type: text/html; charset=utf-8');
  422. 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');
  423. }
  424. /**
  425. * Get RSS for specified owner.
  426. *
  427. * @param string $sUsername wall owner username
  428. * @return string with RSS.
  429. */
  430. function actionRss($sUsername)
  431. {
  432. $aOwner = $this->_oDb->getUser($sUsername, 'username');
  433. $aEvents = $this->_oDb->getEvents(array(
  434. 'type' => 'owner',
  435. 'owner_id' => $aOwner['id'],
  436. 'order' => 'desc',
  437. 'start' => 0,
  438. 'count' => $this->_oConfig->getRssLength(),
  439. 'filter' => ''
  440. ));
  441. $sRssBaseUrl = $this->_oConfig->getBaseUri() . 'index/' . $aOwner['username'] . '/';
  442. $aRssData = array();
  443. foreach($aEvents as $aEvent) {
  444. if(empty($aEvent['title'])) continue;
  445. $aRssData[$aEvent['id']] = array(
  446. 'UnitID' => $aEvent['id'],
  447. 'OwnerID' => $aOwner['id'],
  448. 'UnitTitle' => $aEvent['title'],
  449. 'UnitLink' => BX_DOL_URL_ROOT . $sRssBaseUrl . '#wall-event-' . $aEvent['id'],
  450. 'UnitDesc' => $aEvent['description'],
  451. 'UnitDateTimeUTS' => $aEvent['date'],
  452. 'UnitIcon' => ''
  453. );
  454. }
  455. $oRss = new BxDolRssFactory();
  456. header('Content-Type: text/html; charset=utf-8');
  457. return $oRss->GenRssByData($aRssData, $aOwner['username'] . ' ' . _t('_wall_rss_caption'), $sRssBaseUrl);
  458. }
  459. /**
  460. * Display Post block on profile page.
  461. *
  462. * @param integer $mixed - owner ID or Username.
  463. * @return array containing block info.
  464. */
  465. function serviceViewBlockAccount($mixed, $iStart = -1, $iPerPage = -1, $sFilter = '', $sTimeline = '', $sType = 'id', $aModules = array())
  466. {
  467. $sContent = '';
  468. $aOwner = $this->_oDb->getUser($mixed, $sType);
  469. $this->_iOwnerId = $aOwner['id'];
  470. $aFriends = getMyFriendsEx($this->_iOwnerId, '', '', 'LIMIT 20');
  471. if(empty($aFriends))
  472. return $this->_oTemplate->getEmpty(true);
  473. $this->_iOwnerId = array_keys($aFriends);
  474. if($iStart == -1)
  475. $iStart = 0;
  476. if($iPerPage == -1)
  477. $iPerPage = $this->_oConfig->getPerPage('account');
  478. if(empty($sFilter))
  479. $sFilter = BX_WALL_FILTER_ALL;
  480. //--- Prepare JavaScript paramaters ---//
  481. $oJson = new Services_JSON();
  482. $sOwnerId = implode(BX_TIMELINE_DIVIDER_ID, $this->_iOwnerId);
  483. ob_start();
  484. ?>
  485. var <?=$this->_sJsViewObject; ?> = new BxTimelineView({
  486. sActionUrl: '<?php echo BX_DOL_URL_ROOT . $this->_oConfig->getBaseUri(); ?>',
  487. sObjName: '<?php echo $this->_sJsViewObject; ?>',
  488. iOwnerId: '<?php echo $sOwnerId; ?>',
  489. sAnimationEffect: '<?php echo $this->_oConfig->getAnimationEffect(); ?>',
  490. iAnimationSpeed: '<?php echo $this->_oConfig->getAnimationSpeed(); ?>',
  491. oRequestParams: <?php echo $oJson->encode(array('WallOwnerId' => $sOwnerId, 'WallStart' => $iStart, 'WallPerPage' => $iPerPage, 'WallFilter' => $sFilter, 'WallTimeline' => $sTimeline, 'WallModules' => $aModules)); ?>
  492. });
  493. <?php
  494. $sJsContent = ob_get_clean();
  495. //--- Is used with common Pagination
  496. //$oPaginate = $this->_getPaginate($sFilter, $sTimeline, $aModules);
  497. $aVariables = array(
  498. 'timeline' => $this->_getTimeline($iStart, $iPerPage, $sFilter, $sTimeline, $aModules),
  499. 'content' => $this->_getPosts('desc', $iStart, $iPerPage, $sFilter, $sTimeline, $aModules),
  500. 'view_js_content' => $sJsContent,
  501. //--- Is used with common Pagination
  502. //'paginate' => $oPaginate->getPaginate()
  503. );
  504. bx_import('BxTemplFormView');
  505. $oForm = new BxTemplFormView(array());
  506. $oForm->addCssJs(true, true);
  507. $this->_oTemplate->addCss(array('forms_adv.css', 'view.css'));
  508. $this->_oTemplate->addJs(array('main.js', 'view.js'));
  509. return array($this->_oTemplate->parseHtmlByName('view.html', $aVariables), array(), LoadingBox('bx-wall-view-loading'), false, 'getBlockCaptionMenu');
  510. }
  511. function serviceViewBlockIndex($iStart = -1, $iPerPage = -1, $sFilter = '', $aModules = array())
  512. {
  513. $sContent = '';
  514. $this->_iOwnerId = 0;
  515. if($iStart == -1)
  516. $iStart = 0;
  517. if($iPerPage == -1)
  518. $iPerPage = $this->_oConfig->getPerPage('index');
  519. if(empty($sFilter))
  520. $sFilter = BX_WALL_FILTER_ALL;
  521. //--- Prepare JavaScript paramaters ---//
  522. $oJson = new Services_JSON();
  523. ob_start();
  524. ?>
  525. var <?=$this->_sJsOutlineObject; ?> = new BxTimelineOutline({
  526. sActionUrl: '<?=BX_DOL_URL_ROOT . $this->_oConfig->getBaseUri(); ?>',
  527. sObjName: '<?=$this->_sJsOutlineObject; ?>',
  528. iOwnerId: '0',
  529. sAnimationEffect: '<?php echo $this->_oConfig->getAnimationEffect(); ?>',
  530. iAnimationSpeed: '<?php echo $this->_oConfig->getAnimationSpeed(); ?>',
  531. oRequestParams: <?php echo $oJson->encode(array('WallFilter' => $sFilter, 'WallModules' => $aModules)); ?>
  532. });
  533. <?php
  534. $sJsContent = ob_get_clean();
  535. list($sContent, $sPaginate) = $this->_getPostsOutline('desc', $iStart, $iPerPage, $sFilter, $aModules);
  536. if(empty($sContent))
  537. return;
  538. $aTmplVars = array(
  539. 'outline_js_content' => $sJsContent,
  540. 'content' => $sContent,
  541. 'paginate' => $sPaginate
  542. );
  543. $this->_oTemplate->addCss(array('outline.css'));
  544. $this->_oTemplate->addJs(array('jquery.masonry.min.js', 'main.js', 'outline.js'));
  545. return array($this->_oTemplate->parseHtmlByName('outline.html', $aTmplVars), array(), LoadingBox('bx-wall-view-loading'), true, 'getBlockCaptionMenu');
  546. }
  547. function serviceGetMemberMenuItem()
  548. {
  549. $oMemberMenu = bx_instance('BxDolMemberMenu');
  550. $aLanguageKeys = array(
  551. 'wall' => _t( '_wall_pc_view' ),
  552. );
  553. // fill all necessary data;
  554. $aLinkInfo = array(
  555. 'item_img_src' => 'time',
  556. 'item_img_alt' => $aLanguageKeys['wall'],
  557. 'item_link' => BX_DOL_URL_ROOT . $this -> _oConfig -> getBaseUri(),
  558. 'item_onclick' => null,
  559. 'item_title' => $aLanguageKeys['wall'],
  560. 'extra_info' => null,
  561. );
  562. return $oMemberMenu -> getGetExtraMenuLink($aLinkInfo);
  563. }
  564. /**
  565. * Private Methods
  566. * Is used for content displaying
  567. */
  568. function _getPostsOutline($sOrder, $iStart, $iPerPage, $sFilter, $aModules)
  569. {
  570. $iStartEv = $iStart;
  571. $iPerPageEv = $iPerPage;
  572. //--- Check for Next
  573. $iPerPageEv += 1;
  574. $aEvents = $this->_oDb->getEvents(array(
  575. 'type' => 'outline',
  576. 'order' => $sOrder,
  577. 'start' => $iStartEv,
  578. 'count' => $iPerPageEv,
  579. 'filter' => $sFilter,
  580. 'modules' => $aModules
  581. ));
  582. //--- Check for Next
  583. $bNext = false;
  584. if(count($aEvents) > $iPerPage) {
  585. $aEvent = array_pop($aEvents);
  586. $bNext = true;
  587. }
  588. $iEvents = count($aEvents);
  589. foreach($aEvents as $aEvent) {
  590. if(empty($aEvent['action']))
  591. continue;
  592. $aEvent['content'] = $this->_oTemplate->getSystem($aEvent, BX_WALL_VIEW_OUTLINE);
  593. if(empty($aEvent['content']))
  594. continue;
  595. $sContent .= $aEvent['content'];
  596. }
  597. $sPaginate = $this->_getLoadMoreOutline($iStart, $iPerPage, $bNext, $iEvents > 0);
  598. return array($sContent, $sPaginate);
  599. }
  600. /*
  601. function _getLoadMoreOutline($iStart, $iPerPage, $bEnabled = true, $bVisible = true)
  602. {
  603. return $this->_oTemplate->getLoadMoreOutline($iStart, $iPerPage, $bEnabled, $bVisible);
  604. }
  605. function _getPaginate($sFilter, $sTimeline, $aModules)
  606. {
  607. return new BxDolPaginate(array(
  608. 'page_url' => 'javascript:void(0);',
  609. 'start' => 0,
  610. 'count' => $this->_oDb->getEventsCount($this->_iOwnerId, $sFilter, $sTimeline, $aModules),
  611. 'per_page' => $this->_oConfig->getPerPage(),
  612. 'on_change_page' => $this->_sJsViewObject . '.changePage({start}, {per_page})',
  613. 'on_change_per_page' => $this->_sJsViewObject . '.changePerPage(this)',
  614. 'page_reloader' => true
  615. ));
  616. }
  617. function _addHidden($sPostType = "photos", $sContentType = "upload", $sAction = "post")
  618. {
  619. return array(
  620. 'WallOwnerId' => array (
  621. 'type' => 'hidden',
  622. 'name' => 'WallOwnerId',
  623. 'value' => $this->_iOwnerId,
  624. ),
  625. 'WallPostAction' => array (
  626. 'type' => 'hidden',
  627. 'name' => 'WallPostAction',
  628. 'value' => $sAction,
  629. ),
  630. 'WallPostType' => array (
  631. 'type' => 'hidden',
  632. 'name' => 'WallPostType',
  633. 'value' => $sPostType,
  634. ),
  635. 'WallContentType' => array (
  636. 'type' => 'hidden',
  637. 'name' => 'WallContentType',
  638. 'value' => $sContentType,
  639. ),
  640. );
  641. }
  642. function serviceGetSubscriptionParams($sUnit, $sAction, $iObjectId)
  643. {
  644. $sUnit = str_replace('bx_', '_', $sUnit);
  645. if(empty($sAction))
  646. $sAction = 'main';
  647. $aProfileInfo = getProfileInfo($iObjectId);
  648. return array(
  649. 'template' => array(
  650. 'Subscription' => _t($sUnit . '_sbs_' . $sAction, $aProfileInfo['NickName']),
  651. 'ViewLink' => BX_DOL_URL_ROOT . $this->_oConfig->getBaseUri() . 'index/' . $aProfileInfo['NickName']
  652. )
  653. );
  654. }
  655. function serviceGetSpyData()
  656. {
  657. $AlertName = $this->_oConfig->getAlertSystemName();
  658. return array(
  659. 'handlers' => array(
  660. array('alert_unit' => $AlertName, 'alert_action' => 'post', 'module_uri' => $this->_oConfig->getUri(), 'module_class' => 'Module', 'module_method' => 'get_spy_post'),
  661. array('alert_unit' => $AlertName, 'alert_action' => 'commentPost', 'module_uri' => $this->_oConfig->getUri(), 'module_class' => 'Module', 'module_method' => 'get_spy_post'),
  662. ),
  663. 'alerts' => array(
  664. array('unit' => $AlertName, 'action' => 'post'),
  665. array('unit' => $AlertName, 'action' => 'delete'),
  666. array('unit' => $AlertName, 'action' => 'commentPost'),
  667. array('unit' => $AlertName, 'action' => 'commentRemoved')
  668. )
  669. );
  670. }
  671. function serviceGetSpyPost($sAction, $iObjectId = 0, $iSenderId = 0, $aExtraParams = array())
  672. {
  673. $aEvent = $this->_oDb->getEvents(array('type' => 'id', 'object_id' => $iObjectId));
  674. $aEvent = array_shift($aEvent);
  675. $sLangKey = '';
  676. switch ($sAction) {
  677. case 'post':
  678. $sLangKey = '_wall_spy_post';
  679. break;
  680. case 'commentPost':
  681. $sLangKey = '_wall_spy_post_comment';
  682. break;
  683. }
  684. return array(
  685. 'params' => array(
  686. 'profile_link' => getProfileLink($iSenderId),
  687. 'profile_nick' => getNickName($iSenderId),
  688. 'recipient_p_link' => getProfileLink($aEvent['owner_id']),
  689. 'recipient_p_nick' => getNickName($aEvent['owner_id']),
  690. ),
  691. 'recipient_id' => $aEvent['owner_id'],
  692. 'lang_key' => $sLangKey
  693. );
  694. }
  695. */
  696. }
  697. /** @} */