Beispiel #1
0
/**
 * Downloads data to a file
 * 
 * @param string $url
 * @param string $file
 * @return boolean
 */
function w3_download($url, $file)
{
    $data = w3_url_get($url);
    if ($data !== false) {
        return @file_put_contents($file, $data);
    }
    return false;
}
Beispiel #2
0
 /**
  * Show plugin changes
  */
 function in_plugin_update_message()
 {
     $data = w3_url_get(W3TC_README_URL);
     if ($data) {
         $matches = null;
         if (preg_match('~==\\s*Changelog\\s*==\\s*=\\s*[0-9.]+\\s*=(.*)(=\\s*[0-9.]+\\s*=|$)~Uis', $data, $matches)) {
             $changelog = (array) preg_split('~[\\r\\n]+~', trim($matches[1]));
             echo '<div style="color: #f00;">Take a minute to update, here\'s why:</div><div style="font-weight: normal;">';
             $ul = false;
             foreach ($changelog as $index => $line) {
                 if (preg_match('~^\\s*\\*\\s*~', $line)) {
                     if (!$ul) {
                         echo '<ul style="list-style: disc; margin-left: 20px;">';
                         $ul = true;
                     }
                     $line = preg_replace('~^\\s*\\*\\s*~', '', htmlspecialchars($line));
                     echo '<li style="width: 50%; margin: 0; float: left; ' . ($index % 2 == 0 ? 'clear: left;' : '') . '">' . $line . '</li>';
                 } else {
                     if ($ul) {
                         echo '</ul><div style="clear: left;"></div>';
                         $ul = false;
                     }
                     echo '<p style="margin: 5px 0;">' . htmlspecialchars($line) . '</p>';
                 }
             }
             if ($ul) {
                 echo '</ul><div style="clear: left;"></div>';
             }
             echo '</div>';
         }
     }
 }
Beispiel #3
0
 /**
  * Downloads URL
  *
  * @param string $url
  * @param string $file
  * @return boolean
  */
 function download($url, $file)
 {
     if (($data = w3_url_get($url)) && ($fp = @fopen($file, 'w'))) {
         @fputs($fp, $data);
         @fclose($fp);
         return true;
     }
     return false;
 }
Beispiel #4
0
 /**
  * Precaches external file
  *
  * @param string $url
  * @param string $type
  * @return string
  */
 function _precache_file($url, $type)
 {
     $lifetime = $this->_config->get_integer('minify.lifetime');
     $file_path = sprintf('%s/minify_%s.%s', W3TC_CACHE_FILE_MINIFY_DIR, md5($url), $type);
     $file_exists = file_exists($file_path);
     if (file_exists($file_path) && @filemtime($file_path) >= time() - $lifetime) {
         return $this->_get_minify_source($file_path, $url);
     }
     if (is_dir(W3TC_CACHE_FILE_MINIFY_DIR)) {
         if ($file_data = w3_url_get($url)) {
             if ($fp = @fopen($file_path, 'w')) {
                 @fputs($fp, $file_data);
                 @fclose($fp);
                 return $this->_get_minify_source($file_path, $url);
             } else {
                 $this->log(sprintf('Unable to open file %s for writing', $file_path));
             }
         } else {
             $this->log(sprintf('Unable to download URL: %s', $url));
         }
     } else {
         $this->log(sprintf('The cache directory %s does not exist', W3TC_CACHE_FILE_MINIFY_DIR));
     }
     return $file_exists ? $this->_get_minify_source($file_path, $url) : false;
 }