From 88033c268bf0c5561d8494d382a27ed757a62846 Mon Sep 17 00:00:00 2001 From: Arthur Schiwon Date: Tue, 19 Apr 2011 10:47:20 +0200 Subject: [PATCH 01/19] file icon for file upload button --- files/css/files.css | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/files/css/files.css b/files/css/files.css index 6313e6d1ca6..368adba2911 100644 --- a/files/css/files.css +++ b/files/css/files.css @@ -27,6 +27,14 @@ display: none; } +#file_upload_start { + background-image:url(/owncloud-dev/img/mimetypes/file.png); + background-repeat: no-repeat; + background-position: 0.5em 0; + padding-left: 2em; + +} + #file_upload_form input[type="button"]{ /* this is a dirty wurgaround, Jan needs to fix it in global css*/ font-size: 0.9em; From d1b4f74bc2108963c347a6fb2526e89bbfb5afeb Mon Sep 17 00:00:00 2001 From: Marco Michelino Date: Tue, 19 Apr 2011 12:32:37 +0200 Subject: [PATCH 02/19] Avoid // in URIs --- lib/base.php | 12 ++++++++++-- lib/helper.php | 6 +++++- 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/lib/base.php b/lib/base.php index acdea093d91..324b2f7e0a0 100644 --- a/lib/base.php +++ b/lib/base.php @@ -204,7 +204,11 @@ class OC_UTIL { $file = $application; $application = ""; } - self::$scripts[] = "$application/js/$file"; + if( !empty( $application )){ + self::$scripts[] = "$application/js/$file"; + }else{ + self::$scripts[] = "js/$file"; + } } /** @@ -217,7 +221,11 @@ class OC_UTIL { $file = $application; $application = ""; } - self::$styles[] = "$application/css/$file"; + if( !empty( $application )){ + self::$styles[] = "$application/css/$file"; + }else{ + self::$styles[] = "css/$file"; + } } /** diff --git a/lib/helper.php b/lib/helper.php index c4352ca3344..c141d6f0499 100644 --- a/lib/helper.php +++ b/lib/helper.php @@ -63,7 +63,11 @@ class OC_HELPER { if( file_exists( "$SERVERROOT/apps/img/$app/$image" )){ return "$WEBROOT/apps/img/$app/$image"; } - return "$WEBROOT/$app/img/$image"; + if( !empty( $app )){ + return "$WEBROOT/$app/img/$image"; + }else{ + return "$WEBROOT/img/$image"; + } } /** From 85764257eac2d35db32bfe225fdbf3f6301ef7c2 Mon Sep 17 00:00:00 2001 From: Arthur Schiwon Date: Tue, 19 Apr 2011 12:21:55 +0200 Subject: [PATCH 03/19] refurbished new folder button --- files/css/files.css | 25 ++++++++----- files/js/files.js | 79 +++++++++++++++++++++++++++++++++------ files/templates/index.php | 3 +- 3 files changed, 83 insertions(+), 24 deletions(-) diff --git a/files/css/files.css b/files/css/files.css index 368adba2911..e3a7528fbf4 100644 --- a/files/css/files.css +++ b/files/css/files.css @@ -19,31 +19,36 @@ text-decoration: none; } -#file_upload_form { +#file_upload_form, #file_newfolder_form { display: inline; } -#fileSelector, #file_upload_cancel { +#fileSelector, #file_upload_cancel, #file_newfolder_submit { display: none; } -#file_upload_start { - background-image:url(/owncloud-dev/img/mimetypes/file.png); +#file_upload_start, #file_newfolder_name { background-repeat: no-repeat; background-position: 0.5em 0; padding-left: 2em; - } -#file_upload_form input[type="button"]{ +#file_upload_start {background-image:url(/owncloud-dev/img/mimetypes/file.png);} + +#file_newfolder_name { + background-image:url(/owncloud-dev/img/places/folder.png); font-weight: bold; + width: 14em; +} + +#file_newfolder_submit { + width: 3em; +} + +form input[type="button"], form input[type="text"]{ /* this is a dirty wurgaround, Jan needs to fix it in global css*/ font-size: 0.9em; } -#file_newfolder_form { - display: none; -} - #file_upload_target { display: none; } diff --git a/files/js/files.js b/files/js/files.js index bfb68317b02..901078680de 100644 --- a/files/js/files.js +++ b/files/js/files.js @@ -2,6 +2,8 @@ $(document).ready(function() { $('#file_action_panel').attr('activeAction', false); $('#file_upload_start').attr('mode', 'menu'); $('#file_upload_form').attr('uploading', false); + $('#file_newfolder_name').css('width', '14em'); + $('#file_newfolder_submit').css('width', '3em'); // Sets browser table behaviour : $('.browser tr').hover( @@ -115,6 +117,40 @@ $(document).ready(function() { }); }); + $('#file_newfolder_name').click(function(){ + if($('#file_newfolder_name').val() == 'New Folder'){ + $('#file_newfolder_name').val(''); + } + }); + + $('#file_newfolder_name').bind('keyup', adjustNewFolderSize); + + $('#file_newfolder_submit').bind('vanish', function() { + $('#file_newfolder_name').bind('keyup', adjustNewFolderSize); + unsplitSize($('#file_newfolder_name'),$('#file_newfolder_submit')); + }); + + $('#file_newfolder_name').focusout(function(){ + if($('#file_newfolder_name').val() == '') { + $('#file_newfolder_form')[0].reset(); + $('#file_newfolder_submit').fadeOut(250).trigger('vanish'); + } + }); + + $('#file_newfolder_submit').click(function() { + if($('#file_newfolder_name').val() != '') { + $.ajax({ + url: 'ajax/newfolder.php', + data: "dir="+$('#dir').val()+"&foldername="+$('#file_newfolder_name').val(), + complete: function(data){ + boolOperationFinished(data, false); + $('#file_newfolder_form')[0].reset(); + } + }); + } + $('#file_newfolder_submit').fadeOut(250).trigger('vanish'); + }); + // $('.upload').click(function(){ // if($('#file_action_panel').attr('activeAction') != 'upload') { // $('#file_action_panel').attr('activeAction', 'upload'); @@ -138,18 +174,18 @@ $(document).ready(function() { - $('.new-dir').click(function(){ - if($('#file_action_panel').attr('activeAction') != 'new-dir') { - $('#file_action_panel').attr('activeAction', 'new-dir'); - $('#file_new_dir_name').val(''); - $('#file_action_panel form').slideUp(250); - $('#file_newfolder_form').slideDown(250); - } else { - $('#file_newfolder_form').slideUp(250); - $('#file_action_panel').attr('activeAction', false); - } - return false; - }); +// $('.new-dir').click(function(){ +// if($('#file_action_panel').attr('activeAction') != 'new-dir') { +// $('#file_action_panel').attr('activeAction', 'new-dir'); +// $('#file_new_dir_name').val(''); +// $('#file_action_panel form').slideUp(250); +// $('#file_newfolder_form').slideDown(250); +// } else { +// $('#file_newfolder_form').slideUp(250); +// $('#file_action_panel').attr('activeAction', false); +// } +// return false; +// }); $('.download').click(function(event) { var files=''; @@ -184,6 +220,25 @@ $(document).ready(function() { }); }); +var adjustNewFolderSize = function() { + if($('#file_newfolder_name').val() != '') { + splitSize($('#file_newfolder_name'),$('#file_newfolder_submit')); + $('#file_newfolder_name').unbind('keyup', adjustNewFolderSize); + }; +} + +function splitSize(existingEl, appearingEl) { + nw = parseInt($(existingEl).css('width')) - parseInt($(appearingEl).css('width')); + $(existingEl).css('width', nw + 'px'); + $(appearingEl).fadeIn(250); +} + +function unsplitSize(stayingEl, vanishingEl) { + nw = parseInt($(stayingEl).css('width')) + parseInt($(vanishingEl).css('width')); + $(stayingEl).css('width', nw + 'px'); + $(vanishingEl).fadeOut(250); +} + function uploadFinished() { result = $('#file_upload_target').contents().text(); result = eval("(" + result + ");"); diff --git a/files/templates/index.php b/files/templates/index.php index e794bad300c..4d34222b966 100644 --- a/files/templates/index.php +++ b/files/templates/index.php @@ -3,10 +3,9 @@
" id="max_upload">)">" id="dir">)" /> 
New folderDownloadDelete +type="hidden" class="max_human_file_size" value="(max )">" id="dir">)" /> 
 
DownloadDelete
-
 
From 0385cc52dcc97a11a6efc0720272867a14b1f675 Mon Sep 17 00:00:00 2001 From: Arthur Schiwon Date: Tue, 19 Apr 2011 12:33:19 +0200 Subject: [PATCH 04/19] hide filechooser if user clicked on cancel --- files/js/files.js | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/files/js/files.js b/files/js/files.js index 901078680de..aed2d596272 100644 --- a/files/js/files.js +++ b/files/js/files.js @@ -87,11 +87,23 @@ $(document).ready(function() { $('#file_upload_cancel').slideDown(250); $('#file_upload_start').attr('mode', 'action'); }); + $('#file_upload_start').focusin(function() { + if($('#fileSelector').val() == '') { + $('#fileSelector').hide(); + $('#file_upload_start').unbind('focusin'); + } + }); + $('#fileSelector').focusout(function() { + if($('#fileSelector').val() == '') { + $('#fileSelector').hide(); + } + }); $('#fileSelector').show(); //needed for Chromium compatibility //rekonq does not call change-event, when click() is executed by script if(navigator.userAgent.indexOf('rekonq') == -1){ $('#fileSelector').click(); } + $('#fileSelector').focus(); } else if($('#file_upload_start').attr('mode') == 'action') { $('#file_upload_cancel').slideUp(250); $('#file_upload_form').attr('uploading', true); From 85dd7129a874f4ae92657c9d27b9079c2b9f4d41 Mon Sep 17 00:00:00 2001 From: Arthur Schiwon Date: Tue, 19 Apr 2011 12:46:32 +0200 Subject: [PATCH 05/19] correct paths for css images --- files/css/files.css | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/files/css/files.css b/files/css/files.css index e3a7528fbf4..c3f7d82aa6e 100644 --- a/files/css/files.css +++ b/files/css/files.css @@ -33,10 +33,10 @@ padding-left: 2em; } -#file_upload_start {background-image:url(/owncloud-dev/img/mimetypes/file.png);} +#file_upload_start {background-image:url(../../img/mimetypes/file.png);} #file_newfolder_name { - background-image:url(/owncloud-dev/img/places/folder.png); font-weight: bold; + background-image:url(../../img/places/folder.png); font-weight: bold; width: 14em; } From 4e2ef271bc7b2e5ff2ea81ee5e4b1442cadd0e41 Mon Sep 17 00:00:00 2001 From: Marco Michelino Date: Wed, 20 Apr 2011 13:28:35 +0200 Subject: [PATCH 06/19] bugfixes on GET requests via WebDAV --- lib/HTTP/WebDAV/Server/Filesystem.php | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/lib/HTTP/WebDAV/Server/Filesystem.php b/lib/HTTP/WebDAV/Server/Filesystem.php index 49b2397175a..9cebee48d7c 100644 --- a/lib/HTTP/WebDAV/Server/Filesystem.php +++ b/lib/HTTP/WebDAV/Server/Filesystem.php @@ -297,12 +297,16 @@ while ($filename = readdir($handle)) { if ($filename != "." && $filename != "..") { - $fullpath = $fspath."/".$filename; + if( substr($fspath, -1) != '/' ){ + $fspath .= '/'; + } + $fullpath = $fspath.$filename; $name = htmlspecialchars($filename); + $uri = $_SERVER['SCRIPT_NAME'] . $fullpath; printf($format, - number_format(filesize($fullpath)), - strftime("%Y-%m-%d %H:%M:%S", filemtime($fullpath)), - "$name"); + number_format(OC_FILESYSTEM::filesize($fullpath)), + strftime("%Y-%m-%d %H:%M:%S", OC_FILESYSTEM::filemtime($fullpath)), + "$name"); } } @@ -745,4 +749,4 @@ VALUES (?,?,?,?,?,'timeout',?,?)"); } } -?> \ No newline at end of file +?> From 741519fa79bcc261479a1745c347413c75128ed4 Mon Sep 17 00:00:00 2001 From: Robin Appelman Date: Thu, 21 Apr 2011 23:03:45 +0200 Subject: [PATCH 07/19] loging system --- lib/log.php | 47 ++++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 42 insertions(+), 5 deletions(-) diff --git a/lib/log.php b/lib/log.php index 231ff7997b1..f5651514108 100644 --- a/lib/log.php +++ b/lib/log.php @@ -50,8 +50,9 @@ class OC_LOG { * * This function adds another entry to the log database */ - public static function add( $appid, $subject, $predicate, $object = null ){ - // TODO: write function + public static function add( $appid, $subject, $predicate, $object = ' ' ){ + $query=OC_DB::prepare("INSERT INTO *PREFIX*log(`timestamp`,appid,user,action,info) VALUES(NOW(),?,?,?,?)"); + $query->execute(array($appid,$subject,$predicate,$object)); return true; } @@ -71,8 +72,27 @@ class OC_LOG { * - app: only entries for this app */ public static function get( $filter = array()){ - // TODO: write function - return array(); + $queryString='SELECT * FROM *PREFIX*log WHERE 1=1 '; + $params=array(); + if(isset($filter['from'])){ + $queryString.='AND `timestamp`>? '; + array_push($params,$filter('from')); + } + if(isset($filter['until'])){ + $queryString.='AND `timestamp`execute($params)->fetchAll(); + } /** @@ -83,9 +103,26 @@ class OC_LOG { * This function deletes all entries that are older than $date. */ public static function deleteBefore( $date ){ - // TODO: write function + $query=OC_DB::prepare("DELETE FROM *PREFIX*log WHERE `timestamp`execute(array($date)); return true; } + + /** + * @brief filter an array of log entries on action + * @param array $logs the log entries to filter + * @param array $actions an array of actions to filter for + * @returns array + */ + public static function filterAction($logs,$actions){ + $filteredLogs=array(); + foreach($logs as $log){ + if(array_search($log['action'],$actions)!==false){ + $filteredLogs[]=$log; + } + } + return $filteredLogs; + } } From cf76cad9317fae94c4dc9328db777e0feb562d26 Mon Sep 17 00:00:00 2001 From: Robin Appelman Date: Thu, 21 Apr 2011 23:04:16 +0200 Subject: [PATCH 08/19] change printPageNavi() to getPageNavi() to allow some more flexibility --- help/templates/index.php | 3 ++- lib/base.php | 6 +++--- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/help/templates/index.php b/help/templates/index.php index 262ab3d8cab..a117c3d5fb4 100644 --- a/help/templates/index.php +++ b/help/templates/index.php @@ -15,7 +15,8 @@ printPage(); ?> ASK A QUESTION diff --git a/lib/base.php b/lib/base.php index 324b2f7e0a0..1ab9b23bccb 100644 --- a/lib/base.php +++ b/lib/base.php @@ -244,9 +244,9 @@ class OC_UTIL { * @param int $pagecount * @param int $page * @param string $url - * @return html-string + * @return OC_TEMPLATE */ - public static function showPageNavi($pagecount,$page,$url) { + public static function getPageNavi($pagecount,$page,$url) { $pagelinkcount=8; if ($pagecount>1) { @@ -261,7 +261,7 @@ class OC_UTIL { $tmpl->assign('pagestart',$pagestart); $tmpl->assign('pagestop',$pagestop); $tmpl->assign('url',$url); - $tmpl->printPage(); + return $tmpl; } } From bd034da8f84b8ffac9467c894bcb91757c572a09 Mon Sep 17 00:00:00 2001 From: Robin Appelman Date: Thu, 21 Apr 2011 23:12:32 +0200 Subject: [PATCH 09/19] log viewer --- log/index.php | 65 ++++++++++++++++++++++++++++++++++++----- log/js/log.js | 21 +++++++++++++ log/templates/index.php | 25 +++++++--------- 3 files changed, 89 insertions(+), 22 deletions(-) create mode 100644 log/js/log.js diff --git a/log/index.php b/log/index.php index 646dbc0cc59..d86da6e0004 100644 --- a/log/index.php +++ b/log/index.php @@ -25,21 +25,70 @@ //require_once('../../config/config.php'); require_once('../lib/base.php'); require( 'template.php' ); + if( !OC_USER::isLoggedIn()){ - header( "Location: ".OC_HELPER::linkTo( "index.php" )); + header( 'Location: '.OC_HELPER::linkTo( 'index.php' )); exit(); } -OC_APP::setActiveNavigationEntry( "log" ); -$logs=OC_LOG::get( $dir ); +//load the script +OC_UTIL::addScript( "log", "log" ); -foreach( $logs as &$i ){ - $i["date"] = date( $CONFIG_DATEFORMAT, $i['timestamp'] ); - $i["action"] = OC_LOG::$TYPE[$i['type']]; +$allActions=array('login','logout','read','write','create','delete'); + +//check for a submited config +if(isset($_POST['size'])){ + $selectedActions=array(); + foreach($allActions as $action){ + if(isset($_POST[$action]) and $_POST[$action]=='on'){ + $selectedActions[]=$action; + } + } + OC_APPCONFIG::setValue('log','actions',implode(',',$selectedActions)); + OC_APPCONFIG::setValue('log','pagesize',$_POST['size']); } -$tmpl = new OC_TEMPLATE( "log", "index", "admin" ); -$tmpl->assign( "logs", $logs ); +OC_APP::setActiveNavigationEntry( 'log' ); +$logs=OC_LOG::get(); + +$selectedActions=explode(',',OC_APPCONFIG::getValue('log','actions',implode(',',$allActions))); +$logs=OC_LOG::filterAction($logs,$selectedActions); + +$pageSize=OC_APPCONFIG::getValue('log','pagesize',20); +$pageCount=ceil(count($logs)/$pageSize); +$page=isset($_GET['page'])?$_GET['page']:0; +if($page>=$pageCount){ + $page=$pageCount-1; +} + +$logs=array_slice($logs,$page*$pageSize,$pageSize); + +foreach( $logs as &$i ){ + $i['date'] =$i['timestamp']; +} + +$url=OC_HELPER::linkTo( 'log', 'index.php' ).'?page='; +$pager=OC_UTIL::getPageNavi($pageCount,$page,$url); +if($pager){ + $pagerHTML=$pager->fetchPage(); +}else{ + $pagerHTML=''; +} + +$showActions=array(); +foreach($allActions as $action){ + if(array_search($action,$selectedActions)!==false){ + $showActions[$action]='checked="checked"'; + }else{ + $showActions[$action]=''; + } +} + +$tmpl = new OC_TEMPLATE( 'log', 'index', 'admin' ); +$tmpl->assign( 'logs', $logs ); +$tmpl->assign( 'pager', $pagerHTML ); +$tmpl->assign( 'size', $pageSize ); +$tmpl->assign( 'showActions', $showActions ); $tmpl->printPage(); ?> diff --git a/log/js/log.js b/log/js/log.js new file mode 100644 index 00000000000..47c20b3e860 --- /dev/null +++ b/log/js/log.js @@ -0,0 +1,21 @@ +$(document).ready(function() { + // Sets the select_all checkbox behaviour : + $('#all').click(function() { + if($(this).attr('checked')){ + // Check all + $('input.action:checkbox').attr('checked', true); + }else{ + // Uncheck all + $('input.action:checkbox').attr('checked', false); + } + }); + $('input.action:checkbox').click(function() { + if(!$(this).attr('checked')){ + $('#all').attr('checked',false); + }else{ + if($('input.action:checkbox:checked').length==$('input.action:checkbox').length){ + $('#all').attr('checked',true); + } + } + }); +}); \ No newline at end of file diff --git a/log/templates/index.php b/log/templates/index.php index 18630e49d06..1e294091e3f 100644 --- a/log/templates/index.php +++ b/log/templates/index.php @@ -1,20 +1,19 @@
-
+

Filter : - - - - - - - - + + name="login" id="logins" /> + name="logout" id="logouts" /> + name="read" id="downloads" /> + name="write" id="uploads" /> + name="create" id="creations" /> + name="delete" id="deletions" />

Show : -  entries per page. +  entries per page.

@@ -31,13 +30,11 @@ - + "> -
-

 3/5 

-
+ From 3e47ce3cef71306921f05fce9bdf19cceaf1c2a8 Mon Sep 17 00:00:00 2001 From: Robin Appelman Date: Fri, 22 Apr 2011 17:14:49 +0200 Subject: [PATCH 10/19] properly load css and js files for apps --- lib/template.php | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/lib/template.php b/lib/template.php index dd1943ae7f5..cdd8f2fb32f 100644 --- a/lib/template.php +++ b/lib/template.php @@ -181,6 +181,7 @@ class OC_TEMPLATE{ { // global Data we need global $WEBROOT; + global $SERVERROOT; $data = $this->_fetch(); if( $this->renderas ) @@ -211,10 +212,18 @@ class OC_TEMPLATE{ // Add the css and js files foreach(OC_UTIL::$scripts as $script){ - $page->append( "jsfiles", "$WEBROOT/$script.js" ); + if(is_file("$SERVERROOT/apps/$script.js" )){ + $page->append( "jsfiles", "$WEBROOT/apps/$script.js" ); + }else{ + $page->append( "jsfiles", "$WEBROOT/$script.js" ); + } } foreach(OC_UTIL::$styles as $style){ - $page->append( "cssfiles", "$WEBROOT/$style.css" ); + if(is_file("$SERVERROOT/apps/$style.js" )){ + $page->append( "cssfiles", "$WEBROOT/apps/$style.css" ); + }else{ + $page->append( "cssfiles", "$WEBROOT/$style.css" ); + } } // Add css files and js files From 4c0d6dc9e7842e1a21e5c01f50e0b61edffa34bf Mon Sep 17 00:00:00 2001 From: Robin Appelman Date: Fri, 22 Apr 2011 17:50:04 +0200 Subject: [PATCH 11/19] make OC_HOOKS actually work --- lib/base.php | 10 +++++----- lib/filesystem.php | 12 ++++++++++++ 2 files changed, 17 insertions(+), 5 deletions(-) diff --git a/lib/base.php b/lib/base.php index 1ab9b23bccb..3f1bb6f3149 100644 --- a/lib/base.php +++ b/lib/base.php @@ -91,9 +91,9 @@ require_once('plugin.php'); $error=(count(OC_UTIL::checkServer())>0); -if(!$error){ - OC_PLUGIN::loadPlugins( "" ); -} +// if(!$error){ //disable untill plugin system is proper converted to the new code base +// OC_PLUGIN::loadPlugins( "" ); +// } OC_USER::setBackend( OC_CONFIG::getValue( "userbackend", "database" )); OC_GROUP::setBackend( OC_CONFIG::getValue( "groupbackend", "database" )); @@ -191,7 +191,7 @@ class OC_UTIL { * @return array */ public static function getVersion(){ - return array(1,2,0); + return array(1,60,0); } /** @@ -406,7 +406,7 @@ class OC_HOOK{ } // Call all slots - foreach( $registered[$signalclass][$signalname] as $i ){ + foreach( self::$registered[$signalclass][$signalname] as $i ){ call_user_func( array( $i["class"], $i["name"] ), $params ); } diff --git a/lib/filesystem.php b/lib/filesystem.php index ca4d1a2c474..03fbecdc4c0 100644 --- a/lib/filesystem.php +++ b/lib/filesystem.php @@ -194,6 +194,18 @@ class OC_FILESYSTEM{ } return $foundMountPoint; } + /** + * return the path to a local version of the file + * we need this because we can't know if a file is stored local or not from outside the filestorage and for some purposes a local file is needed + * @param string path + * @return string + */ + static public function getLocalFile($path){ + $parent=substr($path,0,strrpos($path,'/')); + if(self::canRead($parent) and $storage=self::getStorage($path)){ + return $storage->getLocalFile(self::getInternalPath($path)); + } + } static public function mkdir($path){ $parent=substr($path,0,strrpos($path,'/')); From 08cfe4b6ffb651f13d13741eebba9bac373a46d7 Mon Sep 17 00:00:00 2001 From: Robin Appelman Date: Fri, 22 Apr 2011 20:21:33 +0200 Subject: [PATCH 12/19] stylesheets have .css as extention, not .js --- lib/template.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/template.php b/lib/template.php index cdd8f2fb32f..75e4303ff6a 100644 --- a/lib/template.php +++ b/lib/template.php @@ -219,7 +219,7 @@ class OC_TEMPLATE{ } } foreach(OC_UTIL::$styles as $style){ - if(is_file("$SERVERROOT/apps/$style.js" )){ + if(is_file("$SERVERROOT/apps/$style.css" )){ $page->append( "cssfiles", "$WEBROOT/apps/$style.css" ); }else{ $page->append( "cssfiles", "$WEBROOT/$style.css" ); From 8d52fdb7faf4be4ed4282ecdd3e3a08af1fbf150 Mon Sep 17 00:00:00 2001 From: Robin Appelman Date: Sun, 24 Apr 2011 15:23:18 +0200 Subject: [PATCH 13/19] fix chmodr --- lib/helper.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/helper.php b/lib/helper.php index c141d6f0499..009e961397b 100644 --- a/lib/helper.php +++ b/lib/helper.php @@ -166,7 +166,7 @@ class OC_HELPER { * * Makes 2048 to 2 kB. */ - function chmodr($path, $filemode) { + static function chmodr($path, $filemode) { if (!is_dir($path)) return chmod($path, $filemode); $dh = opendir($path); @@ -177,7 +177,7 @@ class OC_HELPER { return FALSE; elseif(!is_dir($fullpath) && !chmod($fullpath, $filemode)) return FALSE; - elseif(!chmodr($fullpath, $filemode)) + elseif(!self::chmodr($fullpath, $filemode)) return FALSE; } } From b7aba15f179125455298aaee411864ebf4ed86f9 Mon Sep 17 00:00:00 2001 From: Robin Appelman Date: Sun, 24 Apr 2011 16:09:07 +0200 Subject: [PATCH 14/19] add search functionality, for now only searches files but plugins/apps can extend that --- css/styles.css | 4 ++ lib/base.php | 1 + lib/filestorage.php | 21 +++++- lib/filesystem.php | 15 +++++ lib/search.php | 121 +++++++++++++++++++++++++++++++++++ lib/template.php | 6 ++ search/appinfo/app.php | 5 ++ search/css/search.css | 17 +++++ search/index.php | 55 ++++++++++++++++ search/templates/index.php | 17 +++++ templates/layout.admin.php | 2 +- templates/layout.user.php | 2 +- templates/part.searchbox.php | 4 ++ 13 files changed, 267 insertions(+), 3 deletions(-) create mode 100644 lib/search.php create mode 100644 search/appinfo/app.php create mode 100644 search/css/search.css create mode 100644 search/index.php create mode 100644 search/templates/index.php create mode 100644 templates/part.searchbox.php diff --git a/css/styles.css b/css/styles.css index 6b866843541..b737181d01b 100644 --- a/css/styles.css +++ b/css/styles.css @@ -130,3 +130,7 @@ p.actions a.delete, div.actions a.delete { background-image:url('../img/delete.p #logs_options input[type="submit"] { float:right; margin:0 2em 0 0; } #logs_options input[type="text"] { margin:0; padding:0; border:1px solid #ccc; text-align:right; } li.error{ list-style:none; width:640px; margin:4em auto; padding:1em 1em 1em 4em; background-color:#fee; background-image:url('../img/task-attention.png'); background-position:0.8em 0.8em; background-repeat:no-repeat; border:1px solid #ccc; -moz-border-radius:10px; -webkit-border-radius:10px; border-radius:10px; } + +/* SEARCH --------------------------------------------------------------------- */ +form.searchbox{display:inline; position:fixed; top:1.5em; right:9em; margin:0; padding:0;}; +form.searchbox .prettybutton{font-size:1.5em !important}; \ No newline at end of file diff --git a/lib/base.php b/lib/base.php index 3f1bb6f3149..10d59a9d0d6 100644 --- a/lib/base.php +++ b/lib/base.php @@ -88,6 +88,7 @@ require_once('ocsclient.php'); require_once('connect.php'); require_once('remotestorage.php'); require_once('plugin.php'); +require_once('search.php'); $error=(count(OC_UTIL::checkServer())>0); diff --git a/lib/filestorage.php b/lib/filestorage.php index 3d0bdf4cc0e..429961b3d69 100644 --- a/lib/filestorage.php +++ b/lib/filestorage.php @@ -62,6 +62,7 @@ class OC_FILESTORAGE{ public function getTree($path){} public function hash($type,$path,$raw){} public function free_space($path){} + public function search($query){} } @@ -468,7 +469,25 @@ class OC_FILESTORAGE_LOCAL extends OC_FILESTORAGE{ public function free_space($path){ return disk_free_space($this->datadir.$path); } - + + public function search($query){ + return $this->searchInDir($query); + } + + private function searchInDir($query,$dir=''){ + $files=array(); + foreach (scandir($this->datadir.$dir) as $item) { + if ($item == '.' || $item == '..') continue; + if(strstr(strtolower($item),strtolower($query))!==false){ + $files[]=$dir.'/'.$item; + } + if(is_dir($this->datadir.$dir.'/'.$item)){ + $files=array_merge($files,$this->searchInDir($query,$dir.'/'.$item)); + } + } + return $files; + } + /** * @brief get the size of folder and it's content * @param string $path file path diff --git a/lib/filesystem.php b/lib/filesystem.php index 03fbecdc4c0..2b5c3a56b6e 100644 --- a/lib/filesystem.php +++ b/lib/filesystem.php @@ -457,5 +457,20 @@ class OC_FILESYSTEM{ return $storage->free_space($path); } } + + static public function search($query){ + $files=array(); + $fakeRootLength=strlen(self::$fakeRoot); + foreach(self::$storages as $mountpoint=>$storage){ + $results=$storage->search($query); + foreach($results as $result){ + $file=str_replace('//','/',$mountpoint.$result); + $file=substr($file,$fakeRootLength); + $files[]=$file; + } + } + return $files; + + } } ?> diff --git a/lib/search.php b/lib/search.php new file mode 100644 index 00000000000..ef82e225f3d --- /dev/null +++ b/lib/search.php @@ -0,0 +1,121 @@ +. + * + */ + + +/** + * provides an interface to all search providers + */ +class OC_SEARCH{ + static private $providers=array(); + + /** + * register a new search provider to be used + * @param OC_SearchProvider $provider + */ + public static function registerProvider($provider){ + self::$providers[]=$provider; + } + + /** + * search all provider for $query + * @param string query + * @return array An array of OC_SearchResult's + */ + public static function search($query){ + $results=array(); + foreach(self::$providers as $provider){ + $results=array_merge($results,$provider->search($query)); + } + return $results; + } +} + +/** + * provides search functionalty + */ +abstract class OC_SearchProvider{ + public function __construct(){ + OC_SEARCH::registerProvider($this); + } + + /** + * search for $query + * @param string $query + * @return array An array of OC_SearchResult's + */ + abstract function search($query); +} + +/** + * a result of a search + */ +class OC_SearchResult{ + private $name; + private $text; + private $link; + private $type; + + /** + * create a new search result + * @param string $name short name for the result + * @param string $text some more information about the result + * @param string $link link for the result + * @param string $type the type of result as human readable string ('File', 'Music', etc) + */ + public function __construct($name,$text,$link,$type){ + $this->name=$name; + $this->text=$text; + $this->link=$link; + $this->type=$type; + } + + public function __get($name){ + switch($name){ + case 'name': + return $this->name; + case 'text': + return $this->text; + case 'link': + return $this->link; + case 'type': + return $this->type; + } + } +} + +class OC_FileSearchProvider extends OC_SearchProvider{ + function search($query){ + $files=OC_FILESYSTEM::search($query); + $results=array(); + foreach($files as $file){ + if(OC_FILESYSTEM::is_dir($file)){ + $results[]=new OC_SearchResult(basename($file),$file,OC_HELPER::linkTo( 'files', 'index.php?dir='.$file ),'Files'); + }else{ + $results[]=new OC_SearchResult(basename($file),$file,OC_HELPER::linkTo( 'files', 'download.php?file='.$file ),'Files'); + } + } + return $results; + } +} + +new OC_FileSearchProvider(); +?> \ No newline at end of file diff --git a/lib/template.php b/lib/template.php index 75e4303ff6a..0d6776aa26d 100644 --- a/lib/template.php +++ b/lib/template.php @@ -190,6 +190,9 @@ class OC_TEMPLATE{ if( $this->renderas == "user" ) { $page = new OC_TEMPLATE( "core", "layout.user" ); + $search=new OC_TEMPLATE( 'core', 'part.searchbox'); + $search->assign('searchurl',OC_HELPER::linkTo( 'search', 'index.php' )); + $page->assign('searchbox', $search->fetchPage()); // Add menu data // Add navigation entry @@ -198,6 +201,9 @@ class OC_TEMPLATE{ elseif( $this->renderas == "admin" ) { $page = new OC_TEMPLATE( "core", "layout.admin" ); + $search=new OC_TEMPLATE( 'core', 'part.searchbox'); + $search->assign('searchurl',OC_HELPER::linkTo( 'search', 'index.php' )); + $page->assign('searchbox', $search->fetchPage()); // Add menu data if( OC_GROUP::inGroup( $_SESSION["user_id"], "admin" )){ $page->assign( "settingsnavigation", OC_APP::getSettingsNavigation()); diff --git a/search/appinfo/app.php b/search/appinfo/app.php new file mode 100644 index 00000000000..44834498fec --- /dev/null +++ b/search/appinfo/app.php @@ -0,0 +1,5 @@ + 2, "id" => 'search', 'name' => 'Search' )); + +?> diff --git a/search/css/search.css b/search/css/search.css new file mode 100644 index 00000000000..df0712be03f --- /dev/null +++ b/search/css/search.css @@ -0,0 +1,17 @@ +#searchresults{ + margin: 2em; + list-style:none; + border: solid 1px #CCC; +} + +#searchresults li.resultHeader{ + font-size:1.2em; + font-weight:bold; + border-bottom: solid 1px #CCC; + padding:0.2em; + background-color:#eee; +} + +#searchresults li.result{ + margin-left:2em; +} \ No newline at end of file diff --git a/search/index.php b/search/index.php new file mode 100644 index 00000000000..e6f41528ea3 --- /dev/null +++ b/search/index.php @@ -0,0 +1,55 @@ +. +* +*/ + + +// Init owncloud +require_once('../lib/base.php'); +require( 'template.php' ); + +// Check if we are a user +if( !OC_USER::isLoggedIn()){ + header( "Location: ".OC_HELPER::linkTo( '', 'index.php' )); + exit(); +} + +// Load the files we need +OC_UTIL::addStyle( 'search', 'search' ); + +$query=(isset($_POST['query']))?$_POST['query']:''; +if($query){ + $results=OC_SEARCH::search($query); +} + +$resultTypes=array(); +foreach($results as $result){ + if(!isset($resultTypes[$result->type])){ + $resultTypes[$result->type]=array(); + } + $resultTypes[$result->type][]=$result; +} + +$tmpl = new OC_TEMPLATE( 'search', 'index', 'user' ); +$tmpl->assign('resultTypes',$resultTypes); +$tmpl->printPage(); + +?> diff --git a/search/templates/index.php b/search/templates/index.php new file mode 100644 index 00000000000..7241553e7fc --- /dev/null +++ b/search/templates/index.php @@ -0,0 +1,17 @@ +
    + +
  • +

    type?>

    +
  • + +
  • +

    + name?> +

    +

    + text?> +

    +
  • + + +
diff --git a/templates/layout.admin.php b/templates/layout.admin.php index 0212419a952..efd9a8b6fdb 100644 --- a/templates/layout.admin.php +++ b/templates/layout.admin.php @@ -15,7 +15,7 @@