ff-counter count ui left"> BIN app/backend/migrations/__pycache__/__init__.cpython-39.pyc
Parādīt failu

+ 50 - 39
app/backend/models.py

@@ -109,6 +109,8 @@ class Patient(models.Model):
109 109
     birth_date = models.DateField(null=True)
110 110
     age = models.IntegerField(null=True, blank=True)
111 111
     idcard = models.CharField(max_length=20, null=True, blank=False)
112
+    tel = models.CharField(max_length=100, null=True, blank=True)
113
+    line_id = models.CharField(max_length=100, null=True, blank=True)
112 114
     prefix = models.CharField(
113 115
         max_length=30,
114 116
         choices=GENDER_CHOICES,
@@ -148,51 +150,57 @@ class Patient(models.Model):
148 150
     def nearby_from_db(self, dlimit):
149 151
         bd = ""
150 152
         temps = []
151
-        for h0 in  Hospital.objects.all():
152
-            p2 = (h0.geolocation.lat, h0.geolocation.lon)
153
-            p1 = (self.geolocation.lat, self.geolocation.lon)
154
-            d = round(hs.haversine(p1,p2), 2)
155
-            if d < dlimit:
156
-                #bd += f"<tr><td>{h0.title}</td><td>{d}km</td></tr>"
157
-                temps.append({'title': h0.title, 'd': d, 'id': h0.id, 'beds': h0.free_beds()})
158
-                #print(f"to {h0.title} => {hs.haversine(p1, p2)}km")
159
-
160
-        temps.sort(key= lambda s: s['d'], reverse=False)
161
-        for t in temps:
162
-            bd += f"<tr><td><a href='/admin/backend/hospital/{t['id']}/change/' target='_blank'>{t['title']}</a></td><td>{t['d']} km</td><td>{t['beds']}</td></tr>"
163
-
164
-        rt = f'''
165
-<br>
166
-        <table><thead><tr><th>Hospital</th><th>Distance</th><th>Free Beds</th></tr></thead>
167
-        <tbody>
168
-            {bd}
169
-        </tbody>
170
-        </table>
171
-        '''
172
-        return rt
153
+        try:
154
+            for h0 in  Hospital.objects.all():
155
+                p2 = (h0.geolocation.lat, h0.geolocation.lon)
156
+                p1 = (self.geolocation.lat, self.geolocation.lon)
157
+                d = round(hs.haversine(p1,p2), 2)
158
+                if d < dlimit:
159
+                    #bd += f"<tr><td>{h0.title}</td><td>{d}km</td></tr>"
160
+                    temps.append({'title': h0.title, 'd': d, 'id': h0.id, 'beds': h0.free_beds()})
161
+                    #print(f"to {h0.title} => {hs.haversine(p1, p2)}km")
162
+
163
+            temps.sort(key= lambda s: s['d'], reverse=False)
164
+            for t in temps:
165
+                bd += f"<tr><td><a href='/admin/backend/hospital/{t['id']}/change/' target='_blank'>{t['title']}</a></td><td>{t['d']} km</td><td>{t['beds']}</td></tr>"
166
+
167
+            rt = f'''
168
+    <br>
169
+            <table><thead><tr><th>Hospital</th><th>Distance</th><th>Free Beds</th></tr></thead>
170
+            <tbody>
171
+                {bd}
172
+            </tbody>
173
+            </table>
174
+            '''
175
+            return rt
176
+        except:
177
+            return "-"
173 178
 
174 179
     def nearby(self):
175 180
         #self.nearby_from_db()
176
-        r = gmaps.places_nearby(location=(self.geolocation.lat, self.geolocation.lon), type="hospital", radius=10000)
177
-        bd = ""
178
-        for r0 in r['results']:
179
-            openh = "-"
180
-            if 'opening_hours' in r0:
181
-                openh = r0['opening_hours']['open_now']
182
-            else:
181
+        try:
182
+            r = gmaps.places_nearby(location=(self.geolocation.lat, self.geolocation.lon), type="hospital", radius=10000)
183
+            bd = ""
184
+            for r0 in r['results']:
183 185
                 openh = "-"
186
+                if 'opening_hours' in r0:
187
+                    openh = r0['opening_hours']['open_now']
188
+                else:
189
+                    openh = "-"
184 190
 
185
-            bd += f"<tr><td>{r0['name']}</td><td>{openh}</td><td>{r0['vicinity']}</td></tr>"
191
+                bd += f"<tr><td>{r0['name']}</td><td>{openh}</td><td>{r0['vicinity']}</td></tr>"
186 192
 
187
-        rt = f'''
188
-<br>
189
-        <table><thead><tr><th>Name</th><th>Opening Hours</th><th>Vicinity</th></tr></thead>
190
-        <tbody>
191
-            {bd}
192
-        </tbody>
193
-        </table>
194
-        '''
195
-        return rt
193
+            rt = f'''
194
+    <br>
195
+            <table><thead><tr><th>Name</th><th>Opening Hours</th><th>Vicinity</th></tr></thead>
196
+            <tbody>
197
+                {bd}
198
+            </tbody>
199
+            </table>
200
+            '''
201
+            return rt
202
+        except:
203
+            return "-"
196 204
 
197 205
 
198 206
 
@@ -250,6 +258,9 @@ class Hospital(models.Model):
250 258
     address = map_fields.AddressField(max_length=200)
251 259
     geolocation = map_fields.GeoLocationField(max_length=100)
252 260
 
261
+    tel = models.CharField(max_length=100, null=True, blank=True)
262
+    line_id = models.CharField(max_length=100, null=True, blank=True)
263
+
253 264
     created_at = models.DateTimeField(auto_now_add=True, null=True)
254 265
     updated_at = models.DateTimeField(auto_now=True)
255 266
 

BIN
app/front/__pycache__/urls.cpython-39.pyc


BIN
app/front/__pycache__/views.cpython-39.pyc


BIN
app/front/migrations/__pycache__/__init__.cpython-39.pyc


+ 8 - 0
app/front/templates/front/404.html

@@ -0,0 +1,8 @@
1
+
2
+{% extends "base.html" %}
3
+
4
+{% block content %}
5
+<div class="alert alert-success" role="alert">
6
+<h1>ไม่มี page นี้</h1>
7
+</div>
8
+{% endblock %}

+ 7 - 3
app/front/templates/front/index.html

@@ -11,8 +11,10 @@
11 11
         <br>
12 12
         <input type='text' name='lastName' class='form-control' placeholder='นามสกุล' required/>
13 13
         <br>
14
-        <input type='text' name='idCard' class='form-control' placeholder='หมายเลขบัตรประชาชน' required />
15
-        <br>
14
+        <!-- 
15
+        <input type='text' name='idCard' class='form-control' placeholder='หมายเลขบัตรประชาชน' required /> 
16
+        <br> -->
17
+        <label>วันเกิด</label>
16 18
         <input type='date' name='bd' class='form-control' placeholder='วันเกิด' required />
17 19
         <br>
18 20
         <textarea name='address' class='form-control' placeholder='ที่อยู่' required></textarea>  
@@ -21,8 +23,10 @@
21 23
         <br>
22 24
         <input type='tel' name='tel' class='form-control' placeholder='Tel.' required/>
23 25
         <br>
26
+        <input type='text' name='line_id' class='form-control' placeholder='Line ID'/>
27
+        <br>
24 28
         <label>อัพโหลดภาพ</label>
25
-        <input type="file" name='photo' accept="image/*;capture=camera" class='form-control' required> </br>
29
+        <input type="file" name='photo' accept="image/*;capture=camera" class='form-control'> </br>
26 30
         <span class="glyphicon glyphicon-map-marker"></span>
27 31
         <a class='btn btn-primary form-control' id="currentLocationBtn">
28 32
         <i class="bi bi-geo-alt-fill"></i>

+ 33 - 0
app/front/templates/front/tracking.html

@@ -0,0 +1,33 @@
1
+
2
+{% extends "base.html" %}
3
+
4
+{% block content %}
5
+<div class="alert alert-success" role="alert">
6
+<h1>Tracking</h1>
7
+        <input type='text' class='form-control' name='geo' id='geoText' readonly/><br>
8
+        <br>Last Update
9
+        <span id='lastUpdate'></span>
10
+</div>
11
+{% endblock %}
12
+{% block foot_script %}
13
+<script>
14
+    $(function() {
15
+
16
+        setInterval(function(){
17
+            console.log("Hello");
18
+            if ("geolocation" in navigator){ //check geolocation available
19
+                //try to get user current location using getCurrentPosition() method
20
+                console.log("current location");
21
+                navigator.geolocation.getCurrentPosition(function(position){
22
+                    console.log("xxxx");
23
+                    $("#geoText").val(position.coords.latitude+","+position.coords.longitude );
24
+                    $("#lastUpdate").html(new Date());
25
+
26
+                });
27
+            }else{
28
+                console.log("Browser doesn't support geolocation!");
29
+            }
30
+        }, 5000);
31
+    });
32
+</script>
33
+{% endblock %}

+ 1 - 0
app/front/urls.py

@@ -5,5 +5,6 @@ from . import views
5 5
 
6 6
 urlpatterns = [
7 7
     path('', views.index, name='index'),
8
+    path('tracking', views.tracking, name='tracking'),
8 9
     path('success', views.success, name='success'),
9 10
 ]

+ 11 - 1
app/front/views.py

@@ -10,11 +10,13 @@ def index(request):
10 10
         p = Patient()
11 11
         p.first_name = request.POST.get('firstName')
12 12
         p.last_name = request.POST.get('lastName')
13
-        p.idcard = request.POST.get('idCard')
13
+        #p.idcard = request.POST.get('idCard')
14 14
         p.address = request.POST.get('address')
15 15
         p.geolocation = request.POST.get('geo')
16 16
         p.birth_date = request.POST.get('bd')
17 17
         p.comment = request.POST.get('comment')
18
+        p.tel = request.POST.get('tel')
19
+        p.line_id = request.POST.get('line_id')
18 20
         p.photo = request.FILES.get('photo')
19 21
         p.patient_status = "request"
20 22
         p.save()
@@ -23,3 +25,11 @@ def index(request):
23 25
 
24 26
 def success(request):
25 27
     return render(request, 'front/success.html')
28
+
29
+def tracking(request):
30
+    return render(request, 'front/tracking.html')
31
+
32
+def my404(request,exception):
33
+    return render(request, 'front/404.html')
34
+    #return redirect("index")
35
+

BIN
app/shaqfindbed/__pycache__/settings.cpython-39.pyc


BIN
app/shaqfindbed/__pycache__/urls.cpython-39.pyc


+ 5 - 1
app/shaqfindbed/settings.py

@@ -27,7 +27,11 @@ SECRET_KEY = 'django-insecure-!=!d6rsewcddw=hr-j46#))^nd-32(kkjmnpxxioi(v&c9!*xn
27 27
 # SECURITY WARNING: don't run with debug turned on in production!
28 28
 DEBUG = True
29 29
 
30
-ALLOWED_HOSTS = []
30
+ALLOWED_HOSTS = [
31
+    "167.71.218.44",
32
+    "localhost",
33
+    '.findbed.xyz'
34
+]
31 35
 
32 36
 
33 37
 # Application definition

+ 6 - 1
app/shaqfindbed/urls.py

@@ -18,13 +18,18 @@ from django.urls import path, include
18 18
 from django.conf import settings
19 19
 from django.conf.urls import url
20 20
 from django.conf.urls.static import static
21
+from django.views.static import serve
22
+
21 23
 
22 24
 urlpatterns = [
25
+    path('', include('front.urls')),
23 26
     path('backend/', include('backend.urls')),
24
-    path('front/', include('front.urls')),
25 27
     path('admin/', admin.site.urls),
26 28
     url(r'^chaining/', include('smart_selects.urls')),
29
+    url(r'^media/(?P<path>.*)$', serve,{'document_root': settings.MEDIA_ROOT}),
27 30
 ] + static(settings.STATIC_URL, document_root=settings.STATIC_ROOT)
28 31
 
32
+
29 33
 if settings.DEBUG:
30 34
     urlpatterns += static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)
35
+handler404 = 'front.views.my404'

+ 162 - 0
app/staticfile/autocomplete_light/autocomplete.init.js

@@ -0,0 +1,162 @@
1
+/*
2
+This script garantees that this will be called once in django admin.
3
+However, its the callback's responsability to clean up if the
4
+element was cloned with data - which should be the case.
5
+*/
6
+
7
+;(function ($) {
8
+    $.fn.getFormPrefix = function() {
9
+        /* Get the form prefix for a field.
10
+         *
11
+         * For example:
12
+         *
13
+         *     $(':input[name$=owner]').getFormsetPrefix()
14
+         *
15
+         * Would return an empty string for an input with name 'owner' but would return
16
+         * 'inline_model-0-' for an input named 'inline_model-0-owner'.
17
+         */
18
+        var parts = $(this).attr('name').split('-');
19
+        var prefix = '';
20
+
21
+        for (var i in parts) {
22
+            var testPrefix = parts.slice(0, -i).join('-');
23
+            if (! testPrefix.length) continue;
24
+            testPrefix += '-';
25
+
26
+            var result = $(':input[name^=' + testPrefix + ']')
27
+
28
+            if (result.length) {
29
+                return testPrefix;
30
+            }
31
+        }
32
+
33
+        return '';
34
+    }
35
+
36
+    $.fn.getFormPrefixes = function() {
37
+        /*
38
+         * Get the form prefixes for a field, from the most specific to the least.
39
+         *
40
+         * For example:
41
+         *
42
+         *      $(':input[name$=owner]').getFormPrefixes()
43
+         *
44
+         * Would return:
45
+         * - [''] for an input named 'owner'.
46
+         * - ['inline_model-0-', ''] for an input named 'inline_model-0-owner' (i.e. nested with a nested inline).
47
+         * - ['sections-0-items-0-', 'sections-0-', ''] for an input named 'sections-0-items-0-product'
48
+         *   (i.e. nested multiple time with django-nested-admin).
49
+         */
50
+        var parts = $(this).attr('name').split('-').slice(0, -1);
51
+        var prefixes = [];
52
+
53
+        for (i = 0; i < parts.length; i += 2) {
54
+            var testPrefix = parts.slice(0, -i || parts.length).join('-');
55
+            if (!testPrefix.length)
56
+                continue;
57
+
58
+            testPrefix += '-';
59
+
60
+            var result = $(':input[name^=' + testPrefix + ']')
61
+
62
+            if (result.length)
63
+                prefixes.push(testPrefix);
64
+        }
65
+
66
+        prefixes.push('');
67
+
68
+        return prefixes;
69
+    }
70
+
71
+    var initialized = [];
72
+
73
+    function initialize(element) {
74
+        if (typeof element === 'undefined' || typeof element === 'number') {
75
+            element = this;
76
+        }
77
+
78
+        if (window.__dal__initListenerIsSet !== true || initialized.indexOf(element) >= 0) {
79
+            return;
80
+        }
81
+
82
+        $(element).trigger('autocompleteLightInitialize');
83
+        initialized.push(element);
84
+    }
85
+
86
+    if (!window.__dal__initialize) {
87
+        window.__dal__initialize = initialize;
88
+
89
+        $(document).ready(function () {
90
+            $('[data-autocomplete-light-function=select2]:not([id*="__prefix__"])').each(initialize);
91
+        });
92
+
93
+        $(document).bind('DOMNodeInserted', function (e) {
94
+            $(e.target).find('[data-autocomplete-light-function=select2]').each(initialize);
95
+        });
96
+    }
97
+
98
+    // using jQuery
99
+    function getCookie(name) {
100
+        var cookieValue = null;
101
+        if (document.cookie && document.cookie != '') {
102
+            var cookies = document.cookie.split(';');
103
+            for (var i = 0; i < cookies.length; i++) {
104
+                var cookie = $.trim(cookies[i]);
105
+                // Does this cookie string begin with the name we want?
106
+                if (cookie.substring(0, name.length + 1) == (name + '=')) {
107
+                    cookieValue = decodeURIComponent(cookie.substring(name.length + 1));
108
+                    break;
109
+                }
110
+            }
111
+        }
112
+        return cookieValue;
113
+    }
114
+
115
+    document.csrftoken = getCookie('csrftoken');
116
+    if (document.csrftoken === null) {
117
+        // Try to get CSRF token from DOM when cookie is missing
118
+        var $csrf = $('form :input[name="csrfmiddlewaretoken"]');
119
+        if ($csrf.length > 0) {
120
+            document.csrftoken = $csrf[0].value;
121
+        }
122
+    }
123
+})(yl.jQuery);
124
+
125
+// Does the same thing as django's admin/js/autocomplete.js, but uses yl.jQuery.
126
+(function($) {
127
+    'use strict';
128
+    var init = function($element, options) {
129
+        var settings = $.extend({
130
+            ajax: {
131
+                data: function(params) {
132
+                    return {
133
+                        term: params.term,
134
+                        page: params.page
135
+                    };
136
+                }
137
+            }
138
+        }, options);
139
+        $element.select2(settings);
140
+    };
141
+
142
+    $.fn.djangoAdminSelect2 = function(options) {
143
+        var settings = $.extend({}, options);
144
+        $.each(this, function(i, element) {
145
+            var $element = $(element);
146
+            init($element, settings);
147
+        });
148
+        return this;
149
+    };
150
+
151
+    $(function() {
152
+        // Initialize all autocomplete widgets except the one in the template
153
+        // form used when a new formset is added.
154
+        $('.admin-autocomplete').not('[name*=__prefix__]').djangoAdminSelect2();
155
+    });
156
+
157
+    $(document).on('formset:added', (function() {
158
+        return function(event, $newFormset) {
159
+            return $newFormset.find('.admin-autocomplete').djangoAdminSelect2();
160
+        };
161
+    })(this));
162
+}(yl.jQuery));

+ 191 - 0
app/staticfile/autocomplete_light/forward.js

@@ -0,0 +1,191 @@
1
+;(function($, yl) {
2
+    yl.forwardHandlerRegistry = yl.forwardHandlerRegistry || {};
3
+
4
+    yl.registerForwardHandler = function(name, handler) {
5
+        yl.forwardHandlerRegistry[name] = handler;
6
+    };
7
+
8
+    yl.getForwardHandler = function(name) {
9
+        return yl.forwardHandlerRegistry[name];
10
+    };
11
+
12
+    function getForwardStrategy(element) {
13
+        var checkForCheckboxes = function() {
14
+            var all = true;
15
+            $.each(element, function(ix, e) {
16
+                if ($(e).attr("type") !== "checkbox") {
17
+                    all = false;
18
+                }
19
+            });
20
+            return all;
21
+        };
22
+
23
+        if (element.length === 1 &&
24
+                element.attr("type") === "checkbox" &&
25
+                element.attr("value") === undefined) {
26
+            // Single checkbox without 'value' attribute
27
+            // Boolean field
28
+            return "exists";
29
+        } else if (element.length === 1 &&
30
+                element.attr("multiple") !== undefined) {
31
+            // Multiple by HTML semantics. E. g. multiple select
32
+            // Multiple choice field
33
+            return "multiple";
34
+        } else if (checkForCheckboxes()) {
35
+            // Multiple checkboxes or one checkbox with 'value' attribute.
36
+            // Multiple choice field represented by checkboxes
37
+            return "multiple";
38
+        } else {
39
+            // Other cases
40
+            return "single";
41
+        }
42
+    }
43
+
44
+    /**
45
+     * Get fields with name `name` relative to `element` with considering form
46
+     * prefixes.
47
+     * @param element the element
48
+     * @param name name of the field
49
+     * @returns jQuery object with found fields or empty jQuery object if no
50
+     * field was found
51
+     */
52
+    yl.getFieldRelativeTo = function(element, name) {
53
+        var prefixes = $(element).getFormPrefixes();
54
+
55
+        for (var i = 0; i < prefixes.length; i++) {
56
+            var fieldSelector = "[name=" + prefixes[i] + name + "]";
57
+            var field = $(fieldSelector);
58
+
59
+            if (field.length) {
60
+                return field;
61
+            }
62
+        }
63
+
64
+        return $();
65
+    };
66
+
67
+    /**
68
+     * Get field value which is put to forwarded dictionary
69
+     * @param field the field
70
+     * @returns forwarded value
71
+     */
72
+    yl.getValueFromField = function(field) {
73
+        var strategy = getForwardStrategy(field);
74
+        var serializedField = $(field).serializeArray();
75
+
76
+        if ((serializedField == false) && ($(field).prop('disabled'))) {
77
+            $(field).prop('disabled', false);
78
+            serializedField = $(field).serializeArray();
79
+            $(field).prop('disabled', true);
80
+        }
81
+
82
+        var getSerializedFieldElementAt = function (index) {
83
+            // Return serializedField[index]
84
+            // or null if something went wrong
85
+            if (serializedField.length > index) {
86
+                return serializedField[index];
87
+            } else {
88
+                return null;
89
+            }
90
+        };
91
+
92
+        var getValueOf = function (elem) {
93
+            // Return elem.value
94
+            // or null if something went wrong
95
+            if (elem.hasOwnProperty("value") &&
96
+                elem.value !== undefined
97
+            ) {
98
+                return elem.value;
99
+            } else {
100
+                return null;
101
+            }
102
+        };
103
+
104
+        var getSerializedFieldValueAt = function (index) {
105
+            // Return serializedField[index].value
106
+            // or null if something went wrong
107
+            var elem = getSerializedFieldElementAt(index);
108
+            if (elem !== null) {
109
+                return getValueOf(elem);
110
+            } else {
111
+                return null;
112
+            }
113
+        };
114
+
115
+        if (strategy === "multiple") {
116
+            return serializedField.map(
117
+                function (item) {
118
+                    return getValueOf(item);
119
+                }
120
+            );
121
+        } else if (strategy === "exists") {
122
+            return serializedField.length > 0;
123
+        } else {
124
+            return getSerializedFieldValueAt(0);
125
+        }
126
+    };
127
+
128
+    yl.getForwards = function(element) {
129
+        var forwardElem,
130
+            forwardList,
131
+            forwardedData,
132
+            divSelector,
133
+            form;
134
+        divSelector = "div.dal-forward-conf#dal-forward-conf-for-" +
135
+                element.attr("id") + ", " +
136
+                "div.dal-forward-conf#dal-forward-conf-for_" +
137
+                element.attr("id");
138
+        form = element.length > 0 ? $(element[0].form) : $();
139
+
140
+        forwardElem =
141
+            form.find(divSelector).find('script');
142
+        if (forwardElem.length === 0) {
143
+            return;
144
+        }
145
+        try {
146
+            forwardList = JSON.parse(forwardElem.text());
147
+        } catch (e) {
148
+            return;
149
+        }
150
+
151
+        if (!Array.isArray(forwardList)) {
152
+            return;
153
+        }
154
+
155
+        forwardedData = {};
156
+
157
+        $.each(forwardList, function(ix, field) {
158
+            var srcName, dstName;
159
+            if (field.type === "const") {
160
+                forwardedData[field.dst] = field.val;
161
+            } else if (field.type === "self") {
162
+                if (field.hasOwnProperty("dst")) {
163
+                    dstName = field.dst;
164
+                } else {
165
+                    dstName = "self";
166
+                }
167
+                forwardedData[dstName] = yl.getValueFromField(element);
168
+            } else if (field.type === "field") {
169
+                srcName = field.src;
170
+                if (field.hasOwnProperty("dst")) {
171
+                    dstName = field.dst;
172
+                } else {
173
+                    dstName = srcName;
174
+                }
175
+                var forwardedField = yl.getFieldRelativeTo(element, srcName);
176
+
177
+                if (!forwardedField.length) {
178
+                    return;
179
+                }
180
+
181
+                forwardedData[dstName] = yl.getValueFromField(forwardedField);
182
+            } else if (field.type === "javascript") {
183
+                var handler = yl.getForwardHandler(field.handler);
184
+                forwardedData[field.dst || field.handler] = handler(element);
185
+            }
186
+
187
+        });
188
+        return JSON.stringify(forwardedData);
189
+    };
190
+
191
+})(yl.jQuery, yl);

+ 36 - 0
app/staticfile/autocomplete_light/jquery.init.js

@@ -0,0 +1,36 @@
1
+var yl = yl || {};
2
+if (typeof django !== 'undefined' && typeof django.jQuery !== 'undefined') {
3
+    // If django.jQuery is already defined, use it.
4
+    yl.jQuery = django.jQuery;
5
+}
6
+else {
7
+    // We include jquery itself in our widget's media, because we need it.
8
+    // Normally, we expect our widget's reference to admin/js/vendor/jquery/jquery.js
9
+    // to be skipped, because django's own code has already included it.
10
+    // However, if django.jQuery is NOT defined, we know that jquery was not
11
+    // included before we did it ourselves. This can happen if we're not being
12
+    // rendered in a django admin form.
13
+    // However, someone ELSE'S jQuery may have been included before ours, in
14
+    // which case we must ensure that our jquery doesn't override theirs, since
15
+    // it might be a newer version that other code on the page relies on.
16
+    // Thus, we must run jQuery.noConflict(true) here to move our jQuery out of
17
+    // the way.
18
+    yl.jQuery = jQuery.noConflict(true);
19
+}
20
+
21
+// In addition to all of this, we must ensure that the global jQuery and $ are
22
+// defined, because Select2 requires that. jQuery will only be undefined at
23
+// this point if only we or django included it.
24
+if (typeof jQuery === 'undefined') {
25
+    jQuery = yl.jQuery;
26
+    $ = yl.jQuery;
27
+}
28
+else {
29
+    // jQuery IS still defined, which means someone else also included jQuery.
30
+    // In this situation, we need to store the old jQuery in a
31
+    // temp variable, set the global jQuery to our yl.jQuery, then let select2
32
+    // set itself up. We restore the global jQuery to its original value in
33
+    // jquery.post-setup.js.
34
+    dal_jquery_backup = jQuery.noConflict(true);
35
+    jQuery = yl.jQuery;
36
+}

+ 7 - 0
app/staticfile/autocomplete_light/jquery.post-setup.js

@@ -0,0 +1,7 @@
1
+if (typeof dal_jquery_backup !== 'undefined') {
2
+    // We made a backup of the original global jQuery before forcing it to our
3
+    // yl.jQuery value. Now that select2 has been set up, we need to restore
4
+    // our backup to its rightful place.
5
+    jQuery = dal_jquery_backup;
6
+    $ = dal_jquery_backup;
7
+}

+ 14 - 0
app/staticfile/autocomplete_light/select2.css

@@ -0,0 +1,14 @@
1
+.select2-container {
2
+    min-width: 20em;
3
+}
4
+
5
+ul li.select2-selection__choice,
6
+ul li.select2-search {
7
+    /* Cancel out django's style */
8
+    list-style-type: none;
9
+}
10
+
11
+.errors .select2-selection {
12
+    /* Highlight select box with error */
13
+    border-color: #ba2121;
14
+}

+ 122 - 0
app/staticfile/autocomplete_light/select2.js

@@ -0,0 +1,122 @@
1
+;(function ($) {
2
+    if (window.__dal__initListenerIsSet)
3
+        return;
4
+
5
+    $(document).on('autocompleteLightInitialize', '[data-autocomplete-light-function=select2]', function() {
6
+        var element = $(this);
7
+
8
+        // Templating helper
9
+        function template(text, is_html) {
10
+            if (is_html) {
11
+                var $result = $('<span>');
12
+                $result.html(text);
13
+                return $result;
14
+            } else {
15
+                return text;
16
+            }
17
+        }
18
+
19
+        function result_template(item) {
20
+            var text = template(item.text,
21
+                element.attr('data-html') !== undefined || element.attr('data-result-html') !== undefined
22
+            );
23
+
24
+            if (item.create_id) {
25
+                return $('<span></span>').text(text).addClass('dal-create')
26
+            } else {
27
+                return text
28
+            }
29
+        }
30
+
31
+        function selected_template(item) {
32
+            if (item.selected_text !== undefined) {
33
+                return template(item.selected_text,
34
+                    element.attr('data-html') !== undefined || element.attr('data-selected-html') !== undefined
35
+                );
36
+            } else {
37
+                return result_template(item);
38
+            }
39
+            return
40
+        }
41
+
42
+        var ajax = null;
43
+        if ($(this).attr('data-autocomplete-light-url')) {
44
+            ajax = {
45
+                url: $(this).attr('data-autocomplete-light-url'),
46
+                dataType: 'json',
47
+                delay: 250,
48
+
49
+                data: function (params) {
50
+                    var data = {
51
+                        q: params.term, // search term
52
+                        page: params.page,
53
+                        create: element.attr('data-autocomplete-light-create') && !element.attr('data-tags'),
54
+                        forward: yl.getForwards(element)
55
+                    };
56
+
57
+                    return data;
58
+                },
59
+                processResults: function (data, page) {
60
+                    if (element.attr('data-tags')) {
61
+                        $.each(data.results, function(index, value) {
62
+                            value.id = value.text;
63
+                        });
64
+                    }
65
+
66
+                    return data;
67
+                },
68
+                cache: true
69
+            };
70
+        }
71
+
72
+        $(this).select2({
73
+            tokenSeparators: element.attr('data-tags') ? [','] : null,
74
+            debug: true,
75
+            containerCssClass: ':all:',
76
+            placeholder: element.attr('data-placeholder') || '',
77
+            language: element.attr('data-autocomplete-light-language'),
78
+            minimumInputLength: element.attr('data-minimum-input-length') || 0,
79
+            allowClear: ! $(this).is('[required]'),
80
+            templateResult: result_template,
81
+            templateSelection: selected_template,
82
+            ajax: ajax,
83
+            tags: Boolean(element.attr('data-tags')),
84
+        });
85
+
86
+        $(this).on('select2:selecting', function (e) {
87
+            var data = e.params.args.data;
88
+
89
+            if (data.create_id !== true)
90
+                return;
91
+
92
+            e.preventDefault();
93
+
94
+            var select = $(this);
95
+
96
+            $.ajax({
97
+                url: $(this).attr('data-autocomplete-light-url'),
98
+                type: 'POST',
99
+                dataType: 'json',
100
+                data: {
101
+                    text: data.id,
102
+                    forward: yl.getForwards($(this))
103
+                },
104
+                beforeSend: function(xhr, settings) {
105
+                    xhr.setRequestHeader("X-CSRFToken", document.csrftoken);
106
+                },
107
+                success: function(data, textStatus, jqXHR ) {
108
+                    select.append(
109
+                        $('<option>', {value: data.id, text: data.text, selected: true})
110
+                    );
111
+                    select.trigger('change');
112
+                    select.select2('close');
113
+                }
114
+            });
115
+        });
116
+
117
+    });
118
+    window.__dal__initListenerIsSet = true;
119
+    $('[data-autocomplete-light-function=select2]:not([id*="__prefix__"])').each(function() {
120
+        window.__dal__initialize(this);
121
+    });
122
+})(yl.jQuery);

BIN
app/staticfile/img/heartbeat.png


+ 22 - 0
app/staticfile/import_export/action_formats.js

@@ -0,0 +1,22 @@
1
+(function($) {
2
+  $(document).ready(function() {
3
+    var $actionsSelect, $formatsElement;
4
+    if ($('body').hasClass('grp-change-list')) {
5
+        // using grappelli
6
+        $actionsSelect = $('#grp-changelist-form select[name="action"]');
7
+        $formatsElement = $('#grp-changelist-form select[name="file_format"]');
8
+    } else {
9
+        // using default admin
10
+        $actionsSelect = $('#changelist-form select[name="action"]');
11
+        $formatsElement = $('#changelist-form select[name="file_format"]').parent();
12
+    }
13
+    $actionsSelect.change(function() {
14
+      if ($(this).val() === 'export_admin_action') {
15
+        $formatsElement.show();
16
+      } else {
17
+        $formatsElement.hide();
18
+      }
19
+    });
20
+    $actionsSelect.change();
21
+  });
22
+})(django.jQuery);

+ 81 - 0
app/staticfile/import_export/import.css

@@ -0,0 +1,81 @@
1
+.import-preview .errors {
2
+  position: relative;
3
+}
4
+
5
+.validation-error-count {
6
+  display: inline-block;
7
+  background-color: #e40000;
8
+  border-radius: 6px;
9
+  color: white;
10
+  font-size: 0.9em;
11
+  position: relative;
12
+  font-weight: bold;
13
+  margin-top: -2px;
14
+  padding: 0.2em 0.4em;
15
+}
16
+
17
+.validation-error-container {
18
+  position: absolute;
19
+  opacity: 0;
20
+  pointer-events: none;
21
+  background-color: #ffc1c1;
22
+  padding: 14px 15px 10px;
23
+  top: 25px;
24
+  margin: 0 0 20px 0;
25
+  width: 200px;
26
+  z-index: 2;
27
+}
28
+
29
+table.import-preview tr.skip {
30
+  background-color: #d2d2d2;
31
+}
32
+
33
+table.import-preview tr.new {
34
+  background-color: #bdd8b2;
35
+}
36
+
37
+table.import-preview tr.delete {
38
+  background-color: #f9bebf;
39
+}
40
+
41
+table.import-preview tr.update {
42
+  background-color: #fdfdcf;
43
+}
44
+
45
+.import-preview td:hover .validation-error-count {
46
+  z-index: 3;
47
+}
48
+.import-preview td:hover .validation-error-container {
49
+  opacity: 1;
50
+  pointer-events: auto;
51
+}
52
+
53
+.validation-error-list {
54
+  margin: 0;
55
+  padding: 0;
56
+}
57
+
58
+.validation-error-list li {
59
+  list-style: none;
60
+  margin: 0;
61
+}
62
+
63
+.validation-error-list > li > ul {
64
+  margin: 8px 0;
65
+  padding: 0;
66
+}
67
+
68
+.validation-error-list > li > ul > li {
69
+  padding: 0;
70
+  margin: 0 0 10px;
71
+  line-height: 1.28em;
72
+}
73
+
74
+.validation-error-field-label {
75
+  display: block;
76
+  border-bottom: 1px solid #e40000;
77
+  color: #e40000;
78
+  text-transform: uppercase;
79
+  font-weight: bold;
80
+  font-size: 0.85em;
81
+}

+ 15 - 0
app/staticfile/js/main.js

@@ -0,0 +1,15 @@
1
+$(function(){
2
+    $("#currentLocationBtn").click(function(){
3
+        if ("geolocation" in navigator){ //check geolocation available
4
+            //try to get user current location using getCurrentPosition() method
5
+            console.log("current location");
6
+            navigator.geolocation.getCurrentPosition(function(position){
7
+                console.log("xxxx");
8
+                $("#geoText").val(position.coords.latitude+","+position.coords.longitude );
9
+
10
+            });
11
+        }else{
12
+            console.log("Browser doesn't support geolocation!");
13
+        }
14
+    });
15
+});

+ 262 - 0
app/staticfile/vendor/select2/Gruntfile.js

@@ -0,0 +1,262 @@
1
+const sass = require('node-sass');
2
+
3
+module.exports = function (grunt) {
4
+  // Full list of files that must be included by RequireJS
5
+  includes = [
6
+    'jquery.select2',
7
+    'almond',
8
+
9
+    'jquery-mousewheel' // shimmed for non-full builds
10
+  ];
11
+
12
+  fullIncludes = [
13
+    'jquery',
14
+
15
+    'select2/compat/containerCss',
16
+    'select2/compat/dropdownCss',
17
+
18
+    'select2/compat/initSelection',
19
+    'select2/compat/inputData',
20
+    'select2/compat/matcher',
21
+    'select2/compat/query',
22
+
23
+    'select2/dropdown/attachContainer',
24
+    'select2/dropdown/stopPropagation',
25
+
26
+    'select2/selection/stopPropagation'
27
+  ].concat(includes);
28
+
29
+  var i18nModules = [];
30
+  var i18nPaths = {};
31
+
32
+  var i18nFiles = grunt.file.expand({
33
+    cwd: 'src/js'
34
+  }, 'select2/i18n/*.js');
35
+
36
+  var testFiles = grunt.file.expand('tests/**/*.html');
37
+  var testUrls = testFiles.map(function (filePath) {
38
+    return 'http://localhost:9999/' + filePath;
39
+  });
40
+
41
+  var testBuildNumber = "unknown";
42
+
43
+  if (process.env.TRAVIS_JOB_ID) {
44
+    testBuildNumber = "travis-" + process.env.TRAVIS_JOB_ID;
45
+  } else {
46
+    var currentTime = new Date();
47
+
48
+    testBuildNumber = "manual-" + currentTime.getTime();
49
+  }
50
+
51
+  for (var i = 0; i < i18nFiles.length; i++) {
52
+    var file = i18nFiles[i];
53
+    var name = file.split('.')[0];
54
+
55
+    i18nModules.push({
56
+      name: name
57
+    });
58
+
59
+    i18nPaths[name] = '../../' + name;
60
+  }
61
+
62
+  var minifiedBanner = '/*! Select2 <%= package.version %> | https://github.com/select2/select2/blob/master/LICENSE.md */';
63
+
64
+  grunt.initConfig({
65
+    package: grunt.file.readJSON('package.json'),
66
+
67
+    concat: {
68
+      'dist': {
69
+        options: {
70
+          banner: grunt.file.read('src/js/wrapper.start.js'),
71
+        },
72
+        src: [
73
+          'dist/js/select2.js',
74
+          'src/js/wrapper.end.js'
75
+        ],
76
+        dest: 'dist/js/select2.js'
77
+      },
78
+      'dist.full': {
79
+        options: {
80
+          banner: grunt.file.read('src/js/wrapper.start.js'),
81
+        },
82
+        src: [
83
+          'dist/js/select2.full.js',
84
+          'src/js/wrapper.end.js'
85
+        ],
86
+        dest: 'dist/js/select2.full.js'
87
+      }
88
+    },
89
+
90
+    connect: {
91
+      tests: {
92
+        options: {
93
+          base: '.',
94
+          hostname: '127.0.0.1',
95
+          port: 9999
96
+        }
97
+      }
98
+    },
99
+
100
+    uglify: {
101
+      'dist': {
102
+        src: 'dist/js/select2.js',
103
+        dest: 'dist/js/select2.min.js',
104
+        options: {
105
+          banner: minifiedBanner
106
+        }
107
+      },
108
+      'dist.full': {
109
+        src: 'dist/js/select2.full.js',
110
+        dest: 'dist/js/select2.full.min.js',
111
+        options: {
112
+          banner: minifiedBanner
113
+        }
114
+      }
115
+    },
116
+
117
+    qunit: {
118
+      all: {
119
+        options: {
120
+          urls: testUrls
121
+        }
122
+      }
123
+    },
124
+
125
+    jshint: {
126
+      options: {
127
+        jshintrc: true,
128
+        reporterOutput: ''
129
+      },
130
+      code: {
131
+        src: ['src/js/**/*.js']
132
+      },
133
+      tests: {
134
+        src: ['tests/**/*.js']
135
+      }
136
+    },
137
+
138
+    sass: {
139
+      dist: {
140
+        options: {
141
+          implementation: sass,
142
+          outputStyle: 'compressed'
143
+        },
144
+        files: {
145
+          'dist/css/select2.min.css': [
146
+            'src/scss/core.scss',
147
+            'src/scss/theme/default/layout.css'
148
+          ]
149
+        }
150
+      },
151
+      dev: {
152
+        options: {
153
+          implementation: sass,
154
+          outputStyle: 'nested'
155
+        },
156
+        files: {
157
+          'dist/css/select2.css': [
158
+            'src/scss/core.scss',
159
+            'src/scss/theme/default/layout.css'
160
+          ]
161
+        }
162
+      }
163
+    },
164
+
165
+    requirejs: {
166
+      'dist': {
167
+        options: {
168
+          baseUrl: 'src/js',
169
+          optimize: 'none',
170
+          name: 'select2/core',
171
+          out: 'dist/js/select2.js',
172
+          include: includes,
173
+          namespace: 'S2',
174
+          paths: {
175
+            'almond': require.resolve('almond').slice(0, -3),
176
+            'jquery': 'jquery.shim',
177
+            'jquery-mousewheel': 'jquery.mousewheel.shim'
178
+          },
179
+          wrap: {
180
+            startFile: 'src/js/banner.start.js',
181
+            endFile: 'src/js/banner.end.js'
182
+          }
183
+        }
184
+      },
185
+      'dist.full': {
186
+        options: {
187
+          baseUrl: 'src/js',
188
+          optimize: 'none',
189
+          name: 'select2/core',
190
+          out: 'dist/js/select2.full.js',
191
+          include: fullIncludes,
192
+          namespace: 'S2',
193
+          paths: {
194
+            'almond': require.resolve('almond').slice(0, -3),
195
+            'jquery': 'jquery.shim',
196
+            'jquery-mousewheel': require.resolve('jquery-mousewheel').slice(0, -3)
197
+          },
198
+          wrap: {
199
+            startFile: 'src/js/banner.start.js',
200
+            endFile: 'src/js/banner.end.js'
201
+          }
202
+        }
203
+      },
204
+      'i18n': {
205
+        options: {
206
+          baseUrl: 'src/js/select2/i18n',
207
+          dir: 'dist/js/i18n',
208
+          paths: i18nPaths,
209
+          modules: i18nModules,
210
+          namespace: 'S2',
211
+          wrap: {
212
+            start: minifiedBanner + grunt.file.read('src/js/banner.start.js'),
213
+            end: grunt.file.read('src/js/banner.end.js')
214
+          }
215
+        }
216
+      }
217
+    },
218
+
219
+    watch: {
220
+      js: {
221
+        files: [
222
+          'src/js/select2/**/*.js',
223
+          'tests/**/*.js'
224
+        ],
225
+        tasks: [
226
+          'compile',
227
+          'test',
228
+          'minify'
229
+        ]
230
+      },
231
+      css: {
232
+        files: [
233
+          'src/scss/**/*.scss'
234
+        ],
235
+        tasks: [
236
+          'compile',
237
+          'minify'
238
+        ]
239
+      }
240
+    }
241
+  });
242
+
243
+  grunt.loadNpmTasks('grunt-contrib-concat');
244
+  grunt.loadNpmTasks('grunt-contrib-connect');
245
+  grunt.loadNpmTasks('grunt-contrib-jshint');
246
+  grunt.loadNpmTasks('grunt-contrib-qunit');
247
+  grunt.loadNpmTasks('grunt-contrib-requirejs');
248
+  grunt.loadNpmTasks('grunt-contrib-uglify');
249
+  grunt.loadNpmTasks('grunt-contrib-watch');
250
+
251
+  grunt.loadNpmTasks('grunt-sass');
252
+
253
+  grunt.registerTask('default', ['compile', 'test', 'minify']);
254
+
255
+  grunt.registerTask('compile', [
256
+    'requirejs:dist', 'requirejs:dist.full', 'requirejs:i18n',
257
+    'concat:dist', 'concat:dist.full',
258
+    'sass:dev'
259
+  ]);
260
+  grunt.registerTask('minify', ['uglify', 'sass:dist']);
261
+  grunt.registerTask('test', ['connect:tests', 'qunit', 'jshint']);
262
+};

+ 13 - 0
app/staticfile/vendor/select2/bower.json

@@ -0,0 +1,13 @@
1
+{
2
+    "name": "select2",
3
+    "description": "Select2 is a jQuery based replacement for select boxes. It supports searching, remote data sets, and infinite scrolling of results.",
4
+    "main": [
5
+        "dist/js/select2.js",
6
+        "src/scss/core.scss"
7
+    ],
8
+    "license": "MIT",
9
+    "repository": {
10
+        "type": "git",
11
+        "url": "git@github.com:select2/select2.git"
12
+    }
13
+}

+ 19 - 0
app/staticfile/vendor/select2/component.json

@@ -0,0 +1,19 @@
1
+{
2
+  "name": "select2",
3
+  "repo": "select/select2",
4
+  "description": "Select2 is a jQuery based replacement for select boxes. It supports searching, remote data sets, and infinite scrolling of results.",
5
+  "version": "4.0.7",
6
+  "demo": "https://select2.org/",
7
+  "keywords": [
8
+    "jquery"
9
+  ],
10
+  "main": "dist/js/select2.js",
11
+  "styles": [
12
+    "dist/css/select2.css"
13
+  ],
14
+  "scripts": [
15
+    "dist/js/select2.js",
16
+    "dist/js/i18n/*.js"
17
+  ],
18
+  "license": "MIT"
19
+}

+ 22 - 0
app/staticfile/vendor/select2/composer.json

@@ -0,0 +1,22 @@
1
+{
2
+  "name": "select2/select2",
3
+  "description": "Select2 is a jQuery based replacement for select boxes.",
4
+  "type": "component",
5
+  "homepage": "https://select2.org/",
6
+  "license": "MIT",
7
+  "extra": {
8
+    "component": {
9
+      "scripts": [
10
+        "dist/js/select2.js"
11
+      ],
12
+      "styles": [
13
+        "dist/css/select2.css"
14
+      ],
15
+      "files": [
16
+        "dist/js/select2.js",
17
+        "dist/js/i18n/*.js",
18
+        "dist/css/select2.css"
19
+      ]
20
+    }
21
+  }
22
+}

+ 484 - 0
app/staticfile/vendor/select2/dist/css/select2.css

@@ -0,0 +1,484 @@
1
+.select2-container {
2
+  box-sizing: border-box;
3
+  display: inline-block;
4
+  margin: 0;
5
+  position: relative;
6
+  vertical-align: middle; }
7
+  .select2-container .select2-selection--single {
8
+    box-sizing: border-box;
9
+    cursor: pointer;
10
+    display: block;
11
+    height: 28px;
12
+    user-select: none;
13
+    -webkit-user-select: none; }
14
+    .select2-container .select2-selection--single .select2-selection__rendered {
15
+      display: block;
16
+      padding-left: 8px;
17
+      padding-right: 20px;
18
+      overflow: hidden;
19
+      text-overflow: ellipsis;
20
+      white-space: nowrap; }
21
+    .select2-container .select2-selection--single .select2-selection__clear {
22
+      position: relative; }
23
+  .select2-container[dir="rtl"] .select2-selection--single .select2-selection__rendered {
24
+    padding-right: 8px;
25
+    padding-left: 20px; }
26
+  .select2-container .select2-selection--multiple {
27
+    box-sizing: border-box;
28
+    cursor: pointer;
29
+    display: block;
30
+    min-height: 32px;
31
+    user-select: none;
32
+    -webkit-user-select: none; }
33
+    .select2-container .select2-selection--multiple .select2-selection__rendered {
34
+      display: inline-block;
35
+      overflow: hidden;
36
+      padding-left: 8px;
37
+      text-overflow: ellipsis;
38
+      white-space: nowrap; }
39
+  .select2-container .select2-search--inline {
40
+    float: left; }
41
+    .select2-container .select2-search--inline .select2-search__field {
42
+      box-sizing: border-box;
43
+      border: none;
44
+      font-size: 100%;
45
+      margin-top: 5px;
46
+      padding: 0; }
47
+      .select2-container .select2-search--inline .select2-search__field::-webkit-search-cancel-button {
48
+        -webkit-appearance: none; }
49
+
50
+.select2-dropdown {
51
+  background-color: white;
52
+  border: 1px solid #aaa;
53
+  border-radius: 4px;
54
+  box-sizing: border-box;
55
+  display: block;
56
+  position: absolute;
57
+  left: -100000px;
58
+  width: 100%;
59
+  z-index: 1051; }
60
+
61
+.select2-results {
62
+  display: block; }
63
+
64
+.select2-results__options {
65
+  list-style: none;
66
+  margin: 0;
67
+  padding: 0; }
68
+
69
+.select2-results__option {
70
+  padding: 6px;
71
+  user-select: none;
72
+  -webkit-user-select: none; }
73
+  .select2-results__option[aria-selected] {
74
+    cursor: pointer; }
75
+
76
+.select2-container--open .select2-dropdown {
77
+  left: 0; }
78
+
79
+.select2-container--open .select2-dropdown--above {
80
+  border-bottom: none;
81
+  border-bottom-left-radius: 0;
82
+  border-bottom-right-radius: 0; }
83
+
84
+.select2-container--open .select2-dropdown--below {
85
+  border-top: none;
86
+  border-top-left-radius: 0;
87
+  border-top-right-radius: 0; }
88
+
89
+.select2-search--dropdown {
90
+  display: block;
91
+  padding: 4px; }
92
+  .select2-search--dropdown .select2-search__field {
93
+    padding: 4px;
94
+    width: 100%;
95
+    box-sizing: border-box; }
96
+    .select2-search--dropdown .select2-search__field::-webkit-search-cancel-button {
97
+      -webkit-appearance: none; }
98
+  .select2-search--dropdown.select2-search--hide {
99
+    display: none; }
100
+
101
+.select2-close-mask {
102
+  border: 0;
103
+  margin: 0;
104
+  padding: 0;
105
+  display: block;
106
+  position: fixed;
107
+  left: 0;
108
+  top: 0;
109
+  min-height: 100%;
110
+  min-width: 100%;
111
+  height: auto;
112
+  width: auto;
113
+  opacity: 0;
114
+  z-index: 99;
115
+  background-color: #fff;
116
+  filter: alpha(opacity=0); }
117
+
118
+.select2-hidden-accessible {
119
+  border: 0 !important;
120
+  clip: rect(0 0 0 0) !important;
121
+  -webkit-clip-path: inset(50%) !important;
122
+  clip-path: inset(50%) !important;
123
+  height: 1px !important;
124
+  overflow: hidden !important;
125
+  padding: 0 !important;
126
+  position: absolute !important;
127
+  width: 1px !important;
128
+  white-space: nowrap !important; }
129
+
130
+.select2-container--default .select2-selection--single {
131
+  background-color: #fff;
132
+  border: 1px solid #aaa;
133
+  border-radius: 4px; }
134
+  .select2-container--default .select2-selection--single .select2-selection__rendered {
135
+    color: #444;
136
+    line-height: 28px; }
137
+  .select2-container--default .select2-selection--single .select2-selection__clear {
138
+    cursor: pointer;
139
+    float: right;
140
+    font-weight: bold; }
141
+  .select2-container--default .select2-selection--single .select2-selection__placeholder {
142
+    color: #999; }
143
+  .select2-container--default .select2-selection--single .select2-selection__arrow {
144
+    height: 26px;
145
+    position: absolute;
146
+    top: 1px;
147
+    right: 1px;
148
+    width: 20px; }
149
+    .select2-container--default .select2-selection--single .select2-selection__arrow b {
150
+      border-color: #888 transparent transparent transparent;
151
+      border-style: solid;
152
+      border-width: 5px 4px 0 4px;
153
+      height: 0;
154
+      left: 50%;
155
+      margin-left: -4px;
156
+      margin-top: -2px;
157
+      position: absolute;
158
+      top: 50%;
159
+      width: 0; }
160
+
161
+.select2-container--default[dir="rtl"] .select2-selection--single .select2-selection__clear {
162
+  float: left; }
163
+
164
+.select2-container--default[dir="rtl"] .select2-selection--single .select2-selection__arrow {
165
+  left: 1px;
166
+  right: auto; }
167
+
168
+.select2-container--default.select2-container--disabled .select2-selection--single {
169
+  background-color: #eee;
170
+  cursor: default; }
171
+  .select2-container--default.select2-container--disabled .select2-selection--single .select2-selection__clear {
172
+    display: none; }
173
+
174
+.select2-container--default.select2-container--open .select2-selection--single .select2-selection__arrow b {
175
+  border-color: transparent transparent #888 transparent;
176
+  border-width: 0 4px 5px 4px; }
177
+
178
+.select2-container--default .select2-selection--multiple {
179
+  background-color: white;
180
+  border: 1px solid #aaa;
181
+  border-radius: 4px;
182
+  cursor: text; }
183
+  .select2-container--default .select2-selection--multiple .select2-selection__rendered {
184
+    box-sizing: border-box;
185
+    list-style: none;
186
+    margin: 0;
187
+    padding: 0 5px;
188
+    width: 100%; }
189
+    .select2-container--default .select2-selection--multiple .select2-selection__rendered li {
190
+      list-style: none; }
191
+  .select2-container--default .select2-selection--multiple .select2-selection__placeholder {
192
+    color: #999;
193
+    margin-top: 5px;
194
+    float: left; }
195
+  .select2-container--default .select2-selection--multiple .select2-selection__clear {
196
+    cursor: pointer;
197
+    float: right;
198
+    font-weight: bold;
199
+    margin-top: 5px;
200
+    margin-right: 10px; }
201
+  .select2-container--default .select2-selection--multiple .select2-selection__choice {
202
+    background-color: #e4e4e4;
203
+    border: 1px solid #aaa;
204
+    border-radius: 4px;
205
+    cursor: default;
206
+    float: left;
207
+    margin-right: 5px;
208
+    margin-top: 5px;
209
+    padding: 0 5px; }
210
+  .select2-container--default .select2-selection--multiple .select2-selection__choice__remove {
211
+    color: #999;
212
+    cursor: pointer;
213
+    display: inline-block;
214
+    font-weight: bold;
215
+    margin-right: 2px; }
216
+    .select2-container--default .select2-selection--multiple .select2-selection__choice__remove:hover {
217
+      color: #333; }
218
+
219
+.select2-container--default[dir="rtl"] .select2-selection--multiple .select2-selection__choice, .select2-container--default[dir="rtl"] .select2-selection--multiple .select2-selection__placeholder, .select2-container--default[dir="rtl"] .select2-selection--multiple .select2-search--inline {
220
+  float: right; }
221
+
222
+.select2-container--default[dir="rtl"] .select2-selection--multiple .select2-selection__choice {
223
+  margin-left: 5px;
224
+  margin-right: auto; }
225
+
226
+.select2-container--default[dir="rtl"] .select2-selection--multiple .select2-selection__choice__remove {
227
+  margin-left: 2px;
228
+  margin-right: auto; }
229
+
230
+.select2-container--default.select2-container--focus .select2-selection--multiple {
231
+  border: solid black 1px;
232
+  outline: 0; }
233
+
234
+.select2-container--default.select2-container--disabled .select2-selection--multiple {
235
+  background-color: #eee;
236
+  cursor: default; }
237
+
238
+.select2-container--default.select2-container--disabled .select2-selection__choice__remove {
239
+  display: none; }
240
+
241
+.select2-container--default.select2-container--open.select2-container--above .select2-selection--single, .select2-container--default.select2-container--open.select2-container--above .select2-selection--multiple {
242
+  border-top-left-radius: 0;
243
+  border-top-right-radius: 0; }
244
+
245
+.select2-container--default.select2-container--open.select2-container--below .select2-selection--single, .select2-container--default.select2-container--open.select2-container--below .select2-selection--multiple {
246
+  border-bottom-left-radius: 0;
247
+  border-bottom-right-radius: 0; }
248
+
249
+.select2-container--default .select2-search--dropdown .select2-search__field {
250
+  border: 1px solid #aaa; }
251
+
252
+.select2-container--default .select2-search--inline .select2-search__field {
253
+  background: transparent;
254
+  border: none;
255
+  outline: 0;
256
+  box-shadow: none;
257
+  -webkit-appearance: textfield; }
258
+
259
+.select2-container--default .select2-results > .select2-results__options {
260
+  max-height: 200px;
261
+  overflow-y: auto; }
262
+
263
+.select2-container--default .select2-results__option[role=group] {
264
+  padding: 0; }
265
+
266
+.select2-container--default .select2-results__option[aria-disabled=true] {
267
+  color: #999; }
268
+
269
+.select2-container--default .select2-results__option[aria-selected=true] {
270
+  background-color: #ddd; }
271
+
272
+.select2-container--default .select2-results__option .select2-results__option {
273
+  padding-left: 1em; }
274
+  .select2-container--default .select2-results__option .select2-results__option .select2-results__group {
275
+    padding-left: 0; }
276
+  .select2-container--default .select2-results__option .select2-results__option .select2-results__option {
277
+    margin-left: -1em;
278
+    padding-left: 2em; }
279
+    .select2-container--default .select2-results__option .select2-results__option .select2-results__option .select2-results__option {
280
+      margin-left: -2em;
281
+      padding-left: 3em; }
282
+      .select2-container--default .select2-results__option .select2-results__option .select2-results__option .select2-results__option .select2-results__option {
283
+        margin-left: -3em;
284
+        padding-left: 4em; }
285
+        .select2-container--default .select2-results__option .select2-results__option .select2-results__option .select2-results__option .select2-results__option .select2-results__option {
286
+          margin-left: -4em;
287
+          padding-left: 5em; }
288
+          .select2-container--default .select2-results__option .select2-results__option .select2-results__option .select2-results__option .select2-results__option .select2-results__option .select2-results__option {
289
+            margin-left: -5em;
290
+            padding-left: 6em; }
291
+
292
+.select2-container--default .select2-results__option--highlighted[aria-selected] {
293
+  background-color: #5897fb;
294
+  color: white; }
295
+
296
+.select2-container--default .select2-results__group {
297
+  cursor: default;
298
+  display: block;
299
+  padding: 6px; }
300
+
301
+.select2-container--classic .select2-selection--single {
302
+  background-color: #f7f7f7;
303
+  border: 1px solid #aaa;
304
+  border-radius: 4px;
305
+  outline: 0;
306
+  background-image: -webkit-linear-gradient(top, white 50%, #eeeeee 100%);
307
+  background-image: -o-linear-gradient(top, white 50%, #eeeeee 100%);
308
+  background-image: linear-gradient(to bottom, white 50%, #eeeeee 100%);
309
+  background-repeat: repeat-x;
310
+  filter: progid:DXImageTransform.Microsoft.gradient(startColorstr='#FFFFFFFF', endColorstr='#FFEEEEEE', GradientType=0); }
311
+  .select2-container--classic .select2-selection--single:focus {
312
+    border: 1px solid #5897fb; }
313
+  .select2-container--classic .select2-selection--single .select2-selection__rendered {
314
+    color: #444;
315
+    line-height: 28px; }
316
+  .select2-container--classic .select2-selection--single .select2-selection__clear {
317
+    cursor: pointer;
318
+    float: right;
319
+    font-weight: bold;
320
+    margin-right: 10px; }
321
+  .select2-container--classic .select2-selection--single .select2-selection__placeholder {
322
+    color: #999; }
323
+  .select2-container--classic .select2-selection--single .select2-selection__arrow {
324
+    background-color: #ddd;
325
+    border: none;
326
+    border-left: 1px solid #aaa;
327
+    border-top-right-radius: 4px;
328
+    border-bottom-right-radius: 4px;
329
+    height: 26px;
330
+    position: absolute;
331
+    top: 1px;
332
+    right: 1px;
333
+    width: 20px;
334
+    background-image: -webkit-linear-gradient(top, #eeeeee 50%, #cccccc 100%);
335
+    background-image: -o-linear-gradient(top, #eeeeee 50%, #cccccc 100%);
336
+    background-image: linear-gradient(to bottom, #eeeeee 50%, #cccccc 100%);
337
+    background-repeat: repeat-x;
338
+    filter: progid:DXImageTransform.Microsoft.gradient(startColorstr='#FFEEEEEE', endColorstr='#FFCCCCCC', GradientType=0); }
339
+    .select2-container--classic .select2-selection--single .select2-selection__arrow b {
340
+      border-color: #888 transparent transparent transparent;
341
+      border-style: solid;
342
+      border-width: 5px 4px 0 4px;
343
+      height: 0;
344
+      left: 50%;
345
+      margin-left: -4px;
346
+      margin-top: -2px;
347
+      position: absolute;
348
+      top: 50%;
349
+      width: 0; }
350
+
351
+.select2-container--classic[dir="rtl"] .select2-selection--single .select2-selection__clear {
352
+  float: left; }
353
+
354
+.select2-container--classic[dir="rtl"] .select2-selection--single .select2-selection__arrow {
355
+  border: none;
356
+  border-right: 1px solid #aaa;
357
+  border-radius: 0;
358
+  border-top-left-radius: 4px;
359
+  border-bottom-left-radius: 4px;
360
+  left: 1px;
361
+  right: auto; }
362
+
363
+.select2-container--classic.select2-container--open .select2-selection--single {
364
+  border: 1px solid #5897fb; }
365
+  .select2-container--classic.select2-container--open .select2-selection--single .select2-selection__arrow {
366
+    background: transparent;
367
+    border: none; }
368
+    .select2-container--classic.select2-container--open .select2-selection--single .select2-selection__arrow b {
369
+      border-color: transparent transparent #888 transparent;
370
+      border-width: 0 4px 5px 4px; }
371
+
372
+.select2-container--classic.select2-container--open.select2-container--above .select2-selection--single {
373
+  border-top: none;
374
+  border-top-left-radius: 0;
375
+  border-top-right-radius: 0;
376
+  background-image: -webkit-linear-gradient(top, white 0%, #eeeeee 50%);
377
+  background-image: -o-linear-gradient(top, white 0%, #eeeeee 50%);
378
+  background-image: linear-gradient(to bottom, white 0%, #eeeeee 50%);
379
+  background-repeat: repeat-x;
380
+  filter: progid:DXImageTransform.Microsoft.gradient(startColorstr='#FFFFFFFF', endColorstr='#FFEEEEEE', GradientType=0); }
381
+
382
+.select2-container--classic.select2-container--open.select2-container--below .select2-selection--single {
383
+  border-bottom: none;
384
+  border-bottom-left-radius: 0;
385
+  border-bottom-right-radius: 0;
386
+  background-image: -webkit-linear-gradient(top, #eeeeee 50%, white 100%);
387
+  background-image: -o-linear-gradient(top, #eeeeee 50%, white 100%);
388
+  background-image: linear-gradient(to bottom, #eeeeee 50%, white 100%);
389
+  background-repeat: repeat-x;
390
+  filter: progid:DXImageTransform.Microsoft.gradient(startColorstr='#FFEEEEEE', endColorstr='#FFFFFFFF', GradientType=0); }
391
+
392
+.select2-container--classic .select2-selection--multiple {
393
+  background-color: white;
394
+  border: 1px solid #aaa;
395
+  border-radius: 4px;
396
+  cursor: text;
397
+  outline: 0; }
398
+  .select2-container--classic .select2-selection--multiple:focus {
399
+    border: 1px solid #5897fb; }
400
+  .select2-container--classic .select2-selection--multiple .select2-selection__rendered {
401
+    list-style: none;
402
+    margin: 0;
403
+    padding: 0 5px; }
404
+  .select2-container--classic .select2-selection--multiple .select2-selection__clear {
405
+    display: none; }
406
+  .select2-container--classic .select2-selection--multiple .select2-selection__choice {
407
+    background-color: #e4e4e4;
408
+    border: 1px solid #aaa;
409
+    border-radius: 4px;
410
+    cursor: default;
411
+    float: left;
412
+    margin-right: 5px;
413
+    margin-top: 5px;
414
+    padding: 0 5px; }
415
+  .select2-container--classic .select2-selection--multiple .select2-selection__choice__remove {
416
+    color: #888;
417
+    cursor: pointer;
418
+    display: inline-block;
419
+    font-weight: bold;
420
+    margin-right: 2px; }
421
+    .select2-container--classic .select2-selection--multiple .select2-selection__choice__remove:hover {
422
+      color: #555; }
423
+
424
+.select2-container--classic[dir="rtl"] .select2-selection--multiple .select2-selection__choice {
425
+  float: right;
426
+  margin-left: 5px;
427
+  margin-right: auto; }
428
+
429
+.select2-container--classic[dir="rtl"] .select2-selection--multiple .select2-selection__choice__remove {
430
+  margin-left: 2px;
431
+  margin-right: auto; }
432
+
433
+.select2-container--classic.select2-container--open .select2-selection--multiple {
434
+  border: 1px solid #5897fb; }
435
+
436
+.select2-container--classic.select2-container--open.select2-container--above .select2-selection--multiple {
437
+  border-top: none;
438
+  border-top-left-radius: 0;
439
+  border-top-right-radius: 0; }
440
+
441
+.select2-container--classic.select2-container--open.select2-container--below .select2-selection--multiple {
442
+  border-bottom: none;
443
+  border-bottom-left-radius: 0;
444
+  border-bottom-right-radius: 0; }
445
+
446
+.select2-container--classic .select2-search--dropdown .select2-search__field {
447
+  border: 1px solid #aaa;
448
+  outline: 0; }
449
+
450
+.select2-container--classic .select2-search--inline .select2-search__field {
451
+  outline: 0;
452
+  box-shadow: none; }
453
+
454
+.select2-container--classic .select2-dropdown {
455
+  background-color: white;
456
+  border: 1px solid transparent; }
457
+
458
+.select2-container--classic .select2-dropdown--above {
459
+  border-bottom: none; }
460
+
461
+.select2-container--classic .select2-dropdown--below {
462
+  border-top: none; }
463
+
464
+.select2-container--classic .select2-results > .select2-results__options {
465
+  max-height: 200px;
466
+  overflow-y: auto; }
467
+
468
+.select2-container--classic .select2-results__option[role=group] {
469
+  padding: 0; }
470
+
471
+.select2-container--classic .select2-results__option[aria-disabled=true] {
472
+  color: grey; }
473
+
474
+.select2-container--classic .select2-results__option--highlighted[aria-selected] {
475
+  background-color: #3875d7;
476
+  color: white; }
477
+
478
+.select2-container--classic .select2-results__group {
479
+  cursor: default;
480
+  display: block;
481
+  padding: 6px; }
482
+
483
+.select2-container--classic.select2-container--open .select2-dropdown {
484
+  border-color: #5897fb; }

Failā izmaiņas netiks attēlotas, jo tās ir par lielu
+ 1 - 0
app/staticfile/vendor/select2/dist/css/select2.min.css


Failā izmaiņas netiks attēlotas, jo tās ir par lielu
+ 3 - 0
app/staticfile/vendor/select2/dist/js/i18n/af.js


Failā izmaiņas netiks attēlotas, jo tās ir par lielu
+ 3 - 0
app/staticfile/vendor/select2/dist/js/i18n/ar.js


Failā izmaiņas netiks attēlotas, jo tās ir par lielu
+ 3 - 0
app/staticfile/vendor/select2/dist/js/i18n/az.js


Failā izmaiņas netiks attēlotas, jo tās ir par lielu
+ 3 - 0
app/staticfile/vendor/select2/dist/js/i18n/bg.js


Failā izmaiņas netiks attēlotas, jo tās ir par lielu
+ 3 - 0
app/staticfile/vendor/select2/dist/js/i18n/bn.js


Failā izmaiņas netiks attēlotas, jo tās ir par lielu
+ 3 - 0
app/staticfile/vendor/select2/dist/js/i18n/bs.js


Failā izmaiņas netiks attēlotas, jo tās ir par lielu
+ 3 - 0
app/staticfile/vendor/select2/dist/js/i18n/ca.js


Failā izmaiņas netiks attēlotas, jo tās ir par lielu
+ 3 - 0
app/staticfile/vendor/select2/dist/js/i18n/cs.js


Failā izmaiņas netiks attēlotas, jo tās ir par lielu
+ 3 - 0
app/staticfile/vendor/select2/dist/js/i18n/da.js


Failā izmaiņas netiks attēlotas, jo tās ir par lielu
+ 3 - 0
app/staticfile/vendor/select2/dist/js/i18n/de.js


Failā izmaiņas netiks attēlotas, jo tās ir par lielu
+ 3 - 0
app/staticfile/vendor/select2/dist/js/i18n/dsb.js


Failā izmaiņas netiks attēlotas, jo tās ir par lielu
+ 3 - 0
app/staticfile/vendor/select2/dist/js/i18n/el.js


Failā izmaiņas netiks attēlotas, jo tās ir par lielu
+ 3 - 0
app/staticfile/vendor/select2/dist/js/i18n/en.js


Failā izmaiņas netiks attēlotas, jo tās ir par lielu
+ 3 - 0
app/staticfile/vendor/select2/dist/js/i18n/es.js


Failā izmaiņas netiks attēlotas, jo tās ir par lielu
+ 3 - 0
app/staticfile/vendor/select2/dist/js/i18n/et.js


Failā izmaiņas netiks attēlotas, jo tās ir par lielu
+ 3 - 0
app/staticfile/vendor/select2/dist/js/i18n/eu.js


Failā izmaiņas netiks attēlotas, jo tās ir par lielu
+ 3 - 0
app/staticfile/vendor/select2/dist/js/i18n/fa.js


Failā izmaiņas netiks attēlotas, jo tās ir par lielu
+ 3 - 0
app/staticfile/vendor/select2/dist/js/i18n/fi.js


Failā izmaiņas netiks attēlotas, jo tās ir par lielu
+ 3 - 0
app/staticfile/vendor/select2/dist/js/i18n/fr.js


Failā izmaiņas netiks attēlotas, jo tās ir par lielu
+ 3 - 0
app/staticfile/vendor/select2/dist/js/i18n/gl.js


Failā izmaiņas netiks attēlotas, jo tās ir par lielu
+ 3 - 0
app/staticfile/vendor/select2/dist/js/i18n/he.js


Failā izmaiņas netiks attēlotas, jo tās ir par lielu
+ 3 - 0
app/staticfile/vendor/select2/dist/js/i18n/hi.js


Failā izmaiņas netiks attēlotas, jo tās ir par lielu
+ 3 - 0
app/staticfile/vendor/select2/dist/js/i18n/hr.js


Failā izmaiņas netiks attēlotas, jo tās ir par lielu
+ 3 - 0
app/staticfile/vendor/select2/dist/js/i18n/hsb.js


+ 0 - 0
app/staticfile/vendor/select2/dist/js/i18n/hu.js


Daži faili netika attēloti, jo izmaiņu fails ir pārāk liels

tum/whitesports - Gogs: Simplico Git Service

Açıklama Yok

class-wp-rewrite.php 61KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997
  1. <?php
  2. /**
  3. * Rewrite API: WP_Rewrite class
  4. *
  5. * @package WordPress
  6. * @subpackage Rewrite
  7. * @since 1.5.0
  8. */
  9. /**
  10. * Core class used to implement a rewrite component API.
  11. *
  12. * The WordPress Rewrite class writes the rewrite module rules to the .htaccess
  13. * file. It also handles parsing the request to get the correct setup for the
  14. * WordPress Query class.
  15. *
  16. * The Rewrite along with WP class function as a front controller for WordPress.
  17. * You can add rules to trigger your page view and processing using this
  18. * component. The full functionality of a front controller does not exist,
  19. * meaning you can't define how the template files load based on the rewrite
  20. * rules.
  21. *
  22. * @since 1.5.0
  23. */
  24. class WP_Rewrite {
  25. /**
  26. * Permalink structure for posts.
  27. *
  28. * @since 1.5.0
  29. * @var string
  30. */
  31. public $permalink_structure;
  32. /**
  33. * Whether to add trailing slashes.
  34. *
  35. * @since 2.2.0
  36. * @var bool
  37. */
  38. public $use_trailing_slashes;
  39. /**
  40. * Base for the author permalink structure (example.com/$author_base/authorname).
  41. *
  42. * @since 1.5.0
  43. * @var string
  44. */
  45. public $author_base = 'author';
  46. /**
  47. * Permalink structure for author archives.
  48. *
  49. * @since 1.5.0
  50. * @var string
  51. */
  52. public $author_structure;
  53. /**
  54. * Permalink structure for date archives.
  55. *
  56. * @since 1.5.0
  57. * @var string
  58. */
  59. public $date_structure;
  60. /**
  61. * Permalink structure for pages.
  62. *
  63. * @since 1.5.0
  64. * @var string
  65. */
  66. public $page_structure;
  67. /**
  68. * Base of the search permalink structure (example.com/$search_base/query).
  69. *
  70. * @since 1.5.0
  71. * @var string
  72. */
  73. public $search_base = 'search';
  74. /**
  75. * Permalink structure for searches.
  76. *
  77. * @since 1.5.0
  78. * @var string
  79. */
  80. public $search_structure;
  81. /**
  82. * Comments permalink base.
  83. *
  84. * @since 1.5.0
  85. * @var string
  86. */
  87. public $comments_base = 'comments';
  88. /**
  89. * Pagination permalink base.
  90. *
  91. * @since 3.1.0
  92. * @var string
  93. */
  94. public $pagination_base = 'page';
  95. /**
  96. * Comments pagination permalink base.
  97. *
  98. * @since 4.2.0
  99. * @var string
  100. */
  101. public $comments_pagination_base = 'comment-page';
  102. /**
  103. * Feed permalink base.
  104. *
  105. * @since 1.5.0
  106. * @var string
  107. */
  108. public $feed_base = 'feed';
  109. /**
  110. * Comments feed permalink structure.
  111. *
  112. * @since 1.5.0
  113. * @var string
  114. */
  115. public $comment_feed_structure;
  116. /**
  117. * Feed request permalink structure.
  118. *
  119. * @since 1.5.0
  120. * @var string
  121. */
  122. public $feed_structure;
  123. /**
  124. * The static portion of the post permalink structure.
  125. *
  126. * If the permalink structure is "/archive/%post_id%" then the front
  127. * is "/archive/". If the permalink structure is "/%year%/%postname%/"
  128. * then the front is "/".
  129. *
  130. * @since 1.5.0
  131. * @var string
  132. *
  133. * @see WP_Rewrite::init()
  134. */
  135. public $front;
  136. /**
  137. * The prefix for all permalink structures.
  138. *
  139. * If PATHINFO/index permalinks are in use then the root is the value of
  140. * `WP_Rewrite::$index` with a trailing slash appended. Otherwise the root
  141. * will be empty.
  142. *
  143. * @since 1.5.0
  144. * @var string
  145. *
  146. * @see WP_Rewrite::init()
  147. * @see WP_Rewrite::using_index_permalinks()
  148. */
  149. public $root = '';
  150. /**
  151. * The name of the index file which is the entry point to all requests.
  152. *
  153. * @since 1.5.0
  154. * @var string
  155. */
  156. public $index = 'index.php';
  157. /**
  158. * Variable name to use for regex matches in the rewritten query.
  159. *
  160. * @since 1.5.0
  161. * @var string
  162. */
  163. public $matches = '';
  164. /**
  165. * Rewrite rules to match against the request to find the redirect or query.
  166. *
  167. * @since 1.5.0
  168. * @var array
  169. */
  170. public $rules;
  171. /**
  172. * Additional rules added external to the rewrite class.
  173. *
  174. * Those not generated by the class, see add_rewrite_rule().
  175. *
  176. * @since 2.1.0
  177. * @var array
  178. */
  179. public $extra_rules = array();
  180. /**
  181. * Additional rules that belong at the beginning to match first.
  182. *
  183. * Those not generated by the class, see add_rewrite_rule().
  184. *
  185. * @since 2.3.0
  186. * @var array
  187. */
  188. public $extra_rules_top = array();
  189. /**
  190. * Rules that don't redirect to WordPress' index.php.
  191. *
  192. * These rules are written to the mod_rewrite portion of the .htaccess,
  193. * and are added by add_external_rule().
  194. *
  195. * @since 2.1.0
  196. * @var array
  197. */
  198. public $non_wp_rules = array();
  199. /**
  200. * Extra permalink structures, e.g. categories, added by add_permastruct().
  201. *
  202. * @since 2.1.0
  203. * @var array
  204. */
  205. public $extra_permastructs = array();
  206. /**
  207. * Endpoints (like /trackback/) added by add_rewrite_endpoint().
  208. *
  209. * @since 2.1.0
  210. * @var array
  211. */
  212. public $endpoints;
  213. /**
  214. * Whether to write every mod_rewrite rule for WordPress into the .htaccess file.
  215. *
  216. * This is off by default, turning it on might print a lot of rewrite rules
  217. * to the .htaccess file.
  218. *
  219. * @since 2.0.0
  220. * @var bool
  221. *
  222. * @see WP_Rewrite::mod_rewrite_rules()
  223. */
  224. public $use_verbose_rules = false;
  225. /**
  226. * Could post permalinks be confused with those of pages?
  227. *
  228. * If the first rewrite tag in the post permalink structure is one that could
  229. * also match a page name (e.g. %postname% or %author%) then this flag is
  230. * set to true. Prior to WordPress 3.3 this flag indicated that every page
  231. * would have a set of rules added to the top of the rewrite rules array.
  232. * Now it tells WP::parse_request() to check if a URL matching the page
  233. * permastruct is actually a page before accepting it.
  234. *
  235. * @since 2.5.0
  236. * @var bool
  237. *
  238. * @see WP_Rewrite::init()
  239. */
  240. public $use_verbose_page_rules = true;
  241. /**
  242. * Rewrite tags that can be used in permalink structures.
  243. *
  244. * These are translated into the regular expressions stored in
  245. * `WP_Rewrite::$rewritereplace` and are rewritten to the query
  246. * variables listed in WP_Rewrite::$queryreplace.
  247. *
  248. * Additional tags can be added with add_rewrite_tag().
  249. *
  250. * @since 1.5.0
  251. * @var string[]
  252. */
  253. public $rewritecode = array(
  254. '%year%',
  255. '%monthnum%',
  256. '%day%',
  257. '%hour%',
  258. '%minute%',
  259. '%second%',
  260. '%postname%',
  261. '%post_id%',
  262. '%author%',
  263. '%pagename%',
  264. '%search%',
  265. );
  266. /**
  267. * Regular expressions to be substituted into rewrite rules in place
  268. * of rewrite tags, see WP_Rewrite::$rewritecode.
  269. *
  270. * @since 1.5.0
  271. * @var string[]
  272. */
  273. public $rewritereplace = array(
  274. '([0-9]{4})',
  275. '([0-9]{1,2})',
  276. '([0-9]{1,2})',
  277. '([0-9]{1,2})',
  278. '([0-9]{1,2})',
  279. '([0-9]{1,2})',
  280. '([^/]+)',
  281. '([0-9]+)',
  282. '([^/]+)',
  283. '([^/]+?)',
  284. '(.+)',
  285. );
  286. /**
  287. * Query variables that rewrite tags map to, see WP_Rewrite::$rewritecode.
  288. *
  289. * @since 1.5.0
  290. * @var string[]
  291. */
  292. public $queryreplace = array(
  293. 'year=',
  294. 'monthnum=',
  295. 'day=',
  296. 'hour=',
  297. 'minute=',
  298. 'second=',
  299. 'name=',
  300. 'p=',
  301. 'author_name=',
  302. 'pagename=',
  303. 's=',
  304. );
  305. /**
  306. * Supported default feeds.
  307. *
  308. * @since 1.5.0
  309. * @var string[]
  310. */
  311. public $feeds = array( 'feed', 'rdf', 'rss', 'rss2', 'atom' );
  312. /**
  313. * Determines whether permalinks are being used.
  314. *
  315. * This can be either rewrite module or permalink in the HTTP query string.
  316. *
  317. * @since 1.5.0
  318. *
  319. * @return bool True, if permalinks are enabled.
  320. */
  321. public function using_permalinks() {
  322. return ! empty( $this->permalink_structure );
  323. }
  324. /**
  325. * Determines whether permalinks are being used and rewrite module is not enabled.
  326. *
  327. * Means that permalink links are enabled and index.php is in the URL.
  328. *
  329. * @since 1.5.0
  330. *
  331. * @return bool Whether permalink links are enabled and index.php is in the URL.
  332. */
  333. public function using_index_permalinks() {
  334. if ( empty( $this->permalink_structure ) ) {
  335. return false;
  336. }
  337. // If the index is not in the permalink, we're using mod_rewrite.
  338. return preg_match( '#^/*' . $this->index . '#', $this->permalink_structure );
  339. }
  340. /**
  341. * Determines whether permalinks are being used and rewrite module is enabled.
  342. *
  343. * Using permalinks and index.php is not in the URL.
  344. *
  345. * @since 1.5.0
  346. *
  347. * @return bool Whether permalink links are enabled and index.php is NOT in the URL.
  348. */
  349. public function using_mod_rewrite_permalinks() {
  350. return $this->using_permalinks() && ! $this->using_index_permalinks();
  351. }
  352. /**
  353. * Indexes for matches for usage in preg_*() functions.
  354. *
  355. * The format of the string is, with empty matches property value, '$NUM'.
  356. * The 'NUM' will be replaced with the value in the $number parameter. With
  357. * the matches property not empty, the value of the returned string will
  358. * contain that value of the matches property. The format then will be
  359. * '$MATCHES[NUM]', with MATCHES as the value in the property and NUM the
  360. * value of the $number parameter.
  361. *
  362. * @since 1.5.0
  363. *
  364. * @param int $number Index number.
  365. * @return string
  366. */
  367. public function preg_index( $number ) {
  368. $match_prefix = '$';
  369. $match_suffix = '';
  370. if ( ! empty( $this->matches ) ) {
  371. $match_prefix = '$' . $this->matches . '[';
  372. $match_suffix = ']';
  373. }
  374. return "$match_prefix$number$match_suffix";
  375. }
  376. /**
  377. * Retrieves all page and attachments for pages URIs.
  378. *
  379. * The attachments are for those that have pages as parents and will be
  380. * retrieved.
  381. *
  382. * @since 2.5.0
  383. *
  384. * @global wpdb $wpdb WordPress database abstraction object.
  385. *
  386. * @return array Array of page URIs as first element and attachment URIs as second element.
  387. */
  388. public function page_uri_index() {
  389. global $wpdb;
  390. // Get pages in order of hierarchy, i.e. children after parents.
  391. $pages = $wpdb->get_results( "SELECT ID, post_name, post_parent FROM $wpdb->posts WHERE post_type = 'page' AND post_status != 'auto-draft'" );
  392. $posts = get_page_hierarchy( $pages );
  393. // If we have no pages get out quick.
  394. if ( ! $posts ) {
  395. return array( array(), array() );
  396. }
  397. // Now reverse it, because we need parents after children for rewrite rules to work properly.
  398. $posts = array_reverse( $posts, true );
  399. $page_uris = array();
  400. $page_attachment_uris = array();
  401. foreach ( $posts as $id => $post ) {
  402. // URL => page name.
  403. $uri = get_page_uri( $id );
  404. $attachments = $wpdb->get_results( $wpdb->prepare( "SELECT ID, post_name, post_parent FROM $wpdb->posts WHERE post_type = 'attachment' AND post_parent = %d", $id ) );
  405. if ( ! empty( $attachments ) ) {
  406. foreach ( $attachments as $attachment ) {
  407. $attach_uri = get_page_uri( $attachment->ID );
  408. $page_attachment_uris[ $attach_uri ] = $attachment->ID;
  409. }
  410. }
  411. $page_uris[ $uri ] = $id;
  412. }
  413. return array( $page_uris, $page_attachment_uris );
  414. }
  415. /**
  416. * Retrieves all of the rewrite rules for pages.
  417. *
  418. * @since 1.5.0
  419. *
  420. * @return string[] Page rewrite rules.
  421. */
  422. public function page_rewrite_rules() {
  423. // The extra .? at the beginning prevents clashes with other regular expressions in the rules array.
  424. $this->add_rewrite_tag( '%pagename%', '(.?.+?)', 'pagename=' );
  425. return $this->generate_rewrite_rules( $this->get_page_permastruct(), EP_PAGES, true, true, false, false );
  426. }
  427. /**
  428. * Retrieves date permalink structure, with year, month, and day.
  429. *
  430. * The permalink structure for the date, if not set already depends on the
  431. * permalink structure. It can be one of three formats. The first is year,
  432. * month, day; the second is day, month, year; and the last format is month,
  433. * day, year. These are matched against the permalink structure for which
  434. * one is used. If none matches, then the default will be used, which is
  435. * year, month, day.
  436. *
  437. * Prevents post ID and date permalinks from overlapping. In the case of
  438. * post_id, the date permalink will be prepended with front permalink with
  439. * 'date/' before the actual permalink to form the complete date permalink
  440. * structure.
  441. *
  442. * @since 1.5.0
  443. *
  444. * @return string|false Date permalink structure on success, false on failure.
  445. */
  446. public function get_date_permastruct() {
  447. if ( isset( $this->date_structure ) ) {
  448. return $this->date_structure;
  449. }
  450. if ( empty( $this->permalink_structure ) ) {
  451. $this->date_structure = '';
  452. return false;
  453. }
  454. // The date permalink must have year, month, and day separated by slashes.
  455. $endians = array( '%year%/%monthnum%/%day%', '%day%/%monthnum%/%year%', '%monthnum%/%day%/%year%' );
  456. $this->date_structure = '';
  457. $date_endian = '';
  458. foreach ( $endians as $endian ) {
  459. if ( false !== strpos( $this->permalink_structure, $endian ) ) {
  460. $date_endian = $endian;
  461. break;
  462. }
  463. }
  464. if ( empty( $date_endian ) ) {
  465. $date_endian = '%year%/%monthnum%/%day%';
  466. }
  467. /*
  468. * Do not allow the date tags and %post_id% to overlap in the permalink
  469. * structure. If they do, move the date tags to $front/date/.
  470. */
  471. $front = $this->front;
  472. preg_match_all( '/%.+?%/', $this->permalink_structure, $tokens );
  473. $tok_index = 1;
  474. foreach ( (array) $tokens[0] as $token ) {
  475. if ( '%post_id%' === $token && ( $tok_index <= 3 ) ) {
  476. $front = $front . 'date/';
  477. break;
  478. }
  479. $tok_index++;
  480. }
  481. $this->date_structure = $front . $date_endian;
  482. return $this->date_structure;
  483. }
  484. /**
  485. * Retrieves the year permalink structure without month and day.
  486. *
  487. * Gets the date permalink structure and strips out the month and day
  488. * permalink structures.
  489. *
  490. * @since 1.5.0
  491. *
  492. * @return string|false Year permalink structure on success, false on failure.
  493. */
  494. public function get_year_permastruct() {
  495. $structure = $this->get_date_permastruct();
  496. if ( empty( $structure ) ) {
  497. return false;
  498. }
  499. $structure = str_replace( '%monthnum%', '', $structure );
  500. $structure = str_replace( '%day%', '', $structure );
  501. $structure = preg_replace( '#/+#', '/', $structure );
  502. return $structure;
  503. }
  504. /**
  505. * Retrieves the month permalink structure without day and with year.
  506. *
  507. * Gets the date permalink structure and strips out the day permalink
  508. * structures. Keeps the year permalink structure.
  509. *
  510. * @since 1.5.0
  511. *
  512. * @return string|false Year/Month permalink structure on success, false on failure.
  513. */
  514. public function get_month_permastruct() {
  515. $structure = $this->get_date_permastruct();
  516. if ( empty( $structure ) ) {
  517. return false;
  518. }
  519. $structure = str_replace( '%day%', '', $structure );
  520. $structure = preg_replace( '#/+#', '/', $structure );
  521. return $structure;
  522. }
  523. /**
  524. * Retrieves the day permalink structure with month and year.
  525. *
  526. * Keeps date permalink structure with all year, month, and day.
  527. *
  528. * @since 1.5.0
  529. *
  530. * @return string|false Year/Month/Day permalink structure on success, false on failure.
  531. */
  532. public function get_day_permastruct() {
  533. return $this->get_date_permastruct();
  534. }
  535. /**
  536. * Retrieves the permalink structure for categories.
  537. *
  538. * If the category_base property has no value, then the category structure
  539. * will have the front property value, followed by 'category', and finally
  540. * '%category%'. If it does, then the root property will be used, along with
  541. * the category_base property value.
  542. *
  543. * @since 1.5.0
  544. *
  545. * @return string|false Category permalink structure on success, false on failure.
  546. */
  547. public function get_category_permastruct() {
  548. return $this->get_extra_permastruct( 'category' );
  549. }
  550. /**
  551. * Retrieve the permalink structure for tags.
  552. *
  553. * If the tag_base property has no value, then the tag structure will have
  554. * the front property value, followed by 'tag', and finally '%tag%'. If it
  555. * does, then the root property will be used, along with the tag_base
  556. * property value.
  557. *
  558. * @since 2.3.0
  559. *
  560. * @return string|false Tag permalink structure on success, false on failure.
  561. */
  562. public function get_tag_permastruct() {
  563. return $this->get_extra_permastruct( 'post_tag' );
  564. }
  565. /**
  566. * Retrieves an extra permalink structure by name.
  567. *
  568. * @since 2.5.0
  569. *
  570. * @param string $name Permalink structure name.
  571. * @return string|false Permalink structure string on success, false on failure.
  572. */
  573. public function get_extra_permastruct( $name ) {
  574. if ( empty( $this->permalink_structure ) ) {
  575. return false;
  576. }
  577. if ( isset( $this->extra_permastructs[ $name ] ) ) {
  578. return $this->extra_permastructs[ $name ]['struct'];
  579. }
  580. return false;
  581. }
  582. /**
  583. * Retrieves the author permalink structure.
  584. *
  585. * The permalink structure is front property, author base, and finally
  586. * '/%author%'. Will set the author_structure property and then return it
  587. * without attempting to set the value again.
  588. *
  589. * @since 1.5.0
  590. *
  591. * @return string|false Author permalink structure on success, false on failure.
  592. */
  593. public function get_author_permastruct() {
  594. if ( isset( $this->author_structure ) ) {
  595. return $this->author_structure;
  596. }
  597. if ( empty( $this->permalink_structure ) ) {
  598. $this->author_structure = '';
  599. return false;
  600. }
  601. $this->author_structure = $this->front . $this->author_base . '/%author%';
  602. return $this->author_structure;
  603. }
  604. /**
  605. * Retrieves the search permalink structure.
  606. *
  607. * The permalink structure is root property, search base, and finally
  608. * '/%search%'. Will set the search_structure property and then return it
  609. * without attempting to set the value again.
  610. *
  611. * @since 1.5.0
  612. *
  613. * @return string|false Search permalink structure on success, false on failure.
  614. */
  615. public function get_search_permastruct() {
  616. if ( isset( $this->search_structure ) ) {
  617. return $this->search_structure;
  618. }
  619. if ( empty( $this->permalink_structure ) ) {
  620. $this->search_structure = '';
  621. return false;
  622. }
  623. $this->search_structure = $this->root . $this->search_base . '/%search%';
  624. return $this->search_structure;
  625. }
  626. /**
  627. * Retrieves the page permalink structure.
  628. *
  629. * The permalink structure is root property, and '%pagename%'. Will set the
  630. * page_structure property and then return it without attempting to set the
  631. * value again.
  632. *
  633. * @since 1.5.0
  634. *
  635. * @return string|false Page permalink structure on success, false on failure.
  636. */
  637. public function get_page_permastruct() {
  638. if ( isset( $this->page_structure ) ) {
  639. return $this->page_structure;
  640. }
  641. if ( empty( $this->permalink_structure ) ) {
  642. $this->page_structure = '';
  643. return false;
  644. }
  645. $this->page_structure = $this->root . '%pagename%';
  646. return $this->page_structure;
  647. }
  648. /**
  649. * Retrieves the feed permalink structure.
  650. *
  651. * The permalink structure is root property, feed base, and finally
  652. * '/%feed%'. Will set the feed_structure property and then return it
  653. * without attempting to set the value again.
  654. *
  655. * @since 1.5.0
  656. *
  657. * @return string|false Feed permalink structure on success, false on failure.
  658. */
  659. public function get_feed_permastruct() {
  660. if ( isset( $this->feed_structure ) ) {
  661. return $this->feed_structure;
  662. }
  663. if ( empty( $this->permalink_structure ) ) {
  664. $this->feed_structure = '';
  665. return false;
  666. }
  667. $this->feed_structure = $this->root . $this->feed_base . '/%feed%';
  668. return $this->feed_structure;
  669. }
  670. /**
  671. * Retrieves the comment feed permalink structure.
  672. *
  673. * The permalink structure is root property, comment base property, feed
  674. * base and finally '/%feed%'. Will set the comment_feed_structure property
  675. * and then return it without attempting to set the value again.
  676. *
  677. * @since 1.5.0
  678. *
  679. * @return string|false Comment feed permalink structure on success, false on failure.
  680. */
  681. public function get_comment_feed_permastruct() {
  682. if ( isset( $this->comment_feed_structure ) ) {
  683. return $this->comment_feed_structure;
  684. }
  685. if ( empty( $this->permalink_structure ) ) {
  686. $this->comment_feed_structure = '';
  687. return false;
  688. }
  689. $this->comment_feed_structure = $this->root . $this->comments_base . '/' . $this->feed_base . '/%feed%';
  690. return $this->comment_feed_structure;
  691. }
  692. /**
  693. * Adds or updates existing rewrite tags (e.g. %postname%).
  694. *
  695. * If the tag already exists, replace the existing pattern and query for
  696. * that tag, otherwise add the new tag.
  697. *
  698. * @since 1.5.0
  699. *
  700. * @see WP_Rewrite::$rewritecode
  701. * @see WP_Rewrite::$rewritereplace
  702. * @see WP_Rewrite::$queryreplace
  703. *
  704. * @param string $tag Name of the rewrite tag to add or update.
  705. * @param string $regex Regular expression to substitute the tag for in rewrite rules.
  706. * @param string $query String to append to the rewritten query. Must end in '='.
  707. */
  708. public function add_rewrite_tag( $tag, $regex, $query ) {
  709. $position = array_search( $tag, $this->rewritecode, true );
  710. if ( false !== $position && null !== $position ) {
  711. $this->rewritereplace[ $position ] = $regex;
  712. $this->queryreplace[ $position ] = $query;
  713. } else {
  714. $this->rewritecode[] = $tag;
  715. $this->rewritereplace[] = $regex;
  716. $this->queryreplace[] = $query;
  717. }
  718. }
  719. /**
  720. * Removes an existing rewrite tag.
  721. *
  722. * @since 4.5.0
  723. *
  724. * @see WP_Rewrite::$rewritecode
  725. * @see WP_Rewrite::$rewritereplace
  726. * @see WP_Rewrite::$queryreplace
  727. *
  728. * @param string $tag Name of the rewrite tag to remove.
  729. */
  730. public function remove_rewrite_tag( $tag ) {
  731. $position = array_search( $tag, $this->rewritecode, true );
  732. if ( false !== $position && null !== $position ) {
  733. unset( $this->rewritecode[ $position ] );
  734. unset( $this->rewritereplace[ $position ] );
  735. unset( $this->queryreplace[ $position ] );
  736. }
  737. }
  738. /**
  739. * Generates rewrite rules from a permalink structure.
  740. *
  741. * The main WP_Rewrite function for building the rewrite rule list. The
  742. * contents of the function is a mix of black magic and regular expressions,
  743. * so best just ignore the contents and move to the parameters.
  744. *
  745. * @since 1.5.0
  746. *
  747. * @param string $permalink_structure The permalink structure.
  748. * @param int $ep_mask Optional. Endpoint mask defining what endpoints are added to the structure.
  749. * Accepts a mask of:
  750. * - `EP_ALL`
  751. * - `EP_NONE`
  752. * - `EP_ALL_ARCHIVES`
  753. * - `EP_ATTACHMENT`
  754. * - `EP_AUTHORS`
  755. * - `EP_CATEGORIES`
  756. * - `EP_COMMENTS`
  757. * - `EP_DATE`
  758. * - `EP_DAY`
  759. * - `EP_MONTH`
  760. * - `EP_PAGES`
  761. * - `EP_PERMALINK`
  762. * - `EP_ROOT`
  763. * - `EP_SEARCH`
  764. * - `EP_TAGS`
  765. * - `EP_YEAR`
  766. * Default `EP_NONE`.
  767. * @param bool $paged Optional. Whether archive pagination rules should be added for the structure.
  768. * Default true.
  769. * @param bool $feed Optional Whether feed rewrite rules should be added for the structure.
  770. * Default true.
  771. * @param bool $forcomments Optional. Whether the feed rules should be a query for a comments feed.
  772. * Default false.
  773. * @param bool $walk_dirs Optional. Whether the 'directories' making up the structure should be walked
  774. * over and rewrite rules built for each in-turn. Default true.
  775. * @param bool $endpoints Optional. Whether endpoints should be applied to the generated rewrite rules.
  776. * Default true.
  777. * @return string[] Array of rewrite rules keyed by their regex pattern.
  778. */
  779. public function generate_rewrite_rules( $permalink_structure, $ep_mask = EP_NONE, $paged = true, $feed = true, $forcomments = false, $walk_dirs = true, $endpoints = true ) {
  780. // Build a regex to match the feed section of URLs, something like (feed|atom|rss|rss2)/?
  781. $feedregex2 = '';
  782. foreach ( (array) $this->feeds as $feed_name ) {
  783. $feedregex2 .= $feed_name . '|';
  784. }
  785. $feedregex2 = '(' . trim( $feedregex2, '|' ) . ')/?$';
  786. /*
  787. * $feedregex is identical but with /feed/ added on as well, so URLs like <permalink>/feed/atom
  788. * and <permalink>/atom are both possible
  789. */
  790. $feedregex = $this->feed_base . '/' . $feedregex2;
  791. // Build a regex to match the trackback and page/xx parts of URLs.
  792. $trackbackregex = 'trackback/?$';
  793. $pageregex = $this->pagination_base . '/?([0-9]{1,})/?$';
  794. $commentregex = $this->comments_pagination_base . '-([0-9]{1,})/?$';
  795. $embedregex = 'embed/?$';
  796. // Build up an array of endpoint regexes to append => queries to append.
  797. if ( $endpoints ) {
  798. $ep_query_append = array();
  799. foreach ( (array) $this->endpoints as $endpoint ) {
  800. // Match everything after the endpoint name, but allow for nothing to appear there.
  801. $epmatch = $endpoint[1] . '(/(.*))?/?$';
  802. // This will be appended on to the rest of the query for each dir.
  803. $epquery = '&' . $endpoint[2] . '=';
  804. $ep_query_append[ $epmatch ] = array( $endpoint[0], $epquery );
  805. }
  806. }
  807. // Get everything up to the first rewrite tag.
  808. $front = substr( $permalink_structure, 0, strpos( $permalink_structure, '%' ) );
  809. // Build an array of the tags (note that said array ends up being in $tokens[0]).
  810. preg_match_all( '/%.+?%/', $permalink_structure, $tokens );
  811. $num_tokens = count( $tokens[0] );
  812. $index = $this->index; // Probably 'index.php'.
  813. $feedindex = $index;
  814. $trackbackindex = $index;
  815. $embedindex = $index;
  816. /*
  817. * Build a list from the rewritecode and queryreplace arrays, that will look something
  818. * like tagname=$matches[i] where i is the current $i.
  819. */
  820. $queries = array();
  821. for ( $i = 0; $i < $num_tokens; ++$i ) {
  822. if ( 0 < $i ) {
  823. $queries[ $i ] = $queries[ $i - 1 ] . '&';
  824. } else {
  825. $queries[ $i ] = '';
  826. }
  827. $query_token = str_replace( $this->rewritecode, $this->queryreplace, $tokens[0][ $i ] ) . $this->preg_index( $i + 1 );
  828. $queries[ $i ] .= $query_token;
  829. }
  830. // Get the structure, minus any cruft (stuff that isn't tags) at the front.
  831. $structure = $permalink_structure;
  832. if ( '/' !== $front ) {
  833. $structure = str_replace( $front, '', $structure );
  834. }
  835. /*
  836. * Create a list of dirs to walk over, making rewrite rules for each level
  837. * so for example, a $structure of /%year%/%monthnum%/%postname% would create
  838. * rewrite rules for /%year%/, /%year%/%monthnum%/ and /%year%/%monthnum%/%postname%
  839. */
  840. $structure = trim( $structure, '/' );
  841. $dirs = $walk_dirs ? explode( '/', $structure ) : array( $structure );
  842. $num_dirs = count( $dirs );
  843. // Strip slashes from the front of $front.
  844. $front = preg_replace( '|^/+|', '', $front );
  845. // The main workhorse loop.
  846. $post_rewrite = array();
  847. $struct = $front;
  848. for ( $j = 0; $j < $num_dirs; ++$j ) {
  849. // Get the struct for this dir, and trim slashes off the front.
  850. $struct .= $dirs[ $j ] . '/'; // Accumulate. see comment near explode('/', $structure) above.
  851. $struct = ltrim( $struct, '/' );
  852. // Replace tags with regexes.
  853. $match = str_replace( $this->rewritecode, $this->rewritereplace, $struct );
  854. // Make a list of tags, and store how many there are in $num_toks.
  855. $num_toks = preg_match_all( '/%.+?%/', $struct, $toks );
  856. // Get the 'tagname=$matches[i]'.
  857. $query = ( ! empty( $num_toks ) && isset( $queries[ $num_toks - 1 ] ) ) ? $queries[ $num_toks - 1 ] : '';
  858. // Set up $ep_mask_specific which is used to match more specific URL types.
  859. switch ( $dirs[ $j ] ) {
  860. case '%year%':
  861. $ep_mask_specific = EP_YEAR;
  862. break;
  863. case '%monthnum%':
  864. $ep_mask_specific = EP_MONTH;
  865. break;
  866. case '%day%':
  867. $ep_mask_specific = EP_DAY;
  868. break;
  869. default:
  870. $ep_mask_specific = EP_NONE;
  871. }
  872. // Create query for /page/xx.
  873. $pagematch = $match . $pageregex;
  874. $pagequery = $index . '?' . $query . '&paged=' . $this->preg_index( $num_toks + 1 );
  875. // Create query for /comment-page-xx.
  876. $commentmatch = $match . $commentregex;
  877. $commentquery = $index . '?' . $query . '&cpage=' . $this->preg_index( $num_toks + 1 );
  878. if ( get_option( 'page_on_front' ) ) {
  879. // Create query for Root /comment-page-xx.
  880. $rootcommentmatch = $match . $commentregex;
  881. $rootcommentquery = $index . '?' . $query . '&page_id=' . get_option( 'page_on_front' ) . '&cpage=' . $this->preg_index( $num_toks + 1 );
  882. }
  883. // Create query for /feed/(feed|atom|rss|rss2|rdf).
  884. $feedmatch = $match . $feedregex;
  885. $feedquery = $feedindex . '?' . $query . '&feed=' . $this->preg_index( $num_toks + 1 );
  886. // Create query for /(feed|atom|rss|rss2|rdf) (see comment near creation of $feedregex).
  887. $feedmatch2 = $match . $feedregex2;
  888. $feedquery2 = $feedindex . '?' . $query . '&feed=' . $this->preg_index( $num_toks + 1 );
  889. // Create query and regex for embeds.
  890. $embedmatch = $match . $embedregex;
  891. $embedquery = $embedindex . '?' . $query . '&embed=true';
  892. // If asked to, turn the feed queries into comment feed ones.
  893. if ( $forcomments ) {
  894. $feedquery .= '&withcomments=1';
  895. $feedquery2 .= '&withcomments=1';
  896. }
  897. // Start creating the array of rewrites for this dir.
  898. $rewrite = array();
  899. // ...adding on /feed/ regexes => queries.
  900. if ( $feed ) {
  901. $rewrite = array(
  902. $feedmatch => $feedquery,
  903. $feedmatch2 => $feedquery2,
  904. $embedmatch => $embedquery,
  905. );
  906. }
  907. // ...and /page/xx ones.
  908. if ( $paged ) {
  909. $rewrite = array_merge( $rewrite, array( $pagematch => $pagequery ) );
  910. }
  911. // Only on pages with comments add ../comment-page-xx/.
  912. if ( EP_PAGES & $ep_mask || EP_PERMALINK & $ep_mask ) {
  913. $rewrite = array_merge( $rewrite, array( $commentmatch => $commentquery ) );
  914. } elseif ( EP_ROOT & $ep_mask && get_option( 'page_on_front' ) ) {
  915. $rewrite = array_merge( $rewrite, array( $rootcommentmatch => $rootcommentquery ) );
  916. }
  917. // Do endpoints.
  918. if ( $endpoints ) {
  919. foreach ( (array) $ep_query_append as $regex => $ep ) {
  920. // Add the endpoints on if the mask fits.
  921. if ( $ep[0] & $ep_mask || $ep[0] & $ep_mask_specific ) {
  922. $rewrite[ $match . $regex ] = $index . '?' . $query . $ep[1] . $this->preg_index( $num_toks + 2 );
  923. }
  924. }
  925. }
  926. // If we've got some tags in this dir.
  927. if ( $num_toks ) {
  928. $post = false;
  929. $page = false;
  930. /*
  931. * Check to see if this dir is permalink-level: i.e. the structure specifies an
  932. * individual post. Do this by checking it contains at least one of 1) post name,
  933. * 2) post ID, 3) page name, 4) timestamp (year, month, day, hour, second and
  934. * minute all present). Set these flags now as we need them for the endpoints.
  935. */
  936. if ( strpos( $struct, '%postname%' ) !== false
  937. || strpos( $struct, '%post_id%' ) !== false
  938. || strpos( $struct, '%pagename%' ) !== false
  939. || ( strpos( $struct, '%year%' ) !== false && strpos( $struct, '%monthnum%' ) !== false && strpos( $struct, '%day%' ) !== false && strpos( $struct, '%hour%' ) !== false && strpos( $struct, '%minute%' ) !== false && strpos( $struct, '%second%' ) !== false )
  940. ) {
  941. $post = true;
  942. if ( strpos( $struct, '%pagename%' ) !== false ) {
  943. $page = true;
  944. }
  945. }
  946. if ( ! $post ) {
  947. // For custom post types, we need to add on endpoints as well.
  948. foreach ( get_post_types( array( '_builtin' => false ) ) as $ptype ) {
  949. if ( strpos( $struct, "%$ptype%" ) !== false ) {
  950. $post = true;
  951. // This is for page style attachment URLs.
  952. $page = is_post_type_hierarchical( $ptype );
  953. break;
  954. }
  955. }
  956. }
  957. // If creating rules for a permalink, do all the endpoints like attachments etc.
  958. if ( $post ) {
  959. // Create query and regex for trackback.
  960. $trackbackmatch = $match . $trackbackregex;
  961. $trackbackquery = $trackbackindex . '?' . $query . '&tb=1';
  962. // Create query and regex for embeds.
  963. $embedmatch = $match . $embedregex;
  964. $embedquery = $embedindex . '?' . $query . '&embed=true';
  965. // Trim slashes from the end of the regex for this dir.
  966. $match = rtrim( $match, '/' );
  967. // Get rid of brackets.
  968. $submatchbase = str_replace( array( '(', ')' ), '', $match );
  969. // Add a rule for at attachments, which take the form of <permalink>/some-text.
  970. $sub1 = $submatchbase . '/([^/]+)/';
  971. // Add trackback regex <permalink>/trackback/...
  972. $sub1tb = $sub1 . $trackbackregex;
  973. // And <permalink>/feed/(atom|...)
  974. $sub1feed = $sub1 . $feedregex;
  975. // And <permalink>/(feed|atom...)
  976. $sub1feed2 = $sub1 . $feedregex2;
  977. // And <permalink>/comment-page-xx
  978. $sub1comment = $sub1 . $commentregex;
  979. // And <permalink>/embed/...
  980. $sub1embed = $sub1 . $embedregex;
  981. /*
  982. * Add another rule to match attachments in the explicit form:
  983. * <permalink>/attachment/some-text
  984. */
  985. $sub2 = $submatchbase . '/attachment/([^/]+)/';
  986. // And add trackbacks <permalink>/attachment/trackback.
  987. $sub2tb = $sub2 . $trackbackregex;
  988. // Feeds, <permalink>/attachment/feed/(atom|...)
  989. $sub2feed = $sub2 . $feedregex;
  990. // And feeds again on to this <permalink>/attachment/(feed|atom...)
  991. $sub2feed2 = $sub2 . $feedregex2;
  992. // And <permalink>/comment-page-xx
  993. $sub2comment = $sub2 . $commentregex;
  994. // And <permalink>/embed/...
  995. $sub2embed = $sub2 . $embedregex;
  996. // Create queries for these extra tag-ons we've just dealt with.
  997. $subquery = $index . '?attachment=' . $this->preg_index( 1 );
  998. $subtbquery = $subquery . '&tb=1';
  999. $subfeedquery = $subquery . '&feed=' . $this->preg_index( 2 );
  1000. $subcommentquery = $subquery . '&cpage=' . $this->preg_index( 2 );
  1001. $subembedquery = $subquery . '&embed=true';
  1002. // Do endpoints for attachments.
  1003. if ( ! empty( $endpoints ) ) {
  1004. foreach ( (array) $ep_query_append as $regex => $ep ) {
  1005. if ( $ep[0] & EP_ATTACHMENT ) {
  1006. $rewrite[ $sub1 . $regex ] = $subquery . $ep[1] . $this->preg_index( 3 );
  1007. $rewrite[ $sub2 . $regex ] = $subquery . $ep[1] . $this->preg_index( 3 );
  1008. }
  1009. }
  1010. }
  1011. /*
  1012. * Now we've finished with endpoints, finish off the $sub1 and $sub2 matches
  1013. * add a ? as we don't have to match that last slash, and finally a $ so we
  1014. * match to the end of the URL
  1015. */
  1016. $sub1 .= '?$';
  1017. $sub2 .= '?$';
  1018. /*
  1019. * Post pagination, e.g. <permalink>/2/
  1020. * Previously: '(/[0-9]+)?/?$', which produced '/2' for page.
  1021. * When cast to int, returned 0.
  1022. */
  1023. $match = $match . '(?:/([0-9]+))?/?$';
  1024. $query = $index . '?' . $query . '&page=' . $this->preg_index( $num_toks + 1 );
  1025. // Not matching a permalink so this is a lot simpler.
  1026. } else {
  1027. // Close the match and finalize the query.
  1028. $match .= '?$';
  1029. $query = $index . '?' . $query;
  1030. }
  1031. /*
  1032. * Create the final array for this dir by joining the $rewrite array (which currently
  1033. * only contains rules/queries for trackback, pages etc) to the main regex/query for
  1034. * this dir
  1035. */
  1036. $rewrite = array_merge( $rewrite, array( $match => $query ) );
  1037. // If we're matching a permalink, add those extras (attachments etc) on.
  1038. if ( $post ) {
  1039. // Add trackback.
  1040. $rewrite = array_merge( array( $trackbackmatch => $trackbackquery ), $rewrite );
  1041. // Add embed.
  1042. $rewrite = array_merge( array( $embedmatch => $embedquery ), $rewrite );
  1043. // Add regexes/queries for attachments, attachment trackbacks and so on.
  1044. if ( ! $page ) {
  1045. // Require <permalink>/attachment/stuff form for pages because of confusion with subpages.
  1046. $rewrite = array_merge(
  1047. $rewrite,
  1048. array(
  1049. $sub1 => $subquery,
  1050. $sub1tb => $subtbquery,
  1051. $sub1feed => $subfeedquery,
  1052. $sub1feed2 => $subfeedquery,
  1053. $sub1comment => $subcommentquery,
  1054. $sub1embed => $subembedquery,
  1055. )
  1056. );
  1057. }
  1058. $rewrite = array_merge(
  1059. array(
  1060. $sub2 => $subquery,
  1061. $sub2tb => $subtbquery,
  1062. $sub2feed => $subfeedquery,
  1063. $sub2feed2 => $subfeedquery,
  1064. $sub2comment => $subcommentquery,
  1065. $sub2embed => $subembedquery,
  1066. ),
  1067. $rewrite
  1068. );
  1069. }
  1070. }
  1071. // Add the rules for this dir to the accumulating $post_rewrite.
  1072. $post_rewrite = array_merge( $rewrite, $post_rewrite );
  1073. }
  1074. // The finished rules. phew!
  1075. return $post_rewrite;
  1076. }
  1077. /**
  1078. * Generates rewrite rules with permalink structure and walking directory only.
  1079. *
  1080. * Shorten version of WP_Rewrite::generate_rewrite_rules() that allows for shorter
  1081. * list of parameters. See the method for longer description of what generating
  1082. * rewrite rules does.
  1083. *
  1084. * @since 1.5.0
  1085. *
  1086. * @see WP_Rewrite::generate_rewrite_rules() See for long description and rest of parameters.
  1087. *
  1088. * @param string $permalink_structure The permalink structure to generate rules.
  1089. * @param bool $walk_dirs Optional. Whether to create list of directories to walk over.
  1090. * Default false.
  1091. * @return array
  1092. */
  1093. public function generate_rewrite_rule( $permalink_structure, $walk_dirs = false ) {
  1094. return $this->generate_rewrite_rules( $permalink_structure, EP_NONE, false, false, false, $walk_dirs );
  1095. }
  1096. /**
  1097. * Constructs rewrite matches and queries from permalink structure.
  1098. *
  1099. * Runs the action {@see 'generate_rewrite_rules'} with the parameter that is an
  1100. * reference to the current WP_Rewrite instance to further manipulate the
  1101. * permalink structures and rewrite rules. Runs the {@see 'rewrite_rules_array'}
  1102. * filter on the full rewrite rule array.
  1103. *
  1104. * There are two ways to manipulate the rewrite rules, one by hooking into
  1105. * the {@see 'generate_rewrite_rules'} action and gaining full control of the
  1106. * object or just manipulating the rewrite rule array before it is passed
  1107. * from the function.
  1108. *
  1109. * @since 1.5.0
  1110. *
  1111. * @return string[] An associative array of matches and queries.
  1112. */
  1113. public function rewrite_rules() {
  1114. $rewrite = array();
  1115. if ( empty( $this->permalink_structure ) ) {
  1116. return $rewrite;
  1117. }
  1118. // robots.txt -- only if installed at the root.
  1119. $home_path = parse_url( home_url() );
  1120. $robots_rewrite = ( empty( $home_path['path'] ) || '/' === $home_path['path'] ) ? array( 'robots\.txt$' => $this->index . '?robots=1' ) : array();
  1121. // favicon.ico -- only if installed at the root.
  1122. $favicon_rewrite = ( empty( $home_path['path'] ) || '/' === $home_path['path'] ) ? array( 'favicon\.ico$' => $this->index . '?favicon=1' ) : array();
  1123. // Old feed and service files.
  1124. $deprecated_files = array(
  1125. '.*wp-(atom|rdf|rss|rss2|feed|commentsrss2)\.php$' => $this->index . '?feed=old',
  1126. '.*wp-app\.php(/.*)?$' => $this->index . '?error=403',
  1127. );
  1128. // Registration rules.
  1129. $registration_pages = array();
  1130. if ( is_multisite() && is_main_site() ) {
  1131. $registration_pages['.*wp-signup.php$'] = $this->index . '?signup=true';
  1132. $registration_pages['.*wp-activate.php$'] = $this->index . '?activate=true';
  1133. }
  1134. // Deprecated.
  1135. $registration_pages['.*wp-register.php$'] = $this->index . '?register=true';
  1136. // Post rewrite rules.
  1137. $post_rewrite = $this->generate_rewrite_rules( $this->permalink_structure, EP_PERMALINK );
  1138. /**
  1139. * Filters rewrite rules used for "post" archives.
  1140. *
  1141. * @since 1.5.0
  1142. *
  1143. * @param string[] $post_rewrite Array of rewrite rules for posts, keyed by their regex pattern.
  1144. */
  1145. $post_rewrite = apply_filters( 'post_rewrite_rules', $post_rewrite );
  1146. // Date rewrite rules.
  1147. $date_rewrite = $this->generate_rewrite_rules( $this->get_date_permastruct(), EP_DATE );
  1148. /**
  1149. * Filters rewrite rules used for date archives.
  1150. *
  1151. * Likely date archives would include `/yyyy/`, `/yyyy/mm/`, and `/yyyy/mm/dd/`.
  1152. *
  1153. * @since 1.5.0
  1154. *
  1155. * @param string[] $date_rewrite Array of rewrite rules for date archives, keyed by their regex pattern.
  1156. */
  1157. $date_rewrite = apply_filters( 'date_rewrite_rules', $date_rewrite );
  1158. // Root-level rewrite rules.
  1159. $root_rewrite = $this->generate_rewrite_rules( $this->root . '/', EP_ROOT );
  1160. /**
  1161. * Filters rewrite rules used for root-level archives.
  1162. *
  1163. * Likely root-level archives would include pagination rules for the homepage
  1164. * as well as site-wide post feeds (e.g. `/feed/`, and `/feed/atom/`).
  1165. *
  1166. * @since 1.5.0
  1167. *
  1168. * @param string[] $root_rewrite Array of root-level rewrite rules, keyed by their regex pattern.
  1169. */
  1170. $root_rewrite = apply_filters( 'root_rewrite_rules', $root_rewrite );
  1171. // Comments rewrite rules.
  1172. $comments_rewrite = $this->generate_rewrite_rules( $this->root . $this->comments_base, EP_COMMENTS, false, true, true, false );
  1173. /**
  1174. * Filters rewrite rules used for comment feed archives.
  1175. *
  1176. * Likely comments feed archives include `/comments/feed/` and `/comments/feed/atom/`.
  1177. *
  1178. * @since 1.5.0
  1179. *
  1180. * @param string[] $comments_rewrite Array of rewrite rules for the site-wide comments feeds, keyed by their regex pattern.
  1181. */
  1182. $comments_rewrite = apply_filters( 'comments_rewrite_rules', $comments_rewrite );
  1183. // Search rewrite rules.
  1184. $search_structure = $this->get_search_permastruct();
  1185. $search_rewrite = $this->generate_rewrite_rules( $search_structure, EP_SEARCH );
  1186. /**
  1187. * Filters rewrite rules used for search archives.
  1188. *
  1189. * Likely search-related archives include `/search/search+query/` as well as
  1190. * pagination and feed paths for a search.
  1191. *
  1192. * @since 1.5.0
  1193. *
  1194. * @param string[] $search_rewrite Array of rewrite rules for search queries, keyed by their regex pattern.
  1195. */
  1196. $search_rewrite = apply_filters( 'search_rewrite_rules', $search_rewrite );
  1197. // Author rewrite rules.
  1198. $author_rewrite = $this->generate_rewrite_rules( $this->get_author_permastruct(), EP_AUTHORS );
  1199. /**
  1200. * Filters rewrite rules used for author archives.
  1201. *
  1202. * Likely author archives would include `/author/author-name/`, as well as
  1203. * pagination and feed paths for author archives.
  1204. *
  1205. * @since 1.5.0
  1206. *
  1207. * @param string[] $author_rewrite Array of rewrite rules for author archives, keyed by their regex pattern.
  1208. */
  1209. $author_rewrite = apply_filters( 'author_rewrite_rules', $author_rewrite );
  1210. // Pages rewrite rules.
  1211. $page_rewrite = $this->page_rewrite_rules();
  1212. /**
  1213. * Filters rewrite rules used for "page" post type archives.
  1214. *
  1215. * @since 1.5.0
  1216. *
  1217. * @param string[] $page_rewrite Array of rewrite rules for the "page" post type, keyed by their regex pattern.
  1218. */
  1219. $page_rewrite = apply_filters( 'page_rewrite_rules', $page_rewrite );
  1220. // Extra permastructs.
  1221. foreach ( $this->extra_permastructs as $permastructname => $struct ) {
  1222. if ( is_array( $struct ) ) {
  1223. if ( count( $struct ) == 2 ) {
  1224. $rules = $this->generate_rewrite_rules( $struct[0], $struct[1] );
  1225. } else {
  1226. $rules = $this->generate_rewrite_rules( $struct['struct'], $struct['ep_mask'], $struct['paged'], $struct['feed'], $struct['forcomments'], $struct['walk_dirs'], $struct['endpoints'] );
  1227. }
  1228. } else {
  1229. $rules = $this->generate_rewrite_rules( $struct );
  1230. }
  1231. /**
  1232. * Filters rewrite rules used for individual permastructs.
  1233. *
  1234. * The dynamic portion of the hook name, `$permastructname`, refers
  1235. * to the name of the registered permastruct.
  1236. *
  1237. * Possible hook names include:
  1238. *
  1239. * - `category_rewrite_rules`
  1240. * - `post_format_rewrite_rules`
  1241. * - `post_tag_rewrite_rules`
  1242. *
  1243. * @since 3.1.0
  1244. *
  1245. * @param string[] $rules Array of rewrite rules generated for the current permastruct, keyed by their regex pattern.
  1246. */
  1247. $rules = apply_filters( "{$permastructname}_rewrite_rules", $rules );
  1248. if ( 'post_tag' === $permastructname ) {
  1249. /**
  1250. * Filters rewrite rules used specifically for Tags.
  1251. *
  1252. * @since 2.3.0
  1253. * @deprecated 3.1.0 Use {@see 'post_tag_rewrite_rules'} instead.
  1254. *
  1255. * @param string[] $rules Array of rewrite rules generated for tags, keyed by their regex pattern.
  1256. */
  1257. $rules = apply_filters_deprecated( 'tag_rewrite_rules', array( $rules ), '3.1.0', 'post_tag_rewrite_rules' );
  1258. }
  1259. $this->extra_rules_top = array_merge( $this->extra_rules_top, $rules );
  1260. }
  1261. // Put them together.
  1262. if ( $this->use_verbose_page_rules ) {
  1263. $this->rules = array_merge( $this->extra_rules_top, $robots_rewrite, $favicon_rewrite, $deprecated_files, $registration_pages, $root_rewrite, $comments_rewrite, $search_rewrite, $author_rewrite, $date_rewrite, $page_rewrite, $post_rewrite, $this->extra_rules );
  1264. } else {
  1265. $this->rules = array_merge( $this->extra_rules_top, $robots_rewrite, $favicon_rewrite, $deprecated_files, $registration_pages, $root_rewrite, $comments_rewrite, $search_rewrite, $author_rewrite, $date_rewrite, $post_rewrite, $page_rewrite, $this->extra_rules );
  1266. }
  1267. /**
  1268. * Fires after the rewrite rules are generated.
  1269. *
  1270. * @since 1.5.0
  1271. *
  1272. * @param WP_Rewrite $wp_rewrite Current WP_Rewrite instance (passed by reference).
  1273. */
  1274. do_action_ref_array( 'generate_rewrite_rules', array( &$this ) );
  1275. /**
  1276. * Filters the full set of generated rewrite rules.
  1277. *
  1278. * @since 1.5.0
  1279. *
  1280. * @param string[] $rules The compiled array of rewrite rules, keyed by their regex pattern.
  1281. */
  1282. $this->rules = apply_filters( 'rewrite_rules_array', $this->rules );
  1283. return $this->rules;
  1284. }
  1285. /**
  1286. * Retrieves the rewrite rules.
  1287. *
  1288. * The difference between this method and WP_Rewrite::rewrite_rules() is that
  1289. * this method stores the rewrite rules in the 'rewrite_rules' option and retrieves
  1290. * it. This prevents having to process all of the permalinks to get the rewrite rules
  1291. * in the form of caching.
  1292. *
  1293. * @since 1.5.0
  1294. *
  1295. * @return string[] Array of rewrite rules keyed by their regex pattern.
  1296. */
  1297. public function wp_rewrite_rules() {
  1298. $this->rules = get_option( 'rewrite_rules' );
  1299. if ( empty( $this->rules ) ) {
  1300. $this->matches = 'matches';
  1301. $this->rewrite_rules();
  1302. if ( ! did_action( 'wp_loaded' ) ) {
  1303. add_action( 'wp_loaded', array( $this, 'flush_rules' ) );
  1304. return $this->rules;
  1305. }
  1306. update_option( 'rewrite_rules', $this->rules );
  1307. }
  1308. return $this->rules;
  1309. }
  1310. /**
  1311. * Retrieves mod_rewrite-formatted rewrite rules to write to .htaccess.
  1312. *
  1313. * Does not actually write to the .htaccess file, but creates the rules for
  1314. * the process that will.
  1315. *
  1316. * Will add the non_wp_rules property rules to the .htaccess file before
  1317. * the WordPress rewrite rules one.
  1318. *
  1319. * @since 1.5.0
  1320. *
  1321. * @return string
  1322. */
  1323. public function mod_rewrite_rules() {
  1324. if ( ! $this->using_permalinks() ) {
  1325. return '';
  1326. }
  1327. $site_root = parse_url( site_url() );
  1328. if ( isset( $site_root['path'] ) ) {
  1329. $site_root = trailingslashit( $site_root['path'] );
  1330. }
  1331. $home_root = parse_url( home_url() );
  1332. if ( isset( $home_root['path'] ) ) {
  1333. $home_root = trailingslashit( $home_root['path'] );
  1334. } else {
  1335. $home_root = '/';
  1336. }
  1337. $rules = "<IfModule mod_rewrite.c>\n";
  1338. $rules .= "RewriteEngine On\n";
  1339. $rules .= "RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]\n";
  1340. $rules .= "RewriteBase $home_root\n";
  1341. // Prevent -f checks on index.php.
  1342. $rules .= "RewriteRule ^index\.php$ - [L]\n";
  1343. // Add in the rules that don't redirect to WP's index.php (and thus shouldn't be handled by WP at all).
  1344. foreach ( (array) $this->non_wp_rules as $match => $query ) {
  1345. // Apache 1.3 does not support the reluctant (non-greedy) modifier.
  1346. $match = str_replace( '.+?', '.+', $match );
  1347. $rules .= 'RewriteRule ^' . $match . ' ' . $home_root . $query . " [QSA,L]\n";
  1348. }
  1349. if ( $this->use_verbose_rules ) {
  1350. $this->matches = '';
  1351. $rewrite = $this->rewrite_rules();
  1352. $num_rules = count( $rewrite );
  1353. $rules .= "RewriteCond %{REQUEST_FILENAME} -f [OR]\n" .
  1354. "RewriteCond %{REQUEST_FILENAME} -d\n" .
  1355. "RewriteRule ^.*$ - [S=$num_rules]\n";
  1356. foreach ( (array) $rewrite as $match => $query ) {
  1357. // Apache 1.3 does not support the reluctant (non-greedy) modifier.
  1358. $match = str_replace( '.+?', '.+', $match );
  1359. if ( strpos( $query, $this->index ) !== false ) {
  1360. $rules .= 'RewriteRule ^' . $match . ' ' . $home_root . $query . " [QSA,L]\n";
  1361. } else {
  1362. $rules .= 'RewriteRule ^' . $match . ' ' . $site_root . $query . " [QSA,L]\n";
  1363. }
  1364. }
  1365. } else {
  1366. $rules .= "RewriteCond %{REQUEST_FILENAME} !-f\n" .
  1367. "RewriteCond %{REQUEST_FILENAME} !-d\n" .
  1368. "RewriteRule . {$home_root}{$this->index} [L]\n";
  1369. }
  1370. $rules .= "</IfModule>\n";
  1371. /**
  1372. * Filters the list of rewrite rules formatted for output to an .htaccess file.
  1373. *
  1374. * @since 1.5.0
  1375. *
  1376. * @param string $rules mod_rewrite Rewrite rules formatted for .htaccess.
  1377. */
  1378. $rules = apply_filters( 'mod_rewrite_rules', $rules );
  1379. /**
  1380. * Filters the list of rewrite rules formatted for output to an .htaccess file.
  1381. *
  1382. * @since 1.5.0
  1383. * @deprecated 1.5.0 Use the {@see 'mod_rewrite_rules'} filter instead.
  1384. *
  1385. * @param string $rules mod_rewrite Rewrite rules formatted for .htaccess.
  1386. */
  1387. return apply_filters_deprecated( 'rewrite_rules', array( $rules ), '1.5.0', 'mod_rewrite_rules' );
  1388. }
  1389. /**
  1390. * Retrieves IIS7 URL Rewrite formatted rewrite rules to write to web.config file.
  1391. *
  1392. * Does not actually write to the web.config file, but creates the rules for
  1393. * the process that will.
  1394. *
  1395. * @since 2.8.0
  1396. *
  1397. * @param bool $add_parent_tags Optional. Whether to add parent tags to the rewrite rule sets.
  1398. * Default false.
  1399. * @return string IIS7 URL rewrite rule sets.
  1400. */
  1401. public function iis7_url_rewrite_rules( $add_parent_tags = false ) {
  1402. if ( ! $this->using_permalinks() ) {
  1403. return '';
  1404. }
  1405. $rules = '';
  1406. if ( $add_parent_tags ) {
  1407. $rules .= '<configuration>
  1408. <system.webServer>
  1409. <rewrite>
  1410. <rules>';
  1411. }
  1412. $rules .= '
  1413. <rule name="WordPress: ' . esc_attr( home_url() ) . '" patternSyntax="Wildcard">
  1414. <match url="*" />
  1415. <conditions>
  1416. <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
  1417. <add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
  1418. </conditions>
  1419. <action type="Rewrite" url="index.php" />
  1420. </rule>';
  1421. if ( $add_parent_tags ) {
  1422. $rules .= '
  1423. </rules>
  1424. </rewrite>
  1425. </system.webServer>
  1426. </configuration>';
  1427. }
  1428. /**
  1429. * Filters the list of rewrite rules formatted for output to a web.config.
  1430. *
  1431. * @since 2.8.0
  1432. *
  1433. * @param string $rules Rewrite rules formatted for IIS web.config.
  1434. */
  1435. return apply_filters( 'iis7_url_rewrite_rules', $rules );
  1436. }
  1437. /**
  1438. * Adds a rewrite rule that transforms a URL structure to a set of query vars.
  1439. *
  1440. * Any value in the $after parameter that isn't 'bottom' will result in the rule
  1441. * being placed at the top of the rewrite rules.
  1442. *
  1443. * @since 2.1.0
  1444. * @since 4.4.0 Array support was added to the `$query` parameter.
  1445. *
  1446. * @param string $regex Regular expression to match request against.
  1447. * @param string|array $query The corresponding query vars for this rewrite rule.
  1448. * @param string $after Optional. Priority of the new rule. Accepts 'top'
  1449. * or 'bottom'. Default 'bottom'.
  1450. */
  1451. public function add_rule( $regex, $query, $after = 'bottom' ) {
  1452. if ( is_array( $query ) ) {
  1453. $external = false;
  1454. $query = add_query_arg( $query, 'index.php' );
  1455. } else {
  1456. $index = false === strpos( $query, '?' ) ? strlen( $query ) : strpos( $query, '?' );
  1457. $front = substr( $query, 0, $index );
  1458. $external = $front != $this->index;
  1459. }
  1460. // "external" = it doesn't correspond to index.php.
  1461. if ( $external ) {
  1462. $this->add_external_rule( $regex, $query );
  1463. } else {
  1464. if ( 'bottom' === $after ) {
  1465. $this->extra_rules = array_merge( $this->extra_rules, array( $regex => $query ) );
  1466. } else {
  1467. $this->extra_rules_top = array_merge( $this->extra_rules_top, array( $regex => $query ) );
  1468. }
  1469. }
  1470. }
  1471. /**
  1472. * Adds a rewrite rule that doesn't correspond to index.php.
  1473. *
  1474. * @since 2.1.0
  1475. *
  1476. * @param string $regex Regular expression to match request against.
  1477. * @param string $query The corresponding query vars for this rewrite rule.
  1478. */
  1479. public function add_external_rule( $regex, $query ) {
  1480. $this->non_wp_rules[ $regex ] = $query;
  1481. }
  1482. /**
  1483. * Adds an endpoint, like /trackback/.
  1484. *
  1485. * @since 2.1.0
  1486. * @since 3.9.0 $query_var parameter added.
  1487. * @since 4.3.0 Added support for skipping query var registration by passing `false` to `$query_var`.
  1488. *
  1489. * @see add_rewrite_endpoint() for full documentation.
  1490. * @global WP $wp Current WordPress environment instance.
  1491. *
  1492. * @param string $name Name of the endpoint.
  1493. * @param int $places Endpoint mask describing the places the endpoint should be added.
  1494. * Accepts a mask of:
  1495. * - `EP_ALL`
  1496. * - `EP_NONE`
  1497. * - `EP_ALL_ARCHIVES`
  1498. * - `EP_ATTACHMENT`
  1499. * - `EP_AUTHORS`
  1500. * - `EP_CATEGORIES`
  1501. * - `EP_COMMENTS`
  1502. * - `EP_DATE`
  1503. * - `EP_DAY`
  1504. * - `EP_MONTH`
  1505. * - `EP_PAGES`
  1506. * - `EP_PERMALINK`
  1507. * - `EP_ROOT`
  1508. * - `EP_SEARCH`
  1509. * - `EP_TAGS`
  1510. * - `EP_YEAR`
  1511. * @param string|bool $query_var Optional. Name of the corresponding query variable. Pass `false` to
  1512. * skip registering a query_var for this endpoint. Defaults to the
  1513. * value of `$name`.
  1514. */
  1515. public function add_endpoint( $name, $places, $query_var = true ) {
  1516. global $wp;
  1517. // For backward compatibility, if null has explicitly been passed as `$query_var`, assume `true`.
  1518. if ( true === $query_var || null === $query_var ) {
  1519. $query_var = $name;
  1520. }
  1521. $this->endpoints[] = array( $places, $name, $query_var );
  1522. if ( $query_var ) {
  1523. $wp->add_query_var( $query_var );
  1524. }
  1525. }
  1526. /**
  1527. * Adds a new permalink structure.
  1528. *
  1529. * A permalink structure (permastruct) is an abstract definition of a set of rewrite rules;
  1530. * it is an easy way of expressing a set of regular expressions that rewrite to a set of
  1531. * query strings. The new permastruct is added to the WP_Rewrite::$extra_permastructs array.
  1532. *
  1533. * When the rewrite rules are built by WP_Rewrite::rewrite_rules(), all of these extra
  1534. * permastructs are passed to WP_Rewrite::generate_rewrite_rules() which transforms them
  1535. * into the regular expressions that many love to hate.
  1536. *
  1537. * The `$args` parameter gives you control over how WP_Rewrite::generate_rewrite_rules()
  1538. * works on the new permastruct.
  1539. *
  1540. * @since 2.5.0
  1541. *
  1542. * @param string $name Name for permalink structure.
  1543. * @param string $struct Permalink structure (e.g. category/%category%)
  1544. * @param array $args {
  1545. * Optional. Arguments for building rewrite rules based on the permalink structure.
  1546. * Default empty array.
  1547. *
  1548. * @type bool $with_front Whether the structure should be prepended with `WP_Rewrite::$front`.
  1549. * Default true.
  1550. * @type int $ep_mask The endpoint mask defining which endpoints are added to the structure.
  1551. * Accepts a mask of:
  1552. * - `EP_ALL`
  1553. * - `EP_NONE`
  1554. * - `EP_ALL_ARCHIVES`
  1555. * - `EP_ATTACHMENT`
  1556. * - `EP_AUTHORS`
  1557. * - `EP_CATEGORIES`
  1558. * - `EP_COMMENTS`
  1559. * - `EP_DATE`
  1560. * - `EP_DAY`
  1561. * - `EP_MONTH`
  1562. * - `EP_PAGES`
  1563. * - `EP_PERMALINK`
  1564. * - `EP_ROOT`
  1565. * - `EP_SEARCH`
  1566. * - `EP_TAGS`
  1567. * - `EP_YEAR`
  1568. * Default `EP_NONE`.
  1569. * @type bool $paged Whether archive pagination rules should be added for the structure.
  1570. * Default true.
  1571. * @type bool $feed Whether feed rewrite rules should be added for the structure. Default true.
  1572. * @type bool $forcomments Whether the feed rules should be a query for a comments feed. Default false.
  1573. * @type bool $walk_dirs Whether the 'directories' making up the structure should be walked over
  1574. * and rewrite rules built for each in-turn. Default true.
  1575. * @type bool $endpoints Whether endpoints should be applied to the generated rules. Default true.
  1576. * }
  1577. */
  1578. public function add_permastruct( $name, $struct, $args = array() ) {
  1579. // Back-compat for the old parameters: $with_front and $ep_mask.
  1580. if ( ! is_array( $args ) ) {
  1581. $args = array( 'with_front' => $args );
  1582. }
  1583. if ( func_num_args() == 4 ) {
  1584. $args['ep_mask'] = func_get_arg( 3 );
  1585. }
  1586. $defaults = array(
  1587. 'with_front' => true,
  1588. 'ep_mask' => EP_NONE,
  1589. 'paged' => true,
  1590. 'feed' => true,
  1591. 'forcomments' => false,
  1592. 'walk_dirs' => true,
  1593. 'endpoints' => true,
  1594. );
  1595. $args = array_intersect_key( $args, $defaults );
  1596. $args = wp_parse_args( $args, $defaults );
  1597. if ( $args['with_front'] ) {
  1598. $struct = $this->front . $struct;
  1599. } else {
  1600. $struct = $this->root . $struct;
  1601. }
  1602. $args['struct'] = $struct;
  1603. $this->extra_permastructs[ $name ] = $args;
  1604. }
  1605. /**
  1606. * Removes a permalink structure.
  1607. *
  1608. * @since 4.5.0
  1609. *
  1610. * @param string $name Name for permalink structure.
  1611. */
  1612. public function remove_permastruct( $name ) {
  1613. unset( $this->extra_permastructs[ $name ] );
  1614. }
  1615. /**
  1616. * Removes rewrite rules and then recreate rewrite rules.
  1617. *
  1618. * Calls WP_Rewrite::wp_rewrite_rules() after removing the 'rewrite_rules' option.
  1619. * If the function named 'save_mod_rewrite_rules' exists, it will be called.
  1620. *
  1621. * @since 2.0.1
  1622. *
  1623. * @param bool $hard Whether to update .htaccess (hard flush) or just update rewrite_rules option (soft flush). Default is true (hard).
  1624. */
  1625. public function flush_rules( $hard = true ) {
  1626. static $do_hard_later = null;
  1627. // Prevent this action from running before everyone has registered their rewrites.
  1628. if ( ! did_action( 'wp_loaded' ) ) {
  1629. add_action( 'wp_loaded', array( $this, 'flush_rules' ) );
  1630. $do_hard_later = ( isset( $do_hard_later ) ) ? $do_hard_later || $hard : $hard;
  1631. return;
  1632. }
  1633. if ( isset( $do_hard_later ) ) {
  1634. $hard = $do_hard_later;
  1635. unset( $do_hard_later );
  1636. }
  1637. update_option( 'rewrite_rules', '' );
  1638. $this->wp_rewrite_rules();
  1639. /**
  1640. * Filters whether a "hard" rewrite rule flush should be performed when requested.
  1641. *
  1642. * A "hard" flush updates .htaccess (Apache) or web.config (IIS).
  1643. *
  1644. * @since 3.7.0
  1645. *
  1646. * @param bool $hard Whether to flush rewrite rules "hard". Default true.
  1647. */
  1648. if ( ! $hard || ! apply_filters( 'flush_rewrite_rules_hard', true ) ) {
  1649. return;
  1650. }
  1651. if ( function_exists( 'save_mod_rewrite_rules' ) ) {
  1652. save_mod_rewrite_rules();
  1653. }
  1654. if ( function_exists( 'iis7_save_url_rewrite_rules' ) ) {
  1655. iis7_save_url_rewrite_rules();
  1656. }
  1657. }
  1658. /**
  1659. * Sets up the object's properties.
  1660. *
  1661. * The 'use_verbose_page_rules' object property will be set to true if the
  1662. * permalink structure begins with one of the following: '%postname%', '%category%',
  1663. * '%tag%', or '%author%'.
  1664. *
  1665. * @since 1.5.0
  1666. */
  1667. public function init() {
  1668. $this->extra_rules = array();
  1669. $this->non_wp_rules = array();
  1670. $this->endpoints = array();
  1671. $this->permalink_structure = get_option( 'permalink_structure' );
  1672. $this->front = substr( $this->permalink_structure, 0, strpos( $this->permalink_structure, '%' ) );
  1673. $this->root = '';
  1674. if ( $this->using_index_permalinks() ) {
  1675. $this->root = $this->index . '/';
  1676. }
  1677. unset( $this->author_structure );
  1678. unset( $this->date_structure );
  1679. unset( $this->page_structure );
  1680. unset( $this->search_structure );
  1681. unset( $this->feed_structure );
  1682. unset( $this->comment_feed_structure );
  1683. $this->use_trailing_slashes = ( '/' === substr( $this->permalink_structure, -1, 1 ) );
  1684. // Enable generic rules for pages if permalink structure doesn't begin with a wildcard.
  1685. if ( preg_match( '/^[^%]*%(?:postname|category|tag|author)%/', $this->permalink_structure ) ) {
  1686. $this->use_verbose_page_rules = true;
  1687. } else {
  1688. $this->use_verbose_page_rules = false;
  1689. }
  1690. }
  1691. /**
  1692. * Sets the main permalink structure for the site.
  1693. *
  1694. * Will update the 'permalink_structure' option, if there is a difference
  1695. * between the current permalink structure and the parameter value. Calls
  1696. * WP_Rewrite::init() after the option is updated.
  1697. *
  1698. * Fires the {@see 'permalink_structure_changed'} action once the init call has
  1699. * processed passing the old and new values
  1700. *
  1701. * @since 1.5.0
  1702. *
  1703. * @param string $permalink_structure Permalink structure.
  1704. */
  1705. public function set_permalink_structure( $permalink_structure ) {
  1706. if ( $permalink_structure != $this->permalink_structure ) {
  1707. $old_permalink_structure = $this->permalink_structure;
  1708. update_option( 'permalink_structure', $permalink_structure );
  1709. $this->init();
  1710. /**
  1711. * Fires after the permalink structure is updated.
  1712. *
  1713. * @since 2.8.0
  1714. *
  1715. * @param string $old_permalink_structure The previous permalink structure.
  1716. * @param string $permalink_structure The new permalink structure.
  1717. */
  1718. do_action( 'permalink_structure_changed', $old_permalink_structure, $permalink_structure );
  1719. }
  1720. }
  1721. /**
  1722. * Sets the category base for the category permalink.
  1723. *
  1724. * Will update the 'category_base' option, if there is a difference between
  1725. * the current category base and the parameter value. Calls WP_Rewrite::init()
  1726. * after the option is updated.
  1727. *
  1728. * @since 1.5.0
  1729. *
  1730. * @param string $category_base Category permalink structure base.
  1731. */
  1732. public function set_category_base( $category_base ) {
  1733. if ( get_option( 'category_base' ) !== $category_base ) {
  1734. update_option( 'category_base', $category_base );
  1735. $this->init();
  1736. }
  1737. }
  1738. /**
  1739. * Sets the tag base for the tag permalink.
  1740. *
  1741. * Will update the 'tag_base' option, if there is a difference between the
  1742. * current tag base and the parameter value. Calls WP_Rewrite::init() after
  1743. * the option is updated.
  1744. *
  1745. * @since 2.3.0
  1746. *
  1747. * @param string $tag_base Tag permalink structure base.
  1748. */
  1749. public function set_tag_base( $tag_base ) {
  1750. if ( get_option( 'tag_base' ) !== $tag_base ) {
  1751. update_option( 'tag_base', $tag_base );
  1752. $this->init();
  1753. }
  1754. }
  1755. /**
  1756. * Constructor - Calls init(), which runs setup.
  1757. *
  1758. * @since 1.5.0
  1759. */
  1760. public function __construct() {
  1761. $this->init();
  1762. }
  1763. }