personal.php 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  1. <?php
  2. /**
  3. * Copyright (c) 2011, Robin Appelman <icewind1991@gmail.com>
  4. * This file is licensed under the Affero General Public License version 3 or later.
  5. * See the COPYING-README file.
  6. */
  7. OC_Util::checkLoggedIn();
  8. $defaults = new OC_Defaults(); // initialize themable default strings and urls
  9. $certificateManager = \OC::$server->getCertificateManager();
  10. $config = \OC::$server->getConfig();
  11. // Highlight navigation entry
  12. OC_Util::addScript( 'settings', 'personal' );
  13. OC_Util::addStyle( 'settings', 'settings' );
  14. \OC_Util::addVendorScript('strengthify/jquery.strengthify');
  15. \OC_Util::addVendorStyle('strengthify/strengthify');
  16. \OC_Util::addScript('files', 'jquery.fileupload');
  17. if ($config->getSystemValue('enable_avatars', true) === true) {
  18. \OC_Util::addVendorScript('jcrop/js/jquery.Jcrop');
  19. \OC_Util::addVendorStyle('jcrop/css/jquery.Jcrop');
  20. }
  21. // Highlight navigation entry
  22. OC_App::setActiveNavigationEntry( 'personal' );
  23. $storageInfo=OC_Helper::getStorageInfo('/');
  24. $email=$config->getUserValue(OC_User::getUser(), 'settings', 'email', '');
  25. $userLang=$config->getUserValue( OC_User::getUser(), 'core', 'lang', OC_L10N::findLanguage() );
  26. $languageCodes=OC_L10N::findAvailableLanguages();
  27. //check if encryption was enabled in the past
  28. $filesStillEncrypted = OC_Util::encryptedFiles();
  29. $backupKeysExists = OC_Util::backupKeysExists();
  30. $enableDecryptAll = $filesStillEncrypted || $backupKeysExists;
  31. // array of common languages
  32. $commonlangcodes = array(
  33. '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'
  34. );
  35. $languageNames=include 'languageCodes.php';
  36. $languages=array();
  37. $commonlanguages = array();
  38. foreach($languageCodes as $lang) {
  39. $l = \OC::$server->getL10N('settings', $lang);
  40. if(substr($l->t('__language_name__'), 0, 1) !== '_') {//first check if the language name is in the translation file
  41. $ln=array('code'=>$lang, 'name'=> (string)$l->t('__language_name__'));
  42. }elseif(isset($languageNames[$lang])) {
  43. $ln=array('code'=>$lang, 'name'=>$languageNames[$lang]);
  44. }else{//fallback to language code
  45. $ln=array('code'=>$lang, 'name'=>$lang);
  46. }
  47. // put apropriate languages into apropriate arrays, to print them sorted
  48. // used language -> common languages -> divider -> other languages
  49. if ($lang === $userLang) {
  50. $userLang = $ln;
  51. } elseif (in_array($lang, $commonlangcodes)) {
  52. $commonlanguages[array_search($lang, $commonlangcodes)]=$ln;
  53. } else {
  54. $languages[]=$ln;
  55. }
  56. }
  57. ksort($commonlanguages);
  58. // sort now by displayed language not the iso-code
  59. usort( $languages, function ($a, $b) {
  60. return strcmp($a['name'], $b['name']);
  61. });
  62. //links to clients
  63. $clients = array(
  64. 'desktop' => $config->getSystemValue('customclient_desktop', $defaults->getSyncClientUrl()),
  65. 'android' => $config->getSystemValue('customclient_android', $defaults->getAndroidClientUrl()),
  66. 'ios' => $config->getSystemValue('customclient_ios', $defaults->getiOSClientUrl())
  67. );
  68. // Return template
  69. $tmpl = new OC_Template( 'settings', 'personal', 'user');
  70. $tmpl->assign('usage', OC_Helper::humanFileSize($storageInfo['used']));
  71. $tmpl->assign('total_space', OC_Helper::humanFileSize($storageInfo['total']));
  72. $tmpl->assign('usage_relative', $storageInfo['relative']);
  73. $tmpl->assign('clients', $clients);
  74. $tmpl->assign('email', $email);
  75. $tmpl->assign('languages', $languages);
  76. $tmpl->assign('commonlanguages', $commonlanguages);
  77. $tmpl->assign('activelanguage', $userLang);
  78. $tmpl->assign('passwordChangeSupported', OC_User::canUserChangePassword(OC_User::getUser()));
  79. $tmpl->assign('displayNameChangeSupported', OC_User::canUserChangeDisplayName(OC_User::getUser()));
  80. $tmpl->assign('displayName', OC_User::getDisplayName());
  81. $tmpl->assign('enableDecryptAll' , $enableDecryptAll);
  82. $tmpl->assign('backupKeysExists' , $backupKeysExists);
  83. $tmpl->assign('filesStillEncrypted' , $filesStillEncrypted);
  84. $tmpl->assign('enableAvatars', $config->getSystemValue('enable_avatars', true));
  85. $tmpl->assign('avatarChangeSupported', OC_User::canUserChangeAvatar(OC_User::getUser()));
  86. $tmpl->assign('certs', $certificateManager->listCertificates());
  87. // Get array of group ids for this user
  88. $groups = \OC::$server->getGroupManager()->getUserIdGroups(OC_User::getUser());
  89. $groups2 = array_map(function($group) { return $group->getGID(); }, $groups);
  90. sort($groups2);
  91. $tmpl->assign('groups', $groups2);
  92. // add hardcoded forms from the template
  93. $l = OC_L10N::get('settings');
  94. $formsAndMore = [];
  95. $formsAndMore[]= ['anchor' => 'clientsbox', 'section-name' => $l->t('Sync clients')];
  96. $formsAndMore[]= ['anchor' => 'passwordform', 'section-name' => $l->t('Personal info')];
  97. $forms=OC_App::getForms('personal');
  98. $formsMap = array_map(function($form){
  99. if (preg_match('%(<h2[^>]*>.*?</h2>)%i', $form, $regs)) {
  100. $sectionName = str_replace('<h2>', '', $regs[0]);
  101. $sectionName = str_replace('</h2>', '', $sectionName);
  102. $anchor = strtolower($sectionName);
  103. $anchor = str_replace(' ', '-', $anchor);
  104. return array(
  105. 'anchor' => 'goto-' . $anchor,
  106. 'section-name' => $sectionName,
  107. 'form' => $form
  108. );
  109. }
  110. return array(
  111. 'form' => $form
  112. );
  113. }, $forms);
  114. $formsAndMore = array_merge($formsAndMore, $formsMap);
  115. // add bottom hardcoded forms from the template
  116. $formsAndMore[]= array( 'anchor' => 'ssl-root-certificates', 'section-name' => $l->t('SSL root certificates') );
  117. if($enableDecryptAll) {
  118. $formsAndMore[]= array( 'anchor' => 'encryption', 'section-name' => $l->t('Encryption') );
  119. }
  120. $tmpl->assign('forms', $formsAndMore);
  121. $tmpl->printPage();