Remove global vars and use the OC static version.

Removed global vars are DOCUMENTROOT, SERVERROOT, SUBURI, WEBROOT and CONFIG_DATADIRECTORY
This commit is contained in:
Bart Visscher 2011-09-18 19:37:54 +02:00
parent d5656716f6
commit 82c7598861
31 changed files with 103 additions and 166 deletions

5
3rdparty/MDB2.php vendored
View File

@ -969,11 +969,10 @@ class MDB2
static function fileExists($file) static function fileExists($file)
{ {
// safe_mode does notwork with is_readable() // safe_mode does notwork with is_readable()
global $SERVERROOT;
if (!@ini_get('safe_mode')) { if (!@ini_get('safe_mode')) {
$dirs = explode(PATH_SEPARATOR, ini_get('include_path')); $dirs = explode(PATH_SEPARATOR, ini_get('include_path'));
array_unshift($dirs,$SERVERROOT); array_unshift($dirs,OC::$SERVERROOT);
array_unshift($dirs,$SERVERROOT. DIRECTORY_SEPARATOR .'inc'); array_unshift($dirs,OC::$SERVERROOT. DIRECTORY_SEPARATOR .'inc');
// print_r($dirs);die(); // print_r($dirs);die();
foreach ($dirs as $dir) { foreach ($dirs as $dir) {
if (is_readable($dir . DIRECTORY_SEPARATOR . $file)) { if (is_readable($dir . DIRECTORY_SEPARATOR . $file)) {

View File

@ -71,8 +71,7 @@ class MDB2_Driver_Manager_sqlite extends MDB2_Driver_Manager_Common
*/ */
function createDatabase($name, $options = array()) function createDatabase($name, $options = array())
{ {
global $SERVERROOT; $datadir=OC_Config::getValue( "datadirectory", OC::$SERVERROOT."/data" );
$datadir=OC_Config::getValue( "datadirectory", "$SERVERROOT/data" );
$db =$this->getDBInstance(); $db =$this->getDBInstance();
if (PEAR::isError($db)) { if (PEAR::isError($db)) {
return $db; return $db;

View File

@ -347,8 +347,7 @@ class MDB2_Driver_sqlite extends MDB2_Driver_Common
**/ **/
function connect() function connect()
{ {
global $SERVERROOT; $datadir=OC_Config::getValue( "datadirectory", OC::$SERVERROOT."/data" );
$datadir=OC_Config::getValue( "datadirectory", "$SERVERROOT/data" );
$database_file = $this->_getDatabaseFile($this->database_name); $database_file = $this->_getDatabaseFile($this->database_name);
if (is_resource($this->connection)) { if (is_resource($this->connection)) {
//if (count(array_diff($this->connected_dsn, $this->dsn)) == 0 //if (count(array_diff($this->connected_dsn, $this->dsn)) == 0

View File

@ -38,7 +38,7 @@ $nodes = array(
// Fire up server // Fire up server
$server = new Sabre_DAV_Server($nodes); $server = new Sabre_DAV_Server($nodes);
$server->setBaseUri($WEBROOT.'/apps/calendar/caldav.php'); $server->setBaseUri(OC::$WEBROOT.'/apps/calendar/caldav.php');
// Add plugins // Add plugins
$server->addPlugin(new Sabre_DAV_Auth_Plugin($authBackend,'ownCloud')); $server->addPlugin(new Sabre_DAV_Auth_Plugin($authBackend,'ownCloud'));
$server->addPlugin(new Sabre_CalDAV_Plugin()); $server->addPlugin(new Sabre_CalDAV_Plugin());

View File

@ -38,7 +38,7 @@ $nodes = array(
// Fire up server // Fire up server
$server = new Sabre_DAV_Server($nodes); $server = new Sabre_DAV_Server($nodes);
$server->setBaseUri($WEBROOT.'/apps/contacts/carddav.php'); $server->setBaseUri(OC::$WEBROOT.'/apps/contacts/carddav.php');
// Add plugins // Add plugins
$server->addPlugin(new Sabre_DAV_Auth_Plugin($authBackend,'ownCloud')); $server->addPlugin(new Sabre_DAV_Auth_Plugin($authBackend,'ownCloud'));
$server->addPlugin(new Sabre_CardDAV_Plugin()); $server->addPlugin(new Sabre_CardDAV_Plugin());

View File

@ -41,7 +41,6 @@ if(!isset($_POST['action']) and isset($_GET['action'])){
foreach($arguments as &$argument){ foreach($arguments as &$argument){
$argument=stripslashes($argument); $argument=stripslashes($argument);
} }
global $CONFIG_DATADIRECTORY;
@ob_clean(); @ob_clean();
if(!isset($arguments['artist'])){ if(!isset($arguments['artist'])){
$arguments['artist']=0; $arguments['artist']=0;

View File

@ -157,7 +157,6 @@ class OC_MEDIA_AMPACHE{
} }
private static function printSong($song,$artistName=false,$albumName=false){ private static function printSong($song,$artistName=false,$albumName=false){
global $WEBROOT;
if(!$artistName){ if(!$artistName){
$artistName=OC_MEDIA_COLLECTION::getArtistName($song['song_artist']); $artistName=OC_MEDIA_COLLECTION::getArtistName($song['song_artist']);
} }

View File

@ -35,7 +35,6 @@ foreach($arguments as &$argument){
$argument=stripslashes($argument); $argument=stripslashes($argument);
} }
ob_clean(); ob_clean();
global $CONFIG_DATADIRECTORY;
if(isset($arguments['action'])){ if(isset($arguments['action'])){
error_log($arguments['action']); error_log($arguments['action']);
switch($arguments['action']){ switch($arguments['action']){

View File

@ -67,7 +67,7 @@ if(count($pathParts) >= 8 && $pathParts[0] == '' && $pathParts[2] == 'unhosted'
$server = new Sabre_DAV_Server($publicDir); $server = new Sabre_DAV_Server($publicDir);
// Path to our script // Path to our script
$server->setBaseUri("$WEBROOT/apps/unhosted/compat.php/$ownCloudUser"); $server->setBaseUri(OC::$WEBROOT."/apps/unhosted/compat.php/$ownCloudUser");
// Auth backend // Auth backend
$authBackend = new OC_Connector_Sabre_Auth_ro_oauth(OC_UnhostedWeb::getValidTokens($ownCloudUser, $userName.'@'.$userHost, $dataScope)); $authBackend = new OC_Connector_Sabre_Auth_ro_oauth(OC_UnhostedWeb::getValidTokens($ownCloudUser, $userName.'@'.$userHost, $dataScope));

View File

@ -32,13 +32,12 @@ if(isset($_GET['openid_mode']) and $_GET['openid_mode'] == 'id_res'){
$openid_validation_result = $openid->ValidateWithServer(); $openid_validation_result = $openid->ValidateWithServer();
if ($openid_validation_result == true){ // OK HERE KEY IS VALID if ($openid_validation_result == true){ // OK HERE KEY IS VALID
error_log('auth sucessfull'); error_log('auth sucessfull');
global $WEBROOT;
$identity=$openid->GetIdentity(); $identity=$openid->GetIdentity();
error_log("auth as $identity"); error_log("auth as $identity");
$user=OC_USER_OPENID::findUserForIdentity($identity); $user=OC_USER_OPENID::findUserForIdentity($identity);
if($user){ if($user){
$_SESSION['user_id']=$user; $_SESSION['user_id']=$user;
header("Location: $WEBROOT"); header("Location: ".OC::$WEBROOT);
} }
}else if($openid->IsError() == true){ // ON THE WAY, WE GOT SOME ERROR }else if($openid->IsError() == true){ // ON THE WAY, WE GOT SOME ERROR
$error = $openid->GetError(); $error = $openid->GetError();

View File

@ -42,7 +42,6 @@ if(!OC_User::userExists($USERNAME)){
error_log($USERNAME.' doesn\'t exist'); error_log($USERNAME.' doesn\'t exist');
$USERNAME=''; $USERNAME='';
} }
global $WEBROOT;
$IDENTITY=OC_Helper::linkTo( "user_openid", "user.php", null, true ).'/'.$USERNAME; $IDENTITY=OC_Helper::linkTo( "user_openid", "user.php", null, true ).'/'.$USERNAME;
require_once 'phpmyid.php'; require_once 'phpmyid.php';

View File

@ -36,13 +36,12 @@ class OC_USER_OPENID extends OC_User_Backend {
* Check if the password is correct without logging in the user * Check if the password is correct without logging in the user
*/ */
public function checkPassword( $uid, $password ){ public function checkPassword( $uid, $password ){
global $WEBROOT;
// Get identity from user and redirect browser to OpenID Server // Get identity from user and redirect browser to OpenID Server
$openid = new SimpleOpenID; $openid = new SimpleOpenID;
$openid->SetIdentity($uid); $openid->SetIdentity($uid);
$openid->SetTrustRoot('http://' . $_SERVER["HTTP_HOST"]); $openid->SetTrustRoot('http://' . $_SERVER["HTTP_HOST"]);
if ($openid->GetOpenIDServer()){ if ($openid->GetOpenIDServer()){
$openid->SetApprovedURL('http://' . $_SERVER["HTTP_HOST"] . $WEBROOT); // Send Response from OpenID server to this script $openid->SetApprovedURL('http://' . $_SERVER["HTTP_HOST"] . OC::$WEBROOT); // Send Response from OpenID server to this script
$openid->Redirect(); // This will redirect user to OpenID Server $openid->Redirect(); // This will redirect user to OpenID Server
exit; exit;
}else{ }else{

View File

@ -8,7 +8,7 @@
<link rel="stylesheet" href="<?php echo $cssfile; ?>" type="text/css" media="screen" /> <link rel="stylesheet" href="<?php echo $cssfile; ?>" type="text/css" media="screen" />
<?php endforeach; ?> <?php endforeach; ?>
<script type="text/javascript"> <script type="text/javascript">
var oc_webroot = '<?php global $WEBROOT; echo $WEBROOT; ?>'; var oc_webroot = '<?php echo OC::$WEBROOT; ?>';
</script> </script>
<?php foreach($_['jsfiles'] as $jsfile): ?> <?php foreach($_['jsfiles'] as $jsfile): ?>
<script type="text/javascript" src="<?php echo $jsfile; ?>"></script> <script type="text/javascript" src="<?php echo $jsfile; ?>"></script>

View File

@ -8,7 +8,7 @@
<link rel="stylesheet" href="<?php echo $cssfile; ?>" type="text/css" media="screen" /> <link rel="stylesheet" href="<?php echo $cssfile; ?>" type="text/css" media="screen" />
<?php endforeach; ?> <?php endforeach; ?>
<script type="text/javascript"> <script type="text/javascript">
var oc_webroot = '<?php global $WEBROOT; echo $WEBROOT; ?>'; var oc_webroot = '<?php echo OC::$WEBROOT; ?>';
var oc_current_user = '<?php echo OC_User::getUser() ?>'; var oc_current_user = '<?php echo OC_User::getUser() ?>';
</script> </script>
<?php foreach($_['jsfiles'] as $jsfile): ?> <?php foreach($_['jsfiles'] as $jsfile): ?>

View File

@ -37,7 +37,7 @@ $publicDir = new OC_Connector_Sabre_Directory('');
// Fire up server // Fire up server
$server = new Sabre_DAV_Server($publicDir); $server = new Sabre_DAV_Server($publicDir);
$server->setBaseUri($WEBROOT.'/files/webdav.php'); $server->setBaseUri(OC::$WEBROOT.'/files/webdav.php');
// Load plugins // Load plugins
$server->addPlugin(new Sabre_DAV_Auth_Plugin($authBackend,'ownCloud')); $server->addPlugin(new Sabre_DAV_Auth_Plugin($authBackend,'ownCloud'));

View File

@ -50,11 +50,11 @@ if($_SERVER['REQUEST_METHOD']=='PROPFIND'){//handle webdav
elseif(OC_User::isLoggedIn()) { elseif(OC_User::isLoggedIn()) {
if(isset($_GET["logout"]) and ($_GET["logout"])) { if(isset($_GET["logout"]) and ($_GET["logout"])) {
OC_User::logout(); OC_User::logout();
header("Location: ".$WEBROOT.'/'); header("Location: ".OC::$WEBROOT.'/');
exit(); exit();
} }
else { else {
header("Location: ".$WEBROOT.'/'.OC_Appconfig::getValue("core", "defaultpage", "files/index.php")); header("Location: ".OC::$WEBROOT.'/'.OC_Appconfig::getValue("core", "defaultpage", "files/index.php"));
exit(); exit();
} }
} }
@ -67,7 +67,7 @@ elseif(isset($_COOKIE["oc_remember_login"]) && $_COOKIE["oc_remember_login"]) {
if(OC_User::userExists($_COOKIE['oc_username']) && if(OC_User::userExists($_COOKIE['oc_username']) &&
OC_Preferences::getValue($_COOKIE['oc_username'], "login", "token") == $_COOKIE['oc_token']) { OC_Preferences::getValue($_COOKIE['oc_username'], "login", "token") == $_COOKIE['oc_token']) {
OC_User::setUserId($_COOKIE['oc_username']); OC_User::setUserId($_COOKIE['oc_username']);
header("Location: ". $WEBROOT.'/'.OC_Appconfig::getValue("core", "defaultpage", "files/index.php")); header("Location: ". OC::$WEBROOT.'/'.OC_Appconfig::getValue("core", "defaultpage", "files/index.php"));
} }
else { else {
OC_Template::printGuestPage("", "login", array("error" => true)); OC_Template::printGuestPage("", "login", array("error" => true));
@ -78,7 +78,7 @@ elseif(isset($_COOKIE["oc_remember_login"]) && $_COOKIE["oc_remember_login"]) {
elseif(isset($_POST["user"]) && isset($_POST['password'])) { elseif(isset($_POST["user"]) && isset($_POST['password'])) {
OC_App::loadApps(); OC_App::loadApps();
if(OC_User::login($_POST["user"], $_POST["password"])) { if(OC_User::login($_POST["user"], $_POST["password"])) {
header("Location: ".$WEBROOT.'/'.OC_Appconfig::getValue("core", "defaultpage", "files/index.php")); header("Location: ".OC::$WEBROOT.'/'.OC_Appconfig::getValue("core", "defaultpage", "files/index.php"));
if(!empty($_POST["remember_login"])){ if(!empty($_POST["remember_login"])){
error_log("Setting remember login to cookie"); error_log("Setting remember login to cookie");
$token = md5($_POST["user"].time()); $token = md5($_POST["user"].time());

View File

@ -69,8 +69,7 @@ class MDB2_Driver_Manager_sqlite3 extends MDB2_Driver_Manager_Common
*/ */
function createDatabase($name, $options = array()) function createDatabase($name, $options = array())
{ {
global $SERVERROOT; $datadir=OC_Config::getValue( "datadirectory", OC::$SERVERROOT."/data" );
$datadir=OC_Config::getValue( "datadirectory", "$SERVERROOT/data" );
$db =$this->getDBInstance(); $db =$this->getDBInstance();
if (PEAR::isError($db)) { if (PEAR::isError($db)) {
return $db; return $db;

View File

@ -351,8 +351,7 @@ class MDB2_Driver_sqlite3 extends MDB2_Driver_Common
if($this->connection instanceof SQLite3){ if($this->connection instanceof SQLite3){
return MDB2_OK; return MDB2_OK;
} }
global $SERVERROOT; $datadir=OC_Config::getValue( "datadirectory", OC::$SERVERROOT."/data" );
$datadir=OC_Config::getValue( "datadirectory", "$SERVERROOT/data" );
$database_file = $this->_getDatabaseFile($this->database_name); $database_file = $this->_getDatabaseFile($this->database_name);
if (is_resource($this->connection)) { if (is_resource($this->connection)) {
//if (count(array_diff($this->connected_dsn, $this->dsn)) == 0 //if (count(array_diff($this->connected_dsn, $this->dsn)) == 0

View File

@ -44,8 +44,6 @@ class OC_App{
* exists. * exists.
*/ */
public static function loadApps(){ public static function loadApps(){
global $SERVERROOT;
// Did we allready load everything? // Did we allready load everything?
if( self::$init ){ if( self::$init ){
return true; return true;
@ -60,7 +58,7 @@ class OC_App{
$apps = OC_Appconfig::getApps(); $apps = OC_Appconfig::getApps();
foreach( $apps as $app ){ foreach( $apps as $app ){
if( self::isEnabled( $app )){ if( self::isEnabled( $app )){
if(is_file($SERVERROOT.'/apps/'.$app.'/appinfo/app.php')){ if(is_file(OC::$SERVERROOT.'/apps/'.$app.'/appinfo/app.php')){
require( 'apps/'.$app.'/appinfo/app.php' ); require( 'apps/'.$app.'/appinfo/app.php' );
} }
} }
@ -285,8 +283,7 @@ class OC_App{
* @return string * @return string
*/ */
public static function getCurrentApp(){ public static function getCurrentApp(){
global $WEBROOT; $script=substr($_SERVER["SCRIPT_NAME"],strlen(OC::$WEBROOT)+1);
$script=substr($_SERVER["SCRIPT_NAME"],strlen($WEBROOT)+1);
$topFolder=substr($script,0,strpos($script,'/')); $topFolder=substr($script,0,strpos($script,'/'));
if($topFolder=='apps'){ if($topFolder=='apps'){
$length=strlen($topFolder); $length=strlen($topFolder);

View File

@ -81,30 +81,21 @@ ini_set('session.cookie_httponly','1;');
session_start(); session_start();
// calculate the documentroot // calculate the documentroot
$DOCUMENTROOT=realpath($_SERVER['DOCUMENT_ROOT']); OC::$DOCUMENTROOT=realpath($_SERVER['DOCUMENT_ROOT']);
$SERVERROOT=str_replace("\\",'/',substr(__FILE__,0,-13)); OC::$SERVERROOT=str_replace("\\",'/',substr(__FILE__,0,-13));
$SUBURI=substr(realpath($_SERVER["SCRIPT_FILENAME"]),strlen($SERVERROOT)); OC::$SUBURI=substr(realpath($_SERVER["SCRIPT_FILENAME"]),strlen(OC::$SERVERROOT));
$scriptName=$_SERVER["SCRIPT_NAME"]; $scriptName=$_SERVER["SCRIPT_NAME"];
if(substr($scriptName,-1)=='/'){ if(substr($scriptName,-1)=='/'){
$scriptName.='index.php'; $scriptName.='index.php';
} }
$WEBROOT=substr($scriptName,0,strlen($scriptName)-strlen($SUBURI)); OC::$WEBROOT=substr($scriptName,0,strlen($scriptName)-strlen(OC::$SUBURI));
OC::$SERVERROOT=$SERVERROOT; if(OC::$WEBROOT!='' and OC::$WEBROOT[0]!=='/'){
OC::$WEBROOT=$WEBROOT; OC::$WEBROOT='/'.OC::$WEBROOT;
if($WEBROOT!='' and $WEBROOT[0]!=='/'){
$WEBROOT='/'.$WEBROOT;
} }
// We are going to use OC::* instead of globels soon
OC::$WEBROOT = $WEBROOT;
OC::$SERVERROOT = $SERVERROOT;
OC::$DOCUMENTROOT = $DOCUMENTROOT;
OC::$SUBURI = $SUBURI;
// set the right include path // set the right include path
set_include_path($SERVERROOT.'/lib'.PATH_SEPARATOR.$SERVERROOT.'/config'.PATH_SEPARATOR.$SERVERROOT.'/3rdparty'.PATH_SEPARATOR.get_include_path().PATH_SEPARATOR.$SERVERROOT); set_include_path(OC::$SERVERROOT.'/lib'.PATH_SEPARATOR.OC::$SERVERROOT.'/config'.PATH_SEPARATOR.OC::$SERVERROOT.'/3rdparty'.PATH_SEPARATOR.get_include_path().PATH_SEPARATOR.OC::$SERVERROOT);
//Some libs we really depend on //Some libs we really depend on
require_once('Sabre/autoload.php'); require_once('Sabre/autoload.php');
@ -119,9 +110,9 @@ if( !isset( $RUNTIME_NOAPPS )){
// TODO: we should get rid of this one, too // TODO: we should get rid of this one, too
// WARNING: to make everything even more confusing, DATADIRECTORY is a var that // WARNING: to make everything even more confusing, DATADIRECTORY is a var that
// changes and DATATIRECTORY_ROOT stays the same, but is set by // changes and DATADIRECTORY_ROOT stays the same, but is set by
// "datadirectory". Any questions? // "datadirectory". Any questions?
$CONFIG_DATADIRECTORY = OC_Config::getValue( "datadirectory", "$SERVERROOT/data" ); OC::$CONFIG_DATADIRECTORY = OC_Config::getValue( "datadirectory", OC::$SERVERROOT."/data" );
// redirect to https site if configured // redirect to https site if configured
if( OC_Config::getValue( "forcessl", false )){ if( OC_Config::getValue( "forcessl", false )){

View File

@ -131,14 +131,12 @@ class OC_Config{
return true; return true;
} }
global $SERVERROOT; if( !file_exists( OC::$SERVERROOT."/config/config.php" )){
if( !file_exists( "$SERVERROOT/config/config.php" )){
return false; return false;
} }
// Include the file, save the data from $CONFIG // Include the file, save the data from $CONFIG
include( "$SERVERROOT/config/config.php" ); include( OC::$SERVERROOT."/config/config.php" );
if( isset( $CONFIG ) && is_array( $CONFIG )){ if( isset( $CONFIG ) && is_array( $CONFIG )){
self::$cache = $CONFIG; self::$cache = $CONFIG;
} }
@ -158,9 +156,6 @@ class OC_Config{
* Known flaws: Strings are not escaped properly * Known flaws: Strings are not escaped properly
*/ */
public static function writeData(){ public static function writeData(){
// We need the serverroot path
global $SERVERROOT;
// Create a php file ... // Create a php file ...
$content = "<?php\n\$CONFIG = array(\n"; $content = "<?php\n\$CONFIG = array(\n";
@ -177,7 +172,7 @@ class OC_Config{
$content .= ");\n?>\n"; $content .= ");\n?>\n";
// Write the file // Write the file
$result=@file_put_contents( "$SERVERROOT/config/config.php", $content ); $result=@file_put_contents( OC::$SERVERROOT."/config/config.php", $content );
if(!$result) { if(!$result) {
$tmpl = new OC_Template( '', 'error', 'guest' ); $tmpl = new OC_Template( '', 'error', 'guest' );
$tmpl->assign('errors',array(1=>array('error'=>"Can't write into config directory 'config'",'hint'=>"You can usually fix this by setting the owner of 'config' to the user that the web server uses (".exec('whoami').")"))); $tmpl->assign('errors',array(1=>array('error'=>"Can't write into config directory 'config'",'hint'=>"You can usually fix this by setting the owner of 'config' to the user that the web server uses (".exec('whoami').")")));

View File

@ -43,8 +43,7 @@ class OC_DB {
$CONFIG_DBUSER = OC_Config::getValue( "dbuser", "" );; $CONFIG_DBUSER = OC_Config::getValue( "dbuser", "" );;
$CONFIG_DBPASSWORD = OC_Config::getValue( "dbpassword", "" );; $CONFIG_DBPASSWORD = OC_Config::getValue( "dbpassword", "" );;
$CONFIG_DBTYPE = OC_Config::getValue( "dbtype", "sqlite" );; $CONFIG_DBTYPE = OC_Config::getValue( "dbtype", "sqlite" );;
global $SERVERROOT; $datadir=OC_Config::getValue( "datadirectory", OC::$SERVERROOT."/data" );
$datadir=OC_Config::getValue( "datadirectory", "$SERVERROOT/data" );
// do nothing if the connection already has been established // do nothing if the connection already has been established
if(!self::$DBConnection){ if(!self::$DBConnection){

View File

@ -33,9 +33,8 @@ class OC_Files {
* @param dir $directory * @param dir $directory
*/ */
public static function getDirectoryContent($directory){ public static function getDirectoryContent($directory){
global $CONFIG_DATADIRECTORY; if(strpos($directory,OC::$CONFIG_DATADIRECTORY)===0){
if(strpos($directory,$CONFIG_DATADIRECTORY)===0){ $directory=substr($directory,strlen(OC::$CONFIG_DATADIRECTORY));
$directory=substr($directory,strlen($CONFIG_DATADIRECTORY));
} }
$filesfound=true; $filesfound=true;
$content=array(); $content=array();
@ -279,16 +278,14 @@ class OC_Files {
* @param int size filesisze in bytes * @param int size filesisze in bytes
*/ */
static function setUploadLimit($size){ static function setUploadLimit($size){
global $SERVERROOT;
global $WEBROOT;
$size=OC_Helper::humanFileSize($size); $size=OC_Helper::humanFileSize($size);
$size=substr($size,0,-1);//strip the B $size=substr($size,0,-1);//strip the B
$size=str_replace(' ','',$size); //remove the space between the size and the postfix $size=str_replace(' ','',$size); //remove the space between the size and the postfix
$content = "ErrorDocument 404 /$WEBROOT/core/templates/404.php\n";//custom 404 error page $content = "ErrorDocument 404 /".OC::$WEBROOT."/core/templates/404.php\n";//custom 404 error page
$content.= "php_value upload_max_filesize $size\n";//upload limit $content.= "php_value upload_max_filesize $size\n";//upload limit
$content.= "php_value post_max_size $size\n"; $content.= "php_value post_max_size $size\n";
$content.= "SetEnv htaccessWorking true\n"; $content.= "SetEnv htaccessWorking true\n";
$content.= "Options -Indexes\n"; $content.= "Options -Indexes\n";
@file_put_contents($SERVERROOT.'/.htaccess', $content); //supress errors in case we don't have permissions for it @file_put_contents(OC::$SERVERROOT.'/.htaccess', $content); //supress errors in case we don't have permissions for it
} }
} }

View File

@ -35,25 +35,22 @@ class OC_Helper {
* Returns a url to the given app and file. * Returns a url to the given app and file.
*/ */
public static function linkTo( $app, $file, $redirect_url=NULL, $absolute=false ){ public static function linkTo( $app, $file, $redirect_url=NULL, $absolute=false ){
global $WEBROOT;
global $SERVERROOT;
if( $app != '' ){ if( $app != '' ){
$app .= '/'; $app .= '/';
// Check if the app is in the app folder // Check if the app is in the app folder
if( file_exists( $SERVERROOT . '/apps/'. $app.$file )){ if( file_exists( OC::$SERVERROOT . '/apps/'. $app.$file )){
$urlLinkTo = $WEBROOT . '/apps/' . $app . $file; $urlLinkTo = OC::$WEBROOT . '/apps/' . $app . $file;
} }
else{ else{
$urlLinkTo = $WEBROOT . '/' . $app . $file; $urlLinkTo = OC::$WEBROOT . '/' . $app . $file;
} }
} }
else{ else{
if( file_exists( $SERVERROOT . '/core/'. $file )){ if( file_exists( OC::$SERVERROOT . '/core/'. $file )){
$urlLinkTo = $WEBROOT . '/core/'.$file; $urlLinkTo = OC::$WEBROOT . '/core/'.$file;
} }
else{ else{
$urlLinkTo = $WEBROOT . '/'.$file; $urlLinkTo = OC::$WEBROOT . '/'.$file;
} }
} }
@ -79,18 +76,15 @@ class OC_Helper {
* Returns the path to the image. * Returns the path to the image.
*/ */
public static function imagePath( $app, $image ){ public static function imagePath( $app, $image ){
global $SERVERROOT;
global $WEBROOT;
// Check if the app is in the app folder // Check if the app is in the app folder
if( file_exists( "$SERVERROOT/apps/$app/img/$image" )){ if( file_exists( OC::$SERVERROOT."/apps/$app/img/$image" )){
return "$WEBROOT/apps/$app/img/$image"; return OC::$WEBROOT."/apps/$app/img/$image";
} }
elseif( !empty( $app )){ elseif( !empty( $app )){
return "$WEBROOT/$app/img/$image"; return OC::$WEBROOT."/$app/img/$image";
} }
else{ else{
return "$WEBROOT/core/img/$image"; return OC::$WEBROOT."/core/img/$image";
} }
} }
@ -102,27 +96,25 @@ class OC_Helper {
* Returns the path to the image of this file type. * Returns the path to the image of this file type.
*/ */
public static function mimetypeIcon( $mimetype ){ public static function mimetypeIcon( $mimetype ){
global $SERVERROOT;
global $WEBROOT;
// Replace slash with a minus // Replace slash with a minus
$mimetype = str_replace( "/", "-", $mimetype ); $mimetype = str_replace( "/", "-", $mimetype );
// Is it a dir? // Is it a dir?
if( $mimetype == "dir" ){ if( $mimetype == "dir" ){
return "$WEBROOT/core/img/places/folder.svg"; return OC::$WEBROOT."/core/img/places/folder.svg";
} }
// Icon exists? // Icon exists?
if( file_exists( "$SERVERROOT/core/img/filetypes/$mimetype.svg" )){ if( file_exists( OC::$SERVERROOT."/core/img/filetypes/$mimetype.svg" )){
return "$WEBROOT/core/img/filetypes/$mimetype.svg"; return OC::$WEBROOT."/core/img/filetypes/$mimetype.svg";
} }
//try only the first part of the filetype //try only the first part of the filetype
$mimetype=substr($mimetype,0,strpos($mimetype,'-')); $mimetype=substr($mimetype,0,strpos($mimetype,'-'));
if( file_exists( "$SERVERROOT/core/img/filetypes/$mimetype.svg" )){ if( file_exists( OC::$SERVERROOT."/core/img/filetypes/$mimetype.svg" )){
return "$WEBROOT/core/img/filetypes/$mimetype.svg"; return OC::$WEBROOT."/core/img/filetypes/$mimetype.svg";
} }
else{ else{
return "$WEBROOT/core/img/filetypes/file.svg"; return OC::$WEBROOT."/core/img/filetypes/file.svg";
} }
} }

View File

@ -55,8 +55,6 @@ class OC_Installer{
* needed to get the app working. * needed to get the app working.
*/ */
public static function installApp( $data = array()){ public static function installApp( $data = array()){
global $SERVERROOT;
if(!isset($data['source'])){ if(!isset($data['source'])){
error_log("No source specified when installing app"); error_log("No source specified when installing app");
return false; return false;
@ -105,7 +103,7 @@ class OC_Installer{
return false; return false;
} }
$info=OC_App::getAppInfo($extractDir.'/appinfo/info.xml'); $info=OC_App::getAppInfo($extractDir.'/appinfo/info.xml');
$basedir=$SERVERROOT.'/apps/'.$info['id']; $basedir=OC::$SERVERROOT.'/apps/'.$info['id'];
//check if an app with the same id is already installed //check if an app with the same id is already installed
if(self::isInstalled( $info['id'] )){ if(self::isInstalled( $info['id'] )){
@ -246,11 +244,10 @@ class OC_Installer{
* If $enabled is false, apps are installed as disabled. * If $enabled is false, apps are installed as disabled.
*/ */
public static function installShippedApps( $enabled ){ public static function installShippedApps( $enabled ){
global $SERVERROOT; $dir = opendir( OC::$SERVERROOT."/apps" );
$dir = opendir( "$SERVERROOT/apps" );
while( false !== ( $filename = readdir( $dir ))){ while( false !== ( $filename = readdir( $dir ))){
if( substr( $filename, 0, 1 ) != '.' and is_dir("$SERVERROOT/apps/$filename") ){ if( substr( $filename, 0, 1 ) != '.' and is_dir(OC::$SERVERROOT."/apps/$filename") ){
if( file_exists( "$SERVERROOT/apps/$filename/appinfo/app.php" )){ if( file_exists( OC::$SERVERROOT."/apps/$filename/appinfo/app.php" )){
if(!OC_Installer::isInstalled($filename)){ if(!OC_Installer::isInstalled($filename)){
OC_Installer::installShippedApp($filename); OC_Installer::installShippedApp($filename);
if( $enabled ){ if( $enabled ){

View File

@ -57,7 +57,6 @@ class OC_L10N{
* language. * language.
*/ */
public function __construct($app, $lang = null){ public function __construct($app, $lang = null){
global $SERVERROOT;
// Find the right language // Find the right language
if(is_null($lang)){ if(is_null($lang)){
$lang = self::findLanguage($app); $lang = self::findLanguage($app);
@ -81,9 +80,9 @@ class OC_L10N{
} }
} }
if(file_exists($SERVERROOT.'/core/l10n/l10n-'.$lang.'.php')){ if(file_exists(OC::$SERVERROOT.'/core/l10n/l10n-'.$lang.'.php')){
// Include the file, save the data from $CONFIG // Include the file, save the data from $CONFIG
include($SERVERROOT.'/core/l10n/l10n-'.$lang.'.php'); include(OC::$SERVERROOT.'/core/l10n/l10n-'.$lang.'.php');
if(isset($LOCALIZATIONS) && is_array($LOCALIZATIONS)){ if(isset($LOCALIZATIONS) && is_array($LOCALIZATIONS)){
$this->localizations = array_merge($this->localizations, $LOCALIZATIONS); $this->localizations = array_merge($this->localizations, $LOCALIZATIONS);
} }
@ -224,17 +223,15 @@ class OC_L10N{
* @returns directory * @returns directory
*/ */
protected static function findI18nDir($app){ protected static function findI18nDir($app){
global $SERVERROOT;
// find the i18n dir // find the i18n dir
$i18ndir = $SERVERROOT.'/core/l10n/'; $i18ndir = OC::$SERVERROOT.'/core/l10n/';
if($app != ''){ if($app != ''){
// Check if the app is in the app folder // Check if the app is in the app folder
if(file_exists($SERVERROOT.'/apps/'.$app.'/l10n/')){ if(file_exists(OC::$SERVERROOT.'/apps/'.$app.'/l10n/')){
$i18ndir = $SERVERROOT.'/apps/'.$app.'/l10n/'; $i18ndir = OC::$SERVERROOT.'/apps/'.$app.'/l10n/';
} }
else{ else{
$i18ndir = $SERVERROOT.'/'.$app.'/l10n/'; $i18ndir = OC::$SERVERROOT.'/'.$app.'/l10n/';
} }
} }
return $i18ndir; return $i18ndir;

View File

@ -184,7 +184,6 @@ class OC_REMOTE_CLOUD{
} }
public function sendFile($sourceDir,$sourceFile,$targetDir,$targetFile){ public function sendFile($sourceDir,$sourceFile,$targetDir,$targetFile){
global $WEBROOT;
$source=$sourceDir.'/'.$sourceFile; $source=$sourceDir.'/'.$sourceFile;
$tmp=OC_Filesystem::toTmpFile($source); $tmp=OC_Filesystem::toTmpFile($source);
return $this->sendTmpFile($tmp,$targetDir,$targetFile); return $this->sendTmpFile($tmp,$targetDir,$targetFile);
@ -192,13 +191,12 @@ class OC_REMOTE_CLOUD{
public function sendTmpFile($tmp,$targetDir,$targetFile){ public function sendTmpFile($tmp,$targetDir,$targetFile){
$token=sha1(uniqid().$tmp); $token=sha1(uniqid().$tmp);
global $WEBROOT;
$file=sys_get_temp_dir().'/'.'remoteCloudFile'.$token; $file=sys_get_temp_dir().'/'.'remoteCloudFile'.$token;
rename($tmp,$file); rename($tmp,$file);
if( OC_Config::getValue( "forcessl", false ) or isset($_SERVER['HTTPS']) and $_SERVER['HTTPS'] == 'on') { if( OC_Config::getValue( "forcessl", false ) or isset($_SERVER['HTTPS']) and $_SERVER['HTTPS'] == 'on') {
$url = "https://". $_SERVER['SERVER_NAME'] . $WEBROOT; $url = "https://". $_SERVER['SERVER_NAME'] . OC::$WEBROOT;
}else{ }else{
$url = "http://". $_SERVER['SERVER_NAME'] . $WEBROOT; $url = "http://". $_SERVER['SERVER_NAME'] . OC::$WEBROOT;
} }
return $this->apiCall('pull',array('dir'=>$targetDir,'file'=>$targetFile,'token'=>$token,'source'=>$url),true); return $this->apiCall('pull',array('dir'=>$targetDir,'file'=>$targetFile,'token'=>$token,'source'=>$url),true);
} }

View File

@ -3,7 +3,7 @@
$hasSQLite = (is_callable('sqlite_open') or class_exists('SQLite3')); $hasSQLite = (is_callable('sqlite_open') or class_exists('SQLite3'));
$hasMySQL = is_callable('mysql_connect'); $hasMySQL = is_callable('mysql_connect');
$hasPostgreSQL = is_callable('pg_connect'); $hasPostgreSQL = is_callable('pg_connect');
$datadir = OC_Config::getValue('datadirectory', $SERVERROOT.'/data'); $datadir = OC_Config::getValue('datadirectory', OC::$SERVERROOT.'/data');
$opts = array( $opts = array(
'hasSQLite' => $hasSQLite, 'hasSQLite' => $hasSQLite,
'hasMySQL' => $hasMySQL, 'hasMySQL' => $hasMySQL,
@ -23,7 +23,7 @@ if(isset($_POST['install']) AND $_POST['install']=='true') {
OC_Template::printGuestPage("", "installation", $options); OC_Template::printGuestPage("", "installation", $options);
} }
else { else {
header("Location: ".$WEBROOT.'/'); header("Location: ".OC::$WEBROOT.'/');
exit(); exit();
} }
} }
@ -270,21 +270,19 @@ class OC_Setup {
* create .htaccess files for apache hosts * create .htaccess files for apache hosts
*/ */
private static function createHtaccess() { private static function createHtaccess() {
$SERVERROOT=OC::$SERVERROOT; $content = "ErrorDocument 404 ".OC::$WEBROOT."/core/templates/404.php\n";//custom 404 error page
$WEBROOT=OC::$WEBROOT;
$content = "ErrorDocument 404 $WEBROOT/core/templates/404.php\n";//custom 404 error page
$content.= "<IfModule mod_php5.c>\n"; $content.= "<IfModule mod_php5.c>\n";
$content.= "php_value upload_max_filesize 512M\n";//upload limit $content.= "php_value upload_max_filesize 512M\n";//upload limit
$content.= "php_value post_max_size 512M\n"; $content.= "php_value post_max_size 512M\n";
$content.= "SetEnv htaccessWorking true\n"; $content.= "SetEnv htaccessWorking true\n";
$content.= "</IfModule>\n"; $content.= "</IfModule>\n";
$content.= "Options -Indexes\n"; $content.= "Options -Indexes\n";
@file_put_contents($SERVERROOT.'/.htaccess', $content); //supress errors in case we don't have permissions for it @file_put_contents(OC::$SERVERROOT.'/.htaccess', $content); //supress errors in case we don't have permissions for it
$content = "deny from all\n"; $content = "deny from all\n";
$content.= "IndexIgnore *"; $content.= "IndexIgnore *";
file_put_contents(OC_Config::getValue('datadirectory', $SERVERROOT.'/data').'/.htaccess', $content); file_put_contents(OC_Config::getValue('datadirectory', OC::$SERVERROOT.'/data').'/.htaccess', $content);
file_put_contents(OC_Config::getValue('datadirectory', $SERVERROOT.'/data').'/index.html', ''); file_put_contents(OC_Config::getValue('datadirectory', OC::$SERVERROOT.'/data').'/index.html', '');
} }
} }

View File

@ -124,18 +124,15 @@ class OC_Template{
* "admin". * "admin".
*/ */
public function __construct( $app, $name, $renderas = "" ){ public function __construct( $app, $name, $renderas = "" ){
// Global vars we need
global $SERVERROOT;
// Get the right template folder // Get the right template folder
$template = "$SERVERROOT/core/templates/"; $template = OC::$SERVERROOT."/core/templates/";
if( $app != "" ){ if( $app != "" ){
// Check if the app is in the app folder // Check if the app is in the app folder
if( file_exists( "$SERVERROOT/apps/$app/templates/" )){ if( file_exists( OC::$SERVERROOT."/apps/$app/templates/" )){
$template = "$SERVERROOT/apps/$app/templates/"; $template = OC::$SERVERROOT."/apps/$app/templates/";
} }
else{ else{
$template = "$SERVERROOT/$app/templates/"; $template = OC::$SERVERROOT."/$app/templates/";
} }
} }
@ -222,9 +219,6 @@ class OC_Template{
* will produce a full page. * will produce a full page.
*/ */
public function fetchPage(){ public function fetchPage(){
// global Data we need
global $WEBROOT;
global $SERVERROOT;
$data = $this->_fetch(); $data = $this->_fetch();
if( $this->renderas ){ if( $this->renderas ){
@ -247,25 +241,25 @@ class OC_Template{
// Add the css and js files // Add the css and js files
foreach(OC_Util::$scripts as $script){ foreach(OC_Util::$scripts as $script){
if(is_file("$SERVERROOT/apps/$script.js" )){ if(is_file(OC::$SERVERROOT."/apps/$script.js" )){
$page->append( "jsfiles", "$WEBROOT/apps/$script.js" ); $page->append( "jsfiles", OC::$WEBROOT."/apps/$script.js" );
} }
elseif(is_file("$SERVERROOT/$script.js" )){ elseif(is_file(OC::$SERVERROOT."/$script.js" )){
$page->append( "jsfiles", "$WEBROOT/$script.js" ); $page->append( "jsfiles", OC::$WEBROOT."/$script.js" );
} }
else{ else{
$page->append( "jsfiles", "$WEBROOT/core/$script.js" ); $page->append( "jsfiles", OC::$WEBROOT."/core/$script.js" );
} }
} }
foreach(OC_Util::$styles as $style){ foreach(OC_Util::$styles as $style){
if(is_file("$SERVERROOT/apps/$style.css" )){ if(is_file(OC::$SERVERROOT."/apps/$style.css" )){
$page->append( "cssfiles", "$WEBROOT/apps/$style.css" ); $page->append( "cssfiles", OC::$WEBROOT."/apps/$style.css" );
} }
elseif(is_file("$SERVERROOT/$style.css" )){ elseif(is_file(OC::$SERVERROOT."/$style.css" )){
$page->append( "cssfiles", "$WEBROOT/$style.css" ); $page->append( "cssfiles", OC::$WEBROOT."/$style.css" );
} }
else{ else{
$page->append( "cssfiles", "$WEBROOT/core/$style.css" ); $page->append( "cssfiles", OC::$WEBROOT."/core/$style.css" );
} }
} }

View File

@ -16,19 +16,15 @@ class OC_Util {
return false; return false;
} }
// Global Variables $CONFIG_DATADIRECTORY_ROOT = OC_Config::getValue( "datadirectory", OC::$SERVERROOT."/data" );
global $SERVERROOT; $CONFIG_BACKUPDIRECTORY = OC_Config::getValue( "backupdirectory", OC::$SERVERROOT."/backup" );
global $CONFIG_DATADIRECTORY;
$CONFIG_DATADIRECTORY_ROOT = OC_Config::getValue( "datadirectory", "$SERVERROOT/data" );
$CONFIG_BACKUPDIRECTORY = OC_Config::getValue( "backupdirectory", "$SERVERROOT/backup" );
// Create root dir // Create root dir
if(!is_dir($CONFIG_DATADIRECTORY_ROOT)){ if(!is_dir($CONFIG_DATADIRECTORY_ROOT)){
$success=@mkdir($CONFIG_DATADIRECTORY_ROOT); $success=@mkdir($CONFIG_DATADIRECTORY_ROOT);
if(!$success) { if(!$success) {
$tmpl = new OC_Template( '', 'error', 'guest' ); $tmpl = new OC_Template( '', 'error', 'guest' );
$tmpl->assign('errors',array(1=>array('error'=>"Can't create data directory ($CONFIG_DATADIRECTORY_ROOT)",'hint'=>"You can usually fix this by setting the owner of '$SERVERROOT' to the user that the web server uses (".exec('whoami').")"))); $tmpl->assign('errors',array(1=>array('error'=>"Can't create data directory (".$CONFIG_DATADIRECTORY_ROOT.")",'hint'=>"You can usually fix this by setting the owner of '".OC::$SERVERROOT."' to the user that the web server uses (".exec('whoami').")")));
$tmpl->printPage(); $tmpl->printPage();
exit; exit;
} }
@ -57,9 +53,9 @@ class OC_Util {
$sharedStorage = OC_Filesystem::createStorage('shared',array('datadir'=>'/'.OC_User::getUser().'/files/Shared')); $sharedStorage = OC_Filesystem::createStorage('shared',array('datadir'=>'/'.OC_User::getUser().'/files/Shared'));
OC_Filesystem::mount($sharedStorage,'/'.OC_User::getUser().'/files/Shared/'); OC_Filesystem::mount($sharedStorage,'/'.OC_User::getUser().'/files/Shared/');
$CONFIG_DATADIRECTORY = "$CONFIG_DATADIRECTORY_ROOT/$user/$root"; OC::$CONFIG_DATADIRECTORY = $CONFIG_DATADIRECTORY_ROOT."/$user/$root";
if( !is_dir( $CONFIG_DATADIRECTORY )){ if( !is_dir( OC::$CONFIG_DATADIRECTORY )){
mkdir( $CONFIG_DATADIRECTORY, 0755, true ); mkdir( OC::$CONFIG_DATADIRECTORY, 0755, true );
} }
// TODO: find a cool way for doing this // TODO: find a cool way for doing this
@ -193,11 +189,8 @@ class OC_Util {
* @return array arrays with error messages and hints * @return array arrays with error messages and hints
*/ */
public static function checkServer(){ public static function checkServer(){
global $SERVERROOT; $CONFIG_DATADIRECTORY_ROOT = OC_Config::getValue( "datadirectory", OC::$SERVERROOT."/data" );
global $CONFIG_DATADIRECTORY; $CONFIG_BACKUPDIRECTORY = OC_Config::getValue( "backupdirectory", OC::$SERVERROOT."/backup" );
$CONFIG_DATADIRECTORY_ROOT = OC_Config::getValue( "datadirectory", "$SERVERROOT/data" );
$CONFIG_BACKUPDIRECTORY = OC_Config::getValue( "backupdirectory", "$SERVERROOT/backup" );
$CONFIG_INSTALLED = OC_Config::getValue( "installed", false ); $CONFIG_INSTALLED = OC_Config::getValue( "installed", false );
$errors=array(); $errors=array();

View File

@ -38,7 +38,7 @@ $query=(isset($_POST['query']))?$_POST['query']:'';
if($query){ if($query){
$results=OC_Search::search($query); $results=OC_Search::search($query);
}else{ }else{
header("Location: ".$WEBROOT.'/'.OC_Appconfig::getValue("core", "defaultpage", "files/index.php")); header("Location: ".OC::$WEBROOT.'/'.OC_Appconfig::getValue("core", "defaultpage", "files/index.php"));
exit(); exit();
} }