aboutsummaryrefslogtreecommitdiff
path: root/www/ajaxGetTitle.php
diff options
context:
space:
mode:
authorSilvio Rhatto <rhatto@riseup.net>2020-10-01 17:48:30 -0300
committerSilvio Rhatto <rhatto@riseup.net>2020-10-01 17:48:30 -0300
commitb3bbae81b7b2c8132a4e43cfa49b81fae58dd8e5 (patch)
tree28f70b6caff40a0b104177f893630c796e540e77 /www/ajaxGetTitle.php
parent9a5f69a671a0ad841d9914293efbdcef0e1b75bf (diff)
parentea04385bc16de6b7b65aab75c5c33cfe2d71ea84 (diff)
downloadsemanticscuttle-b3bbae81b7b2c8132a4e43cfa49b81fae58dd8e5.tar.gz
semanticscuttle-b3bbae81b7b2c8132a4e43cfa49b81fae58dd8e5.tar.bz2
Merge remote-tracking branch 'querwurzelt/master' into mergev0.99.0
Diffstat (limited to 'www/ajaxGetTitle.php')
-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>