2007-12-12 17:29:16 +01:00
|
|
|
<?php
|
|
|
|
/***************************************************************************
|
2008-10-22 16:05:59 +02:00
|
|
|
Copyright (C) 2005 - 2006 Scuttle project
|
|
|
|
http://sourceforge.net/projects/scuttle/
|
|
|
|
http://scuttle.org/
|
2007-12-12 17:29:16 +01:00
|
|
|
|
2008-10-22 16:05:59 +02:00
|
|
|
This program is free software; you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU General Public License as published by
|
|
|
|
the Free Software Foundation; either version 2 of the License, or
|
|
|
|
(at your option) any later version.
|
2007-12-12 17:29:16 +01:00
|
|
|
|
2008-10-22 16:05:59 +02:00
|
|
|
This program is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU General Public License for more details.
|
2007-12-12 17:29:16 +01:00
|
|
|
|
2008-10-22 16:05:59 +02:00
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with this program; if not, write to the Free Software
|
|
|
|
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
|
|
***************************************************************************/
|
2007-12-12 17:29:16 +01:00
|
|
|
|
|
|
|
header("Last-Modified: ". gmdate("D, d M Y H:i:s") ." GMT");
|
|
|
|
header("Cache-Control: no-cache, must-revalidate");
|
|
|
|
|
2010-03-17 21:11:21 +01:00
|
|
|
$httpContentType = 'text/xml';
|
2010-02-08 08:32:34 +01:00
|
|
|
require_once 'www-header.php';
|
2007-12-12 17:29:16 +01:00
|
|
|
|
2008-11-25 16:57:29 +01:00
|
|
|
/* Managing all possible inputs */
|
|
|
|
isset($_GET['url']) ? define('GET_URL', $_GET['url']): define('GET_URL', '');
|
|
|
|
|
2007-12-12 17:29:16 +01:00
|
|
|
function getTitle($url) {
|
2008-10-22 16:05:59 +02:00
|
|
|
$fd = @fopen($url, 'r');
|
|
|
|
if ($fd) {
|
|
|
|
$html = fread($fd, 1750);
|
|
|
|
fclose($fd);
|
2007-12-12 17:29:16 +01:00
|
|
|
|
2008-10-22 16:05:59 +02:00
|
|
|
// Get title from title tag
|
|
|
|
preg_match_all('/<title>(.*)<\/title>/si', $html, $matches);
|
|
|
|
$title = $matches[1][0];
|
2007-12-12 17:29:16 +01:00
|
|
|
|
2011-05-23 18:16:41 +02:00
|
|
|
$encoding = 'utf-8';
|
2008-10-22 16:05:59 +02:00
|
|
|
// Get encoding from charset attribute
|
|
|
|
preg_match_all('/<meta.*charset=([^;"]*)">/i', $html, $matches);
|
2011-05-23 18:16:41 +02:00
|
|
|
if (isset($matches[1][0])) {
|
|
|
|
$encoding = strtoupper($matches[1][0]);
|
|
|
|
}
|
2007-12-12 17:29:16 +01:00
|
|
|
|
2008-10-22 16:05:59 +02:00
|
|
|
// Convert to UTF-8 from the original encoding
|
2008-12-03 12:11:08 +01:00
|
|
|
if (function_exists("mb_convert_encoding")) {
|
2008-10-22 16:05:59 +02:00
|
|
|
$title = @mb_convert_encoding($title, 'UTF-8', $encoding);
|
|
|
|
}
|
2007-12-12 17:29:16 +01:00
|
|
|
|
2008-10-22 16:05:59 +02:00
|
|
|
if (utf8_strlen($title) > 0) {
|
|
|
|
return $title;
|
|
|
|
} else {
|
|
|
|
// No title, so return filename
|
|
|
|
$uriparts = explode('/', $url);
|
|
|
|
$filename = end($uriparts);
|
|
|
|
unset($uriparts);
|
2007-12-12 17:29:16 +01:00
|
|
|
|
2008-10-22 16:05:59 +02:00
|
|
|
return $filename;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
return false;
|
|
|
|
}
|
2007-12-12 17:29:16 +01:00
|
|
|
}
|
|
|
|
echo '<?xml version="1.0" encoding="utf-8"?>';
|
|
|
|
?>
|
|
|
|
<response>
|
2008-10-22 16:05:59 +02:00
|
|
|
<method>
|
|
|
|
getTitle
|
|
|
|
</method>
|
|
|
|
<result>
|
2008-11-25 16:57:29 +01:00
|
|
|
<?php echo getTitle(GET_URL); ?>
|
2008-10-22 16:05:59 +02:00
|
|
|
</result>
|
|
|
|
</response>
|