-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathwp-admin-microblog.php
More file actions
361 lines (316 loc) · 12.9 KB
/
wp-admin-microblog.php
File metadata and controls
361 lines (316 loc) · 12.9 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
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
<?php
/*
Plugin Name: WP Admin Microblog
Plugin URI: http://mtrv.wordpress.com/microblog/
Description: Adds a microblog in your WordPress backend.
Version: 3.1.1
Author: Michael Winkler
Author URI: http://mtrv.wordpress.com/
Min WP Version: 3.8
Max WP Version: 5.3
Text Domain: wp-admin-microblog
Domain Path: /languages
GitHub Plugin URI: https://github.com/winkm89/wp-admin-microblog
GitHub Branch: master
*/
/*
LICENCE
Copyright 2010-2019 Michael Winkler
This program 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 2 of the License, or
(at your option) any later version.
This program 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 this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
You find the license text under:
http://www.opensource.org/licenses/gpl-2.0.php
LICENCE Information of included parts
- document-new-6.png (Oxygen Icons 4.3.1 by http://www.oxygen-icons.org/) - Licence: LPGL
*/
// Define databases
global $wpdb;
if ( !defined('WPAM_ADMIN_BLOG_POSTS') ) {
define('WPAM_ADMIN_BLOG_POSTS', $wpdb->prefix . 'admin_blog_posts'); }
if ( !defined('WPAM_ADMIN_BLOG_TAGS') ) {
define('WPAM_ADMIN_BLOG_TAGS', $wpdb->prefix . 'admin_blog_tags'); }
if ( !defined('WPAM_ADMIN_BLOG_RELATIONS') ) {
define('WPAM_ADMIN_BLOG_RELATIONS', $wpdb->prefix . 'admin_blog_relations'); }
if ( !defined('WPAM_ADMIN_BLOG_LIKES') ) {
define('WPAM_ADMIN_BLOG_LIKES', $wpdb->prefix . 'admin_blog_likes'); }
if ( !defined('WPAM_ADMIN_BLOG_META') ) {
define('WPAM_ADMIN_BLOG_META', $wpdb->prefix . 'admin_blog_meta'); }
/*
* Define overwritable system defaults
*/
// Number of tags
if ( !defined('WPAM_DEFAULT_TAGS') ) {
define('WPAM_DEFAULT_TAGS', 50); }
// Number of messages
if ( !defined('WPAM_DEFAULT_NUMBER_MESSAGES') ) {
define('WPAM_DEFAULT_NUMBER_MESSAGES', 10); }
/*
* Default sort order for messages
* Possible Values:
* - date
* - date_last_comment
*/
if ( !defined('WPAM_DEFAULT_SORT_ORDER') ) {
define('WPAM_DEFAULT_SORT_ORDER', 'date'); }
/*
* Date format for messages
* Possible Values
* - time_difference
* - date
*/
if ( !defined('WPAM_DEFAULT_DATE_FORMAT') ) {
define('WPAM_DEFAULT_DATE_FORMAT', 'time_difference'); }
/**
* This value defines the position in the admin menu.
*
* Options:
* null --> position at the end of the default menu
* int [0..99] --> individual position
* For more see:
* https://developer.wordpress.org/reference/functions/add_menu_page/#default-bottom-of-menu-structure
*
* @since 3.1.1
*/
if ( !defined('WPAM_MENU_POSITION') ) {
define('WPAM_MENU_POSITION', null);}
// load microblog name
$wpam_blog_name = get_option('wp_admin_blog_name');
if ( $wpam_blog_name == false ) {
$wpam_blog_name = 'Microblog';
}
// includes
require_once('core/class-ajax.php');
require_once('core/class-tables.php');
require_once('core/class-templates.php');
require_once('core/database.php');
require_once('core/general.php');
require_once('core/screen.php');
require_once('core/settings.php');
require_once('core/messages.php');
require_once('core/update.php');
require_once('core/widget.php');
// Define menu
function wpam_menu() {
global $wpam_blog_name;
global $wpam_admin_page;
$pos = WPAM_MENU_POSITION;
$wpam_admin_page = add_menu_page(__('Blog','wp-admin-microblog'), $wpam_blog_name,'use_wp_admin_microblog', __FILE__, 'wpam_page', plugins_url() . '/wp-admin-microblog/images/logo.png', $pos);
add_action("load-$wpam_admin_page", 'wpam_add_help_tab');
add_action("load-$wpam_admin_page", 'wpam_screen_options');
add_submenu_page('wp-admin-microblog/wp-admin-microblog.php', __('Settings','wp-admin-microblog'), __('Settings','wp-admin-microblog'), 'administrator', 'wp-admin-microblog/settings.php', 'wpam_settings');
}
/**
* Returns the current wpam version
* @return string
* @since 2.3
*/
function wpam_get_version() {
return '3.1.1';
}
/**
* Display media buttons
* adapted from P2-Theme
*/
function wpam_media_buttons() {
include_once ABSPATH . '/wp-admin/includes/media.php';
ob_start();
do_action( 'media_buttons' );
return ob_get_clean();
}
/**
* WP Admin Microblog Page Menu (= teachPress Admin Page Menu)
* @access public
* @param $number_entries (Integer) -> Number of all available entries
* @param $entries_per_page (Integer) -> Number of entries per page
* @param $current_page (Integer) -> current displayed page
* @param $entry_limit (Integer) -> SQL entry limit
* @param $page_link (String) -> example: admin.php?page=wp-admin-microblog/wp-admin-microblog.php
* @param $link_attributes (String) -> example: search=$search&tag=$tag
* @param $type - top or bottom, default: top
*/
function wpam_page_menu ($number_entries, $entries_per_page, $current_page, $entry_limit, $page_link = '', $link_attributes = '', $type = 'top') {
// if number of entries > number of entries per page
if ($number_entries > $entries_per_page) {
$num_pages = floor (($number_entries / $entries_per_page));
$mod = $number_entries % $entries_per_page;
if ($mod != 0) {
$num_pages = $num_pages + 1;
}
// first page / previous page
if ($entry_limit != 0) {
$back_links = '<a href="' . $page_link . '&limit=1&' . $link_attributes . '" title="' . __('first page','wp-admin-microblog') . '" class="page-numbers">«</a> <a href="' . $page_link . '&limit=' . ($current_page - 1) . '&' . $link_attributes . '" title="' . __('previous page','wp-admin-microblog') . '" class="page-numbers">‹</a> ';
}
else {
$back_links = '<a class="first-page disabled">«</a> <a class="prev-page disabled">‹</a> ';
}
$page_input = ' <input name="limit" type="text" size="2" value="' . $current_page . '" style="text-align:center;" /> ' . __('of','wp-admin-microblog') . ' ' . $num_pages . ' ';
// next page/ last page
if ( ( $entry_limit + $entries_per_page ) <= ($number_entries)) {
$next_links = '<a href="' . $page_link . '&limit=' . ($current_page + 1) . '&' . $link_attributes . '" title="' . __('next page','wp-admin-microblog') . '" class="page-numbers">›</a> <a href="' . $page_link . '&limit=' . $num_pages . '&' . $link_attributes . '" title="' . __('last page','wp-admin-microblog') . '" class="page-numbers">»</a> ';
}
else {
$next_links = '<a class="next-page disabled">›</a> <a class="last-page disabled">»</a> ';
}
// for displaying number of entries
if ($entry_limit + $entries_per_page > $number_entries) {
$anz2 = $number_entries;
}
else {
$anz2 = $entry_limit + $entries_per_page;
}
// return
if ($type == 'top') {
return '<div class="tablenav-pages"><span class="displaying-num">' . ($entry_limit + 1) . ' - ' . $anz2 . ' ' . __('of','wp-admin-microblog') . ' ' . $number_entries . ' ' . __('Entries','wp-admin-microblog') . '</span> ' . $back_links . '' . $page_input . '' . $next_links . '</div>';
}
else {
return '<div class="tablenav"><div class="tablenav-pages"><span class="displaying-num">' . ($entry_limit + 1) . ' - ' . $anz2 . ' ' . __('of','wp-admin-microblog') . ' ' . $number_entries . ' ' . __('Entries','wp-admin-microblog') . '</span> ' . $back_links . ' ' . $current_page . ' ' . __('of','wp-admin-microblog') . ' ' . $num_pages . ' ' . $next_links . '</div></div>';
}
}
}
/**
* Get WPAM options
* @param string $name
* @param string $category
* @return boolean
*/
function wpam_get_options($name = '', $category = '') {
global $wpdb;
if ( $category != '' ) {
$row = $wpdb->get_results("SELECT * FROM " . WPAM_ADMIN_BLOG_META . " WHERE `category` = '$category'", ARRAY_A);
}
if ( $name != '' ) {
$row = $wpdb->get_var("SELECT `value` FROM " . WPAM_ADMIN_BLOG_META . " WHERE `variable` = '$name'");
}
if ( $row == '' ) {
return false;
}
return $row;
}
/**
* Add dashboard widget
*/
function wpam_add_widgets() {
if ( current_user_can( 'use_wp_admin_microblog' ) ) {
// load microblog name
$name = wpam_get_options('blog_name_widget', '');
if ( $name == false || $name == '' ) {
$name = 'Microblog';
}
$str = "'";
$title = '<a onclick="wpam_showhide(' . $str . 'wpam_new_message' . $str . ')" style="cursor:pointer; text-decoration:none; font-size:12px; font-weight:bold; color:#464646;" title="' . __('New Message','wp-admin-microblog') . '">' . $name . ' <img src="' . plugins_url() . '/wp-admin-microblog/images/document-new-6.png' . '" heigth="12" width="12" /></a>';
wp_add_dashboard_widget('wpam_dashboard_widget', '' . $title . '', 'wpam_widget_function');
}
}
/*
* Add scripts and stylesheets
*/
function wpam_header() {
$page = '';
// Define $page
if ( isset($_GET['page']) ) {
$page = $_GET['page'];
}
// load scripts only, when it's wp_admin_blog page
if ( strpos($page, 'wp-admin-microblog') !== FALSE || strpos($_SERVER['PHP_SELF'], 'wp-admin/index.php') !== FALSE ) {
wp_register_script('wp_admin_blog', plugins_url() . '/wp-admin-microblog/js/wp-admin-microblog.js');
wp_register_style('wp_admin_blog_css', plugins_url() . '/wp-admin-microblog/css/wp-admin-microblog.css');
wp_enqueue_style('wp_admin_blog_css');
wp_enqueue_style('teachpress-jquery-ui-dialog.css', includes_url() . '/css/jquery-ui-dialog.min.css');
wp_enqueue_script('wp_admin_blog');
wp_enqueue_script('media-upload');
add_thickbox();
wp_enqueue_script(array('jquery-ui-core', 'jquery-ui-datepicker', 'jquery-ui-resizable', 'jquery-ui-autocomplete', 'jquery-ui-sortable', 'jquery-ui-dialog'));
}
// load the hack for the normal WP Admin Microblog page
if ( strpos($page, 'wp-admin-microblog') !== FALSE ) {
wp_register_script('wpam_upload_hack', plugins_url() . '/wp-admin-microblog/js/media-upload-hack.js');
wp_enqueue_script('wpam_upload_hack');
}
// load the hack for the dashboard, when the user say yes
$test = get_option('wp_admin_blog_media_upload');
if (strpos($_SERVER['REQUEST_URI'], 'wp-admin/index.php') !== FALSE && $test == 'true') {
wp_register_script('wpam_upload_hack', plugins_url() . '/wp-admin-microblog/media-upload-hack.js');
wp_enqueue_script('wpam_upload_hack');
}
}
/**
* WPAM plugin activation
* @param boolean $network_wide
* @since 2.2.0
*/
function wpam_activation ( $network_wide ) {
global $wpdb;
// it's a network activation
if ( $network_wide ) {
$old_blog = $wpdb->blogid;
// Get all blog ids
$blogids = $wpdb->get_col($wpdb->prepare("SELECT `blog_id` FROM $wpdb->blogs"));
foreach ($blogids as $blog_id) {
switch_to_blog($blog_id);
wpam_install();
}
switch_to_blog($old_blog);
return;
}
// it's a normal activation
else {
wpam_install();
}
}
/**
* AJAX callback function
* @since 3.0.4
*/
function wpam_ajax_callback () {
// New message check
if ( is_user_logged_in() && isset( $_GET['p_id'] ) ) {
wpam_ajax::new_message_check($_GET['p_id']);
}
// Edit message
if ( is_user_logged_in() && isset( $_GET['edit_id'] ) ) {
wpam_ajax::get_message_text_for_edit($_GET['edit_id']);
}
// Add like
if ( is_user_logged_in() && isset( $_GET['add_like_id'] ) ) {
wpam_ajax::add_like($_GET['add_like_id']);
}
// Show likes
if ( is_user_logged_in() && isset( $_GET['like_id'] ) ) {
wpam_ajax::show_likes($_GET['like_id']);
}
// this is required to terminate immediately and return a proper response
wp_die();
}
/**
* Installer
* @since 1.0
*/
function wpam_install () {
wpam_tables::create();
}
/**
* Uninstalling
*/
function wpam_uninstall() {
wpam_tables::remove();
}
// load language support
function wpam_language_support() {
load_plugin_textdomain('wp-admin-microblog', false, dirname( plugin_basename( __FILE__ ) ) . '/languages/' );
}
// Register WordPress hooks
register_activation_hook( __FILE__, 'wpam_activation');
add_action('init', 'wpam_language_support');
add_action('wp_ajax_wp_admin_blog', 'wpam_ajax_callback');
add_action('admin_init','wpam_header');
add_action('admin_menu','wpam_menu');
add_action('wp_dashboard_setup','wpam_add_widgets');