ipscone
08-16-2011, 11:08 PM
RE: vB CMS 4.1.5
I read someone else with the problem. It was titled "Solved" but I didn't see the solution. Then it was reported as a but.
I have the same problem and not sure how to fix it. I have a Widget for, that uses Direct PHP. It works perfectly, if I set "Disable Content Caching" to "Yes". But works one time, if I set it to "No" then requires waiting a refresh interval, before it works again. If I refresh before the interval is up, the execution fails.
The code is for a Featured Photo Widget, for integrating PhotoPost into vB CMS 4.1.5 Front Page.
I'm really not sure there is any point in showing the code, since I know it works when content caching is disabled. But people always ask. Here is the code.
ob_start();
// I removed some particulars to the path in the line below, but it's set correctly in my code.
require '/path/to/photopost/config-int.php';
// I deleted some password stuff here
$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 ==
////////////////////////////////////////////////////////////////////////////
function pp_get_ext( $filename )
{
return substr($filename, strrpos($filename,"."));
}
function pp_get_filename($filename)
{
return str_replace( pp_get_ext($filename), "", $filename );
}
function pp_is_image( $filename )
{
$mediatypes = array( ".jpg", ".gif", ".png", ".bmp" );
$ext = pp_get_ext( $filename );
if ( in_array(strtolower($ext), $mediatypes) )
{
return( true );
}
return( false );
}
function pp_is_multimedia( $filename )
{
$mediatypes = array( ".avi", ".mov", ".mpg", ".mpeg", ".swf", ".flv" );
$ext = pp_get_ext( $filename );
if ( in_array(strtolower($ext), $mediatypes) )
{
return( true );
}
return( false );
}
$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
ORDER BY views DESC";
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
ORDER BY date DESC";
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
ORDER BY RAND()";
}
$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 ( pp_is_image($photo)|| pp_is_multimedia($photo) )
{
if ( pp_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}-{$catname}.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 ( pp_is_multimedia($photo) )
{
$filenoext = pp_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="left" class="alt1">
<table cellpadding="0" cellspacing="0" border="0">
<tr>
$plink
</tr>
</table>
<font size="1" face="verdana,arial">by {$puser}<br />
? ? ?<br />
$catlink
$cphotos photos<br />$cposts comments<br /></font>
</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);
$pppro_imagebits = '<table cellpadding="$stylevar[cellpadding]" cellspacing="1" border="0" width="100%">'.$pppro_imagebits.'</tr></table>';
print "$pppro_imagebits";
$output=ob_get_contents();
ob_end_clean();
Like I said, without "Disable Content Cashing" set to "Yes" the code doesn't work right.
It should display 4 photos, at the top of the Front Page. After 1 refresh, it displays 1 and the right page column drops and goes to the center. It's busted unless I disable content caching.
Is there a fix to this problem?
I read someone else with the problem. It was titled "Solved" but I didn't see the solution. Then it was reported as a but.
I have the same problem and not sure how to fix it. I have a Widget for, that uses Direct PHP. It works perfectly, if I set "Disable Content Caching" to "Yes". But works one time, if I set it to "No" then requires waiting a refresh interval, before it works again. If I refresh before the interval is up, the execution fails.
The code is for a Featured Photo Widget, for integrating PhotoPost into vB CMS 4.1.5 Front Page.
I'm really not sure there is any point in showing the code, since I know it works when content caching is disabled. But people always ask. Here is the code.
ob_start();
// I removed some particulars to the path in the line below, but it's set correctly in my code.
require '/path/to/photopost/config-int.php';
// I deleted some password stuff here
$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 ==
////////////////////////////////////////////////////////////////////////////
function pp_get_ext( $filename )
{
return substr($filename, strrpos($filename,"."));
}
function pp_get_filename($filename)
{
return str_replace( pp_get_ext($filename), "", $filename );
}
function pp_is_image( $filename )
{
$mediatypes = array( ".jpg", ".gif", ".png", ".bmp" );
$ext = pp_get_ext( $filename );
if ( in_array(strtolower($ext), $mediatypes) )
{
return( true );
}
return( false );
}
function pp_is_multimedia( $filename )
{
$mediatypes = array( ".avi", ".mov", ".mpg", ".mpeg", ".swf", ".flv" );
$ext = pp_get_ext( $filename );
if ( in_array(strtolower($ext), $mediatypes) )
{
return( true );
}
return( false );
}
$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
ORDER BY views DESC";
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
ORDER BY date DESC";
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
ORDER BY RAND()";
}
$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 ( pp_is_image($photo)|| pp_is_multimedia($photo) )
{
if ( pp_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}-{$catname}.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 ( pp_is_multimedia($photo) )
{
$filenoext = pp_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="left" class="alt1">
<table cellpadding="0" cellspacing="0" border="0">
<tr>
$plink
</tr>
</table>
<font size="1" face="verdana,arial">by {$puser}<br />
? ? ?<br />
$catlink
$cphotos photos<br />$cposts comments<br /></font>
</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);
$pppro_imagebits = '<table cellpadding="$stylevar[cellpadding]" cellspacing="1" border="0" width="100%">'.$pppro_imagebits.'</tr></table>';
print "$pppro_imagebits";
$output=ob_get_contents();
ob_end_clean();
Like I said, without "Disable Content Cashing" set to "Yes" the code doesn't work right.
It should display 4 photos, at the top of the Front Page. After 1 refresh, it displays 1 and the right page column drops and goes to the center. It's busted unless I disable content caching.
Is there a fix to this problem?