[ Index ] |
|
Code source de Zen Cart E-Commerce Shopping Cart 1.3.7.1 |
1 <?php 2 /** 3 * html_output.php 4 * HTML-generating functions used throughout the core 5 * 6 * @package functions 7 * @copyright Copyright 2003-2006 Zen Cart Development Team 8 * @copyright Portions Copyright 2003 osCommerce 9 * @license http://www.zen-cart.com/license/2_0.txt GNU Public License V2.0 10 * @version $Id: html_output.php 4792 2006-10-20 04:41:38Z drbyte $ 11 */ 12 13 /* 14 * The HTML href link wrapper function 15 */ 16 function zen_href_link($page = '', $parameters = '', $connection = 'NONSSL', $add_session_id = true, $search_engine_safe = true, $static = false, $use_dir_ws_catalog = true) { 17 global $request_type, $session_started, $http_domain, $https_domain; 18 19 if (!zen_not_null($page)) { 20 die('</td></tr></table></td></tr></table><br /><br /><strong class="note">Error!<br /><br />Unable to determine the page link!</strong><br /><br />'); 21 } 22 23 if ($connection == 'NONSSL') { 24 $link = HTTP_SERVER; 25 } elseif ($connection == 'SSL') { 26 if (ENABLE_SSL == 'true') { 27 $link = HTTPS_SERVER ; 28 } else { 29 $link = HTTP_SERVER; 30 } 31 } else { 32 die('</td></tr></table></td></tr></table><br /><br /><strong class="note">Error!<br /><br />Unable to determine connection method on a link!<br /><br />Known methods: NONSSL SSL</strong><br /><br />'); 33 } 34 35 if ($use_dir_ws_catalog) { 36 if ($connection == 'SSL' && ENABLE_SSL == 'true') { 37 $link .= DIR_WS_HTTPS_CATALOG; 38 } else { 39 $link .= DIR_WS_CATALOG; 40 } 41 } 42 43 if (!$static) { 44 if (zen_not_null($parameters)) { 45 $link .= 'index.php?main_page='. $page . "&" . zen_output_string($parameters); 46 } else { 47 $link .= 'index.php?main_page=' . $page; 48 } 49 } else { 50 if (zen_not_null($parameters)) { 51 $link .= $page . "?" . zen_output_string($parameters); 52 } else { 53 $link .= $page; 54 } 55 } 56 57 $separator = '&'; 58 59 while ( (substr($link, -1) == '&') || (substr($link, -1) == '?') ) $link = substr($link, 0, -1); 60 // Add the session ID when moving from different HTTP and HTTPS servers, or when SID is defined 61 if ( ($add_session_id == true) && ($session_started == true) && (SESSION_FORCE_COOKIE_USE == 'False') ) { 62 if (defined('SID') && zen_not_null(SID)) { 63 $sid = SID; 64 // } elseif ( ( ($request_type == 'NONSSL') && ($connection == 'SSL') && (ENABLE_SSL_ADMIN == 'true') ) || ( ($request_type == 'SSL') && ($connection == 'NONSSL') ) ) { 65 } elseif ( ( ($request_type == 'NONSSL') && ($connection == 'SSL') && (ENABLE_SSL == 'true') ) || ( ($request_type == 'SSL') && ($connection == 'NONSSL') ) ) { 66 if ($http_domain != $https_domain) { 67 $sid = zen_session_name() . '=' . zen_session_id(); 68 } 69 } 70 } 71 72 // clean up the link before processing 73 while (strstr($link, '&&')) $link = str_replace('&&', '&', $link); 74 while (strstr($link, '&&')) $link = str_replace('&&', '&', $link); 75 76 if ( (SEARCH_ENGINE_FRIENDLY_URLS == 'true') && ($search_engine_safe == true) ) { 77 while (strstr($link, '&&')) $link = str_replace('&&', '&', $link); 78 79 $link = str_replace('&', '/', $link); 80 $link = str_replace('?', '/', $link); 81 $link = str_replace('&', '/', $link); 82 $link = str_replace('=', '/', $link); 83 84 $separator = '?'; 85 } 86 87 if (isset($sid)) { 88 $link .= $separator . zen_output_string($sid); 89 } 90 91 // clean up the link after processing 92 while (strstr($link, '&&')) $link = str_replace('&&', '&', $link); 93 94 $link = ereg_replace('&', '&', $link); 95 return $link; 96 } 97 98 99 /* 100 * The HTML image wrapper function for non-proportional images 101 * used when "proportional images" is turned off or if calling from a template directory 102 */ 103 function zen_image_OLD($src, $alt = '', $width = '', $height = '', $parameters = '') { 104 global $template_dir; 105 106 //auto replace with defined missing image 107 if ($src == DIR_WS_IMAGES and PRODUCTS_IMAGE_NO_IMAGE_STATUS == '1') { 108 $src = DIR_WS_IMAGES . PRODUCTS_IMAGE_NO_IMAGE; 109 } 110 111 if ( (empty($src) || ($src == DIR_WS_IMAGES)) && (IMAGE_REQUIRED == 'false') ) { 112 return false; 113 } 114 115 // if not in current template switch to template_default 116 if (!file_exists($src)) { 117 $src = str_replace(DIR_WS_TEMPLATES . $template_dir, DIR_WS_TEMPLATES . 'template_default', $src); 118 } 119 120 // alt is added to the img tag even if it is null to prevent browsers from outputting 121 // the image filename as default 122 $image = '<img src="' . zen_output_string($src) . '" alt="' . zen_output_string($alt) . '"'; 123 124 if (zen_not_null($alt)) { 125 $image .= ' title=" ' . zen_output_string($alt) . ' "'; 126 } 127 128 if ( (CONFIG_CALCULATE_IMAGE_SIZE == 'true') && (empty($width) || empty($height)) ) { 129 if ($image_size = @getimagesize($src)) { 130 if (empty($width) && zen_not_null($height)) { 131 $ratio = $height / $image_size[1]; 132 $width = $image_size[0] * $ratio; 133 } elseif (zen_not_null($width) && empty($height)) { 134 $ratio = $width / $image_size[0]; 135 $height = $image_size[1] * $ratio; 136 } elseif (empty($width) && empty($height)) { 137 $width = $image_size[0]; 138 $height = $image_size[1]; 139 } 140 } elseif (IMAGE_REQUIRED == 'false') { 141 return false; 142 } 143 } 144 145 if (zen_not_null($width) && zen_not_null($height)) { 146 $image .= ' width="' . zen_output_string($width) . '" height="' . zen_output_string($height) . '"'; 147 } 148 149 if (zen_not_null($parameters)) $image .= ' ' . $parameters; 150 151 $image .= ' />'; 152 153 return $image; 154 } 155 156 157 /* 158 * The HTML image wrapper function 159 */ 160 function zen_image($src, $alt = '', $width = '', $height = '', $parameters = '') { 161 global $template_dir; 162 163 // soft clean the alt tag 164 $alt = zen_clean_html($alt); 165 166 // use old method on template images 167 if (strstr($src, 'includes/templates') or strstr($src, 'includes/languages') or PROPORTIONAL_IMAGES_STATUS == '0') { 168 return zen_image_OLD($src, $alt, $width, $height, $parameters); 169 } 170 171 //auto replace with defined missing image 172 if ($src == DIR_WS_IMAGES and PRODUCTS_IMAGE_NO_IMAGE_STATUS == '1') { 173 $src = DIR_WS_IMAGES . PRODUCTS_IMAGE_NO_IMAGE; 174 } 175 176 if ( (empty($src) || ($src == DIR_WS_IMAGES)) && (IMAGE_REQUIRED == 'false') ) { 177 return false; 178 } 179 180 // if not in current template switch to template_default 181 if (!file_exists($src)) { 182 $src = str_replace(DIR_WS_TEMPLATES . $template_dir, DIR_WS_TEMPLATES . 'template_default', $src); 183 } 184 185 // hook for handle_image() function such as Image Handler etc 186 if (function_exists('handle_image')) { 187 $newimg = handle_image($src, $alt, $width, $height, $parameters); 188 list($src, $alt, $width, $height, $parameters) = $newimg; 189 } 190 191 // Convert width/height to int for proper validation. 192 // intval() used to support compatibility with plugins like image-handler 193 $width = empty($width) ? $width : intval($width); 194 $height = empty($height) ? $height : intval($height); 195 196 // alt is added to the img tag even if it is null to prevent browsers from outputting 197 // the image filename as default 198 $image = '<img src="' . zen_output_string($src) . '" alt="' . zen_output_string($alt) . '"'; 199 200 if (zen_not_null($alt)) { 201 $image .= ' title=" ' . zen_output_string($alt) . ' "'; 202 } 203 204 if ( ((CONFIG_CALCULATE_IMAGE_SIZE == 'true') && (empty($width) || empty($height))) ) { 205 if ($image_size = @getimagesize($src)) { 206 if (empty($width) && zen_not_null($height)) { 207 $ratio = $height / $image_size[1]; 208 $width = $image_size[0] * $ratio; 209 } elseif (zen_not_null($width) && empty($height)) { 210 $ratio = $width / $image_size[0]; 211 $height = $image_size[1] * $ratio; 212 } elseif (empty($width) && empty($height)) { 213 $width = $image_size[0]; 214 $height = $image_size[1]; 215 } 216 } elseif (IMAGE_REQUIRED == 'false') { 217 return false; 218 } 219 } 220 221 222 if (zen_not_null($width) && zen_not_null($height) and file_exists($src)) { 223 // $image .= ' width="' . zen_output_string($width) . '" height="' . zen_output_string($height) . '"'; 224 // proportional images 225 $image_size = @getimagesize($src); 226 // fix division by zero error 227 $ratio = ($image_size[0] != 0 ? $width / $image_size[0] : 1); 228 if ($image_size[1]*$ratio > $height) { 229 $ratio = $height / $image_size[1]; 230 $width = $image_size[0] * $ratio; 231 } else { 232 $height = $image_size[1] * $ratio; 233 } 234 // only use proportional image when image is larger than proportional size 235 if ($image_size[0] < $width and $image_size[1] < $height) { 236 $image .= ' width="' . $image_size[0] . '" height="' . intval($image_size[1]) . '"'; 237 } else { 238 $image .= ' width="' . round($width) . '" height="' . round($height) . '"'; 239 } 240 } else { 241 // override on missing image to allow for proportional and required/not required 242 if (IMAGE_REQUIRED == 'false') { 243 return false; 244 } else { 245 $image .= ' width="' . intval(SMALL_IMAGE_WIDTH) . '" height="' . intval(SMALL_IMAGE_HEIGHT) . '"'; 246 } 247 } 248 249 // inject rollover class if one is defined. NOTE: This could end up with 2 "class" elements if $parameters contains "class" already. 250 if (defined('IMAGE_ROLLOVER_CLASS') && IMAGE_ROLLOVER_CLASS != '') { 251 $parameters .= (zen_not_null($parameters) ? ' ' : '') . 'class="rollover"'; 252 } 253 // add $parameters to the tag output 254 if (zen_not_null($parameters)) $image .= ' ' . $parameters; 255 256 $image .= ' />'; 257 258 return $image; 259 } 260 261 /* 262 * The HTML form submit button wrapper function 263 * Outputs a "submit" button in the selected language 264 */ 265 function zen_image_submit($image, $alt = '', $parameters = '', $sec_class = '') { 266 global $template, $current_page_base, $zco_notifier; 267 if (strtolower(IMAGE_USE_CSS_BUTTONS) == 'yes' && strlen($alt)<30) return zenCssButton($image, $alt, 'submit', $sec_class /*, $parameters = ''*/ ); 268 $zco_notifier->notify('PAGE_OUTPUT_IMAGE_SUBMIT'); 269 270 $image_submit = '<input type="image" src="' . zen_output_string($template->get_template_dir($image, DIR_WS_TEMPLATE, $current_page_base, 'buttons/' . $_SESSION['language'] . '/') . $image) . '" alt="' . zen_output_string($alt) . '"'; 271 272 if (zen_not_null($alt)) $image_submit .= ' title=" ' . zen_output_string($alt) . ' "'; 273 274 if (zen_not_null($parameters)) $image_submit .= ' ' . $parameters; 275 276 $image_submit .= ' />'; 277 278 return $image_submit; 279 } 280 281 /* 282 * Output a function button in the selected language 283 */ 284 function zen_image_button($image, $alt = '', $parameters = '', $sec_class = '') { 285 global $template, $current_page_base, $zco_notifier; 286 287 // inject rollover class if one is defined. NOTE: This could end up with 2 "class" elements if $parameters contains "class" already. 288 if (defined('IMAGE_ROLLOVER_CLASS') && IMAGE_ROLLOVER_CLASS != '') { 289 $parameters .= (zen_not_null($parameters) ? ' ' : '') . 'class="rollover"'; 290 } 291 292 $zco_notifier->notify('PAGE_OUTPUT_IMAGE_BUTTON'); 293 if (strtolower(IMAGE_USE_CSS_BUTTONS) == 'yes') return zenCssButton($image, $alt, 'button', $sec_class, $parameters = ''); 294 return zen_image($template->get_template_dir($image, DIR_WS_TEMPLATE, $current_page_base, 'buttons/' . $_SESSION['language'] . '/') . $image, $alt, '', '', $parameters); 295 } 296 297 298 /** 299 * generate CSS buttons in the current language 300 * concept from contributions by Seb Rouleau and paulm, subsequently adapted to Zen Cart 301 * note: any hard-coded buttons will not be able to use this function 302 **/ 303 function zenCssButton($image = '', $text, $type, $sec_class = '', $parameters = '') { 304 305 // automatic width setting depending on the number of characters 306 $min_width = 80; // this is the minimum button width, change the value as you like 307 $character_width = 6.5; // change this value depending on font size! 308 // end settings 309 // added html_entity_decode function to prevent html special chars to be counted as multiple characters (like &) 310 $width = strlen(html_entity_decode($text)) * $character_width; 311 $width = (int)$width; 312 if ($width < $min_width) $width = $min_width; 313 $style = ' style="width: ' . $width . 'px;"'; 314 // if no secondary class is set use the image name for the sec_class 315 if (empty($sec_class)) $sec_class = basename($image, '.gif'); 316 if(!empty($sec_class))$sec_class = ' ' . $sec_class; 317 if(!empty($parameters))$parameters = ' ' . $parameters; 318 $mouse_out_class = 'cssButton' . $sec_class; 319 $mouse_over_class = 'cssButtonHover' . $sec_class . $sec_class . 'Hover'; 320 // javascript to set different classes on mouseover and mouseout: enables hover effect on the buttons 321 // (pure css hovers on non link elements do work work in every browser) 322 $css_button_js .= 'onmouseover="this.className=\''. $mouse_over_class . '\'" onmouseout="this.className=\'' . $mouse_out_class . '\'"'; 323 324 if ($type == 'submit'){ 325 // form input button 326 $css_button = '<input class="' . $mouse_out_class . '" ' . $css_button_js . ' type="submit" value="' .$text . '"' . $parameters . $style . ' />'; 327 } 328 329 if ($type=='button'){ 330 // link button 331 $css_button = '<span class="' . $mouse_out_class . '" ' . $css_button_js . $style . ' > ' . $text . ' </span>'; // add $parameters ??? 332 } 333 return $css_button; 334 } 335 336 337 /* 338 * Output a separator either through whitespace, or with an image 339 */ 340 function zen_draw_separator($image = 'true', $width = '100%', $height = '1') { 341 342 // set default to use from template - zen_image will translate if not found in current template 343 if ($image == 'true') { 344 $image = DIR_WS_TEMPLATE_IMAGES . OTHER_IMAGE_BLACK_SEPARATOR; 345 } else { 346 if (!strstr($image, DIR_WS_TEMPLATE_IMAGES)) { 347 $image = DIR_WS_TEMPLATE_IMAGES . $image; 348 } 349 } 350 return zen_image($image, '', $width, $height); 351 } 352 353 /* 354 * Output a form 355 */ 356 function zen_draw_form($name, $action, $method = 'post', $parameters = '') { 357 $form = '<form name="' . zen_output_string($name) . '" action="' . zen_output_string($action) . '" method="' . zen_output_string($method) . '"'; 358 359 if (zen_not_null($parameters)) $form .= ' ' . $parameters; 360 361 $form .= '>'; 362 363 return $form; 364 } 365 366 /* 367 * Output a form input field 368 */ 369 function zen_draw_input_field($name, $value = '', $parameters = '', $type = 'text', $reinsert_value = true) { 370 $field = '<input type="' . zen_output_string($type) . '" name="' . zen_output_string($name) . '"'; 371 372 if ( (isset($GLOBALS[$name])) && ($reinsert_value == true) ) { 373 $field .= ' value="' . zen_output_string(stripslashes($GLOBALS[$name])) . '"'; 374 } elseif (zen_not_null($value)) { 375 $field .= ' value="' . zen_output_string($value) . '"'; 376 } 377 378 if (zen_not_null($parameters)) $field .= ' ' . $parameters; 379 380 $field .= ' />'; 381 382 return $field; 383 } 384 385 /* 386 * Output a form password field 387 */ 388 function zen_draw_password_field($name, $value = '', $parameters = 'maxlength="40"') { 389 return zen_draw_input_field($name, $value, $parameters, 'password', true); 390 } 391 392 /* 393 * Output a selection field - alias function for zen_draw_checkbox_field() and zen_draw_radio_field() 394 */ 395 function zen_draw_selection_field($name, $type, $value = '', $checked = false, $parameters = '') { 396 $selection = '<input type="' . zen_output_string($type) . '" name="' . zen_output_string($name) . '"'; 397 398 if (zen_not_null($value)) $selection .= ' value="' . zen_output_string($value) . '"'; 399 400 if ( ($checked == true) || ( isset($GLOBALS[$name]) && is_string($GLOBALS[$name]) && ( ($GLOBALS[$name] == 'on') || (isset($value) && (stripslashes($GLOBALS[$name]) == $value)) ) ) ) { 401 $selection .= ' checked="checked"'; 402 } 403 404 if (zen_not_null($parameters)) $selection .= ' ' . $parameters; 405 406 $selection .= ' />'; 407 408 return $selection; 409 } 410 411 /* 412 * Output a form checkbox field 413 */ 414 function zen_draw_checkbox_field($name, $value = '', $checked = false, $parameters = '') { 415 return zen_draw_selection_field($name, 'checkbox', $value, $checked, $parameters); 416 } 417 418 /* 419 * Output a form radio field 420 */ 421 function zen_draw_radio_field($name, $value = '', $checked = false, $parameters = '') { 422 return zen_draw_selection_field($name, 'radio', $value, $checked, $parameters); 423 } 424 425 /* 426 * Output a form textarea field 427 */ 428 function zen_draw_textarea_field($name, $width, $height, $text = '', $parameters = '', $reinsert_value = true) { 429 $field = '<textarea name="' . zen_output_string($name) . '" cols="' . zen_output_string($width) . '" rows="' . zen_output_string($height) . '"'; 430 431 if (zen_not_null($parameters)) $field .= ' ' . $parameters; 432 433 $field .= '>'; 434 435 if ( (isset($GLOBALS[$name])) && ($reinsert_value == true) ) { 436 $field .= stripslashes($GLOBALS[$name]); 437 } elseif (zen_not_null($text)) { 438 $field .= $text; 439 } 440 441 $field .= '</textarea>'; 442 443 return $field; 444 } 445 446 /* 447 * Output a form hidden field 448 */ 449 function zen_draw_hidden_field($name, $value = '', $parameters = '') { 450 $field = '<input type="hidden" name="' . zen_output_string($name) . '"'; 451 452 if (zen_not_null($value)) { 453 $field .= ' value="' . zen_output_string($value) . '"'; 454 } elseif (isset($GLOBALS[$name])) { 455 $field .= ' value="' . zen_output_string(stripslashes($GLOBALS[$name])) . '"'; 456 } 457 458 if (zen_not_null($parameters)) $field .= ' ' . $parameters; 459 460 $field .= ' />'; 461 462 return $field; 463 } 464 465 /* 466 * Output a form file-field 467 */ 468 function zen_draw_file_field($name, $required = false) { 469 $field = zen_draw_input_field($name, '', ' size="50" ', 'file'); 470 471 return $field; 472 } 473 474 475 /* 476 * Hide form elements while including session id info 477 * IMPORTANT: This should be used in every FORM that has an OnSubmit() function tied to it, to prevent unexpected logouts 478 */ 479 function zen_hide_session_id() { 480 global $session_started; 481 482 if ( ($session_started == true) && defined('SID') && zen_not_null(SID) ) { 483 return zen_draw_hidden_field(zen_session_name(), zen_session_id()); 484 } 485 } 486 487 /* 488 * Output a form pull down menu 489 * Pulls values from a passed array, with the indicated option pre-selected 490 */ 491 function zen_draw_pull_down_menu($name, $values, $default = '', $parameters = '', $required = false) { 492 $field = '<select name="' . zen_output_string($name) . '"'; 493 494 if (zen_not_null($parameters)) $field .= ' ' . $parameters; 495 496 $field .= '>' . "\n"; 497 498 if (empty($default) && isset($GLOBALS[$name])) $default = stripslashes($GLOBALS[$name]); 499 500 for ($i=0, $n=sizeof($values); $i<$n; $i++) { 501 $field .= ' <option value="' . zen_output_string($values[$i]['id']) . '"'; 502 if ($default == $values[$i]['id']) { 503 $field .= ' selected="selected"'; 504 } 505 506 $field .= '>' . zen_output_string($values[$i]['text'], array('"' => '"', '\'' => ''', '<' => '<', '>' => '>')) . '</option>' . "\n"; 507 } 508 $field .= '</select>' . "\n"; 509 510 if ($required == true) $field .= TEXT_FIELD_REQUIRED; 511 512 return $field; 513 } 514 515 /* 516 * Creates a pull-down list of countries 517 */ 518 function zen_get_country_list($name, $selected = '', $parameters = '') { 519 $countries_array = array(array('id' => '', 'text' => PULL_DOWN_DEFAULT)); 520 $countries = zen_get_countries(); 521 522 for ($i=0, $n=sizeof($countries); $i<$n; $i++) { 523 $countries_array[] = array('id' => $countries[$i]['countries_id'], 'text' => $countries[$i]['countries_name']); 524 } 525 526 return zen_draw_pull_down_menu($name, $countries_array, $selected, $parameters); 527 } 528 ?>
titre
Description
Corps
titre
Description
Corps
titre
Description
Corps
titre
Corps
Généré le : Mon Nov 26 16:45:43 2007 | par Balluche grâce à PHPXref 0.7 |
![]() |