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 / user_agent.php

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

133 lines 5.1 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 Agent_Match extends Red_Match {
24 var $user_agent;
25
26 function name() {
27 return __( 'URL and user agent', 'redirection' );
28 }
29
30 function show() {
31 $defined = array(
32 'feedburner|feedvalidator' => __( 'FeedBurner', 'redirection' ),
33 'MSIE' => __( 'Internet Explorer', 'redirection' ),
34 'Firefox' => __( 'FireFox', 'redirection' ),
35 'Opera' => __( 'Opera', 'redirection' ),
36 'Safari' => __( 'Safari', 'redirection' ),
37 'iPhone' => __( 'iPhone', 'redirection' ),
38 'iPad' => __( 'iPad', 'redirection' ),
39 'Android' => __( 'Android', 'redirection' ),
40 'Wii' => __( 'Nintendo Wii', 'redirection' ),
41 );
42
43 ?>
44 <tr>
45 <th width="100"><?php _e( 'User Agent', 'redirection' ); ?>:</th>
46 <td>
47 <input id="user_agent_<?php echo $this->id ?>" style="width: 65%" type="text" name="user_agent" value="<?php echo esc_attr( $this->user_agent ); ?>"/>
48 <select style="width: 30%" class="change-user-agent">
49 <?php foreach ( $defined AS $key => $value ) : ?>
50 <option value="<?php echo $key ?>"<?php if ( $key == $this->user_agent ) echo ' selected="selected"' ?>><?php echo esc_html( $value ) ?></option>
51 <?php endforeach; ?>
52 </select>
53 </td>
54 </tr>
55 <?php if ( $this->action->can_change_code() ) : ?>
56 <tr>
57 <th><?php _e( 'HTTP Code', 'redirection' ); ?>:</th>
58 <td>
59 <select name="action_code">
60 <?php $this->action->display_actions(); ?>
61 </select>
62 </td>
63 </tr>
64 <?php endif; ?>
65
66 <?php if ( $this->action->can_perform_action() ) : ?>
67 <tr>
68 <th></th>
69 <td>
70 <p style="padding: 0.5em"><?php _e( 'The visitor will be redirected from the source URL if the user agent 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. <strong>All matches are performed as regular expressions</strong>.
71 ', 'redirection' ); ?></p>
72 </td>
73 </tr>
74 <tr>
75 <th width="100" valign="top">
76 <?php if ( strlen( $this->url_from ) > 0 ) : ?>
77 <a target="_blank" href="<?php echo esc_url( $this->url_from ) ?>"><?php _e( 'Matched', 'redirection' ); ?>:</a>
78 <?php else : ?>
79 <?php _e( 'Matched', 'redirection' ); ?>:
80 <?php endif; ?>
81 </th>
82 <td valign="top"><input style="width: 95%" type="text" name="url_from" value="<?php echo esc_attr( $this->url_from ); ?>" id="new"/></td>
83 </tr>
84 <tr>
85 <th width="100" valign="top">
86 <?php if ( strlen( $this->url_notfrom ) > 0 ) : ?>
87 <a target="_blank" href="<?php echo esc_url( $this->url_notfrom ) ?>"><?php _e( 'Not matched', 'redirection' ); ?>:</a>
88 <?php else : ?>
89 <?php _e( 'Not matched', 'redirection' ); ?>:
90 <?php endif; ?>
91 </th>
92 <td valign="top">
93 <input style="width: 95%" type="text" name="url_notfrom" value="<?php echo esc_attr( $this->url_notfrom ); ?>" id="new"/><br/>
94 </td>
95 </tr>
96 <?php endif; ?>
97 <?php
98 }
99
100 function save( $details ) {
101 if ( isset( $details['target'] ) )
102 $details['url_from'] = $details['target'];
103
104 return array(
105 'url_from' => isset( $details['url_from'] ) ? $details['url_from'] : false,
106 'url_notfrom' => isset( $details['url_notfrom'] ) ? $details['url_notfrom'] : false,
107 'user_agent' => isset( $details['user_agent'] ) ? $details['user_agent'] : false
108 );
109 }
110
111 function initialize( $url ) {
112 $this->url = array( $url, '' );
113 }
114
115 function wants_it() {
116 // Match referrer
117 return true;
118 }
119
120 function get_target( $url, $matched_url, $regex ) {
121 // Check if referrer matches
122 if ( preg_match( '@'.str_replace( '@', '\\@', $this->user_agent ).'@i', $_SERVER['HTTP_USER_AGENT'], $matches ) > 0 )
123 return preg_replace( '@'.str_replace( '@', '\\@', $matched_url ).'@', $this->url_from, $url );
124 elseif ( $this->url_notfrom != '' )
125 return $this->url_notfrom;
126 return false;
127 }
128
129 function match_name() {
130 return sprintf( 'user agent - %s', $this->user_agent );
131 }
132 }
133