Exemplo n.º 1
0
 public function addDir($path, $excludes)
 {
     if ('.' == basename($path) || '..' == basename($path)) {
         return;
     }
     $this->addEmptyDir($path, str_replace(ABSPATH, '', $path));
     if (file_exists(rtrim($path, '/') . '/.htaccess')) {
         $this->addFile(rtrim($path, '/') . '/.htaccess', rtrim(str_replace(ABSPATH, '', $path), '/') . '/mainwp-htaccess');
     }
     $iterator = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($path), RecursiveIteratorIterator::SELF_FIRST, RecursiveIteratorIterator::CATCH_GET_CHILD);
     if (class_exists('ExampleSortedIterator')) {
         $iterator = new ExampleSortedIterator($iterator);
     }
     /** @var $path DirectoryIterator */
     foreach ($iterator as $path) {
         $name = $path->__toString();
         if ('.' == basename($name) || '..' == basename($name)) {
             continue;
         }
         if (!MainWP_Helper::inExcludes($excludes, str_replace(ABSPATH, '', $name))) {
             if ($path->isDir()) {
                 $this->addEmptyDir($name, str_replace(ABSPATH, '', $name));
             } else {
                 $this->addFile($name, str_replace(ABSPATH, '', $name));
             }
         }
         $name = null;
         unset($name);
     }
     $iterator = null;
     unset($iterator);
 }
Exemplo n.º 2
0
 /**
  * Recursive add directory for default PHP zip library
  */
 public function zipAddDir($path, $excludes)
 {
     $this->zip->addEmptyDir(str_replace(ABSPATH, '', $path));
     if (file_exists(rtrim($path, '/') . '/.htaccess')) {
         $this->addFileToZip(rtrim($path, '/') . '/.htaccess', rtrim(str_replace(ABSPATH, '', $path), '/') . '/mainwp-htaccess');
     }
     $iterator = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($path), RecursiveIteratorIterator::SELF_FIRST);
     foreach ($iterator as $path) {
         $name = $path->__toString();
         if ('.' === basename($name) || '..' === basename($name)) {
             continue;
         }
         if (!MainWP_Helper::inExcludes($excludes, str_replace(ABSPATH, '', $name))) {
             if ($path->isDir()) {
                 $this->zipAddDir($name, $excludes);
             } else {
                 $this->addFileToZip($name, str_replace(ABSPATH, '', $name));
             }
         }
         $name = null;
         unset($name);
     }
     $iterator = null;
     unset($iterator);
     //        $nodes = glob(rtrim($path, '/') . '/*');
     //        if (empty($nodes)) return true;
     //
     //        foreach ($nodes as $node)
     //        {
     //            if (!MainWP_Helper::inExcludes($excludes, str_replace(ABSPATH, '', $node)))
     //            {
     //                if (is_dir($node))
     //                {
     //                    $this->zipAddDir($node, $excludes);
     //                }
     //                else if (is_file($node))
     //                {
     //                    $this->addFileToZip($node, str_replace(ABSPATH, '', $node));
     //                }
     //            }
     //        }
 }