personal.php 6.2 KB

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