Posts tagged url

Firefox problem solved: Address bar not working

0

A few days ago Firefox started one of the most annoying bugs I've come across: The address bar stopped working completely. No matter what I tried to do, this are the detailed symptoms:

  • Write a URL and hit enter and nothing would happen
  • The same as before but clicking the green arrow at the end of the address bar
  • The URL in the address bar would not change when switching between tabs

Now this was really annoying me, and I've realized that quite a lot of people had the same problem so after a lot of research, I got to the solution.
The problem is caused by these plugins: Alexa Sparky 1.4.4 and Delicious. As for the Alexa plugin, just downgrade to 1.3.0 and everything will be fine. With the Delicious plugin though my advice is to completely remove it until there is a new version.

I hope you could get your problem fixed,
Alex

Parse links in user comments

0

When you allow users to comment and post stuff to your website, it is interesting and useful allowing them to post links and other stuff. But how can we do so easily?
Surely there is BBCode, phpBB, allowing only some HTML tags... etc but how easy is this approach for the end user? Of course some users will be familiar with BB code, or with HTML; others will be curious enough to learn how to use it, but most won't. And we want our users to be able to do so.

The solution: URL Parsing

How about this: They simply post the URL of whatever they want to include (A link, a picture, a YouTube video... ) and we detect that, and take the corresponding action.

First of all we need something that detects links, I have written a simple regexp to do so:

 
function parse($text){
		return preg_replace_callback('@(https?://([-\w\.]+)+(:\d+)?(/([\w/_\.-]*(\?\S+)?)?)?)@', 'parseUrl', $text);
	}
 

This is valid for almost all URLs, as long as http is the beggining. This function calls a callback function whenever a URL is found, called parseURL, which will then take care of the URL.

parseURL

Now that the URL is found, we need to take care of it: The url is stored in a parameter returned from the function preg_replace_callback. It is contained in the first element of the returned array.

 
function parseURL($url){
       $link = $url[0];
}
 

We will parse the full url with a built-in function called parse_url(), which will return the following data:

  • scheme - e.g. http
  • host
  • port
  • user
  • pass
  • path
  • query - after the question mark ?
  • fragment - after the hashmark #

To get the file format we will check the extension:

 
$ext = substr(strrchr($url['path']),'.'),1);
 

Image formats:

 
$imgs = array('jpg','jpeg','gif','png','tif'); // You can write more if you want, this is only an example
 

Now let's check if it is or not an image:

 
if(in_array($ext,$imgs)){
          return '<img src="'.$link.'" alt="This is a picture" class="insertedPic" />';
}
 

This way if a user inserts a link to a picture, the picture is displayed. You can now add a link, or change in any way the result of this.

If it is a YouTube video it would also be good to embed it, so we will first check if it is:

 
if(eregi('^(www\.)*(youtube\.).{2,3}$',$url['host'])){ // Check for youtube video
	return youtubeEmbed($url['query']);
}
 

As you can see, if the link comes from youtube, we will embed it using our custom function youtubeEmbed:
youtubeEmbed()

 
	function youtubeEmbed($params){
		parse_str($params);
		if(substr($v , strlen($v)-3 ,3) == '<br '){
			$v = substr($v , 0 ,strlen($v)-3);
		}
		if($v){
 
			return '
<div class="addedLink"/><object width="200px" height="150px" style="display:block; z-index:1"><param name="movie" value="http://www.youtube.com/v/'.$v.'"></param><param name="allowFullScreen" value="true"></param><param name="wmode" value="transparent"></param><param name="allowscriptaccess" value="always"></param><embed src="http://www.youtube.com/v/'.$v.'&rel=1&color1=0xFFFFFF&color2=0x666666&border=0" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="200" height="150" wmode="transparent"></embed></object><br ';
		}else{
			return false;
		}
	}
</pre/>
I won't go into too much detail here, it is quite simple, we take the parameter $v, which is the video ID, and then we proceed to the video embed...
 
You can do the same with Metacafe, Vimeo, College Humor, Google Video... etc and the process would be basically the same for all.
<h2>Further uses</h2>
 
I use this class to detect internal links in some of my websites. If the link points to a page with a picture for example, I show a small version of it, if it points to a user profile I show the user's name and some data... etc
 
The options are endless, and once you have everything parsed it is very easy to add new stuff. It really makes it simple for users to share pictures and videos, and it is the safest way of doing so, as well as the best way if you ever want to change the behavior, since in the database all you store is the raw URL.

Writing a good sitemap.xml file for google

3

A sample sitemap.xml fileThe Google XML allows you to inform search engines about URLs on your websites that are available for crawling. Simply, a Sitemap that uses the Sitemap Protocol is an XML file that lists URLs for a site. It also allows web developers to include additional information about each URL ( last update; how often it changes; how important it is related to other URLs in the site) so that search engines can more intelligently crawl the site. This way search engines can crawl your website better.

Google now uses Sitemap Protocol 0.9 as dictated by sitemaps.org. Sitemaps created for Google using Sitemap Protocol 0.9 are compatible with other search engines.

A Sitemap must begin with an opening urlset tag and end with a closing urlset tag. and include a url entry for each URL as a parent XML tag, and a loc child entry for each url parent tag. It must be UTF-8 encoded.

In a Sitemap, urlset, url and loc are required, but the changefreq, lastmod, and priority are optional. urlset is the header and url tag is used before each urls, loc is where the files are located and it has to start with http:// and end with a slash "/", lastmod means when was the last time this URL was modified and the date there must be written according to W3C Date-Time format (YYYY-MM-DD) hour, minutes and seconds can be added too, changefreq means how often this URL is changed (always, hourly, daily, weekly, monthly, yearly and never), and priority means whats the priority of the URL related to the other URLs in this location, the value must be between 0 and 1, so we use a value like 0.8, the default is the 0.5, and changing the value to 1 does not effect the web site's position on Google, just the priority of this URL among other URLs in this location folder.

An Example XML for http://urbanoalvarez.es domain

 
< ?xml version="1.0" encoding="UTF-8"?>
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
 
<url>
<loc> http://urbanoalvarez.es/blog </loc>
<lastmod>2008-03-12</lastmod>
<changefreq>weekly</changefreq>
<priority>1</priority>
</url>
 
<url>
<loc>http://urbanoalvarez.es/portfolio.php</loc>
<changefreq>monthly</changefreq>
</url>
 
<url>
<loc>http://urbanoalvarez.es</loc>
<lastmod>2008-03-12</lastmod>
</url>
 
</urlset>
 

As we see in the example, all we need to do is to use the required tags, which are urlset, url and loc, the others are optional, but of course for a better solution I recommend you to use all of them, make a hierarchy between your website's each URL, insert their priority values according to that and insert their last modified date time and change frequency as told above.

After completing the Sitemap file, I recommend you to compress it with a gzip, and don't forget the Sitemap file cannot contain more than 50.000 URLs and it cannot be larger than 10MB size, so you better compress it. Then it will be a sitemap.gz file. ( Or how you name it, the file extension will be .gz after gzip)

Now where to put the Sitemap file in the site folder ? Don't forget, wherever you insert the sitemap.gz, it can include the URLs in the same folder or in the sub folder. You can't include an URL which is not in the same directory or in an upper directory. With an example, if you insert the sitemap file in the directory, "http://frihost.com/sitemap.gz" we can include all the URLs starting with "http://frihost.com/". But if we insert the Sitemap file in a directory like " http://frihost.com/tools/sitemap.gz", then we can include only URLs which starting with the "http://frihost.com/tools/". So you better insert it in the root, I think it's clear enough.

Now it's time to validate our Sitemap file. Google uses an XML schema to define the elements and attributes that can appear in your Sitemap file. You can download this schema from the link below:

sitemap.xsd

There are some tools to help you validate the structure of your Sitemap. You can find a list of XML-related tools at each of the following locations:

To validate your Sitemap you will need this header in the XML file you have created. It is something like this.

< ?xml version='1.0' encoding='UTF-8'?>
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.sitemaps.org/schemas/sitemap/0.9
http://www.sitemaps.org/schemas/sitemap/0.9/sitemap.xsd">
</urlset>
<urlset>
<url> ....
<loc>....</loc>
</url>
</urlset>

If you are using a Sitemap Generator, it probably does this part for you.

Our Sitemap File is ready, in a shorter time Google and other Search Bots will crawl our site, easily, regularly and more often , and our site will get more traffic. It's what we aimed when we started to make a Sitemap.
If you want to make sure that Google crawls your pages, create an account in Google Webmaster Tools, and submit your sitemaps manually.
Original post by paskall, in frihost.com

Cheers

Go to Top