Author: spikeyslam
Date: Sun Jul 30 18:25:06 2006
New Revision: 20
Modified:
trunk/header.php
trunk/js/livesearch.js.php
trunk/js/rollingarchives.js.php
trunk/options/app/info.php
trunk/rollingarchive.php
trunk/theloop.php
Log:
Made rolling archives into a class. OOP. yay! Fixed the Older/Newer links problem with rolling archives & live search. There's a dislay glitch with the slider.
k2countpages & rolling archives now works with any query. This should help with implementing the navigation system.
New asides filter.
Modified: trunk/header.php
=========================================================================== ===
--- trunk/header.php (original)
+++ trunk/header.php Sun Jul 30 18:25:06 2006
@@ -34,9 +34,14 @@
<?php /* LiveSearch */ if (get_option('k2livesearch') == 1) { ?>
<script type="text/javascript" src="<?php bloginfo('template_directory'); ?>/js/livesearch.js.php"></script>
+ <script type="text/javascript">
+ // <![CDATA[
+ var currentquery = '<?php echo $wp_query->query; ?>';
+ // ]]>
+ </script>
<?php } ?>
- <?php /* Rolling Archives */ if ((is_home() or is_paged()) and (get_option('k2rollingarchives')) == 1) { ?>
+ <?php /* Rolling Archives */ if (get_option('k2rollingarchives') == 1) { ?>
<script type="text/javascript" src="<?php bloginfo('template_directory'); ?>/js/rollingarchives.js.php"></script>
<?php } ?>
Modified: trunk/js/livesearch.js.php
=========================================================================== ===
--- trunk/js/livesearch.js.php (original)
+++ trunk/js/livesearch.js.php Sun Jul 30 18:25:06 2006
@@ -72,7 +72,7 @@
{
method: 'get',
evalScripts: true,
- parameters: this.pars + $F(this.attachitem)
+ parameters: this.pars + $F(this.attachitem) + '&rolling=1'
//onLoading: Effect.Appear(this.loaditem, {duration: .2})
});
Event.observe(this.resetbutton, 'click', this.resetLivesearch.bindAsEventListener(this));
@@ -93,7 +93,7 @@
{
method: 'get',
evalScripts: true,
- parameters: this.pars + $F(this.attachitem)
+ parameters: currentquery + '&rolling=1'
});
Event.stop(this.resetbutton);
$(this.resetbutton).style.cursor = 'default';
Modified: trunk/js/rollingarchives.js.php
=========================================================================== ===
--- trunk/js/rollingarchives.js.php (original)
+++ trunk/js/rollingarchives.js.php Sun Jul 30 18:25:06 2006
@@ -19,109 +19,130 @@
header('Content-Type: text/javascript; charset: UTF-8');
?>
-function rollArchive(direction, parms) {
- if (direction == 1 || direction == -1) {
- pagenumber += direction;
- new Effect.Appear('rollload', {duration: .1});
- } else if (direction == 'home') {
- pagenumber = 1;
- }
+RollingArchives = Class.create();
- checkRollingElements();
- new Ajax.Updater({success: 'content'}, '<?php bloginfo('template_url'); ?>/theloop.php', {method: 'get', parameters: '&s='+parms+'&paged='+pagenumber, onSuccess: rollSuccess, onFailure: rollError});
-}
-
-
-function rollGotoPage(gotopage, parms) {
- pagenumber = (gotopage - 1);
- rollArchive(1, parms);
-}
-
-
-function rollSuccess() {
- rollRemoveLoad();
- /*if (pagenumber > 1) { // If we've moved into the archives,
- setCookie('rollpage', pagenumber); // set a cookie so we can return to that page.
- } else if (pagenumber = 1) {
- deleteCookie('rollpage');
- }*/
-}
-
-
-function rollError() {
- $('rollnotices').innerHTML = 'Error! <a href="javascript:initRollingArchives()">Reboot</a>';
-}
-
-
-function rollRemoveLoad() {
- new Effect.Fade('rollload', {duration: .1});
-}
-
-
-// Needs to be run when a direction is picked, but not when you click the link the notice provides. FIX IT
-function rollRemoveNotices() {
- new Effect.Fade($('rollnotices'));
- $('rollnotices').innerHTML = null;
-}
-
-
-function checkRollingElements() {
- if (pagenumber == 1) {
- $('rollprevious').className = null;
- $('rollprevious').onclick = function() { PageSlider.setValueBy(1); return false; };
- $('rollnext').className = 'inactive';
- $('rollnext').onclick = null;
- $('rollhome').className = 'inactive';
- $('rollhome').onclick = null;
- } else if (pagenumber > 1) {
- $('rollnext').className = null;
- $('rollnext').onclick = function() { PageSlider.setValueBy(-1); return false; };
- $('rollhome').className = null;
- $('rollhome').onclick = function() { rollArchive('home'); };
- }
+RollingArchives.prototype = {
+ initialize: function(targetitem, url, query, pagecount) {
+ var rolling = this;
+
+ this.targetitem = targetitem;
+ this.url = url;
+ this.query = query;
+ this.pagecount = pagecount;
+ this.pagenumber = 1;
+
+ this.rollnext = $('rollnext');
+ this.rollprev = $('rollprevious');
+
+ var sliderValues = new Array(this.pagecount);
+ for (var i = 0; i < this.pagecount; i++) {
+ sliderValues[i] = i + 1;
+ }
+ this.PageSlider = new Control.Slider('pagehandle','pagetrack', {
+ range: $R(rolling.pagecount, 1),
+ values: sliderValues,
+ sliderValue: 1,
+ onSlide: function(v) { $('rollpages').innerHTML = 'Page '+v+' of '+rolling.pagecount; },
+ onChange: function(v) { rolling.gotoPage(v); },
+ handleImage: 'pagehandle'
+ });
+
+ Event.observe('rollprevious', 'click', function(){ rolling.rollPrevPage(); });
+ Event.observe('rollnext', 'click', function(){ rolling.rollNextPage(); });
+
+ this.checkRollingElements();
+ this.rollRemoveLoad();
+
+ this.initialized = true;
+ },
+
+ rollNextPage: function() {
+ this.PageSlider.setValueBy(-1);
+ },
+
+ rollPrevPage: function() {
+ this.PageSlider.setValueBy(1);
+ },
+
+ checkRollingElements: function() {
+ if (this.pagenumber == 1) {
+ $('rollprevious').className = null;
+ $('rollnext').className = 'inactive';
+ $('rollhome').className = 'inactive';
+ } else if (this.pagenumber > 1) {
+ $('rollnext').className = null;
+ $('rollhome').className = null;
+ }
+
+ if (this.pagenumber >= this.pagecount) {
+ $('rollprevious').className = 'inactive';
+ } else {
+ $('rollprevious').className = null;
+ }
+
+ $('rollpages').innerHTML = 'Page '+this.pagenumber+' of '+this.pagecount;
+ },
- if (pagenumber >= pagecount) {
- $('rollprevious').className = 'inactive';
- $('rollprevious').onclick = null;
- } else {
- $('rollprevious').className = null;
- $('rollprevious').onclick = function() { PageSlider.setValueBy(1); return false; };
- }
+ gotoPage: function(newpage) {
+ var direction = 0;
- //alert('Pagecount: '+pagecount);
- if (pagecount != 0) {
- $('rollpages').innerHTML = 'Page '+pagenumber+' of '+pagecount; // Insert page count
- } else {
- $('rollpages').innerHTML = 'No Pages'; // Insert page count
+ if (newpage != this.pagenumber) {
+ if (newpage > this.pagecount) {
+ direction = 'end';
+ } else if (newpage < 1) {
+ direction = 'home';
+ } else {
+ direction = 1;
+ }
+ this.pagenumber = (newpage - 1);
+ this.rollArchive(direction);
+ }
+ },
+
+ rollRemoveLoad: function() {
+ new Effect.Fade('rollload', {duration: .1});
+ },
+
+ rollSuccess: function() {
+ this.rollRemoveLoad();
+ },
+
+ rollError: function() {
+ $('rollnotices').innerHTML = 'Error!';
+ },
+
+ processQuery: function() {
+ if (this.query.indexOf('&paged=') != -1) {
+ this.query = this.query.replace(/&paged=\d+/,'&paged='+this.pagenumber);
+ } else {
+ this.query += "&paged=" + this.pagenumber;
+ }
+
+ if (this.query.indexOf('&rolling=') == -1) {
+ this.query += '&rolling=1';
+ }
+ },
+
+ rollArchive: function(direction) {
+ if (direction == 1 || direction == -1) {
+ this.pagenumber += direction;
+ new Effect.Appear('rollload', {duration: .1});
+ } else if (direction == 'home') {
+ this.pagenumber = 1;
+ }
+
+ this.checkRollingElements();
+ this.processQuery();
+
+ new Ajax.Updater(
+ this.targetitem,
+ this.url,
+ {
+ method: 'get',
+ parameters: this.query,
+ onSuccess: this.rollSuccess.bind(this),
+ onFailure: this.rollError.bind(this)
+ }
+ );
}
-}
-
-function disableRollingArchives() {
- $('rollprevious').className = 'inactive';
- $('rollnext').className = 'inactive';
- PageSlider.setDisabled();
- Effect.Fade('pagetrack', { duration: .1, from: 1.0, to: 0.3 });
-}
-
-function initRollingArchives(currentpage, pages) {
- pagenumber = currentpage;
- pagecount = pages;
-
- checkRollingElements(pagenumber);
-
- rollRemoveLoad();
-
- $('rollnotices').style.display = 'none';
-
- /*if (getCookie('rollpage') != null) {
- $('rollnotices').innerHTML = 'This session you were last seen on <a href="javascript:rollGotoPage('+getCookie('rollpage')+');">page '+getCookie('rollpage')+'</a>. <img src="<?php bloginfo('template_url'); ?>/images/transparent.gif" alt="Reset" onclick="Effect.Fade($(\'rollnotices\')); deleteCookie(\'rollpage\');" />';
- new Effect.Highlight('rollnotices');
- } else {
- $('rollnotices').style.display = 'none';
- }*/
-
-}
-
-
-// Initialize the Rolling Archives
-//Event.observe(window, 'load', initRollingArchives, false);
+};
\ No newline at end of file
Modified: trunk/options/app/info.php
=========================================================================== ===
--- trunk/options/app/info.php (original)
+++ trunk/options/app/info.php Sun Jul 30 18:25:06 2006
@@ -98,51 +98,22 @@
return false;
}
-function k2countposts() {
- global $wpdb;
-
- $k2asidescategory = get_option('k2asidescategory');
- $k2asidesposition = get_option('k2asidesposition');
-
- $join = '';
- $where = "1=1 AND post_status = 'publish'";
-
- if (($k2asidescategory != '0') and ($k2asidesposition == '1') and ($_GET["dynamic"] != '1')) {
- $join = " LEFT JOIN $wpdb->post2cat ON ($wpdb->posts.ID = $wpdb->post2cat.post_id) ";
- $where .= " AND (category_id != $k2asidescategory)";
+function k2countpages($query_string) {
+ if (!preg_match("/posts_per_page=/", $query_string)) {
+ $posts_per_page = get_settings('posts_per_page');
}
- $query = "SELECT DISTINCT $wpdb->posts.ID FROM $wpdb->posts $join WHERE $where GROUP BY $wpdb->posts.ID";
-
- return (int) count($wpdb->get_col($query));
-}
-
-
-function k2countpages() {
- return (int) ceil(k2countposts() / get_settings('posts_per_page'));
-}
-
-
-function k2countsearchposts($uriquery = '') {
- $search_count = 0;
-
- $search = new WP_Query($uriquery.'&showposts=-1');
- if ($search->have_posts()) {
- while($search->have_posts()) {
- $search->the_post();
- $search_count++;
- }
- }
+ $new_query = new WP_Query();
+ $new_query->parse_query($query_string);
+ $new_query->set('posts_per_page', '-1');
+ $new_query->get_posts();
+ $post_count = $new_query->post_count;
+
+ unset($new_query);
- return (int) $search_count;
+ return ceil($post_count / $posts_per_page );
}
-
-function k2countsearchpages($uriquery) {
- return (int) ceil(k2countsearchposts($uriquery) / get_settings('posts_per_page'));
-}
-
-
/* By Mark Jaquith, http://txfx.net */
function k2_nice_category($normal_separator = ', ', $penultimate_separator = ' and ') {
$categories = get_the_category();
@@ -164,4 +135,18 @@
}
return apply_filters('the_category', $thelist, $normal_separator);
}
+
+
+function k2asides_filter($query) {
+ $k2asidescategory = get_option('k2asidescategory');
+ $k2asidesposition = get_option('k2asidesposition');
+
+ if ( ($k2asidescategory != 0) && ($k2asidesposition == 1) && ($query->is_home) ) {
+ $query->set('cat', '-'.$k2asidescategory);
+ }
+
+ return $query;
+}
+
+add_filter('pre_get_posts', 'k2asides_filter');
?>
Modified: trunk/rollingarchive.php
=========================================================================== ===
--- trunk/rollingarchive.php (original)
+++ trunk/rollingarchive.php Sun Jul 30 18:25:06 2006
@@ -1,16 +1,19 @@
<?php
// Get Core WP Functions If Needed
- if (isset($_GET['s'])) { require (dirname(__FILE__)."/../../../wp-blog-header.php"); }
+ if (isset($_GET['rolling'])) {
+ require (dirname(__FILE__)."/../../../wp-blog-header.php");
+ }
// Load Rolling Archives?
- if (get_option('k2rollingarchives') == 1) {
+ if ( (get_option('k2rollingarchives') == 1) ) {
//Need PHP to construct proper query string based on incoming variables.
- $k2countpages = k2countsearchpages('s='.$s);
-?>
+ $k2pagecount = k2countpages($wp_query->query);
+ if ($k2pagecount > 1) {
+?>
<div id="rollingarchives">
<div id="rollnavigation">
<a href="#" id="rollprevious"><span>«</span> <?php _e('Older','k2_domain'); ?></a>
@@ -18,23 +21,6 @@
<div id="pagetrack"><div id="pagetrackend"><div id="pagehandle"></div></div></div>
- <script type="text/javascript">
- // <![CDATA[
- var pagecount = '<?php echo $k2countpages; ?>';
- var currentpage = '<?php if (isset($_GET[paged])) { echo $_GET[paged]; } else { echo '1'; } ?>';
-
- var PageSlider = new Control.Slider('pagehandle','pagetrack', {
- sliderValue: <?php if (isset($_GET[paged])) { echo $_GET[paged]; } else { echo '1'; } ?>,
- range: $R(<?php echo $k2countpages; ?>, 1),
- values: [<?php for ($i = 1; $i < $k2countpages; $i++) { echo $i.", "; }; echo $i; ?>],
- onSlide: function(v) { $('rollpages').innerHTML = 'Page '+v+' of '+<?php echo $k2countpages; ?> },
- onChange: function(v) { rollGotoPage(v, '<?php echo $s; ?>') },
- handleImage: 'pagehandle',
- handleDisabled: 'images/sliderbgright.png'
- });
- // ]]>
- </script>
-
<span id="rollload"><?php _e('Loading','k2_domain'); ?></span>
<span id="rollpages"></span>
@@ -43,17 +29,14 @@
<div id="rollnotices"></div>
</div>
-
<script type="text/javascript">
- initRollingArchives(currentpage, <?php echo $k2countpages; ?>);
-
- <?php if ($k2countpages < 2) { ?>
- disableRollingArchives();
- <?php } ?>
+ // <![CDATA[
+ var rolling = new RollingArchives('content', '<?php echo get_bloginfo('template_url').'/theloop.php'; ?>', '<?php echo $wp_query->query; ?>', <?php echo $k2pagecount; ?>);
+ // ]]>
</script>
-<?php } ?>
+<?php } } ?>
<div id="content">
<?php include (TEMPLATEPATH . '/theloop.php'); ?>
-</div>
+</div>
\ No newline at end of file
Modified: trunk/theloop.php
=========================================================================== ===
--- trunk/theloop.php (original)
+++ trunk/theloop.php Sun Jul 30 18:25:06 2006
@@ -3,16 +3,11 @@
// It is a delicate piece of machinery. Be gentle!
// Get Core WP Functions If Needed
- if (($_GET["s"] != '') or (($_GET["paged"] != ''))) { require (dirname(__FILE__)."/../../../wp-blog-header.php"); }
-
- // Asides Segregation
- if ( (get_option('k2asidescategory') != '0') and (get_option('k2asidesposition') == '1') and (is_home()) ) {
- if (is_paged()) {
- query_posts('cat=-'.get_option('k2asidescategory').'&paged='.$paged);
- } else {
- query_posts('cat=-'.get_option('k2asidescategory'));
- }
+ if (isset($_GET['rolling'])) {
+ require (dirname(__FILE__).'/../../../wp-blog-header.php');
}
+
+ //print_r($wp_query->query);
?>
<div id="primarycontent">