diff --git a/classes/ComicPressMediaHandling.inc b/classes/ComicPressMediaHandling.inc index 3665d09..11ac09b 100644 --- a/classes/ComicPressMediaHandling.inc +++ b/classes/ComicPressMediaHandling.inc @@ -60,7 +60,7 @@ class ComicPressMediaHandling { // @codeCoverageIgnoreStart function _abspath() { - return ABSPATH; + return realpath(ABSPATH); } // @codeCoverageIgnoreEnd @@ -94,21 +94,30 @@ class ComicPressMediaHandling { while (($file = readdir($dh)) !== false) { $target = $dirname . '/' . $file; if (is_file($target)) { - if (preg_match("#${filename_pattern}#", $file) > 0) { + if (preg_match("#^${filename_pattern}$#", $file) > 0) { $results[] = $target; } } } + closedir($dh); } } 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) { global $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(); 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) { 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; } } diff --git a/functions.php b/functions.php index 6f0f669..8f63e5c 100644 --- a/functions.php +++ b/functions.php @@ -75,7 +75,7 @@ function comicpress_load_options() { global $comicpress_options; $comicpress_options = get_option('comicpress_options'); if (empty($comicpress_options)) { - $comicpress_options['comicpress_version'] = '2.9.0.4'; + $comicpress_options['comicpress_version'] = '2.9.0.4'; foreach (array( 'disable_comic_frontpage' => false, 'disable_comic_blog_frontpage' => false, @@ -181,11 +181,9 @@ if ($comicpress_options['remove_wptexturize']) { // WIDGETS WP 2.8 compatible ONLY, no backwards compatibility here. $dirs_to_search = array_unique(array(get_template_directory(),get_stylesheet_directory())); foreach ($dirs_to_search as $dir) { - // Widgets - foreach (glob($dir . '/widgets/*.php') as $__file) { require_once($__file); } - - // FUNCTIONS & Extra's - foreach (glob($dir . '/functions/*.php') as $__file) { require_once($__file); } + foreach (array('widgets' => 'php', 'functions' => 'php', 'classes' => 'inc') as $folder => $extension) { + foreach (glob($dir . "/${folder}/*.${extension}") as $__file) { require_once($__file); } + } } // 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. $comic_filename_filters = array(); -$comic_filename_filters['default'] = "{date}*.*"; // load all of the comic & non-comic category information 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) { - global $post, $comic_filename_filters, $comic_folder, $archive_comic_folder, $rss_comic_folder, $mini_comic_folder, $comic_pathfinding_errors, $wpmu_version; - - 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 %s folder that matched the pattern %s. Check your WordPress and ComicPress settings.", 'comicpress'), $folder_to_use, $filter_with_date); - return false; + $mh = new ComicPressMediaHandling(); + return $mh->get_comic_path($folder, $override_post, $filter, $multi); } diff --git a/functions/wpmu.php b/functions/wpmu.php new file mode 100644 index 0000000..f2651dd --- /dev/null +++ b/functions/wpmu.php @@ -0,0 +1,33 @@ +assertEquals($expected_result, _comicpress_expand_filter_callback('original', array())); + $this->assertEquals($expected_result, _comicpress_expand_filter_callback('original', array('all', 'wordpress'))); } function providerTestReadDirectory() {