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