2015-05-12 01:45:00 -07:00
< ? php
if ( ! defined ( 'e107_INIT' ))
{
require_once ( " class2.php " );
}
define ( 'e_IFRAME' , true );
require_once ( HEADERF );
2020-05-27 10:36:17 -07:00
class e_unsubscribe
2015-05-12 01:45:00 -07:00
{
function __construct ()
{
$mes = e107 :: getMessage ();
$frm = e107 :: getForm ();
2015-05-12 13:57:11 -07:00
$tp = e107 :: getParser ();
2015-05-12 01:45:00 -07:00
// $this->simulation();
$mailoutPlugins = e107 :: getConfig () -> get ( 'e_mailout_list' );
2015-05-12 13:57:11 -07:00
if ( empty ( $_GET [ 'id' ]))
2015-05-12 01:45:00 -07:00
{
2020-05-27 10:36:17 -07:00
$this -> invalidURL ();
2015-05-12 01:45:00 -07:00
return ;
}
$tmp = base64_decode ( $_GET [ 'id' ]);
2015-05-12 13:57:11 -07:00
2015-05-12 01:45:00 -07:00
parse_str ( $tmp , $data );
2015-05-12 13:57:11 -07:00
$data [ 'plugin' ] = $tp -> filter ( $data [ 'plugin' ], 'str' );
$data [ 'email' ] = $tp -> filter ( $data [ 'email' ], 'email' );
2015-05-12 01:45:00 -07:00
e107 :: getMessage () -> addDebug ( print_a ( $data , true ));
$plugin = vartrue ( $data [ 'plugin' ], false );
if ( empty ( $data ) || ! e107 :: isInstalled ( $plugin ) || ! in_array ( $plugin , $mailoutPlugins ))
{
$this -> invalidURL ();
return ;
}
2015-05-12 13:57:11 -07:00
$ml = e107 :: getAddon ( $plugin , 'e_mailout' );
if ( ! empty ( $data [ 'userclass' ])) // userclass unsubscribe.
{
$data [ 'userclass' ] = intval ( $data [ 'userclass' ]);
$listName = e107 :: getUserClass () -> getName ( $data [ 'userclass' ]);
}
else
{
$listName = $ml -> mailerName ;
}
2015-05-12 01:45:00 -07:00
if ( vartrue ( $_POST [ 'remove' ]) && ! empty ( $data ))
{
if ( $ml -> unsubscribe ( 'process' , $data ) != false )
{
2015-05-12 13:57:11 -07:00
$text = " <p><b> " . $data [ 'email' ] . " </b> has been removed from " . $listName . " .</p> " ;
2015-05-12 01:45:00 -07:00
$mes -> addSuccess ( $text );
}
else
{
2015-05-12 13:57:11 -07:00
$text = " <p>There was a problem when attempting to remove <b> " . $data [ 'email' ] . " </b> from " . $listName . " .</p> " ;
2015-05-12 01:45:00 -07:00
$mes -> addError ( $text );
}
echo " <div class='container'> " . $mes -> render () . " </div> " ;
return ;
}
2015-05-12 13:57:11 -07:00
2015-05-12 01:45:00 -07:00
if ( $ml -> unsubscribe ( 'check' , $data ) != false )
{
2015-05-12 13:57:11 -07:00
$text = " <p>We are very sorry for the inconvenience. <br />Please click the button below to remove <b> " . $data [ 'email' ] . " </b> from <i> " . $listName . " </i>.</p> " ;
2015-05-12 01:45:00 -07:00
$text .= $frm -> open ( 'unsub' , 'post' , e_REQUEST_URI );
$text .= $frm -> button ( 'remove' , 'Remove ' , 'submit' );
$text .= $frm -> close ();
$mes -> setTitle ( 'Unsubscribe' , E_MESSAGE_INFO ) -> addInfo ( $text );
echo " <div class='container'> " . $mes -> render () . " </div> " ;
return ;
}
else
{
$this -> invalidURL ();
return ;
}
}
function simulation ()
{
$row = array ();
$row [ 'datestamp' ] = time ();
$row [ 'email' ] = " test@test.com " ;
$row [ 'id' ] = 23 ;
$unsubscribe = array ( 'date' => $row [ 'datestamp' ], 'email' => $row [ 'email' ], 'id' => $row [ 'id' ], 'plugin' => 'user' );
$urlQuery = http_build_query ( $unsubscribe , null , '&' );
$_GET [ 'id' ] = base64_encode ( $urlQuery );
e107 :: getMessage () -> addDebug ( " urlQuery = " . $urlQuery );
//echo "urlQuery = ".$urlQuery."<br/>";
e107 :: getMessage () -> addDebug ( e_SELF . " ?id= " . $_GET [ 'id' ]);
}
function invalidURL ()
{
$mes = e107 :: getMessage ();
$mes -> addWarning ( " Invalid URL " );
echo " <div class='container'> " . $mes -> render () . " </div> " ;
return ;
}
}
2020-05-27 10:36:17 -07:00
new e_unsubscribe ;
2015-05-12 01:45:00 -07:00
require_once ( FOOTERF );
exit ;