UserApplication.php 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195
  1. <?php
  2. /**
  3. * [Discuz!] (C)2001-2099 Comsenz Inc.
  4. * This is NOT a freeware, use is subject to license terms
  5. *
  6. * $Id: UserApplication.php 33052 2013-04-12 09:39:49Z zhengqingpeng $
  7. */
  8. if(!defined('IN_DISCUZ')) {
  9. exit('Access Denied');
  10. }
  11. class Cloud_Service_Server_UserApplication extends Cloud_Service_Server_Restful {
  12. protected static $_instance;
  13. public static function getInstance() {
  14. if (!(self::$_instance instanceof self)) {
  15. self::$_instance = new self();
  16. }
  17. return self::$_instance;
  18. }
  19. public function onUserApplicationAdd($uId, $appId, $appName, $privacy, $allowSideNav, $allowFeed, $allowProfileLink, $defaultBoxType, $defaultMYML, $defaultProfileLink, $version, $displayMethod, $displayOrder = null, $userPanelArea = null, $canvasTitle = null, $isFullscreen = null , $displayUserPanel = null, $additionalStatus = null) {
  20. global $_G;
  21. $res = $this->getUserSpace($uId);
  22. if (!$res) {
  23. return new Cloud_Service_Server_ErrorResponse('1', "User($uId) Not Exists");
  24. }
  25. $row = C::t('home_userapp')->fetch_by_uid_appid($uId, $appId);
  26. if ($row['appid']) {
  27. $errCode = '170';
  28. $errMessage = 'Application has been already added';
  29. return new Cloud_Service_Server_ErrorResponse($errCode, $errMessage);
  30. }
  31. switch($privacy) {
  32. case 'public':
  33. $privacy = 0;
  34. break;
  35. case 'friends':
  36. $privacy = 1;
  37. break;
  38. case 'me':
  39. $privacy = 3;
  40. break;
  41. case 'none':
  42. $privacy = 5;
  43. break;
  44. default:
  45. $privacy = 0;
  46. }
  47. $narrow = ($defaultBoxType == 'narrow') ? 1 : 0;
  48. $setarr = array('uid' => $uId,
  49. 'appid' => $appId,
  50. 'appname' => $appName,
  51. 'privacy' => $privacy,
  52. 'allowsidenav' => $allowSideNav,
  53. 'allowfeed' => $allowFeed,
  54. 'allowprofilelink' => $allowProfileLink,
  55. 'narrow' => $narrow
  56. );
  57. if ($displayOrder !== null) {
  58. $setarr['displayorder'] = $displayOrder;
  59. }
  60. $maxMenuOrder = C::t('home_userapp')->fetch_max_menuorder_by_uid($uId);
  61. $setarr['menuorder'] = ++$maxMenuOrder;
  62. C::t('home_userapp')->insert($setarr);
  63. $fields = array('uid' => $uId,
  64. 'appid' => $appId,
  65. 'profilelink' => $defaultProfileLink,
  66. 'myml' => $defaultMYML
  67. );
  68. $result = C::t('home_userappfield')->insert($fields, true);
  69. updatecreditbyaction('installapp', $uId, array(), $appId);
  70. require_once libfile('function/cache');
  71. updatecache('userapp');
  72. C::t('common_member_status')->update($uId, array('lastactivity' => TIMESTAMP), 'UNBUFFERED');
  73. $displayMethod = ($displayMethod == 'iframe') ? 1 : 0;
  74. $this->refreshApplication($appId, $appName, $version, $userPanelArea, $canvasTitle, $isFullscreen, $displayUserPanel, $displayMethod, $narrow, null, null, $additionalStatus);
  75. return 1;
  76. }
  77. public function onUserApplicationRemove($uId, $appIds) {
  78. $result = C::t('home_userapp')->delete_by_uid_appid($uId, $appIds);
  79. C::t('home_userappfield')->delete_by_uid_appid($uId, $appIds);
  80. updatecreditbyaction('installapp', $uId, array(), $appId, -1);
  81. require_once libfile('function/cache');
  82. updatecache('userapp');
  83. return $result;
  84. }
  85. public function onUserApplicationUpdate($uId, $appIds, $appName, $privacy, $allowSideNav, $allowFeed, $allowProfileLink, $version, $displayMethod, $displayOrder = null, $userPanelArea = null, $canvasTitle = null, $isFullscreen = null, $displayUserPanel = null) {
  86. switch($privacy) {
  87. case 'public':
  88. $privacy = 0;
  89. break;
  90. case 'friends':
  91. $privacy = 1;
  92. break;
  93. case 'me':
  94. $privacy = 3;
  95. break;
  96. case 'none':
  97. $privacy = 5;
  98. break;
  99. default:
  100. $privacy = 0;
  101. }
  102. $setarr = array(
  103. 'appname' => $appName,
  104. 'privacy' => $privacy,
  105. 'allowsidenav' => $allowSideNav,
  106. 'allowfeed' => $allowFeed,
  107. 'allowprofilelink' => $allowProfileLink
  108. );
  109. if ($displayOrder !== null) {
  110. $setarr['displayorder'] = $displayOrder;
  111. $setarr['menuorder'] = $displayOrder;
  112. }
  113. $result = C::t('home_userapp')->update_by_uid_appid($uId, $appIds, $setarr);
  114. $displayMethod = ($displayMethod == 'iframe') ? 1 : 0;
  115. if (is_array($appIds)) {
  116. foreach($appIds as $appId) {
  117. $this->refreshApplication($appId, $appName, $version, $userPanelArea, $canvasTitle, $isFullscreen, $displayUserPanel, $displayMethod, null, null, null, null);
  118. }
  119. }
  120. return $result;
  121. }
  122. public function onUserApplicationGetInstalled($uId) {
  123. $result = array();
  124. foreach(C::t('home_userapp')->fetch_all_by_uid_appid($uId) as $userApp) {
  125. $result[] = $userApp['appid'];
  126. }
  127. return $result;
  128. }
  129. public function onUserApplicationGet($uId, $appIds) {
  130. $result = array();
  131. foreach(C::t('home_userapp')->fetch_all_by_uid_appid($uId, $appIds) as $userApp) {
  132. switch($userApp['privacy']) {
  133. case 0:
  134. $privacy = 'public';
  135. break;
  136. case 1:
  137. $privacy = 'friends';
  138. break;
  139. case 3:
  140. $privacy = 'me';
  141. break;
  142. case 5:
  143. $privacy = 'none';
  144. break;
  145. default:
  146. $privacy = 'public';
  147. }
  148. $result[] = array(
  149. 'appId' => $userApp['appid'],
  150. 'privacy' => $privacy,
  151. 'allowSideNav' => $userApp['allowsidenav'],
  152. 'allowFeed' => $userApp['allowfeed'],
  153. 'allowProfileLink' => $userApp['allowprofilelink'],
  154. 'displayOrder' => $userApp['displayorder']
  155. );
  156. }
  157. return $result;
  158. }
  159. }