comicpress-core/classes/ComicPress.inc

168 lines
4.7 KiB
PHP
Raw Normal View History

2009-07-08 23:51:02 +00:00
<?php
2009-11-07 22:13:13 +00:00
require_once(dirname(__FILE__) . '/ComicPressComicPost.inc');
2009-07-13 23:14:17 +00:00
/**
* The core functions of ComicPress.
*/
2009-07-08 23:51:02 +00:00
class ComicPress {
var $comicpress_options = array(
2009-07-21 17:40:24 +00:00
'comic_dimensions' => '760x',
'rss_dimensions' => '350x',
'archive_dimensions' => '125x',
'mini_dimensions' => '100x',
2009-08-06 02:29:54 +00:00
'helpers' => array(),
2009-11-01 18:15:59 +00:00
'addons' => array(),
2009-11-09 03:11:26 +00:00
'storyline_order' => '',
'subattachment_types' => array(
'rss' => 'RSS',
'archive' => 'Archive',
'mini' => 'Mini Thumb'
)
2009-07-08 23:51:02 +00:00
);
2009-11-07 22:52:21 +00:00
2009-11-09 03:11:26 +00:00
var $backends = array('ComicPressBackendAttachment');
2009-11-01 19:04:15 +00:00
function &get_instance() {
2009-11-01 18:15:59 +00:00
static $instance;
2009-11-07 22:52:21 +00:00
2009-11-01 19:04:15 +00:00
if (!$instance) {
$instance = array(new ComicPress());
2009-11-01 18:15:59 +00:00
}
2009-11-07 22:52:21 +00:00
2009-11-01 19:04:15 +00:00
return $instance[0];
2009-11-01 18:15:59 +00:00
}
2009-11-07 22:52:21 +00:00
2009-07-13 23:14:13 +00:00
/**
* Load ComicPress options.
*/
2009-07-08 23:51:02 +00:00
function load() {
$result = get_option('comicpress-options');
if (is_array($result)) {
$this->comicpress_options = array_merge($this->comicpress_options, $result);
2009-07-08 23:51:02 +00:00
}
}
2009-11-07 22:52:21 +00:00
2009-07-13 23:14:13 +00:00
/**
* Save ComicPress options.
*/
2009-07-08 23:51:02 +00:00
function save() {
if (is_array($this->comicpress_options)) {
update_option('comicpress-options', $this->comicpress_options);
}
}
// @codeCoverageIgnoreStart
2009-07-13 23:14:13 +00:00
/**
* Initialize the class.
*/
2009-07-08 23:51:02 +00:00
function init() {
$this->load();
2009-11-07 22:52:21 +00:00
if (current_user_can('edit_themes')) {
if (!empty($this->comicpress_options['helpers'])) {
add_action('wp_footer', array(&$this, 'announce_activated_helpers'));
}
}
2009-11-07 22:52:21 +00:00
add_filter('intermediate_image_sizes', array(&$this, 'intermediate_image_sizes'));
2009-11-09 03:11:26 +00:00
add_filter('editor_max_image_size', array(&$this, 'editor_max_image_size'), 10, 2);
2009-11-07 22:52:21 +00:00
foreach (array('comic', 'rss', 'archive', 'mini') as $size) {
list($w, $h) = explode("x", $this->comicpress_options["${size}_dimensions"]);
update_option("${size}_size_w", $w);
update_option("${size}_size_h", $h);
update_option("${size}_crop", 0);
}
}
// WordPress Filters
function intermediate_image_sizes($sizes) {
return array_merge($sizes, array('comic', 'rss', 'archive', 'mini'));
2009-07-13 23:06:32 +00:00
}
2009-11-07 22:52:21 +00:00
2009-11-09 03:11:26 +00:00
function editor_max_image_size($current_max, $size) {
if (isset($this->comicpress_options["${size}_dimensions"])) {
list($width, $height) = explode('x', $this->comicpress_options["${size}_dimensions"]);
$current_max = array(intval($width), intval($height));
}
return $current_max;
}
function announce_activated_helpers() {
echo "<center>[ <strong>Activated ComicPress helpers:</strong> " . implode(", ", array_keys($this->comicpress_options['helpers'])) . " ]</center>";
}
2009-07-19 23:20:23 +00:00
/**
* Gather blog posts for the given index page.
*/
function get_index_blog_posts_query() {
2009-07-19 23:20:23 +00:00
global $post, $paged;
2009-11-07 22:52:21 +00:00
2009-07-19 23:20:23 +00:00
$t = $post;
2009-11-07 22:52:21 +00:00
2009-07-19 23:20:23 +00:00
$wp_query = new WP_Query();
$wp_query->query(
2009-11-07 22:52:21 +00:00
'showposts=' .
2009-07-19 23:20:23 +00:00
(int)$this->comicpress_options['blogpost_count'] .
2009-11-07 22:52:21 +00:00
'&cat=-' .
$this->comicpress_options['comic_category_id'] .
2009-07-19 23:20:23 +00:00
'&paged=' .
$paged
);
2009-11-07 22:52:21 +00:00
return $wp_query;
2009-07-19 23:20:23 +00:00
}
2009-11-07 22:52:21 +00:00
// @codeCoverageIgnoreEnd
2009-11-07 21:38:22 +00:00
/**
* Search a path for directories named after the slugs provided.
* @param array $categories A list of category slugs going from child -> parent -> root.
* @param string $path The path to search.
* @return array All matching paths.
*/
2009-11-07 21:36:57 +00:00
function category_search($categories, $path) {
$path = trailingslashit($path);
$all_categories = array_reverse($categories);
$all_paths = array();
while (count($all_categories) > 0) {
$target = $path . implode('/', $all_categories);
if (is_dir($target)) { $all_paths[] = $target; }
array_pop($all_categories);
}
return array_reverse($all_paths);
}
2009-11-07 22:52:21 +00:00
2009-11-07 22:00:14 +00:00
/**
* Recursively search a particular template directory for a specified file, limiting the search to the provided categories.
* @param string $name The name of the file with no path information.
* @param string $path The path within the template directories to start the search.
* @param attay $categories The child -> root category slugs to search within the specified path. If not provided, retrieve from current post.
* @return string|boolean The path to the file, for false if not found.
*/
2009-11-07 22:35:51 +00:00
function find_file($name, $path = '', $categories = null) {
2009-11-07 22:13:13 +00:00
global $post;
if (!is_array($categories)) {
$comic_post = new ComicPressComicPost($post);
$categories = $comic_post->find_parents();
}
2009-11-07 22:52:21 +00:00
2009-11-07 22:00:14 +00:00
foreach (array(get_stylesheet_directory(), get_template_directory()) as $dir) {
$dir = trailingslashit($dir) . $path;
$dirs_to_search = $this->category_search($categories, $dir);
$dirs_to_search[] = $dir;
2009-11-07 22:52:21 +00:00
2009-11-07 22:00:14 +00:00
foreach ($dirs_to_search as $category_path) {
$target = trailingslashit($category_path) . $name;
if (file_exists($target)) {
return $target;
}
}
}
return false;
}
2009-07-08 23:51:02 +00:00
}
?>