programming posts

Transparent iframe Background in IE

When setting background-color: transparent for an iframe in IE, it just doesn't work.  It shows up as white instead.  Of course, it works in every other browser, but not IE.  So what's the deal? How do you fix it?

This one may not come up very often for everyone, but it did for me, and took me an hour of googling to find the answer:

<iframe src='example.html' allowtransparency='true'></iframe>

You see what I did there?  allowtransparency='true'.  Apparently in IE you have to explicitly state it or it will just ignore the CSS attribute.  Thanks IE!

And while I'm on it, if you want to get rid of the border that IE places on iframes, you have do to this:

<iframe src='example.html' frameborder='0'>

That's right.  frameborder='0'.  I've said it before: IE is the best, most logical browser around.

Find the True URL of Something, Following Redirects

Have you ever wanted to know the definitive URL to something on the Internet, following any 301 redirects?  I am working on a podcast-related site right now, and recently had to keep track of a multitide of podcast URL's, even when they change.  The following PHP code saved the day:

function get_final_url($url) {
 
  $ch = curl_init($url);
  curl_setopt($ch,CURLOPT_FOLLOWLOCATION,true);
  curl_setopt($ch,CURLOPT_RETURNTRANSFER,true);
  curl_exec($ch);
  $url = curl_getinfo($ch, CURLINFO_EFFECTIVE_URL);
  curl_close($ch);  
 
  return $url;
}

To use, let's say you have a url of "http://example123.com/index.html"  but, unbeknownst to you, that URL actually has a 301 redirect to "http://example123.com/welcome.html". 

You can use the function this way:

$url = get_final_url("http://example123.com/index.html");

And $url will now contain "http://example123.com/welcome.html".

Enjoy!

Amazon S3 Logs - Drupal 6 Module

Note!  This project is now an official Drupal project.  You may download it by going here: http://drupal.org/project/amazon_s3_logs

as3l-sc1.pngUsing an Amazon S3 account is ideal for web sites with lots of content, but unfortunately Amazon doesn't make it easy for you to track traffic and visitors to your site.  That is where this drupal 6 module comes in.  Assuming you have correctly set up a log bucket on your account, this module makes it easy to get basic usage stats at a glace for all your files.

You're site doesn't even need to be a drupal site to use this.  If you want, you can always have a drupal installation whose only purpose is to run this module.

See this module's project page on drupal.org for instructions on installing and setting it all up.

Arrange Fields - Drupal 6 Module

 Note!  This project is now an official Drupal project.  You may download it by going here: http://drupal.org/project/arrange_fields

 ar-screen1.pngHave you ever used CCK or Webform with Drupal, and found yourself wishing you could easily arrange the fields in a horizontal style, or just easily resize textfields and areas on the fly?  Then this module is for you.  It gives you a simple drag-and-drop interface to to arrange fields on your forms.

Tab indexing is also respected, so no matter how you arrange your fields, you can still tab through them in a logical order.

Features

  • Drag and drop fields into any arrangement you want. Makes CCK and webforms look more like pen-and-paper forms.
  • Resize textfields and textareas by dragging.
  • Edit CCK configurations for each field (required, help text, allowed values, etc) in a popup without having to leave the page.

Collapsible Fieldsets Without jQuery

Attached File(s): 

c_fieldset.jpgYou know those nifty collapsible fieldsets that Drupal uses?  No?  Oh... well, let me explain: Drupal often uses fieldsets to represent information, which can collapse at the click of a mouse.  This lets visitors to your site hide information or forms they don't care about.  It's accomplished using some jQuery wizardry and is uber slick.

What I have created does not use jQuery, and is not uber slick.  But, it does provide the same basic functionality.  The reason I chose not to use jQuery is so that you are not required to download and install any extra libraries.

What I have created is a simple PHP function which, when called, will generate all of the HTML, CSS, and Javascript necessary to give you a collapsible fieldset.

Click here to see a demo of it in action.  (And use the download link at the top of this post to get the source code).

 


Software License Fine Print

Creative Commons LicenseThis code is licensed as-is, with no warranty or guarantee, under a Creative Commons Attribution 3.0 Unported License.

You may use this code however you want, even in commercial products, but only if you include attribution to me, Richard Peacock, as the original author of this small portion of code, but not in a way that implies I endorse your project.

For example, on a Help/Credits screen:  Portions of this project were based on work freely obtained from these developers: Richard Peacock (http://richardpeacock.com), NAME HERE, etc.  These outside developers neither endorse nor support this software.

If you use this code, feel free to email me to let me know!  I'll include a link to your project here.

Daily Site Backup - Drupal 6 Module

Attached File(s): 

hardrive_000.jpg

Update! You can now split backups into chunks for easier emailing.

This module is intended for drupal sites running linux or unix.  It will create an archive of your site (or multi-site) allowing you to specify included and/or excluded files and directories. Ex: modules, themes, etc.  It can then email it to an address of your choice.  I recommend a gmail account, as you get several gigs of storage for free.

This module will actually issue a tar command to the command line.  This is why you need to be running either unix or linux.

Note:  This module plays very nicely with my other module, Daily MySQL Backup!

Also of note: This module plays especially well with my new desktop backup program, psBackup, which is able to download files from the web as well as regular file backups.

 


Software License Fine Print

Creative Commons LicenseThis code is licensed as-is, with no warranty or guarantee, under a Creative Commons Attribution 3.0 Unported License.

You may use this code however you want, even in commercial products, but only if you include attribution to me, Richard Peacock, as the original author of this small portion of code, but not in a way that implies I endorse your project.

For example, on a Help/Credits screen:  Portions of this project were based on work freely obtained from these developers: Richard Peacock (http://richardpeacock.com), NAME HERE, etc.  These outside developers neither endorse nor support this software.

If you use this code, feel free to email me to let me know!  I'll include a link to your project here.

Shell - Drupal 6 Module

Note!  This project is now an official Drupal project.  You may download it by going here: http://drupal.org/project/shell

shell-screenshot.jpgAre you using an inexpensive (or just plain limited) web host, and don't have access to a proper shell?  You know if only you could pull up putty, you could perform some operation in half the time it will take you in cpanel or some FTP client.  If this sounds familiar, then you should check out my latest Drupal 6 module, Shell.

Shell is a web-based Ajaxy pseudo shell which gives you most of the commands of your linux/unix server.  This will not work for Windows servers.  It works by passing whatever you type through PHP and directly to the server, then shows you the response.  If you are comfortable using putty (or any other shell) then you will feel right at home with this module.  It even gives you a tab-autocomplete like a real shell.

Meet My Friend, Mr. Curly Brace

The curly brace (also known as the curly bracket) is a fairly powerful tool in PHP.  In a nutshell, it lets you specify the name of a variable in a string.  Why is that so important?  Because what if you want to specify a member variable to an object in another variable?  Maybe an example would elucidate the problem...

Let's say you want to compare apples to oranges in a standard object...

$obj = new stdClass();
$obj->apples[] = "Granny";
$obj->apples[] = "Red";
$obj->apples[] = "Bad";

$obj->oranges[] = "Navel";
$obj->oranges[] = "Tangerine";

Now, let's say that you need to access either the apples array or the oranges array based on some other variable, $fruit

PHP Tip: Sorting Multidimensional Associative Arrays

We've all faced this problem before.  You have a multidimensional associative array, and you need to sort it by some element right in the middle.  Or even sort by several elements.  How do you do it?  Well, here's a quick tip that will keep you from having to program custom comparison routines to get usort() to work.

For example, let's say your array looks something like this:

// array structure:  $a[person name][age][pet name] = pet age

$a["mary"][35]["spot"] = 5;
$a["bob"][29]["nosy"] = 8;
$a["mary"][35]["fido"] = 12;
$a["bob"][29]["eve"] = 2;

Now let's say you want to know the order of pet names, sorted by owner's age, then pet age, then person name, then pet name.  If we go the traditional usort route, we would have to program several annoying and confusing comparison functions.  So, here's the trick:  flatten out the array!

 


Software License Fine Print

Creative Commons LicenseThis code is licensed as-is, with no warranty or guarantee, under a Creative Commons Attribution 3.0 Unported License.

You may use this code however you want, even in commercial products, but only if you include attribution to me, Richard Peacock, as the original author of this small portion of code, but not in a way that implies I endorse your project.

For example, on a Help/Credits screen:  Portions of this project were based on work freely obtained from these developers: Richard Peacock (http://richardpeacock.com), NAME HERE, etc.  These outside developers neither endorse nor support this software.

If you use this code, feel free to email me to let me know!  I'll include a link to your project here.

Easy Gallery - Drupal 6 Module

Attached File(s): 

Last updated: 5-26-2011, version 1.1b.

easy-gallery-screenshot-1.jpgLike the name says, this is meant to be a simple and easy photo/image gallery. It is intended for people who just want a simple solution for a photo gallery, and do not want the hassle of having to set up Views and CCK, or of installing another application (like Gallery2).  It is meant to be as easy to use as Facebook or Flickr.

A little backstory:  I wrote this partially because of a client I was building a web site for.  He had no technical expertise at all, so I wanted an image gallery which I felt was easy enough for him to set up and maintain.  I looked around the Drupal community, but never found one that met that description.  Believe me, they were all very good, very snazzy galleries! But, I never found anything that seemed easy enough for a novice to use.

 


Software License Fine Print

Creative Commons LicenseThis code is licensed as-is, with no warranty or guarantee, under a Creative Commons Attribution 3.0 Unported License.

You may use this code however you want, even in commercial products, but only if you include attribution to me, Richard Peacock, as the original author of this small portion of code, but not in a way that implies I endorse your project.

For example, on a Help/Credits screen:  Portions of this project were based on work freely obtained from these developers: Richard Peacock (http://richardpeacock.com), NAME HERE, etc.  These outside developers neither endorse nor support this software.

If you use this code, feel free to email me to let me know!  I'll include a link to your project here.

Syndicate content