aboutsummaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorGravatar Marien Fressinaud <dev@marienfressinaud.fr> 2014-12-12 18:58:34 +0100
committerGravatar Marien Fressinaud <dev@marienfressinaud.fr> 2014-12-12 18:58:34 +0100
commiteabcf90f5266b746503fef5c438971d7d6a1689e (patch)
tree7f2d6d38d297a0f4c4b4e7d52e0d59ce7f7f025b /lib
parent99763412c2f49e4e52b5a0343bb465141be76188 (diff)
parent6078888de631ea105410079888838503fd7acb3d (diff)
Merge branch 'dev' into beta
Conflicts: app/i18n/en.php app/i18n/fr.php
Diffstat (limited to 'lib')
-rw-r--r--lib/Minz/Error.php2
-rw-r--r--lib/Minz/Translate.php114
-rw-r--r--lib/SimplePie/SimplePie.php4
-rw-r--r--lib/SimplePie/SimplePie/Locator.php2
-rw-r--r--lib/lib_rss.php17
5 files changed, 95 insertions, 44 deletions
diff --git a/lib/Minz/Error.php b/lib/Minz/Error.php
index c8222a430..e5f3dff07 100644
--- a/lib/Minz/Error.php
+++ b/lib/Minz/Error.php
@@ -19,7 +19,7 @@ class Minz_Error {
* > $logs['notice']
* @param $redirect indique s'il faut forcer la redirection (les logs ne seront pas transmis)
*/
- public static function error ($code = 404, $logs = array (), $redirect = false) {
+ public static function error ($code = 404, $logs = array (), $redirect = true) {
$logs = self::processLogs ($logs);
$error_filename = APP_PATH . '/Controllers/errorController.php';
diff --git a/lib/Minz/Translate.php b/lib/Minz/Translate.php
index 8c2f90041..e7efb8665 100644
--- a/lib/Minz/Translate.php
+++ b/lib/Minz/Translate.php
@@ -5,71 +5,117 @@
*/
/**
- * La classe Translate se charge de la traduction
- * Utilise les fichiers du répertoire /app/i18n/
+ * This class is used for the internationalization.
+ * It uses files in `./app/i18n/`
*/
class Minz_Translate {
/**
- * $language est la langue à afficher
+ * $lang_name is the name of the current language to use.
*/
- private static $language;
-
+ private static $lang_name;
+
+ /**
+ * $lang_path is the pathname of i18n files (e.g. ./app/i18n/en/).
+ */
+ private static $lang_path;
+
/**
- * $translates est le tableau de correspondance
- * $key => $traduction
+ * $translates is a cache for i18n translation.
*/
private static $translates = array();
-
+
/**
- * Inclus le fichier de langue qui va bien
- * l'enregistre dans $translates
+ * Load $lang_name and $lang_path based on configuration and selected language.
*/
public static function init() {
$l = Minz_Configuration::language();
- self::$language = Minz_Session::param('language', $l);
-
- $l_path = APP_PATH . '/i18n/' . self::$language . '.php';
-
- if (file_exists($l_path)) {
- self::$translates = include($l_path);
- }
+ self::$lang_name = Minz_Session::param('language', $l);
+ self::$lang_path = APP_PATH . '/i18n/' . self::$lang_name . '/';
}
-
+
/**
- * Alias de init
+ * Alias for init().
*/
public static function reset() {
self::init();
}
-
+
/**
- * Traduit une clé en sa valeur du tableau $translates
- * @param $key la clé à traduire
- * @return la valeur correspondante à la clé
- * > si non présente dans le tableau, on retourne la clé elle-même
+ * Translate a key into its corresponding value based on selected language.
+ * @param $key the key to translate.
+ * @param additional parameters for variable keys.
+ * @return the value corresponding to the key.
+ * If no value is found, return the key itself.
*/
public static function t($key) {
- $translate = $key;
-
- if (isset(self::$translates[$key])) {
- $translate = self::$translates[$key];
+ $group = explode('.', $key);
+
+ if (count($group) < 2) {
+ Minz_Log::debug($key . ' is not in a valid format');
+ $top_level = 'gen';
+ } else {
+ $top_level = array_shift($group);
}
+ $filename = self::$lang_path . $top_level . '.php';
+
+ // Try to load the i18n file if it's not done yet.
+ if (!isset(self::$translates[$top_level])) {
+ if (!file_exists($filename)) {
+ Minz_Log::debug($top_level . ' is not a valid top level key');
+ return $key;
+ }
+
+ self::$translates[$top_level] = include($filename);
+ }
+
+ // Go through the i18n keys to get the correct translation value.
+ $translates = self::$translates[$top_level];
+ $size_group = count($group);
+ $level_processed = 0;
+ $translation_value = $key;
+ foreach ($group as $i18n_level) {
+ $level_processed++;
+ if (!isset($translates[$i18n_level])) {
+ Minz_Log::debug($key . ' is not a valid key');
+ return $key;
+ }
+
+ if ($level_processed < $size_group) {
+ $translates = $translates[$i18n_level];
+ } else {
+ $translation_value = $translates[$i18n_level];
+ }
+ }
+
+ if (is_array($translation_value)) {
+ if (isset($translation_value['_'])) {
+ $translation_value = $translation_value['_'];
+ } else {
+ Minz_Log::debug($key . ' is not a valid key');
+ return $key;
+ }
+ }
+
+ // Get the facultative arguments to replace i18n variables.
$args = func_get_args();
unset($args[0]);
-
- return vsprintf($translate, $args);
+
+ return vsprintf($translation_value, $args);
}
-
+
/**
- * Retourne la langue utilisée actuellement
- * @return la langue
+ * Return the current language.
*/
public static function language() {
- return self::$language;
+ return self::$lang_name;
}
}
+
+/**
+ * Alias for Minz_Translate::t()
+ */
function _t($key) {
$args = func_get_args();
unset($args[0]);
diff --git a/lib/SimplePie/SimplePie.php b/lib/SimplePie/SimplePie.php
index 84001dd9a..dc4bbb6cb 100644
--- a/lib/SimplePie/SimplePie.php
+++ b/lib/SimplePie/SimplePie.php
@@ -1582,13 +1582,15 @@ class SimplePie
if (!$locate->is_feed($file))
{
+ $copyStatusCode = $file->status_code; //FreshRSS
+ $copyContentType = $file->headers['content-type']; //FreshRSS
// We need to unset this so that if SimplePie::set_file() has been called that object is untouched
unset($file);
try
{
if (!($file = $locate->find($this->autodiscovery, $this->all_discovered_feeds)))
{
- $this->error = "A feed could not be found at $this->feed_url. A feed with an invalid mime type may fall victim to this error, or " . SIMPLEPIE_NAME . " was unable to auto-discover it.. Use force_feed() if you are certain this URL is a real feed.";
+ $this->error = "A feed could not be found at `$this->feed_url`; the status code is `$copyStatusCode` and content-type is `$copyContentType`"; //FreshRSS
$this->registry->call('Misc', 'error', array($this->error, E_USER_NOTICE, __FILE__, __LINE__));
return false;
}
diff --git a/lib/SimplePie/SimplePie/Locator.php b/lib/SimplePie/SimplePie/Locator.php
index 90ee7a302..4e5f7c1ca 100644
--- a/lib/SimplePie/SimplePie/Locator.php
+++ b/lib/SimplePie/SimplePie/Locator.php
@@ -148,7 +148,7 @@ class SimplePie_Locator
{
$sniffer = $this->registry->create('Content_Type_Sniffer', array($file));
$sniffed = $sniffer->get_type();
- if (in_array($sniffed, array('application/rss+xml', 'application/rdf+xml', 'text/rdf', 'application/atom+xml', 'text/xml', 'application/xml')))
+ if (in_array($sniffed, array('application/rss+xml', 'application/rdf+xml', 'text/rdf', 'application/atom+xml', 'text/xml', 'application/xml', 'application/x-rss+xml'))) //FreshRSS
{
return true;
}
diff --git a/lib/lib_rss.php b/lib/lib_rss.php
index e7ca95aba..264c69d58 100644
--- a/lib/lib_rss.php
+++ b/lib/lib_rss.php
@@ -79,11 +79,11 @@ function format_bytes($bytes, $precision = 2, $system = 'IEC') {
}
function timestamptodate ($t, $hour = true) {
- $month = _t(date('M', $t));
+ $month = _t('gen.date.' . date('M', $t));
if ($hour) {
- $date = _t('format_date_hour', $month);
+ $date = _t('gen.date.format_date_hour', $month);
} else {
- $date = _t('format_date', $month);
+ $date = _t('gen.date.format_date', $month);
}
return @date ($date, $t);
@@ -110,7 +110,7 @@ function html_only_entity_decode($text) {
function customSimplePie() {
$limits = Minz_Configuration::limits();
$simplePie = new SimplePie();
- $simplePie->set_useragent(_t('freshrss') . '/' . FRESHRSS_VERSION . ' (' . PHP_OS . '; ' . FRESHRSS_WEBSITE . ') ' . SIMPLEPIE_NAME . '/' . SIMPLEPIE_VERSION);
+ $simplePie->set_useragent(_t('gen.freshrss') . '/' . FRESHRSS_VERSION . ' (' . PHP_OS . '; ' . FRESHRSS_WEBSITE . ') ' . SIMPLEPIE_NAME . '/' . SIMPLEPIE_VERSION);
$simplePie->set_cache_location(CACHE_PATH);
$simplePie->set_cache_duration($limits['cache_duration']);
$simplePie->set_timeout($limits['timeout']);
@@ -242,11 +242,14 @@ function is_referer_from_same_domain() {
$host = parse_url(((isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] === 'on') ? 'https://' : 'http://') .
(empty($_SERVER['HTTP_HOST']) ? $_SERVER['SERVER_NAME'] : $_SERVER['HTTP_HOST']));
$referer = parse_url($_SERVER['HTTP_REFERER']);
- if (empty($host['scheme']) || empty($referer['scheme']) || $host['scheme'] !== $referer['scheme'] ||
- empty($host['host']) || empty($referer['host']) || $host['host'] !== $referer['host']) {
+ if (empty($host['host']) || empty($referer['host']) || $host['host'] !== $referer['host']) {
return false;
}
- return (isset($host['port']) ? $host['port'] : 0) === (isset($referer['port']) ? $referer['port'] : 0);
+ //TODO: check 'scheme', taking into account the case of a proxy
+ if ((isset($host['port']) ? $host['port'] : 0) !== (isset($referer['port']) ? $referer['port'] : 0)) {
+ return false;
+ }
+ return true;
}