liberty
[ class tree: liberty ] [ index: liberty ] [ all elements ]

Source for file data.img.php

Documentation is available at data.img.php

  1. <?php
  2. /**
  3.  * @version  $Revision$
  4.  *  $Header$
  5.  * @package  liberty
  6.  * @subpackage plugins_data
  7.  */
  8.  
  9. /**
  10.  * definitions
  11.  */
  12. define'PLUGIN_GUID_DATAIMG''dataimg' );
  13. global $gLibertySystem;
  14. $pluginParams array (
  15.     'tag'           => 'img',
  16.     'auto_activate' => TRUE,
  17.     'requires_pair' => FALSE,
  18.     'load_function' => 'data_img',
  19.     'title'         => 'Image',
  20.     'help_page'     => 'DataPluginImg',
  21.     'description'   => tra"Allows you to insert an image into your page with little effort and a multitude of styling options." ),
  22.     'help_function' => 'data_img_help',
  23.     'syntax'        => "{img src=http://www.google.at/logos/olympics06_ski_jump.gif}",
  24.     'plugin_type'   => DATA_PLUGIN,
  25.     'booticon'       => '{booticon iname="icon-picture" iexplain="Web Image"}',
  26.     'taginsert'     => '{img src= width= height= align= description= link=}'
  27. );
  28. $gLibertySystem->registerPluginPLUGIN_GUID_DATAIMG$pluginParams );
  29. $gLibertySystem->registerDataTag$pluginParams['tag']PLUGIN_GUID_DATAIMG );
  30.  
  31. function data_img_help({
  32.     return
  33.         '<table class="data help">'
  34.             .'<tr>'
  35.                 .'<th>'.tra"Key" ).'</th>'
  36.                 .'<th>'.tra"Type" ).'</th>'
  37.                 .'<th>'.tra"Comments" ).'</th>'
  38.             .'</tr>'
  39.             .'<tr class="odd">'
  40.                 .'<td>src</td>'
  41.                 .'<td>'.tra"string").'<br />'.tra("(required)").'</td>'
  42.                 .'<td>'.tra"Specify where the path to the image.").'</td>'
  43.             .'</tr>'
  44.             .'<tr class="even">'
  45.                 .'<td>link</td>'
  46.                 .'<td>'.tra"string").'<br />'.tra("(optional)").'</td>'
  47.                 .'<td>'.tra"If you want your image to link to a web address, use link='link/to/page'." ).'</td>'
  48.             .'</tr>'
  49.             .'<tr class="odd">'
  50.                 .'<td>'.tra"styling" ).'</td>'
  51.                 .'<td>'.tra"string").'<br />'.tra("(optional)").'</td>'
  52.                 .'<td>'.tra"Multiple styling options available: padding, margin, background, border, text-align, color, font, font-size, font-weight, font-family, align. Please view CSS guidelines on what values these settings take.").'</td>'
  53.             .'</tr>'
  54.         .'</table>'
  55.         . tra"Example: ")."{img src=http://www.google.at/logos/olympics06_ski_jump.gif float=right border=\"3px solid blue\"}";
  56. }
  57.  
  58. function data_img$pData$pParams {
  59.     $cssStyle '';
  60.     $cssClass '';
  61.  
  62.     foreach$pParams as $key => $value {
  63.         if!empty$value ) ) {
  64.             switch$key {
  65.                 // rename a couple of parameters
  66.                 case 'width':
  67.                 case 'height':
  68.                     ifpreg_match"/^\d+(em|px|%|pt)$/"trim$value ) ) ) {
  69.                         $cssStyle .= $key.':'.$value.';';
  70.                     elseifpreg_match"/^\d+$/"$value ) ) {
  71.                         $cssStyle .= $key.':'.$value.'px;';
  72.                     }
  73.                     // remove values from the hash that they don't get used in the div as well
  74.                     $pParams[$keyNULL;
  75.                     break;
  76.                 case 'class':
  77.                     $cssClass .= $value.' ';
  78.                     break;
  79.                 case 'style':
  80.                     $cssStyle .= ';'.$value;
  81.                     break;
  82.             }
  83.         }
  84.     }
  85.  
  86.     $wrapper liberty_plugins_wrapper_style$pParams );
  87.  
  88.     // check if we have a source to load an image from
  89.     if!empty$pParams['src') ) {
  90.         // set up image first
  91.         $alt !empty$wrapper['description'$wrapper['description'tra'Image' ) );
  92.         $ret '<img'.
  93.                 ' alt="'.  $alt.'"'.
  94.                 ' title="'.$alt.'"'.
  95.                 ' src="'  .$pParams['src'].'"'.
  96.                 ' style="'.$cssStyle.'"'.
  97.                 ' class="'.$cssClass.'"'.
  98.             ' />';
  99.  
  100.         // if this image is linking to something, wrap the image with the <a>
  101.         if!empty$wrapper['link') ) {
  102.             $ret '<a href="'.trim$wrapper['link').'">'.$ret.'</a>';
  103.         }
  104.  
  105.         // finally, wrap the image
  106.         if!empty$wrapper['style'|| !empty$class || !empty$wrapper['description') ) {
  107.             $ret '<'.$wrapper['wrapper'].' class="'.!empty$wrapper['class'$wrapper['class'"img-plugin" ).'" style="'.$wrapper['style'].'">'.$ret.!empty$wrapper['description''<br />'.$wrapper['description''' ).'</'.$wrapper['wrapper'].'>';
  108.         }
  109.     else {
  110.         $ret '<span class="warning">'.tra'When using <strong>{img}</strong> the <strong>src</strong> parameter is required.' ).'</span>';
  111.     }
  112.  
  113.     return $ret;
  114. }
  115. ?>

Documentation generated on Wed, 29 Jul 2015 13:56:20 +0000 by phpDocumentor 1.5.0-lsces