This repository was archived by the owner on May 10, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathconnectedweb.php
More file actions
197 lines (164 loc) · 6.66 KB
/
connectedweb.php
File metadata and controls
197 lines (164 loc) · 6.66 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
<?php
/**
* @package connectedweb
* @version 0.1.0
*/
/*
Plugin Name: Connected Web
Plugin URI: https://connectedweb.org
Description: Add Connected Web feed support to your Wordpress website
Version: 0.1.0
Author: Fabio Endrizzi (jcte02)
License: GPLv3 or later
License URI: https://www.gnu.org/licenses/gpl-3.0.html
connectedweb
Copyright (C) 2017 Fabio Endrizzi (jcte02)
This file is part of connectedweb.
connectedweb is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
connectedweb is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with connectedweb. If not, see <http://www.gnu.org/licenses/>.
*/
defined('ABSPATH') or die('OwO');
add_action('wp_head', function () {
?>
<link rel="alternate" type="application/connectedweb+jsonp"
title="<?php echo get_bloginfo('name') ?>" href="<?php echo get_feed_link('connectedweb') ?>" />
<?php
});
add_action('init', 'connectedweb_register_feed');
function connectedweb_register_feed()
{
add_feed('connectedweb', function () {
load_template(plugin_dir_path(__FILE__) . "/connectedweb-feed.php");
});
add_feed('connectedweb/source', function () {
load_template(plugin_dir_path(__FILE__) . "/connectedweb-source.php");
});
}
register_activation_hook(__FILE__, function () {
connectedweb_register_feed();
flush_rewrite_rules();
});
register_deactivation_hook(__FILE__, function () {
unregister_setting('connectedweb', 'use_popular_tags');
unregister_setting('connectedweb', 'custom_keywords');
unregister_setting('connectedweb', 'use_default_cache');
unregister_setting('connectedweb', 'can_cache');
unregister_setting('connectedweb', 'cache_expire_milliseconds');
flush_rewrite_rules();
});
register_uninstall_hook(__FILE__, 'connectedweb_uninstall');
function connectedweb_uninstall()
{
delete_option('use_popular_tags');
delete_option('custom_keywords');
delete_option('use_default_cache');
delete_option('can_cache');
delete_option('cache_expire_milliseconds');
}
add_action('admin_enqueue_scripts', function () {
wp_enqueue_script('jquery-core');
// wp_enqueue_script('jquery-effects-core');
// wp_enqueue_script('jquery-effects-slide');
wp_enqueue_style('onoff', plugins_url('admin/css/onoff.css', __FILE__));
});
require_once('includes/output/onoff.php');
add_action('admin_init', function () {
register_setting('connectedweb', 'use_popular_tags', array(
'type' => 'int',
'description' => 'Wheter to use popular tags as feed keywords',
'sanitize_callback' => 'intval',
'default' => 1
));
register_setting('connectedweb', 'custom_keywords', array(
'type' => 'string',
'description' => 'Custom keywords (separated by comma)',
'sanitize_callback' => 'sanitize_text_field',
'default' => ''
));
register_setting('connectedweb', 'use_default_cache', array(
'type' => 'int',
'description' => 'Wheter to use default cache settings',
'sanitize_callback' => 'intval',
'default' => 1
));
register_setting('connectedweb', 'can_cache', array(
'type' => 'int',
'description' => 'Whether or not the feed can be cached by readers',
'sanitize_callback' => 'intval',
'default' => 1
));
register_setting('connectedweb', 'cache_expire_milliseconds', array(
'type' => 'int',
'description' => 'Expire time of the cache (in milliseconds)',
'sanitize_callback' => 'intval',
'default' => 3600000
));
add_settings_section('connectedweb-feed', 'Feed Settings', function () {
}, 'connectedweb');
add_settings_section('connectedweb-cache', 'Cache Settings', function () {
}, 'connectedweb');
add_settings_field('use_popular_tags', 'Use popular tags as keywords', function () {
onoff_switch('use_popular_tags', 'custom_keywords');
}, 'connectedweb', 'connectedweb-feed', array(
'label_for' => 'use_popular_tags'
));
add_settings_field('custom_keywords', 'Custom keywords (separated by comma)', function () {
?>
<input type="text" name="custom_keywords" id="custom_keywords"
pattern="(\w{3,},?\s?){1,5}"
value="<?php echo esc_attr(get_option('custom_keywords')); ?>"
<?php required(get_option('use_popular_tags', 1)) ?> />
<?php
}, 'connectedweb', 'connectedweb-feed', array(
'label_for' => 'custom_keywords',
'class' => 'custom_keywords ' . hidden(get_option('use_popular_tags', 1))
));
add_settings_field('use_default_cache', 'Use default cache settings', function () {
onoff_switch('use_default_cache', 'cache_settings');
}, 'connectedweb', 'connectedweb-cache', array(
'label_for' => 'use_default_cache'
));
add_settings_field('can_cache', 'Readers can cache feed', function () {
onoff_switch('can_cache', 'null');
}, 'connectedweb', 'connectedweb-cache', array(
'label_for' => 'can_cache',
'class' => 'cache_settings ' . hidden(get_option('use_default_cache', 1))
));
add_settings_field('cache_expire_milliseconds', 'Expire time of the cached feed (in milliseconds)', function () {
?>
<input type="number" name="cache_expire_milliseconds"
min='60000' step='1000'
required value="<?php echo esc_attr(get_option('cache_expire_milliseconds')); ?>" />
<?php
}, 'connectedweb', 'connectedweb-cache', array(
'label_for' => 'cache_expire_milliseconds',
'class' => 'cache_settings ' . hidden(get_option('use_default_cache', 1))
));
});
add_action('admin_menu', function () {
add_options_page('Connected Web Settings', 'Connected Web', 'manage_options', 'connecteweb', function () {
if (!current_user_can('manage_options')) {
return;
} ?>
<div class='wrap'>
<h1><?php esc_html(get_admin_page_title()); ?></h1>
<form action="options.php" method="post">
<?php
settings_fields('connectedweb');
do_settings_sections('connectedweb');
submit_button('Save Settings'); ?>
</form>
</div>
<?php
});
});
require_once('includes/metadata/user.php');
require_once('includes/metadata/attachment.php');