1
0
Fork 0
mirror of https://github.com/Yetangitu/ampache synced 2025-10-04 10:19:25 +02:00

fixed a long standing browsing issue where you could not browse two different things at the same time

This commit is contained in:
Karl 'vollmerk' Vollmer 2008-08-08 05:15:34 +00:00
parent dda0815b08
commit 73e70d7d99
6 changed files with 89 additions and 20 deletions

View file

@ -4,6 +4,8 @@
-------------------------------------------------------------------------- --------------------------------------------------------------------------
v.3.5-Alpha1 v.3.5-Alpha1
- Fixed browsing so that you can browse two different types in two
windows at the same time
- Improved gather script for translations (Thx momo-i) - Improved gather script for translations (Thx momo-i)
- Added paging to the localplay playlist - Added paging to the localplay playlist
- Updated German Translation (Thx Laurent) - Updated German Translation (Thx Laurent)

View file

@ -40,6 +40,7 @@ class Browse {
// Static Content, this is defaulted to false, if set to true then wen can't // Static Content, this is defaulted to false, if set to true then wen can't
// apply any filters that would change the result set. // apply any filters that would change the result set.
public static $static_content = false; public static $static_content = false;
private static $_cache = array();
/** /**
@ -215,6 +216,16 @@ class Browse {
} // end type whitelist } // end type whitelist
} // set_type } // set_type
/**
* get_type
* This returns the type of the browse we currently are using
*/
public static function get_type() {
return self::$type;
} // get_type
/** /**
* set_sort * set_sort
* This sets the current sort(s) * This sets the current sort(s)
@ -341,7 +352,20 @@ class Browse {
*/ */
public static function get_saved() { public static function get_saved() {
$objects = $_SESSION['browse']['save'][self::$type]; // See if we have it in the local cache first
if (is_array(self::$_cache['browse'][self::$type])) {
return self::$_cache['browse'][self::$type];
}
// If not then we're going to need to read from the database :(
$sid = session_id() . '::' . self::$type;
$sql = "SELECT `data` FROM `tmp_browse` WHERE `sid`='$sid'";
$db_results = Dba::read($sql);
$row = Dba::fetch_assoc($db_results);
$objects = unserialize($row['data']);
return $objects; return $objects;
@ -900,8 +924,17 @@ class Browse {
*/ */
public static function save_objects($object_ids) { public static function save_objects($object_ids) {
// save these objects // Saving these objects has two operations, one hold it in
$_SESSION['browse']['save'][self::$type] = $object_ids; // a local variable and then second hold it in a row in the tmp_browse
// table
self::$_cache['browse'][self::$type] = $object_ids;
$sid = session_id() . '::' . self::$type;
$data = Dba::escape(serialize($object_ids));
$sql = "REPLACE INTO `tmp_browse` SET `data`='$data', `sid`='$sid'";
$db_results = Dba::write($sql);
self::$total_objects = count($object_ids); self::$total_objects = count($object_ids);
return true; return true;
@ -974,7 +1007,6 @@ class Browse {
self::$simple_browse = make_bool($_SESSION['browse']['simple']); self::$simple_browse = make_bool($_SESSION['browse']['simple']);
self::$static_content = make_bool($_SESSION['browse']['static']); self::$static_content = make_bool($_SESSION['browse']['static']);
self::$type = $_SESSION['browse']['type'];
self::$start = intval($_SESSION['browse'][self::$type]['start']); self::$start = intval($_SESSION['browse'][self::$type]['start']);
} // _auto_init } // _auto_init

View file

@ -284,7 +284,9 @@ class Update {
$update_string = '- Remove Genre Field from song table.<br />' . $update_string = '- Remove Genre Field from song table.<br />' .
'- Add user_catalog table for tracking user<-->catalog mappings.<br />' . '- Add user_catalog table for tracking user<-->catalog mappings.<br />' .
'- Alter user table to handle SHA2 passwords.<br />'; '- Add tmp_browse to handle caching rather then session table.<br />';
$version[] = array('version' => '350002','description'=>$update_string);
return $version; return $version;
@ -1365,5 +1367,36 @@ class Update {
} // update_350001 } // update_350001
/**
* update_350002
* This update adds in the browse_cache table that we use to hold peoples cached browse results
* rather then try to store everything in the session we split them out into one serilized array per
* row, per person. A little slow this way when browsing, but faster when now browsing and more flexible
*/
public static function update_350002() {
$sql = "CREATE TABLE `tmp_browse` (`sid` varchar(128) collate utf8_unicode_ci NOT NULL,`data` longtext collate utf8_unicode_ci NOT NULL," .
" UNIQUE KEY `sid` (`sid`)) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci";
$db_results = Dba::write($sql);
$sql = "ALTER TABLE `tmp_browse` ADD INDEX ( `type` )";
$db_results = Dba::write($sql);
$sql = "ALTER TABLE `song` DROP `genre`";
$db_results = Dba::write($sql);
$sql = "CREATE TABLE `user_catalog` (`user` INT( 11 ) UNSIGNED NOT NULL ,`catalog` INT( 11 ) UNSIGNED NOT NULL ,`level` SMALLINT( 4 ) UNSIGNED NOT NULL DEFAULT '5', " .
"INDEX ( `user` )) ENGINE = MYISAM CHARACTER SET utf8 COLLATE utf8_unicode_ci";
$db_results = Dba::write($sql);
$sql = "ALTER TABLE `user_catalog` ADD INDEX ( `catalog` )";
$db_results = Dba::write($sql);
self::set_version('db_version','350002');
return true;
} // update_350002
} // end update class } // end update class
?> ?>

View file

@ -322,14 +322,6 @@ switch ($_REQUEST['action']) {
$results['browse_content'] = ob_get_contents(); $results['browse_content'] = ob_get_contents();
ob_end_clean(); ob_end_clean();
break; break;
case 'page':
Browse::set_start($_REQUEST['start']);
ob_start();
Browse::show_objects('', true);
$results['browse_content'] = ob_get_contents();
ob_end_clean();
break;
default: default:
$results['rfc3514'] = '0x1'; $results['rfc3514'] = '0x1';
break; break;

View file

@ -88,6 +88,15 @@ switch ($_REQUEST['action']) {
$results[$key] = ''; $results[$key] = '';
break;
case 'page':
Browse::set_type($_REQUEST['type']);
Browse::set_start($_REQUEST['start']);
ob_start();
Browse::show_objects(false,true);
$results['browse_content'] = ob_get_clean();
break; break;
default: default:
$results['rfc3514'] = '0x1'; $results['rfc3514'] = '0x1';

View file

@ -1,7 +1,7 @@
<?php <?php
/* /*
Copyright (c) 2001 - 2007 Ampache.org Copyright (c) Ampache.org
All rights reserved. All rights reserved.
This program is free software; you can redistribute it and/or This program is free software; you can redistribute it and/or
@ -90,14 +90,15 @@ while ($page <= $pages) {
// Sort These Arrays of Hotness // Sort These Arrays of Hotness
ksort($page_data['up']); ksort($page_data['up']);
ksort($page_data['down']); ksort($page_data['down']);
$browse_type = Browse::get_type();
// are there enough items to even need this view? // are there enough items to even need this view?
if ($pages > 1) { if ($pages > 1) {
?> ?>
<div class="list-header"> <div class="list-header">
<?php echo Ajax::text('?action=page&start=' . $prev_offset,_('Prev'),'browse_' . $uid . 'prev','','prev'); ?> <?php echo Ajax::text('?page=browse&action=page&type=' . $browse_type . '&start=' . $prev_offset,_('Prev'),'browse_' . $uid . 'prev','','prev'); ?>
<?php echo Ajax::text('?action=page&start=' . $next_offset,_('Next'),'browse_' . $uid . 'next','','next'); ?> <?php echo Ajax::text('?page=browse&action=page&type=' . $browse_type . '&start=' . $next_offset,_('Next'),'browse_' . $uid . 'next','','next'); ?>
<?php <?php
/* Echo Everything below us */ /* Echo Everything below us */
foreach ($page_data['down'] as $page => $offset) { foreach ($page_data['down'] as $page => $offset) {
@ -105,7 +106,7 @@ if ($pages > 1) {
else { else {
// Hack Alert // Hack Alert
$page++; $page++;
echo Ajax::text('?action=page&start=' . $offset,$page,'browse_' . $uid . 'page_' . $page,'','page-nb'); echo Ajax::text('?page=browse&action=page&type=' . $browse_type .'&start=' . $offset,$page,'browse_' . $uid . 'page_' . $page,'','page-nb');
} }
} // end foreach down } // end foreach down
@ -119,7 +120,7 @@ if ($pages > 1) {
foreach ($page_data['up'] as $page=>$offset) { foreach ($page_data['up'] as $page=>$offset) {
if ($offset === '...') { echo '...&nbsp;'; } if ($offset === '...') { echo '...&nbsp;'; }
else { else {
echo Ajax::text('?action=page&start=' . $offset,$page,'browse_' . $uid . 'page_' . $page,'','page-nb'); echo Ajax::text('?page=browse&action=page&type=' . $browse_type . '&start=' . $offset,$page,'browse_' . $uid . 'page_' . $page,'','page-nb');
} // end else } // end else
} // end foreach up } // end foreach up
?> ?>