Changeset 16125


Ignore:
Timestamp:
06/28/12 16:35:46 (7 years ago)
Author:
mistic100
Message:

let's rewrite a bit [photo] and [random] with more user-friendly form

File:
1 edited

Legend:

Unmodified
Added
Removed
  • extensions/ExtendedDescription/main.inc.php

    r16123 r16125  
    125125  $replacements[] = ($param == 'subcatify_category_description') ? '' : 'get_img_thumb("$1", "$2", "$3")'; 
    126126   
    127   // Balises [photo=xx.yy;SQ|TH|XXS|XS|S|M|L|XL|XXL;true|false] 
    128   $patterns[] = '#\[photo=([\d\.]*);?(SQ|TH|XXS|XS|S|M|L|XL|XXL|);?(true|false|)\]#ie'; 
    129   $replacements[] = ($param == 'subcatify_category_description') ? '' : 'get_photo_sized("$1", "$2", "$3")'; 
    130  
    131   // [random album=xx size=SQ|TH|XXS|XS|S|M|L|XL|XXL] 
    132   $patterns[] = '#\[random\s+(?:album|cat)=(\d+)(\s+size=(SQ|TH|XXS|XS|S|M|L|XL|XXL))?\]#ie'; 
    133   $replacements[] = 'extdesc_get_random_photo("$1", "$3")'; 
     127  // Balises [photo id=xx album=yy size=SQ|TH|XXS|XS|S|M|L|XL|XXL html=yes|no link=yes|no] 
     128  $patterns[] = '#\[photo\s+id=(\d+)(?:\s+album=(\d+))?(?:\s+size=(SQ|TH|XXS|XS|S|M|L|XL|XXL))?(?:\s+html=(yes|no))?(?:\s+link=(yes|no))?\]#ie'; 
     129  $replacements[] = ($param == 'subcatify_category_description') ? '' : 'get_photo_sized("$1", "$2", "$3", "$4", "$5")'; 
     130 
     131  // Balises [random album=xx size=SQ|TH|XXS|XS|S|M|L|XL|XXL html=yes|no link=yes|no] 
     132  $patterns[] = '#\[random\s+(?:album|cat)=(\d+)(?:\s+size=(SQ|TH|XXS|XS|S|M|L|XL|XXL))?(?:\s+html=(yes|no))?(?:\s+link=(yes|no))?\]#ie'; 
     133  $replacements[] = 'extdesc_get_random_photo("$1", "$2", "$3", "$4")'; 
    134134 
    135135  // Balises <!--complete-->, <!--more--> et <!--up-down--> 
     
    372372 
    373373// Return html code for a photo 
    374 function get_photo_sized($elem_id, $size, $show_url) 
     374function get_photo_sized($image_id, $cat_id, $size, $html, $link) 
    375375{ 
    376376  global $template; 
    377    
    378   if (empty($size)) $size = 'M'; 
    379   if (empty($show_url)) $show_url = 'true'; 
    380  
    381   list($image_id, $cat_id) = array_pad(explode(".",$elem_id), 2, ""); 
    382377   
    383378  $size_map = array( 
     
    393388    ); 
    394389     
     390  if (!array_key_exists($size, $size_map)) $size = 'M'; 
     391  $link = $link=='no' ? false: true; 
     392  $html = $html=='no' ? false: true; 
     393     
    395394  $deriv_type = $size_map[ strtoupper($size) ]; 
    396395 
     
    436435    } 
    437436 
    438     $content = $template->parse('extended_description_content', true); 
    439     if (get_boolean($show_url))  
    440     { 
    441       return '<a href="'.$url.'">'.$content.'</a>'; 
    442     } 
    443     else 
    444     { 
    445       return $content; 
     437     
     438    if ($html)  
     439    { 
     440      $content = $template->parse('extended_description_content', true); 
     441      if ($link) return '<a href="'.$url.'">'.$content.'</a>'; 
     442      else       return $content; 
     443    } 
     444    else 
     445    { 
     446      return $selected_derivative->get_url(); 
    446447    } 
    447448  } 
     
    452453 
    453454 
    454 function extdesc_get_random_photo($category_id, $size="M") 
     455function extdesc_get_random_photo($category_id, $size, $html, $link) 
    455456{ 
    456457  include_once(PHPWG_ROOT_PATH.'include/functions_picture.inc.php'); 
     
    469470  { 
    470471    list($img_id) = pwg_db_fetch_row($result); 
    471     return get_photo_sized($img_id, $size, 'false'); 
     472    return get_photo_sized($img_id, $category_id, $size, $html, $link); 
    472473  } 
    473474 
Note: See TracChangeset for help on using the changeset viewer.