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'); } } } } function stc_comment_validation($comm_ids, $type='image') { if (!is_array($comm_ids)) $comm_ids = array($comm_ids); foreach($comm_ids as $comm_id) { if ($type == 'image') { $query = ' SELECT id, image_id, author, content FROM '.COMMENTS_TABLE.' WHERE id = '.$comm_id.' ;'; } else if ($type == 'category') { $query = ' SELECT id, category_id, author, content FROM '.COA_TABLE.' WHERE id = '.$comm_id.' ;'; } $comm = pwg_db_fetch_assoc(pwg_query($query)); send_comment_to_subscribers($comm); } } /** * add field and link on picture page */ function stc_on_picture() { global $template, $picture, $page; $infos = $array = array(); if (isset($_POST['stc_check_stdl'])) { $return = subscribe_to_comments($picture['current']['id'], @$_POST['stc_mail_stdl'], 'image'); if ($return === 'confirm_mail') { array_push($infos, l10n('Please check your email inbox to confirm your subscription.')); } else if ($return === true) { array_push($infos, l10n('You have been added to the list of subscribers for this picture.')); } else { array_push($errors, l10n('Invalid email adress, your are not subscribed to comments.')); } } else if (isset($_GET['stc_unsubscribe'])) { if (un_subscribe_to_comments($picture['current']['id'], null, 'image')) { array_push($infos, l10n('Successfully unsubscribed your email address from receiving notifications.')); } } // 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($template, &$smarty) { global $user, $picture; // if registered user we check if already subscribed $subscribed = false; if (!is_a_guest()) { $query = ' SELECT id FROM '.SUBSCRIBE_TO_TABLE.' WHERE email = "'.$user['email'].'" AND image_id = '.$picture['current']['id'].' AND validated = "true" ;'; if (pwg_db_num_rows(pwg_query($query))) { $subscribed = true; } } ## subscribe at any moment ## $search[1] = '{if isset($comment_add)}'; $replace[1] = $search[1].'
'; ## subscribe while add a comment ## $search[0] = ''; $replace[0] = null; if (!$subscribed) { $replace[0].= ' '; } if (is_a_guest()) { $replace[0].= ' {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}'; } $replace[0].= $search[0]; return str_replace($search, $replace, $template); } /** * add field and on album page */ function stc_on_album() { global $page, $template, $pwg_loaded_plugins; $infos = $errors = array(); if ( script_basename() != 'index' or !isset($page['section']) or !isset($pwg_loaded_plugins['Comments_on_Albums']) or $page['section'] != 'categories' or !isset($page['category']) ) { return; } if (isset($_POST['stc_check_stdl'])) { $return = subscribe_to_comments($page['category']['id'], @$_POST['stc_mail_stdl'], 'category'); if ($return === 'confirm_mail') { array_push($infos, l10n('Please check your email inbox to confirm your subscription.')); } else if ($return === true) { array_push($infos, l10n('You have been added to the list of subscribers for this album.')); } else { array_push($errors, l10n('Invalid email adress, your are not subscribed to comments.')); } } else if (isset($_GET['stc_unsubscribe'])) { if (un_subscribe_to_comments($page['category']['id'], null, 'category')) { array_push($infos, l10n('Successfully unsubscribed your email address from receiving notifications.')); } } // 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($template, &$smarty) { global $user, $page; // if registered user we check if already subscribed $subscribed = false; if (!is_a_guest()) { $query = ' SELECT id FROM '.SUBSCRIBE_TO_TABLE.' WHERE email = "'.$user['email'].'" AND category_id = '.$page['category']['id'].' AND validated = "true" ;'; if (pwg_db_num_rows(pwg_query($query))) { $subscribed = true; } } ## subscribe at any moment ## $search[1] = '{if isset($comment_add)}'; $replace[1] = $search[1].' '; ## subscribe while add a comment ## $search[0] = ''; $replace[0] = null; if (!$subscribed) { $replace[0].= ' '; } if (is_a_guest()) { $replace[0].= ' {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}'; } $replace[0].= $search[0]; return str_replace($search, $replace, $template); } /** * add link to management page for registered users */ function stc_profile_link() { global $template; $template->set_prefilter('profile_content', 'stc_profile_link_prefilter'); } function stc_profile_link_prefilter($content, &$smarty) { global $user; $search = '';
$replace = '{\'Manage my subscriptions to comments\'|@translate}
';
return str_replace($search, $search.$replace, $content);
}
?>