Merge branch '2.9-release'

This commit is contained in:
John Bintz 2010-01-22 23:14:20 -05:00
commit 3613121c05
9 changed files with 332 additions and 9 deletions

View File

@ -30,6 +30,10 @@ class ComicPressMediaHandling {
if (isset($comic_filename_filters[$filter_to_use])) {
return $this->_convert_to_percent_filter($comic_filename_filters[$filter_to_use]);
}
$options = get_option('comicpress_options');
if (isset($options['comic_filename_filters'][$filter_to_use])) {
return $this->_convert_to_percent_filter($options['comic_filename_filters'][$filter_to_use]);
}
}
}
@ -96,6 +100,9 @@ class ComicPressMediaHandling {
case 'type-folder':
$value = $this->type_folder;
break;
case 'upload-path':
$value = get_option('upload_path');
break;
default:
if (preg_match('#^date-(.*)$#', $matches[1], $date_matches) > 0) {
if (isset($this->post_to_use)) {

View File

@ -19,6 +19,23 @@ function comicpress_admin_print_styles() {
wp_enqueue_style('comicpress-options', get_template_directory_uri() . '/options/options.css');
}
function comicpress_save_options_comic_filename_filters($incoming) {
$filters = array();
foreach (array_values($incoming) as $filter) {
$filters[wp_filter_nohtml_kses($filter['name'])] = wp_filter_nohtml_kses($filter['filter']);
}
if (!empty($filters)) {
if (!isset($filters['default'])) {
$cpmh = new ComicPressMediaHandling();
$filters['default'] = $cpmh->default_filter;
}
}
return $filters;
}
function comicpress_admin_page_head() { ?>
<!--[if lt ie 8]> <style> div.show { position: static; margin-top: 1px; } #cpadmin div.off { height: 22px; } </style> <![endif]-->
<?php }
@ -190,6 +207,13 @@ function comicpress_admin() {
) as $key) {
$comicpress_options['comicpress_config'][$key] = wp_filter_nohtml_kses($_REQUEST[$key]);
}
if (isset($_REQUEST['comic_filename_filters'])) {
$comicpress_options['comic_filename_filters'] = comicpress_save_options_comic_filename_filters($_REQUEST['comic_filename_filters']);
} else {
$comicpress_options['comic_filename_filters'] = array();
}
$tab = 'config';
update_option('comicpress_options',$comicpress_options);
}

View File

@ -206,7 +206,8 @@ function comicpress_load_options() {
'enable_comment_count_in_rss' => false,
'enable_scroll_to_top' => false,
'enable_page_load_info' => false
'enable_page_load_info' => false,
'comic_filename_filters' => array()
) as $field => $value) {
$comicpress_options[$field] = $value;

View File

@ -112,7 +112,7 @@
</th>
<td>
<?php _e('Choose a directory to get the ARCHIVE/SEARCH thumbnails from.','comicpress'); ?>
<?php _e('Choose a directory to get the Archive/Search thumbnails from.','comicpress'); ?>
</td>
</tr>
@ -135,7 +135,7 @@
</th>
<td>
<?php _e('Choose a directory to get the MINI thumbnails from. (for archive-comic-list, etc.)','comicpress'); ?>
<?php _e('Choose a directory to get the Mini thumbnails from. (for archive-comic-list, etc.)','comicpress'); ?>
</td>
</tr>
@ -147,18 +147,86 @@
</tr>
<tr>
<th scope="row"><label for="archive_comic_width"><?php _e('ARCHIVE Thumbnail Width','comicpress'); ?></label></th>
<th scope="row"><label for="archive_comic_width"><?php _e('Archive Thumbnail Width','comicpress'); ?></label></th>
<td colspan="2">
<input type="text" size="7" name="archive_comic_width" id="archive_comic_width" value="<?php echo $comicpress_options['comicpress_config']['archive_comic_width']; ?>" />
</td>
</tr>
<tr class="alternate">
<th scope="row"><label for="mini_comic_width"><?php _e('MINI Thumbnail Width','comicpress'); ?></label></th>
<th scope="row"><label for="mini_comic_width"><?php _e('Mini Thumbnail Width','comicpress'); ?></label></th>
<td colspan="2">
<input type="text" size="7" name="mini_comic_width" id="mini_comic_width" value="<?php echo $comicpress_options['comicpress_config']['mini_comic_width']; ?>" />
</td>
</tr>
<?php
$cpmh = new ComicPressMediaHandling();
$filters = $comicpress_options['comic_filename_filters'];
if (!isset($filters['default'])) {
$filters['default'] = $cpmh->default_filter;
}
?>
<tr>
<th scope="row"><label><?php _e('Comic Filename Filters', 'comicpress'); ?></label></th>
<td colspan="2">
<p>
<em>For advanced users.</em> Specify the filters used to find the filename.
</p>
<div id="comicpress-comic-filename-filters-holder">
</div>
<a href="#" id="add-new-filter"><?php _e('Add new filter', 'comicpress') ?></a>
<script type="text/javascript">
(function($) {
var filter_data = [];
<?php foreach ($filters as $name => $filter) { ?>
filter_data.push({name:'<?php echo esc_js($name) ?>', filter:'<?php echo esc_js($filter) ?>'});
<?php } ?>
var build_row = function(data) {
var key = (new Date()).getTime();
var row = $('<div>\
<label>\
<strong>Key:</strong>\
<input type="text" size="15" name="comic_filename_filters[' + key + '][name]" value="' + data.name + '" />\
</label>\
<label>\
<strong>Filter:</strong>\
<input type="text" size="60" name="comic_filename_filters[' + key + '][filter]" value="' + data.filter + '" />\
</label>\
<a href="#">Remove</a>\
</div>');
$('a', row).click(function() {
if (confirm('<?php _e('Are you sure?', 'comicpress') ?>')) {
$(this).parent().remove();
}
return false;
});
return row;
};
$('#add-new-filter').click(function() {
$('#comicpress-comic-filename-filters-holder').append(build_row({name:'new_filter',filter:'%wordpress%'}));
return false;
});
$.each(filter_data, function(index, f) {
$('#comicpress-comic-filename-filters-holder').append(build_row(f));
});
}(jQuery))
</script>
<p>
Available parameters:
</p>
<ul>
<li><strong>%wordpress%</strong>: The WordPress root folder</li>
<li><strong>%type-folder%</strong>: The folder for the requested filetype (comic, rss, archive, or mini)</li>
<li><strong>%date-(format)%</strong>: The formatting to use for the requested date as per the <a href="http://php.net/date">date()</a> function <em>(ex: %date-Ymd% is <?php echo date('Ymd') ?>)</em></li>
<li><strong>%upload-path%</strong>: The value of the upload_path option, which is the destination upload directory for WPMU installs.</li>
</ul>
</td>
</tr>
</table>

View File

@ -221,3 +221,20 @@ div.show .cpadmin-footer img{
min-width: 80px;
text-align: center;
}
/** Comic Filters **/
#comicpress-comic-filename-filters-holder div {
border: solid #ddd 1px;
padding: 3px;
overflow: hidden;
}
#comicpress-comic-filename-filters-holder label {
float: left;
display: inline;
}
#comicpress-comic-filename-filters-holder input {
margin: 0 10px;
}

View File

@ -41,7 +41,8 @@ class ComicPressMediaHandlingTest extends PHPUnit_Framework_TestCase {
array(null, $default),
array('fail', $default),
array(array(), $default),
array('test', 'test')
array('test', 'test'),
array('test-from-option', 'test-from-option'),
);
}
@ -53,6 +54,12 @@ class ComicPressMediaHandlingTest extends PHPUnit_Framework_TestCase {
$comic_filename_filters['test'] = 'test';
update_option('comicpress_options', array(
'comic_filename_filters' => array(
'test-from-option' => 'test-from-option'
)
));
$default = str_replace('{date}', $this->cpmh->default_filename_filter, $this->cpmh->default_filter);
$cpmh = $this->getMock('ComicPressMediaHandling', array('_convert_to_percent_filter'));
@ -95,7 +102,8 @@ class ComicPressMediaHandlingTest extends PHPUnit_Framework_TestCase {
array('%test test%', '%test test%'),
array('%wordpress%/%type-folder%', vfsStream::url('root') . '/comic'),
array('%date-Y%', '2009'),
array('%wordpress%/%type-folder%/%date-Y-m-d%*.*', vfsStream::url('root') . '/comic/2009-01-01.*\..*')
array('%wordpress%/%type-folder%/%date-Y-m-d%*.*', vfsStream::url('root') . '/comic/2009-01-01.*\..*'),
array('%wordpress%/%upload-path%/%type-folder%/%date-Y-m-d%*.*', vfsStream::url('root') . '/1/files/comic/2009-01-01.*\..*')
);
}
@ -106,6 +114,8 @@ class ComicPressMediaHandlingTest extends PHPUnit_Framework_TestCase {
$cpmh = $this->getMock('ComicPressMediaHandling', array('_abspath'));
$cpmh->expects($this->any())->method('_abspath')->will($this->returnValue(vfsStream::url('root')));
update_option('upload_path', '1/files');
$this->assertEquals($expected_result, $cpmh->_expand_filter($filter, 'comic', (object)array('ID' => 1, 'post_date' => '2009-01-01 15:00:00')));
}

View File

@ -0,0 +1,43 @@
<?php
require_once('PHPUnit/Framework.php');
require_once('MockPress/mockpress.php');
require_once(dirname(__FILE__) . '/../comicpress-options.php');
require_once(dirname(__FILE__) . '/../classes/ComicPressMediaHandling.inc');
class ComicPressOptionsAdminTest extends PHPUnit_Framework_TestCase {
function providerTestSaveComicFilenameFilters() {
$cpmh = new ComicPressMediaHandling();
return array(
array(
array(),
array()
),
array(
array(1 => array(
'name' => 'test', 'filter' => 'myfilter'
)),
array(
'default' => $cpmh->default_filter,
'test' => 'myfilter'
)
),
array(
array(1 => array(
'name' => 'default', 'filter' => 'test'
)),
array(
'default' => 'test'
)
)
);
}
/**
* @dataProvider providerTestSaveComicFilenameFilters
*/
function testSaveComicFilenameFilters($incoming, $expected) {
$this->assertEquals($expected, comicpress_save_options_comic_filename_filters($incoming));
}
}

View File

@ -11,7 +11,6 @@ class ComicPressRelatedPostsTest extends PHPUnit_Framework_TestCase {
}
function testBuildPostTable() {
$this->markTestIncomplete();
$posts = array(
(object)array('ID' => 1, 'post_date' => '2009-01-01', 'post_title' => 'Post 1', 'guid' => 'post-1'),
(object)array('ID' => 2, 'post_date' => '2009-01-02', 'post_title' => 'Post 2', 'guid' => 'post-2'),
@ -32,7 +31,7 @@ class ComicPressRelatedPostsTest extends PHPUnit_Framework_TestCase {
wp_set_post_categories($id, $cats);
}
$output = '<div class="related_posts"><span>Title</span><table class="month-table"><tr><td class="archive-date" align="right">Jan 3, 2009</td><td class="archive-title"><a title="Post 3" href="post-3">Post 3</a></td></tr></table></div>';
$output = '<div class="related_posts"><h4>Title</h4><ul><li><a title="Post 3" href="post-3">Post 3</a></li></ul></div>';
$this->rp->related_categories = array(2);

View File

@ -0,0 +1,154 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head profile="http://selenium-ide.openqa.org/profiles/test-case">
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<link rel="selenium.base" href="http://comicpress.local/" />
<title>TestComicFilenameFilters</title>
</head>
<body>
<table cellpadding="1" cellspacing="1" border="1">
<thead>
<tr><td rowspan="1" colspan="3">TestComicFilenameFilters</td></tr>
</thead><tbody>
<tr>
<td>clickAndWait</td>
<td>link=ComicPress Options</td>
<td></td>
</tr>
<tr>
<td>click</td>
<td>//div[@id='comicpress-tab-config']/span</td>
<td></td>
</tr>
<!--Remove existing filters-->
<tr>
<td>storeXpathCount</td>
<td>//div[@id=&quot;comicpress-comic-filename-filters-holder&quot;]/div</td>
<td>filter_count</td>
</tr>
<tr>
<td>while</td>
<td>${filter_count} &gt; 0</td>
<td></td>
</tr>
<tr>
<td>click</td>
<td>//div[@id='comicpress-comic-filename-filters-holder']/div[1]/a</td>
<td></td>
</tr>
<tr>
<td>assertConfirmation</td>
<td>Are you sure?</td>
<td></td>
</tr>
<tr>
<td>storeXpathCount</td>
<td>//div[@id=&quot;comicpress-comic-filename-filters-holder&quot;]/div</td>
<td>filter_count</td>
</tr>
<tr>
<td>endWhile</td>
<td></td>
<td></td>
</tr>
<tr>
<td>clickAndWait</td>
<td>comicpress_save_config</td>
<td></td>
</tr>
<!--Add and remove works-->
<tr>
<td>storeXpathCount</td>
<td>//div[@id=&quot;comicpress-comic-filename-filters-holder&quot;]/div</td>
<td>filter_count</td>
</tr>
<tr>
<td>echo</td>
<td>${filter_count}</td>
<td></td>
</tr>
<tr>
<td>click</td>
<td>add-new-filter</td>
<td></td>
</tr>
<tr>
<td>storeXpathCount</td>
<td>//div[@id=&quot;comicpress-comic-filename-filters-holder&quot;]/div</td>
<td>new_filter_count</td>
</tr>
<tr>
<td>assertEval</td>
<td>(${new_filter_count}) == (${filter_count} + 1)</td>
<td>true</td>
</tr>
<tr>
<td>clickAndWait</td>
<td>comicpress_save_config</td>
<td></td>
</tr>
<tr>
<td>assertTextPresent</td>
<td>ComicPress Settings SAVED!</td>
<td></td>
</tr>
<tr>
<td>storeXpathCount</td>
<td>//div[@id=&quot;comicpress-comic-filename-filters-holder&quot;]/div</td>
<td>new_filter_count</td>
</tr>
<tr>
<td>assertEval</td>
<td>(${new_filter_count}) == (${filter_count} + 1)</td>
<td>true</td>
</tr>
<tr>
<td>click</td>
<td>//div[@id='comicpress-comic-filename-filters-holder']/div[2]/a</td>
<td></td>
</tr>
<tr>
<td>assertConfirmation</td>
<td>Are you sure?</td>
<td></td>
</tr>
<tr>
<td>storeXpathCount</td>
<td>//div[@id=&quot;comicpress-comic-filename-filters-holder&quot;]/div</td>
<td>new_filter_count</td>
</tr>
<tr>
<td>assertEval</td>
<td>(${new_filter_count}) == (${filter_count})</td>
<td>true</td>
</tr>
<tr>
<td>clickAndWait</td>
<td>comicpress_save_config</td>
<td></td>
</tr>
<tr>
<td>assertTextPresent</td>
<td>ComicPress Settings SAVED!</td>
<td></td>
</tr>
<tr>
<td>storeXpathCount</td>
<td>//div[@id=&quot;comicpress-comic-filename-filters-holder&quot;]/div</td>
<td>new_filter_count</td>
</tr>
<tr>
<td>assertEval</td>
<td>(${new_filter_count}) == (${filter_count})</td>
<td>true</td>
</tr>
<tr>
<td>assertTextPresent</td>
<td>ComicPress Settings SAVED!</td>
<td></td>
</tr>
</tbody></table>
</body>
</html>