| 1 |
<?php |
| 2 |
/** |
| 3 |
* Redirection |
| 4 |
* |
| 5 |
* @package Redirection |
| 6 |
* @author John Godley |
| 7 |
* @copyright Copyright( C ) John Godley |
| 8 |
**/ |
| 9 |
|
| 10 |
/* |
| 11 |
============================================================================================================ |
| 12 |
This software is provided "as is" and any express or implied warranties, including, but not limited to, the |
| 13 |
implied warranties of merchantibility and fitness for a particular purpose are disclaimed. In no event shall |
| 14 |
the copyright owner or contributors be liable for any direct, indirect, incidental, special, exemplary, or |
| 15 |
consequential damages( including, but not limited to, procurement of substitute goods or services; loss of |
| 16 |
use, data, or profits; or business interruption ) however caused and on any theory of liability, whether in |
| 17 |
contract, strict liability, or tort( including negligence or otherwise ) arising in any way out of the use of |
| 18 |
this software, even if advised of the possibility of such damage. |
| 19 |
|
| 20 |
For full license details see license.txt |
| 21 |
============================================================================================================ */ |
| 22 |
|
| 23 |
class Login_Match extends Red_Match { |
| 24 |
var $user_agent = ''; |
| 25 |
|
| 26 |
function name() { |
| 27 |
return __( 'URL and login status', 'redirection' ); |
| 28 |
} |
| 29 |
|
| 30 |
function show() { |
| 31 |
?> |
| 32 |
<tr> |
| 33 |
<th></th> |
| 34 |
<td> |
| 35 |
<p> |
| 36 |
<?php _e( 'The target URL will be chosen from one of the following URLs, depending if the user is logged in or out. Leaving a URL blank means that the user is not redirected.', 'redirection' ); ?> |
| 37 |
</p> |
| 38 |
</td> |
| 39 |
</tr> |
| 40 |
<tr> |
| 41 |
<th width="100" valign="top"> |
| 42 |
<?php if ( strlen( $this->url_loggedin ) > 0 ) : ?> |
| 43 |
<a target="_blank" href="<?php echo esc_url( $this->url_loggedin ) ?>"><?php _e( 'Logged In', 'redirection' ); ?>:</a> |
| 44 |
<?php else : ?> |
| 45 |
<?php _e( 'Logged In', 'redirection' ); ?>: |
| 46 |
<?php endif; ?> |
| 47 |
</th> |
| 48 |
<td valign="top"> |
| 49 |
<input style="width: 95%" type="text" name="url_loggedin" value="<?php echo esc_attr( $this->url_loggedin ); ?>"/> |
| 50 |
</td> |
| 51 |
</tr> |
| 52 |
<tr> |
| 53 |
<th width="100" valign="top"> |
| 54 |
<?php if ( strlen( $this->url_loggedout ) > 0 ) : ?> |
| 55 |
<a target="_blank" href="<?php echo esc_url( $this->url_loggedout ) ?>"><?php _e( 'Logged Out', 'redirection' ); ?>:</a> |
| 56 |
<?php else : ?> |
| 57 |
<?php _e( 'Logged Out', 'redirection' ); ?>: |
| 58 |
<?php endif; ?> |
| 59 |
</th> |
| 60 |
<td valign="top"> |
| 61 |
<input style="width: 95%" type="text" name="url_loggedout" value="<?php echo esc_attr( $this->url_loggedout ); ?>"/><br/> |
| 62 |
</td> |
| 63 |
</tr> |
| 64 |
<?php |
| 65 |
} |
| 66 |
|
| 67 |
function save( $details ) { |
| 68 |
if ( isset( $details['target'] ) ) |
| 69 |
$details['target'] = $details; |
| 70 |
|
| 71 |
return array( |
| 72 |
'url_loggedin' => isset( $details['url_loggedin'] ) ? $details['url_loggedin'] : false, |
| 73 |
'url_loggedout' => isset( $details['url_loggedout'] ) ? $details['url_loggedout'] : false, |
| 74 |
); |
| 75 |
} |
| 76 |
|
| 77 |
function initialize( $url ) { |
| 78 |
$this->url = array( $url, '' ); |
| 79 |
} |
| 80 |
|
| 81 |
function get_target( $url, $matched_url, $regex ) { |
| 82 |
if ( is_user_logged_in() === false ) |
| 83 |
$target = $this->url_loggedout; |
| 84 |
else |
| 85 |
$target = $this->url_loggedin; |
| 86 |
|
| 87 |
if ( $regex ) |
| 88 |
$target = preg_replace( '@'.str_replace( '@', '\\@', $matched_url ).'@', $target, $url ); |
| 89 |
return $target; |
| 90 |
} |
| 91 |
|
| 92 |
function wants_it() { |
| 93 |
if ( is_user_logged_in() && strlen( $this->url_loggedin ) > 0 ) |
| 94 |
return true; |
| 95 |
if ( !is_user_logged_in() && strlen( $this->url_loggedout ) > 0 ) |
| 96 |
return true; |
| 97 |
} |
| 98 |
|
| 99 |
function match_name() { |
| 100 |
return sprintf( 'login status', $this->user_agent ); |
| 101 |
} |
| 102 |
} |
| 103 |
|