Quick Search:

View

Revision:

Diff

Diff from 1839 to:

Annotations

Annotate by Age | Author | Mixed | None
/fisheye/browse/osCommerce/oscommerce2/trunk/catalog/includes/functions/html_output.php

Annotated File View

hpdl
477
1 <?php
2 /*
hpdl
1739
3   $Id: html_output.php 1839 2008-12-12 11:15:33Z hpdl $
hpdl
477
4
5   osCommerce, Open Source E-Commerce Solutions
6   http://www.oscommerce.com
7
hpdl
1839
8   Copyright (c) 2008 osCommerce
hpdl
477
9
10   Released under the GNU General Public License
11 */
12
13 ////
14 // The HTML href link wrapper function
15   function tep_href_link($page = '', $parameters = '', $connection = 'NONSSL', $add_session_id = true, $search_engine_safe = true) {
16     global $request_type, $session_started, $SID;
17
hpdl
1839
18     $page = tep_output_string($page);
19
hpdl
477
20     if (!tep_not_null($page)) {
21       die('</td></tr></table></td></tr></table><br><br><font color="#ff0000"><b>Error!</b></font><br><br><b>Unable to determine the page link!<br><br>');
22     }
23
24     if ($connection == 'NONSSL') {
25       $link = HTTP_SERVER . DIR_WS_HTTP_CATALOG;
26     } elseif ($connection == 'SSL') {
27       if (ENABLE_SSL == true) {
28         $link = HTTPS_SERVER . DIR_WS_HTTPS_CATALOG;
29       } else {
30         $link = HTTP_SERVER . DIR_WS_HTTP_CATALOG;
31       }
32     } else {
33       die('</td></tr></table></td></tr></table><br><br><font color="#ff0000"><b>Error!</b></font><br><br><b>Unable to determine connection method on a link!<br><br>Known methods: NONSSL SSL</b><br><br>');
34     }
35
36     if (tep_not_null($parameters)) {
37       $link .= $page . '?' . tep_output_string($parameters);
38       $separator = '&';
39     } else {
40       $link .= $page;
41       $separator = '?';
42     }
43
44     while ( (substr($link, -1) == '&') || (substr($link, -1) == '?') ) $link = substr($link, 0, -1);
45
46 // Add the session ID when moving from different HTTP and HTTPS servers, or when SID is defined
47     if ( ($add_session_id == true) && ($session_started == true) && (SESSION_FORCE_COOKIE_USE == 'False') ) {
48       if (tep_not_null($SID)) {
49         $_sid = $SID;
50       } elseif ( ( ($request_type == 'NONSSL') && ($connection == 'SSL') && (ENABLE_SSL == true) ) || ( ($request_type == 'SSL') && ($connection == 'NONSSL') ) ) {
51         if (HTTP_COOKIE_DOMAIN != HTTPS_COOKIE_DOMAIN) {
52           $_sid = tep_session_name() . '=' . tep_session_id();
53         }
54       }
55     }
56
57     if ( (SEARCH_ENGINE_FRIENDLY_URLS == 'true') && ($search_engine_safe == true) ) {
58       while (strstr($link, '&&')) $link = str_replace('&&', '&', $link);
59
60       $link = str_replace('?', '/', $link);
61       $link = str_replace('&', '/', $link);
62       $link = str_replace('=', '/', $link);
63
64       $separator = '?';
65     }
66
67     if (isset($_sid)) {
68       $link .= $separator . tep_output_string($_sid);
69     }
70
71     return $link;
72   }
73
74 ////
75 // The HTML image wrapper function
76   function tep_image($src, $alt = '', $width = '', $height = '', $parameters = '') {
77     if ( (empty($src) || ($src == DIR_WS_IMAGES)) && (IMAGE_REQUIRED == 'false') ) {
78       return false;
79     }
80
81 // alt is added to the img tag even if it is null to prevent browsers from outputting
82 // the image filename as default
83     $image = '<img src="' . tep_output_string($src) . '" border="0" alt="' . tep_output_string($alt) . '"';
84
85     if (tep_not_null($alt)) {
86       $image .= ' title=" ' . tep_output_string($alt) . ' "';
87     }
88
89     if ( (CONFIG_CALCULATE_IMAGE_SIZE == 'true') && (empty($width) || empty($height)) ) {
90       if ($image_size = @getimagesize($src)) {
91         if (empty($width) && tep_not_null($height)) {
92           $ratio = $height / $image_size[1];
hpdl
707
93           $width = intval($image_size[0] * $ratio);
hpdl
477
94         } elseif (tep_not_null($width) && empty($height)) {
95           $ratio = $width / $image_size[0];
hpdl
707
96           $height = intval($image_size[1] * $ratio);
hpdl
477
97         } elseif (empty($width) && empty($height)) {
98           $width = $image_size[0];
99           $height = $image_size[1];
100         }
101       } elseif (IMAGE_REQUIRED == 'false') {
102         return false;
103       }
104     }
105
106     if (tep_not_null($width) && tep_not_null($height)) {
107       $image .= ' width="' . tep_output_string($width) . '" height="' . tep_output_string($height) . '"';
108     }
109
110     if (tep_not_null($parameters)) $image .= ' ' . $parameters;
111
112     $image .= '>';
113
114     return $image;
115   }
116
117 ////
118 // The HTML form submit button wrapper function
119 // Outputs a button in the selected language
120   function tep_image_submit($image, $alt = '', $parameters = '') {
121     global $language;
122
123     $image_submit = '<input type="image" src="' . tep_output_string(DIR_WS_LANGUAGES . $language . '/images/buttons/' . $image) . '" border="0" alt="' . tep_output_string($alt) . '"';
124
125     if (tep_not_null($alt)) $image_submit .= ' title=" ' . tep_output_string($alt) . ' "';
126
127     if (tep_not_null($parameters)) $image_submit .= ' ' . $parameters;
128
129     $image_submit .= '>';
130
131     return $image_submit;
132   }
133
134 ////
135 // Output a function button in the selected language
136   function tep_image_button($image, $alt = '', $parameters = '') {
137     global $language;
138
139     return tep_image(DIR_WS_LANGUAGES . $language . '/images/buttons/' . $image, $alt, '', '', $parameters);
140   }
141
142 ////
143 // Output a separator either through whitespace, or with an image
144   function tep_draw_separator($image = 'pixel_black.gif', $width = '100%', $height = '1') {
145     return tep_image(DIR_WS_IMAGES . $image, '', $width, $height);
146   }
147
148 ////
149 // Output a form
150   function tep_draw_form($name, $action, $method = 'post', $parameters = '') {
151     $form = '<form name="' . tep_output_string($name) . '" action="' . tep_output_string($action) . '" method="' . tep_output_string($method) . '"';
152
153     if (tep_not_null($parameters)) $form .= ' ' . $parameters;
154
155     $form .= '>';
156
157     return $form;
158   }
159
160 ////
161 // Output a form input field
162   function tep_draw_input_field($name, $value = '', $parameters = '', $type = 'text', $reinsert_value = true) {
hpdl
1599
163     global $HTTP_GET_VARS, $HTTP_POST_VARS;
164
hpdl
477
165     $field = '<input type="' . tep_output_string($type) . '" name="' . tep_output_string($name) . '"';
166
hpdl
1599
167     if ( ($reinsert_value == true) && ( (isset($HTTP_GET_VARS[$name]) && is_string($HTTP_GET_VARS[$name])) || (isset($HTTP_POST_VARS[$name]) && is_string($HTTP_POST_VARS[$name])) ) ) {
168       if (isset($HTTP_GET_VARS[$name]) && is_string($HTTP_GET_VARS[$name])) {
169         $value = stripslashes($HTTP_GET_VARS[$name]);
170       } elseif (isset($HTTP_POST_VARS[$name]) && is_string($HTTP_POST_VARS[$name])) {
171         $value = stripslashes($HTTP_POST_VARS[$name]);
172       }
173     }
174
175     if (tep_not_null($value)) {
hpdl
477
176       $field .= ' value="' . tep_output_string($value) . '"';
177     }
178
179     if (tep_not_null($parameters)) $field .= ' ' . $parameters;
180
181     $field .= '>';
182
183     return $field;
184   }
185
186 ////
187 // Output a form password field
188   function tep_draw_password_field($name, $value = '', $parameters = 'maxlength="40"') {
189     return tep_draw_input_field($name, $value, $parameters, 'password', false);
190   }
191
192 ////
193 // Output a selection field - alias function for tep_draw_checkbox_field() and tep_draw_radio_field()
194   function tep_draw_selection_field($name, $type, $value = '', $checked = false, $parameters = '') {
hpdl
1599
195     global $HTTP_GET_VARS, $HTTP_POST_VARS;
196
hpdl
477
197     $selection = '<input type="' . tep_output_string($type) . '" name="' . tep_output_string($name) . '"';
198
199     if (tep_not_null($value)) $selection .= ' value="' . tep_output_string($value) . '"';
200
hpdl
1599
201     if ( ($checked == true) || (isset($HTTP_GET_VARS[$name]) && is_string($HTTP_GET_VARS[$name]) && (($HTTP_GET_VARS[$name] == 'on') || (stripslashes($HTTP_GET_VARS[$name]) == $value))) || (isset($HTTP_POST_VARS[$name]) && is_string($HTTP_POST_VARS[$name]) && (($HTTP_POST_VARS[$name] == 'on') || (stripslashes($HTTP_POST_VARS[$name]) == $value))) ) {
hpdl
477
202       $selection .= ' CHECKED';
203     }
204
205     if (tep_not_null($parameters)) $selection .= ' ' . $parameters;
206
207     $selection .= '>';
208
209     return $selection;
210   }
211
212 ////
213 // Output a form checkbox field
214   function tep_draw_checkbox_field($name, $value = '', $checked = false, $parameters = '') {
215     return tep_draw_selection_field($name, 'checkbox', $value, $checked, $parameters);
216   }
217
218 ////
219 // Output a form radio field
220   function tep_draw_radio_field($name, $value = '', $checked = false, $parameters = '') {
221     return tep_draw_selection_field($name, 'radio', $value, $checked, $parameters);
222   }
223
224 ////
225 // Output a form textarea field
226   function tep_draw_textarea_field($name, $wrap, $width, $height, $text = '', $parameters = '', $reinsert_value = true) {
hpdl
1599
227     global $HTTP_GET_VARS, $HTTP_POST_VARS;
228
hpdl
477
229     $field = '<textarea name="' . tep_output_string($name) . '" wrap="' . tep_output_string($wrap) . '" cols="' . tep_output_string($width) . '" rows="' . tep_output_string($height) . '"';
230
231     if (tep_not_null($parameters)) $field .= ' ' . $parameters;
232
233     $field .= '>';
234
hpdl
1599
235     if ( ($reinsert_value == true) && ( (isset($HTTP_GET_VARS[$name]) && is_string($HTTP_GET_VARS[$name])) || (isset($HTTP_POST_VARS[$name]) && is_string($HTTP_POST_VARS[$name])) ) ) {
236       if (isset($HTTP_GET_VARS[$name]) && is_string($HTTP_GET_VARS[$name])) {
237         $field .= tep_output_string_protected(stripslashes($HTTP_GET_VARS[$name]));
238       } elseif (isset($HTTP_POST_VARS[$name]) && is_string($HTTP_POST_VARS[$name])) {
239         $field .= tep_output_string_protected(stripslashes($HTTP_POST_VARS[$name]));
240       }
hpdl
477
241     } elseif (tep_not_null($text)) {
242       $field .= tep_output_string_protected($text);
243     }
244
245     $field .= '</textarea>';
246
247     return $field;
248   }
249
250 ////
251 // Output a form hidden field
252   function tep_draw_hidden_field($name, $value = '', $parameters = '') {
hpdl
1599
253     global $HTTP_GET_VARS, $HTTP_POST_VARS;
254
hpdl
477
255     $field = '<input type="hidden" name="' . tep_output_string($name) . '"';
256
257     if (tep_not_null($value)) {
258       $field .= ' value="' . tep_output_string($value) . '"';
hpdl
1599
259     } elseif ( (isset($HTTP_GET_VARS[$name]) && is_string($HTTP_GET_VARS[$name])) || (isset($HTTP_POST_VARS[$name]) && is_string($HTTP_POST_VARS[$name])) ) {
260       if ( (isset($HTTP_GET_VARS[$name]) && is_string($HTTP_GET_VARS[$name])) ) {
261         $field .= ' value="' . tep_output_string(stripslashes($HTTP_GET_VARS[$name])) . '"';
262       } elseif ( (isset($HTTP_POST_VARS[$name]) && is_string($HTTP_POST_VARS[$name])) ) {
263         $field .= ' value="' . tep_output_string(stripslashes($HTTP_POST_VARS[$name])) . '"';
264       }
hpdl
477
265     }
266
267     if (tep_not_null($parameters)) $field .= ' ' . $parameters;
268
269     $field .= '>';
270
271     return $field;
272   }
273
274 ////
275 // Hide form elements
276   function tep_hide_session_id() {
277     global $session_started, $SID;
278
279     if (($session_started == true) && tep_not_null($SID)) {
280       return tep_draw_hidden_field(tep_session_name(), tep_session_id());
281     }
282   }
283
284 ////
285 // Output a form pull down menu
286   function tep_draw_pull_down_menu($name, $values, $default = '', $parameters = '', $required = false) {
hpdl
1599
287     global $HTTP_GET_VARS, $HTTP_POST_VARS;
288
hpdl
477
289     $field = '<select name="' . tep_output_string($name) . '"';
290
291     if (tep_not_null($parameters)) $field .= ' ' . $parameters;
292
293     $field .= '>';
294
hpdl
1599
295     if (empty($default) && ( (isset($HTTP_GET_VARS[$name]) && is_string($HTTP_GET_VARS[$name])) || (isset($HTTP_POST_VARS[$name]) && is_string($HTTP_POST_VARS[$name])) ) ) {
296       if (isset($HTTP_GET_VARS[$name]) && is_string($HTTP_GET_VARS[$name])) {
297         $default = stripslashes($HTTP_GET_VARS[$name]);
298       } elseif (isset($HTTP_POST_VARS[$name]) && is_string($HTTP_POST_VARS[$name])) {
299         $default = stripslashes($HTTP_POST_VARS[$name]);
300       }
301     }
hpdl
477
302
303     for ($i=0, $n=sizeof($values); $i<$n; $i++) {
304       $field .= '<option value="' . tep_output_string($values[$i]['id']) . '"';
305       if ($default == $values[$i]['id']) {
306         $field .= ' SELECTED';
307       }
308
309       $field .= '>' . tep_output_string($values[$i]['text'], array('"' => '&quot;', '\'' => '&#039;', '<' => '&lt;', '>' => '&gt;')) . '</option>';
310     }
311     $field .= '</select>';
312
313     if ($required == true) $field .= TEXT_FIELD_REQUIRED;
314
315     return $field;
316   }
317
318 ////
319 // Creates a pull-down list of countries
320   function tep_get_country_list($name, $selected = '', $parameters = '') {
321     $countries_array = array(array('id' => '', 'text' => PULL_DOWN_DEFAULT));
322     $countries = tep_get_countries();
323
324     for ($i=0, $n=sizeof($countries); $i<$n; $i++) {
325       $countries_array[] = array('id' => $countries[$i]['countries_id'], 'text' => $countries[$i]['countries_name']);
326     }
327
328     return tep_draw_pull_down_menu($name, $countries_array, $selected, $parameters);
329   }
330 ?>