1bc461538SMichael Große<?php 2bc461538SMichael Große/** 3bc461538SMichael Große * DokuWiki Plugin farmer (Helper Component) 4bc461538SMichael Große * 5bc461538SMichael Große * @license GPL 2 http://www.gnu.org/licenses/gpl-2.0.html 6bc461538SMichael Große * @author Michael Große <grosse@cosmocode.de> 7bc461538SMichael Große */ 8bc461538SMichael Große 9bc461538SMichael Große// must be run within Dokuwiki 10bc461538SMichael Großeif(!defined('DOKU_INC')) die(); 11bc461538SMichael Große 12bc461538SMichael Großeclass helper_plugin_farmer extends DokuWiki_Plugin { 13bc461538SMichael Große 14bc461538SMichael Große /** 15bc461538SMichael Große * Copy a file, or recursively copy a folder and its contents. Adapted for DokuWiki. 16bc461538SMichael Große * 17bc461538SMichael Große * @todo: needs tests 18bc461538SMichael Große * 19bc461538SMichael Große * @author Aidan Lister <aidan@php.net> 20bc461538SMichael Große * @author Michael Große <grosse@cosmocode.de> 21bc461538SMichael Große * @version 1.0.1 22bc461538SMichael Große * @link http://aidanlister.com/2004/04/recursively-copying-directories-in-php/ 23bc461538SMichael Große * 24bc461538SMichael Große * @param string $source Source path 25bc461538SMichael Große * @param string $destination Destination path 26bc461538SMichael Große * 27bc461538SMichael Große * @return bool Returns TRUE on success, FALSE on failure 28bc461538SMichael Große */ 29bc461538SMichael Große function io_copyDir($source, $destination) { 30bc461538SMichael Große if (is_link($source)) { 31bc461538SMichael Große io_lock($destination); 32bc461538SMichael Große $result=symlink(readlink($source), $destination); 33bc461538SMichael Große io_unlock($destination); 34bc461538SMichael Große return $result; 35bc461538SMichael Große } 36bc461538SMichael Große 37bc461538SMichael Große if (is_file($source)) { 38bc461538SMichael Große io_lock($destination); 39bc461538SMichael Große $result=copy($source, $destination); 40bc461538SMichael Große io_unlock($destination); 41bc461538SMichael Große return $result; 42bc461538SMichael Große } 43bc461538SMichael Große 44bc461538SMichael Große if (!is_dir($destination)) { 45bc461538SMichael Große io_mkdir_p($destination); 46bc461538SMichael Große } 47bc461538SMichael Große 48bc461538SMichael Große $dir = dir($source); 49bc461538SMichael Große while (false !== ($entry = $dir->read())) { 50bc461538SMichael Große if ($entry == '.' || $entry == '..') { 51bc461538SMichael Große continue; 52bc461538SMichael Große } 53bc461538SMichael Große 54bc461538SMichael Große // recurse into directories 55bc461538SMichael Große $this->io_copyDir("$source/$entry", "$destination/$entry"); 56bc461538SMichael Große } 57bc461538SMichael Große 58bc461538SMichael Große $dir->close(); 59bc461538SMichael Große return true; 60bc461538SMichael Große } 61bc461538SMichael Große 620b96e6d7SMichael Große 630b96e6d7SMichael Große 640b96e6d7SMichael Große public function getAllPlugins() { 650b96e6d7SMichael Große $dir = dir(DOKU_PLUGIN); 660b96e6d7SMichael Große $plugins = array(); 670b96e6d7SMichael Große while (false !== ($entry = $dir->read())) { 68*6ec1ad8fSMichael Große if($entry == '.' || $entry == '..' || $entry == 'testing') { 690b96e6d7SMichael Große continue; 700b96e6d7SMichael Große } 710b96e6d7SMichael Große if (!is_dir(DOKU_PLUGIN ."/$entry")) { 720b96e6d7SMichael Große continue; 730b96e6d7SMichael Große } 740b96e6d7SMichael Große $plugins[] = $entry; 750b96e6d7SMichael Große } 76*6ec1ad8fSMichael Große sort($plugins); 770b96e6d7SMichael Große return $plugins; 780b96e6d7SMichael Große } 790b96e6d7SMichael Große 800b96e6d7SMichael Große public function getAllAnimals() { 810b96e6d7SMichael Große $animals = array(); 820b96e6d7SMichael Große 830b96e6d7SMichael Große $dir = dir(DOKU_FARMDIR); 840b96e6d7SMichael Große while (false !== ($entry = $dir->read())) { 850b96e6d7SMichael Große if ($entry == '.' || $entry == '..' || $entry == '_animal') { 860b96e6d7SMichael Große continue; 870b96e6d7SMichael Große } 880b96e6d7SMichael Große $animals[] = $entry; 890b96e6d7SMichael Große } 900b96e6d7SMichael Große $dir->close(); 910b96e6d7SMichael Große return $animals; 920b96e6d7SMichael Große } 930b96e6d7SMichael Große 94bc461538SMichael Große} 95