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