Skip to content

Commit 986f814

Browse files
committed
Use X-Requested-With header for XHR detection
1 parent ef8b6e2 commit 986f814

6 files changed

Lines changed: 13 additions & 22 deletions

File tree

controllers/Index.php

Lines changed: 8 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
namespace controllers;
44

5+
use Base;
6+
57
/**
68
* Controller for root
79
*
@@ -14,21 +16,14 @@ class Index extends BaseController {
1416
* home site
1517
* html
1618
*
19+
* @param Base $f3 fatfree base instance
20+
*
1721
* @return void
1822
*/
19-
public function home() {
20-
// parse params
21-
$options = [];
22-
if (\F3::get('homepage') != '') {
23-
$options = ['type' => \F3::get('homepage')];
24-
}
25-
26-
// use ajax given params?
27-
if (count($_GET) > 0) {
28-
$options = $_GET;
29-
}
23+
public function home(Base $f3) {
24+
$options = $_GET;
3025

31-
if (!isset($options['ajax'])) {
26+
if (!$f3->ajax()) {
3227
// show as full html page
3328
$this->view->publicMode = \F3::get('public') == 1;
3429
$this->view->authEnabled = \F3::get('auth')->enabled() === true;
@@ -81,7 +76,7 @@ public function home() {
8176
}
8277

8378
// ajax call = only send entries and statistics not full template
84-
if (isset($options['ajax'])) {
79+
if ($f3->ajax()) {
8580
$this->view->jsonSuccess([
8681
'lastUpdate' => \helpers\ViewHelper::date_iso8601($itemsDao->lastUpdate()),
8782
'hasMore' => $items['hasMore'],

controllers/Sources.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -161,13 +161,11 @@ public function write(Base $f3, array $params) {
161161
$tags = htmlspecialchars($data['tags']);
162162
$spout = $data['spout'];
163163
$filter = $data['filter'];
164-
$isAjax = isset($data['ajax']);
165164

166165
unset($data['title']);
167166
unset($data['spout']);
168167
unset($data['filter']);
169168
unset($data['tags']);
170-
unset($data['ajax']);
171169

172170
// check if source already exists
173171
$id = $params['id'];
@@ -219,7 +217,7 @@ public function write(Base $f3, array $params) {
219217
];
220218

221219
// only for selfoss ui (update stats in navigation)
222-
if ($isAjax) {
220+
if ($f3->ajax()) {
223221
// get new tag list with updated count values
224222
$tagController = new \controllers\Tags();
225223
$return['tags'] = $tagController->tagsListAsString();

public/js/selfoss-base.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ var selfoss = {
2222
source: '',
2323
sourcesNav: false,
2424
extraIds: [],
25-
ajax: true
2625
},
2726

2827
/**

public/js/selfoss-events-entries.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,7 @@ selfoss.events.entries = function(e) {
199199
url: $('base').attr('href') + 'source/' + selfoss.filter.source + '/update',
200200
type: 'POST',
201201
dataType: 'text',
202-
data: { ajax: true },
202+
data: {},
203203
success: function(response) {
204204
// hide nav on smartphone
205205
if(selfoss.isSmartphone()) {

public/js/selfoss-events-entriestoolbar.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ selfoss.events.entriesToolbar = function(parent) {
8989

9090
$.ajax({
9191
url: $('base').attr('href') + (starr ? 'starr/' : 'unstarr/') + id,
92-
data: { ajax: true },
92+
data: {},
9393
type: 'POST',
9494
error: function(jqXHR, textStatus, errorThrown) {
9595
// rollback ui changes
@@ -167,7 +167,7 @@ selfoss.events.entriesToolbar = function(parent) {
167167

168168
$.ajax({
169169
url: $('base').attr('href') + (unread ? 'mark/' : 'unmark/') + id,
170-
data: { ajax: true },
170+
data: {},
171171
type: 'POST',
172172
error: function(jqXHR, textStatus, errorThrown) {
173173
// rollback ui changes

public/js/selfoss-events-sources.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,6 @@ selfoss.events.sources = function() {
5656

5757
// get values and params
5858
var values = selfoss.getValues(parent);
59-
values['ajax'] = true;
6059

6160
$.ajax({
6261
url: url,
@@ -121,7 +120,7 @@ selfoss.events.sources = function() {
121120
// delete on server
122121
$.ajax({
123122
url: $('base').attr('href')+'source/delete/'+id,
124-
data: { ajax: true },
123+
data: {},
125124
type: 'POST',
126125
success: function() {
127126
parent.fadeOut('fast', function() {

0 commit comments

Comments
 (0)