[6436] | 1 | <?php |
---|
| 2 | /* |
---|
[6439] | 3 | Plugin Name: NBM Subscriber |
---|
[18488] | 4 | Version: auto |
---|
[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) |
---|
[9535] | 6 | Plugin URI: http://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_PATH')) define('NBMS_PATH' , PHPWG_PLUGINS_PATH.basename(dirname(__FILE__)).'/'); |
---|
| 13 | |
---|
| 14 | include_once (NBMS_PATH.'include/functions.inc.php'); |
---|
| 15 | |
---|
| 16 | load_language('plugin.lang', NBMS_PATH); |
---|
| 17 | |
---|
| 18 | |
---|
| 19 | /* Plugin admin */ |
---|
| 20 | add_event_handler('get_admin_plugin_menu_links', 'NBMS_admin_menu'); |
---|
| 21 | |
---|
| 22 | function NBMS_admin_menu($menu) |
---|
| 23 | { |
---|
| 24 | // +-----------------------------------------------------------------------+ |
---|
| 25 | // | Getting plugin name | |
---|
| 26 | // +-----------------------------------------------------------------------+ |
---|
| 27 | $plugin = NBMSInfos(NBMS_PATH); |
---|
| 28 | $name = $plugin['name']; |
---|
| 29 | |
---|
| 30 | array_push($menu, |
---|
| 31 | array( |
---|
| 32 | 'NAME' => $name, |
---|
[9888] | 33 | 'URL' => get_root_url().'admin.php?page=plugin-'.basename(NBMS_PATH) |
---|
[6436] | 34 | ) |
---|
| 35 | ); |
---|
| 36 | |
---|
| 37 | return $menu; |
---|
| 38 | } |
---|
| 39 | |
---|
| 40 | |
---|
[6439] | 41 | /* Saving from profile with added data */ |
---|
[6436] | 42 | add_event_handler('save_profile_from_post', 'NBMS_Save_Profile'); |
---|
| 43 | |
---|
| 44 | function NBMS_Save_Profile() |
---|
| 45 | { |
---|
[6439] | 46 | global $conf, $user; |
---|
[6436] | 47 | |
---|
[6825] | 48 | include_once(PHPWG_ROOT_PATH.'admin/include/functions_notification_by_mail.inc.php'); |
---|
| 49 | |
---|
| 50 | $query = ' |
---|
| 51 | SELECT * |
---|
| 52 | FROM '.USER_MAIL_NOTIFICATION_TABLE.' |
---|
| 53 | WHERE user_id = \''.$user['id'].'\' |
---|
| 54 | '; |
---|
[23028] | 55 | |
---|
[6825] | 56 | $count = pwg_db_num_rows(pwg_query($query)); |
---|
[23028] | 57 | |
---|
[6825] | 58 | if ($count == 0) |
---|
[6439] | 59 | { |
---|
[6825] | 60 | $inserts = array(); |
---|
| 61 | $check_key_list = array(); |
---|
[23028] | 62 | |
---|
[6825] | 63 | // Calculate key |
---|
| 64 | $nbm_user['check_key'] = find_available_check_key(); |
---|
| 65 | |
---|
| 66 | // Save key |
---|
| 67 | array_push($check_key_list, $nbm_user['check_key']); |
---|
[23028] | 68 | |
---|
[6825] | 69 | // Insert new nbm_users |
---|
| 70 | array_push |
---|
| 71 | ( |
---|
| 72 | $inserts, |
---|
| 73 | array |
---|
| 74 | ( |
---|
| 75 | 'user_id' => $user['id'], |
---|
| 76 | 'check_key' => $nbm_user['check_key'], |
---|
[23028] | 77 | 'enabled' => $_POST['NBM_Subscription'] |
---|
[6825] | 78 | ) |
---|
| 79 | ); |
---|
| 80 | |
---|
[23028] | 81 | mass_inserts(USER_MAIL_NOTIFICATION_TABLE, array('user_id', 'check_key', 'enabled'), $inserts); |
---|
[6825] | 82 | } |
---|
| 83 | elseif ($count != 0 and !empty($_POST['NBM_Subscription']) && in_array($_POST['NBM_Subscription'], array('true', 'false'))) |
---|
| 84 | { |
---|
[6439] | 85 | $query = ' |
---|
[6436] | 86 | UPDATE '.USER_MAIL_NOTIFICATION_TABLE.' |
---|
| 87 | SET enabled = \''.$_POST['NBM_Subscription'].'\' |
---|
| 88 | WHERE user_id = \''.$user['id'].'\';'; |
---|
| 89 | |
---|
[6439] | 90 | pwg_query($query); |
---|
[6436] | 91 | } |
---|
| 92 | } |
---|
| 93 | |
---|
[6439] | 94 | /* Adding NBMS in profile page */ |
---|
[6436] | 95 | add_event_handler('load_profile_in_template', 'NBMS_Load_Profile'); |
---|
| 96 | |
---|
| 97 | function NBMS_Load_Profile() |
---|
| 98 | { |
---|
| 99 | global $conf, $user, $template, $lang; |
---|
| 100 | |
---|
| 101 | $query = ' |
---|
| 102 | SELECT enabled |
---|
| 103 | FROM '.USER_MAIL_NOTIFICATION_TABLE.' |
---|
| 104 | WHERE user_id = \''.$user['id'].'\' |
---|
| 105 | ;'; |
---|
| 106 | |
---|
| 107 | $data = pwg_db_fetch_assoc(pwg_query($query)); |
---|
| 108 | |
---|
| 109 | $values = $data['enabled']; |
---|
[23028] | 110 | |
---|
| 111 | if (is_null($values)) |
---|
| 112 | $values = 'false'; |
---|
[6436] | 113 | |
---|
| 114 | $template->assign('radio_options', |
---|
| 115 | array( |
---|
| 116 | 'true' => l10n('Yes'), |
---|
[23028] | 117 | 'false'=> l10n('No') |
---|
| 118 | ) |
---|
| 119 | ); |
---|
[6436] | 120 | |
---|
| 121 | $template->assign( |
---|
| 122 | array( |
---|
| 123 | 'NBMS'=>$values |
---|
[23028] | 124 | ) |
---|
| 125 | ); |
---|
[6436] | 126 | |
---|
| 127 | $template->set_prefilter('profile_content', 'NBMS_prefilter'); |
---|
| 128 | } |
---|
| 129 | |
---|
[6439] | 130 | /* Original template modification */ |
---|
[6436] | 131 | function NBMS_prefilter($content, &$smarty) |
---|
| 132 | { |
---|
[6750] | 133 | global $template, $lang; |
---|
[6436] | 134 | |
---|
| 135 | load_language('plugin.lang', NBMS_PATH); |
---|
| 136 | |
---|
| 137 | $search = '<p class="bottomButtons">'; |
---|
| 138 | |
---|
[20822] | 139 | $addon = ' |
---|
[6436] | 140 | <fieldset> |
---|
[6439] | 141 | <legend>{\'NBMS_Section\'|@translate}</legend> |
---|
[6436] | 142 | <ul> |
---|
| 143 | <li> |
---|
[6439] | 144 | <span class="property">{\'NBMS_Text\'|@translate}</span> |
---|
[6436] | 145 | {html_radios name=\'NBM_Subscription\' options=$radio_options selected=$NBMS} |
---|
| 146 | </li> |
---|
| 147 | </ul> |
---|
| 148 | </fieldset> |
---|
[20822] | 149 | '; |
---|
[6436] | 150 | |
---|
| 151 | $replacement = $addon.$search; |
---|
| 152 | |
---|
[6750] | 153 | return str_replace($search, $replacement, $content); |
---|
[6436] | 154 | } |
---|
| 155 | ?> |
---|