Annotation of /mambo/branches/4.6/mambots/content/mosimage.php
Parent Directory
|
Revision Log
Revision 129 - (view) (download)
| 1 : | root | 1 | <?php |
| 2 : | /** | ||
| 3 : | * @version $Id: mosimage.php,v 1.2 2005/10/16 00:10:03 cauld Exp $ | ||
| 4 : | * @package Mambo | ||
| 5 : | * @copyright (C) 2000 - 2005 Miro International Pty Ltd | ||
| 6 : | * @license http://www.gnu.org/copyleft/gpl.html GNU/GPL | ||
| 7 : | * Mambo is Free Software | ||
| 8 : | */ | ||
| 9 : | |||
| 10 : | /** ensure this file is being included by a parent file */ | ||
| 11 : | defined( '_VALID_MOS' ) or die( 'Direct Access to this location is not allowed.' ); | ||
| 12 : | |||
| 13 : | csouza | 129 | $_MAMBOTS->registerFunction( 'onPrepareContent', 'botMosImage' ); |
| 14 : | root | 1 | |
| 15 : | /** | ||
| 16 : | */ | ||
| 17 : | csouza | 129 | function botMosImage( $published, &$row, &$cparams, $page=0, $params ) { |
| 18 : | root | 1 | global $database; |
| 19 : | |||
| 20 : | // expression to search for | ||
| 21 : | $regex = '/{mosimage\s*.*?}/i'; | ||
| 22 : | |||
| 23 : | // find all instances of mambot and put in $matches | ||
| 24 : | preg_match_all( $regex, $row->text, $matches ); | ||
| 25 : | |||
| 26 : | // Number of mambots | ||
| 27 : | $count = count( $matches[0] ); | ||
| 28 : | |||
| 29 : | // mambot only processes if there are any instances of the mambot in the text | ||
| 30 : | if ( $count ) { | ||
| 31 : | // load mambot params info | ||
| 32 : | $params->def( 'padding' ); | ||
| 33 : | $params->def( 'margin' ); | ||
| 34 : | $params->def( 'link', 0 ); | ||
| 35 : | |||
| 36 : | $images = processImages( $row, $params ); | ||
| 37 : | |||
| 38 : | // store some vars in globals to access from the replacer | ||
| 39 : | $GLOBALS['botMosImageCount'] = 0; | ||
| 40 : | $GLOBALS['botMosImageParams'] =& $params; | ||
| 41 : | $GLOBALS['botMosImageArray'] =& $images; | ||
| 42 : | //$GLOBALS['botMosImageArray'] =& $combine; | ||
| 43 : | |||
| 44 : | // perform the replacement | ||
| 45 : | $row->text = preg_replace_callback( $regex, 'botMosImage_replacer', $row->text ); | ||
| 46 : | |||
| 47 : | // clean up globals | ||
| 48 : | unset( $GLOBALS['botMosImageCount'] ); | ||
| 49 : | unset( $GLOBALS['botMosImageMask'] ); | ||
| 50 : | unset( $GLOBALS['botMosImageArray'] ); | ||
| 51 : | |||
| 52 : | return true; | ||
| 53 : | } | ||
| 54 : | } | ||
| 55 : | |||
| 56 : | function processImages ( &$row, &$params ) { | ||
| 57 : | global $mosConfig_absolute_path, $mosConfig_live_site; | ||
| 58 : | |||
| 59 : | $images = array(); | ||
| 60 : | |||
| 61 : | // split on \n the images fields into an array | ||
| 62 : | $row->images = explode( "\n", $row->images ); | ||
| 63 : | $total = count( $row->images ); | ||
| 64 : | |||
| 65 : | $start = 0; | ||
| 66 : | for ( $i = $start; $i < $total; $i++ ) { | ||
| 67 : | $img = trim( $row->images[$i] ); | ||
| 68 : | |||
| 69 : | // split on pipe the attributes of the image | ||
| 70 : | if ( $img ) { | ||
| 71 : | $attrib = explode( '|', trim( $img ) ); | ||
| 72 : | // $attrib[0] image name and path from /images/stories | ||
| 73 : | |||
| 74 : | // $attrib[1] alignment | ||
| 75 : | if ( !isset($attrib[1]) || !$attrib[1] ) { | ||
| 76 : | $attrib[1] = ''; | ||
| 77 : | } | ||
| 78 : | |||
| 79 : | // $attrib[2] alt & title | ||
| 80 : | if ( !isset($attrib[2]) || !$attrib[2] ) { | ||
| 81 : | $attrib[2] = 'Image'; | ||
| 82 : | } else { | ||
| 83 : | $attrib[2] = htmlspecialchars( $attrib[2] ); | ||
| 84 : | } | ||
| 85 : | |||
| 86 : | // $attrib[3] border | ||
| 87 : | if ( !isset($attrib[3]) || !$attrib[3] ) { | ||
| 88 : | $attrib[3] = '0'; | ||
| 89 : | } | ||
| 90 : | |||
| 91 : | // $attrib[4] caption | ||
| 92 : | if ( !isset($attrib[4]) || !$attrib[4] ) { | ||
| 93 : | $attrib[4] = ''; | ||
| 94 : | $border = $attrib[3]; | ||
| 95 : | } else { | ||
| 96 : | $border = 0; | ||
| 97 : | } | ||
| 98 : | |||
| 99 : | // $attrib[5] caption position | ||
| 100 : | if ( !isset($attrib[5]) || !$attrib[5] ) { | ||
| 101 : | $attrib[5] = ''; | ||
| 102 : | } | ||
| 103 : | |||
| 104 : | // $attrib[6] caption alignment | ||
| 105 : | if ( !isset($attrib[6]) || !$attrib[6] ) { | ||
| 106 : | $attrib[6] = ''; | ||
| 107 : | } | ||
| 108 : | |||
| 109 : | // $attrib[7] width | ||
| 110 : | if ( !isset($attrib[7]) || !$attrib[7] ) { | ||
| 111 : | $attrib[7] = ''; | ||
| 112 : | $width = ''; | ||
| 113 : | } else { | ||
| 114 : | $width = ' width: '. $attrib[7] .'px;'; | ||
| 115 : | } | ||
| 116 : | |||
| 117 : | // image size attibutes | ||
| 118 : | $size = ''; | ||
| 119 : | if ( function_exists( 'getimagesize' ) ) { | ||
| 120 : | $size = @getimagesize( $mosConfig_absolute_path .'/images/stories/'. $attrib[0] ); | ||
| 121 : | if (is_array( $size )) { | ||
| 122 : | $size = 'width="'. $size[0] .'" height="'. $size[1] .'"'; | ||
| 123 : | } | ||
| 124 : | } | ||
| 125 : | |||
| 126 : | // assemble the <image> tag | ||
| 127 : | $image = '<img src="'. $mosConfig_live_site .'/images/stories/'. $attrib[0] .'" '. $size; | ||
| 128 : | // no aligment variable - if caption detected | ||
| 129 : | if ( !$attrib[4] ) { | ||
| 130 : | $image .= $attrib[1] ? ' align="'. $attrib[1] .'"' : ''; | ||
| 131 : | } | ||
| 132 : | $image .=' hspace="6" alt="'. $attrib[2] .'" title="'. $attrib[2] .'" border="'. $border .'" />'; | ||
| 133 : | |||
| 134 : | // assemble caption - if caption detected | ||
| 135 : | if ( $attrib[4] ) { | ||
| 136 : | $caption = '<div class="mosimage_caption" style="width: '. $width .'; text-align: '. $attrib[6] .';" align="'. $attrib[6] .'">'; | ||
| 137 : | $caption .= $attrib[4]; | ||
| 138 : | $caption .='</div>'; | ||
| 139 : | } | ||
| 140 : | |||
| 141 : | // final output | ||
| 142 : | if ( $attrib[4] ) { | ||
| 143 : | $img = '<div class="mosimage" style="border-width: '. $attrib[3] .'px; float: '. $attrib[1] .'; margin: '. $params->def( 'margin' ) .'px; padding: '. $params->def( 'padding' ) .'px;'. $width .'" align="center">'; | ||
| 144 : | |||
| 145 : | // display caption in top position | ||
| 146 : | if ( $attrib[5] == 'top' ) { | ||
| 147 : | $img .= $caption; | ||
| 148 : | } | ||
| 149 : | |||
| 150 : | $img .= $image; | ||
| 151 : | |||
| 152 : | // display caption in bottom position | ||
| 153 : | if ( $attrib[5] == 'bottom' ) { | ||
| 154 : | $img .= $caption; | ||
| 155 : | } | ||
| 156 : | $img .='</div>'; | ||
| 157 : | } else { | ||
| 158 : | $img = $image; | ||
| 159 : | } | ||
| 160 : | |||
| 161 : | |||
| 162 : | $images[] = $img; | ||
| 163 : | } | ||
| 164 : | } | ||
| 165 : | |||
| 166 : | return $images; | ||
| 167 : | } | ||
| 168 : | |||
| 169 : | /** | ||
| 170 : | * Replaces the matched tags an image | ||
| 171 : | * @param array An array of matches (see preg_match_all) | ||
| 172 : | * @return string | ||
| 173 : | */ | ||
| 174 : | function botMosImage_replacer( &$matches ) { | ||
| 175 : | $i = $GLOBALS['botMosImageCount']++; | ||
| 176 : | |||
| 177 : | return @$GLOBALS['botMosImageArray'][$i]; | ||
| 178 : | } | ||
| 179 : | ?> |
| ViewVC Help | |
| Powered by ViewVC 1.0.0 |
Web Hosting provided by Network Redux.

