Wednesday, 22 December 2010

Drupal: Collapsible blog archive (similar to Wordpress / Blogger) using Views

I was really surprised that after a lot of digging, I could not find any pre-built solution to this seemingly popular problem. Surely all big CMSs should have this functionality. It turns out it's not that hard to build something similar to the Blogger archive block on your own using Views. You can see mine in action at the bottom of the sidebar on this page. It will have the following structure (with collapsible months):
▼ December 2010
   Article 1
   Article 2
   Article 3
► November 2010
► October 2010
1) Create a new View
Give it a name and type=node and create a new block display

2) Fields
Add 2 fields; Node:PostDate (no label, and with custom format "F Y"), Node:Title (no label, and check "link field to it's node")

3) Filters
Add a filter on Node:Type and select the type(s) of nodes you want to include (e.g. Blog). Also add one on Node:Published (and select yes)

4) Sort Criteria
Add one on Node:PostDate and select descending

5) Basic Settings
Click style and select "HTML List", then click settings and group by post date. Now click CSS class and add your own custom class name which we will use later (I used jack-archive-block)

At this point you should save, and click preview. If you have 3 months of blog posts, then you should see 3 Month-Year titles, each with their own list of article links.

6) Block Settings
Admin name: what we will use to select it on the blocks page (I used "Jack Archive")

7) Tweaks
Now go back into the Node:PostDate field and click "hide from display" as we dont want it for every node, only for every group. Also check "re-write output" and enter the following:

 [created]

This will prefix each of the section titles (dates) with a little collapse icon, which we will manipulate later with jQuery. That should be it for coding up your View. So save, and go to the blocks admin page and whack it in your sidebar.

8) Style
Next, we style it. Here's the CSS I used:

div.jack-archive-block h3 {
 cursor: pointer;
 margin: 0;
 font-size: 1em;
 font-weight: normal;
 padding: 6px 0;
}
div.jack-archive-block ul {
 padding: 0 0 0 10px;
 list-style: none;
}
div.jack-archive-block ul li {
 background: none;
 line-height: 130%;
 padding: 3px 0 5px;
}

The first block deals with the dates; it says if you mouse over, it should look like you're hovering over a link. The second and third blocks remove any default list styling you may have, so you dont get any random bullet point graphics.

9) jQuery
Finally, the jQuery that makes the magic happen:

$(document).ready(function()
{ 
 // init: collapse all groups except for the first one
 $(".jack-archive-block ul").each(function(i)
 {
  if (i==0) $(this).siblings("h3").children(".collapse-icon").text("▼");
  else $(this).hide();
 });
 
 // click event: toggle visibility of group clicked (and update icon)
 $(".jack-archive-block h3").click(function()
 {
  var icon = $(this).children(".collapse-icon");
  $(this).siblings("ul").slideToggle(function()
  {
   (icon.text()=="▼") ? icon.text("►") : icon.text("▼");
  });
 });
});

That should be it. You should be able to click the dates, and have the relevant articles appear or disappear as desired, and have the nice little icon change accordingly. The next step would be another tier to the hierarchy, so you can collapse by year, and then by month... but I haven't got that far yet. Suggestions welcome.

REFERENCES
http://drupal.org/node/825052

Friday, 29 October 2010

Drupal 6: Altering the help message for a particular URL

I noticed that on the "All Content" page, the help message is empty, but my theme still displays a big empty bubble, which looks like a bug. After doing some research I realised the help message on this page came from the node_help() function, and was returning just a space on purpose, as a not-null value meant that the little "more help" link would still be displayed.

SOLUTION
Implement the theme_help() hook in your theme's template.php. Note: replace THEME with your theme name.

function THEME_help() {
 $help = menu_get_active_help();
 if (arg(0)."/".arg(1)."/".arg(2)=="admin/content/node" && !arg(3))
 {
  $help = "<p>My help message.<p>".$help;
 }
 
 if ($help) return "<div class='help'>".$help."</div>";
 else return null;
}

This will work for the URL admin/content/node, but can easily be altered to work for any URL.

REFERENCES
http://stackoverflow.com/questions/1296106/drupal-6-hook-for-altering-help-field-in-a-form

Thursday, 28 October 2010

Opening Drupal PHP files in Eclipse

By default, some Drupal files will not open in the proper editor (they will just be treated as plain text). Assuming you have PDT installed for PHP development, you can specify which filetypes contain PHP code and hence should be opened in the PHP editor.

Look in Windows > Preferences > General > Content Types > Text > PHP Content Type, and add each of the following associations:
*.engine
*.theme
*.install
*.inc
*.module
*.profile
*.test

PROBLEM
If when you then try opening one of these files, you get an error along the lines of:
Unable to create editor ID org.eclipse.php.editor: org.eclipse.core.internal.filebuffers.SynchronizableDocument cannot be cast to org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocument

SOLUTION
Restart eclipse.


References: http://drupal.org/node/75242

Saturday, 23 October 2010

Disable Alt+Space from activating the window menu in Ubuntu 10.10 Maverick

I wanted to change my Gnome-Do hotkey to Alt+Space, but it didn't work - when I pressed the key combination, it just activated the window menu. In order to assign this key combination to something else you must first disable it's current use. To do this, go into the main menu, then System > Preferences > Keyboard Shortcuts, and find "Activate Window Menu", double click it to assign it a new key combination, and simply press Backspace to disable it.

Monday, 4 October 2010

Apache Ant error: restrict doesn't support the nested "name" element

System: Ant 1.7.1 and Sun Java 1.6 on Ubuntu Lucid 10.04

Code snippet:
<target name="jar">
<jar basedir="${bin}" destfile="${project.name}.jar">
<restrict>
<name name="**/*" />
<archives>
<zips>
<fileset dir="/opt/project_jars">
<include name="file.jar" /> 
</fileset> 
</zips> 
</archives> 
</restrict> 
</jar> 
</target>

From googling the error, I found this thread: http://markmail.org/message/y2ly5gykzbpab7p7. The suggested solution of adding namespace information got rid of the original error, but introduced a new one:
restrict doesn't support the nested "archives" element

Actual solution: upgrade Ant to 1.8
sudo apt-get install ant1.8 

Thursday, 5 August 2010

Installing Songbird 1.7.3 on Ubuntu 10.04 Lucid

Download the "Songbird 1.7.3 Generic Linux Tarball" for your architecture from the Linux section of the Contributed Builds page on the Songbird wiki. Extract this to a good permanent location (this is the install directory, which contains all the files required to run Songbird), I chose /home/jack/programs/songbird.

I read over the instructions on the Building Songbird page. This was just to make sure I had the right dependencies installed (the rest of the instructions are for compiling from source, which we don't need to do). It also showed me how to completely uninstall any previous versions.

Now I tried running songbird for the first time (running the songbird script in your songbird directory), and it worked, but was giving loads of GStreamer warnings e.g.
Failed to load plugin /usr/lib/gstreamer-0.10/libgstdvdspu.so undefined symbol: gst_video_event_parse_still_frame
This is caused by a clash between Songbird's included libraries and those installed on your computer. The solution is to tell Songbird to only use it's own libraries. This is done by exporting an environment variable before running Songbird each time, for which I have created a little script called songbird-gst-fix, and put in my home/USER/bin directory:
#!/bin/sh
export SB_GST_NO_SYSTEM=1
/home/jack/programs/songbird/songbird
You can now run songbird with the command songbird-gst-fix. I still get a few GDK icon warnings e.g.
gdk_window_set_icon_list: icons too large
But these don't seem to do any harm. Also if you occasionally get an error like this:
Could not call boundObserver.observe(). Key = metadata.artist
It is caused by the "New Releases" add-on, but it doesn't seem to cause any problems. The only way I cant find to get rid of it is to disable the add-on.


REFERENCES: http://ubuntuforums.org/showthread.php?t=1086378

Wednesday, 28 July 2010

Black screen flicker with nVidia v195 drivers on Ubuntu 10.04 Lucid

GPU: nVidia Quadro FX 570
Driver: nVidia version 195.36.24 from the Ubuntu repository

On recent upgrade to Ubuntu 10.04 Lucid Lynx I started getting a really annoying black flicker/flash/blink covering my screens for a fraction of a second at seemingly random intervals (sometimes every 10 seconds, sometimes every 10 minutes). This only happened when I was using dual monitors in TwinView mode. It didn't matter if compiz was enabled.

I originally had the nvidia-current package installed (which at the time of writing was v195.36.24), so I tried a couple of other versions, including v173.14.22 from the Ubuntu repo, and v256.35 - the latest from the nVidia site, both of which had other issues. I also tried reverting to the open source drivers, as detailed here, but it turned out they did not support 3D graphics.

After reading a lot of forum posts about this issue I realised that the problem was with an nVidia tool called PowerMizer. By default is in adaptive mode, which means it jumps between performance levels, juggling your GPU clocking settings on demand. The flicker I was getting was happening every time it jumped between performance level 0 and 1 (which I believe relates to 2D and 3D graphics).

SOLUTION
I fixed the problem by forcing PowerMizer to stay in level 1, which with the v195 drivers you can do graphically by running nvidia-settings, selecting PowerMizer on the left, and then setting the mode to "Prefer Maximum Performance". Unfortunately this setting does not persist through restarts, which is not a problem for me, but I've read that you can fix this by putting something in your xorg.conf (see this post).

Sunday, 18 July 2010

Playing GSM audio files on Ubuntu 9.10 Karmic

Note: you will need to have a package called sox installed for this to work

1) Create script file in your ~/bin directory (assuming that is on your PATH) called play_gsm_with_sox containing the following:
#!/bin/sh
gnome-terminal --command="play $*"

2) Make it executable (and test it by executing the command play_gsm_with_sox file.gsm)

3) R click your gsm file > properties > open with > command > play_gsm_with_sox

Then you should be able to double click gsm files and get a little terminal window playing them, which you can close to stop playback

Friday, 4 June 2010

Installing PHP 5.3 on CentOS 5

Using the 3rd party repository by Remi Collet, which seems to be the most popular 3rd party web repo.

1) Install the repo by following the instructions on his website: http://blog.famillecollet.com/pages/Config (this site is in French, which can be automatically translated if you use Google Chrome!). Note that it depends on the EPEL repo, but the instructions take care of that as well. For me, this meant executing the following commands:
wget http://download.fedora.redhat.com/pub/epel/5/i386/epel-release-5-3.noarch.rpm
wget http://rpms.famillecollet.com/enterprise/remi-release-5.rpm
sudo rpm-Uvh remi-release-5 *. rpm EPEL-release-5 *. rpm

2) Enable the new repository by setting enabled=1 in this file: /etc/yum.repos.d/remi.repo

3) Upgrade your PHP packages. Optionally you can add the suffix mysql-* to upgrade your mysql packages as well. Note: this will automagically fetch the GPG key for Remi's repo.
sudo yum update php php-*

4) Restart Apache
sudo /etc/init.d/httpd restart

Note: after this I got an error on all pages: "Warning: strtotime(): It is not safe to rely on the system's timezone settings". The solution was to add my timezone to /etc/php.ini i.e. add the line
date.timezone = "Europe/London"
You can find a list of supported timezones here: http://www.php.net/manual/en/timezones.php


References
http://gofedora.com/how-to-install-php-on-centos-red-hat-rhel/

Wednesday, 2 June 2010

Installing GIMP 2.7 on Ubuntu 9.10 Karmic

I wanted to try the latest version of GIMP, to see the long sought after single-window mode in action.

Method 1 - PPA

The first, and by far the easiest method is by using the PPA on this page: https://launchpad.net/~matthaeus123/+archive/mrw-gimp-svn

You simply add the repo with this command: 
sudo add-apt-repository ppa:matthaeus123/mrw-gimp-svn
and then add the GPG key:
sudo apt-key adv --recv-keys --keyserver keyserver.ubuntu.com 405A15CB

PROBLEM HTTP fetch error 7: couldn't connect to host
SOLUTION Open up the outbound TCP port 11371

Then you can install gimp using apt-get (or simply run an update if you already had it installed).


Method 2 - From source

The second method is to install it from source, and while this is much more of a challenge, it doesn't rely on any third party PPAs...

PREPERATION
3 commands to modify (change /home/jack to your home dir), and execute:
mkdir /home/jack/programs/gimp-2.7
export PKG_CONFIG_PATH=/home/jack/programs/gimp-2.7/lib/pkgconfig/:$PKG_CONFIG_PATH
export LD_LIBRARY_PATH=/home/jack/programs/gimp-2.7/lib:$LD_LIBRARY_PATH

INSTRUCTIONS
Download gimp-2.7.0.tar.bz2 from http://www.gimp.org/, and extract it and run the installation commands:
./configure --prefix=/home/jack/programs/gimp-2.7
make
sudo make install
But of course I encountered loads of problems during the configuration stage:

PROBLEM configure: error: Your intltool is too old. You need intltool 0.40.1 or later.
SOLUTION sudo apt-get install intltool

PROBLEM No package 'babl' found
SOLUTION Found http://developer.gimp.org/git.html which has lots of the tools you will probably need including babl and gegl. Eventually found my way to ftp://ftp.gtk.org/pub/babl and downloaded the latest version of babl (for me, this was 0.1/babl-0.1.2.tar.bz2). Extract it, and do the following installation commands:
./automake.sh --prefix=/home/jack/programs/gimp-2.7
make
sudo make install
BUT I encountered more problems along the way:

PROBLEM Got an error message saying I needed ruby
SOLUTION sudo apt-get install ruby1.8-dev

I think at this point babl successfully installed. Back to trying to ./configure gimp, and now we get the following problem:

PROBLEM No package 'gegl' found
SOLUTION Similar to babl, we go to ftp://ftp.gtk.org/pub/gegl and download the latest version, extract it and try to install it with:
./automake.sh --prefix=/home/jack/programs/gimp-2.7
make
sudo make install
But of course we encounter lots of problems:

PROBLEM You must have glib-gettextize installed to compile GEGL
SOLUTION sudo apt-get install libglib2.0-dev

PROBLEM Loads of errors about GDK and GTK, the first of which was:
gegl-paint.c:22:21: error: gtk/gtk.h: No such file or directory
SOLUTION (Note: this auto-installed LOADS of dependencies for me):
sudo aptitude install libgtk2.0-dev
May also need to execute this next command, but not sure (BEWARE: BIG DOWNLOAD!)
sudo apt-get install asciidoc

Then I was back on track for the main GIMP installation, so tried to run the configure script again (remember the --prefix)...

PROBLEM Checks for TIFF libary failed
SOLUTION sudo apt-get install libtiff4-dev

PROBLEM Could not find Python headers
SOLUTION sudo apt-get install python2.6-dev

PROBLEM Could not find PyGTK 2.10.4 or newer
SOLUTION sudo apt-get install python-gtk2-dev

And then I was able to complete the install!!!! You can then run it using /home/jack/programs/gimp-2.7/bin/gimp-2.7