xref: /dokuwiki/lib/plugins/config/core/Setting/SettingDirchoice.php (revision 8c7c53b0321a3cd3116b8d3b2ad27863a38dece7)
1<?php
2
3namespace dokuwiki\plugin\config\core\Setting;
4
5/**
6 * Class setting_dirchoice
7 */
8class SettingDirchoice extends SettingMultichoice
9{
10
11    protected $dir = '';
12
13    /** @inheritdoc */
14    public function initialize($default = null, $local = null, $protected = null) {
15
16        // populate $this->_choices with a list of directories
17        $list = [];
18
19        if($dh = @opendir($this->dir)) {
20            while(false !== ($entry = readdir($dh))) {
21                if($entry == '.' || $entry == '..') continue;
22                if($this->pattern && !preg_match($this->pattern, $entry)) continue;
23
24                $file = (is_link($this->dir . $entry)) ? readlink($this->dir . $entry) : $this->dir . $entry;
25                if(is_dir($file)) $list[] = $entry;
26            }
27            closedir($dh);
28        }
29        sort($list);
30        $this->choices = $list;
31
32        parent::initialize($default, $local, $protected);
33    }
34}
35