fr.ench.info

Installation Profile with Content

Posted on

Recently, I encountered a project that requires rebuilding a site over and over in order to test recent changes. There were a bunch of scripts that did this automatically. The scripts were bash and PHP scripts. The bash scripts consist of calling drush commands such as drush en, drush si and drush scr. The PHP scripts task were to import content, terms, and probably set some configurations. These PHP scripts are also the ones ran through drush scr. I didn't go through each line of the scripts but I think what they basically do is enable modules, import contents from a data source, copy some...

Migrating Field Collections

Posted on ,

Field collection allows users to group fields. Basically, when you create a 'field collection' field, you are creating a field_collection_item bundle in which you can then add fields on it. This is nice but unfortunately the migrate module doesn't support this. I got this working though with the patch here. To apply the patch you can do this: cd /path/to/field_collection/ wget http://drupal.org/files/field_collection_migrate-entity_load-1175082-120.patch patch -p1 < field_collection_migrate-entity_load-1175082-120.patch There is a sample usage of the destination handler found at the beg...

Image Gallery in Nanoc

Posted on ,

My image gallery for screenies is a custom data source for Nanoc which generates items for each JSON file located in the gallery directory. This makes it easy for me to grab the images rather than creating an item for each image by hand. I created a ruby script that grabs all images from my Dropbox account since it is where all my desktop screenshots are stored. The script then generates a JSON file with each image in an entry { 'image': '...', 'thumbnail': '...' }. This is my first time messing around with the Dropbox API too. The API is well documented so I just had to follow the tutoria...

Migrating to Nanoc

Posted on ,

Recently, I've migrated my blog to Nanoc. I think there's too much hacking involved if you want to extend Jekyll. Or perhaps I didn't just read enough documentation about Jekyll. But anyway, I've already made the switch. What's done is done. The first thing I did was to convert my markdown files. This wasn't really a problem since both Jekyll and Nanoc almost have the same format for the markdown files. Only difference I think would be the kind and created_at attributes so to be able to use the Blogging helper for Nanoc. Since I am trying to learn Ruby, I decided to create a script to mak...

Breakdown checkboxes in FAPI and '#disabled' Property

Posted on

If you wish to set some FAPI properties of the checkboxes generated with #type => 'checkboxes' individually, you'll need to breakdown the checkboxes first. There are two ways to do this that I am aware of. One is to add a #process callback to the form element, and another is to set each #options as a separate element e.g. $form['checkboxes'][{#option-key}]. For adding the #process callback, you can do it like this: <?php $form['checkboxes'] = array( '#type' => 'checkboxes', '#options' => $options, '#process' => array('some_callback'), ... ) You'll then need to break...

Create Custom Form Instead Of Altering Node Form

Posted on

This a post to remind me to not alter the node form as much as possible, but instead create a custom form and save the node upon submission. Some issues I had trouble with: Field attach form isn't that flexible for altering. The node form becomes ugly for administrators that want to just create/edit a node due to form alterations. The fields I have in the node type I'm trying to create are: Taxonomy term with a 'select' widget. Taxonomy term with the 'checkboxes' widget. 2 textfields for 'First name' and 'Last name'. Email field. Checkbox for agreement. Requirements: Make the first ta...

Add Filters for Apache SOLR

Posted on ,

To add simple filters on your search query with apachesolr can be easily done through hook_apachesolr_query_alter. You'll find the documentation on path/to/apachesolr/apachesolr.api.php. An example would be: <?php function module_apachesolr_query_alter($query) { $query->addFilter('bundle', 'page'); // To filter by either page or article content type $query->addFilter('bundle', 'page OR article'); } For adding subqueries (which is a bit different), you may do this: <?php function module_apachesolr_query_alter($query) { $sometid = 1; $filter = new SolrFilterSubQuery('A...

Print Views Output in Drupal

Posted on

There are times that I would like to print the output of a view without it being rendered from a template i.e. it would go through page.tpl.php. I find this useful when say I'd like to do an Ajax call and I'd like it to return just the output of the view itself so I could print it inside a div container for example. This is quite simple as I could use drupal_json as my reference. I first created a new menu like so: <?php function MODULE_menu() { $items = array(); $items['example/js'] = array( 'page callback' => 'MODULE_menu_callback', 'type' => MENU_CALLBACK, 'acc...

Migrating to Jekyll Part 2

Posted on ,

After setting up the basic install of my Jekyll site, I then migrated the posts of my current Drupal site over to Jekyll. Migrating Drupal Posts to Jekyll Migration was also easy as I only needed to follow these steps. I first installed the extensions sequel and mysqlplus. $ sudo gem install sequel mysqlplus After this, I downloaded a backup copy of the database of my current blog using Backup and Migrate and imported it to a newly created database. As far as I know, you would only actually need the tables node and node_revisions. My Drupal site has a prefix drpl_ for its tables so I nee...

Migrating to Jekyll Part 1

Posted on ,

Recently, I read about a few Drupal blogs migrating over to Jekyll — acko.net and Development Seed. The concept seems nice as you will be writing the content in files instead of a database so I thought I would give it a try. With this, I am able to write blog posts using Vim. Also, on my current blog, I am using Markdown as my input filter for writing blog posts. Installation & Configuration Installing Jekyll was easy as I had only to follow these instructions. Did the following steps to install it: $ sudo apt-get install rubygems $ sudo gem install jekyll $ sudo apt-get install pytho...

jQuery Hover Tricks

Posted on ,

I had an issue in which I need to keep an element shown when the mouse hovers on another element. The markup looks like this: <a href="#" id="hover-here">Hover here</a> <div class="dialog"> <p>Some text</p> <p>Some text</p> <p>Some text</p> <p>Some text</p> </div> The goal is to have .dialog shown when mouse hovers over to #hover-here and the former is kept shown until it either leaves #hover-here or .dialog. Here's the script that I was able to come up with. Not that clean I think but works just fine t...

Using hook_views_query_alter

Posted on ,

There are times that you might want to alter the query that the Views module generates. My problem was to include an attribute filter for products from the Ubercart module. uc_views might be able to do the trick although filters for product attributes were only for products that have already been order. There is also a patch available although I didn't make use of it as I only needed something simple. I decided to use hookviewsquery_alter. It says to put your function MODULENAME_views_query_alter in MODULENAME.views.inc although it seemed to have just been called in my MODULENAME.module. I...

Quick Tip for Numeric and Textual File Permissions

Posted on

There are times that I would want to list the File permissions in the current working directory. To do this, I would use the ls -l command which lists the files and shows the Textual representation of file permissions. But for some reason I would want the Numeric representation such as 777, 755, etc. In order to achieve this, you can simply do stat -c "%a %n" *. If you often use this you may want to add in your .bashrc this line: alias statls='stat -c "%a %n"' Then reload your .bashrc by doing . ~/.bashrc. You can use the alias like so statls * or statls dir/*. For changing permissions, y...

Setting Up Pianobar with lastfmsubmitd

Posted on ,

Pandora is a really neat, free internet radio service. I am using a console client for Pandora which is Pianobar. It's lacking one feature that I wanted though in which it would scrobble the music it plays over to Last.fm. Previously it did support scrobbling to Last.fm but has been moved. The author said you can make use an external scrobbler. For my external scrobbler I've used lastfmsubmitd. To set it up, you'll first need to have a script that would handle the events for Pianobar. You can use the eventcmd.sh script under contrib from Pianobar's source. For lastfmsubmitd, you can simply...

Upcoming Events Calendar View in Drupal

Posted on

Here's what I have when I worked on an Event feature for a site. I first tried the Event module although it wasn't flexible enough to accomplish some of the things I needed. The modules I finally used (with their specific versions) were: Calendar 6.x-2.2 CCK 6.x-2.8 Date 6.x-2.6 Views 6.x-2.11 For my Event content type, I just have the usual fields for a node with a datestamp as a CCK date field. And for my Upcoming Events Calendar view, I simply cloned the Calendar view that came with the Calendar module and removed some of the displays. It did have an Upcoming display although wasn't a ...

Simple FizzBuzz in Haskell

Posted on ,

Yesterday I started reading about Haskell through Learn You a Haskell. I started playing around with Haskell when I changed my window manager to Xmonad. Currently reading on Syntax in Functions: Guards, guards!. I was able to come up with this FizzBuzz function that I've read in Coding Horror. fizzBuzz :: (Integral a) => a -> String fizzBuzz a | a `mod` 5 == 0 && a `mod` 3 == 0 = "FizzBuzz" | a `mod` 3 == 0 = "Fizz" | a `mod` 5 == 0 = "Buzz" | otherwise = show a Somehow cheated because I based it on this though I don't quite get that one yet. :D So for now I...

Add a "Save and continue editing" button in a Node Edit Form

Posted on

There are times that I would somehow want to continue editing a node rather than view it after saving. Here's a little snippet that would achieve what I needed. <?php function module_form_alter(&$form, &$form_state, $form_id) { if (isset($form['type']) && isset($form['#node']) && $form['type']['#value'] .'_node_form' == $form_id) { $form['buttons']['continue_edit'] = array( '#type' => 'submit', '#value' => t('Save and continue editing'), '#submit' => array('node_form_submit', '_module_continue_edit'), ); } } function _module...

Using PhotoRec to Recover Deleted Files in Arch Linux

Posted on

Recently I accidentally deleted my xmonad.hs file which I've worked on for so long. I had no back up or a Trash folder whatsoever. I searched for a file recovery software that would bring back my config file. I took a look at Arch Linux's File Recovery wiki to try out the ones they've listed. The first software I tested was Extundelete unfortunately it seems to require me to unmount the device although the file resided on the same partition where my OS is so I didn't seem to work out for me. I also tried searching for a Windows program to recover files from an ext4 partition but unfortuna...

Bad Theming Job

Posted on

I read last time about Drupal Theming Nightmares written by a Drupalist. It is somehow a series of the blogger's experience upon continuing the theming job started by another themer. If you know about theming in Drupal then your reaction would probably be similar to the comments. I then recently checked one of the themes I've created and also found out that it had a few (:P) mistakes too considering that I wasn't that familiar to theming when we've started this. This one is a subtheme from Zen (at least the theme came from a decent base theme :P). A screenshot of the file structure follows...

Upon Redmine Installation

Posted on

Recently I stumbled upon an entry from nixCraft about Web-Based Project Management Software. The one that got my attention at first was Trac as it was the tool we are using in our projects and that it was written in Python (a programming language I was very much interested to learn but didn't have the time; and was too complicated for me :P). I also wanted to integrate Git with Trac. I then found an entry from Stack Overflow in which the "best" answer was to use Redmine. It's a bit new to me so I decided to give it a try. Installation It was a good thing that there was a wiki about settin...

Starting with Git

Posted on

Recently I started using Git) again so I could play with Kohana v3 (it has a tutorial about Working with Git). Here are some really neat resources which I'm pretty sure are already popular (just wanted to repost them like what everybody does): External Links of Git in Wikipedia#External_links) Github Help #git in Freenode The first two pages provide even more useful links. If you use SVN then you might find this link useful. I am only familiar with two web hosting service that uses Git namely: Codaset (which just recently launched); and Github (which I believe is the popular one) I...

BlueTrip CSS Framework

Posted on ,

I was recently searching for a CSS Framework. Amongst the ones I found that I believe are popular were Blueprint, 960gs, and YUI. I also searched from the Kohana forums since I was planning to use the CSS framework on trying out Kohana and found BlueTrip. Looked really nice and was quite easy to use (check out its documentation :D) although I haven't much explored it. BlueTrip's definition taken directly from its site: A full featured and beautiful CSS framework which originally combined the best of Blueprint, Tripoli (hence the name), Hartija, 960.gs, and Elements, but has now found a l...

Pathauto Batch Custom Module

Posted on

I recently just started studying about Drupal's Batch API. I've decided to duplicate Pathauto Bulk Update but using the Batch API in order to bypass the limit you set for Pathauto Bulk Update. Mostly are based on the samples from the API reference and the Handbook. For my .info file, I simply added the dependency for pathauto like so, dependencies[] = "pathauto". For the .module file specifically the Batch API section, I have this: <?php function pathauto_batch_form_submit($form, &$form_state) { $batch = array( 'title' => t('Generating Aliases'), 'finished' => 'path...

Problems with hook_download_authorize in Ubercart

Posted on ,

My task involved to limit the number of downloads to 1 but with an exemption for those with a specific role or a so-called "credit". I've used hookdownloadauthorize() to try this one out. The first problem I encountered was that if you do a return FALSE as what the documentation mentioned, it would return the error "A hook denied your access to this file. Please contact the site administrator if this message has been received in error." based on this section of the code: <?php //Check any if any hook_download_authorize calls deny the download foreach (module_implements('download_authori...

Changing Username in Linux

Posted on ,

I tried changing my username on my Arch Linux install but somewhat caused a problem. I did the usual usermod -l newlogin oldlogin and renamed my HOME directory. I followed the instructions from this page. I tried logging in with the new username but for some reason, it wasn't logging me in. I was not able to spot any "useful information" in the logs - auth.log and user.log. Someone advised me to login from the root shell by calling the command login. This then gave me the error message. I obviously didn't change my HOME directory correctly as it was pointing to /home/old_login and goes t...

URL Shortening Custom Module

Posted on

I first tried using the modules Short URL and Shorten URLs but I believe the module Short URL is currently on its early stages. I've decided to create a custom module for our project but basing it on the modules above. Unfortunately, the module isn't an API like Short URL. It was a combination of both in which it provides a UI for shortening URLs and records them. I started with how the module redirects the URLs when it encounters one from the record. The Short URL implemented the hookinit() to do this. This is somewhat what I was able to come up with based on the _Short URL__ module: <...

Check Available Variables in Theming

Posted on

First off, you can probably check out this entry which provides four functions to look at upon developing. You would need the Devel module for this. I personally use dsm though I believe it simply makes use of the dpm function from devel. I am not certain if this is the proper way of checking the available variables when theming. You could first take a look at the template files e.g. page.tpl.php or node.tpl.php to check what variables are available for you. I also sometimes add the code below to check for the available variables in a template file. <?php dsm(get_defined_vars()); ?>...

#autocomplete_path of Path Alias

Posted on

I was trying to implement the #autocomplete_path to be used to autocomplete URL aliases. I believe this is somewhat a short introduction to doing autocomplete in your textfields when using the Form API. <?php function example_autocomplete() { $items = array(); $i = 2; while(arg($i)) { $items[] = arg($i); $i++; } $string = implode('/', $items); $matches = array(); if ($string) { $result = db_query_range("SELECT dst FROM {url_alias} WHERE LOWER(dst) LIKE LOWER ('%s%%')", $string, 0, 10); while ($destination = db_fetch_object($result)) { $matches[$dest...

Remove Class from Body Classes

Posted on

Removing a class from the variable $body_classes is very simple. All you need to do is make some changes on the variable in the SUBTHEME_preprocess_page function. I have done this with a Zen subtheme: <?php function SUBTHEME_preprocess_page(&$vars, $hook) { if {$node = menu_get_object()) { $vars['node'] = $node; } /* * Make some changes once the node type is 'full'. 'full' is the content * type I am using for pages with no sidebars. */ if ($node->type == 'full') { $body_classes = explode(' ', $vars['body_classes']); $new_body_classes = array(); ...

Drupal Starter Themes

Posted on

Here's a list of starter themes that I have observed popular. The first three would be the ones that I've tried out. The next ones are the ones I am planning to try out. Below the names of each theme are the description taken directly from their project page: Zen For many people, Zen is the ultimate starting theme for Drupal. If you are building your own standards-compliant theme, you will find it much easier to start with Zen than to start with Garland or Bluemarine. This theme has LOTs of documentation in the form of code comments for both the PHP (template.php) and HTML (page.tpl.php,...

<span> Tag in Primary Links in a Genesis Subtheme

Posted on

The codes on this post below would result to a markup like this in a Genesis subtheme: <a href="/" title="Home" class="active"><span>Home</span></a> First, you would need to edit the template.php file of your Genesis subtheme and add the codes below. For the SUBTHEME_primary_links function, you'll need to copy the theme_links function. You'll then need to make some slight modifications on the function. <?php function SUBTHEME_theme(&$existing, $type, $theme, $path) { $hooks = genesis_theme($existing, $type, $theme, $path); $hooks['primary_links'] = array...

Uzbl - Minimalistic Web Browser

Posted on

Uzbl is a very nice browser — quite easy to use, navigation is through keybinds, has modes, and a lot more features. Uzbl can be taken here. A brief description of Uzbl taken directly from Wikipedia: Uzbl is a free and open source minimalistic web browser designed for simplicity and adherence to the Unix philosophy. Development started in early 2009 and is still considered in alpha software by the developers. The core component of uzbl is developed in C but other languages are also used, most notably Python. All parts of the uzbl project is released as free software under the GNU General...

Fixing Initscripts

Posted on ,

I had a problem yesterday with my Archlinux installation. Everything was just going fine until I restarted my computer. Arch was trying to load the daemons and modules but can't seem to do it as there was an error saying "Read-only filesystem". I was thinking to simply remount it after Arch gives me a prompt though it never did. After some few research and inquiries in the #archlinux channel in Freenode, I was able to resolve this. The solution an arch user gave me: Used an Archlinux Live CD (mine was in a USB drive) to mount my Archlinux system that was not booting. Put sleep 60 in /et...

Current Xmonad Setup

Posted on ,

My xmonad.hs: import XMonad import XMonad.Hooks.DynamicLog import XMonad.Hooks.ManageDocks import XMonad.Util.Run(spawnPipe) import XMonad.Util.EZConfig import System.IO import XMonad.Layout.NoBorders import XMonad.Layout.IM import Data.Ratio ((%)) import XMonad.Layout.Grid import XMonad.Prompt import XMonad.Prompt.Shell import XMonad.Actions.GridSelect import XMonad.Layout.SimplestFloat import XMonad.Layout.Reflect import qualified XMonad.StackSet as W import XMonad.Layout.ResizableTile import XMonad.Layout.PerWorkspace import XMonad.Hooks.ManageHelpers myManageHook = composeAll [ (ro...