From a175bebc4074290658bbcce92013367e4997d9e7 Mon Sep 17 00:00:00 2001 From: Thomas Citharel Date: Sun, 24 Aug 2014 22:43:44 +0200 Subject: [PATCH] begin implement metadata --- inc/poche/Poche.class.php | 15 ++++++++ inc/poche/Tools.class.php | 80 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 95 insertions(+) diff --git a/inc/poche/Poche.class.php b/inc/poche/Poche.class.php index c80e5d2..428b9cf 100755 --- a/inc/poche/Poche.class.php +++ b/inc/poche/Poche.class.php @@ -147,6 +147,21 @@ class Poche $content = Tools::getPageContent($url); $title = ($content['rss']['channel']['item']['title'] != '') ? $content['rss']['channel']['item']['title'] : _('Untitled'); $body = $content['rss']['channel']['item']['description']; + // TODO : convert date + if ($content['rss']['channel']['item']['updated'] == '') { // ATOM + if ($content['rss']['channel']['item']['pubDate'] == '') { // RSS + if($content['rss']['channel']['item']['dc:date'] == '') { // other + $date = '';} + else {$date = $content['rss']['channel']['item']['dc:date'];} + } + else {$date = $content['rss']['channel']['item']['pubDate'];} + } + else { + $date = $content['rss']['channel']['item']['updated']; + } + + $author = ($content['rss']['channel']['item']['author'] != '') ? $content['rss']['channel']['item']['author'] : _('Unknown author'); + $language = ($content['rss']['channel']['item']['language'] != '') ? $content['rss']['channel']['item']['language'] : ''; // clean content from prevent xss attack $purifier = $this->_getPurifier(); diff --git a/inc/poche/Tools.class.php b/inc/poche/Tools.class.php index 63137d7..11cc471 100755 --- a/inc/poche/Tools.class.php +++ b/inc/poche/Tools.class.php @@ -424,4 +424,84 @@ final class Tools return str_replace('+', '', $token); } + // Part of Text_LanguageDetect + + /** + * Maps ISO 639-1 2-letter language codes to the language names + * in the language database + * + * Not all languages have a 2 letter code, so some are missing + * + * @var array + */ + + public static $code2ToName = array( + 'ar' => 'arabic', + 'az' => 'azeri', + 'bg' => 'bulgarian', + 'bn' => 'bengali', + 'cs' => 'czech', + 'cy' => 'welsh', + 'da' => 'danish', + 'de' => 'german', + 'en' => 'english', + 'es' => 'spanish', + 'et' => 'estonian', + 'fa' => 'farsi', + 'fi' => 'finnish', + 'fr' => 'french', + 'ha' => 'hausa', + 'hi' => 'hindi', + 'hr' => 'croatian', + 'hu' => 'hungarian', + 'id' => 'indonesian', + 'is' => 'icelandic', + 'it' => 'italian', + 'kk' => 'kazakh', + 'ky' => 'kyrgyz', + 'la' => 'latin', + 'lt' => 'lithuanian', + 'lv' => 'latvian', + 'mk' => 'macedonian', + 'mn' => 'mongolian', + 'ne' => 'nepali', + 'nl' => 'dutch', + 'no' => 'norwegian', + 'pl' => 'polish', + 'ps' => 'pashto', + 'pt' => 'portuguese', + 'ro' => 'romanian', + 'ru' => 'russian', + 'sk' => 'slovak', + 'sl' => 'slovene', + 'so' => 'somali', + 'sq' => 'albanian', + 'sr' => 'serbian', + 'sv' => 'swedish', + 'sw' => 'swahili', + 'tl' => 'tagalog', + 'tr' => 'turkish', + 'uk' => 'ukrainian', + 'ur' => 'urdu', + 'uz' => 'uzbek', + 'vi' => 'vietnamese', + ); + + /** + * Returns the language name for the given 2-letter ISO 639-1 code. + * + * @param string $code Two-letter language code (e.g. "sv") + * + * @return string English language name like "swedish" + */ + + public static function code2ToName($code) + { + $lang = strtolower($code); + if (!isset(self::$code2ToName[$code])) { + return null; + } + return self::$code2ToName[$code]; + } + }