|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
// TODO output web push JS from this module |
|
|
|
|
|
|
4
|
|
|
|
|
5
|
|
|
class Jetpack_PWA_Web_Push { |
|
6
|
|
|
private static $__instance = null; |
|
7
|
|
|
/** |
|
8
|
|
|
* Singleton implementation |
|
9
|
|
|
* |
|
10
|
|
|
* @return object |
|
11
|
|
|
*/ |
|
12
|
|
|
public static function instance() { |
|
13
|
|
|
if ( ! is_a( self::$__instance, 'Jetpack_PWA_Web_Push' ) ) { |
|
14
|
|
|
self::$__instance = new Jetpack_PWA_Web_Push(); |
|
15
|
|
|
} |
|
16
|
|
|
|
|
17
|
|
|
return self::$__instance; |
|
18
|
|
|
} |
|
19
|
|
|
|
|
20
|
|
|
private function __construct() { |
|
21
|
|
|
if ( get_option( 'pwa_web_push' ) ) { |
|
22
|
|
|
add_filter( 'jetpack_published_post_flags', array( $this, 'modify_published_post_flags' ), 10, 2 ); |
|
23
|
|
|
add_action( 'widgets_init', array( $this, 'register_subscribe_widget' ) ); |
|
24
|
|
|
} |
|
25
|
|
|
} |
|
26
|
|
|
|
|
27
|
|
|
public function modify_published_post_flags( $flags, $post ) { |
|
28
|
|
|
if ( ! $this->post_type_is_web_pushable( $post->post_type ) ) { |
|
29
|
|
|
return $flags; |
|
30
|
|
|
} |
|
31
|
|
|
|
|
32
|
|
|
/** |
|
33
|
|
|
* Determines whether a post being published gets sent to web push subscribers. |
|
34
|
|
|
* |
|
35
|
|
|
* @module pwa |
|
36
|
|
|
* |
|
37
|
|
|
* @since 5.6.0 |
|
38
|
|
|
* |
|
39
|
|
|
* @param bool $should_publicize Should the post be web_pushed? Default to true. |
|
40
|
|
|
* @param WP_POST $post Current Post object. |
|
41
|
|
|
*/ |
|
42
|
|
|
if ( ! apply_filters( 'pwa_should_web_push_published_post', true, $post ) ) { |
|
43
|
|
|
return $flags; |
|
44
|
|
|
} |
|
45
|
|
|
|
|
46
|
|
|
$flags['web_push'] = true; |
|
47
|
|
|
|
|
48
|
|
|
return $flags; |
|
49
|
|
|
} |
|
50
|
|
|
|
|
51
|
|
|
protected function post_type_is_web_pushable( $post_type ) { |
|
52
|
|
|
if ( 'post' == $post_type ) |
|
53
|
|
|
return true; |
|
54
|
|
|
|
|
55
|
|
|
return post_type_supports( $post_type, 'web_push' ); |
|
56
|
|
|
} |
|
57
|
|
|
|
|
58
|
|
|
public function register_subscribe_widget() { |
|
59
|
|
|
register_widget( 'Jetpack_PWA_Web_Push_Subscribe_Widget' ); |
|
60
|
|
|
} |
|
61
|
|
|
} |
|
62
|
|
|
|
|
63
|
|
|
if ( ! class_exists( 'Jetpack_PWA_Web_Push_Subscribe_Widget' ) ) { |
|
64
|
|
|
class Jetpack_PWA_Web_Push_Subscribe_Widget extends WP_Widget { |
|
|
|
|
|
|
65
|
|
|
/** |
|
66
|
|
|
* Constructor |
|
67
|
|
|
*/ |
|
68
|
|
View Code Duplication |
public function __construct() { |
|
69
|
|
|
parent::__construct( |
|
70
|
|
|
'web_push_subscribe_widget', |
|
71
|
|
|
apply_filters( 'jetpack_widget_name', esc_html__( 'Jetpack Web Push Subscribe', 'jetpack' ) ), |
|
72
|
|
|
array( |
|
73
|
|
|
'description' => 'Web Push Subscribe', |
|
74
|
|
|
), |
|
75
|
|
|
array() |
|
76
|
|
|
); |
|
77
|
|
|
|
|
78
|
|
|
if ( is_active_widget( false, false, $this->id_base ) || is_customize_preview() ) { |
|
79
|
|
|
add_action( 'wp_enqueue_scripts', array( $this, 'enqueue_frontend_scripts' ) ); |
|
80
|
|
|
} |
|
81
|
|
|
} |
|
82
|
|
|
|
|
83
|
|
|
/** |
|
84
|
|
|
* Enqueue scripts and styles. |
|
85
|
|
|
*/ |
|
86
|
|
|
function enqueue_frontend_scripts() { |
|
87
|
|
|
// TODO: |
|
|
|
|
|
|
88
|
|
|
// wp_enqueue_style( 'eu-cookie-law-style', plugins_url( 'eu-cookie-law/style.css', __FILE__ ), array(), '20170403' ); |
|
89
|
|
|
// wp_enqueue_script( 'eu-cookie-law-script', plugins_url( 'eu-cookie-law/eu-cookie-law.js', __FILE__ ), array( 'jquery' ), '20170404', true ); |
|
90
|
|
|
} |
|
91
|
|
|
|
|
92
|
|
|
function defaults() { |
|
93
|
|
|
// TODO: |
|
|
|
|
|
|
94
|
|
|
return array(); |
|
95
|
|
|
} |
|
96
|
|
|
|
|
97
|
|
|
/** |
|
98
|
|
|
* Outputs the content of the widget |
|
99
|
|
|
* |
|
100
|
|
|
* @param array $args |
|
101
|
|
|
* @param array $instance |
|
102
|
|
|
*/ |
|
103
|
|
View Code Duplication |
public function widget( $args, $instance ) { |
|
104
|
|
|
$instance = wp_parse_args( $instance, $this->defaults() ); |
|
|
|
|
|
|
105
|
|
|
echo $args['before_widget']; |
|
106
|
|
|
// require( dirname( __FILE__ ) . '/widget.php' ); |
|
107
|
|
|
echo "The widget body"; |
|
108
|
|
|
echo $args['after_widget']; |
|
109
|
|
|
/** This action is already documented in modules/widgets/gravatar-profile.php */ |
|
110
|
|
|
do_action( 'jetpack_stats_extra', 'widget_view', 'web_push_subscribe' ); |
|
111
|
|
|
} |
|
112
|
|
|
|
|
113
|
|
|
/** |
|
114
|
|
|
* Back-end widget form. |
|
115
|
|
|
* |
|
116
|
|
|
* @param array $instance Previously saved values from database. |
|
117
|
|
|
*/ |
|
118
|
|
|
public function form( $instance ) { |
|
119
|
|
|
$instance = wp_parse_args( $instance, $this->defaults() ); |
|
|
|
|
|
|
120
|
|
|
// require( dirname( __FILE__ ) . '/eu-cookie-law/form.php' ); |
|
121
|
|
|
echo "The form"; |
|
122
|
|
|
} |
|
123
|
|
|
|
|
124
|
|
|
/** |
|
125
|
|
|
* Processing widget options on save |
|
126
|
|
|
* |
|
127
|
|
|
* @param array $new_instance The new options |
|
128
|
|
|
* @param array $old_instance The previous options |
|
129
|
|
|
* |
|
130
|
|
|
* @return array |
|
131
|
|
|
*/ |
|
132
|
|
|
public function update( $new_instance, $old_instance ) { |
|
133
|
|
|
// processes widget options to be saved |
|
134
|
|
|
} |
|
135
|
|
|
} |
|
136
|
|
|
} |
|
137
|
|
|
|
|
138
|
|
|
|