<?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>Xiaan Design: Blog &#187; Drupal</title>
	<atom:link href="http://xiaan.com/blog/category/drupal/feed/" rel="self" type="application/rss+xml" />
	<link>http://xiaan.com/blog</link>
	<description>UX design and RIA development in the post-Web 2.0 world.</description>
	<lastBuildDate>Sun, 17 Aug 2008 17:44:48 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Drupal 4.7: Hacking the Upload Module</title>
		<link>http://xiaan.com/blog/2007/06/29/drupal-hacking-the-upload-module/</link>
		<comments>http://xiaan.com/blog/2007/06/29/drupal-hacking-the-upload-module/#comments</comments>
		<pubDate>Fri, 29 Jun 2007 17:42:18 +0000</pubDate>
		<dc:creator>Christiaan van Woudenberg</dc:creator>
				<category><![CDATA[Drupal]]></category>

		<guid isPermaLink="false">http://xiaan.com/blog/index.php/2007/06/29/drupal-hacking-the-upload-module/</guid>
		<description><![CDATA[I&#8217;ve chosen Drupal for a web site project for a long-time client. We&#8217;re slogging our way through hundreds of pages of content, and have decided that we want to display attachment uploads by category, with little to no impact to the content manager uploading the attachments. 
The solution/hack involved a customization to the Upload module, [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve chosen Drupal for a web site project for a long-time client. We&#8217;re slogging our way through hundreds of pages of content, and have decided that we want to display attachment uploads by category, with little to no impact to the content manager uploading the attachments. <span id="more-9"></span></p>
<p>The solution/hack involved a customization to the Upload module, replacing the <code>theme_upload_attachments()</code> function with the customized version below. The idea was to have the content manager add a prefix to the filenames that would identify the category, and the software would take care of the rest.</p>
<p>Some notes:</p>
<ul>
<li>[+] It can&#8217;t get much easier than adding a prefix to a file before you upload it to the web site.</li>
<li>[+] FTP file listings are now sorted by category in the Drupal <code>files/uploads</code> folder.</li>
<li>[-] If the content manager makes a mistake in naming a file, she has to remove the upload, rename the file on her file system, and re-upload.</li>
</ul>
<p>Here&#8217;s the modified function for Drupal 4.7, use at your own risk. At some time before we launch the site I&#8217;ll upgrade to Drupal 5.1, and post a modified version of the function for 5.1.</p>
<pre class="brush: php">
/**
* Displays file attachments in table
*/
function theme_upload_attachments($files) {
  $header = array(t(&#039;Name&#039;), t(&#039;Size&#039;));
  $spec_rows = array();
  $dsgn_rows = array();
  $inst_rows = array();
  $case_rows = array();
  $rows = array();
  $str = array();

  foreach ($files as $file) {
    if ($file-&amp;amp;gt;list) {
      $href = $file-&amp;amp;gt;fid ? file_create_url($file-&amp;amp;gt;filepath) : url(file_create_filename($file-&amp;amp;gt;filename, file_create_path()));
      $text = $file-&amp;amp;gt;description ? $file-&amp;amp;gt;description : $file-&amp;amp;gt;filename;

      if (strpos($file-&amp;amp;gt;filepath,&#039;spec_&#039;) != false) {
        $spec_rows[] = array(l($text, $href), format_size($file-&amp;amp;gt;filesize));
      } elseif (strpos($file-&amp;amp;gt;filepath,&#039;dsgn_&#039;) != false) {
        $dsgn_rows[] = array(l($text, $href), format_size($file-&amp;amp;gt;filesize));
      } elseif (strpos($file-&amp;amp;gt;filepath,&#039;inst_&#039;) != false) {
        $inst_rows[] = array(l($text, $href), format_size($file-&amp;amp;gt;filesize));
      } elseif (strpos($file-&amp;amp;gt;filepath,&#039;case_&#039;) != false) {
        $case_rows[] = array(l($text, $href), format_size($file-&amp;amp;gt;filesize));
      } else {
        $rows[] = array(l($text, $href), format_size($file-&amp;amp;gt;filesize));
      }
    }
  }

  if (count($spec_rows)) {
    $str[] = &#039;&amp;amp;lt;h2&amp;amp;gt;Product Specifications&amp;amp;lt;/h2&amp;amp;gt;&#039;;
    $str[] = theme(&#039;table&#039;, $header, $spec_rows, array(&#039;id&#039; =&amp;amp;gt; &#039;attachments&#039;));
  }
  if (count($dsgn_rows)) {
    $str[] = &#039;&amp;amp;lt;h2&amp;amp;gt;Design Information&amp;amp;lt;/h2&amp;amp;gt;&#039;;
    $str[] = theme(&#039;table&#039;, $header, $dsgn_rows, array(&#039;id&#039; =&amp;amp;gt; &#039;attachments&#039;));
  }
  if (count($inst_rows)) {
    $str[] = &#039;&amp;amp;lt;h2&amp;amp;gt;Installation Guides&amp;amp;lt;/h2&amp;amp;gt;&#039;;
    $str[] = theme(&#039;table&#039;, $header, $inst_rows, array(&#039;id&#039; =&amp;amp;gt; &#039;attachments&#039;));
  }
  if (count($case_rows)) {
    $str[] = &#039;&amp;amp;lt;h2&amp;amp;gt;Case Studies&amp;amp;lt;/h2&amp;amp;gt;&#039;;
    $str[] = theme(&#039;table&#039;, $header, $case_rows, array(&#039;id&#039; =&amp;amp;gt; &#039;attachments&#039;));
  }
  if (count($rows)) {
    $str[] = &#039;&amp;amp;lt;h2&amp;amp;gt;Other Downloads&amp;amp;lt;/h2&amp;amp;gt;&#039;;
    $str[] = theme(&#039;table&#039;, $header, $rows, array(&#039;id&#039; =&amp;amp;gt; &#039;attachments&#039;));
  }
  return implode(&#039;&#039;,$str);
}
</pre>
]]></content:encoded>
			<wfw:commentRss>http://xiaan.com/blog/2007/06/29/drupal-hacking-the-upload-module/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

