20 * @author Dan Fuhry |
20 * @author Dan Fuhry |
21 */ |
21 */ |
22 |
22 |
23 class Enano_Installer_UI |
23 class Enano_Installer_UI |
24 { |
24 { |
25 /** |
25 /** |
26 * The list of installer stages. |
26 * The list of installer stages. |
27 * @var array |
27 * @var array |
28 */ |
28 */ |
29 |
29 |
30 var $stages = array(); |
30 var $stages = array(); |
31 |
31 |
32 /** |
32 /** |
33 * The GUID of the active stage |
33 * The GUID of the active stage |
34 * @var string |
34 * @var string |
35 */ |
35 */ |
36 |
36 |
37 var $current_stage = ''; |
37 var $current_stage = ''; |
38 |
38 |
39 /** |
39 /** |
40 * The application name, or the name displayed after the stage name in the title bar. Should be localized. |
40 * The application name, or the name displayed after the stage name in the title bar. Should be localized. |
41 * @var string |
41 * @var string |
42 */ |
42 */ |
43 |
43 |
44 var $app_name = ''; |
44 var $app_name = ''; |
45 |
45 |
46 /** |
46 /** |
47 * If the header should be simplified (stripped of the Enano logo and top heading), this will be true. |
47 * If the header should be simplified (stripped of the Enano logo and top heading), this will be true. |
48 * @var bool |
48 * @var bool |
49 */ |
49 */ |
50 |
50 |
51 var $simple = false; |
51 var $simple = false; |
52 |
52 |
53 /** |
53 /** |
54 * Text inserted into the header on the right. |
54 * Text inserted into the header on the right. |
55 * @var string |
55 * @var string |
56 */ |
56 */ |
57 |
57 |
58 var $step = ''; |
58 var $step = ''; |
59 |
59 |
60 /** |
60 /** |
61 * Extra text to add to the HTML <head> section |
61 * Extra text to add to the HTML <head> section |
62 * @var array Will be implode()'ed |
62 * @var array Will be implode()'ed |
63 */ |
63 */ |
64 |
64 |
65 var $additional_headers = array(); |
65 var $additional_headers = array(); |
66 |
66 |
67 /** |
67 /** |
68 * Constructor. |
68 * Constructor. |
69 * @param string The name displayed in the <title> tag |
69 * @param string The name displayed in the <title> tag |
70 * @param bool If true, the simplified header format is displayed. |
70 * @param bool If true, the simplified header format is displayed. |
71 */ |
71 */ |
72 |
72 |
73 function __construct($app_name, $simple_header) |
73 function __construct($app_name, $simple_header) |
74 { |
74 { |
75 $this->stages = array( |
75 $this->stages = array( |
76 'main' => array(), |
76 'main' => array(), |
77 'hide' => array() |
77 'hide' => array() |
78 ); |
78 ); |
79 $this->app_name = $app_name; |
79 $this->app_name = $app_name; |
80 $this->simple = ( $simple_header ) ? true : false; |
80 $this->simple = ( $simple_header ) ? true : false; |
81 } |
81 } |
82 |
82 |
83 /** |
83 /** |
84 * Adds more text to the HTML header. |
84 * Adds more text to the HTML header. |
85 * @param string |
85 * @param string |
86 */ |
86 */ |
87 |
87 |
88 function add_header($html) |
88 function add_header($html) |
89 { |
89 { |
90 $this->additional_headers[] = $html; |
90 $this->additional_headers[] = $html; |
91 } |
91 } |
92 |
92 |
93 /** |
93 /** |
94 * Adds a stage to the installer. |
94 * Adds a stage to the installer. |
95 * @param string Title of the stage, should be already put through $lang->get() |
95 * @param string Title of the stage, should be already put through $lang->get() |
96 * @param bool If true, the stage is shown among possible stages at the top of the window. If false, acts as a hidden stage |
96 * @param bool If true, the stage is shown among possible stages at the top of the window. If false, acts as a hidden stage |
97 * @return string Unique identifier for stage, used later on set_visible_stage() |
97 * @return string Unique identifier for stage, used later on set_visible_stage() |
98 */ |
98 */ |
99 |
99 |
100 function add_stage($stage, $visible = true) |
100 function add_stage($stage, $visible = true) |
101 { |
101 { |
102 $key = ( $visible ) ? 'main' : 'hide'; |
102 $key = ( $visible ) ? 'main' : 'hide'; |
103 $guid = md5(microtime() . mt_rand()); |
103 $guid = md5(microtime() . mt_rand()); |
104 $this->stages[$key][$guid] = $stage; |
104 $this->stages[$key][$guid] = $stage; |
105 if ( empty($this->current_stage) ) |
105 if ( empty($this->current_stage) ) |
106 $this->current_stage = $guid; |
106 $this->current_stage = $guid; |
107 return $guid; |
107 return $guid; |
108 } |
108 } |
109 |
109 |
110 /** |
110 /** |
111 * Resets the active stage of installation. This is for the UI only; it doesn't actually change how the backend works. |
111 * Resets the active stage of installation. This is for the UI only; it doesn't actually change how the backend works. |
112 * @param string GUID of stage, returned from add_stage() |
112 * @param string GUID of stage, returned from add_stage() |
113 * @return bool true on success, false if stage GUID not found |
113 * @return bool true on success, false if stage GUID not found |
114 */ |
114 */ |
115 |
115 |
116 function set_visible_stage($guid) |
116 function set_visible_stage($guid) |
117 { |
117 { |
118 foreach ( $this->stages['main'] as $key => $stage_name ) |
118 foreach ( $this->stages['main'] as $key => $stage_name ) |
119 { |
119 { |
120 if ( $key == $guid ) |
120 if ( $key == $guid ) |
121 { |
121 { |
122 $this->current_stage = $guid; |
122 $this->current_stage = $guid; |
123 return true; |
123 return true; |
124 } |
124 } |
125 } |
125 } |
126 foreach ( $this->stages['hide'] as $key => $stage_name ) |
126 foreach ( $this->stages['hide'] as $key => $stage_name ) |
127 { |
127 { |
128 if ( $key == $guid ) |
128 if ( $key == $guid ) |
129 { |
129 { |
130 $this->current_stage = $guid; |
130 $this->current_stage = $guid; |
131 return true; |
131 return true; |
132 } |
132 } |
133 } |
133 } |
134 return false; |
134 return false; |
135 } |
135 } |
136 |
136 |
137 /** |
137 /** |
138 * Outputs the HTML headers and start of the <body>, including stage indicator |
138 * Outputs the HTML headers and start of the <body>, including stage indicator |
139 */ |
139 */ |
140 |
140 |
141 function show_header() |
141 function show_header() |
142 { |
142 { |
143 // Determine the name of the current stage |
143 // Determine the name of the current stage |
144 $stage_name = false; |
144 $stage_name = false; |
145 |
145 |
146 if ( isset($this->stages['main'][$this->current_stage]) ) |
146 if ( isset($this->stages['main'][$this->current_stage]) ) |
147 $stage_name = $this->stages['main'][$this->current_stage]; |
147 $stage_name = $this->stages['main'][$this->current_stage]; |
148 else if ( isset($this->stages['hide'][$this->current_stage]) ) |
148 else if ( isset($this->stages['hide'][$this->current_stage]) ) |
149 $stage_name = $this->stages['hide'][$this->current_stage]; |
149 $stage_name = $this->stages['hide'][$this->current_stage]; |
150 else |
150 else |
151 // Can't determine name of stage |
151 // Can't determine name of stage |
152 return false; |
152 return false; |
153 |
153 |
154 $this->app_name = htmlspecialchars($this->app_name); |
154 $this->app_name = htmlspecialchars($this->app_name); |
155 $stage_name = htmlspecialchars($stage_name); |
155 $stage_name = htmlspecialchars($stage_name); |
156 |
156 |
157 global $lang; |
157 global $lang; |
158 if ( is_object($lang) && isset($GLOBALS['lang_uri']) ) |
158 if ( is_object($lang) && isset($GLOBALS['lang_uri']) ) |
159 { |
159 { |
160 $lang_uri = sprintf($GLOBALS['lang_uri'], $lang->lang_code); |
160 $lang_uri = sprintf($GLOBALS['lang_uri'], $lang->lang_code); |
161 $this->add_header('<script type="text/javascript" src="' . $lang_uri . '"></script>'); |
161 $this->add_header('<script type="text/javascript" src="' . $lang_uri . '"></script>'); |
162 } |
162 } |
163 |
163 |
164 $additional_headers = implode("\n ", $this->additional_headers); |
164 $additional_headers = implode("\n ", $this->additional_headers); |
165 $title = addslashes(str_replace(' ', '_', $stage_name)); |
165 $title = addslashes(str_replace(' ', '_', $stage_name)); |
166 $js_dynamic = '<script type="text/javascript"> |
166 $js_dynamic = '<script type="text/javascript"> |
167 var title="' . $title . '"; |
167 var title="' . $title . '"; |
168 var scriptPath="'.scriptPath.'"; |
168 var scriptPath="'.scriptPath.'"; |
169 var cdnPath="'.scriptPath.'"; |
169 var cdnPath="'.scriptPath.'"; |
170 var ENANO_SID=""; |
170 var ENANO_SID=""; |
171 var AES_BITS='.AES_BITS.'; |
171 var AES_BITS='.AES_BITS.'; |
172 var AES_BLOCKSIZE=' . AES_BLOCKSIZE . '; |
172 var AES_BLOCKSIZE=' . AES_BLOCKSIZE . '; |
173 var pagepass=\'\'; |
173 var pagepass=\'\'; |
174 var ENANO_LANG_ID = 1; |
174 var ENANO_LANG_ID = 1; |
175 var DISABLE_MCE = true; |
175 var DISABLE_MCE = true; |
176 var enano_version = \'' . installer_enano_version() . '\'; |
176 var enano_version = \'' . installer_enano_version() . '\'; |
177 var msg_loading_component = \'Loading %component%...\'; |
177 var msg_loading_component = \'Loading %component%...\'; |
178 </script>'; |
178 </script>'; |
179 |
179 |
180 echo <<<EOF |
180 echo <<<EOF |
181 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd"> |
181 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd"> |
182 <html xmlns="http://www.w3.org/1999/xhtml"> |
182 <html xmlns="http://www.w3.org/1999/xhtml"> |
183 <head> |
183 <head> |
184 <title>{$stage_name} • {$this->app_name}</title> |
184 <title>{$stage_name} • {$this->app_name}</title> |
185 <meta http-equiv="Content-type" content="text/html; charset=utf-8" /> |
185 <meta http-equiv="Content-type" content="text/html; charset=utf-8" /> |
186 <link rel="stylesheet" type="text/css" href="../includes/clientside/css/enano-shared.css" /> |
186 <link rel="stylesheet" type="text/css" href="../includes/clientside/css/enano-shared.css" /> |
187 <link rel="stylesheet" type="text/css" href="images/css/installer.css" id="mdgCss" /> |
187 <link rel="stylesheet" type="text/css" href="images/css/installer.css" id="mdgCss" /> |
188 $js_dynamic |
188 $js_dynamic |
189 <script type="text/javascript" src="../includes/clientside/static/enano-lib-basic.js"></script> |
189 <script type="text/javascript" src="../includes/clientside/static/enano-lib-basic.js"></script> |
190 $additional_headers |
190 $additional_headers |
191 </head> |
191 </head> |
192 <body> |
192 <body> |
193 <div id="enano"> |
193 <div id="enano"> |
194 |
194 |
195 EOF; |
195 EOF; |
196 if ( !$this->simple ) |
196 if ( !$this->simple ) |
197 { |
197 { |
198 $step = ( !empty($this->step) ) ? '<div id="step">' . htmlspecialchars($this->step) . '</div>' : ''; |
198 $step = ( !empty($this->step) ) ? '<div id="step">' . htmlspecialchars($this->step) . '</div>' : ''; |
199 echo <<<EOF |
199 echo <<<EOF |
200 <div id="header"> |
200 <div id="header"> |
201 $step |
201 $step |
202 <img alt="Enano logo" src="images/enano-artwork/installer-header-blue.png" /> |
202 <img alt="Enano logo" src="images/enano-artwork/installer-header-blue.png" /> |
203 </div> |
203 </div> |
204 |
204 |
205 EOF; |
205 EOF; |
206 } |
206 } |
207 $stages_class = ( $this->simple ) ? 'stages' : 'stages stages-fixed'; |
207 $stages_class = ( $this->simple ) ? 'stages' : 'stages stages-fixed'; |
208 echo <<<EOF |
208 echo <<<EOF |
209 <div class="stages-holder"> |
209 <div class="stages-holder"> |
210 <ul class="$stages_class"> |
210 <ul class="$stages_class"> |
211 |
211 |
212 EOF; |
212 EOF; |
213 foreach ( $this->stages['main'] as $guid => $stage ) |
213 foreach ( $this->stages['main'] as $guid => $stage ) |
214 { |
214 { |
215 $class = ( $guid == $this->current_stage ) ? 'stage stage-active' : 'stage'; |
215 $class = ( $guid == $this->current_stage ) ? 'stage stage-active' : 'stage'; |
216 $stage = htmlspecialchars($stage); |
216 $stage = htmlspecialchars($stage); |
217 echo " <li class=\"$class\">$stage</li>\n "; |
217 echo " <li class=\"$class\">$stage</li>\n "; |
218 } |
218 } |
219 echo " </ul>\n <div style=\"clear: both;\"></div>\n </div>\n"; |
219 echo " </ul>\n <div style=\"clear: both;\"></div>\n </div>\n"; |
220 echo " <div id=\"enano-fill\">\n "; |
220 echo " <div id=\"enano-fill\">\n "; |
221 echo " <div id=\"enano-body\">\n "; |
221 echo " <div id=\"enano-body\">\n "; |
222 } |
222 } |
223 |
223 |
224 /** |
224 /** |
225 * Displays the page footer. |
225 * Displays the page footer. |
226 */ |
226 */ |
227 |
227 |
228 function show_footer() |
228 function show_footer() |
229 { |
229 { |
230 $scriptpath = scriptPath; |
230 $scriptpath = scriptPath; |
231 $year = date('Y'); |
231 $year = date('Y'); |
232 echo <<<EOF |
232 echo <<<EOF |
233 <div id="copyright"> |
233 <div id="copyright"> |
234 Enano and its various components, related documentation, and artwork are copyright © 2006-$year Dan Fuhry.<br /> |
234 Enano and its various components, related documentation, and artwork are copyright © 2006-$year Dan Fuhry.<br /> |
235 Copyrights for <a href="{$scriptpath}/licenses/">third-party components</a> are held by their respective authors.<br /> |
235 Copyrights for <a href="{$scriptpath}/licenses/">third-party components</a> are held by their respective authors.<br /> |
236 This program is Free Software; see the file "GPL" included with this package for details. |
236 This program is Free Software; see the file "GPL" included with this package for details. |
237 </div> |
237 </div> |
238 </div> <!-- div#enano-body --> |
238 </div> <!-- div#enano-body --> |
239 </div> <!-- div#enano-fill --> |
239 </div> <!-- div#enano-fill --> |
240 </div> <!-- div#enano --> |
240 </div> <!-- div#enano --> |
241 </body> |
241 </body> |
242 </html> |
242 </html> |
243 EOF; |
243 EOF; |
244 } |
244 } |
245 |
245 |
246 } |
246 } |
247 |
247 |
248 ?> |
248 ?> |