コード例 #1
0
ファイル: Comm.php プロジェクト: kmvan/poiauthor
    protected function optSelectList(array $args = [])
    {
        $args = array_merge(['th' => L10n::__('Enable or not?'), 'value' => (int) static::getOpts('enabled'), 'attrs' => [], 'des' => null, 'opts' => [['value' => 1, 'text' => 'y'], ['value' => -1, 'text' => 'n']]], $args);
        $args['attrs'] = array_merge(['id' => static::getOptID() . 'enabled', 'class' => 'widefat', 'name' => static::getOptID() . '[enabled]'], $args['attrs']);
        foreach ($args['attrs'] as $attrName => $attrValue) {
            if ($attrValue === true) {
                $attrs[] = $attrName;
                continue;
            }
            $attrs[] = "{$attrName}=\"{$attrValue}\"";
        }
        ?>
        <tr>
            <th>
                <?php 
        if (isset($args['attrs']['id'])) {
            ?>
                    <label for="<?php 
            echo $args['attrs']['id'];
            ?>
"><?php 
            echo $args['th'];
            ?>
</label>
                <?php 
        } else {
            ?>
                    <?php 
            echo $args['th'];
            ?>
                <?php 
        }
        ?>
            </th>
            <td>
                <select <?php 
        echo implode(' ', $attrs);
        ?>
 >
                    <?php 
        foreach ($args['opts'] as $v) {
            //yes or no
            if (!isset($v['value'])) {
                if ($v['text'] === 'y') {
                    $v['value'] = 1;
                } elseif ($v['text'] === 'n') {
                    $v['value'] = -1;
                }
            }
            if ($v['text'] === 'y') {
                $v['text'] = L10n::_x('Yes', 'Selector');
            } elseif ($v['text'] === 'n') {
                $v['text'] = L10n::_x('No', 'Selector');
            }
            $selected = $v['value'] == $args['value'] ? 'selected' : null;
            ?>
                        <option value="<?php 
            echo $v['value'];
            ?>
" <?php 
            echo $selected;
            ?>
 ><?php 
            echo $v['text'];
            ?>
</option>
                        <?php 
        }
        ?>
                </select>
                <?php 
        if ($args['des']) {
            ?>
                    <p class="description"><?php 
            echo $args['des'];
            ?>
</p>
                <?php 
        }
        ?>
            </td>
        </tr>
        <?php 
    }