aboutsummaryrefslogtreecommitdiff
path: root/www
diff options
context:
space:
mode:
authorChristian Weiske <cweiske@cweiske.de>2016-05-09 21:39:18 +0200
committerChristian Weiske <cweiske@cweiske.de>2016-05-09 21:39:18 +0200
commit833537692e62db2a7dea1c9eb74b79c5311fc39b (patch)
tree495f78c10a4f369d339d03be6b07b8d5708f31ca /www
parent27e154e5fc3dcfb234ad0784ee72c766fe728b64 (diff)
downloadsemanticscuttle-833537692e62db2a7dea1c9eb74b79c5311fc39b.tar.gz
semanticscuttle-833537692e62db2a7dea1c9eb74b79c5311fc39b.tar.bz2
Move URL title method to dedicated class
Diffstat (limited to 'www')
-rw-r--r--www/ajaxGetTitle.php50
1 files changed, 4 insertions, 46 deletions
diff --git a/www/ajaxGetTitle.php b/www/ajaxGetTitle.php
index e1fbe30..b95e29b 100644
--- a/www/ajaxGetTitle.php
+++ b/www/ajaxGetTitle.php
@@ -27,53 +27,11 @@ require_once 'www-header.php';
/* Managing all possible inputs */
isset($_GET['url']) ? define('GET_URL', $_GET['url']): define('GET_URL', '');
+$urlhelper = new SemanticScuttle_UrlHelper();
-function getTitle($url) {
- $fd = @fopen($url, 'r');
- if ($fd) {
- $html = fread($fd, 1750);
- fclose($fd);
-
- // Get title from title tag
- preg_match_all('/<title>(.*)<\/title>/si', $html, $matches);
- $title = $matches[1][0];
-
- $encoding = 'utf-8';
- // Get encoding from charset attribute
- preg_match_all('/<meta.*charset=([^;"]*)">/i', $html, $matches);
- if (isset($matches[1][0])) {
- $encoding = strtoupper($matches[1][0]);
- }
-
- // Convert to UTF-8 from the original encoding
- if (function_exists("mb_convert_encoding")) {
- $title = @mb_convert_encoding($title, 'UTF-8', $encoding);
- }
-
- $title = trim($title);
-
- if (utf8_strlen($title) > 0) {
- $title = html_entity_decode($title, ENT_QUOTES, 'UTF-8');
- return $title;
- } else {
- // No title, so return filename
- $uriparts = explode('/', $url);
- $filename = end($uriparts);
- unset($uriparts);
-
- return $filename;
- }
- } else {
- return false;
- }
-}
-echo '<?xml version="1.0" encoding="utf-8"?>';
+echo '<?xml version="1.0" encoding="utf-8"?>' . "\n";
?>
<response>
-<method>
-getTitle
-</method>
-<result>
-<?php echo getTitle(GET_URL); ?>
-</result>
+ <method>getTitle</method>
+ <result><?php echo htmlspecialchars($urlhelper->getTitle(GET_URL)); ?></result>
</response>