Page 1 of 1

Sidebar Calendar Problems

Posted: Fri Dec 02, 2005 3:33 am
by graden
Can anyone help me figure out why the "Travelogue Index" sidebar won't work correctly? I am using the "Date List" plugin for this sidebar item.

Here is the site:
http://www.2upon2wheels.com/serendipity/

Any help is appreciated. Thank you! :)

Posted: Fri Dec 02, 2005 3:51 am
by judebert
Well, I can say this much: the entries are creating a link like
<your site>/serendipity/index.php?/archives/20050826.html, which doesn't work, while
<your site>/serendipity/index.php?/archives/2005/08/26.html works fine.

Of course, I also can't find the Date List plugin, so you'll need more help than this. (I must say, it looks cool, though.)

Posted: Fri Dec 02, 2005 12:24 pm
by garvinhicking
We don't have that plugin in our repository, where is it from? The permalinks used there are not compatible with recent serendipity versions...

Regards,
Garvin

Posted: Sat Dec 03, 2005 12:36 am
by graden
Here is the plugin download link:
http://www.risingdawn.org/plugins/seren ... telist.zip

This plugin was actually found toward the bottom of this page:
http://s9y.org/29.html

Perhaps I could modify this plugin to make it Serendipity v0.9-compatible? I'm going to poke around and do my best, but any help is appreciated.

Posted: Sat Dec 03, 2005 1:03 am
by garvinhicking
Sadly the code looks a bit unstructured to me. But I can tell you this:

Code: Select all

if ($ver == 8)
those checks make the problem, because they would only work in serendipity 0.8 and not 0.9.

One would need to modify all the version checks to not only check the minor version, but check if version > 0.8. Because in the future, serendipity 1.0 will be out, and "0" would be smaller than "8".

Regards,
Garvin

Posted: Sun Dec 04, 2005 12:08 am
by graden
I don't intend on upgrading the Serendipity install on this site. All I need is to make it work with v.9. I could open this up and poke around, but honestly, I don't know what the heck I'm doing. Can anyone tell me what needs to be changed?

Posted: Sun Dec 04, 2005 5:15 am
by judebert
Basically, the thing thinks it's working on 0.7 because it checked for 0.8 and couldn't find it. All that needs to be done is to remove all the checking and all the 0.7 code, and everything should work fine.

Heck, let's try it.

Yup, works for me. I tried it on my website. The easiest thing to do is switch the sense of the comparison. Go to line 175; switch it from if (preg_match("/^0.8" to if(!preg_match("/^0.7" -- note the exclamation point before the preg_match, which means "not".

Of course, this is not a complete or completely tested fix. Basically I changed from asking if the s9y version is 0.8 to asking if it wasn't 0.7. The 0.8 code in this plugin works for 0.8 and above, so far, so it proceeds to work as expected.

Posted: Sun Dec 04, 2005 12:50 pm
by garvinhicking
Judebert's fix looks solid and should get the thing working!

Regards,
Garvin

Posted: Mon Dec 05, 2005 4:15 am
by graden
It seems that the version checks aren't affecting me as much as the link format as pointed out by judebert. I've made the changes to the version checks as suggested, but it's still returning paths that apparently don't work with Serendipity 0.9.

I tried to modify the code to make it work, but like I said before I don't know what I'm doing. Can anyone help me? Maybe I'm doing this incorrectly, anyway.

Posted: Mon Dec 05, 2005 10:52 am
by garvinhicking
Try this plugin:

Code: Select all

<?php

// A plug-in for the Serendipity PHP blog (http://www.s9y.org) by Matthew Maude <matthew@risingdawn.org>

// This is a variation of the archives plug-in, and a copy of the navigation used by the blogs at
// http://www.richardherring.com/warmingup and http://www.emmakennedy.net/blog/
// so thanks to whoever designed that


class serendipity_plugin_datelist extends serendipity_plugin {

	var $title = 'Date List';

	function introspect(&$propbag)
	{
		$propbag->add('name','Date List');
		$propbag->add('description', 'Rip-off of the blog style at www.richardherring.com/warmingup');
		$propbag->add('configuration', array('maxmonths'));
	}

	function introspect_config_item($name, &$propbag) {
		switch($name) {
		case 'maxmonths':
			$propbag->add('type', 'string');
			$propbag->add('name', 'Maximum Months');
			$propbag->add('description', 'Months to display in list (0 = all)');
			$propbag->add('default', 0);
			break;

		default:
			return false;
		}
		return true;
	}


	function generate_content(&$title) {
		$title = $this->title;
		global $serendipity;

		$this->writeStyles();
		$this->writeJavascript();
		$this->drawDateList();
	}
	function writeStyles(){
?>
<style type="text/css">
<!--

#datelist_list {
}

#datelist_recent{

	padding-top: 5px;

}

#datelist_month {
	font-size: 11px;
}

#datelist_recent a:link,
#datelist_recent a:visited,
#datelist_list a:link,
#datelist_list a:visited {
}

#datelist_recent a:hover,
#datelist_list a:hover {
}

#datelist_days {
	padding-left: 2em;
	padding-top: 5px;
	padding-bottom: 5px;
	border-style: none;
	font-size: 10px;
}

#datelist_days a:visited  {
   text-decoration: none;
   border: 0;
   color: #444444;
}


#datelist_days a:link {
   text-decoration: none;
   border: 0;
   color: #000000;
}

#datelist_days a:hover {
   color: #c0c0c0;
}

.open {
	display: block;
}

.closed {
	display: none;
}
-->
</style>
<?php
	}

	function writeJavascript(){
		global $serendipity;
		$imgPath = $serendipity['baseURL'] . 'plugins/serendipity_plugin_datelist/';
?>
<script type="text/javascript">
<!--
function toggle(id){

	//closedimg = "<?php echo $imgPath; ?>plus.gif";
	//openimg = "<?php echo $imgPath; ?>minus.gif";

	closedimg = "<?php echo serendipity_getTemplateFile('img/plus.png') ?>";
	openimg = "<?php echo serendipity_getTemplateFile('img/minus.png') ?>";

	ul = "days" + id;
	img = "month_img" + id;
	ulElement = document.getElementById(ul);
	imgElement = document.getElementById(img);
	if (ulElement){
		if (ulElement.className == 'closed'){
			ulElement.className = "open";
			imgElement.src = openimg;
		} else {
			ulElement.className = "closed";
			imgElement.src = closedimg;
		}
	}
}
//-->
</script>
<?php
	}

	function drawDateList(){
		global $serendipity;
		$MaxMonths = $this->get_config('maxmonths');

		if (!isset($serendipity['GET']['calendarZoom'])) {
			if (!isset($serendipity['range'])) {
				$serendipity['GET']['calendarZoom'] = serendipity_serverOffsetHour(time());
			} else {
				$serendipity['GET']['calendarZoom'] = serendipity_serverOffsetHour($serendipity['range'][0]);
			}
		}

		$month = date('m', serendipity_serverOffsetHour($serendipity['GET']['calendarZoom'], true));
		$year  = date('Y', serendipity_serverOffsetHour($serendipity['GET']['calendarZoom'], true));

		$pageTime = mktime(0, 0, 0, $month, 1, $year);
		$pageMonth = date('F Y',$pageTime);

		// Get first and last entry
		$minmax = serendipity_db_query("SELECT MAX(timestamp) AS max, MIN(timestamp) AS min FROM {$serendipity['dbPrefix']}entries");

		if (!is_array($minmax) || !is_array($minmax[0]) || $minmax[0]['min'] < 1 || $minmax[0]['max'] < 1){
			echo '(no entries)<br>';
			return false;
		}

		// Find out about diary entries

		$querystring = "SELECT timestamp
			FROM {$serendipity['dbPrefix']}entries e
			WHERE e.isdraft = 'false'
			ORDER BY timestamp DESC";

		$imgPath = $serendipity['baseURL'] . 'plugins/serendipity_plugin_datelist/';
		$rows = serendipity_db_query($querystring);
		if (is_array($rows)) {
			$monthCount = 0;
			echo '<div id="datelist_list">';
			foreach ($rows as $row){
				$thisMonth = date('F Y',$row['timestamp']);
				$thisDay = date('D jS',$row['timestamp']);
				$date = getdate($row['timestamp']);
				if ($thisMonth != $currentMonth){
					if ($monthCount > 0) echo '</div></div>';
					$monthCount++;
					$currentMonth = $thisMonth;
					$open = ((isset($pageMonth) && $pageMonth == $currentMonth) || (!isset($pageMonth) && $currentMonth == 1));
					$monthTime = mktime(0, 0, 0, $date['mon'], 1, $date['year']);
           			$monthLink = serendipity_archiveDateUrl(sprintf('%04d/%02d', $date['year'], $date['mon']));

?>
<div id="datelist_month"><a href="javascript:toggle(<?php echo $monthCount; ?>);">
<img src="<?php echo ($open ? serendipity_getTemplateFile('img/minus.png') : serendipity_getTemplateFile('img/plus.png')); ?>" alt="+" id="month_img<?php echo $monthCount; ?>" border="0"></a> <a href="<?php echo $monthLink; ?>"><?php echo $currentMonth; ?></a>
</div>
<div id="days<?php echo $monthCount; ?>" class="<?php echo ($open ? 'open' : 'closed'); ?>"><div id="datelist_days">
<?php
				}
				if ($thisDay != $currentDay){
					$currentDay = $thisDay;
?>
<a href="<?php echo serendipity_archiveDateUrl(sprintf('%4d/%02d/%02d', $date['year'], $date['mon'], $date['mday'])); ?>"><?php echo $currentDay; ?></a><br>
<?php
				}
				if ($MaxMonths > 0 && $monthCount >= $MaxMonths) break;
			}
			echo '</div></div></div>';
			echo "<div id='datelist_recent'><a href='{$serendipity['serendipityHTTPPath']}'>" . RECENT . "</a></div>\n";
		}
	}
}

Posted: Mon Dec 05, 2005 5:12 pm
by graden
Yes! This worked great. Thank you very much for all of your help, everybody. I only had to change a couple of things (list order, and delete "Recent" link per client request). One of these days I'll learn PHP code for myself instead of just coasting through it...

The final product is seen here.