rip out non-WP styled code and fix widow issue
This commit is contained in:
parent
14a971af2d
commit
13da782514
|
@ -4,8 +4,7 @@ class DailyImageWidget {
|
|||
function DailyImageWidget($skip_load_data = false) {
|
||||
$this->default_display_options = array(
|
||||
'title',
|
||||
'image',
|
||||
'styles'
|
||||
'image'
|
||||
);
|
||||
|
||||
$this->_cache_time = 86400;
|
||||
|
@ -18,8 +17,7 @@ class DailyImageWidget {
|
|||
$this->_valid_options = array(
|
||||
"image" => __("Daily Image", "hubblesite-daily-image-widget"),
|
||||
"title" => __("Image Title", "hubblesite-daily-image-widget"),
|
||||
"credits" => __("Credits", "hubblesite-daily-image-widget"),
|
||||
"styles" => __("HubbleSite Styles", "hubblesite-daily-image-widget"),
|
||||
"credits" => __("Credits", "hubblesite-daily-image-widget")
|
||||
);
|
||||
|
||||
add_action('init', array($this, "_init"));
|
||||
|
@ -103,13 +101,15 @@ class DailyImageWidget {
|
|||
/**
|
||||
* Render the widget.
|
||||
*/
|
||||
function render() {
|
||||
function render($args) {
|
||||
if (!empty($this->data) && is_array($this->data)) {
|
||||
extract($args);
|
||||
$options = $this->get_display_options();
|
||||
|
||||
echo '<div id="hubblesite-daily-image">';
|
||||
echo '<p id="hubblesite-daily-image-header">HubbleSite Daily Image</p>';
|
||||
|
||||
echo $before_widget;
|
||||
echo $before_title;
|
||||
echo "HubbleSite Daily Image";
|
||||
echo $after_title;
|
||||
if (in_array("image", $options)) {
|
||||
echo '<a href="' . $this->data['gallery_url'] . '" title="' . $this->data['title'] . '">';
|
||||
echo '<img src="' . $this->data['image_url'] . '" alt="' . $this->data['title'] . '" width="100%" />';
|
||||
|
@ -118,22 +118,16 @@ class DailyImageWidget {
|
|||
|
||||
if (in_array("title", $options)) {
|
||||
echo '<a id="hubblesite-daily-image-title" href="' . $this->data['gallery_url'] . '">';
|
||||
echo $this->data['title'];
|
||||
echo $this->_fix_widows($this->data['title']);
|
||||
echo '</a>';
|
||||
}
|
||||
|
||||
if (in_array("credits", $options)) {
|
||||
echo '<div id="hubblesite-daily-image-credits">';
|
||||
echo $this->data['credits'];
|
||||
echo $this->_fix_widows($this->data['credits']);
|
||||
echo '</div>';
|
||||
}
|
||||
echo '</div>';
|
||||
|
||||
if (in_array("styles", $options)) {
|
||||
echo "<style type=\"text/css\">";
|
||||
include(dirname(__FILE__) . '/../hubblesite-styles.css');
|
||||
echo "</style>";
|
||||
}
|
||||
echo $after_widget;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -240,6 +234,10 @@ class DailyImageWidget {
|
|||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
function _fix_widows($text) {
|
||||
return preg_replace("#([^\ ]+)\ ([^\ \>]+)($|</p>|</a>)#", '\1 \2\3', $text);
|
||||
}
|
||||
}
|
||||
|
||||
function the_hubblesite_daily_image_widget() {
|
||||
|
|
|
@ -59,27 +59,21 @@ class DailyImageWidgetTest extends PHPUnit_Framework_TestCase {
|
|||
array(
|
||||
"image",
|
||||
array(
|
||||
'//div[@id="hubblesite-daily-image"]' => true,
|
||||
'//div/a[@href="gallery_url" and @title="title"]' => true,
|
||||
'//div/a/img[@src="image_url" and @alt="title"]' => true,
|
||||
'//div[@id="hubblesite-daily-image"]' => false,
|
||||
'//a[@href="gallery_url" and @title="title"]' => true,
|
||||
'//a/img[@src="image_url" and @alt="title"]' => true,
|
||||
)
|
||||
),
|
||||
array(
|
||||
"title",
|
||||
array(
|
||||
'//div/a[@href="gallery_url" and @id="hubblesite-daily-image-title"]' => "title"
|
||||
)
|
||||
),
|
||||
array(
|
||||
"styles",
|
||||
array(
|
||||
'//style[@type="text/css"]' => true
|
||||
'//a[@href="gallery_url" and @id="hubblesite-daily-image-title"]' => "title"
|
||||
)
|
||||
),
|
||||
array(
|
||||
"credits",
|
||||
array(
|
||||
'//div/div[@id="hubblesite-daily-image-credits"]' => 'credits'
|
||||
'//div[@id="hubblesite-daily-image-credits"]' => 'credits'
|
||||
)
|
||||
)
|
||||
);
|
||||
|
@ -92,7 +86,12 @@ class DailyImageWidgetTest extends PHPUnit_Framework_TestCase {
|
|||
update_option('hubblesite-daily-image-options', $option_string);
|
||||
|
||||
ob_start();
|
||||
$this->diw->render();
|
||||
$this->diw->render(array(
|
||||
'before_widget' => "",
|
||||
'after_widget' => "",
|
||||
'before_title' => "",
|
||||
'after_title' => ""
|
||||
));
|
||||
$result = ob_get_clean();
|
||||
|
||||
$this->assertTrue(!empty($result));
|
||||
|
@ -105,8 +104,8 @@ class DailyImageWidgetTest extends PHPUnit_Framework_TestCase {
|
|||
|
||||
function providerTestGetDisplayOptions() {
|
||||
return array(
|
||||
array("", array("title", "image", "styles")),
|
||||
array("meow", array("title", "image", "styles")),
|
||||
array("", array("title", "image")),
|
||||
array("meow", array("title", "image")),
|
||||
array("title", array("title")),
|
||||
array("title,image", array("title", "image")),
|
||||
array("title,meow", array("title"))
|
||||
|
@ -302,6 +301,14 @@ class DailyImageWidgetTest extends PHPUnit_Framework_TestCase {
|
|||
$this->assertTrue($diw->_load_data());
|
||||
$this->assertTrue(is_array(get_option('hubblesite-daily-image-cache')));
|
||||
}
|
||||
|
||||
function testWidowProtection() {
|
||||
$this->assertEquals("this is fixed", $this->diw->_fix_widows("this is fixed"));
|
||||
$this->assertEquals("<p>this is fixed</p>", $this->diw->_fix_widows("<p>this is fixed</p>"));
|
||||
$this->assertEquals("<a>this is fixed</a>", $this->diw->_fix_widows("<a>this is fixed</a>"));
|
||||
$this->assertEquals("<a href='meow'>word</a>", $this->diw->_fix_widows("<a href='meow'>word</a>"));
|
||||
$this->assertEquals("<p>this is fixed</p><p>Also fixed</p>", $this->diw->_fix_widows("<p>this is fixed</p><p>Also fixed</p>"));
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
Loading…
Reference in New Issue