Advanced search  

News:

cpg1.5.48 Security release - upgrade mandatory!
The Coppermine development team is releasing a security update for Coppermine in order to counter a recently discovered vulnerability. It is important that all users who run version cpg1.5.46 or older update to this latest version as soon as possible.
[more]

Pages: [1]   Go Down

Author Topic: Category/Album Jump  (Read 3542 times)

0 Members and 1 Guest are viewing this topic.

just_some_guy

  • Supporter
  • Coppermine addict
  • ****
  • Offline Offline
  • Posts: 539
  • I am currently on holiday, back in a few weeks. :D
Category/Album Jump
« on: November 13, 2007, 06:27:39 pm »

Category/Album Jump
CPG 1.4x
DEMO

This is a new way to navigate your gallery. This creates a dropdown menu with a list of either categories or albums. The dropdown is the same as the one for choosing a theme or language (using coppermines built in JavaScript). It very easy to use and you can activate it by pasting the code below into a new file (say jump.php) and then in your gallery config navigate to the include of a custom header/footer and type jump.php - Simple.

For Category Jump -

Code: [Select]
<?php
// Start Coppermines code
echo "<form name=\"cpgChooseLanguage\" id=\"cpgChooseLanguage\" action=\"index.php\" method=\"get\" style=\"margin-top:0px;margin-bottom:0px;margin-left:0px;margin-right:0px;display:inline\">";
echo 
"<select name=\"cpgLanguageSelect\" class=\"listbox_lang\" onchange=\"if (this.options[this.selectedIndex].value) window.location.href='index.php?cat=' + this.options[this.selectedIndex].value;\">";
// End Coppermines code
echo '<option selected>Category Jump</option>';

$sql "SELECT * FROM {$CONFIG['TABLE_CATEGORIES']}";
$result cpg_db_query($sql);
while (
$row mysql_fetch_assoc($result)) {
$cid_mod $row['cid'];
$name_mod $row['name'];
echo 
"last ".$name_mod." by ".$cid_mod."";
echo 
'<option value="';
echo 
$cid_mod;
echo 
'">';
echo 
$name_mod;
echo 
'</option>';
}



echo 
'</select>';
echo 
'</form>';
?>

For Album Jump -

Code: [Select]
<?php
// Start Coppermines code
echo "<form name=\"cpgChooseLanguage\" id=\"cpgChooseLanguage\" action=\"index.php\" method=\"get\" style=\"margin-top:0px;margin-bottom:0px;margin-left:0px;margin-right:0px;display:inline\">";
echo 
"<select name=\"cpgLanguageSelect\" class=\"listbox_lang\" onchange=\"if (this.options[this.selectedIndex].value) window.location.href='thumbnails.php?album=' + this.options[this.selectedIndex].value;\">";
// End Coppermines code
echo '<option selected>Album Jump</option>';

$sql "SELECT * FROM {$CONFIG['TABLE_ALBUMS']}";
$result cpg_db_query($sql);
while (
$row mysql_fetch_assoc($result)) {
$cid_mod $row['aid'];
$name_mod $row['title'];
echo 
"last ".$name_mod." by ".$cid_mod."";
echo 
'<option value="';
echo 
$cid_mod;
echo 
'">';
echo 
$name_mod;
echo 
'</option>';
}



echo 
'</select>';
echo 
'</form>';
?>



I would like to hear your feedback,

Thanks,

just_some_guy
« Last Edit: November 13, 2007, 07:07:11 pm by GauGau »
Logged
Tambien, Hablo Español      PHP - Achieve Anything
"The Internet is becoming the town square for the global village of tomorrow. " - Bill Gates
Windows 7 Forums

Steve-R

  • Coppermine novice
  • *
  • Offline Offline
  • Posts: 38
Re: Category/Album Jump
« Reply #1 on: November 13, 2007, 07:06:38 pm »

Installed, tested and working well..Great addition and will be handy for many I'm sure. Especially for people like your sefl who have many categories on their site or many albums.

Simple install...

Steve...:)
Logged

just_some_guy

  • Supporter
  • Coppermine addict
  • ****
  • Offline Offline
  • Posts: 539
  • I am currently on holiday, back in a few weeks. :D
Re: Category/Album Jump
« Reply #2 on: November 13, 2007, 07:10:55 pm »

Thanks, Glad it works well.
Logged
Tambien, Hablo Español      PHP - Achieve Anything
"The Internet is becoming the town square for the global village of tomorrow. " - Bill Gates
Windows 7 Forums

Joachim Müller

  • Dev Team member
  • Coppermine addict
  • ****
  • Offline Offline
  • Gender: Male
  • Posts: 47843
  • aka "GauGau"
    • gaugau.de
Re: Category/Album Jump
« Reply #3 on: November 13, 2007, 07:11:43 pm »

I appreciate the effort and your readiness to share your mods with the community. However this mod has some serious drawbacks.
I told you before already: don't run queries against the database for stuff that already exists using Coppermine's buillt-in functions: your query will not respect permissions at all. Subsequently, users will use the dropdown to navigate somewhere and all they will see is a message that tells them that they're not allowed to see that page. Additionally, the albums will not be within the proper order nor will they be sorted by category. You might want to look at frogfoot's approach for a dropdown list which is much better.

Mod needs improvement.
Logged

just_some_guy

  • Supporter
  • Coppermine addict
  • ****
  • Offline Offline
  • Posts: 539
  • I am currently on holiday, back in a few weeks. :D
Re: Category/Album Jump
« Reply #4 on: November 13, 2007, 07:38:43 pm »

Ouch, that hurt. When you say the query already exists in coppermine's functions; what is it?  i made the change of using cpg_db_quey instead of mysql_query. But im not sure of the function you are talking about.

Thanks for the advice and i will make sure to improve it ASAP.
Logged
Tambien, Hablo Español      PHP - Achieve Anything
"The Internet is becoming the town square for the global village of tomorrow. " - Bill Gates
Windows 7 Forums

Joachim Müller

  • Dev Team member
  • Coppermine addict
  • ****
  • Offline Offline
  • Gender: Male
  • Posts: 47843
  • aka "GauGau"
    • gaugau.de
Re: Category/Album Jump
« Reply #5 on: November 14, 2007, 08:01:49 am »

Take a look at include/functions.inc.php - there are already functions that will return what you need, e.g.
Code: [Select]
/**************************************************************************
   Functions for album/picture management
 **************************************************************************/

// Get the list of albums that the current user can't see

/**
 * get_private_album_set()
 *
 * @param string $aid_str
 * @return
 **/

function get_private_album_set($aid_str="")
Logged

Gephri

  • Coppermine frequent poster
  • ***
  • Offline Offline
  • Posts: 235
Re: Category/Album Jump
« Reply #6 on: January 25, 2008, 07:44:19 pm »

Hey just_some_guy - don't leave hurt!
Any thoughts of updating your Mod based on Müller's suggestions?
Logged

just_some_guy

  • Supporter
  • Coppermine addict
  • ****
  • Offline Offline
  • Posts: 539
  • I am currently on holiday, back in a few weeks. :D
Re: Category/Album Jump
« Reply #7 on: January 27, 2008, 11:00:44 am »

It sort of went of the "to-do" list, but i may put some more thought into it.

Apologies for the delay,
Logged
Tambien, Hablo Español      PHP - Achieve Anything
"The Internet is becoming the town square for the global village of tomorrow. " - Bill Gates
Windows 7 Forums

skmdd

  • Tester
  • Coppermine novice
  • *
  • Offline Offline
  • Gender: Female
  • Posts: 23
    • Celebrities Wallpapers & Photo Gallery
Re: Category/Album Jump
« Reply #8 on: May 04, 2008, 10:31:43 am »

I appreciate the effort and your readiness to share your mods with the community. However this mod has some serious drawbacks.
I told you before already: don't run queries against the database for stuff that already exists using Coppermine's buillt-in functions: your query will not respect permissions at all. Subsequently, users will use the dropdown to navigate somewhere and all they will see is a message that tells them that they're not allowed to see that page. Additionally, the albums will not be within the proper order nor will they be sorted by category. You might want to look at frogfoot's approach for a dropdown list which is much better.

Mod needs improvement.

I used frogfoot's approach he has used in searchnew.php to rewrite this mod. The page below draws a dropdown just like batch add page, but with a javascript which jumps to album on selection.
I want to include this dropdown on every page. I would like it to be included just below language dropdown. Where should I insert this code?

Code: [Select]
<?php
define
('IN_COPPERMINE'true);
define('DB_INPUT_PHP'true);

require(
'include/init.inc.php');
pageheader('DecoratingDesktop.com');

function 
albumselect($id "album") {
// frogfoot re-wrote this function to present the list in categorized, sorted and nicely formatted order

    
global $CONFIG$lang_search_new_php$cpg_udb;
    static 
$select "";

    
// Reset counter
    
$list_count 0;

    if (
$select == "") {
        
$result cpg_db_query("SELECT aid, title FROM {$CONFIG['TABLE_ALBUMS']} WHERE category = 0");
        while (
$row mysql_fetch_array($result)) {
            
// Add to multi-dim array for later sorting
            
$listArray[$list_count]['cat'] = $lang_search_new_php['albums_no_category'];
            
$listArray[$list_count]['aid'] = $row['aid'];
            
$listArray[$list_count]['title'] = $row['title'];
            
$list_count++;
        }
        
mysql_free_result($result);

        
$result cpg_db_query("SELECT DISTINCT a.aid as aid, a.title as title, c.name as cname FROM {$CONFIG['TABLE_ALBUMS']} as a, {$CONFIG['TABLE_CATEGORIES']} as c WHERE a.category = c.cid AND a.category < '" FIRST_USER_CAT "'");
        while (
$row mysql_fetch_array($result)) {
            
// Add to multi-dim array for later sorting
            
$listArray[$list_count]['cat'] = $row['cname'];
            
$listArray[$list_count]['aid'] = $row['aid'];
            
$listArray[$list_count]['title'] = $row['title'];
            
$list_count++;
        }
        
mysql_free_result($result);

        
//if (defined('UDB_INTEGRATION')) {
            
$sql $cpg_udb->get_batch_add_album_list();
        
/*} else {
            $sql = "SELECT aid, CONCAT('(', user_name, ') ', title) AS title " . "FROM {$CONFIG['TABLE_ALBUMS']} AS a " . "INNER JOIN {$CONFIG['TABLE_USERS']} AS u ON category = (" . FIRST_USER_CAT . " + user_id)";
        }*/
        
$result cpg_db_query($sql);
        while (
$row mysql_fetch_array($result)) {
            
// Add to multi-dim array for later sorting
            
$listArray[$list_count]['cat'] = $lang_search_new_php['personal_albums'];
            
$listArray[$list_count]['aid'] = $row['aid'];
            
$listArray[$list_count]['title'] = $row['title'];
            
$list_count++;
        }
        
mysql_free_result($result);

        
$select '<option value="0"> Go to album... </option>\n';

        
// Sort the pulldown options by category and album name
        
$listArray array_csort($listArray,'cat','title');

        
// Create the nicely sorted and formatted drop down list
        
$alb_cat '';
        foreach (
$listArray as $val) {
            if (
$val['cat'] != $alb_cat) {
          if (
$alb_cat$select .= "</optgroup>\n";
                
$select .= '<optgroup label="' $val['cat'] . '">' "\n";
                
$alb_cat $val['cat'];
            }
            
$select .= '<option value="' $val['aid'] . '"' . ($val['aid'] == $sel_album ' selected' '') . '>   ' $val['title'] . "</option>\n";
        }
        if (
$alb_cat$select .= "</optgroup>\n";
    }

    return 
"\n<select name=\"$id\" class=\"listbox\" onchange=\"window.location.href='thumbnails.php?album='+this.value;\">\n$select</select>\n";
}

print 
albumselect();

pagefooter();
?>

Logged
Pages: [1]   Go Up
 

Page created in 0.02 seconds with 20 queries.