aboutsummaryrefslogtreecommitdiff
path: root/app/Models
diff options
context:
space:
mode:
authorGravatar Alexandre Alapetite <alexandre@alapetite.fr> 2014-01-04 01:47:07 +0100
committerGravatar Alexandre Alapetite <alexandre@alapetite.fr> 2014-01-04 01:47:07 +0100
commitd7c929e53b889460cd416d2864563e16200d2a01 (patch)
treeb91657455d48fa31aaa9b0bc6d8828db3622db1d /app/Models
parentcf8b3d080942ad682665569250038eda494d346b (diff)
parentc80ab2af7e0f6de4acf6dc02fab208d7b5baff45 (diff)
Merge remote-tracking branch 'origin/dev' into beta
Diffstat (limited to 'app/Models')
-rw-r--r--app/Models/Category.php2
-rw-r--r--app/Models/Configuration.php424
-rw-r--r--app/Models/ConfigurationDAO.php161
-rw-r--r--app/Models/Entry.php6
-rw-r--r--app/Models/Feed.php32
-rw-r--r--app/Models/LogDAO.php32
-rw-r--r--app/Models/UserDAO.php36
7 files changed, 234 insertions, 459 deletions
diff --git a/app/Models/Category.php b/app/Models/Category.php
index e70d1303f..8e1e44ef8 100644
--- a/app/Models/Category.php
+++ b/app/Models/Category.php
@@ -48,7 +48,7 @@ class FreshRSS_Category extends Minz_Model {
return $this->nbNotRead;
}
public function feeds () {
- if (is_null ($this->feeds)) {
+ if ($this->feeds === null) {
$feedDAO = new FreshRSS_FeedDAO ();
$this->feeds = $feedDAO->listByCategory ($this->id ());
$this->nbFeed = 0;
diff --git a/app/Models/Configuration.php b/app/Models/Configuration.php
index cb2f90655..c29e74603 100644
--- a/app/Models/Configuration.php
+++ b/app/Models/Configuration.php
@@ -1,263 +1,184 @@
<?php
-class FreshRSS_Configuration extends Minz_Model {
- private $available_languages = array (
+class FreshRSS_Configuration {
+ private $filename;
+
+ private $data = array(
+ 'language' => 'en',
+ 'old_entries' => 3,
+ 'keep_history_default' => 0,
+ 'mail_login' => '',
+ 'token' => '',
+ 'posts_per_page' => 20,
+ 'view_mode' => 'normal',
+ 'default_view' => 'not_read',
+ 'auto_load_more' => true,
+ 'display_posts' => false,
+ 'onread_jump_next' => true,
+ 'lazyload' => true,
+ 'sort_order' => 'DESC',
+ 'anon_access' => false,
+ 'mark_when' => array(
+ 'article' => true,
+ 'site' => true,
+ 'scroll' => false,
+ 'reception' => false,
+ ),
+ 'theme' => 'default',
+ 'shortcuts' => array(
+ 'mark_read' => 'r',
+ 'mark_favorite' => 'f',
+ 'go_website' => 'space',
+ 'next_entry' => 'j',
+ 'prev_entry' => 'k',
+ 'collapse_entry' => 'c',
+ 'load_more' => 'm',
+ 'auto_share' => 's',
+ ),
+ 'topline_read' => true,
+ 'topline_favorite' => true,
+ 'topline_date' => true,
+ 'topline_link' => true,
+ 'bottomline_read' => true,
+ 'bottomline_favorite' => true,
+ 'bottomline_sharing' => true,
+ 'bottomline_tags' => true,
+ 'bottomline_date' => true,
+ 'bottomline_link' => true,
+ 'sharing' => array(
+ 'shaarli' => '',
+ 'poche' => '',
+ 'diaspora' => '',
+ 'twitter' => true,
+ 'g+' => true,
+ 'facebook' => true,
+ 'email' => true,
+ 'print' => true,
+ ),
+ );
+
+ private $available_languages = array(
'en' => 'English',
'fr' => 'Français',
);
- private $language;
- private $posts_per_page;
- private $view_mode;
- private $default_view;
- private $display_posts;
- private $onread_jump_next;
- private $lazyload;
- private $sort_order;
- private $old_entries;
- private $keep_history_default;
- private $shortcuts = array ();
- private $mail_login = '';
- private $mark_when = array ();
- private $sharing = array ();
- private $theme;
- private $anon_access;
- private $token;
- private $auto_load_more;
- private $topline_read;
- private $topline_favorite;
- private $topline_date;
- private $topline_link;
- private $bottomline_read;
- private $bottomline_favorite;
- private $bottomline_sharing;
- private $bottomline_tags;
- private $bottomline_date;
- private $bottomline_link;
- public function __construct () {
- $confDAO = new FreshRSS_ConfigurationDAO ();
- $this->_language ($confDAO->language);
- $this->_postsPerPage ($confDAO->posts_per_page);
- $this->_viewMode ($confDAO->view_mode);
- $this->_defaultView ($confDAO->default_view);
- $this->_displayPosts ($confDAO->display_posts);
- $this->_onread_jump_next ($confDAO->onread_jump_next);
- $this->_lazyload ($confDAO->lazyload);
- $this->_sortOrder ($confDAO->sort_order);
- $this->_oldEntries ($confDAO->old_entries);
- $this->_keepHistoryDefault($confDAO->keep_history_default);
- $this->_shortcuts ($confDAO->shortcuts);
- $this->_mailLogin ($confDAO->mail_login);
- $this->_markWhen ($confDAO->mark_when);
- $this->_sharing ($confDAO->sharing);
- $this->_theme ($confDAO->theme);
- FreshRSS_Themes::setThemeId ($confDAO->theme);
- $this->_anonAccess ($confDAO->anon_access);
- $this->_token ($confDAO->token);
- $this->_autoLoadMore ($confDAO->auto_load_more);
- $this->_topline_read ($confDAO->topline_read);
- $this->_topline_favorite ($confDAO->topline_favorite);
- $this->_topline_date ($confDAO->topline_date);
- $this->_topline_link ($confDAO->topline_link);
- $this->_bottomline_read ($confDAO->bottomline_read);
- $this->_bottomline_favorite ($confDAO->bottomline_favorite);
- $this->_bottomline_sharing ($confDAO->bottomline_sharing);
- $this->_bottomline_tags ($confDAO->bottomline_tags);
- $this->_bottomline_date ($confDAO->bottomline_date);
- $this->_bottomline_link ($confDAO->bottomline_link);
- }
+ public function __construct ($user) {
+ $this->filename = DATA_PATH . '/' . $user . '_user.php';
- public function availableLanguages () {
- return $this->available_languages;
- }
- public function language () {
- return $this->language;
- }
- public function postsPerPage () {
- return $this->posts_per_page;
- }
- public function viewMode () {
- return $this->view_mode;
- }
- public function defaultView () {
- return $this->default_view;
- }
- public function displayPosts () {
- return $this->display_posts;
- }
- public function onread_jump_next () {
- return $this->onread_jump_next;
- }
- public function lazyload () {
- return $this->lazyload;
- }
- public function sortOrder () {
- return $this->sort_order;
- }
- public function oldEntries () {
- return $this->old_entries;
- }
- public function keepHistoryDefault() {
- return $this->keep_history_default;
- }
- public function shortcuts () {
- return $this->shortcuts;
- }
- public function mailLogin () {
- return $this->mail_login;
- }
- public function markWhen () {
- return $this->mark_when;
- }
- public function markWhenArticle () {
- return $this->mark_when['article'];
- }
- public function markWhenSite () {
- return $this->mark_when['site'];
+ $data = @include($this->filename);
+ if (!is_array($data)) {
+ throw new Minz_PermissionDeniedException($this->filename);
+ }
+
+ foreach ($data as $key => $value) {
+ if (isset($this->data[$key])) {
+ $function = '_' . $key;
+ $this->$function($value);
+ }
+ }
+ $this->data['user'] = $user;
}
- public function markWhenScroll () {
- return $this->mark_when['scroll'];
+
+ public function save() {
+ @rename($this->filename, $this->filename . '.bak.php');
+ if (file_put_contents($this->filename, "<?php\n return " . var_export($this->data, true) . ';', LOCK_EX) === false) {
+ throw new Minz_PermissionDeniedException($this->filename);
+ }
+ if (function_exists('opcache_invalidate')) {
+ opcache_invalidate($this->filename); //Clear PHP 5.5+ cache for include
+ }
+ invalidateHttpCache();
+ return true;
}
- public function markUponReception () {
- return $this->mark_when['reception'];
+
+ public function __get($name) {
+ if (array_key_exists($name, $this->data)) {
+ return $this->data[$name];
+ } else {
+ $trace = debug_backtrace();
+ trigger_error('Undefined FreshRSS_Configuration->' . $name . 'in ' . $trace[0]['file'] . ' line ' . $trace[0]['line'], E_USER_NOTICE); //TODO: Use Minz exceptions
+ return null;
+ }
}
- public function sharing ($key = false) {
+
+ public function sharing($key = false) {
if ($key === false) {
- return $this->sharing;
- } elseif (isset ($this->sharing[$key])) {
- return $this->sharing[$key];
+ return $this->data['sharing'];
+ }
+ if (isset($this->data['sharing'][$key])) {
+ return $this->data['sharing'][$key];
}
return false;
}
- public function theme () {
- return $this->theme;
- }
- public function anonAccess () {
- return $this->anon_access;
- }
- public function token () {
- return $this->token;
- }
- public function autoLoadMore () {
- return $this->auto_load_more;
- }
- public function toplineRead () {
- return $this->topline_read;
- }
- public function toplineFavorite () {
- return $this->topline_favorite;
- }
- public function toplineDate () {
- return $this->topline_date;
- }
- public function toplineLink () {
- return $this->topline_link;
- }
- public function bottomlineRead () {
- return $this->bottomline_read;
- }
- public function bottomlineFavorite () {
- return $this->bottomline_favorite;
- }
- public function bottomlineSharing () {
- return $this->bottomline_sharing;
- }
- public function bottomlineTags () {
- return $this->bottomline_tags;
- }
- public function bottomlineDate () {
- return $this->bottomline_date;
- }
- public function bottomlineLink () {
- return $this->bottomline_link;
+
+ public function availableLanguages() {
+ return $this->available_languages;
}
- public function _language ($value) {
- if (!isset ($this->available_languages[$value])) {
+ public function _language($value) {
+ if (!isset($this->available_languages[$value])) {
$value = 'en';
}
- $this->language = $value;
+ $this->data['language'] = $value;
}
- public function _postsPerPage ($value) {
+ public function _posts_per_page ($value) {
$value = intval($value);
- $this->posts_per_page = $value > 0 ? $value : 10;
+ $this->data['posts_per_page'] = $value > 0 ? $value : 10;
}
- public function _viewMode ($value) {
- if ($value == 'global' || $value == 'reader') {
- $this->view_mode = $value;
+ public function _view_mode ($value) {
+ if ($value === 'global' || $value === 'reader') {
+ $this->data['view_mode'] = $value;
} else {
- $this->view_mode = 'normal';
+ $this->data['view_mode'] = 'normal';
}
}
- public function _defaultView ($value) {
- if ($value == 'not_read') {
- $this->default_view = 'not_read';
- } else {
- $this->default_view = 'all';
- }
+ public function _default_view ($value) {
+ $this->data['default_view'] = $value === 'all' ? 'all' : 'not_read';
}
- public function _displayPosts ($value) {
- if ($value == 'yes') {
- $this->display_posts = 'yes';
- } else {
- $this->display_posts = 'no';
- }
+ public function _display_posts ($value) {
+ $this->data['display_posts'] = ((bool)$value) && $value !== 'no';
}
public function _onread_jump_next ($value) {
- if ($value == 'no') {
- $this->onread_jump_next = 'no';
- } else {
- $this->onread_jump_next = 'yes';
- }
+ $this->data['onread_jump_next'] = ((bool)$value) && $value !== 'no';
}
public function _lazyload ($value) {
- if ($value == 'no') {
- $this->lazyload = 'no';
- } else {
- $this->lazyload = 'yes';
- }
+ $this->data['lazyload'] = ((bool)$value) && $value !== 'no';
}
- public function _sortOrder ($value) {
- $this->sort_order = $value === 'ASC' ? 'ASC' : 'DESC';
+ public function _sort_order ($value) {
+ $this->data['sort_order'] = $value === 'ASC' ? 'ASC' : 'DESC';
}
- public function _oldEntries($value) {
+ public function _old_entries($value) {
$value = intval($value);
- $this->old_entries = $value > 0 ? $value : 3;
+ $this->data['old_entries'] = $value > 0 ? $value : 3;
}
- public function _keepHistoryDefault($value) {
+ public function _keep_history_default($value) {
$value = intval($value);
- $this->keep_history_default = $value >= -1 ? $value : 0;
+ $this->data['keep_history_default'] = $value >= -1 ? $value : 0;
}
public function _shortcuts ($values) {
foreach ($values as $key => $value) {
- $this->shortcuts[$key] = $value;
+ if (isset($this->data['shortcuts'][$key])) {
+ $this->data['shortcuts'][$key] = $value;
+ }
}
}
- public function _mailLogin ($value) {
- if (filter_var ($value, FILTER_VALIDATE_EMAIL)) {
- $this->mail_login = $value;
- } elseif ($value == false) {
- $this->mail_login = false;
+ public function _mail_login ($value) {
+ $value = filter_var($value, FILTER_VALIDATE_EMAIL);
+ if ($value) {
+ $this->data['mail_login'] = $value;
+ } else {
+ $this->data['mail_login'] = '';
}
}
- public function _markWhen ($values) {
- if(!isset($values['article'])) {
- $values['article'] = 'yes';
- }
- if(!isset($values['site'])) {
- $values['site'] = 'yes';
- }
- if(!isset($values['scroll'])) {
- $values['scroll'] = 'yes';
- }
- if(!isset($values['reception'])) {
- $values['reception'] = 'no';
+ public function _anon_access ($value) {
+ $this->data['anon_access'] = ((bool)$value) && $value !== 'no';
+ }
+ public function _mark_when ($values) {
+ foreach ($values as $key => $value) {
+ if (isset($this->data['mark_when'][$key])) {
+ $this->data['mark_when'][$key] = ((bool)$value) && $value !== 'no';
+ }
}
-
- $this->mark_when['article'] = $values['article'];
- $this->mark_when['site'] = $values['site'];
- $this->mark_when['scroll'] = $values['scroll'];
- $this->mark_when['reception'] = $values['reception'];
}
public function _sharing ($values) {
$are_url = array ('shaarli', 'poche', 'diaspora');
@@ -273,61 +194,50 @@ class FreshRSS_Configuration extends Minz_Model {
if (!$is_url) {
$value = '';
}
- } elseif(!is_bool ($value)) {
+ } elseif (!is_bool($value)) {
$value = true;
}
- $this->sharing[$key] = $value;
+ $this->data['sharing'][$key] = $value;
}
}
- public function _theme ($value) {
- $this->theme = $value;
- }
- public function _anonAccess ($value) {
- if ($value == 'yes') {
- $this->anon_access = 'yes';
- } else {
- $this->anon_access = 'no';
- }
+ public function _theme($value) {
+ $this->data['theme'] = $value;
}
- public function _token ($value) {
- $this->token = $value;
+ public function _token($value) {
+ $this->data['token'] = $value;
}
- public function _autoLoadMore ($value) {
- if ($value == 'yes') {
- $this->auto_load_more = 'yes';
- } else {
- $this->auto_load_more = 'no';
- }
+ public function _auto_load_more($value) {
+ $this->data['auto_load_more'] = ((bool)$value) && $value !== 'no';
}
- public function _topline_read ($value) {
- $this->topline_read = $value === 'yes';
+ public function _topline_read($value) {
+ $this->data['topline_read'] = ((bool)$value) && $value !== 'no';
}
- public function _topline_favorite ($value) {
- $this->topline_favorite = $value === 'yes';
+ public function _topline_favorite($value) {
+ $this->data['topline_favorite'] = ((bool)$value) && $value !== 'no';
}
- public function _topline_date ($value) {
- $this->topline_date = $value === 'yes';
+ public function _topline_date($value) {
+ $this->data['topline_date'] = ((bool)$value) && $value !== 'no';
}
- public function _topline_link ($value) {
- $this->topline_link = $value === 'yes';
+ public function _topline_link($value) {
+ $this->data['topline_link'] = ((bool)$value) && $value !== 'no';
}
- public function _bottomline_read ($value) {
- $this->bottomline_read = $value === 'yes';
+ public function _bottomline_read($value) {
+ $this->data['bottomline_read'] = ((bool)$value) && $value !== 'no';
}
- public function _bottomline_favorite ($value) {
- $this->bottomline_favorite = $value === 'yes';
+ public function _bottomline_favorite($value) {
+ $this->data['bottomline_favorite'] = ((bool)$value) && $value !== 'no';
}
- public function _bottomline_sharing ($value) {
- $this->bottomline_sharing = $value === 'yes';
+ public function _bottomline_sharing($value) {
+ $this->data['bottomline_sharing'] = ((bool)$value) && $value !== 'no';
}
- public function _bottomline_tags ($value) {
- $this->bottomline_tags = $value === 'yes';
+ public function _bottomline_tags($value) {
+ $this->data['bottomline_tags'] = ((bool)$value) && $value !== 'no';
}
- public function _bottomline_date ($value) {
- $this->bottomline_date = $value === 'yes';
+ public function _bottomline_date($value) {
+ $this->data['bottomline_date'] = ((bool)$value) && $value !== 'no';
}
- public function _bottomline_link ($value) {
- $this->bottomline_link = $value === 'yes';
+ public function _bottomline_link($value) {
+ $this->data['bottomline_link'] = ((bool)$value) && $value !== 'no';
}
}
diff --git a/app/Models/ConfigurationDAO.php b/app/Models/ConfigurationDAO.php
deleted file mode 100644
index 91210e701..000000000
--- a/app/Models/ConfigurationDAO.php
+++ /dev/null
@@ -1,161 +0,0 @@
-<?php
-
-class FreshRSS_ConfigurationDAO extends Minz_ModelArray {
- public $language = 'en';
- public $posts_per_page = 20;
- public $view_mode = 'normal';
- public $default_view = 'not_read';
- public $display_posts = 'no';
- public $onread_jump_next = 'yes';
- public $lazyload = 'yes';
- public $sort_order = 'DESC';
- public $old_entries = 3;
- public $keep_history_default = 0;
- public $shortcuts = array (
- 'mark_read' => 'r',
- 'mark_favorite' => 'f',
- 'go_website' => 'space',
- 'next_entry' => 'j',
- 'prev_entry' => 'k',
- 'collapse_entry' => 'c',
- 'load_more' => 'm'
- );
- public $mail_login = '';
- public $mark_when = array (
- 'article' => 'yes',
- 'site' => 'yes',
- 'scroll' => 'no',
- 'reception' => 'no'
- );
- public $sharing = array (
- 'shaarli' => '',
- 'poche' => '',
- 'diaspora' => '',
- 'twitter' => true,
- 'g+' => true,
- 'facebook' => true,
- 'email' => true,
- 'print' => true
- );
- public $theme = 'default';
- public $anon_access = 'no';
- public $token = '';
- public $auto_load_more = 'yes';
- public $topline_read = 'yes';
- public $topline_favorite = 'yes';
- public $topline_date = 'yes';
- public $topline_link = 'yes';
- public $bottomline_read = 'yes';
- public $bottomline_favorite = 'yes';
- public $bottomline_sharing = 'yes';
- public $bottomline_tags = 'yes';
- public $bottomline_date = 'yes';
- public $bottomline_link = 'yes';
-
- public function __construct ($nameFile = '') {
- if (empty($nameFile)) {
- $nameFile = DATA_PATH . '/' . Minz_Configuration::currentUser () . '_user.php';
- }
- parent::__construct ($nameFile);
-
- // TODO : simplifier ce code, une boucle for() devrait suffire !
- if (isset ($this->array['language'])) {
- $this->language = $this->array['language'];
- }
- if (isset ($this->array['posts_per_page'])) {
- $this->posts_per_page = intval($this->array['posts_per_page']);
- }
- if (isset ($this->array['view_mode'])) {
- $this->view_mode = $this->array['view_mode'];
- }
- if (isset ($this->array['default_view'])) {
- $this->default_view = $this->array['default_view'];
- }
- if (isset ($this->array['display_posts'])) {
- $this->display_posts = $this->array['display_posts'];
- }
- if (isset ($this->array['onread_jump_next'])) {
- $this->onread_jump_next = $this->array['onread_jump_next'];
- }
- if (isset ($this->array['lazyload'])) {
- $this->lazyload = $this->array['lazyload'];
- }
- if (isset ($this->array['sort_order'])) {
- $this->sort_order = $this->array['sort_order'];
- }
- if (isset ($this->array['old_entries'])) {
- $this->old_entries = intval($this->array['old_entries']);
- }
- if (isset ($this->array['keep_history_default'])) {
- $this->keep_history_default = intval($this->array['keep_history_default']);
- }
- if (isset ($this->array['shortcuts'])) {
- $this->shortcuts = array_merge (
- $this->shortcuts, $this->array['shortcuts']
- );
- }
- if (isset ($this->array['mail_login'])) {
- $this->mail_login = $this->array['mail_login'];
- }
- if (isset ($this->array['mark_when'])) {
- $this->mark_when = $this->array['mark_when'];
- }
- if (isset ($this->array['sharing'])) {
- $this->sharing = array_merge (
- $this->sharing, $this->array['sharing']
- );
- }
- if (isset ($this->array['theme'])) {
- $this->theme = $this->array['theme'];
- }
- if (isset ($this->array['anon_access'])) {
- $this->anon_access = $this->array['anon_access'];
- }
- if (isset ($this->array['token'])) {
- $this->token = $this->array['token'];
- }
- if (isset ($this->array['auto_load_more'])) {
- $this->auto_load_more = $this->array['auto_load_more'];
- }
-
- if (isset ($this->array['topline_read'])) {
- $this->topline_read = $this->array['topline_read'];
- }
- if (isset ($this->array['topline_favorite'])) {
- $this->topline_favorite = $this->array['topline_favorite'];
- }
- if (isset ($this->array['topline_date'])) {
- $this->topline_date = $this->array['topline_date'];
- }
- if (isset ($this->array['topline_link'])) {
- $this->topline_link = $this->array['topline_link'];
- }
- if (isset ($this->array['bottomline_read'])) {
- $this->bottomline_read = $this->array['bottomline_read'];
- }
- if (isset ($this->array['bottomline_favorite'])) {
- $this->bottomline_favorite = $this->array['bottomline_favorite'];
- }
- if (isset ($this->array['bottomline_sharing'])) {
- $this->bottomline_sharing = $this->array['bottomline_sharing'];
- }
- if (isset ($this->array['bottomline_tags'])) {
- $this->bottomline_tags = $this->array['bottomline_tags'];
- }
- if (isset ($this->array['bottomline_date'])) {
- $this->bottomline_date = $this->array['bottomline_date'];
- }
- if (isset ($this->array['bottomline_link'])) {
- $this->bottomline_link = $this->array['bottomline_link'];
- }
- }
-
- public function update ($values) {
- foreach ($values as $key => $value) {
- $this->array[$key] = $value;
- }
-
- $this->writeFile($this->array);
- invalidateHttpCache();
- }
-}
diff --git a/app/Models/Entry.php b/app/Models/Entry.php
index ab9605eb1..83f68ce78 100644
--- a/app/Models/Entry.php
+++ b/app/Models/Entry.php
@@ -38,11 +38,7 @@ class FreshRSS_Entry extends Minz_Model {
return $this->title;
}
public function author () {
- if (is_null ($this->author)) {
- return '';
- } else {
- return $this->author;
- }
+ return $this->author === null ? '' : $this->author;
}
public function content () {
return $this->content;
diff --git a/app/Models/Feed.php b/app/Models/Feed.php
index 32f8546dd..f38828a42 100644
--- a/app/Models/Feed.php
+++ b/app/Models/Feed.php
@@ -44,11 +44,7 @@ class FreshRSS_Feed extends Minz_Model {
return $this->category;
}
public function entries () {
- if (!is_null ($this->entries)) {
- return $this->entries;
- } else {
- return array ();
- }
+ return $this->entries === null ? array() : $this->entries;
}
public function name () {
return $this->name;
@@ -140,10 +136,7 @@ class FreshRSS_Feed extends Minz_Model {
$this->category = $value >= 0 ? $value : 0;
}
public function _name ($value) {
- if (is_null ($value)) {
- $value = '';
- }
- $this->name = $value;
+ $this->name = $value === null ? '' : $value;
}
public function _website ($value, $validate=true) {
if ($validate) {
@@ -155,10 +148,7 @@ class FreshRSS_Feed extends Minz_Model {
$this->website = $value;
}
public function _description ($value) {
- if (is_null ($value)) {
- $value = '';
- }
- $this->description = $value;
+ $this->description = $value === null ? '' : $value;
}
public function _lastUpdate ($value) {
$this->lastUpdate = $value;
@@ -190,7 +180,7 @@ class FreshRSS_Feed extends Minz_Model {
}
public function load ($loadDetails = false) {
- if (!is_null ($this->url)) {
+ if ($this->url !== null) {
if (CACHE_PATH === false) {
throw new Minz_FileNotExistException (
'CACHE_PATH',
@@ -253,7 +243,7 @@ class FreshRSS_Feed extends Minz_Model {
// si on a utilisé l'auto-discover, notre url va avoir changé
$subscribe_url = $feed->subscribe_url ();
- if (!is_null ($subscribe_url) && $subscribe_url != $this->url) {
+ if ($subscribe_url !== null && $subscribe_url !== $this->url) {
if ($this->httpAuth != '') {
// on enlève les id si authentification HTTP
$subscribe_url = preg_replace ('#((.+)://)((.+)@)(.+)#', '${1}${5}', $subscribe_url);
@@ -263,7 +253,7 @@ class FreshRSS_Feed extends Minz_Model {
if ($loadDetails) {
$title = htmlspecialchars(html_only_entity_decode($feed->get_title()), ENT_COMPAT, 'UTF-8');
- $this->_name (!is_null ($title) ? $title : $this->url);
+ $this->_name ($title === null ? $this->url : $title);
$this->_website(html_only_entity_decode($feed->get_link()));
$this->_description(html_only_entity_decode($feed->get_description()));
@@ -286,7 +276,7 @@ class FreshRSS_Feed extends Minz_Model {
// gestion des tags (catégorie == tag)
$tags_tmp = $item->get_categories ();
$tags = array ();
- if (!is_null ($tags_tmp)) {
+ if ($tags_tmp !== null) {
foreach ($tags_tmp as $tag) {
$tags[] = html_only_entity_decode ($tag->get_label ());
}
@@ -308,10 +298,10 @@ class FreshRSS_Feed extends Minz_Model {
$entry = new FreshRSS_Entry (
$this->id (),
$item->get_id (),
- !is_null ($title) ? $title : '',
- !is_null ($author) ? html_only_entity_decode ($author->name) : '',
- !is_null ($content) ? $content : '',
- !is_null ($link) ? $link : '',
+ $title === null ? '' : $title,
+ $author === null ? '' : html_only_entity_decode ($author->name),
+ $content === null ? '' : $content,
+ $link === null ? '' : $link,
$date ? $date : time ()
);
$entry->_tags ($tags);
diff --git a/app/Models/LogDAO.php b/app/Models/LogDAO.php
index 06855ec66..d1e515200 100644
--- a/app/Models/LogDAO.php
+++ b/app/Models/LogDAO.php
@@ -1,21 +1,25 @@
<?php
-class FreshRSS_LogDAO extends Minz_ModelTxt {
- public function __construct () {
- parent::__construct (LOG_PATH . '/application.log', 'r+');
- }
-
- public function lister () {
+class FreshRSS_LogDAO {
+ public static function lines() {
$logs = array ();
- while (($line = $this->readLine ()) !== false) {
- if (preg_match ('/^\[([^\[]+)\] \[([^\[]+)\] --- (.*)$/', $line, $matches)) {
- $myLog = new FreshRSS_Log ();
- $myLog->_date ($matches[1]);
- $myLog->_level ($matches[2]);
- $myLog->_info ($matches[3]);
- $logs[] = $myLog;
+ $handle = @fopen(LOG_PATH . '/' . Minz_Session::param('currentUser', '_') . '.log', 'r');
+ if ($handle) {
+ while (($line = fgets($handle)) !== false) {
+ if (preg_match ('/^\[([^\[]+)\] \[([^\[]+)\] --- (.*)$/', $line, $matches)) {
+ $myLog = new FreshRSS_Log ();
+ $myLog->_date ($matches[1]);
+ $myLog->_level ($matches[2]);
+ $myLog->_info ($matches[3]);
+ $logs[] = $myLog;
+ }
}
+ fclose($handle);
}
- return $logs;
+ return array_reverse($logs);
+ }
+
+ public static function truncate() {
+ file_put_contents(LOG_PATH . '/' . Minz_Session::param('currentUser', '_') . '.log', '');
}
}
diff --git a/app/Models/UserDAO.php b/app/Models/UserDAO.php
new file mode 100644
index 000000000..a25b57f89
--- /dev/null
+++ b/app/Models/UserDAO.php
@@ -0,0 +1,36 @@
+<?php
+
+class FreshRSS_UserDAO extends Minz_ModelPdo {
+ public function createUser($username) {
+ require_once(APP_PATH . '/sql.php');
+ $db = Minz_Configuration::dataBase();
+
+ $sql = sprintf(SQL_CREATE_TABLES, $db['prefix'] . $username . '_');
+ $stm = $this->bd->prepare($sql, array(PDO::ATTR_EMULATE_PREPARES => true));
+ $values = array(
+ 'catName' => Minz_Translate::t('default_category'),
+ );
+ if ($stm && $stm->execute($values)) {
+ return true;
+ } else {
+ $info = $stm->errorInfo();
+ Minz_Log::record ('SQL error : ' . $info[2], Minz_Log::ERROR);
+ return false;
+ }
+ }
+
+ public function deleteUser($username) {
+ require_once(APP_PATH . '/sql.php');
+ $db = Minz_Configuration::dataBase();
+
+ $sql = sprintf(SQL_DROP_TABLES, $db['prefix'] . $username . '_');
+ $stm = $this->bd->prepare($sql);
+ if ($stm && $stm->execute()) {
+ return true;
+ } else {
+ $info = $stm->errorInfo();
+ Minz_Log::record ('SQL error : ' . $info[2], Minz_Log::ERROR);
+ return false;
+ }
+ }
+}