//reviewsection-test
// Get latest news reviews
// First validate review fids:
$reviewsfids = "4";
if(is_array($reviewsfids))
{
foreach($reviewsfids as $fid)
{
$fid_array[] = intval($fid);
}
$reviewsfids = implode(',', $fid_array);
}
// And get them!
$query = $db->simple_select("forums", "*", "fid IN (".$reviewsfids.")");
while($forumrow = $db->fetch_array($query))
{
$forum[$forumrow['fid']] = $forumrow;
}
$numreviews = intval(5);
$numreviews = $numreviews + 5;
if(!$numreviews)
{
$numreviews = 10; // Default back to 10
}
$pids = '';
$tids = '';
$comma = '';
$query = $db->query("
SELECT p.pid, p.message, p.tid, p.smilieoff
FROM ".TABLE_PREFIX."posts p
LEFT JOIN ".TABLE_PREFIX."threads t ON (t.tid=p.tid)
WHERE t.fid IN (".$reviewsfids.") AND t.visible='1' AND t.closed NOT LIKE 'moved|%' AND t.firstpost=p.pid
ORDER BY t.dateline DESC
LIMIT 4, {$numreviews}"
);
while($getid = $db->fetch_array($query))
{
$pids .= ",'{$getid['pid']}'";
$tids .= ",'{$getid['tid']}'";
$posts[$getid['tid']] = $getid;
}
$pids = "pid IN(0{$pids})";
// Now lets fetch all of the attachments for these posts
$query = $db->simple_select("attachments", "*", $pids);
while($attachment = $db->fetch_array($query))
{
$attachcache[$attachment['pid']][$attachment['aid']] = $attachment;
}
if(is_array($forum))
{
foreach($forum as $fid => $forumrow)
{
$forumpermissions[$fid] = forum_permissions($fid);
}
}
$icon_cache = $cache->read("posticons");
$reviews = '';
$query = $db->query("
SELECT t.*, t.username AS threadusername, u.username, u.avatar, u.avatardimensions
FROM ".TABLE_PREFIX."threads t
LEFT JOIN ".TABLE_PREFIX."users u ON (u.uid = t.uid)
WHERE t.fid IN (".$reviewsfids.") AND t.tid IN (0{$tids}) AND t.visible='1' AND t.closed NOT LIKE 'moved|%'
ORDER BY t.dateline DESC
LIMIT 0, {$numreviews}"
);
while($review = $db->fetch_array($query))
{
// Make sure we can view this review
if($forumpermissions[$review['fid']]['canview'] == 0 || $forumpermissions[$review['fid']]['canviewthreads'] == 0 || $forumpermissions[$review['fid']]['canonlyviewownthreads'] == 1 && $review['uid'] != $mybb->user['uid'])
{
continue;
}
$review['message'] = $posts[$review['tid']]['message'];
$review['pid'] = $posts[$review['tid']]['pid'];
$review['smilieoff'] = $posts[$review['tid']]['smilieoff'];
$review['threadlink'] = get_thread_link($review['tid']);
if($review['uid'] == 0)
{
$profilelink = htmlspecialchars_uni($review['threadusername']);
}
else
{
$profilelink = build_profile_link($review['username'], $review['uid']);
}
if(!$review['username'])
{
$review['username'] = $review['threadusername'];
}
$review['subject'] = htmlspecialchars_uni($parser->parse_badwords($review['subject']));
if($review['icon'] > 0 && $icon_cache[$review['icon']])
{
$icon = $icon_cache[$review['icon']];
$icon = "<img src=\"{$icon['path']}\" alt=\"{$icon['name']}\" />";
}
else
{
$icon = " ";
}
if($review['avatar'] != '')
{
$avatar_dimensions = explode("|", $review['avatardimensions']);
if($avatar_dimensions[0] && $avatar_dimensions[1])
{
$avatar_width_height = "width=\"{$avatar_dimensions[0]}\" height=\"{$avatar_dimensions[1]}\"";
}
if (!stristr($review['avatar'], 'http://'))
{
$review['avatar'] = $mybb->settings['bburl'] . '/' . $review['avatar'];
}
$avatar = "<td class=\"trow1\" width=\"1\" align=\"center\" valign=\"top\"><img src=\"{$review['avatar']}\" alt=\"\" {$avatar_width_height} /></td>";
}
else
{
$avatar = '';
}
$anndate = my_date($mybb->settings['dateformat'], $review['dateline']);
$anntime = my_date($mybb->settings['timeformat'], $review['dateline']);
if($review['replies'])
{
eval("\$numcomments = \"".$templates->get("portal_review_numcomments")."\";");
}
else
{
eval("\$numcomments = \"".$templates->get("portal_review_numcomments_no")."\";");
$lastcomment = '';
}
$plugins->run_hooks("portal_review");
$parser_options = array(
"allow_html" => $forum[$review['fid']]['allowhtml'],
"allow_mycode" => $forum[$review['fid']]['allowmycode'],
"allow_smilies" => $forum[$review['fid']]['allowsmilies'],
"allow_imgcode" => $forum[$review['fid']]['allowimgcode'],
"allow_videocode" => $forum[$review['fid']]['allowvideocode'],
"filter_badwords" => 1
);
if($review['smilieoff'] == 1)
{
$parser_options['allow_smilies'] = 0;
}
$message2 = $parser->parse_message($review['message'], $parser_options);
$message2 = strip_tags($message2, '<img>');
//$excerpt = substr ($message2, 0, 500);
$excerpt = substr($message2.' ' , 0 , 501);
$excerpt = substr($excerpt , 0 , strrpos ($excerpt , ' '));
if(is_array($attachcache[$review['pid']]))
{ // This post has 1 or more attachments
$validationcount = 0;
$id = $review['pid'];
foreach($attachcache[$id] as $aid => $attachment)
{
if($attachment['visible'])
{ // There is an attachment thats visible!
$attachment['filename'] = htmlspecialchars_uni($attachment['filename']);
$attachment['filesize'] = get_friendly_size($attachment['filesize']);
$ext = get_extension($attachment['filename']);
if($ext == "jpeg" || $ext == "gif" || $ext == "bmp" || $ext == "png" || $ext == "jpg")
{
$isimage = true;
}
else
{
$isimage = false;
}
$attachment['icon'] = get_attachment_icon($ext);
// Support for [attachment=id] code
if(stripos($message, "[attachment=".$attachment['aid']."]") !== false)
{
if($attachment['thumbnail'] != "SMALL" && $attachment['thumbnail'] != '')
{ // We have a thumbnail to show (and its not the "SMALL" enough image
eval("\$attbit = \"".$templates->get("postbit_attachments_thumbnails_thumbnail")."\";");
}
elseif($attachment['thumbnail'] == "SMALL" && $forumpermissions[$review['fid']]['candlattachments'] == 1)
{
// Image is small enough to show - no thumbnail
eval("\$attbit = \"".$templates->get("postbit_attachments_images_image")."\";");
}
else
{
// Show standard link to attachment
eval("\$attbit = \"".$templates->get("postbit_attachments_attachment")."\";");
}
$message = preg_replace("#\[attachment=".$attachment['aid']."]#si", $attbit, $message);
}
else
{
if($attachment['thumbnail'] != "SMALL" && $attachment['thumbnail'] != '')
{ // We have a thumbnail to show
eval("\$post['thumblist'] .= \"".$templates->get("postbit_attachments_thumbnails_thumbnail")."\";");
if($tcount == 5)
{
$thumblist .= "<br />";
$tcount = 0;
}
++$tcount;
}
elseif($attachment['thumbnail'] == "SMALL" && $forumpermissions[$review['fid']]['candlattachments'] == 1)
{
// Image is small enough to show - no thumbnail
eval("\$post['imagelist'] .= \"".$templates->get("postbit_attachments_images_image")."\";");
}
else
{
eval("\$post['attachmentlist'] .= \"".$templates->get("postbit_attachments_attachment")."\";");
}
}
}
else
{
$validationcount++;
}
}
if($post['thumblist'])
{
eval("\$post['attachedthumbs'] = \"".$templates->get("postbit_attachments_thumbnails")."\";");
}
if($post['imagelist'])
{
eval("\$post['attachedimages'] = \"".$templates->get("postbit_attachments_images")."\";");
}
if($post['attachmentlist'] || $post['thumblist'] || $post['imagelist'])
{
eval("\$post['attachments'] = \"".$templates->get("postbit_attachments")."\";");
}
}
eval("\$reviews .= \"".$templates->get("portal_review")."\";");
unset($post);
}
//review 2 Block
// First validate review2 fids:
$reviews2fids = "6";
if(is_array($reviews2fids))
{
foreach($reviews2fids as $fid)
{
$fid_array[] = intval($fid);
}
$reviews2fids = implode(',', $fid_array);
}
// And get them!
$query = $db->simple_select("forums", "*", "fid IN (".$reviews2fids.")");
while($forumrow = $db->fetch_array($query))
{
$forum[$forumrow['fid']] = $forumrow;
}
$numreviews2 = intval(5);
if(!$numreviews2)
{
$numreviews2 = 10; // Default back to 10
}
$pids = '';
$tids = '';
$comma = '';
$query = $db->query("
SELECT p.pid, p.message, p.tid, p.smilieoff
FROM ".TABLE_PREFIX."posts p
LEFT JOIN ".TABLE_PREFIX."threads t ON (t.tid=p.tid)
WHERE t.fid IN (".$reviews2fids.") AND t.visible='1' AND t.closed NOT LIKE 'moved|%' AND t.firstpost=p.pid
ORDER BY t.dateline DESC
LIMIT 1, {$numreviews2}"
);
while($getid = $db->fetch_array($query))
{
$pids .= ",'{$getid['pid']}'";
$tids .= ",'{$getid['tid']}'";
$posts[$getid['tid']] = $getid;
}
$pids = "pid IN(0{$pids})";
// Now lets fetch all of the attachments for these posts
$query = $db->simple_select("attachments", "*", $pids);
while($attachment = $db->fetch_array($query))
{
$attachcache[$attachment['pid']][$attachment['aid']] = $attachment;
}
if(is_array($forum))
{
foreach($forum as $fid => $forumrow)
{
$forumpermissions[$fid] = forum_permissions($fid);
}
}
$icon_cache = $cache->read("posticons");
$reviews2 = '';
$query = $db->query("
SELECT t.*, t.username AS threadusername, u.username, u.avatar, u.avatardimensions
FROM ".TABLE_PREFIX."threads t
LEFT JOIN ".TABLE_PREFIX."users u ON (u.uid = t.uid)
WHERE t.fid IN (".$reviews2fids.") AND t.tid IN (0{$tids}) AND t.visible='1' AND t.closed NOT LIKE 'moved|%'
ORDER BY t.dateline DESC
LIMIT 0, {$numreviews2}"
);
while($review2 = $db->fetch_array($query))
{
// Make sure we can view this review2
if($forumpermissions[$review2['fid']]['canview'] == 0 || $forumpermissions[$review2['fid']]['canviewthreads'] == 0 || $forumpermissions[$review2['fid']]['canonlyviewownthreads'] == 1 && $review2['uid'] != $mybb->user['uid'])
{
continue;
}
$review2['message'] = $posts[$review2['tid']]['message'];
$review2['pid'] = $posts[$review2['tid']]['pid'];
$review2['smilieoff'] = $posts[$review2['tid']]['smilieoff'];
$review2['threadlink'] = get_thread_link($review2['tid']);
if($review2['uid'] == 0)
{
$profilelink = htmlspecialchars_uni($review2['threadusername']);
}
else
{
$profilelink = build_profile_link($review2['username'], $review2['uid']);
}
if(!$review2['username'])
{
$review2['username'] = $review2['threadusername'];
}
$review2['subject'] = htmlspecialchars_uni($parser->parse_badwords($review2['subject']));
if($review2['icon'] > 0 && $icon_cache[$review2['icon']])
{
$icon = $icon_cache[$review2['icon']];
$icon = "<img src=\"{$icon['path']}\" alt=\"{$icon['name']}\" />";
}
else
{
$icon = " ";
}
if($review2['avatar'] != '')
{
$avatar_dimensions = explode("|", $review2['avatardimensions']);
if($avatar_dimensions[0] && $avatar_dimensions[1])
{
$avatar_width_height = "width=\"{$avatar_dimensions[0]}\" height=\"{$avatar_dimensions[1]}\"";
}
if (!stristr($review2['avatar'], 'http://'))
{
$review2['avatar'] = $mybb->settings['bburl'] . '/' . $review2['avatar'];
}
$avatar = "<td class=\"trow1\" width=\"1\" align=\"center\" valign=\"top\"><img src=\"{$review2['avatar']}\" alt=\"\" {$avatar_width_height} /></td>";
}
else
{
$avatar = '';
}
$anndate = my_date($mybb->settings['dateformat'], $review2['dateline']);
$anntime = my_date($mybb->settings['timeformat'], $review2['dateline']);
if($review2['replies'])
{
eval("\$numcomments = \"".$templates->get("portal_review_numcomments")."\";");
}
else
{
eval("\$numcomments = \"".$templates->get("portal_review_numcomments_no")."\";");
$lastcomment = '';
}
$parser_options = array(
"allow_html" => $forum[$review2['fid']]['allowhtml'],
"allow_mycode" => $forum[$review2['fid']]['allowmycode'],
"allow_smilies" => $forum[$review2['fid']]['allowsmilies'],
"allow_imgcode" => $forum[$review2['fid']]['allowimgcode'],
"allow_videocode" => $forum[$review2['fid']]['allowvideocode'],
"filter_badwords" => 1
);
if($review2['smilieoff'] == 1)
{
$parser_options['allow_smilies'] = 0;
}
$message2 = $parser->parse_message($review2['message'], $parser_options);
$message2 = strip_tags($message2, '<img>');
// $excerpt = substr ($message2, 0, 500);
$excerpt = substr($message2.' ' , 0 , 501);
$excerpt = substr($excerpt , 0 , strrpos ($excerpt , ' '));
if(is_array($attachcache[$review2['pid']]))
{ // This post has 1 or more attachments
$validationcount = 0;
$id = $review2['pid'];
foreach($attachcache[$id] as $aid => $attachment)
{
if($attachment['visible'])
{ // There is an attachment thats visible!
$attachment['filename'] = htmlspecialchars_uni($attachment['filename']);
$attachment['filesize'] = get_friendly_size($attachment['filesize']);
$ext = get_extension($attachment['filename']);
if($ext == "jpeg" || $ext == "gif" || $ext == "bmp" || $ext == "png" || $ext == "jpg")
{
$isimage = true;
}
else
{
$isimage = false;
}
$attachment['icon'] = get_attachment_icon($ext);
// Support for [attachment=id] code
if(stripos($message, "[attachment=".$attachment['aid']."]") !== false)
{
if($attachment['thumbnail'] != "SMALL" && $attachment['thumbnail'] != '')
{ // We have a thumbnail to show (and its not the "SMALL" enough image
eval("\$attbit = \"".$templates->get("postbit_attachments_thumbnails_thumbnail")."\";");
}
elseif($attachment['thumbnail'] == "SMALL" && $forumpermissions[$review2['fid']]['candlattachments'] == 1)
{
// Image is small enough to show - no thumbnail
eval("\$attbit = \"".$templates->get("postbit_attachments_images_image")."\";");
}
else
{
// Show standard link to attachment
eval("\$attbit = \"".$templates->get("postbit_attachments_attachment")."\";");
}
$message = preg_replace("#\[attachment=".$attachment['aid']."]#si", $attbit, $message);
$excerpt = substr($message, 0, 500);
}
else
{
if($attachment['thumbnail'] != "SMALL" && $attachment['thumbnail'] != '')
{ // We have a thumbnail to show
eval("\$post['thumblist'] .= \"".$templates->get("postbit_attachments_thumbnails_thumbnail")."\";");
if($tcount == 5)
{
$thumblist .= "<br />";
$tcount = 0;
}
++$tcount;
}
elseif($attachment['thumbnail'] == "SMALL" && $forumpermissions[$review2['fid']]['candlattachments'] == 1)
{
// Image is small enough to show - no thumbnail
eval("\$post['imagelist'] .= \"".$templates->get("postbit_attachments_images_image")."\";");
}
else
{
eval("\$post['attachmentlist'] .= \"".$templates->get("postbit_attachments_attachment")."\";");
}
}
}
else
{
$validationcount++;
}
}
if($post['thumblist'])
{
eval("\$post['attachedthumbs'] = \"".$templates->get("postbit_attachments_thumbnails")."\";");
}
if($post['imagelist'])
{
eval("\$post['attachedimages'] = \"".$templates->get("postbit_attachments_images")."\";");
}
if($post['attachmentlist'] || $post['thumblist'] || $post['imagelist'])
{
eval("\$post['attachments'] = \"".$templates->get("postbit_attachments")."\";");
}
}
eval("\$reviews2 .= \"".$templates->get("portal_review_right")."\";");
unset($post);
}