personal.php 8.1 KB

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