finalize get comic path changeover

This commit is contained in:
John Bintz 2009-12-01 22:27:54 -05:00
parent 3b0b3a1471
commit 91436b4b51
4 changed files with 71 additions and 69 deletions

View File

@ -60,7 +60,7 @@ class ComicPressMediaHandling {
// @codeCoverageIgnoreStart // @codeCoverageIgnoreStart
function _abspath() { function _abspath() {
return ABSPATH; return realpath(ABSPATH);
} }
// @codeCoverageIgnoreEnd // @codeCoverageIgnoreEnd
@ -94,21 +94,30 @@ class ComicPressMediaHandling {
while (($file = readdir($dh)) !== false) { while (($file = readdir($dh)) !== false) {
$target = $dirname . '/' . $file; $target = $dirname . '/' . $file;
if (is_file($target)) { if (is_file($target)) {
if (preg_match("#${filename_pattern}#", $file) > 0) { if (preg_match("#^${filename_pattern}$#", $file) > 0) {
$results[] = $target; $results[] = $target;
} }
} }
} }
closedir($dh);
} }
} }
return $results; return $results;
} }
/**
* Get the comic path.
* @param string $type The type to retrieve.
* @param object $override_post The post to use in place of the Loop post.
* @param string $filter The filter to use.
* @param boolean $multi If true, return all matching files.
* @return string|array|boolean A single comic URI relative to the WordPress base, multiple comic URIs, or false if an error occurred.
*/
function get_comic_path($type = 'comic', $override_post = null, $filter = 'default', $multi = false) { function get_comic_path($type = 'comic', $override_post = null, $filter = 'default', $multi = false) {
global $post; global $post;
$post_to_use = !is_null($override_post) ? $override_post : $post; $post_to_use = !is_null($override_post) ? $override_post : $post;
$filter = $this->get_filter($filter); $filter = $this->_get_filter($filter);
$globals = $this->_bundle_global_variables(); $globals = $this->_bundle_global_variables();
if (isset($globals[$type])) { if (isset($globals[$type])) {
@ -118,7 +127,19 @@ class ComicPressMediaHandling {
if (($pre_handle = apply_filters('comicpress_pre_handle_comic_path_results', false, $results, $type, $post_to_use)) !== false) { if (($pre_handle = apply_filters('comicpress_pre_handle_comic_path_results', false, $results, $type, $post_to_use)) !== false) {
return $pre_handle; return $pre_handle;
} }
$new_results = array();
foreach ($results as $result) {
$new_results[] = str_replace($this->_abspath(), '', $result);
}
if ($multi) {
return $new_results;
} else {
return reset($new_results);
}
} }
} }
return false;
} }
} }

View File

@ -181,11 +181,9 @@ if ($comicpress_options['remove_wptexturize']) {
// WIDGETS WP 2.8 compatible ONLY, no backwards compatibility here. // WIDGETS WP 2.8 compatible ONLY, no backwards compatibility here.
$dirs_to_search = array_unique(array(get_template_directory(),get_stylesheet_directory())); $dirs_to_search = array_unique(array(get_template_directory(),get_stylesheet_directory()));
foreach ($dirs_to_search as $dir) { foreach ($dirs_to_search as $dir) {
// Widgets foreach (array('widgets' => 'php', 'functions' => 'php', 'classes' => 'inc') as $folder => $extension) {
foreach (glob($dir . '/widgets/*.php') as $__file) { require_once($__file); } foreach (glob($dir . "/${folder}/*.${extension}") as $__file) { require_once($__file); }
}
// FUNCTIONS & Extra's
foreach (glob($dir . '/functions/*.php') as $__file) { require_once($__file); }
} }
// Dashboard Menu Comicpress Options and ComicPress CSS // Dashboard Menu Comicpress Options and ComicPress CSS
@ -217,7 +215,6 @@ if (defined("CPM_DATE_FORMAT")) {
// Note that it's quite possible to slurp up the wrong file if your expressions are too broad. // Note that it's quite possible to slurp up the wrong file if your expressions are too broad.
$comic_filename_filters = array(); $comic_filename_filters = array();
$comic_filename_filters['default'] = "{date}*.*";
// load all of the comic & non-comic category information // load all of the comic & non-comic category information
add_action('init', 'get_all_comic_categories'); add_action('init', 'get_all_comic_categories');
@ -427,61 +424,8 @@ function get_adjacent_storyline_category_id($next = false) {
*/ */
function get_comic_path($folder = 'comic', $override_post = null, $filter = 'default', $multi = null) { function get_comic_path($folder = 'comic', $override_post = null, $filter = 'default', $multi = null) {
global $post, $comic_filename_filters, $comic_folder, $archive_comic_folder, $rss_comic_folder, $mini_comic_folder, $comic_pathfinding_errors, $wpmu_version; $mh = new ComicPressMediaHandling();
return $mh->get_comic_path($folder, $override_post, $filter, $multi);
if (isset($comic_filename_filters[$filter])) {
$filter_to_use = $comic_filename_filters[$filter];
} else {
$filter_to_use = '{date}*.*';
}
switch ($folder) {
case "rss": $folder_to_use = $rss_comic_folder; break;
case "archive": $folder_to_use = $archive_comic_folder; break;
case "mini": $folder_to_use = $mini_comic_folder; break;
case "comic": default: $folder_to_use = $comic_folder; break;
}
if (!empty($wpmu_version)) {
if (($wpmu_path = get_option('upload_path')) !== false) {
$folder_to_use = $wpmu_path . '/' . $folder_to_use;
}
}
$post_to_use = (is_object($override_post)) ? $override_post : $post;
$post_date = mysql2date(CP_DATE_FORMAT, $post_to_use->post_date);
$filter_with_date = str_replace('{date}', $post_date, $filter_to_use);
$cwd = get_template_directory();
if ($cwd !== false) {
// Strip the wp-admin part and just get to the root.
$root_path = preg_replace('#[\\/]wp-(admin|content).*#', '', $cwd);
}
$results = array();
/* have to use root_path to get subdirectory installation directories */
if (count($results = glob("${root_path}/${folder_to_use}/${filter_with_date}")) > 0) {
if (!empty($wpmu_version)) {
$comic = reset($results);
$comic = $folder_to_use . '/'. basename($comic);
if ($wpmu_path !== false) { $comic = str_replace($wpmu_path, "files", $comic); }
return $comic;
}
if (!empty($multi)) {
return $results;
} else {
/* clear the root path */
$comic = reset($results);
$comic = $folder_to_use .'/'. basename($comic);
return $comic;
}
}
$comic_pathfinding_errors[] = sprintf(__("Unable to find the file in the <strong>%s</strong> folder that matched the pattern <strong>%s</strong>. Check your WordPress and ComicPress settings.", 'comicpress'), $folder_to_use, $filter_with_date);
return false;
} }

33
functions/wpmu.php Normal file
View File

@ -0,0 +1,33 @@
<?php
function _comicpress_pre_handle_comic_path_results($return, $results, $type, $post_to_use) {
global $wpmu_version;
if (!empty($wpmu_version)) {
$globals = ComicPressMediaHandling::_bundle_global_variables();
$comic = $globals[$type] . '/'. basename(reset($results));
if (($wpmu_path = get_option('upload_path')) !== false) {
$comic = str_replace($wpmu_path, "files", $comic);
}
return $comic;
}
return false;
}
function _comicpress_expand_filter_callback($value, $matches) {
global $wpmu_version;
if (!empty($wpmu_version)) {
if (strtolower($matches[1]) == 'wordpress') {
if ($path = get_option('upload_path')) {
return $path;
}
}
}
return $value;
}
add_filter('comicpress_pre_handle_comic_path_results', '_comicpress_pre_handle_comic_path_results', 10, 4);
add_filter('comicpress_expand_filter_callback', '_comicpress_expand_filter_callback', 10, 2);

View File

@ -101,17 +101,21 @@ class ComicPressMediaHandlingTest extends PHPUnit_Framework_TestCase {
function providerTestExpandFilterWPMUCallback() { function providerTestExpandFilterWPMUCallback() {
return array( return array(
array('', 'original'), array('', '', 'original'),
array('new', 'new') array('', 'new', 'original'),
array('1', 'new', 'new'),
); );
} }
/** /**
* @dataProvider providerTestExpandFilterWPMUCallback * @dataProvider providerTestExpandFilterWPMUCallback
*/ */
function testExpandFilterWPMUCallback($option_value, $expected_result) { function testExpandFilterWPMUCallback($_wpmu_version, $option_value, $expected_result) {
global $wpmu_version;
$wpmu_version = $_wpmu_version;
update_option('upload_path', $option_value); update_option('upload_path', $option_value);
$this->assertEquals($expected_result, _comicpress_expand_filter_callback('original', array())); $this->assertEquals($expected_result, _comicpress_expand_filter_callback('original', array('all', 'wordpress')));
} }
function providerTestReadDirectory() { function providerTestReadDirectory() {