soo_image user guide Page 7 of 16

soo_image Source code

  1 : require_plugin('soo_txp_obj');
  2 : @require_plugin('soo_plugin_pref');     // optional
  3 : 
  4 : global $soo_image;
  5 : 
  6 : $soo_image = array(
  7 :     'page_param'        =>  'soo_img_pg',
  8 :     'jump_param'        =>  'soo_img_jp',
  9 : );
 10 : $soo_image_prefs function_exists('soo_plugin_pref_vals') ?
 11 :     soo_plugin_pref_vals('soo_image') : soo_image_defaults();
 12 : foreach ( $soo_image_prefs as $name => $val )
 13 :     $soo_image[$name] = is_array($val) ? $val['val'] : $val;
 14 : 
 15 : add_privs('plugin_prefs.soo_image','1,2');
 16 : add_privs('plugin_lifecycle.soo_image','1,2');
 17 : register_callback('soo_image_prefs''plugin_prefs.soo_image');
 18 : register_callback('soo_image_prefs''plugin_lifecycle.soo_image');
 19 : 
 20 : function soo_image_prefs$event$step ) {
 21 :     if ( function_exists('soo_plugin_pref') )
 22 :         return soo_plugin_pref($event$stepsoo_image_defaults());
 23 :     if ( substr($event012) == 'plugin_prefs' ) {
 24 :         $plugin substr($event12);
 25 :         $message '<p><br /><strong>' gTxt('edit') . " $plugin " .
 26 :             gTxt('edit_preferences') . ':</strong><br />' gTxt('install_plugin')
 27 :             . ' <a href="http://ipsedixit.net/txp/92/soo_plugin_pref">soo_plugin_pref</a></p>';
 28 :         pagetop(gTxt('edit_preferences') . " &#8250; $plugin"$message);
 29 :     }
 30 : }
 31 : 
 32 : function soo_image_defaults( ) {
 33 :     return array(
 34 :         'default_form'          =>  array(
 35 :             'val'   =>  'soo_image',
 36 :             'html'  =>  'text_input',
 37 :             'text'  =>  'Default image form',
 38 :         ),
 39 :         'default_listform'      =>  array(
 40 :             'val'   =>  '',
 41 :             'html'  =>  'text_input',
 42 :             'text'  =>  'Default image list form',
 43 :         ),
 44 :         'default_dimensions'    =>  array(
 45 :             'val'   =>  1,
 46 :             'html'  =>  'yesnoradio',
 47 :             'text'  =>  'Add height and width in pixels to img tag by default?',
 48 :         ),
 49 :         'persistent_context'    =>  array(
 50 :             'val'   =>  1,
 51 :             'html'  =>  'yesnoradio',
 52 :             'text'  =>  'Use persistent context for tags outside an image form?',
 53 :         ),
 54 :     );
 55 : }
 56 : 
 57 :   //---------------------------------------------------------------------//
 58 :  //                                 Tags                                //
 59 : //---------------------------------------------------------------------//
 60 : 
 61 : function soo_image_select$atts$thing null ) {
 62 : 
 63 : // Controller for the soo_image plugin.
 64 : //
 65 : // Determine what images the user is requesting, fetch image data objects
 66 : // (or raw URLs, as appropriate) for those images, and pass this along
 67 : // to an image form (i.e., a form called by this tag, containing one or
 68 : // more of soo_image's output tags) for display.
 69 : 
 70 :     global $soo_image;
 71 : 
 72 :     extract(lAtts(array(
 73 :         'aspect_ratio'  =>  '',
 74 :         'author'        =>  '',
 75 :         'break'         =>  '',
 76 :         'category'      =>  '',
 77 :         'class'         =>  '',
 78 :         'ext'           =>  '',
 79 :         'form'          =>  $soo_image['default_form'],     // required
 80 :         'html_id'       =>  '',
 81 :         'id'            =>  '',
 82 :         'limit'         =>  0,
 83 :         'listform'      =>  $soo_image['default_listform'],
 84 :         'name'          =>  '',
 85 :         'pagination'    =>  true,
 86 :         'persistent_context'    => $soo_image['persistent_context'],
 87 :         'sort'          =>  'name asc',     // accepts lists, e.g. "a asc,b,c desc"
 88 :         'wraptag'       =>  '',
 89 :     ), $atts));
 90 : 
 91 :     $page intval(gps($soo_image['page_param']));
 92 :     if ( $page $page 1;
 93 :     $offset $pagination ? ($page 1) * $limit 0;
 94 : 
 95 :     $jump_to intval(gps($soo_image['jump_param']));
 96 : 
 97 :     $query = new soo_txp_select('txp_image');
 98 : 
 99 : // Selection priority: name; id; (category|author|ext|aspect_ratio); article image.
100 : // Comma-separated lists allowed for all criteria; preserve list order for name|id.
101 : 
102 :     if ( $name or $id ) {
103 :         $sort '';
104 :         if ( $name )
105 :             $query->in('name'$name)->order_by_field('name'$name);
106 :         else
107 :             $ids _soo_range_to_list($id);
108 :     }
109 : 
110 :     elseif ( $category or $author or $ext or $aspect_ratio ) {
111 :         if ( $category $query->in('category'$category);
112 :         if ( $author $query->in('author'$author);
113 :         if ( $ext $query->in('ext'_soo_valid_ext($ext));
114 :         if ( $aspect_ratio _soo_image_aspect_ratio($querytrim($aspect_ratio));
115 :     }
116 : 
117 :     else {
118 :         $image_array _soo_article_image_list();
119 :         if ( ! $image_array )
120 :             return false;
121 :         foreach ( $image_array as $img ) {
122 :             if ( is_numeric($img) )
123 :                 $ids[] = $img;
124 :             else
125 :                 $urls[] = $img;
126 :         }
127 :     }
128 :     if ( isset($ids) ) {
129 :         $sort '';
130 :         $query->in('id'$ids)->order_by_field('id'$ids);
131 :     }
132 : 
133 :     $full_count $query->count();
134 :     if ( $pagination && $full_count <= $offset ) {      // in case of direct URI manipulation and invalid #
135 :         $page $limit ceil($full_count $limit) : 1;    // go to last page
136 :         $offset = ($page 1) * $limit;
137 :     }
138 : 
139 :     $soo_image['this_page'] = $page;
140 :     if ( $pagination $soo_image['total_pages'] = $limit ceil($full_count $limit) : 1;
141 : 
142 :     if ( $jump_to and is_numeric($jump_to) ) {
143 :         $uri = new soo_uri;
144 :         $uri->set_query_param($soo_image['jump_param']);
145 :         $all_ids = new soo_txp_rowset($query->order_by($sort));
146 :         $all_ids array_flip($all_ids->field_vals('id'));
147 :         if ( isset($all_ids[$jump_to]) ) {
148 :             $jump_index $all_ids[$jump_to];
149 :             if ( $limit ) {
150 :                 $page ceil(($jump_index 1) / $limit);
151 :                 $offset = ($page 1) * $limit;
152 :                 $_POST[$soo_image['page_param']] = $page;
153 :             }
154 :         }
155 :     }
156 : 
157 :     $query->order_by($sort)->limit($limit)->offset($offset);
158 :     $rs = new soo_txp_rowset($query);
159 :     unset($query);
160 : 
161 :     if ( isset($urls) )
162 :         foreach ( $image_array as $i => $img ) {
163 :             if ( isset($rs->rows[$img]) )
164 :                 $image_array[$i] = $rs->rows[$img];
165 :             elseif ( ! in_array($img$urls) )
166 :                 unset($image_array[$i]);
167 :         }
168 :     else
169 :         $image_array $rs->rows;
170 : 
171 :     if ( empty($image_array) )
172 :         return false;
173 : 
174 :     if ( $pagination && $limit && ( $offset $limit $full_count ) )
175 :         $soo_image['next'] = $page 1;
176 : 
177 :     // $image_array now contains data objects and/or presumed URLs
178 : 
179 :     if ( ( count($image_array) > or $page 1) and $listform )
180 :         $form $listform;
181 : 
182 :     $soo_image['first_selection'] = isset($jump_index) ? new soo_txp_img($jump_to) : current($image_array);
183 : 
184 :     foreach ( $image_array as $img ) {
185 :         if ( $img instanceof soo_txp_img )
186 :             $soo_image['data_obj'] = $img;
187 :         else
188 :             $soo_image['url'] = $img;
189 :         $parsed is_null($thing) ? parse_form($form) : parse($thing);
190 :         if ( $parsed $out[] = $parsed;
191 :         unset($soo_image['data_obj']);
192 :         unset($soo_image['url']);
193 :     }
194 : 
195 :     if ( ! $persistent_context )
196 :         unset($soo_image['first_selection']);
197 : 
198 :     return isset($out) ? doWrap($out$wraptag$break$class''''''$html_id) : false;
199 : 
200 : }
201 : ////////////////////// end of soo_image_select /////////////////////
202 : 
203 : function soo_image$atts ) {
204 : // Display an image. Selection by, in descending order of priority:
205 :     // the tag's 'name' attribute;
206 :     // the tag's 'id' attribute;
207 :     // the image context:
208 :         // id or url sent by $soo_image to an image form
209 :         // article image
210 :         // first selection from prior soo_image_select (subject to pref setting)
211 : 
212 :     extract(lAtts(array(
213 :         'id'            =>  '',
214 :         'name'          =>  '',
215 :         'thumbnail'     =>  false,
216 :         'height'        =>  '',
217 :         'width'         =>  '',
218 :         'html_id'       =>  '',
219 :         'class'         =>  '',
220 :         'title'         =>  '{caption}',
221 :         'link'          =>  false,
222 :         'link_class'    =>  '',
223 :         'link_id'       =>  '',
224 :         'link_rel'      =>  '',
225 :         'link_to'       =>  '',
226 :         'escape'        =>  true,
227 :         'onclick'       =>  '',     // only for linked thumbnails
228 :     ), $atts));
229 : 
230 :     global $soo_image;
231 : 
232 :     if ( $link_class or $link_id or $link_rel or $onclick or $link_to )
233 :         $link true;
234 : 
235 :     if ( $link )
236 :         $thumbnail true;
237 : 
238 :     if ( $name or $id )
239 :         $image = new soo_txp_img($name $name $id);
240 :     else
241 :         $image _soo_image_by_context();
242 :             // false if image context is empty
243 :             // otherwise a soo_txp_img or soo_html_img object
244 :             // if soo_html_img it will be URL only, no other properties
245 : 
246 :     if ( $image instanceof soo_html_img and $thumbnail )
247 :         return false;
248 : 
249 :     if ( $image instanceof soo_txp_img ) {
250 :         if ( $thumbnail and !$image->thumbnail )
251 :             return false;
252 :         $image_data $image;
253 :         $image = new soo_html_img($image_data$thumbnail$escape);
254 :         $title str_replace(array('{author}''{alt}''{caption}'),
255 :             array(get_author_name($image_data->author), $image->alt$image->title), $title);
256 :     }
257 : 
258 :     if ( ! ( $image instanceof soo_html_img ) )
259 :         return false;
260 : 
261 : // Standard height and width attributes (i.e., actual size in pixels) will be added to the img tag if the default_dimensions preference is true and has not been overriden (by specifying height or width other than 1), or if either attribute has been set to 1. Otherwise, height and width attributes will be passed through as is (in which case a value of 0 or empty will result in no attribute in the img tag).
262 : 
263 :     if ( $width === '0' or $height === '0' or $width or $height )
264 :         $soo_image['default_dimensions'] = false;
265 : 
266 :     if ( ! $soo_image['default_dimensions'] and $height != and $width != )
267 :         $image->height($height)->width($width);
268 : 
269 :     $image->class($class)
270 :         ->id($html_id)
271 :         ->title($title);
272 : 
273 :     // Shadowbox-specific block to create galleries
274 :     if ( strtolower($link_rel) == "shadowbox"
275 :         and isset($soo_image['first_selection'])
276 :         and $soo_image['first_selection'] instanceof soo_txp_img ) {
277 :             $img_obj $soo_image['first_selection'];
278 :             $link_rel .= '[' $img_obj->id ']';
279 :     }
280 : 
281 :     if ( $thumbnail and $link ) {
282 :         if ( $link_to )
283 :             $url hu $link_to '?' $soo_image['jump_param']
284 :                 . '=' $image_data->id;
285 :         else
286 :             $url $image_data->full_url;
287 :         $anchor = new soo_html_anchor($url$image);
288 :         $anchor->title($title)
289 :             ->onclick($onclick)
290 :             ->rel($link_rel)
291 :             ->class($link_class)
292 :             ->id($link_id);
293 :     }
294 : 
295 :     return isset($anchor) ? $anchor->tag() : $image->tag();
296 : }
297 : ///////////////////////// end of soo_image //////////////////////////
298 : 
299 : function soo_image_alt($atts) { return _soo_image_data('alt'$atts); }
300 : function soo_image_author($atts) { return _soo_image_data('author'$atts); }
301 : function soo_image_caption($atts) { return _soo_image_data('caption'$atts); }
302 : function soo_image_category($atts) { return _soo_image_data('category'$atts); }
303 : function soo_image_date($atts) { return _soo_image_data('date'$atts); }
304 : function soo_image_height($atts) { return _soo_image_data('h'$atts); }
305 : function soo_image_id($atts) { return _soo_image_data('id'$atts); }
306 : function soo_image_name($atts) { return _soo_image_data('name'$atts); }
307 : function soo_image_url($atts) { return _soo_image_data('full_url'$atts); }
308 : function soo_image_width($atts) { return _soo_image_data('w'$atts); }
309 : function soo_thumbnail_height($atts) { return _soo_image_data('thumb_h'$atts); }
310 : function soo_thumbnail_url($atts) { return _soo_image_data('thumb_url'$atts); }
311 : function soo_thumbnail_width($atts) { return _soo_image_data('thumb_w'$atts); }
312 : 
313 : function _soo_image_data($field$atts = array()) {
314 :     extract(lAtts(array(
315 :         'format'    =>  '',
316 :         'escape'    =>  1,
317 :         'no_widow'  =>  1,
318 :         'wraptag'   => '',
319 :         'class'     => '',
320 :         'html_id'   => '',
321 :     ), $atts));
322 :     $image _soo_image_by_context();
323 :     if ( ! $image instanceof soo_txp_img )
324 :         $out $field == 'url' $image '';
325 :     else
326 :         switch ( $field ) {
327 :             case 'alt':
328 :                 $out $escape htmlspecialchars($image->alt) : $image->alt;
329 :                 break;
330 :             case 'author':
331 :                 $out get_author_name($image->author);
332 :                 break;
333 :             case 'caption':
334 :                 $out $escape htmlspecialchars($image->caption) : $image->caption;
335 :                 $out $no_widow preg_replace('/\s+(\S+)$/''&nbsp;\1'$out) : $out;
336 :                 break;
337 :             case 'date':
338 :                 global $dateformat;
339 :                 $f $format $format $dateformat;
340 :                 $utime safe_strtotime($image->date);
341 :                 $out $image->date safe_strftime($f$utime) : '';
342 :                 break;
343 :             default:
344 :                 $out $image->$field;
345 :         }
346 :     return doWrap(array($out), $wraptag''$class''''''$html_id);
347 : }
348 : 
349 : function soo_if_txp_image($atts$thing) {
350 : 
351 :     $image _soo_image_by_context();
352 :     return parse(EvalElse($thing$image instanceof soo_txp_img ));
353 : }
354 : 
355 : function soo_if_image_author($atts$thing) {
356 : 
357 :     extract(lAtts(array('name' => ''), $atts));
358 :     $image _soo_image_by_context();
359 :     return parse(EvalElse($thing$image instanceof soo_txp_img and in_list($image->author$name) ));
360 : }
361 : 
362 : function soo_if_image_category($atts$thing) {
363 : 
364 :     extract(lAtts(array('name' => ''), $atts));
365 :     $image _soo_image_by_context();
366 :     return parse(EvalElse($thing$image instanceof soo_txp_img and in_list($image->category$name) ));
367 : }
368 : 
369 : function soo_if_image_thumbnail($atts$thing) {
370 : 
371 :     $image _soo_image_by_context();
372 :     return parse(EvalElse($thing$image instanceof soo_txp_img and $image->thumbnail));
373 : }
374 : 
375 : function soo_image_next($atts$thing null) {
376 : 
377 :     extract(lAtts(array(
378 :         'link_text'     => '&rarr;',
379 :         'class'         => '',
380 :         'html_id'       => '',
381 :     ), $atts));
382 :     global $soo_image;
383 : 
384 :     if ( ! isset($soo_image['next']) )
385 :         return soo_util::secondpass(__FUNCTION__$atts$thing);
386 :     $uri = new soo_uri;
387 :     $uri->set_query_param($soo_image['jump_param']);
388 :     $uri->set_query_param($soo_image['page_param'], $soo_image['next']);
389 :     $out = new soo_html_anchor($uri->full$thing $thing $link_text);
390 :     return $out->class($class)->id($html_id)->tag();
391 : }
392 : 
393 : function soo_image_prev($atts$thing null) {
394 : 
395 :     extract(lAtts(array(
396 :         'link_text'     => '&larr;',
397 :         'class'         => '',
398 :         'html_id'       => '',
399 :     ), $atts));
400 :     global $soo_image;
401 : 
402 :     $prev intval(gps($soo_image['page_param'])) - 1;
403 :     if ( $prev )
404 :         return soo_util::secondpass(__FUNCTION__$atts$thing);
405 :     $uri = new soo_uri;
406 :     $uri->set_query_param($soo_image['jump_param']);
407 :     $uri->set_query_param($soo_image['page_param'], $prev $prev null);
408 :     $out = new soo_html_anchor($uri->full$thing $thing $link_text);
409 :     return $out->class($class)->id($html_id)->tag();
410 : }
411 : 
412 : function soo_image_page_count($atts) {
413 : 
414 :     extract(lAtts(array(
415 :         'format'        =>  'Page {current} of {total}',
416 :         'showalways'    =>  false,
417 :     ), $atts));
418 :     global $soo_image;
419 : 
420 :     if ( ! isset($soo_image['this_page']) )
421 :         return soo_util::secondpass(__FUNCTION__$atts);
422 : 
423 :     if ( ! $showalways and $soo_image['total_pages'] <= ) return;
424 : 
425 :     return str_replace(array('{current}''{total}'),
426 :         array($soo_image['this_page'], $soo_image['total_pages']), $format);
427 : }
428 : 
429 : function soo_exif($atts$thing) {
430 : 
431 :     global $dateformat$soo_exif_field$soo_exif_value;
432 :     extract(lAtts(array(
433 :         'field'     =>  '',
434 :         'format'    =>  '{field}: {value}',
435 :         'wraptag'   =>  '',
436 :         'break'     =>  '',
437 :     ), $atts));
438 : 
439 :     $display = array(
440 :         'Model'                 =>  'Camera',
441 :         'ExposureTime'          =>  'Shutter speed',
442 :         'FNumber'               =>  'F-stop',
443 :         'ISOSpeedRatings'       =>  'ISO speed',
444 :         'DateTimeOriginal'      =>  'Exposure date',
445 :         'FocalLength'           =>  'Focal length',
446 :         'CropFactor'            =>  'Crop factor',
447 :         'FOV'                   =>  'Computed FOV',
448 :         'ImageHistory'          =>  'History',
449 :         );
450 : 
451 :     $shortcuts = array(
452 :         'model'                 =>  'Model',
453 :         'exp-time'              =>  'ExposureTime',
454 :         'f-number'              =>  'FNumber',
455 :         'iso-speed'             =>  'ISOSpeedRatings',
456 :         'date-taken'            =>  'DateTimeOriginal',
457 :         'focal-len'             =>  'FocalLength',
458 :         'crop'                  =>  'CropFactor',
459 :         'history'               =>  'ImageHistory',
460 :     );
461 : 
462 :     if ( empty($field) )
463 :         $fields array_keys($display);
464 : 
465 :     else {
466 :         $fields do_list($field);
467 :         foreach ( $fields as $i => $f )
468 :             if ( array_key_exists(strtolower($f), $shortcuts) )
469 :                 $fields[$i] = $shortcuts[$f];
470 :     }
471 : 
472 :     $exif exif_read_data(_soo_image_path());
473 : 
474 :     extract($exif);
475 : 
476 :     if ( isset($FNumber) )
477 :         $exif['FNumber'] = '&fnof;/' round(_soo_image_convert_ratio($FNumber), 1);
478 : 
479 :     if ( isset($FocalLength) )
480 :         $exif['FocalLength'] = _soo_image_convert_ratio($FocalLength) . 'mm';
481 : 
482 :     if ( isset($FocalLengthIn35mmFilm) ) {
483 :         $fl35 _soo_image_convert_ratio($FocalLengthIn35mmFilm);
484 :         if ( isset($FocalLength) )
485 :             $exif['CropFactor'] = round($fl35 _soo_image_convert_ratio($FocalLength), 1);
486 :         $exif['FocalLengthIn35mmFilm'] = $fl35 'mm';
487 :         // 43.27 is the diagonal length (mm) of a full-frame sensor
488 :         $exif['FOV'] = round(rad2deg(atan(43.27 / ( $fl35 ))), 1) . '&deg;';
489 :     }
490 : 
491 :     if ( isset($DateTimeOriginal) )
492 :         $exif['DateTimeOriginal'] =
493 :             safe_strftime($dateformatstrtotime($DateTimeOriginal));
494 : 
495 :     if ( strtolower($fields[0]) == 'dump' )
496 :         $fields array_keys($exif);
497 : 
498 :     foreach ( $fields as $k ) {
499 :         if ( isset($exif[$k]) ) {
500 :             $v $exif[$k];
501 :             $soo_exif_field = isset($display[$k]) ? $display[$k] : $k;
502 :             $soo_exif_value is_array($v) ? implode(' '$v) : trim($v);
503 :             $r_format str_replace('{field}'$soo_exif_field$format);
504 :             $r_format str_replace('{value}'$soo_exif_value$r_format);
505 :             $out[] = $thing parse($thing) : $r_format;
506 :         }
507 :     }
508 :     return isset($out) ? doWrap($out$wraptag$break) : '';
509 : }
510 : 
511 : function soo_exif_field($atts) {
512 : 
513 :     global $soo_exif_field;
514 :     extract(lAtts(array(
515 :         'wraptag'   =>  '',
516 :     ), $atts));
517 : 
518 :     if ( $soo_exif_field )
519 :         return doWrap(array($soo_exif_field), $wraptag'');
520 : }
521 : 
522 : function soo_exif_value($atts) {
523 : 
524 :     global $soo_exif_value;
525 :     extract(lAtts(array(
526 :         'wraptag'   =>  '',
527 :     ), $atts));
528 : 
529 :     if ( $soo_exif_value ) {
530 :         if ( ! is_array($soo_exif_value) )
531 :             $soo_exif_value = array($soo_exif_value);
532 :         return doWrap($soo_exif_value$wraptag'');
533 :     }
534 : }
535 : 
536 :   //---------------------------------------------------------------------//
537 :  //                         Support Functions                           //
538 : //---------------------------------------------------------------------//
539 : 
540 : function _soo_image_path() {
541 : 
542 :     global $img_dir;
543 : 
544 :     $img_dir_path $_SERVER['DOCUMENT_ROOT'] . "/$img_dir/";
545 :     $image _soo_image_by_context();
546 : 
547 :     if ( $image instanceof soo_txp_img )
548 :         $file_path $img_dir_path $image->id $image->ext;
549 : 
550 :     elseif ( $image instanceof soo_html_img ) {
551 :         $pattern '&^(' str_replace('.''\.'hu) . "|\/)($img_dir.+)&";
552 :         if ( preg_match($pattern$image->src$match) )
553 :             $file_path $match[2];
554 :     }
555 : 
556 :     if ( empty($file_path) or ! file_exists($file_path) )
557 :         return null;
558 : 
559 :     return $file_path;
560 : }
561 : 
562 : function _soo_article_image_list() {
563 :     global $thisarticle;
564 :     return empty($thisarticle['article_image']) ?
565 :         array() : _soo_range_to_list($thisarticle['article_image']);
566 : }
567 : 
568 : function _soo_range_to_list$csv ) {
569 : 
570 :     $items do_list($csv);
571 :     foreach ( $items as $item )
572 :         if ( preg_match('/(\d+)(:|-)(\d+)/'$item$match) ) {
573 :             if ( $match[3] > $match[1] )
574 :                 for ( $i $match[1]; $i <= $match[3]; $i++ )
575 :                     $out[] = $i;
576 :             else
577 :                 for ( $i $match[1]; $i >= $match[3]; $i-- )
578 :                     $out[] = $i;
579 :         }
580 :         else
581 :             $out[] = $item;
582 :     return $out;
583 : }
584 : 
585 : function _soo_valid_ext$in ) {
586 :     $ok = array('jpg''jpeg''gif''png''bmp',
587 :         '.jpg''.jpeg''.gif''.png''.bmp');
588 :     $exts is_array($in) ? $in do_list($in);
589 :     foreach ($exts as $i => $value)
590 :         if ( !in_array($value$ok) )
591 :             unset($exts[$i]);
592 :         else
593 :             $exts[$i] = '.' $value;
594 :     return $exts;
595 : }
596 : 
597 : function _soo_image_convert_ratio$r ) {
598 :     if ( is_numeric($r) )
599 :         return $r;
600 :     if ( ! preg_match('/(.+)(:|\/)(.+)/'$r$match) )
601 :         return null;
602 :     if ( is_numeric($match[1]) and is_numeric($match[3]) and $match[3] != )
603 :         return $match[1] / $match[3];
604 :     else
605 :         return null;
606 : }
607 : 
608 : function _soo_image_aspect_ratio$query$aspect_ratio ) {
609 : 
610 :     $fudge 0.01;
611 :     $pattern '/^(\+|-)?([^-]+)(-)?(.+)?$/';
612 :     if ( ! preg_match($pattern$aspect_ratio$match) )
613 :         return;
614 : 
615 :     if ( $match[1] == '+' ) {
616 :         $min_ar _soo_image_convert_ratio($match[2]);
617 :         if ( is_null($min_ar) )
618 :             return;
619 :     }
620 :     elseif ( $match[1] == '-' ) {
621 :         $max_ar _soo_image_convert_ratio($match[2]);
622 :         if ( is_null($max_ar) )
623 :             return;
624 :     }
625 : 
626 :     elseif ( isset($match[3]) ) {
627 :         $min_ar _soo_image_convert_ratio($match[2]);
628 :         $max_ar _soo_image_convert_ratio($match[4]);
629 :         if ( is_null($min_ar) or is_null($max_ar) )
630 :             return;
631 :         if ( $max_ar $min_ar )
632 :             list($max_ar$min_ar) = array($min_ar$max_ar);
633 :     }
634 :     else {
635 :         $ar _soo_image_convert_ratio($match[2]);
636 :         if ( is_null($ar) )
637 :             return;
638 :         $query->where('w/h'$ar $fudge'<')
639 :             ->where('w/h'$ar $fudge'>');
640 :         return;
641 :     }
642 :     if ( isset($min_ar) )
643 :         $query->where('w/h'$min_ar $fudge'>=');
644 :     if ( isset($max_ar) )
645 :         $query->where('w/h'$max_ar $fudge'<=');
646 : 
647 : }
648 : 
649 : function _soo_image_by_context( ) {
650 : // Return a single image object (Txp or Html) for the current image context.
651 :     // Image passed by parent soo_image_select tag, or;
652 :     // first article image, or;
653 :     // first selection from previous soo_image_select tag (subject to prefs).
654 : // Return false if image context is empty
655 : 
656 :     global $soo_image;
657 : 
658 :     if ( isset($soo_image['data_obj']) )
659 :         $img $soo_image['data_obj'];
660 : 
661 :     elseif ( isset($soo_image['url']) )
662 :         $img $soo_image['url'];
663 : 
664 :     elseif ( $article_image array_shift(_soo_article_image_list()) )
665 :         $img $article_image;
666 : 
667 :     elseif ( ! empty($soo_image['first_selection']) )
668 :         $img $soo_image['first_selection'];
669 : 
670 :     if ( empty($img) ) return false;
671 :     if ( is_object($img) ) return $img;
672 :     if ( is_numeric($img) ) return new soo_txp_img($img);
673 :     return new soo_html_img(array('src' => $img));
674 : }