Merge branch 'master' into interface

remotes/origin/stable
Jan-Christoph Borchardt 14 years ago
commit ba246d3b27
  1. 2
      admin/appinfo/app.php
  2. 3
      apps/media/ajax/api.php
  3. 18
      apps/media/appinfo/database.xml
  4. 28
      apps/media/lib_collection.php
  5. 41
      apps/media/lib_scanner.php
  6. 14
      apps/user_openid/phpmyid.php
  7. 8
      files/templates/admin.php
  8. 58
      lib/filestorage.php
  9. 45
      lib/helper.php
  10. 8
      lib/log.php
  11. 74
      lib/ocs.php

@ -2,7 +2,7 @@
OC_APP::register( array( "order" => 1, "id" => "admin", "name" => "Administration" )); OC_APP::register( array( "order" => 1, "id" => "admin", "name" => "Administration" ));
OC_APP::addAdminPage( array( "id" => "core_system", "order" => 1, "href" => OC_HELPER::linkTo( "admin", "system.php" ), "name" =>"System", "icon" => OC_HELPER::imagePath( "admin", "administration.png" ))); // OC_APP::addAdminPage( array( "id" => "core_system", "order" => 1, "href" => OC_HELPER::linkTo( "admin", "system.php" ), "name" =>"System", "icon" => OC_HELPER::imagePath( "admin", "administration.png" )));
OC_APP::addAdminPage( array( "id" => "core_users", "order" => 2, "href" => OC_HELPER::linkTo( "admin", "users.php" ), "name" => "Users", "icon" => OC_HELPER::imagePath( "admin", "users.png" ))); OC_APP::addAdminPage( array( "id" => "core_users", "order" => 2, "href" => OC_HELPER::linkTo( "admin", "users.php" ), "name" => "Users", "icon" => OC_HELPER::imagePath( "admin", "users.png" )));
OC_APP::addAdminPage( array( "id" => "core_apps", "order" => 3, "href" => OC_HELPER::linkTo( "admin", "apps.php?installed" ), "name" => "Apps", "icon" => OC_HELPER::imagePath( "admin", "apps.png" ))); OC_APP::addAdminPage( array( "id" => "core_apps", "order" => 3, "href" => OC_HELPER::linkTo( "admin", "apps.php?installed" ), "name" => "Apps", "icon" => OC_HELPER::imagePath( "admin", "apps.png" )));

@ -105,6 +105,9 @@ if($arguments['action']){
$ftype=OC_FILESYSTEM::getMimeType( $arguments['path'] ); $ftype=OC_FILESYSTEM::getMimeType( $arguments['path'] );
$songId=OC_MEDIA_COLLECTION::getSongByPath($arguments['path']);
OC_MEDIA_COLLECTION::registerPlay($songId);
header('Content-Type:'.$ftype); header('Content-Type:'.$ftype);
header('Expires: 0'); header('Expires: 0');
header('Cache-Control: must-revalidate, post-check=0, pre-check=0'); header('Cache-Control: must-revalidate, post-check=0, pre-check=0');

@ -206,6 +206,24 @@
<length>4</length> <length>4</length>
</field> </field>
<field>
<name>song_playcount</name>
<type>integer</type>
<default>
</default>
<notnull>true</notnull>
<length>4</length>
</field>
<field>
<name>song_lastplayed</name>
<type>integer</type>
<default>
</default>
<notnull>true</notnull>
<length>4</length>
</field>
</declaration> </declaration>
</table> </table>

@ -270,7 +270,8 @@ class OC_MEDIA_COLLECTION{
if($songId!=0){ if($songId!=0){
return $songId; return $songId;
}else{ }else{
$query=OC_DB::prepare("INSERT INTO `*PREFIX*media_songs` (`song_id` ,`song_name` ,`song_artist` ,`song_album` ,`song_path` ,`song_user`,`song_length`,`song_track`,`song_size`) VALUES (NULL , ?, ?, ?, ?,?,?,?,?)"); $query=OC_DB::prepare("INSERT INTO `*PREFIX*media_songs` (`song_id` ,`song_name` ,`song_artist` ,`song_album` ,`song_path` ,`song_user`,`song_length`,`song_track`,`song_size`,`song_playcount`,`song_lastplayed`)
VALUES (NULL , ?, ?, ?, ?,?,?,?,?,0,0)");
$query->execute(array($name,$artist,$album,$path,$uid,$length,$track,$size)); $query->execute(array($name,$artist,$album,$path,$uid,$length,$track,$size));
$songId=OC_DB::insertid(); $songId=OC_DB::insertid();
// self::setLastUpdated(); // self::setLastUpdated();
@ -346,6 +347,31 @@ class OC_MEDIA_COLLECTION{
$query=OC_DB::prepare("DELETE FROM *PREFIX*media_songs WHERE song_path LIKE ?"); $query=OC_DB::prepare("DELETE FROM *PREFIX*media_songs WHERE song_path LIKE ?");
$query->execute(array("$path%")); $query->execute(array("$path%"));
} }
/**
* increase the play count of a song
* @param int songId
*/
public static function registerPlay($songId){
$now=time();
$query=OC_DB::prepare('UPDATE *PREFIX*media_songs SET song_playcount=song_playcount+1, song_lastplayed=? WHERE song_id=? AND song_lastplayed<?');
$query->execute(array($now,$songId,$now-60));
}
/**
* get the id of the song by path
* @param string $path
* @return int
*/
public static function getSongByPath($path){
$query=OC_DB::prepare("SELECT song_id FROM *PREFIX*media_songs WHERE song_path = ?");
$result=$query->execute(array($path))->fetchAll();
if(count($result)>0){
return $result[0]['song_id'];
}else{
return 0;
}
}
} }
?> ?>

@ -68,10 +68,48 @@ class OC_MEDIA_SCANNER{
* @return boolean * @return boolean
*/ */
public static function scanFile($path){ public static function scanFile($path){
$file=OC_FILESYSTEM::getLocalFile($path);
if(substr($path,-3)=='mp3' and OC_HELPER::canExecute("id3info") and OC_HELPER::canExecute("mp3info")){//use the command line tool id3info if possible
$output=array();
$size=filesize($file);
$length=0;
$title='unknown';
$album='unknown';
$artist='unknown';
$track=0;
exec('id3info "'.$file.'"',$output);
$data=array();
foreach($output as $line) {
switch(substr($line,0,3)){
case '***'://comments
break;
case '==='://tag information
$key=substr($line,4,4);
$value=substr($line,strpos($line,':')+2);
switch(strtolower($key)){
case 'tit1':
case 'tit2':
$title=$value;
break;
case 'tpe1':
case 'tpe2':
$artist=$value;
break;
case 'talb':
$album=$value;
break;
case 'trck':
$track=$value;
break;
}
break;
}
}
$length=exec('mp3info -p "%S" "'.$file.'"');
}else{
if(!self::$getID3){ if(!self::$getID3){
self::$getID3=@new getID3(); self::$getID3=@new getID3();
} }
$file=OC_FILESYSTEM::getLocalFile($path);
$data=@self::$getID3->analyze($file); $data=@self::$getID3->analyze($file);
getid3_lib::CopyTagsToComments($data); getid3_lib::CopyTagsToComments($data);
if(!isset($data['comments'])){ if(!isset($data['comments'])){
@ -102,6 +140,7 @@ class OC_MEDIA_SCANNER{
$size=$data['filesize']; $size=$data['filesize'];
$track=(isset($data['comments']['track']))?$data['comments']['track'][0]:0; $track=(isset($data['comments']['track']))?$data['comments']['track'][0]:0;
$length=round($data['playtime_seconds']); $length=round($data['playtime_seconds']);
}
if(!isset(self::$artists[$artist])){ if(!isset(self::$artists[$artist])){
$artistId=OC_MEDIA_COLLECTION::addArtist($artist); $artistId=OC_MEDIA_COLLECTION::addArtist($artist);
self::$artists[$artist]=$artistId; self::$artists[$artist]=$artistId;

@ -329,27 +329,27 @@ function checkid ( $wait ) {
user_session(); user_session();
// Get the options, use defaults as necessary // Get the options, use defaults as necessary
$return_to = @strlen($_REQUEST['openid_return_to']) $return_to = isset($_REQUEST['openid_return_to'])
? $_REQUEST['openid_return_to'] ? $_REQUEST['openid_return_to']
: error_400('Missing return1_to'); : error_400('Missing return_to');
$identity = @strlen($_REQUEST['openid_identity']) $identity = isset($_REQUEST['openid_identity'])
? $_REQUEST['openid_identity'] ? $_REQUEST['openid_identity']
: error_get($return_to, 'Missing identity'); : error_get($return_to, 'Missing identity');
$assoc_handle = @strlen($_REQUEST['openid_assoc_handle']) $assoc_handle = isset($_REQUEST['openid_assoc_handle'])
? $_REQUEST['openid_assoc_handle'] ? $_REQUEST['openid_assoc_handle']
: null; : null;
$trust_root = @strlen($_REQUEST['openid_trust_root']) $trust_root = isset($_REQUEST['openid_trust_root'])
? $_REQUEST['openid_trust_root'] ? $_REQUEST['openid_trust_root']
: $return_to; : $return_to;
$sreg_required = @strlen($_REQUEST['openid_sreg_required']) $sreg_required = isset($_REQUEST['openid_sreg_required'])
? $_REQUEST['openid_sreg.required'] ? $_REQUEST['openid_sreg.required']
: ''; : '';
$sreg_optional = @strlen($_REQUEST['openid_sreg_optional']) $sreg_optional = isset($_REQUEST['openid_sreg_optional'])
? $_REQUEST['openid_sreg.optional'] ? $_REQUEST['openid_sreg.optional']
: ''; : '';

@ -3,8 +3,11 @@
<form name="filesForm" action='#' method='post'> <form name="filesForm" action='#' method='post'>
<?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/>
<input type='submit' value='Save'/>
<?php else:?>
No settings currently available.
<?php endif;?> <?php endif;?>
<input type="checkbox" name="publicEnable" id="publicEnable" /><label for="publicEnable"> <?php echo $l->t( 'Allow public folders' ); ?></label><br> <!-- <input type="checkbox" name="publicEnable" id="publicEnable" /><label for="publicEnable"> <?php echo $l->t( 'Allow public folders' ); ?></label><br>
<div style="padding-left: 20px"> <div style="padding-left: 20px">
<input type="radio" name="sharingaim" id="separated" /><label for="separated"> <?php echo $l->t( 'separated from webdav storage' ); ?></label><br> <input type="radio" name="sharingaim" id="separated" /><label for="separated"> <?php echo $l->t( 'separated from webdav storage' ); ?></label><br>
@ -13,6 +16,5 @@
</div> </div>
<input type="checkbox" id="downloadShared" /><label for="downloadShared"> <?php echo $l->t( 'Allow downloading shared files' ); ?></label><br> <input type="checkbox" id="downloadShared" /><label for="downloadShared"> <?php echo $l->t( 'Allow downloading shared files' ); ?></label><br>
<input type="checkbox" id="uploadShared" /><label for="uploadShared"> <?php echo $l->t( 'Allow uploading in shared directory' ); ?></label><br> <input type="checkbox" id="uploadShared" /><label for="uploadShared"> <?php echo $l->t( 'Allow uploading in shared directory' ); ?></label><br>-->
<input type='submit' value='Save'/>
</form> </form>

@ -200,7 +200,7 @@ class OC_FILESTORAGE_LOCAL extends OC_FILESTORAGE{
} else if (function_exists("mime_content_type")) { } else if (function_exists("mime_content_type")) {
// use mime magic extension if available // use mime magic extension if available
$mime_type = mime_content_type($this->datadir.$fspath); $mime_type = mime_content_type($this->datadir.$fspath);
} else if (self::canExecute("file")) { } else if (OC_HELPER::canExecute("file")) {
// it looks like we have a 'file' command, // it looks like we have a 'file' command,
// lets see it it does have mime support // lets see it it does have mime support
$fp = popen("file -i -b '{$this->datadir}$fspath' 2>/dev/null", "r"); $fp = popen("file -i -b '{$this->datadir}$fspath' 2>/dev/null", "r");
@ -223,62 +223,6 @@ class OC_FILESTORAGE_LOCAL extends OC_FILESTORAGE{
} }
} }
/**
* detect if a given program is found in the search PATH
*
* helper function used by _mimetype() to detect if the
* external 'file' utility is available
*
* @param string program name
* @param string optional search path, defaults to $PATH
* @return bool true if executable program found in path
*/
private function canExecute($name, $path = false)
{
// path defaults to PATH from environment if not set
if ($path === false) {
$path = getenv("PATH");
}
// check method depends on operating system
if (!strncmp(PHP_OS, "WIN", 3)) {
// on Windows an appropriate COM or EXE file needs to exist
$exts = array(".exe", ".com");
$check_fn = "file_exists";
} else {
// anywhere else we look for an executable file of that name
$exts = array("");
$check_fn = "is_executable";
}
// Default check will be done with $path directories :
$dirs = explode(PATH_SEPARATOR, $path);
// WARNING : We have to check if open_basedir is enabled :
$obd = ini_get('open_basedir');
if($obd != "none")
$obd_values = explode(PATH_SEPARATOR, $obd);
if(count($obd_values) > 0)
{
// open_basedir is in effect !
// We need to check if the program is in one of these dirs :
$dirs = $obd_values;
}
foreach($dirs as $dir)
{
foreach($exts as $ext)
{
if($check_fn("$dir/$name".$ext))
return true;
}
}
return false;
}
public function toTmpFile($path){ public function toTmpFile($path){
$tmpFolder=sys_get_temp_dir(); $tmpFolder=sys_get_temp_dir();
$filename=tempnam($tmpFolder,'OC_TEMP_FILE_'.substr($path,strrpos($path,'.'))); $filename=tempnam($tmpFolder,'OC_TEMP_FILE_'.substr($path,strrpos($path,'.')));

@ -267,6 +267,51 @@ class OC_HELPER {
if((isset($_REQUEST[$s]) && $_REQUEST[$s]==$v) || $v == $d) if((isset($_REQUEST[$s]) && $_REQUEST[$s]==$v) || $v == $d)
print "checked=\"checked\" "; print "checked=\"checked\" ";
} }
/**
* detect if a given program is found in the search PATH
*
* @param string program name
* @param string optional search path, defaults to $PATH
* @return bool true if executable program found in path
*/
public static function canExecute($name, $path = false){
// path defaults to PATH from environment if not set
if ($path === false) {
$path = getenv("PATH");
}
// check method depends on operating system
if (!strncmp(PHP_OS, "WIN", 3)) {
// on Windows an appropriate COM or EXE file needs to exist
$exts = array(".exe", ".com");
$check_fn = "file_exists";
} else {
// anywhere else we look for an executable file of that name
$exts = array("");
$check_fn = "is_executable";
}
// Default check will be done with $path directories :
$dirs = explode(PATH_SEPARATOR, $path);
// WARNING : We have to check if open_basedir is enabled :
$obd = ini_get('open_basedir');
if($obd != "none")
$obd_values = explode(PATH_SEPARATOR, $obd);
if(count($obd_values) > 0 and $obd_values[0])
{
// open_basedir is in effect !
// We need to check if the program is in one of these dirs :
$dirs = $obd_values;
}
foreach($dirs as $dir)
{
foreach($exts as $ext)
{
if($check_fn("$dir/$name".$ext))
return true;
}
}
return false;
}
} }
?> ?>

@ -51,7 +51,7 @@ class OC_LOG {
* This function adds another entry to the log database * This function adds another entry to the log database
*/ */
public static function add( $appid, $subject, $predicate, $object = ' ' ){ public static function add( $appid, $subject, $predicate, $object = ' ' ){
$query=OC_DB::prepare("INSERT INTO *PREFIX*log(moment,appid,user,action,info) VALUES(NOW(),?,?,?,?)"); $query=OC_DB::prepare("INSERT INTO `*PREFIX*log`(moment,appid,user,action,info) VALUES(NOW(),?,?,?,?)");
$result=$query->execute(array($appid,$subject,$predicate,$object)); $result=$query->execute(array($appid,$subject,$predicate,$object));
// Die if we have an error // Die if we have an error
if( PEAR::isError($result)) { if( PEAR::isError($result)) {
@ -79,7 +79,7 @@ class OC_LOG {
* - app: only entries for this app * - app: only entries for this app
*/ */
public static function get( $filter = array()){ public static function get( $filter = array()){
$queryString='SELECT * FROM *PREFIX*log WHERE 1=1 ORDER BY moment DESC'; $queryString='SELECT * FROM `*PREFIX*log` WHERE 1=1 ORDER BY moment DESC';
$params=array(); $params=array();
if(isset($filter['from'])){ if(isset($filter['from'])){
$queryString.='AND moment>? '; $queryString.='AND moment>? ';
@ -116,7 +116,7 @@ class OC_LOG {
* This function deletes all entries that are older than $date. * This function deletes all entries that are older than $date.
*/ */
public static function deleteBefore( $date ){ public static function deleteBefore( $date ){
$query=OC_DB::prepare("DELETE FROM *PREFIX*log WHERE moment<?"); $query=OC_DB::prepare("DELETE FROM `*PREFIX*log` WHERE moment<?");
$query->execute(array($date)); $query->execute(array($date));
return true; return true;
} }
@ -128,7 +128,7 @@ class OC_LOG {
* This function deletes all log entries. * This function deletes all log entries.
*/ */
public static function deleteAll(){ public static function deleteAll(){
$query=OC_DB::prepare("DELETE FROM *PREFIX*log"); $query=OC_DB::prepare("DELETE FROM `*PREFIX*log`");
$query->execute(); $query->execute();
return true; return true;
} }

@ -463,7 +463,6 @@ class OC_OCS {
$xml[$i]['key']=$log['key']; $xml[$i]['key']=$log['key'];
$xml[$i]['app']=$log['app']; $xml[$i]['app']=$log['app'];
$xml[$i]['value']=$log['value']; $xml[$i]['value']=$log['value'];
$xml[$i]['timestamp']=$log['timestamp'];
} }
@ -511,28 +510,26 @@ class OC_OCS {
* @param bool $like use LIKE instead of = when comparing keys * @param bool $like use LIKE instead of = when comparing keys
* @return array * @return array
*/ */
public static function getData($user,$app="",$key="",$like=false) { public static function getData($user,$app="",$key="") {
$key="$user::$key";//ugly hack for the sake of keeping database scheme compatibiliy, needs to be replaced with a seperate user field the next time we break db compatibiliy
$compareFunction=($like)?'LIKE':'=';
if($app){ if($app){
if (!trim($key)) { $apps=array($app);
$query = OC_DB::prepare('select app, `key`,value,`timestamp` from *PREFIX*privatedata where app=? order by `timestamp` desc'); }else{
$result=$query->execute(array($app))->fetchAll(); $apps=OC_PREFERENCES::getApps($user);
} else {
$query = OC_DB::prepare("select app, `key`,value,`timestamp` from *PREFIX*privatedata where app=? and `key` $compareFunction ? order by `timestamp` desc");
$result=$query->execute(array($app,$key))->fetchAll();
} }
if($key){
$keys=array($key);
}else{ }else{
if (!trim($key)) { foreach($apps as $app){
$query = OC_DB::prepare('select app, `key`,value,`timestamp` from *PREFIX*privatedata order by `timestamp` desc'); $keys=OC_PREFERENCES::getKeys($user,$app);
$result=$query->execute()->fetchAll(); }
} else { }
$query = OC_DB::prepare("select app, `key`,value,`timestamp` from *PREFIX*privatedata where `key` $compareFunction ? order by `timestamp` desc"); $result=array();
$result=$query->execute(array($key))->fetchAll(); foreach($apps as $app){
foreach($keys as $key){
$value=OC_PREFERENCES::getValue($user,$app,$key);
$result[]=array('app'=>$app,'key'=>$key,'value'=>$value);
} }
} }
$result=self::trimKeys($result,$user);
return $result; return $result;
} }
@ -545,25 +542,7 @@ class OC_OCS {
* @return bool * @return bool
*/ */
public static function setData($user, $app, $key, $value) { public static function setData($user, $app, $key, $value) {
$key="$user::$key";//ugly hack for the sake of keeping database scheme compatibiliy return OC_PREFERENCES::setValue($user,$app,$key,$value);
//TODO: locking tables, fancy stuff, error checking/handling
$query=OC_DB::prepare("select count(*) as co from *PREFIX*privatedata where `key` = ? and app = ?");
$result=$query->execute(array($key,$app))->fetchAll();
$totalcount=$result[0]['co'];
if ($totalcount != 0) {
$query=OC_DB::prepare("update *PREFIX*privatedata set value=?, `timestamp` = now() where `key` = ? and app = ?");
} else {
$result = OC_DB::prepare("insert into *PREFIX*privatedata(value, `key`, app, `timestamp`) values(?, ?, ?, now())");
}
$result = $query->execute(array($value,$key,$app));
if (PEAR::isError($result)){
$entry='DB Error: "'.$result->getMessage().'"<br />';
error_log($entry);
return false;
}else{
return true;
}
} }
/** /**
@ -574,26 +553,7 @@ class OC_OCS {
* @return string xml/json * @return string xml/json
*/ */
public static function deleteData($user, $app, $key) { public static function deleteData($user, $app, $key) {
$key="$user::$key";//ugly hack for the sake of keeping database scheme compatibiliy return OC_PREFERENCES::deleteKey($user,$app,$key);
//TODO: prepared statements, locking tables, fancy stuff, error checking/handling
$query=OC_DB::prepare("delete from *PREFIX*privatedata where `key` = ? and app = ?");
$result = $query->execute(array($key,$app));
if (PEAR::isError($result)){
$entry='DB Error: "'.$result->getMessage().'"<br />';
error_log($entry);
return false;
}else{
return true;
}
}
//trim username prefixes from $array
private static function trimKeys($array,$user){
$length=strlen("$user::");
foreach($array as &$item){
$item['key']=substr($item['key'],$length);
}
return $array;
} }
} }

Loading…
Cancel
Save