Exemplo n.º 1
0
 /**
  * clean()
  *
  * @param string $dir
  * @return bool success
  **/
 static function clean($dir)
 {
     if (!file_exists($dir)) {
         return xml_sitemaps::mkdir($dir);
     } elseif (!is_dir($dir)) {
         return false;
     }
     if (!($handle = opendir($dir))) {
         return false;
     }
     while (($file = readdir($handle)) !== false) {
         if (in_array($file, array('.', '..'))) {
             continue;
         }
         if (!xml_sitemaps::rm("{$dir}/{$file}")) {
             closedir($handle);
             return false;
         }
     }
     closedir($handle);
     return true;
 }
 /**
  * close()
  *
  * @return void
  **/
 function close()
 {
     if (isset($this->fp) && $this->fp) {
         global $wp_filter;
         $wp_filter['option_blog_public'] = $this->filter_backup;
         $o = '</urlset>';
         fwrite($this->fp, $o);
         fclose($this->fp);
         $this->fp = null;
         # compress
         if (function_exists('gzencode')) {
             $gzdata = gzencode(file_get_contents($this->file), 9);
             $fp = fopen($this->file . '.gz', 'w+');
             fwrite($fp, $gzdata);
             fclose($fp);
         }
         # move
         $dir = WP_CONTENT_DIR . '/sitemaps';
         if (defined('SUBDOMAIN_INSTALL') && SUBDOMAIN_INSTALL) {
             $dir .= '/' . $_SERVER['HTTP_HOST'];
         }
         $home_path = parse_url(get_option('home'));
         $home_path = isset($home_path['path']) ? rtrim($home_path['path'], '/') : '';
         $dir .= $home_path;
         $file = $dir . '/sitemap.xml';
         if (!wp_mkdir_p($dir) || !xml_sitemaps::rm($file) || !xml_sitemaps::rm($file . '.gz') || strpos($_SERVER['HTTP_HOST'], '/') !== false) {
             unlink($this->file);
             unlink($this->file . '.gz');
         } else {
             rename($this->file, $file);
             $stat = stat(dirname($file));
             $perms = $stat['mode'] & 0666;
             @chmod($file, $perms);
             if (function_exists('gzencode')) {
                 rename($this->file . '.gz', $file . '.gz');
                 @chmod($file . '.gz', $perms);
             }
         }
     }
 }