[ Index ] |
|
Code source de Joomla 1.0.13 |
1 <?php 2 /** 3 * @version $Id: mosimage.php 5941 2006-12-06 12:43:29Z predator $ 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 $_MAMBOTS->registerFunction( 'onPrepareContent', 'botMosImage' ); 18 19 /** 20 */ 21 function botMosImage( $published, &$row, &$params, $page=0 ) { 22 global $database, $_MAMBOTS; 23 24 // simple performance check to determine whether bot should process further 25 if ( strpos( $row->text, 'mosimage' ) === false ) { 26 return true; 27 } 28 29 // expression to search for 30 $regex = '/{mosimage\s*.*?}/i'; 31 32 // check whether mosimage has been disabled for page 33 // check whether mambot has been unpublished 34 if (!$published || !$params->get( 'image' )) { 35 $row->text = preg_replace( $regex, '', $row->text ); 36 return true; 37 } 38 39 //count how many {mosimage} are in introtext if it is set to hidden. 40 $introCount=0; 41 if ( ! $params->get( 'introtext' ) & ! $params->get( 'intro_only') ) 42 { 43 preg_match_all( $regex, $row->introtext, $matches ); 44 $introCount = count ( $matches[0] ); 45 } 46 47 // find all instances of mambot and put in $matches 48 preg_match_all( $regex, $row->text, $matches ); 49 50 // Number of mambots 51 $count = count( $matches[0] ); 52 53 // mambot only processes if there are any instances of the mambot in the text 54 if ( $count ) { 55 // check if param query has previously been processed 56 if ( !isset($_MAMBOTS->_content_mambot_params['mosimage']) ) { 57 // load mambot params info 58 $query = "SELECT params" 59 . "\n FROM #__mambots" 60 . "\n WHERE element = 'mosimage'" 61 . "\n AND folder = 'content'" 62 ; 63 $database->setQuery( $query ); 64 $database->loadObject($mambot); 65 66 // save query to class variable 67 $_MAMBOTS->_content_mambot_params['mosimage'] = $mambot; 68 } 69 70 // pull query data from class variable 71 $mambot = $_MAMBOTS->_content_mambot_params['mosimage']; 72 73 $botParams = new mosParameters( $mambot->params ); 74 75 $botParams->def( 'padding' ); 76 $botParams->def( 'margin' ); 77 $botParams->def( 'link', 0 ); 78 79 $images = processImages( $row, $botParams, $introCount ); 80 81 // store some vars in globals to access from the replacer 82 $GLOBALS['botMosImageCount'] = 0; 83 $GLOBALS['botMosImageParams'] =& $botParams; 84 $GLOBALS['botMosImageArray'] =& $images; 85 //$GLOBALS['botMosImageArray'] =& $combine; 86 87 // perform the replacement 88 $row->text = preg_replace_callback( $regex, 'botMosImage_replacer', $row->text ); 89 90 // clean up globals 91 unset( $GLOBALS['botMosImageCount'] ); 92 unset( $GLOBALS['botMosImageMask'] ); 93 unset( $GLOBALS['botMosImageArray'] ); 94 unset( $GLOBALS['botJosIntroCount'] ); 95 return true; 96 } 97 } 98 99 function processImages ( &$row, &$params, &$introCount ) { 100 global $mosConfig_absolute_path, $mosConfig_live_site; 101 102 $images = array(); 103 104 // split on \n the images fields into an array 105 $row->images = explode( "\n", $row->images ); 106 $total = count( $row->images ); 107 108 $start = $introCount; 109 for ( $i = $start; $i < $total; $i++ ) { 110 $img = trim( $row->images[$i] ); 111 112 // split on pipe the attributes of the image 113 if ( $img ) { 114 $attrib = explode( '|', trim( $img ) ); 115 // $attrib[0] image name and path from /images/stories 116 117 // $attrib[1] alignment 118 if ( !isset($attrib[1]) || !$attrib[1] ) { 119 $attrib[1] = ''; 120 } 121 122 // $attrib[2] alt & title 123 if ( !isset($attrib[2]) || !$attrib[2] ) { 124 $attrib[2] = 'Image'; 125 } else { 126 $attrib[2] = htmlspecialchars( $attrib[2] ); 127 } 128 129 // $attrib[3] border 130 if ( !isset($attrib[3]) || !$attrib[3] ) { 131 $attrib[3] = 0; 132 } 133 134 // $attrib[4] caption 135 if ( !isset($attrib[4]) || !$attrib[4] ) { 136 $attrib[4] = ''; 137 $border = $attrib[3]; 138 } else { 139 $border = 0; 140 } 141 142 // $attrib[5] caption position 143 if ( !isset($attrib[5]) || !$attrib[5] ) { 144 $attrib[5] = ''; 145 } 146 147 // $attrib[6] caption alignment 148 if ( !isset($attrib[6]) || !$attrib[6] ) { 149 $attrib[6] = ''; 150 } 151 152 // $attrib[7] width 153 if ( !isset($attrib[7]) || !$attrib[7] ) { 154 $attrib[7] = ''; 155 $width = ''; 156 } else { 157 $width = ' width: '. $attrib[7] .'px;'; 158 } 159 160 // image size attibutes 161 $size = ''; 162 if ( function_exists( 'getimagesize' ) ) { 163 $size = @getimagesize( $mosConfig_absolute_path .'/images/stories/'. $attrib[0] ); 164 if (is_array( $size )) { 165 $size = ' width="'. $size[0] .'" height="'. $size[1] .'"'; 166 } 167 } 168 169 // assemble the <image> tag 170 $image = '<img src="'. $mosConfig_live_site .'/images/stories/'. $attrib[0] .'"'. $size; 171 // no aligment variable - if caption detected 172 if ( !$attrib[4] ) { 173 if ($attrib[1] == 'left' OR $attrib[1] == 'right') { 174 $image .= ' style="float: '. $attrib[1] .';"'; 175 } else { 176 $image .= $attrib[1] ? ' align="middle"' : ''; 177 } 178 } 179 $image .=' hspace="6" alt="'. $attrib[2] .'" title="'. $attrib[2] .'" border="'. $border .'" />'; 180 181 // assemble caption - if caption detected 182 $caption = ''; 183 if ( $attrib[4] ) { 184 $caption = '<div class="mosimage_caption"'; 185 if ( $attrib[6] ) { 186 $caption .= ' style="text-align: '. $attrib[6] .';"'; 187 $caption .= ' align="'. $attrib[6] .'"'; 188 } 189 $caption .= '>'; 190 $caption .= $attrib[4]; 191 $caption .= '</div>'; 192 } 193 194 // final output 195 if ( $attrib[4] ) { 196 // initialize variables 197 $margin = ''; 198 $padding = ''; 199 $float = ''; 200 $border_width = ''; 201 $style = ''; 202 if ( $params->def( 'margin' ) ) { 203 $margin = ' margin: '. $params->def( 'margin' ).'px;'; 204 } 205 if ( $params->def( 'padding' ) ) { 206 $padding = ' padding: '. $params->def( 'padding' ).'px;'; 207 } 208 if ( $attrib[1] ) { 209 $float = ' float: '. $attrib[1] .';'; 210 } 211 if ( $attrib[3] ) { 212 $border_width = ' border-width: '. $attrib[3] .'px;'; 213 } 214 215 if ( $params->def( 'margin' ) || $params->def( 'padding' ) || $attrib[1] || $attrib[3] ) { 216 $style = ' style="'. $border_width . $float . $margin . $padding . $width .'"'; 217 } 218 219 $img = '<div class="mosimage" '. $style .' align="center">'; 220 221 // display caption in top position 222 if ( $attrib[5] == 'top' && $caption ) { 223 $img .= $caption; 224 } 225 226 $img .= $image; 227 228 // display caption in bottom position 229 if ( $attrib[5] == 'bottom' && $caption ) { 230 $img .= $caption; 231 } 232 $img .='</div>'; 233 } else { 234 $img = $image; 235 } 236 237 $images[] = $img; 238 } 239 } 240 241 return $images; 242 } 243 244 /** 245 * Replaces the matched tags an image 246 * @param array An array of matches (see preg_match_all) 247 * @return string 248 */ 249 function botMosImage_replacer( &$matches ) { 250 $i = $GLOBALS['botMosImageCount']++; 251 252 return @$GLOBALS['botMosImageArray'][$i]; 253 } 254 ?>
titre
Description
Corps
titre
Description
Corps
titre
Description
Corps
titre
Corps
Généré le : Wed Nov 21 14:43:32 2007 | par Balluche grâce à PHPXref 0.7 |
![]() |