Merge branch 'master' into sabredav_1.6

This commit is contained in:
Georg Ehrke 2012-03-21 09:42:53 +01:00
commit 8f8d486f35
12 changed files with 248 additions and 187 deletions

View file

@ -77,5 +77,7 @@ $(document).ready(function(){
if(typeof FileActions !== 'undefined'){ if(typeof FileActions !== 'undefined'){
FileActions.register('text/vcard','importaddressbook', '', Contacts_Import.importdialog); FileActions.register('text/vcard','importaddressbook', '', Contacts_Import.importdialog);
FileActions.setDefault('text/vcard','importaddressbook'); FileActions.setDefault('text/vcard','importaddressbook');
FileActions.register('text/x-vcard','importaddressbook', '', Contacts_Import.importdialog);
FileActions.setDefault('text/x-vcard','importaddressbook');
}; };
}); });

View file

@ -5,7 +5,7 @@
left: 12.5em; left: 12.5em;
} }
#editorwrapper{ #editorwrapper{
position: absoloute; position: absolute;
height: 0; height: 0;
width: 0; width: 0;
top: 41px; top: 41px;

View file

@ -37,10 +37,12 @@ if($_POST) {
$maxZipInputSize=$_POST['maxZipInputSize']; $maxZipInputSize=$_POST['maxZipInputSize'];
OC_Preferences::setValue('', 'files', 'maxZipInputSize', OC_Helper::computerFileSize($maxZipInputSize)); OC_Preferences::setValue('', 'files', 'maxZipInputSize', OC_Helper::computerFileSize($maxZipInputSize));
} }
OC_Preferences::setValue('', 'files', 'allowZipDownload', isset($_POST['allowZipDownload']));
}else{ }else{
$upload_max_filesize = OC_Helper::computerFileSize(ini_get('upload_max_filesize')); $upload_max_filesize = OC_Helper::computerFileSize(ini_get('upload_max_filesize'));
$post_max_size = OC_Helper::computerFileSize(ini_get('post_max_size')); $post_max_size = OC_Helper::computerFileSize(ini_get('post_max_size'));
$maxUploadFilesize = min($upload_max_filesize, $post_max_size); $maxUploadFilesize = min($upload_max_filesize, $post_max_size);
$allowZipDownload = intval(OC_Preferences::getValue('', 'files', 'allowZipDownload', 1));
$maxZipInputSize = OC_Helper::humanfilesize(OC_Preferences::getValue('', 'files', 'maxZipInputSize', OC_Helper::computerFileSize('800 MB'))); $maxZipInputSize = OC_Helper::humanfilesize(OC_Preferences::getValue('', 'files', 'maxZipInputSize', OC_Helper::computerFileSize('800 MB')));
} }
@ -49,5 +51,6 @@ OC_App::setActiveNavigationEntry( "files_administration" );
$tmpl = new OC_Template( 'files', 'admin' ); $tmpl = new OC_Template( 'files', 'admin' );
$tmpl->assign( 'htaccessWorking', $htaccessWorking ); $tmpl->assign( 'htaccessWorking', $htaccessWorking );
$tmpl->assign( 'uploadMaxFilesize', $maxUploadFilesize); $tmpl->assign( 'uploadMaxFilesize', $maxUploadFilesize);
$tmpl->assign( 'allowZipDownload', $allowZipDownload);
$tmpl->assign( 'maxZipInputSize', $maxZipInputSize); $tmpl->assign( 'maxZipInputSize', $maxZipInputSize);
return $tmpl->fetchPage(); return $tmpl->fetchPage();

View file

@ -12,4 +12,12 @@ $(document).ready(function(){
$('#publicEnable').click(function(){ $('#publicEnable').click(function(){
switchPublicFolder(); // To get rid of onClick() switchPublicFolder(); // To get rid of onClick()
}); });
$('#allowZipDownload').bind('change', function() {
if($('#allowZipDownload').attr('checked')) {
$('#maxZipInputSize').removeAttr('disabled');
} else {
$('#maxZipInputSize').attr('disabled', 'disabled');
}
});
}); });

View file

@ -128,8 +128,15 @@ FileActions={
} }
} }
FileActions.register('all','Download',function(){return OC.imagePath('core','actions/download')},function(filename){ $(document).ready(function(){
if($('#allowZipDownload').val() == 1){
var downloadScope = 'all';
} else {
var downloadScope = 'file';
}
FileActions.register(downloadScope,'Download',function(){return OC.imagePath('core','actions/download')},function(filename){
window.location='ajax/download.php?files='+encodeURIComponent(filename)+'&dir='+encodeURIComponent($('#dir').val()); window.location='ajax/download.php?files='+encodeURIComponent(filename)+'&dir='+encodeURIComponent($('#dir').val());
});
}); });
FileActions.register('all','Delete',function(){return OC.imagePath('core','actions/delete')},function(filename){ FileActions.register('all','Delete',function(){return OC.imagePath('core','actions/delete')},function(filename){

View file

@ -6,7 +6,10 @@
<?php if($_['htaccessWorking']):?> <?php if($_['htaccessWorking']):?>
<label for="maxUploadSize"><?php echo $l->t( 'Maximum upload size' ); ?> </label><input name='maxUploadSize' id="maxUploadSize" value='<?php echo $_['uploadMaxFilesize'] ?>'/><br/> <label for="maxUploadSize"><?php echo $l->t( 'Maximum upload size' ); ?> </label><input name='maxUploadSize' id="maxUploadSize" value='<?php echo $_['uploadMaxFilesize'] ?>'/><br/>
<?php endif;?> <?php endif;?>
<label for="maxZipInputSize"><?php echo $l->t( 'Maximum input size for zip files (affects folder- and multi-file download)' ); ?> </label><input name="maxZipInputSize" id="maxZipInputSize" value='<?php echo $_['maxZipInputSize'] ?>'/><br/> <input type="checkbox" name="allowZipDownload" id="allowZipDownload" value="1" title="<?php echo $l->t( 'Needed for multi-file and folder downloads.' ); ?>"<?php if ($_['allowZipDownload']) echo ' checked="checked"'; ?> /> <label for="allowZipDownload"><?php echo $l->t( 'Enable ZIP-download' ); ?></label> <br/>
<fieldset class="personalblock">
<label for="maxZipInputSize"><?php echo $l->t( 'Maximum input size for ZIP files:' ); ?> </label><input name="maxZipInputSize" id="maxZipInputSize" value='<?php echo $_['maxZipInputSize'] ?>' title="<?php echo $l->t( '0 is unlimited' ); ?>"<?php if (!$_['allowZipDownload']) echo ' disabled="disabled"'; ?> /><br/>
</fieldset>
<input type="submit" value="Save"/> <input type="submit" value="Save"/>
</fieldset> </fieldset>
</form> </form>

View file

@ -40,7 +40,9 @@
<?php if(!isset($_['readonly']) || !$_['readonly']) { ?><input type="checkbox" id="select_all" /><?php } ?> <?php if(!isset($_['readonly']) || !$_['readonly']) { ?><input type="checkbox" id="select_all" /><?php } ?>
<span class='name'><?php echo $l->t( 'Name' ); ?></span> <span class='name'><?php echo $l->t( 'Name' ); ?></span>
<span class='selectedActions'> <span class='selectedActions'>
<?php if(OC_Preferences::getValue('', 'files', 'allowZipDownload', 1)) : ?>
<a href="" title="<?php echo $l->t('Download')?>" class="download"><img class='svg' alt="Download" src="<?php echo image_path("core", "actions/download.svg"); ?>" /></a> <a href="" title="<?php echo $l->t('Download')?>" class="download"><img class='svg' alt="Download" src="<?php echo image_path("core", "actions/download.svg"); ?>" /></a>
<?php endif; ?>
<a href="" title="Share" class="share"><img class='svg' alt="Share" src="<?php echo image_path("core", "actions/share.svg"); ?>" /></a> <a href="" title="Share" class="share"><img class='svg' alt="Share" src="<?php echo image_path("core", "actions/share.svg"); ?>" /></a>
</span> </span>
</th> </th>
@ -66,3 +68,6 @@
<?php echo $l->t('Current scanning');?> <span id='scan-current'></spann> <?php echo $l->t('Current scanning');?> <span id='scan-current'></spann>
</p> </p>
</div> </div>
<!-- config hints for javascript -->
<input type="hidden" name="allowZipDownload" id="allowZipDownload" value="<?php echo OC_Preferences::getValue('', 'files', 'allowZipDownload', 1); ?>" />

View file

@ -114,42 +114,7 @@ class OC{
return($mode); return($mode);
} }
public static function init(){ public static function initPaths(){
// register autoloader
spl_autoload_register(array('OC','autoload'));
// set some stuff
//ob_start();
error_reporting(E_ALL | E_STRICT);
if (defined('DEBUG') && DEBUG){
ini_set('display_errors', 1);
}
date_default_timezone_set('Europe/Berlin');
ini_set('arg_separator.output','&amp;');
//set http auth headers for apache+php-cgi work around
if (isset($_SERVER['HTTP_AUTHORIZATION']) && preg_match('/Basic\s+(.*)$/i', $_SERVER['HTTP_AUTHORIZATION'], $matches))
{
list($name, $password) = explode(':', base64_decode($matches[1]));
$_SERVER['PHP_AUTH_USER'] = strip_tags($name);
$_SERVER['PHP_AUTH_PW'] = strip_tags($password);
}
//set http auth headers for apache+php-cgi work around if variable gets renamed by apache
if (isset($_SERVER['REDIRECT_HTTP_AUTHORIZATION']) && preg_match('/Basic\s+(.*)$/i', $_SERVER['REDIRECT_HTTP_AUTHORIZATION'], $matches))
{
list($name, $password) = explode(':', base64_decode($matches[1]));
$_SERVER['PHP_AUTH_USER'] = strip_tags($name);
$_SERVER['PHP_AUTH_PW'] = strip_tags($password);
}
// register the stream wrappers
require_once('streamwrappers.php');
stream_wrapper_register("fakedir", "OC_FakeDirStream");
stream_wrapper_register('static', 'OC_StaticStreamWrapper');
stream_wrapper_register('close', 'OC_CloseStreamWrapper');
// calculate the documentroot // calculate the documentroot
OC::$DOCUMENTROOT=realpath($_SERVER['DOCUMENT_ROOT']); OC::$DOCUMENTROOT=realpath($_SERVER['DOCUMENT_ROOT']);
OC::$SERVERROOT=str_replace("\\",'/',substr(__FILE__,0,-13)); OC::$SERVERROOT=str_replace("\\",'/',substr(__FILE__,0,-13));
@ -211,14 +176,18 @@ class OC{
get_include_path().PATH_SEPARATOR. get_include_path().PATH_SEPARATOR.
OC::$SERVERROOT OC::$SERVERROOT
); );
}
public static function checkInstalled() {
// Redirect to installer if not installed // Redirect to installer if not installed
if (!OC_Config::getValue('installed', false) && OC::$SUBURI != '/index.php') { if (!OC_Config::getValue('installed', false) && OC::$SUBURI != '/index.php') {
$url = 'http://'.$_SERVER['SERVER_NAME'].OC::$WEBROOT.'/index.php'; $url = 'http://'.$_SERVER['SERVER_NAME'].OC::$WEBROOT.'/index.php';
header("Location: $url"); header("Location: $url");
exit(); exit();
} }
}
public static function checkSSL() {
// redirect to https site if configured // redirect to https site if configured
if( OC_Config::getValue( "forcessl", false )){ if( OC_Config::getValue( "forcessl", false )){
ini_set("session.cookie_secure", "on"); ini_set("session.cookie_secure", "on");
@ -228,7 +197,9 @@ class OC{
exit(); exit();
} }
} }
}
public static function checkUpgrade() {
if(OC_Config::getValue('installed', false)){ if(OC_Config::getValue('installed', false)){
$installedVersion=OC_Config::getValue('version','0.0.0'); $installedVersion=OC_Config::getValue('version','0.0.0');
$currentVersion=implode('.',OC_Util::getVersion()); $currentVersion=implode('.',OC_Util::getVersion());
@ -250,6 +221,48 @@ class OC{
OC_App::updateApps(); OC_App::updateApps();
} }
}
public static function init(){
// register autoloader
spl_autoload_register(array('OC','autoload'));
// set some stuff
//ob_start();
error_reporting(E_ALL | E_STRICT);
if (defined('DEBUG') && DEBUG){
ini_set('display_errors', 1);
}
date_default_timezone_set('Europe/Berlin');
ini_set('arg_separator.output','&amp;');
//set http auth headers for apache+php-cgi work around
if (isset($_SERVER['HTTP_AUTHORIZATION']) && preg_match('/Basic\s+(.*)$/i', $_SERVER['HTTP_AUTHORIZATION'], $matches))
{
list($name, $password) = explode(':', base64_decode($matches[1]));
$_SERVER['PHP_AUTH_USER'] = strip_tags($name);
$_SERVER['PHP_AUTH_PW'] = strip_tags($password);
}
//set http auth headers for apache+php-cgi work around if variable gets renamed by apache
if (isset($_SERVER['REDIRECT_HTTP_AUTHORIZATION']) && preg_match('/Basic\s+(.*)$/i', $_SERVER['REDIRECT_HTTP_AUTHORIZATION'], $matches))
{
list($name, $password) = explode(':', base64_decode($matches[1]));
$_SERVER['PHP_AUTH_USER'] = strip_tags($name);
$_SERVER['PHP_AUTH_PW'] = strip_tags($password);
}
// register the stream wrappers
require_once('streamwrappers.php');
stream_wrapper_register("fakedir", "OC_FakeDirStream");
stream_wrapper_register('static', 'OC_StaticStreamWrapper');
stream_wrapper_register('close', 'OC_CloseStreamWrapper');
self::initPaths();
self::checkInstalled();
self::checkSSL();
self::checkUpgrade();
ini_set('session.cookie_httponly','1;'); ini_set('session.cookie_httponly','1;');
session_start(); session_start();

View file

@ -59,7 +59,7 @@ class OC_Files {
} }
if(is_array($files)){ if(is_array($files)){
self::checkZipInputSize($dir,$files); self::validateZipDownload($dir,$files);
$executionTime = intval(ini_get('max_execution_time')); $executionTime = intval(ini_get('max_execution_time'));
set_time_limit(0); set_time_limit(0);
$zip = new ZipArchive(); $zip = new ZipArchive();
@ -80,7 +80,7 @@ class OC_Files {
$zip->close(); $zip->close();
set_time_limit($executionTime); set_time_limit($executionTime);
}elseif(OC_Filesystem::is_dir($dir.'/'.$files)){ }elseif(OC_Filesystem::is_dir($dir.'/'.$files)){
self::checkZipInputSize($dir,$files); self::validateZipDownload($dir,$files);
$executionTime = intval(ini_get('max_execution_time')); $executionTime = intval(ini_get('max_execution_time'));
set_time_limit(0); set_time_limit(0);
$zip = new ZipArchive(); $zip = new ZipArchive();
@ -223,7 +223,22 @@ class OC_Files {
* @param dir $dir * @param dir $dir
* @param files $files * @param files $files
*/ */
static function checkZipInputSize($dir, $files) { static function validateZipDownload($dir, $files) {
if(!OC_Preferences::getValue('', 'files', 'allowZipDownload', 1)) {
$l = new OC_L10N('files');
header("HTTP/1.0 409 Conflict");
$tmpl = new OC_Template( '', 'error', 'user' );
$errors = array(
array(
'error' => $l->t('ZIP download is turned off.'),
'hint' => $l->t('Files need to be downloaded one by one.') . '<br/><a href="javascript:history.back()">' . $l->t('Back to Files') . '</a>',
)
);
$tmpl->assign('errors', $errors);
$tmpl->printPage();
exit;
}
$zipLimit = OC_Preferences::getValue('', 'files', 'maxZipInputSize', OC_Helper::computerFileSize('800 MB')); $zipLimit = OC_Preferences::getValue('', 'files', 'maxZipInputSize', OC_Helper::computerFileSize('800 MB'));
if($zipLimit > 0) { if($zipLimit > 0) {
$totalsize = 0; $totalsize = 0;

View file

@ -284,9 +284,7 @@ class OC_Helper {
$isWrapped=(strpos($path,'://')!==false) and (substr($path,0,7)=='file://'); $isWrapped=(strpos($path,'://')!==false) and (substr($path,0,7)=='file://');
$mimeType='application/octet-stream'; $mimeType='application/octet-stream';
if ($mimeType=='application/octet-stream') { if ($mimeType=='application/octet-stream') {
if(count(self::$mimetypes)>0){
self::$mimetypes = include('mimetypes.fixlist.php'); self::$mimetypes = include('mimetypes.fixlist.php');
}
$extention=strtolower(strrchr(basename($path), ".")); $extention=strtolower(strrchr(basename($path), "."));
$extention=substr($extention,1);//remove leading . $extention=substr($extention,1);//remove leading .
$mimeType=(isset(self::$mimetypes[$extention]))?self::$mimetypes[$extention]:'application/octet-stream'; $mimeType=(isset(self::$mimetypes[$extention]))?self::$mimetypes[$extention]:'application/octet-stream';

View file

@ -10,5 +10,11 @@ return array(
'pl'=>'text/x-script.perl', 'pl'=>'text/x-script.perl',
'py'=>'text/x-script.phyton', 'py'=>'text/x-script.phyton',
'vcf' => 'text/vcard', 'vcf' => 'text/vcard',
'vcard' => 'text/vcard' 'vcard' => 'text/vcard',
'doc'=>'application/msword',
'docx'=>'application/msword',
'xls'=>'application/msexcel',
'xlsx'=>'application/msexcel',
'ppt'=>'application/mspowerpoint',
'pptx'=>'application/mspowerpoint'
); );

View file

@ -140,7 +140,7 @@ class OC_Template{
/** /**
* @brief Constructor * @brief Constructor
* @param $app app providing the template * @param $app app providing the template
* @param $file name of the tempalte file (without suffix) * @param $file name of the template file (without suffix)
* @param $renderas = ""; produce a full page * @param $renderas = ""; produce a full page
* @returns OC_Template object * @returns OC_Template object
* *
@ -151,10 +151,20 @@ class OC_Template{
* "admin". * "admin".
*/ */
public function __construct( $app, $name, $renderas = "" ){ public function __construct( $app, $name, $renderas = "" ){
// Read the selected theme from the config file // Set the private data
$theme=OC_Config::getValue( "theme" ); $this->renderas = $renderas;
$this->application = $app;
$this->vars = array();
$this->l10n = new OC_L10N($app);
// Read the detected formfactor and use the right file name. $this->findTemplate($name);
}
/**
* @brief Returns the formfactor extention for current formfactor
*/
protected function getFormFactorExtension()
{
$formfactor=$_SESSION['formfactor']; $formfactor=$_SESSION['formfactor'];
if($formfactor=='default') { if($formfactor=='default') {
$fext=''; $fext='';
@ -167,39 +177,37 @@ class OC_Template{
}else{ }else{
$fext=''; $fext='';
} }
return $fext;
}
/**
* @brief find the template with the given name
* @param $name of the template file (without suffix)
*
* Will select the template file for the selected theme and formfactor.
* Checking all the possible locations.
*/
protected function findTemplate($name)
{
// Read the selected theme from the config file
$theme=OC_Config::getValue( "theme" );
// Read the detected formfactor and use the right file name.
$fext = $this->getFormFactorExtension();
$app = $this->application;
// Check if it is a app template or not. // Check if it is a app template or not.
if( $app != "" ){ if( $app != "" ){
// Check if the app is in the app folder or in the root // Check if the app is in the app folder or in the root
if( file_exists( OC::$APPSROOT."/apps/$app/templates/" )){ if( file_exists( OC::$APPSROOT."/apps/$app/templates/" )){
// Check if the template is overwritten by the selected theme // Check if the template is overwritten by the selected theme
if( file_exists( OC::$SERVERROOT."/themes/$theme/apps/$app/templates/"."$name$fext.php" )){ if ($this->checkPathForTemplate(OC::$SERVERROOT."/themes/$theme/apps/$app/templates/", $name, $fext)) {
$template = OC::$SERVERROOT."/themes/$theme/apps/$app/templates/"."$name$fext.php"; }elseif ($this->checkPathForTemplate(OC::$APPSROOT."/apps/$app/templates/", $name, $fext)) {
$path = OC::$SERVERROOT."/themes/$theme/apps/$app/templates/";
}elseif( file_exists( OC::$SERVERROOT."/themes/$theme/apps/$app/templates/"."$name.php" )){
$template = OC::$SERVERROOT."/themes/$theme/apps/$app/templates/"."$name.php";
$path = OC::$SERVERROOT."/themes/$theme/apps/$app/templates/";
}elseif( OC::$APPSROOT."/apps/$app/templates/"."$name$fext.php" ){
$template = OC::$APPSROOT."/apps/$app/templates/"."$name$fext.php";
$path = OC::$APPSROOT."/apps/$app/templates/";
}else{
$template = OC::$APPSROOT."/apps/$app/templates/"."$name.php";
$path = OC::$APPSROOT."/apps/$app/templates/";
} }
}else{ }else{
// Check if the template is overwritten by the selected theme // Check if the template is overwritten by the selected theme
if( file_exists( OC::$SERVERROOT."/themes/$theme/$app/templates/"."$name$fext.php" )){ if ($this->checkPathForTemplate(OC::$SERVERROOT."/themes/$theme/$app/templates/", $name, $fext)) {
$template = OC::$SERVERROOT."/themes/$theme/$app/templates/"."$name$fext.php"; }elseif ($this->checkPathForTemplate(OC::$SERVERROOT."/$app/templates/", $name, $fext)) {
$path = OC::$SERVERROOT."/themes/$theme/$app/templates/";
}elseif( file_exists( OC::$SERVERROOT."/themes/$theme/$app/templates/"."$name.php" )){
$template = OC::$SERVERROOT."/themes/$theme/$app/templates/"."$name.php";
$path = OC::$SERVERROOT."/themes/$theme/$app/templates/";
}elseif( file_exists( OC::$SERVERROOT."/$app/templates/"."$name$fext.php" )){
$template = OC::$SERVERROOT."/$app/templates/"."$name$fext.php";
$path = OC::$SERVERROOT."/$app/templates/";
}elseif( file_exists( OC::$SERVERROOT."/$app/templates/"."$name.php" )){
$template = OC::$SERVERROOT."/$app/templates/"."$name.php";
$path = OC::$SERVERROOT."/$app/templates/";
}else{ }else{
echo('template not found: template:'.$name.' formfactor:'.$fext.' webroot:'.OC::$WEBROOT.' serverroot:'.OC::$SERVERROOT); echo('template not found: template:'.$name.' formfactor:'.$fext.' webroot:'.OC::$WEBROOT.' serverroot:'.OC::$SERVERROOT);
die(); die();
@ -208,29 +216,40 @@ class OC_Template{
} }
}else{ }else{
// Check if the template is overwritten by the selected theme // Check if the template is overwritten by the selected theme
if( file_exists( OC::$SERVERROOT."/themes/$theme/core/templates/"."$name$fext.php" )){ if ($this->checkPathForTemplate(OC::$SERVERROOT."/themes/$theme/core/templates/", $name, $fext)) {
$template = OC::$SERVERROOT."/themes/$theme/core/templates/"."$name$fext.php"; } elseif ($this->checkPathForTemplate(OC::$SERVERROOT."/core/templates/", $name, $fext)) {
$path = OC::$SERVERROOT."/themes/$theme/core/templates/";
}elseif( file_exists( OC::$SERVERROOT."/themes/$theme/core/templates/"."$name.php" )){
$template = OC::$SERVERROOT."/themes/$theme/core/templates/"."$name.php";
$path = OC::$SERVERROOT."/themes/$theme/core/templates/";
}elseif( file_exists( OC::$SERVERROOT."/core/templates/"."$name$fext.php" )){
$template = OC::$SERVERROOT."/core/templates/"."$name$fext.php";
$path = OC::$SERVERROOT."/core/templates/";
}else{ }else{
$template = OC::$SERVERROOT."/core/templates/"."$name.php"; echo('template not found: template:'.$name.' formfactor:'.$fext.' webroot:'.OC::$WEBROOT.' serverroot:'.OC::$SERVERROOT);
$path = OC::$SERVERROOT."/core/templates/"; die();
}
} }
} }
/**
// Set the private data * @brief check Path For Template with and without $fext
$this->renderas = $renderas; * @param $path to check
$this->application = $app; * @param $name of the template file (without suffix)
* @param $fext formfactor extension
* @return bool true when found
*
* Will set $this->template and $this->path if there is a template at
* the specifief $path
*/
protected function checkPathForTemplate($path, $name, $fext)
{
if ($name =='') return false;
$template = null;
if( is_file( $path.$name.$fext.'.php' )){
$template = $path.$name.$fext.'.php';
}elseif( is_file( $path.$name.'.php' )){
$template = $path.$name.'.php';
}
if ($template) {
$this->template = $template; $this->template = $template;
$this->path = $path; $this->path = $path;
$this->vars = array(); return true;
$this->l10n = new OC_L10N($app); }
return false;
} }
/** /**
@ -295,11 +314,25 @@ class OC_Template{
} }
} }
/*
* @brief append the $file-url if exist at $root
* @param $type of collection to use when appending
* @param $root path to check
* @param $web base for path
* @param $file the filename
*/
public function appendIfExist($type, $root, $web, $file) {
if (is_file($root.'/'.$file)) {
$this->append( $type, $web.'/'.$file);
return true;
}
return false;
}
/** /**
* @brief Proceeds the template * @brief Proceeds the template
* @returns content * @returns content
* *
* This function proceeds the template. If $this->renderas is set, it will * This function proceeds the template. If $this->renderas is set, it
* will produce a full page. * will produce a full page.
*/ */
public function fetchPage(){ public function fetchPage(){
@ -334,60 +367,36 @@ class OC_Template{
$theme=OC_Config::getValue( "theme" ); $theme=OC_Config::getValue( "theme" );
// Read the detected formfactor and use the right file name. // Read the detected formfactor and use the right file name.
$formfactor=$_SESSION['formfactor']; $fext = $this->getFormFactorExtension();
if($formfactor=='default') {
$fext='';
}elseif($formfactor=='mobile') {
$fext='.mobile';
}elseif($formfactor=='tablet') {
$fext='.tablet';
}elseif($formfactor=='standalone') {
$fext='.standalone';
}else{
$fext='';
}
// Add the core js files or the js files provided by the selected theme // Add the core js files or the js files provided by the selected theme
foreach(OC_Util::$scripts as $script){ foreach(OC_Util::$scripts as $script){
// Is it in 3rd party? // Is it in 3rd party?
if(is_file(OC::$THIRDPARTYROOT."/$script.js" )){ if($page->appendIfExist('jsfiles', OC::$THIRDPARTYROOT, OC::$THIRDPARTYWEBROOT, $script.'.js')) {
$page->append( "jsfiles", OC::$THIRDPARTYWEBROOT."/$script.js" );
// Is it in apps and overwritten by the theme? // Is it in apps and overwritten by the theme?
}elseif(is_file(OC::$SERVERROOT."/themes/$theme/apps/$script$fext.js" )){ }elseif($page->appendIfExist('jsfiles', OC::$SERVERROOT, OC::$WEBROOT, "themes/$theme/apps/$script$fext.js" )) {
$page->append( "jsfiles", OC::$WEBROOT."/themes/$theme/apps/$script$fext.js" ); }elseif($page->appendIfExist('jsfiles', OC::$SERVERROOT, OC::$WEBROOT, "themes/$theme/apps/$script.js" )) {
}elseif(is_file(OC::$SERVERROOT."/themes/$theme/apps/$script.js" )){
$page->append( "jsfiles", OC::$WEBROOT."/themes/$theme/apps/$script.js" );
// Is it part of an app? // Is it part of an app?
}elseif(is_file(OC::$APPSROOT."/apps/$script$fext.js" )){ }elseif($page->appendIfExist('jsfiles', OC::$APPSROOT, OC::$APPSWEBROOT, "apps/$script$fext.js" )) {
$page->append( "jsfiles", OC::$APPSWEBROOT."/apps/$script$fext.js" ); }elseif($page->appendIfExist('jsfiles', OC::$APPSROOT, OC::$APPSWEBROOT, "apps/$script.js" )) {
}elseif(is_file(OC::$APPSROOT."/apps/$script.js" )){
$page->append( "jsfiles", OC::$APPSWEBROOT."/apps/$script.js" );
// Is it in the owncloud root but overwritten by the theme? // Is it in the owncloud root but overwritten by the theme?
}elseif(is_file(OC::$SERVERROOT."/themes/$theme/$script$fext.js" )){ }elseif($page->appendIfExist('jsfiles', OC::$SERVERROOT, OC::$WEBROOT, "themes/$theme/$script$fext.js" )) {
$page->append( "jsfiles", OC::$WEBROOT."/themes/$theme/$script$fext.js" ); }elseif($page->appendIfExist('jsfiles', OC::$SERVERROOT, OC::$WEBROOT, "themes/$theme/$script.js" )) {
}elseif(is_file(OC::$SERVERROOT."/themes/$theme/$script.js" )){
$page->append( "jsfiles", OC::$WEBROOT."/themes/$theme/$script.js" );
// Is it in the owncloud root ? // Is it in the owncloud root ?
}elseif(is_file(OC::$SERVERROOT."/$script$fext.js" )){ }elseif($page->appendIfExist('jsfiles', OC::$SERVERROOT, OC::$WEBROOT, "$script$fext.js" )) {
$page->append( "jsfiles", OC::$WEBROOT."/$script$fext.js" ); }elseif($page->appendIfExist('jsfiles', OC::$SERVERROOT, OC::$WEBROOT, "$script.js" )) {
}elseif(is_file(OC::$SERVERROOT."/$script.js" )){
$page->append( "jsfiles", OC::$WEBROOT."/$script.js" );
// Is in core but overwritten by a theme? // Is in core but overwritten by a theme?
}elseif(is_file(OC::$SERVERROOT."/themes/$theme/core/$script$fext.js" )){ }elseif($page->appendIfExist('jsfiles', OC::$SERVERROOT, OC::$WEBROOT, "themes/$theme/core/$script$fext.js" )) {
$page->append( "jsfiles", OC::$WEBROOT."/themes/$theme/core/$script$fext.js" ); }elseif($page->appendIfExist('jsfiles', OC::$SERVERROOT, OC::$WEBROOT, "themes/$theme/core/$script.js" )) {
}elseif(is_file(OC::$SERVERROOT."/themes/$theme/core/$script.js" )){
$page->append( "jsfiles", OC::$WEBROOT."/themes/$theme/core/$script.js" );
// Is it in core? // Is it in core?
}elseif(is_file(OC::$SERVERROOT."/core/$script$fext.js" )){ }elseif($page->appendIfExist('jsfiles', OC::$SERVERROOT, OC::$WEBROOT, "core/$script$fext.js" )) {
$page->append( "jsfiles", OC::$WEBROOT."/core/$script$fext.js" ); }elseif($page->appendIfExist('jsfiles', OC::$SERVERROOT, OC::$WEBROOT, "core/$script.js" )) {
}elseif(is_file(OC::$SERVERROOT."/core/$script.js" )){
$page->append( "jsfiles", OC::$WEBROOT."/core/$script.js" );
}else{ }else{
echo('js file not found: script:'.$script.' formfactor:'.$fext.' webroot:'.OC::$WEBROOT.' serverroot:'.OC::$SERVERROOT); echo('js file not found: script:'.$script.' formfactor:'.$fext.' webroot:'.OC::$WEBROOT.' serverroot:'.OC::$SERVERROOT);
@ -398,23 +407,19 @@ class OC_Template{
// Add the css files // Add the css files
foreach(OC_Util::$styles as $style){ foreach(OC_Util::$styles as $style){
// is it in 3rdparty? // is it in 3rdparty?
if(is_file(OC::$THIRDPARTYROOT."/$style.css" )){ if($page->appendIfExist('cssfiles', OC::$THIRDPARTYROOT, OC::$THIRDPARTYWEBROOT, $style.'.css')) {
$page->append( "cssfiles", OC::$THIRDPARTYWEBROOT."/$style.css" );
// or in apps? // or in apps?
}elseif(is_file(OC::$APPSROOT."/apps/$style$fext.css" )){ }elseif($page->appendIfExist('cssfiles', OC::$APPSROOT, OC::$APPSWEBROOT, "apps/$style$fext.css" )) {
$page->append( "cssfiles", OC::$APPSWEBROOT."/apps/$style$fext.css" ); }elseif($page->appendIfExist('cssfiles', OC::$APPSROOT, OC::$APPSWEBROOT, "apps/$style.css" )) {
}elseif(is_file(OC::$APPSROOT."/apps/$style.css" )){
$page->append( "cssfiles", OC::$APPSWEBROOT."/apps/$style.css" );
// or in the owncloud root? // or in the owncloud root?
}elseif(is_file(OC::$SERVERROOT."/$style$fext.css" )){ }elseif($page->appendIfExist('cssfiles', OC::$SERVERROOT, OC::$WEBROOT, "$style$fext.css" )) {
$page->append( "cssfiles", OC::$WEBROOT."/$style$fext.css" ); }elseif($page->appendIfExist('cssfiles', OC::$SERVERROOT, OC::$WEBROOT, "$style.css" )) {
}elseif(is_file(OC::$SERVERROOT."/$style.css" )){
$page->append( "cssfiles", OC::$WEBROOT."/$style.css" );
// or in core ? // or in core ?
}elseif(is_file(OC::$SERVERROOT."/core/$style$fext.css" )){ }elseif($page->appendIfExist('cssfiles', OC::$SERVERROOT, OC::$WEBROOT, "core/$style$fext.css" )) {
$page->append( "cssfiles", OC::$WEBROOT."/core/$style$fext.css" ); }elseif($page->appendIfExist('cssfiles', OC::$SERVERROOT, OC::$WEBROOT, "core/$style.css" )) {
}elseif(is_file(OC::$SERVERROOT."/core/$style.css" )){
$page->append( "cssfiles", OC::$WEBROOT."/core/$style.css" );
}else{ }else{
echo('css file not found: style:'.$script.' formfactor:'.$fext.' webroot:'.OC::$WEBROOT.' serverroot:'.OC::$SERVERROOT); echo('css file not found: style:'.$script.' formfactor:'.$fext.' webroot:'.OC::$WEBROOT.' serverroot:'.OC::$SERVERROOT);
@ -424,18 +429,14 @@ class OC_Template{
// Add the theme css files. you can override the default values here // Add the theme css files. you can override the default values here
if(!empty($theme)) { if(!empty($theme)) {
foreach(OC_Util::$styles as $style){ foreach(OC_Util::$styles as $style){
if(is_file(OC::$SERVERROOT."/themes/$theme/apps/$style$fext.css" )){ if($page->appendIfExist('cssfiles', OC::$SERVERROOT, OC::$WEBROOT, "themes/$theme/apps/$style$fext.css" )) {
$page->append( "cssfiles", OC::$WEBROOT."/themes/$theme/apps/$style$fext.css" ); }elseif($page->appendIfExist('cssfiles', OC::$SERVERROOT, OC::$WEBROOT, "themes/$theme/apps/$style.css" )) {
}elseif(is_file(OC::$SERVERROOT."/themes/$theme/apps/$style.css" )){
$page->append( "cssfiles", OC::$WEBROOT."/themes/$theme/apps/$style.css" ); }elseif($page->appendIfExist('cssfiles', OC::$SERVERROOT, OC::$WEBROOT, "themes/$theme/$style$fext.css" )) {
}elseif(is_file(OC::$SERVERROOT."/themes/$theme/$style$fext.css" )){ }elseif($page->appendIfExist('cssfiles', OC::$SERVERROOT, OC::$WEBROOT, "themes/$theme/$style.css" )) {
$page->append( "cssfiles", OC::$WEBROOT."/themes/$theme/$style$fext.css" );
}elseif(is_file(OC::$SERVERROOT."/themes/$theme/$style.css" )){ }elseif($page->appendIfExist('cssfiles', OC::$SERVERROOT, OC::$WEBROOT, "themes/$theme/core/$style$fext.css" )) {
$page->append( "cssfiles", OC::$WEBROOT."/themes/$theme/$style.css" ); }elseif($page->appendIfExist('cssfiles', OC::$SERVERROOT, OC::$WEBROOT, "themes/$theme/core/$style.css" )) {
}elseif(is_file(OC::$SERVERROOT."/themes/$theme/core/$style$fext.css" )){
$page->append( "cssfiles", OC::$WEBROOT."/themes/$theme/core/$style$fext.css" );
}elseif(is_file(OC::$SERVERROOT."/themes/$theme/core/$style.css" )){
$page->append( "cssfiles", OC::$WEBROOT."/themes/$theme/core/$style.css" );
} }
} }
} }