Tuesday, November 27, 2007

Publishing Content With RSS

Tivo has changed the way I watch TV. Rather than looking up when the shows I want to watch are on, with a few clicks of a button I can set up a recurring recording that will record the shows whenever they're on, for future viewing at my leisure. RSS provides a similar similar concept for online content, by automatically retrieving and storing news and information from my favorite sites.

What is RSS?

RSS, which stands for Really Simple Syndication, is a method for publishing and distributing online content. At it's most basic, it is a list of items, each consisting of a title, some content, and a link. There are a few ways subscribers can subscribe to a feed:

These readers will store a list of subscribed feeds, and periodically check to see if any of them have been updated. When a new item is published, it is added to the list of unread messages. Subscribers can then review the items, and read the ones that interest them.

What are the benefits of RSS?

As spam continues to clog email inboxes at incredible rates, it can be increasingly difficult to get email newsletters opened and read. It is unfortunately all too easy for legitimate emails to get lost in the clutter, or at worst, never even make it to the subscriber's inbox at all.

Because subscribers only receive the feeds they subscribe to, spam problems are removed from the equation.

What are the uses of RSS?

Here are some common examples of RSS uses:

  • Blog entries
  • News Articles
  • Forum posts
Basically, anything you would use email to notify customers, or website content that is regularly updated or added to, can also be published in an RSS feed.

How can I publish an RSS feed?

Many blog and content management systems include built-in RSS feed capability. Another option are hosted services that will allow you to publish one quickly and easily, and can include a variety of tracking and monitoring tools.

There are numerous directories you can then advertise your feed on, expanding the reach of your internet presence.

Contact us at the Helix Group for assistance setting up your RSS feed.

Read more->

Monday, November 19, 2007

Using PHP5’s __autoload() function.

PHP5 has brought with it a great deal of new features, primarily the addition of better object handling. One of these functions is (or “magic methods” as PHP calls them) is the __autoload() function.

Many developers like to separate their classes into separate files, such as a database class that wraps MySQL functions, and another that handles XML processing.

Example (MySQL.php)

<?php class MySQL { /* code goes here */ } ?>

To initiate this class, you would first need to include the file MySQL.php, and then create an object

<?php require_once('MySQL.php'); $objMySQL = new MySQL(); ?>

While this does not pose a problem as is, it can start to be a pain to keep a list of all class files that are needed in a script and then include each one into your page. After a while, this can begin to pose serious problems.

With the magic function __autoload(), however, that is no longer necessary. When a class is created that has not already been included into the script, __autoload() will automatically try and include it. All that is needed is the following code.

<?php function __autoload($className) { require_once($className.'.php'); } $objMySQL = new MySQL(); ?>

Now if the MySQL.php class has not yet been included, PHP will automatically search for it and try to include, thereby saving you the trouble of have to manually do it yourself.

Things To Keep In Mind

__autoload() acts as a last ditch effort to load a class before PHP fails. Two important notes from the PHP manual are:

  • Exceptions thrown in __autoload function cannot be caught in the catch block and results in a fatal error.
  • Autoloading is not available if using PHP in CLI interactive mode.

There are two other important things to remember. One is that the value of $className which is passed to the __autoload() function is case sensitive. If your class is named MySQL and your filename is mysql.php, the function will fail. It is also important to remember to set your include path prior to calling the script, especially if you have your class files in several locations.

<?php set_include_path(get_include_path().PATH_SEPARATOR.'includes'); set_include_path(get_include_path().PATH_SEPARATOR.'includes/classes'); set_include_path(get_include_path().PATH_SEPARATOR.'includes/classes/more_classes'); function __autoload($className) { // if your class names and file names differ in case, here's where you could change it $className = strtolower($className); // try including the class file require_once($className.'php'); } ?>

This function obviously only needs to be defined once, such as in a config.php file. Afterwards, you'll never have to worry about having to manually include all of your class files again.

Further reading: http://us2.php.net/__autoload

Read more->

Thursday, November 15, 2007

Styling links with CSS attribute selectors

CSS attribute selectors allow developers to apply styles based on the attributes within a tag, rather than solely a tag name, id or class. This feature can be very useful for dynamically styling links according to the domain being linked to, the file type, a directory name within the link URL, and much more.

Why are these powerful features not in wide use yet? Largely because Internet Explorer versions 6 and earlier do not support attribute selectors. Other modern browsers such as IE7, Firefox, Opera and Safari do, however. Just be aware that there is a significant portion of the population that will not be able to see styles applied with attribute selectors, so avoid using them for anything vital to your site's basic functioning. But these tools can still be used to add useful enhancements for those using newer browsers.

Basic attribute selectors

This applies to all links with a title attribute, regardless of its value:

a[title] {     font-weight: bold; }

This applies to all links with an href value of "index.html":

a[href="index.html"] {     font-weight: bold; }

It is important to note that depending on the document’s doctype declaration setting, the attribute selectors may be case-sensitive. The above rule would not necessarily apply to links with an href of "index.HTML", for example.

Multiple attribute selectors can also be strung together. This applies to links with an href value of "index.html" and a title attribute with any value:

a[href="index.html"][title] {     font-weight: bold; }

Selecting substrings

Now with CSS3, you can also use substring selectors to match a portion of an attribute.

^="string" will match the beginning of a string, handy for highlighting links based on the target's protocol, such as a secure server (https), ftp, or mailto. This would apply to all ftp links:

a[href^="ftp:"] {     font-weight: bold; }

$="string" will match the end of a string. This is particularly helpful for highlighting links to specific file types. This would apply to links with an href value ending in ".pdf":

a[href$=".pdf"] {     font-weight: bold; }

*="string" will match any portion within the string. This is good for highlighting links to a specific domain name or directory. This would apply to links with "amazon.com" anywhere in the href:

a[href*="amazon.com"] {     font-weight: bold; }

Pseudo-classes

In addition, the attribute selector can be combined with any of the common pseudo-classes of :link, :visited, :hover, :active and :focus .

a[href="index.html"][rel]:hover {     font-weight: bold; }

You can also use the :before and :after pseudo-classes to add icons or text to your links. For example, if you wish to add a small Adobe icon to links to pdf files:

a[href$=".pdf"]:after {     content: url(icon.gif); }

As an alternative to the above method, if you did not want the icon to be part of the clickable link, use it as a background image instead, adjusting the padding as necessary to fit your icon:

a[href$=".pdf"] {     background: transparent url(icon.gif) no-repeat center right;     padding-right: 12px; }

Or you can add the text "(pdf)" to the link text:

a[href$=".pdf"]:after {     content: "(pdf)"; }

It is important to note that the content string will only accept plain text, HTML tags will display as <tag>. However, you can apply CSS styling to the added content:

a[href$=".pdf"]:after {     content: "(pdf)";     font-weight: bold; }

Negation pseudo-class

CSS3's negation pseudo-class adds another powerful option to attribute selectors. Unfortunately, these are not yet supported by IE7, although there are some workaround hacks.

This would apply to all links EXCEPT ones with an href of "index.html":

a:not([href="index.html"]) {     font-weight: bold; }

We can also string together two or more "not" statements. This would apply to all links with an href of anything other than "index.html" AND no title attribute:

a:not([href="index.html"]):not[title] {     font-weight: bold; }

Exceptions can be combined with regular selectors as well. This would apply to links with an href value of "index.html" but no title attribute:

a[href="index.html"]:not[title] {     font-weight: bold; }

Read more->