Skip to content

A free, self-hostable news aggregator…

Merge branch 'dev' into 252-extensions

Marien Fressinaud73023bc12b81
diff --cc app/Controllers/extensionController.php
index adb3e1864,000000000..3eedcd949
mode 100644,000000..100644
--- a/app/Controllers/extensionController.php
+++ b/app/Controllers/extensionController.php
@@@ -1,197 -1,0 +1,195 @@@
+<?php
+
+/**
+ * The controller to manage extensions.
+ */
+class FreshRSS_extension_Controller extends Minz_ActionController {
+ /**
+ * This action is called before every other action in that class. It is
+ * the common boiler plate for every action. It is triggered by the
+ * underlying framework.
+ */
+ public function firstAction() {
+ if (!FreshRSS_Auth::hasAccess()) {
+ Minz_Error::error(403);
+ }
+ }
+
+ /**
+ * This action lists all the extensions available to the current user.
+ */
+ public function indexAction() {
+ Minz_View::prependTitle(_t('admin.extensions.title') . ' · ');
+ $this->view->extension_list = Minz_ExtensionManager::list_extensions();
+ }
+
+ /**
+ * This action handles configuration of a given extension.
+ *
+ * Only administrator can configure a system extension.
+ *
+ * Parameters are:
+ * - e: the extension name (urlencoded)
+ * - additional parameters which should be handle by the extension
+ * handleConfigureAction() method (POST request).
+ */
+ public function configureAction() {
+ if (Minz_Request::param('ajax')) {
+ $this->view->_useLayout(false);
+ }
+
+ $ext_name = urldecode(Minz_Request::param('e'));
+ $ext = Minz_ExtensionManager::find_extension($ext_name);
+
+ if (is_null($ext)) {
+ Minz_Error::error(404);
+ }
+ if ($ext->getType() === 'system' && !FreshRSS_Auth::hasAccess('admin')) {
+ Minz_Error::error(403);
+ }
+
+ $this->view->extension = $ext;
+
+ if (Minz_Request::isPost()) {
+ $this->view->extension->handleConfigureAction();
+ }
+ }
+
+ /**
+ * This action enables a disabled extension for the current user.
+ *
+ * System extensions can only be enabled by an administrator.
+ * This action must be reached by a POST request.
+ *
+ * Parameter is:
+ * - e: the extension name (urlencoded).
+ */
+ public function enableAction() {
+ $url_redirect = array('c' => 'extension', 'a' => 'index');
+
+ if (Minz_Request::isPost()) {
+ $ext_name = urldecode(Minz_Request::param('e'));
+ $ext = Minz_ExtensionManager::find_extension($ext_name);
+
+ if (is_null($ext)) {
+ Minz_Request::bad(_t('feedback.extensions.not_found', $ext_name),
+ $url_redirect);
+ }
+
+ if ($ext->is_enabled()) {
+ Minz_Request::bad(_t('feedback.extensions.already_enabled', $ext_name),
+ $url_redirect);
+ }
+
++ $conf = null;
+ if ($ext->getType() === 'system' && FreshRSS_Auth::hasAccess('admin')) {
- $ext->install();
-
- Minz_Configuration::addExtension($ext_name);
- Minz_Configuration::writeFile();
-
- Minz_Request::good(_t('feedback.extensions.enabled', $ext_name),
- $url_redirect);
++ $conf = FreshRSS_Context::$system_conf;
+ } elseif ($ext->getType() === 'user') {
- $ext->install();
-
- FreshRSS_Context::$conf->addExtension($ext_name);
- FreshRSS_Context::$conf->save();
-
- Minz_Request::good(_t('feedback.extensions.enabled', $ext_name),
- $url_redirect);
++ $conf = FreshRSS_Context::$user_conf;
+ } else {
+ Minz_Request::bad(_t('feedback.extensions.no_access', $ext_name),
+ $url_redirect);
+ }
++
++ $ext->install();
++
++ $ext_list = $conf->extensions_enabled;
++ array_push_unique($ext_list, $ext_name);
++ $conf->extensions_enabled = $ext_list;
++ $conf->save();
++
++ Minz_Request::good(_t('feedback.extensions.enabled', $ext_name),
++ $url_redirect);
+ }
+
+ Minz_Request::forward($url_redirect, true);
+ }
+
+ /**
+ * This action disables an enabled extension for the current user.
+ *
+ * System extensions can only be disabled by an administrator.
+ * This action must be reached by a POST request.
+ *
+ * Parameter is:
+ * - e: the extension name (urlencoded).
+ */
+ public function disableAction() {
+ $url_redirect = array('c' => 'extension', 'a' => 'index');
+
+ if (Minz_Request::isPost()) {
+ $ext_name = urldecode(Minz_Request::param('e'));
+ $ext = Minz_ExtensionManager::find_extension($ext_name);
+
+ if (is_null($ext)) {
+ Minz_Request::bad(_t('feedback.extensions.not_found', $ext_name),
+ $url_redirect);
+ }
+
+ if (!$ext->is_enabled()) {
+ Minz_Request::bad(_t('feedback.extensions.not_enabled', $ext_name),
+ $url_redirect);
+ }
+
++ $conf = null;
+ if ($ext->getType() === 'system' && FreshRSS_Auth::hasAccess('admin')) {
- $ext->uninstall();
-
- Minz_Configuration::removeExtension($ext_name);
- Minz_Configuration::writeFile();
-
- Minz_Request::good(_t('feedback.extensions.disabled', $ext_name),
- $url_redirect);
++ $conf = FreshRSS_Context::$system_conf;
+ } elseif ($ext->getType() === 'user') {
- $ext->uninstall();
-
- FreshRSS_Context::$conf->removeExtension($ext_name);
- FreshRSS_Context::$conf->save();
-
- Minz_Request::good(_t('feedback.extensions.disabled', $ext_name),
- $url_redirect);
++ $conf = FreshRSS_Context::$user_conf;
+ } else {
+ Minz_Request::bad(_t('feedback.extensions.no_access', $ext_name),
+ $url_redirect);
+ }
++
++ $ext->uninstall();
++
++ $ext_list = $conf->extensions_enabled;
++ array_remove($ext_list, $ext_name);
++ $conf->extensions_enabled = $ext_list;
++ $conf->save();
++
++ Minz_Request::good(_t('feedback.extensions.disabled', $ext_name),
++ $url_redirect);
+ }
+
+ Minz_Request::forward($url_redirect, true);
+ }
+
+ /**
+ * This action handles deletion of an extension.
+ *
+ * Only administrator can remove an extension.
+ * This action must be reached by a POST request.
+ *
+ * Parameter is:
+ * -e: extension name (urlencoded)
+ */
+ public function removeAction() {
+ if (!FreshRSS_Auth::hasAccess('admin')) {
+ Minz_Error::error(403);
+ }
+
+ $url_redirect = array('c' => 'extension', 'a' => 'index');
+
+ if (Minz_Request::isPost()) {
+ $ext_name = urldecode(Minz_Request::param('e'));
+ $ext = Minz_ExtensionManager::find_extension($ext_name);
+
+ if (is_null($ext)) {
+ Minz_Request::bad(_t('feedback.extensions.not_found', $ext_name),
+ $url_redirect);
+ }
+
+ $res = recursive_unlink($ext->getPath());
+ if ($res) {
+ Minz_Request::good(_t('feedback.extensions.removed', $ext_name),
+ $url_redirect);
+ } else {
+ Minz_Request::bad(_t('feedback.extensions.cannot_delete', $ext_name),
+ $url_redirect);
+ }
+ }
+
+ Minz_Request::forward($url_redirect, true);
+ }
+}
diff --cc app/FreshRSS.php
index 88fe60850,002a70af5..453cc2d69
--- a/app/FreshRSS.php
+++ b/app/FreshRSS.php
@@@ -6,13 -6,30 +6,36 @@@ class FreshRSS extends Minz_FrontContro
Minz_Session::init('FreshRSS');
}
+ // Load list of extensions and enable the "system" ones.
+ Minz_ExtensionManager::init();
+ $this->initConfiguration();
+ $this->initAuth();
+ FreshRSS_Context::init();
+ $this->initI18n();
+ FreshRSS_Share::load(join_path(DATA_PATH, 'shares.php'));
+ $this->loadStylesAndScripts();
+ $this->loadNotifications();
- $this->loadExtensions();
++ // Enable extensions for the current (logged) user.
++ if (FreshRSS_Auth::hasAccess()) {
++ $ext_list = FreshRSS_Context::$user_conf->extensions_enabled;
++ Minz_ExtensionManager::enable_by_list($ext_list);
++ }
+ }
- // Need to be called just after session init because it initializes
- // current user.
- FreshRSS_Auth::init();
+ private function initConfiguration() {
+ $configuration_setter = new FreshRSS_ConfigurationSetter();
+ $current_user = Minz_Session::param('currentUser', '_');
+ Minz_Configuration::register('user',
+ join_path(USERS_PATH, $current_user, 'config.php'),
+ join_path(USERS_PATH, '_', 'config.default.php'),
+ $configuration_setter);
+ $system_conf = Minz_Configuration::get('system');
+ $system_conf->_configurationSetter($configuration_setter);
+ }
+
+ private function initAuth() {
+ FreshRSS_Auth::init();
if (Minz_Request::isPost() && !is_referer_from_same_domain()) {
// Basic protection against XSRF attacks
FreshRSS_Auth::removeAccess();
@@@ -25,22 -42,15 +48,11 @@@
))
);
}
+ }
- // Load context and configuration.
- FreshRSS_Context::init();
-
- // Init i18n.
- Minz_Session::_param('language', FreshRSS_Context::$conf->language);
- Minz_Translate::init();
-
- $this->loadStylesAndScripts();
- $this->loadNotifications();
-
- // Enable extensions for the current (logged) user.
- if (FreshRSS_Auth::hasAccess()) {
- $ext_list = FreshRSS_Context::$conf->extensions_enabled;
- Minz_ExtensionManager::enable_by_list($ext_list);
- }
+ private function initI18n() {
+ Minz_Session::_param('language', FreshRSS_Context::$user_conf->language);
-
- Minz_Translate::init(array(
- 'en' => 'English',
- 'fr' => 'Français',
- ), FreshRSS_Context::$user_conf->language);
++ Minz_Translate::init(FreshRSS_Context::$user_conf->language);
}
private function loadStylesAndScripts() {
diff --cc app/install.php
index 8091a9eb0,a9faa764b..55817ec68
--- a/app/install.php
+++ b/app/install.php
@@@ -43,30 -43,29 +43,26 @@@ function param($key, $default = false)
// gestion internationalisation
function initTranslate() {
+ $available_languages = array(
+ 'en' => 'English',
+ 'fr' => 'Français'
+ );
+
if (!isset($_SESSION['language'])) {
- $_SESSION['language'] = getBetterLanguage('en');
+ $best = get_best_language();
+ if (!isset($available_languages[$best])) {
+ $best = 'en';
+ }
+
+ $_SESSION['language'] = $best;
}
- Minz_Translate::init();
- Minz_Translate::init(array(
- 'en' => 'English',
- 'fr' => 'Français',
- ), $_SESSION['language']);
++ Minz_Translate::init($_SESSION['language']);
}
- function getBetterLanguage($fallback) {
- $available = availableLanguages();
+ function get_best_language() {
$accept = $_SERVER['HTTP_ACCEPT_LANGUAGE'];
- $language = strtolower(substr($accept, 0, 2));
-
- if (isset($available[$language])) {
- return $language;
- } else {
- return $fallback;
- }
- }
-
- function availableLanguages() {
- return array(
- 'en' => 'English',
- 'fr' => 'Français'
- );
+ return strtolower(substr($accept, 0, 2));
}
diff --cc app/views/helpers/index/normal/entry_bottom.phtml
index a9f5389df,000000000..32317d027
mode 100644,000000..100644
--- a/app/views/helpers/index/normal/entry_bottom.phtml
+++ b/app/views/helpers/index/normal/entry_bottom.phtml
@@@ -1,88 -1,0 +1,86 @@@
+<?php
+ $sharing = array();
+ if (FreshRSS_Auth::hasAccess()) {
- $sharing = FreshRSS_Context::$conf->sharing;
++ $sharing = FreshRSS_Context::$user_conf->sharing;
+ }
+
- $bottomline_read = FreshRSS_Context::$conf->bottomline_read;
- $bottomline_favorite = FreshRSS_Context::$conf->bottomline_favorite;
- $bottomline_sharing = FreshRSS_Context::$conf->bottomline_sharing && (count($sharing) > 0);
- $bottomline_tags = FreshRSS_Context::$conf->bottomline_tags;
- $bottomline_date = FreshRSS_Context::$conf->bottomline_date;
- $bottomline_link = FreshRSS_Context::$conf->bottomline_link;
++ $bottomline_read = FreshRSS_Context::$user_conf->bottomline_read;
++ $bottomline_favorite = FreshRSS_Context::$user_conf->bottomline_favorite;
++ $bottomline_sharing = FreshRSS_Context::$user_conf->bottomline_sharing && (count($sharing) > 0);
++ $bottomline_tags = FreshRSS_Context::$user_conf->bottomline_tags;
++ $bottomline_date = FreshRSS_Context::$user_conf->bottomline_date;
++ $bottomline_link = FreshRSS_Context::$user_conf->bottomline_link;
+?><ul class="horizontal-list bottom"><?php
+ if (FreshRSS_Auth::hasAccess()) {
+ if ($bottomline_read) {
+ ?><li class="item manage"><?php
+ $arUrl = array('c' => 'entry', 'a' => 'read', 'params' => array('id' => $this->entry->id()));
+ if ($this->entry->isRead()) {
+ $arUrl['params']['is_read'] = 0;
+ }
+ ?><a class="read" href="<?php echo Minz_Url::display($arUrl); ?>"><?php
+ echo _i($this->entry->isRead() ? 'read' : 'unread'); ?></a><?php
+ ?></li><?php
+ }
+ if ($bottomline_favorite) {
+ ?><li class="item manage"><?php
+ $arUrl = array('c' => 'entry', 'a' => 'bookmark', 'params' => array('id' => $this->entry->id()));
+ if ($this->entry->isFavorite()) {
+ $arUrl['params']['is_favorite'] = 0;
+ }
+ ?><a class="bookmark" href="<?php echo Minz_Url::display($arUrl); ?>"><?php
+ echo _i($this->entry->isFavorite() ? 'starred' : 'non-starred'); ?></a><?php
+ ?></li><?php
+ }
+ } ?>
+ <li class="item"><?php
+ if ($bottomline_sharing) {
- $link = urlencode($this->entry->link());
- $title = urlencode($this->entry->title() . ' · ' . $this->feed->name());
+ ?><div class="dropdown">
- <div id="dropdown-share-<?php echo $this->entry->id();?>" class="dropdown-target"></div>
- <a class="dropdown-toggle" href="#dropdown-share-<?php echo $this->entry->id();?>">
++ <div id="dropdown-share-<?php echo $item->id();?>" class="dropdown-target"></div>
++ <a class="dropdown-toggle" href="#dropdown-share-<?php echo $item->id();?>">
+ <?php echo _i('share'); ?>
+ <?php echo _t('index.share'); ?>
+ </a>
+
+ <ul class="dropdown-menu">
- <li class="dropdown-close"><a href="#close">❌</a></li>
- <?php
- foreach ($sharing as $share) {
- $type_share = FreshRSS_Context::$conf->shares[$share['type']];
- $has_specific_title = ($type_share['form'] === 'advanced');
- ?>
- <li class="item share">
- <a target="_blank" href="<?php echo FreshRSS_Share::generateUrl(FreshRSS_Context::$conf->shares, $share, $this->entry->link(), $this->entry->title() . ' . ' . $this->feed->name())?>">
- <?php echo $has_specific_title ? $share['name'] : _t('index.share.' . $share['name']); ?>
- </a>
- </li>
- <?php } ?>
- </ul>
++ <li class="dropdown-close"><a href="#close">❌</a></li><?php
++ $link = $item->link();
++ $title = $item->title() . ' · ' . $feed->name();
++ foreach (FreshRSS_Context::$user_conf->sharing as $share_options) {
++ $share = FreshRSS_Share::get($share_options['type']);
++ $share_options['link'] = $link;
++ $share_options['title'] = $title;
++ $share->update($share_options);
++ ?><li class="item share">
++ <a target="_blank" href="<?php echo $share->url(); ?>"><?php echo $share->name(); ?></a>
++ </li><?php
++ }
++ ?></ul>
+ </div>
+ <?php } ?>
+ </li><?php
+ $tags = $bottomline_tags ? $this->entry->tags() : null;
+ if (!empty($tags)) {
+ ?><li class="item">
+ <div class="dropdown">
+ <div id="dropdown-tags-<?php echo $this->entry->id();?>" class="dropdown-target"></div>
+ <?php echo _i('tag'); ?>
+ <a class="dropdown-toggle" href="#dropdown-tags-<?php echo $this->entry->id();?>"><?php
+ echo _t('index.tag.related');
+ ?></a>
+ <ul class="dropdown-menu">
+ <li class="dropdown-close"><a href="#close">❌</a></li><?php
+ foreach($tags as $tag) {
+ ?><li class="item"><a href="<?php echo _url('index', 'index', 'search', urlencode('#' . $tag)); ?>"><?php echo $tag; ?></a></li><?php
+ } ?>
+ </ul>
+ </div>
+ </li><?php
+ }
+ if ($bottomline_date) {
+ ?><li class="item date"><?php echo $this->entry->date(); ?></li><?php
+ }
+ if ($bottomline_link) {
+ ?><li class="item link"><a target="_blank" href="<?php echo $this->entry->link(); ?>"><?php echo _i('link'); ?></a></li><?php
+ } ?>
+</ul>
diff --cc app/views/helpers/index/normal/entry_header.phtml
index 3d8b089b9,000000000..dc544298f
mode 100644,000000..100644
--- a/app/views/helpers/index/normal/entry_header.phtml
+++ b/app/views/helpers/index/normal/entry_header.phtml
@@@ -1,33 -1,0 +1,33 @@@
+<?php
- $topline_read = FreshRSS_Context::$conf->topline_read;
- $topline_favorite = FreshRSS_Context::$conf->topline_favorite;
- $topline_date = FreshRSS_Context::$conf->topline_date;
- $topline_link = FreshRSS_Context::$conf->topline_link;
++ $topline_read = FreshRSS_Context::$user_conf->topline_read;
++ $topline_favorite = FreshRSS_Context::$user_conf->topline_favorite;
++ $topline_date = FreshRSS_Context::$user_conf->topline_date;
++ $topline_link = FreshRSS_Context::$user_conf->topline_link;
+?><ul class="horizontal-list flux_header"><?php
+ if (FreshRSS_Auth::hasAccess()) {
+ if ($topline_read) {
+ ?><li class="item manage"><?php
+ $arUrl = array('c' => 'entry', 'a' => 'read', 'params' => array('id' => $this->entry->id()));
+ if ($this->entry->isRead()) {
+ $arUrl['params']['is_read'] = 0;
+ }
+ ?><a class="read" href="<?php echo Minz_Url::display($arUrl); ?>"><?php
+ echo _i($this->entry->isRead() ? 'read' : 'unread'); ?></a><?php
+ ?></li><?php
+ }
+ if ($topline_favorite) {
+ ?><li class="item manage"><?php
+ $arUrl = array('c' => 'entry', 'a' => 'bookmark', 'params' => array('id' => $this->entry->id()));
+ if ($this->entry->isFavorite()) {
+ $arUrl['params']['is_favorite'] = 0;
+ }
+ ?><a class="bookmark" href="<?php echo Minz_Url::display($arUrl); ?>"><?php
+ echo _i($this->entry->isFavorite() ? 'starred' : 'non-starred'); ?></a><?php
+ ?></li><?php
+ }
+ }
+ ?><li class="item website"><a href="<?php echo _url('index', 'index', 'get', 'f_' . $this->feed->id()); ?>"><img class="favicon" src="<?php echo $this->feed->favicon(); ?>" alt="✇" /> <span><?php echo $this->feed->name(); ?></span></a></li>
+ <li class="item title"><a target="_blank" href="<?php echo $this->entry->link(); ?>"><?php echo $this->entry->title(); ?></a></li>
+ <?php if ($topline_date) { ?><li class="item date"><?php echo $this->entry->date(); ?> </li><?php } ?>
+ <?php if ($topline_link) { ?><li class="item link"><a target="_blank" href="<?php echo $this->entry->link(); ?>"><?php echo _i('link'); ?></a></li><?php } ?>
+</ul>
diff --cc app/views/index/normal.phtml
index 817732c2c,8c6ddd1ee..f71abf158
--- a/app/views/index/normal.phtml
+++ b/app/views/index/normal.phtml
@@@ -7,10 -7,25 +7,9 @@@ if (!empty($this->entries))
$display_today = true;
$display_yesterday = true;
$display_others = true;
- $hidePosts = !FreshRSS_Context::$conf->display_posts;
- $lazyload = FreshRSS_Context::$conf->lazyload;
-
- $content_width = FreshRSS_Context::$conf->content_width;
- if (FreshRSS_Auth::hasAccess()) {
- $sharing = FreshRSS_Context::$user_conf->sharing;
- } else {
- $sharing = array();
- }
+ $hidePosts = !FreshRSS_Context::$user_conf->display_posts;
+ $lazyload = FreshRSS_Context::$user_conf->lazyload;
- $topline_read = FreshRSS_Context::$user_conf->topline_read;
- $topline_favorite = FreshRSS_Context::$user_conf->topline_favorite;
- $topline_date = FreshRSS_Context::$user_conf->topline_date;
- $topline_link = FreshRSS_Context::$user_conf->topline_link;
- $bottomline_read = FreshRSS_Context::$user_conf->bottomline_read;
- $bottomline_favorite = FreshRSS_Context::$user_conf->bottomline_favorite;
- $bottomline_sharing = FreshRSS_Context::$user_conf->bottomline_sharing && (count($sharing));
- $bottomline_tags = FreshRSS_Context::$user_conf->bottomline_tags;
- $bottomline_date = FreshRSS_Context::$user_conf->bottomline_date;
- $bottomline_link = FreshRSS_Context::$user_conf->bottomline_link;
-
+ $content_width = FreshRSS_Context::$user_conf->content_width;
$today = @strtotime('today');
?>
diff --cc app/views/index/reader.phtml
index ae65a72d2,017297710..a19ee322e
--- a/app/views/index/reader.phtml
+++ b/app/views/index/reader.phtml
@@@ -2,17 -2,14 +2,17 @@@
$this->partial('nav_menu');
if (!empty($this->entries)) {
- $lazyload = FreshRSS_Context::$conf->lazyload;
- $content_width = FreshRSS_Context::$conf->content_width;
+ $lazyload = FreshRSS_Context::$user_conf->lazyload;
+ $content_width = FreshRSS_Context::$user_conf->content_width;
?>
-<div id="stream" class="reader">
- <?php foreach ($this->entries as $item) { ?>
-
- <div class="flux<?php echo !$item->isRead() ? ' not_read' : ''; ?><?php echo $item->isFavorite() ? ' favorite' : ''; ?>" id="flux_<?php echo $item->id(); ?>">
+<div id="stream" class="reader"><?php
+ foreach ($this->entries as $item) {
+ $item = Minz_ExtensionManager::callHook('entry_before_display', $item);
+ if (is_null($item)) {
+ continue;
+ }
+ ?><div class="flux<?php echo !$item->isRead() ? ' not_read' : ''; ?><?php echo $item->isFavorite() ? ' favorite' : ''; ?>" id="flux_<?php echo $item->id(); ?>">
<div class="flux_content">
<div class="content <?php echo $content_width; ?>">
<?php
diff --cc data/config.default.php
index 000000000,193ac5726..97df3a299
mode 000000,100644..100644
--- a/data/config.default.php
+++ b/data/config.default.php
@@@ -1,0 -1,30 +1,31 @@@
+ <?php
+
+ return array(
+ 'environment' => 'production',
+ 'salt' => '',
+ 'base_url' => '',
+ 'language' => 'en',
+ 'title' => 'FreshRSS',
+ 'default_user' => '_',
+ 'allow_anonymous' => false,
+ 'allow_anonymous_refresh' => false,
+ 'auth_type' => 'none',
+ 'api_enabled' => false,
+ 'unsafe_autologin_enabled' => false,
+ 'limits' => array(
+ 'cache_duration' => 800,
+ 'timeout' => 10,
+ 'max_inactivity' => PHP_INT_MAX,
+ 'max_feeds' => 16384,
+ 'max_categories' => 16384,
+ ),
+ 'db' => array(
+ 'type' => 'sqlite',
+ 'host' => '',
+ 'user' => '',
+ 'password' => '',
+ 'base' => '',
+ 'prefix' => '',
+ ),
++ 'extensions_enabled' => array(),
+ );
diff --cc data/users/_/config.default.php
index 000000000,56d54b293..6d3f73a13
mode 000000,100644..100644
--- a/data/users/_/config.default.php
+++ b/data/users/_/config.default.php
@@@ -1,0 -1,66 +1,67 @@@
+ <?php
+
+ return array (
+ 'language' => 'en',
+ 'old_entries' => 3,
+ 'keep_history_default' => 0,
+ 'ttl_default' => 3600,
+ 'mail_login' => '',
+ 'token' => '',
+ 'passwordHash' => '',
+ 'apiPasswordHash' => '',
+ 'posts_per_page' => 20,
+ 'view_mode' => 'normal',
+ 'default_view' => 'adaptive',
+ 'default_state' => FreshRSS_Entry::STATE_NOT_READ,
+ 'auto_load_more' => true,
+ 'display_posts' => false,
+ 'display_categories' => false,
+ 'hide_read_feeds' => true,
+ 'onread_jump_next' => true,
+ 'lazyload' => true,
+ 'sticky_post' => true,
+ 'reading_confirm' => false,
+ 'auto_remove_article' => false,
+ 'sort_order' => 'DESC',
+ 'anon_access' => false,
+ 'mark_when' => array (
+ 'article' => true,
+ 'site' => true,
+ 'scroll' => false,
+ 'reception' => false,
+ ),
+ 'theme' => 'Origine',
+ 'content_width' => 'thin',
+ 'shortcuts' => array (
+ 'mark_read' => 'r',
+ 'mark_favorite' => 'f',
+ 'go_website' => 'space',
+ 'next_entry' => 'j',
+ 'prev_entry' => 'k',
+ 'first_entry' => 'home',
+ 'last_entry' => 'end',
+ 'collapse_entry' => 'c',
+ 'load_more' => 'm',
+ 'auto_share' => 's',
+ 'focus_search' => 'a',
+ 'user_filter' => 'u',
+ 'help' => 'f1',
+ 'close_dropdown' => 'escape',
+ ),
+ '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 (
+ ),
+ 'queries' => array (
+ ),
+ 'html5_notif_timeout' => 0,
++ 'extensions_enabled' => array(),
+ );
diff --cc lib/Minz/Configuration.php
index 4a3221ef5,6044fc269..fe415e22b
--- a/lib/Minz/Configuration.php
+++ b/lib/Minz/Configuration.php
@@@ -1,223 -1,133 +1,146 @@@
<?php
- /**
- * MINZ - Copyright 2011 Marien Fressinaud
- * Sous licence AGPL3 <http://www.gnu.org/licenses/>
- */
/**
- * La classe Configuration permet de gérer la configuration de l'application
+ * Manage configuration for the application.
*/
class Minz_Configuration {
- const CONF_PATH_NAME = '/config.php';
-
/**
- * VERSION est la version actuelle de MINZ
+ * The list of configurations.
*/
- const VERSION = '1.3.1.freshrss'; // version spéciale FreshRSS
+ private static $config_list = array();
/**
- * valeurs possibles pour l'"environment"
- * SILENT rend l'application muette (pas de log)
- * PRODUCTION est recommandée pour une appli en production
- * (log les erreurs critiques)
- * DEVELOPMENT log toutes les erreurs
+ * Add a new configuration to the list of configuration.
+ *
+ * @param $namespace the name of the current configuration
+ * @param $config_filename the filename of the configuration
+ * @param $default_filename a filename containing default values for the configuration
+ * @param $configuration_setter an optional helper to set values in configuration
+ * @throws Minz_ConfigurationNamespaceException if the namespace already exists.
*/
- const SILENT = 0;
- const PRODUCTION = 1;
- const DEVELOPMENT = 2;
+ public static function register($namespace, $config_filename, $default_filename = null,
+ $configuration_setter = null) {
+ if (isset(self::$config_list[$namespace])) {
+ throw new Minz_ConfigurationNamespaceException(
+ $namespace . ' namespace already exists'
+ );
+ }
+
+ self::$config_list[$namespace] = new Minz_Configuration(
+ $namespace, $config_filename, $default_filename, $configuration_setter
+ );
+ }
/**
- * définition des variables de configuration
- * $salt une chaîne de caractères aléatoires (obligatoire)
- * $environment gère le niveau d'affichage pour log et erreurs
- * $base_url le chemin de base pour accéder à l'application
- * $title le nom de l'application
- * $language la langue par défaut de l'application
- * $db paramètres pour la base de données (tableau)
- * - host le serveur de la base
- * - user nom d'utilisateur
- * - password mot de passe de l'utilisateur
- * - base le nom de la base de données
+ * Parse a file and return its data.
+ *
+ * If the file does not contain a valid PHP code returning an array, an
+ * empty array is returned anyway.
+ *
+ * @param $filename the name of the file to parse.
+ * @return an array of values
+ * @throws Minz_FileNotExistException if the file does not exist.
*/
- private static $salt = '';
- private static $environment = Minz_Configuration::PRODUCTION;
- private static $base_url = '';
- private static $title = '';
- private static $language = 'en';
- private static $default_user = '';
- private static $allow_anonymous = false;
- private static $allow_anonymous_refresh = false;
- private static $auth_type = 'none';
- private static $api_enabled = false;
- private static $unsafe_autologin_enabled = false;
+ public static function load($filename) {
+ if (!file_exists($filename)) {
+ throw new Minz_FileNotExistException($filename);
+ }
- private static $db = array (
- 'type' => 'mysql',
- 'host' => '',
- 'user' => '',
- 'password' => '',
- 'base' => '',
- 'prefix' => '',
- );
+ $data = @include($filename);
+ if (is_array($data)) {
+ return $data;
+ } else {
+ return array();
+ }
+ }
- const MAX_SMALL_INT = 16384;
- private static $limits = array(
- 'cache_duration' => 800, //SimplePie cache duration in seconds
- 'timeout' => 10, //SimplePie timeout in seconds
- 'max_inactivity' => PHP_INT_MAX, //Time in seconds after which a user who has not used the account is considered inactive (no auto-refresh of feeds).
- 'max_feeds' => Minz_Configuration::MAX_SMALL_INT,
- 'max_categories' => Minz_Configuration::MAX_SMALL_INT,
- );
+ /**
+ * Return the configuration related to a given namespace.
+ *
+ * @param $namespace the name of the configuration to get.
+ * @return a Minz_Configuration object
+ * @throws Minz_ConfigurationNamespaceException if the namespace does not exist.
+ */
+ public static function get($namespace) {
+ if (!isset(self::$config_list[$namespace])) {
+ throw new Minz_ConfigurationNamespaceException(
+ $namespace . ' namespace does not exist'
+ );
+ }
- private static $extensions_enabled = array();
+ return self::$config_list[$namespace];
+ }
- /*
- * Getteurs
+ /**
+ * The namespace of the current configuration.
*/
- public static function salt () {
- return self::$salt;
- }
- public static function environment ($str = false) {
- $env = self::$environment;
+ private $namespace = '';
- if ($str) {
- switch (self::$environment) {
- case self::SILENT:
- $env = 'silent';
- break;
- case self::DEVELOPMENT:
- $env = 'development';
- break;
- case self::PRODUCTION:
- default:
- $env = 'production';
- }
- }
+ /**
+ * The filename for the current configuration.
+ */
+ private $config_filename = '';
- return $env;
- }
- public static function baseUrl () {
- return self::$base_url;
- }
- public static function title () {
- return self::$title;
- }
- public static function language () {
- return self::$language;
- }
- public static function dataBase () {
- return self::$db;
- }
- public static function limits() {
- return self::$limits;
- }
- public static function defaultUser () {
- return self::$default_user;
- }
- public static function allowAnonymous() {
- return self::$allow_anonymous;
- }
- public static function allowAnonymousRefresh() {
- return self::$allow_anonymous_refresh;
- }
- public static function authType() {
- return self::$auth_type;
- }
- public static function needsLogin() {
- return self::$auth_type !== 'none';
- }
- public static function canLogIn() {
- return self::$auth_type === 'form' || self::$auth_type === 'persona';
- }
- public static function apiEnabled() {
- return self::$api_enabled;
- }
- public static function unsafeAutologinEnabled() {
- return self::$unsafe_autologin_enabled;
- }
- public static function extensionsEnabled() {
- return self::$extensions_enabled;
- }
+ /**
+ * The filename for the current default values, null by default.
+ */
+ private $default_filename = null;
- public static function _allowAnonymous($allow = false) {
- self::$allow_anonymous = ((bool)$allow) && self::canLogIn();
- }
- public static function _allowAnonymousRefresh($allow = false) {
- self::$allow_anonymous_refresh = ((bool)$allow) && self::allowAnonymous();
- }
- public static function _authType($value) {
- $value = strtolower($value);
- switch ($value) {
- case 'form':
- case 'http_auth':
- case 'persona':
- case 'none':
- self::$auth_type = $value;
- break;
- }
- self::_allowAnonymous(self::$allow_anonymous);
- }
+ /**
+ * The configuration values, an empty array by default.
+ */
+ private $data = array();
- public static function _enableApi($value = false) {
- self::$api_enabled = (bool)$value;
- }
- public static function _enableAutologin($value = false) {
- self::$unsafe_autologin_enabled = (bool)$value;
- }
+ /**
+ * The default values, an empty array by default.
+ */
+ private $data_default = array();
+
+ /**
+ * An object which help to set good values in configuration.
+ */
+ private $configuration_setter = null;
+ public function removeExtension($ext_name) {
+ self::$extensions_enabled = array_diff(
+ self::$extensions_enabled,
+ array($ext_name)
+ );
+ }
+ public function addExtension($ext_name) {
+ $found = array_search($ext_name, self::$extensions_enabled) !== false;
+ if (!$found) {
+ self::$extensions_enabled[] = $ext_name;
+ }
+ }
+
/**
- * Initialise les variables de configuration
- * @exception Minz_FileNotExistException si le CONF_PATH_NAME n'existe pas
- * @exception Minz_BadConfigurationException si CONF_PATH_NAME mal formaté
+ * Create a new Minz_Configuration object.
+ *
+ * @param $namespace the name of the current configuration.
+ * @param $config_filename the file containing configuration values.
+ * @param $default_filename the file containing default values, null by default.
+ * @param $configuration_setter an optional helper to set values in configuration
*/
- public static function init () {
+ private function __construct($namespace, $config_filename, $default_filename = null,
+ $configuration_setter = null) {
+ $this->namespace = $namespace;
+ $this->config_filename = $config_filename;
+
try {
- self::parseFile ();
- self::setReporting ();
+ $this->data = self::load($this->config_filename);
} catch (Minz_FileNotExistException $e) {
- throw $e;
- } catch (Minz_BadConfigurationException $e) {
- throw $e;
+ if (is_null($default_filename)) {
+ throw $e;
+ }
}
- }
- public static function writeFile() {
- $ini_array = array(
- 'general' => array(
- 'environment' => self::environment(true),
- 'salt' => self::$salt,
- 'base_url' => self::$base_url,
- 'title' => self::$title,
- 'default_user' => self::$default_user,
- 'allow_anonymous' => self::$allow_anonymous,
- 'allow_anonymous_refresh' => self::$allow_anonymous_refresh,
- 'auth_type' => self::$auth_type,
- 'api_enabled' => self::$api_enabled,
- 'unsafe_autologin_enabled' => self::$unsafe_autologin_enabled,
- ),
- 'limits' => self::$limits,
- 'db' => self::$db,
- 'extensions_enabled' => self::$extensions_enabled,
- );
- @rename(DATA_PATH . self::CONF_PATH_NAME, DATA_PATH . self::CONF_PATH_NAME . '.bak.php');
- $result = file_put_contents(DATA_PATH . self::CONF_PATH_NAME, "<?php\n return " . var_export($ini_array, true) . ';');
- if (function_exists('opcache_invalidate')) {
- opcache_invalidate(DATA_PATH . self::CONF_PATH_NAME); //Clear PHP 5.5+ cache for include
+ $this->default_filename = $default_filename;
+ if (!is_null($this->default_filename)) {
+ $this->data_default = self::load($this->default_filename);
}
- return (bool)$result;
+
+ $this->_configurationSetter($configuration_setter);
}
/**
diff --cc lib/Minz/ExtensionManager.php
index 9e6a3155a,000000000..5880e80f6
mode 100644,000000..100644
--- a/lib/Minz/ExtensionManager.php
+++ b/lib/Minz/ExtensionManager.php
@@@ -1,248 -1,0 +1,249 @@@
+<?php
+
+/**
+ * An extension manager to load extensions present in EXTENSIONS_PATH.
+ *
+ * @todo see coding style for methods!!
+ */
+class Minz_ExtensionManager {
+ private static $ext_metaname = 'metadata.json';
+ private static $ext_entry_point = 'extension.php';
+ private static $ext_list = array();
+ private static $ext_list_enabled = array();
+
+ private static $ext_auto_enabled = array();
+
+ // List of available hooks. Please keep this list sorted.
+ private static $hook_list = array(
+ 'entry_before_display' => array(), // function($entry) -> Entry | null
+ 'entry_before_insert' => array(), // function($entry) -> Entry | null
+ 'feed_before_insert' => array(), // function($feed) -> Feed | null
+ );
+ private static $ext_to_hooks = array();
+
+ /**
+ * Initialize the extension manager by loading extensions in EXTENSIONS_PATH.
+ *
+ * A valid extension is a directory containing metadata.json and
+ * extension.php files.
+ * metadata.json is a JSON structure where the only required fields are
+ * `name` and `entry_point`.
+ * extension.php should contain at least a class named <name>Extension where
+ * <name> must match with the entry point in metadata.json. This class must
+ * inherit from Minz_Extension class.
+ */
+ public static function init() {
+ $list_potential_extensions = array_values(array_diff(
+ scandir(EXTENSIONS_PATH),
+ array('..', '.')
+ ));
+
- self::$ext_auto_enabled = Minz_Configuration::extensionsEnabled();
++ $system_conf = Minz_Configuration::get('system');
++ self::$ext_auto_enabled = $system_conf->extensions_enabled;
+
+ foreach ($list_potential_extensions as $ext_dir) {
+ $ext_pathname = EXTENSIONS_PATH . '/' . $ext_dir;
+ $metadata_filename = $ext_pathname . '/' . self::$ext_metaname;
+
+ // Try to load metadata file.
+ if (!file_exists($metadata_filename)) {
+ // No metadata file? Invalid!
+ continue;
+ }
+ $meta_raw_content = file_get_contents($metadata_filename);
+ $meta_json = json_decode($meta_raw_content, true);
+ if (!$meta_json || !self::is_valid_metadata($meta_json)) {
+ // metadata.json is not a json file? Invalid!
+ // or metadata.json is invalid (no required information), invalid!
+ Minz_Log::warning('`' . $metadata_filename . '` is not a valid metadata file');
+ continue;
+ }
+
+ $meta_json['path'] = $ext_pathname;
+
+ // Try to load extension itself
+ $extension = self::load($meta_json);
+ if (!is_null($extension)) {
+ self::register($extension);
+ }
+ }
+ }
+
+ /**
+ * Indicates if the given parameter is a valid metadata array.
+ *
+ * Required fields are:
+ * - `name`: the name of the extension
+ * - `entry_point`: a class name to load the extension source code
+ * If the extension class name is `TestExtension`, entry point will be `Test`.
+ * `entry_point` must be composed of alphanumeric characters.
+ *
+ * @param $meta is an array of values.
+ * @return true if the array is valid, false else.
+ */
+ public static function is_valid_metadata($meta) {
+ return !(empty($meta['name']) ||
+ empty($meta['entrypoint']) ||
+ !ctype_alnum($meta['entrypoint']));
+ }
+
+ /**
+ * Load the extension source code based on info metadata.
+ *
+ * @param $info an array containing information about extension.
+ * @return an extension inheriting from Minz_Extension.
+ */
+ public static function load($info) {
+ $entry_point_filename = $info['path'] . '/' . self::$ext_entry_point;
+ $ext_class_name = $info['entrypoint'] . 'Extension';
+
+ include($entry_point_filename);
+
+ // Test if the given extension class exists.
+ if (!class_exists($ext_class_name)) {
+ Minz_Log::warning('`' . $ext_class_name .
+ '` cannot be found in `' . $entry_point_filename . '`');
+ return null;
+ }
+
+ // Try to load the class.
+ $extension = null;
+ try {
+ $extension = new $ext_class_name($info);
+ } catch (Minz_ExtensionException $e) {
+ // We cannot load the extension? Invalid!
+ Minz_Log::warning('In `' . $metadata_filename . '`: ' . $e->getMessage());
+ return null;
+ }
+
+ // Test if class is correct.
+ if (!($extension instanceof Minz_Extension)) {
+ Minz_Log::warning('`' . $ext_class_name .
+ '` is not an instance of `Minz_Extension`');
+ return null;
+ }
+
+ return $extension;
+ }
+
+ /**
+ * Add the extension to the list of the known extensions ($ext_list).
+ *
+ * If the extension is present in $ext_auto_enabled and if its type is "system",
+ * it will be enabled in the same time.
+ *
+ * @param $ext a valid extension.
+ */
+ public static function register($ext) {
+ $name = $ext->getName();
+ self::$ext_list[$name] = $ext;
+
+ if ($ext->getType() === 'system' &&
+ in_array($name, self::$ext_auto_enabled)) {
+ self::enable($ext->getName());
+ }
+
+ self::$ext_to_hooks[$name] = array();
+ }
+
+ /**
+ * Enable an extension so it will be called when necessary.
+ *
+ * The extension init() method will be called.
+ *
+ * @param $ext_name is the name of a valid extension present in $ext_list.
+ */
+ public static function enable($ext_name) {
+ if (isset(self::$ext_list[$ext_name])) {
+ $ext = self::$ext_list[$ext_name];
+ self::$ext_list_enabled[$ext_name] = $ext;
+ $ext->enable();
+ $ext->init();
+ }
+ }
+
+ /**
+ * Enable a list of extensions.
+ *
+ * @param $ext_list the names of extensions we want to load.
+ */
+ public static function enable_by_list($ext_list) {
+ foreach ($ext_list as $ext_name) {
+ self::enable($ext_name);
+ }
+ }
+
+ /**
+ * Return a list of extensions.
+ *
+ * @param $only_enabled if true returns only the enabled extensions (false by default).
+ * @return an array of extensions.
+ */
+ public static function list_extensions($only_enabled = false) {
+ if ($only_enabled) {
+ return self::$ext_list_enabled;
+ } else {
+ return self::$ext_list;
+ }
+ }
+
+ /**
+ * Return an extension by its name.
+ *
+ * @param $ext_name the name of the extension.
+ * @return the corresponding extension or null if it doesn't exist.
+ */
+ public static function find_extension($ext_name) {
+ if (!isset(self::$ext_list[$ext_name])) {
+ return null;
+ }
+
+ return self::$ext_list[$ext_name];
+ }
+
+ /**
+ * Add a hook function to a given hook.
+ *
+ * The hook name must be a valid one. For the valid list, see self::$hook_list
+ * array keys.
+ *
+ * @param $hook_name the hook name (must exist).
+ * @param $hook_function the function name to call (must be callable).
+ * @param $ext the extension which register the hook.
+ */
+ public static function addHook($hook_name, $hook_function, $ext) {
+ if (isset(self::$hook_list[$hook_name]) && is_callable($hook_function)) {
+ self::$hook_list[$hook_name][] = $hook_function;
+ self::$ext_to_hooks[$ext->getName()][] = $hook_name;
+ }
+ }
+
+ /**
+ * Call functions related to a given hook.
+ *
+ * The hook name must be a valid one. For the valid list, see self::$hook_list
+ * array keys.
+ *
+ * @param $hook_name the hook to call.
+ * @param additionnal parameters (for signature, please see self::$hook_list comments)
+ * @todo hook functions will have different signatures. So the $res = func($args);
+ * $args = $res; will not work for all of them in the future. We must
+ * find a better way to call hooks.
+ */
+ public static function callHook($hook_name) {
+ $args = func_get_args();
+ unset($args[0]);
+
+ $result = $args[1];
+ foreach (self::$hook_list[$hook_name] as $function) {
+ $result = call_user_func_array($function, $args);
+
+ if (is_null($result)) {
+ break;
+ }
+
+ $args = $result;
+ }
+ return $result;
+ }
+}
diff --cc lib/Minz/Translate.php
index aa96728f2,1b4102ca9..b05c9c695
--- a/lib/Minz/Translate.php
+++ b/lib/Minz/Translate.php
@@@ -25,79 -30,30 +25,88 @@@ class Minz_Translate
private static $translates = array();
/**
- * Load $lang_name and $lang_path based on configuration and selected language.
+ * Init the translation object.
- * @param $lang_list the list of available languages.
+ * @param $lang_name the lang to show.
*/
- public static function init() {
- $l = Minz_Configuration::language();
- self::$lang_name = Minz_Session::param('language', $l);
- public static function init($lang_list, $lang_name) {
- self::$lang_list = $lang_list;
++ public static function init($lang_name) {
+ self::$lang_name = $lang_name;
- self::$lang_path = APP_PATH . '/i18n/' . self::$lang_name . '/';
+ self::$lang_files = array();
+ self::$translates = array();
-
+ self::registerPath(APP_PATH . '/i18n');
}
/**
- * Alias for init().
+ * Reset the translation object with a new language.
+ * @param $lang_name the new language to use
+ */
+ public static function reset($lang_name) {
- self::init(self::$lang_list, $lang_name);
++ self::init($lang_name);
+ }
+
+ /**
+ * Return the list of available languages.
+ * @return an array.
++ * @todo fix this method.
*/
- public static function reset() {
- self::init();
+ public static function availableLanguages() {
- return self::$lang_list;
++ return array();
+ }
+
+ /**
+ * Register a new path and load i18n files inside.
+ *
+ * @param $path a path containing i18n directories (e.g. ./en/, ./fr/).
+ */
+ public static function registerPath($path) {
+ // We load first i18n files for the current language.
+ $lang_path = $path . '/' . self::$lang_name;
+ $list_i18n_files = array_values(array_diff(
+ scandir($lang_path),
+ array('..', '.')
+ ));
+
+ // Each file basename correspond to a top-level i18n key. For each of
+ // these keys we store the file pathname and mark translations must be
+ // reloaded (by setting $translates[$i18n_key] to null).
+ foreach ($list_i18n_files as $i18n_filename) {
+ $i18n_key = basename($i18n_filename, '.php');
+ if (!isset(self::$lang_files[$i18n_key])) {
+ self::$lang_files[$i18n_key] = array();
+ }
+ self::$lang_files[$i18n_key][] = $lang_path . '/' . $i18n_filename;
+ self::$translates[$i18n_key] = null;
+ }
+ }
+
+ /**
+ * Load the files associated to $key into $translates.
+ *
+ * @param $key the top level i18n key we want to load.
+ */
+ private static function loadKey($key) {
+ // The top level key is not in $lang_files, it means it does not exist!
+ if (!isset(self::$lang_files[$key])) {
+ Minz_Log::debug($key . ' is not a valid top level key');
+ return false;
+ }
+
+ self::$translates[$key] = array();
+
+ foreach (self::$lang_files[$key] as $lang_pathname) {
+ $i18n_array = include($lang_pathname);
+ if (!is_array($i18n_array)) {
+ Minz_Log::warning('`' . $lang_pathname . '` does not contain a PHP array');
+ continue;
+ }
+
+ // We must avoid to erase previous data so we just override them if
+ // needed.
+ self::$translates[$key] = array_replace_recursive(
+ self::$translates[$key], $i18n_array
+ );
+ }
+
+ return true;
}
/**
diff --cc lib/lib_rss.php
index c2bd2bfb3,ffd56eae4..083e87745
--- a/lib/lib_rss.php
+++ b/lib/lib_rss.php
@@@ -342,6 -385,22 +386,46 @@@ function recursive_unlink($dir)
unlink($filename);
}
}
+
return rmdir($dir);
}
+
+
+ /**
+ * Remove queries where $get is appearing.
+ * @param $get the get attribute which should be removed.
+ * @param $queries an array of queries.
+ * @return the same array whithout those where $get is appearing.
+ */
+ function remove_query_by_get($get, $queries) {
+ $final_queries = array();
+ foreach ($queries as $key => $query) {
+ if (empty($query['get']) || $query['get'] !== $get) {
+ $final_queries[$key] = $query;
+ }
+ }
+ return $final_queries;
+ }
++
++
++/**
++ * Add a value in an array and take care it is unique.
++ * @param $array the array in which we add the value.
++ * @param $value the value to add.
++ */
++function array_push_unique(&$array, $value) {
++ $found = array_search($value, $array) !== false;
++ if (!$found) {
++ $array[] = $value;
++ }
++}
++
++
++/**
++ * Remove a value from an array.
++ * @param $array the array from wich value is removed.
++ * @param $value the value to remove.
++ */
++function array_remove(&$array, $value) {
++ $array = array_diff($array, array($value));
++}