summaryrefslogtreecommitdiff
path: root/lib/lib_rss.php
diff options
context:
space:
mode:
authorGravatar Alexandre Alapetite <alexandre@alapetite.fr> 2013-12-15 03:30:24 +0100
committerGravatar Alexandre Alapetite <alexandre@alapetite.fr> 2013-12-15 03:30:24 +0100
commit878e96202e8a22e4857b98e29b0a1fce68eccbc9 (patch)
treef9233c3b48a0cd6e0ac2536ddcc1897201595ad4 /lib/lib_rss.php
parent4af233e1f736eb2256e5e1696418635165467855 (diff)
Grosse refactorisation pour permettre le chargement automatique des classes
C'est parti de changements pour https://github.com/marienfressinaud/FreshRSS/issues/255 et finalement j'ai continué la refactorisation... Ajout de préfixes FreshRSS_ et Minz_ sur le modèle de SimplePie_. Toutes les classes sont maintenant en chargement automatique (devrait améliorer les performances en évitant de charger plein de classes inutilisées, et faciliter la maintenance). Suppression de set_include_path(). Si souhaité, certaines classes de Minz pourraient être déplacées dans un sous-répertoire, par exemple les exceptions. Tests et relecture nécessaires.
Diffstat (limited to 'lib/lib_rss.php')
-rw-r--r--lib/lib_rss.php45
1 files changed, 35 insertions, 10 deletions
diff --git a/lib/lib_rss.php b/lib/lib_rss.php
index 4f5b90b61..2fdfd4bd8 100644
--- a/lib/lib_rss.php
+++ b/lib/lib_rss.php
@@ -15,6 +15,31 @@ if (!function_exists('json_encode')) {
}
}
+//<Auto-loading>
+function classAutoloader($class) {
+ if (strpos($class, 'FreshRSS') === 0) {
+ $components = explode('_', $class);
+ switch (count($components)) {
+ case 1:
+ include(APP_PATH . '/' . $components[0] . '.php');
+ return;
+ case 2:
+ include(APP_PATH . '/Models/' . $components[1] . '.php');
+ return;
+ case 3: //Controllers, Exceptions
+ include(APP_PATH . '/' . $components[2] . 's/' . $components[1] . $components[2] . '.php');
+ return;
+ }
+ } elseif (strpos($class, 'Minz') === 0) {
+ include(LIB_PATH . '/' . str_replace('_', '/', $class) . '.php');
+ } elseif (strpos($class, 'SimplePie') === 0) {
+ include(LIB_PATH . '/SimplePie/' . str_replace('_', '/', $class) . '.php');
+ }
+}
+
+spl_autoload_register('classAutoloader');
+//</Auto-loading>
+
function checkUrl($url) {
if (empty ($url)) {
return '';
@@ -33,7 +58,7 @@ function checkUrl($url) {
// vérifie qu'on est connecté
function is_logged () {
- return Session::param ('mail') != false;
+ return Minz_Session::param ('mail') != false;
}
// vérifie que le système d'authentification est configuré
@@ -63,11 +88,11 @@ function formatBytes($bytes, $precision = 2, $system = 'IEC') {
}
function timestamptodate ($t, $hour = true) {
- $month = Translate::t (date('M', $t));
+ $month = Minz_Translate::t (date('M', $t));
if ($hour) {
- $date = Translate::t ('format_date_hour', $month);
+ $date = Minz_Translate::t ('format_date_hour', $month);
} else {
- $date = Translate::t ('format_date', $month);
+ $date = Minz_Translate::t ('format_date', $month);
}
return @date ($date, $t);
@@ -123,10 +148,10 @@ function opml_import ($xml) {
$opml = simplexml_import_dom($dom);
if (!$opml) {
- throw new OpmlException ();
+ throw new FreshRSS_Opml_Exception ();
}
- $catDAO = new CategoryDAO();
+ $catDAO = new FreshRSS_CategoryDAO();
$catDAO->checkDefault();
$defCat = $catDAO->getDefault();
@@ -152,10 +177,10 @@ function opml_import ($xml) {
// Y ne sera pas ajouté et le flux non plus vu que l'id
// de sa catégorie n'exisera pas
$title = htmlspecialchars($title, ENT_QUOTES, 'UTF-8');
- $catDAO = new CategoryDAO ();
+ $catDAO = new FreshRSS_CategoryDAO ();
$cat = $catDAO->searchByName ($title);
if ($cat === false) {
- $cat = new Category ($title);
+ $cat = new FreshRSS_Category ($title);
$values = array (
'name' => $cat->name (),
'color' => $cat->color ()
@@ -204,7 +229,7 @@ function getFeed ($outline, $cat_id) {
$title = (string) $outline['title'];
}
$title = htmlspecialchars($title, ENT_QUOTES, 'UTF-8');
- $feed = new Feed ($url);
+ $feed = new FreshRSS_Feed ($url);
$feed->_category ($cat_id);
$feed->_name ($title);
if (isset($outline['htmlUrl'])) {
@@ -250,7 +275,7 @@ function get_content_by_parsing ($url, $path) {
function lazyimg($content) {
return preg_replace(
'/<img([^>]+?)src=[\'"]([^"\']+)[\'"]([^>]*)>/i',
- '<img$1src="' . Url::display('/themes/icons/grey.gif') . '" data-original="$2"$3>',
+ '<img$1src="' . Minz_Url::display('/themes/icons/grey.gif') . '" data-original="$2"$3>',
$content
);
}