personal.php 8.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218
  1. <?php
  2. /**
  3. * @author Arthur Schiwon <blizzz@arthur-schiwon.de>
  4. * @author Bart Visscher <bartv@thisnet.nl>
  5. * @author Björn Schießle <bjoern@schiessle.org>
  6. * @author Christoph Wurst <christoph@owncloud.com>
  7. * @author Christopher Schäpers <kondou@ts.unde.re>
  8. * @author Georg Ehrke <georg@owncloud.com>
  9. * @author Jakob Sack <mail@jakobsack.de>
  10. * @author Jan-Christoph Borchardt <hey@jancborchardt.net>
  11. * @author Joas Schilling <nickvergessen@owncloud.com>
  12. * @author Lukas Reschke <lukas@statuscode.ch>
  13. * @author Marvin Thomas Rabe <mrabe@marvinrabe.de>
  14. * @author Morris Jobke <hey@morrisjobke.de>
  15. * @author Robin Appelman <icewind@owncloud.com>
  16. * @author Roeland Jago Douma <rullzer@owncloud.com>
  17. * @author Thomas Müller <thomas.mueller@tmit.eu>
  18. * @author Vincent Petry <pvince81@owncloud.com>
  19. * @author Volkan Gezer <volkangezer@gmail.com>
  20. *
  21. * @copyright Copyright (c) 2016, ownCloud, Inc.
  22. * @license AGPL-3.0
  23. *
  24. * This code is free software: you can redistribute it and/or modify
  25. * it under the terms of the GNU Affero General Public License, version 3,
  26. * as published by the Free Software Foundation.
  27. *
  28. * This program is distributed in the hope that it will be useful,
  29. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  30. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  31. * GNU Affero General Public License for more details.
  32. *
  33. * You should have received a copy of the GNU Affero General Public License, version 3,
  34. * along with this program. If not, see <http://www.gnu.org/licenses/>
  35. *
  36. */
  37. OC_Util::checkLoggedIn();
  38. $defaults = new OC_Defaults(); // initialize themable default strings and urls
  39. $certificateManager = \OC::$server->getCertificateManager();
  40. $config = \OC::$server->getConfig();
  41. $urlGenerator = \OC::$server->getURLGenerator();
  42. // Highlight navigation entry
  43. OC_Util::addScript('settings', 'authtoken');
  44. OC_Util::addScript('settings', 'authtoken_collection');
  45. OC_Util::addScript('settings', 'authtoken_view');
  46. OC_Util::addScript( 'settings', 'personal' );
  47. OC_Util::addScript('settings', 'certificates');
  48. OC_Util::addStyle( 'settings', 'settings' );
  49. \OC_Util::addVendorScript('strengthify/jquery.strengthify');
  50. \OC_Util::addVendorStyle('strengthify/strengthify');
  51. \OC_Util::addScript('files', 'jquery.fileupload');
  52. if ($config->getSystemValue('enable_avatars', true) === true) {
  53. \OC_Util::addVendorScript('jcrop/js/jquery.Jcrop');
  54. \OC_Util::addVendorStyle('jcrop/css/jquery.Jcrop');
  55. }
  56. \OC::$server->getEventDispatcher()->dispatch('OC\Settings\Personal::loadAdditionalScripts');
  57. // Highlight navigation entry
  58. OC::$server->getNavigationManager()->setActiveEntry('personal');
  59. $storageInfo=OC_Helper::getStorageInfo('/');
  60. $user = OC::$server->getUserManager()->get(OC_User::getUser());
  61. $email = $user->getEMailAddress();
  62. $userLang=$config->getUserValue( OC_User::getUser(), 'core', 'lang', OC_L10N::findLanguage() );
  63. $languageCodes = \OC::$server->getL10NFactory()->findAvailableLanguages();
  64. // array of common languages
  65. $commonLangCodes = array(
  66. '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'
  67. );
  68. $languageNames=include 'languageCodes.php';
  69. $languages=array();
  70. $commonLanguages = array();
  71. foreach($languageCodes as $lang) {
  72. $l = \OC::$server->getL10N('settings', $lang);
  73. // TRANSLATORS this is the language name for the language switcher in the personal settings and should be the localized version
  74. $potentialName = (string) $l->t('__language_name__');
  75. if($l->getLanguageCode() === $lang && substr($potentialName, 0, 1) !== '_') {//first check if the language name is in the translation file
  76. $ln=array('code'=>$lang, 'name'=> $potentialName);
  77. }elseif(isset($languageNames[$lang])) {
  78. $ln=array('code'=>$lang, 'name'=>$languageNames[$lang]);
  79. }else{//fallback to language code
  80. $ln=array('code'=>$lang, 'name'=>$lang);
  81. }
  82. // put appropriate languages into appropriate arrays, to print them sorted
  83. // used language -> common languages -> divider -> other languages
  84. if ($lang === $userLang) {
  85. $userLang = $ln;
  86. } elseif (in_array($lang, $commonLangCodes)) {
  87. $commonLanguages[array_search($lang, $commonLangCodes)]=$ln;
  88. } else {
  89. $languages[]=$ln;
  90. }
  91. }
  92. // if user language is not available but set somehow: show the actual code as name
  93. if (!is_array($userLang)) {
  94. $userLang = [
  95. 'code' => $userLang,
  96. 'name' => $userLang,
  97. ];
  98. }
  99. ksort($commonLanguages);
  100. // sort now by displayed language not the iso-code
  101. usort( $languages, function ($a, $b) {
  102. if ($a['code'] === $a['name'] && $b['code'] !== $b['name']) {
  103. // If a doesn't have a name, but b does, list b before a
  104. return 1;
  105. }
  106. if ($a['code'] !== $a['name'] && $b['code'] === $b['name']) {
  107. // If a does have a name, but b doesn't, list a before b
  108. return -1;
  109. }
  110. // Otherwise compare the names
  111. return strcmp($a['name'], $b['name']);
  112. });
  113. //links to clients
  114. $clients = array(
  115. 'desktop' => $config->getSystemValue('customclient_desktop', $defaults->getSyncClientUrl()),
  116. 'android' => $config->getSystemValue('customclient_android', $defaults->getAndroidClientUrl()),
  117. 'ios' => $config->getSystemValue('customclient_ios', $defaults->getiOSClientUrl())
  118. );
  119. // only show root certificate import if external storages are enabled
  120. $enableCertImport = false;
  121. $externalStorageEnabled = \OC::$server->getAppManager()->isEnabledForUser('files_external');
  122. if ($externalStorageEnabled) {
  123. /** @var \OCA\Files_External\Service\BackendService $backendService */
  124. $backendService = \OC_Mount_Config::$app->getContainer()->query('\OCA\Files_External\Service\BackendService');
  125. $enableCertImport = $backendService->isUserMountingAllowed();
  126. }
  127. // Return template
  128. $l = \OC::$server->getL10N('settings');
  129. $tmpl = new OC_Template( 'settings', 'personal', 'user');
  130. $tmpl->assign('usage', OC_Helper::humanFileSize($storageInfo['used']));
  131. if ($storageInfo['quota'] === \OCP\Files\FileInfo::SPACE_UNLIMITED) {
  132. $totalSpace = $l->t('Unlimited');
  133. } else {
  134. $totalSpace = OC_Helper::humanFileSize($storageInfo['total']);
  135. }
  136. $tmpl->assign('total_space', $totalSpace);
  137. $tmpl->assign('usage_relative', $storageInfo['relative']);
  138. $tmpl->assign('clients', $clients);
  139. $tmpl->assign('email', $email);
  140. $tmpl->assign('languages', $languages);
  141. $tmpl->assign('commonlanguages', $commonLanguages);
  142. $tmpl->assign('activelanguage', $userLang);
  143. $tmpl->assign('passwordChangeSupported', OC_User::canUserChangePassword(OC_User::getUser()));
  144. $tmpl->assign('displayNameChangeSupported', OC_User::canUserChangeDisplayName(OC_User::getUser()));
  145. $tmpl->assign('displayName', OC_User::getDisplayName());
  146. $tmpl->assign('enableAvatars', $config->getSystemValue('enable_avatars', true) === true);
  147. $tmpl->assign('avatarChangeSupported', OC_User::canUserChangeAvatar(OC_User::getUser()));
  148. $tmpl->assign('certs', $certificateManager->listCertificates());
  149. $tmpl->assign('showCertificates', $enableCertImport);
  150. $tmpl->assign('urlGenerator', $urlGenerator);
  151. // Get array of group ids for this user
  152. $groups = \OC::$server->getGroupManager()->getUserIdGroups(OC_User::getUser());
  153. $groups2 = array_map(function($group) { return $group->getGID(); }, $groups);
  154. sort($groups2);
  155. $tmpl->assign('groups', $groups2);
  156. // add hardcoded forms from the template
  157. $formsAndMore = [];
  158. $formsAndMore[]= ['anchor' => 'avatar', 'section-name' => $l->t('Personal info')];
  159. $formsAndMore[]= ['anchor' => 'sessions', 'section-name' => $l->t('Sessions')];
  160. $formsAndMore[]= ['anchor' => 'devices', 'section-name' => $l->t('Devices')];
  161. $formsAndMore[]= ['anchor' => 'clientsbox', 'section-name' => $l->t('Sync clients')];
  162. $forms=OC_App::getForms('personal');
  163. // add bottom hardcoded forms from the template
  164. if ($enableCertImport) {
  165. $certificatesTemplate = new OC_Template('settings', 'certificates');
  166. $certificatesTemplate->assign('type', 'personal');
  167. $certificatesTemplate->assign('uploadRoute', 'settings.Certificate.addPersonalRootCertificate');
  168. $certificatesTemplate->assign('certs', $certificateManager->listCertificates());
  169. $certificatesTemplate->assign('urlGenerator', $urlGenerator);
  170. $forms[] = $certificatesTemplate->fetchPage();
  171. }
  172. $formsMap = array_map(function($form){
  173. if (preg_match('%(<h2(?P<class>[^>]*)>.*?</h2>)%i', $form, $regs)) {
  174. $sectionName = str_replace('<h2'.$regs['class'].'>', '', $regs[0]);
  175. $sectionName = str_replace('</h2>', '', $sectionName);
  176. $anchor = strtolower($sectionName);
  177. $anchor = str_replace(' ', '-', $anchor);
  178. return array(
  179. 'anchor' => $anchor,
  180. 'section-name' => $sectionName,
  181. 'form' => $form
  182. );
  183. }
  184. return array(
  185. 'form' => $form
  186. );
  187. }, $forms);
  188. $formsAndMore = array_merge($formsAndMore, $formsMap);
  189. $tmpl->assign('forms', $formsAndMore);
  190. $tmpl->printPage();