/modules/shop/includes/modules/pages/document_product_info/main_template_vars_images_additional.php

https://github.com/severnaya99/Sg-2010 · PHP · 116 lines · 81 code · 5 blank · 30 comment · 27 complexity · c4b8c98574666ec28170039b538d30b4 MD5 · raw file

  1. <?php
  2. //
  3. // +----------------------------------------------------------------------+
  4. // |zen-cart Open Source E-commerce |
  5. // +----------------------------------------------------------------------+
  6. // | Copyright (c) 2004 The zen-cart developers |
  7. // | |
  8. // | http://www.zen-cart.com/index.php |
  9. // | |
  10. // | Portions Copyright (c) 2003 osCommerce |
  11. // +----------------------------------------------------------------------+
  12. // | This source file is subject to version 2.0 of the GPL license, |
  13. // | that is bundled with this package in the file LICENSE, and is |
  14. // | available through the world-wide-web at the following url: |
  15. // | http://www.zen-cart.com/license/2_0.txt. |
  16. // | If you did not receive a copy of the zen-cart license and are unable |
  17. // | to obtain it through the world-wide-web, please send a note to |
  18. // | license@zen-cart.com so we can mail you a copy immediately. |
  19. // +----------------------------------------------------------------------+
  20. // $Id: main_template_vars_images_additional.php 1163 2005-04-10 19:32:18Z drbyte $
  21. //
  22. ?>
  23. <?php
  24. if ($products_image != '') {
  25. // prepare image name
  26. $products_image_extention = substr($products_image, strrpos($products_image, '.'));
  27. $products_image_base = ereg_replace($products_image_extention, '', $products_image);
  28. // if in a subdirectory
  29. if (strrpos($products_image, '/')) {
  30. $products_image_match = substr($products_image, strrpos($products_image, '/')+1);
  31. //echo 'TEST 1: I match ' . $products_image_match . ' - ' . $file . ' - base ' . $products_image_base . '<br>';
  32. $products_image_match = ereg_replace($products_image_extention, '', $products_image_match) . '_';
  33. $products_image_base = $products_image_match;
  34. }
  35. $products_image_directory = ereg_replace($products_image, '', substr($products_image, strrpos($products_image, '/')));
  36. if ($products_image_directory != '') {
  37. $products_image_directory = DIR_WS_IMAGES . ereg_replace($products_image_directory, '', $products_image) . "/";
  38. } else {
  39. $products_image_directory = DIR_WS_IMAGES;
  40. }
  41. // Check for additional matching images
  42. $file_extension = $products_image_extention;
  43. $products_image_match_array = array();
  44. if ($dir = @dir($products_image_directory)) {
  45. while ($file = $dir->read()) {
  46. if (!is_dir($products_image_directory . $file)) {
  47. if (substr($file, strrpos($file, '.')) == $file_extension) {
  48. // if(preg_match("/" . $products_image_match . "/i", $file) == '1') {
  49. if(preg_match("/" . $products_image_base . "/i", $file) == '1') {
  50. if ($file != $products_image) {
  51. if ($products_image_base . ereg_replace($products_image_base, '', $file) == $file) {
  52. $products_image_match_array[] = $file;
  53. // echo 'I AM A MATCH ' . $file . '<br>';
  54. } else {
  55. // echo 'I AM NOT A MATCH ' . $file . '<br>';
  56. }
  57. }
  58. }
  59. }
  60. }
  61. }
  62. if (sizeof($products_image_match_array)) {
  63. sort($products_image_match_array);
  64. }
  65. $dir->close();
  66. }
  67. if (sizeof($products_image_match_array)) {
  68. echo ' <tr>';
  69. echo ' <td colspan="2" align="center" valign="top" class="plainBox">';
  70. echo '<table align="center">';
  71. echo "\n\n" . '<tr>';
  72. $new_images_cnt = 0;
  73. for ($i = 0, $n = sizeof($products_image_match_array); $i < $n; $i++) {
  74. if ($new_images_cnt >= IMAGES_AUTO_ADDED) {
  75. echo '<tr>';
  76. $new_images_cnt = 0;
  77. }
  78. $new_images_cnt ++;
  79. $file = $products_image_match_array[$i];
  80. $products_image_large_additional = ereg_replace(DIR_WS_IMAGES, DIR_WS_IMAGES . 'large/', $products_image_directory) . ereg_replace($products_image_extention, '', $file) . IMAGE_SUFFIX_LARGE . $products_image_extention;
  81. if (!file_exists($products_image_large_additional)) {
  82. $products_image_large_additional = $products_image_directory . $file;
  83. }
  84. //echo 'WHO AM I ' . $products_image_large_additional . ' vs ' . $products_image_large_additional;
  85. ?>
  86. <td align="center" class="smallText">
  87. <script language="javascript" type="text/javascript"><!--
  88. document.write('<?php echo (file_exists($products_image_large_additional) ? '<a href="javascript:popupWindow(\\\'' . zen_href_link(FILENAME_POPUP_IMAGE_ADDITIONAL, 'pID=' . $_GET['products_id'] . '&pic=' . $i . '&products_image_large_additional=' . $products_image_large_additional) . '\\\')">' . zen_image($products_image_directory . $file, addslashes($products_name), SMALL_IMAGE_WIDTH, SMALL_IMAGE_HEIGHT, 'hspace="5" vspace="5"') . '<br />' . TEXT_CLICK_TO_ENLARGE . '</a>' : zen_image($products_image_directory . $file, addslashes($products_name), SMALL_IMAGE_WIDTH, SMALL_IMAGE_HEIGHT, 'hspace="5" vspace="5"')); ?>');
  89. //--></script>
  90. <noscript>
  91. <?php
  92. //$products_image_large_additional = $products_image_base . IMAGE_SUFFIX_LARGE . $products_image_extention;
  93. if (file_exists($products_image_large_additional)) {
  94. echo '<a href="' . zen_href_link(FILENAME_POPUP_IMAGE_ADDITIONAL, 'pID=' . $_GET['products_id'] . '&pic=' . $i . '&products_image_large_additional=' . $products_image_large_additional) . '" target="_blank">' . zen_image(DIR_WS_IMAGES . $products_image, $products_name, SMALL_IMAGE_WIDTH, SMALL_IMAGE_HEIGHT, 'hspace="5" vspace="5"') . '<br />' . TEXT_CLICK_TO_ENLARGE . '</a>';
  95. } else {
  96. echo zen_image(DIR_WS_IMAGES . $products_image, $products_name, SMALL_IMAGE_WIDTH, SMALL_IMAGE_HEIGHT, 'hspace="5" vspace="5"') . '<br />';
  97. }
  98. ?>
  99. </noscript>
  100. </td>
  101. <?php
  102. if ($new_images_cnt >= IMAGES_AUTO_ADDED or $i == ($n-1)) {
  103. echo '</tr>' . "\n\n";
  104. }
  105. }
  106. echo '</table>';
  107. echo ' </td>';
  108. echo ' </tr>';
  109. }
  110. }
  111. ?>