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

ThemeGenerator.php « classes « libraries - github.com/phpmyadmin/phpmyadmin.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: c49dca25fe4b3795a801a2c90c18edd9688b8c63 (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
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
<?php
/* vim: set expandtab sw=4 ts=4 sts=4: */
/**
 * Holds the PhpMyAdmin\ThemeGenerator class
 *
 * @package PhpMyAdmin
 */
declare(strict_types=1);

namespace PhpMyAdmin;

use PhpMyAdmin\Message;
use PhpMyAdmin\Sanitize;
use PhpMyAdmin\Template;
use PhpMyAdmin\ThemeGenerator\Common;
use PhpMyAdmin\ThemeGenerator\Layout;
use PhpMyAdmin\ThemeGenerator\Navigation;

/**
 * Set of functions for Automated Theme Generator in phpMyAdmin
 *
 * @package PhpMyAdmin
 */
class ThemeGenerator
{
    protected $template;

    /**
     * Constructor
     */
    public function __construct()
    {
        $this->template = new Template();
    }

    /**
     * Colour Picker HTML file
     *
     * @return string HTML for the color picker tool
     */
    public function colorPicker()
    {
        $output = $this->template->render('theme_generator/color_picker');
        return $output;
    }

    /**
     * File creation form
     *
     * @return string HTML for the form submission
     */
    public function form()
    {
        $output = $this->template->render('theme_generator/form');
        return $output;
    }

    /**
     * Preview panel for Table
     *
     * @return string HTML for the preview panels
     */
    public function tablePreview()
    {
        $output = $this->template->render('theme_generator/table_preview');
        return $output;
    }

    /**
     * Preview panel for Groups
     *
     * @return string HTML for the preview panels
     */
    public function groupPreview()
    {
        $output = $this->template->render('theme_generator/group_preview');
        return $output;
    }

    /**
     * Creates file structure
     *
     * @param array $post POST form data
     *
     * @return array $out generated file data
     */
    public function createFileStructure(array $post)
    {
        $out = array();
        $nav = new Navigation();
        $layout = new Layout();
        $common = new Common();
        $post['theme_name'] = Sanitize::sanitizeFilename($post['theme_name'], true);
        $name = $post['theme_name'];
        if (!is_dir("themes/" . $name)) {
            @mkdir("themes/" . $name);
            @mkdir("themes/" . $name . "/css");
        }
        if (is_dir("themes/" . $name)) {
            $out['json'] = $this->createJsonFile($post);
            $common->createCommonFile($name);
            $out['layout'] = $layout->createLayoutFile($post);
            $nav->createNavigationFile($name);
        }
        return $out;
    }

    /**
     * Checks whether the theme directory is writable
     *
     * @return null
     */
    public function testWritableThemeDirectory()
    {
      clearstatcache();
      if (! is_writable('themes')) {
        trigger_error(__("The 'themes' directory is not writable by the webserver process. You must change permissions for the theme generator to be able to write the generated theme."), E_USER_WARNING);
      }
      return;
    }

    /**
     * Creates theme.json
     *
     * @param array $post POST data
     *
     * @return string $txt JSON file data
     */
    public function createJsonFile($post)
    {
        $name = $post['theme_name'];
        $file = fopen("themes/" . $name . "/theme.json", "w");
        $txt = '{';
        $txt .= '"name": "' . $name . '",';
        if ($post['version'] != "") {
            $txt .= '"version": "' . $post['version'] . '",';
        } else {
            $txt .= '"version": "5.0",';
        }
        if ($post['description'] != "") {
            $txt .= '"description": "' . $post['description'] . '",';
        } else {
            $txt .= '"description": "Theme Generated by Automated Theme Generator",';
        }
        if ($post['author'] != "") {
            $txt .= '"author": "' . $post['author'] . '",';
        } else {
            $txt .= '"author": "",';
        }
        if ($post['url'] != "") {
            $txt .= '"url": "' . $post['url'] . '",';
        } else {
            $txt .= '"url": "https://www.phpmyadmin.net/",';
        }
        $version = str_split(PMA_VERSION);
        $trimmed_version = array_slice($version, 0, 3);
        $txt .= '"supports": ["' . implode($trimmed_version) . '"]';
        $txt .= '}';
        // Check if the file is writable as this condition would only occur if files are overwritten.
        if ($file) {
            fwrite($file, $txt);
            fclose($file);
            return $txt;
        } else {
            trigger_error(__("The theme.json file is not writable by the webserver process. You must change permissions for the theme generator to be able to write the generated theme."), E_USER_ERROR);
            return;
        }
    }
}