Index: /extensions/Subscribe_to_comments/include/subscribe_to_comments.inc.php =================================================================== --- /extensions/Subscribe_to_comments/include/subscribe_to_comments.inc.php (revision 12707) +++ /extensions/Subscribe_to_comments/include/subscribe_to_comments.inc.php (revision 12708) @@ -5,5 +5,6 @@ * detect 'subscriptions' section and load page */ -function stc_detect_section() { +function stc_detect_section() +{ global $tokens, $page; @@ -14,5 +15,6 @@ } -function stc_load_section() { +function stc_load_section() +{ global $page; @@ -65,19 +67,6 @@ } - // messages management - if (!empty($errors)) - { - $errors_bak = $template->get_template_vars('errors'); - if (empty($errors_bak)) $errors_bak = array(); - $template->assign('errors', array_merge($errors_bak, $errors)); - $template->set_prefilter('index', 'coa_messages'); // here we use a prefilter existing in COA - } - if (!empty($infos)) - { - $infos_bak = $template->get_template_vars('infos'); - if (empty($infos_bak)) $infos_bak = array(); - $template->assign('infos', array_merge($infos_bak, $infos)); - $template->set_prefilter('index', 'coa_messages'); - } + // messages management + stc_add_messages($errors, $infos, true); } } @@ -126,7 +115,7 @@ function stc_on_picture() { - global $template, $picture, $page; - - $infos = $array = array(); + global $template, $picture, $page, $user; + + $infos = $errors = array(); if (isset($_POST['stc_submit'])) @@ -155,26 +144,7 @@ // messages management - if (!empty($errors)) - { - $errors_bak = $template->get_template_vars('errors'); - if (empty($errors_bak)) $errors_bak = array(); - $template->assign('errors', array_merge($errors_bak, $errors)); - } - if (!empty($infos)) - { - $infos_bak = $template->get_template_vars('infos'); - if (empty($infos_bak)) $infos_bak = array(); - $template->assign('infos', array_merge($infos_bak, $infos)); - } - - $template->set_prefilter('picture', 'stc_on_picture_prefilter'); -} - -function stc_on_picture_prefilter($content, &$smarty) -{ - global $user, $picture; + stc_add_messages($errors, $infos); // if registered user with mail we check if already subscribed - $subscribed = false; if ( !is_a_guest() and !empty($user['email']) ) { @@ -189,75 +159,20 @@ if (pwg_db_num_rows(pwg_query($query))) { - $subscribed = true; - } - } - - ## subscribe at any moment ## - $search = '#\<\/div\>(.{0,5})\{\/if\}(.{0,5})\{\*comments\*\}#is'; - - $replace = ' -
- -{/if}{*comments*}'; - - $content = preg_replace($search, $replace, $content); - - - ## subscribe while add a comment ## - $search = '##'; - $replace = ''; - - if (!$subscribed) - { - $replace.= ' - '; - } - if ( is_a_guest() or empty($user['email']) ) - { - $replace.= ' - - {footer_script require="jquery"}{literal} - jQuery(document).ready(function() { - $("input[name=stc_check]").change(function() { - if ($(this).is(":checked")) $("#stc_mail").css("display", ""); - else $("#stc_mail").css("display", "none"); - }); - }); - {/literal}{/footer_script}'; - } - - $content = preg_replace($search, $replace, $content); - - return $content; -} - + $template->assign('ASK_MAIL', true); + } + + if ( $is_simple = strstr($user['theme'], 'simple') !== false or strstr($user['theme'], 'stripped') !== false ) + $template->set_prefilter('picture', 'stc_simple_prefilter'); + else + $template->set_prefilter('picture', 'stc_main_prefilter'); +} /** @@ -266,5 +181,5 @@ function stc_on_album() { - global $page, $template, $pwg_loaded_plugins; + global $page, $template, $pwg_loaded_plugins, $user; $infos = $errors = array(); @@ -304,28 +219,7 @@ // messages management - if (!empty($errors)) - { - $errors_bak = $template->get_template_vars('errors'); - if (empty($errors_bak)) $errors_bak = array(); - $template->assign('errors', array_merge($errors_bak, $errors)); - $template->set_prefilter('index', 'coa_messages'); // here we use a prefilter existing in COA - } - if (!empty($infos)) - { - $infos_bak = $template->get_template_vars('infos'); - if (empty($infos_bak)) $infos_bak = array(); - $template->assign('infos', array_merge($infos_bak, $infos)); - $template->set_prefilter('index', 'coa_messages'); - } - - $template->set_prefilter('comments_on_albums', 'stc_on_album_prefilter'); -} - -function stc_on_album_prefilter($content, &$smarty) -{ - global $user, $page; + stc_add_messages($errors, $infos, true); // if registered user we check if already subscribed - $subscribed = false; if ( !is_a_guest() and !empty($user['email']) ) { @@ -340,65 +234,65 @@ if (pwg_db_num_rows(pwg_query($query))) { - $subscribed = true; - } - } - + $url_params['section'] = 'categories'; + $url_params['category'] = $page['category']; + $element_url = make_index_url($url_params); + + $template->assign(array( + 'SUBSCRIBED' => true, + 'UNSUB_LINK' => add_url_params($element_url, array('stc_unsubscribe'=>'1')), + )); + } + } + else + { + $template->assign('ASK_MAIL', true); + } + + if ( $is_simple = strstr($user['theme'], 'simple') !== false or strstr($user['theme'], 'stripped') !== false ) + $template->set_prefilter('comments_on_albums', 'stc_simple_prefilter'); + else + $template->set_prefilter('comments_on_albums', 'stc_main_prefilter'); +} + + +/** + * prefilter for common themes + */ +function stc_main_prefilter($content, &$smarty) +{ ## subscribe at any moment ## - $search = '#\<\/div\>(.{0,5})\{\/if\}(.{0,5})\{\*comments\*\}#is'; + $search = '#\<\/div\>(.{0,10})\{\/if\}(.{0,10})\{\*comments\*\}#is'; $replace = ' - -{/if}{*comments*}'; +$1{/if}$2{*comments*}'; $content = preg_replace($search, $replace, $content); - - + ## subscribe while add a comment ## - $search = ''; - $replace = $search; - - if (!$subscribed) - { - $replace.= ' - '; - } - if ( is_a_guest() or empty($user['email']) ) - { - $replace.= ' - + $search = '##'; + + $replace = ' + +{if $SUBSCRIBED != true} +