summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMax Kremmel <xing@synapse.plus.com>2006-12-13 18:01:38 +0000
committerMax Kremmel <xing@synapse.plus.com>2006-12-13 18:01:38 +0000
commitc238c95cd8ecef0f0f5fec283c06cb630a4ed895 (patch)
treef994a151347ecd59ffd8e5fad9c65ba7c1a91565
parentd407aa21957b3e7eb5b1bcadf1364d775aab1092 (diff)
downloadliberty-c238c95cd8ecef0f0f5fec283c06cb630a4ed895.tar.gz
liberty-c238c95cd8ecef0f0f5fec283c06cb630a4ed895.tar.bz2
liberty-c238c95cd8ecef0f0f5fec283c06cb630a4ed895.zip
move div styling options to a common function for easy maintenance and modification
-rwxr-xr-xLibertySystem.php57
-rw-r--r--plugins/data.attachment.php73
-rw-r--r--plugins/data.img.php70
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 <spider@steelsun.com>
*/
@@ -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 @@
<?php
/**
- * @version $Revision: 1.8 $
+ * @version $Revision: 1.9 $
* @package liberty
* @subpackage plugins_data
*/
@@ -15,7 +15,7 @@
// +----------------------------------------------------------------------+
// | Authors: drewslater <andrew@andrewslater.com>
// +----------------------------------------------------------------------+
-// $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 = '<img'.
- ' alt="'. ( !empty( $attstring['desc'] ) ? $attstring['desc'] : tra( 'Image' ) ).'"'.
- ' title="'.( !empty( $attstring['desc'] ) ? $attstring['desc'] : tra( 'Image' ) ).'"'.
+ ' alt="'. ( !empty( $div['description'] ) ? $div['description'] : tra( 'Image' ) ).'"'.
+ ' title="'.( !empty( $div['description'] ) ? $div['description'] : tra( 'Image' ) ).'"'.
' src="' .$thumburl.'"'.
' />';
// 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 = '<a href="'.trim( $attstring['link'] ).'">'.$ret.'</a>';
- } elseif( empty( $params['size'] ) || $params['size'] != 'original' ) {
+ if( !empty( $pParams['link'] ) && $pParams['link'] == 'false' ) {
+ } elseif( !empty( $pParams['link'] ) ) {
+ $ret = '<a href="'.trim( $pParams['link'] ).'">'.$ret.'</a>';
+ } elseif( empty( $pParams['size'] ) || $pParams['size'] != 'original' ) {
$ret = '<a href="'.trim( $att['source_url'] ).'">'.$ret.'</a>';
}
// finally, wrap the image with a div
- if( !empty( $attstring['div_style'] ) || !empty( $class ) || !empty( $attstring['desc'] ) ) {
- $ret = '<div class="'.( !empty( $class ) ? $class : "att-plugin" ).'" style="'.$attstring['div_style'].'">'.$ret.'<br />'.( !empty( $attstring['desc'] ) ? $attstring['desc'] : '' ).'</div>';
+ if( !empty( $div['style'] ) || !empty( $class ) || !empty( $div['description'] ) ) {
+ $ret = '<div class="'.( !empty( $div['class'] ) ? $div['class'] : "att-plugin" ).'" style="'.$div['style'].'">'.$ret.'<br />'.( !empty( $div['description'] ) ? $div['description'] : '' ).'</div>';
}
} 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 @@
<?php
/**
- * @version $Revision: 1.10 $
- * $Header: /cvsroot/bitweaver/_bit_liberty/plugins/data.img.php,v 1.10 2006/11/01 08:36:47 squareing Exp $
+ * @version $Revision: 1.11 $
+ * $Header: /cvsroot/bitweaver/_bit_liberty/plugins/data.img.php,v 1.11 2006/12/13 18:01:38 squareing Exp $
* @package liberty
* @subpackage plugins_data
*/
@@ -25,7 +25,7 @@ $pluginParams = array (
'security' => '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 = '<img'.
- ' alt="'. ( !empty( $imgdata['desc'] ) ? $imgdata['desc'] : tra( 'Image' ) ).'"'.
- ' title="'.( !empty( $imgdata['desc'] ) ? $imgdata['desc'] : tra( 'Image' ) ).'"'.
- ' src="' .$imgdata['src'].'"'.
- ' style="'.$imgdata['img_style'].'"'.
+ ' alt="'. $alt.'"'.
+ ' title="'.$alt.'"'.
+ ' src="' .$div['src'].'"'.
+ ' style="'.$div['img_style'].'"'.
' />';
// if this image is linking to something, wrap the image with the <a>
- if( !empty( $imgdata['link'] ) ) {
- $ret = '<a href="'.trim( $imgdata['link'] ).'">'.$ret.'</a>';
+ if( !empty( $div['link'] ) ) {
+ $ret = '<a href="'.trim( $div['link'] ).'">'.$ret.'</a>';
}
// finally, wrap the image with a div
- if( !empty( $imgdata['div_style'] ) || !empty( $class ) || !empty( $imgdata['desc'] ) ) {
- $ret = '<div class="'.( !empty( $class ) ? $class : "img-plugin" ).'" style="'.$imgdata['div_style'].'">'.$ret.'<br />'.( !empty( $imgdata['desc'] ) ? $imgdata['desc'] : '' ).'</div>';
+ if( !empty( $div['style'] ) || !empty( $class ) || !empty( $div['description'] ) ) {
+ $ret = '<div class="'.( !empty( $div['class'] ) ? $div['class'] : "img-plugin" ).'" style="'.$div['style'].'">'.$ret.'<br />'.( !empty( $div['description'] ) ? $div['description'] : '' ).'</div>';
}
} else {
$ret = '<span class="warning">'.tra( 'When using <strong>{img}</strong> the <strong>src</strong> parameter is required.' ).'</span>';