This commit is contained in:
Robin Appelman 2011-04-28 23:59:02 +02:00
commit 5d358bb63f
29 changed files with 606 additions and 106 deletions

View File

@ -1500,7 +1500,7 @@ class MDB2_Driver_Common extends PEAR
}
}
$err = $this->raiseError(null, $code, $mode, $options, $userinfo, 'MDB2_Error', true);
$err = PEAR::raiseError(null, $code, $mode, $options, $userinfo, 'MDB2_Error', true);
if ($err->getMode() !== PEAR_ERROR_RETURN
&& isset($this->nested_transaction_counter) && !$this->has_transaction_error) {
$this->has_transaction_error =$err;

View File

@ -71,6 +71,8 @@ class MDB2_Driver_Manager_sqlite extends MDB2_Driver_Manager_Common
*/
function createDatabase($name, $options = array())
{
global $SERVERROOT;
$datadir=OC_CONFIG::getValue( "datadirectory", "$SERVERROOT/data" );
$db =$this->getDBInstance();
if (PEAR::isError($db)) {
return $db;
@ -82,7 +84,8 @@ class MDB2_Driver_Manager_sqlite extends MDB2_Driver_Manager_Common
'database already exists', __FUNCTION__);
}
$php_errormsg = '';
$handle = @sqlite_open($database_file, $db->dsn['mode'], $php_errormsg);
$database_file="$datadir/$database_file.db";
$handle = sqlite_open($database_file, $db->dsn['mode'], $php_errormsg);
if (!$handle) {
return $db->raiseError(MDB2_ERROR_CANNOT_CREATE, null, null,
(isset($php_errormsg) ? $php_errormsg : 'could not create the database file'), __FUNCTION__);

View File

@ -205,7 +205,7 @@ class MDB2_Driver_sqlite extends MDB2_Driver_Common
register_shutdown_function('MDB2_closeOpenTransactions');
}
$query = 'BEGIN TRANSACTION '.$this->options['base_transaction_name'];
$result =& $this->_doQuery($query, true);
$result =$this->_doQuery($query, true);
if (PEAR::isError($result)) {
return $result;
}
@ -240,7 +240,7 @@ class MDB2_Driver_sqlite extends MDB2_Driver_Common
}
$query = 'COMMIT TRANSACTION '.$this->options['base_transaction_name'];
$result =& $this->_doQuery($query, true);
$result =$this->_doQuery($query, true);
if (PEAR::isError($result)) {
return $result;
}
@ -275,7 +275,7 @@ class MDB2_Driver_sqlite extends MDB2_Driver_Common
}
$query = 'ROLLBACK TRANSACTION '.$this->options['base_transaction_name'];
$result =& $this->_doQuery($query, true);
$result =$this->_doQuery($query, true);
if (PEAR::isError($result)) {
return $result;
}
@ -347,6 +347,8 @@ class MDB2_Driver_sqlite extends MDB2_Driver_Common
**/
function connect()
{
global $SERVERROOT;
$datadir=OC_CONFIG::getValue( "datadirectory", "$SERVERROOT/data" );
$database_file = $this->_getDatabaseFile($this->database_name);
if (is_resource($this->connection)) {
//if (count(array_diff($this->connected_dsn, $this->dsn)) == 0
@ -370,6 +372,9 @@ class MDB2_Driver_sqlite extends MDB2_Driver_Common
}
if ($database_file !== ':memory:') {
if(!strpos($database_file,'.db')){
$database_file="$datadir/$database_file.db";
}
if (!file_exists($database_file)) {
if (!touch($database_file)) {
return $this->raiseError(MDB2_ERROR_NOT_FOUND, null, null,
@ -405,7 +410,9 @@ class MDB2_Driver_sqlite extends MDB2_Driver_Common
$php_errormsg = '';
if (version_compare('5.1.0', PHP_VERSION, '>')) {
@ini_set('track_errors', true);
echo 1;
$connection = @$connect_function($database_file);
echo 2;
@ini_restore('track_errors');
} else {
$connection = @$connect_function($database_file, 0666, $php_errormsg);
@ -538,7 +545,7 @@ class MDB2_Driver_sqlite extends MDB2_Driver_Common
$this->_lasterror = $php_errormsg;
if (!$result) {
$err =& $this->raiseError(null, null, null,
$err =$this->raiseError(null, null, null,
'Could not execute statement', __FUNCTION__);
return $err;
}
@ -753,7 +760,7 @@ class MDB2_Driver_sqlite extends MDB2_Driver_Common
$table = $this->quoteIdentifier($table, true);
$query = "REPLACE INTO $table ($query) VALUES ($values)";
$result =& $this->_doQuery($query, true, $connection);
$result =$this->_doQuery($query, true, $connection);
if (PEAR::isError($result)) {
return $result;
}
@ -781,7 +788,7 @@ class MDB2_Driver_sqlite extends MDB2_Driver_Common
$query = "INSERT INTO $sequence_name ($seqcol_name) VALUES (NULL)";
$this->pushErrorHandling(PEAR_ERROR_RETURN);
$this->expectError(MDB2_ERROR_NOSUCHTABLE);
$result =& $this->_doQuery($query, true);
$result =$this->_doQuery($query, true);
$this->popExpect();
$this->popErrorHandling();
if (PEAR::isError($result)) {
@ -800,7 +807,7 @@ class MDB2_Driver_sqlite extends MDB2_Driver_Common
$value = $this->lastInsertID();
if (is_numeric($value)) {
$query = "DELETE FROM $sequence_name WHERE $seqcol_name < $value";
$result =& $this->_doQuery($query, true);
$result =$this->_doQuery($query, true);
if (PEAR::isError($result)) {
$this->warnings[] = 'nextID: could not delete previous sequence table values from '.$seq_name;
}
@ -896,7 +903,7 @@ class MDB2_Result_sqlite extends MDB2_Result_Common
}
if (!$row) {
if ($this->result === false) {
$err =& $this->db->raiseError(MDB2_ERROR_NEED_MORE_DATA, null, null,
$err =$this->db->raiseError(MDB2_ERROR_NEED_MORE_DATA, null, null,
'resultset has already been freed', __FUNCTION__);
return $err;
}

View File

@ -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};

View File

@ -19,23 +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_form input[type="button"]{
#file_upload_start, #file_newfolder_name {
background-repeat: no-repeat;
background-position: 0.5em 0;
padding-left: 2em;
}
#file_upload_start {background-image:url(../../img/mimetypes/file.png);}
#file_newfolder_name {
background-image:url(../../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;
}

View File

@ -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(
@ -85,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);
@ -115,6 +129,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 +186,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 +232,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 + ");");

View File

@ -3,10 +3,9 @@
<form id="file_upload_form" action="ajax/upload.php"
method="post" enctype="multipart/form-data" target="file_upload_target"><input
type="hidden" name="MAX_FILE_SIZE" value="<?php echo $_["uploadMaxFilesize"] ?>" id="max_upload"><input
type="hidden" class="max_human_file_size" value="(max <?php echo $_["uploadMaxHumanFilesize"]; ?>)"><input type="hidden" name="dir" value="<?php echo $_["dir"] ?>" id="dir"><input class="prettybutton" type="submit" id="file_upload_start" value="Upload (max <?php echo $_["uploadMaxHumanFilesize"];?>)" />&nbsp;<input class="prettybutton" type="button" id="file_upload_cancel" value="X" /><input type="file" name="file" id="fileSelector"><iframe id="file_upload_target" name="file_upload_target" src=""></iframe></form><a href="" title="" class="new-dir">New folder</a><a href="" title="" class="download">Download</a><a href="" title="" class="share">Share</a><a href="" title="" class="delete">Delete</a>
type="hidden" class="max_human_file_size" value="(max <?php echo $_["uploadMaxHumanFilesize"]; ?>)"><input type="hidden" name="dir" value="<?php echo $_["dir"] ?>" id="dir"><input class="prettybutton" type="submit" id="file_upload_start" value="Upload (max <?php echo $_["uploadMaxHumanFilesize"];?>)" />&nbsp;<input class="prettybutton" type="button" id="file_upload_cancel" value="X" /><input type="file" name="file" id="fileSelector"><iframe id="file_upload_target" name="file_upload_target" src=""></iframe></form><form id="file_newfolder_form"><input type="text" class="prettybutton" name="file_newfolder_name" id="file_newfolder_name" value="New Folder" />&nbsp;<input class="prettybutton" type="button" id="file_newfolder_submit" name="file_newfolder_submit" value="OK" /></form><a href="" title="" class="download">Download</a><a href="" title="" class="share">Share</a><a href="" title="" class="delete">Delete</a>
</div>
<div id="file_action_panel">
<form id="file_newfolder_form"><input type="text" name="file_new_dir_name" id="file_new_dir_name" />&nbsp;<input class="prettybutton" type="button" id="file_new_dir_submit" name="file_new_dir_submit" value="OK" /></form>
</div>
</div>

View File

@ -15,7 +15,8 @@
</table>
<?php
$url=OC_HELPER::linkTo( "help", "index.php" ).'?page=';
OC_UTIL::showPageNavi($_['pagecount'],$_['page'],$url);
$pageNavi=OC_UTIL::getPageNavi($_['pagecount'],$_['page'],$url);
$pageNavi->printPage();
?>
<a target="_blank" class="prettybutton" href="http://apps.owncloud.com/knowledgebase/editquestion.php?action=new">ASK A QUESTION</a>

View File

@ -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)),
"<a href='$name'>$name</a>");
number_format(OC_FILESYSTEM::filesize($fullpath)),
strftime("%Y-%m-%d %H:%M:%S", OC_FILESYSTEM::filemtime($fullpath)),
"<a href='$uri'>$name</a>");
}
}
@ -745,4 +749,4 @@ VALUES (?,?,?,?,?,'timeout',?,?)");
}
}
?>
?>

View File

@ -47,7 +47,7 @@ class OC_APPCONFIG{
*/
public static function getApps(){
// No magic in here!
$query = OC_DB::prepare( 'SELECT DISTINCT( `appid` ) FROM `*PREFIX*appconfig`' );
$query = OC_DB::prepare( 'SELECT DISTINCT( appid ) FROM `*PREFIX*appconfig`' );
$result = $query->execute();
$apps = array();
@ -68,7 +68,7 @@ class OC_APPCONFIG{
*/
public static function getKeys( $app ){
// No magic in here as well
$query = OC_DB::prepare( 'SELECT `key` FROM `*PREFIX*appconfig` WHERE `appid` = ?' );
$query = OC_DB::prepare( 'SELECT key FROM `*PREFIX*appconfig` WHERE `appid` = ?' );
$result = $query->execute( array( $app ));
$keys = array();
@ -91,7 +91,7 @@ class OC_APPCONFIG{
*/
public static function getValue( $app, $key, $default = null ){
// At least some magic in here :-)
$query = OC_DB::prepare( 'SELECT `value` FROM `*PREFIX*appconfig` WHERE `appid` = ? AND `key` = ?' );
$query = OC_DB::prepare( 'SELECT value FROM *PREFIX*appconfig WHERE appid = ? AND key = ?' );
$result = $query->execute( array( $app, $key ));
if( !$result->numRows()){
@ -118,11 +118,11 @@ class OC_APPCONFIG{
// null: does not exist
if( is_null( $exists )){
$query = OC_DB::prepare( 'INSERT INTO `*PREFIX*appconfig` ( `appid`, `key`, `value` ) VALUES( ?, ?, ? )' );
$query = OC_DB::prepare( 'INSERT INTO *PREFIX*appconfig ( `appid`, `key`, `value` ) VALUES( ?, ?, ? )' );
$query->execute( array( $app, $key, $value ));
}
else{
$query = OC_DB::prepare( 'UPDATE `*PREFIX*appconfig` SET `value` = ? WHERE `appid` = ? AND `key` = ?' );
$query = OC_DB::prepare( 'UPDATE *PREFIX*appconfig SET value = ? WHERE appid = ? AND key = ?' );
$query->execute( array( $value, $app, $key ));
}
}

View File

@ -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);
@ -191,7 +192,7 @@ class OC_UTIL {
* @return array
*/
public static function getVersion(){
return array(1,2,0);
return array(1,60,0);
}
/**
@ -204,7 +205,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 +222,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";
}
}
/**
@ -236,9 +245,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) {
@ -253,7 +262,7 @@ class OC_UTIL {
$tmpl->assign('pagestart',$pagestart);
$tmpl->assign('pagestop',$pagestop);
$tmpl->assign('url',$url);
$tmpl->printPage();
return $tmpl;
}
}
@ -293,20 +302,6 @@ class OC_UTIL {
//check for correct file permissions
if(!stristr(PHP_OS, 'WIN')){
if($CONFIG_DBTYPE=='sqlite'){
$file=$SERVERROOT.'/'.$CONFIG_DBNAME;
if(file_exists($file)){
$prems=substr(decoct(fileperms($file)),-3);
if(substr($prems,2,1)!='0'){
@chmod($file,0660);
clearstatcache();
$prems=substr(decoct(fileperms($file)),-3);
if(substr($prems,2,1)!='0'){
$errors[]=array('error'=>'SQLite database file ('.$file.') is readable from the web<br/>','hint'=>$permissionsHint);
}
}
}
}
$prems=substr(decoct(fileperms($CONFIG_DATADIRECTORY_ROOT)),-3);
if(substr($prems,-1)!='0'){
OC_HELPER::chmodr($CONFIG_DATADIRECTORY_ROOT,0770);
@ -398,7 +393,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 );
}

View File

@ -43,8 +43,8 @@ class OC_DB {
$CONFIG_DBUSER = OC_CONFIG::getValue( "dbuser", "" );;
$CONFIG_DBPASSWORD = OC_CONFIG::getValue( "dbpassword", "" );;
$CONFIG_DBTYPE = OC_CONFIG::getValue( "dbtype", "sqlite" );;
global $DOCUMENTROOT;
global $SERVERROOT;
$datadir=OC_CONFIG::getValue( "datadirectory", "$SERVERROOT/data" );
// do nothing if the connection already has been established
if(!self::$DBConnection){
@ -64,7 +64,7 @@ class OC_DB {
// sqlite
$dsn = array(
'phptype' => 'sqlite',
'database' => "$SERVERROOT/$CONFIG_DBNAME",
'database' => "$datadir/$CONFIG_DBNAME.db",
'mode' => '0644' );
}
elseif( $CONFIG_DBTYPE == 'mysql' ){
@ -256,9 +256,9 @@ class OC_DB {
if( $definition instanceof MDB2_Schema_Error ){
die( $definition->getMessage().': '.$definition->getUserInfo());
}
if(OC_CONFIG::getValue('dbtype','sqlite')=='sqlite'){
$definition['overwrite']=true;//always overwrite for sqlite
}
// if(OC_CONFIG::getValue('dbtype','sqlite')=='sqlite'){
// $definition['overwrite']=true;//always overwrite for sqlite
// }
$ret=self::$schema->createDatabase( $definition );
// Die in case something went wrong
@ -300,7 +300,13 @@ class OC_DB {
// We need Database type and table prefix
$CONFIG_DBTYPE = OC_CONFIG::getValue( "dbtype", "sqlite" );
$CONFIG_DBTABLEPREFIX = OC_CONFIG::getValue( "dbtableprefix", "oc_" );
// differences is getting the current timestamp
if( $CONFIG_DBTYPE == 'sqlite' ){
$query = str_replace( 'NOW()', "strftime('%s', 'now')", $query );
$query = str_replace( 'now()', "strftime('%s', 'now')", $query );
}
// differences in escaping of table names (` for mysql)
// Problem: what if there is a ` in the value we want to insert?
if( $CONFIG_DBTYPE == 'sqlite' ){
@ -310,7 +316,7 @@ class OC_DB {
$query = str_replace( '`', '"', $query );
}
// replace table names
// replace table name prefix
$query = str_replace( '*PREFIX*', $CONFIG_DBTABLEPREFIX, $query );
return $query;

View File

@ -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

View File

@ -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,'/'));
@ -445,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;
}
}
?>

View File

@ -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";
}
}
/**
@ -162,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);
@ -173,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;
}
}

View File

@ -136,7 +136,7 @@ class OC_INSTALLER{
global $SERVERROOT;
global $WEBROOT;
$content="ErrorDocument 404 /$WEBROOT/templates/404.php\n";
file_put_contents($SERVERROOT.'/.htaccess',$content);
@file_put_contents($SERVERROOT.'/.htaccess',$content); //supress errors in case we don't have permissions for it
$content="deny from all";
file_put_contents(OC_CONFIG::getValue('datadirectory',$SERVERROOT.'/data').'/.htaccess',$content);

View File

@ -50,8 +50,16 @@ 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(),?,?,?,?)");
$result=$query->execute(array($appid,$subject,$predicate,$object));
// Die if we have an error
if( PEAR::isError($result)) {
$entry = 'DB Error: "'.$result->getMessage().'"<br />';
$entry .= 'Offending command was: '.$query.'<br />';
error_log( $entry );
die( $entry );
}
return true;
}
@ -71,8 +79,33 @@ 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`<? ';
array_push($params,$filter('until'));
}
if(isset($filter['user'])){
$queryString.='AND user=? ';
array_push($params,$filter('user'));
}
if(isset($filter['app'])){
$queryString.='AND appid=? ';
array_push($params,$filter('app'));
}
$query=OC_DB::prepare($queryString);
$result=$query->execute($params)->fetchAll();
if(count($result)>0 and is_numeric($result[0]['timestamp'])){
foreach($result as &$row){
$row['timestamp']=OC_UTIL::formatDate($row['timestamp']);
}
}
return $result;
}
/**
@ -83,9 +116,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`<?");
$query->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;
}
}

121
lib/search.php Normal file
View File

@ -0,0 +1,121 @@
<?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/>.
*
*/
/**
* 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();
?>

View File

@ -181,6 +181,7 @@ class OC_TEMPLATE{
{
// global Data we need
global $WEBROOT;
global $SERVERROOT;
$data = $this->_fetch();
if( $this->renderas )
@ -189,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
@ -197,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());
@ -211,10 +218,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.css" )){
$page->append( "cssfiles", "$WEBROOT/apps/$style.css" );
}else{
$page->append( "cssfiles", "$WEBROOT/$style.css" );
}
}
// Add css files and js files

View File

@ -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();
?>

21
log/js/log.js Normal file
View File

@ -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);
}
}
});
});

View File

@ -1,20 +1,19 @@
<div class="controls">
<form id="logs_options">
<form id="logs_options" method='post'>
<p>
<span>Filter :</span>
<input type="checkbox" checked="checked" name="all" id="all" /> <label for="all">All</label>
<input type="checkbox" checked="checked" name="logins" id="logins" /> <label for="logins">Logins</label>
<input type="checkbox" checked="checked" name="logouts" id="logouts" /> <label for="logouts">Logouts</label>
<input type="checkbox" checked="checked" name="downloads" id="downloads" /> <label for="downloads">Downloads</label>
<input type="checkbox" checked="checked" name="uploads" id="uploads" /> <label for="uploads">Uploads</label>
<input type="checkbox" checked="checked" name="creations" id="creations" /> <label for="creations">Creations</label>
<input type="checkbox" checked="checked" name="deletions" id="deletions" /> <label for="deletions">Deletions</label>
<input type="checkbox" checked="" name="all" id="all" /> <label for="all">All</label>
<input type="checkbox" class='action' <?php echo $_['showActions']['login']?> name="login" id="logins" /> <label for="logins">Logins</label>
<input type="checkbox" class='action' <?php echo $_['showActions']['logout']?> name="logout" id="logouts" /> <label for="logouts">Logouts</label>
<input type="checkbox" class='action' <?php echo $_['showActions']['read']?> name="read" id="downloads" /> <label for="downloads">Downloads</label>
<input type="checkbox" class='action' <?php echo $_['showActions']['write']?> name="write" id="uploads" /> <label for="uploads">Uploads</label>
<input type="checkbox" class='action' <?php echo $_['showActions']['create']?> name="create" id="creations" /> <label for="creations">Creations</label>
<input type="checkbox" class='action' <?php echo $_['showActions']['delete']?> name="delete" id="deletions" /> <label for="deletions">Deletions</label>
</p>
<p>
<span>Show :</span>
<input type="text" maxlength="3" size="3" value="10" />&nbsp;entries per page.
<input type="text" maxlength="3" size="3" value="<?php echo $_['size']?>" name='size'/>&nbsp;entries per page.
<input class="prettybutton" type="submit" value="Save" />
</p>
@ -31,13 +30,11 @@
<tbody>
<?php foreach($_["logs"] as $entry): ?>
<tr>
<td class="login"><em><?php echo $entry["user"]; ?></em> <?php echo $entry["message"]; ?></td>
<td class="<?php echo $entry["action"]; ?>"><em><?php echo $entry["action"]; ?> <?php echo $entry["user"]; ?></em> <?php echo $entry["info"]; ?></td>
<td class="date"><?php echo $entry["date"]; ?></td>
</tr>
<?php endforeach; ?>
</tbody>
</table>
<div class="controls">
<p class="center"><a href="" title="Previous page">&larr;</a>&nbsp;3/5&nbsp;<a href="" title="Next page">&rarr;</a></p>
</div>
<?php echo $_['pager'];?>

5
search/appinfo/app.php Normal file
View File

@ -0,0 +1,5 @@
<?php
OC_APP::register( array( 'order' => 2, "id" => 'search', 'name' => 'Search' ));
?>

17
search/css/search.css Normal file
View File

@ -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;
}

55
search/index.php Normal file
View File

@ -0,0 +1,55 @@
<?php
/**
* ownCloud - ajax frontend
*
* @author Robin Appelman
* @copyright 2010 Robin Appelman icewind1991@gmail.com
*
* 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/>.
*
*/
// 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();
?>

View File

@ -0,0 +1,17 @@
<ul id='searchresults'>
<?php foreach($_['resultTypes'] as $resultType):?>
<li class='resultHeader'>
<p><?php echo $resultType[0]->type?></p>
</li>
<?php foreach($resultType as $result):?>
<li class='result'>
<p>
<a href='<?php echo $result->link?>' title='<?php echo $result->name?>'><?php echo $result->name?></a>
</p>
<p>
<?php echo $result->text?>
</p>
</li>
<?php endforeach;?>
<?php endforeach;?>
</ul>

View File

@ -15,7 +15,7 @@
<body id="body-settings">
<div id="header">
<a href="<?php echo link_to('', 'index.php'); ?>" title="" id="owncloud"><img src="<?php echo image_path('', 'owncloud-logo-small-white.png'); ?>" alt="ownCloud" /></a>
<?php echo $_['searchbox']?>
<ul id="metanav">
<li><a href="<?php echo link_to('', 'index.php'); ?>" title="Back to files"><img src="<?php echo image_path('', 'layout/back.png'); ?>"></a></li>
<li><a href="<?php echo link_to('', 'index.php?logout=true'); ?>" title="Log out"><img src="<?php echo image_path('', 'layout/logout.png'); ?>"></a></li>

View File

@ -15,7 +15,7 @@
<body id="body-user">
<div id="header">
<a href="<?php echo link_to('', 'index.php'); ?>" title="" id="owncloud"><img src="<?php echo image_path('', 'owncloud-logo-small-white.png'); ?>" alt="ownCloud" /></a>
<?php echo $_['searchbox']?>
<ul id="metanav">
<li><a href="<?php echo link_to('settings', 'index.php'); ?>" title="Settings"><img src="<?php echo image_path('', 'layout/settings.png'); ?>"></a></li>
<li><a href="<?php echo link_to('', 'index.php'); ?>?logout=true" title="Log out"><img src="<?php echo image_path('', 'layout/logout.png'); ?>"></a></li>

View File

@ -0,0 +1,4 @@
<form class='searchbox' action='<?php echo $_['searchurl']?>' method='post'>
<input name='query' value='<?php if(isset($_POST['query'])){echo $_POST['query'];};?>'/>
<input type='submit' value='Search' class='prettybutton'/>
</form>