本文整理汇总了PHP中OC_Config类的典型用法代码示例。如果您正苦于以下问题:PHP OC_Config类的具体用法?PHP OC_Config怎么用?PHP OC_Config使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了OC_Config类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: testParentOfMountPointIsGone
/**
* if the parent of the mount point is gone then the mount point should move up
*
* @medium
*/
function testParentOfMountPointIsGone()
{
// share to user
$fileinfo = $this->view->getFileInfo($this->folder);
$result = \OCP\Share::shareItem('folder', $fileinfo['fileid'], \OCP\Share::SHARE_TYPE_USER, self::TEST_FILES_SHARING_API_USER2, 31);
$this->assertTrue($result);
self::loginHelper(self::TEST_FILES_SHARING_API_USER2);
$user2View = new \OC\Files\View('/' . self::TEST_FILES_SHARING_API_USER2 . '/files');
$this->assertTrue($user2View->file_exists($this->folder));
// create a local folder
$result = $user2View->mkdir('localfolder');
$this->assertTrue($result);
// move mount point to local folder
$result = $user2View->rename($this->folder, '/localfolder/' . $this->folder);
$this->assertTrue($result);
// mount point in the root folder should no longer exist
$this->assertFalse($user2View->is_dir($this->folder));
// delete the local folder
$fullPath = \OC_Config::getValue('datadirectory') . '/' . self::TEST_FILES_SHARING_API_USER2 . '/files/localfolder';
rmdir($fullPath);
//enforce reload of the mount points
self::loginHelper(self::TEST_FILES_SHARING_API_USER2);
//mount point should be back at the root
$this->assertTrue($user2View->is_dir($this->folder));
//cleanup
self::loginHelper(self::TEST_FILES_SHARING_API_USER1);
$this->view->unlink($this->folder);
}
示例2: __construct
/**
* @brief Constructor
* @param string $app app providing the template
* @param string $name of the template file (without suffix)
* @param string $renderas = ""; produce a full page
* @return OC_Template object
*
* This function creates an OC_Template object.
*
* If $renderas is set, OC_Template will try to produce a full page in the
* according layout. For now, renderas can be set to "guest", "user" or
* "admin".
*/
public function __construct($app, $name, $renderas = "")
{
// Read the selected theme from the config file
$theme = OC_Util::getTheme();
// Read the detected formfactor and use the right file name.
$fext = self::getFormFactorExtension();
$requesttoken = OC::$session ? OC_Util::callRegister() : '';
$parts = explode('/', $app);
// fix translation when app is something like core/lostpassword
$l10n = OC_L10N::get($parts[0]);
$themeDefaults = new OC_Defaults();
list($path, $template) = $this->findTemplate($theme, $app, $name, $fext);
// Set the private data
$this->renderas = $renderas;
$this->path = $path;
parent::__construct($template, $requesttoken, $l10n, $themeDefaults);
// Some headers to enhance security
header('X-XSS-Protection: 1; mode=block');
// Enforce browser based XSS filters
header('X-Content-Type-Options: nosniff');
// Disable sniffing the content type for IE
// iFrame Restriction Policy
$xFramePolicy = OC_Config::getValue('xframe_restriction', true);
if ($xFramePolicy) {
header('X-Frame-Options: Sameorigin');
// Disallow iFraming from other domains
}
// Content Security Policy
// If you change the standard policy, please also change it in config.sample.php
$policy = OC_Config::getValue('custom_csp_policy', 'default-src \'self\'; ' . 'script-src \'self\' \'unsafe-eval\'; ' . 'style-src \'self\' \'unsafe-inline\'; ' . 'frame-src *; ' . 'img-src *; ' . 'font-src \'self\' data:; ' . 'media-src *');
header('Content-Security-Policy:' . $policy);
// Standard
}
示例3: prepare
/**
* Prepares an SQL statement.
*
* @param string $statement The SQL statement to prepare.
* @param int $limit
* @param int $offset
* @return \Doctrine\DBAL\Driver\Statement The prepared statement.
*/
public function prepare($statement, $limit = null, $offset = null)
{
if ($limit === -1) {
$limit = null;
}
if (!is_null($limit)) {
$platform = $this->getDatabasePlatform();
$statement = $platform->modifyLimitQuery($statement, $limit, $offset);
} else {
if (isset($this->preparedQueries[$statement]) && $this->cachingQueryStatementEnabled) {
return $this->preparedQueries[$statement];
}
$origStatement = $statement;
}
$statement = $this->replaceTablePrefix($statement);
$statement = $this->adapter->fixupStatement($statement);
if (\OC_Config::getValue('log_query', false)) {
\OC_Log::write('core', 'DB prepare : ' . $statement, \OC_Log::DEBUG);
}
$result = parent::prepare($statement);
if (is_null($limit) && $this->cachingQueryStatementEnabled) {
$this->preparedQueries[$origStatement] = $result;
}
return $result;
}
示例4: setupDatabase
public function setupDatabase($username) {
//check if the database user has admin right
$masterConnectionInfo = array( "Database" => "master", "UID" => $this->dbuser, "PWD" => $this->dbpassword);
$masterConnection = @sqlsrv_connect($this->dbhost, $masterConnectionInfo);
if(!$masterConnection) {
$entry = '';
if( ($errors = sqlsrv_errors() ) != null) {
$entry='DB Error: "'.print_r(sqlsrv_errors()).'"<br />';
}
throw new \OC\DatabaseSetupException($this->trans->t('MS SQL username and/or password not valid: %s', array($entry)),
$this->trans->t('You need to enter either an existing account or the administrator.'));
}
\OC_Config::setValues([
'dbuser' => $this->dbuser,
'dbpassword' => $this->dbpassword,
]);
$this->createDBLogin($masterConnection);
$this->createDatabase($masterConnection);
$this->createDBUser($masterConnection);
sqlsrv_close($masterConnection);
$this->createDatabaseStructure();
}
示例5: 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);
}
}
示例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: getEntries
/**
* get entries from the log in reverse chronological order
* @param int limit
* @param int offset
* @return array
*/
public static function getEntries($limit = 50, $offset = 0)
{
self::init();
$minLevel = OC_Config::getValue("loglevel", OC_Log::WARN);
$entries = array();
$handle = @fopen(self::$logFile, 'r');
if ($handle) {
// Just a guess to set the file pointer to the right spot
$maxLineLength = 150;
fseek($handle, -($limit * $maxLineLength + $offset * $maxLineLength), SEEK_END);
// Skip first line, because it is most likely a partial line
fgets($handle);
while (!feof($handle)) {
$line = fgets($handle);
if (!empty($line)) {
$entry = json_decode($line);
if ($entry->level >= $minLevel) {
$entries[] = $entry;
}
}
}
fclose($handle);
// Extract the needed entries and reverse the order
$entries = array_reverse(array_slice($entries, -($limit + $offset), $limit));
}
return $entries;
}
示例8: createDatabase
/**
* create a new database
*
* @param string $name name of the database that should be created
* @param array $options array with charset info
*
* @return mixed MDB2_OK on success, a MDB2 error on failure
* @access public
*/
function createDatabase($name, $options = array())
{
$datadir = OC_Config::getValue("datadirectory", OC::$SERVERROOT . "/data");
$db = $this->getDBInstance();
if (PEAR::isError($db)) {
return $db;
}
$database_file = $db->_getDatabaseFile($name);
if (file_exists($database_file)) {
return $db->raiseError(MDB2_ERROR_ALREADY_EXISTS, null, null, 'database already exists', __FUNCTION__);
}
$php_errormsg = '';
$database_file = "{$datadir}/{$database_file}.db";
$handle = new SQLite3($database_file);
if (!$handle) {
return $db->raiseError(MDB2_ERROR_CANNOT_CREATE, null, null, isset($php_errormsg) ? $php_errormsg : 'could not create the database file', __FUNCTION__);
}
//sqlite doesn't support the latin1 we use
// if (!empty($options['charset'])) {
// $query = 'PRAGMA encoding = ' . $db->quote($options['charset'], 'text');
// $handle->exec($query);
// }
$handle->close();
return MDB2_OK;
}
示例9: start
/**
* Start a editing session or return an existing one
* @param string $uid of the user starting a session
* @param \OCA\Documents\File $file - file object
* @return array
* @throws \Exception
*/
public static function start($uid, $file)
{
// Create a directory to store genesis
$genesis = new Genesis($file);
list($ownerView, $path) = $file->getOwnerViewAndPath();
$oldSession = new Db_Session();
$oldSession->loadBy('file_id', $file->getFileId());
//If there is no existing session we need to start a new one
if (!$oldSession->hasData()) {
$newSession = new Db_Session(array($genesis->getPath(), $genesis->getHash(), $file->getOwner(), $file->getFileId()));
if (!$newSession->insert()) {
throw new \Exception('Failed to add session into database');
}
}
$sessionData = $oldSession->loadBy('file_id', $file->getFileId())->getData();
$memberColor = Helper::getMemberColor($uid);
$member = new Db_Member(array($sessionData['es_id'], $uid, $memberColor, time(), intval($file->isPublicShare()), $file->getToken()));
if ($member->insert()) {
// Do we have OC_Avatar in out disposal?
if (!class_exists('\\OC_Avatar') || \OC_Config::getValue('enable_avatars', true) !== true) {
$imageUrl = 'data:image/gif;base64,R0lGODlhAQABAIAAAAAAAAAAACH5BAAAAAAALAAAAAABAAEAAAICTAEAOw==';
} else {
$imageUrl = $uid;
}
$displayName = $file->isPublicShare() ? $uid . ' ' . Db_Member::getGuestPostfix() : \OCP\User::getDisplayName($uid);
$sessionData['member_id'] = (string) $member->getLastInsertId();
$op = new Db_Op();
$op->addMember($sessionData['es_id'], $sessionData['member_id'], $displayName, $memberColor, $imageUrl);
} else {
throw new \Exception('Failed to add member into database');
}
$sessionData['title'] = basename($path);
$sessionData['permissions'] = $ownerView->getFilePermissions($path);
return $sessionData;
}
示例10: runStep
/**
* Send an email to {$limit} users
*
* @param int $limit Number of users we want to send an email to
* @return int Number of users we sent an email to
*/
protected function runStep($limit)
{
// Get all users which should receive an email
$affectedUsers = $this->mqHandler->getAffectedUsers($limit);
if (empty($affectedUsers)) {
// No users found to notify, mission abort
return 0;
}
$preferences = new \OC\Preferences(\OC_DB::getConnection());
$userLanguages = $preferences->getValueForUsers('core', 'lang', $affectedUsers);
$userEmails = $preferences->getValueForUsers('settings', 'email', $affectedUsers);
// Get all items for these users
// We don't use time() but "time() - 1" here, so we don't run into
// runtime issues and delete emails later, which were created in the
// same second, but were not collected for the emails.
$sendTime = time() - 1;
$mailData = $this->mqHandler->getItemsForUsers($affectedUsers, $sendTime);
// Send Email
$default_lang = \OC_Config::getValue('default_language', 'en');
foreach ($mailData as $user => $data) {
if (!isset($userEmails[$user])) {
// The user did not setup an email address
// So we will not send an email :(
continue;
}
$language = isset($userLanguages[$user]) ? $userLanguages[$user] : $default_lang;
$this->mqHandler->sendEmailToUser($user, $userEmails[$user], $language, $data);
}
// Delete all entries we dealt with
$this->mqHandler->deleteSentItems($affectedUsers, $sendTime);
return sizeof($affectedUsers);
}
示例11: setUp
public function setUp()
{
//clear all proxies and hooks so we can do clean testing
\OC_FileProxy::clearProxies();
\OC_Hook::clear('OC_Filesystem');
//disabled atm
//enable only the encryption hook if needed
//if(OC_App::isEnabled('files_encryption')) {
// OC_FileProxy::register(new OC_FileProxy_Encryption());
//}
//set up temporary storage
\OC\Files\Filesystem::clearMounts();
$storage = new \OC\Files\Storage\Temporary(array());
\OC\Files\Filesystem::mount($storage, array(), '/');
$datadir = str_replace('local::', '', $storage->getId());
$this->datadir = \OC_Config::getValue('cachedirectory', \OC::$SERVERROOT . '/data/cache');
\OC_Config::setValue('cachedirectory', $datadir);
\OC_User::clearBackends();
\OC_User::useBackend(new \OC_User_Dummy());
//login
\OC_User::createUser('test', 'test');
$this->user = \OC_User::getUser();
\OC_User::setUserId('test');
//set up the users dir
$rootView = new \OC\Files\View('');
$rootView->mkdir('/test');
$this->instance = new \OC\Cache\UserCache();
}
示例12: write
/**
* write a message in the log
* @param string $app
* @param string $message
* @param int $level
*/
public static function write($app, $message, $level)
{
$minLevel = min(OC_Config::getValue("loglevel", OC_Log::WARN), OC_Log::ERROR);
if ($level >= $minLevel) {
error_log('[owncloud][' . $app . '] ' . $message);
}
}
示例13: getServerConfigurationPrefixes
/**
* returns prefixes for each saved LDAP/AD server configuration.
* @param bool $activeConfigurations optional, whether only active configuration shall be
* retrieved, defaults to false
* @return array with a list of the available prefixes
*
* Configuration prefixes are used to set up configurations for n LDAP or
* AD servers. Since configuration is stored in the database, table
* appconfig under appid user_ldap, the common identifiers in column
* 'configkey' have a prefix. The prefix for the very first server
* configuration is empty.
* Configkey Examples:
* Server 1: ldap_login_filter
* Server 2: s1_ldap_login_filter
* Server 3: s2_ldap_login_filter
*
* The prefix needs to be passed to the constructor of Connection class,
* except the default (first) server shall be connected to.
*
*/
public function getServerConfigurationPrefixes($activeConfigurations = false)
{
$referenceConfigkey = 'ldap_configuration_active';
$sql = '
SELECT DISTINCT `configkey`
FROM `*PREFIX*appconfig`
WHERE `appid` = \'user_ldap\'
AND `configkey` LIKE ?
';
if ($activeConfigurations) {
if (\OC_Config::getValue('dbtype', 'sqlite') === 'oci') {
//FIXME oracle hack: need to explicitly cast CLOB to CHAR for comparison
$sql .= ' AND to_char(`configvalue`)=\'1\'';
} else {
$sql .= ' AND `configvalue` = \'1\'';
}
}
$stmt = \OCP\DB::prepare($sql);
$serverConfigs = $stmt->execute(array('%' . $referenceConfigkey))->fetchAll();
$prefixes = array();
foreach ($serverConfigs as $serverConfig) {
$len = strlen($serverConfig['configkey']) - strlen($referenceConfigkey);
$prefixes[] = substr($serverConfig['configkey'], 0, $len);
}
return $prefixes;
}
示例14: send
/**
* send an email
*
* @param string $toaddress
* @param string $toname
* @param string $subject
* @param string $mailtext
* @param string $fromaddress
* @param string $fromname
* @param bool $html
*/
public static function send($toaddress, $toname, $subject, $mailtext, $fromaddress, $fromname, $html = 0, $altbody = '', $ccaddress = '', $ccname = '', $bcc = '')
{
$SMTPMODE = OC_Config::getValue('mail_smtpmode', 'sendmail');
$SMTPHOST = OC_Config::getValue('mail_smtphost', '127.0.0.1');
$SMTPAUTH = OC_Config::getValue('mail_smtpauth', false);
$SMTPUSERNAME = OC_Config::getValue('mail_smtpname', '');
$SMTPPASSWORD = OC_Config::getValue('mail_smtppassword', '');
$mailo = new PHPMailer(true);
if ($SMTPMODE == 'sendmail') {
$mailo->IsSendmail();
} elseif ($SMTPMODE == 'smtp') {
$mailo->IsSMTP();
} elseif ($SMTPMODE == 'qmail') {
$mailo->IsQmail();
} else {
$mailo->IsMail();
}
$mailo->Host = $SMTPHOST;
$mailo->SMTPAuth = $SMTPAUTH;
$mailo->Username = $SMTPUSERNAME;
$mailo->Password = $SMTPPASSWORD;
$mailo->From = $fromaddress;
$mailo->FromName = $fromname;
$mailo->Sender = $fromaddress;
$a = explode(' ', $toaddress);
try {
foreach ($a as $ad) {
$mailo->AddAddress($ad, $toname);
}
if ($ccaddress != '') {
$mailo->AddCC($ccaddress, $ccname);
}
if ($bcc != '') {
$mailo->AddBCC($bcc);
}
$mailo->AddReplyTo($fromaddress, $fromname);
$mailo->WordWrap = 50;
if ($html == 1) {
$mailo->IsHTML(true);
} else {
$mailo->IsHTML(false);
}
$mailo->Subject = $subject;
if ($altbody == '') {
$mailo->Body = $mailtext . OC_MAIL::getfooter();
$mailo->AltBody = '';
} else {
$mailo->Body = $mailtext;
$mailo->AltBody = $altbody;
}
$mailo->CharSet = 'UTF-8';
$mailo->Send();
unset($mailo);
OC_Log::write('mail', 'Mail from ' . $fromname . ' (' . $fromaddress . ')' . ' to: ' . $toname . '(' . $toaddress . ')' . ' subject: ' . $subject, OC_Log::DEBUG);
} catch (Exception $exception) {
OC_Log::write('mail', $exception->getMessage(), OC_Log::ERROR);
throw $exception;
}
}
示例15: write
/**
* write a message in the log
* @param string $app
* @param string $message
* @param int $level
*/
public static function write($app, $message, $level)
{
$minLevel = min(OC_Config::getValue("loglevel", OC_Log::WARN), OC_Log::ERROR);
if ($level >= $minLevel) {
$syslog_level = self::$levels[$level];
syslog($syslog_level, '{' . $app . '} ' . $message);
}
}