One class per file!

This commit is contained in:
Jakob Sack 2011-07-29 21:03:53 +02:00
parent 2bfad189e7
commit 2ff8d7a8bc
26 changed files with 211 additions and 233 deletions

View File

@ -82,7 +82,7 @@ class OC_MEDIA{
}
}
class OC_MediaSearchProvider extends OC_SearchProvider{
class OC_MediaSearchProvider extends OC_Search_Provider{
function search($query){
require_once('lib_collection.php');
$artists=OC_MEDIA_COLLECTION::getArtists($query);
@ -90,18 +90,18 @@ class OC_MediaSearchProvider extends OC_SearchProvider{
$songs=OC_MEDIA_COLLECTION::getSongs(0,0,$query);
$results=array();
foreach($artists as $artist){
$results[]=new OC_SearchResult($artist['artist_name'],'',OC_HELPER::linkTo( 'apps/media', 'index.php#artist='.urlencode($artist['artist_name']) ),'Music');
$results[]=new OC_Search_Result($artist['artist_name'],'',OC_HELPER::linkTo( 'apps/media', 'index.php#artist='.urlencode($artist['artist_name']) ),'Music');
}
foreach($albums as $album){
$artist=urlencode(OC_MEDIA_COLLECTION::getArtistName($album['album_artist']));
$results[]=new OC_SearchResult($album['album_name'],'',OC_HELPER::linkTo( 'apps/media', 'index.php#artist='.$artist.'&album='.urlencode($album['album_name']) ),'Music');
$results[]=new OC_Search_Result($album['album_name'],'',OC_HELPER::linkTo( 'apps/media', 'index.php#artist='.$artist.'&album='.urlencode($album['album_name']) ),'Music');
}
foreach($songs as $song){
$minutes=floor($song['song_length']/60);
$secconds=$song['song_length']%60;
$artist=urlencode(OC_MEDIA_COLLECTION::getArtistName($song['song_artist']));
$album=urlencode(OC_MEDIA_COLLECTION::getalbumName($song['song_album']));
$results[]=new OC_SearchResult($song['song_name'],"$minutes:$secconds",OC_HELPER::linkTo( 'apps/media', 'index.php#artist='.$artist.'&album='.$album.'&song='.urlencode($song['song_name']) ),'Music');
$results[]=new OC_Search_Result($song['song_name'],"$minutes:$secconds",OC_HELPER::linkTo( 'apps/media', 'index.php#artist='.$artist.'&album='.$album.'&song='.urlencode($song['song_name']) ),'Music');
}
return $results;
}

View File

@ -408,4 +408,3 @@ class OC_APP{
}
}
}
?>

View File

@ -158,4 +158,3 @@ class OC_APPCONFIG{
return true;
}
}
?>

View File

@ -110,3 +110,93 @@ OC_UTIL::addStyle( "styles" );
if(!$error and !$RUNTIME_NOAPPS ){
OC_APP::loadApps();
}
// FROM Connect.php
function OC_CONNECT_TEST($path,$user,$password){
echo 'connecting...';
$remote=OC_CONNECT::connect($path,$user,$password);
if($remote->connected){
echo 'done<br/>';
if($remote->isLoggedIn()){
echo 'logged in, session working<br/>';
echo 'trying to get remote files...';
$files=$remote->getFiles('');
if($files){
echo count($files).' files found:<br/>';
foreach($files as $file){
echo "{$file['type']} {$file['name']}: {$file['size']} bytes<br/>";
}
echo 'getting file "'.$file['name'].'"...';
$size=$file['size'];
$file=$remote->getFile('',$file['name']);
if(file_exists($file)){
$newSize=filesize($file);
if($size!=$newSize){
echo "fail<br/>Error: $newSize bytes received, $size expected.";
echo '<br/><br/>Recieved file:<br/>';
readfile($file);
unlink($file);
return;
}
OC_FILESYSTEM::fromTmpFile($file,'/remoteFile');
echo 'done<br/>';
echo 'sending file "burning_avatar.png"...';
$res=$remote->sendFile('','burning_avatar.png','','burning_avatar.png');
if($res){
echo 'done<br/>';
}else{
echo 'fail<br/>';
}
}else{
echo 'fail<br/>';
}
}else{
echo 'fail<br/>';
}
}else{
echo 'no longer logged in, session fail<br/>';
}
}else{
echo 'fail<br/>';
}
$remote->disconnect();
die();
}
// From files.php
function zipAddDir($dir,$zip,$internalDir=''){
$dirname=basename($dir);
$zip->addEmptyDir($internalDir.$dirname);
$internalDir.=$dirname.='/';
$files=OC_FILES::getdirectorycontent($dir);
foreach($files as $file){
$filename=$file['name'];
$file=$dir.'/'.$filename;
if(OC_FILESYSTEM::is_file($file)){
$tmpFile=OC_FILESYSTEM::toTmpFile($file);
OC_FILES::$tmpFiles[]=$tmpFile;
$zip->addFile($tmpFile,$internalDir.$filename);
}elseif(OC_FILESYSTEM::is_dir($file)){
zipAddDir($file,$zip,$internalDir);
}
}
}
if(!function_exists('sys_get_temp_dir')) {
function sys_get_temp_dir() {
if( $temp=getenv('TMP') ) return $temp;
if( $temp=getenv('TEMP') ) return $temp;
if( $temp=getenv('TMPDIR') ) return $temp;
$temp=tempnam(__FILE__,'');
if (file_exists($temp)) {
unlink($temp);
return dirname($temp);
}
return null;
}
}
require_once('fakedirstream.php');
// FROM search.php
new OC_Search_Provider_File();

View File

@ -182,4 +182,3 @@ class OC_CONFIG{
return true;
}
}
?>

View File

@ -38,57 +38,3 @@ class OC_CONNECT{
}
}
}
function OC_CONNECT_TEST($path,$user,$password){
echo 'connecting...';
$remote=OC_CONNECT::connect($path,$user,$password);
if($remote->connected){
echo 'done<br/>';
if($remote->isLoggedIn()){
echo 'logged in, session working<br/>';
echo 'trying to get remote files...';
$files=$remote->getFiles('');
if($files){
echo count($files).' files found:<br/>';
foreach($files as $file){
echo "{$file['type']} {$file['name']}: {$file['size']} bytes<br/>";
}
echo 'getting file "'.$file['name'].'"...';
$size=$file['size'];
$file=$remote->getFile('',$file['name']);
if(file_exists($file)){
$newSize=filesize($file);
if($size!=$newSize){
echo "fail<br/>Error: $newSize bytes received, $size expected.";
echo '<br/><br/>Recieved file:<br/>';
readfile($file);
unlink($file);
return;
}
OC_FILESYSTEM::fromTmpFile($file,'/remoteFile');
echo 'done<br/>';
echo 'sending file "burning_avatar.png"...';
$res=$remote->sendFile('','burning_avatar.png','','burning_avatar.png');
if($res){
echo 'done<br/>';
}else{
echo 'fail<br/>';
}
}else{
echo 'fail<br/>';
}
}else{
echo 'fail<br/>';
}
}else{
echo 'no longer logged in, session fail<br/>';
}
}else{
echo 'fail<br/>';
}
$remote->disconnect();
die();
}
?>

View File

@ -149,4 +149,3 @@ class OC_Connector_Sabre_Locks extends Sabre_DAV_Locks_Backend_Abstract {
}
}

View File

@ -155,4 +155,3 @@ abstract class OC_Connector_Sabre_Node implements Sabre_DAV_INode, Sabre_DAV_IPr
return $props;
}
}

View File

@ -362,4 +362,3 @@ class OC_DB {
}
}
}
?>

45
lib/fakedirstream.php Normal file
View File

@ -0,0 +1,45 @@
<?php
global $FAKEDIRS;
$FAKEDIRS=array();
class fakeDirStream{
private $name;
private $data;
private $index;
public function dir_opendir($path,$options){
global $FAKEDIRS;
$url=parse_url($path);
$this->name=substr($path,strlen('fakedir://'));
$this->index=0;
if(isset($FAKEDIRS[$this->name])){
$this->data=$FAKEDIRS[$this->name];
}else{
$this->data=array();
}
return true;
}
public function dir_readdir(){
if($this->index>=count($this->data)){
return false;
}
$filename=$this->data[$this->index];
$this->index++;
return $filename;
}
public function dir_closedir() {
$this->data=false;
$this->name='';
return true;
}
public function dir_rewinddir() {
$this->index=0;
return true;
}
}
stream_wrapper_register("fakedir", "fakeDirStream");

View File

@ -298,79 +298,3 @@ class OC_FILES {
@file_put_contents($SERVERROOT.'/.htaccess', $content); //supress errors in case we don't have permissions for it
}
}
function zipAddDir($dir,$zip,$internalDir=''){
$dirname=basename($dir);
$zip->addEmptyDir($internalDir.$dirname);
$internalDir.=$dirname.='/';
$files=OC_FILES::getdirectorycontent($dir);
foreach($files as $file){
$filename=$file['name'];
$file=$dir.'/'.$filename;
if(OC_FILESYSTEM::is_file($file)){
$tmpFile=OC_FILESYSTEM::toTmpFile($file);
OC_FILES::$tmpFiles[]=$tmpFile;
$zip->addFile($tmpFile,$internalDir.$filename);
}elseif(OC_FILESYSTEM::is_dir($file)){
zipAddDir($file,$zip,$internalDir);
}
}
}
if(!function_exists('sys_get_temp_dir')) {
function sys_get_temp_dir() {
if( $temp=getenv('TMP') ) return $temp;
if( $temp=getenv('TEMP') ) return $temp;
if( $temp=getenv('TMPDIR') ) return $temp;
$temp=tempnam(__FILE__,'');
if (file_exists($temp)) {
unlink($temp);
return dirname($temp);
}
return null;
}
}
global $FAKEDIRS;
$FAKEDIRS=array();
class fakeDirStream{
private $name;
private $data;
private $index;
public function dir_opendir($path,$options){
global $FAKEDIRS;
$url=parse_url($path);
$this->name=substr($path,strlen('fakedir://'));
$this->index=0;
if(isset($FAKEDIRS[$this->name])){
$this->data=$FAKEDIRS[$this->name];
}else{
$this->data=array();
}
return true;
}
public function dir_readdir(){
if($this->index>=count($this->data)){
return false;
}
$filename=$this->data[$this->index];
$this->index++;
return $filename;
}
public function dir_closedir() {
$this->data=false;
$this->name='';
return true;
}
public function dir_rewinddir() {
$this->index=0;
return true;
}
}
stream_wrapper_register("fakedir", "fakeDirStream");
?>

View File

@ -21,7 +21,6 @@
*
*/
class OC_FILESTORAGE_REMOTE extends OC_FILESTORAGE{
private $url;
private $username;
@ -349,5 +348,3 @@ class OC_FILESTORAGE_REMOTE extends OC_FILESTORAGE{
}
}
}
?>

View File

@ -588,4 +588,3 @@ class OC_FILESYSTEM{
}
}
?>

View File

@ -318,5 +318,3 @@ class OC_HELPER {
return false;
}
}
?>

View File

@ -149,7 +149,3 @@ class OC_LOG {
return $filteredLogs;
}
}
?>

View File

@ -78,4 +78,3 @@ return array(
'webm'=>'video/webm',
'wmv'=>'video/x-ms-asf'
);
?>

View File

@ -556,5 +556,3 @@ class OC_OCS {
return OC_PREFERENCES::deleteKey($user,$app,$key);
}
}
?>

View File

@ -160,4 +160,3 @@ class OC_OCSCLIENT{
}
?>

View File

@ -217,4 +217,3 @@ class OC_PREFERENCES{
return true;
}
}
?>

View File

@ -203,4 +203,4 @@ class OC_REMOTE_CLOUD{
return $this->apiCall('pull',array('dir'=>$targetDir,'file'=>$targetFile,'token'=>$token,'source'=>$url),true);
}
}

View File

@ -29,7 +29,7 @@ class OC_SEARCH{
/**
* register a new search provider to be used
* @param OC_SearchProvider $provider
* @param OC_Search_Provider $provider
*/
public static function registerProvider($provider){
self::$providers[]=$provider;
@ -38,7 +38,7 @@ class OC_SEARCH{
/**
* search all provider for $query
* @param string query
* @return array An array of OC_SearchResult's
* @return array An array of OC_Search_Result's
*/
public static function search($query){
$results=array();
@ -48,74 +48,3 @@ class OC_SEARCH{
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();
?>

16
lib/search/provider.php Normal file
View File

@ -0,0 +1,16 @@
<?php
/**
* provides search functionalty
*/
abstract class OC_Search_Provider{
public function __construct(){
OC_SEARCH::registerProvider($this);
}
/**
* search for $query
* @param string $query
* @return array An array of OC_Search_Result's
*/
abstract function search($query);
}

View File

@ -0,0 +1,16 @@
<?php
class OC_Search_Provider_File extends OC_Search_Provider{
function search($query){
$files=OC_FILESYSTEM::search($query);
$results=array();
foreach($files as $file){
if(OC_FILESYSTEM::is_dir($file)){
$results[]=new OC_Search_Result(basename($file),$file,OC_HELPER::linkTo( 'files', 'index.php?dir='.$file ),'Files');
}else{
$results[]=new OC_Search_Result(basename($file),$file,OC_HELPER::linkTo( 'files', 'download.php?file='.$file ),'Files');
}
}
return $results;
}
}

37
lib/search/result.php Normal file
View File

@ -0,0 +1,37 @@
<?php
/**
* a result of a search
*/
class OC_Search_Result{
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;
}
}
}

View File

@ -1,7 +1,5 @@
<?php
include_once( 'installer.php' );
$hasSQLite = (is_callable('sqlite_open') or class_exists('SQLite3'));
$hasMySQL = is_callable('mysql_connect');
$datadir = OC_CONFIG::getValue('datadir', $SERVERROOT.'/data');

View File

@ -365,5 +365,3 @@ class OC_TEMPLATE{
return $content->printPage();
}
}
?>