SEF urls and wordpress SEF urls and wordpress
 

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

SEF urls and wordpress

Started by msiwind, June 15, 2008, 10:04:48 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

msiwind

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 and put the following code into the widgets options once installed;


<?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.

NicMason.com

Very nice!  Thank you for posting the code.

Will the password be secure..?

Cheers,

Nic

NicMason.com