Merge branch 'master' of git@github.com:johnbintz/comicpress-theme-core

This commit is contained in:
John Bintz 2009-08-24 20:50:22 -04:00
commit 3543e14aea
11 changed files with 536 additions and 345 deletions

View File

@ -1,6 +1,8 @@
<?php
class ComicPressAddonBookmarkWidget extends ComicPressAddon {
var $name = "Bookmark Widget";
function init($comicpress) {
wp_register_sidebar_widget('comic-bookmark', __('Comic Bookmark', 'comicpress'), array(&$this, 'render_widget'), array('description' => __('Let your readers save their place via a cookie.', 'comicpress')));
@ -8,31 +10,25 @@ class ComicPressAddonBookmarkWidget extends ComicPressAddon {
add_action('wp_head', array(&$this, 'wp_head'));
$this->comicpress->additional_javascripts[] = '/js/bookmark.js';
wp_enqueue_script('prototype');
wp_enqueue_script('cookiejar', get_template_directory_uri() . '/js/cookiejar.js', array('prototype'));
wp_enqueue_script('bookmark', get_template_directory_uri() . '/js/bookmark.js', array('prototype', 'cookiejar'));
}
function wp_head() {
$last_comic = $this->comicpress->get_last_comic(); ?>
function wp_head() { ?>
<script type="text/javascript">
var imgTag = '<?php bloginfo('template_directory'); ?>/images/1.gif'; //add tag image.
var imgClearOff = '<?php bloginfo('template_directory'); ?>/images/3a.gif'; //no comic tagged, clear not possible
var imgGotoOff = '<?php bloginfo('template_directory'); ?>/images/2a.gif'; //no comic tagged, goto not possible
var imgClearOn = '<?php bloginfo('template_directory'); ?>/images/3.gif'; //clear a tag, shows when comic previously tagged
var imgGotoOn = '<?php bloginfo('template_directory'); ?>/images/2.gif'; //shows when a comic is tagged
var imgInfo = '<?php bloginfo('template_directory'); ?>/images/4.gif'; //img that displays the help
var comicDir = '/'; //alter this if you run multiple comics in different directories on your site.
var comicPermalink = '<?php echo get_permalink($last_comic->ID) ?>';
var isHome = <?php echo is_home() ? "true" : "false" ?>;
var isSingle = <?php echo (is_single() && $this->comicpress->in_comic_category()) ? "true" : "false" ?>;
var image_root = '<?php bloginfo('template_directory'); ?>/images/';
var permalink = '<?php the_permalink() ?>';
</script>
<?php
}
<?php }
function render_widget() {
?>
<div class="comic-bookmark">
<script type="text/javascript">writeBookmarkWidget()</script>
<div id="comic-bookmark-holder">
<a href="#" class="tag-page"><img src="<?php bloginfo('template_directory'); ?>/images/1.gif" /></a>
<a href="#" class="goto-tag"><img /></a>
<a href="#" class="clear-tag"><img /></a>
</div>
<?php
}

View File

@ -1,6 +1,10 @@
<?php
class ComicPressAddonCore extends ComicPressAddon {
var $is_addon_manager = true;
var $cannot_be_disabled = true;
var $name = "ComicPress Core";
/**
* Initialize the addon.
* @param ComicPress $comicpress The master ComicPress object.
@ -504,7 +508,9 @@ class ComicPressAddonCore extends ComicPressAddon {
* Update ComicPress options.
*/
function handle_update_comicpress_options() {
$this->comicpress->comicpress_options['helpers'] = array();
foreach (array('helpers', 'options') as $type) {
$this->comicpress->comicpress_options[$type] = array();
}
foreach ($this->comicpress->comicpress_options as $option => $value) {
if (isset($_POST['cp'][$option])) {
switch ($option) {
@ -550,8 +556,9 @@ class ComicPressAddonCore extends ComicPressAddon {
$this->comicpress->comicpress_options[$option] = $_POST['cp'][$option];
break;
case 'helpers':
foreach ($_POST['cp'][$option] as $helper => $set) {
$this->comicpress->comicpress_options['helpers'][$helper] = true;
case 'addons':
foreach ($_POST['cp'][$option] as $type => $set) {
$this->comicpress->comicpress_options[$option][$type] = true;
}
break;
}
@ -575,7 +582,7 @@ class ComicPressAddonCore extends ComicPressAddon {
function handle_update_override_partial($info) {
switch ($info['action']) {
case __('Update partial', 'comicpress'):
$this->comicpress->comicpress_options['override_partials'][$info['partial']] = $info['code'];
$this->comicpress->comicpress_options['override_partials'][$info['partial']] = stripslashes($info['code']);
break;
case __('Delete override partial', 'comicpress'):
unset($this->comicpress->comicpress_options['override_partials'][$info['partial']]);

View File

@ -69,7 +69,7 @@
<?php }
}
?>
<p><em>(categories can be modified on the Posts -> Categories page)</em></p>
<p><em><?php _e('(categories can be modified on the Posts -> Categories page)', 'comicpress') ?></em></p>
</td>
</tr>
<tr>
@ -98,20 +98,51 @@
<h3><?php _e('Admin Options', 'comicpress') ?></h3>
<table class="widefat fixed">
<tr>
<th scope="row">
Enable editing helpers
</th>
<th scope="row"><?php _e('Enable editing helpers', 'comicpress') ?></th>
<td>
<?php
foreach (array(
"show_partials_info" => __('Show partials info', 'comicpress'),
"show_inline_comic_ordering" => __('Show inline comic ordering', 'comicpress')
) as $key => $label) { ?>
<label><input type="checkbox" name="cp[helpers][<?php echo $key ?>]" value="yes" <?php echo (($this->comicpress->comicpress_options['helpers'][$key] === true) ? 'checked="checked"' : '') ?> /> <?php echo $label ?></label><br />
<label>
<input type="checkbox"
name="cp[helpers][<?php echo $key ?>]"
value="yes"
<?php echo (($this->comicpress->comicpress_options['helpers'][$key] === true) ? 'checked="checked"' : '') ?> />
<?php echo $label ?>
</label>
<br />
<?php }
?>
</td>
</tr>
<?php if (is_array($this->all_addons)) { ?>
<tr>
<th scope="row"><?php _e('Enable addons', 'comicpress') ?></th>
<td>
<?php
foreach ($this->all_addons as $addon) {
if (!empty($addon->name)) {
$enabled = ($addon->is_addon_manager !== true);
$checked = $enabled && $this->comicpress->comicpress_options['addons'][$addon->name];
?>
<label>
<input type="checkbox"
name="cp[addons][<?php echo $addon->name ?>]"
value="yes"
<?php echo !$enabled ? 'disabled="disabled"' : '' ?>
<?php echo $checked ? 'checked="checked"' : '' ?> />
<?php echo $addon->name ?>
</label><br />
<?php }
}
?>
</td>
</tr>
<?php } ?>
</table>
<input type="submit" value="<?php _e("Submit Changes", 'comicpress') ?>" /> </form>
<input class="button" type="submit" value="<?php _e('Submit Changes', 'comicpress') ?>" />
</form>
</div>

View File

@ -7,6 +7,7 @@
class ComicPressAddonSearchTranscripts extends ComicPressAddon {
var $custom_template_default = 'search-transcript.php';
var $name = "Search Transcripts";
function init($comicpress) {
add_filter('posts_join', array(&$this, 'search_custom_join'));

View File

@ -16,7 +16,8 @@ class ComicPress {
'category_usage' => 'storyline',
'layout' => 'classic.inc',
'helpers' => array(),
'override_partials' => array()
'override_partials' => array(),
'addons' => array()
);
var $additional_stylesheets = array();

View File

@ -170,10 +170,16 @@ class ComicPressComicPost {
usort($remaining_posts_to_sort[$type], array(&$this, 'sort_remaining_comic_images'));
}
$result = array_merge($comic_image_ordering, $remaining_posts_to_sort);
foreach ($remaining_posts_to_sort as $type => $posts) {
if (is_array($comic_image_ordering[$type])) {
$comic_image_ordering[$type] = array_merge($comic_image_ordering[$type], $posts);
} else {
$comic_image_ordering[$type] = $posts;
}
}
update_post_meta($this->post->ID, 'comic_ordering', $this->build_comic_ordering_string($result));
return $result;
update_post_meta($this->post->ID, 'comic_ordering', $this->build_comic_ordering_string($comic_image_ordering));
return $comic_image_ordering;
}
}

View File

@ -18,12 +18,6 @@ function __comicpress_init() {
$comicpress->init();
$addons = array();
if (get_magic_quotes_gpc()) {
$_POST = stripslashes_deep($_POST);
$_GET = stripslashes_deep($_GET);
$_REQUEST = stripslashes_deep($_REQUEST);
}
if (is_dir($addons_dir = (dirname(__FILE__) . '/addons'))) {
$entries = glob($addons_dir . '/*');
if (is_array($entries)) {
@ -36,6 +30,10 @@ function __comicpress_init() {
if (class_exists($classname)) {
$addon =& new $classname();
if (
$comicpress->comicpress_options['addons'][$addon->name] ||
$addon->is_addon_manager
) {
$addon->init(&$comicpress);
if (current_user_can('edit_posts')) {
if (is_array($_REQUEST['cp'])) {
@ -54,6 +52,7 @@ function __comicpress_init() {
add_action('wp_head', array(&$addon, 'display_messages'));
}
}
}
$addons[] = $addon;
}
}
@ -62,6 +61,10 @@ function __comicpress_init() {
}
}
foreach ($addons as $addon) {
if ($addon->is_addon_manager) { $addon->all_addons =& $addons; break; }
}
$layouts = $comicpress->get_layout_choices();
if (isset($layouts[$comicpress->comicpress_options['layout']])) {
if (isset($layouts[$comicpress->comicpress_options['layout']]['Sidebars'])) {
@ -98,7 +101,7 @@ function include_partial($partials = '') {
if (($result = $comicpress->get_options_partial($partials)) !== false) {
list($target, $code) = $result;
ob_start(); eval('?>' . $code . '<?'); $content = ob_get_clean();
ob_start(); eval(' ?>' . $code . '<?php '); $content = ob_get_clean();
} else {
$target = $comicpress->get_partial_path($partials);

View File

@ -1,81 +1,70 @@
var cl = 31;
/* Below are our functions for this little script */
function bmhome() {
if(document.getElementById) {
document.getElementById('gtc').src = imgGotoOn;
document.getElementById('rmc').src = imgClearOn;
var button_images = {
'clear-tag': {
'off': '3a.gif', 'on': '3.gif'
},
'goto-tag': {
'off': '2a.gif', 'on': '2.gif'
}
createCookie("bm", comicPermalink, cl);
};
var BookmarkInfo = Class.create({
'default': {
'permalink': false
},
'initialize': function() {
this.jar = new CookieJar({
'expires': 60 * 60 * 24 * 31,
'path': '/'
});
},
'read': function() {
var bookmark_info = this.jar.get('bookmark-info');
if ((typeof(bookmark_info) != 'object') || (bookmark_info == null)) {
bookmark_info = this.default;
}
function bm() {
if(document.getElementById) {
document.getElementById('gtc').src = imgGotoOn;
document.getElementById('rmc').src = imgClearOn;
}
createCookie("bm", window.location, cl);
return bookmark_info;
},
'write': function(bookmark_info) {
this.jar.put('bookmark-info', bookmark_info);
if (this.onWrite) { this.onWrite(bookmark_info); }
}
});
function bmc() {
if(document.getElementById) {
document.getElementById('gtc').src = imgGotoOff;
document.getElementById('rmc').src = imgClearOff;
}
createCookie("bm","",-1);
}
Event.observe(window, 'load', function() {
var bookmark_info = new BookmarkInfo();
var info = bookmark_info.read();
function gto() {
var g = readCookie('bm');
if(g) {
window.location = g;
}
}
var hrefs = {};
$$('#comic-bookmark-holder a').each(function(a) {
var name = $w(a.className).shift();
hrefs[name] = a;
});
/* The follow functions have been borrowed from Peter-Paul Koch. Please find them here: http://www.quirksmode.org */
var set_goto_tag = function(i) {
hrefs['goto-tag'].href = (i.permalink ? i.permalink : "#");
[ 'goto-tag','clear-tag' ].each(function(which) {
hrefs[which].select('img')[0].src = image_root + button_images[which][i.permalink ? "on" : "off"];
});
};
function createCookie(name,value,days) {
if (days) {
var date = new Date();
date.setTime(date.getTime()+(days*24*60*60*1000));
var expires = "; expires="+date.toGMTString();
} else var expires = "";
document.cookie = name+"="+value+expires+"; path="+comicDir;
}
function readCookie(name) {
var nameEQ = name + "=";
var ca = document.cookie.split(';');
for(var i=0;i < ca.length;i++) {
var c = ca[i];
while (c.charAt(0)==' ') c = c.substring(1,c.length);
if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
}
return null;
}
bookmark_info.onWrite = function(i) { set_goto_tag(i); }
set_goto_tag(info);
function writeBookmarkWidget() {
createCookie('t', 1);
var c = readCookie('t');
if (c && document.getElementById) {
var l = readCookie('bm');
var gt = imgGotoOff;
var ct = imgClearOff;
if (l) {
gt = imgGotoOn;
ct = imgClearOn;
}
document.write('<div id="bmh" style="width: 173px; margin: 15px 0 0 0; padding: 5px; position: absolute; color: #eee; font-size: 11px; background-color:#222; border: 1px solid #ccc; visibility: hidden;"><b>COMIC BOOKMARK</b><br />Click "Tag Page" to bookmark a comic page. When you return to the site, click "Goto Tag" to continue where you left off.</div>');
if (isHome) {
document.write('<a href="#" onClick="bmhome();return false;"><img src="'+imgTag+'" alt="Tag This Page" border="0"></a>');
document.write('<a href="#" onClick="gto();return false;"><img src="'+gt+'" alt="Goto Tag" border="0" id="gtc"></a>');
document.write('<a href="#" onClick="bmc();return false;"><img src="'+ct+'" alt="Clear Tag" border="0" id="rmc"></a>');
document.write('<a href="#" onMouseOver="document.getElementById(\'bmh\').style.visibility=\'visible\';" onMouseOut="document.getElementById(\'bmh\').style.visibility=\'hidden\';" onClick="return false;"><img src="'+imgInfo+'" alt="" border="0"></a>');
} else if (isSingle) {
document.write('<a href="#" onClick="bm();return false;"><img src="'+imgTag+'" alt="Tag This Page" border="0"></a>');
document.write('<a href="#" onClick="gto();return false;"><img src="'+gt+'" alt="Goto Tag" border="0" id="gtc"></a>');
document.write('<a href="#" onClick="bmc();return false;"><img src="'+ct+'" alt="Clear Tag" border="0" id="rmc"></a>');
document.write('<a href="#" onMouseOver="document.getElementById(\'bmh\').style.visibility=\'visible\';" onMouseOut="document.getElementById(\'bmh\').style.visibility=\'hidden\';" onClick="return false;"><img src="'+imgInfo+'" alt="" border="0"></a>');
}
}
}
Event.observe(hrefs['tag-page'], 'click', function(e) {
Event.stop(e);
info.permalink = permalink;
bookmark_info.write(info);
});
Event.observe(hrefs['clear-tag'], 'click', function(e) {
Event.stop(e);
info.permalink = false;
bookmark_info.write(info);
});
Event.observe(hrefs['goto-tag'], 'click', function(e) {
if (hrefs['goto-tag'].href == "#") { Event.stop(e); }
});
});

157
js/cookiejar.js Normal file
View File

@ -0,0 +1,157 @@
/**
* Javascript code to store data as JSON strings in cookies.
* It uses prototype.js 1.5.1 (http://www.prototypejs.org)
*
* Author : Lalit Patel
* Website: http://www.lalit.org/lab/jsoncookies
* License: Apache Software License 2
* http://www.apache.org/licenses/LICENSE-2.0
* Version: 0.5
* Updated: Jan 26, 2009
*
* Chnage Log:
* v 0.5
* - Changed License from CC to Apache 2
* v 0.4
* - Removed a extra comma in options (was breaking in IE and Opera). (Thanks Jason)
* - Removed the parameter name from the initialize function
* - Changed the way expires date was being calculated. (Thanks David)
* v 0.3
* - Removed dependancy on json.js (http://www.json.org/json.js)
* - empty() function only deletes the cookies set by CookieJar
*/
var CookieJar = Class.create();
CookieJar.prototype = {
/**
* Append before all cookie names to differntiate them.
*/
appendString: "__CJ_",
/**
* Initializes the cookie jar with the options.
*/
initialize: function(options) {
this.options = {
expires: 3600, // seconds (1 hr)
path: '', // cookie path
domain: '', // cookie domain
secure: '' // secure ?
};
Object.extend(this.options, options || {});
if (this.options.expires != '') {
var date = new Date();
date = new Date(date.getTime() + (this.options.expires * 1000));
this.options.expires = '; expires=' + date.toGMTString();
}
if (this.options.path != '') {
this.options.path = '; path=' + escape(this.options.path);
}
if (this.options.domain != '') {
this.options.domain = '; domain=' + escape(this.options.domain);
}
if (this.options.secure == 'secure') {
this.options.secure = '; secure';
} else {
this.options.secure = '';
}
},
/**
* Adds a name values pair.
*/
put: function(name, value) {
name = this.appendString + name;
cookie = this.options;
var type = typeof value;
switch(type) {
case 'undefined':
case 'function' :
case 'unknown' : return false;
case 'boolean' :
case 'string' :
case 'number' : value = String(value.toString());
}
var cookie_str = name + "=" + escape(Object.toJSON(value));
try {
document.cookie = cookie_str + cookie.expires + cookie.path + cookie.domain + cookie.secure;
} catch (e) {
return false;
}
return true;
},
/**
* Removes a particular cookie (name value pair) form the Cookie Jar.
*/
remove: function(name) {
name = this.appendString + name;
cookie = this.options;
try {
var date = new Date();
date.setTime(date.getTime() - (3600 * 1000));
var expires = '; expires=' + date.toGMTString();
document.cookie = name + "=" + expires + cookie.path + cookie.domain + cookie.secure;
} catch (e) {
return false;
}
return true;
},
/**
* Return a particular cookie by name;
*/
get: function(name) {
name = this.appendString + name;
var cookies = document.cookie.match(name + '=(.*?)(;|$)');
if (cookies) {
return (unescape(cookies[1])).evalJSON();
} else {
return null;
}
},
/**
* Empties the Cookie Jar. Deletes all the cookies.
*/
empty: function() {
keys = this.getKeys();
size = keys.size();
for(i=0; i<size; i++) {
this.remove(keys[i]);
}
},
/**
* Returns all cookies as a single object
*/
getPack: function() {
pack = {};
keys = this.getKeys();
size = keys.size();
for(i=0; i<size; i++) {
pack[keys[i]] = this.get(keys[i]);
}
return pack;
},
/**
* Returns all keys.
*/
getKeys: function() {
keys = $A();
keyRe= /[^=; ]+(?=\=)/g;
str = document.cookie;
CJRe = new RegExp("^" + this.appendString);
while((match = keyRe.exec(str)) != undefined) {
if (CJRe.test(match[0].strip())) {
keys.push(match[0].strip().gsub("^" + this.appendString,""));
}
}
return keys;
}
};

View File

@ -1,6 +1,6 @@
<div class="post-comic-head"></div>
<div class="post-comic">
<?php include('nav.inc') ?>
<?php include_partial('nav') ?>
<div class="comicdate"><?php the_date('F jS, Y') ?></div>
<br class="clear" />
<h2>

View File

@ -151,7 +151,7 @@ class ComicPressComicPostTest extends PHPUnit_Framework_TestCase {
$p->expects($this->any())->method('get_comic_image_attachments')->will($this->returnValue($attachments));
wp_insert_post((object)array('ID' => 1));
update_post_meta(1, 'comic_ordering', "comic:3,2");
update_post_meta(1, 'comic_ordering', "comic:3");
$p->post = (object)array('ID' => 1);