-
Notifications
You must be signed in to change notification settings - Fork 3
/
favicon.inc.php
executable file
·93 lines (82 loc) · 2.77 KB
/
favicon.inc.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
<?php
################################################################################
#
# Favicon Class (work with favicons), ver. 1.0, June, 2006.
#
# (c) 2006 ControlStyle Company. All rights reserved.
# Developped by Nikolay I. Yarovoy, Dmitry V. Domojilov.
#
# http://www.controlstyle.com
#
################################################################################
class favicon
{
var $ver = '1.1';
var $site_url = ''; # url of site
var $if_modified_since = 0; # cache
var $is_not_modified = false;
var $ico_type = 'ico'; # ico, gif or png only
var $ico_url = ''; # full uri to favicon
var $ico_exists = 'not checked'; # no comments
# main proc
function favicon($site_url, $if_modified_since = 0)
{
$site_url = trim(str_replace('http://', '', trim($site_url)), '/');
$site_url = explode('/', $site_url);
$site_url = 'http://' . $site_url[0] . '/';
$this->site_url = $site_url;
$this->if_modified_since = $if_modified_since;
}
# get uri of site
function get_site_url(){
return $this->site_url;
}
# get uri of favicon
function get_ico_url()
{
if ($this->ico_url == '')
{
$this->ico_url = $this->site_url . 'favicon.ico';
# get html of page
$h = @fopen($this->site_url, 'r');
if ($h)
{
$html = '';
while (!feof($h) and !preg_match('/<([s]*)body([^>]*)>/i', $html))
{
$html .= fread($h, 200);
}
fclose($h);
# search need <link> tag
if (preg_match('/<([^>]*)link([^>]*)(rel="icon"|rel="shortcut icon")([^>]*)>/iU', $html, $out))
{
$link_tag = $out[0];
if (preg_match('/href([s]*)=([s]*)"([^"]*)"/iU', $link_tag, $out))
{
$this->ico_type = (!(strpos($link_tag, 'png')===false)) ? 'png' : 'ico';
$ico_href = trim($out[3]);
if (strpos($ico_href, 'http://')===false)
{
$ico_href = rtrim($this->site_url, '/') . '/' . ltrim($ico_href, '/');
}
$this->ico_url = $ico_href;
}
}
}
}
return $this->ico_url;
}
# check that favicon is exists
function is_ico_exists()
{
if ($this->ico_exists=='not checked')
{
$h = @fopen($this->get_ico_url(), 'r');
$this->ico_exists = ($h) ? true : false;
if ($h) fclose($h);
}
return $this->ico_exists;
}
}
?>