From dfa6b749baf95856601ea476e58f884cfb453055 Mon Sep 17 00:00:00 2001 From: Jakob Sack Date: Wed, 2 Mar 2011 22:18:22 +0100 Subject: [PATCH] Introducing OC_HELPER for small helper functions; making setup of filesystem optional --- img/actions/go-home.png | Bin 0 -> 635 bytes img/mimetypes/application-octet-stream.png | Bin 0 -> 1854 bytes img/places/folder.png | Bin 0 -> 386 bytes lib/base.php | 135 +++++++-------------- lib/helper.php | 84 +++++++++++++ lib/template.php | 8 +- 6 files changed, 133 insertions(+), 94 deletions(-) create mode 100644 img/actions/go-home.png create mode 100644 img/mimetypes/application-octet-stream.png create mode 100644 img/places/folder.png create mode 100644 lib/helper.php diff --git a/img/actions/go-home.png b/img/actions/go-home.png new file mode 100644 index 0000000000000000000000000000000000000000..9ee717c8b124c186edfd629c70d83ebc3dfc6b4e GIT binary patch literal 635 zcmeAS@N?(olHy`uVBq!ia0vp^0wB!63?wyl`GbKJbFq_W2nPqp?T7vkfLzW3kH}&M z2FBeW%xLxI@gtz1WQl7;NpOBzNqJ&XDnogBxn5>oc5!lIL8@MUQTpt6Hc~*<;sHJ( zuK)l4PfAbIH!(A^ur#%@Hn+92u(P+cwX=3`aCCKX_ww-e^YQWb@d*s{3-I+1@(&0N z1+w*x4D<{Pl2TKWQd1L>k`j`W(lRmp{}_Vo7i2AT{sFeo%IG}t#*k0BwGA)%B3Xe7|6w9K?DE1vv<)M879;%J7F;=Gd5 z%!-Pfnwo-!hT_IFu9lXvj;_|uo~|xuhTh)pIYGP&7S3G~z_2!iVOQJbd`*@#Ck@o;`o@ z`pw(VU%veQ^9L9vOH|^o0K-wbB*-tAp`rm5^j)~}^XIQ$fByb`P`a@KsBFEbi(^Q| zt<;|Dd`$rYF6;M}zuBvu9_+>u2KDjwcG z>uT>9#rA3W?4o~P+fJClr!T8}$ zJCS$qI^o{LM uTFAdLcI_93TAP57bSXBm$5B#$KQr0RRZpyT(^LaGox#)9&t;ucLK6VI&jeEd literal 0 HcmV?d00001 diff --git a/img/mimetypes/application-octet-stream.png b/img/mimetypes/application-octet-stream.png new file mode 100644 index 0000000000000000000000000000000000000000..0a90cf06b5f2eb8da1aedd25388183ccefaec7f4 GIT binary patch literal 1854 zcmV-E2f_G>P)glc zi6cWvAr(j>nIYijX&1zj;8Ijm;<~B6Ry);B=7%SRCx$2LzvT7Ei^_|-;*BkfJsEp4 zblgn8n0`Cmfomz(>}!Gk=U+Pi^75ApPBaJOf)Z@^9bp#z@H#E(gcu?$lSFk@RTGvz zTyP;*~8pJM>0*crT zvPzc7Yvid?)u7huW0EH$u&E|wO8$x)okIOD~=RW-PD=R7-yW53ids_&8|dy=9<6sY(Y2OZNAua2_EG=n%q(f zG3TS5n0g2_1?<2q2(1lOhqi*9?HsY)nJ@KgtOf5q-z;x7=o;s;z79QVdNlSt462Xn zrk+OY^?IXTgQkKrRD!89bh=Ij-Kv{)EvQ=6sJ;QqwmPhR;H+`pck)0ctF_|Jw_0wi z|CtcX4&IE)fX+zgfX=Ug@91D1c;EJ(^X`K1xX7Qv?a&n0+^cCbL_dle5q%i!h#hYq z0sXH2z*z~VI;%?5B~Z)NVl@x=HJ|G~(CyFN>bt!J-ZkC??-mHI3A_+!0CTai!R!vc z-M)YL`T+lw0;vGK)*0bU1T)t&!?OuI_q+7&au5Q^{;>ZoU?ABn1J$Zx)OQFUvO$`_ zB#Bg>0ZKSS8OTw!OBDe3=&SpJ|A=qBuN<5dr`5Rvx=dH;J zIqG@v|JL`c|0A$AS`AhdPOv^|SJX%dZP=gdO5QCOE!TLsZiL|4bmg^p_LQO6EY-K9?a;2#r+3*>?PK%6Xx&K&!J z-3F2TNLzR&L2l|x`aj^i!=N%E9Ci`^f`-!7vg)PD`RUP&H4syzu5U|=R(BJu>W9t zxfq@t$%w23tB>_@=eG=Pbz1wj9*d%fB4bKRrAqd)dx5pq6t~=xaJY*)LhV9X}=jgJ~}zNtFf-6 zdx=pJ+P^I;KWk4`@rq&qa1MAZ&qGfWADc9DlX~DZ%{-JWRc$ziBkhJZ>&<#FV)RzM zUGB;T*(e*SBZ+~e0By7o0jZR4r2?FgTZ`3uoEuKWDK=)7zE_%AI(+{NvlC}0&mNjJ z2mrzdQa7Z2keY+t??Auee#bD(_JQq5?Mcwlz2nJ_C+&(y@3c&4ned>T_w{1E*tgBO z=iGEZO;fL^scNbWlXFrbXR(;VD@-M9{a{_Ts`TTw=i4T?{m!$tVt&Po6&YWAnVFcG zocZ(BO#l$toOV3za9RNm(`wTi((Ylzx5c-_-^Da@7v#>#odfM(wC`x&QPZp8(}v{@ z%SZP$mzs;rMSP{_>nxo`74nls9ORHo^hTYdbEq|5{gJG*H`|}MDXcUreU-L1P+nfHmzkGcoSayYs+V7sKKq@G6i`t`fKQ0) z|NsAi%(S`hfFuwsx$tl9sb7^FzE`jRoWJaC(wyg0cE1Um{Lr)WR{H$6=2d6y8ZKol zcxzOC%DDV=+WfZ#%RiQ``dqc{OT*@`jk|ueZ2Q^@MEigB?)lcc_xse{FQy&&G4tq; zB}ZQ`J@<3{y`^&4cE^O2ihl8666=mAZAn3wsO7OX0ZYk8_>e(gW7&=+2A%p!AXT@VDH~x2fCf#hk{AEdD!dvN^xfyMqJiPn$ X6bytKFJC|L2IO&1S3j3^P6 "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(''); - }elseif($filetype=='foo'){ echo('foo'); - }else{ echo(''); - } - } } @@ -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; -} - ?> diff --git a/lib/helper.php b/lib/helper.php new file mode 100644 index 00000000000..085ab67e737 --- /dev/null +++ b/lib/helper.php @@ -0,0 +1,84 @@ +. +* +*/ + + +/** + * 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"; + } + } +} + +?> diff --git a/lib/template.php b/lib/template.php index 6415ab6a845..efa8dde8b9d 100644 --- a/lib/template.php +++ b/lib/template.php @@ -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