SMFHacks.com
SMF Classifieds => Support => Topic started by: tank_fv101 on February 28, 2014, 09:33:30 am
-
Are you able to make a block that works with Simple Portal? I'd like it to randomly show items, and perhaps change after a set time to a different listing. Happy to pay for it.
Thanks!
-
For what SMF version?
-
I have SMF 2.0.6 and Simple Portal 2.3.5
-
Try this in a php block you have uncomment out one of the examples
// ClassifiedsBlock(2,4, 'random','vertical');
// ClassifiedsBlock(1,1, 'random','vertical');
ClassifiedsBlock(2,4, 'random','horizonstal');
function ClassifiedsBlock($rows = 4, $listings = 4, $type = 'recent', $category = 0, $format = 'vertical', $startHtml = '', $endHtml = '')
{
global $smcFunc, $scripturl, $txt, $modSettings, $boardurl, $user_info, $context, $sourcedir, $boarddir;
$rows = (int) $rows;
$listings = (int) $listings;
$category = (int) $category;
// Html Header
echo $startHtml;
// Load the language files
if (loadlanguage('classifieds') == false)
loadLanguage('classifieds', 'english');
$g_manage = allowedTo('smfclassifieds_manage');
$groupsdata = implode($user_info['groups'],',');
if (empty($modSettings['class_url']))
$modSettings['class_url'] = $boardurl . '/classifieds/';
if (empty($modSettings['class_path']))
$modSettings['class_path'] = $boarddir . '/classifieds/';
$maxrowlevel = $rows;
echo '<table cellspacing="0" cellpadding="5" border="0" align="center" width="100%">
';
// Check what type it is
$query = ' ';
switch($type)
{
case 'recent':
$query = "SELECT i.ID_LISTING, i.commenttotal,
i.primaryID_PICTURE, i.title, p.thumbfilename, p.remotefilename, i.currentbid,i.currency,
i.datelisted, i.views, i.is_auction, i.totalbids, i.ID_CAT, c.noprice, i.expiredate
FROM {db_prefix}class_listing as i
LEFT JOIN {db_prefix}class_listing_pic as p ON (i.primaryID_PICTURE = p.ID_PICTURE)
LEFT JOIN {db_prefix}class_cat as c ON (i.ID_CAT = c.ID_CAT)
LEFT JOIN {db_prefix}class_catperm AS r ON (r.ID_GROUP IN ($groupsdata) AND r.ID_CAT = i.ID_CAT)
WHERE i.removed = 0 AND i.approved = 1 AND (r.view IS NULL || r.view =1) GROUP BY i.ID_LISTING ORDER BY i.ID_LISTING DESC LIMIT $listings";
break;
case 'viewed':
$query = "SELECT i.ID_LISTING, i.commenttotal,
i.primaryID_PICTURE, i.title, p.thumbfilename, p.remotefilename, i.currentbid,i.currency,
i.datelisted, i.views, i.is_auction, i.totalbids, i.ID_CAT, c.noprice, i.expiredate
FROM {db_prefix}class_listing as i
LEFT JOIN {db_prefix}class_listing_pic as p ON (i.primaryID_PICTURE = p.ID_PICTURE)
LEFT JOIN {db_prefix}class_cat as c ON (i.ID_CAT = c.ID_CAT)
LEFT JOIN {db_prefix}class_catperm AS r ON (r.ID_GROUP IN ($groupsdata) AND r.ID_CAT = i.ID_CAT)
WHERE i.removed = 0 AND i.approved = 1 AND (r.view IS NULL || r.view =1) GROUP BY i.ID_LISTING ORDER BY i.views DESC LIMIT $listings";
break;
case 'random':
$query = "SELECT i.ID_LISTING, i.commenttotal,
i.primaryID_PICTURE, i.title, p.thumbfilename, p.remotefilename, i.currentbid,i.currency,
i.datelisted, i.views, i.is_auction, i.totalbids, i.ID_CAT, c.noprice, i.expiredate
FROM {db_prefix}class_listing as i
LEFT JOIN {db_prefix}class_listing_pic as p ON (i.primaryID_PICTURE = p.ID_PICTURE)
LEFT JOIN {db_prefix}class_cat as c ON (i.ID_CAT = c.ID_CAT)
LEFT JOIN {db_prefix}class_catperm AS r ON (r.ID_GROUP IN ($groupsdata) AND r.ID_CAT = i.ID_CAT)
WHERE i.removed = 0 AND i.approved = 1 AND (r.view IS NULL || r.view =1) GROUP BY i.ID_LISTING ORDER BY RAND() DESC LIMIT $listings";
break;
case 'mostcomments':
$query = "SELECT i.ID_LISTING, i.commenttotal,
i.primaryID_PICTURE, i.title, p.thumbfilename, p.remotefilename, i.currentbid,i.currency,
i.datelisted, i.views, i.is_auction, i.totalbids, i.ID_CAT, c.noprice, i.expiredate
FROM {db_prefix}class_listing as i
LEFT JOIN {db_prefix}class_listing_pic as p ON (i.primaryID_PICTURE = p.ID_PICTURE)
LEFT JOIN {db_prefix}class_cat as c ON (i.ID_CAT = c.ID_CAT)
LEFT JOIN {db_prefix}class_catperm AS r ON (r.ID_GROUP IN ($groupsdata) AND r.ID_CAT = i.ID_CAT)
WHERE i.removed = 0 AND i.approved = 1 AND (r.view IS NULL || r.view =1) GROUP BY i.ID_LISTING ORDER BY i.commenttotal DESC LIMIT $listings";
break;
case 'featured':
$query = "SELECT i.ID_LISTING, i.commenttotal,
i.primaryID_PICTURE, i.title, p.thumbfilename, p.remotefilename, i.currentbid,i.currency,
i.datelisted, i.views, i.is_auction, i.totalbids, i.ID_CAT, c.noprice, i.expiredate
FROM {db_prefix}class_listing as i
LEFT JOIN {db_prefix}class_listing_pic as p ON (i.primaryID_PICTURE = p.ID_PICTURE)
LEFT JOIN {db_prefix}class_cat as c ON (i.ID_CAT = c.ID_CAT)
LEFT JOIN {db_prefix}class_catperm AS r ON (r.ID_GROUP IN ($groupsdata) AND r.ID_CAT = i.ID_CAT)
WHERE i.removed = 0 AND i.approved = 1 AND i.featuredlisting = 1 AND (r.view IS NULL || r.view =1) GROUP BY i.ID_LISTING ORDER BY i.ID_LISTING DESC LIMIT $listings";
break;
}
// Execute the SQL query
$dbresult = $smcFunc['db_query']('', $query);
$rowlevel = 0;
while($row = $smcFunc['db_fetch_assoc']($dbresult))
{
if ($rowlevel == 0)
echo '<tr class="windowbg2">';
echo '<td align="center"><a href="', $scripturl, '?action=classifieds;sa=view;id=', $row['ID_LISTING'], '">', $row['title'], '</a><br />';
if (!empty($row['primaryID_PICTURE']) && $modSettings['class_catlist_showimage'])
{
if (empty($row['remotefilename']))
echo '<a href="', $scripturl, '?action=classifieds;sa=view;id=', $row['ID_LISTING'], '"><img src="', $modSettings['class_url'], $row['thumbfilename'], '" alt="" /></a><br />';
else
echo '<a href="', $scripturl, '?action=classifieds;sa=view;id=', $row['ID_LISTING'], '"><img src="', $row['remotefilename'], '" alt="" /></a><br />';
}
echo '<span class="smalltext">';
if (!empty($modSettings['class_catlist_currentprice']) && $row['noprice'] == 0)
echo $txt['class_text_price'] . SMFEzformatprice($row['currentbid'],$row['currency']) . '<br />';
if (!empty($modSettings['class_catlist_listingdate']))
{
if (!empty($modSettings['class_set_date_format_mdy']))
echo $txt['class_text_date'] . date($modSettings['class_set_date_format_mdy'],$row['datelisted']), ' ', date($modSettings['class_set_date_format_hia'],$row['datelisted']) . '<br />';
else
echo $txt['class_text_date'] . date("m/d/Y",$row['datelisted']) . ' ' . date("h:i a",$row['datelisted']) . '<br />';
}
if ($modSettings['class_catlist_timeleft'])
{
echo $txt['class_txt_time_left'] ;
echo ($row['expiredate'] == 0 ? $txt['class_expire_never'] : SMFezblockclass_cattimeleft( date("Y",$row['expiredate']), date("m",$row['expiredate']), date("d",$row['expiredate']), date("H",$row['expiredate']), date("i",$row['expiredate']),date("s",$row['expiredate'])) ) , '<br />';
}
if (!empty($modSettings['class_catlist_numofbids']) && $row['noprice'] == 0 && $row['is_auction'] == 1)
echo $txt['class_text_totalbids'] . ' ' . $row['totalbids'] . '<br />';
if (!empty($modSettings['class_catlist_comments']))
echo $txt['class_text_comments'] . ' (<a href="' . $scripturl . '?action=classifieds;sa=view;id=' . $row['ID_LISTING'] . '">' . $row['commenttotal'] . '</a>)<br />';
if ($g_manage)
{
if ($row['is_auction'] == 0)
echo ' <a href="' . $scripturl . '?action=classifieds;sa=editlisting;id=' . $row['ID_LISTING'] . '">' . $txt['class_text_edit'] . '</a>';
else
echo ' <a href="' . $scripturl . '?action=classifieds;sa=editauction;id=' . $row['ID_LISTING'] . '">' . $txt['class_text_edit'] . '</a>';
echo ' <a href="' . $scripturl . '?action=classifieds;sa=deletelisting;id=' . $row['ID_LISTING'] . '">' . $txt['class_text_delete'] . '</a>';
}
echo '</span></td>';
if($rowlevel < ($maxrowlevel-1))
$rowlevel++;
else
{
echo '</tr>';
$rowlevel = 0;
}
}
if($rowlevel !=0)
{
echo '</tr>';
}
echo '
</table><br />';
// Free the Mysql Resoruces
$smcFunc['db_free_result']($dbresult);
// Html Footer
echo $endHtml;
}
function SMFEzformatprice($price,$currency)
{
if ($currency == 'USD')
return '$' . number_format($price, 2, '.', '');
else if ($currency == 'GBP')
return '£' . number_format($price, 2, '.', '');
elseif ($currency == 'CAD')
return '$' . number_format($price, 2, '.', '');
elseif ($currency == 'AUD')
return '$' . number_format($price, 2, '.', '');
elseif ($currency == 'ZAR')
return 'R ' . number_format($price, 2, '-', '');
else
return $price . ' ' . $currency;
}
function SMFezblockclass_cattimeleft($year, $month, $day, $hour, $minute, $seconds)
{
global $txt;
// make a unix timestamp for the given date
$the_countdown_date = mktime($hour, $minute, $seconds, $month, $day, $year, -1);
// get current unix timestamp
$today = forum_time(false);
$difference = $the_countdown_date - $today;
if ($difference < 0) $difference = 0;
$days_left = floor($difference/60/60/24);
$hours_left = floor(($difference - $days_left*60*60*24)/60/60);
$minutes_left = floor(($difference - $days_left*60*60*24 - $hours_left*60*60)/60);
$seconds_left = floor(($difference - $days_left*60*60*24 - $hours_left*60*60 - $minutes_left*60));
if ($days_left == 0 && $hours_left == 0 && $minutes_left < 5 && ($minutes_left != 0 && $seconds_left !=0))
{
echo '<font color="#FF0000">';
}
echo '<span class="smalltext">';
if ($days_left > 0)
{
echo $days_left . 'd ' . $hours_left . 'h ' . $minutes_left . 'm';
}
else
{
if ($hours_left > 0)
echo $hours_left . 'h ' . $minutes_left . 'm';
else
{
if ($minutes_left > 0)
echo $minutes_left . 'm ' . $seconds_left . 's';
else
{
if ($seconds_left > 0)
echo $seconds_left . 's';
}
}
}
echo '</span>';
if ($days_left == 0 && $hours_left == 0 && $minutes_left < 5 && ($minutes_left != 0 && $seconds_left !=0))
{
echo '</font>';
}
}
-
Can you please help me with a Dream portal block? :-[
Same block, another portal--> http://dream-portal.net (http://dream-portal.net)
-
That block should work for Dream Portal too.
-
That block should work for Dream Portal too.
I don´t understand what to do so that I would have horizontal block with 4 random items.
I got error,
when I took away // -marks (which I believed uncommenting means)
-
What error did you get?
-
What error did you get?
I don't remember but with Dream Portal nothing appears, just white, blanc block.
Could you show me what to do that code, I mean what happens(what to do) when uncomment out that earlier code?
Maybe Im doing something wrong. :-[
-
Made some changes try this
// ClassifiedsBlock(2,4, 'random','vertical');
// ClassifiedsBlock(1,1, 'random','vertical');
ClassifiedsBlock(2,4, 'random','horizonstal');
function ClassifiedsBlock($rows = 4, $listings = 4, $type = 'recent', $category = 0, $format = 'vertical', $startHtml = '', $endHtml = '')
{
global $smcFunc, $scripturl, $txt, $modSettings, $boardurl, $user_info, $context, $sourcedir, $boarddir;
$rows = (int) $rows;
$listings = (int) $listings;
$category = (int) $category;
// Html Header
echo $startHtml;
// Load the language files
if (loadlanguage('classifieds') == false)
loadLanguage('classifieds', 'english');
$g_manage = allowedTo('smfclassifieds_manage');
$groupsdata = implode($user_info['groups'],',');
if (empty($modSettings['class_url']))
$modSettings['class_url'] = $boardurl . '/classifieds/';
if (empty($modSettings['class_path']))
$modSettings['class_path'] = $boarddir . '/classifieds/';
$maxrowlevel = $rows;
echo '<table cellspacing="0" cellpadding="5" border="0" align="center" width="100%">
';
// Check what type it is
$query = ' ';
switch($type)
{
case 'recent':
$query = "SELECT i.ID_LISTING, i.commenttotal,
i.primaryID_PICTURE, i.title, p.thumbfilename, p.remotefilename, i.currentbid,i.currency,
i.datelisted, i.views, i.is_auction, i.totalbids, i.ID_CAT, c.noprice, i.expiredate
FROM {db_prefix}class_listing as i
LEFT JOIN {db_prefix}class_listing_pic as p ON (i.primaryID_PICTURE = p.ID_PICTURE)
LEFT JOIN {db_prefix}class_cat as c ON (i.ID_CAT = c.ID_CAT)
LEFT JOIN {db_prefix}class_catperm AS r ON (r.ID_GROUP IN ($groupsdata) AND r.ID_CAT = i.ID_CAT)
WHERE i.removed = 0 AND i.approved = 1 AND (r.view IS NULL || r.view =1) GROUP BY i.ID_LISTING ORDER BY i.ID_LISTING DESC LIMIT $listings";
break;
case 'viewed':
$query = "SELECT i.ID_LISTING, i.commenttotal,
i.primaryID_PICTURE, i.title, p.thumbfilename, p.remotefilename, i.currentbid,i.currency,
i.datelisted, i.views, i.is_auction, i.totalbids, i.ID_CAT, c.noprice, i.expiredate
FROM {db_prefix}class_listing as i
LEFT JOIN {db_prefix}class_listing_pic as p ON (i.primaryID_PICTURE = p.ID_PICTURE)
LEFT JOIN {db_prefix}class_cat as c ON (i.ID_CAT = c.ID_CAT)
LEFT JOIN {db_prefix}class_catperm AS r ON (r.ID_GROUP IN ($groupsdata) AND r.ID_CAT = i.ID_CAT)
WHERE i.removed = 0 AND i.approved = 1 AND (r.view IS NULL || r.view =1) GROUP BY i.ID_LISTING ORDER BY i.views DESC LIMIT $listings";
break;
case 'random':
$query = "SELECT i.ID_LISTING, i.commenttotal,
i.primaryID_PICTURE, i.title, p.thumbfilename, p.remotefilename, i.currentbid,i.currency,
i.datelisted, i.views, i.is_auction, i.totalbids, i.ID_CAT, c.noprice, i.expiredate
FROM {db_prefix}class_listing as i
LEFT JOIN {db_prefix}class_listing_pic as p ON (i.primaryID_PICTURE = p.ID_PICTURE)
LEFT JOIN {db_prefix}class_cat as c ON (i.ID_CAT = c.ID_CAT)
LEFT JOIN {db_prefix}class_catperm AS r ON (r.ID_GROUP IN ($groupsdata) AND r.ID_CAT = i.ID_CAT)
WHERE i.removed = 0 AND i.approved = 1 AND (r.view IS NULL || r.view =1) GROUP BY i.ID_LISTING ORDER BY RAND() DESC LIMIT $listings";
break;
case 'mostcomments':
$query = "SELECT i.ID_LISTING, i.commenttotal,
i.primaryID_PICTURE, i.title, p.thumbfilename, p.remotefilename, i.currentbid,i.currency,
i.datelisted, i.views, i.is_auction, i.totalbids, i.ID_CAT, c.noprice, i.expiredate
FROM {db_prefix}class_listing as i
LEFT JOIN {db_prefix}class_listing_pic as p ON (i.primaryID_PICTURE = p.ID_PICTURE)
LEFT JOIN {db_prefix}class_cat as c ON (i.ID_CAT = c.ID_CAT)
LEFT JOIN {db_prefix}class_catperm AS r ON (r.ID_GROUP IN ($groupsdata) AND r.ID_CAT = i.ID_CAT)
WHERE i.removed = 0 AND i.approved = 1 AND (r.view IS NULL || r.view =1) GROUP BY i.ID_LISTING ORDER BY i.commenttotal DESC LIMIT $listings";
break;
case 'featured':
$query = "SELECT i.ID_LISTING, i.commenttotal,
i.primaryID_PICTURE, i.title, p.thumbfilename, p.remotefilename, i.currentbid,i.currency,
i.datelisted, i.views, i.is_auction, i.totalbids, i.ID_CAT, c.noprice, i.expiredate
FROM {db_prefix}class_listing as i
LEFT JOIN {db_prefix}class_listing_pic as p ON (i.primaryID_PICTURE = p.ID_PICTURE)
LEFT JOIN {db_prefix}class_cat as c ON (i.ID_CAT = c.ID_CAT)
LEFT JOIN {db_prefix}class_catperm AS r ON (r.ID_GROUP IN ($groupsdata) AND r.ID_CAT = i.ID_CAT)
WHERE i.removed = 0 AND i.approved = 1 AND i.featuredlisting = 1 AND (r.view IS NULL || r.view =1) GROUP BY i.ID_LISTING ORDER BY i.ID_LISTING DESC LIMIT $listings";
break;
}
// Execute the SQL query
$dbresult = $smcFunc['db_query']('', $query);
$rowlevel = 0;
while($row = $smcFunc['db_fetch_assoc']($dbresult))
{
if ($rowlevel == 0)
echo '<tr class="windowbg2">';
echo '<td align="center"><a href="', $scripturl, '?action=classifieds;sa=view;id=', $row['ID_LISTING'], '">', $row['title'], '</a><br />';
if (!empty($row['primaryID_PICTURE']) && $modSettings['class_catlist_showimage'])
{
if (empty($row['remotefilename']))
echo '<a href="', $scripturl, '?action=classifieds;sa=view;id=', $row['ID_LISTING'], '"><img src="', $modSettings['class_url'], $row['thumbfilename'], '" alt="" /></a><br />';
else
echo '<a href="', $scripturl, '?action=classifieds;sa=view;id=', $row['ID_LISTING'], '"><img src="', $row['remotefilename'], '" alt="" /></a><br />';
}
echo '<span class="smalltext">';
if (!empty($modSettings['class_catlist_currentprice']) && $row['noprice'] == 0)
echo $txt['class_text_price'] . SMFEzformatprice($row['currentbid'],$row['currency']) . '<br />';
if (!empty($modSettings['class_catlist_listingdate']))
{
if (!empty($modSettings['class_set_date_format_mdy']))
echo $txt['class_text_date'] . date($modSettings['class_set_date_format_mdy'],$row['datelisted']), ' ', date($modSettings['class_set_date_format_hia'],$row['datelisted']) . '<br />';
else
echo $txt['class_text_date'] . date("m/d/Y",$row['datelisted']) . ' ' . date("h:i a",$row['datelisted']) . '<br />';
}
if ($modSettings['class_catlist_timeleft'])
{
echo $txt['class_txt_time_left'] ;
echo ($row['expiredate'] == 0 ? $txt['class_expire_never'] : SMFezblockclass_cattimeleft( date("Y",$row['expiredate']), date("m",$row['expiredate']), date("d",$row['expiredate']), date("H",$row['expiredate']), date("i",$row['expiredate']),date("s",$row['expiredate'])) ) , '<br />';
}
if (!empty($modSettings['class_catlist_numofbids']) && $row['noprice'] == 0 && $row['is_auction'] == 1)
echo $txt['class_text_totalbids'] . ' ' . $row['totalbids'] . '<br />';
if (!empty($modSettings['class_catlist_comments']))
echo $txt['class_text_comments'] . ' (<a href="' . $scripturl . '?action=classifieds;sa=view;id=' . $row['ID_LISTING'] . '">' . $row['commenttotal'] . '</a>)<br />';
if ($g_manage)
{
if ($row['is_auction'] == 0)
echo ' <a href="' . $scripturl . '?action=classifieds;sa=editlisting;id=' . $row['ID_LISTING'] . '">' . $txt['class_text_edit'] . '</a>';
else
echo ' <a href="' . $scripturl . '?action=classifieds;sa=editauction;id=' . $row['ID_LISTING'] . '">' . $txt['class_text_edit'] . '</a>';
echo ' <a href="' . $scripturl . '?action=classifieds;sa=deletelisting;id=' . $row['ID_LISTING'] . '">' . $txt['class_text_delete'] . '</a>';
}
echo '</span></td>';
if($rowlevel < ($maxrowlevel-1))
$rowlevel++;
else
{
echo '</tr>';
$rowlevel = 0;
}
}
if($rowlevel !=0)
{
echo '</tr>';
}
echo '
</table><br />';
// Free the Mysql Resoruces
$smcFunc['db_free_result']($dbresult);
// Html Footer
echo $endHtml;
}
function SMFEzformatprice($price,$currency)
{
if ($currency == 'USD')
return '$' . number_format($price, 2, '.', '');
else if ($currency == 'GBP')
return '£' . number_format($price, 2, '.', '');
elseif ($currency == 'CAD')
return '$' . number_format($price, 2, '.', '');
elseif ($currency == 'AUD')
return '$' . number_format($price, 2, '.', '');
elseif ($currency == 'ZAR')
return 'R ' . number_format($price, 2, '-', '');
else
return $price . ' ' . $currency;
}
function SMFezblockclass_cattimeleft($year, $month, $day, $hour, $minute, $seconds)
{
global $txt;
// make a unix timestamp for the given date
$the_countdown_date = mktime($hour, $minute, $seconds, $month, $day, $year, -1);
// get current unix timestamp
$today = forum_time(false);
$difference = $the_countdown_date - $today;
if ($difference < 0) $difference = 0;
$days_left = floor($difference/60/60/24);
$hours_left = floor(($difference - $days_left*60*60*24)/60/60);
$minutes_left = floor(($difference - $days_left*60*60*24 - $hours_left*60*60)/60);
$seconds_left = floor(($difference - $days_left*60*60*24 - $hours_left*60*60 - $minutes_left*60));
if ($days_left == 0 && $hours_left == 0 && $minutes_left < 5 && ($minutes_left != 0 && $seconds_left !=0))
{
echo '<font color="#FF0000">';
}
echo '<span class="smalltext">';
if ($days_left > 0)
{
echo $days_left . 'd ' . $hours_left . 'h ' . $minutes_left . 'm';
}
else
{
if ($hours_left > 0)
echo $hours_left . 'h ' . $minutes_left . 'm';
else
{
if ($minutes_left > 0)
echo $minutes_left . 'm ' . $seconds_left . 's';
else
{
if ($seconds_left > 0)
echo $seconds_left . 's';
}
}
}
echo '</span>';
if ($days_left == 0 && $hours_left == 0 && $minutes_left < 5 && ($minutes_left != 0 && $seconds_left !=0))
{
echo '</font>';
}
}
-
That code works! :)
Thank you very much, you are the best!
-
Many thanks for that, works perfectly. I'll make a donation to you for your help. :)
-
Thanks!
-
A little problem I've seen. There is an accented 'A' before the Pound sign in the price. How do I get rid of it please?
(http://i67.photobucket.com/albums/h287/tank_fv101/Screenshot1-1.png) (http://s67.photobucket.com/user/tank_fv101/media/Screenshot1-1.png.html)
-
Try changing the code above
Find
return '£' . number_format($price, 2, '.', '');
Change to
return '&pound;'. number_format($price, 2, '.', '');
-
Hi,
I am using the code you had posted (pasted below) in an adseller pro ad (after last post). It is functionally working perfectly but I am getting the formatting error below. Can you assist?
On site example: http://www.standupzone.com/forum/index.php/topic,23689.msg238919/topicseen.html#new
// ClassifiedsBlock(2,4, 'random','vertical');
// ClassifiedsBlock(1,1, 'random','vertical');
ClassifiedsBlock(2,4, 'random','horizonstal');
function ClassifiedsBlock($rows = 4, $listings = 4, $type = 'recent', $category = 0, $format = 'vertical', $startHtml = '', $endHtml = '')
{
global $smcFunc, $scripturl, $txt, $modSettings, $boardurl, $user_info, $context, $sourcedir, $boarddir;
$rows = (int) $rows;
$listings = (int) $listings;
$category = (int) $category;
// Html Header
echo $startHtml;
// Load the language files
if (loadlanguage('classifieds') == false)
loadLanguage('classifieds', 'english');
$g_manage = allowedTo('smfclassifieds_manage');
$groupsdata = implode($user_info['groups'],',');
if (empty($modSettings['class_url']))
$modSettings['class_url'] = $boardurl . '/classifieds/';
if (empty($modSettings['class_path']))
$modSettings['class_path'] = $boarddir . '/classifieds/';
$maxrowlevel = $rows;
echo '<table cellspacing="0" cellpadding="5" border="0" align="center" width="100%">
';
// Check what type it is
$query = ' ';
switch($type)
{
case 'recent':
$query = "SELECT i.ID_LISTING, i.commenttotal,
i.primaryID_PICTURE, i.title, p.thumbfilename, p.remotefilename, i.currentbid,i.currency,
i.datelisted, i.views, i.is_auction, i.totalbids, i.ID_CAT, c.noprice, i.expiredate
FROM {db_prefix}class_listing as i
LEFT JOIN {db_prefix}class_listing_pic as p ON (i.primaryID_PICTURE = p.ID_PICTURE)
LEFT JOIN {db_prefix}class_cat as c ON (i.ID_CAT = c.ID_CAT)
LEFT JOIN {db_prefix}class_catperm AS r ON (r.ID_GROUP IN ($groupsdata) AND r.ID_CAT = i.ID_CAT)
WHERE i.removed = 0 AND i.approved = 1 AND (r.view IS NULL || r.view =1) GROUP BY i.ID_LISTING ORDER BY i.ID_LISTING DESC LIMIT $listings";
break;
case 'viewed':
$query = "SELECT i.ID_LISTING, i.commenttotal,
i.primaryID_PICTURE, i.title, p.thumbfilename, p.remotefilename, i.currentbid,i.currency,
i.datelisted, i.views, i.is_auction, i.totalbids, i.ID_CAT, c.noprice, i.expiredate
FROM {db_prefix}class_listing as i
LEFT JOIN {db_prefix}class_listing_pic as p ON (i.primaryID_PICTURE = p.ID_PICTURE)
LEFT JOIN {db_prefix}class_cat as c ON (i.ID_CAT = c.ID_CAT)
LEFT JOIN {db_prefix}class_catperm AS r ON (r.ID_GROUP IN ($groupsdata) AND r.ID_CAT = i.ID_CAT)
WHERE i.removed = 0 AND i.approved = 1 AND (r.view IS NULL || r.view =1) GROUP BY i.ID_LISTING ORDER BY i.views DESC LIMIT $listings";
break;
case 'random':
$query = "SELECT i.ID_LISTING, i.commenttotal,
i.primaryID_PICTURE, i.title, p.thumbfilename, p.remotefilename, i.currentbid,i.currency,
i.datelisted, i.views, i.is_auction, i.totalbids, i.ID_CAT, c.noprice, i.expiredate
FROM {db_prefix}class_listing as i
LEFT JOIN {db_prefix}class_listing_pic as p ON (i.primaryID_PICTURE = p.ID_PICTURE)
LEFT JOIN {db_prefix}class_cat as c ON (i.ID_CAT = c.ID_CAT)
LEFT JOIN {db_prefix}class_catperm AS r ON (r.ID_GROUP IN ($groupsdata) AND r.ID_CAT = i.ID_CAT)
WHERE i.removed = 0 AND i.approved = 1 AND (r.view IS NULL || r.view =1) GROUP BY i.ID_LISTING ORDER BY RAND() DESC LIMIT $listings";
break;
case 'mostcomments':
$query = "SELECT i.ID_LISTING, i.commenttotal,
i.primaryID_PICTURE, i.title, p.thumbfilename, p.remotefilename, i.currentbid,i.currency,
i.datelisted, i.views, i.is_auction, i.totalbids, i.ID_CAT, c.noprice, i.expiredate
FROM {db_prefix}class_listing as i
LEFT JOIN {db_prefix}class_listing_pic as p ON (i.primaryID_PICTURE = p.ID_PICTURE)
LEFT JOIN {db_prefix}class_cat as c ON (i.ID_CAT = c.ID_CAT)
LEFT JOIN {db_prefix}class_catperm AS r ON (r.ID_GROUP IN ($groupsdata) AND r.ID_CAT = i.ID_CAT)
WHERE i.removed = 0 AND i.approved = 1 AND (r.view IS NULL || r.view =1) GROUP BY i.ID_LISTING ORDER BY i.commenttotal DESC LIMIT $listings";
break;
case 'featured':
$query = "SELECT i.ID_LISTING, i.commenttotal,
i.primaryID_PICTURE, i.title, p.thumbfilename, p.remotefilename, i.currentbid,i.currency,
i.datelisted, i.views, i.is_auction, i.totalbids, i.ID_CAT, c.noprice, i.expiredate
FROM {db_prefix}class_listing as i
LEFT JOIN {db_prefix}class_listing_pic as p ON (i.primaryID_PICTURE = p.ID_PICTURE)
LEFT JOIN {db_prefix}class_cat as c ON (i.ID_CAT = c.ID_CAT)
LEFT JOIN {db_prefix}class_catperm AS r ON (r.ID_GROUP IN ($groupsdata) AND r.ID_CAT = i.ID_CAT)
WHERE i.removed = 0 AND i.approved = 1 AND i.featuredlisting = 1 AND (r.view IS NULL || r.view =1) GROUP BY i.ID_LISTING ORDER BY i.ID_LISTING DESC LIMIT $listings";
break;
}
// Execute the SQL query
$dbresult = $smcFunc['db_query']('', $query);
$rowlevel = 0;
while($row = $smcFunc['db_fetch_assoc']($dbresult))
{
if ($rowlevel == 0)
echo '<tr class="windowbg2">';
echo '<td align="center"><a href="', $scripturl, '?action=classifieds;sa=view;id=', $row['ID_LISTING'], '">', $row['title'], '</a><br />';
if (!empty($row['primaryID_PICTURE']) && $modSettings['class_catlist_showimage'])
{
if (empty($row['remotefilename']))
echo '<a href="', $scripturl, '?action=classifieds;sa=view;id=', $row['ID_LISTING'], '"><img src="', $modSettings['class_url'], $row['thumbfilename'], '" alt="" /></a><br />';
else
echo '<a href="', $scripturl, '?action=classifieds;sa=view;id=', $row['ID_LISTING'], '"><img src="', $row['remotefilename'], '" alt="" /></a><br />';
}
echo '<span class="smalltext">';
if (!empty($modSettings['class_catlist_currentprice']) && $row['noprice'] == 0)
echo $txt['class_text_price'] . SMFEzformatprice($row['currentbid'],$row['currency']) . '<br />';
if (!empty($modSettings['class_catlist_listingdate']))
{
if (!empty($modSettings['class_set_date_format_mdy']))
echo $txt['class_text_date'] . date($modSettings['class_set_date_format_mdy'],$row['datelisted']), ' ', date($modSettings['class_set_date_format_hia'],$row['datelisted']) . '<br />';
else
echo $txt['class_text_date'] . date("m/d/Y",$row['datelisted']) . ' ' . date("h:i a",$row['datelisted']) . '<br />';
}
if ($modSettings['class_catlist_timeleft'])
{
echo $txt['class_txt_time_left'] ;
echo ($row['expiredate'] == 0 ? $txt['class_expire_never'] : SMFezblockclass_cattimeleft( date("Y",$row['expiredate']), date("m",$row['expiredate']), date("d",$row['expiredate']), date("H",$row['expiredate']), date("i",$row['expiredate']),date("s",$row['expiredate'])) ) , '<br />';
}
if (!empty($modSettings['class_catlist_numofbids']) && $row['noprice'] == 0 && $row['is_auction'] == 1)
echo $txt['class_text_totalbids'] . ' ' . $row['totalbids'] . '<br />';
if (!empty($modSettings['class_catlist_comments']))
echo $txt['class_text_comments'] . ' (<a href="' . $scripturl . '?action=classifieds;sa=view;id=' . $row['ID_LISTING'] . '">' . $row['commenttotal'] . '</a>)<br />';
if ($g_manage)
{
if ($row['is_auction'] == 0)
echo ' <a href="' . $scripturl . '?action=classifieds;sa=editlisting;id=' . $row['ID_LISTING'] . '">' . $txt['class_text_edit'] . '</a>';
else
echo ' <a href="' . $scripturl . '?action=classifieds;sa=editauction;id=' . $row['ID_LISTING'] . '">' . $txt['class_text_edit'] . '</a>';
echo ' <a href="' . $scripturl . '?action=classifieds;sa=deletelisting;id=' . $row['ID_LISTING'] . '">' . $txt['class_text_delete'] . '</a>';
}
echo '</span></td>';
if($rowlevel < ($maxrowlevel-1))
$rowlevel++;
else
{
echo '</tr>';
$rowlevel = 0;
}
}
if($rowlevel !=0)
{
echo '</tr>';
}
echo '
</table><br />';
// Free the Mysql Resoruces
$smcFunc['db_free_result']($dbresult);
// Html Footer
echo $endHtml;
}
function SMFEzformatprice($price,$currency)
{
if ($currency == 'USD')
return '$' . number_format($price, 2, '.', '');
else if ($currency == 'GBP')
return '£' . number_format($price, 2, '.', '');
elseif ($currency == 'CAD')
return '$' . number_format($price, 2, '.', '');
elseif ($currency == 'AUD')
return '$' . number_format($price, 2, '.', '');
elseif ($currency == 'ZAR')
return 'R ' . number_format($price, 2, '-', '');
else
return $price . ' ' . $currency;
}
function SMFezblockclass_cattimeleft($year, $month, $day, $hour, $minute, $seconds)
{
global $txt;
// make a unix timestamp for the given date
$the_countdown_date = mktime($hour, $minute, $seconds, $month, $day, $year, -1);
// get current unix timestamp
$today = forum_time(false);
$difference = $the_countdown_date - $today;
if ($difference < 0) $difference = 0;
$days_left = floor($difference/60/60/24);
$hours_left = floor(($difference - $days_left*60*60*24)/60/60);
$minutes_left = floor(($difference - $days_left*60*60*24 - $hours_left*60*60)/60);
$seconds_left = floor(($difference - $days_left*60*60*24 - $hours_left*60*60 - $minutes_left*60));
if ($days_left == 0 && $hours_left == 0 && $minutes_left < 5 && ($minutes_left != 0 && $seconds_left !=0))
{
echo '<font color="#FF0000">';
}
echo '<span class="smalltext">';
if ($days_left > 0)
{
echo $days_left . 'd ' . $hours_left . 'h ' . $minutes_left . 'm';
}
else
{
if ($hours_left > 0)
echo $hours_left . 'h ' . $minutes_left . 'm';
else
{
if ($minutes_left > 0)
echo $minutes_left . 'm ' . $seconds_left . 's';
else
{
if ($seconds_left > 0)
echo $seconds_left . 's';
}
}
}
echo '</span>';
if ($days_left == 0 && $hours_left == 0 && $minutes_left < 5 && ($minutes_left != 0 && $seconds_left !=0))
{
echo '</font>';
}
}
-
What is the error how do you want it to appear?
-
What is the error how do you want it to appear?
I am unsure why but the title bar (I am unsure what it is called but I "arrowed" it in the image I uploaded above) is showing up below the content rather than above it. Thanks as always.
-
...or would that formatting be coding form the Adseller Pro side?
-
Attach your themes display.template.php
-
OK, attached.
-
That first link on your page I can't see since not open to guests.
-
Apologies, please try this one:
http://www.standupzone.com/forum/index.php/topic,23697.0.html
-
This should fix it.
-
I uploaded that one but it knocked out the classifieds insertion on that page. I left it live so you can have a look. I appreciate your efforts!
-
Try again
-
That one produced that layout error in the attachment.
-
We can try this without any formatting
-
Works for me. Thanks again!
-
This works for me also.
SMF 2.0.9, SimplePortal 2.3.6
-
Hi, can I change the height and width, inside this code? Like "max_width" and "max_height"??
/Dan
Try this in a php block you have uncomment out one of the examples
// ClassifiedsBlock(2,4, 'random','vertical');
// ClassifiedsBlock(1,1, 'random','vertical');
ClassifiedsBlock(2,4, 'random','horizonstal');
function ClassifiedsBlock($rows = 4, $listings = 4, $type = 'recent', $category = 0, $format = 'vertical', $startHtml = '', $endHtml = '')
{
global $smcFunc, $scripturl, $txt, $modSettings, $boardurl, $user_info, $context, $sourcedir, $boarddir;
$rows = (int) $rows;
$listings = (int) $listings;
$category = (int) $category;
// Html Header
echo $startHtml;
// Load the language files
if (loadlanguage('classifieds') == false)
loadLanguage('classifieds', 'english');
$g_manage = allowedTo('smfclassifieds_manage');
$groupsdata = implode($user_info['groups'],',');
if (empty($modSettings['class_url']))
$modSettings['class_url'] = $boardurl . '/classifieds/';
if (empty($modSettings['class_path']))
$modSettings['class_path'] = $boarddir . '/classifieds/';
$maxrowlevel = $rows;
echo '<table cellspacing="0" cellpadding="5" border="0" align="center" width="100%">
';
// Check what type it is
$query = ' ';
switch($type)
{
case 'recent':
$query = "SELECT i.ID_LISTING, i.commenttotal,
i.primaryID_PICTURE, i.title, p.thumbfilename, p.remotefilename, i.currentbid,i.currency,
i.datelisted, i.views, i.is_auction, i.totalbids, i.ID_CAT, c.noprice, i.expiredate
FROM {db_prefix}class_listing as i
LEFT JOIN {db_prefix}class_listing_pic as p ON (i.primaryID_PICTURE = p.ID_PICTURE)
LEFT JOIN {db_prefix}class_cat as c ON (i.ID_CAT = c.ID_CAT)
LEFT JOIN {db_prefix}class_catperm AS r ON (r.ID_GROUP IN ($groupsdata) AND r.ID_CAT = i.ID_CAT)
WHERE i.removed = 0 AND i.approved = 1 AND (r.view IS NULL || r.view =1) GROUP BY i.ID_LISTING ORDER BY i.ID_LISTING DESC LIMIT $listings";
break;
case 'viewed':
$query = "SELECT i.ID_LISTING, i.commenttotal,
i.primaryID_PICTURE, i.title, p.thumbfilename, p.remotefilename, i.currentbid,i.currency,
i.datelisted, i.views, i.is_auction, i.totalbids, i.ID_CAT, c.noprice, i.expiredate
FROM {db_prefix}class_listing as i
LEFT JOIN {db_prefix}class_listing_pic as p ON (i.primaryID_PICTURE = p.ID_PICTURE)
LEFT JOIN {db_prefix}class_cat as c ON (i.ID_CAT = c.ID_CAT)
LEFT JOIN {db_prefix}class_catperm AS r ON (r.ID_GROUP IN ($groupsdata) AND r.ID_CAT = i.ID_CAT)
WHERE i.removed = 0 AND i.approved = 1 AND (r.view IS NULL || r.view =1) GROUP BY i.ID_LISTING ORDER BY i.views DESC LIMIT $listings";
break;
case 'random':
$query = "SELECT i.ID_LISTING, i.commenttotal,
i.primaryID_PICTURE, i.title, p.thumbfilename, p.remotefilename, i.currentbid,i.currency,
i.datelisted, i.views, i.is_auction, i.totalbids, i.ID_CAT, c.noprice, i.expiredate
FROM {db_prefix}class_listing as i
LEFT JOIN {db_prefix}class_listing_pic as p ON (i.primaryID_PICTURE = p.ID_PICTURE)
LEFT JOIN {db_prefix}class_cat as c ON (i.ID_CAT = c.ID_CAT)
LEFT JOIN {db_prefix}class_catperm AS r ON (r.ID_GROUP IN ($groupsdata) AND r.ID_CAT = i.ID_CAT)
WHERE i.removed = 0 AND i.approved = 1 AND (r.view IS NULL || r.view =1) GROUP BY i.ID_LISTING ORDER BY RAND() DESC LIMIT $listings";
break;
case 'mostcomments':
$query = "SELECT i.ID_LISTING, i.commenttotal,
i.primaryID_PICTURE, i.title, p.thumbfilename, p.remotefilename, i.currentbid,i.currency,
i.datelisted, i.views, i.is_auction, i.totalbids, i.ID_CAT, c.noprice, i.expiredate
FROM {db_prefix}class_listing as i
LEFT JOIN {db_prefix}class_listing_pic as p ON (i.primaryID_PICTURE = p.ID_PICTURE)
LEFT JOIN {db_prefix}class_cat as c ON (i.ID_CAT = c.ID_CAT)
LEFT JOIN {db_prefix}class_catperm AS r ON (r.ID_GROUP IN ($groupsdata) AND r.ID_CAT = i.ID_CAT)
WHERE i.removed = 0 AND i.approved = 1 AND (r.view IS NULL || r.view =1) GROUP BY i.ID_LISTING ORDER BY i.commenttotal DESC LIMIT $listings";
break;
case 'featured':
$query = "SELECT i.ID_LISTING, i.commenttotal,
i.primaryID_PICTURE, i.title, p.thumbfilename, p.remotefilename, i.currentbid,i.currency,
i.datelisted, i.views, i.is_auction, i.totalbids, i.ID_CAT, c.noprice, i.expiredate
FROM {db_prefix}class_listing as i
LEFT JOIN {db_prefix}class_listing_pic as p ON (i.primaryID_PICTURE = p.ID_PICTURE)
LEFT JOIN {db_prefix}class_cat as c ON (i.ID_CAT = c.ID_CAT)
LEFT JOIN {db_prefix}class_catperm AS r ON (r.ID_GROUP IN ($groupsdata) AND r.ID_CAT = i.ID_CAT)
WHERE i.removed = 0 AND i.approved = 1 AND i.featuredlisting = 1 AND (r.view IS NULL || r.view =1) GROUP BY i.ID_LISTING ORDER BY i.ID_LISTING DESC LIMIT $listings";
break;
}
// Execute the SQL query
$dbresult = $smcFunc['db_query']('', $query);
$rowlevel = 0;
while($row = $smcFunc['db_fetch_assoc']($dbresult))
{
if ($rowlevel == 0)
echo '<tr class="windowbg2">';
echo '<td align="center"><a href="', $scripturl, '?action=classifieds;sa=view;id=', $row['ID_LISTING'], '">', $row['title'], '</a><br />';
if (!empty($row['primaryID_PICTURE']) && $modSettings['class_catlist_showimage'])
{
if (empty($row['remotefilename']))
echo '<a href="', $scripturl, '?action=classifieds;sa=view;id=', $row['ID_LISTING'], '"><img src="', $modSettings['class_url'], $row['thumbfilename'], '" alt="" /></a><br />';
else
echo '<a href="', $scripturl, '?action=classifieds;sa=view;id=', $row['ID_LISTING'], '"><img src="', $row['remotefilename'], '" alt="" /></a><br />';
}
echo '<span class="smalltext">';
if (!empty($modSettings['class_catlist_currentprice']) && $row['noprice'] == 0)
echo $txt['class_text_price'] . SMFEzformatprice($row['currentbid'],$row['currency']) . '<br />';
if (!empty($modSettings['class_catlist_listingdate']))
{
if (!empty($modSettings['class_set_date_format_mdy']))
echo $txt['class_text_date'] . date($modSettings['class_set_date_format_mdy'],$row['datelisted']), ' ', date($modSettings['class_set_date_format_hia'],$row['datelisted']) . '<br />';
else
echo $txt['class_text_date'] . date("m/d/Y",$row['datelisted']) . ' ' . date("h:i a",$row['datelisted']) . '<br />';
}
if ($modSettings['class_catlist_timeleft'])
{
echo $txt['class_txt_time_left'] ;
echo ($row['expiredate'] == 0 ? $txt['class_expire_never'] : SMFezblockclass_cattimeleft( date("Y",$row['expiredate']), date("m",$row['expiredate']), date("d",$row['expiredate']), date("H",$row['expiredate']), date("i",$row['expiredate']),date("s",$row['expiredate'])) ) , '<br />';
}
if (!empty($modSettings['class_catlist_numofbids']) && $row['noprice'] == 0 && $row['is_auction'] == 1)
echo $txt['class_text_totalbids'] . ' ' . $row['totalbids'] . '<br />';
if (!empty($modSettings['class_catlist_comments']))
echo $txt['class_text_comments'] . ' (<a href="' . $scripturl . '?action=classifieds;sa=view;id=' . $row['ID_LISTING'] . '">' . $row['commenttotal'] . '</a>)<br />';
if ($g_manage)
{
if ($row['is_auction'] == 0)
echo ' <a href="' . $scripturl . '?action=classifieds;sa=editlisting;id=' . $row['ID_LISTING'] . '">' . $txt['class_text_edit'] . '</a>';
else
echo ' <a href="' . $scripturl . '?action=classifieds;sa=editauction;id=' . $row['ID_LISTING'] . '">' . $txt['class_text_edit'] . '</a>';
echo ' <a href="' . $scripturl . '?action=classifieds;sa=deletelisting;id=' . $row['ID_LISTING'] . '">' . $txt['class_text_delete'] . '</a>';
}
echo '</span></td>';
if($rowlevel < ($maxrowlevel-1))
$rowlevel++;
else
{
echo '</tr>';
$rowlevel = 0;
}
}
if($rowlevel !=0)
{
echo '</tr>';
}
echo '
</table><br />';
// Free the Mysql Resoruces
$smcFunc['db_free_result']($dbresult);
// Html Footer
echo $endHtml;
}
function SMFEzformatprice($price,$currency)
{
if ($currency == 'USD')
return '$' . number_format($price, 2, '.', '');
else if ($currency == 'GBP')
return '£' . number_format($price, 2, '.', '');
elseif ($currency == 'CAD')
return '$' . number_format($price, 2, '.', '');
elseif ($currency == 'AUD')
return '$' . number_format($price, 2, '.', '');
elseif ($currency == 'ZAR')
return 'R ' . number_format($price, 2, '-', '');
else
return $price . ' ' . $currency;
}
function SMFezblockclass_cattimeleft($year, $month, $day, $hour, $minute, $seconds)
{
global $txt;
// make a unix timestamp for the given date
$the_countdown_date = mktime($hour, $minute, $seconds, $month, $day, $year, -1);
// get current unix timestamp
$today = forum_time(false);
$difference = $the_countdown_date - $today;
if ($difference < 0) $difference = 0;
$days_left = floor($difference/60/60/24);
$hours_left = floor(($difference - $days_left*60*60*24)/60/60);
$minutes_left = floor(($difference - $days_left*60*60*24 - $hours_left*60*60)/60);
$seconds_left = floor(($difference - $days_left*60*60*24 - $hours_left*60*60 - $minutes_left*60));
if ($days_left == 0 && $hours_left == 0 && $minutes_left < 5 && ($minutes_left != 0 && $seconds_left !=0))
{
echo '<font color="#FF0000">';
}
echo '<span class="smalltext">';
if ($days_left > 0)
{
echo $days_left . 'd ' . $hours_left . 'h ' . $minutes_left . 'm';
}
else
{
if ($hours_left > 0)
echo $hours_left . 'h ' . $minutes_left . 'm';
else
{
if ($minutes_left > 0)
echo $minutes_left . 'm ' . $seconds_left . 's';
else
{
if ($seconds_left > 0)
echo $seconds_left . 's';
}
}
}
echo '</span>';
if ($days_left == 0 && $hours_left == 0 && $minutes_left < 5 && ($minutes_left != 0 && $seconds_left !=0))
{
echo '</font>';
}
}
-
No you can't. Only the number of listings display and number per row
-
any new code, doesnt work on my install
-
What do you mean by that?
-
block comes up blank
-
Which code are you using and your SMF version?
-
tried tham all
2.0.12
-
What type of block in SP?
And what was the call that you used was it ClassifiedsBlock(1,1, 'random','vertical');
That information I need to know in order to test.
-
i tried each, php block
-
says database error in block code
-
What does the SMF error log say?
-
i see no error generated from it
-
Any nothing else other database error no full error?
-
This code worked with me with no errors on my simple portal using latest SMF Classifieds
ClassifiedsBlock(2,4, 'random','horizonstal');
function ClassifiedsBlock($rows = 4, $listings = 4, $type = 'recent', $category = 0, $format = 'vertical', $startHtml = '', $endHtml = '')
{
global $smcFunc, $scripturl, $txt, $modSettings, $boardurl, $user_info, $context, $sourcedir, $boarddir;
$rows = (int) $rows;
$listings = (int) $listings;
$category = (int) $category;
// Html Header
echo $startHtml;
// Load the language files
if (loadlanguage('classifieds') == false)
loadLanguage('classifieds', 'english');
$g_manage = allowedTo('smfclassifieds_manage');
$groupsdata = implode($user_info['groups'],',');
if (empty($modSettings['class_url']))
$modSettings['class_url'] = $boardurl . '/classifieds/';
if (empty($modSettings['class_path']))
$modSettings['class_path'] = $boarddir . '/classifieds/';
$maxrowlevel = $rows;
echo '<table cellspacing="0" cellpadding="5" border="0" align="center" width="100%">
';
// Check what type it is
$query = ' ';
switch($type)
{
case 'recent':
$query = "SELECT i.ID_LISTING, i.commenttotal,
i.primaryID_PICTURE, i.title, p.thumbfilename, p.remotefilename, i.currentbid,i.currency,
i.datelisted, i.views, i.is_auction, i.totalbids, i.ID_CAT, c.noprice, i.expiredate
FROM {db_prefix}class_listing as i
LEFT JOIN {db_prefix}class_listing_pic as p ON (i.primaryID_PICTURE = p.ID_PICTURE)
LEFT JOIN {db_prefix}class_cat as c ON (i.ID_CAT = c.ID_CAT)
LEFT JOIN {db_prefix}class_catperm AS r ON (r.ID_GROUP IN ($groupsdata) AND r.ID_CAT = i.ID_CAT)
WHERE i.removed = 0 AND i.approved = 1 AND (r.view IS NULL || r.view =1) GROUP BY i.ID_LISTING ORDER BY i.ID_LISTING DESC LIMIT $listings";
break;
case 'viewed':
$query = "SELECT i.ID_LISTING, i.commenttotal,
i.primaryID_PICTURE, i.title, p.thumbfilename, p.remotefilename, i.currentbid,i.currency,
i.datelisted, i.views, i.is_auction, i.totalbids, i.ID_CAT, c.noprice, i.expiredate
FROM {db_prefix}class_listing as i
LEFT JOIN {db_prefix}class_listing_pic as p ON (i.primaryID_PICTURE = p.ID_PICTURE)
LEFT JOIN {db_prefix}class_cat as c ON (i.ID_CAT = c.ID_CAT)
LEFT JOIN {db_prefix}class_catperm AS r ON (r.ID_GROUP IN ($groupsdata) AND r.ID_CAT = i.ID_CAT)
WHERE i.removed = 0 AND i.approved = 1 AND (r.view IS NULL || r.view =1) GROUP BY i.ID_LISTING ORDER BY i.views DESC LIMIT $listings";
break;
case 'random':
$query = "SELECT i.ID_LISTING, i.commenttotal,
i.primaryID_PICTURE, i.title, p.thumbfilename, p.remotefilename, i.currentbid,i.currency,
i.datelisted, i.views, i.is_auction, i.totalbids, i.ID_CAT, c.noprice, i.expiredate
FROM {db_prefix}class_listing as i
LEFT JOIN {db_prefix}class_listing_pic as p ON (i.primaryID_PICTURE = p.ID_PICTURE)
LEFT JOIN {db_prefix}class_cat as c ON (i.ID_CAT = c.ID_CAT)
LEFT JOIN {db_prefix}class_catperm AS r ON (r.ID_GROUP IN ($groupsdata) AND r.ID_CAT = i.ID_CAT)
WHERE i.removed = 0 AND i.approved = 1 AND (r.view IS NULL || r.view =1) GROUP BY i.ID_LISTING ORDER BY RAND() DESC LIMIT $listings";
break;
case 'mostcomments':
$query = "SELECT i.ID_LISTING, i.commenttotal,
i.primaryID_PICTURE, i.title, p.thumbfilename, p.remotefilename, i.currentbid,i.currency,
i.datelisted, i.views, i.is_auction, i.totalbids, i.ID_CAT, c.noprice, i.expiredate
FROM {db_prefix}class_listing as i
LEFT JOIN {db_prefix}class_listing_pic as p ON (i.primaryID_PICTURE = p.ID_PICTURE)
LEFT JOIN {db_prefix}class_cat as c ON (i.ID_CAT = c.ID_CAT)
LEFT JOIN {db_prefix}class_catperm AS r ON (r.ID_GROUP IN ($groupsdata) AND r.ID_CAT = i.ID_CAT)
WHERE i.removed = 0 AND i.approved = 1 AND (r.view IS NULL || r.view =1) GROUP BY i.ID_LISTING ORDER BY i.commenttotal DESC LIMIT $listings";
break;
case 'featured':
$query = "SELECT i.ID_LISTING, i.commenttotal,
i.primaryID_PICTURE, i.title, p.thumbfilename, p.remotefilename, i.currentbid,i.currency,
i.datelisted, i.views, i.is_auction, i.totalbids, i.ID_CAT, c.noprice, i.expiredate
FROM {db_prefix}class_listing as i
LEFT JOIN {db_prefix}class_listing_pic as p ON (i.primaryID_PICTURE = p.ID_PICTURE)
LEFT JOIN {db_prefix}class_cat as c ON (i.ID_CAT = c.ID_CAT)
LEFT JOIN {db_prefix}class_catperm AS r ON (r.ID_GROUP IN ($groupsdata) AND r.ID_CAT = i.ID_CAT)
WHERE i.removed = 0 AND i.approved = 1 AND i.featuredlisting = 1 AND (r.view IS NULL || r.view =1) GROUP BY i.ID_LISTING ORDER BY i.ID_LISTING DESC LIMIT $listings";
break;
}
// Execute the SQL query
$dbresult = $smcFunc['db_query']('', $query);
$rowlevel = 0;
while($row = $smcFunc['db_fetch_assoc']($dbresult))
{
if ($rowlevel == 0)
echo '<tr class="windowbg2">';
echo '<td align="center"><a href="', $scripturl, '?action=classifieds;sa=view;id=', $row['ID_LISTING'], '">', $row['title'], '</a><br />';
if (!empty($row['primaryID_PICTURE']) && $modSettings['class_catlist_showimage'])
{
if (empty($row['remotefilename']))
echo '<a href="', $scripturl, '?action=classifieds;sa=view;id=', $row['ID_LISTING'], '"><img src="', $modSettings['class_url'], $row['thumbfilename'], '" alt="" /></a><br />';
else
echo '<a href="', $scripturl, '?action=classifieds;sa=view;id=', $row['ID_LISTING'], '"><img src="', $row['remotefilename'], '" alt="" /></a><br />';
}
echo '<span class="smalltext">';
if (!empty($modSettings['class_catlist_currentprice']) && $row['noprice'] == 0)
echo $txt['class_text_price'] . SMFEzformatprice($row['currentbid'],$row['currency']) . '<br />';
if (!empty($modSettings['class_catlist_listingdate']))
{
if (!empty($modSettings['class_set_date_format_mdy']))
echo $txt['class_text_date'] . date($modSettings['class_set_date_format_mdy'],$row['datelisted']), ' ', date($modSettings['class_set_date_format_hia'],$row['datelisted']) . '<br />';
else
echo $txt['class_text_date'] . date("m/d/Y",$row['datelisted']) . ' ' . date("h:i a",$row['datelisted']) . '<br />';
}
if ($modSettings['class_catlist_timeleft'])
{
echo $txt['class_txt_time_left'] ;
echo ($row['expiredate'] == 0 ? $txt['class_expire_never'] : SMFezblockclass_cattimeleft( date("Y",$row['expiredate']), date("m",$row['expiredate']), date("d",$row['expiredate']), date("H",$row['expiredate']), date("i",$row['expiredate']),date("s",$row['expiredate'])) ) , '<br />';
}
if (!empty($modSettings['class_catlist_numofbids']) && $row['noprice'] == 0 && $row['is_auction'] == 1)
echo $txt['class_text_totalbids'] . ' ' . $row['totalbids'] . '<br />';
if (!empty($modSettings['class_catlist_comments']))
echo $txt['class_text_comments'] . ' (<a href="' . $scripturl . '?action=classifieds;sa=view;id=' . $row['ID_LISTING'] . '">' . $row['commenttotal'] . '</a>)<br />';
if ($g_manage)
{
if ($row['is_auction'] == 0)
echo ' <a href="' . $scripturl . '?action=classifieds;sa=editlisting;id=' . $row['ID_LISTING'] . '">' . $txt['class_text_edit'] . '</a>';
else
echo ' <a href="' . $scripturl . '?action=classifieds;sa=editauction;id=' . $row['ID_LISTING'] . '">' . $txt['class_text_edit'] . '</a>';
echo ' <a href="' . $scripturl . '?action=classifieds;sa=deletelisting;id=' . $row['ID_LISTING'] . '">' . $txt['class_text_delete'] . '</a>';
}
echo '</span></td>';
if($rowlevel < ($maxrowlevel-1))
$rowlevel++;
else
{
echo '</tr>';
$rowlevel = 0;
}
}
if($rowlevel !=0)
{
echo '</tr>';
}
echo '
</table><br />';
// Free the Mysql Resoruces
$smcFunc['db_free_result']($dbresult);
// Html Footer
echo $endHtml;
}
function SMFEzformatprice($price,$currency)
{
if ($currency == 'USD')
return '$' . number_format($price, 2, '.', '');
else if ($currency == 'GBP')
return '£' . number_format($price, 2, '.', '');
elseif ($currency == 'CAD')
return '$' . number_format($price, 2, '.', '');
elseif ($currency == 'AUD')
return '$' . number_format($price, 2, '.', '');
elseif ($currency == 'ZAR')
return 'R ' . number_format($price, 2, '-', '');
else
return $price . ' ' . $currency;
}
function SMFezblockclass_cattimeleft($year, $month, $day, $hour, $minute, $seconds)
{
global $txt;
// make a unix timestamp for the given date
$the_countdown_date = mktime($hour, $minute, $seconds, $month, $day, $year, -1);
// get current unix timestamp
$today = forum_time(false);
$difference = $the_countdown_date - $today;
if ($difference < 0) $difference = 0;
$days_left = floor($difference/60/60/24);
$hours_left = floor(($difference - $days_left*60*60*24)/60/60);
$minutes_left = floor(($difference - $days_left*60*60*24 - $hours_left*60*60)/60);
$seconds_left = floor(($difference - $days_left*60*60*24 - $hours_left*60*60 - $minutes_left*60));
if ($days_left == 0 && $hours_left == 0 && $minutes_left < 5 && ($minutes_left != 0 && $seconds_left !=0))
{
echo '<font color="#FF0000">';
}
echo '<span class="smalltext">';
if ($days_left > 0)
{
echo $days_left . 'd ' . $hours_left . 'h ' . $minutes_left . 'm';
}
else
{
if ($hours_left > 0)
echo $hours_left . 'h ' . $minutes_left . 'm';
else
{
if ($minutes_left > 0)
echo $minutes_left . 'm ' . $seconds_left . 's';
else
{
if ($seconds_left > 0)
echo $seconds_left . 's';
}
}
}
echo '</span>';
if ($days_left == 0 && $hours_left == 0 && $minutes_left < 5 && ($minutes_left != 0 && $seconds_left !=0))
{
echo '</font>';
}
}
-
still not working
-
I need the error code full to help.../screenshot
-
not getting any error
just the one i told you about
-
An Error Has Occurred!
Database error in block code. Please check the code.
-
You might have to ask simple portal then i can't help without more information.
I need the error from the SMF error log.
-
there is none from the log
-
[edit] ignore me, please delete....blonde moment
-
Glad you have it working!
-
Block does not show the "time left" although the item has about 3 hours remaining.
Using this code on SMF 2.0.18 with simple portal 2.3.7
ClassifiedsBlock(1,1, 'random','vertical');
function ClassifiedsBlock($rows = 4, $listings = 4, $type = 'recent', $category = 0, $format = 'vertical', $startHtml = '', $endHtml = '')
{
global $smcFunc, $scripturl, $txt, $modSettings, $boardurl, $user_info, $context, $sourcedir, $boarddir;
$rows = (int) $rows;
$listings = (int) $listings;
$category = (int) $category;
// Html Header
echo $startHtml;
// Load the language files
if (loadlanguage('classifieds') == false)
loadLanguage('classifieds', 'english');
$g_manage = allowedTo('smfclassifieds_manage');
$groupsdata = implode($user_info['groups'],',');
if (empty($modSettings['class_url']))
$modSettings['class_url'] = $boardurl . '/classifieds/';
if (empty($modSettings['class_path']))
$modSettings['class_path'] = $boarddir . '/classifieds/';
$maxrowlevel = $rows;
echo '<table cellspacing="0" cellpadding="5" border="0" align="center" width="100%">
';
// Check what type it is
$query = ' ';
switch($type)
{
case 'recent':
$query = "SELECT i.ID_LISTING, i.commenttotal,
i.primaryID_PICTURE, i.title, p.thumbfilename, p.remotefilename, i.currentbid,i.currency,
i.datelisted, i.views, i.is_auction, i.totalbids, i.ID_CAT, c.noprice, i.expiredate
FROM {db_prefix}class_listing as i
LEFT JOIN {db_prefix}class_listing_pic as p ON (i.primaryID_PICTURE = p.ID_PICTURE)
LEFT JOIN {db_prefix}class_cat as c ON (i.ID_CAT = c.ID_CAT)
LEFT JOIN {db_prefix}class_catperm AS r ON (r.ID_GROUP IN ($groupsdata) AND r.ID_CAT = i.ID_CAT)
WHERE i.removed = 0 AND i.approved = 1 AND (r.view IS NULL || r.view =1) GROUP BY i.ID_LISTING ORDER BY i.ID_LISTING DESC LIMIT $listings";
break;
case 'viewed':
$query = "SELECT i.ID_LISTING, i.commenttotal,
i.primaryID_PICTURE, i.title, p.thumbfilename, p.remotefilename, i.currentbid,i.currency,
i.datelisted, i.views, i.is_auction, i.totalbids, i.ID_CAT, c.noprice, i.expiredate
FROM {db_prefix}class_listing as i
LEFT JOIN {db_prefix}class_listing_pic as p ON (i.primaryID_PICTURE = p.ID_PICTURE)
LEFT JOIN {db_prefix}class_cat as c ON (i.ID_CAT = c.ID_CAT)
LEFT JOIN {db_prefix}class_catperm AS r ON (r.ID_GROUP IN ($groupsdata) AND r.ID_CAT = i.ID_CAT)
WHERE i.removed = 0 AND i.approved = 1 AND (r.view IS NULL || r.view =1) GROUP BY i.ID_LISTING ORDER BY i.views DESC LIMIT $listings";
break;
case 'random':
$query = "SELECT i.ID_LISTING, i.commenttotal,
i.primaryID_PICTURE, i.title, p.thumbfilename, p.remotefilename, i.currentbid,i.currency,
i.datelisted, i.views, i.is_auction, i.totalbids, i.ID_CAT, c.noprice, i.expiredate
FROM {db_prefix}class_listing as i
LEFT JOIN {db_prefix}class_listing_pic as p ON (i.primaryID_PICTURE = p.ID_PICTURE)
LEFT JOIN {db_prefix}class_cat as c ON (i.ID_CAT = c.ID_CAT)
LEFT JOIN {db_prefix}class_catperm AS r ON (r.ID_GROUP IN ($groupsdata) AND r.ID_CAT = i.ID_CAT)
WHERE i.removed = 0 AND i.approved = 1 AND (r.view IS NULL || r.view =1) GROUP BY i.ID_LISTING ORDER BY RAND() DESC LIMIT $listings";
break;
case 'mostcomments':
$query = "SELECT i.ID_LISTING, i.commenttotal,
i.primaryID_PICTURE, i.title, p.thumbfilename, p.remotefilename, i.currentbid,i.currency,
i.datelisted, i.views, i.is_auction, i.totalbids, i.ID_CAT, c.noprice, i.expiredate
FROM {db_prefix}class_listing as i
LEFT JOIN {db_prefix}class_listing_pic as p ON (i.primaryID_PICTURE = p.ID_PICTURE)
LEFT JOIN {db_prefix}class_cat as c ON (i.ID_CAT = c.ID_CAT)
LEFT JOIN {db_prefix}class_catperm AS r ON (r.ID_GROUP IN ($groupsdata) AND r.ID_CAT = i.ID_CAT)
WHERE i.removed = 0 AND i.approved = 1 AND (r.view IS NULL || r.view =1) GROUP BY i.ID_LISTING ORDER BY i.commenttotal DESC LIMIT $listings";
break;
case 'featured':
$query = "SELECT i.ID_LISTING, i.commenttotal,
i.primaryID_PICTURE, i.title, p.thumbfilename, p.remotefilename, i.currentbid,i.currency,
i.datelisted, i.views, i.is_auction, i.totalbids, i.ID_CAT, c.noprice, i.expiredate
FROM {db_prefix}class_listing as i
LEFT JOIN {db_prefix}class_listing_pic as p ON (i.primaryID_PICTURE = p.ID_PICTURE)
LEFT JOIN {db_prefix}class_cat as c ON (i.ID_CAT = c.ID_CAT)
LEFT JOIN {db_prefix}class_catperm AS r ON (r.ID_GROUP IN ($groupsdata) AND r.ID_CAT = i.ID_CAT)
WHERE i.removed = 0 AND i.approved = 1 AND i.featuredlisting = 1 AND (r.view IS NULL || r.view =1) GROUP BY i.ID_LISTING ORDER BY i.ID_LISTING DESC LIMIT $listings";
break;
}
// Execute the SQL query
$dbresult = $smcFunc['db_query']('', $query);
$rowlevel = 0;
while($row = $smcFunc['db_fetch_assoc']($dbresult))
{
if ($rowlevel == 0)
echo '<tr class="windowbg2">';
echo '<td align="center"><a href="', $scripturl, '?action=classifieds;sa=view;id=', $row['ID_LISTING'], '">', $row['title'], '</a><br />';
if (!empty($row['primaryID_PICTURE']) && $modSettings['class_catlist_showimage'])
{
if (empty($row['remotefilename']))
echo '<a href="', $scripturl, '?action=classifieds;sa=view;id=', $row['ID_LISTING'], '"><img src="', $modSettings['class_url'], $row['thumbfilename'], '" alt="" /></a><br />';
else
echo '<a href="', $scripturl, '?action=classifieds;sa=view;id=', $row['ID_LISTING'], '"><img src="', $row['remotefilename'], '" alt="" /></a><br />';
}
echo '<span class="smalltext">';
if (!empty($modSettings['class_catlist_currentprice']) && $row['noprice'] == 0)
echo $txt['class_text_price'] . SMFEzformatprice($row['currentbid'],$row['currency']) . '<br />';
if (!empty($modSettings['class_catlist_listingdate']))
{
if (!empty($modSettings['class_set_date_format_mdy']))
echo $txt['class_text_date'] . date($modSettings['class_set_date_format_mdy'],$row['datelisted']), ' ', date($modSettings['class_set_date_format_hia'],$row['datelisted']) . '<br />';
else
echo $txt['class_text_date'] . date("m/d/Y",$row['datelisted']) . ' ' . date("h:i a",$row['datelisted']) . '<br />';
}
if ($modSettings['class_catlist_timeleft'])
{
echo $txt['class_txt_time_left'] ;
echo ($row['expiredate'] == 0 ? $txt['class_expire_never'] : SMFezblockclass_cattimeleft( date("Y",$row['expiredate']), date("m",$row['expiredate']), date("d",$row['expiredate']), date("H",$row['expiredate']), date("i",$row['expiredate']),date("s",$row['expiredate'])) ) , '<br />';
}
if (!empty($modSettings['class_catlist_numofbids']) && $row['noprice'] == 0 && $row['is_auction'] == 1)
echo $txt['class_text_totalbids'] . ' ' . $row['totalbids'] . '<br />';
if (!empty($modSettings['class_catlist_comments']))
echo $txt['class_text_comments'] . ' (<a href="' . $scripturl . '?action=classifieds;sa=view;id=' . $row['ID_LISTING'] . '">' . $row['commenttotal'] . '</a>)<br />';
if ($g_manage)
{
if ($row['is_auction'] == 0)
echo ' <a href="' . $scripturl . '?action=classifieds;sa=editlisting;id=' . $row['ID_LISTING'] . '">' . $txt['class_text_edit'] . '</a>';
else
echo ' <a href="' . $scripturl . '?action=classifieds;sa=editauction;id=' . $row['ID_LISTING'] . '">' . $txt['class_text_edit'] . '</a>';
echo ' <a href="' . $scripturl . '?action=classifieds;sa=deletelisting;id=' . $row['ID_LISTING'] . '">' . $txt['class_text_delete'] . '</a>';
}
echo '</span></td>';
if($rowlevel < ($maxrowlevel-1))
$rowlevel++;
else
{
echo '</tr>';
$rowlevel = 0;
}
}
if($rowlevel !=0)
{
echo '</tr>';
}
echo '
</table><br />';
// Free the Mysql Resoruces
$smcFunc['db_free_result']($dbresult);
// Html Footer
echo $endHtml;
}
function SMFEzformatprice($price,$currency)
{
if ($currency == 'USD')
return '$' . number_format($price, 2, '.', '');
else if ($currency == 'GBP')
return '£' . number_format($price, 2, '.', '');
elseif ($currency == 'CAD')
return '$' . number_format($price, 2, '.', '');
elseif ($currency == 'AUD')
return '$' . number_format($price, 2, '.', '');
elseif ($currency == 'ZAR')
return 'R ' . number_format($price, 2, '-', '');
else
return $price . ' ' . $currency;
}
function SMFezblockclass_cattimeleft($year, $month, $day, $hour, $minute, $seconds)
{
global $txt;
// make a unix timestamp for the given date
$the_countdown_date = mktime($hour, $minute, $seconds, $month, $day, $year, -1);
// get current unix timestamp
$today = forum_time(false);
$difference = $the_countdown_date - $today;
if ($difference < 0) $difference = 0;
$days_left = floor($difference/60/60/24);
$hours_left = floor(($difference - $days_left*60*60*24)/60/60);
$minutes_left = floor(($difference - $days_left*60*60*24 - $hours_left*60*60)/60);
$seconds_left = floor(($difference - $days_left*60*60*24 - $hours_left*60*60 - $minutes_left*60));
if ($days_left == 0 && $hours_left == 0 && $minutes_left < 5 && ($minutes_left != 0 && $seconds_left !=0))
{
echo '<font color="#FF0000">';
}
echo '<span class="smalltext">';
if ($days_left > 0)
{
echo $days_left . 'd ' . $hours_left . 'h ' . $minutes_left . 'm';
}
else
{
if ($hours_left > 0)
echo $hours_left . 'h ' . $minutes_left . 'm';
else
{
if ($minutes_left > 0)
echo $minutes_left . 'm ' . $seconds_left . 's';
else
{
if ($seconds_left > 0)
echo $seconds_left . 's';
}
}
}
echo '</span>';
if ($days_left == 0 && $hours_left == 0 && $minutes_left < 5 && ($minutes_left != 0 && $seconds_left !=0))
{
echo '</font>';
}
}
Live on right hand side at https://bikerhound.com/
SMF Classifieds 5.1.4a