Commit 154fe13d authored by Rolf Forst's avatar Rolf Forst
Browse files

Init commit

parent 6f5ca45c
#, fuzzy
msgid ""
msgstr ""
"Project-Id-Version: RRZE Post Expiration\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2016-03-17 18:02+0100\n"
"PO-Revision-Date: \n"
"Last-Translator: \n"
"Language-Team: RRZE-Webteam <webmaster@rrze.fau.de>\n"
"Language: de\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n"
"X-Poedit-KeywordsList: __;_e;esc_attr__;esc_attr_e;_n:1,2;_nx:4c,1,2\n"
"X-Poedit-Basepath: .\n"
"X-Poedit-SourceCharset: UTF-8\n"
"Plural-Forms: nplurals=2; plural=n != 1;\n"
"X-Generator: Poedit 1.8.7\n"
"X-Poedit-SearchPath-0: ..\n"
#: ../rrze-post-expiration.php:80
#, php-format
msgid ""
"Ihre PHP-Version %s ist veraltet. Bitte aktualisieren Sie mindestens auf die "
"PHP-Version %s."
msgstr ""
#: ../rrze-post-expiration.php:82
#, php-format
msgid ""
"Ihre Wordpress-Version %s ist veraltet. Bitte aktualisieren Sie mindestens "
"auf die Wordpress-Version %s."
msgstr ""
#: ../rrze-post-expiration.php:102
msgid "Verfallsdatum"
msgstr ""
#: ../rrze-post-expiration.php:123
msgid "Keine"
msgstr ""
#: ../rrze-post-expiration.php:126
msgid "Y/m/d g:i:s A"
msgstr ""
#: ../rrze-post-expiration.php:134
#, php-format
msgid "in %s"
msgstr ""
#: ../rrze-post-expiration.php:137
#, php-format
msgid "%s ago"
msgstr ""
#: ../rrze-post-expiration.php:139
msgid "Y/m/d"
msgstr ""
#: ../rrze-post-expiration.php:143
msgid "Abgelaufen"
msgstr ""
#: ../rrze-post-expiration.php:156
msgid "M j, Y @ G:i"
msgstr ""
#: ../rrze-post-expiration.php:158 ../rrze-post-expiration.php:329
msgid "Verfallsdatum <b>deaktiviert</b>"
msgstr ""
#: ../rrze-post-expiration.php:165
#, php-format
msgid "Verfällt am: <b>%s</b>"
msgstr ""
#: ../rrze-post-expiration.php:167
#, php-format
msgid "Abgelaufen am: <b>%s</b>"
msgstr ""
#: ../rrze-post-expiration.php:177
msgid "Edit"
msgstr ""
#: ../rrze-post-expiration.php:230
msgid "Verfallsdatum aktivieren"
msgstr ""
#: ../rrze-post-expiration.php:233
#, php-format
msgid "%1$s%2$s, %3$s @ %4$s : %5$s"
msgstr ""
#: ../rrze-post-expiration.php:252
msgid "OK"
msgstr ""
#: ../rrze-post-expiration.php:253
msgid "Cancel"
msgstr ""
#: ../rrze-post-expiration.php:310
msgid "Verfällt am:"
msgstr ""
#: ../rrze-post-expiration.php:312
msgid "Abgelaufen am:"
msgstr ""
#: ../rrze-post-expiration.php:392
msgid "Every Two Minutes"
msgstr ""
<?php
/*
Plugin Name: RRZE Post Expiration
Plugin URI: https://gitlab.rrze.fau.de/rrze-webteam/rrze-post-expiration
Version: 1.0.0
Description: Verfallsdatum für Beiträge.
Author: RRZE-Webteam
License: GPLv2 or later
*/
/*
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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
load_plugin_textdomain('rrze-post-expiration', FALSE, dirname(plugin_basename(__FILE__)) . '/languages');
add_action('plugins_loaded', array('RRZE_Post_Expiration', 'instance'));
register_activation_hook(__FILE__, array('RRZE_Post_Expiration', 'activation'));
class RRZE_Post_Expiration {
const option_name = '_rrze_post_expiration';
const php_version = '5.4';
const wp_version = '4.4';
private static $instance = NULL;
public static function instance() {
if (self::$instance == NULL) {
self::$instance = new self;
}
return self::$instance;
}
private function __construct() {
global $current_blog;
add_filter('manage_posts_columns', array(__CLASS__, 'expiration_date_column'));
add_action('manage_posts_custom_column', array(__CLASS__, 'expiration_date_custom_colum'), 10, 2);
add_action('post_submitbox_misc_actions', array(__CLASS__, 'exp_meta_box'));
add_action('admin_head', array(__CLASS__, 'expiration_js'));
add_action('save_post', array(__CLASS__, 'update_post_expiration_date'));
add_filter('cron_schedules', array(__CLASS__, 'add_cron_schedule'));
add_action(self::option_name, array(__CLASS__, 'set_expired_posts'));
$cron_hook = sprintf('%s_%s', self::option_name, $current_blog->blog_id);
add_action($cron_hook, array(__CLASS__, 'set_expired_posts'));
}
public static function activation() {
self::verify_system_requirements();
}
private static function verify_system_requirements() {
$error = '';
if (version_compare(PHP_VERSION, self::php_version, '<')) {
$error = sprintf(__('Ihre PHP-Version %s ist veraltet. Bitte aktualisieren Sie mindestens auf die PHP-Version %s.', 'rrze-post-expiration'), PHP_VERSION, self::php_version);
} elseif (version_compare($GLOBALS['wp_version'], self::wp_version, '<')) {
$error = sprintf(__('Ihre Wordpress-Version %s ist veraltet. Bitte aktualisieren Sie mindestens auf die Wordpress-Version %s.', 'rrze-post-expiration'), $GLOBALS['wp_version'], self::wp_version);
}
if (!empty($error)) {
deactivate_plugins(plugin_basename(__FILE__), false, true);
wp_die($error);
}
}
public static function expiration_date_column($columns) {
global $post_type;
if ($post_type != 'post')
return $columns;
$columns['expiration_date'] = __('Verfallsdatum', 'rrze-post-expiration');
return $columns;
}
public static function expiration_date_custom_colum($column, $post_id) {
if ($column != 'expiration_date')
return;
$post = get_post($post_id);
if ($post->post_type != 'post')
return;
$expiration_date = get_post_meta($post->ID, 'expiration_date', 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)
echo '<br/>', __('Keine', 'rrze-post-expiration');
else {
$t_time = date(__('Y/m/d g:i:s A'), mysql2date('U', $expiration_date));
$m_time = $expiration_date;
$time = mysql2date('G', $expiration_date_gmt);
$time_diff = $time - time();
if ($time_diff > 0 && $time_diff < 24 * 60 * 60)
$h_time = sprintf(__('in %s'), human_time_diff($time));
elseif ($time_diff < 0 && abs($time_diff) < 24 * 60 * 60)
$h_time = sprintf(__('%s ago'), human_time_diff($time));
else
$h_time = mysql2date(__('Y/m/d'), $m_time);
echo '<abbr title="' . $t_time . '">' . $h_time . '</abbr>';
if ($time_diff < 0)
echo '<br/>', __('Abgelaufen', 'rrze-post-expiration');
}
}
public static function exp_meta_box() {
global $post, $post_type, $post_type_object;
if ($post_type != 'post')
return;
$can_publish = current_user_can($post_type_object->cap->publish_posts);
if ($can_publish) :
$cur_time = strtotime(current_time('mysql'));
$datef = __('M j, Y @ H:i');
$date = date_i18n($datef, $cur_time);
$stamp = __('Verfallsdatum <b>deaktiviert</b>', 'rrze-post-expiration');
if (0 != $post->ID) {
$expiration_date = get_post_meta($post->ID, 'expiration_date', true);
if ($expiration_date) {
$exp_time = strtotime($expiration_date);
if ($exp_time > $cur_time) {
$stamp = __('Verfällt am: <b>%s</b>', 'rrze-post-expiration');
} else {
$stamp = __('Abgelaufen am: <b>%s</b>', 'rrze-post-expiration');
}
$enabled = ' checked="checked"';
$date = date_i18n($datef, strtotime($expiration_date));
}
}
?>
<div class="misc-pub-section curtime misc-pub-section-last">
<span id="timestamp" class="exp_timestamp">
<?php printf($stamp, $date); ?></span>
<a href="#edit_exp_timestamp" class="edit-exp-timestamp hide-if-no-js" tabindex="4"><?php _e('Edit', 'rrze-post-expiration') ?></a>
<div id="exp_timestampdiv" class="hide-if-js">
<?php self::expire_time(); ?>
</div>
</div>
<?php
endif;
}
private static function expire_time() {
global $wp_locale, $post;
$expiration_date = get_post_meta($post->ID, 'expiration_date', true);
$expiration_date_gmt = get_post_meta($post->ID, 'expiration_date_gmt', true);
$enabled = '';
if ($expiration_date) {
$enabled = ' checked="checked"';
}
$edit = !(!$expiration_date );
$time_adj = current_time('timestamp');
$jj = ($edit) ? mysql2date('d', $expiration_date, false) : gmdate('d', $time_adj);
$mm = ($edit) ? mysql2date('m', $expiration_date, false) : gmdate('m', $time_adj);
$aa = ($edit) ? mysql2date('Y', $expiration_date, false) : gmdate('Y', $time_adj);
$hh = ($edit) ? mysql2date('H', $expiration_date, false) : gmdate('H', $time_adj);
$mn = ($edit) ? mysql2date('i', $expiration_date, false) : gmdate('i', $time_adj);
$ss = ($edit) ? mysql2date('s', $expiration_date, false) : gmdate('s', $time_adj);
$cur_jj = gmdate('d', $time_adj);
$cur_mm = gmdate('m', $time_adj);
$cur_aa = gmdate('Y', $time_adj);
$cur_hh = gmdate('H', $time_adj);
$cur_mn = gmdate('i', $time_adj);
$month = "<select id=\"exp_mm\" name=\"exp_mm\" tabindex=\"4\" style=\"height:20px; line-height:14px; padding:0; vertical-align:top;\">\n";
for ($i = 1; $i < 13; $i = $i + 1) {
$month .= "\t\t\t" . '<option value="' . zeroise($i, 2) . '"';
if ($i == $mm)
$month .= ' selected="selected"';
$month .= '>' . $wp_locale->get_month_abbrev($wp_locale->get_month($i)) . "</option>\n";
}
$month .= '</select>';
$day = '<input type="text" id="exp_jj" name="exp_jj" value="' . $jj . '" size="2" maxlength="2" tabindex="4" autocomplete="off" style="font-size:12px; padding:1px; width:2em;" />';
$year = '<input type="text" id="exp_aa" name="exp_aa" value="' . $aa . '" size="4" maxlength="4" tabindex="4" autocomplete="off" style="font-size:12px; padding:1px; width:3.4em;" />';
$hour = '<input type="text" id="exp_hh" name="exp_hh" value="' . $hh . '" size="2" maxlength="2" tabindex="4" autocomplete="off" style="font-size:12px; padding:1px; width:2em;" />';
$minute = '<input type="text" id="exp_mn" name="exp_mn" value="' . $mn . '" size="2" maxlength="2" tabindex="4" autocomplete="off" style="font-size:12px; padding:1px; width:2em;" />';
echo '<div class="exp-timestamp-wrap">';
echo '<p style="margin:0.5em 0;"><input type="checkbox" name="enable_expiration" id="enable_expiration" value="checked"' . $enabled . ' />';
echo '<label class="selectit" for="enable_expiration">' . __('Verfallsdatum aktivieren', 'rrze-post-expiration') . '</label></p>';
/* 1: month input, 2: day input, 3: year input, 4: hour input, 5: minute input */
printf(__('%1$s%2$s, %3$s @ %4$s : %5$s'), $month, $day, $year, $hour, $minute);
echo '</div><input type="hidden" id="exp_ss" name="exp_ss" value="' . $ss . '" />';
echo "\n\n";
if ($enabled)
echo '<input type="hidden" id="exp_enabled" name="exp_enabled" value="1" />';
else
echo '<input type="hidden" id="exp_enabled" name="exp_enabled" value="0" />';
echo "\n\n";
foreach (array('mm', 'jj', 'aa', 'hh', 'mn') as $timeunit) {
echo '<input type="hidden" id="exp_hidden_' . $timeunit . '" name="hidden_' . $timeunit . '" value="' . $$timeunit . '" />' . "\n";
$cur_timeunit = 'cur_' . $timeunit;
echo '<input type="hidden" id="exp_' . $cur_timeunit . '" name="exp_' . $cur_timeunit . '" value="' . $$cur_timeunit . '" />' . "\n";
}
?>
<p>
<a href="#edit_exp_timestamp" class="save-exp-timestamp hide-if-no-js button"><?php _e('OK'); ?></a>
<a href="#edit_exp_timestamp" class="cancel-exp-timestamp hide-if-no-js"><?php _e('Cancel'); ?></a>
</p>
<?php
}
public static function expiration_js() {
?>
<script type="text/javascript">
//<![CDATA[
var $j = jQuery.noConflict();
$j(function () {
enabled = $j('#exp_enabled').val();
$j('#exp_timestampdiv').siblings('a.edit-exp-timestamp').click(function () {
if ($j('#exp_timestampdiv').is(":hidden")) {
$j('#exp_timestampdiv').slideDown("normal");
$j(this).hide();
}
return false;
});
$j('.cancel-exp-timestamp', '#exp_timestampdiv').click(function () {
$j('#exp_timestampdiv').slideUp("normal");
$j('#exp_mm').val($j('#exp_hidden_mm').val());
$j('#exp_jj').val($j('#exp_hidden_jj').val());
$j('#exp_aa').val($j('#exp_hidden_aa').val());
$j('#exp_hh').val($j('#exp_hidden_hh').val());
$j('#exp_mn').val($j('#exp_hidden_mn').val());
$j('#exp_timestampdiv').siblings('a.edit-exp-timestamp').show();
updateExpiration();
return false;
});
$j('.save-exp-timestamp', '#exp_timestampdiv').click(function () {
if (updateExpiration()) {
$j('#exp_timestampdiv').slideUp("normal");
$j('#exp_timestampdiv').siblings('a.edit-exp-timestamp').show();
}
return false;
});
function updateExpiration() {
var stamp = $j('.exp_timestamp').html(), attemptedDate, postDate, currentDate,
postStatus = $j('#post_status'), optPublish = $j('option[value=publish]', postStatus), aa = $j('#exp_aa').val(),
mm = $j('#exp_mm').val(), jj = $j('#exp_jj').val(), hh = $j('#exp_hh').val(), mn = $j('#exp_mn').val(), txt = '';
attemptedDate = new Date(aa, mm - 1, jj, hh, mn);
postDate = new Date($j('#exp_hidden_aa').val(), $j('#exp_hidden_mm').val() - 1, $j('#exp_hidden_jj').val(), $j('#exp_hidden_hh').val(), $j('#exp_hidden_mn').val());
currentDate = new Date($j('#exp_cur_aa').val(), $j('#exp_cur_mm').val() - 1, $j('#exp_cur_jj').val(), $j('#exp_cur_hh').val(), $j('#exp_cur_mn').val());
if (attemptedDate.getFullYear() != aa || (1 + attemptedDate.getMonth()) != mm || attemptedDate.getDate() != jj || attemptedDate.getMinutes() != mn) {
$j('.exp-timestamp-wrap', '#exp_timestampdiv').addClass('form-invalid');
return false;
} else {
$j('.exp-timestamp-wrap', '#exp_timestampdiv').removeClass('form-invalid');
}
if ($j('#enable_expiration').attr('checked') == 'checked') {
if (attemptedDate > currentDate)
txt = '<?php _e('Verfällt am:', 'rrze-post-expiration'); ?>';
else
txt = '<?php _e('Abgelaufen am:', 'rrze-post-expiration'); ?>';
if (postDate.toUTCString() == attemptedDate.toUTCString() && enabled == 1) {
$j('.exp_timestamp').html(stamp);
} else {
$j('.exp_timestamp').html(
txt + ' <b>' +
$j('option[value=' + $j('#exp_mm').val() + ']', '#exp_mm').text() + ' ' +
jj + ', ' +
aa + ' @ ' +
hh + ':' +
mn + '</b> '
);
}
} else {
enabled = 0;
$j('.exp_timestamp').html('<?php _e('Verfallsdatum <b>deaktiviert</b>', 'rrze-post-expiration'); ?>');
}
return true;
}
});
//]]>
</script>
<?php
}
public static function update_post_expiration_date() {
global $current_blog, $post;
if (!$post || $post->post_type != 'post')
return;
delete_post_meta($post->ID, 'expiration_date');
delete_post_meta($post->ID, 'expiration_date_gmt');
if (isset($_POST['enable_expiration'])) {
$aa = $_POST['exp_aa'];
$mm = $_POST['exp_mm'];
$jj = $_POST['exp_jj'];
$hh = $_POST['exp_hh'];
$mn = $_POST['exp_mn'];
$ss = $_POST['exp_ss'];
$aa = ($aa <= 0 ) ? date('Y') : $aa;
$mm = ($mm <= 0 ) ? date('n') : $mm;
$jj = ($jj > 31 ) ? 31 : $jj;
$jj = ($jj <= 0 ) ? date('j') : $jj;
$hh = ($hh > 23 ) ? $hh - 24 : $hh;
$mn = ($mn > 59 ) ? $mn - 60 : $mn;
$ss = ($ss > 59 ) ? $ss - 60 : $ss;
$ts = sprintf("%04d-%02d-%02d %02d:%02d:%02d", $aa, $mm, $jj, $hh, $mn, $ss);
update_post_meta($post->ID, 'expiration_date', $ts, true);
$ts_gmt = get_gmt_from_date($ts);
update_post_meta($post->ID, 'expiration_date_gmt', $ts_gmt, true);
$cron_hook = sprintf('%s_%s', self::option_name, $current_blog->blog_id);
wp_clear_scheduled_hook($cron_hook);
wp_schedule_event(time(), 'two-minutes', $cron_hook);
}
}
public static function add_cron_schedule($schedules) {
$schedules['two-minutes'] = array(
'interval' => 120,
'display' => __('Every Two Minutes')
);
return $schedules;
}
public static function set_expired_posts() {
global $wpdb;
$cur_date = current_time('mysql');
$result = $wpdb->get_results(
"SELECT post_id
FROM " . $wpdb->postmeta . " as postmeta
LEFT JOIN " . $wpdb->posts . " as posts ON postmeta.post_id = posts.ID
WHERE posts.post_status = 'publish' AND posts.post_type = 'post'
AND postmeta.meta_key = 'expiration_date'
AND postmeta.meta_value <= '" . $cur_date . "'");
if (!empty($result)) {
foreach ($result as $row) {
wp_update_post(array('ID' => $row->post_id, 'post_status' => 'draft'));
}
}
}
}
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment