1<?php
2/**
3 * additional setting classes specific to these settings
4 *
5 * @author    Chris Smith <chris@jalakai.co.uk>
6 */
7
8namespace dokuwiki\plugin\config\core\Setting;
9
10/**
11 * Class setting_renderer
12 */
13class SettingRenderer extends SettingMultichoice {
14    protected $prompts = array();
15    protected $format = null;
16
17    /** @inheritdoc */
18    public function initialize($default = null, $local = null, $protected = null) {
19        $format = $this->format;
20
21        foreach(plugin_list('renderer') as $plugin) {
22            $renderer = plugin_load('renderer', $plugin);
23            if(method_exists($renderer, 'canRender') && $renderer->canRender($format)) {
24                $this->choices[] = $plugin;
25
26                $info = $renderer->getInfo();
27                $this->prompts[$plugin] = $info['name'];
28            }
29        }
30
31        parent::initialize($default, $local, $protected);
32    }
33
34    /** @inheritdoc */
35    public function html(\admin_plugin_config $plugin, $echo = false) {
36
37        // make some language adjustments (there must be a better way)
38        // transfer some plugin names to the config plugin
39        foreach($this->choices as $choice) {
40            if(!$plugin->getLang($this->key . '_o_' . $choice)) {
41                if(!isset($this->prompts[$choice])) {
42                    $plugin->addLang(
43                        $this->key . '_o_' . $choice,
44                        sprintf($plugin->getLang('renderer__core'), $choice)
45                    );
46                } else {
47                    $plugin->addLang(
48                        $this->key . '_o_' . $choice,
49                        sprintf($plugin->getLang('renderer__plugin'), $this->prompts[$choice])
50                    );
51                }
52            }
53        }
54        return parent::html($plugin, $echo);
55    }
56}
57