function all()
 {
     $data = array();
     $avail = Red_Match::available();
     foreach ($avail as $name => $file) {
         $obj = Red_Match::create($name);
         $data[$name] = $obj->name();
     }
     return $data;
 }
Exemple #2
0
			<tr>
				<th align="right" width="100"><?php 
_e('Source URL', 'redirection');
?>
:</th>
				<td><input type="text" name="source" style="width: 95%" id="old"/></td>
			</tr>
			<tr>
				<th align="right"><?php 
_e('Match', 'redirection');
?>
:</th>
				<td>
					<select name="match">
						<?php 
echo $this->select(Red_Match::all());
?>
					</select>

					<strong><?php 
_e('Action', 'redirection');
?>
:</strong>
					<select name="red_action">
						<?php 
echo $this->select(Red_Item::actions(), 'url');
?>
					</select>

					<label><?php 
_e('Regular expression', 'redirection');
Exemple #3
0
 static function create(array $details)
 {
     global $wpdb;
     $details = array_map('trim', $details);
     $details = array_map('stripslashes', $details);
     // Auto generate URLs
     if (empty($details['source'])) {
         $details['source'] = self::auto_generate();
     }
     if (empty($details['target'])) {
         $details['target'] = self::auto_generate();
     }
     // Make sure we don't redirect to ourself
     if ($details['source'] == $details['target']) {
         return new WP_Error('redirect-add', __('Source and target URL must be different', 'redirection'));
     }
     $matcher = Red_Match::create($details['match']);
     $group_id = intval($details['group']);
     $group = Red_Group::get($group_id);
     if ($group_id <= 0 || !$group) {
         return new WP_Error('redirect-add', __('Invalid group when creating redirect', 'redirection'));
     }
     if (!$matcher) {
         return new WP_Error('redirect-add', __('Invalid source URL when creating redirect for given match type', 'redirection'));
     }
     $regex = isset($details['regex']) && $details['regex'] != false ? 1 : 0;
     $position = $wpdb->get_var($wpdb->prepare("SELECT COUNT(*) FROM {$wpdb->prefix}redirection_items WHERE group_id=%d", $group_id));
     $action = $details['red_action'];
     $action_code = 0;
     if ($action == 'url' || $action == 'random') {
         $action_code = 301;
     } elseif ($action == 'error') {
         $action_code = 404;
     }
     if (isset($details['action_code'])) {
         $action_code = intval($details['action_code']);
     }
     $data = array('url' => self::sanitize_url($details['source'], $regex), 'action_type' => $details['red_action'], 'regex' => $regex, 'position' => $position, 'match_type' => $details['match'], 'action_data' => $matcher->data($details), 'action_code' => $action_code, 'last_access' => '0000-00-00 00:00:00', 'group_id' => $group_id);
     $data = apply_filters('redirection_create_redirect', $data);
     $wpdb->delete($wpdb->prefix . 'redirection_items', array('url' => $data['action_data'], 'action_type' => $data['action_type'], 'action_data' => $data['url']));
     if ($wpdb->insert($wpdb->prefix . 'redirection_items', $data)) {
         Red_Module::flush($group->module_id);
         return self::get_by_id($wpdb->insert_id);
     }
     return new WP_Error('redirect-add', __('Unable to add new redirect - delete Redirection from the options page and re-install'));
 }
 function create($details)
 {
     global $wpdb;
     // Auto generate URLs
     if ($details['source'] == '') {
         $details['source'] = Red_Item::auto_generate();
     }
     if ($details['target'] == '') {
         $details['target'] = Red_Item::auto_generate();
     }
     // Make sure we don't redirect to ourself
     if ($details['source'] == $details['target']) {
         $details['target'] .= '-1';
     }
     $matcher = Red_Match::create($details['match']);
     $group_id = intval($details['group']);
     if ($group_id > 0 && $matcher) {
         $regex = isset($details['regex']) && $details['regex'] != false ? 1 : 0;
         $position = $wpdb->get_var($wpdb->prepare("SELECT COUNT(id) FROM {$wpdb->prefix}redirection_items WHERE group_id=%d", $group_id));
         $action = $details['red_action'];
         $action_code = 0;
         if ($action == 'url' || $action == 'random') {
             $action_code = 301;
         } elseif ($action == 'error') {
             $action_code = 404;
         }
         if (isset($details['action_code'])) {
             $action_code = intval($details['action_code']);
         }
         $data = array('url' => Red_Item::sanitize_url($details['source'], $regex), 'action_type' => $details['red_action'], 'regex' => $regex, 'position' => $position, 'match_type' => $details['match'], 'action_data' => $matcher->data($details), 'action_code' => $action_code, 'last_access' => '0000-00-00 00:00:00', 'group_id' => $group_id);
         $wpdb->insert($wpdb->prefix . 'redirection_items', $data);
         $group = Red_Group::get($group_id);
         Red_Module::flush($group->module_id);
         return Red_Item::get_by_id($wpdb->insert_id);
     }
     return false;
 }
 function create($details)
 {
     global $wpdb;
     // Auto generate URLs
     if ($details['source'] == '') {
         $details['source'] = Red_Item::auto_generate();
     }
     if ($details['target'] == '') {
         $details['target'] = Red_Item::auto_generate();
     }
     // Make sure we don't redirect to ourself
     if ($details['source'] == $details['target']) {
         $details['target'] .= '-1';
     }
     $matcher = Red_Match::create($details['match']);
     $group_id = intval($details['group']);
     if ($group_id > 0 && $matcher) {
         $match = $wpdb->escape($details['match']);
         $regex = isset($details['regex']) && $details['regex'] != false ? true : false;
         $url = $wpdb->escape(Red_Item::sanitize_url($details['source'], $regex));
         $action = $details['red_action'];
         $position = $wpdb->get_var("SELECT COUNT(id) FROM {$wpdb->prefix}redirection_items WHERE group_id='{$group_id}'");
         $data = $wpdb->escape($matcher->data($details));
         if ($action == 'url' || $action == 'random') {
             $action_code = 301;
         } else {
             if ($action == 'error') {
                 $action_code = 404;
             } else {
                 $action_code = 0;
             }
         }
         if (isset($details['action_code'])) {
             $action_code = intval($details['action_code']);
         }
         $wpdb->query("INSERT INTO {$wpdb->prefix}redirection_items (url,action_type,regex,position,match_type,action_data,action_code,last_access,group_id) VALUES ('{$url}','{$action}','" . ($regex ? 1 : 0) . "','{$position}','{$match}','{$data}',{$action_code},0,'{$group_id}')");
         $group = Red_Group::get($group_id);
         Red_Module::flush($group->module_id);
         return Red_Item::get_by_id($wpdb->insert_id);
     }
     return false;
 }