forum.coppermine-gallery.net

No Support => Modifications/Add-Ons/Hacks => Mods: Miscellaneous => Topic started by: msiwind on June 15, 2008, 10:04:48 pm

Title: SEF urls and wordpress
Post by: msiwind on June 15, 2008, 10:04:48 pm
Right so this might not be of use to anyone except me but just incase, I figured I would post it here. I setup a site with word press and wanted to use SEF URLs in Coppermine so I wrote something that should properly link wordpress and coppermine. Which displays a random thumb from the gallery and a link to that image.

All I did was get the Samsarin PHP Widget for wordpress (http://www.samsarin.com/blog/2007/03/10/samsarin-php-widget/) and put the following code into the widgets options once installed;

Code: [Select]
<?PHP

function cpg_rand() {
$user_name = "database user";
$password = "database password";
$database = "database";
$server = "127.0.0.1";
$cpgUrl = "http://www.example.com/photos/";
        $cpgTitle = "gallery description"

$db_handle = mysql_connect($server, $user_name, $password);
$db_found = mysql_select_db($database, $db_handle);

if ($db_found) {

$SQL = "SELECT * FROM cpg14x_pictures";
$result = mysql_query($SQL);

while ($db_field = mysql_fetch_assoc($result)) {
$thumb[] = $db_field['pid'];
$title[] = $db_field['title'];
$file[] = $db_field['filename'];
$path[] = $db_field['filepath'];
}

mysql_close($db_handle);

$rand_keys = array_rand($thumb, count($thumb));
$var1 = $thumb[$rand_keys[0]];
$varid = $var1 - 1;
$var2 = $title[$varid];
$var3 = $file[$varid];
$var4 = $path[$varid];

// construct $cpgHtml

$cpgHtml = '
<a href="' . $cpgUrl . 'displayimage-random-0--' . $var1 . '.html" title="' . $var2 . '">
<img src="' . $cpgUrl . 'albums/' . $var4 . 'thumb_' . $var3 .'" alt="' . $var2 . '" />
</a>
<br /><br />
<a href="' . $cpgUrl . '" title="' . $cpgTitle . '">Visit the Gallery</a>';

echo "$cpgHtml";

} else {
print "Database NOT Found ";
mysql_close($db_handle);
}
}

cpg_rand();

?>

Remember to enter the correct database info and I hope this helps someone.
Title: Re: SEF urls and wordpress
Post by: NicMason.com on November 07, 2008, 08:51:58 am
Very nice!  Thank you for posting the code.

Will the password be secure..?

Cheers,

Nic

NicMason.com