vb.org Archive

vb.org Archive (https://vborg.vbsupport.ru/index.php)
-   vBulletin 4.x Add-ons (https://vborg.vbsupport.ru/forumdisplay.php?f=245)
-   -   vBulletin CMS Widgets - Photopost Pro Random Image Widget (https://vborg.vbsupport.ru/showthread.php?t=234589)

ZippySLC 01-30-2010 10:00 PM

Photopost Pro Random Image Widget
 
1 Attachment(s)
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.)
    PHP Code:

    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


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:

PHP Code:

<a href=\"/gallery\">See more photos in the Gallery</a></div>"


Bergler 01-31-2010 10:40 PM

Quote:

Originally Posted by ZippySLC (Post 1971691)
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

Quote:

Originally Posted by tonmo (Post 1971710)
Great widget, thanks. Please note you're missing your closing /a tag after the link to the gallery - it should instead look like this:

PHP Code:

<a href=\"/gallery\">See more photos in the Gallery</a></div>"


Gah, you're right! Thanks!

Magz 01-31-2010 10:47 PM

Whats the fix if using _pp prefix?

ZippySLC 01-31-2010 10:51 PM

Quote:

Originally Posted by Bergler (Post 1971712)
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

Quote:

Originally Posted by Magz (Post 1971716)
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.

Magz 01-31-2010 10:57 PM

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

Quote:

Originally Posted by Magz (Post 1971725)
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.)

Magz 02-01-2010 12:17 AM

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

Quote:

Originally Posted by ZippySLC (Post 1971721)
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

Bergler 02-01-2010 02:42 AM

Quote:

Originally Posted by Bergler (Post 1971805)
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>

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.

Magz 02-01-2010 03:57 AM

Quote:

Originally Posted by Prasutagus (Post 1971859)
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

Quote:

Originally Posted by Magz (Post 1971864)
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

Quote:

Originally Posted by Bergler (Post 1971797)
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.

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

Quote:

Originally Posted by Drache (Post 1973326)
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 in the original authors thread might point you in the right direction.


All times are GMT. The time now is 09:31 AM.

Powered by vBulletin® Version 3.8.12 by vBS
Copyright ©2000 - 2025, vBulletin Solutions Inc.

X vBulletin 3.8.12 by vBS Debug Information
  • Page Generation 0.03292 seconds
  • Memory Usage 1,843KB
  • Queries Executed 10 (?)
More Information
Template Usage:
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_header_end
  • (1)ad_header_logo
  • (1)ad_navbar_below
  • (1)bbcode_code_printable
  • (5)bbcode_php_printable
  • (11)bbcode_quote_printable
  • (1)footer
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (6)option
  • (1)pagenav
  • (1)pagenav_curpage
  • (1)pagenav_pagelink
  • (1)post_thanks_navbar_search
  • (1)printthread
  • (40)printthreadbit
  • (1)spacer_close
  • (1)spacer_open 

Phrase Groups Available:
  • global
  • postbit
  • showthread
Included Files:
  • ./printthread.php
  • ./global.php
  • ./includes/init.php
  • ./includes/class_core.php
  • ./includes/config.php
  • ./includes/functions.php
  • ./includes/class_hook.php
  • ./includes/modsystem_functions.php
  • ./includes/class_bbcode_alt.php
  • ./includes/class_bbcode.php
  • ./includes/functions_bigthree.php 

Hooks Called:
  • init_startup
  • init_startup_session_setup_start
  • init_startup_session_setup_complete
  • cache_permissions
  • fetch_threadinfo_query
  • fetch_threadinfo
  • fetch_foruminfo
  • style_fetch
  • cache_templates
  • global_start
  • parse_templates
  • global_setup_complete
  • printthread_start
  • pagenav_page
  • pagenav_complete
  • bbcode_fetch_tags
  • bbcode_create
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • printthread_post
  • printthread_complete