Archive for January, 2008

A PHP killer feature - Streams abstraction

Thursday, January 31st, 2008
Picture of Manuel Lemos
By Manuel Lemos
This article explains what are stream handlers and how they simplify PHP developers lives by allowing PHP applications to easily read and write data from containers, like remote Web pages or e-mail messages, as if they were files.

A real world example is presented to demonstrate how you can access messages in a POP3 mailbox and how it can be used to automatically process messages from the site users requesting support.

The article also presents more examples of cool stream handlers classes submitted to the PHPClasses site by several authors.

Unrelated to this topic, the PHPClasses site is announcing the availability of a Twitter activity stream that may be used to keep track in a single place of the submissions like: the latest classes, reviews, blog posts and trackbacks.

What programming language should I learn?

Thursday, January 31st, 2008

I have a slight programming background. Basic C, C++ and HTML.

I want to concentrate on one or two languages in-depth.

What do you recommend I learn & how?

Stay on :target

Thursday, January 31st, 2008

In this article, I want to introduce you to a really powerful CSS3 pseudo selector called :target. Much like :hover, :target is invoked during certain interactions with the website. Specifically, when applied to a fragment identifier. On a page such as http://example.com/index.html#hello-world, the id=”hello-world” element is the target and any matching :target styles would be applied.

I am going to demonstrate two examples of when and how :target can be used. Hopefully, this introduction will get you thinking about some of simple ways :target can add benefit your customers.

Tabs in CSS

A well structured document is one that makes sense in the ordering of sections and topics. It works well when there is no CSS and no JavaScript. Tabbed systems make use of some sort of display tab which shows the current section, and in doing so hides the other sections. We’ve all seen a tabbed system before, and probably plenty of poor implementations as well. Sometimes when you click the tab, it calls a JavaScript function to populate the area below the tab. The downside is that when there is no JavaScript the data does not appear.

The ideal way to build a tab system is to have all your data in the HTML, then use JavaScript to hide the other tab panes and build the tabs themselves dynamically. That way if there is no JavaScript, it just defaults to a linear set of text blocks. This is progressive enhancement; build for the lowest common denominator and add more functionality and styling as you go — no one is left behind, not even googlebot.

Instead of using JavaScript to do this show/hide, it is possible to use CSS3 using the :target selector. Before you get too excited, it must be said that the :target selector is not supported in IE6 or IE7, so the practical uses for this are pretty slim. Instead this can be used for user chrome type objects which don’t effect functionality, but improve usability. You can add the :target info today, and when browsers implementations catch-up they get the bells and whistles auto-magically. It is important to not use :target for mission critical things, but there are plenty of other possibilities. As an example, I will show you how make a simple tab system based on Daniel Glazman’s example.

First we should create the basic un-styled HTML.

<h2 id="topic1"><a href="#content1">Topic 1</a></h2>
<p id="content1">This is the text for topic 1. Hello World!</p> <h2 id="topic2"><a href="#content2">Topic 2</a></h2>
<p id="content2">Different text for topic 2. Ah, foobar.</p>

Without CSS or JavaScript this text is completely accessible and reads normally, it just makes the page longer. Tabs are a way to compact the information into a smaller space, so lets proceed to do this.

If we add some simple styles to the page, we can get the two headings to appear and act like tabs through positioning. The interesting part is the :target selector.

// set the default state first
p { display: none;
} // When the link is clicked, set the contents to display
p:target { display: block;
}

When the fragment (#content1) is not part of the URL, the :target selector does not match the <p> element, so it is set the default view of display: none. This is a very simple way to create a tabbed system. You can view a working example and see for yourself.

The Yellow Fade Technique

There is a popular usability feature called the “Yellow Fade Technique”. This is used to direct the user’s attention back to a specific area subtly. For example, when you want to edit a piece of a page you may click edit which takes to a new page with form fields. When you press save you are returned to the original page where there is a brief yellow fade of the area that was just edited. It brings your eye to the area, possibly to confirm the changes look correctly in the template, or to just make people aware the change took place at all. Either way, it seems to be a welcomed usability feature that has been picked-up by several web applications.

Normally, this is accomplished through the use of JavaScript and page IDs or classes. The JavaScript runs an onload function looking for those classes or ID and once the parts of the page have been identified, the script runs a timer and ever few microseconds change the background color from pure yellow to white. This create a smooth, not too annoying, yellow fade effect.

The downside to all this is that there are several resources at work, including onload functions (which might be happening every time the page loads, not just the times when a form is submitted) and hooks into the classes and IDs and JavaScript timers. All this adds to the client download and subtracts from the speed of the page.

With CSS3 there is a much easier and simpler solution. Using the :target pseudo class it is possible to emulate the yellow fade without a single line of JavaScript.

First, you need to create (or download) a tiny 1 pixel-wide yellow animated gif. This will fade from yellow to white. The animated gif isn’t repeating, so it will fade once and then stay pure white. This also defines the length of the fade, so there is no need to for a JavaScript timer.

Second, we need to set this as the background image for the area which has been changed. To do this, we use the CSS3 :target pseudo selector.

#here:target { background-image: url('yellow-fade.gif');
}

This will fade the element with an id=”here”, the URL would look like http://example.com/#here. It is good web architecture to use fragment identifiers for each of your headings and to use RESTful URLs.

Now, the downside to that CSS statement is that it will only fade the area with the ID.

<h1 id="here">Hello World</h1>
<p>I am saying Hello to everyone in the World!</p>

Only the heading element would get the yellow fade. So how do we fix this? Well, we could change the ID to a class and create something like:

.here:target { background-image: url('yellow-fade.gif');
}

But then on the server, we’d have to add classes dynamically to all our elements.

<h1 class="here">Hello World</h1>
<p class="here">I am saying Hello to everyone in the World!</p>

We could put a wrapper around both the heading and the paragraph.

<div id="here">
<h1>Hello World</h1>
<p>I am saying Hello to everyone in the World!</p>
</div>

But that seems too much work. Instead, we can make use of another CSS combinator, the adjacent sibling selector:

#here:target, #here:target+p { background-image: url('yellow-fade.gif');
}

This targets both the heading with the ID ‘here’ and the first sibling paragraph. So both will get the background image and the subsequent fade. You can easily change your CSS to fit your HTML design, but this is a quick and simple alternative to the Yellow Fade technique in JavaScript used on so many sites.

In CSS there is also a wildcard * to stand for all nodes. So you could further take the example to

#here:target, #here:target+* { background-image: url('yellow-fade.gif');
}

This would match the first sibling of #here no matter what the type of element it might be. Firefox correctly supports this, but as of writing, Safari does not.

You can see an example of this in action and view the source to see how it all works.

Blurring the lines between behaviour and presentation

I am obligated by the behaviorists to mention that there is a debate over presentation and behavior, where does one stop and the other start? By adding the :target selector into your CSS, you are styling the HTML based on the behavior of the browser and the users. We talk about the “holy trinity” of web design, and we have spent the last few years campaigning to divide data, presentation and behavior into their respective HTML, CSS and JavaScript camps. The :target, as well as the :hover, selectors blur that line between presentation and behavior. Depending on how comfortable or how much of a purist you are, you may or may not agree with what has been demonstrated.

These examples were written to better understand the CSS3 :target element and to explore those blurry grey-areas. Hopefully, a discussion will emerge with even more ideas, caveats and problems that were not originally thought of. Together we can create some best practices on when to best use CSS behavior and JavaScript presentation.

Conclusion

Over a year ago, Andy Budd demonstrated the yellow-fade technique with :target and I was impressed! (http://www.andybudd.com/presentations/css3/) In the time in between, I have seen very little attention or articles on this little known selector. As I was started working on this article, I found several examples some from as early as January 2003 that talk about uses for the :target selector. The reason for not getting the traction it deserves could be the lack of information about when and how to use it correctly or documentation on the poor CSS3 implementations in browsers.

CSS3 is closer than you think, many of the selectors and attributes are available in several major browsers today. They can be used with progressive enhancement to add more style to your design at little cost, when other browsers catch-up they get the benefits of your progressive code for free. The CSS3 :target selector is just one example of some of the new selectors arriving that can be taken advantage of in interesting new ways.

Weird Wordpress Import error…need help…I am on Dreamhost

Monday, January 28th, 2008

I am getting a strange error during the IMPORT process in Wordpress.

I posted on the Wordpress Forums, but here was my question

I have successfully "exported" my blog entries from one of my WordPress blogs (version 2.2.1) and have tried to "import" those entries into my other Wordpress Blog (version 2.3.2).

I get the following error in my error log files because typically Apache or whatever throws the "500 Internal Server Error page".

Premature end of script headers: php5.cgi, referer: http://www.[removed-my-url].com/wp-admin/admin.php?import=wordpress&step=1

What would be causing this? Is it a problem with my version of WP I am exporting from (maybe the export document has been updated)?

Thanks

Help with time-based conditionals

Sunday, January 27th, 2008

I'm in WordPress (don't know if that matters for this particular code) and I'm trying to display various different things between certain dates, and something else outside of those dates.

Here's what I have so far:

<?php $eventheader = getdate() ?>
<?php if ($eventheader[mon] = 2 && $eventheader[mday] > 12 && $eventheader[mday] < 22){ ?>
<?php include (TEMPLATEPATH . '/event-winter.php'); ?> <!-- Winter Cup -->
<?php if ($eventheader[mon] = 3 && $eventheader[mday] > 4 && $eventheader[mday] < 14){ ?>
<?php include (TEMPLATEPATH . '/event-margutti.php'); ?> <!-- Margutti Trophy -->
<?php if ($eventheader[mon] = 3 && $eventheader[mday] > 4 && $eventheader[mday] < 14){ ?>
<?php include (TEMPLATEPATH . '/event-wsk1.php'); ?> <!-- WSK Round 1 -->
<?php } else { ?>
<?php include (TEMPLATEPATH . '/poll.php'); ?> <!-- Any other time -->
<?php } ?>

As anyone familiar with PHP can probably see, it works with just either event-winter.php or poll.php, but I'm the noobiest of noobs and I don't know how to make it choose from a whole list. Does anyone else know or can point me to an informative link?

Where can I find strong CSS/HTML/Photoshop coders?

Friday, January 25th, 2008

Hi,

I'm looking for some top notch CSS/HTML coders that can take a photoshop designs and slice it into XHTML compliant code.

I'm having a difficult time finding these kinds of people. Where can I find these types of people?

Thanks

Tim

How to Build a Web Start-up - Part 1

Thursday, January 24th, 2008

We live in an extremely exciting period of human history where it has never been easier or cheaper to start a web-based business. You just don’t need a bricks-and-mortar shop to make it big anymore.

However, there are still a massive number web start-ups that fail every year. How can you avoid becoming one of them and being plunged into the TechCrunch deadpool?

In this series for Vitamin, I’ll be sharing some of the valuable tips you’ll need to survive and thrive as a new web startup. I’ll also share some exclusive new content from our upcoming workshop, Start-up Clinic.

So if you’re itching to tell your boss where to stick it and start your own company, this series of articles is perfect for you.


PHP Redirect vs POST Resend. Help?

Sunday, January 20th, 2008

I was coding my webblog and hit upon this tiny problem of refreshing a page. I am using the PRG (Post/Redirect/Get) pattern for my blog post where, after submitting a comment, it processes the data and redirects to itself in order to avoid resending of POST data once the user refreshes the page. But due to this I am not able to post a thank you message for the user that leaves a comment.

Here's the basic structure:

<?php
if(submit)
{process_data();
redirect_to_self();}
?>
<div id="post">Post content</div>
<div id="comment">All Comments</div>
<div id="form>
<!--Here's where I had like to show the thank you message-->
<form></form>
</div>

I am not at all with NOT using redirect as resending POST data is a punishable offense.

Any suggestions?

Any idea why the title of my blog does not come up in the browser

Friday, January 18th, 2008

When I am at my main link of my blog http://wonderlandornot.net the link in firefox and ie browser appears as < ?php bloginfo('name'); in stead of as "wonderland or not , also when when I looked at a splog pingback the pingback also read that way - like this--->


[…] < ?php bloginfo('name'); ?> wrote an interesting post today on One Snowy Day.Here's a quick excerpt blah blah blah

The php thing being in place of the name of my blog.

This was not a problem in the past, so I assume it is theme related.

Any idea as to why this is happening?

Accessible can be Beautiful

Tuesday, January 15th, 2008

I may be preaching to the choir in this post, but one can always use it as a reference to clients or colleagues.

Accessibility is one of my favourite aspects of web design. It’s also got a lot of hangups and myths associated with it. For example, it is not just for disabled users contrary to popular belief. I hope the linked article put that one to bed for a while.

My other favourite myth is the old-fangled “Accessible sites are boring.” Pah! Poppycock! It may be true that often accessible sites are created from a pool of fairly unimaginative templates (think the accessible template set from pre-Dreamweaver 8.) They don’t do anything wrong (except harm my case thus far) but they’re not exciting. They’re not really designed. I aim to show you examples of brilliant and accessible design, and show that it is all a myth after all. Accessibility and design are not mutually exclusive. They walk hand in hand.

Boring? Try Beautiful

Without inspiration such as a bunch of CSS galleries (nothing looked promising after searching for an accessible website showcase) I had to dig a little deeper this time. The following is the pick of the bunch from my search. Feel free to suggest a site if you think it fits the list.

For the record, the following are chosen based upon achieving WAI Priority 2 using the Cynthia Says accessibility tester for their homepage. I am fully aware that validation is not the be-all-and end-all of accessibility. I know accessibility goes beyond the homepage. I think this is the fairest and quickest (let’s be honest I don’t have that much free time!) way to put a benchmark on a site in this case. I’m not suggesting for a minute that this should be the benchmark to test all sites - this simply allows me to find sites of a certain standard. Anyway, on with the sites:

Website Thumbnail

Clean and creative. Good use of space and typography to create a welcoming site.

Website Thumbnail

Use of a flash element - passes the accessibility test. Nicely falls back to good old HTML.

Website Thumbnail

Accessibility - not ’spoiling’ this textured design at all.

Website Thumbnail

Bold, clean and simple.

Website Thumbnail

Ultra-minimal portfolio. Mixed sans-serif font cases adds interest.

I hope to have shown with the aid of the preceding examples that accessibility doesn’t necessarily stunt great design. In fact using accessibility, usability and web standards as a ‘trinity’ one can often improve on their design skills. The examples above also illustrate that the code elements that increase a website’s accessibility do not often show on the design. The sites in question aren’t “littered with accessibility aids that most people don’t use” - another of my favourite statements I hear far too often.

Let me know your additions via a comment and I’ll add the best to the list, along with some link-love to the commenter if desired.


Created by DesignForWeb company. All rights reserved © 2007-2010. Check also the iPhone / iPad developers blog
Disclaimer
The materials collected in this blog were taken from open access sources. We try our best to preserve the copyrights of original authors and clearly state the authorship as well as link to original source website where it's possible. Please leave your comment if you feel offended by any post or if you dispose of any information about breach of copyright law in this blog. We will do our best to resolve the situation immediately.