</td>
                        <td>
                            <a href="/ads/publisher_ad_view.php?id=<?php 
        echo $row['id'];
        ?>
">Get Code</a>
                            <?php 
        if ($row['adType'] == TNB_AD_TYPE_CUSTOM) {
            if ($status == 'active') {
                ?>
                                    &middot;
                                    <a href="/ads/publisher.php?id=<?php 
                echo $row['id'];
                ?>
&action=delete-ad&<?php 
                echo buckys_get_form_token();
                ?>
=1">Delete</a>
                                <?php 
            }
            ?>
                            <?php 
        }
        ?>
                        </td>
                        <td style="text-align:right;"><?php 
        echo number_format($unpaidImpressions);
        ?>
</td>
                        <td style="text-align:right;">
                            <?php 
    /**
     * @param $token
     * @return bool|string
     */
    public function renderAd($token)
    {
        global $db;
        //Getting Ad details by token
        $query = $db->prepare("SELECT * FROM " . TABLE_PUBLISHER_ADS . " WHERE token=%s", $token);
        $adDetail = $db->getRow($query);
        if (!$adDetail) {
            return false;
        }
        $classAds = new BuckysAds();
        $sizeDetail = $classAds->getAdSizeById($adDetail['size']);
        //fixes a display issues with vertical ads
        if ($sizeDetail['type'] == 'vertical') {
            $spaceToSubtract = $sizeDetail['width'] - 18;
            //16px for padding, 2px for border
            $displayWidth = 'width:' . $spaceToSubtract . 'px;';
        }
        //changes padding for horizontal ads
        if ($sizeDetail['type'] == 'horizontal' && $sizeDetail['ads'] > 1) {
            $newHorizontalPadding = 'padding: 0px 20px;';
        }
        $query1 = "SELECT AD.* FROM " . TABLE_ADS . " AS AD WHERE AD.defaultAd=0 AND AD.status='" . TNB_AD_STATUS_ACTIVE . "' AND AD.ownerID != '" . $adDetail['publisherID'] . "' AND AD.type = 'Text' ORDER BY rand() LIMIT " . $sizeDetail['ads'];
        $query2 = "SELECT AD.* FROM " . TABLE_ADS . " AS AD WHERE AD.defaultAd=0 AND AD.status='" . TNB_AD_STATUS_ACTIVE . "' AND AD.ownerID != '" . $adDetail['publisherID'] . "' AND AD.type = 'Image' AND AD.adSize='" . $sizeDetail['id'] . "' ORDER BY rand() LIMIT 1";
        if (mt_rand(0, 10) > 5) {
            $results = $db->getResultsArray($query1);
            if (!$results) {
                $results = $db->getResultsArray($query2);
            }
        } else {
            $results = $db->getResultsArray($query2);
            if (!$results) {
                $results = $db->getResultsArray($query1);
            }
        }
        //Do not display borders on Image ads
        if ($results[0]['type'] == 'Image') {
            $displayBorder = ';border:none;';
        }
        if (count($results) < $sizeDetail['ads']) {
            //Getting Buckysroom Default Ads
            $query3 = "SELECT AD.* FROM " . TABLE_ADS . " AS AD WHERE AD.defaultAd=1 AND AD.status='" . TNB_AD_STATUS_ACTIVE . "' AND AD.type = 'Text' ORDER BY rand() LIMIT " . ($sizeDetail['ads'] - count($results));
            $results2 = $db->getResultsArray($query3);
            $results = array_merge($results, $results2);
        }
        $counts = count($results);
        $formToken = buckys_get_form_token();
        $bannerHTML = '<div class="buckysroom-ad-banner" id="buckysroom-ads-preview">';
        $bannerHTML .= '<table cellpadding="0" cellspacing="0" style="width: ' . $sizeDetail['width'] . 'px; height: ' . $sizeDetail['height'] . 'px; border: solid 1px #' . $adDetail['borderColor'] . ';  background-color: #' . $adDetail['bgColor'] . $displayBorder . '">';
        for ($i = 1; $i <= $counts; $i++) {
            if ($sizeDetail['type'] == 'vertical' || $i == 1) {
                $bannerHTML .= '<tr>';
            }
            $bannerHTML .= '<td>';
            if ($results[$i - 1]['type'] == 'Text') {
                $bannerHTML .= '<div class="buckysroom-ad ' . $sizeDetail['class'] . ' " style=" ' . $displayWidth . $newHorizontalPadding . ' ">
                                    <a href="//' . TNB_DOMAIN . '/goto-ad-url.php?key=' . $results[$i - 1]['adKey'] . '&' . $formToken . '=1&url=' . base64_encode($results[$i - 1]['url']) . '" class="bsroom-ad-title" style="color: #' . $adDetail['titleColor'] . '" target="_blank">' . $results[$i - 1]['title'] . '</a>
									<br />
                                    <p class="bsroom-ad-desc" style="color: #' . $adDetail['textColor'] . '">' . $results[$i - 1]['description'] . '</p>
                                    <div style=" ' . $displayWidth . 'overflow:hidden;">
									<a style="color: #' . $adDetail['urlColor'] . '" href="//' . TNB_DOMAIN . '/goto-ad-url.php?key=' . $results[$i - 1]['adKey'] . '&' . $formToken . '=1&url=' . base64_encode($results[$i - 1]['url']) . '" class="bsroom-ad-link" target="_blank">' . $results[$i - 1]['display_url'] . '</a>
									</div>
                                </div>';
            } else {
                $bannerHTML .= '<div class="buckysroom-ad buckysroom-ad-image"  style="padding: 0; margin: 0; line-height: 0; overflow: hidden"><a href="//' . TNB_DOMAIN . '/goto-ad-url.php?key=' . $results[$i - 1]['adKey'] . '&' . $formToken . '=1&url=' . base64_encode($results[$i - 1]['url']) . '" target="_blank"><img src="' . DIR_WS_IMAGE . 'user_ads/' . $results[$i - 1]['fileName'] . '" width="' . $sizeDetail['width'] . '" height="' . $sizeDetail['height'] . '" /></a></div>';
            }
            $bannerHTML .= '</td>';
            if ($sizeDetail['type'] == 'vertical' || $i == $counts) {
                $bannerHTML .= '</tr>';
            }
            if ($results[$i - 1]['defaultAd']) {
                continue;
            }
            $db->query("UPDATE " . TABLE_PUBLISHER_ADS . " SET `impressions` = `impressions` + 1 WHERE id=" . $adDetail['id']);
            $db->query("UPDATE " . TABLE_ADS . " SET `receivedImpressions` = `receivedImpressions` + 1 WHERE id=" . $results[$i - 1]['id']);
            //Make it to expired if all expressions are received
            $db->query("UPDATE " . TABLE_ADS . " SET `status` = " . TNB_AD_STATUS_EXPIRED . " WHERE  id=" . $results[$i - 1]['id'] . " AND `receivedImpressions` >= `impressions` ");
            //Image ads were creating multiple table rows
            if ($results[$i - 1]['type'] == 'Image') {
                break;
            }
        }
        $bannerHTML .= '</table>';
        $bannerHTML .= '</div>';
        return $bannerHTML;
    }
/**
 * Token URL Param
 *
 * @param bool $forceNew
 * @return string
 */
function buckys_get_token_param($forceNew = false)
{
    return '&' . buckys_get_form_token($forceNew) . "=1";
}
Esempio n. 4
0
function render_form_token($isReturn = false)
{
    $html = '<input type="hidden" name="' . buckys_get_form_token() . '" value="1" />';
    if ($isReturn) {
        return $html;
    } else {
        echo $html;
    }
}
<?php

require dirname(__FILE__) . '/includes/bootstrap.php';
header("content-type: application/javascript");
//Create Form Token
$formToken = buckys_get_form_token();
echo 'document.write(\'<iframe width="\' + buckysroom_ad_width +\'" height="\' + buckysroom_ad_height +\'" src="//' . TNB_DOMAIN . '/buckys_ad.php?ad=\' + buckysroom_ad_token + \'&' . $formToken . '=1" style="padding:0;margin: 0; border: none"></iframe>\');';