Changeset 27027


Ignore:
Timestamp:
01/28/14 11:42:57 (6 years ago)
Author:
mistic100
Message:

use preg_replace_callback, fix random with no argument

Location:
extensions/ExtendedDescription/include
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • extensions/ExtendedDescription/include/events.inc.php

    r26424 r27027  
    129129 
    130130  // [cat=xx] 
    131   $patterns[] = '#\[cat=(\d*)\]#ie'; 
    132   $replacements[] = ($param == 'subcatify_category_description') ? '' : 'get_cat_thumb("$1")'; 
    133  
    134131  // [img=xx.yy,xx.yy,xx.yy;left|right|;name|titleName|] 
    135   $patterns[] = '#\[img([^\]]*)\]#ie'; 
    136   $replacements[] = ($param == 'subcatify_category_description') ? '' : '[img] must be replaced by [photo]'; 
    137  
    138132  // [photo id=xx album=yy size=SQ|TH|XXS|XS|S|M|L|XL|XXL html=yes|no link=yes|no] 
    139   $patterns[] = '#\[photo ([^\]]+)\]#ie'; 
    140   $replacements[] = ($param == 'subcatify_category_description') ? '' : 'get_photo_sized("$1")'; 
    141  
    142133  // [random album=xx size=SQ|TH|XXS|XS|S|M|L|XL|XXL html=yes|no link=yes|no] 
    143   $patterns[] = '#\[random([^\]]*)\]#ie'; 
    144   $replacements[] = ($param == 'subcatify_category_description') ? '' : 'extdesc_get_random_photo("$1")'; 
    145  
    146134  // [slider album=xx nb_images=yy random=yes|no list=aa,bb,cc size=SQ|TH|XXS|XS|S|M|L|XL|XXL speed=z title=yes|no effect=... arrows=yes|no control=yes|no|thumb elastic=yes|no thumbs_size=dd] 
    147   $patterns[] = '#\[slider ([^\]]+)\]#ie'; 
    148   $replacements[] = ($param == 'subcatify_category_description') ? '' : 'get_slider("$1")'; 
     135  $generic_pattern = '#\[(cat=|img|photo|random|slider)([^\]]*)\]#i'; 
    149136 
    150137  // <!--complete-->, <!--more--> et <!--up-down--> 
     
    153140    case 'subcatify_category_description' : 
    154141      $patterns[] = '#^(.*?)(' . preg_quote($conf['ExtendedDescription']['complete']) . '|' . preg_quote($conf['ExtendedDescription']['more']) . '|' . preg_quote($conf['ExtendedDescription']['up-down']) . ').*$#is'; 
    155       $replacements[] = '$1'; 
     142      $replacement = '$1'; 
    156143      $desc = preg_replace($patterns, $replacements, $desc); 
     144      $desc = preg_replace($generic_pattern, '', $desc); 
    157145      break; 
    158146 
     
    161149      $replacements[] = ''; 
    162150      $desc = preg_replace($patterns, $replacements, $desc); 
     151      $desc = preg_replace_callback($generic_pattern, 'extended_desc_generic_callback', $desc); 
    163152 
    164153      if (substr_count($desc, $conf['ExtendedDescription']['up-down'])) 
     
    170159 
    171160    default: 
    172       $desc = preg_replace($patterns, $replacements, $desc); 
     161      $desc = preg_replace_callback($generic_pattern, 'extended_desc_generic_callback', $desc); 
    173162  } 
    174163 
     
    176165} 
    177166 
     167function extended_desc_generic_callback($matches) 
     168{ 
     169  switch ($matches[1]) 
     170  { 
     171    case 'cat=': 
     172      return get_cat_thumb($matches[2]); 
     173      break; 
     174       
     175    case 'img': 
     176      return '[img] must be replaced by [photo]'; 
     177      break; 
     178       
     179    case 'photo': 
     180      return get_photo_sized($matches[2]); 
     181      break; 
     182       
     183    case 'random': 
     184      return extdesc_get_random_photo($matches[2]); 
     185      break; 
     186       
     187    case 'slider': 
     188      return get_slider($matches[2]); 
     189      break; 
     190  } 
     191} 
     192 
    178193/** 
    179194 * Parse ED tags on NBM mail 
     
    195210  global $template, $conf; 
    196211 
    197   $template->concat('PLUGIN_INDEX_CONTENT_END', ' 
    198     <div class="additional_info"> 
    199     ' . $conf['ExtendedDescription']['bottom_comment'] . ' 
    200     </div>'); 
     212  if (!empty($conf['ExtendedDescription']['bottom_comment'])) 
     213  { 
     214    $template->concat('PLUGIN_INDEX_CONTENT_END', ' 
     215      <div class="additional_info"> 
     216      ' . $conf['ExtendedDescription']['bottom_comment'] . ' 
     217      </div>' 
     218      ); 
     219  } 
    201220} 
    202221 
  • extensions/ExtendedDescription/include/functions.inc.php

    r26424 r27027  
    88{ 
    99  global $template, $user; 
     10 
     11  $elem_id = intval($elem_id); 
     12  if ($elem_id<=0) 
     13  { 
     14    return ''; 
     15  } 
    1016 
    1117  $query = ' 
     
    193199  if (empty($params['album'])) 
    194200  { 
    195     $query = ' 
     201    $query.= ' 
    196202  WHERE 1=1 ' 
    197203      .get_sql_condition_FandF(array( 
Note: See TracChangeset for help on using the changeset viewer.