personal.php 8.5 KB

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