View Full Version : Help with side blocks pease
Phil Dart
12-16-2016, 08:29 PM
Hello everyone - I wonder if someone could give some pointers please. I recently bought a forum that was already established, so I am pretty naive about the nuts and bolts behind the scene
The version is 4.2.3
There is currently a section that renders a selection of 4 random photos drawn from a gallery elsewhere. I would like to move it to a side block so I can use that space for something else. I stupidly thought I could copy and paste the template code into a side block and that would be that, having removed the title bar, but all that happens is that the side block renders some of the code, irrespective of whether I paste it as html or php
The template code that currently does the job is below.
<vb:if condition="!empty($pppro_imagebits)">
<div id="pppro"></div>
<ol class="floatcontainer">
<li class="forumbit_nopost">
<div class="forumhead foruminfo L1 collapse">
<a class="collapse" id="collapse_featurepal" href="forum.php#top"><img src="images/buttons/collapse_40b.png" alt="" /></a>
<h2><span class="forumtitle"> From the Gallery</span></h2>
</div>
<ol class="childforum">
<li class="forumbit_post">
<div id="featurepal" class="forumrow table">
<table class="tborder" cellpadding="0" cellspacing="0" border="0" width="100%" align="center">
<tr>
<td>
<br />
<table cellpadding="$stylevar[cellpadding]" cellspacing="1" border="0" width="100%">
<tr>
{vb:raw pppro_imagebits}
</tr>
</table>
<br />
</td>
</tr>
</table>
</div>
</li>
</ol>
</li>
</ol>
<br />
</vb:if>
Anyone kind enough to reply should assume I am an idiot with no knowledge. I am more than happy to be talked down to
Best wishes
Lynne
12-17-2016, 01:11 AM
What hook are you using to add the needed php code and what is the code you are adding there?
Phil Dart
12-17-2016, 08:01 AM
Thanks for your reply Lynne
I know nothing about hooks I'm afraid:confused: I simply pasted the code above into the block, then tried experimenting with it when I found it didn't work.
MarkFL
12-17-2016, 08:36 AM
Typically in a forum block, you need to return data, just as if you are operating inside a PHP function with local variables. You would need to build your data, then render your HTML containing the data you built, and return the finished HTML.
For example, here is the PHP code I use for a simple forum block that displays the users who have visited the site within the last 7 days:
global $vbulletin, $db;
$output = '<div class="restore"><ul>';
$users_visited = $vbulletin->db->query_read("
SELECT user.*
FROM " . TABLE_PREFIX . "user AS user
WHERE lastvisit >= " . TIMENOW . " - " . 7 * 86400 . "
AND usergroupid != 8
ORDER BY lastvisit DESC
");
$vcount = 0;
while ($visitor = $db->fetch_array($users_visited))
{
$output .= '<li>' . visitor_link($visitor, $visitor['lastvisit']) . '</li>';
$vcount++;
}
$output .= '</ul></div>';
$output = '<div style="text-align: center; font-weight: bold; margin-bottom: 1em">' . $vcount . ' Visiting Members</div>' . $output;
return $output;
function visitor_link($user_name, $dateline)
{
global $vbulletin;
$link = 'member.php?do=getinfo&username=' . $user_name['username'];
if ($user_name['displaygroupid'])
{
$groupid = $user_name['displaygroupid'];
}
else
{
$groupid = $user_name['usergroupid'];
}
$open_tag = $vbulletin->usergroupcache[$groupid]['opentag'];
$close_tag = $vbulletin->usergroupcache[$groupid]['closetag'];
$title = 'Last Visited: ' . vbdate($vbulletin->options['dateformat'], $dateline, 1) . ' at ' . vbdate($vbulletin->options['timeformat'], $dateline);
return '<a title="' . $title . '" href="' . $link . '">' . $open_tag . $user_name['username'] . $close_tag . '</a>';
}
scottkoz20
12-17-2016, 04:48 PM
Simple is a relative term Mark :)
However, I have found that using a table with a sidebar block does not output with the desired effect. My knowledge of writing PHP is limited as well. I would take some time and research past threads, someone might have already built out something that you are looking for (you might need to modify a bit)
CAG CheechDogg
12-17-2016, 10:45 PM
I have a forum side block that will pull a single image from any gallery you want ....
Replace the id which is highlighted in red with the id of the album which you want to use ...
You can also change the width of the sideblock as well, the width for this one is highlighted in red and its 225 px ...
// -- Widget Configuration --
$use_vB_thumbnail_size = false;
$use_custom_css = true;
$twidth = 225;
$limit = 1;
$albums_list = "17";
// -- Nothing to configure below this line --
if ($use_custom_css){
$pthumb = 'class="pthumb"';
$pcaption = 'class="pcaption"';
$pmore = 'class="pmore"';
$pstyle = '';
}else{
$pthumb = 'style="text-align:center;"';
$pcaption = 'style="text-align:center;font-style:italic;font-family: Times, serif;margin-bottom:10px;"';
$pmore = 'style="text-align:right;display:block;"';
$pstyle = 'style="border: 1px solid black;padding:4px;background: white;"';
}
if ($albums_list!="") $sup_cond = "AND alb.albumid IN ($albums_list)"; else $sup_cond ="";
ob_start();
require_once(DIR . '/includes/functions_album.php');
require_once(DIR . '/includes/functions_user.php');
$pic_get = vB::$db->query_read("
SELECT alb.albumid, att.attachmentid, att.userid, att.caption, att.dateline, att.state, fdt.filesize, IF(fdt.thumbnail_filesize > 0, 1, 0) AS hasthumbnail, fdt.thumbnail_dateline, fdt.thumbnail_width, fdt.thumbnail_height, u.username
FROM ".TABLE_PREFIX."album AS alb
LEFT JOIN ".TABLE_PREFIX."attachment AS att ON alb.albumid = att.contentid
LEFT JOIN ".TABLE_PREFIX."filedata AS fdt ON att.filedataid = fdt.filedataid
LEFT JOIN ".TABLE_PREFIX."user AS u ON att.userid = u.userid
WHERE alb.state = 'public' AND att.contenttypeid = '8' $sup_cond
ORDER BY rand(" . microtime()*1000000 . ")
LIMIT $limit");
$output_bits = "";
while($pic = vB::$db->fetch_array($pic_get))
{
$albuminfo = fetch_albuminfo($pic[albumid]);
$picture = prepare_pictureinfo_thumb($pic, $albuminfo);
if ($use_vB_thumbnail_size) $size = $picture[dimensions]; else $size = "width=$twidth";
$output_bits .= "<div $pthumb><a href=\"album.php?{$vbulletin->session->vars['sessionurl']}albumid={$pic[albumid]}&attachmentid={$picture[attachmentid]}\"><img $pstyle src=\"attachment.php?{$vbulletin->session->vars['sessionurl']}attachmentid={$picture[attachmentid]}&thumb=0&d={$picture[thumbnail_dateline]}\" alt=\"{$picture[caption_preview]}\" $size /></a>";
$output_bits .= "</div><div $pcaption>{$picture[caption_preview]} by {$pic[username]}</div>";
}
$output_bits .= '<span '.$pmore.'><a href="album.php" alt="To the albums">More...</a></span>';
$output = $output_bits;
ob_end_clean();
return $output;
Phil Dart
12-18-2016, 06:44 AM
Thanks for your replies guys.
The current setup renders four random thumbs drawn from multiple albums in Photopost Pro, so although I see where you're coming from CAG, it doesn't really work because there are many album lists not just one.
The code below works perfectly in the main body of the home page, and all I'm trying to do is make it work in a sideblock instead.
Mark, the data is built and works just fine where it is, I just have no understanding of hooks and returns and so on to make it work in a block. I know I am probably being particularly dim, but when you don't know, you just don't know.
<vb:if condition="!empty($pppro_imagebits)">
<div id="pppro"></div>
<ol class="floatcontainer">
<li class="forumbit_nopost">
// -- i know I can get rid of this <div> for the haeder, it won't be needed, and the ol and li classes too --
<div class="forumhead foruminfo L1 collapse">
<a class="collapse" id="collapse_featurepal" href="forum.php#top"><img src="images/buttons/collapse_40b.png" alt="" /></a>
<h2>
<span class="forumtitle">{vb:rawphrase pp_featured_photos}</span></h2>
</div>
<ol class="childforum">
<li class="forumbit_post">
<div id="featurepal" class="forumrow table">
<table class="tborder" cellpadding="0" cellspacing="0" border="0" width="100%" align="center">
<tr>
<td>
<br />
<table cellpadding="$stylevar[cellpadding]" cellspacing="1" border="0" width="100%">
<tr>
{vb:raw pppro_imagebits}
</tr>
</table>
<br />
</td>
</tr>
</table>
</div>
</li>
</ol>
</li>
</ol>
<br />
</vb:if>
CAG CheechDogg
12-18-2016, 11:14 PM
Ok try this ...
Make a new template and call it some like "block_html_random_photos"
Inside the template add this
<vb:if condition="is_member_of($bbuserinfo, 9)">
<li>
<div class="block smaller" id="pppro">
<div class="blocksubhead">
<a class="collapse" id="collapse_block_html_{vb:raw blockinfo.blockid}" href="{vb:raw relpath}#top"><img alt="" src="{vb:stylevar imgdir_button}/collapse_40b.png" width="16" height="16" id="collapseimg_html_{vb:raw blockinfo.blockid}"/></a>
<span class="blocktitle">{vb:rawphrase pp_featured_photos}</span>
</div>
<div class="widget_content blockbody floatcontainer">
<div id="block_html_{vb:raw blockinfo.blockid}" class="blockrow">
{vb:raw pppro_imagebits}
</div>
</div>
</div>
<div class="underblock"></div>
</li>
</vb:if>
Then make a new forum sideblock and call it "Random Photos"
Make it an html block then inside the content block add this
<div align="center"><!--{vb:raw pppro_imagebits}--></div>
or
<div align="center">{vb:raw pppro_imagebits}</div>
In the template to use add this "block_html_random_photos"
One of these should work ....
Let me know if it works for yah'
Phil Dart
12-19-2016, 09:06 AM
Thanks for your reply. Unfortuantely neither works. They both render nothing at all, but I'm really grateful to you for trying.
Lynne
12-19-2016, 04:08 PM
Are you putting this side block on the same page that the current random images are on? If you go to admincp > Products & Hooks > Manage Products, do you see anything titled that may be the modification being used here? If so, then go to admincp > Products & Hooks > Hook Manager and look up the plugins for that Product - can you give us the titles and then hook location for them? And, are you creating a Forum Block or are you trying to create a CMS Block?
cellarius
12-19-2016, 04:20 PM
As of yet, I'm still using Photopost, too. I can't really remember the installation process, but from what I can see one had to manually create a plugin at forumhome_complete, doing nothing but including the gallery's inc_features.php file.
In my case the single line is
include('./[dir_to_gallery]/inc_features.php');
Phil Dart
12-19-2016, 07:35 PM
Hi Lynne - thanks for your reply.
The block I'm trying to create is to go in an existing column of blocks on my home page. The controls for that column already exist within Forums & Moderators>Forum Blocks Manager, and I know the column works because there are already one or two blocks in it, both of which I have edited myself without issue.
The side block is on the home page, which is indeed the same page as the existing random images appear, but only because I was hoping to have the side block working before I switch off the existing images. I can do that now though if you think it may be causing a conflict
My version of vB is 4.2.3 - my control panel has a section labelled Plugins & Products. Looking in there I can see Manage Products, and Plugin Manager.
Manage Products shows me no useful information at all, beyond that it is PhotoPost Pro v8.2
Plugin Manager shows me various different options to explore and I've pasted a screenshot of those options below. There is no menu option Hooks Manager, but each of the options in the screenshot shows a hook. I can't identify which would be relevant though, and I'm not entirely certain that any of them are, but that may just be further proof of my total ignorance of the subject.
cellarius
12-20-2016, 06:22 AM
I'm not Lynne, but maybe you're reading my posts anyway ;)
As I said: It's at the hook forumhome_complete, so it's obviously "Photopost Featured Photos on Forumhome". Open it, and you'll find the code I posted above.
Phil Dart
12-20-2016, 08:09 AM
Hi Cellarius - sorry, I don't know how I missed your post.
Yes, Photopost Featured Photos on Forumhome - Doh!!! I did warn you I am dim. However , no code resembling yours within it I'm afraid.
require $vbulletin->options['pppath'].'/config-int.php';
$dbhost = $vbulletin->options['dbhost'];
$dbuser = $vbulletin->options['dbuser'];
$dbpass = $vbulletin->options['dbpass'];
$dbname = $vbulletin->options['db1'];
$link = mysql_connect ("$dbhost", "$dbuser", "$dbpass") or die('I cannot connect to the database.');
mysql_select_db ("$dbname")or die("Could not select photopost database");
// Number of photos to display
$num_display = 4;
// Number of columns (1 for vertical)
$columns = 4;
// which type of images do you want to show (random, most_view, latest)
$q_switch = "random";
// == END CONFIGURATION ==
////////////////////////////////////////////////////////////////////////////
if ( !isset($ViewPerm) )
{
if ( isset($bbuserinfo['usergroupid']) )
{
$mygroups = $bbuserinfo['usergroupid'];
if ( $bbuserinfo['membergroupids'] != "" )
{
$mygroups .= ",".$bbuserinfo['membergroupids'];
}
}
else
{
// vB3.5 uses $vbulletin
$mygroups = $vbulletin->userinfo['usergroupid'];
if ( $vbulletin->userinfo['membergroupids'] != "" )
{
$mygroups .= ",".$vbulletin->userinfo['membergroupids'];
}
}
$grouparr = explode( ",", $mygroups );
$resultb = mysql_query("SELECT id,ugnoview,password FROM {$pp_db_prefix}categories");
$ViewPerm = array();
while ( list( $catugid, $ugnoview, $catugpass ) = mysql_fetch_row($resultb) )
{
$noview=0;
$ViewPerm[$catugid] = 1;
$allnoview = explode( ",", $ugnoview );
foreach ($allnoview as $key)
{
if (in_array($key, $grouparr) )
{
$noview = 1;
}
}
if ( $noview == 0 && $catugpass == "" )
{
$ViewPerm[$catugid]=0;
}
}
}
$resultc = mysql_query("SELECT setting FROM {$pp_db_prefix}settings WHERE id=133");
list( $seotype ) = mysql_fetch_row($resultc);
$resultd = mysql_query("SELECT setting FROM {$pp_db_prefix}settings WHERE id=6");
list( $data_full ) = mysql_fetch_row($resultd);
//
// Featured Photos Code
// Follow down to End Feature Photos Code
//
switch ($q_switch)
{
case "most_view":
$query = "SELECT p.id,p.user,p.userid,p.cat,p.bigimage,p.title,c.ca tname,c.photos,c.posts
FROM {$pp_db_prefix}photos p
LEFT JOIN {$pp_db_prefix}categories c ON c.id = p.cat
WHERE p.storecat = 0 AND p.approved = 1 AND p.ismature = 0
ORDER BY views DESC LIMIT 25";
break;
case "latest":
$query = "SELECT p.id,p.user,p.userid,p.cat,p.bigimage,p.title,c.ca tname,c.photos,c.posts
FROM {$pp_db_prefix}photos p
LEFT JOIN {$pp_db_prefix}categories c ON c.id = p.cat
WHERE p.storecat = 0 AND p.approved = 1 AND p.ismature = 0
ORDER BY date DESC LIMIT 25";
break;
default:
$query = "SELECT p.id,p.user,p.userid,p.cat,p.bigimage,p.title,c.ca tname,c.photos,c.posts
FROM {$pp_db_prefix}photos p
LEFT JOIN {$pp_db_prefix}categories c ON c.id = p.cat
WHERE p.storecat = 0 AND p.approved = 1 AND p.ismature = 0
ORDER BY RAND() LIMIT 25";
}
$result = mysql_query($query) or die(mysql_error());
$counted = 0;
$countcol = 0;
$pppro_imagebits = null;
while (list($pid,$puser,$puserid,$pcat,$photo,$ptitle,$c atname,$cphotos,$cposts) = mysql_fetch_row($result))
{
if ( $seotype == "seo" )
{
$seocatname = photourlsafe( $catname );
$ptitle = photourlsafe( $ptitle );
}
if ( photo_is_image($photo)|| photo_is_multimedia($photo) )
{
if ( $ViewPerm[$pcat] == 1 )
{
continue;
}
if ( photo_is_image($photo) )
{
if ( $seotype == "seo" )
{
$plink = "<td><a href=\"{$url_path}/$catname/p{$pid}-{$ptitle}.html\"><img src=\"{$data_dir}/{$pcat}/thumbs/$photo\" border=\"0\" alt=\"\" /></a></td>";
$catlink = "<a href=\"{$url_path}/g{$pcat}-{$seocatname}.html\">$catname</a><br />";
}
else
{
$plink = "<td><a href=\"{$url_path}/showphoto.php?photo={$pid}\"><img src=\"{$data_dir}/{$pcat}/thumbs/$photo\" border=\"0\" alt=\"\" /></a></td>";
$catlink = "<a href=\"{$url_path}/showgallery.php?cat={$pcat}\">$catname</a><br />";
}
}
if ( photo_is_multimedia($photo) )
{
$filenoext = photo_get_filename( $photo );
$mmthumb = "{$data_dir}/$pcat/thumbs/$filenoext.jpg";
$dirthumb = "{$data_full}/$pcat/thumbs/$filenoext.jpg";
if ( !file_exists($dirthumb) )
{
$mmthumb = "{$url_path}/images/video.gif";
}
if ( $seotype == "seo" )
{
$plink = "<td><a href=\"{$url_path}/$catname/p{$pid}-{$ptitle}.html\"><img src=\"{$mmthumb}\" border=\"0\" alt=\"\" /></a></td>";
$catlink = "<a href=\"{$url_path}/g{$pcat}-{$catname}.html\">$catname</a><br />";
}
else
{
$plink = "<td><br /><a href=\"{$url_path}/showphoto.php?photo={$pid}\"><img src=\"{$mmthumb}\" border=\"0\" alt=\"\" /></a></td>";
$catlink = "<a href=\"{$url_path}/showgallery.php?cat={$pcat}\">$catname</a><br />";
}
}
// One box for each feature
$pppro_imagebits .= <<<PPPRINT
<td align="center" class="alt1">
<table cellpadding="0" cellspacing="0" border="0">
<tr>
$plink
</tr>
</table>
<font size="1" face="verdana,arial">by {$puser}<br />
? ? ?<br />
</td>
PPPRINT;
$counted++;
$countcol++;
}
// If we've reached our limit, quit
if ( $counted == $num_display )
{
break;
}
// If we need to end the column, do so.
if ( $countcol == $columns )
{
$pppro_imagebits .= <<<PPPRINT
</tr>
<tr>
PPPRINT;
$countcol = 0;
}
}
@mysql_free_result($result);
$templater = vB_Template::create('forumhome_addon');
$templater->register_page_templates();
$templater->register('pppro_imagebits', $pppro_imagebits);
$template_hook['forumhome_above_forums'] .= $templater->render();
cellarius
12-20-2016, 09:03 AM
OK, so that's practically the code that's in the included file, in my case. As I said, I'm on vB3 still, but it's basically the same.
You'd just need to find out which hook to use and probably adapt the template. Since I don't have a vB4 installation handy anymore, someone else will hopefully chime in here.
Phil Dart
12-23-2016, 08:47 AM
Is the hook not 'forumhome_above_forums' ?
vBulletin® v3.8.12 by vBS, Copyright ©2000-2025, vBulletin Solutions Inc.