| [ Index ] |
PHP Cross Reference of Joomla 1.5.26 DE |
[Summary view] [Print] [Text view]
1 <?php 2 /** 3 * @version $Id: helper.php 14401 2010-01-26 14:10:00Z louis $ 4 * @package Joomla 5 * @copyright Copyright (C) 2005 - 2010 Open Source Matters. All rights reserved. 6 * @license 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( '_JEXEC' ) or die( 'Restricted access' ); 16 17 18 class modRandomImageHelper 19 { 20 function getRandomImage(&$params, $images) 21 { 22 $width = $params->get( 'width' ); 23 $height = $params->get( 'height' ); 24 25 $i = count($images); 26 $random = mt_rand(0, $i - 1); 27 $image = $images[$random]; 28 $size = getimagesize (JPATH_BASE.DS.$image->folder .DS. $image->name); 29 30 31 if ($width == '') { 32 $width = 100; 33 } 34 35 if ($size[0] < $width) { 36 $width = $size[0]; 37 } 38 39 $coeff = $size[0]/$size[1]; 40 if ($height == '') { 41 $height = (int) ($width/$coeff); 42 } else { 43 $newheight = min ($height, (int) ($width/$coeff)); 44 if ($newheight < $height) { 45 $height = $newheight; 46 } else { 47 $width = $height * $coeff; 48 } 49 } 50 51 $image->width = $width; 52 $image->height = $height; 53 $image->folder = str_replace( '\\', '/', $image->folder ); 54 55 return $image; 56 } 57 58 function getImages(&$params, $folder) 59 { 60 $type = $params->get( 'type', 'jpg' ); 61 62 $files = array(); 63 $images = array(); 64 65 $dir = JPATH_BASE.DS.$folder; 66 67 // check if directory exists 68 if (is_dir($dir)) 69 { 70 if ($handle = opendir($dir)) { 71 while (false !== ($file = readdir($handle))) { 72 if ($file != '.' && $file != '..' && $file != 'CVS' && $file != 'index.html' ) { 73 $files[] = $file; 74 } 75 } 76 } 77 closedir($handle); 78 79 $i = 0; 80 foreach ($files as $img) 81 { 82 if (!is_dir($dir .DS. $img)) 83 { 84 if (preg_match("#$type#i", $img)) { 85 $images[$i]->name = $img; 86 $images[$i]->folder = $folder; 87 ++$i; 88 } 89 } 90 } 91 } 92 93 return $images; 94 } 95 96 function getFolder(&$params) 97 { 98 $folder = $params->get( 'folder' ); 99 100 $LiveSite = JURI::base(); 101 102 // if folder includes livesite info, remove 103 if ( JString::strpos($folder, $LiveSite) === 0 ) { 104 $folder = str_replace( $LiveSite, '', $folder ); 105 } 106 // if folder includes absolute path, remove 107 if ( JString::strpos($folder, JPATH_SITE) === 0 ) { 108 $folder= str_replace( JPATH_BASE, '', $folder ); 109 } 110 $folder = str_replace('\\',DS,$folder); 111 $folder = str_replace('/',DS,$folder); 112 113 return $folder; 114 } 115 } 116
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
| Generated: Wed Mar 28 15:54:07 2012 | Cross-referenced by PHPXref 0.7.1 |