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) {
|
function DailyImageWidget($skip_load_data = false) {
|
||||||
$this->default_display_options = array(
|
$this->default_display_options = array(
|
||||||
'title',
|
'title',
|
||||||
'image',
|
'image'
|
||||||
'styles'
|
|
||||||
);
|
);
|
||||||
|
|
||||||
$this->_cache_time = 86400;
|
$this->_cache_time = 86400;
|
||||||
@ -18,8 +17,7 @@ class DailyImageWidget {
|
|||||||
$this->_valid_options = array(
|
$this->_valid_options = array(
|
||||||
"image" => __("Daily Image", "hubblesite-daily-image-widget"),
|
"image" => __("Daily Image", "hubblesite-daily-image-widget"),
|
||||||
"title" => __("Image Title", "hubblesite-daily-image-widget"),
|
"title" => __("Image Title", "hubblesite-daily-image-widget"),
|
||||||
"credits" => __("Credits", "hubblesite-daily-image-widget"),
|
"credits" => __("Credits", "hubblesite-daily-image-widget")
|
||||||
"styles" => __("HubbleSite Styles", "hubblesite-daily-image-widget"),
|
|
||||||
);
|
);
|
||||||
|
|
||||||
add_action('init', array($this, "_init"));
|
add_action('init', array($this, "_init"));
|
||||||
@ -103,13 +101,15 @@ class DailyImageWidget {
|
|||||||
/**
|
/**
|
||||||
* Render the widget.
|
* Render the widget.
|
||||||
*/
|
*/
|
||||||
function render() {
|
function render($args) {
|
||||||
if (!empty($this->data) && is_array($this->data)) {
|
if (!empty($this->data) && is_array($this->data)) {
|
||||||
|
extract($args);
|
||||||
$options = $this->get_display_options();
|
$options = $this->get_display_options();
|
||||||
|
|
||||||
echo '<div id="hubblesite-daily-image">';
|
echo $before_widget;
|
||||||
echo '<p id="hubblesite-daily-image-header">HubbleSite Daily Image</p>';
|
echo $before_title;
|
||||||
|
echo "HubbleSite Daily Image";
|
||||||
|
echo $after_title;
|
||||||
if (in_array("image", $options)) {
|
if (in_array("image", $options)) {
|
||||||
echo '<a href="' . $this->data['gallery_url'] . '" title="' . $this->data['title'] . '">';
|
echo '<a href="' . $this->data['gallery_url'] . '" title="' . $this->data['title'] . '">';
|
||||||
echo '<img src="' . $this->data['image_url'] . '" alt="' . $this->data['title'] . '" width="100%" />';
|
echo '<img src="' . $this->data['image_url'] . '" alt="' . $this->data['title'] . '" width="100%" />';
|
||||||
@ -118,22 +118,16 @@ class DailyImageWidget {
|
|||||||
|
|
||||||
if (in_array("title", $options)) {
|
if (in_array("title", $options)) {
|
||||||
echo '<a id="hubblesite-daily-image-title" href="' . $this->data['gallery_url'] . '">';
|
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>';
|
echo '</a>';
|
||||||
}
|
}
|
||||||
|
|
||||||
if (in_array("credits", $options)) {
|
if (in_array("credits", $options)) {
|
||||||
echo '<div id="hubblesite-daily-image-credits">';
|
echo '<div id="hubblesite-daily-image-credits">';
|
||||||
echo $this->data['credits'];
|
echo $this->_fix_widows($this->data['credits']);
|
||||||
echo '</div>';
|
echo '</div>';
|
||||||
}
|
}
|
||||||
echo '</div>';
|
echo $after_widget;
|
||||||
|
|
||||||
if (in_array("styles", $options)) {
|
|
||||||
echo "<style type=\"text/css\">";
|
|
||||||
include(dirname(__FILE__) . '/../hubblesite-styles.css');
|
|
||||||
echo "</style>";
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -240,6 +234,10 @@ class DailyImageWidget {
|
|||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function _fix_widows($text) {
|
||||||
|
return preg_replace("#([^\ ]+)\ ([^\ \>]+)($|</p>|</a>)#", '\1 \2\3', $text);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function the_hubblesite_daily_image_widget() {
|
function the_hubblesite_daily_image_widget() {
|
||||||
|
@ -59,27 +59,21 @@ class DailyImageWidgetTest extends PHPUnit_Framework_TestCase {
|
|||||||
array(
|
array(
|
||||||
"image",
|
"image",
|
||||||
array(
|
array(
|
||||||
'//div[@id="hubblesite-daily-image"]' => true,
|
'//div[@id="hubblesite-daily-image"]' => false,
|
||||||
'//div/a[@href="gallery_url" and @title="title"]' => true,
|
'//a[@href="gallery_url" and @title="title"]' => true,
|
||||||
'//div/a/img[@src="image_url" and @alt="title"]' => true,
|
'//a/img[@src="image_url" and @alt="title"]' => true,
|
||||||
)
|
)
|
||||||
),
|
),
|
||||||
array(
|
array(
|
||||||
"title",
|
"title",
|
||||||
array(
|
array(
|
||||||
'//div/a[@href="gallery_url" and @id="hubblesite-daily-image-title"]' => "title"
|
'//a[@href="gallery_url" and @id="hubblesite-daily-image-title"]' => "title"
|
||||||
)
|
|
||||||
),
|
|
||||||
array(
|
|
||||||
"styles",
|
|
||||||
array(
|
|
||||||
'//style[@type="text/css"]' => true
|
|
||||||
)
|
)
|
||||||
),
|
),
|
||||||
array(
|
array(
|
||||||
"credits",
|
"credits",
|
||||||
array(
|
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);
|
update_option('hubblesite-daily-image-options', $option_string);
|
||||||
|
|
||||||
ob_start();
|
ob_start();
|
||||||
$this->diw->render();
|
$this->diw->render(array(
|
||||||
|
'before_widget' => "",
|
||||||
|
'after_widget' => "",
|
||||||
|
'before_title' => "",
|
||||||
|
'after_title' => ""
|
||||||
|
));
|
||||||
$result = ob_get_clean();
|
$result = ob_get_clean();
|
||||||
|
|
||||||
$this->assertTrue(!empty($result));
|
$this->assertTrue(!empty($result));
|
||||||
@ -105,8 +104,8 @@ class DailyImageWidgetTest extends PHPUnit_Framework_TestCase {
|
|||||||
|
|
||||||
function providerTestGetDisplayOptions() {
|
function providerTestGetDisplayOptions() {
|
||||||
return array(
|
return array(
|
||||||
array("", array("title", "image", "styles")),
|
array("", array("title", "image")),
|
||||||
array("meow", array("title", "image", "styles")),
|
array("meow", array("title", "image")),
|
||||||
array("title", array("title")),
|
array("title", array("title")),
|
||||||
array("title,image", array("title", "image")),
|
array("title,image", array("title", "image")),
|
||||||
array("title,meow", array("title"))
|
array("title,meow", array("title"))
|
||||||
@ -302,6 +301,14 @@ class DailyImageWidgetTest extends PHPUnit_Framework_TestCase {
|
|||||||
$this->assertTrue($diw->_load_data());
|
$this->assertTrue($diw->_load_data());
|
||||||
$this->assertTrue(is_array(get_option('hubblesite-daily-image-cache')));
|
$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
Block a user