1<?php 2/** 3 * DokuWiki Plugin farmer (Helper Component) 4 * 5 * @license GPL 2 http://www.gnu.org/licenses/gpl-2.0.html 6 * @author Michael Große <grosse@cosmocode.de> 7 */ 8 9// must be run within Dokuwiki 10if(!defined('DOKU_INC')) die(); 11 12class helper_plugin_farmer extends DokuWiki_Plugin { 13 14 /** 15 * Copy a file, or recursively copy a folder and its contents. Adapted for DokuWiki. 16 * 17 * @todo: needs tests 18 * 19 * @author Aidan Lister <aidan@php.net> 20 * @author Michael Große <grosse@cosmocode.de> 21 * @version 1.0.1 22 * @link http://aidanlister.com/2004/04/recursively-copying-directories-in-php/ 23 * 24 * @param string $source Source path 25 * @param string $destination Destination path 26 * 27 * @return bool Returns TRUE on success, FALSE on failure 28 */ 29 function io_copyDir($source, $destination) { 30 if (is_link($source)) { 31 io_lock($destination); 32 $result=symlink(readlink($source), $destination); 33 io_unlock($destination); 34 return $result; 35 } 36 37 if (is_file($source)) { 38 io_lock($destination); 39 $result=copy($source, $destination); 40 io_unlock($destination); 41 return $result; 42 } 43 44 if (!is_dir($destination)) { 45 io_mkdir_p($destination); 46 } 47 48 $dir = dir($source); 49 while (false !== ($entry = $dir->read())) { 50 if ($entry == '.' || $entry == '..') { 51 continue; 52 } 53 54 // recurse into directories 55 $this->io_copyDir("$source/$entry", "$destination/$entry"); 56 } 57 58 $dir->close(); 59 return true; 60 } 61 62} 63