add initial support for setting image sizes in theme options

This commit is contained in:
John Bintz 2009-07-06 22:45:17 -04:00
parent 8b34c320c3
commit e72e6c39a6
6 changed files with 92 additions and 7 deletions

View File

@ -1,6 +1,6 @@
<?php <?php
include(TEMPLATEPATH . '/comicpress-config.php'); include(dirname(__FILE__) . '/comicpress-config.php');
// If any errors occur while searching for a comic file, the error messages will be pushed into here. // If any errors occur while searching for a comic file, the error messages will be pushed into here.
$comic_pathfinding_errors = array(); $comic_pathfinding_errors = array();
@ -48,6 +48,29 @@ function get_last_comic() {
return get_terminal_post_in_category(get_all_comic_categories_as_cat_string(), false); return get_terminal_post_in_category(get_all_comic_categories_as_cat_string(), false);
} }
function the_comic_img_tag($url, $type, $additional_parameters = array()) {
global $comicpress_options_admin;
$dimensions = array();
if (isset($comicpress_options_admin->comicpress_options["${type}_dimensions"])) {
list($width, $height) = explode("x", $comicpress_options_admin->comicpress_options["${type}_dimensions"]);
$dimensions = compact('width', 'height');
}
echo '<img src="' . $url . '" ';
foreach (array('width', 'height') as $field) {
if (!empty($dimensions[$field])) {
echo $field . '="' . $dimensions[$field] . '" ';
}
}
if (is_array($additional_parameters)) {
foreach ($additional_parameters as $parameter => $value) {
echo $parameter . '="' . $value . '" ';
}
}
echo "/>";
}
/** /**
* Get the hyperlink to the first comic post in the database. * Get the hyperlink to the first comic post in the database.
* @return string The hyperlink to the first comic post, or false. * @return string The hyperlink to the first comic post, or false.
@ -357,8 +380,12 @@ function comicpress_list_storyline_categories($args = "") {
* Text is taken from a custom field named "hovertext" * Text is taken from a custom field named "hovertext"
*/ */
function the_hovertext() { function the_hovertext() {
$hovertext = get_post_meta( get_the_ID(), "hovertext", true ); echo get_the_hovertext();
echo (empty($hovertext)) ? get_the_title() : $hovertext; }
function get_the_hovertext() {
$hovertext = get_post_meta(get_the_ID(), "hovertext", true );
return (empty($hovertext)) ? get_the_title() : $hovertext;
} }
/** /**

View File

@ -1,5 +1,10 @@
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" <?php language_attributes() ?>> <html xmlns="http://www.w3.org/1999/xhtml" <?php language_attributes() ?>>
<?php
$result = get_option('comicpress-options');
if (!empty($result)) { extract($result); }
var_dump($result);
?>
<head profile="http://gmpg.org/xfn/11"> <head profile="http://gmpg.org/xfn/11">
<title><?php <title><?php

View File

@ -6,7 +6,8 @@
while ($comicFrontpage->have_posts()) : $comicFrontpage->the_post() ?> while ($comicFrontpage->have_posts()) : $comicFrontpage->the_post() ?>
<div id="comic-head"></div> <div id="comic-head"></div>
<div id="comic"> <div id="comic">
<img src="<?php the_comic() ?>" alt="<?php the_title() ?>" title="<?php the_hovertext() ?>" /> <?php the_comic_img_tag(get_comic_url('comic'), 'comic', array('alt' => get_the_title(),
'title' => get_the_hovertext())) ?>
</div> </div>
<div id="comic-foot"></div> <div id="comic-foot"></div>
<?php endwhile; ?> <?php endwhile; ?>

View File

@ -5,7 +5,7 @@ class ComicPressOptionsAdmin {
'comic_category_id' => 1, 'comic_category_id' => 1,
'comic_dimensions' => '760x', 'comic_dimensions' => '760x',
'rss_dimensions' => '350x', 'rss_dimensions' => '350x',
'thumbnail_dimensions' => '125x' 'archive_dimensions' => '125x'
); );
function render_admin() { function render_admin() {
@ -97,7 +97,7 @@ class ComicPressOptionsAdmin {
break; break;
case 'comic_dimensions': case 'comic_dimensions':
case 'rss_dimensions': case 'rss_dimensions':
case 'thumbnail_dimensions': case 'archive_dimensions':
if (is_array($_POST['cp'][$option])) { if (is_array($_POST['cp'][$option])) {
$dim_parts = array(); $dim_parts = array();
$is_valid = true; $is_valid = true;
@ -125,10 +125,16 @@ class ComicPressOptionsAdmin {
$this->update_comicpress_options(); $this->update_comicpress_options();
} }
} }
function init() {
$this->get_comicpress_options();
}
} }
$comicpress_options_admin = new ComicPressOptionsAdmin(); $comicpress_options_admin = new ComicPressOptionsAdmin();
add_action('init', array(&$comicpress_options_admin, 'init'));
function __comicpress_add_options_admin() { function __comicpress_add_options_admin() {
global $comicpress_options_admin; global $comicpress_options_admin;
add_theme_page(__("ComicPress Options", 'comicpress'), __('ComicPress Options', 'comicpress'), 'edit_themes', basename(__FILE__), array($comicpress_options_admin, 'render_admin')); add_theme_page(__("ComicPress Options", 'comicpress'), __('ComicPress Options', 'comicpress'), 'edit_themes', basename(__FILE__), array($comicpress_options_admin, 'render_admin'));

View File

@ -14,7 +14,7 @@
<?php foreach (array( <?php foreach (array(
'comic_dimensions' => __('Comic Image Dimensions', 'comicpress'), 'comic_dimensions' => __('Comic Image Dimensions', 'comicpress'),
'rss_dimensions' => __('RSS Feed Image Dimensions', 'comicpress'), 'rss_dimensions' => __('RSS Feed Image Dimensions', 'comicpress'),
'thumbnail_dimensions' => __('Thumbnail Image Dimensions', 'comicpress'), 'archive_dimensions' => __('Archive Image Dimensions', 'comicpress'),
) as $field => $name) { ?> ) as $field => $name) { ?>
<tr> <tr>
<th scope="row"><?php echo $name ?></th> <th scope="row"><?php echo $name ?></th>

46
test/FunctionsTest.php Normal file
View File

@ -0,0 +1,46 @@
<?php
require_once('PHPUnit/Framework.php');
require_once(dirname(__FILE__) . '/../../mockpress/mockpress.php');
require_once(dirname(__FILE__) . '/../functions.php');
class FunctionsTest extends PHPUnit_Framework_TestCase {
function providerTestGenerateComicTag() {
return array(
array(
"150x150",
),
array(
false,
)
);
}
/**
* @dataProvider providerTestGenerateComicTag
*/
function testGenerateComicImgTag($dimensions) {
global $comicpress_options_admin;
$comicpress_options_admin->comicpress_options['comic_dimensions'] = $dimensions;
ob_start();
the_comic_img_tag("test.gif", "comic");
$source = ob_get_clean();
if (count($parts = explode("x", $dimensions)) == 2) {
list($width, $height) = $parts;
$dimensions = compact('width', 'height');
}
foreach (array('width', 'height') as $field) {
if (isset($dimensions[$field])) {
$this->assertTrue(strpos($source, "${field}=\"{$dimensions[$field]}\"") !== false, $field);
} else {
$this->assertTrue(strpos($source, "${field}=") === false, 'not set');
}
}
}
}
?>