[ Index ]
 

Code source de Joomla 1.0.13

Accédez au Source d'autres logiciels libres

title

Body

[fermer]

/modules/ -> mod_random_image.php (source)

   1  <?php
   2  /**
   3  * @version $Id: mod_random_image.php 2744 2006-03-11 18:15:33Z stingrey $
   4  * @package Joomla
   5  * @copyright Copyright (C) 2005 Open Source Matters. All rights reserved.
   6  * @license http://www.gnu.org/copyleft/gpl.html GNU/GPL, see LICENSE.php
   7  * Joomla! is free software. This version may have been modified pursuant
   8  * to the GNU General Public License, and as distributed it includes or
   9  * is derivative of works licensed under the GNU General Public License or
  10  * other free or open source software licenses.
  11  * See COPYRIGHT.php for copyright notices and details.
  12  */
  13  
  14  // no direct access
  15  defined( '_VALID_MOS' ) or die( 'Restricted access' );
  16  
  17  global $mosConfig_absolute_path, $mosConfig_live_site;
  18  
  19  $type             = $params->get( 'type', 'jpg' );
  20  $folder         = $params->get( 'folder' );
  21  $link             = $params->get( 'link' );
  22  $width             = $params->get( 'width' );
  23  $height         = $params->get( 'height' );
  24  $the_array         = array();
  25  $the_image         = array();
  26  
  27  // if folder includes livesite info, remove
  28  if ( strpos($folder, $mosConfig_live_site) === 0 ) {
  29      $folder = str_replace( $mosConfig_live_site, '', $folder );
  30  }
  31  // if folder includes absolute path, remove
  32  if ( strpos($folder, $mosConfig_absolute_path) === 0 ) {
  33      $folder= str_replace( $mosConfig_absolute_path, '', $folder );
  34  }
  35  // if folder doesnt contain slash to start, add
  36  if ( strpos($folder, '/') !== 0 ) {    
  37      $folder = '/'. $folder;
  38  }
  39  // construct absolute path to directory
  40  $abspath_folder = $mosConfig_absolute_path . $folder;
  41  
  42  // check if directory exists
  43  if (is_dir($abspath_folder)) {
  44      if ($handle = opendir($abspath_folder)) {
  45          while (false !== ($file = readdir($handle))) {
  46              if ($file != '.' && $file != '..' && $file != 'CVS' && $file != 'index.html' ) {
  47                  $the_array[] = $file;
  48              }
  49          }
  50      }
  51      closedir($handle);
  52  
  53      foreach ($the_array as $img) {
  54          if (!is_dir($abspath_folder .'/'. $img)) {
  55              if (eregi($type, $img)) {
  56                  $the_image[] = $img;
  57              }
  58          }
  59      }
  60  
  61      if (!$the_image) {
  62          echo _NO_IMAGES;
  63      } else {
  64            $i                 = count($the_image);
  65            $random         = mt_rand(0, $i - 1);
  66            $image_name     = $the_image[$random];
  67            $abspath_image    = $abspath_folder . '/'. $image_name;
  68            $size             = getimagesize ($abspath_image);
  69      
  70            if ($width == '') {
  71                ($size[0] > 100 ? $width = 100 : $width = $size[0]);
  72            }
  73            if ($height == '') {
  74                $coeff     = $size[0]/$size[1];
  75                $height = (int) ($width/$coeff);
  76            }
  77      
  78            $image = $mosConfig_live_site . $folder .'/'. $image_name;
  79            ?>
  80           <div align="center">
  81               <?php
  82                if ($link) {
  83                    ?>
  84                    <a href="<?php echo $link; ?>" target="_self">
  85                    <?php
  86                }
  87                ?>
  88               <img src="<?php echo $image; ?>" border="0" width="<?php echo $width; ?>" height="<?php echo $height; ?>" alt="<?php echo $image_name; ?>" /><br />
  89               <?php
  90                if ($link) {
  91                    ?>
  92                    </a>
  93                    <?php
  94                }
  95                ?>
  96           </div>
  97            <?php
  98      }
  99  }
 100  ?>


Généré le : Wed Nov 21 14:43:32 2007 par Balluche grâce à PHPXref 0.7
  Clicky Web Analytics