PluginProbe
Redirection / 2.3.13
Redirection v2.3.13
5.10.0 5.9.0 5.8.1 5.8.0 3.7.2 3.7.3 4.0 4.0.1 4.1 4.1.1 4.2 4.2.1 4.2.2 4.2.3 4.3 4.3.1 4.3.2 4.3.3 4.4 4.4.1 4.4.2 4.5 4.5.1 4.6.2 4.7.1 All 130 releases
redirection / matches / referrer.php

referrer.php in Redirection 2.3.13, at matches/referrer.php

127 lines 4.6 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
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 Referrer_Match extends Red_Match {
24 var $referrer;
25 var $regex;
26
27 function name() {
28 return __( 'URL and referrer', 'redirection' );
29 }
30
31 function show() {
32 $codes = array(
33 301 => get_status_header_desc( 301 ),
34 302 => get_status_header_desc( 302 ),
35 307 => get_status_header_desc( 307 )
36 );
37
38 ?>
39 <tr>
40 <th width="100"><?php _e( 'Referrer', 'redirection' ); ?>:</th>
41 <td valign="top">
42 <input style="width: 85%" type="text" name="referrer" value="<?php echo esc_attr( $this->referrer ); ?>"/>
43 <label><?php _e( 'Regex', 'redirection' ); ?>: <input type="checkbox" name="regex" <?php if ( $this->regex == true ) echo ' checked="checked"' ?>/></label>
44 </td>
45 </tr>
46 <tr>
47 <th><?php _e( 'HTTP Code', 'redirection' ); ?>:</th>
48 <td>
49 <select name="action_code">
50 <?php foreach ( $codes AS $key => $code ) : ?>
51 <option value="<?php echo $key ?>"<?php if ( $key == $this->action_code ) echo ' selected="selected"' ?>><?php printf( '%s - %s', $key, $code ) ?></option>
52 <?php endforeach?>
53 </select>
54 </td>
55 </tr>
56 <tr>
57 <th><?php _e( 'HTTP Code', 'redirection' ); ?>:</th>
58 <td>
59 <p style="padding: 0.5em"><?php _e( 'The visitor will be redirected from the source URL if the referrer matches. You can specify a <em>matched</em> target URL as the address to send visitors if they do match, and <em>not matched</em> if they don\'t match. Leaving a URL blank means that the visitor is not redirected.', 'redirection' ); ?></p>
60 </td>
61 </tr>
62 <tr>
63 <th width="100" valign="top">
64 <?php if ( strlen( $this->url_from ) > 0 ) : ?>
65 <a target="_blank" href="<?php echo esc_url( $this->url_from ) ?>"><?php _e( 'Matched', 'redirection' ); ?>:</a>
66 <?php else : ?>
67 <?php _e( 'Matched', 'redirection' ); ?>:
68 <?php endif; ?>
69 </th>
70 <td valign="top"><input style="width: 95%" type="text" name="url_from" value="<?php echo esc_attr( $this->url_from ); ?>" id="new"/></td>
71 </tr>
72 <tr>
73 <th width="100" valign="top">
74 <?php if ( strlen( $this->url_notfrom ) > 0 ) : ?>
75 <a target="_blank" href="<?php echo $this->url_notfrom ?>"><?php _e( 'Not matched', 'redirection' ); ?>:</a>
76 <?php else : ?>
77 <?php _e( 'Not matched', 'redirection' ); ?>:
78 <?php endif; ?>
79 </th>
80 <td valign="top">
81 <input style="width: 95%" type="text" name="url_notfrom" value="<?php echo esc_attr( $this->url_notfrom ); ?>" id="new"/><br/>
82 </td>
83 </tr>
84 <?php
85 }
86
87 function save( $details ) {
88 if ( isset( $details['target'] ) )
89 $details['url_from'] = $details['target'];
90
91 return array(
92 'url_from' => $details['url_from'],
93 'url_notfrom' => isset( $details['url_notfrom'] ) ? $details['url_notfrom'] : false,
94 'regex' => isset( $details['regex'] ) ? true : false,
95 'referrer' => isset( $details['referrer'] ) ? $details['referrer'] : false
96 );
97 }
98
99 function initialize( $url ) {
100 $this->url = array( $url, '' );
101 }
102
103 function wants_it() {
104 // Match referrer
105 return true;
106 }
107
108 function get_target( $url, $matched_url, $regex ) {
109 $target = false;
110
111 // Check if referrer matches
112 if ( ( $this->regex == false && $_SERVER['HTTP_REFERER'] == $this->referrer ) ||( $this->regex == true && preg_match( '@'.str_replace( '@', '\\@', $this->referrer ).'@', $_SERVER['HTTP_REFERER'], $matches ) ) ) {
113 $target = $this->url_from;
114
115 if ( $regex )
116 $target = preg_replace( '@'.str_replace( '@', '\\@', $matched_url ).'@', $target, $url );
117 }
118 elseif ( $this->url_notfrom != '' )
119 $target = $this->url_notfrom;
120 return $target;
121 }
122
123 function match_name() {
124 return sprintf( 'referrer - <code>%s</code>', $this->referrer );
125 }
126 }
127