WordPress.org

Ready to get started?Download WordPress

Forums

rotating ad plugin on domains and subdomains (4 posts)

  1. ahmedredashaban
    Member
    Posted 11 months ago #

    Hi experts, how's life? hope you are doing great.

    I want to create a develop a advertising plugin, I'm using datafeedr plugin for advertising and it's great however, I want to add some codes to enable it from functions as the following:

    When I add a post in the (main domain) it posts in the rest of sub-domains running with the same theme.

    I have these codes and I don't know how to use it

    <?php
    //-------------- Configuration ----------------------------
    define('ads_server_url','http://ads.302labs.net');
    define('ads_cache_dir','ads/cache/');
    define('ads_cache_path','/var/www/ads/');
    define('ads_server_id','23');
    // in secs with max 60, in minutes with max 60, in hours with max 24 or in days with max 31.
    define('cache_time', 5);
    // use 'sec', 'min', 'hr' or 'day'.
    define('cache_time_unit', 'min');
    
    //-------------- Code ----------------------------
    $year = date('Y');
    $month = date('m');
    
    if(cache_time_unit == 'day') {
    	$day = floor(date('j') / cache_time) * cache_time;
    	$day_end = $day + cache_time;
    } else {
    	$day = date('j');
    	$day_end = $day;
    }
    
    if(cache_time_unit == 'hr') {
    	$hour = floor(date('H') / cache_time) * cache_time;
    	$hour_end = $hour + cache_time;
    } else {
    	$hour = date('H');
    	$hour_end = $hour;
    }
    
    if(cache_time_unit == 'min') {
    	$minute = floor(date('i') / cache_time) * cache_time;
    	$minute_end = $minute + cache_time;
    } else {
    	$minute = date('i');
    	$minute_end = $minute;
    }
    
    if(cache_time_unit == 'sec') {
    	$sec = floor(date('s') / cache_time) * cache_time;
    	$sec_end = $sec + cache_time;
    } else {
    	$sec = 0;
    	$sec_end = $sec;
    }
    
    $current_time = time();
    $st_time = mktime($hour, $minute, $sec, $month, $day, $year);
    $end_time = mktime($hour_end, $minute_end, $sec_end, $month, $day_end, $year);
    
    //$file_name = ads_cache_path . $st_time . '.inc';
    $file_name = ads_cache_path . 'data.inc';
    
    if(($current_time > $st_time && $current_time < $end_time) && file_exists($file_name)) {
            include($file_name);
    } else {
            $xml = simplexml_load_file( ads_server_url . "/?post_type=ads&feed=rss2" . "&cat=" . ads_server_id);
            $i = 0;
            foreach($xml->channel->item as $srvad){
                    $srvads[$i]['adid'] = (string) $srvad->adid;
                    $srvads[$i]['adurl'] = (string) $srvad->adurl;
                    $srvads[$i]['adimgurl'] = (string) $srvad->adimgurl[0];
    		copy($srvads[$i]['adimgurl'] , ads_cache_dir . $srvad->adid . '.gif');
    		$srvads[$i]['adimgurl'] = ads_cache_dir . $srvad->adid . '.gif';
                    $srvads[$i]['title'] = (string) $srvad->title;
                    $i++;
            }
    
            $fp = fopen($file_name, 'w+');
            fwrite($fp, '<?php $srvads = unserialize(\'' . serialize($srvads) . '\');');
            fclose($fp);
    
    }
    $ad_keys = array_keys($srvads);
    shuffle($ad_keys);
    foreach($ad_keys  as $value) {
            $srvads_rand[] = $srvads[$value];
    }
    $srvads = $srvads_rand;
    
    $ad_order = 0;
    
    function ad_widget() {
            global $srvads, $ad_order;
    
            if (!empty($srvads)){
                    echo "<a href='" . ads_server_url . "/redirect.php?adid=" . $srvads[$ad_order]['adid'] . "&act=" . $srvads[$ad_order]['adurl'] . "'>";
                    echo "<img src='" . $srvads[$ad_order]['adimgurl'] . "' class='attachment-full wp-post-image'>";
                    echo "</a>";
                    $ad_order++;
             }
    }

    and I know that I have to include a function in the main theme
    (functions.php)

    include('/var/www/ads/ads.inc');

    but I don't know how to merge those functions with datafeedr plugin or creating another plugin that functions as I want .. Please help .. I know you have the answers

  2. ahmedredashaban
    Member
    Posted 11 months ago #

    anybody there?

  3. ahmedredashaban
    Member
    Posted 11 months ago #

    how can I edit this post?

  4. ahmedredashaban
    Member
    Posted 11 months ago #

    up

Reply

You must log in to post.

About this Topic