本文整理汇总了PHP中OC_L10N类的典型用法代码示例。如果您正苦于以下问题:PHP OC_L10N类的具体用法?PHP OC_L10N怎么用?PHP OC_L10N使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了OC_L10N类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: checkAdminUser
/**
* Check if the user is a admin, send json error msg if not
*/
public static function checkAdminUser()
{
self::checkLoggedIn();
if (!OC_Group::inGroup(OC_User::getUser(), 'admin')) {
$l = new OC_L10N('core');
self::error(array('data' => array('message' => $l->t('Authentication error'))));
exit;
}
}
示例2: buildFileStorageStatistics
public static function buildFileStorageStatistics($dir)
{
// information about storage capacities
$storageInfo = \OC_Helper::getStorageInfo($dir);
$l = new \OC_L10N('files');
$maxUploadFileSize = \OCP\Util::maxUploadFilesize($dir, $storageInfo['free']);
$maxHumanFileSize = \OCP\Util::humanFileSize($maxUploadFileSize);
$maxHumanFileSize = $l->t('Upload (max. %s)', array($maxHumanFileSize));
return array('uploadMaxFilesize' => $maxUploadFileSize, 'maxHumanFilesize' => $maxHumanFileSize, 'freeSpace' => $storageInfo['free'], 'usedSpacePercent' => (int) $storageInfo['relative']);
}
示例3: getNotificationTypes
/**
* @param \OC_L10N $l
* @return array Array "stringID of the type" => "translated string description for the setting"
*/
public function getNotificationTypes(\OC_L10N $l)
{
if (isset($this->notificationTypes[$l->getLanguageCode()])) {
return $this->notificationTypes[$l->getLanguageCode()];
}
$notificationTypes = array(self::TYPE_SHARED => $l->t('A file or folder has been <strong>shared</strong>'), self::TYPE_SHARE_CREATED => $l->t('A new file or folder has been <strong>created</strong>'), self::TYPE_SHARE_CHANGED => $l->t('A file or folder has been <strong>changed</strong>'), self::TYPE_SHARE_DELETED => $l->t('A file or folder has been <strong>deleted</strong>'), self::TYPE_SHARE_RESTORED => $l->t('A file or folder has been <strong>restored</strong>'));
// Allow other apps to add new notification types
$additionalNotificationTypes = $this->activityManager->getNotificationTypes($l->getLanguageCode());
$notificationTypes = array_merge($notificationTypes, $additionalNotificationTypes);
$this->notificationTypes[$l->getLanguageCode()] = $notificationTypes;
return $notificationTypes;
}
示例4: login
/**
* @brief Startup encryption backend upon user login
* @note This method should never be called for users using client side encryption
*/
public static function login($params)
{
$l = new \OC_L10N('files_encryption');
//check if all requirements are met
if (!Helper::checkRequirements()) {
$error_msg = $l->t("Missing requirements.");
$hint = $l->t('Please make sure that PHP 5.3.3 or newer is installed and that the OpenSSL PHP extension is enabled and configured properly. For now, the encryption app has been disabled.');
\OC_App::disable('files_encryption');
\OCP\Util::writeLog('Encryption library', $error_msg . ' ' . $hint, \OCP\Util::ERROR);
\OCP\Template::printErrorPage($error_msg, $hint);
}
$view = new \OC_FilesystemView('/');
// ensure filesystem is loaded
if (!\OC\Files\Filesystem::$loaded) {
\OC_Util::setupFS($params['uid']);
}
$util = new Util($view, $params['uid']);
// setup user, if user not ready force relogin
if (Helper::setupUser($util, $params['password']) === false) {
return false;
}
$encryptedKey = Keymanager::getPrivateKey($view, $params['uid']);
$privateKey = Crypt::decryptPrivateKey($encryptedKey, $params['password']);
if ($privateKey === false) {
\OCP\Util::writeLog('Encryption library', 'Private key for user "' . $params['uid'] . '" is not valid! Maybe the user password was changed from outside if so please change it back to gain access', \OCP\Util::ERROR);
}
$session = new \OCA\Encryption\Session($view);
$session->setPrivateKey($privateKey);
// Check if first-run file migration has already been performed
$ready = false;
if ($util->getMigrationStatus() === Util::MIGRATION_OPEN) {
$ready = $util->beginMigration();
}
// If migration not yet done
if ($ready) {
$userView = new \OC_FilesystemView('/' . $params['uid']);
// Set legacy encryption key if it exists, to support
// depreciated encryption system
if ($userView->file_exists('encryption.key') && ($encLegacyKey = $userView->file_get_contents('encryption.key'))) {
$plainLegacyKey = Crypt::legacyDecrypt($encLegacyKey, $params['password']);
$session->setLegacyKey($plainLegacyKey);
}
// Encrypt existing user files:
// This serves to upgrade old versions of the encryption
// app (see appinfo/spec.txt)
if ($util->encryptAll('/' . $params['uid'] . '/' . 'files', $session->getLegacyKey(), $params['password'])) {
\OC_Log::write('Encryption library', 'Encryption of existing files belonging to "' . $params['uid'] . '" completed', \OC_Log::INFO);
}
// Register successful migration in DB
$util->finishMigration();
}
return true;
}
示例5: __construct
function __construct()
{
$this->l = OC_L10N::get('lib');
$version = OC_Util::getVersion();
$this->defaultEntity = 'ownCloud';
/* e.g. company name, used for footers and copyright notices */
$this->defaultName = 'ownCloud';
/* short name, used when referring to the software */
$this->defaultTitle = 'ownCloud';
/* can be a longer name, for titles */
$this->defaultBaseUrl = 'https://owncloud.org';
$this->defaultSyncClientUrl = 'https://owncloud.org/sync-clients/';
$this->defaultiOSClientUrl = 'https://itunes.apple.com/us/app/owncloud/id543672169?mt=8';
$this->defaultAndroidClientUrl = 'https://play.google.com/store/apps/details?id=com.owncloud.android';
$this->defaultDocBaseUrl = 'http://doc.owncloud.org';
$this->defaultDocVersion = $version[0] . '.0';
// used to generate doc links
$this->defaultSlogan = $this->l->t('web services under your control');
$this->defaultLogoClaim = '';
$this->defaultMailHeaderColor = '#1d2d44';
/* header color of mail notifications */
if (file_exists(OC::$SERVERROOT . '/themes/' . OC_Util::getTheme() . '/defaults.php')) {
// prevent defaults.php from printing output
ob_start();
require_once 'themes/' . OC_Util::getTheme() . '/defaults.php';
ob_end_clean();
$this->theme = new OC_Theme();
}
}
示例6: sendEmail
public static function sendEmail($args)
{
if (OC_User::userExists($_POST['user'])) {
$token = hash('sha256', OC_Util::generate_random_bytes(30) . OC_Config::getValue('passwordsalt', ''));
OC_Preferences::setValue($_POST['user'], 'owncloud', 'lostpassword', hash('sha256', $token));
// Hash the token again to prevent timing attacks
$email = OC_Preferences::getValue($_POST['user'], 'settings', 'email', '');
if (!empty($email)) {
$link = OC_Helper::linkToRoute('core_lostpassword_reset', array('user' => $_POST['user'], 'token' => $token));
$link = OC_Helper::makeURLAbsolute($link);
$tmpl = new OC_Template('core/lostpassword', 'email');
$tmpl->assign('link', $link, false);
$msg = $tmpl->fetchPage();
$l = OC_L10N::get('core');
$from = 'lostpassword-noreply@' . OCP\Util::getServerHost();
OC_Mail::send($email, $_POST['user'], $l->t('ownCloud password reset'), $msg, $from, 'ownCloud');
echo 'Mailsent';
self::displayLostPasswordPage(false, true);
} else {
self::displayLostPasswordPage(true, false);
}
} else {
self::displayLostPasswordPage(true, false);
}
}
示例7: search
function search($query)
{
$collection = new Collection(\OCP\User::getUser());
$l = \OC_L10N::get('media');
$app_name = (string) $l->t('Music');
$artists = $collection->getArtists($query);
$albums = $collection->getAlbums(0, $query);
$songs = $collection->getSongs(0, 0, $query);
$results = array();
foreach ($artists as $artist) {
$results[] = new \OC_Search_Result($artist['artist_name'], '', \OCP\Util::linkTo('media', 'index.php') . '#artist=' . urlencode($artist['artist_name']), $app_name);
}
foreach ($albums as $album) {
$artist = $collection->getArtistName($album['album_artist']);
$results[] = new \OC_Search_Result($album['album_name'], 'by ' . $artist, \OCP\Util::linkTo('media', 'index.php') . '#artist=' . urlencode($artist) . '&album=' . urlencode($album['album_name']), $app_name);
}
foreach ($songs as $song) {
$minutes = floor($song['song_length'] / 60);
$seconds = $song['song_length'] % 60;
$artist = $collection->getArtistName($song['song_artist']);
$album = $collection->getalbumName($song['song_album']);
$results[] = new \OC_Search_Result($song['song_name'], "by {$artist}, in {$album} {$minutes}:{$seconds}", \OCP\Util::linkTo('media', 'index.php') . '#artist=' . urlencode($artist) . '&album=' . urlencode($album) . '&song=' . urlencode($song['song_name']), $app_name);
}
return $results;
}
示例8: getUserLang
/**
* Gets the language of the user, including anonymous
*
* @return The user language
*/
public static function getUserLang()
{
$config = \OC::$server->getConfig();
$lang = \OC_L10N::findLanguage();
$userLang = $config->getUserValue(\OC_User::getUser(), 'core', 'lang', $lang);
return $userLang;
}
示例9: search
function search($query)
{
require_once 'lib_collection.php';
$l = OC_L10N::get('media');
$app_name = (string) $l->t('Music');
$artists = OC_MEDIA_COLLECTION::getArtists($query);
$albums = OC_MEDIA_COLLECTION::getAlbums(0, $query);
$songs = OC_MEDIA_COLLECTION::getSongs(0, 0, $query);
$results = array();
foreach ($artists as $artist) {
$results[] = new OC_Search_Result($artist['artist_name'], '', OCP\Util::linkTo('media', 'index.php') . '#artist=' . urlencode($artist['artist_name']), $app_name);
}
foreach ($albums as $album) {
$artist = OC_MEDIA_COLLECTION::getArtistName($album['album_artist']);
$results[] = new OC_Search_Result($album['album_name'], 'by ' . $artist, OCP\Util::linkTo('media', 'index.php') . '#artist=' . urlencode($artist) . '&album=' . urlencode($album['album_name']), $app_name);
}
foreach ($songs as $song) {
$minutes = floor($song['song_length'] / 60);
$secconds = $song['song_length'] % 60;
$artist = OC_MEDIA_COLLECTION::getArtistName($song['song_artist']);
$album = OC_MEDIA_COLLECTION::getalbumName($song['song_album']);
$results[] = new OC_Search_Result($song['song_name'], "by {$artist}, in {$album} {$minutes}:{$secconds}", OCP\Util::linkTo('media', 'index.php') . '#artist=' . urlencode($artist) . '&album=' . urlencode($album) . '&song=' . urlencode($song['song_name']), $app_name);
}
return $results;
}
示例10: set
/**
* sets the users avatar
* @param \OC_Image|resource|string $data OC_Image, imagedata or path to set a new avatar
* @throws Exception if the provided file is not a jpg or png image
* @throws Exception if the provided image is not valid
* @throws \OC\NotSquareException if the image is not square
* @return void
*/
public function set($data)
{
if ($data instanceof OC_Image) {
$img = $data;
$data = $img->data();
} else {
$img = new OC_Image($data);
}
$type = substr($img->mimeType(), -3);
if ($type === 'peg') {
$type = 'jpg';
}
if ($type !== 'jpg' && $type !== 'png') {
$l = \OC_L10N::get('lib');
throw new \Exception($l->t("Unknown filetype"));
}
if (!$img->valid()) {
$l = \OC_L10N::get('lib');
throw new \Exception($l->t("Invalid image"));
}
if (!($img->height() === $img->width())) {
throw new \OC\NotSquareException();
}
$this->view->unlink('avatar.jpg');
$this->view->unlink('avatar.png');
$this->view->file_put_contents('avatar.' . $type, $data);
}
示例11: sendEmail
public static function sendEmail($args)
{
$isEncrypted = OC_App::isEnabled('files_encryption');
if (!$isEncrypted || isset($_POST['continue'])) {
$continue = true;
} else {
$continue = false;
}
if (OC_User::userExists($_POST['user']) && $continue) {
$token = hash('sha256', OC_Util::generate_random_bytes(30) . OC_Config::getValue('passwordsalt', ''));
OC_Preferences::setValue($_POST['user'], 'owncloud', 'lostpassword', hash('sha256', $token));
// Hash the token again to prevent timing attacks
$email = OC_Preferences::getValue($_POST['user'], 'settings', 'email', '');
if (!empty($email)) {
$link = OC_Helper::linkToRoute('core_lostpassword_reset', array('user' => $_POST['user'], 'token' => $token));
$link = OC_Helper::makeURLAbsolute($link);
$tmpl = new OC_Template('core/lostpassword', 'email');
$tmpl->assign('link', $link, false);
$msg = $tmpl->fetchPage();
$l = OC_L10N::get('core');
$from = OCP\Util::getDefaultEmailAddress('lostpassword-noreply');
try {
OC_Mail::send($email, $_POST['user'], $l->t('ownCloud password reset'), $msg, $from, 'ownCloud');
} catch (Exception $e) {
OC_Template::printErrorPage('A problem occurs during sending the e-mail please contact your administrator.');
}
self::displayLostPasswordPage(false, true);
} else {
self::displayLostPasswordPage(true, false);
}
} else {
self::displayLostPasswordPage(true, false);
}
}
示例12: validatepassword
public function validatepassword($password)
{
$response = array();
$error = '';
if (strlen($password) < intval($this->service->getAppValue('minlength'))) {
$error .= \OC_L10N::get('passwordpolicy')->t('Password is too short. ');
}
if ($this->service->getAppValue('hasnumbers') == "true") {
if (preg_match("/[0-9]/", $password) != 1) {
$error .= \OC_L10N::get('passwordpolicy')->t('Password does not contain numbers. ');
}
}
if ($this->service->getAppValue('hasspecialchars') == "true") {
$specialcharslist = $this->service->getAppValue('specialcharslist');
if (!checkSpecialChars($specialcharslist, $password)) {
$error .= \OC_L10N::get('passwordpolicy')->t('Password does not contain special characters. ');
}
}
if ($this->service->getAppValue('hasmixedcase') == "true") {
if (!checkMixedCase($password)) {
$error .= \OC_L10N::get('passwordpolicy')->t('Password does not contain upper and lower case characters.');
}
}
if (!empty($error)) {
$errormsg = \OC_L10N::get('passwordpolicy')->t('Password does not conform to the Password Policy. [%s]', [$error]);
if ($this->request->server['PATH_INFO'] == "/settings/personal/changepassword") {
$response = array('status' => "Failure", 'data' => array('message' => "{$errormsg}"));
} else {
$response = array('status' => "Failure", 'msg' => "{$errormsg}");
}
}
return $response;
}
示例13: rename
/**
* rename a file
*
* @param string $dir
* @param string $oldname
* @param string $newname
* @return array
*/
public function rename($dir, $oldname, $newname)
{
$result = array('success' => false, 'data' => NULL);
$normalizedOldPath = \OC\Files\Filesystem::normalizePath($dir . '/' . $oldname);
$normalizedNewPath = \OC\Files\Filesystem::normalizePath($dir . '/' . $newname);
// rename to non-existing folder is denied
if (!$this->view->file_exists($normalizedOldPath)) {
$result['data'] = array('message' => $this->l10n->t('%s could not be renamed as it has been deleted', array($oldname)), 'code' => 'sourcenotfound', 'oldname' => $oldname, 'newname' => $newname);
} else {
if (!$this->view->file_exists($dir)) {
$result['data'] = array('message' => (string) $this->l10n->t('The target folder has been moved or deleted.', array($dir)), 'code' => 'targetnotfound');
// rename to existing file is denied
} else {
if ($this->view->file_exists($normalizedNewPath)) {
$result['data'] = array('message' => $this->l10n->t("The name %s is already used in the folder %s. Please choose a different name.", array($newname, $dir)));
} else {
if ($newname !== '.' and $this->view->rename($normalizedOldPath, $normalizedNewPath)) {
// successful rename
$meta = $this->view->getFileInfo($normalizedNewPath);
$meta = \OCA\Files\Helper::populateTags(array($meta));
$fileInfo = \OCA\Files\Helper::formatFileInfo(current($meta));
$fileInfo['path'] = dirname($normalizedNewPath);
$result['success'] = true;
$result['data'] = $fileInfo;
} else {
// rename failed
$result['data'] = array('message' => $this->l10n->t('%s could not be renamed', array($oldname)));
}
}
}
}
return $result;
}
示例14: rename
/**
* rename a file
*
* @param string $dir
* @param string $oldname
* @param string $newname
* @return array
*/
public function rename($dir, $oldname, $newname)
{
$result = array('success' => false, 'data' => NULL);
// rename to "/Shared" is denied
if ($dir === '/' and $newname === 'Shared') {
$result['data'] = array('message' => $this->l10n->t("Invalid folder name. Usage of 'Shared' is reserved."));
// rename to existing file is denied
} else {
if ($this->view->file_exists($dir . '/' . $newname)) {
$result['data'] = array('message' => $this->l10n->t("The name %s is already used in the folder %s. Please choose a different name.", array($newname, $dir)));
} else {
if ($newname !== '.' and !($dir === '/' and $oldname === 'Shared') and $this->view->rename($dir . '/' . $oldname, $dir . '/' . $newname)) {
// successful rename
$meta = $this->view->getFileInfo($dir . '/' . $newname);
if ($meta['mimetype'] === 'httpd/unix-directory') {
$meta['type'] = 'dir';
} else {
$meta['type'] = 'file';
}
$fileinfo = array('id' => $meta['fileid'], 'mime' => $meta['mimetype'], 'size' => $meta['size'], 'etag' => $meta['etag'], 'directory' => $dir, 'name' => $newname, 'isPreviewAvailable' => \OC::$server->getPreviewManager()->isMimeSupported($meta['mimetype']), 'icon' => \OCA\Files\Helper::determineIcon($meta));
$result['success'] = true;
$result['data'] = $fileinfo;
} else {
// rename failed
$result['data'] = array('message' => $this->l10n->t('%s could not be renamed', array($oldname)));
}
}
}
return $result;
}
示例15: __toString
public function __toString()
{
$translations = $this->l10n->getTranslations();
$text = $this->text;
if (array_key_exists($this->text, $translations)) {
if (is_array($translations[$this->text])) {
$fn = $this->l10n->getPluralFormFunction();
$id = $fn($this->count);
if ($translations[$this->text][$id] !== '') {
// The translation of this plural case is not empty, so use it
$text = $translations[$this->text][$id];
} else {
// We didn't find the plural in the language,
// so we fall back to english.
$id = $id != 0 ? 1 : 0;
if (isset($this->plurals[$id])) {
// Fallback to the english plural
$text = $this->plurals[$id];
}
}
} else {
$text = $translations[$this->text];
}
}
// Replace %n first (won't interfere with vsprintf)
$text = str_replace('%n', $this->count, $text);
return vsprintf($text, $this->parameters);
}