Exemplo n.º 1
0
 function post_updated($post_id, $post, $post_before)
 {
     if (isset($_POST['redirection_slug'])) {
         $after = parse_url(get_permalink($post_id));
         $after = $after['path'];
         $before = esc_url($_POST['redirection_slug']);
         $site = parse_url(get_site_url());
         if (in_array($post->post_status, array('publish', 'static')) && $before != $after && $before != '/' && $before != $site['path'] . '/') {
             Red_Item::create(array('source' => $before, 'target' => $after, 'match' => 'url', 'red_action' => 'url', 'group' => $this->monitor_post));
         }
     }
 }
 public function post_updated($post_id, $post, $post_before)
 {
     if ($this->can_monitor_post($post, $post_before, $_POST)) {
         $after = parse_url(get_permalink($post_id));
         $after = $after['path'];
         $before = esc_url($_POST['redirection_slug']);
         $site = parse_url(get_site_url());
         if ($before !== $after && $before !== '/' && (!isset($site['path']) || isset($site['path']) && $before !== $site['path'] . '/')) {
             Red_Item::create(array('source' => $before, 'target' => $after, 'match' => 'url', 'red_action' => 'url', 'group_id' => $this->monitor_group_id));
         }
     }
 }
Exemplo n.º 3
0
 function load($group, $data, $filename)
 {
     $count = 0;
     $file = fopen($filename, 'r');
     if ($file) {
         while ($csv = fgetcsv($file, 1000, ',')) {
             if ($csv[0] != 'source' && $csv[1] != 'target') {
                 Red_Item::create(array('source' => trim($csv[0]), 'target' => trim($csv[1]), 'regex' => $this->is_regex($csv[0]), 'group' => $group, 'match' => 'url', 'red_action' => 'url'));
                 $count++;
             }
         }
     }
     return $count;
 }
Exemplo n.º 4
0
 function post_changed($id)
 {
     if (isset($_POST['redirection_slug'])) {
         $post = get_post($id);
         $newslug = get_permalink($id);
         $oldslug = $_POST['redirection_slug'];
         $base = get_option('home');
         if ($newslug != $oldslug && strlen($oldslug) > 0 && ($post->post_status == 'publish' || $post->post_status == 'static') && $_POST['redirection_status'] != 'draft' && $_POST['redirection_status'] != 'pending' && $newslug != '/') {
             $old_url = parse_url($oldslug);
             $new_url = parse_url($newslug);
             Red_Item::create(array('source' => $old_url['path'], 'target' => $new_url['path'], 'match' => 'url', 'red_action' => 'url', 'group' => $this->monitor_post));
         }
     }
 }
Exemplo n.º 5
0
 function load($group, $data)
 {
     // Split it into lines
     $lines = array_filter(explode("\r", $data));
     if (count($lines) > 0) {
         $count = 0;
         foreach ($lines as $line) {
             $csv = $this->parse_csv($line);
             if ($csv[0] != 'source' && $csv[1] != 'target') {
                 Red_Item::create(array('source' => trim($csv[0]), 'target' => $csv[1], 'regex' => $this->is_regex($csv[0]), 'group' => $group, 'match' => 'url', 'red_action' => $csv[2] == 0 ? 'pass' : 'url'));
                 $count++;
             }
         }
         return $count;
     }
     return 0;
 }
Exemplo n.º 6
0
 function load($group, $data, $filename = '')
 {
     // Remove any comments
     $data = preg_replace('@#(.*)@', '', $data);
     $data = str_replace("\n", "\r", $data);
     $data = str_replace('\\ ', '%20', $data);
     // Split it into lines
     $lines = array_filter(explode("\r", $data));
     if (count($lines) > 0) {
         foreach ($lines as $line) {
             if (preg_match('@rewriterule\\s+(.*?)\\s+(.*?)\\s+(\\[.*\\])*@i', $line, $matches) > 0) {
                 $items[] = array('source' => $this->regex_url($matches[1]), 'target' => $this->decode_url($matches[2]), 'code' => $this->get_code($matches[3]), 'regex' => $this->is_regex($matches[1]));
             } elseif (preg_match('@Redirect\\s+(.*?)\\s+(.*?)\\s+(.*)@i', $line, $matches) > 0) {
                 $items[] = array('source' => $this->decode_url($matches[2]), 'target' => $this->decode_url($matches[3]), 'code' => $this->get_code($matches[1]));
             } elseif (preg_match('@Redirect\\s+(.*?)\\s+(.*?)@i', $line, $matches) > 0) {
                 $items[] = array('source' => $this->decode_url($matches[1]), 'target' => $this->decode_url($matches[2]), 'code' => 302);
             } elseif (preg_match('@Redirectmatch\\s+(.*?)\\s+(.*?)\\s+(.*)@i', $line, $matches) > 0) {
                 $items[] = array('source' => $this->decode_url($matches[2]), 'target' => $this->decode_url($matches[3]), 'code' => $this->get_code($matches[1]), 'regex' => true);
             } elseif (preg_match('@Redirectmatch\\s+(.*?)\\s+(.*?)@i', $line, $matches) > 0) {
                 $items[] = array('source' => $this->decode_url($matches[1]), 'target' => $this->decode_url($matches[2]), 'code' => 302, 'regex' => true);
             }
         }
         // Add items to group
         if (count($items) > 0) {
             foreach ($items as $item) {
                 $item['group'] = $group;
                 $item['red_action'] = 'url';
                 $item['match'] = 'url';
                 if ($item['code'] == 0) {
                     $item['red_action'] = 'pass';
                 }
                 Red_Item::create($item);
             }
             return count($items);
         }
     }
     return 0;
 }
Exemplo n.º 7
0
 public function ajax_redirect_add()
 {
     global $hook_suffix;
     $hook_suffix = '';
     $this->check_ajax_referer('redirection-redirect_add');
     $item = Red_Item::create($_POST);
     if (is_wp_error($item)) {
         $json['error'] = $item->get_error_message();
     } elseif ($item !== false) {
         $pager = new Redirection_Table(array());
         $json = array('html' => $pager->get_row($item));
     } else {
         $json['error'] = __('Sorry, but your redirection was not created', 'redirection');
     }
     $this->output_ajax_response($json);
 }
Exemplo n.º 8
0
 function red_redirect_add()
 {
     if (check_ajax_referer('redirection-redirect_add')) {
         $item = Red_Item::create($this->post);
         if (is_wp_error($item)) {
             $this->render_error($item->get_error_message());
         } elseif ($item !== false) {
             echo '<li class="type_' . $item->action_type . '" id="item_' . $item->id . '">';
             $this->render_admin('item', array('redirect' => $item, 'date_format' => get_option('date_format')));
             echo '</li>';
         } else {
             $this->render_error(__('Sorry, but your redirection was not created', 'redirection'));
         }
         die;
     }
 }
Exemplo n.º 9
0
 function upgrade_from_0()
 {
     // Convert to new format
     $items = get_option('redirection_list');
     if (is_array($items) && count($items) > 0) {
         foreach ($items as $item) {
             $data = array('old' => $item->url_old, 'type' => $item->type, 'red_action' => 'A_Redirector_URL', 'new' => $item->url_new);
             if ($item->regex) {
                 $data['regex'] = 'on';
             }
             Red_Item::create($data);
         }
         delete_option('redirection_list');
     }
     $this->upgrade_from_1();
     $this->upgrade_from_2();
     $this->upgrade_from_21();
     $this->upgrade_from_22();
 }