Version: 1.00, by ZippySLC
Developer Last Online: Nov 2010
Category: vBulletin CMS Widgets -
Version: 4.0.1
Rating:
Released: 01-30-2010
Last Update: Never
Installs: 45
Re-useable Code Translations
No support by the author.
Hey all,
One of the things that I missed from my transition from Drupal to vBCMS was my Photopost random image block. It's one of the features that my visitors seem to really like as well. After some trial and error, I managed to create a working vBCMS widget that utilizes the "Random Image Anywhere" code submitted by Garrynz on the Photopost site.
Now, I will say that I am not a huge fan of the way that Garrynz's code works (variables are defined in the code rather than looking at the config files), but it's a quick and dirty way to get this work. In no way are your database details visible to anybody, so don't worry - it's more of an aesthetic thing than a security thing.
Anyway, to utilize this widget, follow these steps:
1. Go into your AdminCP, vBulletin CMS, Widgets, and click on "Add New Widget"
2. Create a new widget of type "PHP Direct Execution" and name it what you want. This name gets used in the header of the widget. I chose "Random Image."
3. Paste the following code in, making changes for your specific environment:
PHP Code:
$host = 'database_server';
$dbUser = 'database_user';
$dbPass = 'database_password';
$db = 'database_name';
mysql_connect("$host", "$dbUser", "$dbPass") or die(mysql_error());
mysql_select_db("$db") or die(mysql_error());
ob_start();
$result = mysql_query("SELECT id,cat,bigimage FROM pp_photos order by rand() LIMIT 1" ) or die(mysql_error());
while($row = mysql_fetch_array( $result )) {
print "<div align=\"center\"><a href=\"photos/showphoto.php/photo/" . $row['id'] . "\"><img src=\"photos/data/" . $row['cat'] . "/thumbs/" . $row['bigimage'] . "\"></a><br /><a href=\"/gallery\">See more photos in the Gallery</a></div>";
}
$output .= ob_get_contents();
ob_end_clean();
Important Notes:
Make sure you make the widget be a "PHP Direct Execution" widget! If you don't, none of this will work!
Make sure you enter your database information correctly! Check your photopost config files if you've forgotten it. The correct syntax for the entries should be something like this:
$host = 'localhost'; (with the entry in apostrophes and a semi-colon at the end)
If your Photopost tables don't have the pp_ prefix, you'll need to alter the code to reflect your prefix.
Make sure the URL to your gallery is set correctly after the print statement. In my case, since my gallery runs in a subdomain, my own print statement looks something like this:
PHP Code:
print "<div align=\"center\"><a href=\"http://gallery.njpinebarrens.com/showphoto.php/photo/" . $row['id'] . "\"><img src=\"http://gallery.njpinebarrens.com/data/" . $row['cat'] . "/thumbs/" . $row['bigimage'] . "\"></a><br /><a href=\"/gallery\">See more photos in the Gallery</div>";
The output is wrapped in a div that's centered. Feel free to change that to your liking.
Again, this will not run out of the box without some customization on your part! But I hope it's fairly straightforward to understand.
SEO vs Non-SEO Friendly URL's:
Photopost lets you use "Spider-Friendly URL's." There's three different options, spider, SEO, and none. I personally use spider on my Photopost site and the code I have above works fine. If you have your URL's set to "none" you'll need to use slightly different code. In that case, use this alternate print statement. (Replace the one in the code above with this, and obviously adjust the paths to match your specific install.)
I have noticed a glitch, I have my random image block above my section menu and now the Header title text "Section" links to my photopost? see here, www.flyfishbc.com
I have noticed a glitch, I have my random image block above my section menu and now the Header title text "Section" links to my photopost? see here, www.flyfishbc.com
I fixed this by removing this,
Code:
<a href="/gallery\">See more photos in the Gallery</a>
Excellent, thanks for the post. Was looking for a widget like this. The plugin on the Photopost site generates a film strip in the forum and a profile reference. Slightly too much for my taste since there's no config/controls.
Aside from the db prefix and the relative path, I had to tweak href=\"photos/showphoto.php/photo/" to href=\"photos/showphoto.php?photo=" in order for the link to the actual picture to work, but it was up and running within 5 mins or less.
Aside from the db prefix and the relative path, I had to tweak href=\"photos/showphoto.php/photo/" to href=\"photos/showphoto.php?photo=" in order for the link to the actual picture to work, but it was up and running within 5 mins or less.
Excellent, that edit also fixed the issue i reported earlier :up:
Excellent, that edit also fixed the issue i reported earlier :up:
Yeah, the thing is that there seems to be two ways that the URLs for photos seem to be generated (SEO friendly and not.) The vBSEO rewriting the gallery URL's also made it a bit harder to troubleshoot. Then I clicked on your image and saw you had fixed it before I got to you! Glad it's working for you now!
Now that I am playing around with it a bit, I see it doesnt always show a picture?
So what is happening here is that the script is selecting a valid photo in your photopost database, but the thumbnail and possibly the full size photo don't exist on your server.