Version Description
- Code cleanup
Download this release
Release Info
Developer | johnny5 |
Plugin | Search Regex |
Version | 1.4.13 |
Comparing to | |
See all releases |
Code changes from version 1.4.12 to 1.4.13
- ajax.php +0 -35
- js/search-regex.js +0 -80
- models/result.php +4 -5
- models/search.php +125 -124
- plugin.php +58 -379
- readme.txt +15 -12
- search-regex.php +78 -75
- searches/comment_author.php +10 -13
- searches/comment_author_email.php +10 -14
- searches/comment_author_url.php +10 -14
- searches/comment_content.php +9 -13
- searches/post_content.php +7 -8
- searches/post_excerpt.php +3 -8
- searches/post_meta.php +10 -12
- searches/post_title.php +3 -8
- searches/post_url.php +3 -6
- searches/sniplet_content.php +0 -60
- searches/tag_name.php +0 -60
- searches/tag_slug.php +0 -60
- view/admin/head.php +0 -7
- view/admin/results.php +10 -10
- view/admin/search.php +71 -65
ajax.php
DELETED
@@ -1,35 +0,0 @@
|
|
1 |
-
<?php
|
2 |
-
|
3 |
-
include ('../../../wp-config.php');
|
4 |
-
include (dirname (__FILE__).'/models/search.php');
|
5 |
-
include (dirname (__FILE__).'/models/result.php');
|
6 |
-
|
7 |
-
class Search_AJAX extends Redirection_Plugin
|
8 |
-
{
|
9 |
-
function Search_AJAX ($id, $command)
|
10 |
-
{
|
11 |
-
if (!current_user_can ('administrator') && !current_user_can ('search_regex_write'))
|
12 |
-
die ('<p style="color: red">You are not allowed access to this resource</p>');
|
13 |
-
|
14 |
-
$this->register_plugin ('search-regex', __FILE__);
|
15 |
-
if (method_exists ($this, $command))
|
16 |
-
$this->$command ($id);
|
17 |
-
else
|
18 |
-
die ('<p style="color: red">That function is not defined</p>');
|
19 |
-
}
|
20 |
-
|
21 |
-
function regex_replace ($id)
|
22 |
-
{
|
23 |
-
if (Search::valid_search (stripslashes( $_POST['klass'] )))
|
24 |
-
{
|
25 |
-
$searcher = new $_POST['klass'];
|
26 |
-
$searcher->replace_inline (intval ($_POST['item']), intval ($_POST['offset']), intval ($_POST['length']), stripslashes( $_POST['replace']) );
|
27 |
-
}
|
28 |
-
}
|
29 |
-
|
30 |
-
}
|
31 |
-
|
32 |
-
$id = $_GET['id'];
|
33 |
-
$cmd = $_GET['cmd'];
|
34 |
-
|
35 |
-
$obj = new Search_AJAX ($id, $cmd);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
js/search-regex.js
DELETED
@@ -1,80 +0,0 @@
|
|
1 |
-
function toggle_regex ()
|
2 |
-
{
|
3 |
-
Element.toggle ('regex-options');
|
4 |
-
}
|
5 |
-
|
6 |
-
function regex_replace (classs, item, offset, length, replace)
|
7 |
-
{
|
8 |
-
// Need an ID, start, end, and replace
|
9 |
-
new Ajax.Request (wp_base + '?cmd=regex_replace&id=' + item,
|
10 |
-
{
|
11 |
-
asynchronous: true,
|
12 |
-
evalScripts: true,
|
13 |
-
parameters: { klass: classs, item: item, offset: offset, length: length, replace: replace },
|
14 |
-
onLoading: function(request)
|
15 |
-
{
|
16 |
-
$('options_' + item + '_' + offset).innerHTML = '<img src="' + wp_loading + '" alt="loading" width="16" height="16"/>';
|
17 |
-
},
|
18 |
-
onComplete: function(request)
|
19 |
-
{
|
20 |
-
new Effect.Fade ('search_' + item + '_' + offset, { to: 0.2});
|
21 |
-
new Effect.Fade ('options_' + item + '_' + offset);
|
22 |
-
}
|
23 |
-
});
|
24 |
-
}
|
25 |
-
|
26 |
-
function regex_edit_replace (classs, item, offset, length)
|
27 |
-
{
|
28 |
-
$('replace_' + item + '_' + offset).innerHTML = re_replace[item + '_' + offset];
|
29 |
-
$('replace_' + item + '_' + offset).innerHTML += ' <input type="submit" name="cancel" value="Cancel" onclick="regex_cancel_replace(' + item + ',' + offset + ')"/>';
|
30 |
-
Field.activate ('rep_' + item + '_' + offset);
|
31 |
-
}
|
32 |
-
|
33 |
-
function regex_edit (classs, item, offset, length)
|
34 |
-
{
|
35 |
-
$('value_' + item + '_' + offset).innerHTML = re_input[item + '_' + offset];
|
36 |
-
$('value_' + item + '_' + offset).innerHTML += ' <input type="submit" name="cancel" value="Cancel" onclick="regex_cancel(' + item + ',' + offset + ')"/>';
|
37 |
-
Field.activate ('txt_' + item + '_' + offset);
|
38 |
-
}
|
39 |
-
|
40 |
-
function regex_cancel (item, offset)
|
41 |
-
{
|
42 |
-
$('value_' + item + '_' + offset).innerHTML = re_text[item + '_' + offset].gsub ('"', '"');
|
43 |
-
}
|
44 |
-
|
45 |
-
function regex_cancel_replace (item, offset)
|
46 |
-
{
|
47 |
-
$('replace_' + item + '_' + offset).innerHTML = re_text_replace[item + '_' + offset].gsub ('"', '"');
|
48 |
-
}
|
49 |
-
|
50 |
-
function save_edit (classs, item, offset, start, length)
|
51 |
-
{
|
52 |
-
new Ajax.Request (wp_base + '?cmd=regex_replace&id=' + item,
|
53 |
-
{
|
54 |
-
asynchronous: true, evalScripts: true,
|
55 |
-
parameters: { klass: classs, item: item, offset: start, length: length, replace: $('txt_' + item + '_' + offset).value},
|
56 |
-
onLoading: function(request) { $('options_' + item + '_' + offset).innerHTML = '<img src="' + wp_loading + '" alt="loading" width="16" height="16"/>'; },
|
57 |
-
onComplete: function(request)
|
58 |
-
{
|
59 |
-
new Effect.Fade ('search_' + item + '_' + offset, { to: 0.2});
|
60 |
-
new Effect.Fade ('options_' + item + '_' + offset);
|
61 |
-
$('value_' + item + '_' + offset).innerHTML = $('txt_' + item + '_' + offset).value;
|
62 |
-
}
|
63 |
-
});
|
64 |
-
}
|
65 |
-
|
66 |
-
function save_edit_rep (classs, item, offset, start, length)
|
67 |
-
{
|
68 |
-
new Ajax.Request (wp_base + '?cmd=regex_replace&id=' + item,
|
69 |
-
{
|
70 |
-
asynchronous: true, evalScripts: true,
|
71 |
-
parameters: { klass: classs, item: item, offset: start, length: length, replace: $('rep_' + item + '_' + offset).value},
|
72 |
-
onLoading: function(request) { $('options_' + item + '_' + offset).innerHTML = '<img src="' + wp_loading + '" alt="loading" width="16" height="16"/>'; },
|
73 |
-
onComplete: function(request)
|
74 |
-
{
|
75 |
-
new Effect.Fade ('search_' + item + '_' + offset, { to: 0.2});
|
76 |
-
new Effect.Fade ('options_' + item + '_' + offset);
|
77 |
-
$('replace_' + item + '_' + offset).innerHTML = $('rep_' + item + '_' + offset).value;
|
78 |
-
}
|
79 |
-
});
|
80 |
-
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
models/result.php
CHANGED
@@ -1,5 +1,5 @@
|
|
1 |
<?php
|
2 |
-
|
3 |
class Result
|
4 |
{
|
5 |
var $search;
|
@@ -7,11 +7,11 @@ class Result
|
|
7 |
var $content;
|
8 |
var $id;
|
9 |
var $title;
|
10 |
-
|
11 |
var $offset;
|
12 |
var $length;
|
13 |
var $replace_string;
|
14 |
-
|
15 |
function for_js ($js)
|
16 |
{
|
17 |
$js = str_replace ('\\', '\\\\', $js);
|
@@ -23,7 +23,7 @@ class Result
|
|
23 |
$js = str_replace ("\r", "\\r", $js);
|
24 |
return $js;
|
25 |
}
|
26 |
-
|
27 |
function single_line ()
|
28 |
{
|
29 |
if (strpos ($this->search_plain, "\r") !== false || strpos ($this->search_plain, "\n") !== false)
|
@@ -32,4 +32,3 @@ class Result
|
|
32 |
}
|
33 |
}
|
34 |
|
35 |
-
?>
|
1 |
<?php
|
2 |
+
|
3 |
class Result
|
4 |
{
|
5 |
var $search;
|
7 |
var $content;
|
8 |
var $id;
|
9 |
var $title;
|
10 |
+
|
11 |
var $offset;
|
12 |
var $length;
|
13 |
var $replace_string;
|
14 |
+
|
15 |
function for_js ($js)
|
16 |
{
|
17 |
$js = str_replace ('\\', '\\\\', $js);
|
23 |
$js = str_replace ("\r", "\\r", $js);
|
24 |
return $js;
|
25 |
}
|
26 |
+
|
27 |
function single_line ()
|
28 |
{
|
29 |
if (strpos ($this->search_plain, "\r") !== false || strpos ($this->search_plain, "\n") !== false)
|
32 |
}
|
33 |
}
|
34 |
|
|
models/search.php
CHANGED
@@ -8,182 +8,184 @@ class Search
|
|
8 |
var $save = false;
|
9 |
var $source = null;
|
10 |
var $error = null;
|
11 |
-
|
12 |
var $regex_options = null;
|
13 |
var $regex_error = null;
|
14 |
var $regex = false;
|
15 |
-
|
16 |
-
function set_regex_options
|
17 |
{
|
18 |
$this->regex = true;
|
19 |
-
if
|
20 |
$this->regex_options .= 'i';
|
21 |
-
|
22 |
-
if
|
23 |
$this->regex_options .= 's';
|
24 |
-
|
25 |
-
if
|
26 |
$this->regex_options .= 'm';
|
27 |
}
|
28 |
|
29 |
-
function regex_error
|
30 |
{
|
31 |
-
$this->regex_error = __
|
32 |
}
|
33 |
|
34 |
-
function name
|
35 |
-
function run_search
|
36 |
-
|
37 |
-
function search_and_replace
|
38 |
{
|
39 |
$this->replace = $replace;
|
40 |
-
$results = $this->search_for_pattern
|
41 |
|
42 |
-
if
|
43 |
-
$this->replace
|
44 |
return $results;
|
45 |
}
|
46 |
-
|
47 |
-
function search_for_pattern
|
48 |
-
|
49 |
-
|
50 |
-
|
51 |
-
|
52 |
-
|
|
|
|
|
|
|
|
|
53 |
|
54 |
// First test that the search and replace strings are valid regex
|
55 |
-
if ($this->regex)
|
56 |
-
|
57 |
-
|
58 |
-
|
59 |
-
|
60 |
-
|
61 |
-
if ($valid === false)
|
62 |
return $this->regex_error;
|
63 |
-
|
64 |
-
return $this->find
|
65 |
}
|
66 |
else
|
67 |
-
return $this->find
|
68 |
}
|
69 |
-
|
70 |
-
return __
|
71 |
}
|
72 |
-
|
73 |
-
function get_searches
|
74 |
{
|
75 |
global $search_regex_searches;
|
76 |
-
if
|
77 |
{
|
78 |
-
$available = get_declared_classes
|
79 |
-
$files = glob (
|
80 |
-
if
|
81 |
{
|
82 |
-
foreach
|
83 |
-
include_once
|
84 |
}
|
85 |
|
86 |
-
$classes = array
|
87 |
-
$available = array_diff
|
88 |
-
if (
|
89 |
{
|
90 |
-
foreach
|
91 |
$classes[] = new $class;
|
92 |
}
|
93 |
-
|
94 |
$search_regex_searches = $classes;
|
95 |
}
|
96 |
-
|
97 |
return $search_regex_searches;
|
98 |
}
|
99 |
|
100 |
-
function valid_search
|
101 |
-
|
102 |
-
$classes
|
103 |
-
|
104 |
-
{
|
105 |
-
if (strcasecmp (get_class ($item), $class) == 0)
|
106 |
return true;
|
107 |
}
|
|
|
108 |
return false;
|
109 |
}
|
110 |
-
|
111 |
-
function matches
|
112 |
{
|
113 |
-
if (
|
114 |
{
|
115 |
-
$results = array
|
116 |
-
|
117 |
// We found something
|
118 |
-
foreach
|
119 |
{
|
120 |
-
$result = new Result
|
121 |
$result->id = $id;
|
122 |
|
123 |
$result->offset = $found[1];
|
124 |
-
$result->length = strlen
|
125 |
-
|
126 |
// Extract the context - surrounding 40 characters either side
|
127 |
// Index 0 is the match, index 1 is the position
|
128 |
$start = $found[1] - 40;
|
129 |
-
if
|
130 |
$start = 0;
|
131 |
-
|
132 |
$end = $found[1] + 40;
|
133 |
-
if
|
134 |
-
$end = strlen
|
135 |
|
136 |
$end -= $start;
|
137 |
|
138 |
-
$left = substr
|
139 |
-
$right = substr
|
140 |
-
|
141 |
$result->left = $start;
|
142 |
-
$result->left_length = strlen
|
143 |
|
144 |
-
if
|
145 |
$result->search = '… ';
|
146 |
-
|
147 |
-
$result->search .= htmlspecialchars
|
148 |
-
$result->search .= '<a
|
149 |
-
$result->search .= htmlspecialchars
|
150 |
-
$result->search .= htmlspecialchars
|
151 |
-
|
152 |
-
$result->search_plain = htmlspecialchars
|
153 |
-
$result->search_plain .= htmlspecialchars
|
154 |
-
$result->search_plain .= htmlspecialchars
|
155 |
-
|
156 |
-
if
|
157 |
$result->search .= ' …';
|
158 |
-
|
159 |
-
if
|
160 |
{
|
161 |
// Produce preview
|
162 |
-
$rep = preg_replace
|
163 |
$result->replace_string = $rep;
|
164 |
-
|
165 |
-
if
|
166 |
$result->replace = '… ';
|
167 |
-
|
168 |
-
$result->replace .= htmlspecialchars
|
169 |
-
$result->replace .= '<a title="'.__
|
170 |
-
if
|
171 |
-
$result->replace .= '<strong>'.htmlspecialchars
|
172 |
else
|
173 |
-
$result->replace .= '<strong>['.__
|
174 |
-
$result->replace .= htmlspecialchars
|
175 |
-
|
176 |
-
$result->left_length_replace = strlen
|
177 |
-
|
178 |
-
$result->replace_plain = htmlspecialchars
|
179 |
-
$result->replace_plain .= htmlspecialchars
|
180 |
-
$result->replace_plain .= htmlspecialchars
|
181 |
-
|
182 |
-
if
|
183 |
$result->replace .= ' …';
|
184 |
-
|
185 |
// And the real thing
|
186 |
-
$result->content = preg_replace
|
187 |
}
|
188 |
|
189 |
$results[] = $result;
|
@@ -193,43 +195,42 @@ class Search
|
|
193 |
}
|
194 |
return false;
|
195 |
}
|
196 |
-
|
197 |
-
|
198 |
-
function replace
|
199 |
{
|
200 |
global $wpdb;
|
201 |
-
|
202 |
// Update database, if appropriate
|
203 |
-
if (
|
204 |
{
|
205 |
// We only do the first replace of any set, as that will cover everything
|
206 |
$lastid = '';
|
207 |
-
foreach
|
208 |
{
|
209 |
-
if
|
210 |
{
|
211 |
-
$this->replace_content
|
212 |
$lastid = $result->id;
|
213 |
}
|
214 |
}
|
215 |
}
|
216 |
}
|
217 |
-
|
218 |
-
function replace_inline
|
219 |
{
|
220 |
-
$content = $this->get_content
|
221 |
|
222 |
// Delete the original string
|
223 |
-
$before = substr
|
224 |
-
$after = substr
|
225 |
-
|
226 |
// Stick the new string between
|
227 |
$content = $before.$replace.$after;
|
228 |
-
|
229 |
// Insert back into database
|
230 |
-
$this->replace_content
|
231 |
}
|
232 |
}
|
233 |
|
234 |
global $search_regex_searches;
|
235 |
-
?>
|
8 |
var $save = false;
|
9 |
var $source = null;
|
10 |
var $error = null;
|
11 |
+
|
12 |
var $regex_options = null;
|
13 |
var $regex_error = null;
|
14 |
var $regex = false;
|
15 |
+
|
16 |
+
function set_regex_options( $dotall, $case, $multi)
|
17 |
{
|
18 |
$this->regex = true;
|
19 |
+
if( !empty( $case))
|
20 |
$this->regex_options .= 'i';
|
21 |
+
|
22 |
+
if( !empty( $dotall))
|
23 |
$this->regex_options .= 's';
|
24 |
+
|
25 |
+
if( !empty( $multi))
|
26 |
$this->regex_options .= 'm';
|
27 |
}
|
28 |
|
29 |
+
function regex_error( $errno, $errstr, $errfile, $errline)
|
30 |
{
|
31 |
+
$this->regex_error = __( "Invalid regular expression", 'search-regex').": ".preg_replace( '/(.*?):/', '', $errstr);
|
32 |
}
|
33 |
|
34 |
+
function name() { return '';}
|
35 |
+
function run_search( $search) { return false; }
|
36 |
+
|
37 |
+
function search_and_replace( $search, $replace, $limit, $offset, $orderby, $save = false)
|
38 |
{
|
39 |
$this->replace = $replace;
|
40 |
+
$results = $this->search_for_pattern( $search, $limit, $offset, $orderby);
|
41 |
|
42 |
+
if( $results !== false && $save)
|
43 |
+
$this->replace( $results);
|
44 |
return $results;
|
45 |
}
|
46 |
+
|
47 |
+
function search_for_pattern( $search, $limit, $offset, $orderby ) {
|
48 |
+
if ( !in_array( $orderby, array( 'asc', 'desc' ) ) )
|
49 |
+
$orderby = 'asc';
|
50 |
+
|
51 |
+
$limit = intval( $limit );
|
52 |
+
$offset = intval( $offset );
|
53 |
+
|
54 |
+
if ( strlen( $search ) > 0 ) {
|
55 |
+
if ( !ini_get( 'safe_mode' ) )
|
56 |
+
set_time_limit( 0 );
|
57 |
|
58 |
// First test that the search and replace strings are valid regex
|
59 |
+
if ( $this->regex ) {
|
60 |
+
set_error_handler( array( &$this, 'regex_error' ) );
|
61 |
+
$valid = @preg_match( $search, '', $matches );
|
62 |
+
restore_error_handler();
|
63 |
+
|
64 |
+
if ( $valid === false )
|
|
|
65 |
return $this->regex_error;
|
66 |
+
|
67 |
+
return $this->find( $search, $limit, $offset, $orderby );
|
68 |
}
|
69 |
else
|
70 |
+
return $this->find( '@'.preg_quote( $search, '@' ).'@', $limit, $offset, $orderby );
|
71 |
}
|
72 |
+
|
73 |
+
return __( "No search pattern", 'search-regex' );
|
74 |
}
|
75 |
+
|
76 |
+
function get_searches()
|
77 |
{
|
78 |
global $search_regex_searches;
|
79 |
+
if( !is_array( $search_regex_searches))
|
80 |
{
|
81 |
+
$available = get_declared_classes();
|
82 |
+
$files = glob( dirname( __FILE__).'/../searches/*.php');
|
83 |
+
if( !empty( $files))
|
84 |
{
|
85 |
+
foreach( $files AS $file)
|
86 |
+
include_once( $file);
|
87 |
}
|
88 |
|
89 |
+
$classes = array();
|
90 |
+
$available = array_diff( get_declared_classes(), $available);
|
91 |
+
if( count( $available) > 0)
|
92 |
{
|
93 |
+
foreach( $available AS $class)
|
94 |
$classes[] = new $class;
|
95 |
}
|
96 |
+
|
97 |
$search_regex_searches = $classes;
|
98 |
}
|
99 |
+
|
100 |
return $search_regex_searches;
|
101 |
}
|
102 |
|
103 |
+
function valid_search( $class ) {
|
104 |
+
$classes = Search::get_searches();
|
105 |
+
foreach ( $classes AS $item ) {
|
106 |
+
if ( strcasecmp( get_class( $item ), $class ) == 0 )
|
|
|
|
|
107 |
return true;
|
108 |
}
|
109 |
+
|
110 |
return false;
|
111 |
}
|
112 |
+
|
113 |
+
function matches( $pattern, $content, $id)
|
114 |
{
|
115 |
+
if( preg_match_all( $pattern.$this->regex_options, $content, $matches, PREG_OFFSET_CAPTURE) > 0)
|
116 |
{
|
117 |
+
$results = array();
|
118 |
+
|
119 |
// We found something
|
120 |
+
foreach( $matches[0] AS $found)
|
121 |
{
|
122 |
+
$result = new Result();
|
123 |
$result->id = $id;
|
124 |
|
125 |
$result->offset = $found[1];
|
126 |
+
$result->length = strlen( $found[0]);
|
127 |
+
|
128 |
// Extract the context - surrounding 40 characters either side
|
129 |
// Index 0 is the match, index 1 is the position
|
130 |
$start = $found[1] - 40;
|
131 |
+
if( $start < 0)
|
132 |
$start = 0;
|
133 |
+
|
134 |
$end = $found[1] + 40;
|
135 |
+
if( $end > strlen( $content))
|
136 |
+
$end = strlen( $content);
|
137 |
|
138 |
$end -= $start;
|
139 |
|
140 |
+
$left = substr( $content, $start, $found[1] - $start);
|
141 |
+
$right = substr( $content, $found[1] + strlen( $found[0]), $end);
|
142 |
+
|
143 |
$result->left = $start;
|
144 |
+
$result->left_length = strlen( $found[0]) +( $found[1] - $start) + $end;
|
145 |
|
146 |
+
if( $start != 0)
|
147 |
$result->search = '… ';
|
148 |
+
|
149 |
+
$result->search .= htmlspecialchars( $left, HTML_ENTITIES, 'UTF-8');
|
150 |
+
$result->search .= '<a href="#" onclick="return false">';
|
151 |
+
$result->search .= htmlspecialchars( $found[0], HTML_ENTITIES, 'UTF-8').'</a>';
|
152 |
+
$result->search .= htmlspecialchars( $right, HTML_ENTITIES, 'UTF-8');
|
153 |
+
|
154 |
+
$result->search_plain = htmlspecialchars( $left, HTML_ENTITIES, 'UTF-8');
|
155 |
+
$result->search_plain .= htmlspecialchars( $found[0], HTML_ENTITIES, 'UTF-8');
|
156 |
+
$result->search_plain .= htmlspecialchars( $right, HTML_ENTITIES, 'UTF-8');
|
157 |
+
|
158 |
+
if( $start + $end < strlen( $content))
|
159 |
$result->search .= ' …';
|
160 |
+
|
161 |
+
if( !is_null( $this->replace))
|
162 |
{
|
163 |
// Produce preview
|
164 |
+
$rep = preg_replace( $pattern.$this->regex_options, $this->replace, $found[0]);
|
165 |
$result->replace_string = $rep;
|
166 |
+
|
167 |
+
if( $start != 0)
|
168 |
$result->replace = '… ';
|
169 |
+
|
170 |
+
$result->replace .= htmlspecialchars( $left, HTML_ENTITIES, 'UTF-8');
|
171 |
+
$result->replace .= '<a title="'.__( 'edit').'" onclick="return false;" ondblclick="regex_edit_replace(\''.get_class( $this).'\','.$result->id.','.$result->offset.','.$result->length.'); return false" href="#">';
|
172 |
+
if( $rep != '')
|
173 |
+
$result->replace .= '<strong>'.htmlspecialchars( $rep, HTML_ENTITIES, 'UTF-8').'</strong></a>';
|
174 |
else
|
175 |
+
$result->replace .= '<strong>['.__( 'deleted','search-regex').']</strong></a>';
|
176 |
+
$result->replace .= htmlspecialchars( $right, HTML_ENTITIES, 'UTF-8');
|
177 |
+
|
178 |
+
$result->left_length_replace = strlen( $left) + strlen( $rep) + strlen( $right) + 1;
|
179 |
+
|
180 |
+
$result->replace_plain = htmlspecialchars( $left, HTML_ENTITIES, 'UTF-8');
|
181 |
+
$result->replace_plain .= htmlspecialchars( $rep, HTML_ENTITIES, 'UTF-8');
|
182 |
+
$result->replace_plain .= htmlspecialchars( $right, HTML_ENTITIES, 'UTF-8');
|
183 |
+
|
184 |
+
if( $start + $end < strlen( $content))
|
185 |
$result->replace .= ' …';
|
186 |
+
|
187 |
// And the real thing
|
188 |
+
$result->content = preg_replace( $pattern.$this->regex_options, $this->replace, $content);
|
189 |
}
|
190 |
|
191 |
$results[] = $result;
|
195 |
}
|
196 |
return false;
|
197 |
}
|
198 |
+
|
199 |
+
|
200 |
+
function replace( $results)
|
201 |
{
|
202 |
global $wpdb;
|
203 |
+
|
204 |
// Update database, if appropriate
|
205 |
+
if( count( $results) > 0)
|
206 |
{
|
207 |
// We only do the first replace of any set, as that will cover everything
|
208 |
$lastid = '';
|
209 |
+
foreach( $results AS $result)
|
210 |
{
|
211 |
+
if( $result->id != $lastid)
|
212 |
{
|
213 |
+
$this->replace_content( $result->id, $result->content);
|
214 |
$lastid = $result->id;
|
215 |
}
|
216 |
}
|
217 |
}
|
218 |
}
|
219 |
+
|
220 |
+
function replace_inline( $id, $offset, $length, $replace)
|
221 |
{
|
222 |
+
$content = $this->get_content( $id);
|
223 |
|
224 |
// Delete the original string
|
225 |
+
$before = substr( $content, 0, $offset);
|
226 |
+
$after = substr( $content, $offset + $length);
|
227 |
+
|
228 |
// Stick the new string between
|
229 |
$content = $before.$replace.$after;
|
230 |
+
|
231 |
// Insert back into database
|
232 |
+
$this->replace_content( $id, $content);
|
233 |
}
|
234 |
}
|
235 |
|
236 |
global $search_regex_searches;
|
|
plugin.php
CHANGED
@@ -5,7 +5,7 @@
|
|
5 |
// modify it under the terms of the GNU Lesser General Public
|
6 |
// License as published by the Free Software Foundation; either
|
7 |
// version 2.1 of the License, or (at your option) any later version.
|
8 |
-
//
|
9 |
// This library is distributed in the hope that it will be useful,
|
10 |
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
11 |
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
@@ -47,44 +47,44 @@
|
|
47 |
* The class uses a similar technique to Ruby On Rails views, whereby the display HTML is kept
|
48 |
* in a separate directory and file from the main code. A display is 'rendered' (sent to the browser)
|
49 |
* or 'captured' (returned to the calling function).
|
50 |
-
*
|
51 |
* Template files are separated into two areas: admin and user. Admin templates are only for display in
|
52 |
* the WordPress admin interface, while user templates are typically for display on the site (although neither
|
53 |
* of these are enforced). All templates are PHP code, but are referred to without .php extension.
|
54 |
-
*
|
55 |
* The reason for this separation is that one golden rule of plugin creation is that someone will always want to change
|
56 |
* the formatting and style of your output. Rather than forcing them to modify the plugin (bad), or modify files within
|
57 |
* the plugin (equally bad), the class allows user templates to be overridden with files contained within the theme.
|
58 |
*
|
59 |
* An additional benefit is that it leads to code re-use, especially with regards to Ajax (i.e. your display code can be called from
|
60 |
* many locations)
|
61 |
-
*
|
62 |
* Template files are located within the 'view' subdirectory of the plugins base (specified when registering the plugin):
|
63 |
-
*
|
64 |
* <pre>myplugin/view/admin
|
65 |
* myplugin/view/myplugin</pre>
|
66 |
-
*
|
67 |
* Admin templates are contained within 'admin', and user templates are contained within a directory of the same name as the plugin.
|
68 |
-
*
|
69 |
* User files can be overridden within the theme by creating a similar directory structure:
|
70 |
-
*
|
71 |
* <pre>/themes/mytheme/view/myplugin</pre>
|
72 |
-
*
|
73 |
* The class will first look in the theme and then defaults to the plugin. A plugin should always provide default templates.
|
74 |
-
*
|
75 |
* <h4>Display Parameters</h4>
|
76 |
* Also similar to Ruby On Rails, when you display a template you must supply the parameters that the template has access to. This tries
|
77 |
* to ensure a very clean separation between code and display. Parameters are supplied as an associative array mapping variable name to variable value.
|
78 |
-
*
|
79 |
* For example,
|
80 |
-
*
|
81 |
* array ('message' => 'Your data was processed', 'items' => 103);
|
82 |
*
|
83 |
* <h4>How it works in practice</h4>
|
84 |
* You create a template file to display how many items have been processed. You store this in 'view/admin/processed.php':
|
85 |
*
|
86 |
* <pre><p>You processed <?php echo $items ?> items</p></pre>
|
87 |
-
*
|
88 |
* When you want to display this in your plugin you use:
|
89 |
*
|
90 |
* <pre> $this->render_admin ('processed', array ('items' => 100));
|
@@ -101,14 +101,14 @@ class SearchRegex_Plugin
|
|
101 |
* @var string
|
102 |
**/
|
103 |
var $plugin_name;
|
104 |
-
|
105 |
/**
|
106 |
* Plugin 'view' directory
|
107 |
* @var string Directory
|
108 |
**/
|
109 |
var $plugin_base;
|
110 |
-
|
111 |
-
|
112 |
/**
|
113 |
* Register your plugin with a name and base directory. This <strong>must</strong> be called once.
|
114 |
*
|
@@ -116,7 +116,7 @@ class SearchRegex_Plugin
|
|
116 |
* @param string $base Directory containing the plugin's 'view' files.
|
117 |
* @return void
|
118 |
**/
|
119 |
-
|
120 |
function register_plugin ($name, $base)
|
121 |
{
|
122 |
$this->plugin_base = rtrim (dirname ($base), '/');
|
@@ -124,7 +124,7 @@ class SearchRegex_Plugin
|
|
124 |
|
125 |
$this->add_action ('init', 'load_locale');
|
126 |
}
|
127 |
-
|
128 |
function load_locale ()
|
129 |
{
|
130 |
// Here we manually fudge the plugin locale as WP doesnt allow many options
|
@@ -135,8 +135,8 @@ class SearchRegex_Plugin
|
|
135 |
$mofile = dirname (__FILE__)."/locale/$locale.mo";
|
136 |
load_textdomain ($this->plugin_name, $mofile);
|
137 |
}
|
138 |
-
|
139 |
-
|
140 |
/**
|
141 |
* Register a WordPress action and map it back to the calling object
|
142 |
*
|
@@ -146,7 +146,7 @@ class SearchRegex_Plugin
|
|
146 |
* @param int $accepted_args Number of arguments the function accepts (optional)
|
147 |
* @return void
|
148 |
**/
|
149 |
-
|
150 |
function add_action ($action, $function = '', $priority = 10, $accepted_args = 1)
|
151 |
{
|
152 |
add_action ($action, array (&$this, $function == '' ? $action : $function), $priority, $accepted_args);
|
@@ -162,7 +162,7 @@ class SearchRegex_Plugin
|
|
162 |
* @param int $accepted_args Number of arguments the function accepts (optional)
|
163 |
* @return void
|
164 |
**/
|
165 |
-
|
166 |
function add_filter ($filter, $function = '', $priority = 10, $accepted_args = 1)
|
167 |
{
|
168 |
add_filter ($filter, array (&$this, $function == '' ? $filter : $function), $priority, $accepted_args);
|
@@ -176,13 +176,13 @@ class SearchRegex_Plugin
|
|
176 |
* @param string $function Optional function name, or default to 'activate'
|
177 |
* @return void
|
178 |
**/
|
179 |
-
|
180 |
function register_activation ($pluginfile, $function = '')
|
181 |
{
|
182 |
add_action ('activate_'.basename (dirname ($pluginfile)).'/'.basename ($pluginfile), array (&$this, $function == '' ? 'activate' : $function));
|
183 |
}
|
184 |
-
|
185 |
-
|
186 |
/**
|
187 |
* Special deactivation function that takes into account the plugin directory
|
188 |
*
|
@@ -190,13 +190,13 @@ class SearchRegex_Plugin
|
|
190 |
* @param string $function Optional function name, or default to 'deactivate'
|
191 |
* @return void
|
192 |
**/
|
193 |
-
|
194 |
function register_deactivation ($pluginfile, $function = '')
|
195 |
{
|
196 |
add_action ('deactivate_'.basename (dirname ($pluginfile)).'/'.basename ($pluginfile), array (&$this, $function == '' ? 'deactivate' : $function));
|
197 |
}
|
198 |
-
|
199 |
-
|
200 |
/**
|
201 |
* Renders an admin section of display code
|
202 |
*
|
@@ -204,7 +204,7 @@ class SearchRegex_Plugin
|
|
204 |
* @param string $array Array of variable name=>value that is available to the display code (optional)
|
205 |
* @return void
|
206 |
**/
|
207 |
-
|
208 |
function render_admin ($ug_name, $ug_vars = array ())
|
209 |
{
|
210 |
global $plugin_base;
|
@@ -226,7 +226,7 @@ class SearchRegex_Plugin
|
|
226 |
* @param string $array Array of variable name=>value that is available to the display code (optional)
|
227 |
* @return void
|
228 |
**/
|
229 |
-
|
230 |
function render ($ug_name, $ug_vars = array ())
|
231 |
{
|
232 |
foreach ($ug_vars AS $key => $val)
|
@@ -239,8 +239,8 @@ class SearchRegex_Plugin
|
|
239 |
else
|
240 |
echo "<p>Rendering of template $ug_name.php failed</p>";
|
241 |
}
|
242 |
-
|
243 |
-
|
244 |
/**
|
245 |
* Renders a section of user display code. The code is first checked for in the current theme display directory
|
246 |
* before defaulting to the plugin
|
@@ -258,7 +258,7 @@ class SearchRegex_Plugin
|
|
258 |
ob_end_clean ();
|
259 |
return $output;
|
260 |
}
|
261 |
-
|
262 |
|
263 |
/**
|
264 |
* Captures an admin section of display code
|
@@ -276,15 +276,33 @@ class SearchRegex_Plugin
|
|
276 |
ob_end_clean ();
|
277 |
return $output;
|
278 |
}
|
279 |
-
|
280 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
281 |
/**
|
282 |
* Display a standard error message (using CSS ID 'message' and classes 'fade' and 'error)
|
283 |
*
|
284 |
* @param string $message Message to display
|
285 |
* @return void
|
286 |
**/
|
287 |
-
|
288 |
function render_error ($message)
|
289 |
{
|
290 |
?>
|
@@ -293,8 +311,8 @@ class SearchRegex_Plugin
|
|
293 |
</div>
|
294 |
<?php
|
295 |
}
|
296 |
-
|
297 |
-
|
298 |
/**
|
299 |
* Display a standard notice (using CSS ID 'message' and class 'updated').
|
300 |
* Note that the notice can be made to automatically disappear, and can be removed
|
@@ -304,175 +322,16 @@ class SearchRegex_Plugin
|
|
304 |
* @param int $timeout Number of seconds to automatically remove the message (optional)
|
305 |
* @return void
|
306 |
**/
|
307 |
-
|
308 |
function render_message ($message, $timeout = 0)
|
309 |
{
|
310 |
?>
|
311 |
<div class="updated" id="message" onclick="this.parentNode.removeChild (this)">
|
312 |
<p><?php echo $message ?></p>
|
313 |
</div>
|
314 |
-
<?php
|
315 |
-
}
|
316 |
-
|
317 |
-
|
318 |
-
/**
|
319 |
-
* Get the plugin's base directory
|
320 |
-
*
|
321 |
-
* @return string Base directory
|
322 |
-
**/
|
323 |
-
|
324 |
-
function dir ()
|
325 |
-
{
|
326 |
-
return $this->plugin_base;
|
327 |
-
}
|
328 |
-
|
329 |
-
|
330 |
-
/**
|
331 |
-
* Get a URL to the plugin. Useful for specifying JS and CSS files
|
332 |
-
*
|
333 |
-
* For example, <img src="<?php echo $this->url () ?>/myimage.png"/>
|
334 |
-
*
|
335 |
-
* @return string URL
|
336 |
-
**/
|
337 |
-
|
338 |
-
function url ($url = '')
|
339 |
-
{
|
340 |
-
if ($url)
|
341 |
-
return str_replace ('\\', urlencode ('\\'), str_replace ('&amp', '&', str_replace ('&', '&', $url)));
|
342 |
-
else
|
343 |
-
{
|
344 |
-
$root = ABSPATH;
|
345 |
-
if (defined ('WP_PLUGIN_DIR'))
|
346 |
-
$root = WP_PLUGIN_DIR;
|
347 |
-
|
348 |
-
$url = substr ($this->plugin_base, strlen ($this->realpath ($root)));
|
349 |
-
if (DIRECTORY_SEPARATOR != '/')
|
350 |
-
$url = str_replace (DIRECTORY_SEPARATOR, '/', $url);
|
351 |
-
|
352 |
-
if (defined ('WP_PLUGIN_URL'))
|
353 |
-
$url = WP_PLUGIN_URL.'/'.ltrim ($url, '/');
|
354 |
-
else
|
355 |
-
$url = get_bloginfo ('wpurl').'/'.ltrim ($url, '/');
|
356 |
-
|
357 |
-
// Do an SSL check - only works on Apache
|
358 |
-
global $is_IIS;
|
359 |
-
if (isset ($_SERVER['HTTPS']) && !$is_IIS)
|
360 |
-
$url = str_replace ('http://', 'https://', $url);
|
361 |
-
}
|
362 |
-
return $url;
|
363 |
}
|
364 |
-
|
365 |
-
/**
|
366 |
-
* Performs a version update check using an RSS feed. The function ensures that the feed is only
|
367 |
-
* hit once every given number of days, and the data is cached using the WordPress Magpie library
|
368 |
-
*
|
369 |
-
* @param string $url URL of the RSS feed
|
370 |
-
* @param int $days Number of days before next check
|
371 |
-
* @return string Text to display
|
372 |
-
**/
|
373 |
-
|
374 |
-
function version_update ($url, $days = 7)
|
375 |
-
{
|
376 |
-
if (!function_exists ('fetch_rss'))
|
377 |
-
{
|
378 |
-
if (!file_exists (ABSPATH.'wp-includes/rss.php'))
|
379 |
-
return '';
|
380 |
-
include (ABSPATH.'wp-includes/rss.php');
|
381 |
-
}
|
382 |
|
383 |
-
$now = time ();
|
384 |
-
|
385 |
-
$checked = get_option ('plugin_urbangiraffe_rss');
|
386 |
-
|
387 |
-
// Use built-in Magpie caching
|
388 |
-
if (function_exists ('fetch_rss') && (!isset ($checked[$this->plugin_name]) || $now > $checked[$this->plugin_name] + ($days * 24 * 60 * 60)))
|
389 |
-
{
|
390 |
-
$rss = fetch_rss ($url);
|
391 |
-
if (count ($rss->items) > 0)
|
392 |
-
{
|
393 |
-
foreach ($rss->items AS $pos => $item)
|
394 |
-
{
|
395 |
-
if (isset ($checked[$this->plugin_name]) && strtotime ($item['pubdate']) < $checked[$this->plugin_name])
|
396 |
-
unset ($rss->items[$pos]);
|
397 |
-
}
|
398 |
-
}
|
399 |
-
|
400 |
-
$checked[$this->plugin_name] = $now;
|
401 |
-
update_option ('plugin_urbangiraffe_rss', $checked);
|
402 |
-
return $rss;
|
403 |
-
}
|
404 |
-
}
|
405 |
-
|
406 |
-
|
407 |
-
/**
|
408 |
-
* Version of realpath that will work on systems without realpath
|
409 |
-
*
|
410 |
-
* @param string $path The path to canonicalize
|
411 |
-
* @return string Canonicalized path
|
412 |
-
**/
|
413 |
-
|
414 |
-
function realpath ($path)
|
415 |
-
{
|
416 |
-
if (function_exists ('realpath'))
|
417 |
-
return realpath ($path);
|
418 |
-
else if (DIRECTORY_SEPARATOR == '/')
|
419 |
-
{
|
420 |
-
$path = preg_replace ('/^~/', $_SERVER['DOCUMENT_ROOT'], $path);
|
421 |
-
|
422 |
-
// canonicalize
|
423 |
-
$path = explode (DIRECTORY_SEPARATOR, $path);
|
424 |
-
$newpath = array ();
|
425 |
-
for ($i = 0; $i < sizeof ($path); $i++)
|
426 |
-
{
|
427 |
-
if ($path[$i] === '' || $path[$i] === '.')
|
428 |
-
continue;
|
429 |
-
|
430 |
-
if ($path[$i] === '..')
|
431 |
-
{
|
432 |
-
array_pop ($newpath);
|
433 |
-
continue;
|
434 |
-
}
|
435 |
-
|
436 |
-
array_push ($newpath, $path[$i]);
|
437 |
-
}
|
438 |
-
|
439 |
-
$finalpath = DIRECTORY_SEPARATOR.implode (DIRECTORY_SEPARATOR, $newpath);
|
440 |
-
return $finalpath;
|
441 |
-
}
|
442 |
-
|
443 |
-
return $path;
|
444 |
-
}
|
445 |
-
|
446 |
-
|
447 |
-
function checked ($item, $field = '')
|
448 |
-
{
|
449 |
-
if ($field && is_array ($item))
|
450 |
-
{
|
451 |
-
if (isset ($item[$field]) && $item[$field])
|
452 |
-
echo ' checked="checked"';
|
453 |
-
}
|
454 |
-
else if (!empty ($item))
|
455 |
-
echo ' checked="checked"';
|
456 |
-
}
|
457 |
-
|
458 |
-
function select ($items, $default = '')
|
459 |
-
{
|
460 |
-
if (count ($items) > 0)
|
461 |
-
{
|
462 |
-
foreach ($items AS $key => $value)
|
463 |
-
{
|
464 |
-
if (is_array ($value))
|
465 |
-
{
|
466 |
-
echo '<optgroup label="'.$key.'">';
|
467 |
-
foreach ($value AS $sub => $subvalue)
|
468 |
-
echo '<option value="'.$sub.'"'.($sub == $default ? ' selected="selected"' : '').'>'.$subvalue.'</option>';
|
469 |
-
echo '</optgroup>';
|
470 |
-
}
|
471 |
-
else
|
472 |
-
echo '<option value="'.$key.'"'.($key == $default ? ' selected="selected"' : '').'>'.$value.'</option>';
|
473 |
-
}
|
474 |
-
}
|
475 |
-
}
|
476 |
}
|
477 |
|
478 |
if (!function_exists ('pr'))
|
@@ -484,183 +343,3 @@ if (!function_exists ('pr'))
|
|
484 |
echo '</pre>';
|
485 |
}
|
486 |
}
|
487 |
-
|
488 |
-
if (!class_exists ('SR_Widget_Class'))
|
489 |
-
{
|
490 |
-
class SR_Widget_Class
|
491 |
-
{
|
492 |
-
function SR_Widget_Class ($name, $max = 1, $id = '', $args = '')
|
493 |
-
{
|
494 |
-
$this->name = $name;
|
495 |
-
$this->id = $id;
|
496 |
-
$this->widget_max = $max;
|
497 |
-
$this->args = $args;
|
498 |
-
|
499 |
-
if ($this->id == '')
|
500 |
-
$this->id = strtolower (preg_replace ('/[^A-Za-z]/', '-', $this->name));
|
501 |
-
|
502 |
-
$this->widget_available = 1;
|
503 |
-
if ($this->widget_max > 1)
|
504 |
-
{
|
505 |
-
$this->widget_available = get_option ('widget_available_'.$this->id ());
|
506 |
-
if ($this->widget_available === false)
|
507 |
-
$this->widget_available = 1;
|
508 |
-
}
|
509 |
-
|
510 |
-
add_action ('init', array (&$this, 'initialize'));
|
511 |
-
}
|
512 |
-
|
513 |
-
function initialize ()
|
514 |
-
{
|
515 |
-
// Compatability functions for WP 2.1
|
516 |
-
if (!function_exists ('wp_register_sidebar_widget'))
|
517 |
-
{
|
518 |
-
function wp_register_sidebar_widget ($id, $name, $output_callback, $classname = '')
|
519 |
-
{
|
520 |
-
register_sidebar_widget($name, $output_callback, $classname);
|
521 |
-
}
|
522 |
-
}
|
523 |
-
|
524 |
-
if (!function_exists ('wp_register_widget_control'))
|
525 |
-
{
|
526 |
-
function wp_register_widget_control($name, $control_callback, $width = 300, $height = 200)
|
527 |
-
{
|
528 |
-
register_widget_control($name, $control_callback, $width, $height);
|
529 |
-
}
|
530 |
-
}
|
531 |
-
|
532 |
-
if (function_exists ('wp_register_sidebar_widget'))
|
533 |
-
{
|
534 |
-
if ($this->widget_max > 1)
|
535 |
-
{
|
536 |
-
add_action ('sidebar_admin_setup', array (&$this, 'setup_save'));
|
537 |
-
add_action ('sidebar_admin_page', array (&$this, 'setup_display'));
|
538 |
-
}
|
539 |
-
|
540 |
-
$this->load_widgets ();
|
541 |
-
}
|
542 |
-
}
|
543 |
-
|
544 |
-
function load_widgets ()
|
545 |
-
{
|
546 |
-
for ($pos = 1; $pos <= $this->widget_max; $pos++)
|
547 |
-
{
|
548 |
-
wp_register_sidebar_widget ($this->id ($pos), $this->name ($pos), $pos <= $this->widget_available ? array (&$this, 'show_display') : '', $this->args (), $pos);
|
549 |
-
|
550 |
-
if ($this->has_config ())
|
551 |
-
wp_register_widget_control ($this->id ($pos), $this->name ($pos), $pos <= $this->widget_available ? array (&$this, 'show_config') : '', $this->args (), $pos);
|
552 |
-
}
|
553 |
-
}
|
554 |
-
|
555 |
-
function args ()
|
556 |
-
{
|
557 |
-
if ($this->args)
|
558 |
-
$args = $this->args;
|
559 |
-
else
|
560 |
-
$args = array ('classname' => '');
|
561 |
-
|
562 |
-
if ($this->description ())
|
563 |
-
$args['description'] = $this->description ();
|
564 |
-
return $args;
|
565 |
-
}
|
566 |
-
|
567 |
-
function description () { return ''; }
|
568 |
-
|
569 |
-
function name ($pos)
|
570 |
-
{
|
571 |
-
if ($this->widget_available > 1)
|
572 |
-
return $this->name.' ('.$pos.')';
|
573 |
-
return $this->name;
|
574 |
-
}
|
575 |
-
|
576 |
-
function id ($pos = 0)
|
577 |
-
{
|
578 |
-
if ($pos == 0)
|
579 |
-
return $this->id;
|
580 |
-
return $this->id.'-'.$pos;
|
581 |
-
}
|
582 |
-
|
583 |
-
function show_display ($args, $number = 1)
|
584 |
-
{
|
585 |
-
$config = get_option ('widget_config_'.$this->id ($number));
|
586 |
-
if ($config === false)
|
587 |
-
$config = array ();
|
588 |
-
|
589 |
-
$this->load ($config);
|
590 |
-
$this->display ($args);
|
591 |
-
}
|
592 |
-
|
593 |
-
function show_config ($position)
|
594 |
-
{
|
595 |
-
if (isset ($_POST['widget_config_save_'.$this->id ($position)]))
|
596 |
-
{
|
597 |
-
$data = $_POST[$this->id ()];
|
598 |
-
if (count ($data) > 0)
|
599 |
-
{
|
600 |
-
$newdata = array ();
|
601 |
-
foreach ($data AS $item => $values)
|
602 |
-
$newdata[$item] = $values[$position];
|
603 |
-
$data = $newdata;
|
604 |
-
}
|
605 |
-
|
606 |
-
update_option ('widget_config_'.$this->id ($position), $this->save ($data));
|
607 |
-
}
|
608 |
-
|
609 |
-
$options = get_option ('widget_config_'.$this->id ($position));
|
610 |
-
if ($options === false)
|
611 |
-
$options = array ();
|
612 |
-
|
613 |
-
$this->config ($options, $position);
|
614 |
-
echo '<input type="hidden" name="widget_config_save_'.$this->id ($position).'" value="1" />';
|
615 |
-
}
|
616 |
-
|
617 |
-
function has_config () { return false; }
|
618 |
-
function save ($data)
|
619 |
-
{
|
620 |
-
return array ();
|
621 |
-
}
|
622 |
-
|
623 |
-
function setup_save ()
|
624 |
-
{
|
625 |
-
if (isset ($_POST['widget_setup_save_'.$this->id ()]))
|
626 |
-
{
|
627 |
-
$this->widget_available = intval ($_POST['widget_setup_count_'.$this->id ()]);
|
628 |
-
if ($this->widget_available < 1)
|
629 |
-
$this->widget_available = 1;
|
630 |
-
else if ($this->widget_available > $this->widget_max)
|
631 |
-
$this->widget_available = $this->widget_max;
|
632 |
-
|
633 |
-
update_option ('widget_available_'.$this->id (), $this->widget_available);
|
634 |
-
|
635 |
-
$this->load_widgets ();
|
636 |
-
}
|
637 |
-
}
|
638 |
-
|
639 |
-
function config_name ($field, $pos)
|
640 |
-
{
|
641 |
-
return $this->id ().'['.$field.']['.$pos.']';
|
642 |
-
}
|
643 |
-
|
644 |
-
function setup_display ()
|
645 |
-
{
|
646 |
-
?>
|
647 |
-
<div class="wrap">
|
648 |
-
<form method="post">
|
649 |
-
<h2><?php echo $this->name ?></h2>
|
650 |
-
<p style="line-height: 30px;"><?php _e('How many widgets would you like?', $this->id); ?>
|
651 |
-
<select name="widget_setup_count_<?php echo $this->id () ?>" value="<?php echo $options; ?>">
|
652 |
-
<?php for ( $i = 1; $i <= $this->widget_max; ++$i ) : ?>
|
653 |
-
<option value="<?php echo $i ?>"<?php if ($this->widget_available == $i) echo ' selected="selected"' ?>><?php echo $i ?></option>
|
654 |
-
<?php endfor; ?>
|
655 |
-
</select>
|
656 |
-
<span class="submit">
|
657 |
-
<input type="submit" name="widget_setup_save_<?php echo $this->id () ?>" value="<?php echo attribute_escape(__('Save', $this->id)); ?>" />
|
658 |
-
</span>
|
659 |
-
</p>
|
660 |
-
</form>
|
661 |
-
</div>
|
662 |
-
<?php
|
663 |
-
}
|
664 |
-
}
|
665 |
-
}
|
666 |
-
?>
|
5 |
// modify it under the terms of the GNU Lesser General Public
|
6 |
// License as published by the Free Software Foundation; either
|
7 |
// version 2.1 of the License, or (at your option) any later version.
|
8 |
+
//
|
9 |
// This library is distributed in the hope that it will be useful,
|
10 |
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
11 |
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
47 |
* The class uses a similar technique to Ruby On Rails views, whereby the display HTML is kept
|
48 |
* in a separate directory and file from the main code. A display is 'rendered' (sent to the browser)
|
49 |
* or 'captured' (returned to the calling function).
|
50 |
+
*
|
51 |
* Template files are separated into two areas: admin and user. Admin templates are only for display in
|
52 |
* the WordPress admin interface, while user templates are typically for display on the site (although neither
|
53 |
* of these are enforced). All templates are PHP code, but are referred to without .php extension.
|
54 |
+
*
|
55 |
* The reason for this separation is that one golden rule of plugin creation is that someone will always want to change
|
56 |
* the formatting and style of your output. Rather than forcing them to modify the plugin (bad), or modify files within
|
57 |
* the plugin (equally bad), the class allows user templates to be overridden with files contained within the theme.
|
58 |
*
|
59 |
* An additional benefit is that it leads to code re-use, especially with regards to Ajax (i.e. your display code can be called from
|
60 |
* many locations)
|
61 |
+
*
|
62 |
* Template files are located within the 'view' subdirectory of the plugins base (specified when registering the plugin):
|
63 |
+
*
|
64 |
* <pre>myplugin/view/admin
|
65 |
* myplugin/view/myplugin</pre>
|
66 |
+
*
|
67 |
* Admin templates are contained within 'admin', and user templates are contained within a directory of the same name as the plugin.
|
68 |
+
*
|
69 |
* User files can be overridden within the theme by creating a similar directory structure:
|
70 |
+
*
|
71 |
* <pre>/themes/mytheme/view/myplugin</pre>
|
72 |
+
*
|
73 |
* The class will first look in the theme and then defaults to the plugin. A plugin should always provide default templates.
|
74 |
+
*
|
75 |
* <h4>Display Parameters</h4>
|
76 |
* Also similar to Ruby On Rails, when you display a template you must supply the parameters that the template has access to. This tries
|
77 |
* to ensure a very clean separation between code and display. Parameters are supplied as an associative array mapping variable name to variable value.
|
78 |
+
*
|
79 |
* For example,
|
80 |
+
*
|
81 |
* array ('message' => 'Your data was processed', 'items' => 103);
|
82 |
*
|
83 |
* <h4>How it works in practice</h4>
|
84 |
* You create a template file to display how many items have been processed. You store this in 'view/admin/processed.php':
|
85 |
*
|
86 |
* <pre><p>You processed <?php echo $items ?> items</p></pre>
|
87 |
+
*
|
88 |
* When you want to display this in your plugin you use:
|
89 |
*
|
90 |
* <pre> $this->render_admin ('processed', array ('items' => 100));
|
101 |
* @var string
|
102 |
**/
|
103 |
var $plugin_name;
|
104 |
+
|
105 |
/**
|
106 |
* Plugin 'view' directory
|
107 |
* @var string Directory
|
108 |
**/
|
109 |
var $plugin_base;
|
110 |
+
|
111 |
+
|
112 |
/**
|
113 |
* Register your plugin with a name and base directory. This <strong>must</strong> be called once.
|
114 |
*
|
116 |
* @param string $base Directory containing the plugin's 'view' files.
|
117 |
* @return void
|
118 |
**/
|
119 |
+
|
120 |
function register_plugin ($name, $base)
|
121 |
{
|
122 |
$this->plugin_base = rtrim (dirname ($base), '/');
|
124 |
|
125 |
$this->add_action ('init', 'load_locale');
|
126 |
}
|
127 |
+
|
128 |
function load_locale ()
|
129 |
{
|
130 |
// Here we manually fudge the plugin locale as WP doesnt allow many options
|
135 |
$mofile = dirname (__FILE__)."/locale/$locale.mo";
|
136 |
load_textdomain ($this->plugin_name, $mofile);
|
137 |
}
|
138 |
+
|
139 |
+
|
140 |
/**
|
141 |
* Register a WordPress action and map it back to the calling object
|
142 |
*
|
146 |
* @param int $accepted_args Number of arguments the function accepts (optional)
|
147 |
* @return void
|
148 |
**/
|
149 |
+
|
150 |
function add_action ($action, $function = '', $priority = 10, $accepted_args = 1)
|
151 |
{
|
152 |
add_action ($action, array (&$this, $function == '' ? $action : $function), $priority, $accepted_args);
|
162 |
* @param int $accepted_args Number of arguments the function accepts (optional)
|
163 |
* @return void
|
164 |
**/
|
165 |
+
|
166 |
function add_filter ($filter, $function = '', $priority = 10, $accepted_args = 1)
|
167 |
{
|
168 |
add_filter ($filter, array (&$this, $function == '' ? $filter : $function), $priority, $accepted_args);
|
176 |
* @param string $function Optional function name, or default to 'activate'
|
177 |
* @return void
|
178 |
**/
|
179 |
+
|
180 |
function register_activation ($pluginfile, $function = '')
|
181 |
{
|
182 |
add_action ('activate_'.basename (dirname ($pluginfile)).'/'.basename ($pluginfile), array (&$this, $function == '' ? 'activate' : $function));
|
183 |
}
|
184 |
+
|
185 |
+
|
186 |
/**
|
187 |
* Special deactivation function that takes into account the plugin directory
|
188 |
*
|
190 |
* @param string $function Optional function name, or default to 'deactivate'
|
191 |
* @return void
|
192 |
**/
|
193 |
+
|
194 |
function register_deactivation ($pluginfile, $function = '')
|
195 |
{
|
196 |
add_action ('deactivate_'.basename (dirname ($pluginfile)).'/'.basename ($pluginfile), array (&$this, $function == '' ? 'deactivate' : $function));
|
197 |
}
|
198 |
+
|
199 |
+
|
200 |
/**
|
201 |
* Renders an admin section of display code
|
202 |
*
|
204 |
* @param string $array Array of variable name=>value that is available to the display code (optional)
|
205 |
* @return void
|
206 |
**/
|
207 |
+
|
208 |
function render_admin ($ug_name, $ug_vars = array ())
|
209 |
{
|
210 |
global $plugin_base;
|
226 |
* @param string $array Array of variable name=>value that is available to the display code (optional)
|
227 |
* @return void
|
228 |
**/
|
229 |
+
|
230 |
function render ($ug_name, $ug_vars = array ())
|
231 |
{
|
232 |
foreach ($ug_vars AS $key => $val)
|
239 |
else
|
240 |
echo "<p>Rendering of template $ug_name.php failed</p>";
|
241 |
}
|
242 |
+
|
243 |
+
|
244 |
/**
|
245 |
* Renders a section of user display code. The code is first checked for in the current theme display directory
|
246 |
* before defaulting to the plugin
|
258 |
ob_end_clean ();
|
259 |
return $output;
|
260 |
}
|
261 |
+
|
262 |
|
263 |
/**
|
264 |
* Captures an admin section of display code
|
276 |
ob_end_clean ();
|
277 |
return $output;
|
278 |
}
|
279 |
+
|
280 |
+
function select ($items, $default = '')
|
281 |
+
{
|
282 |
+
if (count ($items) > 0)
|
283 |
+
{
|
284 |
+
foreach ($items AS $key => $value)
|
285 |
+
{
|
286 |
+
if (is_array ($value))
|
287 |
+
{
|
288 |
+
echo '<optgroup label="'.$key.'">';
|
289 |
+
foreach ($value AS $sub => $subvalue)
|
290 |
+
echo '<option value="'.esc_attr( $sub ).'"'.($sub == $default ? ' selected="selected"' : '').'>'.esc_html( $subvalue ).'</option>';
|
291 |
+
echo '</optgroup>';
|
292 |
+
}
|
293 |
+
else
|
294 |
+
echo '<option value="'.esc_attr( $key ).'"'.($key == $default ? ' selected="selected"' : '').'>'.esc_html( $value ).'</option>';
|
295 |
+
}
|
296 |
+
}
|
297 |
+
}
|
298 |
+
|
299 |
/**
|
300 |
* Display a standard error message (using CSS ID 'message' and classes 'fade' and 'error)
|
301 |
*
|
302 |
* @param string $message Message to display
|
303 |
* @return void
|
304 |
**/
|
305 |
+
|
306 |
function render_error ($message)
|
307 |
{
|
308 |
?>
|
311 |
</div>
|
312 |
<?php
|
313 |
}
|
314 |
+
|
315 |
+
|
316 |
/**
|
317 |
* Display a standard notice (using CSS ID 'message' and class 'updated').
|
318 |
* Note that the notice can be made to automatically disappear, and can be removed
|
322 |
* @param int $timeout Number of seconds to automatically remove the message (optional)
|
323 |
* @return void
|
324 |
**/
|
325 |
+
|
326 |
function render_message ($message, $timeout = 0)
|
327 |
{
|
328 |
?>
|
329 |
<div class="updated" id="message" onclick="this.parentNode.removeChild (this)">
|
330 |
<p><?php echo $message ?></p>
|
331 |
</div>
|
332 |
+
<?php
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
333 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
334 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
335 |
}
|
336 |
|
337 |
if (!function_exists ('pr'))
|
343 |
echo '</pre>';
|
344 |
}
|
345 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
readme.txt
CHANGED
@@ -3,7 +3,7 @@ Contributors: johnny5
|
|
3 |
Donate link: http://urbangiraffe.com/about/support/
|
4 |
Tags: search, regex, regular expression, admin, post, page
|
5 |
Requires at least: 2.0
|
6 |
-
Tested up to: 3.
|
7 |
Stable tag: trunk
|
8 |
|
9 |
Search Regex adds a powerful set of search and replace functions to WordPress that go beyond the standard searching capabilities, with full regex support.
|
@@ -45,6 +45,9 @@ Full documentation can be found on the [Search Regex Page](http://urbangiraffe.c
|
|
45 |
|
46 |
== Changelog ==
|
47 |
|
|
|
|
|
|
|
48 |
= 1.4.11 =
|
49 |
* Add Arabic translation
|
50 |
|
@@ -54,41 +57,41 @@ Full documentation can be found on the [Search Regex Page](http://urbangiraffe.c
|
|
54 |
= 1.4.9 =
|
55 |
* WP 2.8 compatibility
|
56 |
|
57 |
-
= 1.4.8 =
|
58 |
* Update base library
|
59 |
* Fix issue with regex not being selected
|
60 |
|
61 |
-
= 1.4.7 =
|
62 |
* WP 2.6
|
63 |
-
= 1.4.6 =
|
64 |
* Added tag & sniplet searching.
|
65 |
* Make work in Safari
|
66 |
|
67 |
-
= 1.4.5 =
|
68 |
* Add search regex capabilities ('search_regex_read' and 'search_regex_write').
|
69 |
* Fix meta values
|
70 |
|
71 |
-
= 1.4.4 =
|
72 |
* Fix escaping issue
|
73 |
* Allowing search limit and direction
|
74 |
|
75 |
-
= 1.4.3 =
|
76 |
* Allow searching in pings & trackbacks
|
77 |
|
78 |
-
= 1.4.2 =
|
79 |
* Fix escaping bug
|
80 |
|
81 |
-
= 1.4 =
|
82 |
* Extensible plugins
|
83 |
* Reorganisation of code
|
84 |
|
85 |
-
= 1.3 =
|
86 |
* Use correct table prefix
|
87 |
|
88 |
-
= 1.2 =
|
89 |
* Fix stupid typo
|
90 |
|
91 |
-
= 1.1 =
|
92 |
* Minor cosmetic changes
|
93 |
* Set a timeout limit
|
94 |
|
3 |
Donate link: http://urbangiraffe.com/about/support/
|
4 |
Tags: search, regex, regular expression, admin, post, page
|
5 |
Requires at least: 2.0
|
6 |
+
Tested up to: 3.4
|
7 |
Stable tag: trunk
|
8 |
|
9 |
Search Regex adds a powerful set of search and replace functions to WordPress that go beyond the standard searching capabilities, with full regex support.
|
45 |
|
46 |
== Changelog ==
|
47 |
|
48 |
+
= 1.4.13 =
|
49 |
+
* Code cleanup
|
50 |
+
|
51 |
= 1.4.11 =
|
52 |
* Add Arabic translation
|
53 |
|
57 |
= 1.4.9 =
|
58 |
* WP 2.8 compatibility
|
59 |
|
60 |
+
= 1.4.8 =
|
61 |
* Update base library
|
62 |
* Fix issue with regex not being selected
|
63 |
|
64 |
+
= 1.4.7 =
|
65 |
* WP 2.6
|
66 |
+
= 1.4.6 =
|
67 |
* Added tag & sniplet searching.
|
68 |
* Make work in Safari
|
69 |
|
70 |
+
= 1.4.5 =
|
71 |
* Add search regex capabilities ('search_regex_read' and 'search_regex_write').
|
72 |
* Fix meta values
|
73 |
|
74 |
+
= 1.4.4 =
|
75 |
* Fix escaping issue
|
76 |
* Allowing search limit and direction
|
77 |
|
78 |
+
= 1.4.3 =
|
79 |
* Allow searching in pings & trackbacks
|
80 |
|
81 |
+
= 1.4.2 =
|
82 |
* Fix escaping bug
|
83 |
|
84 |
+
= 1.4 =
|
85 |
* Extensible plugins
|
86 |
* Reorganisation of code
|
87 |
|
88 |
+
= 1.3 =
|
89 |
* Use correct table prefix
|
90 |
|
91 |
+
= 1.2 =
|
92 |
* Fix stupid typo
|
93 |
|
94 |
+
= 1.1 =
|
95 |
* Minor cosmetic changes
|
96 |
* Set a timeout limit
|
97 |
|
search-regex.php
CHANGED
@@ -4,101 +4,104 @@ Plugin Name: Search Regex
|
|
4 |
Plugin URI: http://urbangiraffe.com/plugins/search-regex
|
5 |
Description: Adds search & replace functionality across posts, pages, comments, and meta-data, with full regular expression support
|
6 |
Author: John Godley
|
7 |
-
Version: 1.4.
|
8 |
Author URI: http://urbangiraffe.com/
|
9 |
*/
|
10 |
|
11 |
-
include (
|
12 |
-
|
13 |
-
class SearchRegex extends SearchRegex_Plugin
|
14 |
-
{
|
15 |
-
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
-
include (dirname (__FILE__).'/models/search.php');
|
20 |
-
include (dirname (__FILE__).'/models/result.php');
|
21 |
-
|
22 |
-
$this->register_plugin ('search-regex', __FILE__);
|
23 |
-
$this->add_filter ('admin_menu');
|
24 |
-
|
25 |
-
if (strstr ($_SERVER['REQUEST_URI'], 'search-regex.php'))
|
26 |
-
{
|
27 |
-
wp_enqueue_script ('prototype');
|
28 |
-
wp_enqueue_script ('scriptaculous');
|
29 |
-
$this->add_filter ('admin_head');
|
30 |
-
}
|
31 |
}
|
32 |
}
|
33 |
-
|
34 |
-
function
|
35 |
-
|
36 |
-
|
37 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
38 |
$search_pattern = $replace_pattern = '';
|
39 |
-
if (isset
|
40 |
$search_pattern = stripslashes( $_POST['search_pattern'] );
|
41 |
-
|
|
|
42 |
$replace_pattern = stripslashes( $_POST['replace_pattern'] );
|
43 |
|
44 |
-
$search_pattern = str_replace
|
45 |
-
$replace_pattern = str_replace
|
46 |
-
$orderby =
|
47 |
-
|
48 |
-
$
|
49 |
-
|
|
|
|
|
|
|
50 |
$source = isset( $_POST['source'] ) ? stripslashes( $_POST['source'] ) : '';
|
51 |
-
|
52 |
-
if (Search::valid_search
|
53 |
-
|
54 |
-
$klass = stripslashes( $_POST['source'] );
|
55 |
$searcher = new $klass;
|
56 |
-
|
57 |
-
|
58 |
-
|
|
|
59 |
// Make sure no one sneaks in with a replace
|
60 |
-
if (!current_user_can
|
61 |
-
|
62 |
-
unset
|
63 |
-
unset ($_POST['replace_and_save']);
|
64 |
$_POST['search'] = 'search';
|
65 |
}
|
66 |
-
|
67 |
$results = array();
|
68 |
-
|
69 |
-
|
70 |
-
|
71 |
-
|
72 |
-
|
73 |
-
|
74 |
-
|
75 |
-
|
76 |
-
|
77 |
-
|
78 |
-
|
79 |
-
|
80 |
-
|
81 |
-
|
82 |
-
|
83 |
-
|
|
|
84 |
}
|
85 |
else
|
86 |
-
$this->render_admin
|
87 |
}
|
88 |
-
|
89 |
-
function admin_menu
|
90 |
-
|
91 |
-
|
92 |
-
|
93 |
-
|
94 |
-
|
|
|
|
|
|
|
95 |
}
|
96 |
-
|
97 |
-
function
|
98 |
-
|
99 |
-
|
|
|
|
|
|
|
100 |
}
|
101 |
}
|
102 |
|
103 |
$search_regex = new SearchRegex;
|
104 |
-
?>
|
4 |
Plugin URI: http://urbangiraffe.com/plugins/search-regex
|
5 |
Description: Adds search & replace functionality across posts, pages, comments, and meta-data, with full regular expression support
|
6 |
Author: John Godley
|
7 |
+
Version: 1.4.13
|
8 |
Author URI: http://urbangiraffe.com/
|
9 |
*/
|
10 |
|
11 |
+
include dirname( __FILE__ ).'/plugin.php';
|
12 |
+
|
13 |
+
class SearchRegex extends SearchRegex_Plugin {
|
14 |
+
function SearchRegex() {
|
15 |
+
if ( is_admin()) {
|
16 |
+
$this->register_plugin( 'search-regex', __FILE__ );
|
17 |
+
$this->add_filter( 'admin_menu' );
|
18 |
+
$this->add_action( 'load-tools_page_search-regex', 'search_head' );
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
19 |
}
|
20 |
}
|
21 |
+
|
22 |
+
function search_head() {
|
23 |
+
include dirname( __FILE__ ).'/models/search.php';
|
24 |
+
include dirname( __FILE__ ).'/models/result.php';
|
25 |
+
|
26 |
+
wp_enqueue_style( 'search-regex', plugin_dir_url( __FILE__ ).'admin.css', $this->version() );
|
27 |
+
}
|
28 |
+
|
29 |
+
function admin_screen() {
|
30 |
+
$searches = Search::get_searches();
|
31 |
+
|
32 |
$search_pattern = $replace_pattern = '';
|
33 |
+
if ( isset( $_POST['search_pattern'] ) )
|
34 |
$search_pattern = stripslashes( $_POST['search_pattern'] );
|
35 |
+
|
36 |
+
if ( isset( $_POST['replace_pattern'] ) )
|
37 |
$replace_pattern = stripslashes( $_POST['replace_pattern'] );
|
38 |
|
39 |
+
$search_pattern = str_replace( "\'", "'", $search_pattern );
|
40 |
+
$replace_pattern = str_replace( "\'", "'", $replace_pattern );
|
41 |
+
$orderby = 'asc';
|
42 |
+
|
43 |
+
if ( isset( $_POST['orderby'] ) && $_POST['orderby'] == 'desc' )
|
44 |
+
$orderby = 'desc';
|
45 |
+
|
46 |
+
$limit = isset( $_POST['limit'] ) ? intval( $_POST['limit'] ) : 10;
|
47 |
+
$offset = 0;
|
48 |
$source = isset( $_POST['source'] ) ? stripslashes( $_POST['source'] ) : '';
|
49 |
+
|
50 |
+
if ( Search::valid_search( $source ) && ( isset( $_POST['search'] ) || isset( $_POST['replace'] ) || isset( $_POST['replace_and_save'] ) ) ) {
|
51 |
+
$klass = stripslashes( $source );
|
|
|
52 |
$searcher = new $klass;
|
53 |
+
|
54 |
+
if ( isset( $_POST['regex'] ) )
|
55 |
+
$searcher->set_regex_options( $_POST['dotall'], $_POST['case'], $_POST['multi'] );
|
56 |
+
|
57 |
// Make sure no one sneaks in with a replace
|
58 |
+
if ( !current_user_can( 'administrator' ) && !current_user_can( 'search_regex_write' ) ) {
|
59 |
+
unset( $_POST['replace'] );
|
60 |
+
unset( $_POST['replace_and_save'] );
|
|
|
61 |
$_POST['search'] = 'search';
|
62 |
}
|
63 |
+
|
64 |
$results = array();
|
65 |
+
|
66 |
+
if ( isset( $_POST['search'] ) )
|
67 |
+
$results = $searcher->search_for_pattern( $search_pattern, $limit, $offset, $orderby );
|
68 |
+
elseif ( isset( $_POST['replace'] ) )
|
69 |
+
$results = $searcher->search_and_replace( $search_pattern, $replace_pattern, $limit, $offset, $orderby );
|
70 |
+
elseif ( isset( $_POST['replace_and_save'] ) )
|
71 |
+
$results = $searcher->search_and_replace( $search_pattern, $replace_pattern, $limit, $offset, $orderby, true );
|
72 |
+
|
73 |
+
if ( !is_array( $results ) )
|
74 |
+
$this->render_error( $results );
|
75 |
+
elseif ( isset( $_POST['replace_and_save'] ) )
|
76 |
+
$this->render_message( sprintf( '%d occurrence(s) replaced', count( $results ) ) );
|
77 |
+
|
78 |
+
$this->render_admin( 'search', array( 'search' => $search_pattern, 'replace' => $replace_pattern, 'searches' => $searches, 'source' => $source ) );
|
79 |
+
|
80 |
+
if ( is_array( $results ) && !isset( $_POST['replace_and_save'] ) )
|
81 |
+
$this->render_admin( 'results', array( 'search' => $searcher, 'results' => $results ) );
|
82 |
}
|
83 |
else
|
84 |
+
$this->render_admin( 'search', array( 'search' => $search_pattern, 'replace' => $replace_pattern, 'searches' => $searches, 'source' => $source ) );
|
85 |
}
|
86 |
+
|
87 |
+
function admin_menu() {
|
88 |
+
if ( current_user_can( 'administrator' ) )
|
89 |
+
add_management_page( __( "Search Regex", 'search-regex' ), __( "Search Regex", 'search-regex' ), 'administrator', basename(__FILE__), array( &$this, 'admin_screen' ) );
|
90 |
+
elseif ( current_user_can('search_regex_read'))
|
91 |
+
add_management_page( __( "Search Regex", 'search-regex' ), __( "Search Regex", 'search-regex' ), 'search_regex_read', basename(__FILE__), array( &$this, 'admin_screen' ) );
|
92 |
+
}
|
93 |
+
|
94 |
+
function base_url() {
|
95 |
+
return __FILE__;
|
96 |
}
|
97 |
+
|
98 |
+
function version() {
|
99 |
+
$plugin_data = implode( '', file( __FILE__ ) );
|
100 |
+
|
101 |
+
if ( preg_match( '|Version:(.*)|i', $plugin_data, $version ) )
|
102 |
+
return trim( $version[1] );
|
103 |
+
return '';
|
104 |
}
|
105 |
}
|
106 |
|
107 |
$search_regex = new SearchRegex;
|
|
searches/comment_author.php
CHANGED
@@ -10,9 +10,9 @@ class SearchCommentAuthor extends Search
|
|
10 |
$order = 'comment_ID ASC';
|
11 |
else
|
12 |
$order = 'comment_date DESC';
|
13 |
-
|
14 |
$results = array ();
|
15 |
-
$comments = $wpdb->get_results ("SELECT {$wpdb->comments}.comment_ID AS comment_ID, {$wpdb->comments}.comment_post_ID AS comment_post_ID, {$wpdb->comments}.comment_author AS comment_author, {$wpdb->posts}.post_title AS post_title FROM {$wpdb->comments},{$wpdb->posts} WHERE {$wpdb->comments}.comment_approved='1' AND {$wpdb->posts}.ID={$wpdb->comments}.comment_post_ID ORDER BY {$wpdb->comments}.comment_ID $orderby LIMIT $offset,$limit
|
16 |
if (count ($comments) > 0)
|
17 |
{
|
18 |
foreach ($comments AS $comment)
|
@@ -24,7 +24,7 @@ class SearchCommentAuthor extends Search
|
|
24 |
$match->sub_id = $comment->comment_post_ID;
|
25 |
$match->title = $comment->post_title;
|
26 |
}
|
27 |
-
|
28 |
$results = array_merge ($results, $matches);
|
29 |
}
|
30 |
}
|
@@ -32,40 +32,37 @@ class SearchCommentAuthor extends Search
|
|
32 |
|
33 |
return $results;
|
34 |
}
|
35 |
-
|
36 |
function get_options ($result)
|
37 |
{
|
38 |
$options[] = '<a href="'.get_permalink ($result->sub_id).'">'.__ ('view post', 'search-regex').'</a>';
|
39 |
if ($result->replace)
|
40 |
$options[] = '<a href="#" onclick="regex_replace (\'SearchCommentAuthor\','.$result->id.','.$result->offset.','.$result->length.',\''.str_replace ("'", "\'", $result->replace_string).'\'); return false">replace</a>';
|
41 |
-
|
42 |
if (current_user_can ('edit_post', $result->id))
|
43 |
$options[] = '<a href="'.get_bloginfo ('wpurl').'/wp-admin/comment.php?action=editcomment&c='.$result->id.'">'.__ ('edit','search-regex').'</a>';
|
44 |
return $options;
|
45 |
}
|
46 |
-
|
47 |
function show ($result)
|
48 |
{
|
49 |
printf (__ ('Comment #%d: %s', 'search-regex'), $result->id, $result->title);
|
50 |
}
|
51 |
-
|
52 |
function name () { return __ ('Comment author', 'search-regex'); }
|
53 |
|
54 |
function get_content ($id)
|
55 |
{
|
56 |
global $wpdb;
|
57 |
|
58 |
-
$row = $wpdb->get_row ("SELECT comment_author FROM {$wpdb->comments} WHERE comment_ID
|
59 |
return $row->comment_content;
|
60 |
}
|
61 |
-
|
62 |
function replace_content ($id, $content)
|
63 |
{
|
64 |
global $wpdb;
|
65 |
-
$
|
66 |
-
$wpdb->query ("UPDATE {$wpdb->comments} SET comment_author='{$content}' WHERE comment_ID='$id'");
|
67 |
}
|
68 |
}
|
69 |
|
70 |
-
|
71 |
-
?>
|
10 |
$order = 'comment_ID ASC';
|
11 |
else
|
12 |
$order = 'comment_date DESC';
|
13 |
+
|
14 |
$results = array ();
|
15 |
+
$comments = $wpdb->get_results ($wpdb->prepare( "SELECT {$wpdb->comments}.comment_ID AS comment_ID, {$wpdb->comments}.comment_post_ID AS comment_post_ID, {$wpdb->comments}.comment_author AS comment_author, {$wpdb->posts}.post_title AS post_title FROM {$wpdb->comments},{$wpdb->posts} WHERE {$wpdb->comments}.comment_approved='1' AND {$wpdb->posts}.ID={$wpdb->comments}.comment_post_ID ORDER BY {$wpdb->comments}.comment_ID $orderby LIMIT %d,%d", $offset,$limit ) );
|
16 |
if (count ($comments) > 0)
|
17 |
{
|
18 |
foreach ($comments AS $comment)
|
24 |
$match->sub_id = $comment->comment_post_ID;
|
25 |
$match->title = $comment->post_title;
|
26 |
}
|
27 |
+
|
28 |
$results = array_merge ($results, $matches);
|
29 |
}
|
30 |
}
|
32 |
|
33 |
return $results;
|
34 |
}
|
35 |
+
|
36 |
function get_options ($result)
|
37 |
{
|
38 |
$options[] = '<a href="'.get_permalink ($result->sub_id).'">'.__ ('view post', 'search-regex').'</a>';
|
39 |
if ($result->replace)
|
40 |
$options[] = '<a href="#" onclick="regex_replace (\'SearchCommentAuthor\','.$result->id.','.$result->offset.','.$result->length.',\''.str_replace ("'", "\'", $result->replace_string).'\'); return false">replace</a>';
|
41 |
+
|
42 |
if (current_user_can ('edit_post', $result->id))
|
43 |
$options[] = '<a href="'.get_bloginfo ('wpurl').'/wp-admin/comment.php?action=editcomment&c='.$result->id.'">'.__ ('edit','search-regex').'</a>';
|
44 |
return $options;
|
45 |
}
|
46 |
+
|
47 |
function show ($result)
|
48 |
{
|
49 |
printf (__ ('Comment #%d: %s', 'search-regex'), $result->id, $result->title);
|
50 |
}
|
51 |
+
|
52 |
function name () { return __ ('Comment author', 'search-regex'); }
|
53 |
|
54 |
function get_content ($id)
|
55 |
{
|
56 |
global $wpdb;
|
57 |
|
58 |
+
$row = $wpdb->get_row ($wpdb->prepare( "SELECT comment_author FROM {$wpdb->comments} WHERE comment_ID=%d", $id ) );
|
59 |
return $row->comment_content;
|
60 |
}
|
61 |
+
|
62 |
function replace_content ($id, $content)
|
63 |
{
|
64 |
global $wpdb;
|
65 |
+
$wpdb->query ($wpdb->prepare( "UPDATE {$wpdb->comments} SET comment_author=%s WHERE comment_ID=%d", $content, $id ) );
|
|
|
66 |
}
|
67 |
}
|
68 |
|
|
|
|
searches/comment_author_email.php
CHANGED
@@ -10,9 +10,9 @@ class SearchCommentAuthorEmail extends Search
|
|
10 |
$order = 'comment_ID ASC';
|
11 |
else
|
12 |
$order = 'comment_date DESC';
|
13 |
-
|
14 |
$results = array ();
|
15 |
-
$comments = $wpdb->get_results ("SELECT {$wpdb->comments}.comment_ID AS comment_ID, {$wpdb->comments}.comment_post_ID AS comment_post_ID, {$wpdb->comments}.comment_author_email AS comment_author_email, {$wpdb->posts}.post_title AS post_title FROM {$wpdb->comments},{$wpdb->posts} WHERE {$wpdb->comments}.comment_approved='1' AND {$wpdb->posts}.ID={$wpdb->comments}.comment_post_ID ORDER BY {$wpdb->comments}.comment_ID $orderby LIMIT $offset,$limit
|
16 |
if (count ($comments) > 0)
|
17 |
{
|
18 |
foreach ($comments AS $comment)
|
@@ -24,7 +24,7 @@ class SearchCommentAuthorEmail extends Search
|
|
24 |
$match->sub_id = $comment->comment_post_ID;
|
25 |
$match->title = $comment->post_title;
|
26 |
}
|
27 |
-
|
28 |
$results = array_merge ($results, $matches);
|
29 |
}
|
30 |
}
|
@@ -32,40 +32,36 @@ class SearchCommentAuthorEmail extends Search
|
|
32 |
|
33 |
return $results;
|
34 |
}
|
35 |
-
|
36 |
function get_options ($result)
|
37 |
{
|
38 |
$options[] = '<a href="'.get_permalink ($result->sub_id).'">'.__ ('view post', 'search-regex').'</a>';
|
39 |
if ($result->replace)
|
40 |
$options[] = '<a href="#" onclick="regex_replace (\'SearchCommentAuthorEmail\','.$result->id.','.$result->offset.','.$result->length.',\''.str_replace ("'", "\'", $result->replace_string).'\'); return false">replace</a>';
|
41 |
-
|
42 |
if (current_user_can ('edit_post', $result->id))
|
43 |
$options[] = '<a href="'.get_bloginfo ('wpurl').'/wp-admin/comment.php?action=editcomment&c='.$result->id.'">'.__ ('edit','search-regex').'</a>';
|
44 |
return $options;
|
45 |
}
|
46 |
-
|
47 |
function show ($result)
|
48 |
{
|
49 |
printf (__ ('Comment #%d: %s', 'search-regex'), $result->id, $result->title);
|
50 |
}
|
51 |
-
|
52 |
function name () { return __ ('Comment author email', 'search-regex'); }
|
53 |
|
54 |
function get_content ($id)
|
55 |
{
|
56 |
global $wpdb;
|
57 |
|
58 |
-
$row = $wpdb->get_row ("SELECT comment_author_email FROM {$wpdb->comments} WHERE comment_ID
|
59 |
return $row->comment_author_email;
|
60 |
}
|
61 |
-
|
62 |
function replace_content ($id, $content)
|
63 |
{
|
64 |
global $wpdb;
|
65 |
-
$
|
66 |
-
$wpdb->query ("UPDATE {$wpdb->comments} SET comment_author_email='{$content}' WHERE comment_ID='$id'");
|
67 |
}
|
68 |
}
|
69 |
-
|
70 |
-
|
71 |
-
?>
|
10 |
$order = 'comment_ID ASC';
|
11 |
else
|
12 |
$order = 'comment_date DESC';
|
13 |
+
|
14 |
$results = array ();
|
15 |
+
$comments = $wpdb->get_results ($wpdb->prepare( "SELECT {$wpdb->comments}.comment_ID AS comment_ID, {$wpdb->comments}.comment_post_ID AS comment_post_ID, {$wpdb->comments}.comment_author_email AS comment_author_email, {$wpdb->posts}.post_title AS post_title FROM {$wpdb->comments},{$wpdb->posts} WHERE {$wpdb->comments}.comment_approved='1' AND {$wpdb->posts}.ID={$wpdb->comments}.comment_post_ID ORDER BY {$wpdb->comments}.comment_ID $orderby LIMIT %d,%d", $offset,$limit ) );
|
16 |
if (count ($comments) > 0)
|
17 |
{
|
18 |
foreach ($comments AS $comment)
|
24 |
$match->sub_id = $comment->comment_post_ID;
|
25 |
$match->title = $comment->post_title;
|
26 |
}
|
27 |
+
|
28 |
$results = array_merge ($results, $matches);
|
29 |
}
|
30 |
}
|
32 |
|
33 |
return $results;
|
34 |
}
|
35 |
+
|
36 |
function get_options ($result)
|
37 |
{
|
38 |
$options[] = '<a href="'.get_permalink ($result->sub_id).'">'.__ ('view post', 'search-regex').'</a>';
|
39 |
if ($result->replace)
|
40 |
$options[] = '<a href="#" onclick="regex_replace (\'SearchCommentAuthorEmail\','.$result->id.','.$result->offset.','.$result->length.',\''.str_replace ("'", "\'", $result->replace_string).'\'); return false">replace</a>';
|
41 |
+
|
42 |
if (current_user_can ('edit_post', $result->id))
|
43 |
$options[] = '<a href="'.get_bloginfo ('wpurl').'/wp-admin/comment.php?action=editcomment&c='.$result->id.'">'.__ ('edit','search-regex').'</a>';
|
44 |
return $options;
|
45 |
}
|
46 |
+
|
47 |
function show ($result)
|
48 |
{
|
49 |
printf (__ ('Comment #%d: %s', 'search-regex'), $result->id, $result->title);
|
50 |
}
|
51 |
+
|
52 |
function name () { return __ ('Comment author email', 'search-regex'); }
|
53 |
|
54 |
function get_content ($id)
|
55 |
{
|
56 |
global $wpdb;
|
57 |
|
58 |
+
$row = $wpdb->get_row ($wpdb->prepare( "SELECT comment_author_email FROM {$wpdb->comments} WHERE comment_ID=%d", $id ) );
|
59 |
return $row->comment_author_email;
|
60 |
}
|
61 |
+
|
62 |
function replace_content ($id, $content)
|
63 |
{
|
64 |
global $wpdb;
|
65 |
+
$wpdb->query ($wpdb->prepare( "UPDATE {$wpdb->comments} SET comment_author_email=%s WHERE comment_ID=%d", $content, $id ) );
|
|
|
66 |
}
|
67 |
}
|
|
|
|
|
|
searches/comment_author_url.php
CHANGED
@@ -10,9 +10,9 @@ class SearchCommentAuthorURL extends Search
|
|
10 |
$order = 'comment_ID ASC';
|
11 |
else
|
12 |
$order = 'comment_date DESC';
|
13 |
-
|
14 |
$results = array ();
|
15 |
-
$comments = $wpdb->get_results ("SELECT {$wpdb->comments}.comment_ID AS comment_ID, {$wpdb->comments}.comment_post_ID AS comment_post_ID, {$wpdb->comments}.comment_author_url AS comment_author_url, {$wpdb->posts}.post_title AS post_title FROM {$wpdb->comments},{$wpdb->posts} WHERE {$wpdb->comments}.comment_approved='1' AND {$wpdb->posts}.ID={$wpdb->comments}.comment_post_ID ORDER BY {$wpdb->comments}.comment_ID $orderby LIMIT $offset,$limit
|
16 |
if (count ($comments) > 0)
|
17 |
{
|
18 |
foreach ($comments AS $comment)
|
@@ -24,7 +24,7 @@ class SearchCommentAuthorURL extends Search
|
|
24 |
$match->sub_id = $comment->comment_post_ID;
|
25 |
$match->title = $comment->post_title;
|
26 |
}
|
27 |
-
|
28 |
$results = array_merge ($results, $matches);
|
29 |
}
|
30 |
}
|
@@ -32,40 +32,36 @@ class SearchCommentAuthorURL extends Search
|
|
32 |
|
33 |
return $results;
|
34 |
}
|
35 |
-
|
36 |
function get_options ($result)
|
37 |
{
|
38 |
$options[] = '<a href="'.get_permalink ($result->sub_id).'">'.__ ('view post', 'search-regex').'</a>';
|
39 |
if ($result->replace)
|
40 |
$options[] = '<a href="#" onclick="regex_replace (\'SearchCommentAuthorURL\','.$result->id.','.$result->offset.','.$result->length.',\''.str_replace ("'", "\'", $result->replace_string).'\'); return false">replace</a>';
|
41 |
-
|
42 |
if (current_user_can ('edit_post', $result->id))
|
43 |
$options[] = '<a href="'.get_bloginfo ('wpurl').'/wp-admin/comment.php?action=editcomment&c='.$result->id.'">'.__ ('edit','search-regex').'</a>';
|
44 |
return $options;
|
45 |
}
|
46 |
-
|
47 |
function show ($result)
|
48 |
{
|
49 |
printf (__ ('Comment #%d: %s', 'search-regex'), $result->id, $result->title);
|
50 |
}
|
51 |
-
|
52 |
function name () { return __ ('Comment author URL', 'search-regex'); }
|
53 |
|
54 |
function get_content ($id)
|
55 |
{
|
56 |
global $wpdb;
|
57 |
|
58 |
-
$row = $wpdb->get_row ("SELECT comment_author_url FROM {$wpdb->comments} WHERE comment_ID
|
59 |
return $row->comment_author_url;
|
60 |
}
|
61 |
-
|
62 |
function replace_content ($id, $content)
|
63 |
{
|
64 |
global $wpdb;
|
65 |
-
$
|
66 |
-
$wpdb->query ("UPDATE {$wpdb->comments} SET comment_author_url='{$content}' WHERE comment_ID='$id'");
|
67 |
}
|
68 |
}
|
69 |
-
|
70 |
-
|
71 |
-
?>
|
10 |
$order = 'comment_ID ASC';
|
11 |
else
|
12 |
$order = 'comment_date DESC';
|
13 |
+
|
14 |
$results = array ();
|
15 |
+
$comments = $wpdb->get_results ($wpdb->prepare( "SELECT {$wpdb->comments}.comment_ID AS comment_ID, {$wpdb->comments}.comment_post_ID AS comment_post_ID, {$wpdb->comments}.comment_author_url AS comment_author_url, {$wpdb->posts}.post_title AS post_title FROM {$wpdb->comments},{$wpdb->posts} WHERE {$wpdb->comments}.comment_approved='1' AND {$wpdb->posts}.ID={$wpdb->comments}.comment_post_ID ORDER BY {$wpdb->comments}.comment_ID $orderby LIMIT %d,%d", $offset,$limit ) );
|
16 |
if (count ($comments) > 0)
|
17 |
{
|
18 |
foreach ($comments AS $comment)
|
24 |
$match->sub_id = $comment->comment_post_ID;
|
25 |
$match->title = $comment->post_title;
|
26 |
}
|
27 |
+
|
28 |
$results = array_merge ($results, $matches);
|
29 |
}
|
30 |
}
|
32 |
|
33 |
return $results;
|
34 |
}
|
35 |
+
|
36 |
function get_options ($result)
|
37 |
{
|
38 |
$options[] = '<a href="'.get_permalink ($result->sub_id).'">'.__ ('view post', 'search-regex').'</a>';
|
39 |
if ($result->replace)
|
40 |
$options[] = '<a href="#" onclick="regex_replace (\'SearchCommentAuthorURL\','.$result->id.','.$result->offset.','.$result->length.',\''.str_replace ("'", "\'", $result->replace_string).'\'); return false">replace</a>';
|
41 |
+
|
42 |
if (current_user_can ('edit_post', $result->id))
|
43 |
$options[] = '<a href="'.get_bloginfo ('wpurl').'/wp-admin/comment.php?action=editcomment&c='.$result->id.'">'.__ ('edit','search-regex').'</a>';
|
44 |
return $options;
|
45 |
}
|
46 |
+
|
47 |
function show ($result)
|
48 |
{
|
49 |
printf (__ ('Comment #%d: %s', 'search-regex'), $result->id, $result->title);
|
50 |
}
|
51 |
+
|
52 |
function name () { return __ ('Comment author URL', 'search-regex'); }
|
53 |
|
54 |
function get_content ($id)
|
55 |
{
|
56 |
global $wpdb;
|
57 |
|
58 |
+
$row = $wpdb->get_row ($wpdb->prepare( "SELECT comment_author_url FROM {$wpdb->comments} WHERE comment_ID=%d", $id ) );
|
59 |
return $row->comment_author_url;
|
60 |
}
|
61 |
+
|
62 |
function replace_content ($id, $content)
|
63 |
{
|
64 |
global $wpdb;
|
65 |
+
$wpdb->query ($wpdb->prepare( "UPDATE {$wpdb->comments} SET comment_author_url=%s WHERE comment_ID=%d", $content, $id ) );
|
|
|
66 |
}
|
67 |
}
|
|
|
|
|
|
searches/comment_content.php
CHANGED
@@ -7,7 +7,7 @@ class SearchCommentContent extends Search
|
|
7 |
global $wpdb;
|
8 |
|
9 |
$results = array ();
|
10 |
-
$comments = $wpdb->get_results ("SELECT {$wpdb->comments}.comment_ID AS comment_ID, {$wpdb->comments}.comment_post_ID AS comment_post_ID, {$wpdb->comments}.comment_content AS comment_content, {$wpdb->posts}.post_title AS post_title FROM {$wpdb->comments},{$wpdb->posts} WHERE {$wpdb->comments}.comment_approved='1' AND {$wpdb->posts}.ID={$wpdb->comments}.comment_post_ID ORDER BY {$wpdb->comments}.comment_ID $orderby LIMIT $offset,$limit
|
11 |
if (count ($comments) > 0)
|
12 |
{
|
13 |
foreach ($comments AS $comment)
|
@@ -19,7 +19,7 @@ class SearchCommentContent extends Search
|
|
19 |
$match->sub_id = $comment->comment_post_ID;
|
20 |
$match->title = $comment->post_title;
|
21 |
}
|
22 |
-
|
23 |
$results = array_merge ($results, $matches);
|
24 |
}
|
25 |
}
|
@@ -27,40 +27,36 @@ class SearchCommentContent extends Search
|
|
27 |
|
28 |
return $results;
|
29 |
}
|
30 |
-
|
31 |
function get_options ($result)
|
32 |
{
|
33 |
$options[] = '<a href="'.get_permalink ($result->sub_id).'">'.__ ('view post', 'search-regex').'</a>';
|
34 |
if ($result->replace)
|
35 |
$options[] = '<a href="#" onclick="regex_replace (\'SearchCommentContent\','.$result->id.','.$result->offset.','.$result->length.',\''.str_replace ("'", "\'", $result->replace_string).'\'); return false">replace</a>';
|
36 |
-
|
37 |
if (current_user_can ('edit_post', $result->id))
|
38 |
$options[] = '<a href="'.get_bloginfo ('wpurl').'/wp-admin/comment.php?action=editcomment&c='.$result->id.'">'.__ ('edit','search-regex').'</a>';
|
39 |
return $options;
|
40 |
}
|
41 |
-
|
42 |
function show ($result)
|
43 |
{
|
44 |
printf (__ ('Comment #%d: %s', 'search-regex'), $result->id, $result->title);
|
45 |
}
|
46 |
-
|
47 |
function name () { return __ ('Comment content', 'search-regex'); }
|
48 |
|
49 |
function get_content ($id)
|
50 |
{
|
51 |
global $wpdb;
|
52 |
|
53 |
-
$row = $wpdb->get_row ("SELECT comment_content FROM {$wpdb->comments} WHERE comment_ID=
|
54 |
return $row->comment_content;
|
55 |
}
|
56 |
-
|
57 |
function replace_content ($id, $content)
|
58 |
{
|
59 |
global $wpdb;
|
60 |
-
$
|
61 |
-
$wpdb->query ("UPDATE {$wpdb->comments} SET comment_content='{$content}' WHERE comment_ID='$id'");
|
62 |
}
|
63 |
}
|
64 |
-
|
65 |
-
|
66 |
-
?>
|
7 |
global $wpdb;
|
8 |
|
9 |
$results = array ();
|
10 |
+
$comments = $wpdb->get_results ($wpdb->prepare( "SELECT {$wpdb->comments}.comment_ID AS comment_ID, {$wpdb->comments}.comment_post_ID AS comment_post_ID, {$wpdb->comments}.comment_content AS comment_content, {$wpdb->posts}.post_title AS post_title FROM {$wpdb->comments},{$wpdb->posts} WHERE {$wpdb->comments}.comment_approved='1' AND {$wpdb->posts}.ID={$wpdb->comments}.comment_post_ID ORDER BY {$wpdb->comments}.comment_ID $orderby LIMIT %d,%d", $offset,$limit ) );
|
11 |
if (count ($comments) > 0)
|
12 |
{
|
13 |
foreach ($comments AS $comment)
|
19 |
$match->sub_id = $comment->comment_post_ID;
|
20 |
$match->title = $comment->post_title;
|
21 |
}
|
22 |
+
|
23 |
$results = array_merge ($results, $matches);
|
24 |
}
|
25 |
}
|
27 |
|
28 |
return $results;
|
29 |
}
|
30 |
+
|
31 |
function get_options ($result)
|
32 |
{
|
33 |
$options[] = '<a href="'.get_permalink ($result->sub_id).'">'.__ ('view post', 'search-regex').'</a>';
|
34 |
if ($result->replace)
|
35 |
$options[] = '<a href="#" onclick="regex_replace (\'SearchCommentContent\','.$result->id.','.$result->offset.','.$result->length.',\''.str_replace ("'", "\'", $result->replace_string).'\'); return false">replace</a>';
|
36 |
+
|
37 |
if (current_user_can ('edit_post', $result->id))
|
38 |
$options[] = '<a href="'.get_bloginfo ('wpurl').'/wp-admin/comment.php?action=editcomment&c='.$result->id.'">'.__ ('edit','search-regex').'</a>';
|
39 |
return $options;
|
40 |
}
|
41 |
+
|
42 |
function show ($result)
|
43 |
{
|
44 |
printf (__ ('Comment #%d: %s', 'search-regex'), $result->id, $result->title);
|
45 |
}
|
46 |
+
|
47 |
function name () { return __ ('Comment content', 'search-regex'); }
|
48 |
|
49 |
function get_content ($id)
|
50 |
{
|
51 |
global $wpdb;
|
52 |
|
53 |
+
$row = $wpdb->get_row ($wpdb->prepare( "SELECT comment_content FROM {$wpdb->comments} WHERE comment_ID=", $id ) );
|
54 |
return $row->comment_content;
|
55 |
}
|
56 |
+
|
57 |
function replace_content ($id, $content)
|
58 |
{
|
59 |
global $wpdb;
|
60 |
+
$wpdb->query ( $wpdb->prepare( "UPDATE {$wpdb->comments} SET comment_content=%s WHERE comment_ID=%d", $content, $id ) );
|
|
|
61 |
}
|
62 |
}
|
|
|
|
|
|
searches/post_content.php
CHANGED
@@ -7,7 +7,11 @@ class SearchPostContent extends Search
|
|
7 |
global $wpdb;
|
8 |
|
9 |
$results = array ();
|
10 |
-
$posts = $wpdb->get_results ("SELECT ID, post_content, post_title FROM {$wpdb->posts} WHERE post_status != 'inherit' ORDER BY ID $orderby
|
|
|
|
|
|
|
|
|
11 |
if (count ($posts) > 0)
|
12 |
{
|
13 |
foreach ($posts AS $post)
|
@@ -47,18 +51,13 @@ class SearchPostContent extends Search
|
|
47 |
{
|
48 |
global $wpdb;
|
49 |
|
50 |
-
$post = $wpdb->get_row ("SELECT post_content FROM {$wpdb->prefix}posts WHERE id
|
51 |
return $post->post_content;
|
52 |
}
|
53 |
|
54 |
function replace_content ($id, $content)
|
55 |
{
|
56 |
global $wpdb;
|
57 |
-
$
|
58 |
-
$wpdb->query ("UPDATE {$wpdb->posts} SET post_content='{$content}' WHERE ID='$id'");
|
59 |
}
|
60 |
}
|
61 |
-
|
62 |
-
|
63 |
-
|
64 |
-
?>
|
7 |
global $wpdb;
|
8 |
|
9 |
$results = array ();
|
10 |
+
$posts = $wpdb->get_results ($wpdb->prepare( "SELECT ID, post_content, post_title FROM {$wpdb->posts} WHERE post_status != 'inherit' ORDER BY ID $orderby" ) );
|
11 |
+
|
12 |
+
if ( $limit > 0 )
|
13 |
+
$sql .= $wpdb->prepare( " LIMIT %d,%d", $offset, $limit );
|
14 |
+
|
15 |
if (count ($posts) > 0)
|
16 |
{
|
17 |
foreach ($posts AS $post)
|
51 |
{
|
52 |
global $wpdb;
|
53 |
|
54 |
+
$post = $wpdb->get_row ( $wpdb->prepare( "SELECT post_content FROM {$wpdb->prefix}posts WHERE id=%d", $id ) );
|
55 |
return $post->post_content;
|
56 |
}
|
57 |
|
58 |
function replace_content ($id, $content)
|
59 |
{
|
60 |
global $wpdb;
|
61 |
+
$wpdb->query ($wpdb->prepare( "UPDATE {$wpdb->posts} SET post_content=%s WHERE ID=%d", $content, $id ) );
|
|
|
62 |
}
|
63 |
}
|
|
|
|
|
|
|
|
searches/post_excerpt.php
CHANGED
@@ -7,7 +7,7 @@ class SearchPostExcerpt extends Search
|
|
7 |
global $wpdb;
|
8 |
|
9 |
$results = array ();
|
10 |
-
$posts = $wpdb->get_results ("SELECT ID, post_title, post_excerpt FROM {$wpdb->posts} WHERE post_status != 'inherit' ORDER BY ID $orderby LIMIT $offset,$limit
|
11 |
if (count ($posts) > 0)
|
12 |
{
|
13 |
foreach ($posts AS $post)
|
@@ -47,18 +47,13 @@ class SearchPostExcerpt extends Search
|
|
47 |
{
|
48 |
global $wpdb;
|
49 |
|
50 |
-
$post = $wpdb->get_row ("SELECT post_excerpt FROM {$wpdb->prefix}posts WHERE id
|
51 |
return $post->post_excerpt;
|
52 |
}
|
53 |
|
54 |
function replace_content ($id, $content)
|
55 |
{
|
56 |
global $wpdb;
|
57 |
-
$
|
58 |
-
$wpdb->query ("UPDATE {$wpdb->posts} SET post_excerpt='{$content}' WHERE ID='$id'");
|
59 |
}
|
60 |
}
|
61 |
-
|
62 |
-
|
63 |
-
|
64 |
-
?>
|
7 |
global $wpdb;
|
8 |
|
9 |
$results = array ();
|
10 |
+
$posts = $wpdb->get_results ($wpdb->prepare( "SELECT ID, post_title, post_excerpt FROM {$wpdb->posts} WHERE post_status != 'inherit' ORDER BY ID $orderby LIMIT %d,%d", $offset,$limit ) );
|
11 |
if (count ($posts) > 0)
|
12 |
{
|
13 |
foreach ($posts AS $post)
|
47 |
{
|
48 |
global $wpdb;
|
49 |
|
50 |
+
$post = $wpdb->get_row ($wpdb->prepare( "SELECT post_excerpt FROM {$wpdb->prefix}posts WHERE id=%d", $id ) );
|
51 |
return $post->post_excerpt;
|
52 |
}
|
53 |
|
54 |
function replace_content ($id, $content)
|
55 |
{
|
56 |
global $wpdb;
|
57 |
+
$wpdb->query ($wpdb->prepare( "UPDATE {$wpdb->posts} SET post_excerpt=%s WHERE ID=%d", $content, $id ) );
|
|
|
58 |
}
|
59 |
}
|
|
|
|
|
|
|
|
searches/post_meta.php
CHANGED
@@ -7,8 +7,8 @@ class SearchPostMetaValue extends Search
|
|
7 |
global $wpdb;
|
8 |
|
9 |
$results = array ();
|
10 |
-
|
11 |
-
$metas = $wpdb->get_results ("SELECT {$wpdb->postmeta}.meta_id AS meta_id, {$wpdb->postmeta}.meta_value AS meta_value, {$wpdb->postmeta}.post_id AS post_id, {$wpdb->posts}.post_title AS title FROM {$wpdb->postmeta} LEFT JOIN {$wpdb->posts} ON {$wpdb->postmeta}.post_id = {$wpdb->posts}.ID ORDER BY meta_value $orderby LIMIT $offset,$limit
|
12 |
|
13 |
if (count ($metas) > 0)
|
14 |
{
|
@@ -29,39 +29,37 @@ class SearchPostMetaValue extends Search
|
|
29 |
|
30 |
return $results;
|
31 |
}
|
32 |
-
|
33 |
function get_options ($result)
|
34 |
{
|
35 |
$options[] = '<a href="'.get_permalink ($result->sub_id).'">'.__ ('view post', 'search-regex').'</a>';
|
36 |
if ($result->replace)
|
37 |
$options[] = '<a href="#" onclick="regex_replace (\'SearchPostMetaValue\','.$result->id.','.$result->offset.','.$result->length.',\''.str_replace ("'", "\'", $result->replace_string).'\'); return false">replace</a>';
|
38 |
-
|
39 |
if (current_user_can ('edit_post', $result->sub_id))
|
40 |
$options[] = '<a href="'.get_bloginfo ('wpurl').'/wp-admin/post.php?action=edit&post='.$result->sub_id.'">'.__ ('edit','search-regex').'</a>';
|
41 |
return $options;
|
42 |
}
|
43 |
-
|
44 |
function show ($result)
|
45 |
{
|
46 |
printf (__ ('Meta data for post #%d: %s', 'search-regex'), $result->sub_id, $result->title);
|
47 |
}
|
48 |
-
|
49 |
function name () { return __ ('Post meta value', 'search-regex'); }
|
50 |
-
|
51 |
function get_content ($id)
|
52 |
{
|
53 |
global $wpdb;
|
54 |
|
55 |
-
$post = $wpdb->get_row ("SELECT meta_value FROM {$wpdb->postmeta} WHERE meta_id
|
56 |
return $post->meta_value;
|
57 |
}
|
58 |
-
|
59 |
function replace_content ($id, $content)
|
60 |
{
|
61 |
global $wpdb;
|
62 |
-
$
|
63 |
-
$wpdb->query ("UPDATE {$wpdb->postmeta} SET meta_value='{$content}' WHERE meta_id='$id'");
|
64 |
}
|
65 |
}
|
66 |
|
67 |
-
?>
|
7 |
global $wpdb;
|
8 |
|
9 |
$results = array ();
|
10 |
+
|
11 |
+
$metas = $wpdb->get_results ($wpdb->prepare( "SELECT {$wpdb->postmeta}.meta_id AS meta_id, {$wpdb->postmeta}.meta_value AS meta_value, {$wpdb->postmeta}.post_id AS post_id, {$wpdb->posts}.post_title AS title FROM {$wpdb->postmeta} LEFT JOIN {$wpdb->posts} ON {$wpdb->postmeta}.post_id = {$wpdb->posts}.ID ORDER BY meta_value $orderby LIMIT %d,%d", $offset,$limit ) );
|
12 |
|
13 |
if (count ($metas) > 0)
|
14 |
{
|
29 |
|
30 |
return $results;
|
31 |
}
|
32 |
+
|
33 |
function get_options ($result)
|
34 |
{
|
35 |
$options[] = '<a href="'.get_permalink ($result->sub_id).'">'.__ ('view post', 'search-regex').'</a>';
|
36 |
if ($result->replace)
|
37 |
$options[] = '<a href="#" onclick="regex_replace (\'SearchPostMetaValue\','.$result->id.','.$result->offset.','.$result->length.',\''.str_replace ("'", "\'", $result->replace_string).'\'); return false">replace</a>';
|
38 |
+
|
39 |
if (current_user_can ('edit_post', $result->sub_id))
|
40 |
$options[] = '<a href="'.get_bloginfo ('wpurl').'/wp-admin/post.php?action=edit&post='.$result->sub_id.'">'.__ ('edit','search-regex').'</a>';
|
41 |
return $options;
|
42 |
}
|
43 |
+
|
44 |
function show ($result)
|
45 |
{
|
46 |
printf (__ ('Meta data for post #%d: %s', 'search-regex'), $result->sub_id, $result->title);
|
47 |
}
|
48 |
+
|
49 |
function name () { return __ ('Post meta value', 'search-regex'); }
|
50 |
+
|
51 |
function get_content ($id)
|
52 |
{
|
53 |
global $wpdb;
|
54 |
|
55 |
+
$post = $wpdb->get_row ($wpdb->prepare( "SELECT meta_value FROM {$wpdb->postmeta} WHERE meta_id=%d", $id ) );
|
56 |
return $post->meta_value;
|
57 |
}
|
58 |
+
|
59 |
function replace_content ($id, $content)
|
60 |
{
|
61 |
global $wpdb;
|
62 |
+
$wpdb->query ($wpdb->prepare( "UPDATE {$wpdb->postmeta} SET meta_value=%s WHERE meta_id=%d", $content, $id ) );
|
|
|
63 |
}
|
64 |
}
|
65 |
|
|
searches/post_title.php
CHANGED
@@ -7,7 +7,7 @@ class SearchPostTitle extends Search
|
|
7 |
global $wpdb;
|
8 |
|
9 |
$results = array ();
|
10 |
-
$posts = $wpdb->get_results ("SELECT ID, post_title FROM {$wpdb->posts} WHERE post_status != 'inherit' ORDER BY ID $orderby LIMIT $offset,$limit
|
11 |
if (count ($posts) > 0)
|
12 |
{
|
13 |
foreach ($posts AS $post)
|
@@ -47,18 +47,13 @@ class SearchPostTitle extends Search
|
|
47 |
{
|
48 |
global $wpdb;
|
49 |
|
50 |
-
$post = $wpdb->get_row ("SELECT post_title FROM {$wpdb->prefix}posts WHERE id
|
51 |
return $post->post_title;
|
52 |
}
|
53 |
|
54 |
function replace_content ($id, $content)
|
55 |
{
|
56 |
global $wpdb;
|
57 |
-
$
|
58 |
-
$wpdb->query ("UPDATE {$wpdb->posts} SET post_title='{$content}' WHERE ID='$id'");
|
59 |
}
|
60 |
}
|
61 |
-
|
62 |
-
|
63 |
-
|
64 |
-
?>
|
7 |
global $wpdb;
|
8 |
|
9 |
$results = array ();
|
10 |
+
$posts = $wpdb->get_results ($wpdb->prepare( "SELECT ID, post_title FROM {$wpdb->posts} WHERE post_status != 'inherit' ORDER BY ID $orderby LIMIT %d,%d", $offset,$limit ) );
|
11 |
if (count ($posts) > 0)
|
12 |
{
|
13 |
foreach ($posts AS $post)
|
47 |
{
|
48 |
global $wpdb;
|
49 |
|
50 |
+
$post = $wpdb->get_row ($wpdb->prepare( "SELECT post_title FROM {$wpdb->prefix}posts WHERE id=%d", $id ) );
|
51 |
return $post->post_title;
|
52 |
}
|
53 |
|
54 |
function replace_content ($id, $content)
|
55 |
{
|
56 |
global $wpdb;
|
57 |
+
$wpdb->query ($wpdb->prepare( "UPDATE {$wpdb->posts} SET post_title=%s WHERE ID=%d", $content, $id ) );
|
|
|
58 |
}
|
59 |
}
|
|
|
|
|
|
|
|
searches/post_url.php
CHANGED
@@ -7,7 +7,7 @@ class SearchPostURL extends Search
|
|
7 |
global $wpdb;
|
8 |
|
9 |
$results = array ();
|
10 |
-
$posts = $wpdb->get_results ("SELECT ID, post_name, post_title FROM {$wpdb->posts} WHERE post_status != 'inherit' ORDER BY ID $orderby LIMIT $offset
|
11 |
if (count ($posts) > 0)
|
12 |
{
|
13 |
foreach ($posts AS $post)
|
@@ -47,16 +47,13 @@ class SearchPostURL extends Search
|
|
47 |
{
|
48 |
global $wpdb;
|
49 |
|
50 |
-
$post = $wpdb->get_row ("SELECT post_name FROM {$wpdb->prefix}posts WHERE id
|
51 |
return $post->post_name;
|
52 |
}
|
53 |
|
54 |
function replace_content ($id, $content)
|
55 |
{
|
56 |
global $wpdb;
|
57 |
-
$
|
58 |
-
$wpdb->query ("UPDATE {$wpdb->posts} SET post_name='{$content}' WHERE ID='$id'");
|
59 |
}
|
60 |
}
|
61 |
-
|
62 |
-
?>
|
7 |
global $wpdb;
|
8 |
|
9 |
$results = array ();
|
10 |
+
$posts = $wpdb->get_results ( $wpdb->prepare( "SELECT ID, post_name, post_title FROM {$wpdb->posts} WHERE post_status != 'inherit' ORDER BY ID $orderby LIMIT %d,%d", $offset, $limit ) );
|
11 |
if (count ($posts) > 0)
|
12 |
{
|
13 |
foreach ($posts AS $post)
|
47 |
{
|
48 |
global $wpdb;
|
49 |
|
50 |
+
$post = $wpdb->get_row ($wpdb->prepare( "SELECT post_name FROM {$wpdb->prefix}posts WHERE id=%d", $id ) );
|
51 |
return $post->post_name;
|
52 |
}
|
53 |
|
54 |
function replace_content ($id, $content)
|
55 |
{
|
56 |
global $wpdb;
|
57 |
+
$wpdb->query ($wpdb->prepare( "UPDATE {$wpdb->posts} SET post_name=%s WHERE ID=%d", $content, $id ) );
|
|
|
58 |
}
|
59 |
}
|
|
|
|
searches/sniplet_content.php
DELETED
@@ -1,60 +0,0 @@
|
|
1 |
-
<?php
|
2 |
-
|
3 |
-
class SearchSnipletContent extends Search
|
4 |
-
{
|
5 |
-
function find ($pattern, $limit, $offset, $orderby)
|
6 |
-
{
|
7 |
-
global $wpdb;
|
8 |
-
|
9 |
-
$results = array ();
|
10 |
-
$terms = $wpdb->get_results ("SELECT {$wpdb->prefix}sniplets.id, {$wpdb->prefix}sniplets.contents, {$wpdb->prefix}sniplets.name FROM {$wpdb->prefix}sniplets LIMIT $offset,$limit");
|
11 |
-
if (count ($terms) > 0)
|
12 |
-
{
|
13 |
-
foreach ($terms AS $term)
|
14 |
-
{
|
15 |
-
if (($matches = $this->matches ($pattern, $term->contents, $term->id)))
|
16 |
-
{
|
17 |
-
foreach ($matches AS $match)
|
18 |
-
{
|
19 |
-
$match->sub_id = $term->id;
|
20 |
-
$match->title = $term->name;
|
21 |
-
}
|
22 |
-
|
23 |
-
$results = array_merge ($results, $matches);
|
24 |
-
}
|
25 |
-
}
|
26 |
-
}
|
27 |
-
|
28 |
-
return $results;
|
29 |
-
}
|
30 |
-
|
31 |
-
function get_options ($result)
|
32 |
-
{
|
33 |
-
return array ();
|
34 |
-
}
|
35 |
-
|
36 |
-
function show ($result)
|
37 |
-
{
|
38 |
-
printf (__ ('Sniplet #%d: %s', 'search-regex'), $result->id, $result->title);
|
39 |
-
}
|
40 |
-
|
41 |
-
function name () { return __ ('Sniplet Content', 'search-regex'); }
|
42 |
-
|
43 |
-
function get_content ($id)
|
44 |
-
{
|
45 |
-
global $wpdb;
|
46 |
-
|
47 |
-
$row = $wpdb->get_row ("SELECT contents FROM {$wpdb->prefix}sniplets WHERE id='$id'");
|
48 |
-
return $row->contents;
|
49 |
-
}
|
50 |
-
|
51 |
-
function replace_content ($id, $content)
|
52 |
-
{
|
53 |
-
global $wpdb;
|
54 |
-
$content = $wpdb->escape ($content);
|
55 |
-
$wpdb->query ("UPDATE {$wpdb->prefix}sniplets SET contents='{$content}' WHERE id='$id'");
|
56 |
-
}
|
57 |
-
}
|
58 |
-
|
59 |
-
|
60 |
-
?>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
searches/tag_name.php
DELETED
@@ -1,60 +0,0 @@
|
|
1 |
-
<?php
|
2 |
-
|
3 |
-
class SearchTagName extends Search
|
4 |
-
{
|
5 |
-
function find ($pattern, $limit, $offset, $orderby)
|
6 |
-
{
|
7 |
-
global $wpdb;
|
8 |
-
|
9 |
-
$results = array ();
|
10 |
-
$terms = $wpdb->get_results ("SELECT {$wpdb->terms}.term_id, {$wpdb->terms}.name FROM {$wpdb->terms} LIMIT $offset,$limit");
|
11 |
-
if (count ($terms) > 0)
|
12 |
-
{
|
13 |
-
foreach ($terms AS $term)
|
14 |
-
{
|
15 |
-
if (($matches = $this->matches ($pattern, $term->name, $term->term_id)))
|
16 |
-
{
|
17 |
-
foreach ($matches AS $match)
|
18 |
-
{
|
19 |
-
$match->sub_id = $term->term_id;
|
20 |
-
$match->title = $term->name;
|
21 |
-
}
|
22 |
-
|
23 |
-
$results = array_merge ($results, $matches);
|
24 |
-
}
|
25 |
-
}
|
26 |
-
}
|
27 |
-
|
28 |
-
return $results;
|
29 |
-
}
|
30 |
-
|
31 |
-
function get_options ($result)
|
32 |
-
{
|
33 |
-
return array ();
|
34 |
-
}
|
35 |
-
|
36 |
-
function show ($result)
|
37 |
-
{
|
38 |
-
printf (__ ('Tag #%d: %s', 'search-regex'), $result->id, $result->title);
|
39 |
-
}
|
40 |
-
|
41 |
-
function name () { return __ ('Tag Name', 'search-regex'); }
|
42 |
-
|
43 |
-
function get_content ($id)
|
44 |
-
{
|
45 |
-
global $wpdb;
|
46 |
-
|
47 |
-
$row = $wpdb->get_row ("SELECT name FROM {$wpdb->terms} WHERE term_id='$id'");
|
48 |
-
return $row->name;
|
49 |
-
}
|
50 |
-
|
51 |
-
function replace_content ($id, $content)
|
52 |
-
{
|
53 |
-
global $wpdb;
|
54 |
-
$content = $wpdb->escape ($content);
|
55 |
-
$wpdb->query ("UPDATE {$wpdb->terms} SET name='{$content}' WHERE term_id='$id'");
|
56 |
-
}
|
57 |
-
}
|
58 |
-
|
59 |
-
|
60 |
-
?>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
searches/tag_slug.php
DELETED
@@ -1,60 +0,0 @@
|
|
1 |
-
<?php
|
2 |
-
|
3 |
-
class SearchTagSlug extends Search
|
4 |
-
{
|
5 |
-
function find ($pattern, $limit, $offset, $orderby)
|
6 |
-
{
|
7 |
-
global $wpdb;
|
8 |
-
|
9 |
-
$results = array ();
|
10 |
-
$terms = $wpdb->get_results ("SELECT {$wpdb->terms}.term_id, {$wpdb->terms}.slug FROM {$wpdb->terms} LIMIT $offset,$limit");
|
11 |
-
if (count ($terms) > 0)
|
12 |
-
{
|
13 |
-
foreach ($terms AS $term)
|
14 |
-
{
|
15 |
-
if (($matches = $this->matches ($pattern, $term->slug, $term->term_id)))
|
16 |
-
{
|
17 |
-
foreach ($matches AS $match)
|
18 |
-
{
|
19 |
-
$match->sub_id = $term->term_id;
|
20 |
-
$match->title = $term->slug;
|
21 |
-
}
|
22 |
-
|
23 |
-
$results = array_merge ($results, $matches);
|
24 |
-
}
|
25 |
-
}
|
26 |
-
}
|
27 |
-
|
28 |
-
return $results;
|
29 |
-
}
|
30 |
-
|
31 |
-
function get_options ($result)
|
32 |
-
{
|
33 |
-
return array ();
|
34 |
-
}
|
35 |
-
|
36 |
-
function show ($result)
|
37 |
-
{
|
38 |
-
printf (__ ('Tag #%d: %s', 'search-regex'), $result->id, $result->title);
|
39 |
-
}
|
40 |
-
|
41 |
-
function name () { return __ ('Tag slug', 'search-regex'); }
|
42 |
-
|
43 |
-
function get_content ($id)
|
44 |
-
{
|
45 |
-
global $wpdb;
|
46 |
-
|
47 |
-
$row = $wpdb->get_row ("SELECT slug FROM {$wpdb->terms} WHERE term_id='$id'");
|
48 |
-
return $row->slug;
|
49 |
-
}
|
50 |
-
|
51 |
-
function replace_content ($id, $content)
|
52 |
-
{
|
53 |
-
global $wpdb;
|
54 |
-
$content = $wpdb->escape ($content);
|
55 |
-
$wpdb->query ("UPDATE {$wpdb->terms} SET slug='{$content}' WHERE term_id='$id'");
|
56 |
-
}
|
57 |
-
}
|
58 |
-
|
59 |
-
|
60 |
-
?>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
view/admin/head.php
DELETED
@@ -1,7 +0,0 @@
|
|
1 |
-
<?php if (!defined ('ABSPATH')) die ('No direct access allowed'); ?>
|
2 |
-
<link rel="stylesheet" href="<?php echo $this->url () ?>/admin.css" type="text/css" media="screen" title="no title" charset="utf-8"/>
|
3 |
-
<script type="text/javascript" charset="utf-8">
|
4 |
-
var wp_base = '<?php echo $this->url () ?>/ajax.php';
|
5 |
-
var wp_loading = '<?php echo $this->url () ?>/images/small.gif';
|
6 |
-
</script>
|
7 |
-
<script type="text/javascript" src="<?php echo $this->url () ?>/js/search-regex.js"></script>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
view/admin/results.php
CHANGED
@@ -8,13 +8,13 @@
|
|
8 |
<ol class="results">
|
9 |
<?php foreach ($results AS $pos => $result) : ?>
|
10 |
<li id="search_<?php echo $result->id.'_'.$result->offset ?>"<?php if ($pos % 2 == 1) echo ' class="alt"' ?>>
|
11 |
-
|
12 |
<div id="options_<?php echo $result->id.'_'.$result->offset ?>" class="options"><?php echo implode (' | ', $search->get_options ($result)); ?></div>
|
13 |
|
14 |
<?php $search->show ($result); ?>
|
15 |
-
|
16 |
<div class="searchx" id="value_<?php echo $result->id.'_'.$result->offset ?>"><?php echo $result->search ?></div>
|
17 |
-
|
18 |
<?php if ($result->replace) : ?>
|
19 |
<?php _e ('replaced with:', 'search-regex') ?>
|
20 |
<div class="replacex" id="replace_<?php echo $result->id.'_'.$result->offset ?>"><?php echo $result->replace ?></div>
|
@@ -22,13 +22,13 @@
|
|
22 |
</li>
|
23 |
<?php endforeach; ?>
|
24 |
</ol>
|
25 |
-
|
26 |
-
<img src="<?php
|
27 |
-
|
28 |
<script type="text/javascript" charset="utf-8">
|
29 |
var re_text = new Array (), re_input = new Array (), re_replace = new Array (), re_text_replace = new Array ();
|
30 |
-
|
31 |
-
<?php foreach ($results AS $result) : ?>
|
32 |
<?php
|
33 |
$id = $result->id.'_'.$result->offset;
|
34 |
$edit = '<br/><input type="submit" name="save" value="Save" onclick="save_edit(\\\''.get_class ($search).'\\\','.$result->id.','.$result->offset.','.$result->left.','.$result->left_length.');return false"/>';
|
@@ -39,7 +39,7 @@ re_text['<?php echo $id ?>'] = '<?php echo $result->for_js ($result->search); ?>
|
|
39 |
|
40 |
<?php if ($result->single_line ()) : ?>
|
41 |
re_input['<?php echo $id ?>'] = '<input id="txt_<?php echo $id ?>" style="width: 95%" type="text" name="replace" value="<?php echo $result->for_js ($result->search_plain); ?>"/><?php echo $edit ?>';
|
42 |
-
<?php else : ?>
|
43 |
re_input['<?php echo $id ?>'] = '<textarea id="txt_<?php echo $id ?>" style="width: 95%" rows="2" name="replace"><?php echo $result->for_js ($result->search_plain); ?><\/textarea><?php echo $edit ?>';
|
44 |
<?php endif; ?>
|
45 |
|
@@ -54,7 +54,7 @@ re_text['<?php echo $id ?>'] = '<?php echo $result->for_js ($result->search); ?>
|
|
54 |
|
55 |
<?php endforeach; ?>
|
56 |
</script>
|
57 |
-
|
58 |
<?php else : ?>
|
59 |
<p><?php _e ('There are no results.', 'search-regex') ?></p>
|
60 |
<?php endif; ?>
|
8 |
<ol class="results">
|
9 |
<?php foreach ($results AS $pos => $result) : ?>
|
10 |
<li id="search_<?php echo $result->id.'_'.$result->offset ?>"<?php if ($pos % 2 == 1) echo ' class="alt"' ?>>
|
11 |
+
|
12 |
<div id="options_<?php echo $result->id.'_'.$result->offset ?>" class="options"><?php echo implode (' | ', $search->get_options ($result)); ?></div>
|
13 |
|
14 |
<?php $search->show ($result); ?>
|
15 |
+
|
16 |
<div class="searchx" id="value_<?php echo $result->id.'_'.$result->offset ?>"><?php echo $result->search ?></div>
|
17 |
+
|
18 |
<?php if ($result->replace) : ?>
|
19 |
<?php _e ('replaced with:', 'search-regex') ?>
|
20 |
<div class="replacex" id="replace_<?php echo $result->id.'_'.$result->offset ?>"><?php echo $result->replace ?></div>
|
22 |
</li>
|
23 |
<?php endforeach; ?>
|
24 |
</ol>
|
25 |
+
|
26 |
+
<img src="<?php echo plugins_url( '/images/small.gif', $this->base_url() ); ?>" style="display: none" alt="pre"/>
|
27 |
+
|
28 |
<script type="text/javascript" charset="utf-8">
|
29 |
var re_text = new Array (), re_input = new Array (), re_replace = new Array (), re_text_replace = new Array ();
|
30 |
+
|
31 |
+
<?php foreach ($results AS $result) : ?>
|
32 |
<?php
|
33 |
$id = $result->id.'_'.$result->offset;
|
34 |
$edit = '<br/><input type="submit" name="save" value="Save" onclick="save_edit(\\\''.get_class ($search).'\\\','.$result->id.','.$result->offset.','.$result->left.','.$result->left_length.');return false"/>';
|
39 |
|
40 |
<?php if ($result->single_line ()) : ?>
|
41 |
re_input['<?php echo $id ?>'] = '<input id="txt_<?php echo $id ?>" style="width: 95%" type="text" name="replace" value="<?php echo $result->for_js ($result->search_plain); ?>"/><?php echo $edit ?>';
|
42 |
+
<?php else : ?>
|
43 |
re_input['<?php echo $id ?>'] = '<textarea id="txt_<?php echo $id ?>" style="width: 95%" rows="2" name="replace"><?php echo $result->for_js ($result->search_plain); ?><\/textarea><?php echo $edit ?>';
|
44 |
<?php endif; ?>
|
45 |
|
54 |
|
55 |
<?php endforeach; ?>
|
56 |
</script>
|
57 |
+
|
58 |
<?php else : ?>
|
59 |
<p><?php _e ('There are no results.', 'search-regex') ?></p>
|
60 |
<?php endif; ?>
|
view/admin/search.php
CHANGED
@@ -1,69 +1,75 @@
|
|
1 |
-
<?php if (!defined
|
2 |
-
|
3 |
-
<
|
4 |
-
<p><?php _e
|
|
|
5 |
|
6 |
-
<form method="post" action="
|
7 |
-
|
8 |
-
|
9 |
-
|
10 |
-
|
11 |
-
|
12 |
-
|
13 |
-
|
14 |
-
|
15 |
-
|
16 |
-
|
17 |
-
|
18 |
-
<strong><?php _e ('Limit to', 'search-regex'); ?>:</strong>
|
19 |
-
<?php $limit = isset( $_POST['limit'] ) ? intval( $_POST['limit'] ) : 0 ?>
|
20 |
-
<select name="limit">
|
21 |
-
<?php echo $this->select (array ('18446744073709551615' => __ ('No limit', 'search-regex'), '10' => '10', '25' => '25', '50' => '50', '100' => '100'), $limit) ?>
|
22 |
-
</select>
|
23 |
-
|
24 |
-
<strong><?php _e ('Order By', 'search-regex'); ?>:</strong>
|
25 |
-
<?php $orderby = isset( $_POST['orderby'] ) ? $_POST['orderby'] : ''; ?>
|
26 |
-
<select name="orderby">
|
27 |
-
<?php echo $this->select (array ('asc' => __ ('Ascending', 'search-regex'), 'desc' => __ ('Descending', 'search-regex')), $orderby ); ?>
|
28 |
-
</select>
|
29 |
-
</td>
|
30 |
-
</tr>
|
31 |
-
<tr>
|
32 |
-
<th width="150" valign="top"><?php _e ("Search pattern", 'search-regex') ?></th>
|
33 |
-
<td>
|
34 |
-
<input class="term" type="text" name="search_pattern" value="<?php echo htmlspecialchars ($search) ?>"/><br/>
|
35 |
-
</td>
|
36 |
-
</tr>
|
37 |
-
<tr>
|
38 |
-
<th width="150" valign="top"><?php _e ('Replace pattern', 'search-regex') ?></th>
|
39 |
-
<td>
|
40 |
-
<input class="term" type="text" name="replace_pattern" value="<?php echo htmlspecialchars ($replace) ?>"/><br/>
|
41 |
-
</td>
|
42 |
-
</tr>
|
43 |
-
<tr>
|
44 |
-
<th><label for="regex"><?php _e( 'Regex', 'search-regex' ); ?></label>:</th>
|
45 |
-
<td>
|
46 |
-
<input onclick="toggle_regex(); return true" id="regex" type="checkbox" value="regex" name="regex"<?php if (isset ($_POST['regex'])) echo 'checked="checked"' ?>/>
|
47 |
-
<span id="regex-options" <?php if (!isset ($_POST['regex'])) : ?>style="display: none"<?php endif; ?> class="sub">
|
48 |
-
<label for="case"><?php _e ('case-insensitive:', 'search-regex') ?></label> <input id="case" type="checkbox" name="regex_case" value="caseless"<?php if (isset ($_POST['regex_case'])) echo 'checked="checked"' ?>/>
|
49 |
-
<label for="multi"><?php _e ('multi-line:', 'search-regex') ?></label> <input id="multi" type="checkbox" name="regex_multi" value="multiline"<?php if (isset ($_POST['regex_multi'])) echo 'checked="checked"' ?>/>
|
50 |
-
<label for="dotall"><?php _e ('dot-all:', 'search-regex') ?></label> <input id="dotall" type="checkbox" name="regex_dot" value="dotall"<?php if (isset ($_POST['regex_dot'])) echo 'checked="checked"' ?>/>
|
51 |
-
— <?php _e ('remember to surround your regex with a delimiter!', 'search-regex'); ?>
|
52 |
-
</span>
|
53 |
-
</td>
|
54 |
-
</tr>
|
55 |
-
<tr>
|
56 |
-
<th width="150"></th>
|
57 |
-
<td><p class="submit">
|
58 |
-
<input type="submit" name="search" value="<?php _e ('Search', 'search-regex')?> »" />
|
59 |
|
60 |
-
|
61 |
-
|
62 |
-
|
63 |
-
|
64 |
-
|
65 |
-
|
66 |
-
|
67 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
68 |
</form>
|
69 |
</div>
|
|
|
|
|
|
|
|
1 |
+
<?php if (!defined( 'ABSPATH' )) die( 'No direct access allowed' ); ?>
|
2 |
+
<div class="wrap">
|
3 |
+
<h2><?php _e( 'Search Regex', 'search-regex' ) ?></h2>
|
4 |
+
<p><?php _e( "Replacements will only be saved to the database if you click '<strong>Replace & Save</strong>', otherwise you will get a preview of the results.", 'search-regex' ) ?></p>
|
5 |
+
<p><?php _e( "NOTE: <strong>No liability</strong> is accepted for any damage caused. You are strongly advised to backup your database before making any changes.", 'search-regex' ) ?></p>
|
6 |
|
7 |
+
<form method="post" action="">
|
8 |
+
<table class="searchargs">
|
9 |
+
<tr>
|
10 |
+
<th width="150"><?php _e( "Source", 'search-regex' ) ?></th>
|
11 |
+
<td>
|
12 |
+
<select name="source">
|
13 |
+
<?php foreach ( $searches AS $searcher ) : ?>
|
14 |
+
<option value="<?php echo get_class( $searcher ) ?>" <?php if ( strcasecmp( $source, get_class( $searcher ) ) == 0 || ( $source == '' && strcasecmp( get_class( $searcher ), 'SearchPostContent' ) == 0 ) ) echo ' selected="selected"' ?>>
|
15 |
+
<?php echo $searcher->name() ?>
|
16 |
+
</option>
|
17 |
+
<?php endforeach; ?>
|
18 |
+
</select>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
19 |
|
20 |
+
<strong><?php _e( 'Limit to', 'search-regex' ); ?>:</strong>
|
21 |
+
<?php $limit = isset( $_POST['limit'] ) ? intval( $_POST['limit'] ) : 0 ?>
|
22 |
+
<select name="limit">
|
23 |
+
<?php echo $this->select( array( '0' => __( 'No limit', 'search-regex' ), '10' => '10', '25' => '25', '50' => '50', '100' => '100' ), $limit ) ?>
|
24 |
+
</select>
|
25 |
+
|
26 |
+
<strong><?php _e( 'Order By', 'search-regex' ); ?>:</strong>
|
27 |
+
<?php $orderby = isset( $_POST['orderby'] ) ? $_POST['orderby'] : ''; ?>
|
28 |
+
<select name="orderby">
|
29 |
+
<?php echo $this->select( array( 'asc' => __( 'Ascending', 'search-regex' ), 'desc' => __( 'Descending', 'search-regex' ) ), $orderby ); ?>
|
30 |
+
</select>
|
31 |
+
</td>
|
32 |
+
</tr>
|
33 |
+
<tr>
|
34 |
+
<th width="150" valign="top"><?php _e( "Search pattern", 'search-regex' ) ?></th>
|
35 |
+
<td>
|
36 |
+
<input class="term" type="text" name="search_pattern" value="<?php esc_attr_e( $search ) ?>"/><br/>
|
37 |
+
</td>
|
38 |
+
</tr>
|
39 |
+
<tr>
|
40 |
+
<th width="150" valign="top"><?php _e( 'Replace pattern', 'search-regex' ) ?></th>
|
41 |
+
<td>
|
42 |
+
<input class="term" type="text" name="replace_pattern" value="<?php esc_attr_e( $replace ) ?>"/><br/>
|
43 |
+
</td>
|
44 |
+
</tr>
|
45 |
+
<tr>
|
46 |
+
<th><label for="regex"><?php _e( 'Regex', 'search-regex' ); ?></label>:</th>
|
47 |
+
<td>
|
48 |
+
<input id="regex" type="checkbox" value="regex" name="regex"<?php if (isset ($_POST['regex'])) echo 'checked="checked"' ?>/>
|
49 |
+
<span id="regex-options" <?php if (!isset ($_POST['regex'])) : ?>style="display: none"<?php endif; ?> class="sub">
|
50 |
+
<label for="case"><?php _e( 'case-insensitive:', 'search-regex' ) ?></label> <input id="case" type="checkbox" name="regex_case" value="caseless"<?php if (isset ($_POST['regex_case'])) echo 'checked="checked"' ?>/>
|
51 |
+
<label for="multi"><?php _e( 'multi-line:', 'search-regex' ) ?></label> <input id="multi" type="checkbox" name="regex_multi" value="multiline"<?php if (isset ($_POST['regex_multi'])) echo 'checked="checked"' ?>/>
|
52 |
+
<label for="dotall"><?php _e( 'dot-all:', 'search-regex' ) ?></label> <input id="dotall" type="checkbox" name="regex_dot" value="dotall"<?php if (isset ($_POST['regex_dot'])) echo 'checked="checked"' ?>/>
|
53 |
+
— <?php _e( 'remember to surround your regex with a delimiter!', 'search-regex' ); ?>
|
54 |
+
</span>
|
55 |
+
</td>
|
56 |
+
</tr>
|
57 |
+
<tr>
|
58 |
+
<th width="150"></th>
|
59 |
+
<td><p class="submit">
|
60 |
+
<input type="submit" name="search" value="<?php esc_attr_e( 'Search', 'search-regex' )?> »" />
|
61 |
+
|
62 |
+
<?php if (current_user_can( 'administrator' ) || current_user_can( 'search_regex_write' )) : ?>
|
63 |
+
<input type="submit" name="replace" value="<?php esc_attr_e( 'Replace', 'search-regex' )?> »" />
|
64 |
+
<input type="submit" name="replace_and_save" value="<?php esc_attr_e( 'Replace & Save »', 'search-regex' ) ?>"/>
|
65 |
+
<?php endif; ?>
|
66 |
+
</p>
|
67 |
+
</td>
|
68 |
+
</tr>
|
69 |
+
</table>
|
70 |
</form>
|
71 |
</div>
|
72 |
+
|
73 |
+
<script type="text/javascript" charset="utf-8">
|
74 |
+
var wp_loading = '<?php echo plugins_url( '/images/small.gif', $this->base_url() ); ?>';
|
75 |
+
</script>
|