<?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/"
	>

<channel>
	<title>GiveGoodWeb</title>
	<atom:link href="http://www.givegoodweb.com/feed" rel="self" type="application/rss+xml" />
	<link>http://www.givegoodweb.com</link>
	<description>Web n' What-Not</description>
	<pubDate>Mon, 15 Feb 2010 19:20:37 +0000</pubDate>
	<generator>http://wordpress.org/?v=2.7.1</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Sizing and Positioning Fancybox</title>
		<link>http://www.givegoodweb.com/post/125/sizing-and-positioning-fancybox</link>
		<comments>http://www.givegoodweb.com/post/125/sizing-and-positioning-fancybox#comments</comments>
		<pubDate>Mon, 15 Feb 2010 19:16:54 +0000</pubDate>
		<dc:creator>Matt</dc:creator>
		
		<category><![CDATA[jquery]]></category>

		<guid isPermaLink="false">http://www.givegoodweb.com/?p=125</guid>
		<description><![CDATA[You&#8217;ve probably seen Fancybox all over the place. In a way, it&#8217;s the living-successor of ThickBox and Lightbox.
I was recently on a project where I had to both size and place it. Sizing it it easy. Say you have a link tag with an id of opener, like this:
&#60;a id="opener" href="http://www.google.com"&#62;Google&#60;/a&#62;
To create and size the [...]]]></description>
			<content:encoded><![CDATA[<p>You&#8217;ve probably seen <a href="http://fancybox.net">Fancybox</a> all over the place. In a way, it&#8217;s the living-successor of ThickBox and Lightbox.</p>
<p>I was recently on a project where I had to both size and place it. Sizing it it easy. Say you have a link tag with an id of opener, like this:</p>
<pre>&lt;a id="opener" href="http://www.google.com"&gt;Google&lt;/a&gt;</pre>
<p>To create and size the fancybox that will open when it&#8217;s clicked, you&#8217;d just add the following javascript to your page:</p>
<pre>&lt;script type="text/javascript" charset="utf-8"&gt;<br style="font-size: 18px; line-height: 27px;" />  $(document).ready(function(){<br style="font-size: 18px; line-height: 27px;" />  $("#opener").fancybox({<br style="font-size: 18px; line-height: 27px;" />    'width': 390,<br style="font-size: 18px; line-height: 27px;" />    'height': 400<br style="font-size: 18px; line-height: 27px;" />  });<br style="font-size: 18px; line-height: 27px;" />});</pre>
<p>Note that pixels is assumed, you should not say something like &#8220;390 pixels&#8221; like you would in css, it won&#8217;t work then.</p>
<p>So, above we have defined a fancybox that is 390 pixels wide, and 400 pixels high. Next we need to position it.</p>
<p><em>(Note this is based on Fancybox 1.3 - I can&#8217;t say if it&#8217;ll work with other versions.)</em></p>
<p>Fancybox puts everything in a layer with an id of &#8220;fancybox-wrap&#8221; - so we can easily manipulate it with basic css, like so:</p>
<pre>#fancybox-wrap {
  margin: -70px 0 0 290px;
}</pre>
<p>You can do the same with padding, maybe even positioning.</p>
<p>Hope that helps someone!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.givegoodweb.com/post/125/sizing-and-positioning-fancybox/feed</wfw:commentRss>
		</item>
		<item>
		<title>Drupal: Redirecting a User After Login</title>
		<link>http://www.givegoodweb.com/post/121/drupal-redirecting-a-user-after-login</link>
		<comments>http://www.givegoodweb.com/post/121/drupal-redirecting-a-user-after-login#comments</comments>
		<pubDate>Thu, 07 Jan 2010 20:21:52 +0000</pubDate>
		<dc:creator>Matt</dc:creator>
		
		<category><![CDATA[Drupal]]></category>

		<guid isPermaLink="false">http://www.givegoodweb.com/?p=121</guid>
		<description><![CDATA[This has me beating my head on the desk a bit. I&#8217;m coding up a Drupal 6 module, and wanted to redirect the user after logging in, depending on what role they belong to.
In this example, let&#8217;s say I have a role called &#8220;treasurer&#8221; - and anyone that&#8217;s logged in and not a treasurer is [...]]]></description>
			<content:encoded><![CDATA[<p>This has me beating my head on the desk a bit. I&#8217;m coding up a Drupal 6 module, and wanted to redirect the user after logging in, depending on what role they belong to.</p>
<p>In this example, let&#8217;s say I have a role called &#8220;treasurer&#8221; - and anyone that&#8217;s logged in and <em>not</em> a treasurer is an administrator. In my module (called mymod here), I knew that <a href="http://api.drupal.org/api/function/hook_user/6">hook_user</a> would do the trick somehow. Note that in hook_user, the $op variable contains what operation is being performed, and &#8220;login&#8221; is an option we can use here. So, this will fire right after the login form is processed and the user is loaded. The $account variable contains the entire $user object being worked on (so we can use it instead of a <em>&#8220;global $user&#8221;</em> declaration). Here&#8217;s what I originally wanted to do but <strong>it does not work</strong>:</p>
<pre>function mymod_user($op, &amp;$edit, &amp;$account, $category = NULL) {
  switch ($op) {
    case 'login':
      if (in_array('treasurer', $account-&gt;roles)) {
        drupal_goto('user/' . $account-&gt;uid);
      } else {
        drupal_goto('admin/users');
      }
      break;
    default:
      // nothing
      break;
  }
}</pre>
<p>We can&#8217;t  use <a href="http://api.drupal.org/api/function/drupal_goto/6">drupal_goto</a> here, surprisingly. But after a little Googling, here is the way to do it - <strong>this works</strong>:</p>
<pre>function mymod_user($op, &amp;$edit, &amp;$account, $category = NULL) {
  switch ($op) {
    case 'login':
      if (in_array('treasurer', $account-&gt;roles)) {
        $_REQUEST['destination'] = 'user/' . $account-&gt;uid;
      } else {
        $_REQUEST['destination'] = 'admin/user/user';
      }
      break;
    default:
      // nothing
      break;
  }
}</pre>
<p>In short, we just need to set $_REQUEST['destination'] to whatever we want. In the above example, if the user is a treasurer, we sent them to their user account page. Otherwise, we know that it&#8217;s an administrator (since that&#8217;s the only other role I set up), and we show the admin all the users. Tailor to your needs. Note that if your destination has a url alias setup, this will automatically fetch the alias too. Cheers.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.givegoodweb.com/post/121/drupal-redirecting-a-user-after-login/feed</wfw:commentRss>
		</item>
		<item>
		<title>Tweeting from Launchbar</title>
		<link>http://www.givegoodweb.com/post/115/tweeting-from-launchbar</link>
		<comments>http://www.givegoodweb.com/post/115/tweeting-from-launchbar#comments</comments>
		<pubDate>Mon, 07 Dec 2009 21:27:24 +0000</pubDate>
		<dc:creator>Matt</dc:creator>
		
		<category><![CDATA[OS X]]></category>

		<guid isPermaLink="false">http://www.givegoodweb.com/?p=115</guid>
		<description><![CDATA[I&#8217;ve been checking out Launchbar, thinking replacing my beloved Quicksilver because supposedly it is not being worked on much anymore. While viewing these very helpful Launchbar Video tutorials, I noticed one of them was about Tweeting from Launchbar. For firing off a quick tweet, this is very handy.
However, I had problems getting the script mentioned [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve been checking out <a href="http://www.obdev.at/products/launchbar/index.html">Launchbar</a>, thinking replacing my beloved Quicksilver because supposedly it is not being worked on much anymore. While viewing these <a href="http://www.zettt.de/2009/04/mac-launchbar-tutorial-1/">very helpful Launchbar Video tutorials</a>, I noticed one of them was about <a href="http://www.zettt.de/2009/04/mac-launchbar-tutorial-5/">Tweeting from Launchbar</a>. For firing off a quick tweet, this is very handy.</p>
<p>However, I had problems getting the script mentioned in the tutorial to work. After some more searching and tweaking, I can came up with this script, which works well enough for me and gives Launchbar credit for the tweet, which makes you look super cool/geeky as most folks will probably be like <em>what the hell is this Launchbar???</em></p>
<p><em><a href="http://tr.im/GWR1"><img class="alignnone size-full wp-image-116" title="cartman-tweet" src="http://www.givegoodweb.com/wp-content/uploads/2009/12/cartman-tweet.png" alt="cartman-tweet" width="358" height="93" /></a><br />
</em></p>
<p>To use this script, open up Script Editor and copy it in, Compile and save it into ~/Library/Application Support/LaunchBar/Actions - where Launchbar should pick it up. From there, just use as <a href="http://www.zettt.de/2009/04/mac-launchbar-tutorial-5/">shown in the video</a>. Note this assumes you have <a href="http://growl.info/">Growl</a> installed - which you should ;)</p>
<pre>using terms from application "LaunchBar"
    on handle_string(tweet)
        -- Init
        my growlRegister()
        set charcount_max to 140
        set charcount_tweet to (count characters of tweet)

        -- Check message length
        if charcount_tweet ? charcount_max then
            -- Get credentials for twitter.com
            tell application "Keychain Scripting"
                set twitter_key to first Internet key of current keychain whose server is "twitter.com"
                set twitter_login to quoted form of (account of twitter_key &amp; ":" &amp; password of twitter_key)
            end tell

            set twitter_status to quoted form of ("source=launchbarat&amp;status=" &amp; tweet)
            try
                -- Send tweet
                do shell script "curl --user " &amp; twitter_login &amp; " --data-binary " &amp; twitter_status &amp; " http://twitter.com/statuses/update.json"
                -- Display success message
                growlNotify("Tweet Sent:", tweet)
            on error
                -- Display error message
                growlNotify("Error Tweeting.", "Try again?")
            end try
        else
            -- Tweet is too long
            growlNotify("Tweet Too Long", "Tweet is " &amp; charcount_tweet &amp; " characters long. The maximum length is " &amp; charcount_max &amp; " characters.")
        end if
    end handle_string
end using terms from

using terms from application "GrowlHelperApp"
    -- Register Growl
    on growlRegister()
        tell application "GrowlHelperApp"
            register as application "Tweet" all notifications {"Alert"} default notifications {"Alert"} icon of application "Script Editor.app"
        end tell
    end growlRegister

    -- Notify using Growl
    on growlNotify(grrTitle, grrDescription)
        tell application "GrowlHelperApp"
            notify with name "Alert" title grrTitle description grrDescription application name "Tweet"
        end tell
    end growlNotify
end using terms from</pre>
]]></content:encoded>
			<wfw:commentRss>http://www.givegoodweb.com/post/115/tweeting-from-launchbar/feed</wfw:commentRss>
		</item>
		<item>
		<title>Finding Duplicates in MySQL</title>
		<link>http://www.givegoodweb.com/post/113/finding-duplicates-in-mysql</link>
		<comments>http://www.givegoodweb.com/post/113/finding-duplicates-in-mysql#comments</comments>
		<pubDate>Wed, 25 Nov 2009 17:31:08 +0000</pubDate>
		<dc:creator>Matt</dc:creator>
		
		<category><![CDATA[mysql]]></category>

		<guid isPermaLink="false">http://www.givegoodweb.com/?p=113</guid>
		<description><![CDATA[I get quite a few Excel files from clients that need to get cleaned up and inserted in to MySQL. Sometimes the import goes smoothly, sometimes it doesn&#8217;t. This last time, I had 3,741 rows in an Excel file, but somehow wound up with 3,751 rows in the database - what went wrong? Don&#8217;t know, [...]]]></description>
			<content:encoded><![CDATA[<p>I get quite a few Excel files from clients that need to get cleaned up and inserted in to MySQL. Sometimes the import goes smoothly, sometimes it doesn&#8217;t. This last time, I had 3,741 rows in an Excel file, but somehow wound up with 3,751 rows in the database - what went wrong? Don&#8217;t know, and don&#8217;t have time to figure it out - so I just used this query to isolate all the duplicates.</p>
<p>My database table consists of nothing more than an id, a part number (number), a description, and a price. Here&#8217;s the query that located all duplicate part numbers - from there I was able to easily delete them:</p>
<pre>SELECT number,
 COUNT(number) AS NumOccurrences
FROM part_prices_new
GROUP BY number
HAVING ( COUNT(number) &gt; 1 )</pre>
]]></content:encoded>
			<wfw:commentRss>http://www.givegoodweb.com/post/113/finding-duplicates-in-mysql/feed</wfw:commentRss>
		</item>
		<item>
		<title>Easily Search a Twitter Stream</title>
		<link>http://www.givegoodweb.com/post/107/easily-search-a-twitter-stream</link>
		<comments>http://www.givegoodweb.com/post/107/easily-search-a-twitter-stream#comments</comments>
		<pubDate>Wed, 18 Nov 2009 21:45:05 +0000</pubDate>
		<dc:creator>Matt</dc:creator>
		
		<category><![CDATA[twitter]]></category>

		<guid isPermaLink="false">http://www.givegoodweb.com/?p=107</guid>
		<description><![CDATA[I occasionally see people wondering how to search their Twitter stream, or anybody&#8217;s Twitter stream for that matter. Sure, you can easily search all of twitter for something, but what about limiting a search to a particular user? Twitter&#8217;s search features are pretty hit or miss for such specific searches, so as long as the [...]]]></description>
			<content:encoded><![CDATA[<p>I occasionally see people wondering how to search their Twitter stream, or anybody&#8217;s Twitter stream for that matter. Sure, you can easily search <em>all </em>of twitter for something, but what about limiting a search to a particular user? Twitter&#8217;s search features are pretty hit or miss for such specific searches, so as long as the account being searched is public and accessible to anyone, Google will have indexed it much more efficiently than Twitter.</p>
<p>So&#8230; I would try to explain how to use Google to restrict a search to a particular website or even part of a website. That wasn&#8217;t working so well. So I just made a website that does it for you - <a title="Twitter stream search" href="http://www.searchapeepstweets.com/">Search a Peep&#8217;s Tweets</a>. It even remembers your most recent searches for you.</p>
<div class="mceTemp">
<dl id="attachment_108" class="wp-caption alignnone" style="width: 411px;">
<dt class="wp-caption-dt"><a href="http://www.searchapeepstweets.com/"><img class="size-medium wp-image-108" title="sapt" src="http://www.givegoodweb.com/wp-content/uploads/2009/11/sapt-300x191.png" alt="Searc a Peep's Tweets" width="401" height="255" /></a></dt>
</dl>
</div>
<p>As a comparison, I used Twitter&#8217;s <em>advanced search</em> to search my Twitter account (stoptime) for &#8220;beer&#8221; -  I get <a title="no results!" href="http://search.twitter.com/search?q=&amp;ands=beer&amp;phrase=&amp;ors=&amp;nots=&amp;tag=&amp;lang=all&amp;from=stoptime&amp;to=&amp;ref=&amp;near=&amp;within=15&amp;units=mi&amp;since=&amp;until=&amp;rpp=15">no results</a>. The same search on Google gives me <a title="leave search to the masters" href="http://www.google.com/search?q=beer+site%3Atwitter.com%2Fstoptime">10 results</a>. So hopefully this&#8217;ll be useful and easy, cheers!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.givegoodweb.com/post/107/easily-search-a-twitter-stream/feed</wfw:commentRss>
		</item>
		<item>
		<title>Using the Shell and Cron to Automate Your MySQL Backups</title>
		<link>http://www.givegoodweb.com/post/101/using-the-shell-and-cron-to-automate-your-mysql-backups</link>
		<comments>http://www.givegoodweb.com/post/101/using-the-shell-and-cron-to-automate-your-mysql-backups#comments</comments>
		<pubDate>Wed, 29 Apr 2009 16:34:04 +0000</pubDate>
		<dc:creator>Matt</dc:creator>
		
		<category><![CDATA[OS X]]></category>

		<guid isPermaLink="false">http://www.givegoodweb.com/post/101/using-the-shell-and-cron-to-automate-your-mysql-backups</guid>
		<description><![CDATA[This article describes a simple shell script that backs up your local MySQL databases. It also goes into how to automate the process so it runs everyday using a cron job. Handy!]]></description>
			<content:encoded><![CDATA[<p>This little shell script has proven to be a handy way to backup my local databases:</p>
<pre>#!/bin/bash<br style="font-size: 16.5px; line-height: 19.5px" /><br style="font-size: 16.5px; line-height: 19.5px" />cd '/folder/to/store/your/backups/'<br style="font-size: 16.5px; line-height: 19.5px" />for x in db-name-a db-name-b db-name-c
do
   mysqldump --user=username --password=pass $x --lock-tables --add-drop-table &gt; $x`date +%u`.sql;
done</pre>
<p>So what&#8217;s up with this little snippet? The first line with the &#8216;cd&#8217; commad, we&#8217;re just <strong>c</strong>hanging into the <strong>d</strong>irectory where all the sql dumps will be stored. I also store this little script in there (backup.sh).</p>
<p>The next line is a basic loop. we list all of the local database names we want to backup, right after the &#8220;for x in&#8221; phrase, separated by a space.  The indented line is what actually dumps, names, and saves the file. On my local development computer, I just pass in the root username and pass, so it will work for each database. Each backup file then follows the &#8220;db-name&#8221; + &#8220;day of week&#8221; naming convention. For example, <em>db-name-a1.sql</em> would be Monday&#8217;s backup, <em>db-name-a2.sql</em> would be Tuesday&#8217;s backup, etc. A week&#8217;s worth of backups is fine for me, though you can customize this to your liking.</p>
<p>And the command line, you can test if this is working like so (assuming you are in the same directory as the file):</p>
<pre>$ sh db-backup.sh</pre>
<h2>Not Working?</h2>
<p>If it&#8217;s not working, a couple things may be happening. You can alter the script with more conditionals to output some general errors, but OS X will actually mail you a detailed copy of the error. Getting at it can be a little cryptic though. At the prompt, type mail:</p>
<pre>$ mail</pre>
<p>If you see a message like <em>&#8220;You have mail in /var/mail/your-username&#8221;</em> then you should check it out. You can use the terminal to check it (<em>man mail</em> to check the manual entry for mail). Or, what I tend to do is just open the entire mail file in my text editor, which is TextMate - using the command line tool:</p>
<pre>$ mate /var/mail/your-username</pre>
<p>Some juicy debugging info may be in there. You can delete everything in the file and save it if  you like. This will get rid of the &#8220;You have mail in&#8230;&#8221; message whenever you start up terminal.</p>
<h3>Automating It</h3>
<p>I have this script run everyday at 3pm - I do that with a <a href="http://en.wikipedia.org/wiki/Cron" title="Wikipedia entry">cron job</a>, using <a href="http://h775982.serverkompetenz.net:9080/abstracture_public/projects-en/cronnix" title="Cronnix home page">Cronnix</a> as a graphical interface:</p>
<p><img src="http://www.givegoodweb.com/wp-content/uploads/2009/04/screen-capture.png" alt="cronnix" width="549" height="299" /></p>
<p>One problem you may have is that your crontab&#8217;s path is not necessarily the same as your user account&#8217;s shell path. For example, if you are seeing an error like &#8220;mysqldump - command not found&#8221; - simply go back to the terminal, and enter &#8220;which mysqldump&#8221;:</p>
<pre>$ which mysqldump</pre>
<p>It will output the full path to this command. Copy that path and paste the full path into your script. So for example, the line following the &#8220;do&#8221; command may look like:</p>
<pre>/Applications/MAMP/Library/bin/mysqldump --user=user --password=pass $x --lock-tables --add-drop-table &gt; $x`date +%u`.sql;</pre>
<p>I use the <a href="http://www.mamp.info" title="MAMP home page">MAMP</a> version of mysql dump, so I need to tell the script exactly what version to use.</p>
<p>From here, I use <strong>SVN</strong> to keep this folder under version control as well, which makes switching from the desktop to the laptop much easier when developing. Cheers!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.givegoodweb.com/post/101/using-the-shell-and-cron-to-automate-your-mysql-backups/feed</wfw:commentRss>
		</item>
		<item>
		<title>Drupal Multi-site Configuration on a Dedicated Server</title>
		<link>http://www.givegoodweb.com/post/99/drupal-multi-site-dedicated-server</link>
		<comments>http://www.givegoodweb.com/post/99/drupal-multi-site-dedicated-server#comments</comments>
		<pubDate>Mon, 23 Mar 2009 19:00:51 +0000</pubDate>
		<dc:creator>Matt</dc:creator>
		
		<category><![CDATA[Drupal]]></category>

		<guid isPermaLink="false">http://www.givegoodweb.com/post/99/drupal-multi-site-configuration-on-dedicated-server</guid>
		<description><![CDATA[So I just figured out how to get Drupal&#8217;s multi-site configuration working on my Rackspace Linux server.
Let&#8217;s say  your Drupal core is located at my-drupal-core.com. Install Drupal there, this will be your master copy.
Within your &#8217;sites&#8217; folder, create a folder for each domain you will want to run off this core installation. Let&#8217;s say [...]]]></description>
			<content:encoded><![CDATA[<p align="left">So I just figured out how to get Drupal&#8217;s multi-site configuration working on my Rackspace Linux server.</p>
<p>Let&#8217;s say  your Drupal core is located at <em>my-drupal-core.com</em>. Install Drupal there, this will be your master copy.</p>
<p>Within your &#8217;sites&#8217; folder, create a folder for each domain you will want to run off this core installation. Let&#8217;s say we&#8217;ll make a Drupal site, based on this core, which will be <em>drupal-slave.com</em>.  So, within your <em>sites</em> folder, create a drupal-slave.com folder. I prefer using a different database for each site. So create the database for the slave site, and then copy the settings.php file from your <em>sites/default</em> folder, alter it for your slave database, and put it into the drupal-slave.com folder. While you&#8217;re in there, create a <em>files</em> folder, you may need to change its permissions to 777.</p>
<p>So, your drupal-slave.com folder should look like this:</p>
<pre>sites
   -- drupal-slave.com [folder]
      -- settings.php
      -- files [folder]
      -- modules [modules specific to this domain]
      -- themes [themes specific to this domain]</pre>
<p>Now, on my server, every domain has a <em>vhost.conf</em> file, located inside a domains <em>conf</em> directory - this is at least how Red Hat does it. If you have a <em>conf </em>folder, but no <em>vhost.conf</em> file, go ahead and create it - you&#8217;ll likely need to login as root to do this.</p>
<p>Now, within your <em>vhost.conf</em> file (for drupal-slave.com, in this scenario), you&#8217;ll need to do something like this (alter for your own needs):</p>
<pre>DocumentRoot /httpd/vhosts/<em>my-drupal-core.com</em>/httpdocs&lt;Directory /httpd/vhosts/<em>my-drupal-core.com</em>/httpdocs&gt;
  php_admin_value open_basedir /tmp:/httpd/vhosts/<em>my-drupal-core.com</em>/httpdocs
  AllowOverride All
&lt;/Directory&gt;</pre>
<p>Then, (gracefully) restart Apache - viola! Works for me at least. By the way, the AllowOverride All is to allow the <em>my-drupal-core.com&#8217;s </em>.htaccess file to work on all slave sites. The /tmp directory allows the slave site to write to the tmp directory for file uploads. Hope this helps someone.</p>
<h2>Security</h2>
<p>Note that with a multi-site setup, you really need to be careful of who can use the PHP filter (preferably, nobody). Reason being you can use PHP to read/output any domain&#8217;s <em>settings.php</em> file and gain access to the database username and password for any domain sharing the Drupal installation, including the master domain. Careful! This alone makes me think I won&#8217;t be using a multisite setup for high profile sites, or any site I&#8217;m not directly managing.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.givegoodweb.com/post/99/drupal-multi-site-dedicated-server/feed</wfw:commentRss>
		</item>
		<item>
		<title>Drupal - Adding Author Name Search to Main Search Results Page</title>
		<link>http://www.givegoodweb.com/post/97/drupal-add-author-to-search</link>
		<comments>http://www.givegoodweb.com/post/97/drupal-add-author-to-search#comments</comments>
		<pubDate>Tue, 17 Mar 2009 13:58:04 +0000</pubDate>
		<dc:creator>Matt</dc:creator>
		
		<category><![CDATA[Drupal]]></category>

		<guid isPermaLink="false">http://www.givegoodweb.com/post/97/drupal-add-author-to-search</guid>
		<description><![CDATA[Perhaps you typed an author's name into Drupal's search box, looking for content from that particular author. But for all Drupal knows, you're just looking for content that matches the search phrase you just entered and could care less about who wrote it.]]></description>
			<content:encoded><![CDATA[<p align="left">Perhaps you typed an author&#8217;s name into Drupal&#8217;s search box, looking for content from that particular author. But for all Drupal knows, you&#8217;re just looking for content that matches the search phrase you just entered and could care less about who wrote it.</p>
<h2>What do to?</h2>
<p align="left"><em>Note: This page assumes some familiarity with how Drupal works. </em></p>
<p align="left"> The answer is the following sequence:</p>
<ol>
<li>Alongside the regular data query, query the user database for a username using a LIKE query, and if one is found, grab the user id too (uid).</li>
<li>Perform a search for published content that matches that user id.</li>
<li>Count the total pieces of content found.</li>
<li>Spit out a link on the search result page that says something like, <em>&#8220;Looking for posts written by Joe Author? (# found)&#8221;</em></li>
</ol>
<p align="left">I was hoping I could use the Views module for this, but I couldn&#8217;t figure out how to do a &#8220;LIKE&#8221; query with it. Besides, rather than loading a huge view object, why not to write a couple simple functions to do this? They can be efficient, and still take advantage of Drupal&#8217;s nifty (and secure) database functionality. The finished search page will look something like this:</p>
<p align="left"><img src="http://www.givegoodweb.com/wp-content/uploads/2009/03/include-user-name-search.png" alt="include-user-name-search.png" height="425" width="572" /></p>
<p align="left"><strong>Step 1: Build the query function</strong></p>
<p align="left">First things first - open up your theme&#8217;s <em>template.php</em> file. This is the place we store functions that we want to make available to the theme you are using. We&#8217;re going to add the following function to it - I&#8217;ve commented it pretty heavily:</p>
<pre>
/**
  * This function will search the database for an
  * aurhor's name, if it finds a match, will
  * count how many published stories and forum topics
  * they have
  * @param $name - the user name being searched for
  */
function get_user_content_total($name) {
  // this is the placeholder for the output link we're building
  $output = '';

  // build a user name search query with a string placeholder
  $sql = "SELECT name, uid FROM {users} WHERE name LIKE '%%%s%%'";
  $result = db_query(db_rewrite_sql($sql), $name);

  // build a count query with a digit placeholder for the user_id (uid from last query)
  $sql_count = "SELECT COUNT(node.uid) as count
  FROM {node} WHERE ({node}.status &lt;&gt; 0) AND ({node}.type in ('forum', 'story')) AND ({node}.uid = %d)";

  // iterate over the results
  while ($data = db_fetch_object($result)) {
    $result_count = db_query(db_rewrite_sql($sql_count), $data-&gt;uid);
    $data_count = db_fetch_object($result_count);

    // if we found any stories or forum topics, generate the text and link
    if ($data_count-&gt;count &gt; 0) {
      $link_text = t('» Looking for content written by %author (%count)?', array('%author' =&gt; $data-&gt;name, '%count' =&gt; $data_count-&gt;count));
      $link = l($link_text, 'user/' . $data-&gt;uid . '/recent', array('html' =&gt; TRUE));
      $output .= '&lt;p&gt;' . $link . '&lt;/p&gt;' . "\n";
    }
  }
  return $output;
}</pre>
<p align="left">You might be wondering about my link. Basically, I have a view already setup to fetch content written by a specific user. <a href="http://www.givegoodweb.com/post/95/drupal-get-username-from-uid" title="Getting a name and content from UID">More on that over here</a>. Ok, now we have some data to work with, so on to displaying it.</p>
<p align="left"><strong>Step 2: Override the Search Results Template</strong></p>
<p align="left">The search module has a template file name <em>search-results.tpl.php</em> - we&#8217;re going to override that template file simply by making a file of the same name in our theme&#8217;s directory. So, your theme&#8217;s directory, create a file called <em>search-results.tpl.php</em> and put this into it:</p>
<pre align="left">
&lt;?php
print get_user_content_total(arg(2));
?&gt;
&lt;dl class="search-results &lt;?php print $type; ?&gt;-results"&gt;
  &lt;?php print $search_results; ?&gt;
&lt;/dl&gt;
&lt;?php print $pager; ?&gt;</pre>
<p align="left">Now, the only difference between the search module&#8217;s <em>search-results.tpl.php</em> and ours is that ours calls our function at the top - the rest is exactly the same. And the nice thing about overriding it in this manner is that the next time we upgrade Drupal, our custom template here won&#8217;t get overridden because we&#8217;re not touching any core files.</p>
<p align="left">After you create this file, you&#8217;ll need to visit admin/build/modules, which will rebuild the template files and let Drupal know that we are overriding something.</p>
<p align="left">The last thing you may be asking is what&#8217;s with the <em>arg(2)</em> thing. That is just Drupal&#8217;s way of fetching things from the current URL. When you search with the search module, the URL is something like:</p>
<pre align="left">http://www.your-drupal.com/search/node/search words</pre>
<p align="left">The counting starts at 0, and does not include the domain. So &#8217;search&#8217; is 0, &#8216;node&#8217; is 1, and &#8217;search words&#8217; is 2. Since this URL is always structured this way for a search result page, we can just pull the search query words directly from it, and rely on Drupal&#8217;s database functions to clean them up for safe querying.</p>
<p align="left">This may not be the best way to do this - so I&#8217;m all ears if there&#8217;s a better way, cheers!</p>
<p align="left">&nbsp;</p>
<p align="left">&nbsp;</p>
<p align="left">&nbsp;</p>
]]></content:encoded>
			<wfw:commentRss>http://www.givegoodweb.com/post/97/drupal-add-author-to-search/feed</wfw:commentRss>
		</item>
		<item>
		<title>Drupal: Get a Username from a User ID</title>
		<link>http://www.givegoodweb.com/post/95/drupal-get-username-from-uid</link>
		<comments>http://www.givegoodweb.com/post/95/drupal-get-username-from-uid#comments</comments>
		<pubDate>Tue, 17 Feb 2009 23:02:45 +0000</pubDate>
		<dc:creator>Matt</dc:creator>
		
		<category><![CDATA[Drupal]]></category>

		<guid isPermaLink="false">http://www.givegoodweb.com/post/95/drupal-get-username-from-uid</guid>
		<description><![CDATA[I&#8217;ve been really enjoying working with Drupal - the more I learn about it, the more ideas I get on how to use it. Yet, sometimes it can make a simple thing a bit daunting - like fetching a user&#8217;s name from a user id, without needed to load the entire user object with user_load() [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve been really enjoying working with Drupal - the more I learn about it, the more ideas I get on how to use it. Yet, sometimes it can make a simple thing a bit daunting - like fetching a user&#8217;s name from a user id, without needed to load the entire user object with <a title="user_load api doc" href="http://api.drupal.org/api/function/user_load/6">user_load()</a> - which can get expensive.</p>
<p>So, here&#8217;s a handy little function. Just plop it in your template.php file for your theme of choice, and it will be available where you need it on your site (as long as you&#8217;re using that template!):</p>
<pre><span style="text-decoration: line-through;">function getUserName($id) {
  $sql = "SELECT name FROM {users} WHERE uid = '$id'";
  $result = db_query(db_rewrite_sql($sql));
  $username = db_fetch_object($result);
  return $username-&gt;name;
}

</span>// after learning more Drupal, this is the better way:
// note that $id must be a number

function getUserName($id) {
  return db_result(db_query("SELECT name FROM {users} WHERE uid = %d", $id));
}</pre>
<p>To use it for output, just do something like:</p>
<pre>&lt;?php print getUserName(1234); ?&gt;</pre>
<h2>Using This With the Views Module</h2>
<p>I often use this with the Views module. For example, I have a View for displaying all content created by a given user. The URL looks something like this:</p>
<p>http://www.some-drupal-site.com/user/1234/recent</p>
<p>The &#8220;1234&#8243; is the user id argument getting passed to the view. The view will then go in and fetch content created by this user id. Oftentimes I want to create a nice header in the View with dynamic output - but Views doesn&#8217;t really allow that sort of thing in the header/footer areas under Basic Settings. So I use this function to get around it. In the view&#8217;s header, I do this to fetch a username:</p>
<pre>&lt;?php
  $view=views_get_current_view();
  $user_name = getUserName($view-&gt;args[0]);
  print '&lt;h1&gt;Content created by  ' . $user_name . '&lt;/h1&gt;';
?&gt;</pre>
<p><em>*Note that to get the PHP input type working, you need to allow the PHP Filter in the modules section, and then select PHP as the input type for this view&#8217;s header.</em></p>
<p>Note that after you click the Update button, the Views module may give you an error message - that&#8217;s OK. It just doesn&#8217;t know what to do with this php code outside of the actual page you&#8217;re going to use it on.Below is a screenshot example.</p>
<p><img src="http://www.givegoodweb.com/wp-content/uploads/2009/02/user-header-views.png" alt="user-header-views.png" /></p>
<p>Hope this helps someone! And if you know a better way to do this, speak up! Cheers.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.givegoodweb.com/post/95/drupal-get-username-from-uid/feed</wfw:commentRss>
		</item>
		<item>
		<title>Drupal - Encoding Email Addresses to Deter Spam-bots</title>
		<link>http://www.givegoodweb.com/post/91/druapl-encode-email</link>
		<comments>http://www.givegoodweb.com/post/91/druapl-encode-email#comments</comments>
		<pubDate>Mon, 12 Jan 2009 21:15:19 +0000</pubDate>
		<dc:creator>Matt</dc:creator>
		
		<category><![CDATA[Drupal]]></category>

		<guid isPermaLink="false">http://www.givegoodweb.com/post/91/druapl-encode-email</guid>
		<description><![CDATA[While working on my latest Drupal project, I really wanted an easy, brainless way for users to create clickable &#8220;mailto:&#8221; links that gave pesky spam-bots a hard time.
Turns out, the Bbcode module does just the trick. Even if you don&#8217;t normally use it, you can add this input filter to your standard HTML filters, and [...]]]></description>
			<content:encoded><![CDATA[<p>While working on my latest Drupal project, I really wanted an easy, brainless way for users to create clickable &#8220;mailto:&#8221; links that gave pesky spam-bots a hard time.</p>
<p>Turns out, the <strong>Bbcode module</strong> does just the trick. Even if you don&#8217;t normally use it, you can add this input filter to your standard HTML filters, and it will work. The first step is to <a href="http://drupal.org/project/bbcode" title="Bbcode Module page">download and install the module</a>.</p>
<p>Next up, enable the module, and add it to your input filters (located at /admin/settings/filters):</p>
<p><img src="http://www.givegoodweb.com/wp-content/uploads/2009/01/input-filters.png" alt="input-filters.png" height="112" width="502" /></p>
<p>As you can see,  you don&#8217;t even need to assign it any roles. However, the Filtered HTML and Full HTML filters can use it, just set them up like so:</p>
<p><img src="http://www.givegoodweb.com/wp-content/uploads/2009/01/input-filters-shot.jpg" alt="Input Filters" height="288" width="501" /></p>
<p>Next, go in and and <em>configure</em> the Bbcode module to encode email addresses:</p>
<p><img src="http://www.givegoodweb.com/wp-content/uploads/2009/01/bbcode-email.png" alt="bbcode-email.png" /></p>
<p>Now, to use it - just use the standard bbcode to encode any email address:</p>
<p>[email]someone@domain.com[/email]</p>
<p>And when the page is rendered, the underlying HTML will all be JavaScript gobbly-gook, but to the end user, it will be a normal link.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.givegoodweb.com/post/91/druapl-encode-email/feed</wfw:commentRss>
		</item>
	</channel>
</rss>
