[6436] | 1 | <?php |
---|
| 2 | /* |
---|
[6439] | 3 | Plugin Name: NBM Subscriber |
---|
[6825] | 4 | Version: 1.0.2 |
---|
[6439] | 5 | Description: Permet aux visiteurs inscrits de gérer eux-même leur abonnement à la notification par mail (NBM) - Allows registered visitors to manage their own subscription to the notification by mail (NBM) |
---|
[6440] | 6 | Plugin URI: http://fr.piwigo.org/ext/extension_view.php?eid=397 |
---|
[6436] | 7 | Author: Eric |
---|
| 8 | Author URI: http://www.infernoweb.net |
---|
| 9 | */ |
---|
| 10 | |
---|
| 11 | if (!defined('PHPWG_ROOT_PATH')) die('Hacking attempt!'); |
---|
| 12 | if (!defined('NBMS_DIR')) define('NBMS_DIR' , basename(dirname(__FILE__))); |
---|
| 13 | if (!defined('NBMS_PATH')) define('NBMS_PATH' , PHPWG_PLUGINS_PATH.basename(dirname(__FILE__)).'/'); |
---|
| 14 | |
---|
| 15 | include_once (NBMS_PATH.'include/functions.inc.php'); |
---|
| 16 | |
---|
| 17 | load_language('plugin.lang', NBMS_PATH); |
---|
| 18 | |
---|
| 19 | |
---|
| 20 | /* Plugin admin */ |
---|
| 21 | add_event_handler('get_admin_plugin_menu_links', 'NBMS_admin_menu'); |
---|
| 22 | |
---|
| 23 | function NBMS_admin_menu($menu) |
---|
| 24 | { |
---|
| 25 | // +-----------------------------------------------------------------------+ |
---|
| 26 | // | Getting plugin name | |
---|
| 27 | // +-----------------------------------------------------------------------+ |
---|
| 28 | $plugin = NBMSInfos(NBMS_PATH); |
---|
| 29 | $name = $plugin['name']; |
---|
| 30 | |
---|
| 31 | array_push($menu, |
---|
| 32 | array( |
---|
| 33 | 'NAME' => $name, |
---|
| 34 | 'URL' => get_admin_plugin_menu_link(NBMS_PATH.'/admin/NBMS_admin.php') |
---|
| 35 | ) |
---|
| 36 | ); |
---|
| 37 | |
---|
| 38 | return $menu; |
---|
| 39 | } |
---|
| 40 | |
---|
| 41 | |
---|
[6439] | 42 | /* Saving from profile with added data */ |
---|
[6436] | 43 | add_event_handler('save_profile_from_post', 'NBMS_Save_Profile'); |
---|
| 44 | |
---|
| 45 | function NBMS_Save_Profile() |
---|
| 46 | { |
---|
[6439] | 47 | global $conf, $user; |
---|
[6436] | 48 | |
---|
[6825] | 49 | include_once(PHPWG_ROOT_PATH.'admin/include/functions_notification_by_mail.inc.php'); |
---|
| 50 | |
---|
| 51 | $query = ' |
---|
| 52 | SELECT * |
---|
| 53 | FROM '.USER_MAIL_NOTIFICATION_TABLE.' |
---|
| 54 | WHERE user_id = \''.$user['id'].'\' |
---|
| 55 | '; |
---|
| 56 | |
---|
| 57 | $count = pwg_db_num_rows(pwg_query($query)); |
---|
| 58 | |
---|
| 59 | if ($count == 0) |
---|
[6439] | 60 | { |
---|
[6825] | 61 | $inserts = array(); |
---|
| 62 | $check_key_list = array(); |
---|
| 63 | |
---|
| 64 | // Calculate key |
---|
| 65 | $nbm_user['check_key'] = find_available_check_key(); |
---|
| 66 | |
---|
| 67 | // Save key |
---|
| 68 | array_push($check_key_list, $nbm_user['check_key']); |
---|
| 69 | |
---|
| 70 | // Insert new nbm_users |
---|
| 71 | array_push |
---|
| 72 | ( |
---|
| 73 | $inserts, |
---|
| 74 | array |
---|
| 75 | ( |
---|
| 76 | 'user_id' => $user['id'], |
---|
| 77 | 'check_key' => $nbm_user['check_key'], |
---|
| 78 | 'enabled' => 'false' // By default if false, set to true with specific functions |
---|
| 79 | ) |
---|
| 80 | ); |
---|
| 81 | |
---|
| 82 | mass_inserts(USER_MAIL_NOTIFICATION_TABLE, array('user_id', 'check_key', 'enabled'), $inserts); |
---|
| 83 | } |
---|
| 84 | elseif ($count != 0 and !empty($_POST['NBM_Subscription']) && in_array($_POST['NBM_Subscription'], array('true', 'false'))) |
---|
| 85 | { |
---|
[6439] | 86 | $query = ' |
---|
[6436] | 87 | UPDATE '.USER_MAIL_NOTIFICATION_TABLE.' |
---|
| 88 | SET enabled = \''.$_POST['NBM_Subscription'].'\' |
---|
| 89 | WHERE user_id = \''.$user['id'].'\';'; |
---|
| 90 | |
---|
[6439] | 91 | pwg_query($query); |
---|
[6436] | 92 | } |
---|
| 93 | } |
---|
| 94 | |
---|
[6439] | 95 | /* Adding NBMS in profile page */ |
---|
[6436] | 96 | add_event_handler('load_profile_in_template', 'NBMS_Load_Profile'); |
---|
| 97 | |
---|
| 98 | function NBMS_Load_Profile() |
---|
| 99 | { |
---|
| 100 | global $conf, $user, $template, $lang; |
---|
| 101 | |
---|
| 102 | $query = ' |
---|
| 103 | SELECT enabled |
---|
| 104 | FROM '.USER_MAIL_NOTIFICATION_TABLE.' |
---|
| 105 | WHERE user_id = \''.$user['id'].'\' |
---|
| 106 | ;'; |
---|
| 107 | |
---|
| 108 | $data = pwg_db_fetch_assoc(pwg_query($query)); |
---|
| 109 | |
---|
| 110 | $values = $data['enabled']; |
---|
| 111 | |
---|
| 112 | $template->assign('radio_options', |
---|
| 113 | array( |
---|
| 114 | 'true' => l10n('Yes'), |
---|
| 115 | 'false'=> l10n('No'))); |
---|
| 116 | |
---|
| 117 | $template->assign( |
---|
| 118 | array( |
---|
| 119 | 'NBMS'=>$values |
---|
| 120 | )); |
---|
| 121 | |
---|
| 122 | $template->set_prefilter('profile_content', 'NBMS_prefilter'); |
---|
| 123 | } |
---|
| 124 | |
---|
[6439] | 125 | /* Original template modification */ |
---|
[6436] | 126 | function NBMS_prefilter($content, &$smarty) |
---|
| 127 | { |
---|
[6750] | 128 | global $template, $lang; |
---|
[6436] | 129 | |
---|
| 130 | load_language('plugin.lang', NBMS_PATH); |
---|
| 131 | |
---|
| 132 | $search = '<p class="bottomButtons">'; |
---|
| 133 | |
---|
| 134 | $addon = '{if $ALLOW_USER_CUSTOMIZATION} |
---|
| 135 | <fieldset> |
---|
[6439] | 136 | <legend>{\'NBMS_Section\'|@translate}</legend> |
---|
[6436] | 137 | <ul> |
---|
| 138 | <li> |
---|
[6439] | 139 | <span class="property">{\'NBMS_Text\'|@translate}</span> |
---|
[6436] | 140 | {html_radios name=\'NBM_Subscription\' options=$radio_options selected=$NBMS} |
---|
| 141 | </li> |
---|
| 142 | </ul> |
---|
| 143 | </fieldset> |
---|
| 144 | {/if}'; |
---|
| 145 | |
---|
| 146 | $replacement = $addon.$search; |
---|
| 147 | |
---|
[6750] | 148 | return str_replace($search, $replacement, $content); |
---|
[6436] | 149 | } |
---|
| 150 | ?> |
---|