User Galleries as Root Categories User Galleries as Root Categories
 

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]

Main Menu

User Galleries as Root Categories

Started by pkulak, May 02, 2004, 11:18:12 AM

Previous topic - Next topic

0 Members and 2 Guests are viewing this topic.

pkulak

I only have two users, so I modified index.php so that their user galleries show up just as if they were categories. I'm not going to post a guide yet. I'll do that if someone actually wants to try it since the guide takes as long as the hack. You can check it out here:

http://www.pkulak.com/photos/
"To do any good at all, just believing you are right and you motives are good isn't enough." - Ursula K. Le Guin

photoman13

I would love to see your hack for this... :)

also if you have normal admin created Galleries (Noticed you don't have any on that site) will they be effected in any way?

Thanks

pkulak

#2
Here we go.

1. Add the following code in index.php:

   // Display the user categories if we're at the top.
   if (empty($parent)) {
      $sql = "SELECT user_id + " . FIRST_USER_CAT . " AS catID,
                     user_name
              FROM {$CONFIG['TABLE_USERS']}
              ORDER BY user_name";
      $users = db_fetch_rowset(db_query($sql));
     
      foreach ($users as $user) {
         $sql = "SELECT COUNT(*)
                 FROM {$CONFIG['TABLE_ALBUMS']}
                 WHERE category = {$user[0]}";
         $album = mysql_fetch_array(db_query($sql));
         
         $sql = "SELECT COUNT(*)
                 FROM {$CONFIG['TABLE_ALBUMS']} JOIN {$CONFIG['TABLE_PICTURES']}
                      ON {$CONFIG['TABLE_ALBUMS']}.aid = {$CONFIG['TABLE_PICTURES']}.aid
                 WHERE {$CONFIG['TABLE_ALBUMS']}.category = {$user[0]}";
         $picture = mysql_fetch_array(db_query($sql));
 
         $cat_data[] = array("<a href=\"index.php?cat={$user[0]}\">{$user[1]}'s Photos</a>","","{$album[0]}","{$picture[0]}", 'cat_albums' => list_cat_albums($user[0]) );
      }
   }

right before

}
// List all categories
function get_cat_list(&$breadcrumb, &$cat_data, &$statistics)

Basicaly, you want that if statement to be the last thing in the get_subcat_data() function.

2. That's really it, just a few little things to tidy up. First, there is no need to
have the User Galleries category show up anymore. Change the following SQL:

SELECT cid, name, description FROM {$CONFIG['TABLE_CATEGORIES']} WHERE parent = '$parent'  ORDER BY pos

to

SELECT cid, name, description FROM {$CONFIG['TABLE_CATEGORIES']} WHERE parent = '$parent' AND cid <> 1 ORDER BY pos

3. Next we need to have the stats reflecting our changes. Change this code block:

$result = db_query("SELECT count(*) FROM {$CONFIG['TABLE_CATEGORIES']} WHERE 1");
$nbEnr = mysql_fetch_array($result);
$cat_count = $nbEnr[0] - $HIDE_USER_CAT;
mysql_free_result($result);

to

$result = db_query("SELECT count(*) FROM {$CONFIG['TABLE_CATEGORIES']} WHERE 1");
$nbEnr = mysql_fetch_array($result);
$totalCats = $nbEnr[0];
$result = db_query("SELECT count(*) FROM {$CONFIG['TABLE_USERS']} WHERE 1");
$nbEnr = mysql_fetch_array($result);
$totalUsers = $nbEnr[0];
$cat_count = $totalCats - $HIDE_USER_CAT - 1 + $totalUsers;
mysql_free_result($result);

And you're done. The only thing left would be to add a row to your config table and turn
this into something you can turn on and off. To borrow from a bad textbook,
I'll leave that as an exercise to the reader.

I can always just post my index.php file. If you have 1.2.1 and haven't modified yours you can just replace it.
"To do any good at all, just believing you are right and you motives are good isn't enough." - Ursula K. Le Guin

jpepin

Will this work without doing the database mods?  I'm getting this error:

There was an error while processing a database query


rostros

great Mod, One problem it displays all the users albums on the main page ??? even though you set the options in config to only display 2rows and 2 colloumns ?

comic

#5
Quote from: jpepin on May 16, 2004, 08:45:31 PM
Will this work without doing the database mods?  I'm getting this error:

There was an error while processing a database query



I'm getting the same error on coppermine v1.3.0. The statement that is offending is the first sql query (I commented it out and didn't get the same error, though ofcause it didn't work). I tried it on 1.2.1 too on another site and got the same error there too :/

Some experimenting gives that the following code is giving the error:
          $sql = "SELECT COUNT(*)
                  FROM {$CONFIG['TABLE_ALBUMS']} JOIN {$CONFIG['TABLE_PICTURES']}
                       ON {$CONFIG['TABLE_ALBUMS']}.aid = {$CONFIG['TABLE_PICTURES']}.aid
                  WHERE {$CONFIG['TABLE_ALBUMS']}.category = {$user[0]}";
          $picture = mysql_fetch_array(db_query($sql));


Anyone?

kalasdojan

How do I make this work in CPG 1.3x? I get a MySQL-error after changing the index.php-file.
Help appreciated!
//daniel.

Joachim Müller

Quote from: kalasdojan on August 22, 2004, 07:21:04 PMHow do I make this work in CPG 1.3x? I get a MySQL-error after changing the index.php-file.
That's why the thread is labelled
Quote[CPG1.2.1]: HACK: User Galleries as Root Categories
If you need it, you will have to adjust the code. Mods are user contributions, they come as-is.

GauGau

comic

Ok now I go it working, I like the hack vey much, but realized that many usergalleries will make a very very long page. For example a few (ie 50) users will work fine on one page, but when you have several hundreds you would like to have some tabs and display 50 users at every page. Anyone has an idea how to do that?

I presume I should hack index.php with something similar as the function list_cat_albums for starting the userlist. Then probaby another file with a similar functionality as thumbnails.php which answers the call for another page of users.

Even when you don't have the time, please give some directions and I will try for myself . . . .

thanks,
Comic

crashtd

Quote from: comic on October 27, 2004, 01:46:10 AM
Ok now I go it working, I like the hack vey much, but realized that many usergalleries will make a very very long page. For example a few (ie 50) users will work fine on one page, but when you have several hundreds you would like to have some tabs and display 50 users at every page. Anyone has an idea how to do that?

I presume I should hack index.php with something similar as the function list_cat_albums for starting the userlist. Then probaby another file with a similar functionality as thumbnails.php which answers the call for another page of users.

Even when you don't have the time, please give some directions and I will try for myself . . . .

thanks,
Comic

comic what did you do to get this to work on 1.3?

partypics

If you just want to see a list of your users on the first page (not all of their albums) you can achieve it by modifying your index.php :
find this
if (isset($HTTP_GET_VARS['cat'])) {
    $cat = (int)$HTTP_GET_VARS['cat'];
}

and replace it with this:
if (isset($HTTP_GET_VARS['cat'])) {
    $cat = (int)$HTTP_GET_VARS['cat'];
}
else {
$cat = USER_GAL_CAT;
}

That's if you don't have any other categories except User Galleries.

crashtd

Quote from: partypics on January 10, 2005, 08:30:24 PM
If you just want to see a list of your users on the first page (not all of their albums) you can achieve it by modifying your index.php :
find this
if (isset($HTTP_GET_VARS['cat'])) {
   $cat = (int)$HTTP_GET_VARS['cat'];
}

and replace it with this:
if (isset($HTTP_GET_VARS['cat'])) {
   $cat = (int)$HTTP_GET_VARS['cat'];
}
else {
$cat = USER_GAL_CAT;
}

That's if you don't have any other categories except User Galleries.


but that doesn't work when you want to display the user galleries and the admin created galleries does it?

partypics

It doesn't. you will only see User Galleries

ToddW

So did someone figure out how to limit it to two rows and work for 1.3 ?

Charles Scott

pkulak, this works perfectly. Now the real question. What if I want to have my categories display normally and also have the user albums display like your mod makes it do?

How do I get the best of both worlds?

Joachim Müller


HaVaNa7

#16
For CPG 1.3 i have found a very simple way to show user galleries as root.

Yoh have to do three simple steps:

1)Upload a redirect script in your web space and point it to http://www.yoururl.com/index.php?cat=1

use this:
<?php
///////////////////////////////////////////////////////////////////////////
// Free Redirection Script By Only PHP www.onlyphp.com
///////////////////////////////////////////////////////////////////////////

$SETUP[siteurl] = "http://www.yoursite.com/index.php?cat=1";

if (
$url) {

$lines_array file($url);
$lines_string implode(''$lines_array);
eregi("<head>(.*)</head>"$lines_string$head);


?>

<html>

<head>
<title>Redirecting Now...</title>
<script LANGUAGE="JavaScript">
 var VersionString = navigator.appVersion

 if (navigator.appName == "Netscape") {
   if (VersionString.substring(0,1) >= 1) {
 // Netscape 3.0 (or later) browsers go to this location:
 location = "<?php echo $url?>"
 }
   }

 if (navigator.appName == "Microsoft Internet Explorer") {
   if (VersionString.substring(0,1) >= 1) {
 // Microsoft Internet Explorer users go to this location:
 location = "<?php echo $url?>";
 }
   }

 </script>
</head>

<body bgcolor=white>

 <p>You're Being Redirected To The Page Requested <a href="<?php echo $url?>">If you don't want to wait or it doesn't open please click here...</a>
 </body>


</html>




<?php
exit();

} else {

header("Location: $SETUP[siteurl]");
exit();

}



2)Modify Theme.php in your theme dir and modify theese lines:


<!-- BEGIN album_list -->
                       <a href="{ALB_LIST_TGT}" title="{ALB_LIST_TITLE}">{ALB_LIST_LNK}</a> ::
<!-- END album_list -->


in:


<!-- BEGIN album_list -->
                       <a href="http://yoursite.com/coppermine/index.php?cat=1" title="{ALB_LIST_TITLE}">{ALB_LIST_LNK}</a>
<!-- END album_list -->


3)

in functions.inc.php in include folder modify thees lines:


}else{ //Dont bother just add the Home link to breadcrumb
               $breadcrumb = '<a href=index.php?cat=1>'.$lang_list_categories['home'].'</a>';
               $BREADCRUMB_TEXT = $lang_list_categories['home'];
       }


in:


}else{ //Dont bother just add the Home link to breadcrumb
               $breadcrumb = '<a href=index.php?cat=1>'.$lang_list_categories['home'].'</a>';
               $BREADCRUMB_TEXT = $lang_list_categories['home'];
       }


and:


 $breadcrumb_array = array_reverse($breadcrumb_array);
               $breadcrumb = '<a href=index.php?cat=1>'.$lang_list_categories['home'].'</a>';
               $BREADCRUMB_TEXT = $lang_list_categories['home'];


in:


 $breadcrumb_array = array_reverse($breadcrumb_array);
               $breadcrumb = '<a href=index.php?cat=1>'.$lang_list_categories['home'].'</a>';
               $BREADCRUMB_TEXT = $lang_list_categories['home'];


Ok, done!

It seems to work well...

ant eater

i achieved this by simply adding a line and it works like a charm  :D

possibly not the best solution but here it goes:

find this around line 703 on index.php:
            case 'alblist':
                list_albums();
                flush();
                break;


replace it with:
            case 'alblist':
                list_albums();
            if ($cat == "0"){ list_users(); }
                flush();
                break;


that will show the list of users in the index.

regards.