comic date widget
This commit is contained in:
parent
85844be3e8
commit
bf603ec8db
|
@ -0,0 +1,36 @@
|
|||
<?php
|
||||
|
||||
require_once('PHPUnit/Framework.php');
|
||||
require_once('MockPress/mockpress.php');
|
||||
require_once(dirname(__FILE__) . '/../../widgets/ComicDateWidget.inc');
|
||||
|
||||
class ComicDateWidgetTest extends PHPUnit_Framework_TestCase {
|
||||
function setUp() {
|
||||
_reset_wp();
|
||||
$this->w = new ComicDateWidget();
|
||||
}
|
||||
|
||||
function providerTestFilterInstance() {
|
||||
return array(
|
||||
array(array(), array('format' => 'F jS, Y')),
|
||||
array(array('title' => 'test'), array('title' => 'test', 'format' => 'F jS, Y')),
|
||||
array(array('title' => '<em>test</em>'), array('title' => 'test', 'format' => 'F jS, Y')),
|
||||
array(array('title' => '<em>test</em>', 'format' => 'test'), array('title' => 'test', 'format' => 'test')),
|
||||
array(array('title' => '<em>test</em>', 'format' => ''), array('title' => 'test', 'format' => 'F jS, Y')),
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider providerTestFilterInstance
|
||||
*/
|
||||
function testFilterInstance($new_instance, $expected_result) {
|
||||
$this->assertEquals($expected_result, $this->w->_filter_instance($new_instance, array()));
|
||||
}
|
||||
|
||||
function testUpdate() {
|
||||
$w = $this->getMock('ComicDateWidget', array('_filter_instance'));
|
||||
$w->expects($this->once())->method('_filter_instance');
|
||||
|
||||
$w->update(array(), array());
|
||||
}
|
||||
}
|
|
@ -0,0 +1,72 @@
|
|||
<?php
|
||||
/*
|
||||
Widget Name: Comic Date
|
||||
Widget URI: http://comicpress.org/
|
||||
Description: Display's the date of post of the comic.
|
||||
Author: Philip M. Hofer (Frumph)
|
||||
Version: 1.01
|
||||
Author URI: http://frumph.net/
|
||||
*/
|
||||
|
||||
class ComicDateWidget extends WP_Widget {
|
||||
function ComicDateWidget() {
|
||||
$widget_ops = array('classname' => 'ComicDateWidget', 'description' => __('Displays the date of the post of the comic.','comicpress') );
|
||||
$this->WP_Widget('comic_date', __('Comic Date','comicpress'), $widget_ops);
|
||||
}
|
||||
|
||||
// @codeCoverageIgnoreStart
|
||||
function widget($args, $instance) {
|
||||
extract($args, EXTR_SKIP);
|
||||
|
||||
echo $before_widget;
|
||||
$title = empty($instance['title']) ? '' : apply_filters('widget_title', $instance['title']);
|
||||
if ( !empty( $title ) ) { echo $title; } ?> <?php the_time($instance['format']); ?>
|
||||
<?php echo $after_widget;
|
||||
}
|
||||
// @codeCoverageIgnoreEnd
|
||||
|
||||
function _filter_instance($instance) {
|
||||
foreach (array('title', 'format') as $field) {
|
||||
if (isset($instance[$field])) {
|
||||
$instance[$field] = strip_tags($instance[$field]);
|
||||
}
|
||||
switch ($field) {
|
||||
case 'format':
|
||||
if (empty($instance[$field])) {
|
||||
$instance[$field] = 'F jS, Y';
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
return $instance;
|
||||
}
|
||||
|
||||
function update($new_instance, $old_instance) {
|
||||
return $this->_filter_instance($new_instance);
|
||||
}
|
||||
|
||||
// @codeCoverageIgnoreStart
|
||||
function form($instance) {
|
||||
$instance = wp_parse_args((array) $instance, array('title' => '', 'format' => ''));
|
||||
$instance = $this->_filter_instance($instance);
|
||||
|
||||
foreach (array(
|
||||
'title' => __('Words to use before date:', 'comicpress'),
|
||||
'format' => __('Format of the Time/Date:', 'comicpress'),
|
||||
) as $field => $title) {
|
||||
?><p>
|
||||
<label for="<?php echo esc_attr($this->get_field_id($field)); ?>">
|
||||
<?php echo esc_html($title); ?><br />
|
||||
<input class="widefat" id="<?php echo esc_attr($this->get_field_id($field)); ?>"
|
||||
name="<?php echo esc_attr($this->get_field_name($field)); ?>"
|
||||
type="text"
|
||||
value="<?php echo esc_attr($instance[$field]); ?>" />
|
||||
</label>
|
||||
</p><?php
|
||||
}
|
||||
?>
|
||||
<p><a href="http://us.php.net/manual/en/function.date.php" target="_blank"><?php _e('Date String Examples','comicpress'); ?></a></p>
|
||||
<?php
|
||||
}
|
||||
// @codeCoverageIgnoreEnd
|
||||
}
|
|
@ -1,59 +0,0 @@
|
|||
<?php
|
||||
/*
|
||||
Widget Name: Comic Date
|
||||
Widget URI: http://comicpress.org/
|
||||
Description: Display's the date of post of the comic.
|
||||
Author: Philip M. Hofer (Frumph)
|
||||
Version: 1.01
|
||||
Author URI: http://frumph.net/
|
||||
|
||||
*/
|
||||
|
||||
class widget_comicpress_comic_date extends WP_Widget {
|
||||
|
||||
function widget_comicpress_comic_date() {
|
||||
$widget_ops = array('classname' => 'widget_comicpress_comic_date', 'description' => __('Displays the date of the post of the comic.','comicpress') );
|
||||
$this->WP_Widget('comic_date', __('Comic Date','comicpress'), $widget_ops);
|
||||
}
|
||||
|
||||
function widget($args, $instance) {
|
||||
global $post;
|
||||
extract($args, EXTR_SKIP);
|
||||
|
||||
echo $before_widget;
|
||||
$title = empty($instance['title']) ? '' : apply_filters('widget_title', $instance['title']);
|
||||
if ( !empty( $title ) ) { echo $title; } ?> <?php the_time($instance['format']); ?>
|
||||
<?php echo $after_widget;
|
||||
}
|
||||
|
||||
function update($new_instance, $old_instance) {
|
||||
$instance = $old_instance;
|
||||
$instance['title'] = strip_tags($new_instance['title']);
|
||||
$instance['format'] = strip_tags($new_instance['format']);
|
||||
if (empty($instance['format'])) $instance['format'] = 'F jS, Y';
|
||||
return $instance;
|
||||
}
|
||||
|
||||
function form($instance) {
|
||||
$instance = wp_parse_args( (array) $instance, array( 'title' => '', 'format' => '' ) );
|
||||
$title = strip_tags($instance['title']);
|
||||
$format = strip_tags($instance['format']);
|
||||
if (empty($format)) $format = 'F jS, Y';
|
||||
?>
|
||||
<p><label for="<?php echo $this->get_field_id('title'); ?>"><?php _e('Words to use before date:','comicpress'); ?><br /><input class="widefat" id="<?php echo $this->get_field_id('title'); ?>" name="<?php echo $this->get_field_name('title'); ?>" type="text" value="<?php echo attribute_escape($title); ?>" /></label></p>
|
||||
<p><label for="<?php echo $this->get_field_id('format'); ?>"><?php _e('Format of the Time/Date:','comicpress'); ?><br /><input class="widefat" id="<?php echo $this->get_field_id('format'); ?>" name="<?php echo $this->get_field_name('format'); ?>" type="text" value="<?php echo attribute_escape($format); ?>" /></label></p>
|
||||
<p><a href="http://us.php.net/manual/en/function.date.php" target="_blank"><?php _e('Date String Examples','comicpress'); ?></a></p>
|
||||
|
||||
<?php
|
||||
}
|
||||
}
|
||||
register_widget('widget_comicpress_comic_date');
|
||||
|
||||
|
||||
function widget_comicpress_comic_date_init() {
|
||||
new widget_comicpress_comic_date();
|
||||
}
|
||||
|
||||
add_action('widgets_init', 'widget_comicpress_comic_date_init');
|
||||
|
||||
?>
|
Loading…
Reference in New Issue