BxTimelineModule.php 35 KB

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