<?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>David Pratt &#187; drupal</title> <atom:link href="http://daipratt.co.uk/tag/drupal/feed/" rel="self" type="application/rss+xml" /><link>http://daipratt.co.uk</link> <description>Concerned about Website Construction &#38; SEO</description> <lastBuildDate>Thu, 17 May 2012 19:14:00 +0000</lastBuildDate> <language>en</language> <sy:updatePeriod>hourly</sy:updatePeriod> <sy:updateFrequency>1</sy:updateFrequency> <generator>http://wordpress.org/?v=3.3.2</generator> <item><title>Drupal &#8211; Getting the image path of a CCK field</title><link>http://daipratt.co.uk/drupal-getting-the-image-path-of-a-cck-field/</link> <comments>http://daipratt.co.uk/drupal-getting-the-image-path-of-a-cck-field/#comments</comments> <pubDate>Tue, 26 Jan 2010 08:37:54 +0000</pubDate> <dc:creator>David Pratt</dc:creator> <category><![CDATA[Tech]]></category> <category><![CDATA[drupal]]></category> <guid
isPermaLink="false">http://daipratt.co.uk/?p=1027</guid> <description><![CDATA[An explanation about how to use the internal Drupal function field_file_load() to get the path of an image that is stored in a CCK field.]]></description> <content:encoded><![CDATA[<p>I often find myself using the Views module in Drupal to generate SQL that I can then use elsewhere directly, such as from <a
href="http://drupal.org/node/146172">page handler include files</a>.  Occasionally however, the SQL that the View module generates doesn&#8217;t quite work as you would expect, or as though it would from within a standard View.  This happens in my experience more often than not when you&#8217;re dealing with CCK image fields. The problem being that the contents of the 3 fields that are associated to a particular image within the content type table, don&#8217;t contain anything that resembles a path to the physical location of the image in the file system.  The 3 fields that I am referring to can be identified by their endings; one will end in <i>_fid</i>, another with <i>_list</i> and the last with <i>_data</i>.  To explain this better it might be easier if I give an example, the following SQL will get the contents of the 3 fields that are associated with an image, in this case it is the website logo field:</p><pre class="brush: sql">
SELECT
field_website_logo_fid,
field_website_logo_list,
field_website_logo_data
FROM content_type_website
LIMIT 1
</pre><p>When I perform this query I get:</p><pre class="brush: plain">
fid: 1723
list: 1
data: a:10:{s:8:"duration"; i:0; s:6:"height"; i:0;s:5:"width"; i:0;s:18:"audio_bitrate_mode"; s:0:""; s:18:"audio_channel_mode";s:0:""; s:12:"audio_format"; s:0:""; s:13:"audio_bitrate"; i:0; s:17:"audio_sample_rate"; i:0; s:3:"alt"; s:0:""; s:5:"title"; s:0:"";}
</pre><p>You&#8217;ll notice that none of these values give anything obviously meaningful to work with, and this can be confusing because as you can see, there isn&#8217;t anything obvious here (to me anyway) that looks like an image path, or that can be used to construct an image path. You might be able to guess that the <i>fid</i> value can be used as a look up on another table to get more information about the image (which it can by the way), but you&#8217;d need to find that table and either do a join or an additional look up to find that out.  Rather that doing that, the easiest method that I&#8217;ve come across to find the path of the image (if you know the <i>fid</i> value) is to use the <a
href="http://api.lullabot.com/field_file_load">field_file_load</a> function like so:</p><pre class="brush: php">
$file = field_file_load($node->website_logo_fid);
$filepath = $file['filepath'];
</pre><p>You could then put the $filepath directly into an image:</p><pre class="brush: php">
print '&lt;img src="/'.$filepath.'" alt="" /&gt;';
</pre><p>Bear in mind that you might need to consider the base path before the <i>$filepath</i>.</p><p>The other instance that you might want to retrieve an image path from a CCK image field, is from within a template file.  If you know the name of the CCK image field, then you can retrieve the path by doing something like:</p><pre class="brush: php">
$field_website_logo[0]['filepath'];
</pre>]]></content:encoded> <wfw:commentRss>http://daipratt.co.uk/drupal-getting-the-image-path-of-a-cck-field/feed/</wfw:commentRss> <slash:comments>10</slash:comments> </item> <item><title>Removing unwanted stylesheets from Drupal</title><link>http://daipratt.co.uk/removing-unwanted-stylesheets-from-drupal/</link> <comments>http://daipratt.co.uk/removing-unwanted-stylesheets-from-drupal/#comments</comments> <pubDate>Wed, 16 Dec 2009 13:18:21 +0000</pubDate> <dc:creator>David Pratt</dc:creator> <category><![CDATA[Tech]]></category> <category><![CDATA[css]]></category> <category><![CDATA[drupal]]></category> <guid
isPermaLink="false">http://daipratt.co.uk/?p=748</guid> <description><![CDATA[A way of stripping unwanted stylesheets out of a Drupal site by using a preprocess function in the template.php file.]]></description> <content:encoded><![CDATA[<p>One of the things that irritates me about adding modules in Drupal, is that they often have their own stylesheets associated with them that get automatically added to the site upon module activation.  Not always, but very often you&#8217;ll find that the rules within these supporting stylesheets result in one or more of the following undesirable side-effects:</p><ul><li>possess rules that clash, or are made redundant by rules that you already have in place</li><li>control aspects of the module administration that a user would never see</li><li>cater for features that the module provides that you don&#8217;t need, or haven&#8217;t activated</li><li>offer browser and device support that is not part of the site requirements</li><li>you have themed a modules mark-up, thus rendering its own stylesheet obsolete</li></ul><p>Generally there is no easy way, or no way at all to disable these stylesheets from the admin or module settings.</p><p>If you took a typical Drupal setup with a <a
href="http://drupal.org/project/zen">Zen starter theme</a> and add about 10 of the popular modules, it wouldn&#8217;t be unthinkable for the number of stylesheets to breach the 20 mark! 20 stylesheets!</p><div
id="attachment_802" class="wp-caption alignnone" style="width: 379px"><img
src="http://daipratt.co.uk/wp-content/uploads/2009/12/css.png" alt="Even before you start adding your own stylesheets..." title="Initial CSS" width="369" height="86" class="size-full wp-image-802" /><p
class="wp-caption-text">Even before you start adding your own stylesheets...</p></div><p>I know that the stylesheets can be cached and served as one file, but when you&#8217;re debugging the CSS and adding new sections to a site of any real size, you will inevitably end up playing specificity wars and having to reset rule properties more often than you&#8217;d like.  This all leads to bloated CSS that is a pain to debug and maintain.</p><p>To overcome this in the past and regain some sort of control over what CSS ends up on the site, I have adopted a code butchers approach and taken to ripping out the line seen below in the page.tpl.php file, and then just manually adding the stylesheets in the html.</p><pre class="brush: php">print $styles; //bye, bye</pre><p>That&#8217;s a problem solved, but another problem created in that sometimes you do actually want a modules stylesheet to be used. Determining the CSS file location(s) that a module uses can be difficult, especially when there are configuration options within a module that force different sets of stylesheets to be used such as in the popular <a
href="http://drupal.org/project/fivestar">fivestar</a> module.</p><p>I&#8217;m sure there are probably better, cleaner ways to achieve this, but what I do now is cull the Zen starter theme.info of all superfluous stylesheets and then add the <a
href="http://api.drupal.org/api/function/phptemplate_preprocess_page/6">phptemplate_preprocess_page</a> function within the template.php file with code that removes the remaining unwanted stylesheets, like so:</p><pre class="brush: php">function phptemplate_preprocess_page(&amp;$vars){
	//Get the loaded stylesheets as an array
	$stylesheets = drupal_add_css();
&nbsp;
	//Remove the default style sheets
	unset($stylesheets['all']['module'] ['modules/aggregator/aggregator.css']);
	unset($stylesheets['all']['module'] ['modules/node/node.css']);
	unset($stylesheets['all']['module'] ['modules/system/defaults.css']);
	unset($stylesheets['all']['module'] ['modules/system/system.css']);
	unset($stylesheets['all']['module'] ['modules/system/system-menus.css']);
	unset($stylesheets['all']['module'] ['modules/taxonomy/taxonomy.css']);
	unset($stylesheets['all']['module'] ['modules/user/user.css']);
&nbsp;
	//Remove some of the popular module stylesheets - add / remove your own here
	unset($stylesheets['all']['module'] ['sites/all/modules/cck/modules/fieldgroup/fieldgroup.css']);
	unset($stylesheets['all']['module'] ['sites/all/modules/cck/theme/content-module.css']);
	unset($stylesheets['all']['module'] ['sites/all/modules/date/date.css']);
	unset($stylesheets['all']['module'] ['sites/all/modules/filefield/filefield.css']);
	unset($stylesheets['all']['module'] ['sites/all/modules/link/link.css']);
&nbsp;
	//Set the styles
	$vars['styles'] = drupal_get_css($stylesheets);
}</pre><p>This function will do the trick for all of the Drupal system stylesheets and a few of the popular modules.  There is a big drawback to all this stylesheet optimisation of course, which is you&#8217;ll notice that your admin area falls apart and becomes completely unusable due to the fact that the supporting stylesheets aren&#8217;t present.  To overcome this is simple in most cases &#8211; you just need to set your administration theme (Administer -> Site Configuration -> Administration theme) to use a different theme and all module stylesheets will be pulled in &#8211; I usually go for the comforting shades of Garland.</p> ]]></content:encoded> <wfw:commentRss>http://daipratt.co.uk/removing-unwanted-stylesheets-from-drupal/feed/</wfw:commentRss> <slash:comments>3</slash:comments> </item> <item><title>How to get the path of a node from the node ID in Drupal</title><link>http://daipratt.co.uk/how-to-get-the-path-of-a-node-from-the-node-id-in-drupal/</link> <comments>http://daipratt.co.uk/how-to-get-the-path-of-a-node-from-the-node-id-in-drupal/#comments</comments> <pubDate>Thu, 03 Dec 2009 11:29:29 +0000</pubDate> <dc:creator>David Pratt</dc:creator> <category><![CDATA[Tech]]></category> <category><![CDATA[drupal]]></category> <category><![CDATA[seo]]></category> <guid
isPermaLink="false">http://daipratt.co.uk/?p=750</guid> <description><![CDATA[If you have a node that you know the node ID for, but you don't know what the full clean url is (or how to generate it), then you need to know about the rupal_lookup_path() function.]]></description> <content:encoded><![CDATA[<p>I&#8217;ve just stumbled across a very useful internal function in Drupal that I thought I&#8217;d share here.</p><p>If you have a node that you know the node ID for, but you don&#8217;t know what the full clean url is (or how to generate it), then there is a handy function you should know about called <a
href="http://api.drupal.org/api/function/drupal_lookup_path/6">drupal_lookup_path()</a> that will get the full clean (pathauto) path for you. For example, a typical Drupal relative path such as:</p><pre class="brush: plain">
/node/9999
</pre><p>Is easy to generate if you know the node ID, but if you pass it through the drupal_lookup_path function like so:</p><pre class="brush: php">
drupal_lookup_path('alias',"node/".$node->nid)
</pre><p>Then you will get the full clean path of the node based on the rules set out in the pathauto module. For example:</p><pre class="brush: plain">
/band/future-of-the-left
</pre><p>This is very important for <abbr
title="Search Engine Optimisation">SEO</abbr>.  If the exact same content/page can exist on two different urls on your site, then you will run into problems with duplicate content and will have to start using things like the <a
href="http://www.mattcutts.com/blog/canonical-link-tag/" title="Matt Cutts: Learn about the Canonical Link Element in 5 minutes">canonical link element</a> to fix a problem that shouldn&#8217;t have been created in the first place.</p> ]]></content:encoded> <wfw:commentRss>http://daipratt.co.uk/how-to-get-the-path-of-a-node-from-the-node-id-in-drupal/feed/</wfw:commentRss> <slash:comments>9</slash:comments> </item> <item><title>Meta keywords and descriptions in Drupal</title><link>http://daipratt.co.uk/meta-keywords-and-descriptions-in-drupal/</link> <comments>http://daipratt.co.uk/meta-keywords-and-descriptions-in-drupal/#comments</comments> <pubDate>Fri, 21 Aug 2009 07:50:24 +0000</pubDate> <dc:creator>David Pratt</dc:creator> <category><![CDATA[Tech]]></category> <category><![CDATA[drupal]]></category> <category><![CDATA[seo]]></category> <guid
isPermaLink="false">http://daipratt.co.uk/?p=416</guid> <description><![CDATA[A function that utilises the internal Drupal functions drupal_set_title() and drupal_set_html_head() to set the meta tags of a webpage.]]></description> <content:encoded><![CDATA[<p>Meta tags, once a powerful force in determining the search engine ranking of a page, have seen their influence wane over time to the point that they don&#8217;t really count that much at all anymore.  However, they are still worth investing some time in so that a when a page is returned in organic search results, the best possible description of the page is presented to the user to encourage them to click through.  Best get your online marketers to write them for you then&#8230;</p><p>In Drupal, the two most popular ways of controlling your meta keywords and descriptions are using the modules:</p><ul><li><a
href="http://drupal.org/project/nodewords">Node Words</a></li><li><a
href="http://drupal.org/project/int_meta">Integrated Meta Tags</a></li></ul><p>Both are very good and offer a range of options that allow meta keywords and descriptions to be automatically set for a node of a given content type, but occasionally you&#8217;ll find that they just don&#8217;t give you the level of control that you require.</p><p>Step forward the Drupal &#8220;<a
href="http://api.drupal.org/api/function/drupal_set_html_head/6">drupal_set_html_head</a>&#8221; function &#8211; this allows you to add any code you like to the document &lt;head&gt;.</p><p>This is the function that I use to set the meta and title tags from within a page/template in Drupal:</p><pre class="brush: php;">function setTitleAndMeta($title = null, $metaK = null, $metaD = null){
	drupal_set_title($title);   //Set page title
	$metaDescription = "&lt;meta name=\"description\" content=\"$metaD\" /&gt;";
	$metaKeywords = "&lt;meta name=\"keywords\" content=\"$metaK\" /&gt;";
	$meta = $metaKeywords . $metaDescription;
	drupal_set_html_head($meta);
}</pre><p>Pretty simple huh? A typical call might look like:</p><pre class="brush: php; light: true;">setTitleAndMeta("motorbikes | daipratt.co.uk", "motorbikes, gsxr, donors", "I really hope that motorcyclist has signed his organ donor card. If he keeps riding like that and he won't need them anymore.");</pre>]]></content:encoded> <wfw:commentRss>http://daipratt.co.uk/meta-keywords-and-descriptions-in-drupal/feed/</wfw:commentRss> <slash:comments>1</slash:comments> </item> <item><title>Drupal &#8211; Importing into CCK fields with checkboxes</title><link>http://daipratt.co.uk/drupal-importing-into-cck-fields-with-checkboxes/</link> <comments>http://daipratt.co.uk/drupal-importing-into-cck-fields-with-checkboxes/#comments</comments> <pubDate>Sat, 08 Aug 2009 18:33:57 +0000</pubDate> <dc:creator>David Pratt</dc:creator> <category><![CDATA[Tech]]></category> <category><![CDATA[drupal]]></category> <guid
isPermaLink="false">http://daipratt.co.uk/?p=409</guid> <description><![CDATA[If you are using the node import module, then you will need to apply a patch if you want to import CCK fields with checkboxes.]]></description> <content:encoded><![CDATA[<p>I recently had a bit of a problem importing records into Drupal using the &#8220;<a
href="http://drupal.org/project/node_import">Node Import</a>&#8221; module.  The problem was trying to import data into a field that had a series of checkbox options that allowed more than one of which to be selected.</p><p>The pipe-delimited CSV file that I was using looked something like:</p><pre class="brush: plain; light: true;">"string"|"string"|"checkbox integer 1,checkbox integer 2, checkbox integer 3"|"string"</pre><p>e.g.<pre class="brush: plain; light: true;">"dave"|"test"|"2,8,10"|"test"</pre><p>But for some inexplicable reason the data just wouldn&#8217;t import.  After many failed attempts and a fair bit of Googling, I stumbled across a <a
href="http://drupal.org/node/384550">solution</a> in the Drupal forums.  What I had to do was patch the module with the file: <a
rel="nofollow" href="http://cvs.drupal.org/viewvc.py/drupal/contributions/modules/node_import/supported/cck/optionwidgets.inc?revision=1.1.2.1&amp;pathrev=DRUPAL-6--1">optionswidgets.inc from CVS</a> and drop it into the node_import module directory<pre class="brush: plain; light: true;">sites/all/modules/node_import/supported/cck</pre><p> And the import continues&#8230;</p> ]]></content:encoded> <wfw:commentRss>http://daipratt.co.uk/drupal-importing-into-cck-fields-with-checkboxes/feed/</wfw:commentRss> <slash:comments>1</slash:comments> </item> <item><title>How to convert the Drupal node &#8220;created&#8221; date to something readable</title><link>http://daipratt.co.uk/how-to-convert-the-drupal-node-created-date-to-something-readable/</link> <comments>http://daipratt.co.uk/how-to-convert-the-drupal-node-created-date-to-something-readable/#comments</comments> <pubDate>Sat, 08 Aug 2009 17:57:24 +0000</pubDate> <dc:creator>David Pratt</dc:creator> <category><![CDATA[Tech]]></category> <category><![CDATA[date]]></category> <category><![CDATA[drupal]]></category> <guid
isPermaLink="false">http://daipratt.co.uk/?p=419</guid> <description><![CDATA[A code snippet that allows you to display a user readable version of a Drupal date field. You'll know that only robots can understand the Drupal date value...]]></description> <content:encoded><![CDATA[<p>Should you want to display a user readable version of a Drupal 6 date field, the following code snippet might be of use to you:</p><pre class="brush: php; light: true;">&lt;?php echo date("D, j M Y \a\\t G:i", $created_date) ?&gt;</pre><p>For example, if <em>created_date</em> were to equal &#8220;1249641973&#8243;, it would get rendered as &#8220;Fri, 7 Aug 2009 at 11:46&#8243;.  Nice.</p> ]]></content:encoded> <wfw:commentRss>http://daipratt.co.uk/how-to-convert-the-drupal-node-created-date-to-something-readable/feed/</wfw:commentRss> <slash:comments>4</slash:comments> </item> <item><title>Drupal &#8211; Delete all content nodes of a given type</title><link>http://daipratt.co.uk/drupal-delete-all-content-nodes-of-a-given-type/</link> <comments>http://daipratt.co.uk/drupal-delete-all-content-nodes-of-a-given-type/#comments</comments> <pubDate>Tue, 28 Jul 2009 10:47:10 +0000</pubDate> <dc:creator>David Pratt</dc:creator> <category><![CDATA[Tech]]></category> <category><![CDATA[drupal]]></category> <guid
isPermaLink="false">http://daipratt.co.uk/?p=407</guid> <description><![CDATA[A SQL code snippet that allows you to delete all content nodes of a given content type.]]></description> <content:encoded><![CDATA[<p>If you have thousands of nodes in your Drupal 6 CMS, there is no easy way from within the admin area to delete large numbers of nodes of a given type.  If you rely on the GUI you will end up having to do dozens of &#8220;select all, delete&#8221; iterations to get through it all.</p><p>This sneaky bit of code will delete all records of a particular type (just replace the #### appropriately):</p><pre class="brush: php;">
$query = db_query("SELECT n.nid FROM {node} n WHERE n.type = '####'");
while ($n = db_fetch_object($query)) {
	node_delete($n-&gt;nid);
}
</pre><p>Careful!</p><p>UPDATE:<br
/> There is a far better way of doing this: if you activate the <a
href="http://drupal.org/project/devel">Devel module</a>, and then use the following line of code:</p><pre class="brush: php;">
//Delete all data of content type "event":
devel_generate_content_kill(array('node_types' => array('event')));
</pre>]]></content:encoded> <wfw:commentRss>http://daipratt.co.uk/drupal-delete-all-content-nodes-of-a-given-type/feed/</wfw:commentRss> <slash:comments>4</slash:comments> </item> </channel> </rss>
