本文整理汇总了PHP中OCP\IConfig类的典型用法代码示例。如果您正苦于以下问题:PHP IConfig类的具体用法?PHP IConfig怎么用?PHP IConfig使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了IConfig类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: run
/**
* Enables the files app if it is disabled
*/
public function run()
{
if ($this->config->getAppValue('files', 'enabled', 'no') !== 'yes') {
$this->config->setAppValue('files', 'enabled', 'yes');
$this->emit('\\OC\\Repair', 'info', ['Files app was disabled - re-enabled']);
}
}
示例2: index
/**
* @NoAdminRequired
* @NoCSRFRequired
*
* @return TemplateResponse
*/
public function index()
{
$userId = $this->userSession->getUser()->getUID();
$appVersion = $this->config->getAppValue($this->appName, 'installed_version');
$defaultView = $this->config->getUserValue($userId, $this->appName, 'currentView', 'month');
return new TemplateResponse('calendar', 'main', ['appVersion' => $appVersion, 'defaultView' => $defaultView]);
}
示例3: validateUserPass
/**
* Validates a username and password
*
* This method should return true or false depending on if login
* succeeded.
*
* @param string $username
* @param string $password
*
* @return bool
*/
protected function validateUserPass($username, $password)
{
$linkItem = \OCP\Share::getShareByToken($username, false);
\OC_User::setIncognitoMode(true);
$this->share = $linkItem;
if (!$linkItem) {
return false;
}
// check if the share is password protected
if (isset($linkItem['share_with'])) {
if ($linkItem['share_type'] == \OCP\Share::SHARE_TYPE_LINK) {
// Check Password
$forcePortable = CRYPT_BLOWFISH != 1;
$hasher = new \PasswordHash(8, $forcePortable);
if (!$hasher->CheckPassword($password . $this->config->getSystemValue('passwordsalt', ''), $linkItem['share_with'])) {
return false;
} else {
return true;
}
} else {
return false;
}
} else {
return true;
}
}
示例4: run
/**
* @param $argument
* @throws \Exception
*/
protected function run($argument)
{
$maxAge = $this->expiration->getMaxAgeAsTimestamp();
if (!$maxAge) {
return;
}
$offset = $this->config->getAppValue('files_trashbin', 'cronjob_user_offset', 0);
$users = $this->userManager->search('', self::USERS_PER_SESSION, $offset);
if (!count($users)) {
// No users found, reset offset and retry
$offset = 0;
$users = $this->userManager->search('', self::USERS_PER_SESSION);
}
$offset += self::USERS_PER_SESSION;
$this->config->setAppValue('files_trashbin', 'cronjob_user_offset', $offset);
foreach ($users as $user) {
$uid = $user->getUID();
if (!$this->setupFS($uid)) {
continue;
}
$dirContent = Helper::getTrashFiles('/', $uid, 'mtime');
Trashbin::deleteExpiredFiles($dirContent, $uid);
}
\OC_Util::tearDownFS();
}
示例5: execute
protected function execute(InputInterface $input, OutputInterface $output)
{
$includeExpensive = $input->getOption('include-expensive');
if ($includeExpensive) {
foreach ($this->repair->getExpensiveRepairSteps() as $step) {
$this->repair->addStep($step);
}
}
$maintenanceMode = $this->config->getSystemValue('maintenance', false);
$this->config->setSystemValue('maintenance', true);
$this->repair->listen('\\OC\\Repair', 'step', function ($description) use($output) {
$output->writeln(' - ' . $description);
});
$this->repair->listen('\\OC\\Repair', 'info', function ($description) use($output) {
$output->writeln(' - ' . $description);
});
$this->repair->listen('\\OC\\Repair', 'warning', function ($description) use($output) {
$output->writeln(' - WARNING: ' . $description);
});
$this->repair->listen('\\OC\\Repair', 'error', function ($description) use($output) {
$output->writeln(' - ERROR: ' . $description);
});
$this->repair->run();
$this->config->setSystemValue('maintenance', $maintenanceMode);
}
示例6: createKey
/**
* Generate a keypair
*
* @return array ['privatekey' => $privateKey, 'publickey' => $publicKey]
*/
public function createKey()
{
$rsa = new RSACrypt();
$rsa->setPublicKeyFormat(RSACrypt::PUBLIC_FORMAT_OPENSSH);
$rsa->setPassword($this->config->getSystemValue('secret', ''));
return $rsa->createKey(self::CREATE_KEY_BITS);
}
示例7: execute
protected function execute(InputInterface $input, OutputInterface $output)
{
$importFile = $input->getArgument('file');
if ($importFile !== null) {
$content = $this->getArrayFromFile($importFile);
} else {
$content = $this->getArrayFromStdin();
}
try {
$configs = $this->validateFileContent($content);
} catch (\UnexpectedValueException $e) {
$output->writeln('<error>' . $e->getMessage() . '</error>');
return;
}
if (!empty($configs['system'])) {
$this->config->setSystemValues($configs['system']);
}
if (!empty($configs['apps'])) {
foreach ($configs['apps'] as $app => $appConfigs) {
foreach ($appConfigs as $key => $value) {
if ($value === null) {
$this->config->deleteAppValue($app, $key);
} else {
$this->config->setAppValue($app, $key, $value);
}
}
}
}
$output->writeln('<info>Config successfully imported from: ' . $importFile . '</info>');
}
示例8: testSetException
public function testSetException()
{
$this->config->expects($this->once())->method('setUserValue')->with('JohnDoe', 'contacts', 'keyValue', 'valueValue')->will($this->throwException(new \Exception()));
$expected = new JSONResponse();
$expected->setStatus(Http::STATUS_INTERNAL_SERVER_ERROR);
$this->assertEquals($expected, $this->controller->set('keyValue', 'valueValue'));
}
示例9: format
/**
* @param IEvent $event
* @param string $parameter The parameter to be formatted
* @param bool $allowHtml Should HTML be used to format the parameter?
* @param bool $verbose Should paths, names, etc be shortened or full length
* @return string The formatted parameter
*/
public function format(IEvent $event, $parameter, $allowHtml, $verbose = false)
{
// If the username is empty, the action has been performed by a remote
// user, or via a public share. We don't know the username in that case
if ($parameter === '') {
if ($allowHtml === null) {
return '<user display-name="' . Util::sanitizeHTML($this->l->t('"remote user"')) . '">' . Util::sanitizeHTML('') . '</user>';
}
if ($allowHtml) {
return '<strong>' . $this->l->t('"remote user"') . '</strong>';
} else {
return $this->l->t('"remote user"');
}
}
$user = $this->manager->get($parameter);
$displayName = $user ? $user->getDisplayName() : $parameter;
$parameter = Util::sanitizeHTML($parameter);
if ($allowHtml === null) {
return '<user display-name="' . Util::sanitizeHTML($displayName) . '">' . Util::sanitizeHTML($parameter) . '</user>';
}
if ($allowHtml) {
$avatarPlaceholder = '';
if ($this->config->getSystemValue('enable_avatars', true)) {
$avatarPlaceholder = '<div class="avatar" data-user="' . $parameter . '"></div>';
}
return $avatarPlaceholder . '<strong>' . Util::sanitizeHTML($displayName) . '</strong>';
} else {
return $displayName;
}
}
示例10: deleteAppValue
/**
* @param array $parameters
* @return \OC_OCS_Result
*/
public function deleteAppValue($parameters)
{
$app = $parameters['appid'];
$configKey = $parameters['configkey'];
$this->config->deleteAppValue($app, $configKey);
return new \OC_OCS_Result();
}
示例11: show
/**
* @PublicPage
* @NoCSRFRequired
*
* @return TemplateResponse
*/
public function show()
{
try {
$user = $this->activityManager->getCurrentUserId();
$userLang = $this->config->getUserValue($user, 'core', 'lang');
// Overwrite user and language in the helper
$l = Util::getL10N('activity', $userLang);
$l->forceLanguage($userLang);
$this->helper->setL10n($l);
$this->helper->setUser($user);
$description = (string) $l->t('Personal activity feed for %s', $user);
$activities = $this->data->read($this->helper, $this->settings, 0, self::DEFAULT_PAGE_SIZE, 'all', $user);
} catch (\UnexpectedValueException $e) {
$l = Util::getL10N('activity');
$description = (string) $l->t('Your feed URL is invalid');
$activities = [['activity_id' => -1, 'timestamp' => time(), 'subject' => true, 'subjectformatted' => ['full' => $description]]];
}
$response = new TemplateResponse('activity', 'rss', ['rssLang' => $l->getLanguageCode(), 'rssLink' => $this->urlGenerator->linkToRouteAbsolute('activity.Feed.show'), 'rssPubDate' => date('r'), 'description' => $description, 'activities' => $activities], '');
if ($this->request->getHeader('accept') !== null && stristr($this->request->getHeader('accept'), 'application/rss+xml')) {
$response->addHeader('Content-Type', 'application/rss+xml');
} else {
$response->addHeader('Content-Type', 'text/xml; charset=UTF-8');
}
return $response;
}
示例12: linkTo
/**
* Creates an url
* @param string $app app
* @param string $file file
* @param array $args array with param=>value, will be appended to the returned url
* The value of $args will be urlencoded
* @return string the url
*
* Returns a url to the given app and file.
*/
public function linkTo($app, $file, $args = array())
{
$frontControllerActive = $this->config->getSystemValue('front_controller_active', 'false') == 'true';
if ($app != '') {
$app_path = \OC_App::getAppPath($app);
// Check if the app is in the app folder
if ($app_path && file_exists($app_path . '/' . $file)) {
if (substr($file, -3) == 'php') {
$urlLinkTo = \OC::$WEBROOT . '/index.php/apps/' . $app;
if ($frontControllerActive) {
$urlLinkTo = \OC::$WEBROOT . '/apps/' . $app;
}
$urlLinkTo .= $file != 'index.php' ? '/' . $file : '';
} else {
$urlLinkTo = \OC_App::getAppWebPath($app) . '/' . $file;
}
} else {
$urlLinkTo = \OC::$WEBROOT . '/' . $app . '/' . $file;
}
} else {
if (file_exists(\OC::$SERVERROOT . '/core/' . $file)) {
$urlLinkTo = \OC::$WEBROOT . '/core/' . $file;
} else {
if ($frontControllerActive && $file === 'index.php') {
$urlLinkTo = \OC::$WEBROOT;
} else {
$urlLinkTo = \OC::$WEBROOT . '/' . $file;
}
}
}
if ($args && ($query = http_build_query($args, '', '&'))) {
$urlLinkTo .= '?' . $query;
}
return $urlLinkTo;
}
示例13: upgrade
public function upgrade()
{
$previousVersion = $this->config->getAppValue($this->appName, 'installed_version');
if (version_compare($previousVersion, '7', '<')) {
$this->itemService->generateSearchIndices();
}
}
示例14: runStep
/**
* Send an email to {$limit} users
*
* @param int $limit Number of users we want to send an email to
* @param int $sendTime The latest send time
* @return int Number of users we sent an email to
*/
protected function runStep($limit, $sendTime)
{
// Get all users which should receive an email
$affectedUsers = $this->mqHandler->getAffectedUsers($limit, $sendTime);
if (empty($affectedUsers)) {
// No users found to notify, mission abort
return 0;
}
$userLanguages = $this->config->getUserValueForUsers('core', 'lang', $affectedUsers);
$userTimezones = $this->config->getUserValueForUsers('core', 'timezone', $affectedUsers);
$userEmails = $this->config->getUserValueForUsers('settings', 'email', $affectedUsers);
// Send Email
$default_lang = $this->config->getSystemValue('default_language', 'en');
$defaultTimeZone = date_default_timezone_get();
foreach ($affectedUsers as $user) {
if (empty($userEmails[$user])) {
// The user did not setup an email address
// So we will not send an email :(
$this->logger->debug("Couldn't send notification email to user '" . $user . "' (email address isn't set for that user)", ['app' => 'activity']);
continue;
}
$language = !empty($userLanguages[$user]) ? $userLanguages[$user] : $default_lang;
$timezone = !empty($userTimezones[$user]) ? $userTimezones[$user] : $defaultTimeZone;
$this->mqHandler->sendEmailToUser($user, $userEmails[$user], $language, $timezone, $sendTime);
}
// Delete all entries we dealt with
$this->mqHandler->deleteSentItems($affectedUsers, $sendTime);
return sizeof($affectedUsers);
}
示例15: loadCommands
/**
* @param OutputInterface $output
*/
public function loadCommands(OutputInterface $output)
{
// $application is required to be defined in the register_command scripts
$application = $this->application;
require_once \OC::$SERVERROOT . '/core/register_command.php';
if ($this->config->getSystemValue('installed', false)) {
if (!\OCP\Util::needUpgrade()) {
OC_App::loadApps();
foreach (OC_App::getAllApps() as $app) {
$file = OC_App::getAppPath($app) . '/appinfo/register_command.php';
if (file_exists($file)) {
require $file;
}
}
} else {
$output->writeln("ownCloud or one of the apps require upgrade - only a limited number of commands are available");
}
} else {
$output->writeln("ownCloud is not installed - only a limited number of commands are available");
}
$input = new ArgvInput();
if ($input->getFirstArgument() !== 'check') {
$errors = \OC_Util::checkServer(\OC::$server->getConfig());
if (!empty($errors)) {
foreach ($errors as $error) {
$output->writeln($error['error']);
$output->writeln($error['hint']);
$output->writeln('');
}
throw new \Exception("Environment not properly prepared.");
}
}
}