From 7505720350369943d4b1a8be5f3840ada424221b Mon Sep 17 00:00:00 2001 From: Robin Appelman Date: Wed, 27 Jul 2011 22:44:51 +0200 Subject: [PATCH 1/6] fix log when no tablename prefix is used --- lib/log.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/log.php b/lib/log.php index 894575ef05..764c094c91 100644 --- a/lib/log.php +++ b/lib/log.php @@ -51,7 +51,7 @@ class OC_LOG { * This function adds another entry to the log database */ 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)); // Die if we have an error if( PEAR::isError($result)) { @@ -79,7 +79,7 @@ class OC_LOG { * - app: only entries for this app */ 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(); if(isset($filter['from'])){ $queryString.='AND moment>? '; @@ -116,7 +116,7 @@ class OC_LOG { * This function deletes all entries that are older than $date. */ public static function deleteBefore( $date ){ - $query=OC_DB::prepare("DELETE FROM *PREFIX*log WHERE momentexecute(array($date)); return true; } @@ -128,7 +128,7 @@ class OC_LOG { * This function deletes all log entries. */ public static function deleteAll(){ - $query=OC_DB::prepare("DELETE FROM *PREFIX*log"); + $query=OC_DB::prepare("DELETE FROM `*PREFIX*log`"); $query->execute(); return true; } From 0d408fe6f540161b9367d7b6abb93965139898a4 Mon Sep 17 00:00:00 2001 From: Robin Appelman Date: Thu, 28 Jul 2011 20:10:58 +0200 Subject: [PATCH 2/6] make use of the command line tools id3info and mp3info for scanning music if they are available --- apps/media/lib_scanner.php | 99 ++++++++++++++++++++++++++------------ lib/filestorage.php | 58 +--------------------- lib/helper.php | 45 +++++++++++++++++ 3 files changed, 115 insertions(+), 87 deletions(-) diff --git a/apps/media/lib_scanner.php b/apps/media/lib_scanner.php index aa0ca94a43..296acbdbaa 100644 --- a/apps/media/lib_scanner.php +++ b/apps/media/lib_scanner.php @@ -68,40 +68,79 @@ class OC_MEDIA_SCANNER{ * @return boolean */ public static function scanFile($path){ - if(!self::$getID3){ - self::$getID3=@new getID3(); - } $file=OC_FILESYSTEM::getLocalFile($path); - $data=@self::$getID3->analyze($file); - getid3_lib::CopyTagsToComments($data); - if(!isset($data['comments'])){ - error_log("error reading id3 tags in '$file'"); - return; - } - if(!isset($data['comments']['artist'])){ - error_log("error reading artist tag in '$file'"); - $artist='unknown'; - }else{ - $artist=stripslashes($data['comments']['artist'][0]); - $artist=utf8_encode($artist); - } - if(!isset($data['comments']['album'])){ - error_log("error reading album tag in '$file'"); - $album='unknown'; - }else{ - $album=stripslashes($data['comments']['album'][0]); - $album=utf8_encode($album); - } - if(!isset($data['comments']['title'])){ - error_log("error reading title tag in '$file'"); + 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{ - $title=stripslashes($data['comments']['title'][0]); - $title=utf8_encode($title); + if(!self::$getID3){ + self::$getID3=@new getID3(); + } + $data=@self::$getID3->analyze($file); + getid3_lib::CopyTagsToComments($data); + if(!isset($data['comments'])){ + error_log("error reading id3 tags in '$file'"); + return; + } + if(!isset($data['comments']['artist'])){ + error_log("error reading artist tag in '$file'"); + $artist='unknown'; + }else{ + $artist=stripslashes($data['comments']['artist'][0]); + $artist=utf8_encode($artist); + } + if(!isset($data['comments']['album'])){ + error_log("error reading album tag in '$file'"); + $album='unknown'; + }else{ + $album=stripslashes($data['comments']['album'][0]); + $album=utf8_encode($album); + } + if(!isset($data['comments']['title'])){ + error_log("error reading title tag in '$file'"); + $title='unknown'; + }else{ + $title=stripslashes($data['comments']['title'][0]); + $title=utf8_encode($title); + } + $size=$data['filesize']; + $track=(isset($data['comments']['track']))?$data['comments']['track'][0]:0; + $length=round($data['playtime_seconds']); } - $size=$data['filesize']; - $track=(isset($data['comments']['track']))?$data['comments']['track'][0]:0; - $length=round($data['playtime_seconds']); if(!isset(self::$artists[$artist])){ $artistId=OC_MEDIA_COLLECTION::addArtist($artist); self::$artists[$artist]=$artistId; diff --git a/lib/filestorage.php b/lib/filestorage.php index 95e8c31eff..601cf6f37f 100644 --- a/lib/filestorage.php +++ b/lib/filestorage.php @@ -200,7 +200,7 @@ class OC_FILESTORAGE_LOCAL extends OC_FILESTORAGE{ } else if (function_exists("mime_content_type")) { // use mime magic extension if available $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, // lets see it it does have mime support $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){ $tmpFolder=sys_get_temp_dir(); $filename=tempnam($tmpFolder,'OC_TEMP_FILE_'.substr($path,strrpos($path,'.'))); diff --git a/lib/helper.php b/lib/helper.php index 96d5bfad82..1fbcc589d1 100755 --- a/lib/helper.php +++ b/lib/helper.php @@ -267,6 +267,51 @@ class OC_HELPER { if((isset($_REQUEST[$s]) && $_REQUEST[$s]==$v) || $v == $d) 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; + } } ?> From aa33812104d37bd6d7e7de5b1cebdfb63f5ae9d0 Mon Sep 17 00:00:00 2001 From: Robin Appelman Date: Thu, 28 Jul 2011 20:12:07 +0200 Subject: [PATCH 3/6] hopefully fix some issues with the openid server --- apps/user_openid/phpmyid.php | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/apps/user_openid/phpmyid.php b/apps/user_openid/phpmyid.php index 146eb380f7..bc2950982f 100644 --- a/apps/user_openid/phpmyid.php +++ b/apps/user_openid/phpmyid.php @@ -329,27 +329,27 @@ function checkid ( $wait ) { user_session(); // 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'] - : error_400('Missing return1_to'); + : error_400('Missing return_to'); - $identity = @strlen($_REQUEST['openid_identity']) + $identity = isset($_REQUEST['openid_identity']) ? $_REQUEST['openid_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'] : null; - $trust_root = @strlen($_REQUEST['openid_trust_root']) + $trust_root = isset($_REQUEST['openid_trust_root']) ? $_REQUEST['openid_trust_root'] : $return_to; - $sreg_required = @strlen($_REQUEST['openid_sreg_required']) + $sreg_required = isset($_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'] : ''; From 7d15a45e09bfa27597a1169e12ba79b6e5221946 Mon Sep 17 00:00:00 2001 From: Robin Appelman Date: Thu, 28 Jul 2011 20:23:58 +0200 Subject: [PATCH 4/6] use oc_preferences to store ocs privatedata --- lib/ocs.php | 76 +++++++++++++---------------------------------------- 1 file changed, 18 insertions(+), 58 deletions(-) diff --git a/lib/ocs.php b/lib/ocs.php index 4e9e6522e8..b1be2cb11c 100644 --- a/lib/ocs.php +++ b/lib/ocs.php @@ -463,7 +463,6 @@ class OC_OCS { $xml[$i]['key']=$log['key']; $xml[$i]['app']=$log['app']; $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 * @return array */ - public static function getData($user,$app="",$key="",$like=false) { - $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':'='; - + public static function getData($user,$app="",$key="") { if($app){ - if (!trim($key)) { - $query = OC_DB::prepare('select app, `key`,value,`timestamp` from *PREFIX*privatedata where app=? order by `timestamp` desc'); - $result=$query->execute(array($app))->fetchAll(); - } 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(); - } + $apps=array($app); }else{ - if (!trim($key)) { - $query = OC_DB::prepare('select app, `key`,value,`timestamp` from *PREFIX*privatedata order by `timestamp` desc'); - $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=$query->execute(array($key))->fetchAll(); + $apps=OC_PREFERENCES::getApps($user); + } + if($key){ + $keys=array($key); + }else{ + foreach($apps as $app){ + $keys=OC_PREFERENCES::getKeys($user,$app); + } + } + $result=array(); + 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; } @@ -545,25 +542,7 @@ class OC_OCS { * @return bool */ public static function setData($user, $app, $key, $value) { - $key="$user::$key";//ugly hack for the sake of keeping database scheme compatibiliy - //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().'"
'; - error_log($entry); - return false; - }else{ - return true; - } + return OC_PREFERENCES::setValue($user,$app,$key,$value); } /** @@ -574,26 +553,7 @@ class OC_OCS { * @return string xml/json */ public static function deleteData($user, $app, $key) { - $key="$user::$key";//ugly hack for the sake of keeping database scheme compatibiliy - //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().'"
'; - 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; + return OC_PREFERENCES::deleteKey($user,$app,$key); } } From bc51425bb753d7a5adffe707053b6186a4de7bba Mon Sep 17 00:00:00 2001 From: Robin Appelman Date: Thu, 28 Jul 2011 20:59:36 +0200 Subject: [PATCH 5/6] keep track of playcount as last played time of music files --- apps/media/ajax/api.php | 3 +++ apps/media/appinfo/database.xml | 18 ++++++++++++++++++ apps/media/lib_collection.php | 28 +++++++++++++++++++++++++++- 3 files changed, 48 insertions(+), 1 deletion(-) diff --git a/apps/media/ajax/api.php b/apps/media/ajax/api.php index 0ccfb63f41..84d5dd1788 100644 --- a/apps/media/ajax/api.php +++ b/apps/media/ajax/api.php @@ -105,6 +105,9 @@ if($arguments['action']){ $ftype=OC_FILESYSTEM::getMimeType( $arguments['path'] ); + $songId=OC_MEDIA_COLLECTION::getSongByPath($arguments['path']); + OC_MEDIA_COLLECTION::registerPlay($songId); + header('Content-Type:'.$ftype); header('Expires: 0'); header('Cache-Control: must-revalidate, post-check=0, pre-check=0'); diff --git a/apps/media/appinfo/database.xml b/apps/media/appinfo/database.xml index 91fa1f9e2a..223682fcfc 100644 --- a/apps/media/appinfo/database.xml +++ b/apps/media/appinfo/database.xml @@ -206,6 +206,24 @@ 4 + + song_playcount + integer + + + true + 4 + + + + song_lastplayed + integer + + + true + 4 + + diff --git a/apps/media/lib_collection.php b/apps/media/lib_collection.php index 6e2011675a..278e450b77 100644 --- a/apps/media/lib_collection.php +++ b/apps/media/lib_collection.php @@ -270,7 +270,8 @@ class OC_MEDIA_COLLECTION{ if($songId!=0){ return $songId; }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)); $songId=OC_DB::insertid(); // self::setLastUpdated(); @@ -346,6 +347,31 @@ class OC_MEDIA_COLLECTION{ $query=OC_DB::prepare("DELETE FROM *PREFIX*media_songs WHERE song_path LIKE ?"); $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_lastplayedexecute(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; + } + } } ?> \ No newline at end of file From 5728f801161ae0ee25113581157a26b1b63cd9ff Mon Sep 17 00:00:00 2001 From: Robin Appelman Date: Thu, 28 Jul 2011 21:05:49 +0200 Subject: [PATCH 6/6] remove dummy settings --- admin/appinfo/app.php | 2 +- files/templates/admin.php | 8 +++++--- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/admin/appinfo/app.php b/admin/appinfo/app.php index b78d698e50..7ce784cfb9 100644 --- a/admin/appinfo/app.php +++ b/admin/appinfo/app.php @@ -2,7 +2,7 @@ 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_apps", "order" => 3, "href" => OC_HELPER::linkTo( "admin", "apps.php?installed" ), "name" => "Apps", "icon" => OC_HELPER::imagePath( "admin", "apps.png" ))); diff --git a/files/templates/admin.php b/files/templates/admin.php index ff331f860e..40880d3491 100644 --- a/files/templates/admin.php +++ b/files/templates/admin.php @@ -3,8 +3,11 @@
'/>
+ + + No settings currently available. -
+