b2evolution PHP Cross Reference Blogging Systems

Source: /htsrv/quick_unsubscribe.php - 149 lines - 4211 bytes - Text - Print

Description: Initialize everything:

   1  <?php
   2  /**
   3   * Initialize everything:
   4   */
   5  require_once dirname(__FILE__).'/../conf/_config.php';
   6  require_once $inc_path.'/_main.inc.php';
   7  
   8  global $UserSettings;
   9  
  10  param( 'type', 'string', true );
  11  param( 'user_ID', 'integer', true );
  12  param( 'key', 'string', true );
  13  param( 'coll_ID', 'integer', 0 );
  14  param( 'post_ID', 'integer', 0 );
  15  
  16  $UserCache = & get_UserCache();
  17  $edited_User = $UserCache->get_by_ID( $user_ID, false, false );
  18  
  19  // User not found
  20  if( empty( $edited_User ) )
  21  {
  22      echo T_( 'The user you are trying to unsubscribe does not seem to exist. You may already have deleted your account.' );
  23      exit;
  24  }
  25  
  26  // Security check
  27  if( $key != md5( $user_ID.$edited_User->get( 'unsubscribe_key' ) ) )
  28  {
  29      echo 'Invalid unsubscribe link!';
  30      exit;
  31  }
  32  
  33  switch( $type )
  34  {
  35      case 'coll_comment':
  36      case 'coll_post':
  37          // unsubscribe from blog
  38          if( $coll_ID == 0 )
  39          {
  40              echo 'Invalid unsubscribe link!';
  41              exit;
  42          }
  43  
  44          $subscription_name = ( ( $type == 'coll_comment' ) ? 'sub_comments' : 'sub_items' );
  45          $DB->query( 'UPDATE T_subscriptions SET '.$subscription_name.' = 0
  46                          WHERE sub_user_ID = '.$user_ID.' AND sub_coll_ID = '.$coll_ID );
  47          break;
  48  
  49      case 'post':
  50          // unsubscribe from a specific post
  51          if( $post_ID == 0 )
  52          {
  53              echo 'Invalid unsubscribe link!';
  54              exit;
  55          }
  56  
  57          $DB->query( 'DELETE FROM T_items__subscriptions
  58                          WHERE isub_user_ID = '.$user_ID.' AND isub_item_ID = '.$post_ID );
  59          break;
  60  
  61      case 'creator':
  62          // unsubscribe from the user own posts
  63          $UserSettings->set( 'notify_published_comments', '0', $edited_User->ID );
  64          $UserSettings->dbupdate();
  65          break;
  66  
  67      case 'cmt_moderation_reminder':
  68          // unsubscribe from comment moderation reminder notifications
  69          $UserSettings->set( 'send_cmt_moderation_reminder', '0', $edited_User->ID );
  70          $UserSettings->dbupdate();
  71          break;
  72  
  73      case 'comment_moderator':
  74      case 'moderator': // Note: This was not chaned to 'comment_moderator' to make sure old emails unsubscribe link are also work
  75          // unsubscribe from new comment may need moderation notifications
  76          $UserSettings->set( 'notify_comment_moderation', '0', $edited_User->ID );
  77          $UserSettings->dbupdate();
  78          break;
  79  
  80      case 'post_moderator':
  81          // unsubscribe from post moderation notifications
  82          $UserSettings->set( 'notify_post_moderation', '0', $edited_User->ID );
  83          $UserSettings->dbupdate();
  84          break;
  85  
  86      case 'unread_msg':
  87          // unsubscribe from unread messages reminder
  88          $UserSettings->set( 'notify_unread_messages', '0', $edited_User->ID );
  89          $UserSettings->dbupdate();
  90          break;
  91  
  92      case 'new_msg':
  93          // unsubscribe from new messages notification
  94          $UserSettings->set( 'notify_messages', '0', $edited_User->ID );
  95          $UserSettings->dbupdate();
  96          break;
  97  
  98      case 'account_activation':
  99          // unsubscribe from account activation reminder
 100          $UserSettings->set( 'send_activation_reminder', '0', $edited_User->ID );
 101          $UserSettings->dbupdate();
 102          break;
 103  
 104      case 'newsletter':
 105          // unsubscribe from newsletter
 106          $UserSettings->set( 'newsletter_news', '0', $edited_User->ID );
 107          $UserSettings->dbupdate();
 108          break;
 109  
 110      case 'user_registration':
 111          // unsubscribe from new user registration notifications
 112          $UserSettings->set( 'notify_new_user_registration', '0', $edited_User->ID );
 113          $UserSettings->dbupdate();
 114          break;
 115  
 116      case 'account_activated':
 117          // unsubscribe from account activated notifications
 118          $UserSettings->set( 'notify_activated_account', '0', $edited_User->ID );
 119          $UserSettings->dbupdate();
 120          break;
 121  
 122      case 'account_closed':
 123          // unsubscribe from account closed notifications
 124          $UserSettings->set( 'notify_closed_account', '0', $edited_User->ID );
 125          $UserSettings->dbupdate();
 126          break;
 127  
 128      case 'account_reported':
 129          // unsubscribe from account reported notifications
 130          $UserSettings->set( 'notify_reported_account', '0', $edited_User->ID );
 131          $UserSettings->dbupdate();
 132          break;
 133  
 134      case 'msgform':
 135          // turn off allow emails through b2evo message forms
 136          $UserSettings->set( 'enable_email', '0', $edited_User->ID );
 137          $UserSettings->dbupdate();
 138          break;
 139  
 140      case 'cronjob_error':
 141          // unsubscribe from cron job error notifications
 142          $UserSettings->set( 'notify_cronjob_error', '0', $edited_User->ID );
 143          $UserSettings->dbupdate();
 144          break;
 145  }
 146  
 147  echo( T_( 'You have successfully unsubscribed.' ) );
 148  exit;
 149  ?>

title

Description

title

Description

title

Description

title

title

Body