personal.php 7.0 KB

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