1<?php 2// (c) Copyright by authors of the Tiki Wiki CMS Groupware Project 3// 4// All Rights Reserved. See copyright.txt for details and a complete list of authors. 5// Licensed under the GNU LESSER GENERAL PUBLIC LICENSE. See license.txt for details. 6// $Id$ 7 8class Search_Formatter_ValueFormatter_Imagegrabber extends Search_Formatter_ValueFormatter_Abstract 9{ 10 11 private $max; 12 private $height; 13 private $width; 14 private $smartcrop; 15 16 function __construct($arguments) 17 { 18 if (isset($arguments['max'])) { 19 $this->max = $arguments['max']; 20 } 21 22 if (isset($arguments['height'])) { 23 $this->height = $arguments['height']; 24 } 25 26 if (isset($arguments['width'])) { 27 $this->width = $arguments['width']; 28 } 29 30 if (isset($arguments['smartcrop'])) { 31 $this->smartcrop = $arguments['smartcrop']; 32 } 33 } 34 35 function render($name, $value, array $entry) 36 { 37 $pattern = '/\{img [^}]*(fileId="|dl)([0-9]+)"?[^}]*\}/'; 38 preg_match_all($pattern, $value, $entry); 39 $extract = $entry[2]; 40 41 $output = ''; 42 foreach ($extract as $key => $val) { 43 if ($key < $this->max) { 44 $fileId = $val; 45 $query = 'fileId=' . $fileId . '&display=' . $name; 46 if ($this->height) { 47 $query .= '&y=' . $this->height; 48 } 49 if ($this->width) { 50 $query .= '&x=' . $this->width; 51 } 52 if ($this->height && $this->width && $this->smartcrop == 'y') { 53 $query .= '&smartcrop=y'; 54 } 55 $output .= '<img src=tiki-download_file.php?' . $query . '></img>'; 56 } 57 } 58 59 return '{HTML()}' . $output . '{HTML}'; 60 } 61} 62