<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Ben&#039;s Blog</title>
	<atom:link href="http://www.benmalen.com/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.benmalen.com</link>
	<description>Just another WordPress weblog</description>
	<lastBuildDate>Wed, 04 Aug 2010 08:57:18 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
		<item>
		<title>Add an extra field to the Gallery module</title>
		<link>http://www.benmalen.com/2010/04/09/add-an-extra-field-to-the-gallery-module/</link>
		<comments>http://www.benmalen.com/2010/04/09/add-an-extra-field-to-the-gallery-module/#comments</comments>
		<pubDate>Fri, 09 Apr 2010 09:21:14 +0000</pubDate>
		<dc:creator>Ben</dc:creator>
				<category><![CDATA[Web development]]></category>
		<category><![CDATA[cmsms]]></category>
		<category><![CDATA[extra fields]]></category>
		<category><![CDATA[gallery]]></category>
		<category><![CDATA[modify]]></category>
		<category><![CDATA[module]]></category>

		<guid isPermaLink="false">http://www.benmalen.com/?p=74</guid>
		<description><![CDATA[The Gallery module for CMS Made Simple has two fields where you can enter a title and comment for any image. You can place these in your template using {$image-&#62;title} and {$image-&#62;comment}. Ideally, you should be able to add field &#8230; <a href="http://www.benmalen.com/2010/04/09/add-an-extra-field-to-the-gallery-module/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>The Gallery module for CMS Made Simple has two fields where you can enter a title and comment for any image. You can place these in your template using <code>{$image-&gt;title}</code> and <code>{$image-&gt;comment}</code>. Ideally, you should be able to add field definitions, like in the News module. This would make it much more flexible, giving you more Smarty variables to work with, but this would require some hefty module modification. Instead, I will show you how to add a single extra field to the Gallery module, and if you require more, you have something to work off.</p>
<p>Download the Gallery module (1.2.1 at the time of writing) from:<br />
<a href="http://dev.cmsmadesimple.org/projects/gallery" target="_blank">http://dev.cmsmadesimple.org/projects/gallery</a></p>
<p>The files we will be making modifications to are:</p>
<p>Gallery/method.install.php<br />
Gallery/action.default.php<br />
Gallery/action.do_editgallery.php<br />
Gallery/action.editgallery.php<br />
Gallery/lang/en_US.php<br />
Gallery/templates/editgallery.tpl</p>
<h3>Making the modifications</h3>
<p>Lines that need to be added or modified are highlighted.</p>
<h4>Gallery/method.install.php</h4>
<p>If you would like to make a re-packaged version of the Gallery module that you can freshly install with the modifications in place, you will need to edit this file. Here, we add another field to the database table called &#8220;extra&#8221; set to <code>VARCHAR(255)</code>.</p>
<pre class="brush: php; first-line: 23; highlight: [34]; html-script: true;">
$flds = &quot;
    fileid I KEY AUTO,
    filename C(255),
    filepath C(255),
    filedate &quot; . CMS_ADODB_DT . &quot;,
    fileorder I,
    active I,
    defaultfile I,
    galleryid I KEY,
    title C(255),
    comment X,
    extra C(255)
&quot;;
</pre>
<p>If you have already installed the Gallery module, you can alter the table in the database directly, for example:</p>
<pre class="brush: sql;">
ALTER TABLE cms_module_gallery ADD extra VARCHAR(255) NOT NULL;
</pre>
<p>Make sure the prefix matches your CMSMS installation.</p>
<h4>Gallery/lang/en_US.php</h4>
<p>Add the name of the field to the language file. If you ever decide to change the name of the field that is viewable to the administrator, you can just change this line and you won&#8217;t have to make any other code changes.</p>
<pre class="brush: php; first-line: 41; highlight: [42]; html-script: true;">
$lang['comment'] = 'Comment';
$lang['extra'] = 'Extra';
</pre>
<h4>Gallery/action.default.php</h4>
<pre class="brush: php; first-line: 134; highlight: [135]; html-script: true;">
                $rec-&gt;comment = ($galeryfiles &amp;&amp; array_key_exists($key, $galeryfiles)) ? $galeryfiles[$key]['comment'] : '';
                $rec-&gt;extra = ($galeryfiles &amp;&amp; array_key_exists($key, $galeryfiles)) ? $galeryfiles[$key]['extra'] : '';
</pre>
<h4>Gallery/action.do_editgallery.php</h4>
<pre class="brush: php; first-line: 104; highlight: [107,108,114,115]; html-script: true;">
                else
                {
                    $searchwords .= ' ' . $filetitle . ' ' . $params['filecomment'][$key];
                    $query = &quot;UPDATE &quot; . cms_db_prefix() . &quot;module_gallery SET title=?, comment=?, extra=?, fileorder=? WHERE fileid = ?&quot;;
                    $result = $db-&gt;Execute($query, array($filetitle, $params['filecomment'][$key], $params['fileextra'][$key], $sortkey, $key));
                }
            }
            elseif ( $filetitle != &quot;#dir&quot; )
            {
                $searchwords .= ' ' . $filetitle . ' ' . $params['filecomment'][$key];
                $query = &quot;UPDATE &quot; . cms_db_prefix() . &quot;module_gallery SET title=?, comment=?, extra=? WHERE fileid = ?&quot;;
                $result = $db-&gt;Execute($query, array($filetitle, $params['filecomment'][$key], $params['fileextra'][$key], $key));
            }
</pre>
<h4>Gallery/action.editgallery.php</h4>
<pre class="brush: php; first-line: 103; highlight: [104]; html-script: true;">
            $onerow-&gt;comment = $this-&gt;CreateTextArea(0, $id, $file['comment'], 'filecomment[' . $file['fileid'] . ']', 'fake&quot; style=&quot;width:400px; height:4em;', '', '', '', '40', '4');  // class filled with fake and style-info to overrule the theme-css
            $onerow-&gt;extra = $this-&gt;CreateInputText($id, 'fileextra[' . $file['fileid'] . ']', $file['extra'], 30, 100);
</pre>
<p>Adding an extra field will increase the width of the Gallery module administration interface. Depending on your administration theme, this might be too wide. To accommodate for this, you can change the width style of the Comment textarea, for example, <code>width:200px;</code>.</p>
<h4>Gallery/templates/editgallery.tpl</h4>
<pre class="brush: php; first-line: 36; highlight: [43,57]; html-script: true;">
    &lt;table id=&quot;gtable&quot; cellspacing=&quot;0&quot; class=&quot;pagetable&quot;&gt;
        &lt;thead&gt;
        &lt;tr&gt;
            &lt;th class=&quot;pageicon&quot;&gt;&amp;nbsp;&lt;/th&gt;
            &lt;th&gt;{$item}&lt;/th&gt;
            &lt;th&gt;{$title}&lt;/th&gt;
            &lt;th&gt;{$comment}&lt;/th&gt;
            &lt;th&gt;{$extra}&lt;/th&gt;
            &lt;th&gt;{$filedate}&lt;/th&gt;
            &lt;th class=&quot;pageicon&quot;&gt;{$cover}&lt;/th&gt;
            &lt;th class=&quot;pageicon&quot;&gt;{$active}&lt;/th&gt;
        &lt;/tr&gt;
        &lt;/thead&gt;
        &lt;tbody&gt;
    {foreach from=$items item=entry}
        {cycle values=&quot;row1,row2&quot; assign=rowclass}
        &lt;tr id=&quot;{$entry-&gt;fileid}&quot; class=&quot;{$rowclass}&quot;&gt;
            &lt;td&gt;&amp;nbsp;&lt;/td&gt;
            &lt;td&gt;&lt;div style=&quot;width:96px; height:72px; background: url({$entry-&gt;thumburl}) no-repeat center; overflow:hidden; cursor:default;&quot;&gt;&amp;nbsp;&lt;/div&gt;&lt;/td&gt;
            &lt;td{if $entry-&gt;isdir} colspan=&quot;2&quot;{/if}&gt;{$entry-&gt;filename}&lt;br /&gt;{$entry-&gt;title}&lt;/td&gt;
            {if !$entry-&gt;isdir}&lt;td&gt;{$entry-&gt;comment}&lt;/td&gt;{/if}
            &lt;td&gt;{$entry-&gt;extra}&lt;/td&gt;
            &lt;td&gt;{$entry-&gt;filedate}&lt;/td&gt;
            &lt;td class=&quot;pagepos&quot; style=&quot;text-align:center&quot;&gt;{$entry-&gt;defaultlink}&lt;/td&gt;
            &lt;td class=&quot;pagepos&quot; style=&quot;text-align:center&quot;&gt;{$entry-&gt;activelink}&lt;/td&gt;
        &lt;/tr&gt;
    {/foreach}
        &lt;/tbody&gt;
    &lt;/table&gt;
</pre>
<p>Further down in the same file:</p>
<pre class="brush: php; first-line: 146; highlight: [147]; html-script: true;">
    $this-&gt;smarty-&gt;assign('comment', $this-&gt;Lang('comment'));
    $this-&gt;smarty-&gt;assign('extra', $this-&gt;Lang('extra'));
</pre>
<h3>Download</h3>
<p>For your convenience, I have re-packaged the Gallery module (1.2.1) with an extra field. You can download it here:</p>
Download: <a href="http://www.benmalen.com/wp-content/plugins/download-monitor/download.php?id=2">Gallery module with extra field 1.2.1 (zip, 320.24 kB)</a>
]]></content:encoded>
			<wfw:commentRss>http://www.benmalen.com/2010/04/09/add-an-extra-field-to-the-gallery-module/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>HTTP Front-end</title>
		<link>http://www.benmalen.com/2010/04/06/http-front-end/</link>
		<comments>http://www.benmalen.com/2010/04/06/http-front-end/#comments</comments>
		<pubDate>Tue, 06 Apr 2010 10:25:44 +0000</pubDate>
		<dc:creator>Ben</dc:creator>
				<category><![CDATA[Web development]]></category>
		<category><![CDATA[full path disclosure]]></category>
		<category><![CDATA[http front-end]]></category>
		<category><![CDATA[php security]]></category>

		<guid isPermaLink="false">http://www.benmalen.com/?p=7</guid>
		<description><![CDATA[HTTP Front-end is quite an old project of mine (started in 2005). It allows you to go behind the scenes, to see exactly what is happening in a HTTP transaction. By sending a customised HTTP request, you can see how &#8230; <a href="http://www.benmalen.com/2010/04/06/http-front-end/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>HTTP Front-end is quite an old project of mine (started in 2005). It allows you to go behind the scenes, to see exactly what is happening in a HTTP transaction.</p>
<p>By sending a customised HTTP request, you can see how a certain web application will behave. This makes HTTP Front-end a great tool for debugging and finding weak spots or vulnerabilities in web applications.</p>
<p>Take the following code for example:</p>
<pre class="brush: php; html-script: true;">
&lt;?php
if (isset($_POST['foo'])) {
    echo htmlspecialchars($_POST['foo']);
}
?&gt;

&lt;form action=&quot;test.php&quot; method=&quot;post&quot;&gt;
&lt;input type=&quot;text&quot; name=&quot;foo&quot; /&gt;
&lt;input type=&quot;submit&quot; name=&quot;submit&quot; value=&quot;Submit&quot; /&gt;
&lt;/form&gt;
</pre>
<p>You may think this is a pretty securely typed snippet of code. <code>isset()</code> is used to check if the variable is set, and <code>htmlspecialchars()</code> makes sure any special characters are converted to HTML entities.</p>
<p>If you typed &#8220;bar&#8221; into the text box and hit Submit, your web browser (client) would send a HTTP request to the server that looks something like this:</p>
<pre class="brush: plain;">
POST /test.php HTTP/1.0
Host: localhost
Content-Type: application/x-www-form-urlencoded
Content-Length: 7
Connection: close

foo=bar
</pre>
<p>The response body contains:</p>
<pre class="brush: xml;">
bar
...
</pre>
<p>Everything is fine, right? Let&#8217;s take a look at a specially crafted HTTP request sent with HTTP Front-end.</p>
<pre class="brush: plain;">
POST /test.php HTTP/1.0
Host: localhost
Content-Type: application/x-www-form-urlencoded
Content-Length: 9
Connection: close

foo[]=bar
</pre>
<p>Now we get the following response body:</p>
<pre class="brush: xml;">
&lt;br /&gt;
&lt;b&gt;Warning&lt;/b&gt;: htmlspecialchars() expects parameter 1 to be string, array given in &lt;b&gt;/var/www/html/test.php&lt;/b&gt; on line &lt;b&gt;4&lt;/b&gt;&lt;br /&gt;
...
</pre>
<p>By sending an array instead of a string, this has resulted in full path disclosure. Full path disclosure by itself is not a big worry, but it is good coding practice to make sure this cannot occur, even if the <code>display_errors</code> directive is enabled. Let&#8217;s secure the code:</p>
<pre class="brush: php; html-script: true;">
&lt;?php
if (isset($_POST['foo']) &amp;&amp; is_string($_POST['foo'])) {
    echo htmlspecialchars($_POST['foo']);
}
?&gt;

&lt;form action=&quot;test.php&quot; method=&quot;post&quot;&gt;
&lt;input type=&quot;text&quot; name=&quot;foo&quot; /&gt;
&lt;input type=&quot;submit&quot; name=&quot;submit&quot; value=&quot;Submit&quot; /&gt;
&lt;/form&gt;
</pre>
<p><code>is_string()</code> is added to make sure the variable is of the correct type.</p>
<p>You may access HTTP Front-end here:</p>
<p><a title="HTTP Front-end" href="http://www.benmalen.com/projects/http-front-end/" target="_blank">http://www.benmalen.com/projects/http-front-end/</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.benmalen.com/2010/04/06/http-front-end/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Additional Smarty variables for CMSMS CGBlog</title>
		<link>http://www.benmalen.com/2010/04/06/additional-smarty-variables-for-cmsms-cgblog/</link>
		<comments>http://www.benmalen.com/2010/04/06/additional-smarty-variables-for-cmsms-cgblog/#comments</comments>
		<pubDate>Tue, 06 Apr 2010 08:49:25 +0000</pubDate>
		<dc:creator>Ben</dc:creator>
				<category><![CDATA[Web development]]></category>
		<category><![CDATA[cgblog]]></category>
		<category><![CDATA[cmsms]]></category>
		<category><![CDATA[smarty variables]]></category>

		<guid isPermaLink="false">http://www.benmalen.com/?p=22</guid>
		<description><![CDATA[I have released a plugin for CMS Made Simple, for use with with the CGBlog module. What does this do? CGBlog (1.3.2 at the time of writing) does not provide a lot of Smarty variables. This plugin provides a quick &#8230; <a href="http://www.benmalen.com/2010/04/06/additional-smarty-variables-for-cmsms-cgblog/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>I have released a plugin for CMS Made Simple, for use with with the CGBlog module.</p>
<h3>What does this do?</h3>
<p>CGBlog (1.3.2 at the time of writing) does not provide a lot of Smarty variables. This plugin provides a quick fix to that problem. It will retrieve information from the summary, detail, or archive view, and assign that information to Smarty variables that you can use anywhere in the page template or the module templates themselves.</p>
<h3>How do I use it?</h3>
<p>Call this plugin at the very top of your page template using:</p>
<p><code>{blog_info}</code></p>
<p>The following Smarty variables will be set if the information is found:</p>
<p><code>$blog_category_id</code> (for example, 1)<br />
<code>$blog_category_name</code> (for example, Animals)<br />
<code>$blog_archive_year</code> (for example, 2010)<br />
<code>$blog_archive_month</code> (for example, 04)<br />
<code>$blog_archive_month_full</code> (for example, April)</p>
<p>Note: These Smarty variables are not escaped so they can be used for string comparison logic. <code>$blog_category_name</code> may contain special HTML characters, which would cause invalid markup, so be sure to escape it when outputting, for example, <code>{$blog_category_name|cms_escape}</code>.</p>
<p>What about the article name? This is already available in the CGBlog detail template. This also applies to the News module. To place this variable into your page template, add the following code to the top of the CGBlog detail template:</p>
<p><code>{assign var='blog_article_name' value=$entry-&gt;title|cms_escape}</code></p>
<p><del datetime="2010-06-22T08:56:54+00:00">The very first line of your page template should contain:</del></p>
<p><del datetime="2010-06-22T08:56:54+00:00"><code>{process_pagedata}</code></del></p>
<p>This assumes <code>$config['process_whole_template'] = false;</code> in config.php (this is the default value in CMSMS 1.7.1).</p>
<p>You can now access <code>$blog_article_name</code> in the <code>&lt;head&gt;</code> section of your page template.</p>
<p>Because of the way CMSMS processes the page template, if you wish to access <code>$blog_article_name</code> in the <code>&lt;body&gt;</code> section of your page template, you will need to do a little extra.</p>
<p>Add this to the first line of your page template:</p>
<p><code>{content assign='mycontent'}</code></p>
<p>Then replace your original <code>{content}</code> tag with <code>{$mycontent}</code>.</p>
<p>You should now be able to access <code>$blog_article_name</code> in the <code>&lt;body&gt;</code> section of your page template.</p>
<p>Further reading:<br />
<a href="http://calguy1000.com/Blogs/4/60.html" target="_blank">http://calguy1000.com/Blogs/4/60.html</a><br />
<a href="http://forum.cmsmadesimple.org/index.php/topic,30475.45.html" target="_blank">http://forum.cmsmadesimple.org/index.php/topic,30475.45.html</a></p>
<h3>What parameters does it take?</h3>
<ul>
<li><em>(optional)</em> <code>match</code> &#8211; String in CSV format, containing other CGBlog modules to check for (case-insensitive). This is useful if you are running multiple instances of the CGBlog module under different names (i.e. you have duplicated/renamed the CGBlog module). If not specified, it will default to &#8216;CGBlog&#8217;. For example: <code>{blog_info match='CGBlog, RGuide, FGuide'}</code></li>
</ul>
<h3>Download</h3>
Download: <a href="http://www.benmalen.com/wp-content/plugins/download-monitor/download.php?id=3">Blog Info 1.1 (zip, 2.79 kB)</a>
]]></content:encoded>
			<wfw:commentRss>http://www.benmalen.com/2010/04/06/additional-smarty-variables-for-cmsms-cgblog/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>
