xref: /dokuwiki/lib/plugins/config/core/Setting/SettingDirchoice.php (revision d4f83172d9533c4d84f450fe22ef630816b21d75)
10a5b05ebSAndreas Gohr<?php
20a5b05ebSAndreas Gohr
30a5b05ebSAndreas Gohrnamespace dokuwiki\plugin\config\core\Setting;
40a5b05ebSAndreas Gohr
50a5b05ebSAndreas Gohr/**
60a5b05ebSAndreas Gohr * Class setting_dirchoice
70a5b05ebSAndreas Gohr */
88c7c53b0SAndreas Gohrclass SettingDirchoice extends SettingMultichoice
98c7c53b0SAndreas Gohr{
100a5b05ebSAndreas Gohr    protected $dir = '';
110a5b05ebSAndreas Gohr
120a5b05ebSAndreas Gohr    /** @inheritdoc */
13*d868eb89SAndreas Gohr    public function initialize($default = null, $local = null, $protected = null)
14*d868eb89SAndreas Gohr    {
150a5b05ebSAndreas Gohr
160a5b05ebSAndreas Gohr        // populate $this->_choices with a list of directories
17467c1427SAndreas Gohr        $list = [];
180a5b05ebSAndreas Gohr
190a5b05ebSAndreas Gohr        if ($dh = @opendir($this->dir)) {
200a5b05ebSAndreas Gohr            while (false !== ($entry = readdir($dh))) {
210a5b05ebSAndreas Gohr                if ($entry == '.' || $entry == '..') continue;
220a5b05ebSAndreas Gohr                if ($this->pattern && !preg_match($this->pattern, $entry)) continue;
230a5b05ebSAndreas Gohr
240a5b05ebSAndreas Gohr                $file = (is_link($this->dir . $entry)) ? readlink($this->dir . $entry) : $this->dir . $entry;
250a5b05ebSAndreas Gohr                if (is_dir($file)) $list[] = $entry;
260a5b05ebSAndreas Gohr            }
270a5b05ebSAndreas Gohr            closedir($dh);
280a5b05ebSAndreas Gohr        }
290a5b05ebSAndreas Gohr        sort($list);
300a5b05ebSAndreas Gohr        $this->choices = $list;
310a5b05ebSAndreas Gohr
320a5b05ebSAndreas Gohr        parent::initialize($default, $local, $protected);
330a5b05ebSAndreas Gohr    }
340a5b05ebSAndreas Gohr}
35