<?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/"
	xmlns:georss="http://www.georss.org/georss" xmlns:geo="http://www.w3.org/2003/01/geo/wgs84_pos#" xmlns:media="http://search.yahoo.com/mrss/"
	>

<channel>
	<title>Kristian Nissen</title>
	<atom:link href="http://kristiannissen.wordpress.com/feed/" rel="self" type="application/rss+xml" />
	<link>http://kristiannissen.wordpress.com</link>
	<description>my digital footprint</description>
	<lastBuildDate>Mon, 23 Jan 2012 15:22:29 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.com/</generator>
<cloud domain='kristiannissen.wordpress.com' port='80' path='/?rsscloud=notify' registerProcedure='' protocol='http-post' />
<image>
		<url>http://s2.wp.com/i/buttonw-com.png</url>
		<title>Kristian Nissen</title>
		<link>http://kristiannissen.wordpress.com</link>
	</image>
	<atom:link rel="search" type="application/opensearchdescription+xml" href="http://kristiannissen.wordpress.com/osd.xml" title="Kristian Nissen" />
	<atom:link rel='hub' href='http://kristiannissen.wordpress.com/?pushpress=hub'/>
		<item>
		<title>Drupal 7 adding user profile picture at registration</title>
		<link>http://kristiannissen.wordpress.com/2011/12/30/drupal-7-adding-user-profile-picture-at-registration/</link>
		<comments>http://kristiannissen.wordpress.com/2011/12/30/drupal-7-adding-user-profile-picture-at-registration/#comments</comments>
		<pubDate>Fri, 30 Dec 2011 12:44:13 +0000</pubDate>
		<dc:creator>Kristian Nissen</dc:creator>
				<category><![CDATA[code is poetry]]></category>
		<category><![CDATA[Drupal]]></category>
		<category><![CDATA[Hooks]]></category>
		<category><![CDATA[form api]]></category>
		<category><![CDATA[Drupal 7]]></category>

		<guid isPermaLink="false">http://kristiannissen.wordpress.com/?p=442</guid>
		<description><![CDATA[It took me a while to get this working and since I&#8217;m sure others will be struggling with the same task I decided to share my code. Here&#8217;s my approach, all stored in a module called &#8220;customers&#8221; Alter &#8220;user-register-form&#8221; found at www.your-domain.com/user/register Add custom submit handler to &#8220;user-register-form&#8221; form Upload user image in custom submit &#8230; <a href="http://kristiannissen.wordpress.com/2011/12/30/drupal-7-adding-user-profile-picture-at-registration/">Continue reading <span class="meta-nav">&#8594;</span></a><img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=kristiannissen.wordpress.com&amp;blog=6383083&amp;post=442&amp;subd=kristiannissen&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>It took me a while to get this working and since I&#8217;m sure others will be struggling with the same task I decided to share my code.</p>
<p>Here&#8217;s my approach, all stored in a module called &#8220;customers&#8221;</p>
<ol>
<li>Alter &#8220;user-register-form&#8221; found at www.your-domain.com/user/register</li>
<li>Add custom submit handler to &#8220;user-register-form&#8221; form</li>
<li>Upload user image in custom submit handler</li>
</ol>
<p>it really is that simple :)</p>
<p>Using <a href="http://api.drupal.org/api/drupal/modules--system--system.api.php/function/hook_form_FORM_ID_alter/7">hook_form_FORM_ID_alter()</a> to alter &#8220;user-register-form&#8221; making sure I only hook into that form.</p>
<p>Inside this function which in my case is called &#8220;customers_form_user_register_form_alter&#8221; I add a few attributes to the form so that it can <strong>handle file uploads</strong>:</p>
<pre>$form['#attributes'] = array(
  'enctype' =&gt; 'multipart/form-data',
  'autocomplete' =&gt; 'off'
);</pre>
<p>then add <strong>custom submit handler</strong> like so:</p>
<pre>$form['#submit'][] = 'customers_register_handler';</pre>
<p>and then the <strong>field that holds the image file</strong>:</p>
<pre>$form['picture_upload'] = array(
  '#type' =&gt; 'file',
  '#title' =&gt; t('Company Logo')
);</pre>
<p>in my case I use the <strong>user profile picture</strong> to store a company logo, but it&#8217;s just the title of the field. And now to where the magic happens; the custom submit handler:</p>
<pre>$validators = array(
  'file_validate_is_image' =&gt; array(),
);
$file = file_save_upload('picture_upload', $validators);

if ($file == false) {
  form_set_error('picture_upload', t('Failed to upload picture'));
  $picture = null;
} elseif ($file != null) {
  $picture = $file;
  // Set the user id
  $picture-&gt;uid = $user-&gt;uid;
}

user_save($user, array(
  'picture_upload' =&gt; $picture,
));</pre>
<p>One of the things that took me a bit of time to grasp was the fact that files are not passed inside the <strong>$form_state</strong> array, instead you call <a href="http://api.drupal.org/api/drupal/includes--file.inc/function/file_save_upload/7">file_save_upload()</a> where the 1. parameter is the name of the file field. In my case the file field is called picture_upload, and as you can see I&#8217;m currently not passing any file validation. The next &#8220;if statement&#8221; just takes care that a file was uploaded and sets the owner to the newly created user.</p>
<p>The only thing left is to call <a href="http://api.drupal.org/api/drupal/modules--user--user.module/function/user_save/7">user_save()</a> and <strong>pass in the file that was uploaded</strong>.</p>
<p>I know several modules exist that handle this for you, but adding a module just for that is an overkill in my opinion, especially since all my other logic related to &#8220;customers&#8221; is stored inside my customers.module.</p>
<br />Filed under: <a href='http://kristiannissen.wordpress.com/category/code-is-poetry/'>code is poetry</a> Tagged: <a href='http://kristiannissen.wordpress.com/tag/drupal/'>Drupal</a>, <a href='http://kristiannissen.wordpress.com/tag/drupal-7/'>Drupal 7</a>, <a href='http://kristiannissen.wordpress.com/tag/form-api/'>form api</a>, <a href='http://kristiannissen.wordpress.com/tag/hooks/'>Hooks</a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/kristiannissen.wordpress.com/442/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/kristiannissen.wordpress.com/442/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/kristiannissen.wordpress.com/442/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/kristiannissen.wordpress.com/442/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/kristiannissen.wordpress.com/442/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/kristiannissen.wordpress.com/442/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/kristiannissen.wordpress.com/442/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/kristiannissen.wordpress.com/442/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/kristiannissen.wordpress.com/442/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/kristiannissen.wordpress.com/442/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/kristiannissen.wordpress.com/442/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/kristiannissen.wordpress.com/442/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/kristiannissen.wordpress.com/442/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/kristiannissen.wordpress.com/442/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=kristiannissen.wordpress.com&amp;blog=6383083&amp;post=442&amp;subd=kristiannissen&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://kristiannissen.wordpress.com/2011/12/30/drupal-7-adding-user-profile-picture-at-registration/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/eaf2025323bb63b0befc35491afa618e?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">kristiannissen</media:title>
		</media:content>
	</item>
		<item>
		<title>Rails options_for_select with include blank and selected option</title>
		<link>http://kristiannissen.wordpress.com/2011/11/16/rails-options_for_select-with-include-blank-and-selected-option/</link>
		<comments>http://kristiannissen.wordpress.com/2011/11/16/rails-options_for_select-with-include-blank-and-selected-option/#comments</comments>
		<pubDate>Wed, 16 Nov 2011 13:56:26 +0000</pubDate>
		<dc:creator>Kristian Nissen</dc:creator>
				<category><![CDATA[code is poetry]]></category>
		<category><![CDATA[options_from_collection_for_select]]></category>
		<category><![CDATA[Ruby]]></category>
		<category><![CDATA[Ruby On Rails]]></category>

		<guid isPermaLink="false">http://kristiannissen.wordpress.com/?p=345</guid>
		<description><![CDATA[If you want to use a select_tag and include a blank option it can be achieved using the following snippet: &#60;%= select_tag &#8220;district&#8221;, options_for_select(Customer.all.collect { &#124;k&#124; ["#{k.district} #{k.store}", k.id] }.insert(0, ["", 0]), params[:number].to_i) %&#62; - it also handles setting the selected option if one is passed &#8211; in this case in the query string. I &#8230; <a href="http://kristiannissen.wordpress.com/2011/11/16/rails-options_for_select-with-include-blank-and-selected-option/">Continue reading <span class="meta-nav">&#8594;</span></a><img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=kristiannissen.wordpress.com&amp;blog=6383083&amp;post=345&amp;subd=kristiannissen&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>If you want to use a select_tag and include a blank option it can be achieved using the following snippet:</p>
<p>&lt;%= select_tag &#8220;district&#8221;, options_for_select(Customer.all.collect { |k| ["#{k.district} #{k.store}", k.id] }.insert(0, ["", 0]), params[:number].to_i) %&gt;</p>
<p>- it also handles setting the selected option if one is passed &#8211; in this case in the query string. I have been <a title="How to fix missing Rails select_tag include_blank attribute" href="http://kristiannissen.wordpress.com/2009/06/02/how-to-fix-missing-rails-select_tag-include_blank-attribute/">blogging about this previously</a> but noticed that I had forgotten to show how to pass the chosen option if one exists.</p>
<br />Filed under: <a href='http://kristiannissen.wordpress.com/category/code-is-poetry/'>code is poetry</a> Tagged: <a href='http://kristiannissen.wordpress.com/tag/options_from_collection_for_select/'>options_from_collection_for_select</a>, <a href='http://kristiannissen.wordpress.com/tag/ruby/'>Ruby</a>, <a href='http://kristiannissen.wordpress.com/tag/ruby-on-rails/'>Ruby On Rails</a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/kristiannissen.wordpress.com/345/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/kristiannissen.wordpress.com/345/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/kristiannissen.wordpress.com/345/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/kristiannissen.wordpress.com/345/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/kristiannissen.wordpress.com/345/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/kristiannissen.wordpress.com/345/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/kristiannissen.wordpress.com/345/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/kristiannissen.wordpress.com/345/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/kristiannissen.wordpress.com/345/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/kristiannissen.wordpress.com/345/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/kristiannissen.wordpress.com/345/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/kristiannissen.wordpress.com/345/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/kristiannissen.wordpress.com/345/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/kristiannissen.wordpress.com/345/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=kristiannissen.wordpress.com&amp;blog=6383083&amp;post=345&amp;subd=kristiannissen&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://kristiannissen.wordpress.com/2011/11/16/rails-options_for_select-with-include-blank-and-selected-option/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/eaf2025323bb63b0befc35491afa618e?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">kristiannissen</media:title>
		</media:content>
	</item>
		<item>
		<title>mysql change collation to utf8</title>
		<link>http://kristiannissen.wordpress.com/2011/11/05/mysql-change-collation-to-utf8/</link>
		<comments>http://kristiannissen.wordpress.com/2011/11/05/mysql-change-collation-to-utf8/#comments</comments>
		<pubDate>Sat, 05 Nov 2011 14:40:10 +0000</pubDate>
		<dc:creator>Kristian Nissen</dc:creator>
				<category><![CDATA[code is poetry]]></category>
		<category><![CDATA[MySQL]]></category>

		<guid isPermaLink="false">http://kristiannissen.wordpress.com/?p=439</guid>
		<description><![CDATA[If your encoding is off and you didn&#8217;t get it right from the beginning changing it is not a difficult task to do &#8211; but doing it in production could be risky. To check you database collation in MySQL you can use the following SQL statement: SHOW TABLE STATUS; This will show you a lot &#8230; <a href="http://kristiannissen.wordpress.com/2011/11/05/mysql-change-collation-to-utf8/">Continue reading <span class="meta-nav">&#8594;</span></a><img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=kristiannissen.wordpress.com&amp;blog=6383083&amp;post=439&amp;subd=kristiannissen&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>If your encoding is off and you didn&#8217;t get it right from the beginning changing it is not a difficult task to do &#8211; but doing it in production could be risky.</p>
<p>To check you database collation in <strong>MySQL</strong> you can use the following <strong>SQL statement</strong>:</p>
<pre>SHOW TABLE STATUS;</pre>
<p>This will show you a lot of useful info about your database including collation. If you want to check it for a specific table use the following SQL statement:</p>
<pre>SHOW TABLE STATUS WHERE NAME = 'The Name of Your Table';</pre>
<p>This will show you the same info as above but only for a specific table. And if you <strong>want to change you collation</strong> to utf8 use the following SQL statement:</p>
<pre>ALTER TABLE The Name of Your Table CONVERT TO CHARACTER SET utf8;</pre>
<br />Filed under: <a href='http://kristiannissen.wordpress.com/category/code-is-poetry/'>code is poetry</a> Tagged: <a href='http://kristiannissen.wordpress.com/tag/mysql/'>MySQL</a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/kristiannissen.wordpress.com/439/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/kristiannissen.wordpress.com/439/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/kristiannissen.wordpress.com/439/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/kristiannissen.wordpress.com/439/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/kristiannissen.wordpress.com/439/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/kristiannissen.wordpress.com/439/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/kristiannissen.wordpress.com/439/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/kristiannissen.wordpress.com/439/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/kristiannissen.wordpress.com/439/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/kristiannissen.wordpress.com/439/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/kristiannissen.wordpress.com/439/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/kristiannissen.wordpress.com/439/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/kristiannissen.wordpress.com/439/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/kristiannissen.wordpress.com/439/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=kristiannissen.wordpress.com&amp;blog=6383083&amp;post=439&amp;subd=kristiannissen&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://kristiannissen.wordpress.com/2011/11/05/mysql-change-collation-to-utf8/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/eaf2025323bb63b0befc35491afa618e?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">kristiannissen</media:title>
		</media:content>
	</item>
		<item>
		<title>drupal 7 theme tutorial</title>
		<link>http://kristiannissen.wordpress.com/2011/11/04/drupal-7-theme-tutorial/</link>
		<comments>http://kristiannissen.wordpress.com/2011/11/04/drupal-7-theme-tutorial/#comments</comments>
		<pubDate>Fri, 04 Nov 2011 11:39:11 +0000</pubDate>
		<dc:creator>Kristian Nissen</dc:creator>
				<category><![CDATA[code is poetry]]></category>
		<category><![CDATA[Drupal 7]]></category>
		<category><![CDATA[Drupal theming]]></category>

		<guid isPermaLink="false">http://kristiannissen.wordpress.com/?p=435</guid>
		<description><![CDATA[I&#8217;m helping a friend of mine whip a Drupal 7 site together, and part of the work is to create a responsive HTML5 based design for the site. Building a Drupal 7 theme from the grounds up isn&#8217;t difficult, all you have to do is follow these simple steps and then your ready to rock &#8230; <a href="http://kristiannissen.wordpress.com/2011/11/04/drupal-7-theme-tutorial/">Continue reading <span class="meta-nav">&#8594;</span></a><img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=kristiannissen.wordpress.com&amp;blog=6383083&amp;post=435&amp;subd=kristiannissen&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>I&#8217;m helping a friend of mine whip a Drupal 7 site together, and part of the work is to create a responsive HTML5 based design for the site.</p>
<p>Building a Drupal 7 theme from the grounds up isn&#8217;t difficult, all you have to do is follow these simple steps and then your ready to rock n roll.</p>
<p>1) create a folder for your theme in sites/all/themes/ in my case the theme will be called &#8220;badning&#8221;, so Ill create the folder sites/all/themes/badning</p>
<p>2) place a name-of-your-theme.info file in sites/all/themes/name-of-your-theme, in my case it will be badning.info</p>
<p>Add the following to your name-of-your-theme.info file:</p>
<pre>  1 name = Badning theme
  2 description = Badning.dk responsive theme
  3 core = 7.x
  4 engine = phptemplate
  5 regions[header] = Header
  6 regions[content] = Content
  7 regions[footer] = Footer
  8 stylesheets[all][] = badning.css
  9 scripts[] = badning.js</pre>
<p>I have only added the bare minimum of regions that I will use.  Now your ready to building your actual theme.</p>
<br />Filed under: <a href='http://kristiannissen.wordpress.com/category/code-is-poetry/'>code is poetry</a> Tagged: <a href='http://kristiannissen.wordpress.com/tag/drupal-7/'>Drupal 7</a>, <a href='http://kristiannissen.wordpress.com/tag/drupal-theming/'>Drupal theming</a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/kristiannissen.wordpress.com/435/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/kristiannissen.wordpress.com/435/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/kristiannissen.wordpress.com/435/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/kristiannissen.wordpress.com/435/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/kristiannissen.wordpress.com/435/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/kristiannissen.wordpress.com/435/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/kristiannissen.wordpress.com/435/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/kristiannissen.wordpress.com/435/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/kristiannissen.wordpress.com/435/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/kristiannissen.wordpress.com/435/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/kristiannissen.wordpress.com/435/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/kristiannissen.wordpress.com/435/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/kristiannissen.wordpress.com/435/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/kristiannissen.wordpress.com/435/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=kristiannissen.wordpress.com&amp;blog=6383083&amp;post=435&amp;subd=kristiannissen&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://kristiannissen.wordpress.com/2011/11/04/drupal-7-theme-tutorial/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/eaf2025323bb63b0befc35491afa618e?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">kristiannissen</media:title>
		</media:content>
	</item>
		<item>
		<title>PHP pass by reference to call_user_func_array</title>
		<link>http://kristiannissen.wordpress.com/2011/10/19/php-pass-by-reference-call_user_func_array/</link>
		<comments>http://kristiannissen.wordpress.com/2011/10/19/php-pass-by-reference-call_user_func_array/#comments</comments>
		<pubDate>Wed, 19 Oct 2011 08:11:35 +0000</pubDate>
		<dc:creator>Kristian Nissen</dc:creator>
				<category><![CDATA[code is poetry]]></category>
		<category><![CDATA[napkn]]></category>
		<category><![CDATA[PHP]]></category>

		<guid isPermaLink="false">http://kristiannissen.wordpress.com/?p=432</guid>
		<description><![CDATA[You need to make a small change in the call_user_func_array if you want to pass the user_func an argument that is a reference. I&#8217;m using this in my own small PHP micro framework when I call the &#8220;view&#8221;. Here is a small snippet: call_user_func_array('before_all', array($func, &#38;$params)); as you can see, the $params is now a &#8230; <a href="http://kristiannissen.wordpress.com/2011/10/19/php-pass-by-reference-call_user_func_array/">Continue reading <span class="meta-nav">&#8594;</span></a><img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=kristiannissen.wordpress.com&amp;blog=6383083&amp;post=432&amp;subd=kristiannissen&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>You need to make a small change in the <a href="http://php.net/manual/en/function.call-user-func-array.php">call_user_func_array</a> if you want to pass the user_func an argument that is a <a href="http://php.net/manual/en/language.references.pass.php">reference</a>. I&#8217;m using this in my own small PHP micro framework when I call the &#8220;view&#8221;. Here is a small snippet:</p>
<pre>call_user_func_array('before_all', array($func, &amp;$params));</pre>
<p>as you can see, the $params is now a reference <em>within an array</em> and putting it into an array makes the whole difference. I found this solution over at <a href="http://stackoverflow.com/questions/295016/is-it-possible-to-pass-parameters-by-reference-using-call-user-func-array">stackoverflow.com</a> - MAN I LOVE THAT SITE!</p>
<p>The user_func which in this case is called &#8220;before_all&#8221; looks like this:</p>
<pre>function before_all($func, &amp;$args)
{
}</pre>
<p>In my PHP micro framework it takes the current function and the arguments passed to that function as it&#8217;s arguments, and the second argument is passed as a reference.</p>
<br />Filed under: <a href='http://kristiannissen.wordpress.com/category/code-is-poetry/'>code is poetry</a> Tagged: <a href='http://kristiannissen.wordpress.com/tag/napkn/'>napkn</a>, <a href='http://kristiannissen.wordpress.com/tag/php/'>PHP</a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/kristiannissen.wordpress.com/432/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/kristiannissen.wordpress.com/432/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/kristiannissen.wordpress.com/432/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/kristiannissen.wordpress.com/432/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/kristiannissen.wordpress.com/432/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/kristiannissen.wordpress.com/432/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/kristiannissen.wordpress.com/432/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/kristiannissen.wordpress.com/432/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/kristiannissen.wordpress.com/432/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/kristiannissen.wordpress.com/432/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/kristiannissen.wordpress.com/432/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/kristiannissen.wordpress.com/432/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/kristiannissen.wordpress.com/432/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/kristiannissen.wordpress.com/432/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=kristiannissen.wordpress.com&amp;blog=6383083&amp;post=432&amp;subd=kristiannissen&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://kristiannissen.wordpress.com/2011/10/19/php-pass-by-reference-call_user_func_array/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/eaf2025323bb63b0befc35491afa618e?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">kristiannissen</media:title>
		</media:content>
	</item>
		<item>
		<title>PHP micro framework routing</title>
		<link>http://kristiannissen.wordpress.com/2011/10/18/php-micro-framework-routing/</link>
		<comments>http://kristiannissen.wordpress.com/2011/10/18/php-micro-framework-routing/#comments</comments>
		<pubDate>Tue, 18 Oct 2011 07:58:59 +0000</pubDate>
		<dc:creator>Kristian Nissen</dc:creator>
				<category><![CDATA[code is poetry]]></category>
		<category><![CDATA[micro framework]]></category>
		<category><![CDATA[napkn]]></category>
		<category><![CDATA[PHP]]></category>

		<guid isPermaLink="false">http://kristiannissen.wordpress.com/?p=429</guid>
		<description><![CDATA[Building your own PHP micro framework is great fun, I just started updating my own small codebase. One of the things I would like to change is the layout for my applications URLs. Imagine that you have several URL&#8217;s that could be handled by the same function: $urls = array( 'home' =&#62; '^/$', 'blog_post' =&#62; &#8230; <a href="http://kristiannissen.wordpress.com/2011/10/18/php-micro-framework-routing/">Continue reading <span class="meta-nav">&#8594;</span></a><img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=kristiannissen.wordpress.com&amp;blog=6383083&amp;post=429&amp;subd=kristiannissen&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>Building your own PHP micro framework is great fun, I just started updating my own small codebase. One of the things I would like to change is the layout for my applications URLs.</p>
<p>Imagine that you have several URL&#8217;s that could be handled by the same function:</p>
<pre>$urls = array(
 'home' =&gt; '^/$',
 'blog_post' =&gt; 'blog/([0-9]{4})-([0-9]{2})-([0-9]{2})/([a-z-]+)/',
 'page' =&gt; array(
 'about-me',
 'my-work',
 'contact'
 )
 );</pre>
<p>the &#8216;page&#8217; function could be a function that load a static html page based on the argument it&#8217;s receiving. The stub code for that function could look something like:</p>
<pre>function page($args)
 {
 # Load static file based on $args
 }</pre>
<p>That would be a nice feature to have in a micro framework</p>
<br />Filed under: <a href='http://kristiannissen.wordpress.com/category/code-is-poetry/'>code is poetry</a> Tagged: <a href='http://kristiannissen.wordpress.com/tag/micro-framework/'>micro framework</a>, <a href='http://kristiannissen.wordpress.com/tag/napkn/'>napkn</a>, <a href='http://kristiannissen.wordpress.com/tag/php/'>PHP</a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/kristiannissen.wordpress.com/429/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/kristiannissen.wordpress.com/429/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/kristiannissen.wordpress.com/429/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/kristiannissen.wordpress.com/429/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/kristiannissen.wordpress.com/429/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/kristiannissen.wordpress.com/429/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/kristiannissen.wordpress.com/429/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/kristiannissen.wordpress.com/429/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/kristiannissen.wordpress.com/429/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/kristiannissen.wordpress.com/429/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/kristiannissen.wordpress.com/429/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/kristiannissen.wordpress.com/429/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/kristiannissen.wordpress.com/429/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/kristiannissen.wordpress.com/429/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=kristiannissen.wordpress.com&amp;blog=6383083&amp;post=429&amp;subd=kristiannissen&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://kristiannissen.wordpress.com/2011/10/18/php-micro-framework-routing/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/eaf2025323bb63b0befc35491afa618e?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">kristiannissen</media:title>
		</media:content>
	</item>
		<item>
		<title>Building your own PHP micro framework</title>
		<link>http://kristiannissen.wordpress.com/2011/10/18/building-your-own-php-micro-framework/</link>
		<comments>http://kristiannissen.wordpress.com/2011/10/18/building-your-own-php-micro-framework/#comments</comments>
		<pubDate>Tue, 18 Oct 2011 07:50:44 +0000</pubDate>
		<dc:creator>Kristian Nissen</dc:creator>
				<category><![CDATA[code is poetry]]></category>
		<category><![CDATA[micro framework]]></category>
		<category><![CDATA[napkn]]></category>
		<category><![CDATA[PHP]]></category>

		<guid isPermaLink="false">http://kristiannissen.wordpress.com/?p=427</guid>
		<description><![CDATA[Some time ago I wrote my own PHP based micro framework, now I think it&#8217;s time to give it an update. One of the things I want to improve is how you handle your applications URL, I&#8217;ve been using Google&#8217;s webapp framework and I like the way you define your applications URLs: $urls = array( &#8230; <a href="http://kristiannissen.wordpress.com/2011/10/18/building-your-own-php-micro-framework/">Continue reading <span class="meta-nav">&#8594;</span></a><img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=kristiannissen.wordpress.com&amp;blog=6383083&amp;post=427&amp;subd=kristiannissen&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>Some time ago I wrote my own PHP based micro framework, now I think it&#8217;s time to give it an update.</p>
<p>One of the things I want to improve is how you handle your applications URL, I&#8217;ve been using Google&#8217;s webapp framework and I like the way you define your applications URLs:</p>
<pre>$urls = array(
  'home' =&gt; '^/$',
  'blog_post' =&gt; 'blog/([0-9]{4})-([0-9]{2})-([0-9]{2})/([a-z-]+)/',
  'page' =&gt; 'about-me'
);</pre>
<p>as you can see it&#8217;s a simple <a href="http://php.net/manual/en/language.types.array.php">hash table</a> where the key is the name of a function and the value is the URL triggering the function.</p>
<br />Filed under: <a href='http://kristiannissen.wordpress.com/category/code-is-poetry/'>code is poetry</a> Tagged: <a href='http://kristiannissen.wordpress.com/tag/micro-framework/'>micro framework</a>, <a href='http://kristiannissen.wordpress.com/tag/napkn/'>napkn</a>, <a href='http://kristiannissen.wordpress.com/tag/php/'>PHP</a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/kristiannissen.wordpress.com/427/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/kristiannissen.wordpress.com/427/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/kristiannissen.wordpress.com/427/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/kristiannissen.wordpress.com/427/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/kristiannissen.wordpress.com/427/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/kristiannissen.wordpress.com/427/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/kristiannissen.wordpress.com/427/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/kristiannissen.wordpress.com/427/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/kristiannissen.wordpress.com/427/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/kristiannissen.wordpress.com/427/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/kristiannissen.wordpress.com/427/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/kristiannissen.wordpress.com/427/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/kristiannissen.wordpress.com/427/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/kristiannissen.wordpress.com/427/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=kristiannissen.wordpress.com&amp;blog=6383083&amp;post=427&amp;subd=kristiannissen&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://kristiannissen.wordpress.com/2011/10/18/building-your-own-php-micro-framework/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/eaf2025323bb63b0befc35491afa618e?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">kristiannissen</media:title>
		</media:content>
	</item>
		<item>
		<title>Drupal 7 blog customized teaser</title>
		<link>http://kristiannissen.wordpress.com/2011/10/03/drupal-7-blog-customized-teaser/</link>
		<comments>http://kristiannissen.wordpress.com/2011/10/03/drupal-7-blog-customized-teaser/#comments</comments>
		<pubDate>Mon, 03 Oct 2011 20:51:25 +0000</pubDate>
		<dc:creator>Kristian Nissen</dc:creator>
				<category><![CDATA[code is poetry]]></category>
		<category><![CDATA[Work I've done]]></category>
		<category><![CDATA[Drupal 7]]></category>
		<category><![CDATA[Hooks]]></category>

		<guid isPermaLink="false">http://kristiannissen.wordpress.com/?p=423</guid>
		<description><![CDATA[In the theme I&#8217;m working on I want to use the block &#8220;Recent blog posts&#8221; which is part of the blog module. But the &#8220;Recent blog posts&#8221; shows a list of minimum 2 blog posts as a list and I want to show 1 blog post in my teaser. You can achieve this by using &#8230; <a href="http://kristiannissen.wordpress.com/2011/10/03/drupal-7-blog-customized-teaser/">Continue reading <span class="meta-nav">&#8594;</span></a><img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=kristiannissen.wordpress.com&amp;blog=6383083&amp;post=423&amp;subd=kristiannissen&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>In the theme I&#8217;m working on I want to use the block &#8220;Recent blog posts&#8221; which is part of the blog module. But the &#8220;Recent blog posts&#8221; shows a list of minimum 2 blog posts as a list and I want to show 1 blog post in my teaser.</p>
<p>You can achieve this by using the <a href="http://api.drupal.org/api/drupal/modules--block--block.api.php/function/hook_block_view_MODULE_DELTA_alter/7">hook_block_view_MODULE_DELTA_alter</a> inside your template.php file where the MODULE is &#8220;blog&#8221; and DELTA is &#8220;recent&#8221;, so in my case where my theme is called &#8220;smackblue&#8221; the function name is &#8220;smackblue_block_view_blog_recent_alter&#8221;:</p>
<pre>/**
 * hook_block_view_MODULE_DELTA_alter()
 */
function smackblue_block_view_blog_recent_alter (&amp;$data, $block) {
    $content = $data['content'];

    if ($content['blog_list']) {
        $result = db_query('SELECT n.nid FROM {node} n WHERE n.type = :type ORDER BY created DESC LIMIT 1', array(':type' =&gt; 'blog'));
        $obj = $result-&gt;fetchObject();
        $node = node_load($obj-&gt;nid);
        $data['content'] = node_view($node, 'full');
    }
}</pre>
<p>I&#8217;m not keen on using <a href="http://api.drupal.org/api/drupal/includes--database--database.inc/function/db_query/7">db_query</a> inside my template.php file, but I did not find any other way to get the recent blog post, if you know how, let me know. Now the teaser blog is being themed the same way as every other blog post in my theme.</p>
<br />Filed under: <a href='http://kristiannissen.wordpress.com/category/code-is-poetry/'>code is poetry</a>, <a href='http://kristiannissen.wordpress.com/category/work-ive-done/'>Work I've done</a> Tagged: <a href='http://kristiannissen.wordpress.com/tag/drupal-7/'>Drupal 7</a>, <a href='http://kristiannissen.wordpress.com/tag/hooks/'>Hooks</a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/kristiannissen.wordpress.com/423/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/kristiannissen.wordpress.com/423/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/kristiannissen.wordpress.com/423/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/kristiannissen.wordpress.com/423/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/kristiannissen.wordpress.com/423/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/kristiannissen.wordpress.com/423/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/kristiannissen.wordpress.com/423/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/kristiannissen.wordpress.com/423/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/kristiannissen.wordpress.com/423/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/kristiannissen.wordpress.com/423/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/kristiannissen.wordpress.com/423/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/kristiannissen.wordpress.com/423/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/kristiannissen.wordpress.com/423/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/kristiannissen.wordpress.com/423/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=kristiannissen.wordpress.com&amp;blog=6383083&amp;post=423&amp;subd=kristiannissen&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://kristiannissen.wordpress.com/2011/10/03/drupal-7-blog-customized-teaser/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/eaf2025323bb63b0befc35491afa618e?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">kristiannissen</media:title>
		</media:content>
	</item>
		<item>
		<title>drupal 7 override system css</title>
		<link>http://kristiannissen.wordpress.com/2011/10/01/drupal-7-override-system-css/</link>
		<comments>http://kristiannissen.wordpress.com/2011/10/01/drupal-7-override-system-css/#comments</comments>
		<pubDate>Sat, 01 Oct 2011 09:47:36 +0000</pubDate>
		<dc:creator>Kristian Nissen</dc:creator>
				<category><![CDATA[code is poetry]]></category>
		<category><![CDATA[Drupal 7]]></category>
		<category><![CDATA[Hooks]]></category>

		<guid isPermaLink="false">http://kristiannissen.wordpress.com/?p=420</guid>
		<description><![CDATA[When you start building your own drupal 7 theme from scratch you will probably want to avoid any drupal 7 specific module generated CSS. You can remove these css files from within your template.php file which is what I prefer. Here I&#8217;m removing anything that is not related to my own theme specific CSS file &#8230; <a href="http://kristiannissen.wordpress.com/2011/10/01/drupal-7-override-system-css/">Continue reading <span class="meta-nav">&#8594;</span></a><img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=kristiannissen.wordpress.com&amp;blog=6383083&amp;post=420&amp;subd=kristiannissen&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>When you start building your own drupal 7 theme from scratch you will probably want to avoid any <strong>drupal 7 specific module generated CSS</strong>.</p>
<p>You can remove these css files from within your <strong>template.php</strong> file which is what I prefer.</p>
<p>Here I&#8217;m removing anything that is not related to my own theme specific CSS file by using drupal 7&#8242;s <a href="http://api.drupal.org/api/drupal/modules--system--system.api.php/function/hook_css_alter/7">hook_css_alter</a> function.</p>
<pre>/**
 * implement hook_css_alter()
 */
function smackblue_css_alter (&amp;$css) {
    foreach ($css as $mod =&gt; $val) {
        // Remove modules/*
        if (stripos($mod, 'modules') !== false) {
            unset($css[$mod]);
        }
    }
}</pre>
<p>I think this is the cleanest way to override or remove <strong>system specific CSS in drupal 7</strong>.</p>
<br />Filed under: <a href='http://kristiannissen.wordpress.com/category/code-is-poetry/'>code is poetry</a> Tagged: <a href='http://kristiannissen.wordpress.com/tag/drupal-7/'>Drupal 7</a>, <a href='http://kristiannissen.wordpress.com/tag/hooks/'>Hooks</a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/kristiannissen.wordpress.com/420/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/kristiannissen.wordpress.com/420/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/kristiannissen.wordpress.com/420/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/kristiannissen.wordpress.com/420/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/kristiannissen.wordpress.com/420/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/kristiannissen.wordpress.com/420/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/kristiannissen.wordpress.com/420/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/kristiannissen.wordpress.com/420/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/kristiannissen.wordpress.com/420/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/kristiannissen.wordpress.com/420/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/kristiannissen.wordpress.com/420/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/kristiannissen.wordpress.com/420/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/kristiannissen.wordpress.com/420/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/kristiannissen.wordpress.com/420/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=kristiannissen.wordpress.com&amp;blog=6383083&amp;post=420&amp;subd=kristiannissen&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://kristiannissen.wordpress.com/2011/10/01/drupal-7-override-system-css/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/eaf2025323bb63b0befc35491afa618e?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">kristiannissen</media:title>
		</media:content>
	</item>
		<item>
		<title>Rails Authentication system with polymorphic models</title>
		<link>http://kristiannissen.wordpress.com/2011/09/17/rails-authentication-system-with-polymorphic-models/</link>
		<comments>http://kristiannissen.wordpress.com/2011/09/17/rails-authentication-system-with-polymorphic-models/#comments</comments>
		<pubDate>Sat, 17 Sep 2011 14:34:09 +0000</pubDate>
		<dc:creator>Kristian Nissen</dc:creator>
				<category><![CDATA[code is poetry]]></category>
		<category><![CDATA[Authentication]]></category>
		<category><![CDATA[Polymorphic]]></category>
		<category><![CDATA[Ruby On Rails]]></category>

		<guid isPermaLink="false">http://kristiannissen.wordpress.com/?p=416</guid>
		<description><![CDATA[Uuuhhh&#8230; the title alone sounds funky :) I want to use polymorphic models for my current app in order to represent the different types of users that the app is handling. The base model is just a user and inside this model all the log in logic is stored and everything that is shared between &#8230; <a href="http://kristiannissen.wordpress.com/2011/09/17/rails-authentication-system-with-polymorphic-models/">Continue reading <span class="meta-nav">&#8594;</span></a><img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=kristiannissen.wordpress.com&amp;blog=6383083&amp;post=416&amp;subd=kristiannissen&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>Uuuhhh&#8230; the title alone sounds funky :)</p>
<p><strong>I want to use polymorphic</strong> models for my current app in order to <strong>represent the different types of users</strong> that the app is handling.</p>
<p>The base model is just a user and inside this model all the log in logic is stored and everything that is shared between all my different user types.</p>
<p>Inspired by cancan I wanted something that would be easy to maintain and easy to setup, therefor I decided to build a simple authentication system which I can then use in my app like this:</p>
<pre>Visitor.can?(:view, '/secret/stuff')</pre>
<p>and here the Visitor inherits from the User like so Visitor &lt; User and the user is representing the database table in this case.</p>
<p>Inside my Visitor all the permissions are stored in a hash like this:</p>
<pre>@permissions  = {
      :view =&gt; ["^/$", "deals", "deal\/[0-9]+$"]
    }</pre>
<p>as you can see each key is the action and the value is an array of regular expressions. And then in the rails console I tested this like so:</p>
<pre>["^/$", "deals", "deal\/[0-9]+$"].collect { |r| "/super/secret".match(r).nil? }</pre>
<p>where the path (just a string) being tested is &#8220;/super/secret&#8221; then the above line of code will return:</p>
<pre>[true, true, true]</pre>
<p>the path &#8220;/super/secret&#8221; is not in the array of regular expressions representing the resources a visitor can view. But if I change the path to &#8220;/deal/42&#8243; the returned array from the one liner would look like:</p>
<pre>[true, true, false]</pre>
<p>where false actually tells me that the visitor <em>can</em> view any path looking like &#8220;/deal/42&#8243;</p>
<br />Filed under: <a href='http://kristiannissen.wordpress.com/category/code-is-poetry/'>code is poetry</a> Tagged: <a href='http://kristiannissen.wordpress.com/tag/authentication/'>Authentication</a>, <a href='http://kristiannissen.wordpress.com/tag/polymorphic/'>Polymorphic</a>, <a href='http://kristiannissen.wordpress.com/tag/ruby-on-rails/'>Ruby On Rails</a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/kristiannissen.wordpress.com/416/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/kristiannissen.wordpress.com/416/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/kristiannissen.wordpress.com/416/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/kristiannissen.wordpress.com/416/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/kristiannissen.wordpress.com/416/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/kristiannissen.wordpress.com/416/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/kristiannissen.wordpress.com/416/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/kristiannissen.wordpress.com/416/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/kristiannissen.wordpress.com/416/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/kristiannissen.wordpress.com/416/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/kristiannissen.wordpress.com/416/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/kristiannissen.wordpress.com/416/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/kristiannissen.wordpress.com/416/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/kristiannissen.wordpress.com/416/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=kristiannissen.wordpress.com&amp;blog=6383083&amp;post=416&amp;subd=kristiannissen&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://kristiannissen.wordpress.com/2011/09/17/rails-authentication-system-with-polymorphic-models/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/eaf2025323bb63b0befc35491afa618e?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">kristiannissen</media:title>
		</media:content>
	</item>
	</channel>
</rss>
