diff --git a/comicpress-config.php b/comicpress-config.php index 5dc1e18..a51a7c8 100644 --- a/comicpress-config.php +++ b/comicpress-config.php @@ -10,10 +10,10 @@ $blogcat = "1"; $comic_folder = "comics"; //RSS COMIC FOLDER - the folder your comic files are in for the RSS feed (default "comics"). -$rss_comic_folder = "comics-rss"; +$rss_comic_folder = "comics"; //ARCHIVE COMIC FOLDER - the folder your comic files are in for your archive pages (default "comics"). -$archive_comic_folder = "comics-archive"; +$archive_comic_folder = "comics"; //ARCHIVE COMIC WIDTH - the width your comics will appear on archive or search results (default "380"). $archive_comic_width = "380"; diff --git a/functions.php b/functions.php index b34c033..3cea527 100644 --- a/functions.php +++ b/functions.php @@ -32,6 +32,15 @@ $comic_filename_filters['default'] = "{date}*.*"; // load all of the comic & non-comic category information add_action('init', 'get_all_comic_categories'); +add_action('init', 'comicpress_handle_options_changes'); +add_action('admin_menu', 'comicpress_add_options_menu'); +add_action('admin_notices', 'comicpress_admin_notices'); + +$__comicpress_notices = array(); + +function comicpress_add_options_menu() { + add_theme_page(__("ComicPress Config", 'comicpress'), __('ComicPress Config', 'comicpress'), 'edit_themes', basename(__FILE__), 'comicpress_options_menu'); +} function get_first_comic() { return get_terminal_post_in_category(get_all_comic_categories_as_cat_string()); @@ -41,6 +50,117 @@ function get_last_comic() { return get_terminal_post_in_category(get_all_comic_categories_as_cat_string(), false); } +function comicpress_admin_notices() { + global $__comicpress_notices; + + if (!empty($__comicpress_notices) && is_array($__comicpress_notices)) { + echo '
'; + foreach ($__comicpress_notices as $notice) { echo '

' . $notice . '

'; } + echo '
'; + } +} + +function comicpress_handle_options_changes() { + global $__comicpress_notices; + + include(get_template_directory() . '/comicpress-config.php'); + + if (isset($_POST['cp'])) { + if (wp_verify_nonce($_POST['cp']['_nonce'], 'comicpress')) { + foreach ($_POST['cp'] as $field => $value) { + ${$field} = $value; + } + + $lines = file(get_template_directory() . '/comicpress-config.php', FILE_IGNORE_NEW_LINES); + for ($i = 0, $il = count($lines); $i < $il; ++$i) { + if (preg_match('#\$([^\ ]+)#', $lines[$i], $matches) > 0) { + if (!empty(${$matches[1]})) { + $lines[$i] = "\${$matches[1]} = \"" . ${$matches[1]} . "\";"; + } + } + } + + if (($fh = fopen(get_template_directory() . '/comicpress-config.php', "w")) !== false) { + foreach ($lines as $line) { fwrite($fh, $line . "\n"); } + fclose($fh); + $__comicpress_notices[] = __('ComicPress options updated.', 'comicpress'); + } else { + $__comicpress_notices[] = __("Unable to write file. Check your theme directory's permissions.", 'comicpress'); + } + } + } +} + +function comicpress_options_menu() { + include(get_template_directory() . '/comicpress-config.php'); + + $categories = get_all_category_ids(); + + echo '
'; + _e('

ComicPress Config

', 'comicpress'); + + echo '
'; + echo ''; + echo ''; + foreach (array( + 'blogcat' => array( + 'type' => 'category', + 'label' => __('Blog category', 'comicpress') + ), + 'comiccat' => array( + 'type' => 'category', + 'label' => __('Comic category', 'comicpress') + ), + 'comic_folder' => array( + 'type' => 'text', + 'label' => __('Comic folder', 'comicpress') + ), + 'rss_comic_folder' => array( + 'type' => 'text', + 'label' => __('RSS comic folder', 'comicpress') + ), + 'archive_comic_folder' => array( + 'type' => 'text', + 'label' => __('Archive comic folder', 'comicpress') + ), + 'archive_comic_width' => array( + 'type' => 'text', + 'label' => __('Archive comic width', 'comicpress') + ), + 'rss_comic_width' => array( + 'type' => 'text', + 'label' => __('RSS comic width', 'comicpress') + ), + 'blog_postcount' => array( + 'type' => 'text', + 'label' => __('Blog postcount', 'comicpress') + ) + ) as $field => $parameters) { + echo ''; + echo ''; + echo ''; + echo ''; + } + + echo ''; + echo '
' . $parameters['label'] . ''; + switch ($parameters['type']) { + case "category": + echo ''; + break; + case "text": + echo ''; + break; + } + echo '
'; + echo '
'; + echo '
'; +} + /** * Get the hyperlink to the first comic post in the database. * @return string The hyperlink to the first comic post, or false. diff --git a/style.css b/style.css index cc3c716..1beaf08 100644 --- a/style.css +++ b/style.css @@ -10,7 +10,7 @@ The CSS, XHTML and design is released under GPL v3: http://www.opensource.org/licenses/gpl-3.0.html . */ - + /* STANDARD TAGS */