1
0

personal.php 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283
  1. <?php
  2. /**
  3. * @copyright Copyright (c) 2016, ownCloud, Inc.
  4. *
  5. * @author Arthur Schiwon <blizzz@arthur-schiwon.de>
  6. * @author Bart Visscher <bartv@thisnet.nl>
  7. * @author Björn Schießle <bjoern@schiessle.org>
  8. * @author Christopher Schäpers <kondou@ts.unde.re>
  9. * @author Christoph Wurst <christoph@owncloud.com>
  10. * @author Georg Ehrke <georg@owncloud.com>
  11. * @author Jakob Sack <mail@jakobsack.de>
  12. * @author Jan-Christoph Borchardt <hey@jancborchardt.net>
  13. * @author Joas Schilling <coding@schilljs.com>
  14. * @author Lukas Reschke <lukas@statuscode.ch>
  15. * @author Marvin Thomas Rabe <mrabe@marvinrabe.de>
  16. * @author Morris Jobke <hey@morrisjobke.de>
  17. * @author Robin Appelman <robin@icewind.nl>
  18. * @author Roeland Jago Douma <roeland@famdouma.nl>
  19. * @author Thomas Müller <thomas.mueller@tmit.eu>
  20. * @author Vincent Petry <pvince81@owncloud.com>
  21. * @author Volkan Gezer <volkangezer@gmail.com>
  22. *
  23. * @license AGPL-3.0
  24. *
  25. * This code is free software: you can redistribute it and/or modify
  26. * it under the terms of the GNU Affero General Public License, version 3,
  27. * as published by the Free Software Foundation.
  28. *
  29. * This program is distributed in the hope that it will be useful,
  30. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  31. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  32. * GNU Affero General Public License for more details.
  33. *
  34. * You should have received a copy of the GNU Affero General Public License, version 3,
  35. * along with this program. If not, see <http://www.gnu.org/licenses/>
  36. *
  37. */
  38. OC_Util::checkLoggedIn();
  39. $defaults = \OC::$server->getThemingDefaults();
  40. $certificateManager = \OC::$server->getCertificateManager();
  41. $accountManager = new \OC\Accounts\AccountManager(
  42. \OC::$server->getDatabaseConnection(),
  43. \OC::$server->getEventDispatcher(),
  44. \OC::$server->getJobList()
  45. );
  46. $config = \OC::$server->getConfig();
  47. $urlGenerator = \OC::$server->getURLGenerator();
  48. // Highlight navigation entry
  49. OC_Util::addScript('settings', 'authtoken');
  50. OC_Util::addScript('settings', 'authtoken_collection');
  51. OC_Util::addScript('settings', 'authtoken_view');
  52. OC_Util::addScript('settings', 'usersettings');
  53. OC_Util::addScript('settings', 'federationsettingsview');
  54. OC_Util::addScript('settings', 'federationscopemenu');
  55. OC_Util::addScript('settings', 'personal');
  56. OC_Util::addScript('settings', 'certificates');
  57. OC_Util::addStyle( 'settings', 'settings' );
  58. \OC_Util::addVendorScript('strengthify/jquery.strengthify');
  59. \OC_Util::addVendorStyle('strengthify/strengthify');
  60. \OC_Util::addScript('files', 'jquery.fileupload');
  61. \OC_Util::addVendorScript('jcrop/js/jquery.Jcrop');
  62. \OC_Util::addVendorStyle('jcrop/css/jquery.Jcrop');
  63. \OC::$server->getEventDispatcher()->dispatch('OC\Settings\Personal::loadAdditionalScripts');
  64. // Highlight navigation entry
  65. OC::$server->getNavigationManager()->setActiveEntry('personal');
  66. $storageInfo=OC_Helper::getStorageInfo('/');
  67. $user = OC::$server->getUserManager()->get(OC_User::getUser());
  68. $forceLanguage = $config->getSystemValue('force_language', false);
  69. if ($forceLanguage === false) {
  70. $userLang=$config->getUserValue( OC_User::getUser(), 'core', 'lang', \OC::$server->getL10NFactory()->findLanguage() );
  71. $languageCodes = \OC::$server->getL10NFactory()->findAvailableLanguages();
  72. // array of common languages
  73. $commonLangCodes = array(
  74. 'en', 'es', 'fr', 'de', 'de_DE', 'ja', 'ar', 'ru', 'nl', 'it', 'pt_BR', 'pt_PT', 'da', 'fi_FI', 'nb_NO', 'sv', 'tr', 'zh_CN', 'ko'
  75. );
  76. $languages=array();
  77. $commonLanguages = array();
  78. foreach($languageCodes as $lang) {
  79. $l = \OC::$server->getL10N('settings', $lang);
  80. // TRANSLATORS this is the language name for the language switcher in the personal settings and should be the localized version
  81. $potentialName = (string) $l->t('__language_name__');
  82. if($l->getLanguageCode() === $lang && substr($potentialName, 0, 1) !== '_') {//first check if the language name is in the translation file
  83. $ln = array('code' => $lang, 'name' => $potentialName);
  84. } elseif ($lang === 'en') {
  85. $ln = ['code' => $lang, 'name' => 'English (US)'];
  86. }else{//fallback to language code
  87. $ln=array('code'=>$lang, 'name'=>$lang);
  88. }
  89. // put appropriate languages into appropriate arrays, to print them sorted
  90. // used language -> common languages -> divider -> other languages
  91. if ($lang === $userLang) {
  92. $userLang = $ln;
  93. } elseif (in_array($lang, $commonLangCodes)) {
  94. $commonLanguages[array_search($lang, $commonLangCodes)]=$ln;
  95. } else {
  96. $languages[]=$ln;
  97. }
  98. }
  99. // if user language is not available but set somehow: show the actual code as name
  100. if (!is_array($userLang)) {
  101. $userLang = [
  102. 'code' => $userLang,
  103. 'name' => $userLang,
  104. ];
  105. }
  106. ksort($commonLanguages);
  107. // sort now by displayed language not the iso-code
  108. usort( $languages, function ($a, $b) {
  109. if ($a['code'] === $a['name'] && $b['code'] !== $b['name']) {
  110. // If a doesn't have a name, but b does, list b before a
  111. return 1;
  112. }
  113. if ($a['code'] !== $a['name'] && $b['code'] === $b['name']) {
  114. // If a does have a name, but b doesn't, list a before b
  115. return -1;
  116. }
  117. // Otherwise compare the names
  118. return strcmp($a['name'], $b['name']);
  119. });
  120. }
  121. //links to clients
  122. $clients = array(
  123. 'desktop' => $config->getSystemValue('customclient_desktop', $defaults->getSyncClientUrl()),
  124. 'android' => $config->getSystemValue('customclient_android', $defaults->getAndroidClientUrl()),
  125. 'ios' => $config->getSystemValue('customclient_ios', $defaults->getiOSClientUrl())
  126. );
  127. // only show root certificate import if external storages are enabled
  128. $enableCertImport = false;
  129. $externalStorageEnabled = \OC::$server->getAppManager()->isEnabledForUser('files_external');
  130. if ($externalStorageEnabled) {
  131. /** @var \OCA\Files_External\Service\BackendService $backendService */
  132. $backendService = \OC_Mount_Config::$app->getContainer()->query('\OCA\Files_External\Service\BackendService');
  133. $enableCertImport = $backendService->isUserMountingAllowed();
  134. }
  135. // Return template
  136. $l = \OC::$server->getL10N('settings');
  137. $tmpl = new OC_Template( 'settings', 'personal', 'user');
  138. $tmpl->assign('usage', OC_Helper::humanFileSize($storageInfo['used']));
  139. if ($storageInfo['quota'] === \OCP\Files\FileInfo::SPACE_UNLIMITED) {
  140. $totalSpace = $l->t('Unlimited');
  141. } else {
  142. $totalSpace = OC_Helper::humanFileSize($storageInfo['total']);
  143. }
  144. $uid = $user->getUID();
  145. $userData = $accountManager->getUser($user);
  146. $tmpl->assign('total_space', $totalSpace);
  147. $tmpl->assign('usage_relative', $storageInfo['relative']);
  148. $tmpl->assign('quota', $storageInfo['quota']);
  149. $tmpl->assign('clients', $clients);
  150. $tmpl->assign('email', $userData[\OC\Accounts\AccountManager::PROPERTY_EMAIL]['value']);
  151. if ($forceLanguage === false) {
  152. $tmpl->assign('languages', $languages);
  153. $tmpl->assign('commonlanguages', $commonLanguages);
  154. $tmpl->assign('activelanguage', $userLang);
  155. }
  156. $tmpl->assign('passwordChangeSupported', OC_User::canUserChangePassword(OC_User::getUser()));
  157. $tmpl->assign('displayNameChangeSupported', OC_User::canUserChangeDisplayName(OC_User::getUser()));
  158. $tmpl->assign('displayName', $userData[\OC\Accounts\AccountManager::PROPERTY_DISPLAYNAME]['value']);
  159. $tmpl->assign('phone', $userData[\OC\Accounts\AccountManager::PROPERTY_PHONE]['value']);
  160. $tmpl->assign('website', $userData[\OC\Accounts\AccountManager::PROPERTY_WEBSITE]['value']);
  161. $tmpl->assign('twitter', $userData[\OC\Accounts\AccountManager::PROPERTY_TWITTER]['value']);
  162. $tmpl->assign('address', $userData[\OC\Accounts\AccountManager::PROPERTY_ADDRESS]['value']);
  163. $tmpl->assign('avatarScope', $userData[\OC\Accounts\AccountManager::PROPERTY_AVATAR]['scope']);
  164. $tmpl->assign('displayNameScope', $userData[\OC\Accounts\AccountManager::PROPERTY_DISPLAYNAME]['scope']);
  165. $tmpl->assign('phoneScope', $userData[\OC\Accounts\AccountManager::PROPERTY_PHONE]['scope']);
  166. $tmpl->assign('emailScope', $userData[\OC\Accounts\AccountManager::PROPERTY_EMAIL]['scope']);
  167. $tmpl->assign('websiteScope', $userData[\OC\Accounts\AccountManager::PROPERTY_WEBSITE]['scope']);
  168. $tmpl->assign('twitterScope', $userData[\OC\Accounts\AccountManager::PROPERTY_TWITTER]['scope']);
  169. $tmpl->assign('addressScope', $userData[\OC\Accounts\AccountManager::PROPERTY_ADDRESS]['scope']);
  170. $tmpl->assign('websiteVerification', $userData[\OC\Accounts\AccountManager::PROPERTY_WEBSITE]['verified']);
  171. $tmpl->assign('twitterVerification', $userData[\OC\Accounts\AccountManager::PROPERTY_TWITTER]['verified']);
  172. $tmpl->assign('emailVerification', $userData[\OC\Accounts\AccountManager::PROPERTY_EMAIL]['verified']);
  173. $needVerifyMessage = [\OC\Accounts\AccountManager::PROPERTY_EMAIL, \OC\Accounts\AccountManager::PROPERTY_WEBSITE, \OC\Accounts\AccountManager::PROPERTY_TWITTER];
  174. foreach ($needVerifyMessage as $property) {
  175. switch ($userData[$property]['verified']) {
  176. case \OC\Accounts\AccountManager::VERIFIED:
  177. $message = $l->t('Verifying');
  178. break;
  179. case \OC\Accounts\AccountManager::VERIFICATION_IN_PROGRESS:
  180. $message = $l->t('Verifying …');
  181. break;
  182. default:
  183. $message = $l->t('Verify');
  184. }
  185. $tmpl->assign($property . 'Message', $message);
  186. }
  187. $tmpl->assign('avatarChangeSupported', OC_User::canUserChangeAvatar(OC_User::getUser()));
  188. $tmpl->assign('certs', $certificateManager->listCertificates());
  189. $tmpl->assign('showCertificates', $enableCertImport);
  190. $tmpl->assign('urlGenerator', $urlGenerator);
  191. $federatedFileSharingEnabled = \OC::$server->getAppManager()->isEnabledForUser('federatedfilesharing');
  192. $lookupServerUploadEnabled = false;
  193. if ($federatedFileSharingEnabled) {
  194. $federatedFileSharing = new \OCA\FederatedFileSharing\AppInfo\Application();
  195. $shareProvider = $federatedFileSharing->getFederatedShareProvider();
  196. $lookupServerUploadEnabled = $shareProvider->isLookupServerUploadEnabled();
  197. }
  198. $tmpl->assign('lookupServerUploadEnabled', $lookupServerUploadEnabled);
  199. // Get array of group ids for this user
  200. $groups = \OC::$server->getGroupManager()->getUserIdGroups(OC_User::getUser());
  201. $groups2 = array_map(function($group) { return $group->getGID(); }, $groups);
  202. sort($groups2);
  203. $tmpl->assign('groups', $groups2);
  204. // add hardcoded forms from the template
  205. $formsAndMore = [];
  206. $formsAndMore[]= ['anchor' => 'personal-settings', 'section-name' => $l->t('Personal info')];
  207. if (\OC::$server->getAppManager()->isEnabledForUser('firstrunwizard')) {
  208. $formsAndMore[]= ['anchor' => 'clientsbox', 'section-name' => $l->t('Sync clients')];
  209. }
  210. $formsAndMore[]= ['anchor' => 'security', 'section-name' => $l->t('Security')];
  211. $forms=OC_App::getForms('personal');
  212. // add bottom hardcoded forms from the template
  213. if ($enableCertImport) {
  214. $certificatesTemplate = new OC_Template('settings', 'certificates');
  215. $certificatesTemplate->assign('type', 'personal');
  216. $certificatesTemplate->assign('uploadRoute', 'settings.Certificate.addPersonalRootCertificate');
  217. $certificatesTemplate->assign('certs', $certificateManager->listCertificates());
  218. $certificatesTemplate->assign('urlGenerator', $urlGenerator);
  219. $forms[] = $certificatesTemplate->fetchPage();
  220. }
  221. $formsMap = array_map(function($form){
  222. if (preg_match('%(<h2(?P<class>[^>]*)>.*?</h2>)%i', $form, $regs)) {
  223. $sectionName = str_replace('<h2'.$regs['class'].'>', '', $regs[0]);
  224. $sectionName = str_replace('</h2>', '', $sectionName);
  225. if (strpos($regs['class'], 'data-anchor-name') !== false) {
  226. preg_match('%.*data-anchor-name="(?P<anchor>[^"]*)"%i', $regs['class'], $matches);
  227. $anchor = $matches['anchor'];
  228. } else {
  229. $anchor = strtolower($sectionName);
  230. $anchor = str_replace(' ', '-', $anchor);
  231. }
  232. return array(
  233. 'anchor' => $anchor,
  234. 'section-name' => $sectionName,
  235. 'form' => $form
  236. );
  237. }
  238. return array(
  239. 'form' => $form
  240. );
  241. }, $forms);
  242. $formsAndMore = array_merge($formsAndMore, $formsMap);
  243. $tmpl->assign('forms', $formsAndMore);
  244. $tmpl->printPage();