PHP Classes

Transparency

Recommend this page to a friend!

      floIcon  >  All threads  >  Transparency  >  (Un) Subscribe thread alerts  
Subject:Transparency
Summary:Error when transparency = true
Messages:13
Author:Jason Brook
Date:2010-03-11 21:26:44
Update:2010-03-15 20:49:52
 
  1 - 10   11 - 13  

  11. Re: Transparency   Reply   Report abuse  
Picture of Jason Brook Jason Brook - 2010-03-15 15:53:22 - In reply to message 10 from Joshua hatfield
Unfortunatly i don't have the site address i got it from anymore, i if did i would happily share it with you.

If you could paste the code that would be great, thanks so much.

  12. Re: Transparency   Reply   Report abuse  
Picture of Joshua hatfield Joshua hatfield - 2010-03-15 20:01:16 - In reply to message 11 from Jason Brook
I don't know how well this "forum" is going to format this, but at least it should give you an idea. This is the code I'm using to detect the favicon.

function favicon_find($referrence_url = null) {
// Set absolute path to false in case nothing else is found.
$favicon_abs = false;
// Check to make sure a url was given.
if ($referrence_url) {
// Find hostname and path from url.
if (preg_match("/(https?\:\/\/[\w\d_.]+)(\/.*)?$/si", $referrence_url, $matches)) {
$host = $matches[1];
$pagepath = $matches[2];
// Get page contents from url.
if ($file_contents = @file_get_contents($referrence_url)) {
// Check url contents for link tag.
if (preg_match("/<link[^>]+rel=\"(?:shortcut )?icon\"[^>]+?href=\"([^\"]+?)\"/si", $file_contents, $matches)) {
$favicon = $matches[1];
} else {
// No link tag, assign default.
$favicon = "/favicon.ico";
}
// Convert favicon path to absolute.
$favicon_abs = url_find_absolute($favicon, $referrence_url);
}
}
}
// Make sure there is actually a file there.
if (!file_get_contents($favicon_abs)) {
$favicon_abs = false;
}
return $favicon_abs;
}
function url_find_absolute($relative_url, $referrence_url) {
// First check if this is actually absolute.
if (preg_match("/(https?\:\/\/[\w\d_.]+)(\/.*)?$/si", $relative_url, $matches)) {
// If so, return itself.
$favicon_abs = $relative_url;
// Then, make sure the referrence is absolute, this is necessary (otherise, return false).
} elseif (preg_match("/(https?\:\/\/[\w\d_.]+)(\/.*)?$/si", $referrence_url, $matches)) {
// Pull out the hostname and path for later use.
$ref_host = $matches[1];
$ref_pagepath = $matches[2];
// If relative url begins with /, just add it to the host.
if (preg_match('/^\//si', $relative_url, $matches)) {
$favicon_abs = $ref_host.$relative_url;
// Otherwise, merging paths is needed.
} else {
// Break up the paths by directory.
$ref_array = explode("/", $ref_pagepath);
$rel_array = explode("/", $relative_url);
// Pop off the filename from the referrence (it's not needed).
array_pop($ref_array);
// Check each directory
while (null !== $rel_part = array_shift($rel_array)) {
// Looking for "." or empty (stay in same directory).
if ($rel_part == "." || $rel_part == "") {
// Don't do anything, already in current directory
// Looking for ".." (going up one directory).
} elseif ($rel_part == "..") {
// Move up one directory.
array_pop($ref_array);
} else {
// Add directory (or file) to altered referrence array
array_push($ref_array, $rel_part);
}
// Make sure there's always room for the starting /
if (count($ref_array) == 0) {
array_push($ref_array, "");
}
}
// Implode altered referrence and add to hostname for final result.
$favicon_abs = $ref_host.implode("/", $ref_array);
}
} else {
// Returninf false because referrence is not absolute.
return false;
}
return $favicon_abs;
}

  13. Re: Transparency   Reply   Report abuse  
Picture of Jason Brook Jason Brook - 2010-03-15 20:49:52 - In reply to message 12 from Joshua hatfield
I already have a script coded that does that part i may have posted my message badly.

What i have got so far is a script that finds the favicon file when a url is entered by the user, it then finds the file from either the default location or in the meta tags of the site pages. It will then send back the full link to the favicon file.

The part that im stuck on is the actual loading it into your class and getting it to send back the image to be displayed on the page as a transparent PNG. It worked with the old one which i could work out how to use but the new updated one has confused me totally.

Hope that makes sense. I'm just totally lost in what all the commands do and in what order they need to be run.

Thanks

 
  1 - 10   11 - 13