Example #1
0
 function tla_ads($xml_filename, $inventory_key, $box_type)
 {
     // Examples
     /*
     $xml_filename = 'local_222925.xml';
     $inventory_key = 'I3XF0SPPQPJOOFR2WSS9';
     */
     // Number of seconds before connection to XML times out
     // (This can be left the way it is)
     $CONNECTION_TIMEOUT = 15;
     // Local file to store XML
     // This file MUST be writable by web server
     // You should create a blank file and CHMOD it to 666
     $LOCAL_XML_FILENAME = IP_ROOT_PATH . 'files/' . $xml_filename;
     $ads_content = '';
     if (!file_exists($LOCAL_XML_FILENAME)) {
         @touch($LOCAL_XML_FILENAME);
         @chmod($LOCAL_XML_FILENAME, 0666);
     }
     if (!file_exists($LOCAL_XML_FILENAME) || !is_writable($LOCAL_XML_FILENAME)) {
         $ads_content = 'File ' . htmlspecialchars($LOCAL_XML_FILENAME) . ' either doesn\'t exist or isn\'t writable.';
         return $ads_content;
     }
     if (filemtime($LOCAL_XML_FILENAME) < time() - 3600 || filesize($LOCAL_XML_FILENAME) < 3) {
         $url = 'http://www.text-link-ads.com/xml.php?k=' . $inventory_key . '&l=php-tla-2.0.1';
         if (function_exists('json_decode') && is_array(json_decode('{"a":1}', true))) {
             $url .= '&f=json';
         }
         tla_updateLocal($url, $LOCAL_XML_FILENAME, $CONNECTION_TIMEOUT);
     }
     if (filemtime($LOCAL_XML_FILENAME) < time() - 3600 || filesize($LOCAL_XML_FILENAME) < 20) {
         $request_uri = isset($_SERVER['REQUEST_URI']) ? $_SERVER['REQUEST_URI'] : '';
         $user_agent = isset($_SERVER['HTTP_USER_AGENT']) ? $_SERVER['HTTP_USER_AGENT'] : '';
         tla_updateLocalXML('http://www.text-link-ads.com/xml.php?inventory_key=' . $inventory_key . '&referer=' . urlencode($request_uri) . '&user_agent=' . urlencode($user_agent), $LOCAL_XML_FILENAME, $CONNECTION_TIMEOUT);
     }
     $xml = tla_getLocal($LOCAL_XML_FILENAME);
     $links = tla_decode($xml);
     if ($links && is_array($links)) {
         $ads_content .= empty($box_type) ? "\n<ul>\n" : '';
         $ads_content .= empty($box_type) ? "\n</ul>\n" : '';
         echo "\n<ul>\n";
         foreach ($links as $link) {
             if (isset($link['PostID']) && $link['PostID'] > 0) {
                 continue;
             }
             //echo '<li style="padding: 0; float: left; margin: 0; width: 25%; clear: none; display: block;">' . ($link['BeforeText'] ? $link['BeforeText'] . ' ' : '') . '<a href="' . $link['URL'] . '">' . $link['Text'] . '</a>' . ($link['AfterText'] ? ' ' . $link['AfterText'] : '') . '</li>' . "\n";
             $ads_content .= (empty($box_type) ? '<li>' : ($ads_count > 0 ? '&nbsp;&nbsp;&bull;&nbsp;&nbsp;' : '')) . $link['BeforeText'] . '<a href="' . $link['URL'] . '">' . $link['Text'] . '</a> ' . $link['AfterText'] . (empty($box_type) ? '</li>' . "\n" : '');
             $ads_count++;
             if (isset($link['PostID']) && $link['PostID'] > 0) {
                 continue;
             }
         }
         echo '</ul>';
     }
     $ads_content = empty($box_type) ? $ads_content : '<div class="gensmall" style="text-align: center;">' . $ads_content . '</div>';
     return $ads_content;
 }
Example #2
0
function tla_ads()
{
    // Number of seconds before connection to XML times out
    // (This can be left the way it is)
    $CONNECTION_TIMEOUT = 15;
    // Local file to store XML
    // This file MUST be writable by web server
    // You should create a blank file and CHMOD it to 666
    $LOCAL_FILENAME = 'local_305242.xml';
    if (!file_exists($LOCAL_FILENAME)) {
        @touch($LOCAL_FILENAME);
        @chmod($LOCAL_FILENAME, 0666);
    }
    if (!file_exists($LOCAL_FILENAME)) {
        die("Script error: {$LOCAL_FILENAME} does not exist. Please create a blank file named {$LOCAL_FILENAME}.");
    }
    if (!is_writable($LOCAL_FILENAME)) {
        die("Script error: {$LOCAL_FILENAME} is not writable. Please set write permissions on {$LOCAL_FILENAME}.");
    }
    if (filemtime($LOCAL_FILENAME) < time() - 3600 || filesize($LOCAL_FILENAME) < 3) {
        $url = 'http://www.text-link-ads.com/xml.php?k=7L84ADUM1LV29T0YVRKR&l=php-tla-2.0.1';
        if (function_exists('json_decode') && is_array(json_decode('{"a":1}', true))) {
            $url .= '&f=json';
        }
        tla_updateLocal($url, $LOCAL_FILENAME, $CONNECTION_TIMEOUT);
    }
    $xml = tla_getLocal($LOCAL_FILENAME);
    $links = tla_decode($xml);
    if (is_array($links)) {
        echo "<div class=\"blog_categories friends\"><ul style=\"margin: 0;padding: 0;\">\n";
        foreach ($links as $link) {
            if (isset($link['PostID']) && $link['PostID'] > 0) {
                continue;
            }
            echo "<li style=\"border-bottom: 1px solid #DDDDDD;display: block;margin: 0;padding: 5px 0 2px;\">" . ($link['BeforeText'] ? $link['BeforeText'] . ' ' : '') . '<a href="' . $link['URL'] . '">' . $link['Text'] . '</a>' . ($link['AfterText'] ? ' ' . $link['AfterText'] : '') . "</li>\n";
        }
        echo '</ul>';
    }
}