Web Design & Development Blog
We're putting the finishing touches on two new Drupal 7 modules. These are still "sandbox" modules as of now, but we'll update this blog post when that changes.
If you have ever had a use case that called for a double or triple text field with those text fields grouped together, this module may be for you.
- 1-3 text fields (text fields ONLY!) grouped into a single field.
- Field formatters to display only text box 1 (Title), text box 2 (Details), or text box 3 (Additional)
- Views integration
The problem: the Redirect module can result in the occasional "Oops, looks like this request tried to create an infinite loop. We do not allow such things here. We are a professional website!".
This module removes redirects that cause infinite loops; this only applies to redirects created by the Redirect module, and as such this module has just one dependency: the Redirect module (). The module hooks intro cron. When cron runs, this module checks for any aliases that clash with existing redirects, and then removes them. It logs these actions to the watchdog table.
- Runs when cron runs
- Logs each redirect deletion to watchdog
Note that the Redirect module has a pending patch (see https://drupal.org/node/1796596) that takes care of the infinite loop issue at the moment it gets created, but our module is intended to remove pre-existing infinite loops during a cron run.
Some Drupal sites don't allow regular users to log in at all; they may only be used by administrators. In such cases it may be desirable to lock down access to the login and admin screens. This can be done using htaccess.
In this example let's assume the site is installed at /var/www/yoursite.com/public_html. First you need to create the .htpasswd file. You should not put it in public_html - it needs to be outside your web root. In this example we can put it at /var/www/yoursite/.htpasswd which keeps it in a logical, easy to find place. To create this file do the following:
- htpasswd -c /var/www/yoursite.com/.htpasswd yourdesiredusernamehere
- Next it will ask you to enter a password (hit enter afterwards). Then it asks again.
In your web root folder (where Drupal is installed) open up .htaccess. If you're using the command line, type:
That will show all files, including normally hidden "dot" files.
Go into public_html and edit the file (e.g. "nano .htaccess" or "vi .htaccess") and add the following code to the top or bottom of the file;
Now http://www.yoursite.com/user and http://www.yoursite.com/admin are protecting the Drupal login form from brute force attacks. Doesn't mean it still couldn't happen, but it makes it much less attractive to the brute force attackers. This approach is not a good for sites that need to allow regular users to log in. This is intended only for sites with NO regular users who need to log in to the site. Admin users can still get in. You can set it up so each admin user has his/her own unique htpasswd username/password, or they can all share one. In any case their Drupal logins will differ.
Here's a handy module that takes care of those pesky node/123 style links scattered throughout your site, as well as links to unpublished nodes.
To quote from the project page at drupal.org;
The Internal Links module, Intlinks, is a simple set (currently two) of input filters which modify the output of internal, root-relative links in any text input format for which they are enabled. The title filter allows you to have the node titles of linked content automatically inserted into the link as the HTML "title" attribute, with "node/123" -type href paths converted to URL aliases, too. It is especially useful for streamlining the editorial workflow and improving SEO.
So what does this do for you, intrepid Drupal site owner? Well, it removes any links to unpublished nodes for any viewers that don't have access to those nodes, and changes any node/123 style links to the appropriate aliased paths (/about-us, for example). This way you can link to an unpublished node (on purpose or by accident), and only admins / editors will see the actual link. Everyone else will just see the link's text - without the link. On large sites you're bound to rack up some bad links, and tools such as this module are a great way to clamp down on them.
This module scans your pages, comments and custom blocks for broken internal and external links during the regular Drupal cron run. You can selectively omit certain links in case you know they're OK, or you don't care if thy fail (for example some external links in very old blog posts or news items). It provides a report in the Reports menu which shows which pages contain the offending link. It's a really indispensable module for managing sites with lots of links in nodes and blocks.
We have finally redesigned plethoradesign.com, using Drupal (what else?!). It's mobile-friendly and just about everything has been revamped, even the logo. In the Work section (our portfolio) we're using the Isotope jQuery plugin with Drupal's Views Isotope module. We're making extensive use of Drupal's taxonomy system for tagging content, and using Views to display that content in different ways throughout the site.
We attended DrupalCon Prague in September, and it was great to see familiar faces from the Munich conference. The big focus for many attendees and certainly for us was the push to Drupal 8, especially the new theming layer, which uses Twig as its template engine. From what I saw, it looked like a significant leap forward for theming, especially for keeping logic and theming separate - as much as is possible or reasonable. I suspect the logic/presentation debate will rage on for a long time to come, because there will always be edge cases where the lines are a bit blurred. Switching to D8 will require porting your D7 TPL files to the new Twig method - for the moment you can find instructions here.
Ever needed to generate nicely formatted PDFs and/or PNGs on-the-fly? Check out wkhtmltopdf for PDF conversion using Webkit printing to PDF. From there you can conver the PDF to a PNG using pdftoppm.
Here's a very condensed run-down of the procedure on Ubuntu;
- install GCC C++ compiler if not already installed (sudo apt-get install build-essential). See http://www.shibuvarkala.com/2009/03/how-to-install-gcc-cc-compiler-in.html
- install XLL libraries (sudo apt-get install libx11-dev, sudo apt-get build-dep qt4-qmake).
- install wkhtmltopdf on server See http://blog.tcs.de/install-wkhtmltopdf-on-ubuntu-server/
- install xvfb; sudo apt-get install xvfb
- You can now generate nice HTML/CSS to PDF conversions using this command: xvfb-run --server-args="-screen 0, 1280x768x24" wkhtmltopdf http://www.your-awesome-site.com some-awesome-file.pdf
- Install Imagemagick or poppler-utils. (apt-get install poppler-utils). This is for converting the PDF to a PNG. Imagemagick seems to run faster.
TCPDF is another widely used PDF conversion utility but I have found its layout and formatting options to be incredibly tedious. It makes a lot more sense to me to just print to PDF and let the Webkit browser do the heavy lifting .. with a helping hand from xvfb. You can invoke the xvfb command in PHP as follows:
$url = 'http://www.your-awesome-site.com/somepage.html;
$path = '/home/youraccount/somedir'; //path to where you want to write the file. Make sure the web user (www-data) owns this folder and has write permissions.
$pdfcommand = 'xvfb-run --server-args="-screen 0, 960x768x24" wkhtmltopdf '.escapeshellarg($url).' '.escapeshellarg($path).'some-awesome-file.pdf';<br />exec($pdfcommand);
//Then to convert the file to PNG:
$pngcommand = 'convert -density 300 '.escapeshellarg($path).'reminder.pdf '.escapeshellarg($path).'some-awesome-file.png';//imagemagick seems faster. 'convert' is the Imagemagick command. <br />exec($pngcommand);
We write to you today from DrupalCon Munich 2012. Dries Buytaert, Drupal's founder, talked about the plans for the future. Drupal 8 is scheduled for release mid 2013 (August-ish) with a feeature freeze this December and a code freeze in February 2013. He also talked a bit about how he views Acquia vs Drupal. Acquia is his company, which obviously benefits from Drupal, but it also benefits Drupal. He sees a fear of competition in the Drupal community, which he finds unfounded since there is a lack of Drupal developers when it comes to the growing market for Drupal sites. It is not unheard of for Drupal projects to get halted or switched to some other framework due to lack of enough developers. We need more competition, not less!
Ubuntu users will recognize this common issue;
You have a user directory, e.g. /home/someuser, and you can SSH in and use 'sudo -s' to do super-usery things. Now try to SFTP (Dreamweaver, FileZilla, etc), and you can download, but if the files are 'owned' by www-data you probably can't upload anything except maybe new files. Many web applications (Drupal at least) need the files to be writable by the same user/group that Apache uses /... in the case of Ubuntu this is www-data.
You can't use 'sudo -s' within Dreamweaver or FileZilla.. yes, FileZilla has a custom command option, but it doesn't work with 'sudo -s'.
You can "chown someuser:someuser * -R" inside the /home/someuser directory and make them writable by your user that way, but then you would need to chown them back to www-data to keep Drupal running well.
A long-term solution is this:
sudo usermod -a -G www-data someuser
Then ... log that user out of the FTP client and try again. You have to log out for the new permissions to be recognized.
Middle East / North Africa
$detectedcountry = module_invoke('ip2country','get_country',$_SERVER['REMOTE_ADDR']);
$mideast = array('AM', 'AZ', 'BH', 'GE', 'IR', 'IQ', 'IL', 'JO', 'KW', 'LB', 'NT', 'OM', 'QA', 'SA', 'SY', 'TR', 'TM', 'AE', 'YE', 'SO', 'DZ', 'MA', 'TN', 'EG', 'LY', 'CY');
$detectedcountry = module_invoke('ip2country','get_country',$_SERVER['REMOTE_ADDR']);
$uscanada = array(
'US', 'CA', 'GU', 'FM', 'AS', 'VI', 'PR'
We are frequently tasked with creating custom image slideshows for Drupal sites.
We work mainly in Drupal 7, and for simple home page sliders we like to use this combination;
- New content type called Slide
- Use Link Image Field and add that as a field in your Slide content type. Allow for unlimited images. This will allow you to link your slides to custom URLs and add titles, rel attributes etc.
- A View (using Views) showing all results for nodes of type "Slide". Use fields display in combination with Nivo or Slideshow.
- Try either Views Nivo Slider or Views Slideshow. We have had more luck with Views Slideshow.
- If using Views Slideshow, also consider Views Slideshow Configurable Controls, which enables next/pause/previous icons instead of just text links.
- Create a new Slide node - let's call it "Home Slides". Add as many pictures as you need, and provide links for them as needed (thanks to Link Image Field). Save.
- Edit your view and add a new display page or block. Add a filter for "nid" and restrict it to only the node ID of the "Home Slides" node you just created. Since we are including multiple images within a single node, we do not need to show multiple nodes. In the image field's settings make sure to NOT have it show multiple field results in a single row. We want them as separate rows so each photo will be separate.
- Add sorting as needed. Nodequeue isn't an option here, but you don't need it since you can drag and drop the images when editing the node.
- Your node is now essentially an image gallery exposed to Views. You could now also theme your Slide nodes to show thumbnail images in a gallery format, but you don't need to display the node. We only need it for Views.