Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
R
radar-wp
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Container registry
Model registry
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
radar
radar-wp
Commits
7083316a
Commit
7083316a
authored
3 years ago
by
ekes
Browse files
Options
Downloads
Patches
Plain Diff
Fixes and updates to not break 5.9
parent
a34db48a
Branches
Branches containing commit
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
assets/squat-radar.js
+1
-12
1 addition, 12 deletions
assets/squat-radar.js
includes/squat-radar-widget.php
+34
-26
34 additions, 26 deletions
includes/squat-radar-widget.php
with
35 additions
and
38 deletions
assets/squat-radar.js
+
1
−
12
View file @
7083316a
...
...
@@ -7,7 +7,7 @@ jQuery(function($){
type
:
'
POST
'
,
data
:
{
action
:
"
squat_radar_events
"
,
instance
:
window
[
widget
.
id
],
instance
:
squat_radar_widget
[
widget
.
id
],
},
success
:
function
(
result
){
...
...
@@ -20,17 +20,6 @@ jQuery(function($){
}
else
{
$
(
widget
).
empty
();
$
(
widget
).
append
(
result
.
html
);
// $(".squat-li a").on('click', function(e){
// if (this.hasAttribute("data-link")) {
// e.preventDefault();
// $(this).parent().find('p').show();
// this.textContent = this.getAttribute('data-nog-meer');
// this.setAttribute('href', this.getAttribute('data-link'));
// this.removeAttribute('data-link');
// }
//
// });
}
},
error
:
function
(
res
){
...
...
This diff is collapsed.
Click to expand it.
includes/squat-radar-widget.php
+
34
−
26
View file @
7083316a
...
...
@@ -25,11 +25,11 @@ class Squat_Radar_Widget extends WP_Widget {
/**
* Register the widget
*/
public
static
function
register_widget
()
{
register_widget
(
__CLASS__
);
public
static
function
register_widget
()
{
register_widget
(
__CLASS__
);
add_action
(
'wp_ajax_squat_radar_events'
,
[
__CLASS__
,
'ajax_callback'
]
);
add_action
(
'wp_ajax_nopriv_squat_radar_events'
,
[
__CLASS__
,
'ajax_callback'
]
);
add_action
(
'wp_enqueue_scripts'
,
[
__CLASS__
,
'widget_script
'
]
);
wp_register_script
(
'squat-radar-widget'
,
SQUAT_RADAR_URL
.
'assets/squat-radar.js'
,
[
'jquery
'
]
);
add_action
(
'wp_enqueue_scripts'
,
[
__CLASS__
,
'widget_style'
]
);
add_action
(
'squat_radar_widget_cache_cron'
,
[
__CLASS__
,
'cache_cron'
]
);
...
...
@@ -44,13 +44,6 @@ class Squat_Radar_Widget extends WP_Widget {
wp_enqueue_style
(
'squat-radar-widget'
);
}
/**
* Enqueue scripts callback, add JS.
*/
static
public
function
widget_script
()
{
wp_register_script
(
'squat-radar-widget'
,
SQUAT_RADAR_URL
.
'assets/squat-radar.js'
,
[
'jquery'
]
);
}
/**
* Cron action.
*
...
...
@@ -66,7 +59,7 @@ class Squat_Radar_Widget extends WP_Widget {
}
}
}
add
_option
(
'squat_radar_widget_cron_run'
,
$last_run
);
update
_option
(
'squat_radar_widget_cron_run'
,
$last_run
);
}
/**
...
...
@@ -75,9 +68,9 @@ class Squat_Radar_Widget extends WP_Widget {
protected
static
function
cache_refresh
(
$instance
)
{
$connector
=
new
Squat_Radar_Connector
();
$languages
=
apply_filters
(
'wpml_active_languages'
,
NULL
);
$languages
=
is_array
(
$languages
)
?
array_keys
(
$languages
)
:
[];
$languages
=
array_merge
(
$instance
[
'url'
][
'keys'
][
'language'
],
$languages
);
$languages
=
apply_filters
(
'wpml_active_languages'
,
NULL
);
$languages
=
is_array
(
$languages
)
?
array_keys
(
$languages
)
:
[];
$languages
=
array_merge
(
[
$instance
[
'url'
][
'keys'
][
'language'
]
]
,
$languages
);
foreach
(
$languages
as
$language
)
{
try
{
// Force update. Don't set expire.
...
...
@@ -119,9 +112,12 @@ class Squat_Radar_Widget extends WP_Widget {
}
}
else
{
wp_enqueue_script
(
'squat-radar-widget'
);
wp_localize_script
(
'squat-radar-widget'
,
'squat_radar_widget'
,
[
'ajaxurl'
=>
admin_url
(
'admin-ajax.php'
)
]
);
wp_localize_script
(
'squat-radar-widget'
,
$widget_id
,
[
'number'
=>
$this
->
number
]
);
wp_enqueue_script
(
'squat-radar-widget'
);
wp_add_inline_script
(
'squat-radar-widget'
,
'const squat_radar_widget = '
.
json_encode
(
[
'ajaxurl'
=>
admin_url
(
'admin-ajax.php'
),
$widget_id
=>
$this
->
number
,
]
)
.
';'
,
'before'
);
echo
'<div id="'
.
$widget_id
.
'" class="squat-radar-widget squat-radar-ajax"><a href="'
.
esc_url_raw
(
$instance
[
'url'
][
'value'
]
)
.
'">'
.
esc_url
(
$instance
[
'url'
][
'value'
]
)
...
...
@@ -142,7 +138,7 @@ class Squat_Radar_Widget extends WP_Widget {
$data
=
[];
// Load instance configuration from ID.
$instance_number
=
(
int
)
$_POST
[
'instance'
]
[
'number'
]
;
$instance_number
=
(
int
)
$_POST
[
'instance'
];
$widget_options_all
=
get_option
(
'widget_squat_radar'
);
if
(
!
isset
(
$widget_options_all
[
$instance_number
])
)
{
wp_die
();
...
...
@@ -181,7 +177,6 @@ class Squat_Radar_Widget extends WP_Widget {
* Widget options.
*/
public
function
form
(
$instance
)
{
//
// Title.
//
...
...
@@ -329,8 +324,7 @@ class Squat_Radar_Widget extends WP_Widget {
* Save widget options.
*/
public
function
update
(
$new_instance
,
$old_instance
)
{
$options
=
[];
$options
=
[];
if
(
!
empty
(
$new_instance
[
'title'
]
)
)
{
$options
[
'title'
]
=
sanitize_text_field
(
$new_instance
[
'title'
]
);
}
...
...
@@ -338,10 +332,18 @@ class Squat_Radar_Widget extends WP_Widget {
$options
[
'title'
]
=
''
;
}
if
(
!
empty
(
$new_instance
[
'url'
])
)
{
$keys
=
$this
->
connector
->
decode_search_url
(
$new_instance
[
'url'
]);
if
(
!
empty
(
$new_instance
[
'url'
])
)
{
// The value passed here changes somewhere post WP5.4.
// More recent versions have the options array in the instance.
if
(
is_string
(
$new_instance
[
'url'
]))
{
$url
=
$new_instance
[
'url'
];
}
else
{
$url
=
$new_instance
[
'url'
][
'value'
];
}
$keys
=
$this
->
connector
->
decode_search_url
(
$url
);
$options
[
'url'
][
'keys'
]
=
$keys
;
$options
[
'url'
][
'value'
]
=
$
new_instance
[
'
url
'
]
;
$options
[
'url'
][
'value'
]
=
$url
;
if
(
empty
(
$keys
))
{
$options
[
'url'
][
'error'
]
=
'URL not recognised'
;
}
...
...
@@ -350,14 +352,20 @@ class Squat_Radar_Widget extends WP_Widget {
$options
[
'url'
]
=
[
'value'
=>
''
,
'keys'
=>
[]];
}
$options
[
'fields'
]
=
[];
// When called by 5.9 ajax this contains the already set array.
// Just check it's sane.
$options
[
'fields'
]
=
is_array
(
$new_instance
[
'fields'
])
?
$new_instance
[
'fields'
]
:
[];
array_filter
(
$options
[
'fields'
],
function
(
$v
,
$k
)
{
return
(
$v
==
$k
)
&&
(
preg_match
(
'([^a-zA-Z_:])'
,
$k
)
===
0
);
},
ARRAY_FILTER_USE_BOTH
);
foreach
(
$this
->
preset_fields
()
as
$field_name
=>
$field_label
)
{
if
(
!
empty
(
$new_instance
[
'field-'
.
$field_name
])
)
{
$options
[
'fields'
][
$field_name
]
=
$field_name
;
}
}
if
(
!
empty
(
$new_instance
[
'fields'
])
)
{
if
(
!
empty
(
$new_instance
[
'fields'
])
&&
is_string
(
$new_instance
[
'fields'
])
)
{
$matches
=
[];
preg_match_all
(
'/([a-zA-Z_:]+)/'
,
$new_instance
[
'fields'
],
$matches
);
$options
[
'fields'
]
+=
array_combine
(
$matches
[
0
],
$matches
[
0
]);
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment