Commit cf27006c authored by Rolf Forst's avatar Rolf Forst
Browse files

Add options (allowed post types) and settings.

parent 09a3ec98
...@@ -4,4 +4,6 @@ RRZE Post Expiration ...@@ -4,4 +4,6 @@ RRZE Post Expiration
Wordpress-Plugin Wordpress-Plugin
---------------- ----------------
Verfallsdatum für Beiträge. Verfallsdatum für Beiträge und Seiten.
Einstellungsmenü: Einstellungen › Verfallsdatum
...@@ -2,7 +2,7 @@ msgid "" ...@@ -2,7 +2,7 @@ msgid ""
msgstr "" msgstr ""
"Project-Id-Version: RRZE Post Expiration\n" "Project-Id-Version: RRZE Post Expiration\n"
"Report-Msgid-Bugs-To: \n" "Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2016-06-01 15:08+0200\n" "POT-Creation-Date: 2016-06-15 09:22+0200\n"
"PO-Revision-Date: \n" "PO-Revision-Date: \n"
"Last-Translator: \n" "Last-Translator: \n"
"Language-Team: RRZE-Webteam <webmaster@rrze.fau.de>\n" "Language-Team: RRZE-Webteam <webmaster@rrze.fau.de>\n"
...@@ -17,7 +17,7 @@ msgstr "" ...@@ -17,7 +17,7 @@ msgstr ""
"X-Generator: Poedit 1.8.8\n" "X-Generator: Poedit 1.8.8\n"
"X-Poedit-SearchPath-0: ..\n" "X-Poedit-SearchPath-0: ..\n"
#: ../rrze-post-expiration.php:82 #: ../rrze-post-expiration.php:98
#, php-format #, php-format
msgid "" msgid ""
"Ihre PHP-Version %s ist veraltet. Bitte aktualisieren Sie mindestens auf die " "Ihre PHP-Version %s ist veraltet. Bitte aktualisieren Sie mindestens auf die "
...@@ -26,7 +26,7 @@ msgstr "" ...@@ -26,7 +26,7 @@ msgstr ""
"Your server is running PHP version %s. Please upgrade at least to PHP " "Your server is running PHP version %s. Please upgrade at least to PHP "
"version %s." "version %s."
#: ../rrze-post-expiration.php:84 #: ../rrze-post-expiration.php:100
#, php-format #, php-format
msgid "" msgid ""
"Ihre Wordpress-Version %s ist veraltet. Bitte aktualisieren Sie mindestens " "Ihre Wordpress-Version %s ist veraltet. Bitte aktualisieren Sie mindestens "
...@@ -35,83 +35,91 @@ msgstr "" ...@@ -35,83 +35,91 @@ msgstr ""
"Your Wordpress version is %s. Please upgrade at least to Wordpress version " "Your Wordpress version is %s. Please upgrade at least to Wordpress version "
"%s." "%s."
#: ../rrze-post-expiration.php:98 #: ../rrze-post-expiration.php:129 ../rrze-post-expiration.php:135
#: ../rrze-post-expiration.php:193
msgid "Verfallsdatum" msgid "Verfallsdatum"
msgstr "Expiration" msgstr "Expiration"
#: ../rrze-post-expiration.php:116 #: ../rrze-post-expiration.php:150
msgid "Freigabe"
msgstr "Allowed Post Types"
#: ../rrze-post-expiration.php:210
msgid "Y/m/d g:i:s A" msgid "Y/m/d g:i:s A"
msgstr "Y/m/d g:i:s A" msgstr "Y/m/d g:i:s A"
#: ../rrze-post-expiration.php:124 #: ../rrze-post-expiration.php:218
#, php-format #, php-format
msgid "in %s" msgid "in %s"
msgstr "in %s" msgstr "in %s"
#: ../rrze-post-expiration.php:127 #: ../rrze-post-expiration.php:221
#, php-format #, php-format
msgid "%s ago" msgid "%s ago"
msgstr "%s ago" msgstr "%s ago"
#: ../rrze-post-expiration.php:129 #: ../rrze-post-expiration.php:223
msgid "Y/m/d" msgid "Y/m/d"
msgstr "Y/m/d" msgstr "Y/m/d"
#: ../rrze-post-expiration.php:133 #: ../rrze-post-expiration.php:229
msgid "abgelaufen" msgid "abgelaufen"
msgstr "expired" msgstr "expired"
#: ../rrze-post-expiration.php:177 #: ../rrze-post-expiration.php:273
msgid "j. M Y @ H:i" msgid "j. M Y @ H:i"
msgstr "M j, Y @ H:i" msgstr "M j, Y @ H:i"
#: ../rrze-post-expiration.php:179 ../rrze-post-expiration.php:350 #: ../rrze-post-expiration.php:275 ../rrze-post-expiration.php:446
msgid "Verfallsdatum <b>deaktiviert</b>" msgid "Verfallsdatum <b>deaktiviert</b>"
msgstr "Expiration <b>disabled</b>" msgstr "Expiration <b>disabled</b>"
#: ../rrze-post-expiration.php:185 #: ../rrze-post-expiration.php:281
#, php-format #, php-format
msgid "Verfällt am: <b>%s</b>" msgid "Verfällt am: <b>%s</b>"
msgstr "Expires on: <b>%s</b>" msgstr "Expires on: <b>%s</b>"
#: ../rrze-post-expiration.php:187 #: ../rrze-post-expiration.php:283
#, php-format #, php-format
msgid "Abgelaufen am: <b>%s</b>" msgid "Abgelaufen am: <b>%s</b>"
msgstr "Expired on: <b>%s</b>" msgstr "Expired on: <b>%s</b>"
#: ../rrze-post-expiration.php:197 #: ../rrze-post-expiration.php:293
msgid "Bearbeiten" msgid "Bearbeiten"
msgstr "Edit" msgstr "Edit"
#: ../rrze-post-expiration.php:250 #: ../rrze-post-expiration.php:346
msgid "Verfallsdatum aktivieren" msgid "Verfallsdatum aktivieren"
msgstr "Enable expiration" msgstr "Enable expiration"
#: ../rrze-post-expiration.php:253 #: ../rrze-post-expiration.php:349
#, php-format #, php-format
msgid "%1$s%2$s, %3$s @ %4$s : %5$s" msgid "%1$s%2$s, %3$s @ %4$s : %5$s"
msgstr "%1$s%2$s, %3$s @ %4$s : %5$s" msgstr "%1$s%2$s, %3$s @ %4$s : %5$s"
#: ../rrze-post-expiration.php:273 #: ../rrze-post-expiration.php:369
msgid "OK" msgid "OK"
msgstr "OK" msgstr "OK"
#: ../rrze-post-expiration.php:274 #: ../rrze-post-expiration.php:370
msgid "Abbrechen" msgid "Abbrechen"
msgstr "Cancel" msgstr "Cancel"
#: ../rrze-post-expiration.php:331 #: ../rrze-post-expiration.php:427
msgid "Verfällt am:" msgid "Verfällt am:"
msgstr "Expires on:" msgstr "Expires on:"
#: ../rrze-post-expiration.php:333 #: ../rrze-post-expiration.php:429
msgid "Abgelaufen am:" msgid "Abgelaufen am:"
msgstr "Expired on:" msgstr "Expired on:"
#: ../rrze-post-expiration.php:403 #: ../rrze-post-expiration.php:498
msgid "Every Two Minutes" msgid "Every Two Minutes"
msgstr "Every Two Minutes" msgstr "Every Two Minutes"
#~ msgid "Einstellungen &rsaquo; Verfallsdatum"
#~ msgstr "Settings &rsaquo; Expiration"
#~ msgid "Keine" #~ msgid "Keine"
#~ msgstr "None" #~ msgstr "None"
......
...@@ -3,7 +3,7 @@ msgid "" ...@@ -3,7 +3,7 @@ msgid ""
msgstr "" msgstr ""
"Project-Id-Version: RRZE Post Expiration\n" "Project-Id-Version: RRZE Post Expiration\n"
"Report-Msgid-Bugs-To: \n" "Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2016-06-01 15:08+0200\n" "POT-Creation-Date: 2016-06-15 09:22+0200\n"
"PO-Revision-Date: \n" "PO-Revision-Date: \n"
"Last-Translator: \n" "Last-Translator: \n"
"Language-Team: RRZE-Webteam <webmaster@rrze.fau.de>\n" "Language-Team: RRZE-Webteam <webmaster@rrze.fau.de>\n"
...@@ -18,93 +18,98 @@ msgstr "" ...@@ -18,93 +18,98 @@ msgstr ""
"X-Generator: Poedit 1.8.8\n" "X-Generator: Poedit 1.8.8\n"
"X-Poedit-SearchPath-0: ..\n" "X-Poedit-SearchPath-0: ..\n"
#: ../rrze-post-expiration.php:82 #: ../rrze-post-expiration.php:98
#, php-format #, php-format
msgid "" msgid ""
"Ihre PHP-Version %s ist veraltet. Bitte aktualisieren Sie mindestens auf die " "Ihre PHP-Version %s ist veraltet. Bitte aktualisieren Sie mindestens auf die "
"PHP-Version %s." "PHP-Version %s."
msgstr "" msgstr ""
#: ../rrze-post-expiration.php:84 #: ../rrze-post-expiration.php:100
#, php-format #, php-format
msgid "" msgid ""
"Ihre Wordpress-Version %s ist veraltet. Bitte aktualisieren Sie mindestens " "Ihre Wordpress-Version %s ist veraltet. Bitte aktualisieren Sie mindestens "
"auf die Wordpress-Version %s." "auf die Wordpress-Version %s."
msgstr "" msgstr ""
#: ../rrze-post-expiration.php:98 #: ../rrze-post-expiration.php:129 ../rrze-post-expiration.php:135
#: ../rrze-post-expiration.php:193
msgid "Verfallsdatum" msgid "Verfallsdatum"
msgstr "" msgstr ""
#: ../rrze-post-expiration.php:116 #: ../rrze-post-expiration.php:150
msgid "Freigabe"
msgstr ""
#: ../rrze-post-expiration.php:210
msgid "Y/m/d g:i:s A" msgid "Y/m/d g:i:s A"
msgstr "" msgstr ""
#: ../rrze-post-expiration.php:124 #: ../rrze-post-expiration.php:218
#, php-format #, php-format
msgid "in %s" msgid "in %s"
msgstr "" msgstr ""
#: ../rrze-post-expiration.php:127 #: ../rrze-post-expiration.php:221
#, php-format #, php-format
msgid "%s ago" msgid "%s ago"
msgstr "" msgstr ""
#: ../rrze-post-expiration.php:129 #: ../rrze-post-expiration.php:223
msgid "Y/m/d" msgid "Y/m/d"
msgstr "" msgstr ""
#: ../rrze-post-expiration.php:133 #: ../rrze-post-expiration.php:229
msgid "abgelaufen" msgid "abgelaufen"
msgstr "" msgstr ""
#: ../rrze-post-expiration.php:177 #: ../rrze-post-expiration.php:273
msgid "j. M Y @ H:i" msgid "j. M Y @ H:i"
msgstr "" msgstr ""
#: ../rrze-post-expiration.php:179 ../rrze-post-expiration.php:350 #: ../rrze-post-expiration.php:275 ../rrze-post-expiration.php:446
msgid "Verfallsdatum <b>deaktiviert</b>" msgid "Verfallsdatum <b>deaktiviert</b>"
msgstr "" msgstr ""
#: ../rrze-post-expiration.php:185 #: ../rrze-post-expiration.php:281
#, php-format #, php-format
msgid "Verfällt am: <b>%s</b>" msgid "Verfällt am: <b>%s</b>"
msgstr "" msgstr ""
#: ../rrze-post-expiration.php:187 #: ../rrze-post-expiration.php:283
#, php-format #, php-format
msgid "Abgelaufen am: <b>%s</b>" msgid "Abgelaufen am: <b>%s</b>"
msgstr "" msgstr ""
#: ../rrze-post-expiration.php:197 #: ../rrze-post-expiration.php:293
msgid "Bearbeiten" msgid "Bearbeiten"
msgstr "" msgstr ""
#: ../rrze-post-expiration.php:250 #: ../rrze-post-expiration.php:346
msgid "Verfallsdatum aktivieren" msgid "Verfallsdatum aktivieren"
msgstr "" msgstr ""
#: ../rrze-post-expiration.php:253 #: ../rrze-post-expiration.php:349
#, php-format #, php-format
msgid "%1$s%2$s, %3$s @ %4$s : %5$s" msgid "%1$s%2$s, %3$s @ %4$s : %5$s"
msgstr "" msgstr ""
#: ../rrze-post-expiration.php:273 #: ../rrze-post-expiration.php:369
msgid "OK" msgid "OK"
msgstr "" msgstr ""
#: ../rrze-post-expiration.php:274 #: ../rrze-post-expiration.php:370
msgid "Abbrechen" msgid "Abbrechen"
msgstr "" msgstr ""
#: ../rrze-post-expiration.php:331 #: ../rrze-post-expiration.php:427
msgid "Verfällt am:" msgid "Verfällt am:"
msgstr "" msgstr ""
#: ../rrze-post-expiration.php:333 #: ../rrze-post-expiration.php:429
msgid "Abgelaufen am:" msgid "Abgelaufen am:"
msgstr "" msgstr ""
#: ../rrze-post-expiration.php:403 #: ../rrze-post-expiration.php:498
msgid "Every Two Minutes" msgid "Every Two Minutes"
msgstr "" msgstr ""
...@@ -2,8 +2,8 @@ ...@@ -2,8 +2,8 @@
/* /*
Plugin Name: RRZE Post Expiration Plugin Name: RRZE Post Expiration
Plugin URI: https://gitlab.rrze.fau.de/rrze-webteam/rrze-post-expiration Plugin URI: https://gitlab.rrze.fau.de/rrze-webteam/rrze-post-expiration
Version: 1.1.2 Version: 1.2.0
Description: Verfallsdatum für Beiträge. Description: Verfallsdatum für Beiträge und Seiten.
Author: RRZE-Webteam Author: RRZE-Webteam
License: GPLv2 or later License: GPLv2 or later
*/ */
...@@ -32,11 +32,17 @@ register_activation_hook(__FILE__, array('RRZE_Post_Expiration', 'activation')); ...@@ -32,11 +32,17 @@ register_activation_hook(__FILE__, array('RRZE_Post_Expiration', 'activation'));
class RRZE_Post_Expiration { class RRZE_Post_Expiration {
const option_name = '_rrze_post_expiration'; const option_name = 'rrze_post_expiration';
const php_version = '5.4'; const php_version = '5.4';
const wp_version = '4.5'; const wp_version = '4.5';
protected static $cron_hook;
protected static $allowed_post_types = array('post', 'page');
protected static $options;
private static $instance = NULL; private static $instance = NULL;
public static function instance() { public static function instance() {
...@@ -51,24 +57,34 @@ class RRZE_Post_Expiration { ...@@ -51,24 +57,34 @@ class RRZE_Post_Expiration {
private function __construct() { private function __construct() {
global $current_blog; global $current_blog;
self::$options = self::get_options();
add_action('admin_menu', array(__CLASS__, 'add_options_page'));
add_action('admin_init', array(__CLASS__, 'settings_init'));
add_action('admin_enqueue_scripts', array(__CLASS__, 'enqueue_scripts')); add_action('admin_enqueue_scripts', array(__CLASS__, 'enqueue_scripts'));
add_filter('manage_post_posts_columns', array(__CLASS__, 'expiration_date_column')); if (!empty(self::$options->post_types)) {
add_action('manage_post_posts_custom_column', array(__CLASS__, 'expiration_date_custom_column'), 10, 2); foreach (self::$options->post_types as $post_type) {
add_filter('manage_edit-post_sortable_columns', array(__CLASS__, 'expiration_date_sortable_column')); add_filter('manage_' . $post_type . '_posts_columns', array(__CLASS__, 'expiration_date_column'));
add_action('pre_get_posts', array(__CLASS__, 'expiration_date_orderby')); add_action('manage_' . $post_type . '_posts_custom_column', array(__CLASS__, 'expiration_date_custom_column'), 10, 2);
add_filter('manage_edit-' . $post_type . '_sortable_columns', array(__CLASS__, 'expiration_date_sortable_column'));
}
add_action('post_submitbox_misc_actions', array(__CLASS__, 'exp_meta_box')); add_action('pre_get_posts', array(__CLASS__, 'expiration_date_orderby'));
add_action('admin_head', array(__CLASS__, 'expiration_js')); add_action('post_submitbox_misc_actions', array(__CLASS__, 'exp_meta_box'));
add_action('save_post', array(__CLASS__, 'update_post_expiration_date')); add_action('admin_head', array(__CLASS__, 'expiration_js'));
add_filter('cron_schedules', array(__CLASS__, 'add_cron_schedule')); add_action('save_post', array(__CLASS__, 'update_post_expiration_date'));
add_action(self::option_name, array(__CLASS__, 'set_expired_posts'));
$cron_hook = sprintf('%s_%s', self::option_name, $current_blog->blog_id); add_filter('cron_schedules', array(__CLASS__, 'add_cron_schedule'));
add_action($cron_hook, array(__CLASS__, 'set_expired_posts'));
self::$cron_hook = sprintf('%s_%s', self::option_name, $current_blog->blog_id);
add_action(self::$cron_hook, array(__CLASS__, 'set_expired_posts'));
}
} }
public static function activation() { public static function activation() {
...@@ -85,11 +101,90 @@ class RRZE_Post_Expiration { ...@@ -85,11 +101,90 @@ class RRZE_Post_Expiration {
} }
if (!empty($error)) { if (!empty($error)) {
deactivate_plugins(plugin_basename(__FILE__), false, true); deactivate_plugins(plugin_basename(__FILE__), FALSE, TRUE);
wp_die($error); wp_die($error);
} }
} }
private static function default_options() {
$options = array(
'post_types' => array('post')
);
return $options;
}
private static function get_options() {
$defaults = self::default_options();
$options = (array) get_option(self::option_name);
$options = wp_parse_args($options, $defaults);
$options = array_intersect_key($options, $defaults);
return (object) $options;
}
public static function add_options_page() {
add_options_page(__('Verfallsdatum', 'rrze-post-expiration'), __('Verfallsdatum', 'rrze-post-expiration'), 'manage_options', 'options-post-expiration', array(__CLASS__, 'options_page'));
}
public static function options_page() {
?>
<div class="wrap">
<h2><?php echo esc_html(__('Verfallsdatum', 'rrze-post-expiration')); ?></h2>
<form method="post" action="options.php">
<?php
settings_fields('post_expiration_options');
do_settings_sections('post_expiration_options');
submit_button();
?>
</form>
</div>
<?php
}
public static function settings_init() {
register_setting('post_expiration_options', self::option_name, array(__CLASS__, 'options_validate'));
add_settings_section('options_general_section', FALSE, '__return_false', 'post_expiration_options');
add_settings_field('options_general', __('Freigabe', 'rrze-post-expiration'), array(__CLASS__, 'field_options_general'), 'post_expiration_options', 'options_general_section');
}
public static function field_options_general() {
?>
<ul>
<?php foreach (self::$allowed_post_types as $post_type): ?>
<li>
<label for="<?php echo $post_type; ?>"><input type="checkbox" <?php checked(in_array($post_type, self::$options->post_types), TRUE); ?> name="<?php printf('%s[post_types][]', self::option_name); ?>" value="<?php echo $post_type; ?>" id="<?php echo $post_type; ?>" /> <?php echo self::get_post_type_label($post_type); ?></label>
</li>
<?php endforeach; ?>
</ul>
<?php
}
public static function options_validate($input) {
if (!empty($input['post_types'])) {
foreach ($input['post_types'] as $key => $post_type) {
if (!in_array($post_type, self::$allowed_post_types)) {
unset($input['post_types'][$key]);
}
}
} else {
$input['post_types'] = array();
}
return $input;
}
private static function get_post_type_label($post_type = 'post') {
$post_types = get_post_types(array('show_in_menu' => true), 'objects');
$labels = wp_list_pluck($post_types, 'labels');
$labels = wp_list_pluck($labels, 'name');
return isset($labels[$post_type]) ? $labels[$post_type] : '';
}
public static function enqueue_scripts() { public static function enqueue_scripts() {
wp_enqueue_style('post-expiration', plugins_url('css/post-expiration.css', __FILE__ ), 'all', NULL); wp_enqueue_style('post-expiration', plugins_url('css/post-expiration.css', __FILE__ ), 'all', NULL);
} }
...@@ -106,13 +201,12 @@ class RRZE_Post_Expiration { ...@@ -106,13 +201,12 @@ class RRZE_Post_Expiration {
$post = get_post($post_id); $post = get_post($post_id);
$expiration_date = get_post_meta($post->ID, 'expiration_date', true); $expiration_date = get_post_meta($post->ID, 'expiration_date', TRUE);
$expiration_date_gmt = get_post_meta($post->ID, 'expiration_date_gmt', true); $expiration_date_gmt = get_post_meta($post->ID, 'expiration_date_gmt', TRUE);
if (( '0000-00-00 00:00:00' == $post->post_date ) || !$expiration_date) if ($post->post_date == '0000-00-00 00:00:00' || !$expiration_date) {
echo '&#8212;'; echo '&#8212;';
} else {
else {
$t_time = date(__('Y/m/d g:i:s A'), mysql2date('U', $expiration_date)); $t_time = date(__('Y/m/d g:i:s A'), mysql2date('U', $expiration_date));
$m_time = $expiration_date; $m_time = $expiration_date;
...@@ -128,7 +222,9 @@ class RRZE_Post_Expiration { ...@@ -128,7 +222,9 @@ class RRZE_Post_Expiration {
} else { } else {
$h_time = mysql2date(__('Y/m/d'), $m_time); $h_time = mysql2date(__('Y/m/d'), $m_time);
} }
echo '<abbr title="' . $t_time . '">' . $h_time . '</abbr>'; echo '<abbr title="' . $t_time . '">' . $h_time . '</abbr>';
if ($time_diff < 0) { if ($time_diff < 0) {
echo '<br/>', __('abgelaufen', 'rrze-post-expiration'); echo '<br/>', __('abgelaufen', 'rrze-post-expiration');
} }
...@@ -167,7 +263,7 @@ class RRZE_Post_Expiration { ...@@ -167,7 +263,7 @@ class RRZE_Post_Expiration {
public static function exp_meta_box() { public static function exp_meta_box() {
global $post, $post_type, $post_type_object; global $post, $post_type, $post_type_object;