personal.php 9.8 KB

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