Ticket #1485: user-trail.diff

File user-trail.diff, 10.7 KB (added by MathiasBynens, 8 years ago)
Line 
1Index: wp-includes/template-functions-general.php
2===================================================================
3--- wp-includes/template-functions-general.php  (revision 2681)
4+++ wp-includes/template-functions-general.php  (working copy)
5@@ -301,12 +301,12 @@
6         if ($arcresults) {
7             $afterafter = $after;
8             foreach ($arcresults as $arcresult) {
9-                $url  = get_month_link($arcresult->year,   $arcresult->month);
10+                $url = get_month_link($arcresult->year, $arcresult->month);
11                 if ($show_post_count) {
12                     $text = sprintf('%s %d', $month[zeroise($arcresult->month,2)], $arcresult->year);
13-                    $after = ' ('.$arcresult->posts.')' . $afterafter;
14+                    $after = ' (' . $arcresult->posts . ')' . $afterafter;
15                 } else {
16-                    $text = sprintf('%s %d', $month[zeroise($arcresult->month,2)], $arcresult->year);
17+                    $text = sprintf('%s %d', $month[zeroise($arcresult->month, 2)], $arcresult->year);
18                 }
19                 echo get_archives_link($url, $text, $format, $before, $after);
20             }
21Index: wp-includes/template-functions-category.php
22===================================================================
23--- wp-includes/template-functions-category.php (revision 2681)
24+++ wp-includes/template-functions-category.php (working copy)
25@@ -21,7 +21,7 @@
26 
27 function get_category_link($category_id) {
28        global $wp_rewrite;
29-       $catlink = $wp_rewrite->get_category_permastruct();
30+       $catlink = user_trailing_slash($wp_rewrite->get_category_permastruct());
31 
32        if ( empty($catlink) ) {
33                $file = get_settings('home') . '/' . get_settings('blogfilename');
34@@ -34,7 +34,7 @@
35                        $category_nicename = get_category_parents($parent, false, '/', true) . $category_nicename . '/';
36 
37                $catlink = str_replace('%category%', $category_nicename, $catlink);
38-               $catlink = get_settings('home') . trailingslashit($catlink);
39+               $catlink = get_settings('home') . $catlink;
40        }
41        return apply_filters('category_link', $catlink, $category_id);
42 }
43Index: wp-includes/classes.php
44===================================================================
45--- wp-includes/classes.php     (revision 2681)
46+++ wp-includes/classes.php     (working copy)
47@@ -813,9 +813,9 @@
48        }                                       
49 
50        function using_index_permalinks() {
51-    if (empty($this->permalink_structure)) {
52+               if (empty($this->permalink_structure)) {
53                        return false;
54-    }
55+       }
56 
57     // If the index is not in the permalink, we're using mod_rewrite.
58     if (preg_match('#^/*' . $this->index . '#', $this->permalink_structure)) {
59@@ -833,15 +833,15 @@
60        }                                       
61 
62        function preg_index($number) {
63-    $match_prefix = '$';
64-    $match_suffix = '';
65+               $match_prefix = '$';
66+               $match_suffix = '';
67     
68-    if (! empty($this->matches)) {
69+               if (! empty($this->matches)) {
70                        $match_prefix = '$' . $this->matches . '[';
71                        $match_suffix = ']';
72-    }       
73+               }
74     
75-    return "$match_prefix$number$match_suffix";       
76+               return "$match_prefix$number$match_suffix";
77        }
78 
79        function page_rewrite_rules() {
80@@ -849,8 +849,7 @@
81 
82                $rewrite_rules = array();
83                $page_structure = $this->get_page_permastruct();
84-               if( is_array( $uris ) )
85-                       {
86+               if( is_array( $uris ) ) {
87                                foreach ($uris as $uri => $pagename) {
88                                        $this->add_rewrite_tag('%pagename%', "($uri)", 'pagename=');
89                                        $rewrite_rules += $this->generate_rewrite_rules($page_structure);
90@@ -910,8 +909,8 @@
91                        return false;
92                }
93 
94-               $structure = str_replace('%monthnum%', '', $structure);
95-               $structure = str_replace('%day%', '', $structure);
96+               $structure = str_replace('/%monthnum%', '', $structure);
97+               $structure = str_replace('/%day%', '', $structure);
98 
99                $structure = preg_replace('#/+#', '/', $structure);
100 
101@@ -925,7 +924,7 @@
102                        return false;
103                }
104 
105-               $structure = str_replace('%day%', '', $structure);
106+               $structure = str_replace('/%day%', '', $structure);
107 
108                $structure = preg_replace('#/+#', '/', $structure);
109 
110@@ -941,7 +940,7 @@
111                        return $this->category_structure;
112                }
113 
114-    if (empty($this->permalink_structure)) {
115+               if (empty($this->permalink_structure)) {
116                        $this->category_structure = '';
117                        return false;
118                }
119Index: wp-includes/template-functions-links.php
120===================================================================
121--- wp-includes/template-functions-links.php    (revision 2681)
122+++ wp-includes/template-functions-links.php    (working copy)
123@@ -89,9 +89,9 @@
124        if ('' != $pagestruct) {
125                $link = get_page_uri($id);
126                $link = str_replace('%pagename%', $link, $pagestruct);
127-               $link = get_settings('home') . "/$link/";
128+               $link = user_trailing_slash(get_settings('home') . '/' . $link);
129        } else {
130-               $link = get_settings('home') . "/?page_id=$id";
131+               $link = get_settings('home') . '/?page_id=' . $id;
132        }
133 
134        return apply_filters('page_link', $link, $id);
135@@ -103,7 +103,7 @@
136                $yearlink = $wp_rewrite->get_year_permastruct();
137     if (!empty($yearlink)) {
138         $yearlink = str_replace('%year%', $year, $yearlink);
139-        return apply_filters('year_link', get_settings('home') . trailingslashit($yearlink), $year);
140+        return apply_filters('year_link', get_settings('home') . $yearlink, $year);
141     } else {
142         return apply_filters('year_link', get_settings('home') . '/?m=' . $year, $year);
143     }
144@@ -111,13 +111,13 @@
145 
146 function get_month_link($year, $month) {
147     global $wp_rewrite;
148-    if (!$year) $year = gmdate('Y', time()+(get_settings('gmt_offset') * 3600));
149-    if (!$month) $month = gmdate('m', time()+(get_settings('gmt_offset') * 3600));
150+    if (!$year) $year = gmdate('Y', time() + (get_settings('gmt_offset') * 3600));
151+    if (!$month) $month = gmdate('m', time() + (get_settings('gmt_offset') * 3600));
152                $monthlink = $wp_rewrite->get_month_permastruct();
153     if (!empty($monthlink)) {
154         $monthlink = str_replace('%year%', $year, $monthlink);
155         $monthlink = str_replace('%monthnum%', zeroise(intval($month), 2), $monthlink);
156-        return apply_filters('month_link', get_settings('home') . trailingslashit($monthlink), $year, $month);
157+        return apply_filters('month_link', get_settings('home') . $monthlink, $year, $month);
158     } else {
159         return apply_filters('month_link', get_settings('home') . '/?m=' . $year . zeroise($month, 2), $year, $month);
160     }
161@@ -134,7 +134,7 @@
162         $daylink = str_replace('%year%', $year, $daylink);
163         $daylink = str_replace('%monthnum%', zeroise(intval($month), 2), $daylink);
164         $daylink = str_replace('%day%', zeroise(intval($day), 2), $daylink);
165-        return apply_filters('day_link', get_settings('home') . trailingslashit($daylink), $year, $month, $day);
166+        return apply_filters('day_link', get_settings('home') . $daylink, $year, $month, $day);
167     } else {
168         return apply_filters('day_link', get_settings('home') . '/?m=' . $year . zeroise($month, 2) . zeroise($day, 2), $year, $month, $day);
169     }
170@@ -157,7 +157,7 @@
171                        $feed = '';
172 
173                $permalink = str_replace('%feed%', $feed, $permalink);
174-               $permalink = preg_replace('#/+#', '/', "/$permalink/");
175+               $permalink = preg_replace('#/+#', '/', "/$permalink");
176                $output =  get_settings('home') . $permalink;
177        } else {
178                if ( false !== strpos($feed, 'comments_') )
179Index: wp-includes/template-functions-post.php
180===================================================================
181--- wp-includes/template-functions-post.php     (revision 2681)
182+++ wp-includes/template-functions-post.php     (working copy)
183@@ -289,10 +289,10 @@
184        }
185 
186        $pages = $wpdb->get_results("SELECT * " .
187-                                                                                                                       "FROM $wpdb->posts " .
188-                                                                                                                       "WHERE post_status = 'static' " .
189-                                                                                                                       "$exclusions " .
190-                                                                                                                       "ORDER BY " . $r['sort_column'] . " " . $r['sort_order']);
191+                                                       "FROM $wpdb->posts " .
192+                                                       "WHERE post_status = 'static' " .
193+                                                       "$exclusions " .
194+                                                       "ORDER BY " . $r['sort_column'] . " " . $r['sort_order']);
195 
196        if ( empty($pages) )
197                return array();
198@@ -373,7 +373,7 @@
199 
200        if($depth)
201                $indent = str_repeat("\t", $depth);
202-       //$indent = join('', array_fill(0,$depth,"\t"));
203+       //$indent = join('', array_fill(0, $depth, "\t"));
204 
205        foreach($page_tree[$parent]['children'] as $page_id) {
206                $cur_page = $page_tree[$page_id];
207Index: wp-includes/comment-functions.php
208===================================================================
209--- wp-includes/comment-functions.php   (revision 2681)
210+++ wp-includes/comment-functions.php   (working copy)
211@@ -307,7 +307,7 @@
212        $tb_url = get_settings('siteurl') . '/wp-trackback.php?p=' . $id;
213 
214        if ( '' != get_settings('permalink_structure') )
215-               $tb_url = trailingslashit(get_permalink()) . 'trackback/';
216+               $tb_url = user_trailing_slash(trailingslashit(get_permalink()) . 'trackback');
217 
218        return $tb_url;
219 }
220Index: wp-includes/feed-functions.php
221===================================================================
222--- wp-includes/feed-functions.php      (revision 2681)
223+++ wp-includes/feed-functions.php      (working copy)
224@@ -82,7 +82,7 @@
225        global $id;
226 
227        if ('' != get_settings('permalink_structure'))
228-               $url = trailingslashit( get_permalink() ) . 'feed/';
229+               $url = user_trailing_slash(trailingslashit(get_permalink()) . 'feed');
230        else
231                $url = get_settings('home') . "/$commentsrssfilename?feed=rss2&p=$id";
232 
233@@ -97,7 +97,7 @@
234                                 $link = get_settings('home') . '?feed=rss2&author=' . $author_id;
235        } else {
236                                 $link = get_author_link(0, $author_id, $author_nicename);
237-                                $link = $link . "feed/";
238+                                $link = user_trailing_slash($link . 'feed');
239        }
240                         
241                         $link = apply_filters('author_feed_link', $link);
242@@ -113,7 +113,7 @@
243                                 $link = get_settings('home') . '?feed=rss2&cat=' . $cat_ID;
244        } else {
245                                 $link = get_category_link($cat_ID);
246-                                $link = $link . "feed/";
247+                                $link = user_trailing_slash($link . 'feed');
248        }
249 
250                         $link = apply_filters('category_feed_link', $link);
251Index: wp-includes/functions-formatting.php
252===================================================================
253--- wp-includes/functions-formatting.php        (revision 2681)
254+++ wp-includes/functions-formatting.php        (working copy)
255@@ -515,13 +515,20 @@
256        return $string;
257 }
258 
259-function trailingslashit($string) {
260-    if ( '/' != substr($string, -1)) {
261-        $string .= '/';
262-    }
263-    return $string;
264+function trailingslashit($iri) {
265+       if ('/' != substr($iri, -1)) {
266+               $iri .= '/';
267+       }
268+       return $iri;
269 }
270 
271+function user_trailing_slash($iri) {
272+       if (('/' == substr(get_settings('permalink_structure'), -1)) && ('/' != substr($iri, -1))) {
273+               $iri .= '/';
274+       }
275+       return $iri;
276+}
277+
278 function addslashes_gpc($gpc) {
279        if (!get_magic_quotes_gpc()) {
280                $gpc = addslashes($gpc);