Welcome to mirror list, hosted at ThFree Co, Russian Federation.

TreeController.php « xhtml « src - github.com/HuasoFoundries/phpPgAdmin6.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: e50620723ab65267f9bd5d97fb11583b74da5ab9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
<?php

/**
 * PHPPgAdmin v6.0.0-RC1.
 */

namespace PHPPgAdmin\XHtml;

use PHPPgAdmin\Decorators\Decorator;

/**
 * Base TreeController controller class.
 */
class TreeController
{
    use \PHPPgAdmin\Traits\HelperTrait;

    protected $container;
    public $form             = '';
    public $href             = '';
    public $lang             = [];
    public $action           = '';
    public $controller_name  = 'TreeController';
    public $controller_title = 'base';

    // Constructor
    public function __construct(\Slim\Container $container, $controller_name = null)
    {
        $this->container = $container;
        $this->lang      = $container->get('lang');
        //$this->conf           = $container->get('conf');
        $this->view           = $container->get('view');
        $this->plugin_manager = $container->get('plugin_manager');
        $this->appName        = $container->get('settings')['appName'];
        $this->appVersion     = $container->get('settings')['appVersion'];
        $this->appLangFiles   = $container->get('appLangFiles');
        $this->misc           = $container->get('misc');
        $this->conf           = $this->misc->getConf();
        $this->appThemes      = $container->get('appThemes');
        $this->action         = $container->get('action');
        if (null !== $controller_name) {
            $this->controller_name = $controller_name;
        }
    }

    /**
     * Produce JSON data for the browser tree.
     *
     * @param array $treedata a set of records to populate the tree
     * @param array $attrs    Attributes for tree items
     *                        'text' - the text for the tree node
     *                        'icon' - an icon for node
     *                        'openIcon' - an alternative icon when the node is expanded
     *                        'toolTip' - tool tip text for the node
     *                        'action' - URL to visit when single clicking the node
     *                        'iconAction' - URL to visit when single clicking the icon node
     *                        'branch' - URL for child nodes (tree JSON)
     *                        'expand' - the action to return JSON for the subtree
     *                        'nodata' - message to display when node has no children
     * @param string  $section section of the tree
     *
     * @return \Slim\Http\Response|string the json rendered tree
     */
    public function printTreeJSON(&$treedata, &$attrs, $section = '')
    {
        $tree_params = [
            'treedata' => &$treedata,
            'attrs'    => &$attrs,
            'section'  => $section,
        ];
        $plugin_manager = $this->plugin_manager;
        $plugin_manager->doHook('tree', $tree_params);

        $parent = [];

        if (isset($attrs['is_root'])) {
            $parent = [
                'id'       => 'root',
                'children' => true,
                'icon'     => \SUBFOLDER . '/assets/images/themes/default/Servers.png',
                'state'    => ['opened' => true],
                'a_attr'   => ['href' => str_replace('//', '/', \SUBFOLDER . '/src/views/servers')],
                'url'      => str_replace('//', '/', \SUBFOLDER . '/src/views/servers?action=tree'),
                'text'     => 'Servers',
            ];
        } elseif (count($treedata) > 0) {
            foreach ($treedata as $rec) {
                $icon = $this->misc->icon(Decorator::get_sanitized_value($attrs['icon'], $rec));
                if (!empty($attrs['openicon'])) {
                    $icon = $this->misc->icon(Decorator::get_sanitized_value($attrs['openIcon'], $rec));
                }

                $tree = [
                    'text'       => Decorator::get_sanitized_value($attrs['text'], $rec),
                    'id'         => sha1(Decorator::get_sanitized_value($attrs['action'], $rec)),
                    'icon'       => Decorator::get_sanitized_value($icon, $rec),
                    'iconaction' => Decorator::get_sanitized_value($attrs['iconAction'], $rec),
                    'openicon'   => Decorator::get_sanitized_value($icon, $rec),
                    'tooltip'    => Decorator::get_sanitized_value($attrs['toolTip'], $rec),
                    'a_attr'     => ['href' => Decorator::get_sanitized_value($attrs['action'], $rec)],
                    'children'   => false,
                ];
                $url = Decorator::get_sanitized_value($attrs['branch'], $rec);
                if ($url && strpos($url, '/src/views') === false) {
                    $url = str_replace('//', '/', \SUBFOLDER . '/src/views/' . $url);
                }
                if ($url) {
                    $tree['url']      = $url;
                    $tree['children'] = true;
                }

                //$tree['text'] = '<a href="' . $tree['id'] . '" target="detail">' . $tree['text'] . '</a>';

                $parent[] = $tree;
            }
        } else {
            $parent = ['children' => false];
        }

        if (isset($_REQUEST['children'])) {
            $children = $parent;
            $parent   = ['children' => $children];
        }

        return $this
            ->container
            ->responseobj
            ->withStatus(200)
            ->withJson($parent);

    }

    /**
     * Hides or show tree tabs according to their properties.
     *
     * @param array $tabs The tabs
     *
     * @return \PHPPgAdmin\ArrayRecordSet filtered tabs in the form of an ArrayRecordSet
     */
    public function adjustTabsForTree(&$tabs)
    {
        foreach ($tabs as $i => $tab) {
            if ((isset($tab['hide']) && true === $tab['hide']) || (isset($tab['tree']) && false === $tab['tree'])) {
                unset($tabs[$i]);
            }
        }

        return new \PHPPgAdmin\ArrayRecordSet($tabs);
    }
}