From fe16218122d199bc6250b72177ceb83134fced1c Mon Sep 17 00:00:00 2001
From: Denis Walker <dez@sucs.org>
Date: Wed, 28 Nov 2007 21:54:33 +0000
Subject: [PATCH] Addresses URI encoding so that spaces become underscores

---
 components/front.php                |  4 ++--
 components/news.php                 |  5 +++--
 htdocs/index.php                    |  3 +--
 plugins/function.articlesummary.php | 14 ++------------
 plugins/modifier.encodestring.php   |  8 ++++++++
 templates/contents-loop.tpl         |  3 ++-
 templates/front.tpl                 |  3 ++-
 templates/news.tpl                  |  6 +++---
 templates/news_edit.tpl             |  2 +-
 9 files changed, 24 insertions(+), 24 deletions(-)
 create mode 100644 plugins/modifier.encodestring.php

diff --git a/components/front.php b/components/front.php
index 469d730..d0f910e 100644
--- a/components/front.php
+++ b/components/front.php
@@ -12,9 +12,9 @@ if (!$session->loggedin) {
 //include('users.php');
 //$output .= $result;
 //include('planetposts.php');
-$output .= $result;
+//$output .= $result;
 //include('forumposts.php');
-$output .= $result;
+//$output .= $result;
 
 }
 $smarty->assign("secondary",$output);
diff --git a/components/news.php b/components/news.php
index 8c6631e..ef8a99c 100644
--- a/components/news.php
+++ b/components/news.php
@@ -1,7 +1,7 @@
 <?php
 
 // A user must be in the staff group in order to edit content in this component
-$permission = "staff";
+$permission = "html";
 $newstable = "news";
 
 if (isset($session->groups[$permission])) {
@@ -19,6 +19,7 @@ if (isset($session->groups[$permission])) {
 		if ($_REQUEST['id']=="*") {
 			$record['author'] = $session->username;
 			$record['date'] = "now";
+			$record['shorttitle'] = $_REQUEST['edittitle'];
 			$DB->AutoExecute($newstable, $record, 'INSERT');
 		} else {
 			$DB->AutoExecute($newstable, $record, 'UPDATE', "id=".$DB->qstr($_REQUEST['id']));
@@ -54,9 +55,9 @@ if (isset($session->groups[$permission])) {
 		$news = array(array("id" => "*"));
 		$smarty->assign("news", $news);
 	case "edit":
-		$output = $smarty->fetch("news_edit.tpl");
 		$smarty->assign("action", "edit");
 		$smarty->assign("title", "Edit News");
+		$output = $smarty->fetch("news_edit.tpl");
 		break;
 	case "delete-query":
 		$output = $smarty->fetch('news_delete.tpl').$output;		
diff --git a/htdocs/index.php b/htdocs/index.php
index 27b2f1e..3c99268 100644
--- a/htdocs/index.php
+++ b/htdocs/index.php
@@ -104,9 +104,8 @@ if (SUCS_USE_HTTPS) {
 $smarty->assign("ssl_url", $ssl_url);
 
 
-
 // Determine which component to run
-$pathlist = explode('/', parse_url(@$_SERVER['PATH_INFO'],PHP_URL_PATH));
+$pathlist = explode('/', parse_url(rawurldecode(str_replace("_", " ", @$_SERVER['PATH_INFO'])),PHP_URL_PATH));
 while (end($pathlist) === "") array_pop($pathlist);
 $smarty->assign_by_ref("pathlist", $pathlist);
 $path = '';
diff --git a/plugins/function.articlesummary.php b/plugins/function.articlesummary.php
index ee321e1..2c8a115 100644
--- a/plugins/function.articlesummary.php
+++ b/plugins/function.articlesummary.php
@@ -1,17 +1,7 @@
 <?php
-
 	function smarty_function_articlesummary($params, &$smarty) {
-		
-		$article = $params['article'];
-		$id = $params['id'];
-		$title = rawurlencode($params['title']);
-
-		$linky = "<span style=\"float: right\"><a href=\"/News/".rawurlencode($title)."\">Read More</a></span>";
-
 		$matches = array();
-		preg_match("/^(<p>.*?<\/p>)/", $article, $matches);
-		$summary = preg_replace("/<\/p>/","$linky</p>", $matches[0]);
-		return $summary;
+		preg_match("/^(<p>.*?<\/p>)/", $params['article'], $matches);
+		return $matches[0];
 	}
-
 ?>
diff --git a/plugins/modifier.encodestring.php b/plugins/modifier.encodestring.php
new file mode 100644
index 0000000..ab30731
--- /dev/null
+++ b/plugins/modifier.encodestring.php
@@ -0,0 +1,8 @@
+<?php
+	function smarty_modifier_encodestring($string) {
+		$string = rawurlencode($string);
+		$string = str_replace("_", "%5F", $string);
+		$string = str_replace("%20", "_", $string);
+		return $string;
+	}
+?>
diff --git a/templates/contents-loop.tpl b/templates/contents-loop.tpl
index a0de4c2..d7b118e 100644
--- a/templates/contents-loop.tpl
+++ b/templates/contents-loop.tpl
@@ -3,8 +3,9 @@
 <ul>
 {/if}
 {foreach name=contents from=$data key=name item=item}
-	{if $level == 0}<h3>{else}<li>{/if}<a href="{$rootnode}{$parent}/{$name}">{$name}</a>{if $level == 0}</h3>
+	{if $level == 0}<h3>{else}<li>{/if}<a href="{$rootnode}{$parent}/{$name|encodestring}">{$name}</a>{if $level == 0}</h3>
 {/if}{if $item.summary}{if $level > 0} - {/if}{$item.summary}{/if}{if is_array($item.file)}
+		{assign var='name' value=$name|encodestring}
 		{include file="contents-loop.tpl" data=$item.file parent="$parent/$name" level=$level}
 {/if}
 {if $level > 0}</li>{/if}
diff --git a/templates/front.tpl b/templates/front.tpl
index 61a4489..345bb7e 100644
--- a/templates/front.tpl
+++ b/templates/front.tpl
@@ -8,7 +8,8 @@
 {foreach name=news from=$news key=itemnum item=item}
 	<h3>{$item.title}</h3>
 	<div>
-	{articlesummary id=$item.id article=$item.body title=$item.title}
+	{articlesummary article=$item.body}
+	<span style="float: right"><a href="/News/{$item.title|encodestring}">Read More</a></span>
 	</div>
 {/foreach}
 	<div class="clear"></div>
diff --git a/templates/news.tpl b/templates/news.tpl
index 9279d36..e59ee47 100644
--- a/templates/news.tpl
+++ b/templates/news.tpl
@@ -8,10 +8,10 @@
 {if $editable}
 <div class="edit">
 <ul>
-<li><a href="{$item.title}?action=delete-query">Delete</a></li>
-<li><a href="{$item.title}?action=edit">Edit</a></li>
+<li><a href="{$item.title|encodestring}?action=delete-query">Delete</a></li>
+<li><a href="{$item.title|encodestring}?action=edit">Edit</a></li>
 {if $item.expirytime > $smarty.now}
-<li><a href="{$item.title}?action=expire-query">Expire</a></li>
+<li><a href="{$item.title|encodestring}?action=expire-query">Expire</a></li>
 {/if}
 </ul>
 <div class="clear"></div>
diff --git a/templates/news_edit.tpl b/templates/news_edit.tpl
index 5adfa4e..c2c5a82 100644
--- a/templates/news_edit.tpl
+++ b/templates/news_edit.tpl
@@ -1,5 +1,5 @@
 
-<h2>Post a news item</h2>
+<h2>{if $action == 'edit'}Edit{else}Post{/if} a news item</h2>
 
 <form class="admin" action="{$path}" method="POST">
         <div class="row">
-- 
GitLab