b2evolution PHP Cross Reference Blogging Systems

Source: /htsrv/anon_unsubscribe.php - 121 lines - 4721 bytes - Text - Print

Description: This is the handler for ANONYMOUS (not logged in) users unsubscribe calls. This file is part of the evoCore framework - {@link http://evocore.net/} See also {@link http://sourceforge.net/projects/evocms/}.

   1  <?php
   2  /**

   3   * This is the handler for ANONYMOUS (not logged in) users unsubscribe calls.

   4   *

   5   * This file is part of the evoCore framework - {@link http://evocore.net/}

   6   * See also {@link http://sourceforge.net/projects/evocms/}.

   7   *

   8   * @copyright (c)2003-2014 by Francois Planque - {@link http://fplanque.com/}

   9   *

  10   * {@internal License choice

  11   * - If you have received this file as part of a package, please find the license.txt file in

  12   *   the same folder or the closest folder above for complete license terms.

  13   * - If you have received this file individually (e-g: from http://evocms.cvs.sourceforge.net/)

  14   *   then you must choose one of the following licenses before using the file:

  15   *   - GNU General Public License 2 (GPL) - http://www.opensource.org/licenses/gpl-license.php

  16   *   - Mozilla Public License 1.1 (MPL) - http://www.opensource.org/licenses/mozilla1.1.php

  17   * }}

  18   *

  19   * {@internal Open Source relicensing agreement:

  20   * }}

  21   *

  22   * @package evocore

  23   *

  24   * @version $Id: anon_async.php 1121 2012-03-29 09:59:02Z yura $

  25   */
  26  
  27  /**

  28   * Do the MAIN initializations:

  29   */
  30  require_once dirname(__FILE__).'/../conf/_config.php';
  31  require_once $inc_path.'_main.inc.php';
  32  
  33  global $Session;
  34  
  35  header( 'Content-Type: text/html; charset='.$io_charset );
  36  
  37  // init anonymous user request params

  38  $type = param( 'type', 'string', true );
  39  $req_ID = param( 'req_ID', 'string', '' );
  40  $anon_email = param( 'anon_email', 'string', '' );
  41  
  42  switch( $type )
  43  {
  44      case 'comment':
  45          if( !is_email( $anon_email ) )
  46          {
  47              $Messages->add( 'Your email address is not correct. Probably the unsubscribe link was modified.' );
  48              $Messages->display();
  49              exit(0);
  50          }
  51  
  52          if( empty( $req_ID ) )
  53          { // Clicked to unsubscribe link on email, but unsubscribe is not confirmed yet
  54              $comment_id = param( 'c', 'integer', 0 );
  55              $CommentCache = & get_CommentCache();
  56              $Comment = $CommentCache->get_by_ID( $comment_id, false );
  57              if( empty( $Comment ) || ( $anon_email != $Comment->get_author_email() ) || ( ! $Comment->get( 'allow_msgform' ) ) )
  58              { // invalid request
  59                  $Messages->add( 'Invalid unsubscribe request, or you have already unsubscribed.' );
  60                  $Messages->display();
  61                  exit(0);
  62              }
  63  
  64              $req_ID = generate_random_key(32);
  65  
  66              $message = sprintf( T_("We have received a request that you do not want to receive emails through\na message form on your comments anymore.\n\nTo confirm that this request is from you, please click on the following link:") )
  67                  ."\n\n"
  68                  .$samedomain_htsrv_url.'anon_unsubscribe.php?type=comment&anon_email='.$anon_email.'&req_ID='.$req_ID
  69                  ."\n\n"
  70                  .T_('Please note:')
  71                  .' '.T_('For security reasons the link is only valid for your current session (by means of your session cookie).')
  72                  ."\n\n"
  73                  .T_('If it was not you that requested this, simply ignore this mail.');
  74  
  75              if( send_mail( $anon_email, NULL, T_('Confirm opt-out for emails through message form'), $message ) )
  76              {
  77                  $Messages->add( T_('An email has been sent to you, with a link to confirm your request not to receive emails through the comments you have made on this blog.'), 'success' );
  78                  $Session->set( 'core.msgform.optout_cmt_email', $anon_email );
  79                  $Session->set( 'core.msgform.optout_cmt_reqID', $req_ID );
  80              }
  81              elseif( $demo_mode )
  82              { // Debug mode restriction: sending email is disabled
  83                  $Messages->add( 'Sorry, could not send email. Sending email in demo mode is disabled.', 'error' );
  84              }
  85              else
  86              {
  87                  $Messages->add( T_('Sorry, could not send email.')
  88                              .'<br />'.T_('Possible reason: the PHP mail() function may have been disabled on the server.'), 'error' );
  89              }
  90  
  91              $Messages->display();
  92              exit(0);
  93          }
  94  
  95          // clicked on link from e-mail

  96          if( ( $req_ID == $Session->get( 'core.msgform.optout_cmt_reqID' ) ) && ( $anon_email == $Session->get( 'core.msgform.optout_cmt_email' ) ) )
  97          { // Update anonymous user comments to not allow msgform
  98              $DB->query( '
  99                  UPDATE T_comments
 100                     SET comment_allow_msgform = 0
 101                   WHERE comment_author_email = '.$DB->quote( $anon_email ) );
 102  
 103              $Messages->add( T_('All your comments have been marked not to allow emailing you through a message form.'), 'success' );
 104  
 105              $Session->delete('core.msgform.optout_cmt_email');
 106              $Session->delete('core.msgform.optout_cmt_reqID');
 107          }
 108          else
 109          {
 110              $Messages->add( T_('The request not to receive emails through a message form for your comments failed.'), 'error' );
 111          }
 112  
 113          $Messages->display();
 114          exit(0);
 115          // will have exited

 116      default:
 117          debug_die( 'Invalid unsubscribe request from anonymous user!' );
 118          break; // will have exited

 119  }
 120  // will have exited in all circumstances

 121  ?>

title

Description

title

Description

title

Description

title

title

Body