personal.php 9.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240
  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(\OC::$server->getDatabaseConnection(), \OC::$server->getEventDispatcher());
  42. $config = \OC::$server->getConfig();
  43. $urlGenerator = \OC::$server->getURLGenerator();
  44. // Highlight navigation entry
  45. OC_Util::addScript('settings', 'authtoken');
  46. OC_Util::addScript('settings', 'authtoken_collection');
  47. OC_Util::addScript('settings', 'authtoken_view');
  48. OC_Util::addScript('settings', 'usersettings');
  49. OC_Util::addScript('settings', 'federationsettingsview');
  50. OC_Util::addScript('settings', 'federationscopemenu');
  51. OC_Util::addScript('settings', 'personal');
  52. OC_Util::addScript('settings', 'certificates');
  53. OC_Util::addStyle( 'settings', 'settings' );
  54. \OC_Util::addVendorScript('strengthify/jquery.strengthify');
  55. \OC_Util::addVendorStyle('strengthify/strengthify');
  56. \OC_Util::addScript('files', 'jquery.fileupload');
  57. if ($config->getSystemValue('enable_avatars', true) === true) {
  58. \OC_Util::addVendorScript('jcrop/js/jquery.Jcrop');
  59. \OC_Util::addVendorStyle('jcrop/css/jquery.Jcrop');
  60. }
  61. \OC::$server->getEventDispatcher()->dispatch('OC\Settings\Personal::loadAdditionalScripts');
  62. // Highlight navigation entry
  63. OC::$server->getNavigationManager()->setActiveEntry('personal');
  64. $storageInfo=OC_Helper::getStorageInfo('/');
  65. $user = OC::$server->getUserManager()->get(OC_User::getUser());
  66. $userLang=$config->getUserValue( OC_User::getUser(), 'core', 'lang', \OC::$server->getL10NFactory()->findLanguage() );
  67. $languageCodes = \OC::$server->getL10NFactory()->findAvailableLanguages();
  68. // array of common languages
  69. $commonLangCodes = array(
  70. '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'
  71. );
  72. $languageNames=include 'languageCodes.php';
  73. $languages=array();
  74. $commonLanguages = array();
  75. foreach($languageCodes as $lang) {
  76. $l = \OC::$server->getL10N('settings', $lang);
  77. // TRANSLATORS this is the language name for the language switcher in the personal settings and should be the localized version
  78. $potentialName = (string) $l->t('__language_name__');
  79. if($l->getLanguageCode() === $lang && substr($potentialName, 0, 1) !== '_') {//first check if the language name is in the translation file
  80. $ln=array('code'=>$lang, 'name'=> $potentialName);
  81. }elseif(isset($languageNames[$lang])) {
  82. $ln=array('code'=>$lang, 'name'=>$languageNames[$lang]);
  83. }else{//fallback to language code
  84. $ln=array('code'=>$lang, 'name'=>$lang);
  85. }
  86. // put appropriate languages into appropriate arrays, to print them sorted
  87. // used language -> common languages -> divider -> other languages
  88. if ($lang === $userLang) {
  89. $userLang = $ln;
  90. } elseif (in_array($lang, $commonLangCodes)) {
  91. $commonLanguages[array_search($lang, $commonLangCodes)]=$ln;
  92. } else {
  93. $languages[]=$ln;
  94. }
  95. }
  96. // if user language is not available but set somehow: show the actual code as name
  97. if (!is_array($userLang)) {
  98. $userLang = [
  99. 'code' => $userLang,
  100. 'name' => $userLang,
  101. ];
  102. }
  103. ksort($commonLanguages);
  104. // sort now by displayed language not the iso-code
  105. usort( $languages, function ($a, $b) {
  106. if ($a['code'] === $a['name'] && $b['code'] !== $b['name']) {
  107. // If a doesn't have a name, but b does, list b before a
  108. return 1;
  109. }
  110. if ($a['code'] !== $a['name'] && $b['code'] === $b['name']) {
  111. // If a does have a name, but b doesn't, list a before b
  112. return -1;
  113. }
  114. // Otherwise compare the names
  115. return strcmp($a['name'], $b['name']);
  116. });
  117. //links to clients
  118. $clients = array(
  119. 'desktop' => $config->getSystemValue('customclient_desktop', $defaults->getSyncClientUrl()),
  120. 'android' => $config->getSystemValue('customclient_android', $defaults->getAndroidClientUrl()),
  121. 'ios' => $config->getSystemValue('customclient_ios', $defaults->getiOSClientUrl())
  122. );
  123. // only show root certificate import if external storages are enabled
  124. $enableCertImport = false;
  125. $externalStorageEnabled = \OC::$server->getAppManager()->isEnabledForUser('files_external');
  126. if ($externalStorageEnabled) {
  127. /** @var \OCA\Files_External\Service\BackendService $backendService */
  128. $backendService = \OC_Mount_Config::$app->getContainer()->query('\OCA\Files_External\Service\BackendService');
  129. $enableCertImport = $backendService->isUserMountingAllowed();
  130. }
  131. // Return template
  132. $l = \OC::$server->getL10N('settings');
  133. $tmpl = new OC_Template( 'settings', 'personal', 'user');
  134. $tmpl->assign('usage', OC_Helper::humanFileSize($storageInfo['used']));
  135. if ($storageInfo['quota'] === \OCP\Files\FileInfo::SPACE_UNLIMITED) {
  136. $totalSpace = $l->t('Unlimited');
  137. } else {
  138. $totalSpace = OC_Helper::humanFileSize($storageInfo['total']);
  139. }
  140. $uid = $user->getUID();
  141. $userData = $accountManager->getUser($user);
  142. $tmpl->assign('total_space', $totalSpace);
  143. $tmpl->assign('usage_relative', $storageInfo['relative']);
  144. $tmpl->assign('clients', $clients);
  145. $tmpl->assign('email', $userData[\OC\Accounts\AccountManager::PROPERTY_EMAIL]['value']);
  146. $tmpl->assign('languages', $languages);
  147. $tmpl->assign('commonlanguages', $commonLanguages);
  148. $tmpl->assign('activelanguage', $userLang);
  149. $tmpl->assign('passwordChangeSupported', OC_User::canUserChangePassword(OC_User::getUser()));
  150. $tmpl->assign('displayNameChangeSupported', OC_User::canUserChangeDisplayName(OC_User::getUser()));
  151. $tmpl->assign('displayName', $userData[\OC\Accounts\AccountManager::PROPERTY_DISPLAYNAME]['value']);
  152. $tmpl->assign('phone', $userData[\OC\Accounts\AccountManager::PROPERTY_PHONE]['value']);
  153. $tmpl->assign('website', $userData[\OC\Accounts\AccountManager::PROPERTY_WEBSITE]['value']);
  154. $tmpl->assign('twitter', $userData[\OC\Accounts\AccountManager::PROPERTY_TWITTER]['value']);
  155. $tmpl->assign('address', $userData[\OC\Accounts\AccountManager::PROPERTY_ADDRESS]['value']);
  156. $tmpl->assign('avatarScope', $userData[\OC\Accounts\AccountManager::PROPERTY_AVATAR]['scope']);
  157. $tmpl->assign('displayNameScope', $userData[\OC\Accounts\AccountManager::PROPERTY_DISPLAYNAME]['scope']);
  158. $tmpl->assign('phoneScope', $userData[\OC\Accounts\AccountManager::PROPERTY_PHONE]['scope']);
  159. $tmpl->assign('emailScope', $userData[\OC\Accounts\AccountManager::PROPERTY_EMAIL]['scope']);
  160. $tmpl->assign('websiteScope', $userData[\OC\Accounts\AccountManager::PROPERTY_WEBSITE]['scope']);
  161. $tmpl->assign('twitterScope', $userData[\OC\Accounts\AccountManager::PROPERTY_TWITTER]['scope']);
  162. $tmpl->assign('addressScope', $userData[\OC\Accounts\AccountManager::PROPERTY_ADDRESS]['scope']);
  163. $tmpl->assign('enableAvatars', $config->getSystemValue('enable_avatars', true) === true);
  164. $tmpl->assign('avatarChangeSupported', OC_User::canUserChangeAvatar(OC_User::getUser()));
  165. $tmpl->assign('certs', $certificateManager->listCertificates());
  166. $tmpl->assign('showCertificates', $enableCertImport);
  167. $tmpl->assign('urlGenerator', $urlGenerator);
  168. // Get array of group ids for this user
  169. $groups = \OC::$server->getGroupManager()->getUserIdGroups(OC_User::getUser());
  170. $groups2 = array_map(function($group) { return $group->getGID(); }, $groups);
  171. sort($groups2);
  172. $tmpl->assign('groups', $groups2);
  173. // add hardcoded forms from the template
  174. $formsAndMore = [];
  175. $formsAndMore[]= ['anchor' => 'avatar', 'section-name' => $l->t('Personal info')];
  176. $formsAndMore[]= ['anchor' => 'sessions', 'section-name' => $l->t('Sessions')];
  177. $formsAndMore[]= ['anchor' => 'apppasswords', 'section-name' => $l->t('App passwords')];
  178. $formsAndMore[]= ['anchor' => 'clientsbox', 'section-name' => $l->t('Sync clients')];
  179. $forms=OC_App::getForms('personal');
  180. // add bottom hardcoded forms from the template
  181. if ($enableCertImport) {
  182. $certificatesTemplate = new OC_Template('settings', 'certificates');
  183. $certificatesTemplate->assign('type', 'personal');
  184. $certificatesTemplate->assign('uploadRoute', 'settings.Certificate.addPersonalRootCertificate');
  185. $certificatesTemplate->assign('certs', $certificateManager->listCertificates());
  186. $certificatesTemplate->assign('urlGenerator', $urlGenerator);
  187. $forms[] = $certificatesTemplate->fetchPage();
  188. }
  189. $formsMap = array_map(function($form){
  190. if (preg_match('%(<h2(?P<class>[^>]*)>.*?</h2>)%i', $form, $regs)) {
  191. $sectionName = str_replace('<h2'.$regs['class'].'>', '', $regs[0]);
  192. $sectionName = str_replace('</h2>', '', $sectionName);
  193. $anchor = strtolower($sectionName);
  194. $anchor = str_replace(' ', '-', $anchor);
  195. return array(
  196. 'anchor' => $anchor,
  197. 'section-name' => $sectionName,
  198. 'form' => $form
  199. );
  200. }
  201. return array(
  202. 'form' => $form
  203. );
  204. }, $forms);
  205. $formsAndMore = array_merge($formsAndMore, $formsMap);
  206. $tmpl->assign('forms', $formsAndMore);
  207. $tmpl->printPage();