From c238c95cd8ecef0f0f5fec283c06cb630a4ed895 Mon Sep 17 00:00:00 2001 From: Max Kremmel Date: Wed, 13 Dec 2006 18:01:38 +0000 Subject: move div styling options to a common function for easy maintenance and modification --- LibertySystem.php | 57 ++++++++++++++++++++++++++++++++++- plugins/data.attachment.php | 73 +++++++++++---------------------------------- plugins/data.img.php | 70 +++++++++++++------------------------------ 3 files changed, 94 insertions(+), 106 deletions(-) diff --git a/LibertySystem.php b/LibertySystem.php index 7c384fa..b211de5 100755 --- a/LibertySystem.php +++ b/LibertySystem.php @@ -3,7 +3,7 @@ * System class for handling the liberty package * * @package liberty -* @version $Header: /cvsroot/bitweaver/_bit_liberty/LibertySystem.php,v 1.48 2006/10/11 10:18:56 squareing Exp $ +* @version $Header: /cvsroot/bitweaver/_bit_liberty/LibertySystem.php,v 1.49 2006/12/13 18:01:37 squareing Exp $ * @author spider */ @@ -593,4 +593,59 @@ function parse_data_plugins( &$data, &$preparsed, &$noparsed, &$pParser, &$pComm global $gLibertySystem; $gLibertySystem = new LibertySystem(); + + + +// generic functions that make the life of a plugin easier +/** + * pass in the plugin paramaters and out comes a hash with usable styling information + * + * @param array $pParamHash + * @access public + * @return hash full of styling goodies + */ +function liberty_plugins_div_style( $pParamHash ) { + $ret = array(); + $ret['style'] = ''; + + if( !empty( $pParamHash ) && is_array( $pParamHash ) ) { + foreach( $pParamHash as $key => $value ) { + if( !empty( $value ) ) { + switch( $key ) { + // rename a couple of parameters + case 'background-color': + $key = 'background'; + case 'desc': + $key = 'description'; + // these are used as-is + case 'float': + case 'padding': + case 'margin': + case 'background': + case 'border': + case 'text-align': + case 'color': + case 'font': + case 'font-size': + case 'font-weight': + case 'font-family': + $ret['style'] .= "$key:$value;"; + break; + case 'align': + if( $value == 'center' || $value == 'middle' ) { + $ret['style'] .= 'text-align:center;'; + } else { + $ret['style'] .= "float:$value;"; + } + break; + default: + $ret[$key] = $value; + break; + } + } + } + } + + return $ret; +} ?> diff --git a/plugins/data.attachment.php b/plugins/data.attachment.php index 39f7bcb..f1437d4 100644 --- a/plugins/data.attachment.php +++ b/plugins/data.attachment.php @@ -1,6 +1,6 @@ // +----------------------------------------------------------------------+ -// $Id: data.attachment.php,v 1.8 2006/12/09 10:39:58 squareing Exp $ +// $Id: data.attachment.php,v 1.9 2006/12/13 18:01:38 squareing Exp $ /** * definitions @@ -77,89 +77,50 @@ function data_attachment_help() { return $help; } -function data_attachment($data, $params) { // NOTE: The original plugin had several parameters that have been dropped +function data_attachment( $pData, $pParams ) { // NOTE: The original plugin had several parameters that have been dropped // at a minimum, return blank string (not empty) so we still replace the tag $ret = ' '; - if( empty( $params['id'] ) ) { + if( empty( $pParams['id'] ) ) { // The Manditory Parameter is missing. we are not gonna trow an error, and just return empty since // many sites use the old style required second "closing" empty tag return $ret; } $liba = new LibertyAttachable(); - if( !$att = $liba->getAttachment( $params['id'] ) ) { + if( !$att = $liba->getAttachment( $pParams['id'] ) ) { $ret = tra( "The attachment id given is not valid." ); return $ret; } // insert source url if we need the original file - if( !empty( $params['size'] ) && $params['size'] == 'original' ) { + if( !empty( $pParams['size'] ) && $pParams['size'] == 'original' ) { $thumburl = $att['source_url']; } else { - $thumburl = ( !empty( $params['size'] ) && !empty( $att['thumbnail_url'][$params['size']] ) ? $att['thumbnail_url'][$params['size']] : $att['thumbnail_url']['medium'] ); - } - - $attstring = array(); - $attstring['div_style'] = ''; - - foreach( $params as $key => $value ) { - if( !empty( $value ) ) { - switch( $key ) { - // rename a couple of parameters - case 'background-color': - $key = 'background'; - case 'description': - $key = 'desc'; - case 'class': - $class = $value; - break; - case 'float': - case 'padding': - case 'margin': - case 'background': - case 'border': - case 'text-align': - case 'color': - case 'font': - case 'font-size': - case 'font-weight': - case 'font-family': - $attstring['div_style'] .= $key.':'.$value.';'; - break; - case 'align': - if( $value == 'center' || $value == 'middle' ) { - $attstring['div_style'] .= 'text-align:center;'; - } else { - $attstring['div_style'] .= 'float:'.$value.';'; - } - break; - default: - $attstring[$key] = $value; - break; - } - } + $thumburl = ( !empty( $pParams['size'] ) && !empty( $att['thumbnail_url'][$pParams['size']] ) ? $att['thumbnail_url'][$pParams['size']] : $att['thumbnail_url']['medium'] ); } // check if we have a valid thumbnail if( !empty( $thumburl ) ) { + $div = liberty_plugins_div_style( $pParams ); + // set up image first $ret = ''; // use specified link as href. insert default link to source only when source not already displayed - if( !empty( $params['link'] ) && $params['link'] == 'false' ) { - } elseif( !empty( $params['link'] ) ) { - $ret = ''.$ret.''; - } elseif( empty( $params['size'] ) || $params['size'] != 'original' ) { + if( !empty( $pParams['link'] ) && $pParams['link'] == 'false' ) { + } elseif( !empty( $pParams['link'] ) ) { + $ret = ''.$ret.''; + } elseif( empty( $pParams['size'] ) || $pParams['size'] != 'original' ) { $ret = ''.$ret.''; } // finally, wrap the image with a div - if( !empty( $attstring['div_style'] ) || !empty( $class ) || !empty( $attstring['desc'] ) ) { - $ret = '
'.$ret.'
'.( !empty( $attstring['desc'] ) ? $attstring['desc'] : '' ).'
'; + if( !empty( $div['style'] ) || !empty( $class ) || !empty( $div['description'] ) ) { + $ret = '
'.$ret.'
'.( !empty( $div['description'] ) ? $div['description'] : '' ).'
'; } } else { $ret = tra( "The attachment id given is not valid." ); diff --git a/plugins/data.img.php b/plugins/data.img.php index 73f9b01..dfa07cc 100644 --- a/plugins/data.img.php +++ b/plugins/data.img.php @@ -1,7 +1,7 @@ 'registered', 'plugin_type' => DATA_PLUGIN, 'biticon' => '{biticon iclass="quicktag icon" ipackage=quicktags iname=image iexplain="Image"}', - 'taginsert' => '{img src= width= height= align= desc= link=}' + 'taginsert' => '{img src= width= height= align= description= link=}' ); $gLibertySystem->registerPlugin( PLUGIN_GUID_DATAIMG, $pluginParams ); $gLibertySystem->registerDataTag( $pluginParams['tag'], PLUGIN_GUID_DATAIMG ); @@ -57,73 +57,45 @@ function data_img_help() { . tra( "Example: ")."{img src=http://www.google.at/logos/olympics06_ski_jump.gif float=right border=\"3px solid blue\"}"; } -function data_img($data, $params) { - $imgdata = array(); - $imgdata['img_style'] = ''; - $imgdata['div_style'] = ''; +function data_img( $pData, $pParams ) { + $div = liberty_plugins_div_style( $pParams ); + $div['img_style'] = ''; - foreach( $params as $key => $value ) { + foreach( $pParams as $key => $value ) { if( !empty( $value ) ) { switch( $key ) { // rename a couple of parameters - case 'background-color': - $key = 'background'; - case 'description': - $key = 'desc'; case 'width': case 'height': - if( preg_match( "/^\d/", $value ) ) { - $imgdata['img_style'] .= $key.':'.$value.';'; + if( preg_match( "/^\d+(em|px|%|pt)$/", $value ) ) { + $div['img_style'] .= $key.':'.$value.';'; + } elseif( preg_match( "/^\d+$/", $value ) ) { + $div['img_style'] .= $key.':'.$value.'px;'; } break; - case 'class': - $class = $value; - break; - case 'float': - case 'padding': - case 'margin': - case 'background': - case 'border': - case 'text-align': - case 'color': - case 'font': - case 'font-size': - case 'font-weight': - case 'font-family': - $imgdata['div_style'] .= $key.':'.$value.';'; - break; - case 'align': - if( $value == 'center' || $value == 'middle' ) { - $imgdata['div_style'] .= 'text-align:center;'; - } else { - $imgdata['div_style'] .= 'float:'.$value.';'; - } - break; - default: - $imgdata[$key] = $value; - break; } } } // check if we have a source to load an image from - if( !empty( $imgdata['src'] ) ) { + if( !empty( $div['src'] ) ) { // set up image first + $alt = ( !empty( $div['description'] ) ? $div['description'] : tra( 'Image' ) ); $ret = ''; // if this image is linking to something, wrap the image with the - if( !empty( $imgdata['link'] ) ) { - $ret = ''.$ret.''; + if( !empty( $div['link'] ) ) { + $ret = ''.$ret.''; } // finally, wrap the image with a div - if( !empty( $imgdata['div_style'] ) || !empty( $class ) || !empty( $imgdata['desc'] ) ) { - $ret = '
'.$ret.'
'.( !empty( $imgdata['desc'] ) ? $imgdata['desc'] : '' ).'
'; + if( !empty( $div['style'] ) || !empty( $class ) || !empty( $div['description'] ) ) { + $ret = '
'.$ret.'
'.( !empty( $div['description'] ) ? $div['description'] : '' ).'
'; } } else { $ret = ''.tra( 'When using {img} the src parameter is required.' ).''; -- cgit v1.3