Go Back   vb.org Archive > vBulletin Modifications > vBulletin 4.x Modifications > vBulletin 4.x Add-ons

Reply
 
Thread Tools
Photopost Pro Random Image Widget Details »»
Photopost Pro Random Image Widget
Version: 1.00, by ZippySLC ZippySLC is offline
Developer Last Online: Nov 2010 Show Printable Version Email this Page

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

Show Your Support

  • This modification may not be copied, reproduced or published elsewhere without author's permission.
Благодарность от:
andro140

Comments
  #72  
Old 03-22-2011, 06:22 PM
rosebudtr rosebudtr is offline
 
Join Date: May 2008
Posts: 5
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

<a href="http://www.dizilerimizden.com" target="_blank">www.dizilerimizden.com</a> . i added my cms
Reply With Quote
  #73  
Old 04-03-2011, 07:12 PM
stl7997 stl7997 is offline
 
Join Date: Nov 2009
Location: Germany
Posts: 61
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Works for me, thanks for this!

http://www.aerovacworld.com (left side of page)
Reply With Quote
  #74  
Old 07-14-2011, 09:57 AM
sjm14 sjm14 is offline
 
Join Date: Oct 2009
Posts: 5
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

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;-)
Reply With Quote
  #75  
Old 07-25-2011, 06:52 AM
8thos's Avatar
8thos 8thos is offline
 
Join Date: Aug 2010
Location: Pensacola, FL
Posts: 772
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Interesting.
Reply With Quote
  #76  
Old 07-25-2011, 07:02 AM
bpi007 bpi007 is offline
 
Join Date: Oct 2010
Location: Belgium
Posts: 38
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Quote:
Originally Posted by sjm14 View Post
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 :

Code:
$host  = 'localhost';
If yes, try like original post.
Reply With Quote
  #77  
Old 08-16-2011, 03:11 AM
tommyxv tommyxv is offline
 
Join Date: Feb 2005
Posts: 295
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

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.
Reply With Quote
  #78  
Old 04-18-2012, 02:24 PM
glaive glaive is offline
 
Join Date: Jan 2009
Posts: 13
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

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.

PHP Code:
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 == )
  {
    echo 
"<tr>";
  }
  elseif( 
$x == )
  {
    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(); 
Reply With Quote
  #79  
Old 05-22-2012, 01:52 AM
Magnusson2u Magnusson2u is offline
 
Join Date: Dec 2002
Posts: 28
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Quote:
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?

PHP Code:
$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+))+ 
Do I replace "pp_photos" with the name of my database?

Thanks in advance...
Reply With Quote
  #80  
Old 01-25-2014, 11:28 PM
BGObsession's Avatar
BGObsession BGObsession is offline
 
Join Date: Apr 2009
Posts: 199
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Quote:
Originally Posted by glaive View Post
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.

PHP Code:
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 == )
  {
    echo 
"<tr>";
  }
  elseif( 
$x == )
  {
    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)?
Reply With Quote
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT. The time now is 09:18 PM.


Powered by vBulletin® Version 3.8.12 by vBS
Copyright ©2000 - 2024, vBulletin Solutions Inc.
X vBulletin 3.8.12 by vBS Debug Information
  • Page Generation 0.04696 seconds
  • Memory Usage 2,362KB
  • Queries Executed 25 (?)
More Information
Template Usage:
  • (1)SHOWTHREAD
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_header_end
  • (1)ad_header_logo
  • (1)ad_navbar_below
  • (1)ad_showthread_beforeqr
  • (1)bbcode_code
  • (6)bbcode_php
  • (3)bbcode_quote
  • (1)footer
  • (1)forumjump
  • (1)forumrules
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (1)modsystem_post
  • (1)navbar
  • (4)navbar_link
  • (120)option
  • (1)pagenav
  • (1)pagenav_curpage
  • (2)pagenav_pagelink
  • (10)post_thanks_box
  • (1)post_thanks_box_bit
  • (10)post_thanks_button
  • (1)post_thanks_javascript
  • (1)post_thanks_navbar_search
  • (1)post_thanks_postbit
  • (10)post_thanks_postbit_info
  • (9)postbit
  • (10)postbit_onlinestatus
  • (10)postbit_wrapper
  • (1)spacer_close
  • (1)spacer_open
  • (1)tagbit_wrapper 

Phrase Groups Available:
  • global
  • inlinemod
  • postbit
  • posting
  • reputationlevel
  • showthread
Included Files:
  • ./showthread.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/functions_bigthree.php
  • ./includes/class_postbit.php
  • ./includes/class_bbcode.php
  • ./includes/functions_reputation.php
  • ./includes/functions_post_thanks.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
  • showthread_start
  • showthread_getinfo
  • forumjump
  • showthread_post_start
  • showthread_query_postids
  • showthread_query
  • bbcode_fetch_tags
  • bbcode_create
  • showthread_postbit_create
  • postbit_factory
  • postbit_display_start
  • post_thanks_function_post_thanks_off_start
  • post_thanks_function_post_thanks_off_end
  • post_thanks_function_fetch_thanks_start
  • fetch_musername
  • post_thanks_function_fetch_thanks_end
  • post_thanks_function_thanked_already_start
  • post_thanks_function_thanked_already_end
  • post_thanks_function_fetch_thanks_bit_start
  • post_thanks_function_show_thanks_date_start
  • post_thanks_function_show_thanks_date_end
  • post_thanks_function_fetch_thanks_bit_end
  • post_thanks_function_fetch_post_thanks_template_start
  • post_thanks_function_fetch_post_thanks_template_end
  • postbit_imicons
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • postbit_display_complete
  • post_thanks_function_can_thank_this_post_start
  • pagenav_page
  • pagenav_complete
  • tag_fetchbit_complete
  • forumrules
  • navbits
  • navbits_complete
  • showthread_complete