Results 1 to 6 of 6

Thread: Display Ad Help Needed

  1. #1
    Join Date
    Feb 2009
    Posts
    62
    Thanks
    15
    Thanked 0 Times in 0 Posts

    Default Display Ad Help Needed

    Ok so my page is set up like this.


    PHP Code:
     <?php
    $myAd 
    = <a href="http://kywordpro.com/sponsor/index.php">
                 <
    b>Advertise Your Business with KyWordPRO!</a
    ?>

    Then in my page I have it like this

    PHP Code:
     <?php
    echo googleAdd(1);
    echo 
    userAdd();
    echo 
    $myAd;
    ?>
    So I want my add to display only if there isnt a User Ad.

    Can anyone help?

    Tim..
    Last edited by tgallagher26; 02-27-2009 at 07:00 PM.

  2. #2
    Join Date
    Jan 2008
    Posts
    4,168
    Thanks
    28
    Thanked 628 Times in 624 Posts
    Blog Entries
    1

    Default

    Can you give me the functions googleAdd, and userAdd please?
    Jeremy | jfein.net

  3. #3
    Join Date
    Feb 2009
    Posts
    62
    Thanks
    15
    Thanked 0 Times in 0 Posts

    Default

    PHP Code:
    function userAdd() {
        global 
    $baza$q;
        
    $sql "SELECT * FROM adds WHERE LOWER(keyword) = '$q' AND STATUS = '1'";
        
    $baza -> izvrsiUpit($sql);
        
    $baza -> stvoriNiz();
        while(
    $red $baza -> noviRed()) {
            if(empty(
    $red['img'])) {
                
    $str file_get_contents('inc/templates/sponsor.htm');
            }
            else {
                
    $str file_get_contents('inc/templates/sponsorImg.htm');
            }
            
    $search = array('[url]''[title]''[desc]''[root]''[img]');
            
    $rep = array($red['url'], $red['title'], $red['desc'], ROOT$red['img']);
            
    $add .= str_replace($search$rep$str);
            
    $sql "UPDATE adds SET hits = hits + '1' WHERE id = '{$red['id']}'";
            
    $baza -> izvrsiUpit($sql);
        }
        return 
    $add '<br /><br />';
    }


    function 
    googleAdd($int) {
        if(
    file_get_contents('inc/ads/' $int '.txt') == 1) {
            return 
    file_get_contents('inc/ads/google' $int '.txt');    
        }


  4. #4
    Join Date
    Jan 2008
    Posts
    4,168
    Thanks
    28
    Thanked 628 Times in 624 Posts
    Blog Entries
    1

    Default

    Ok, provide all the code please.
    Jeremy | jfein.net

  5. #5
    Join Date
    Feb 2009
    Posts
    62
    Thanks
    15
    Thanked 0 Times in 0 Posts

    Default

    Ok here is my complete functions list.

    PHP Code:
    <?php

     

    /**
     * Function that gets last xx searches from database.
     * @param int $searches Number of searches that sould be returned from database
     * @return string String that contains last
     */
    function lastSearches($searches) {
        global 
    $baza;
        if(!isset(
    $_GET['a'])) $_GET['a'] = 'txt';
        
    $sql "SELECT cat, query FROM cache WHERE cat = '{$_GET['a']}' LIMIT $searches";
        
    $baza -> izvrsiUpit($sql);
        
    $baza -> stvoriNiz();
        
    $str "";
        while(
    $red $baza -> noviRed()) {
            
    $str .= "<li><a href=\"http://kywordpro.com/txt/1/10/" urlencode($red["query"]) . ".html\" target=\"blank\">" $red['query'] . "</a> ";
        }
        return 
    substr($str0strlen($str) - 2);
    }

    function 
    remUserAd() {
        global 
    $baza;
        
    $sql "DELETE FROM adds WHERE UNIX_TIMESTAMP(NOW()) > UNIX_TIMESTAMP(expire)";
        
    $baza -> izvrsiUpit($sql);
    }

    if(!
    function_exists('file_get_contents')) {
        function 
    file_get_contents($url) {
            
    $f fopen($url'r');
            while(!
    feof($f)) {
                
    $str .= fread($f'1024');
            }
            
    fclose($f);
            return 
    $str;
        }
    }

    if(!
    function_exists('file_get_contents')) {
        function 
    file_put_contents($url$data) {
            
    $f fopen($url'w+');
            
    fwrite($f$data);
            
    fclose($f);
            return 
    true;
        }
    }

    /**
     * Returns user adds
     * @return string String that contains add code
     */
    function userAdd() {
        global 
    $baza$q;
        
    $sql "SELECT * FROM adds WHERE LOWER(keyword) = '$q' AND STATUS = '1'";
        
    $baza -> izvrsiUpit($sql);
        
    $baza -> stvoriNiz();
        while(
    $red $baza -> noviRed()) {
            if(empty(
    $red['img'])) {
                
    $str file_get_contents('inc/templates/sponsor.htm');
            }
            else {
                
    $str file_get_contents('inc/templates/sponsorImg.htm');
            }
            
    $search = array('[url]''[title]''[desc]''[root]''[img]');
            
    $rep = array($red['url'], $red['title'], $red['desc'], ROOT$red['img']);
            
    $add .= str_replace($search$rep$str);
            
    $sql "UPDATE adds SET hits = hits + '1' WHERE id = '{$red['id']}'";
            
    $baza -> izvrsiUpit($sql);
        }
        return 
    $add '';
    }

    /**
     * Returns google adds
     * @param int $int Code (1 upp, 2 low)
     * @return string String that contains google add code
     */
    function googleAdd($int) {
        if(
    file_get_contents('inc/ads/' $int '.txt') == 1) {
            return 
    file_get_contents('inc/ads/google' $int '.txt');    
        }
    }

    /**
     * Function that generates xml sitemap
     * @return bool True on success, false on failure
     */
    function genSiteMap() {
        global 
    $baza$clear;
        
    $xml "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<urlset xmlns=\"http://www.sitemaps.org/schemas/sitemap/0.9\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xsi:schemaLocation=\"http://www.sitemaps.org/schemas/sitemap/0.9 http://www.sitemaps.org/schemas/sitemap/0.9/sitemap.xsd\">\n";
        
    $xml .= "\t<url>\n\t\t<loc>" ROOT "</loc>\n\t\t";
                      
    $xml .= "<priority>1</priority>\n\t\t";
        
    $xml .= "<changefreq>" $clear "</changefreq>\n\t";
        
    $xml .= "</url>\n";
        
    $xml .= "\t<url>\n\t\t<loc>" ROOT "index.php</loc>\n\t\t";
                      
    $xml .= "<priority>0.9</priority>\n\t\t";
        
    $xml .= "<changefreq>" $clear "</changefreq>\n\t";
        
    $xml .= "</url>\n";
        
    $sql "SELECT query, cat FROM cache";
        
    $baza -> izvrsiUpit($sql);
        
    $baza -> stvoriNiz();
        while(
    $red $baza -> noviRed()) {
            
    $xml .= "\t<url>\n\t\t<loc>" ROOT "txt/1/10/" urlencode($red["query"]) . ".html</loc>\n\t\t";
                                        
    $xml .= "<priority>0.8</priority>\n\t\t";
                          
    $xml .= "<changefreq>" $clear "</changefreq>\n\t";
                          
    $xml .= "</url>\n";
        }
        
    $xml .= "</urlset>";
        
    file_put_contents('sitemap.xml'$xml);
    }

    /**
     * Function check if we have that query in cache.
     * @param string $q Query string
     * @param string $a Action
     * @return mix query string if in cache, false if not
     */
    function inCache($q$a) {
        global 
    $baza;
        
    $sql "SELECT * FROM cache WHERE LCASE(query) = LCASE('$q') AND cat = '$a' LIMIT 1";
        
    $baza -> izvrsiUpit($sql); echo mysql_error();
        if(
    $baza -> brSelectRedova() > 0) {
            
    $baza -> stvoriNiz();
            
    $red $baza -> noviRed();
            return 
    $red['result'];
        }
        else {
            return 
    false;
        }
    }

    /**
     * Function that clears chache.
     * @return bool True if success, false if not
     */
    function clearCache($time) {
    if(
    $time 1) return true;
        global 
    $baza;
        
    $sql "DELETE cache FROM cache WHERE UNIX_TIMESTAMP(NOW()) - UNIX_TIMESTAMP(time) > $time";
        
    $baza -> izvrsiUpit($sql) ? true false;
        return 
    $baza -> optimize("cache") ? true false;
    }

    /**
     * Function that paginates the result.
     * @param int $count Number of results
     * @param int $num Array count.
     * @param int $page Current page
     * @return string Pages
     */
    function paginate($count$num$page) {
        global 
    $a$q;
        
    $str '';
        if(
    is_float($count $num)) {
            
    $max substr($count $num0strpos($count $num".")) + 1;
        }
        else {
            
    $max $count $num;
        }
        if(
    == $page) {
                
    $str .= '&lt;&lt;&lt; | &lt; | ';
            }
        else {
                
    $str .= "<a href=\"" ROOT "$a/1/$num/" urlencode($q) . ".html\">&lt;&lt;&lt;</a> | <a href=\"" ROOT "$a/" . ($page 1) . "/$num/" urlencode($q) . ".html\">&lt;</a> | ";
        }
        for(
    $i 1$i 11$i++) {
            if(
    $i == $max 1) break;
            if(
    $i == $page) {
                
    $str .= "$i | ";
            }
            else {
                
    $str .= "<a href=\"" ROOT "$a/$i/$num/" urlencode($q) . ".html\">$i</a> | ";
            }
        }
        if(
    $page == $max) {
            
    $str .= '&gt; | &gt;&gt;&gt;';
        }
        else {
            
    $str .= "<a href=\"" ROOT "$a/" . ($page 1) . "/$num/" urlencode($q) . ".html\">&gt;</a> | <a href=\"" ROOT "$a/$max/$num/" urlencode($q) . ".html\">&gt;&gt;&gt;</a>";
        }
        return 
    $str;
    }

    /**
     * Function that sends request to server and returns results.
     * @param string $req Request url
     * @return string Results string
     */
    function sendReq($req) {
        return 
    file_get_contents($req);
    }

  6. #6
    Join Date
    Feb 2009
    Posts
    62
    Thanks
    15
    Thanked 0 Times in 0 Posts

    Default

    Here is the second half.

    PHP Code:
    /**
     * Function that echoes add packages.
     */
    function showPackages() {
        global $baza;
        $sql = "SELECT * FROM packages WHERE status = '1'";
        $baza -> izvrsiUpit($sql);
        $baza -> stvoriNiz();
        $i = 0;
        while($red = $baza -> noviRed()) {
            $i++;
    ?>
        <input style="margin-top: 7px;" <?php if($i == 1)  echo "checked"?> type="radio" name="package" value="<?=$red['id']; ?>" />&nbsp;<?=$red['name']; ?> (<?=$red['price']; ?> USD) : <?=$red['desc']; ?><br />
    <?php
        
    }
    }

    /**
     * Function buys add
     */
    function purchaseAdd() {
        global 
    $_POST$baza$_SESSION;
        
    $error false;
        
    $sql "SELECT * FROM packages WHERE id = '{$_POST['package']}' LIMIT 1";
        
    $baza -> izvrsiUpit($sql);
        
    $baza -> stvoriNiz();
        while(
    $red $baza -> noviRed()) {
            
    $expire $red['time'] * 60*60*24 time();
            
    $price $red['price'];
        }
        if(
    strlen($_POST['url']) < 10) {
            echo 
    "Url is to short.<br />";
            
    $error true;
        }
        if(
    strlen($_POST['keyword']) < 3) {
            echo 
    "Keyword is to short.<br />";
            
    $error true;
        }
        if(
    strlen($_POST['desc']) < 10) {
            echo 
    "Description is to short.<br />";
            
    $error true;
        }
        if(
    preg_match("/^http:\/\/$/i"$_POST['img'])) {
            
    $img '';
        }
        else {
            
    $img mysql_real_escape_string($_POST['img']);
        }
        if(
    preg_match("/^http:\/\/(.*?)$/i"$_POST['url'])) {
            
    $url mysql_real_escape_string($_POST['url']);
        }
        else {
            
    $url 'http://' mysql_real_escape_string($_POST['url']);
        }
        if(
    strlen($_POST['title']) < 5) {
            echo 
    "Title is to short.<br />";
            
    $error true;
        }
        
    $sql "SELECT count(*) AS num FROM adds WHERE keyword = '{$_POST['keyword']}' LIMIT 1";
        
    $baza -> izvrsiUpit($sql);
        
    $baza -> stvoriNiz();
        while(
    $red $baza -> noviRed()) {
            if(
    $red['num'] >= NUM_ADDS) {
                echo 
    "We hame maximum number of ads for that keyword.<br />Try an other.";
            
    $error true;
            }
        }
        
    $sql "SELECT amount FROM users WHERE id = '{$_SESSION['id']}' LIMIT 1";
        
    $baza -> izvrsiUpit($sql);
        
    $baza -> stvoriNiz();
        while(
    $red $baza -> noviRed()) {
            if(
    $red['amount'] < $price) {
                echo 
    "You don't have enough money to buy that ad. Please make a deposit.";
            
    $error true;
            }
        }
        if(!
    $error) {
            
    $sql "INSERT INTO adds VALUES('', '" mysql_real_escape_string($_POST['keyword']) . "', '" mysql_real_escape_string($_POST['title']) . "', '$url', '" mysql_real_escape_string($_POST['desc']) . "', '$img', '1', FROM_UNIXTIME('$expire'), '0', '{$_SESSION['id']}')";
            if(
    $baza -> izvrsiUpit($sql)) echo "Ad has been added.";
            
    $sql "UPDATE users SET spent = spent + '$price' WHERE id = '{$_SESSION['id']}'";
            
    $baza -> izvrsiUpit($sql);
            
    $_SESSION['spent'] = $price;
        }
    }

    /**
     * Function that shows all adds from user.
     */
    function showAdds() {
        global 
    $baza$_SESSION;
        
    $sql "SELECT * FROM adds WHERE user = '{$_SESSION['id']}'";
        
    $baza -> izvrsiUpit($sql);
        
    $baza -> stvoriNiz();
        while(
    $red $baza -> noviRed()) {
            if(
    $red['status'] == 1) {
                
    $status "<a href=\"" ROOT "sponsor/ap.php?act=disable&id={$red['id']}\" title=\"Disable\">On</a>";
            }
            else {
                
    $status "<a href=\"" ROOT "sponsor/ap.php?act=enable&id={$red['id']}\" title=\"Enable\">Off</a>";
            }
    ?>
                        <tr>
                            <td><?=$red['keyword'];  ?></td><td><?=$red['title']; ?></td><td><?=$red['url']; ?></td><td><?=$red['desc']; ?></td><td><?=$red['img']; ?></td><td>Package</td><td><?=$status?></td><td><?=$red['hits']; ?></td><td><?=$red['expire']; ?></td>
                        </tr>
    <?php
        
    }
    }

    /**
     * Function adds deposited money amount to database.
     */
    function addFunds() {
        global 
    $baza$_SESSION;
        
    $sql "UPDATE users SET amount = amount + '{$_SESSION['money']}' WHERE id = '{$_SESSION['id']}'";
        if(
    $baza -> izvrsiUpit($sql)) echo "Money has been added to your account.";
        
    $_SESSION['amount'] += $_SESSION['money'];
        unset(
    $_SESSION['money']);
        unset(
    $_SESSION['status']);
    }

    /**
     * Function that to checks if users query passes our list of blacklisted words.
     * @param string $q Users query
     * @return bool True if is blacklisted, false if not
     */
    function isBlackListed($q) {
    global 
    $baza;
    $words split('\+|-|_'$q);
    foreach(
    $words as $word) {
    $query "SELECT * FROM blacklist WHERE name LIKE '%$word%'";
    $baza -> izvrsiUpit($query);
    if(
    $baza -> brSelectRedova() > 0) {
    return 
    true;
    }
    }
    return 
    false;
    }
    ?>
    Let me know what you think.

    Tim..

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •