xref: /plugin/farmer/helper.php (revision 0b96e6d772940c87b02986642b7897719b5a87dc)
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
62*0b96e6d7SMichael Große
63*0b96e6d7SMichael Große
64*0b96e6d7SMichael Große    public function getAllPlugins() {
65*0b96e6d7SMichael Große        $dir = dir(DOKU_PLUGIN);
66*0b96e6d7SMichael Große        $plugins = array();
67*0b96e6d7SMichael Große        while (false !== ($entry = $dir->read())) {
68*0b96e6d7SMichael Große            if($entry == '.' || $entry == '..') {
69*0b96e6d7SMichael Große                continue;
70*0b96e6d7SMichael Große            }
71*0b96e6d7SMichael Große            if (!is_dir(DOKU_PLUGIN ."/$entry")) {
72*0b96e6d7SMichael Große                continue;
73*0b96e6d7SMichael Große            }
74*0b96e6d7SMichael Große            $plugins[] = $entry;
75*0b96e6d7SMichael Große        }
76*0b96e6d7SMichael Große        return $plugins;
77*0b96e6d7SMichael Große    }
78*0b96e6d7SMichael Große
79*0b96e6d7SMichael Große    public function getAllAnimals() {
80*0b96e6d7SMichael Große        $animals = array();
81*0b96e6d7SMichael Große
82*0b96e6d7SMichael Große        $dir = dir(DOKU_FARMDIR);
83*0b96e6d7SMichael Große        while (false !== ($entry = $dir->read())) {
84*0b96e6d7SMichael Große            if ($entry == '.' || $entry == '..' || $entry == '_animal') {
85*0b96e6d7SMichael Große                continue;
86*0b96e6d7SMichael Große            }
87*0b96e6d7SMichael Große            $animals[] = $entry;
88*0b96e6d7SMichael Große        }
89*0b96e6d7SMichael Große        $dir->close();
90*0b96e6d7SMichael Große        return $animals;
91*0b96e6d7SMichael Große    }
92*0b96e6d7SMichael Große
93bc461538SMichael Große}
94