Introducing OC_HELPER for small helper functions; making setup of filesystem optional

remotes/origin/stable
Jakob Sack 13 years ago
parent ede34c17dd
commit dfa6b749ba

Binary file not shown.

After

Width:  |  Height:  |  Size: 635 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.8 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 386 B

@ -46,6 +46,11 @@ if($WEBROOT!='' and $WEBROOT[0]!=='/'){
// set the right include path
// set_include_path(get_include_path().PATH_SEPARATOR.$SERVERROOT.PATH_SEPARATOR.$SERVERROOT.'/inc'.PATH_SEPARATOR.$SERVERROOT.'/config');
// define runtime variables - unless this already has been done
if( !isset( $RUNTIME_NOSETUPFS )){
$RUNTIME_NOSETUPFS = false;
}
// define default config values
$CONFIG_INSTALLED=false;
$CONFIG_DATADIRECTORY=$SERVERROOT.'/data';
@ -91,19 +96,35 @@ if(!isset($CONFIG_BACKEND)){
}
OC_USER::setBackend($CONFIG_BACKEND);
OC_UTIL::setupFS();
// Set up file system unless forbidden
if( !$RUNTIME_NOSETUPFS ){
OC_UTIL::setupFS();
}
oc_startup();
// Add the stuff we need always
OC_UTIL::addPersonalMenuEntry( array( "file" => "index.php?logout=1", "name" => "Logout" ));
OC_UTIL::addScript( "jquery-1.5.min" );
OC_UTIL::addScript( "jquery-ui-1.8.10.custom.min" );
OC_UTIL::addScript( "js" );
OC_UTIL::addStyle( "jquery-ui-1.8.10.custom" );
OC_UTIL::addStyle( "styles" );
// Require all appinfo.php
$dir = opendir( $SERVERROOT );
while( false !== ( $filename = readdir( $dir ))){
if( substr( $filename, 0, 1 ) != '.' ){
if( file_exists( "$SERVERROOT/$filename/appinfo.php" )){
oc_require( "$filename/appinfo.php" );
}
}
}
closedir( $dir );
// check if the server is correctly configured for ownCloud
OC_UTIL::checkserver();
// listen for login or logout actions
OC_USER::logoutlistener();
$loginresult=OC_USER::loginlistener();
/**
* Class for utility functions
*
@ -117,28 +138,39 @@ class OC_UTIL {
public static $personalmenu = array();
private static $fsSetup=false;
public static function setupFS(){// configure the initial filesystem based on the configuration
// Can be set up
public static function setupFS( $user = "" ){// configure the initial filesystem based on the configuration
if(self::$fsSetup){//setting up the filesystem twice can only lead to trouble
return false;
}
// Global Variables
global $SERVERROOT;
global $CONFIG_DATADIRECTORY_ROOT;
global $CONFIG_DATADIRECTORY;
global $CONFIG_BACKUPDIRECTORY;
global $CONFIG_ENABLEBACKUP;
global $CONFIG_FILESYSTEM;
// Create root dir
if(!is_dir($CONFIG_DATADIRECTORY_ROOT)){
@mkdir($CONFIG_DATADIRECTORY_ROOT) or die("Can't create data directory ($CONFIG_DATADIRECTORY_ROOT), you can usually fix this by setting the owner of '$SERVERROOT' to the user that the web server uses (www-data for debian/ubuntu)");
}
if(OC_USER::isLoggedIn()){ //if we aren't logged in, there is no use to set up the filesystem
// If we are not forced to load a specific user we load the one that is logged in
if( $user == "" && OC_USER::isLoggedIn()){
$user = $_SESSION['username_clean'];
}
if( $user != "" ){ //if we aren't logged in, there is no use to set up the filesystem
//first set up the local "root" storage and the backupstorage if needed
$rootStorage=OC_FILESYSTEM::createStorage('local',array('datadir'=>$CONFIG_DATADIRECTORY));
if($CONFIG_ENABLEBACKUP){
if(!is_dir($CONFIG_BACKUPDIRECTORY)){
mkdir($CONFIG_BACKUPDIRECTORY);
}
if(!is_dir($CONFIG_BACKUPDIRECTORY.'/'.$_SESSION['username_clean'])){
mkdir($CONFIG_BACKUPDIRECTORY.'/'.$_SESSION['username_clean']);
if(!is_dir($CONFIG_BACKUPDIRECTORY.'/'.$user )){
mkdir($CONFIG_BACKUPDIRECTORY.'/'.$user );
}
$backupStorage=OC_FILESYSTEM::createStorage('local',array('datadir'=>$CONFIG_BACKUPDIRECTORY));
$backup=new OC_FILEOBSERVER_BACKUP(array('storage'=>$backupStorage));
@ -146,7 +178,7 @@ class OC_UTIL {
}
OC_FILESYSTEM::mount($rootStorage,'/');
$CONFIG_DATADIRECTORY=$CONFIG_DATADIRECTORY_ROOT.'/'.$_SESSION['username_clean'];
$CONFIG_DATADIRECTORY=$CONFIG_DATADIRECTORY_ROOT.'/'.$user;
if(!is_dir($CONFIG_DATADIRECTORY)){
mkdir($CONFIG_DATADIRECTORY);
}
@ -165,7 +197,7 @@ class OC_UTIL {
}
//jail the user into his "home" directory
OC_FILESYSTEM::chroot('/'.$_SESSION['username_clean']);
OC_FILESYSTEM::chroot('/'.$user);
self::$fsSetup=true;
}
}
@ -178,36 +210,6 @@ class OC_UTIL {
return array(1,2,0);
}
/**
* Create an url
*
* @param string $application
* @param string $file
*/
public static function linkTo( $application, $file = null ){
global $WEBROOT;
if( is_null( $file )){
$file = $application;
$application = "";
}
return "$WEBROOT/$application/$file";
}
/**
* Create an image link
*
* @param string $application
* @param string $file
*/
public static function imagePath( $application, $file = null ){
global $WEBROOT;
if( is_null( $file )){
$file = $application;
$application = "";
}
return "$WEBROOT/$application/img/$file";
}
/**
* add a javascript file
*
@ -340,18 +342,6 @@ class OC_UTIL {
}
return false;
}
/**
* show an icon for a filetype
*
*/
public static function showIcon($filetype){
global $WEBROOT;
if($filetype=='dir'){ echo('<td><img src="'.$WEBROOT.'/img/icons/folder.png" width="16" height="16"></td>');
}elseif($filetype=='foo'){ echo('<td>foo</td>');
}else{ echo('<td><img src="'.$WEBROOT.'/img/icons/other.png" width="16" height="16"></td>');
}
}
}
@ -767,41 +757,4 @@ function chmodr($path, $filemode) {
return FALSE;
}
function oc_startup(){
global $SERVERROOT;
global $DOCUMENTROOT;
global $WEBROOT;
global $CONFIG_DBNAME;
global $CONFIG_DBHOST;
global $CONFIG_DBUSER;
global $CONFIG_DBPASSWORD;
global $CONFIG_DBTYPE;
global $CONFIG_DATADIRECTORY;
global $CONFIG_HTTPFORCESSL;
global $CONFIG_DATEFORMAT;
global $CONFIG_INSTALLED;
// Add the stuff we need always
OC_UTIL::addPersonalMenuEntry( array( "file" => "index.php?logout=1", "name" => "Logout" ));
OC_UTIL::addScript( "jquery-1.5.min" );
OC_UTIL::addScript( "jquery-ui-1.8.10.custom.min" );
OC_UTIL::addScript( "js" );
OC_UTIL::addStyle( "jquery-ui-1.8.10.custom" );
OC_UTIL::addStyle( "styles" );
// Require all appinfo.php
$dir = opendir( $SERVERROOT );
while( false !== ( $filename = readdir( $dir ))){
if( substr( $filename, 0, 1 ) != '.' ){
if( file_exists( "$SERVERROOT/$filename/appinfo.php" )){
oc_require( "$filename/appinfo.php" );
}
}
}
closedir( $dir );
// Everything done
return true;
}
?>

@ -0,0 +1,84 @@
<?php
/**
* ownCloud
*
* @author Frank Karlitschek
* @copyright 2010 Frank Karlitschek karlitschek@kde.org
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE
* License as published by the Free Software Foundation; either
* version 3 of the License, or any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU AFFERO GENERAL PUBLIC LICENSE for more details.
*
* You should have received a copy of the GNU Affero General Public
* License along with this library. If not, see <http://www.gnu.org/licenses/>.
*
*/
/**
* Class for utility functions
*
*/
class OC_HELPER {
/**
* Create an url
*
* @param string $application
* @param string $file
*/
public static function linkTo( $application, $file = null ){
global $WEBROOT;
if( is_null( $file )){
$file = $application;
$application = "";
}
return "$WEBROOT/$application/$file";
}
/**
* Create an image link
*
* @param string $application
* @param string $file
*/
public static function imagePath( $application, $file = null ){
global $WEBROOT;
if( is_null( $file )){
$file = $application;
$application = "";
}
return "$WEBROOT/$application/img/$file";
}
/**
* show an icon for a filetype
*
*/
public static function showIcon( $mimetype ){
global $SERVERROOT;
global $WEBROOT;
// Replace slash with a minus
$mimetype = str_replace( "/", "-", $mimetype );
// Is it a dir?
if( $mimetype == "dir" ){
return "$WEBROOT/img/places/folder.png";
}
// Icon exists?
if( file_exists( "$SERVERROOT/img/mimetypes/$mimetype.png" )){
return "$WEBROOT/img/mimetypes/$mimetype.png";
}
else{
return "$WEBROOT/img/mimetypes/application-octet-stream.png";
}
}
}
?>

@ -21,18 +21,20 @@
*
*/
oc_include_once( "helper.php" );
/**
*
*/
function link_to( $app, $file ){
return OC_UTIL::linkTo( $app, $file );
return OC_HELPER::linkTo( $app, $file );
}
/**
*
*/
function image_path( $app, $file ){
return OC_UTIL::imagePath( $app, $file );
return OC_HELPER::imagePath( $app, $file );
}
class OC_TEMPLATE{
@ -67,7 +69,7 @@ class OC_TEMPLATE{
public function append( $a, $b ){
if( array_key_exists( $a, $this->vars )){
if( is_a( $this->vars[$a], "array" )){
if( is_array( $this->vars[$a] )){
$this->vars[$a][] = $b;
}
else

Loading…
Cancel
Save