News:

CPG Release 1.6.28
added submissions from {406man}
cleaned up a few PHP (8.4) deprecations
fixed PHP deprecation in calendar
removed security vulnerability
(please upgrade when possible)

Main Menu

another question (regarding user album urls)

Started by Oasis, September 25, 2003, 05:38:01 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

kegobeer

QuoteOne last question though... Is there a way I could do it so the the url doesn't change automatically? What I mean is that currently when the page loads the url in the address bar is changed... what should I do to keep it there? Is there any other function other than header(location: URL) ? One that will keep the shortened url in the address bar.
The easiest way is to use frames.  A buddy of mine does this so the url never changes in the address bar.  Make an index.html file with two frames, one that is only one pixel wide.  Use that frame to call cpg into the large frame.

That should keep your url in place.
Do not send me a private message unless I ask for one.  Make your post public so everyone can benefit.

There are no stupid questions
But there are a LOT of inquisitive idiots

Tarique Sani

Quote from: "oasis"One last question though... Is there a way I could do it so the the url doesn't change automatically? What I mean is that currently when the page loads the url in the address bar is changed... what should I do to keep it there? Is there any other function other than header(location: URL) ? One that will keep the shortened url in the address bar.
There is something in the rewrite rules which allows this ... Can't recall

BTW - thanks for the files, this should go into the FAQ....
SANIsoft PHP applications for E Biz

Oasis

OK I've done it!

I tweaked it a bit, and removed useless code. I've also made it so that the url will stay in place.

HTACCESS hasn't changed much, but the most important thing is that now it points to index.php not album.php as it previously did.
QuoteRewriteEngine On
RewriteRule ^([a-z0-9&_=]+)$ index.php?username=$1

Second, ALBUM.PHP has change A LOT!:
Quote<?php
require('include/init.inc.php')
if (isset($HTTP_GET_VARS['username'])) {
        $username = $HTTP_GET_VARS['username'];
        $results = mysql_query("SELECT user_id FROM cpg11d_users WHERE user_name = '$username'");
        list($row) = mysql_fetch_row($results);
        if (!$row) {
                $row = -10000;
        }
        $idnum=$row+10000;
        $catid = $idnum;
        $cat = $catid;
$HTTP_GET_VARS['cat'] = $cat;
}
?>

Lastly, I'm afraid I had to chang a tiny bit of INDEX.PHP:
I removed from the top:
Quoterequire('include/init.inc.php');
and added
Quoterequire('album.php');

the removed line has been moved to album.php, where it still gets called.
What it does now is when I enter http://photo.enctu.org/USERNAME in the browser,
mod_rewrite makes it call index.php?username=USERNAME
ALBUM.PHP will process the variable and turn it into the user_id $cat,
which is the variable INDEX.PHP uses for calling out the albums of a specific category(in this case a user). INDEX.PHP will be tricked into thinking that the user specified a cat, and will go to that category. And best of all, since INDEX.PHP is giving all the information, there is no need for redirection, which means that the url will not change!!!

Try: http://photo.enctu.org/stunion

Oh god, I can't help feeling pleased with myself for doing all this with hardly any knowledge of PHP. Thanks to everyone who helped me. Coppermine RULES!
Pixnet Gallery: http://www.pixnet.net
iNSiGNiA Weblog: http://www.jayliu.org

moorey


Joachim Müller

Quote from: "tarique"BTW - thanks for the files, this should go into the FAQ....
hehe, and what exactly should go there? This thread is somewhat "oversized" for the faq... :wink:
Could anyone do a resumé that I can put into the faq?

Thanks

GauGau

lasa

Very nice script!
Can you please rewrite this script?
I want to use it for albums, not for the users.

Lasa.

kegobeer

QuoteCan you please rewrite this script?
Are you kidding?  :roll:
Do not send me a private message unless I ask for one.  Make your post public so everyone can benefit.

There are no stupid questions
But there are a LOT of inquisitive idiots

lasa

Some small PHP modifications. :wink:
I can't code PHP.... :oops:

Joachim Müller

Quote from: "lasa"Some small PHP modifications. :wink:
I can't code PHP.... :oops:
Then how do you know these are going to be small modifications if you can't code php? :evil:

GauGau

lasa

Because the only thing you have to change is the album instead of the user. I have tried it, but it don't work out...

lasa

I have made this, but it doesn't work:

.htaccess

RewriteEngine On
RewriteRule ^([a-z0-9&=]+)$ album.php?album=$1


album.php

<?php 

/************************************************************************** 
Database functions 
**************************************************************************/ 

// Connect to the database 
mysql_connect &#40;***,***,'***'&#41;;
mysql_select_db &#40;***'&#41;;


// Perform a database query 
function db_query&#40;$query&#41; 
&#123; 
global $query_stats

$query_start getmicrotime&#40;&#41;; 
$result mysql_query&#40;$query&#41;; 
$query_end getmicrotime&#40;&#41;; 
$query_stats[&#93; = $query_end - $query_start; 

if &#40;!$result&#41; db_error&#40;"While executing query \"$query\""&#41;; 

return $result
&
#125; 

// Error message if a query failed 
function db_error&#40;$the_error&#41; 
&#123; 
global $CONFIG

if &
#40;!$CONFIG['debug_mode'&#93;&#41; &#123; 
cpg_die&#40;CRITICAL_ERROR, 'There was an error while processing a database query', __FILE__, __LINE__&#41;; 
&#125; else &#123; 

$the_error .= "\n\nmySQL error&#58; ".mysql_error&#40;&#41;."\n"; 

$out "<br />There was an error while processing a database query.<br /><br/> 
<form name='mysql'><textarea rows=\"8\" cols=\"60\">"
.htmlspecialchars&#40;$the_error&#41;."</textarea></form>"; 

cpg_die&#40;CRITICAL_ERROR, $out, __FILE__, __LINE__&#41;; 
&#125; 
&#125; 

// Fetch all rows in an array 
function db_fetch_rowset&#40;$result&#41; 
&#123; 
$rowset = array&#40;&#41;; 

while &#40;$row = mysql_fetch_array&#40;$result&#41;&#41; $rowset[&#93; = $row; 

return $rowset
&
#125; 

function getmicrotime&#40;&#41;&#123; 
list&#40;$usec, $sec&#41; = explode&#40;" ",microtime&#40;&#41;&#41;; 
return &#40;&#40;float&#41;$usec + &#40;float&#41;$sec&#41;; 
&#125; 

function cpg_die&#40;$msg_code, $msg_text, $error_file, $error_line, $output_buffer = false&#41; 
&#123; 
$ob ob_get_contents&#40;&#41;; 
if &#40;$ob&#41; ob_end_clean&#40;&#41;; 
exit; 
&
#125; 


$album $HTTP_GET_VARS['album'&#93;; 
$results mysql_query&#40;"SELECT aid FROM cpg00d_albums WHERE title = '$album'"&#41;; 

list&#40;$row&#41; = mysql_fetch_row&#40;$results&#41;; 
if &#40;!$row&#41; &#123; 
$row 0
&
#125; 
$idnum=$row
Header&#40;"Location&#58; thumbnails.php?album=".$idnum&#41;; 
exit; 
?>



I have replaced my MySQL data by *** for my privacy.

lasa


intranet

Is this the complete Mod ? I was trying to follow along, but got a bit confused once it was completed.

Will adding the following code to the appropriate files work as is ( also moving the line from index.php to album.php )
, or is there other code previous in the thread that is required?

Quote from: "oasis"OK I've done it!

I tweaked it a bit, and removed useless code. I've also made it so that the url will stay in place.

HTACCESS hasn't changed much, but the most important thing is that now it points to index.php not album.php as it previously did.
QuoteRewriteEngine On
RewriteRule ^([a-z0-9&_=]+)$ index.php?username=$1

Second, ALBUM.PHP has change A LOT!:
Quote<?php
require('include/init.inc.php')
if (isset($HTTP_GET_;VARS['username'])) {
        $username = $HTTP_GET_VARS['username'];
        $results = mysql_query("SELECT user_id FROM cpg11d_users WHERE user_name = '$username'");
        list($row) = mysql_fetch_row($results);
        if (!$row) {
                $row = -10000;
        }
        $idnum=$row+10000;
        $catid = $idnum;
        $cat = $catid;
$HTTP_GET_VARS['cat'] = $cat;
}
?>

Lastly, I'm afraid I had to chang a tiny bit of INDEX.PHP:
I removed from the top:
Quoterequire('include/init.inc.php');
and added
Quoterequire('album.php');

the removed line has been moved to album.php, where it still gets called.
What it does now is when I enter http://photo.enctu.org/USERNAME in the browser,
mod_rewrite makes it call index.php?username=USERNAME
ALBUM.PHP will process the variable and turn it into the user_id $cat,
which is the variable INDEX.PHP uses for calling out the albums of a specific category(in this case a user). INDEX.PHP will be tricked into thinking that the user specified a cat, and will go to that category. And best of all, since INDEX.PHP is giving all the information, there is no need for redirection, which means that the url will not change!!!

Try: http://photo.enctu.org/stunion

Oh god, I can't help feeling pleased with myself for doing all this with hardly any knowledge of PHP. Thanks to everyone who helped me. Coppermine RULES!

Oasis

Quote from: "intranet"Is this the complete Mod ? I was trying to follow along, but got a bit confused once it was completed.

Will adding the following code to the appropriate files work as is ( also moving the line from index.php to album.php )
, or is there other code previous in the thread that is required?

No intranet, this is all you need. When I said I tweaked the code a bit, actually I meant I rewrote it.  :lol:
So all you will need is the new .htaccess file, the new(shorter) album.php file and the slight change in index.php.
Oh by the, if you changed your table prefix, you will have to edit "cpg11d_users" in album.php

@lasa: try editing the newer version and not that old one... you do realise that albums are called by thumbnail.php and not index.php... also, it will not work if you have special characters(it will only take numbers, characters, hyphens and underscores) or spaces in the album name. Also, instead of cpg11d_users you'll have to call the table with the information about the albums. Good luck~
Pixnet Gallery: http://www.pixnet.net
iNSiGNiA Weblog: http://www.jayliu.org

Oasis

NOTE: This is not the user album url rewrite code! If you're looking for that, look further back.

@lasa: try this

.htaccess
QuoteRewriteEngine On
RewriteRule ^([a-z0-9&_=]+)$ thumbnails.php?albumname=$1

albumname.php
Quote<?php
require('include/init.inc.php')
if (isset($HTTP_GET_VARS['albumname'])) {
$albumname = $HTTP_GET_VARS['albumname'];
$results = mysql_query("SELECT aid FROM cpg11d_album WHERE title = '$albumname'");
list($row) = mysql_fetch_row($results);
if (!$row) {
$row = 0;
}
$album = $row;
$HTTP_GET_VARS[album'] = $album;
}
?>

replace in thumbnails.php
Quoterequire('include/init.inc.php');
with
Quoterequire('include/albumname.php');

I have not tested this because my gallery is now live so I can't change the settings. But, hopefully, if you enter http://yourdomain.com/pathtocoppermine/THISISALBUMNAME
it will go to the album with that name.

IF YOU HAVE TWO ALBUMS WITH THE SAME NAME, IT WILL NOT WORK!
IF YOU HAVE ALBUM NAMES WITH SPACES OR ANY SPECIAL CHARACTERS IT WILL NOT WORK.
So use this only if you are the sole admin and users can't create albums.
Pixnet Gallery: http://www.pixnet.net
iNSiGNiA Weblog: http://www.jayliu.org

TheGamer1701

Hey,

it works great for, only that I just can see the last 4 uploaded pictures, not more.
But I want to see the category of the user (album overview)

Any idea what I have to change?
Or where this come from?

Thx