PluginProbe
Redirection / 2.1.29
Redirection v2.1.29
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 / models / monitor.php

monitor.php in Redirection 2.1.29, at models/monitor.php

123 lines 3.5 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 class Red_Monitor
4 {
5 var $monitor_post;
6 var $monitor_category;
7
8 function Red_Monitor ($options)
9 {
10 if ($options['monitor_post'] > 0)
11 {
12 $this->monitor_post = $options['monitor_post'];
13
14 add_action ('edit_form_advanced', array (&$this, 'insert_old_post'));
15 add_action ('edit_page_form', array (&$this, 'insert_old_post'));
16 add_action ('edit_post', array (&$this, 'post_changed'));
17 add_action ('delete_post', array (&$this, 'post_deleted'));
18
19 // if ($options['monitor_new_posts'])
20 // add_action ('transition_post_status', array (&$this, 'transition_post_status'), 10, 3);
21 }
22
23 if ($options['monitor_category'] > 0)
24 {
25 /* $this->monitor_category = $options['monitor_category'];
26
27 add_action ('edit_category_form', array (&$this, 'insert_old_category'));
28 add_action ('edit_category', array (&$this, 'category_changed'));
29 */
30 }
31 }
32
33 function transition_post_status ($new_status, $old_status, $post)
34 {
35 if ($new_status == 'publish')
36 {
37 $redirect = array
38 (
39 'source' => '',
40 'target' => substr (get_permalink ($post->ID), strlen (get_bloginfo ('home'))),
41 'match' => 'url',
42 'red_action' => 'url',
43 'regex' => false,
44 'group' => $this->monitor_post
45 );
46
47 Red_Item::create ($redirect);
48 }
49 }
50
51 function insert_old_category ($category)
52 {
53 if (isset ($category->cat_ID))
54 {
55 $link = get_category_link ($category->cat_ID);
56 $url = parse_url ($link);
57 ?>
58 <input type="hidden" name="redirection_slug" value="<?php echo attribute_escape ($url['path']) ?>"/>
59 <?php
60 }
61 }
62
63 function category_changed ($categoryid)
64 {
65 $new_url = parse_url (get_category_link ($categoryid));
66 $new_url['path'] = dirname ($new_url['path']).'/'.$_POST['category_nicename'];
67
68 if ($new_url['path'] != $_POST['redirection_slug'] && $_POST['redirection_slug'] != '')
69 {
70 $redirect = array
71 (
72 'source' => '^'.$_POST['redirection_slug'].'/(.*)$',
73 'target' => $new_url['path'].'/$1',
74 'match' => 'url',
75 'red_action' => 'url',
76 'regex' => true,
77 'group' => $this->monitor_post
78 );
79
80 Red_Item::create ($redirect);
81 }
82 }
83
84 function insert_old_post ()
85 {
86 global $post;
87 ?>
88 <input type="hidden" name="redirection_slug" value="<?php the_permalink () ?>"/>
89 <input type="hidden" name="redirection_status" value="<?php echo $post->post_status ?>"/>
90 <?php
91 }
92
93 function post_changed ($id)
94 {
95 if (isset($_POST['redirection_slug'])) {
96 $post = get_post ($id);
97 $newslug = get_permalink ($id);
98 $oldslug = $_POST['redirection_slug'];
99 $base = get_option ('home');
100
101 if ( $newslug != $oldslug && strlen( $oldslug ) > 0 && ( strpos( $oldslug, '?p=' ) === false ) && ( $post->post_status == 'publish' || $post->post_status == 'static' ) && $_POST['redirection_status'] != 'draft' && ( $post->post_type == 'post' || $post->post_type == 'page' ) && $oldslug != '/' && rtrim( $oldslug, '/' ) != rtrim( get_option( 'home' ), '/' ) )
102 {
103 $old_url = parse_url ($oldslug);
104 $new_url = parse_url ($newslug);
105
106 Red_Item::create (array ('source' => $old_url['path'], 'target' => $new_url['path'], 'match' => 'url', 'red_action' => 'url', 'group' => $this->monitor_post));
107 }
108 }
109 }
110
111 function post_deleted ($id)
112 {
113 $post = get_post ($id);
114 if ($post->post_status == 'publish' || $post->post_status == 'static')
115 {
116 $url = get_permalink ($id);
117 $slug = parse_url ($url);
118
119 // Red_Item::create (array ('source' => $slug['path'], 'target' => '', 'match' => 'url', 'red_action' => 'error', 'group' => $this->monitor_post, 'action_code' => 410));
120 }
121 }
122 }
123