Ignore:
Timestamp:
Dec 9, 2011, 12:07:57 PM (12 years ago)
Author:
mistic100
Message:

fix major issue with prefilters, works better with Simple and Stripped themes

Location:
extensions/Subscribe_to_comments
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • extensions/Subscribe_to_comments/include/subscribe_to_comments.inc.php

    r12620 r12708  
    55 * detect 'subscriptions' section and load page
    66 */
    7 function stc_detect_section() {
     7function stc_detect_section()
     8{
    89  global $tokens, $page;
    910 
     
    1415}
    1516
    16 function stc_load_section() {
     17function stc_load_section()
     18{
    1719  global $page;
    1820
     
    6567      }
    6668     
    67        // messages management
    68       if (!empty($errors))
    69       {
    70         $errors_bak = $template->get_template_vars('errors');
    71         if (empty($errors_bak)) $errors_bak = array();
    72         $template->assign('errors', array_merge($errors_bak, $errors));
    73         $template->set_prefilter('index', 'coa_messages'); // here we use a prefilter existing in COA
    74       }
    75       if (!empty($infos))
    76       {
    77         $infos_bak = $template->get_template_vars('infos');
    78         if (empty($infos_bak)) $infos_bak = array();
    79         $template->assign('infos', array_merge($infos_bak, $infos));
    80         $template->set_prefilter('index', 'coa_messages');
    81       }
     69      // messages management
     70      stc_add_messages($errors, $infos, true);
    8271    }
    8372  }
     
    126115function stc_on_picture()
    127116{
    128   global $template, $picture, $page;
    129  
    130   $infos = $array = array();
     117  global $template, $picture, $page, $user;
     118 
     119  $infos = $errors = array();
    131120 
    132121  if (isset($_POST['stc_submit']))
     
    155144 
    156145  // messages management
    157   if (!empty($errors))
    158   {
    159     $errors_bak = $template->get_template_vars('errors');
    160     if (empty($errors_bak)) $errors_bak = array();
    161     $template->assign('errors', array_merge($errors_bak, $errors));
    162   }
    163   if (!empty($infos))
    164   {
    165     $infos_bak = $template->get_template_vars('infos');
    166     if (empty($infos_bak)) $infos_bak = array();
    167     $template->assign('infos', array_merge($infos_bak, $infos));
    168   }
    169  
    170   $template->set_prefilter('picture', 'stc_on_picture_prefilter');
    171 }
    172 
    173 function stc_on_picture_prefilter($content, &$smarty)
    174 {
    175   global $user, $picture;
     146  stc_add_messages($errors, $infos);
    176147 
    177148  // if registered user with mail we check if already subscribed
    178   $subscribed = false;
    179149  if ( !is_a_guest() and !empty($user['email']) )
    180150  {
     
    189159    if (pwg_db_num_rows(pwg_query($query)))
    190160    {
    191       $subscribed = true;
    192     }
    193   }
    194  
    195   ## subscribe at any moment ##
    196   $search = '#\<\/div\>(.{0,5})\{\/if\}(.{0,5})\{\*comments\*\}#is';
    197  
    198   $replace = '
    199 <form method="post" action="{$comment_add.F_ACTION}" class="filter" id="stc_standalone">
    200   <fieldset>';
    201  
    202   if ($subscribed)
    203   {
    204     $replace.= '
    205     {\'You are currently subscribed to comments of this picture.\'|@translate}
    206     <a href="'.add_url_params($picture['current']['url'], array('stc_unsubscribe'=>'1')).'">{\'Unsubscribe\'|@translate}';
     161      $template->assign(array(
     162        'SUBSCRIBED' => true,
     163        'UNSUB_LINK' => add_url_params($picture['current']['url'], array('stc_unsubscribe'=>'1')),
     164        ));
     165    }
    207166  }
    208167  else
    209168  {
    210     $replace.= '
    211     <legend>{\'Subscribe without commenting\'|@translate}</legend>';
    212     if ( is_a_guest() or empty($user['email']) ) // email input for guest or users without mail
    213     {
    214       $replace.= '
    215       <label>{\'Email address\'|@translate} <input type="text" name="stc_mail_stdl"></label>
    216       <label><input type="submit" name="stc_submit" value="{\'Submit\'|@translate}"></label>';
    217     }
    218     else
    219     {
    220       $replace.= '
    221       <label><input type="submit" name="stc_submit" value="{\'Subscribe\'|@translate}"></label>';
    222     }
    223   }
    224      
    225   $replace.= '
    226   </fieldset>
    227 </form>
    228 </div>
    229 {/if}{*comments*}';
    230 
    231   $content = preg_replace($search, $replace, $content);
    232 
    233 
    234   ## subscribe while add a comment ##
    235   $search = '#<input type="hidden" name="key" value="{\$comment_add\.KEY}"([ /]*)>#';
    236   $replace = '<input type="hidden" name="key" value="{$comment_add.KEY}"$1>';
    237  
    238   if (!$subscribed)
    239   {
    240     $replace.= '
    241     <label>{\'Notify me of followup comments\'|@translate} <input type="checkbox" name="stc_check" value="1"></label>';
    242   }
    243   if ( is_a_guest() or empty($user['email']) )
    244   {
    245     $replace.= '
    246     <label id="stc_mail" style="display:none;">{\'Email address\'|@translate} <input type="text" name="stc_mail"></label>
    247     {footer_script require="jquery"}{literal}
    248     jQuery(document).ready(function() {
    249       $("input[name=stc_check]").change(function() {
    250         if ($(this).is(":checked")) $("#stc_mail").css("display", "");
    251         else $("#stc_mail").css("display", "none");
    252       });
    253     });
    254     {/literal}{/footer_script}';
    255   }
    256  
    257   $content = preg_replace($search, $replace, $content);
    258  
    259   return $content;
    260 }
    261 
     169    $template->assign('ASK_MAIL', true);
     170  }
     171 
     172  if ( $is_simple = strstr($user['theme'], 'simple') !== false or strstr($user['theme'], 'stripped') !== false )
     173    $template->set_prefilter('picture', 'stc_simple_prefilter');
     174  else
     175    $template->set_prefilter('picture', 'stc_main_prefilter');
     176}
    262177
    263178/**
     
    266181function stc_on_album()
    267182{
    268   global $page, $template, $pwg_loaded_plugins;
     183  global $page, $template, $pwg_loaded_plugins, $user;
    269184 
    270185  $infos = $errors = array();
     
    304219 
    305220  // messages management
    306   if (!empty($errors))
    307   {
    308     $errors_bak = $template->get_template_vars('errors');
    309     if (empty($errors_bak)) $errors_bak = array();
    310     $template->assign('errors', array_merge($errors_bak, $errors));
    311     $template->set_prefilter('index', 'coa_messages'); // here we use a prefilter existing in COA
    312   }
    313   if (!empty($infos))
    314   {
    315     $infos_bak = $template->get_template_vars('infos');
    316     if (empty($infos_bak)) $infos_bak = array();
    317     $template->assign('infos', array_merge($infos_bak, $infos));
    318     $template->set_prefilter('index', 'coa_messages');
    319   }
    320  
    321   $template->set_prefilter('comments_on_albums', 'stc_on_album_prefilter');
    322 }
    323 
    324 function stc_on_album_prefilter($content, &$smarty)
    325 {
    326   global $user, $page;
     221  stc_add_messages($errors, $infos, true);
    327222 
    328223  // if registered user we check if already subscribed
    329   $subscribed = false;
    330224  if ( !is_a_guest() and !empty($user['email']) )
    331225  {
     
    340234    if (pwg_db_num_rows(pwg_query($query)))
    341235    {
    342       $subscribed = true;
    343     }
    344   }
    345  
     236      $url_params['section'] = 'categories';
     237      $url_params['category'] = $page['category'];
     238      $element_url = make_index_url($url_params);
     239     
     240      $template->assign(array(
     241        'SUBSCRIBED' => true,
     242        'UNSUB_LINK' => add_url_params($element_url, array('stc_unsubscribe'=>'1')),
     243        ));
     244    }
     245  }
     246  else
     247  {
     248    $template->assign('ASK_MAIL', true);
     249  }
     250 
     251  if ( $is_simple = strstr($user['theme'], 'simple') !== false or strstr($user['theme'], 'stripped') !== false )
     252    $template->set_prefilter('comments_on_albums', 'stc_simple_prefilter');
     253  else
     254    $template->set_prefilter('comments_on_albums', 'stc_main_prefilter');
     255}
     256
     257
     258/**
     259 * prefilter for common themes
     260 */
     261function stc_main_prefilter($content, &$smarty)
     262
    346263  ## subscribe at any moment ##
    347   $search = '#\<\/div\>(.{0,5})\{\/if\}(.{0,5})\{\*comments\*\}#is';
     264  $search = '#\<\/div\>(.{0,10})\{\/if\}(.{0,10})\{\*comments\*\}#is';
    348265 
    349266  $replace = '
    350267<form method="post" action="{$comment_add.F_ACTION}" class="filter" id="stc_standalone">
    351   <fieldset>';
    352  
    353   if ($subscribed)
    354   {
    355     $url_params['section'] = 'categories';
    356     $url_params['category'] = $page['category'];
    357    
    358     $element_url = make_index_url($url_params);
    359  
    360     $replace.= '
    361     {\'You are currently subscribed to comments of this album.\'|@translate}
    362     <a href="'.add_url_params($element_url, array('stc_unsubscribe'=>'1')).'">{\'Unsubscribe\'|@translate}';
    363   }
    364   else
    365   {
    366     $replace.= '
    367     <legend>{\'Subscribe without commenting\'|@translate}</legend>';
    368     if ( is_a_guest() or empty($user['email']) ) // email input for guest or users without mail
    369     {
    370       $replace.= '
     268  <fieldset>
     269  {if $SUBSCRIBED == true}
     270    {\'You are currently subscribed to comments of this picture.\'|@translate}
     271    <a href="{$UNSUB_LINK}">{\'Unsubscribe\'|@translate}
     272  {else}
     273    <legend>{\'Subscribe without commenting\'|@translate}</legend>
     274    {if $ASK_MAIL == true}
    371275      <label>{\'Email address\'|@translate} <input type="text" name="stc_mail_stdl"></label>
    372       <label><input type="submit" name="stc_submit" value="{\'Submit\'|@translate}"></label>';
    373     }
    374     else
    375     {
    376       $replace.= '
    377       <label><input type="submit" name="stc_submit" value="{\'Subscribe\'|@translate}"></label>';
    378     }
    379   }
    380      
    381   $replace.= '
     276      <label><input type="submit" name="stc_submit" value="{\'Submit\'|@translate}"></label>
     277    {else}
     278      <label><input type="submit" name="stc_submit" value="{\'Subscribe\'|@translate}"></label>
     279    {/if}
     280  {/if}
    382281  </fieldset>
    383282</form>
    384 </div>
    385 {/if}{*comments*}';
     283</div>$1{/if}$2{*comments*}';
    386284
    387285  $content = preg_replace($search, $replace, $content);
    388 
    389 
     286 
    390287  ## subscribe while add a comment ##
    391   $search = '<input type="hidden" name="key" value="{$comment_add.KEY}">';
    392   $replace = $search;
    393  
    394   if (!$subscribed)
    395   {
    396     $replace.= '
    397     <label>{\'Notify me of followup comments\'|@translate} <input type="checkbox" name="stc_check" value="1"></label>';
    398   }
    399   if ( is_a_guest() or empty($user['email']) )
    400   {
    401     $replace.= '
    402     <label id="stc_mail" style="display:none;">{\'Email address\'|@translate} <input type="text" name="stc_mail"></label>
     288  $search = '#<input type="hidden" name="key" value="{\$comment_add\.KEY}"([ /]*)>#';
     289 
     290  $replace = '
     291<input type="hidden" name="key" value="{$comment_add.KEY}"$1>
     292{if $SUBSCRIBED != true}
     293  <label>{\'Notify me of followup comments\'|@translate} <input type="checkbox" name="stc_check" value="1"></label><br>
     294
     295  {if $ASK_MAIL == true}
     296    <label id="stc_mail" style="display:none;">{\'Email address\'|@translate} <input type="text" name="stc_mail"></label><br>
    403297    {footer_script require="jquery"}{literal}
    404298    jQuery(document).ready(function() {
     
    408302      });
    409303    });
    410     {/literal}{/footer_script}';
    411   }
    412 
    413   $content = str_replace($search, $replace, $content);
     304    {/literal}{/footer_script}
     305  {/if}
     306{/if}';
     307 
     308  $content = preg_replace($search, $replace, $content);
    414309 
    415310  return $content;
    416311}
    417312
     313/**
     314 * prefilter for simple/stripped themes
     315 */
     316function stc_simple_prefilter($content, &$smarty)
     317
     318  ## subscribe at any moment ##
     319  $search = '#\<\/div\>(.{0,10})\{\/if\}(.{0,10})\{if \!empty\(\$navbar\) \}\{include file\=\'navigation_bar.tpl\'\|\@get_extent:\'navbar\'\}\{\/if\}#is';
     320 
     321  $replace = '
     322<form method="post" action="{$comment_add.F_ACTION}" class="filter" id="stc_standalone">
     323  <fieldset>
     324  {if $SUBSRIBED == true}
     325    {\'You are currently subscribed to comments of this album.\'|@translate}
     326    <a href="{$UNSUB_LINK}">{\'Unsubscribe\'|@translate}
     327  {else}
     328    <legend>{\'Subscribe without commenting\'|@translate}</legend>
     329    {if $ASK_MAIL == true}
     330      <label>{\'Email address\'|@translate} <input type="text" name="stc_mail_stdl"></label>
     331      <label><input type="submit" name="stc_submit" value="{\'Submit\'|@translate}"></label>
     332    {else}
     333      <label><input type="submit" name="stc_submit" value="{\'Subscribe\'|@translate}"></label>
     334    {/if}
     335  {/if}
     336  </fieldset>
     337</form>
     338</div>$1{/if}$2{if !empty($navbar) }{include file=\'navigation_bar.tpl\'|@get_extent:\'navbar\'}{/if}';
     339
     340  $content = preg_replace($search, $replace, $content);
     341 
     342  ## subscribe while add a comment ##
     343  $search = '#<input type="hidden" name="key" value="{\$comment_add\.KEY}"([ /]*)>#';
     344 
     345  $replace = '
     346<input type="hidden" name="key" value="{$comment_add.KEY}"$1>
     347{if $SUBSCRIBED != true}
     348  <label>{\'Notify me of followup comments\'|@translate} <input type="checkbox" name="stc_check" value="1"></label><br>
     349
     350  {if $ASK_MAIL == true}
     351    <label id="stc_mail" style="display:none;">{\'Email address\'|@translate} <input type="text" name="stc_mail"></label><br>
     352    {footer_script require="jquery"}{literal}
     353    jQuery(document).ready(function() {
     354      $("input[name=stc_check]").change(function() {
     355        if ($(this).is(":checked")) $("#stc_mail").css("display", "");
     356        else $("#stc_mail").css("display", "none");
     357      });
     358    });
     359    {/literal}{/footer_script}
     360  {/if}
     361{/if}';
     362 
     363  $content = preg_replace($search, $replace, $content);
     364 
     365  return $content;
     366}
    418367
    419368/**
     
    439388  return str_replace($search, $search.$replace, $content);
    440389}
     390
     391/**
     392 * must overload messages because Piwigo is weird
     393 */
     394function stc_add_messages($errors, $infos, $prefilter=false)
     395{
     396  global $template;
     397 
     398  if (!empty($errors))
     399  {
     400    $errors_bak = $template->get_template_vars('errors');
     401    if (empty($errors_bak)) $errors_bak = array();
     402    $template->assign('errors', array_merge($errors_bak, $errors));
     403    if ($prefilter) $template->set_prefilter('index', 'coa_messages'); // here we use a prefilter existing in COA
     404  }
     405  if (!empty($infos))
     406  {
     407    $infos_bak = $template->get_template_vars('infos');
     408    if (empty($infos_bak)) $infos_bak = array();
     409    $template->assign('infos', array_merge($infos_bak, $infos));
     410    if ($prefilter) $template->set_prefilter('index', 'coa_messages');
     411  }
     412}
    441413?>
  • extensions/Subscribe_to_comments/language/en_UK/plugin.lang.php

    r12609 r12708  
    66$lang['Invalid email adress, your are not subscribed to comments.'] = 'Invalid email adress, your are not subscribed to comments.';
    77$lang['Successfully unsubscribed your email address from receiving notifications.'] = 'Successfully unsubscribed your email address from receiving notifications.';
    8 $lang['You are currently subscribed to comments of this picture.'] = 'You are currently subscribed to comments of this picture.';
    9 $lang['You are currently subscribed to comments of this album.'] = 'You are currently subscribed to comments of this album.';
     8$lang['You are currently subscribed to comments.'] = 'You are currently subscribed to comments.';
    109$lang['Unsubscribe'] = 'Unsubscribe';
    1110$lang['Subscribe'] = 'Subscribe';
  • extensions/Subscribe_to_comments/language/fr_FR/plugin.lang.php

    r12609 r12708  
    66$lang['Invalid email adress, your are not subscribed to comments.'] = 'Addresse email invalide, vous n\'avez pas été inscrit.';
    77$lang['Successfully unsubscribed your email address from receiving notifications.'] = 'Inscription aux commentaires annulée avec succès.';
    8 $lang['You are currently subscribed to comments of this picture.'] = 'Vous êtes actuellement inscrit aux commentaires de cette photo.';
    9 $lang['You are currently subscribed to comments of this album.'] = 'Vous êtes actuellement inscrit aux commentaires de cet album.';
     8$lang['You are currently subscribed to comments.'] = 'Vous êtes actuellement inscrit aux commentaires.';
    109$lang['Unsubscribe'] = 'Se désinscrire';
    1110$lang['Subscribe'] = 'S\'inscrire';
Note: See TracChangeset for help on using the changeset viewer.