View Full Version : vBulletin CMS Widgets - Photopost Pro Random Image Widget
ZippySLC
01-30-2010, 10:00 PM
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 (http://www.photopost.com/forum/photopost-mods-pro/116182-random-photo-anywhere.html)" 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:
$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:
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.)
print "<a href=\"/photopost/showphoto.php?photo=" . $row['id'] . "&cat=" . $row['cat'] . "\"><img src=\"/photos/data/" . $row['cat'] . "/thumbs/" . $row['bigimage'] . "\" border=\"0\"></a>";
You can see this widget in action on my site, http://www.njpinebarrens.com
Froggfish
01-31-2010, 07:11 AM
Is this for Photopost Callery og for Photopost Pro?
tazattitude
01-31-2010, 10:03 AM
Actually, there is a file that you can download from Photopost, and re-upload in your "Gallery". Then you run it from your Gallery cp. This will create a "product" file that you upload in your vb products section.
This will create a thumbnail strip that you can specify weather you want newest or newest pics. Plus the amount of images you want to show up.
You can make the changes in the Plugin section.
You can see how I have 6 images are 'random' on my website
(http://www.custompaintforum.com/forum/forum.php)
This of course, if it's Photopost Gallery
ZippySLC
01-31-2010, 10:42 AM
Froggfish,
Photopost Pro, but it might work for regular Photopost (vBGallery) as well.
Taz,
I saw their plugin, but I don't think that works on the CMS side. Additionally, it takes up a lot of space. This is just a quick and dirty way to display one random image and be done with it.
Your site design is very nice, by the way.
MattZ DSLR
01-31-2010, 04:50 PM
OK
What am I doing wrong
My site takes a very long time to load in
Template Name???
vbcms_widget_execphp_page
ZippySLC
01-31-2010, 05:14 PM
You can leave the template name as the default vbcms_widget_execphp_page.
What is the URL to your site?
MattZ DSLR
01-31-2010, 05:33 PM
Pm Send
ZippySLC
01-31-2010, 05:46 PM
I don't see the random image widget on your CMS.
MattZ DSLR
01-31-2010, 06:07 PM
I took it out as home page wouldn't load :(
ZippySLC
01-31-2010, 06:25 PM
Wouldn't load at all, or would load very slowly?
MattZ DSLR
01-31-2010, 06:43 PM
OK the link works but there is no photo
Do you know y this could be?
ZippySLC
01-31-2010, 06:54 PM
Send me a PM with the code you're using. (Edit out your database information)
I'll take a look.
MattZ DSLR
01-31-2010, 07:24 PM
PM send
ZippySLC
01-31-2010, 07:50 PM
Thanks.
Two things:
1. Is the table prefix for your gallery pp_
2. It might also be because your images are not viewable by unregistered users, but I'm not quite sure.
MattZ DSLR
01-31-2010, 07:53 PM
Thank you
Can you delete my code
I will keep you posted
ZippySLC
01-31-2010, 08:04 PM
Yes.
MattZ DSLR
01-31-2010, 09:02 PM
Got it thank you it was the pp_
What a great mod :)
Bergler
01-31-2010, 09:35 PM
Great mod!! I had it working but slowed the site down to a snails pace!! not sure what I did wrong or if that is just how it is? Hope for some help, cheers!
ZippySLC
01-31-2010, 09:56 PM
Matt, awesome. Glad I could help!
Bergler - it shouldn't slow the site down. It's just one db lookup. What's your URL?
tonmo
01-31-2010, 10:36 PM
Great widget, thanks. Please note you're missing your closing /a tag after the link to the gallery - it should instead look like this:
<a href=\"/gallery\">See more photos in the Gallery</a></div>";
Bergler
01-31-2010, 10:40 PM
Matt, awesome. Glad I could help!
Bergler - it shouldn't slow the site down. It's just one db lookup. What's your URL?
www.flyfishbc.com is my site!
ZippySLC
01-31-2010, 10:46 PM
Great widget, thanks. Please note you're missing your closing /a tag after the link to the gallery - it should instead look like this:
<a href=\"/gallery\">See more photos in the Gallery</a></div>";
Gah, you're right! Thanks!
Whats the fix if using _pp prefix?
ZippySLC
01-31-2010, 10:51 PM
www.flyfishbc.com is my site!
Alright, well I don't see the random image widget on your CMS, so I'm assuming you've disabled it. In any case, I'm getting very slow load times on everything on your site. (Forums, CMS, Photopost, etc.)
I think you're having problems that are deeper than just this widget.
I noticed that some of your ads were coming up with broken images. I wonder if whatever is serving up those banners is slowing things down for you.
ZippySLC
01-31-2010, 10:52 PM
Whats the fix if using _pp prefix?
By default the code assumes that your prefix is "pp_" so you don't need to change anything if that is the case.
Ok, well I do use default pp_ , but am getting this error at top of forum when i enable this widget.
Parse error: syntax error, unexpected T_STRING in /***/****/*****/packages/vbcms/widget/execphp.php(171) : eval()'d code on line 12
My gallery is located in /photopost directory if that helps
ZippySLC
02-01-2010, 12:01 AM
Ok, well I do use default pp_ , but am getting this error at top of forum when i enable this widget.
Parse error: syntax error, unexpected T_STRING in /***/****/*****/packages/vbcms/widget/execphp.php(171) : eval()'d code on line 12
My gallery is located in /photopost directory if that helps
Make sure that you have a closing semi-colon at the end of line 12 (which should be the line with the print statement in it.)
Thanks, seems it was a path issue, however...
The image block now appears, but, when clicking on the image, it takes me to /photopost/showphoto.php url with message "Photo not found in the database!"
Any ideas?
ZippySLC
02-01-2010, 12:24 AM
PM me a copy of your code (without the database login details) and a link to your gallery.
Bergler
02-01-2010, 12:42 AM
Alright, well I don't see the random image widget on your CMS, so I'm assuming you've disabled it. In any case, I'm getting very slow load times on everything on your site. (Forums, CMS, Photopost, etc.)
I think you're having problems that are deeper than just this widget.
I noticed that some of your ads were coming up with broken images. I wonder if whatever is serving up those banners is slowing things down for you.
Yes, my apologies, there is latency issue with my server. I have since enabled the image block and seems to be fine. Thanks for this great widget! :up: I sure like the new vB4.0.1!! :D
Also can this be used as a forum block aswell?
Bergler
02-01-2010, 12:58 AM
Now that I am playing around with it a bit, I see it doesnt always show a picture?
Bergler
02-01-2010, 01:12 AM
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 (http://www.flyfishbc.com)
Bergler
02-01-2010, 02:42 AM
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 (http://www.flyfishbc.com)
I fixed this by removing this,
<a href="/gallery\">See more photos in the Gallery</a>
Prasutagus
02-01-2010, 03:33 AM
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:
kisanjong
02-01-2010, 08:20 AM
working great thanks :) 5* :up:
ZippySLC
02-01-2010, 11:59 PM
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!
ZippySLC
02-02-2010, 12:04 AM
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.
Look at post #4 (and the replies) in this thread (http://www.photopost.com/forum/photopost-mods-pro/116182-random-photo-anywhere.html).
Drache
02-02-2010, 07:29 PM
Is it possible make it show only certain category photos in the gallery instead of selecting from all category in the gallery and showing them?
ZippySLC
02-03-2010, 02:25 AM
Is it possible make it show only certain category photos in the gallery instead of selecting from all category in the gallery and showing them?
Yes. It's a matter of adjusting the SQL query that the script uses to find a picture.
This post (http://www.photopost.com/forum/photopost-mods-pro/116182-random-photo-anywhere-2.html#post1114755) in the original authors thread might point you in the right direction.
lovevn
02-10-2010, 11:13 AM
Problem fixed!
works ok
ZippySLC
02-10-2010, 11:52 AM
I tried it but the result is jut a time in formation. 10/02/2010. No image. How to solve the problem?
PM me the URL to your site and your code please.
HRCHOSTING
02-10-2010, 09:48 PM
Entered the code but all I see is "see more photo's in our Gallery"
ZippySLC
02-10-2010, 10:30 PM
Yeah, there's a problem with the code or the path to your gallery. If you send me a copy of your code (with the database info redacted) and a link to your CMS and gallery, I'll take a look.
HRCHOSTING
02-14-2010, 02:29 PM
Working great now, thanks for the help!
ZippySLC
02-14-2010, 03:45 PM
Glad I could help!
LCN2007
02-23-2010, 05:47 PM
Any way to show more than one image like maybe 3 or 5 images?
Now that I am playing around with it a bit, I see it doesnt always show a picture?
X2 on this issue, any fix?
ZippySLC
02-24-2010, 02:16 AM
Any way to show more than one image like maybe 3 or 5 images?
The way the code is written, it just does one SQL query and grabs one picture out of the database. To get it to do any more would require the entire thing to be re-written. I didn't write the code to grab the pic from the db or display it, I just adjusted it so it would play nice as a CMS widget.
X2 on this issue, any fix?
So what is happening here is the code is selecting an image that your Photopost database thinks is there, but it isn't. If you look at the thread on Photopost's (http://www.photopost.com/forum/photopost-mods-pro/116182-random-photo-anywhere.html) site you'll see people having the same problem there too.
theduyet
02-27-2010, 06:50 AM
Actually, there is a file that you can download from Photopost, and re-upload in your "Gallery". Then you run it from your Gallery cp. This will create a "product" file that you upload in your vb products section.
This will create a thumbnail strip that you can specify weather you want newest or newest pics. Plus the amount of images you want to show up.
You can make the changes in the Plugin section.
You can see how I have 6 images are 'random' on my website
(http://www.custompaintforum.com/forum/forum.php)
This of course, if it's Photopost Gallery
Would you like to attach this file into this thread?
I and serveral VB.ORg members really like to get it.
Thank you!
tazattitude
02-27-2010, 09:29 AM
Would you like to attach this file into this thread?
I and serveral VB.ORg members really like to get it.
Thank you!
Here would be the link (http://www.photopost.com/forum/photopost-mods-pro/141769-photopost-pro-plugin-vbulletin-4-0-a.html) and info to it
Keep in mind this is not a widget like ZippySLC's
theduyet
02-27-2010, 12:12 PM
I can't download.
Would you like to attach it in vbulletin.org ?
theduyet
03-06-2010, 03:45 AM
help me :(
ZippySLC
03-06-2010, 10:04 AM
It's right there in the thread that Taz linked to.
tazattitude
03-06-2010, 11:07 AM
help me :(
Not for sure what you need help with. The link, instructions, download are all there (thanks Zippy). Of course, you'll have to own a Photopost to do this.
Again, this is not the exact same thing that Zippy has done.
molieman
03-06-2010, 12:04 PM
Can this be used with PhotoPost "Classifieds?"
Fantastic job, looks great. :) Thank you. :)
molieman
03-06-2010, 02:38 PM
This is probably a simple error in my part, but would appreciate some advise to correct this :)
I get this error after installing the widget on the home page:
Table '*****_****simvb4.pp_photos' doesn't exist
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
===============================================
Disregard above, figured that one out :)
Now I don't have a photos showing. Here is my code, what did I do wrong. Photopost is in the root public_html/photopost and my forum (vB) is here public_html/forums/
If I right click on empty image and select show image in new tab, I get "Photo not found in the database!"
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=\"photopost/showphoto.php/photo/" . $row['id'] . "\"><img src=\"photopost/data/" . $row['cat'] . "/thumbs/" . $row['bigimage'] . "\"></a><br /><a href=\"/photopost\">See more photos in the Gallery</a></div>";
}
Heldenverband
03-11-2010, 06:41 AM
Anybody use this in VBCMS ( vbdesigns.de ) ? I am searching for a similar module to show random images on VBCMS portal.
molieman
03-11-2010, 10:24 AM
I'm assuming this mod/widget is dead? I couldn't get it to work :( Looks great on the demo.... but that doesn't help me :(
Finished all steps but no output.
Heldenverband
03-11-2010, 03:58 PM
At the moment we try to solve this on a module in VBCMS ( vbdesigns.de )
how can i let the output appear on new winprint "<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>"; dows, new frame.
ZGeek
03-12-2010, 12:45 AM
Just in case anyone needs it. I've modified the query to exclude a category I have for NSFW images. This was based on help from the photopost forums. Thought I would share.
Change
$result = mysql_query("SELECT id,cat,bigimage FROM pp_photos order by rand() LIMIT 1" ) or die(mysql_error());
to
$result = mysql_query("SELECT id,cat,bigimage FROM pp_photos WHERE approved=1 AND cat NOT IN (502) order by rand() LIMIT 1" ) or die(mysql_error());
Just change the 502 to the category number you want to exclude. You should be able to add extra categories by adding numbers like so (502,503,504,505). But I am a n00b with php so I could be wrong.
wampforum
03-13-2010, 06:22 AM
hmm couldnt get this to show an actual picture - just the 'more pictures in the gallery' (the link of which worked ok)
shame
Wild Bronco
03-27-2010, 07:45 PM
I have 4 images in a horizontal line
Is it possible to show images in vertical line rather than horizontal?
Wild Bronco
03-28-2010, 08:17 PM
I have tried to change the div align code
and a few other things but I can't find the right way.
Heldenverband
03-29-2010, 07:25 AM
It works as VBCMS Modul at HERE (http://www.hangfliegen.de)
antboy
04-11-2010, 03:10 AM
ZippySLC - thanks for such a nice little hack works as described no problems
couple of things
1) i have found that i can increase the number of images shown by changing LIMIT to a higher number
this is great but i would love to have the images shown horizontally - is this possible ??
2) i also tried changing the order from random to date but strangely it showed it in the reverse order with the oldest images in the database showing first -
regards and thnx again Anthony
msolano
11-03-2010, 08:11 PM
If you are usign SEO in "Spider-Friendly URL's" you have to change the Select and the href code:
SELECT p.id,p.user,p.userid,p.cat,p.bigimage,p.title,c.ca tname,c.photos,c.posts
FROM pp_photos p LEFT JOIN pp_categories c ON c.id = p.cat
WHERE p.storecat = 0
AND p.cat NOT IN (500)
ORDER BY RAND()
LIMIT 1
And the href:
print "<div align=\"center\">
<a href=\"gallery_url/g" . $row['cat'] . "-" . $row['catname'] . ".html\">
<img ...
I'm not php programmer but I know about programming :) and I used the code from vb profile integration published in photopost official site.
It works in my site about aquariums (http://acuarios.desdecostarica.com)
pankaj1980
11-23-2010, 05:47 AM
Hi,
I am a newbie and want to use your widget. I have followed the steps as mentioned by you but i don't have Photopost tables. From where i can get this tables. Please help me on this.
Regards,
Pankaj
tattooz
01-08-2011, 08:27 PM
I was messing around with this code today and was able to get the widget to show HORIZONTALLY. Here is what I got and if you want to see it in action, visit http://www.modificationnation.com/ and under the big banner in the center you will see random members then FRESH INK & MODS.
You will need to add your database info at the top and change DOMAIN.COM to your URL. It should work no matter what your seo url's are set to but I don't know for sure. I have it set up to pull the newest photos from the gallery. If you would like it to pull random simply change "order by id DESC" to "order by rand()"
I am no coder, so I will do my absolute best to help you if it doesn't work
$host = 'localhost';
$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 id DESC LIMIT 8") or die(mysql_error());
print "<table align=\"center\" border=\"3\" bordercolor=\"black\" cellpadding=\"10\"><tr>";
while($row = mysql_fetch_array( $result )) {
print "<td><div align=\"center\"><a href=\"http://DOMAIN.COM/showphoto.php/photo/" . $row['id'] . "\"><img src=\"http://DOMAIN.COM/data/" . $row['cat'] . "/thumbs/" . $row['bigimage'] . "\" width=\"100px\" height=\"100px\"></a></div></td>";
}
print "</tr></table>";
$output .= ob_get_contents();
ob_end_clean();
rosebudtr
03-22-2011, 06:22 PM
<a href="http://www.dizilerimizden.com" target="_blank">www.dizilerimizden.com</a> . i added my cms
stl7997
04-03-2011, 07:12 PM
Works for me, thanks for this!
http://www.aerovacworld.com (left side of page)
sjm14
07-14-2011, 09:57 AM
Great! but I cannot get it to work I've installed it but I'm getting this message
Warning: mysql_connect() [function.mysql-connect]: Unknown MySQL server host 'database_server' (1) in [path]/packages/vbcms/widget/execphp.php(191) : eval()'d code on line 6
Can you point me in the right direction please, Dummies guide;-)
8thos
07-25-2011, 06:52 AM
Interesting.
bpi007
07-25-2011, 07:02 AM
Great! but I cannot get it to work I've installed it but I'm getting this message
Warning: mysql_connect() [function.mysql-connect]: Unknown MySQL server host 'database_server' (1) in [path]/packages/vbcms/widget/execphp.php(191) : eval()'d code on line 6
Can you point me in the right direction please, Dummies guide;-)
Have you change something in :
$host = 'localhost';
If yes, try like original post.
tommyxv
08-16-2011, 03:11 AM
isn't there a way to reference (require once or include) a custom php file that can store the database and password info instead of putting it into the widget itself? Don't want all admins to have that info.
glaive
04-18-2012, 02:24 PM
Here's an update to this code using vb db class type stuff I learned from migrating another project from vb 3.8x to v4.x. Now the "dangerous" db connection stuff is not available to any who read the code.
My version comments out two query executions you will need if your photopost db is different than your vb db.
I have also tweaked the query to fix an issue where the storage cat was different than the cat field and not 0 ( meaning catstore was not used.
My code builds on 9 random images in a simple table.
Note that I pull the cat out as cat_real and not just cat anymore.
I give this code freely to the original author and the community. I will try to mind the thread to help people and/or the OP. Thank you ZippySLC for getting my brain rolling on this.
You can see my version working here (http://www.cichlidforums.com/index.php).
ob_start();
// If your photo_post is not in the vbulletin db
//$sql_pp_db="USE Replace_with_PhotoPost_DB_name";
//$GLOBALS["vbulletin"]->db->query_read($sql_pp_db);
$sql_rp = <<<SQL
SELECT
id,
if(
storecat = 0,
cat,
if(
cat != storecat,
storecat,
cat
)
) as cat_real,
bigimage
FROM
pp_photos
ORDER BY rand()
LIMIT 9
SQL;
$result_rp = $GLOBALS["vbulletin"]->db->query_read($sql_rp);
echo "<center>";
echo "<table>";
$x = 0;
while(($array_rp = $GLOBALS["vbulletin"]->db->fetch_array($result_rp)))
{
if( $x == 0 )
{
echo "<tr>";
}
elseif( $x % 3 == 0 )
{
echo "</tr><tr>";
}
echo "<td>";
echo "<a href=\"/gallery/showphoto.php/photo/" . $array_rp["id"] . "\">";
echo "<img src=\"/gallery/data/" . $array_rp["cat_real"] . "/thumbs/" . $array_rp["bigimage"] . "\" />";
echo "</a></td>\n";
$x++;
}
echo "</tr></table><br /><a href=\"/gallery\">See more photos in the Gallery</a></center>\n";
// If your photo_post is not in the vbulletin db
//$sql_pp_db="USE Replace_with_vbulletin_DB_name";
//$GLOBALS["vbulletin"]->db->query_read($sql_pp_db);
$output .= ob_get_contents();
ob_end_clean();
Magnusson2u
05-22-2012, 01:52 AM
Photopost tables don't have the pp_ prefix, you'll need to alter the code to reflect your prefix.
Hi,
How/where would I place/define this?
$result+=+mysql_query("SELECT+id,cat,bigimage+FROM+pp_photos+order+by+ran d()+LIMIT+1"+)+or+die(mysql_error());+++
while($row+=+mysql_fetch_array(+$result+))+
Do I replace "pp_photos" with the name of my database?
Thanks in advance...
BGObsession
01-25-2014, 11:28 PM
Here's an update to this code using vb db class type stuff I learned from migrating another project from vb 3.8x to v4.x. Now the "dangerous" db connection stuff is not available to any who read the code.
My version comments out two query executions you will need if your photopost db is different than your vb db.
I have also tweaked the query to fix an issue where the storage cat was different than the cat field and not 0 ( meaning catstore was not used.
My code builds on 9 random images in a simple table.
Note that I pull the cat out as cat_real and not just cat anymore.
I give this code freely to the original author and the community. I will try to mind the thread to help people and/or the OP. Thank you ZippySLC for getting my brain rolling on this.
You can see my version working here (http://www.cichlidforums.com/index.php).
ob_start();
// If your photo_post is not in the vbulletin db
//$sql_pp_db="USE Replace_with_PhotoPost_DB_name";
//$GLOBALS["vbulletin"]->db->query_read($sql_pp_db);
$sql_rp = <<<SQL
SELECT
id,
if(
storecat = 0,
cat,
if(
cat != storecat,
storecat,
cat
)
) as cat_real,
bigimage
FROM
pp_photos
ORDER BY rand()
LIMIT 9
SQL;
$result_rp = $GLOBALS["vbulletin"]->db->query_read($sql_rp);
echo "<center>";
echo "<table>";
$x = 0;
while(($array_rp = $GLOBALS["vbulletin"]->db->fetch_array($result_rp)))
{
if( $x == 0 )
{
echo "<tr>";
}
elseif( $x % 3 == 0 )
{
echo "</tr><tr>";
}
echo "<td>";
echo "<a href=\"/gallery/showphoto.php/photo/" . $array_rp["id"] . "\">";
echo "<img src=\"/gallery/data/" . $array_rp["cat_real"] . "/thumbs/" . $array_rp["bigimage"] . "\" />";
echo "</a></td>\n";
$x++;
}
echo "</tr></table><br /><a href=\"/gallery\">See more photos in the Gallery</a></center>\n";
// If your photo_post is not in the vbulletin db
//$sql_pp_db="USE Replace_with_vbulletin_DB_name";
//$GLOBALS["vbulletin"]->db->query_read($sql_pp_db);
$output .= ob_get_contents();
ob_end_clean();
This is working great for me. If anyone wants to see it in action, you can see it in my left CMS column at http://www.bgobsession.com/content/
I changed the '9' to '1' as I want just a single random photo showing. Only questions I have are, does the photo change daily or should it be changing with every screen refresh (I expected it to change with every screen refresh but that doesn't seem to be the case). Also - is it possible to make the pulled image a little bigger or define the default width and height (the pulled image is smaller than I'd like for that widget)?
vBulletin® v3.8.12 by vBS, Copyright ©2000-2025, vBulletin Solutions Inc.