This site is developed to XHTML and CSS2 W3C standards. If you see this paragraph, your browser does not support those standards and you need to upgrade. Visit WaSP for a variety of options.

Gallery Pastebin - Paste and link to it

Posted by phinze Wed 18th Jun 2008 18:12

Description: ImageAreasHelper.class
  1. <?php
  2. /*
  3. * Gallery - a web based photo album viewer and editor
  4. * Copyright (C) 2000-2008 Bharat Mediratta
  5. *
  6. * This program is free software; you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License as published by
  8. * the Free Software Foundation; either version 2 of the License, or (at
  9. * your option) any later version.
  10. *
  11. * This program is distributed in the hope that it will be useful, but
  12. * WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  14. * General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License
  17. * along with this program; if not, write to the Free Software
  18. * Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA  02110-1301, USA.
  19. */
  20.  
  21. GalleryCoreApi::requireOnce('modules/imageareas/classes/ImageArea.class');
  22.  
  23. /*
  24. * Functions to retrieve/add/update/remove ImageAreas
  25. * @package ImageAreas
  26. * @author Paul Hinze <paul.t.hinze@gmail.com>
  27. * @version: $Revision$
  28. */
  29. class ImageAreasHelper {
  30.  
  31.  
  32.     /**
  33.      * Given an image, returns the HTML necessary to generate the UI for it.
  34.      * @param img an ImageAreasImage
  35.      */
  36.     function getImageAreasUI($img) {
  37.         $content = null;
  38.         $content .= "\n<!--module_imageareas-->\n";
  39.        
  40.         // canvas offsets
  41.         $canvasOffSetTop    = 20;
  42.         $canvasOffSetBottom = 0;
  43.         $canvasOffSetLeft   = 0;
  44.         $canvasOffSetRight  = 0;
  45.         $canvasHeight       = $img->getHeight()+$canvasOffSetTop+$canvasOffSetBottom;
  46.         $canvasWidth        = $img->getWidth()+$canvasOffSetLeft+$canvasOffSetRight;
  47.        
  48.         $content .= '<div id="ia-canvas-id-'.$img->getUUID().'" '.
  49.                         'class="ia-canvas ia-container-active" '.
  50.                         'style="width: '.$canvasWidth.'px; height: '.$canvasHeight.'px;">'."\n";
  51.         $content .= '<div id="unique-id-'.$img->getUUID().'" '.
  52.                         'class="ia-container ia-container-active" '.
  53.                         'style="width: '.$img->getWidth().'px; height: '.$img->getHeight().'px; '.
  54.                         'top:'.$canvasOffSetTop.'px; left:'.$canvasOffSetLeft.'px;">'."\n";
  55.         $content .= '<img src="'.$img->getSrc().'" width="'.$img->getWidth().'"'.
  56.                         'height="'.$img->getHeight().'" alt="'.$img->getAlt().'" />'."\n";
  57.         $content .= '<span class="ia-scalefactor" title="'.$img->getScaleFactor().'"></span>';
  58.  
  59.         list ($ret, $areaArray) = ImageAreasHelper::getImageAreas($img->getItemId());
  60.         if ($ret) {
  61.             return array($ret, null);
  62.         }
  63.  
  64.         $area = null;
  65.         for ($i=0; $i<count($areaArray); $i++) {
  66.             $area = $areaArray[$i];
  67.             $areaBounds = ImageAreasHelper::boundsToVars($area->getAreaBounds());
  68.             $areaTitle = $area->getAreaTitle();
  69.             $areaContent = $area->getAreaContent();
  70.             $areaId = $area->getAreaId();
  71.        
  72.             // This will kill the page if the content has '--' in it.
  73.             //$content .= "\n\n<!-- ******* ANNOTATION $i : $areaContent ********* -->\n";
  74.             $content .= <<<EOF
  75.         <div class="ia-area" style="left: $areaBounds[0]px; top: $areaBounds[1]px; width:
  76.             $areaBounds[2]px; height: $areaBounds[3]px;"
  77.             <div class="ia-note">
  78.                 <span class="ia-note-title">$areaTitle</span>
  79.                 <span class="ia-note-content">$areaContent</span>
  80.                 <span class="ia-note-id" title="$areaId"></span>
  81.             </div>
  82.             <div class="ia-area-innerborder-left"></div>
  83.             <div class="ia-area-innerborder-right"></div>
  84.             <div class="ia-area-innerborder-top"></div>
  85.             <div class="ia-area-innerborder-bottom"></div>
  86.            
  87.         </div>
  88.         <!-- end ia-area -->
  89. EOF;
  90.  
  91.         }
  92.         $content .= <<<EOF
  93.    
  94.     <div class="ia-controlbar ia-controlbar-active">
  95.             <!--span class="ia-controlbar-logo"></span-->
  96.             <!--span class="ia-controlbar-credits"></span-->
  97.             <span class="ia-controlbar-del-inactive"></span>
  98.             <span class="ia-controlbar-edit-inactive"></span>
  99.             <span class="ia-controlbar-add-inactive"></span>
  100.             <span class="ia-controlbar-toggle-inactive"></span>
  101.         </div>
  102.  
  103.          <form class="ia-editbar ia-editbar-inactive" name="ia_editbar" id="ia_editbar">
  104.                      
  105.                 <div class="ia-editbar-fields">
  106.                    <p>TITLE:</p>
  107.                    <input type="input" class="ia-editbar-title" name="title" value="default" />
  108.                 <input type="hidden" class="ia-editbar-entry_id" name="entry_ID" value="$areaId" />
  109.                 <input type="hidden" class="ia-editbar-border-color" name="border_color" value="#FE0000" />
  110.                
  111.               </div>
  112.      
  113.               <div class="ia-editbar-fields">
  114.                   <p>CONTENT:</p>
  115.                 <textarea class="ia-editbar-content" name="content"></textarea>
  116.               </div>
  117.               <div class="ia-editbar-fields">
  118.                   <span class="ia-editbar-ok"></span>
  119.                 <span class="ia-editbar-cancel"></span>
  120.             </div>
  121.          </form>
  122.          
  123.     </div>
  124.  
  125. EOF;
  126.        
  127.         $content .= "\n</div><!--close ia-canvas-->\n";
  128.         $content .= "\n<!--module_imageareas-->\n";
  129.         return array (null, $content);
  130.     }
  131.  
  132.     function xmldecode($txt) {
  133.         $txt = str_replace('&amp;''&', $txt);
  134.         $txt = str_replace('&lt;',   '<', $txt);
  135.         $txt = str_replace('&gt;',   '>', $txt);
  136.         $txt = str_replace('&apos;', "'", $txt);
  137.         $txt = str_replace('&quot;', '"', $txt);
  138.         return $txt;
  139.     }
  140.  
  141.     /**
  142.      * Get all ImageAreas for a given itemId.
  143.      * @param itemId Gallery2 item
  144.      * @return array(GalleryStatus,  array of ImageAreas)
  145.      */
  146.     function getImageAreas($itemId) {
  147.         $areas = array();
  148.         list ($ret, $searchResults) = GalleryCoreApi::getMapEntry("ImageAreaMap",
  149.                                         array('areaId', 'areaTitle', 'areaContent', 'areaBounds'),
  150.                                         array('itemId' => $itemId));
  151.         if ($ret) {
  152.             return array($ret, null);
  153.         }
  154.  
  155.         while ($result = $searchResults->nextResult()) {
  156.             $areas[] = new ImageArea($result[0], $itemId, $result[1], $result[2], $result[3]);
  157.         }
  158.        
  159.         return array(null, $areas);
  160.     }
  161.  
  162.     function addArea($area) {
  163.         global $gallery;
  164.         $storage =& $gallery->getStorage();
  165.         list ($ret, $newAreaId) = $storage->getUniqueId();
  166.         if ($ret) {
  167.             return $ret;
  168.         }
  169.         $ret = GalleryCoreApi::addMapEntry('ImageAreaMap',
  170.             array('areaId' => $newAreaId,
  171.                   'itemId' => $area->getItemId(),
  172.                   'areaTitle' => $area->getAreaTitle(),
  173.                   'areaContent' => $area->getAreaContent(),
  174.                   'areaBounds' => $area->getAreaBounds()
  175.             ));
  176.         if ($ret) {
  177.             return array($ret, null);
  178.         }
  179.  
  180.         return array(null, $newAreaId);
  181.     }
  182.  
  183.     function updateArea($area) {
  184.         global $gallery;
  185.         $storage =& $gallery->getStorage();
  186.  
  187.         return GalleryCoreApi::updateMapEntry('ImageAreaMap',
  188.             array('areaId' => $area->getAreaId()),
  189.             array( 'areaTitle' => $area->getAreaTitle(),
  190.                   'areaContent' => $area->getAreaContent(),
  191.                   'areaBounds' => $area->getAreaBounds()
  192.             ));
  193.     }
  194.  
  195.     function deleteArea($areaId) {
  196.         global $gallery;
  197.         $storage =& $gallery->getStorage();
  198.  
  199.         return GalleryCoreApi::removeMapEntry('ImageAreaMap',
  200.             array('areaId' => $areaId));
  201.     }
  202.  
  203.     /**
  204.      * Converts string x1,y1,x2,y2 to array x1,y1,w,h.
  205.      * @param bounds a string of the format "x1,y1,x2,y2"
  206.      * @returns array(upperleftx, upperlefty, width, height)
  207.      */
  208.     function boundsToVars($bounds) {
  209.         $ba = split(',', $bounds);
  210.         return array($ba[0], $ba[1], $ba[2] - $ba[0], $ba[3] - $ba[1]);
  211.     }
  212.  
  213. }
  214.  
  215. ?>
  216.  

PermaLink to this entry http://tools.gallery2.org/pastebin/2000 Download 2000.txt
Submit a correction or amendment below. (click here to make a fresh posting)

Your Name
Syntax:
For (optional)
Leave permalink as note for user. Remember my name in a cookie

Select channel for announcement:
#gallery#gallery-support

Code: To ensure legibility, keep your code lines under 80 characters long.

You can highlight lines: start with "@#" and end with "!#"

Description: You can leave a small description for your code. (Errors, etc)

Please note that your script will be available publicly.
Page generated in 0.662 seconds.