Changeset 16123


Ignore:
Timestamp:
Jun 28, 2012, 3:31:54 PM (8 years ago)
Author:
mistic100
Message:

rewrite [random] tag with size param (default size is M)

File:
1 edited

Legend:

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

    r16121 r16123  
    129129  $replacements[] = ($param == 'subcatify_category_description') ? '' : 'get_photo_sized("$1", "$2", "$3")';
    130130
    131   // [random album=xx]
    132   $patterns[] = '#\[random\s+(?:album|cat)=\s*?(\d+)\s*?\]#ie';
    133   $replacements[] = 'extdesc_get_random_photo("$1")';
     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")';
    134134
    135135  // Balises <!--complete-->, <!--more--> et <!--up-down-->
     
    398398  $result = pwg_query($query);
    399399
    400   if ($result)
     400  if (pwg_db_num_rows($result))
    401401  {
    402402    $template->set_filename('extended_description_content', 'picture_content.tpl');
    403403   
    404     $picture = mysql_fetch_assoc($result);
     404    $picture = pwg_db_fetch_assoc($result);
    405405   
    406406    // url
     
    452452
    453453
    454 function extdesc_get_random_photo($category_id)
     454function extdesc_get_random_photo($category_id, $size="M")
    455455{
    456456  include_once(PHPWG_ROOT_PATH.'include/functions_picture.inc.php');
    457457 
    458458  $query = '
    459 SELECT
    460     id,
    461     path
     459SELECT id
    462460  FROM '.IMAGES_TABLE.'
    463461    JOIN '.IMAGE_CATEGORY_TABLE.' ON image_id = id
     
    467465;';
    468466  $result = pwg_query($query);
    469   while ($row = pwg_db_fetch_assoc($result))
    470   {
    471     return '<img src="'.get_element_url($row).'">';
     467 
     468  if (pwg_db_num_rows($result))
     469  {
     470    list($img_id) = pwg_db_fetch_row($result);
     471    return get_photo_sized($img_id, $size, 'false');
    472472  }
    473473
Note: See TracChangeset for help on using the changeset viewer.