Source for file mosimage.php

Documentation is available at mosimage.php

  1. <?php
  2. /**
  3. @package Mambo
  4. @author Mambo Foundation Inc see README.php
  5. @copyright Mambo Foundation Inc.
  6. *  See COPYRIGHT.php for copyright notices and details.
  7. @license http://www.gnu.org/copyleft/gpl.html GNU/GPL, see
  8. *  LICENSE.php
  9. *  Mambo is free software; you can redistribute it and/or
  10. *  modify it under the terms of the GNU General Public License
  11. *  as published by the Free Software Foundation; version 2 of the
  12. *  License.
  13. */ 
  14.  
  15. /** ensure this file is being included by a parent file */
  16. defined'_VALID_MOS' or die'Direct Access to this location is not allowed.' );
  17.  
  18. $_MAMBOTS->registerFunction'onPrepareContent''botMosImage' );
  19.  
  20. /**
  21. */
  22. function botMosImage$published&$row&$cparams$page=0$params {
  23.     global $database;
  24.     
  25.      // expression to search for
  26.     $regex '/{mosimage\s*.*?}/i';
  27.       
  28.     // find all instances of mambot and put in $matches
  29.     if (is_callable(array($row'getText'))) $localtext $row->getText();
  30.     else $localtext $row->text;
  31.     preg_match_all$regex$localtext$matches );
  32.     
  33.      // Number of mambots
  34.     $count count$matches[0);
  35.  
  36.      // mambot only processes if there are any instances of the mambot in the text
  37.      if $count {
  38.      
  39.         // load mambot params info
  40.         
  41.         /*$query = "SELECT id FROM #__mambots WHERE element = 'mosimage' AND folder = 'mosimage'";
  42.         $database->setQuery( $query );
  43.         $id     = $database->loadResult();
  44.         $mambot = new mosMambot( $database );
  45.         $mambot->load( $id );*/
  46.         $mambots =mosMambotHandler::getInstance();
  47.         $mambot $mambots->getBot('mosimage','content');
  48.         $params =new mosParameters( (isset($mambot->params)?$mambot->params:'')  );
  49.     
  50.          $params->def'padding' );
  51.          $params->def'margin' );
  52.          $params->def'link');
  53.  
  54.          $images     processImages$row$params$cparams );
  55.         
  56.         // store some vars in globals to access from the replacer
  57.         $GLOBALS['botMosImageCount']    0;
  58.         $GLOBALS['botMosImageParams']    =$params;
  59.         $GLOBALS['botMosImageArray']    =$images;
  60.         //$GLOBALS['botMosImageArray']    =& $combine;
  61.     
  62.         // perform the replacement
  63.         $localtext preg_replace_callback$regex'botMosImage_replacer'$localtext );
  64.         if (is_callable(array($row'saveText'))) $row->saveText($localtext);
  65.         else $row->text $localtext;
  66.     
  67.         // clean up globals
  68.         unset$GLOBALS['botMosImageCount');
  69.         unset$GLOBALS['botMosImageMask');
  70.         unset$GLOBALS['botMosImageArray');
  71.     
  72.         return true;
  73.     }     
  74. }
  75.  
  76. function processImages &$row&$params&$cparams {
  77.     global $mosConfig_absolute_path$mosConfig_live_site;
  78.     
  79.     $images         array();
  80.  
  81.     // split on \n the images fields into an array
  82.     if (is_callable(array($row'getImages'))) $localimages $row->getImages();
  83.     else $localimages $row->images;
  84.     $rimages explode"\n"$localimages);
  85.     $total             count$rimages );
  86.     if (is_callable(array($row'saveImages'))) $row->saveImages($rimages);
  87.     else $row->images $rimages;
  88.         
  89.     if ( (!$cparams->get('introtext')) && strstr$row->introtext'{mosimage}' ) ) {
  90.         $search explode'{mosimage}'$row->introtext );
  91.         $start count$search 1;
  92.     else {
  93.         $start 0;
  94.     }
  95.     
  96.     for $i $start$i $total$i++ {
  97.         $img trim$rimages[$i);
  98.  
  99.         // split on pipe the attributes of the image
  100.         if $img {
  101.             $attrib explode'|'trim$img ) );
  102.             // $attrib[0] image name and path from /images/stories
  103.             
  104.             // $attrib[1] alignment
  105.             if !isset($attrib[1]|| !$attrib[1{
  106.                 $attrib[1'';
  107.             }
  108.             
  109.             // $attrib[2] alt & title
  110.             if !isset($attrib[2]|| !$attrib[2{
  111.                 $attrib[2'Image';
  112.             else {
  113.                 $attrib[2htmlspecialchars$attrib[2);
  114.             }
  115.             
  116.             // $attrib[3] border
  117.             if !isset($attrib[3]|| !$attrib[3{
  118.                 $attrib[3'0';
  119.             }
  120.             
  121.             // $attrib[4] caption
  122.             if !isset($attrib[4]|| !$attrib[4{
  123.                 $attrib[4]    '';
  124.                 $border     $attrib[3];
  125.             else {
  126.                 $border     0;
  127.             }
  128.             
  129.             // $attrib[5] caption position
  130.             if !isset($attrib[5]|| !$attrib[5{
  131.                 $attrib[5'';
  132.             }
  133.             
  134.             // $attrib[6] caption alignment
  135.             if !isset($attrib[6]|| !$attrib[6{
  136.                 $attrib[6'';
  137.             }
  138.             
  139.             // $attrib[7] width
  140.             if !isset($attrib[7]|| !$attrib[7{
  141.                 $attrib[7]     '';
  142.                 $width         '';
  143.             else {
  144.                 $width         ' width: '$attrib[7.'px;';
  145.             }
  146.             
  147.             // image size attibutes
  148.             $size '';
  149.             if function_exists'getimagesize' ) ) {
  150.                 $size     @getimagesize$mosConfig_absolute_path .'/images/stories/'$attrib[0);
  151.                 if (is_array$size )) {
  152.                     $size 'width="'$size[0.'" height="'$size[1.'"';
  153.                 }
  154.             }
  155.             
  156.             // assemble the <image> tag
  157.             $image '<img src="'$mosConfig_live_site .'/images/stories/'$attrib[0.'" '$size;
  158.             // no aligment variable - if caption detected
  159.             if !$attrib[4{
  160.                 $image .= $attrib[1' align="'$attrib[1.'"' '';
  161.             }
  162.             $image .=' hspace="6" alt="'$attrib[2.'" title="'$attrib[2.'" border="'$border .'" />';
  163.             
  164.             // assemble caption - if caption detected
  165.             if $attrib[4{
  166.                 $caption '<div class="mosimage_caption" style="width: '$width .'; text-align: '$attrib[6.';" align="'$attrib[6.'">';
  167.                 $caption .= $attrib[4];
  168.                 $caption .='</div>';
  169.             }        
  170.             
  171.             // final output
  172.             if $attrib[4{
  173.                 $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">';
  174.                 
  175.                 // display caption in top position
  176.                 if $attrib[5== 'top' {
  177.                     $img .= $caption;
  178.                 }
  179.                 
  180.                 $img .= $image;                
  181.                 
  182.                 // display caption in bottom position
  183.                 if $attrib[5== 'bottom' {
  184.                     $img .= $caption;
  185.                 }
  186.                 $img .='</div>';
  187.             else {
  188.                 $img $image;
  189.             }
  190.  
  191.             
  192.             $images[$img;
  193.         }
  194.     }
  195.     
  196.     return $images;
  197. }
  198.  
  199. /**
  200. * Replaces the matched tags an image
  201. @param array An array of matches (see preg_match_all)
  202. @return string 
  203. */
  204. function botMosImage_replacer&$matches {
  205.     $i $GLOBALS['botMosImageCount']++;
  206.     
  207.     return @$GLOBALS['botMosImageArray'][$i];
  208. }
  209. ?>

Documentation generated on Mon, 05 May 2008 16:21:30 +0400 by phpDocumentor 1.4.0