Version Description
(20/4/2014) =
- Fix: taxonomy base removal.
Download this release
Release Info
Developer | antonioandra.de |
Plugin | WP htaccess Control |
Version | 3.4.2 |
Comparing to | |
See all releases |
Code changes from version 3.4.1 to 3.4.2
- readme.txt +7 -3
- wp-htaccess-control.php +726 -678
readme.txt
CHANGED
@@ -7,7 +7,7 @@ Donate link: https://www.paypal.com/cgi-bin/webscr?cmd=_donations&business=anton
|
|
7 |
Tags: permalinks, permalink, author, htaccess, rewrite, redirect, admin, maintenance, pagination, category, category base, archive, archives
|
8 |
Requires at least: 3.4
|
9 |
Tested up to: 3.9
|
10 |
-
Stable tag: 3.4.
|
11 |
|
12 |
Interface to customize the permalinks (author, category, archives and pagination) and htaccess file generated by WordPress.
|
13 |
|
@@ -93,9 +93,13 @@ For WordPress versions prior to 3.4 use the plugin version 2.7.2.1.
|
|
93 |
|
94 |
== Changelog ==
|
95 |
|
96 |
-
= 3.4.
|
97 |
|
98 |
-
* Fix:
|
|
|
|
|
|
|
|
|
99 |
|
100 |
= 3.4 (19/4/2014) =
|
101 |
|
7 |
Tags: permalinks, permalink, author, htaccess, rewrite, redirect, admin, maintenance, pagination, category, category base, archive, archives
|
8 |
Requires at least: 3.4
|
9 |
Tested up to: 3.9
|
10 |
+
Stable tag: 3.4.2
|
11 |
|
12 |
Interface to customize the permalinks (author, category, archives and pagination) and htaccess file generated by WordPress.
|
13 |
|
93 |
|
94 |
== Changelog ==
|
95 |
|
96 |
+
= 3.4.2 (20/4/2014) =
|
97 |
|
98 |
+
* Fix: taxonomy base removal.
|
99 |
+
|
100 |
+
= 3.4.1 (20/4/2014) =
|
101 |
+
|
102 |
+
* Fix: implicit array with break the admin interface on some php versions.
|
103 |
|
104 |
= 3.4 (19/4/2014) =
|
105 |
|
wp-htaccess-control.php
CHANGED
@@ -27,268 +27,304 @@ Author URI: http://antonioandra.de
|
|
27 |
Search redirection is based on Nice Search by Mark Jaquith, 2011 */
|
28 |
|
29 |
if (!class_exists("WPhtc")) {
|
30 |
-
|
31 |
-
|
32 |
-
|
33 |
-
|
34 |
-
|
35 |
-
|
36 |
-
|
|
|
|
|
|
|
37 |
/*
|
38 |
* @param $key
|
39 |
*/
|
40 |
-
function get_data($key, $key_inner="")
|
41 |
-
|
42 |
-
|
|
|
43 |
return $this->data[$key][$key_inner];
|
|
|
|
|
44 |
}
|
45 |
-
|
46 |
-
return
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
47 |
}
|
|
|
|
|
|
|
48 |
}
|
49 |
-
|
50 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
51 |
}
|
52 |
}
|
53 |
-
|
54 |
-
|
55 |
-
$currentLocale = get_locale();
|
56 |
-
if(!empty($currentLocale)) {
|
57 |
-
$moFile = dirname(__FILE__) . "/lang/wp-htaccess-control-" . $currentLocale . ".mo";
|
58 |
-
if(@file_exists($moFile) && is_readable($moFile)) load_textdomain('wp-htaccess-control', $moFile);
|
59 |
-
}
|
60 |
-
}
|
61 |
-
function search_template_redirect(){
|
62 |
-
# redirect "?s=*" to "/search-base/*"
|
63 |
-
if($_GET['s']){
|
64 |
-
wp_redirect( home_url( $this->data['custom_search_permalink']. "/" . rawurlencode(get_query_var( 's' )) ) );
|
65 |
-
}
|
66 |
-
|
67 |
-
# rewrite query
|
68 |
-
if(strpos($_SERVER["REQUEST_URI"], $this->data['custom_search_permalink'])){
|
69 |
-
global $wp_query;
|
70 |
-
if(strpos($_SERVER["REQUEST_URI"], '/feed')){
|
71 |
-
preg_match("/feed\/(feed|rdf|rss|rss2|atom)?/",$_SERVER["REQUEST_URI"], $feed);
|
72 |
-
if($feed[1]){
|
73 |
-
$format="&feed=".$feed[1];
|
74 |
-
}
|
75 |
-
else{
|
76 |
-
$format="&feed=feed";
|
77 |
-
}
|
78 |
-
}
|
79 |
-
$page_base=($this->data['cpp']!='')?$this->data['cpp']:'page';
|
80 |
-
|
81 |
-
# in need of better regex
|
82 |
-
if(!strpos($_SERVER["REQUEST_URI"], '/feed')&&!strpos($_SERVER["REQUEST_URI"],$page_base)){
|
83 |
-
$pattern="/\/".$this->data['custom_search_permalink']."\/(.+)/";
|
84 |
-
}
|
85 |
-
else{
|
86 |
-
$pattern="/\/".$this->data['custom_search_permalink']."\/(.+)\/feed|".$page_base."?/";
|
87 |
-
}
|
88 |
-
|
89 |
-
$pattern="/\/".$this->data['custom_search_permalink']."\/(.+)/";
|
90 |
-
preg_match($pattern,$_SERVER["REQUEST_URI"], $matches);
|
91 |
-
$results=split("/",$matches[1]);
|
92 |
-
if($results[1]==$page_base){
|
93 |
-
$page="&paged=".$results[2];
|
94 |
-
}
|
95 |
-
$wp_query=new WP_Query('s='.$results[0].$page.$format );
|
96 |
-
}
|
97 |
-
}
|
98 |
-
# return get_search_query on custom search base
|
99 |
-
function get_search_query_filter($query){
|
100 |
-
|
101 |
-
if($this->data['custom_search_permalink']!=''&&strpos($_SERVER["REQUEST_URI"], $this->data['custom_search_permalink'])){
|
102 |
-
$page_base=($this->data['cpp']!='')?$this->data['cpp']:'page';
|
103 |
-
# in need of better regex
|
104 |
-
if(!strpos($_SERVER["REQUEST_URI"], '/feed')&&!strpos($_SERVER["REQUEST_URI"],"/".$page_base)){
|
105 |
-
$pattern="/\/".$this->data['custom_search_permalink']."\/(.+)/";
|
106 |
-
}
|
107 |
-
else{
|
108 |
-
$pattern="/\/".$this->data['custom_search_permalink']."\/(.+)\/feed|".$page_base."?/";
|
109 |
-
}
|
110 |
-
preg_match($pattern,$_SERVER["REQUEST_URI"], $matches);
|
111 |
-
$results=split("/",$matches[1]);
|
112 |
-
return urldecode($results[0]);
|
113 |
-
}
|
114 |
-
return $query;
|
115 |
-
}
|
116 |
-
function search_feed_link($link){
|
117 |
-
|
118 |
-
$link=str_replace("search",$this->data['custom_search_permalink'],$link);
|
119 |
-
return $link;
|
120 |
-
}
|
121 |
-
function check_first_run(){
|
122 |
-
|
123 |
-
# flush rules to get some data filled on first usage
|
124 |
-
if(!isset($this->data['htaccess_original'])){
|
125 |
-
$this->refresh_rewrite_rules();
|
126 |
-
}
|
127 |
-
}
|
128 |
-
# Flush rules
|
129 |
/*
|
130 |
* @var $wp_rewrite WP_Rewrite
|
131 |
*/
|
132 |
-
|
133 |
-
|
134 |
-
|
135 |
-
|
136 |
-
|
137 |
-
|
138 |
-
|
139 |
-
|
140 |
-
|
141 |
-
|
142 |
-
|
143 |
-
|
144 |
-
|
145 |
-
|
146 |
-
|
147 |
-
|
148 |
-
|
149 |
-
|
150 |
-
|
151 |
-
|
152 |
-
|
153 |
-
|
154 |
-
|
155 |
-
|
156 |
-
|
157 |
-
|
158 |
-
|
159 |
-
|
160 |
-
|
161 |
-
|
162 |
-
|
163 |
-
|
164 |
-
|
165 |
-
|
166 |
-
|
167 |
-
|
168 |
-
|
169 |
-
|
170 |
-
|
171 |
-
|
172 |
-
|
173 |
-
|
174 |
-
|
175 |
-
|
176 |
-
|
177 |
-
|
178 |
-
|
179 |
-
|
180 |
-
|
181 |
-
|
182 |
-
|
183 |
-
|
184 |
-
|
185 |
-
|
186 |
-
|
187 |
-
|
188 |
-
|
189 |
-
|
190 |
-
|
191 |
-
|
192 |
-
|
193 |
-
|
194 |
-
|
195 |
-
|
196 |
-
|
197 |
-
|
198 |
-
|
199 |
-
|
200 |
-
|
201 |
-
|
202 |
-
|
203 |
-
|
204 |
-
|
205 |
-
|
206 |
-
|
207 |
-
|
208 |
-
|
209 |
-
|
210 |
-
|
211 |
-
|
212 |
-
|
213 |
-
|
214 |
-
|
215 |
-
|
216 |
-
|
217 |
-
|
218 |
-
|
219 |
-
|
220 |
-
|
221 |
-
|
222 |
-
|
223 |
-
|
224 |
-
|
225 |
-
|
226 |
-
|
227 |
-
|
228 |
-
|
229 |
-
|
230 |
-
|
231 |
-
|
232 |
-
|
233 |
-
|
234 |
-
|
235 |
-
|
236 |
-
|
237 |
-
|
238 |
-
|
239 |
-
|
240 |
-
|
241 |
-
|
242 |
-
|
243 |
-
|
244 |
-
|
245 |
-
|
246 |
-
|
247 |
-
|
248 |
-
|
249 |
-
|
250 |
-
|
251 |
-
|
252 |
-
|
253 |
-
|
254 |
-
|
255 |
-
|
256 |
-
|
257 |
-
|
258 |
-
|
259 |
-
|
260 |
-
|
261 |
-
|
262 |
-
|
263 |
-
|
264 |
-
|
265 |
-
|
266 |
-
|
267 |
-
|
268 |
-
|
269 |
-
|
270 |
-
|
271 |
-
|
272 |
-
|
273 |
-
|
274 |
-
|
275 |
-
|
276 |
-
|
277 |
-
|
278 |
-
|
279 |
-
|
280 |
-
|
281 |
-
|
282 |
-
|
283 |
-
|
284 |
-
|
285 |
-
|
286 |
-
|
287 |
-
|
288 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
289 |
/* var $wpdb WP_DB */
|
290 |
-
|
291 |
-
|
292 |
p.ID,
|
293 |
u.user_nicename,
|
294 |
MAX(p.post_modified_gmt) AS last_post
|
@@ -300,443 +336,455 @@ if (!class_exists("WPhtc")) {
|
|
300 |
AND p.post_status = 'publish'
|
301 |
AND p.post_type = 'post'
|
302 |
AND p.post_password = ''
|
303 |
-
" . (floatval($wp_version) < 2.1?"AND p.post_date_gmt <= '" . gmdate('Y-m-d H:i:59') . "'":"") . "
|
304 |
GROUP BY
|
305 |
u.ID,
|
306 |
u.user_nicename";
|
307 |
-
|
308 |
-
|
309 |
-
|
310 |
-
|
311 |
-
|
312 |
-
|
313 |
-
|
314 |
-
|
315 |
-
|
316 |
-
|
317 |
-
|
|
|
318 |
/*
|
319 |
* @var $wp_rewrite WP_Rewrite
|
320 |
* @return WP_Rewrite
|
321 |
*/
|
322 |
-
|
323 |
-
|
324 |
-
|
325 |
-
|
326 |
-
|
327 |
-
|
328 |
-
|
329 |
-
|
330 |
-
|
331 |
-
|
332 |
-
|
333 |
-
|
334 |
-
|
335 |
-
|
336 |
-
|
337 |
-
|
338 |
-
|
339 |
-
|
340 |
-
|
341 |
-
|
342 |
-
|
343 |
-
|
344 |
-
|
345 |
-
|
346 |
-
|
347 |
-
|
348 |
-
|
349 |
-
|
350 |
-
|
351 |
-
|
352 |
-
|
353 |
-
|
354 |
-
|
355 |
-
|
356 |
-
|
357 |
-
|
358 |
-
|
359 |
-
|
360 |
-
|
361 |
-
|
362 |
-
|
363 |
-
|
364 |
-
|
365 |
-
|
366 |
-
|
367 |
-
|
368 |
-
|
369 |
-
|
370 |
-
|
371 |
-
|
372 |
-
|
373 |
-
|
374 |
-
|
375 |
-
|
376 |
-
|
377 |
-
|
378 |
-
|
379 |
-
|
380 |
-
|
381 |
-
|
382 |
-
|
383 |
-
|
384 |
-
|
385 |
-
|
386 |
-
|
387 |
-
|
388 |
-
|
389 |
-
|
390 |
-
|
391 |
-
|
392 |
-
|
393 |
-
|
394 |
-
|
395 |
-
|
396 |
-
|
397 |
-
|
398 |
-
|
399 |
-
|
400 |
-
|
401 |
-
|
402 |
-
|
403 |
-
|
404 |
-
|
405 |
-
|
406 |
-
|
407 |
-
|
408 |
-
|
409 |
-
|
410 |
-
|
411 |
-
|
412 |
-
|
413 |
-
|
414 |
-
|
415 |
-
|
416 |
-
|
417 |
-
|
418 |
-
|
419 |
-
|
420 |
-
|
421 |
-
|
422 |
-
|
423 |
-
|
424 |
-
|
425 |
-
|
426 |
-
|
427 |
-
|
428 |
-
|
429 |
-
|
430 |
-
|
431 |
-
|
432 |
-
|
433 |
-
|
434 |
-
|
435 |
-
|
436 |
-
|
437 |
-
|
438 |
-
|
439 |
-
|
440 |
-
|
441 |
-
|
442 |
-
|
443 |
-
|
444 |
-
|
445 |
-
|
446 |
-
|
447 |
-
|
448 |
-
|
449 |
-
|
450 |
-
|
451 |
-
|
452 |
-
|
453 |
-
|
454 |
-
|
455 |
-
|
456 |
-
|
457 |
-
|
458 |
-
|
459 |
-
|
460 |
-
|
461 |
-
|
462 |
-
|
463 |
-
|
464 |
-
|
465 |
-
|
466 |
-
|
467 |
-
|
468 |
-
|
469 |
-
|
470 |
-
|
471 |
-
|
472 |
-
|
473 |
-
|
474 |
-
|
475 |
-
|
476 |
-
|
477 |
-
|
478 |
-
|
479 |
-
|
480 |
-
|
481 |
-
|
482 |
-
|
483 |
-
|
484 |
-
|
485 |
-
|
486 |
-
|
487 |
-
|
488 |
-
|
489 |
-
|
490 |
-
|
491 |
-
|
492 |
-
|
493 |
-
|
494 |
-
|
495 |
-
|
496 |
-
|
497 |
-
|
498 |
-
|
499 |
-
|
500 |
-
|
501 |
-
|
502 |
-
|
503 |
-
|
504 |
-
|
505 |
-
|
506 |
-
|
507 |
-
|
508 |
-
|
509 |
-
|
510 |
-
|
511 |
-
|
512 |
-
|
513 |
-
|
514 |
-
|
515 |
-
|
516 |
-
|
517 |
-
|
518 |
-
|
519 |
-
|
520 |
-
|
521 |
-
|
522 |
-
|
523 |
-
|
524 |
-
|
525 |
-
|
526 |
-
|
527 |
-
|
528 |
-
|
529 |
-
|
530 |
-
|
531 |
-
|
532 |
-
|
533 |
-
|
534 |
-
|
535 |
-
|
536 |
-
|
537 |
-
|
538 |
-
|
539 |
-
|
540 |
-
|
541 |
-
|
542 |
-
|
543 |
-
|
544 |
-
|
545 |
-
|
546 |
-
|
547 |
-
|
548 |
-
|
549 |
-
|
550 |
-
|
551 |
-
|
552 |
-
|
553 |
-
|
554 |
-
|
555 |
-
|
556 |
-
|
557 |
-
|
558 |
-
|
559 |
-
|
560 |
-
|
561 |
-
|
562 |
-
|
563 |
-
|
564 |
-
|
565 |
-
|
566 |
-
|
567 |
-
|
568 |
-
|
569 |
-
|
570 |
-
|
571 |
-
|
572 |
-
|
573 |
-
|
574 |
-
|
575 |
-
|
576 |
-
|
577 |
-
|
578 |
-
|
579 |
-
|
580 |
-
|
581 |
-
|
582 |
-
|
583 |
-
|
584 |
-
|
585 |
-
|
586 |
-
|
587 |
-
|
588 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
589 |
global $WPhtcEcho;
|
590 |
-
|
591 |
-
|
592 |
-
|
593 |
-
|
594 |
-
|
595 |
-
|
596 |
-
|
597 |
-
|
598 |
-
|
599 |
-
|
600 |
-
|
601 |
-
|
602 |
-
|
603 |
-
|
604 |
-
|
605 |
-
|
606 |
-
|
607 |
-
|
608 |
-
|
609 |
-
|
610 |
-
|
611 |
-
|
612 |
-
|
613 |
-
|
614 |
-
|
615 |
-
|
616 |
-
|
617 |
-
|
618 |
-
|
619 |
-
|
620 |
-
|
621 |
-
|
622 |
-
|
623 |
-
|
624 |
-
|
625 |
-
|
626 |
-
|
627 |
-
|
628 |
-
|
629 |
-
|
630 |
-
|
631 |
-
|
632 |
-
|
633 |
-
|
634 |
-
|
635 |
-
|
636 |
-
|
637 |
-
|
638 |
-
|
639 |
-
|
640 |
-
|
641 |
-
|
642 |
-
|
643 |
-
|
644 |
-
|
645 |
-
|
646 |
-
|
647 |
-
|
648 |
-
|
649 |
-
|
650 |
-
|
651 |
-
|
652 |
-
|
653 |
-
|
654 |
-
|
655 |
-
|
656 |
-
|
657 |
-
|
658 |
-
|
659 |
-
|
660 |
-
|
661 |
-
|
662 |
-
|
663 |
-
|
664 |
-
|
665 |
-
|
666 |
-
|
667 |
-
|
668 |
-
|
669 |
-
|
670 |
-
|
671 |
-
|
672 |
-
|
673 |
-
|
674 |
-
|
675 |
-
|
676 |
-
|
677 |
-
|
678 |
-
|
679 |
-
|
680 |
-
|
681 |
-
|
682 |
-
|
683 |
-
|
684 |
-
|
685 |
-
|
686 |
-
|
687 |
-
|
688 |
-
|
689 |
if (class_exists("WPhtc")) {
|
690 |
-
|
691 |
-
|
692 |
if (isset($WPhtc)) {
|
693 |
-
|
694 |
-
|
695 |
-
|
696 |
-
|
697 |
-
|
698 |
-
|
699 |
-
|
700 |
-
|
701 |
-
|
702 |
-
|
703 |
-
|
704 |
-
|
705 |
-
|
706 |
-
|
707 |
-
|
708 |
-
|
709 |
-
|
710 |
-
|
711 |
-
|
712 |
-
|
713 |
-
|
714 |
-
|
715 |
-
|
716 |
-
|
717 |
-
|
718 |
-
|
719 |
-
|
720 |
-
|
721 |
-
|
722 |
-
|
723 |
-
|
724 |
-
|
725 |
-
|
726 |
-
|
727 |
-
|
728 |
-
|
729 |
-
|
730 |
-
|
731 |
-
|
732 |
-
|
733 |
-
|
734 |
-
|
735 |
-
|
736 |
-
|
737 |
-
|
738 |
-
|
739 |
-
|
740 |
-
|
741 |
-
|
742 |
?>
|
27 |
Search redirection is based on Nice Search by Mark Jaquith, 2011 */
|
28 |
|
29 |
if (!class_exists("WPhtc")) {
|
30 |
+
class WPhtc
|
31 |
+
{
|
32 |
+
|
33 |
+
public $data;
|
34 |
+
|
35 |
+
function WPhtc()
|
36 |
+
{
|
37 |
+
$this->data = get_option('WPhtc_data');
|
38 |
+
}
|
39 |
+
|
40 |
/*
|
41 |
* @param $key
|
42 |
*/
|
43 |
+
function get_data($key, $key_inner = "")
|
44 |
+
{
|
45 |
+
if (isset($this->data[$key])) {
|
46 |
+
if ($key_inner != "" && isset($this->data[$key][$key_inner])) {
|
47 |
return $this->data[$key][$key_inner];
|
48 |
+
} else {
|
49 |
+
return $this->data[$key];
|
50 |
}
|
51 |
+
} else {
|
52 |
+
return false;
|
53 |
+
}
|
54 |
+
}
|
55 |
+
|
56 |
+
function init()
|
57 |
+
{
|
58 |
+
# set locale
|
59 |
+
$currentLocale = get_locale();
|
60 |
+
if (!empty($currentLocale)) {
|
61 |
+
$moFile = dirname(__FILE__) . "/lang/wp-htaccess-control-" . $currentLocale . ".mo";
|
62 |
+
if (@file_exists($moFile) && is_readable($moFile)) load_textdomain('wp-htaccess-control', $moFile);
|
63 |
+
}
|
64 |
+
}
|
65 |
+
|
66 |
+
function search_template_redirect()
|
67 |
+
{
|
68 |
+
# redirect "?s=*" to "/search-base/*"
|
69 |
+
if ($_GET['s']) {
|
70 |
+
wp_redirect(home_url($this->data['custom_search_permalink'] . "/" . rawurlencode(get_query_var('s'))));
|
71 |
+
}
|
72 |
+
|
73 |
+
# rewrite query
|
74 |
+
if (strpos($_SERVER["REQUEST_URI"], $this->data['custom_search_permalink'])) {
|
75 |
+
global $wp_query;
|
76 |
+
if (strpos($_SERVER["REQUEST_URI"], '/feed')) {
|
77 |
+
preg_match("/feed\/(feed|rdf|rss|rss2|atom)?/", $_SERVER["REQUEST_URI"], $feed);
|
78 |
+
if ($feed[1]) {
|
79 |
+
$format = "&feed=" . $feed[1];
|
80 |
+
} else {
|
81 |
+
$format = "&feed=feed";
|
82 |
+
}
|
83 |
+
}
|
84 |
+
$page_base = ($this->data['cpp'] != '') ? $this->data['cpp'] : 'page';
|
85 |
+
|
86 |
+
# in need of better regex
|
87 |
+
if (!strpos($_SERVER["REQUEST_URI"], '/feed') && !strpos($_SERVER["REQUEST_URI"], $page_base)) {
|
88 |
+
$pattern = "/\/" . $this->data['custom_search_permalink'] . "\/(.+)/";
|
89 |
+
} else {
|
90 |
+
$pattern = "/\/" . $this->data['custom_search_permalink'] . "\/(.+)\/feed|" . $page_base . "?/";
|
91 |
+
}
|
92 |
+
|
93 |
+
$pattern = "/\/" . $this->data['custom_search_permalink'] . "\/(.+)/";
|
94 |
+
preg_match($pattern, $_SERVER["REQUEST_URI"], $matches);
|
95 |
+
$results = split("/", $matches[1]);
|
96 |
+
if ($results[1] == $page_base) {
|
97 |
+
$page = "&paged=" . $results[2];
|
98 |
+
}
|
99 |
+
$wp_query = new WP_Query('s=' . $results[0] . $page . $format);
|
100 |
+
}
|
101 |
+
}
|
102 |
+
|
103 |
+
# return get_search_query on custom search base
|
104 |
+
function get_search_query_filter($query)
|
105 |
+
{
|
106 |
+
|
107 |
+
if ($this->data['custom_search_permalink'] != '' && strpos($_SERVER["REQUEST_URI"], $this->data['custom_search_permalink'])) {
|
108 |
+
$page_base = ($this->data['cpp'] != '') ? $this->data['cpp'] : 'page';
|
109 |
+
# in need of better regex
|
110 |
+
if (!strpos($_SERVER["REQUEST_URI"], '/feed') && !strpos($_SERVER["REQUEST_URI"], "/" . $page_base)) {
|
111 |
+
$pattern = "/\/" . $this->data['custom_search_permalink'] . "\/(.+)/";
|
112 |
+
} else {
|
113 |
+
$pattern = "/\/" . $this->data['custom_search_permalink'] . "\/(.+)\/feed|" . $page_base . "?/";
|
114 |
}
|
115 |
+
preg_match($pattern, $_SERVER["REQUEST_URI"], $matches);
|
116 |
+
$results = split("/", $matches[1]);
|
117 |
+
return urldecode($results[0]);
|
118 |
}
|
119 |
+
return $query;
|
120 |
+
}
|
121 |
+
|
122 |
+
function search_feed_link($link)
|
123 |
+
{
|
124 |
+
|
125 |
+
$link = str_replace("search", $this->data['custom_search_permalink'], $link);
|
126 |
+
return $link;
|
127 |
+
}
|
128 |
+
|
129 |
+
function check_first_run()
|
130 |
+
{
|
131 |
+
|
132 |
+
# flush rules to get some data filled on first usage
|
133 |
+
if (!isset($this->data['htaccess_original'])) {
|
134 |
+
$this->refresh_rewrite_rules();
|
135 |
}
|
136 |
}
|
137 |
+
|
138 |
+
# Flush rules
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
139 |
/*
|
140 |
* @var $wp_rewrite WP_Rewrite
|
141 |
*/
|
142 |
+
function refresh_rewrite_rules()
|
143 |
+
{
|
144 |
+
global $wp_rewrite;
|
145 |
+
$wp_rewrite->flush_rules();
|
146 |
+
}
|
147 |
+
|
148 |
+
function refresh_rewrite_rules_later()
|
149 |
+
{
|
150 |
+
wp_schedule_single_event(time(), 'flush_event');
|
151 |
+
}
|
152 |
+
|
153 |
+
# Filter pagination links generated by WordPress
|
154 |
+
function filter_get_pagenum_link($result)
|
155 |
+
{
|
156 |
+
$result = preg_replace("/" . urlencode($this->data['cpp']) . "\/[0-9]+[\/]?/", "", $result);
|
157 |
+
$result = str_replace("page", urlencode($this->data['cpp']), $result);
|
158 |
+
return $result;
|
159 |
+
}
|
160 |
+
|
161 |
+
# Filter link generated by get_author_posts_url() to use the Custom Author Permalink
|
162 |
+
function filter_author_link($link)
|
163 |
+
{
|
164 |
+
|
165 |
+
if ($this->data['remove_author_base']) {
|
166 |
+
$link = str_replace("author/", "", $link);
|
167 |
+
} else if (isset($this->data['cap']) && $this->data['cap'] != '') {
|
168 |
+
$link = str_replace("author", urlencode($this->data['cap']), $link);
|
169 |
+
}
|
170 |
+
return $link;
|
171 |
+
}
|
172 |
+
|
173 |
+
function filter_redirect_canonical($requested_url)
|
174 |
+
{
|
175 |
+
global $wp;
|
176 |
+
|
177 |
+
# Disable canonical redirection on urls using custom pagination permalink
|
178 |
+
if (isset($this->data['cpp']) && $this->data['cpp'] != '' && get_query_var('paged') > 1 && preg_match("/" . urlencode($this->data['cpp']) . "/", $wp->request)) {
|
179 |
+
return false;
|
180 |
+
} else {
|
181 |
+
return $requested_url;
|
182 |
+
}
|
183 |
+
}
|
184 |
+
|
185 |
+
# ancestors nesting method
|
186 |
+
function term_ancestors($tax, $id)
|
187 |
+
{
|
188 |
+
$term = get_term($id, $tax);
|
189 |
+
$ancestor = $term->slug;
|
190 |
+
|
191 |
+
if ($term->parent != 0 && !$this->data['remove_hierarchy']) {
|
192 |
+
$ancestor = $this->term_ancestors($tax, $term->parent) . "/" . $ancestor;
|
193 |
+
}
|
194 |
+
return $ancestor;
|
195 |
+
}
|
196 |
+
|
197 |
+
# Rewrite Rules: Add Category + Tag + Author Archives; Custom Pagination; Custom Author Base
|
198 |
+
function filter_rewrite_rules($rewrite_rules)
|
199 |
+
{
|
200 |
+
|
201 |
+
$new_rules = array();
|
202 |
+
|
203 |
+
$page_base = ($this->data['cpp'] != '') ? $this->data['cpp'] : 'page';
|
204 |
+
|
205 |
+
// if we have either to remove the tax base or create tax archives
|
206 |
+
if (isset($this->data['create_archive']) or isset($this->data['remove_taxonomy_base'])) {
|
207 |
+
foreach (get_taxonomies('', 'objects') as $taxonomy) {
|
208 |
+
if (!$taxonomy->rewrite
|
209 |
+
or (
|
210 |
+
(
|
211 |
+
isset($this->data['remove_taxonomy_base'][$taxonomy->name])
|
212 |
+
and (
|
213 |
+
isset($this->data['remove_taxonomy_base'][$taxonomy->name])
|
214 |
+
and !$this->data['remove_taxonomy_base'][$taxonomy->name])
|
215 |
+
)
|
216 |
+
and !$this->data['create_archive'][$taxonomy->name]
|
217 |
+
)
|
218 |
+
) {
|
219 |
+
continue;
|
220 |
+
}
|
221 |
+
/*
|
222 |
+
* @todo this should be rewritten: UNLESS we are removing the tax base we should be using a wildcard for tax term
|
223 |
+
*/
|
224 |
+
$terms = get_terms($taxonomy->name, array("hide_empty" => false));
|
225 |
+
foreach ($terms as $term) {
|
226 |
+
$base = isset($this->data['remove_taxonomy_base'], $this->data['remove_taxonomy_base'][$taxonomy->name])
|
227 |
+
? ""
|
228 |
+
: $taxonomy->rewrite['slug'] . "/";
|
229 |
+
if ($term->parent != 0 && !$this->data['remove_hierarchy']) {
|
230 |
+
$ancestors = $this->term_ancestors($taxonomy->name, $term->parent) . "/";
|
231 |
+
} else {
|
232 |
+
$ancestors = "";
|
233 |
+
}
|
234 |
+
|
235 |
+
$tax_name = $taxonomy->name;
|
236 |
+
|
237 |
+
# create archives
|
238 |
+
if (isset($this->data['create_archive'][$tax_name])) {
|
239 |
+
#year
|
240 |
+
$new_rules[$base . $ancestors . '(' . $term->slug . ')/([0-9]{4})/?$'] = 'index.php?' . $tax_name . '=$matches[1]&year=$matches[2]';
|
241 |
+
$new_rules[$base . $ancestors . '(' . $term->slug . ')/([0-9]{4})/' . $page_base . '/?([0-9]{1,})/?$'] = 'index.php?' . $tax_name . '=$matches[1]&year=$matches[2]&paged=$matches[3]';
|
242 |
+
#year/month
|
243 |
+
$new_rules[$base . $ancestors . '(' . $term->slug . ')/([0-9]{4})/([0-9]{2})/?$'] = 'index.php?' . $tax_name . '=$matches[1]&year=$matches[2]&monthnum=$matches[3]';
|
244 |
+
$new_rules[$base . $ancestors . '(' . $term->slug . ')/([0-9]{4})/([0-9]{2})/' . $page_base . '/?([0-9]{1,})/?$'] = 'index.php?' . $tax_name . '=$matches[1]&year=$matches[2]&monthnum=$matches[3]&paged=$matches[4]';
|
245 |
+
#year/month/day
|
246 |
+
$new_rules[$base . $ancestors . '(' . $term->slug . ')/([0-9]{4})/([0-9]{2})/([0-9]{2})/?$'] = 'index.php?' . $tax_name . '=$matches[1]&year=$matches[2]&monthnum=$matches[3]&day=$matches[4]';
|
247 |
+
$new_rules[$base . $ancestors . '(' . $term->slug . ')/([0-9]{4})/([0-9]{2})/([0-9]{2})/' . $page_base . '/?([0-9]{1,})/?$'] = 'index.php?' . $tax_name . '=$matches[1]&year=$matches[2]&monthnum=$matches[3]&day=$matches[4]&paged=$matches[5]';
|
248 |
+
}
|
249 |
+
# create rewrite rules with tax base
|
250 |
+
|
251 |
+
# appending ".html" to taxonomy permalinks
|
252 |
+
$suffix = $this->data['suffix_html'] ? ".html" : "";
|
253 |
+
|
254 |
+
if (!$base) {
|
255 |
+
$new_rules[$ancestors . '(' . $term->slug . ')/(?:feed/)?(feed|rdf|rss|rss2|atom)/?$'] = 'index.php?' . $tax_name . '=$matches[1]&feed=$matches[2]';
|
256 |
+
$new_rules[$ancestors . '(' . $term->slug . ')/page/?([0-9]{1,})/?$'] = 'index.php?' . $tax_name . '=$matches[1]&paged=$matches[2]';
|
257 |
+
$new_rules[$ancestors . '(' . $term->slug . ')' . $suffix . '/?$'] = 'index.php?' . $tax_name . '=$matches[1]';
|
258 |
+
}
|
259 |
+
$rewrite_rules = $new_rules + $rewrite_rules;
|
260 |
+
}
|
261 |
+
}
|
262 |
+
}
|
263 |
+
|
264 |
+
# Author Archives
|
265 |
+
if ($this->data['remove_author_base']) {
|
266 |
+
$blogusers = get_users('who=authors');
|
267 |
+
foreach ($blogusers as $user) {
|
268 |
+
|
269 |
+
$new_rules = array(
|
270 |
+
'(' . $user->user_nicename . ')/([0-9]{4})/?$' => 'index.php?author_name=$matches[1]&year=$matches[2]',
|
271 |
+
'(' . $user->user_nicename . ')/([0-9]{4})/' . $page_base . '/?([0-9]{1,})/?$' => 'index.php?author_name=$matches[1]&year=$matches[2]&paged=$matches[3]',
|
272 |
+
|
273 |
+
'(' . $user->user_nicename . ')/([0-9]{4})/([0-9]{2})/?$' => 'index.php?author_name=$matches[1]&year=$matches[2]&monthnum=$matches[3]',
|
274 |
+
'(' . $user->user_nicename . ')/([0-9]{4})/([0-9]{2})/' . $page_base . '/?([0-9]{1,})/?$' => 'index.php?author_name=$matches[1]&year=$matches[2]&monthnum=$matches[3]&paged=$matches[4]',
|
275 |
+
|
276 |
+
'(' . $user->user_nicename . ')/([0-9]{4})/([0-9]{2})/([0-9]{2})/?$' => 'index.php?author_name=$matches[1]&year=$matches[2]&monthnum=$matches[3]&day=$matches[4]',
|
277 |
+
'(' . $user->user_nicename . ')/([0-9]{4})/([0-9]{2})/([0-9]{2})/' . $page_base . '/?([0-9]{1,})/?$' => 'index.php?author_name=$matches[1]&year=$matches[2]&monthnum=$matches[3]&day=$matches[4]&paged=$matches[5]');
|
278 |
+
|
279 |
+
$rewrite_rules = $new_rules + $rewrite_rules;
|
280 |
+
}
|
281 |
+
} else if (isset($this->data['author_archives'])) {
|
282 |
+
$author_base = ($this->data['cap'] != '') ? $this->data['cap'] : 'author';
|
283 |
+
$new_rules = array(
|
284 |
+
$author_base . '/([^/]+)/([0-9]{4})/?$' => 'index.php?author_name=$matches[1]&year=$matches[2]',
|
285 |
+
$author_base . '/([^/]+)/([0-9]{4})/' . $page_base . '/?([0-9]{1,})/?$' => 'index.php?author_name=$matches[1]&year=$matches[2]&paged=$matches[3]',
|
286 |
+
|
287 |
+
$author_base . '/([^/]+)/([0-9]{4})/([0-9]{2})/?$' => 'index.php?author_name=$matches[1]&year=$matches[2]&monthnum=$matches[3]',
|
288 |
+
$author_base . '/([^/]+)/([0-9]{4})/([0-9]{2})/' . $page_base . '/?([0-9]{1,})/?$' => 'index.php?author_name=$matches[1]&year=$matches[2]&monthnum=$matches[3]&paged=$matches[4]',
|
289 |
+
|
290 |
+
$author_base . '/([^/]+)/([0-9]{4})/([0-9]{2})/([0-9]{2})/?$' => 'index.php?author_name=$matches[1]&year=$matches[2]&monthnum=$matches[3]&day=$matches[4]',
|
291 |
+
$author_base . '/([^/]+)/([0-9]{4})/([0-9]{2})/([0-9]{2})/' . $page_base . '/?([0-9]{1,})/?$' => 'index.php?author_name=$matches[1]&year=$matches[2]&monthnum=$matches[3]&day=$matches[4]&paged=$matches[5]');
|
292 |
+
|
293 |
+
$rewrite_rules = $new_rules + $rewrite_rules;
|
294 |
+
}
|
295 |
+
|
296 |
+
# Custom Pagination; Custom Author Permalink
|
297 |
+
if ((isset($this->data['cap']) && $this->data['cap'] != '') || (isset($this->data['cpp']) && $this->data['cpp'] != '')) {
|
298 |
+
$rewrite_rules = serialize($rewrite_rules);
|
299 |
+
# Author
|
300 |
+
if (isset($this->data['cap']) && $this->data['cap'] != '') {
|
301 |
+
$rewrite_rules = str_replace('author/', $this->data['cap'] . '/', $rewrite_rules);
|
302 |
+
}
|
303 |
+
# Pagination
|
304 |
+
if (isset($this->data['cpp']) && $this->data['cpp'] != '') {
|
305 |
+
$rewrite_rules = str_replace('page/', $this->data['cpp'] . '/', $rewrite_rules);
|
306 |
+
}
|
307 |
+
# Search
|
308 |
+
if (isset($this->data['custom_search_permalink']) && $this->data['custom_search_permalink'] != '') {
|
309 |
+
$rewrite_rules = str_replace('search/', $this->data['custom_search_permalink'] . '/', $rewrite_rules);
|
310 |
+
}
|
311 |
+
|
312 |
+
$rewrite_rules = unserialize(preg_replace('!s:(\d+):"(.*?)";!se', "'s:'.strlen('$2').':\"$2\";'", $rewrite_rules));
|
313 |
+
}
|
314 |
+
return $rewrite_rules;
|
315 |
+
}
|
316 |
+
|
317 |
+
# Adding our Custom Author Base to the sitemap generated by Google XML Sitemaps
|
318 |
+
# Adapted from sitemap-core.php (line ~2036)
|
319 |
+
function set_sm()
|
320 |
+
{
|
321 |
+
|
322 |
+
if (class_exists('GoogleSitemapGenerator') && $this->data['cap'] != '') {
|
323 |
+
$generatorObject = & GoogleSitemapGenerator::GetInstance();
|
324 |
+
if ($generatorObject != null) {
|
325 |
/* var $wpdb WP_DB */
|
326 |
+
global $wpdb, $wp_version;
|
327 |
+
$sql = "SELECT DISTINCT
|
328 |
p.ID,
|
329 |
u.user_nicename,
|
330 |
MAX(p.post_modified_gmt) AS last_post
|
336 |
AND p.post_status = 'publish'
|
337 |
AND p.post_type = 'post'
|
338 |
AND p.post_password = ''
|
339 |
+
" . (floatval($wp_version) < 2.1 ? "AND p.post_date_gmt <= '" . gmdate('Y-m-d H:i:59') . "'" : "") . "
|
340 |
GROUP BY
|
341 |
u.ID,
|
342 |
u.user_nicename";
|
343 |
+
$authors = $wpdb->get_results($sql);
|
344 |
+
if ($authors && is_array($authors)) {
|
345 |
+
foreach ($authors as $author) {
|
346 |
+
$url = get_bloginfo('url') . "/" . $this->data['cap'] . "/" . $author->user_nicename . "/";
|
347 |
+
$generatorObject->AddUrl($url, $generatorObject->GetTimestampFromMySql($author->last_post), $generatorObject->GetOption("cf_auth"), $generatorObject->GetOption("pr_auth"));
|
348 |
+
}
|
349 |
+
}
|
350 |
+
}
|
351 |
+
}
|
352 |
+
}
|
353 |
+
|
354 |
+
# Adding rewrite pairs to the .htaccess generated by WordPress, everytime the rules are flush
|
355 |
/*
|
356 |
* @var $wp_rewrite WP_Rewrite
|
357 |
* @return WP_Rewrite
|
358 |
*/
|
359 |
+
function wp_rewrite_rules($wp_rewrite)
|
360 |
+
{
|
361 |
+
# Keeping a copy of the generated htaccess in our option array for later reviewing
|
362 |
+
$this->data['cur_hta'] = '# BEGIN WordPress<br/>' . nl2br($wp_rewrite->mod_rewrite_rules()) . "# END WordPress";
|
363 |
+
update_option('WPhtc_data', $this->data);
|
364 |
+
return $wp_rewrite;
|
365 |
+
}
|
366 |
+
|
367 |
+
# Adding Custom Rules to htaccess file generated by WordPress, everytime the rules are flush
|
368 |
+
function hta_rules($rules)
|
369 |
+
{
|
370 |
+
$new_rules = "";
|
371 |
+
# keeping original hta
|
372 |
+
if (!isset($this->data['htaccess_original'])) {
|
373 |
+
$this->data['htaccess_original'] = $rules;
|
374 |
+
update_option('WPhtc_data', $this->data);
|
375 |
+
}
|
376 |
+
# Maintenance Mode
|
377 |
+
if ($this->data['maintenance_active'] && isset($this->data['maintenance_ips'][0])) {
|
378 |
+
$no_ips = count($this->data['maintenance_ips']);
|
379 |
+
$new_rules .= "\n# WPhtc: Begin Maintenance Mode\n";
|
380 |
+
# redirect
|
381 |
+
if ($this->data['maintenance_redirection'] != '') {
|
382 |
+
$new_rules .= "RewriteEngine on\n";
|
383 |
+
$new_rules .= "RewriteCond %{REQUEST_URI} !\.(jpe?g|png|gif) [NC]\n";
|
384 |
+
for ($i = 0; $i < $no_ips; $i++) {
|
385 |
+
$new_rules .= "RewriteCond %{REMOTE_HOST} !^" . str_replace(".", "\.", trim($this->data['maintenance_ips'][$i])) . "\n";
|
386 |
+
}
|
387 |
+
if (substr($this->data['maintenance_redirection'], 0, 1) == "/") {
|
388 |
+
$new_rules .= "RewriteCond %{REQUEST_URI} !" . $this->data['maintenance_redirection'] . "$ [NC]\n";
|
389 |
+
}
|
390 |
+
$new_rules .= "RewriteRule .* " . $this->data['maintenance_redirection'] . " [R=302,L]\n";
|
391 |
+
} # no redirection
|
392 |
+
else {
|
393 |
+
$new_rules .= "order deny,allow\n";
|
394 |
+
$new_rules .= "deny from all\n";
|
395 |
+
foreach ($this->data['maintenance_ips'] as $ip) {
|
396 |
+
$new_rules .= "allow from " . $ip . "\n";
|
397 |
+
}
|
398 |
+
}
|
399 |
+
$new_rules .= "# WPhtc: End Maintenance Mode\n";
|
400 |
+
}
|
401 |
+
|
402 |
+
# Login Control
|
403 |
+
if ($this->data['login_disabled']) {
|
404 |
+
$no_ips = count($this->data['login_ips']);
|
405 |
+
$new_rules .= "\n# WPhtc: Begin Login Control (start deleting here if you're having trouble logging in)\n";
|
406 |
+
# redirect
|
407 |
+
$new_rules .= "RewriteEngine on\n";
|
408 |
+
$new_rules .= "RewriteCond %{REQUEST_URI} .wp-login\.php* [NC]\n";
|
409 |
+
if ($this->data['login_half_mode']) {
|
410 |
+
$new_rules .= "RewriteCond %{REQUEST_METHOD} !=POST\n";
|
411 |
+
$new_rules .= "RewriteCond %{QUERY_STRING} !action=(logout|lostpassword|postpass|retrievepassword|resetpass|rp)*\n";
|
412 |
+
}
|
413 |
+
if ($no_ips > 0) {
|
414 |
+
for ($i = 0; $i < $no_ips; $i++) {
|
415 |
+
$new_rules .= "RewriteCond %{REMOTE_HOST} !^" . str_replace(".", "\.", trim($this->data['login_ips'][$i])) . "\n";
|
416 |
+
}
|
417 |
+
}
|
418 |
+
$new_rules .= "RewriteRule .* " . $this->data['login_redirection'] . " [R=301,L]\n";
|
419 |
+
$new_rules .= "# WPhtc: End Login Control Mode (stop deleting here if you're having trouble logging in)\n";
|
420 |
+
}
|
421 |
+
# Custom htaccess
|
422 |
+
if ($this->data['hta']) {
|
423 |
+
$new_rules .= "\n# WPhtc: Begin Custom htaccess\n";
|
424 |
+
$new_rules .= stripslashes($this->data['hta']) . "\n";
|
425 |
+
$new_rules .= "# WPhtc: End Custom htaccess\n";
|
426 |
+
}
|
427 |
+
# htaccess suggestions
|
428 |
+
if ($this->data['disable_serversignature']) {
|
429 |
+
$new_rules .= "\n# WPhtC: Disable ServerSignature on generated error pages\n";
|
430 |
+
$new_rules .= "ServerSignature Off\n";
|
431 |
+
}
|
432 |
+
if ($this->data['admin_email']) {
|
433 |
+
$new_rules .= "\n# WPhtC: Set admin email\n";
|
434 |
+
$new_rules .= "SetEnv SERVER_ADMIN " . $this->data['admin_email'] . "\n\n";
|
435 |
+
}
|
436 |
+
if ($this->data['disable_indexes']) {
|
437 |
+
$new_rules .= "\n# WPhtC: Disable directory browsing\n";
|
438 |
+
$new_rules .= "Options All -Indexes\n";
|
439 |
+
}
|
440 |
+
if ($this->data['up_limit']) {
|
441 |
+
$new_rules .= "\n# WPhtC: Limit upload size to " . $this->data['up_limit'] . " MB\n";
|
442 |
+
$new_rules .= "LimitRequestBody " . ($this->data['up_limit'] * 1024 * 1024) . " \n";
|
443 |
+
}
|
444 |
+
if ($this->data['redirect_500']) {
|
445 |
+
$new_rules .= "\n# WPhtC: Setting 500 Error page\n";
|
446 |
+
$new_rules .= "ErrorDocument 500 " . $this->data['redirect_500'] . "\n";
|
447 |
+
}
|
448 |
+
if ($this->data['redirect_403']) {
|
449 |
+
$new_rules .= "\n# WPhtC: Setting 403 Error page\n";
|
450 |
+
$new_rules .= "ErrorDocument 403 " . $this->data['redirect_403'] . "\n";
|
451 |
+
}
|
452 |
+
if ($this->data['protect_wp_config']) {
|
453 |
+
$new_rules .= "\n# WPhtC: Protect WP-config.php\n";
|
454 |
+
$new_rules .= "<files wp-config.php>\n";
|
455 |
+
$new_rules .= "order allow,deny\n";
|
456 |
+
$new_rules .= "deny from all\n";
|
457 |
+
$new_rules .= "</files>\n";
|
458 |
+
}
|
459 |
+
if ($this->data['protect_htaccess']) {
|
460 |
+
$new_rules .= "\n# WPhtC: Protect .htaccess file\n";
|
461 |
+
$new_rules .= "<files ~ \"^.*\.([Hh][Tt][Aa])\">\n";
|
462 |
+
$new_rules .= "order allow,deny\n";
|
463 |
+
$new_rules .= "deny from all\n";
|
464 |
+
$new_rules .= "</files>\n";
|
465 |
+
}
|
466 |
+
if ($this->data['protect_comments']) {
|
467 |
+
$new_rules .= "\n# WPhtC: Protect comments.php\n";
|
468 |
+
$new_rules .= "RewriteCond %{REQUEST_METHOD} POST\n";
|
469 |
+
$new_rules .= "RewriteCond %{REQUEST_URI} .wp-comments-post\.php*\n";
|
470 |
+
$new_rules .= "RewriteCond %{HTTP_REFERER} !.*" . get_bloginfo('url') . ".* [OR]\n";
|
471 |
+
$new_rules .= "RewriteCond %{HTTP_USER_AGENT} ^$\n";
|
472 |
+
$new_rules .= "RewriteRule (.*) ^http://%{REMOTE_ADDR}/$ [R=301,L]\n";
|
473 |
+
}
|
474 |
+
if ($this->data['disable_hotlink']) {
|
475 |
+
$new_rules .= "\n# WPhtC: Disable image hotlinking\n";
|
476 |
+
$new_rules .= "<IfModule mod_rewrite.c>\n";
|
477 |
+
$new_rules .= "RewriteEngine on\n";
|
478 |
+
$new_rules .= "RewriteCond %{HTTP_REFERER} !^$\n";
|
479 |
+
$new_rules .= "RewriteCond %{HTTP_REFERER} !^http(s)?://(www\.)?" . str_ireplace(array("http://", "www."), "", get_bloginfo("url")) . "/.*$ [NC]\n";
|
480 |
+
$new_rules .= "RewriteRule \.(jpg|jpeg|png|gif)$ " . $this->data['disable_hotlink'] . " [NC,R,L]\n";
|
481 |
+
$new_rules .= "</IfModule>\n";
|
482 |
+
}
|
483 |
+
if ($this->data['disable_file_hotlink_ext']) {
|
484 |
+
$redir = $this->data['disable_file_hotlink_redir'] ? $this->data['disable_file_hotlink_redir'] : "_";
|
485 |
+
$new_rules .= "\n# WPhtC: Disable file hotlinking\n";
|
486 |
+
$new_rules .= "<IfModule mod_rewrite.c>\n";
|
487 |
+
$new_rules .= "RewriteEngine on\n";
|
488 |
+
$new_rules .= "RewriteCond %{HTTP_REFERER} !^$\n";
|
489 |
+
$new_rules .= "RewriteCond %{HTTP_REFERER} !^http(s)?://(www\.)?" . str_ireplace(array("http://", "www."), "", get_bloginfo("url")) . "/.*$ [NC]\n";
|
490 |
+
$new_rules .= "RewriteRule \.(" . str_replace(" ", "|", $this->data['disable_file_hotlink_ext']) . ")$ " . $redir . " [NC,R,L]\n";
|
491 |
+
$new_rules .= "</IfModule>\n";
|
492 |
+
}
|
493 |
+
if ($this->data['canon']) {
|
494 |
+
$url = str_ireplace(array("http://", "www."), "", get_bloginfo("url"));
|
495 |
+
$domain = explode("/", $url);
|
496 |
+
$escaped_domain = str_ireplace(".", "\.", $domain[0]);
|
497 |
+
if ($this->data['canon'] == 'www') {
|
498 |
+
$siteurl = get_option('siteurl');
|
499 |
+
if (!preg_match('/^http:\/\/www\./', $siteurl)) {
|
500 |
+
$siteurl = str_replace("http://", "http://www.", $siteurl);
|
501 |
+
update_option('siteurl', $siteurl);
|
502 |
+
}
|
503 |
+
$homeurl = get_option('home');
|
504 |
+
if (!preg_match('/^http:\/\/www\./', $homeurl)) {
|
505 |
+
$homeurl = str_replace("http://", "http://www.", $homeurl);
|
506 |
+
update_option('home', $homeurl);
|
507 |
+
}
|
508 |
+
} else if ($this->data['canon'] == 'simple') {
|
509 |
+
$siteurl = get_option('siteurl');
|
510 |
+
if (preg_match('/^http:\/\/www\./', $siteurl)) {
|
511 |
+
$siteurl = str_replace("http://www.", "http://", $siteurl);
|
512 |
+
update_option('siteurl', $siteurl);
|
513 |
+
}
|
514 |
+
$homeurl = get_option('home');
|
515 |
+
if (preg_match('/^http:\/\/www\./', $homeurl)) {
|
516 |
+
$homeurl = str_replace("http://www.", "http://", $homeurl);
|
517 |
+
update_option('home', $homeurl);
|
518 |
+
}
|
519 |
+
}
|
520 |
+
}
|
521 |
+
if ($this->data['gzip']) {
|
522 |
+
$new_rules .= "\n# WPhtC: Setting mod_gzip\n";
|
523 |
+
$new_rules .= "<ifModule mod_gzip.c>\n";
|
524 |
+
$new_rules .= "mod_gzip_on Yes\n";
|
525 |
+
$new_rules .= "mod_gzip_dechunk Yes\n";
|
526 |
+
$new_rules .= "mod_gzip_item_include file \.(html?|txt|css|js|php|pl)$\n";
|
527 |
+
$new_rules .= "mod_gzip_item_include handler ^cgi-script$\n";
|
528 |
+
$new_rules .= "mod_gzip_item_include mime ^text/.*\n";
|
529 |
+
$new_rules .= "mod_gzip_item_include mime ^application/x-javascript.*\n";
|
530 |
+
$new_rules .= "mod_gzip_item_exclude mime ^image/.*\n";
|
531 |
+
$new_rules .= "mod_gzip_item_exclude rspheader ^Content-Encoding:.*gzip.*\n";
|
532 |
+
$new_rules .= "</ifModule>\n";
|
533 |
+
}
|
534 |
+
if ($this->data['deflate']) {
|
535 |
+
$new_rules .= "\n# WPhtC: Setting mod_deflate\n";
|
536 |
+
$new_rules .= "<IfModule mod_deflate.c>\n";
|
537 |
+
$new_rules .= "AddOutputFilterByType DEFLATE text/html text/plain text/xml application/xml application/xhtml+xml text/javascript text/css application/x-javascript\n";
|
538 |
+
$new_rules .= "BrowserMatch ^Mozilla/4 gzip-only-text/html\n";
|
539 |
+
$new_rules .= "BrowserMatch ^Mozilla/4.0[678] no-gzip\n";
|
540 |
+
$new_rules .= "BrowserMatch bMSIE !no-gzip !gzip-only-text/html\n";
|
541 |
+
$new_rules .= "Header append Vary User-Agent env=!dont-vary\n";
|
542 |
+
$new_rules .= "</IfModule>\n";
|
543 |
+
}
|
544 |
+
if ($this->data['wp_hta'] && trim($this->data['wp_hta']) != '') {
|
545 |
+
$new_rules .= "\n" . $this->data['wp_hta'];
|
546 |
+
} else {
|
547 |
+
$new_rules .= "\n" . $rules;
|
548 |
+
}
|
549 |
+
return $new_rules;
|
550 |
+
}
|
551 |
+
|
552 |
+
# Filter Term Link
|
553 |
+
function filter_term_link($termlink, $term, $taxonomy)
|
554 |
+
{
|
555 |
+
// WPhtc -> this
|
556 |
+
if ($this->data['remove_taxonomy_base'][$taxonomy]) {
|
557 |
+
$txs = get_taxonomies(array('name' => $taxonomy), "object");
|
558 |
+
foreach ($txs as $t) {
|
559 |
+
//return str_replace($t->rewrite['slug']."/","",$termlink);
|
560 |
+
if ($term->parent != 0 && !$this->data['remove_hierarchy']) {
|
561 |
+
return get_bloginfo('url') . "/" . $this->term_ancestors($taxonomy, $term->parent) . "/" . $term->slug;
|
562 |
+
} else {
|
563 |
+
return get_bloginfo('url') . "/" . $term->slug;
|
564 |
+
}
|
565 |
+
}
|
566 |
+
} else
|
567 |
+
return $termlink;
|
568 |
+
}
|
569 |
+
|
570 |
+
# Filter Taxonomy Base
|
571 |
+
function remove_taxonomy_base_from_rewrite_rules($rules)
|
572 |
+
{
|
573 |
+
# Let's remove every taxonomy rule here, we'll reacreate them at filter_rewrite_rules()
|
574 |
+
return array();
|
575 |
+
//return $rules;
|
576 |
+
}
|
577 |
+
|
578 |
+
# Filter Author Rewrite Rules
|
579 |
+
function remove_author_base_from_rewrite_rules($author_rewrite)
|
580 |
+
{
|
581 |
+
|
582 |
+
if ($this->data['remove_author_base']) {
|
583 |
+
$author_rewrite = array();
|
584 |
+
$blogusers = get_users('who=authors');
|
585 |
+
foreach ($blogusers as $user) {
|
586 |
+
$author_rewrite['(' . $user->user_nicename . ')/(?:feed/)?(feed|rdf|rss|rss2|atom)/?$'] = 'index.php?author_name=$matches[1]&feed=$matches[2]';
|
587 |
+
$author_rewrite['(' . $user->user_nicename . ')/page/?([0-9]{1,})/?$'] = 'index.php?author_name=$matches[1]&paged=$matches[2]';
|
588 |
+
$author_rewrite['(' . $user->user_nicename . ')/?$'] = 'index.php?author_name=$matches[1]';
|
589 |
+
}
|
590 |
+
}
|
591 |
+
return $author_rewrite;
|
592 |
+
}
|
593 |
+
|
594 |
+
# WP-htaccess Control options page interface
|
595 |
+
function page()
|
596 |
+
{
|
597 |
+
include(dirname(__FILE__) . '/wp-htaccess-control-ui.php');
|
598 |
+
}
|
599 |
+
|
600 |
+
# Adding our options page to the admin menu
|
601 |
+
function configure_menu()
|
602 |
+
{
|
603 |
+
if (current_user_can("administrator")) {
|
604 |
+
$page = add_submenu_page("options-general.php", "WP htaccess Control", "htaccess Control", 'activate_plugins', __FILE__, array('WPhtc', 'page'));
|
605 |
+
add_action('admin_print_scripts-' . $page, array('WPhtc', 'page_script'));
|
606 |
+
add_action('admin_print_styles-' . $page, array('WPhtc', 'page_style'));
|
607 |
+
}
|
608 |
+
}
|
609 |
+
|
610 |
+
# Enqueue Ui Scripts on Plugin page
|
611 |
+
function page_script()
|
612 |
+
{
|
613 |
+
wp_enqueue_script("htaccess-control-js", WP_PLUGIN_URL . '/wp-htaccess-control/wp-htaccess-control-ui.js');
|
614 |
+
}
|
615 |
+
|
616 |
+
# Enqueue Ui Scripts on Plugin page
|
617 |
+
function page_style()
|
618 |
+
{
|
619 |
+
wp_enqueue_style("htaccess-control-css", WP_PLUGIN_URL . '/wp-htaccess-control/wp-htaccess-control-ui.css');
|
620 |
+
}
|
621 |
+
|
622 |
+
# Filter "View" Link on Administration
|
623 |
+
function filter_tax_table_actions($actions, $tag)
|
624 |
+
{
|
625 |
+
if ($tag->parent != 0) {
|
626 |
+
$actions['view'] = '<a href="' . get_bloginfo('url') . '/' . $this->term_ancestors($tag->taxonomy, $tag->parent) . '/' . $tag->slug . '">View</a>';
|
627 |
+
}
|
628 |
+
return $actions;
|
629 |
+
}
|
630 |
+
|
631 |
+
# Options Page Actions
|
632 |
+
function page_action()
|
633 |
+
{
|
634 |
+
$this->check_first_run();
|
635 |
+
if (isset($_REQUEST['action'])) {
|
636 |
+
$action = $_REQUEST['action'];
|
637 |
global $WPhtcEcho;
|
638 |
+
|
639 |
+
switch ($action) {
|
640 |
+
# Hide donation message for one month
|
641 |
+
case 'hide_donation_message':
|
642 |
+
$this->data['donation_hidden_time'] = time() + 90 * 24 * 60 * 60;
|
643 |
+
update_option('WPhtc_data', $this->data);
|
644 |
+
break;
|
645 |
+
# if reseting everything just delete the option array
|
646 |
+
case 'reset_rules':
|
647 |
+
# nonce
|
648 |
+
if (!check_admin_referer('WPhtc_reset_settings')) {
|
649 |
+
die("You have no permission to do this.");
|
650 |
+
}
|
651 |
+
$this->data = array();
|
652 |
+
delete_option('WPhtc_data');
|
653 |
+
//update_option('WPhtc_data',$this->data);
|
654 |
+
$WPhtcEcho .= __('All rules reset.', 'wp-htaccess-control');
|
655 |
+
$this->refresh_rewrite_rules();
|
656 |
+
break;
|
657 |
+
# if updating, save new rules in database and flush rewrite rules
|
658 |
+
case 'update':
|
659 |
+
# first donation hidding time 'now'
|
660 |
+
if (!$this->data['donation_hidden_time']) {
|
661 |
+
$this->data['donation_hidden_time'] = time();
|
662 |
+
}
|
663 |
+
# nonce
|
664 |
+
if (!check_admin_referer('WPhtc_settings')) {
|
665 |
+
die("You have no permission to do this.");
|
666 |
+
}
|
667 |
+
|
668 |
+
foreach (array("hta", "cap", "cpp", "custom_search_permalink", "remove_author_base", "category_archives", "author_archives", "tag_archives", "disable_serversignature", "disable_indexes", "protect_wp_config", "protect_htaccess", "protect_comments", "disable_hotlink", "disable_file_hotlink_ext", "disable_file_hotlink_redir", "redirect_500", "redirect_403", "canon", "admin_email", "deflate", "gzip", "maintenance_active", "maintenance_redirection", "login_disabled", "login_half_mode", "login_redirection", "sm_enabled", "jim_morgan_hta", "remove_hierarchy", "suffix_html")
|
669 |
+
as $k) {
|
670 |
+
$this->data[$k] = isset($_POST['WPhtc_' . $k]) ? $_POST['WPhtc_' . $k] : '';
|
671 |
+
}
|
672 |
+
|
673 |
+
# wordpress htaccess and jim morgan's htaccess
|
674 |
+
$this->data['wp_hta'] = $_POST['WPhtc_wp_hta'] . "\n";
|
675 |
+
|
676 |
+
# get htaccess Suggestions
|
677 |
+
$this->data['up_limit'] = (is_numeric($_POST['WPhtc_up_limit']) && $_POST['WPhtc_up_limit'] > 0) ? $_POST['WPhtc_up_limit'] : '';
|
678 |
+
# get maintenance
|
679 |
+
$lines = preg_split("/\n|,/", $_POST['WPhtc_maintenance_ips']);
|
680 |
+
$this->data['maintenance_ips'] = array();
|
681 |
+
foreach ($lines as $line) {
|
682 |
+
trim($line);
|
683 |
+
if (preg_match("/[a-z,0-9,\.]/", $line)) {
|
684 |
+
$this->data['maintenance_ips'][] = $line;
|
685 |
+
}
|
686 |
+
}
|
687 |
+
# get login control data
|
688 |
+
$lines = preg_split("/\n|,/", $_POST['WPhtc_login_ips']);
|
689 |
+
$this->data['login_ips'] = array();
|
690 |
+
foreach ($lines as $line) {
|
691 |
+
trim($line);
|
692 |
+
if (preg_match("/[a-z,0-9,\.]/", $line)) {
|
693 |
+
$this->data['login_ips'][] = $line;
|
694 |
+
}
|
695 |
+
}
|
696 |
+
|
697 |
+
# Unsetting inclusion of Author pages on Google XML Sitemap options, we'll add those links to the sitemap later with our Custom Author Permalink
|
698 |
+
if ($this->data['sm_enabled'] == true) {
|
699 |
+
$SMoptions = get_option("sm_options");
|
700 |
+
if ($SMoptions && is_array($SMoptions)) {
|
701 |
+
$SMoptions = get_option("sm_options");
|
702 |
+
$SMoptions['sm_in_auth'] = 0;
|
703 |
+
update_option('sm_options', $SMoptions);
|
704 |
+
# Try to rebuild Sitemap
|
705 |
+
do_action("sm_rebuild");
|
706 |
+
}
|
707 |
+
}
|
708 |
+
|
709 |
+
# Taxonomy Base removal options
|
710 |
+
unset($this->data['remove_taxonomy_base']);
|
711 |
+
if ($_POST['WPhtc_remove_base']) {
|
712 |
+
foreach ($_POST['WPhtc_remove_base'] as $tax_key => $remove) {
|
713 |
+
$this->data['remove_taxonomy_base'][$tax_key] = $remove;
|
714 |
+
}
|
715 |
+
}
|
716 |
+
|
717 |
+
# Advanced archives
|
718 |
+
unset($this->data['create_archive']);
|
719 |
+
if (isset($_POST['WPhtc_create_archive'])) {
|
720 |
+
foreach ($_POST['WPhtc_create_archive'] as $tax_key => $create_archive) {
|
721 |
+
$this->data['create_archive'][$tax_key] = $create_archive;
|
722 |
+
}
|
723 |
+
}
|
724 |
+
|
725 |
+
# Update WP htaccess Control options
|
726 |
+
update_option('WPhtc_data', $this->data);
|
727 |
+
|
728 |
+
# Flush Rewrite Rules
|
729 |
+
$this->refresh_rewrite_rules();
|
730 |
+
$WPhtcEcho .= __('All options updated.', 'wp-htaccess-control');
|
731 |
+
break;
|
732 |
+
}
|
733 |
+
}
|
734 |
+
}
|
735 |
+
}
|
736 |
+
}
|
737 |
if (class_exists("WPhtc")) {
|
738 |
+
$WPhtc = new WPhtc();
|
739 |
+
}
|
740 |
if (isset($WPhtc)) {
|
741 |
+
|
742 |
+
add_action('init', array($WPhtc, 'init'));
|
743 |
+
add_filter('mod_rewrite_rules', array($WPhtc, 'hta_rules'));
|
744 |
+
add_filter('redirect_canonical', array($WPhtc, 'filter_redirect_canonical'), 10, 10);
|
745 |
+
add_action('admin_menu', array($WPhtc, 'configure_menu'));
|
746 |
+
add_action('flush_event', array($WPhtc, 'refresh_rewrite_rules'));
|
747 |
+
add_filter('generate_rewrite_rules', array($WPhtc, 'wp_rewrite_rules'));
|
748 |
+
add_filter('rewrite_rules_array', array($WPhtc, 'filter_rewrite_rules'));
|
749 |
+
|
750 |
+
// AUTHOR improve this
|
751 |
+
if ($WPhtc->data['cap'] != '' || $WPhtc->data['remove_author_base']) {
|
752 |
+
add_filter('author_link', array($WPhtc, 'filter_author_link'));
|
753 |
+
add_filter('author_rewrite_rules', array($WPhtc, 'remove_author_base_from_rewrite_rules'));
|
754 |
+
}
|
755 |
+
|
756 |
+
// Filter pagination links
|
757 |
+
if ($WPhtc->data['cpp'] != '') add_filter('get_pagenum_link', array($WPhtc, 'filter_get_pagenum_link'));
|
758 |
+
|
759 |
+
// Filter search
|
760 |
+
if (trim($WPhtc->data['custom_search_permalink']) != '') {
|
761 |
+
add_filter('search_feed_link', array($WPhtc, 'search_feed_link'), 10, 10);
|
762 |
+
add_filter('get_search_query', array($WPhtc, 'get_search_query_filter'), 10, 10);
|
763 |
+
add_action('template_redirect', array($WPhtc, 'search_template_redirect'));
|
764 |
+
}
|
765 |
+
|
766 |
+
|
767 |
+
add_action('sm_buildmap', array($WPhtc, 'set_sm'));
|
768 |
+
|
769 |
+
// Taxonomy Base Removal
|
770 |
+
if ($WPhtc->data['remove_taxonomy_base']) {
|
771 |
+
add_filter('term_link', array($WPhtc, 'filter_term_link'), 10, 3);
|
772 |
+
foreach ($WPhtc->data['remove_taxonomy_base'] as $tax => $v) {
|
773 |
+
if ($v) {
|
774 |
+
add_filter($tax . '_rewrite_rules', array($WPhtc, 'remove_taxonomy_base_from_rewrite_rules'));
|
775 |
+
add_filter($tax . "_row_actions", array($WPhtc, 'filter_tax_table_actions'), 10, 2);
|
776 |
+
}
|
777 |
+
}
|
778 |
+
}
|
779 |
+
/* Term management actions*/
|
780 |
+
if ($WPhtc->data['remove_taxonomy_base'] || $WPhtc->data['create_archive']) {
|
781 |
+
add_action('created_term', array($WPhtc, 'refresh_rewrite_rules_later'));
|
782 |
+
add_action('edited_term', array($WPhtc, 'refresh_rewrite_rules_later'));
|
783 |
+
add_action('delete_term', array($WPhtc, 'refresh_rewrite_rules_later'));
|
784 |
+
}
|
785 |
+
|
786 |
+
/* This flush should maybe be conditional to content authors only, maybe not */
|
787 |
+
add_action('user_register', array($WPhtc, 'refresh_rewrite_rules_later'));
|
788 |
+
add_action('delete_user', array($WPhtc, 'refresh_rewrite_rules_later'));
|
789 |
+
}
|
790 |
?>
|