Beispiel #1
0
/**
 * show ads
 *
 * @param array $params parameters
 *
 * @return ads HTML
 */
function Ads_widget($params)
{
    if (!isset($params->{'ad-type'})) {
        return 'missing ad type';
    }
    $type_id = (int) $params->{'ad-type'};
    $howmany = (int) $params->{'how-many'};
    $type = dbRow('select * from ads_types where id=' . $type_id);
    $ads = array();
    $i = 0;
    if ($howmany > 1) {
        $sql = 'select id,image_url,target_type,poster from ads' . ' where type_id=' . $type_id . ' and is_active and cdate>date_add(now(), interval -2 day) order by rand()' . ' limit ' . $howmany;
        $adsNew = dbAll($sql);
        for (; $i < count($adsNew); ++$i) {
            $ads[] = $adsNew[$i];
        }
    }
    $adsOld = dbAll('select id,image_url,target_type,poster from ads' . ' where type_id=' . $type_id . ' and is_active order by rand()' . ' limit ' . $howmany);
    for ($j = 0; $j < $howmany - $i && $j < count($adsOld); ++$j) {
        $ads[] = $adsOld[$j];
    }
    $html = '<div class="ads-wrapper type-' . $type_id . '">';
    foreach ($ads as $ad) {
        $html .= Ads_adShow($ad, $type);
        dbQuery('insert into ads_track set ad_id=' . $ad['id'] . ', view=1, cdate=now()');
    }
    $html .= '</div>';
    WW_addScript('ads/j/js.js');
    WW_addCSS('/ww.plugins/ads/css.css');
    return $html;
}
Beispiel #2
0
<?php

$types = dbAll('select id, name, width, height from ads_types');
$html .= '<div class="ads-show-all">';
foreach ($types as $type) {
    $html .= '<h2>' . htmlspecialchars($type['name']) . '</h2>';
    $ads = dbAll('select id, image_url, cdate, target_type from ads where type_id=' . $type['id'] . ' and is_active order by name');
    foreach ($ads as $ad) {
        $html .= Ads_adShow($ad, $type);
    }
}
$html .= '</div>';