From 5f7ca89496d8a1767a06c8d665d312c1e277d5f1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20Guillot?= Date: Thu, 5 Dec 2013 21:23:46 -0500 Subject: [PATCH] Ability to edit a subscription --- index.php | 41 ++++++++++++++++++++++++++++++++++ locales/fr_FR/translations.php | 14 ++++++++++++ model.php | 32 ++++++++++++++++++++++++++ templates/edit_feed.php | 27 ++++++++++++++++++++++ templates/feeds.php | 6 +++-- vendor/PicoTools/Helper.php | 2 +- 6 files changed, 119 insertions(+), 3 deletions(-) create mode 100644 templates/edit_feed.php diff --git a/index.php b/index.php index 6a79ccb..85e5418 100644 --- a/index.php +++ b/index.php @@ -377,6 +377,47 @@ Router\get_action('refresh-all', function() { }); +// Edit feed form +Router\get_action('edit-feed', function() { + + $id = Request\int_param('feed_id'); + + Response\html(Template\layout('edit_feed', array( + 'values' => Model\get_feed($id), + 'errors' => array(), + 'menu' => 'feeds', + 'title' => t('Edit subscription') + ))); +}); + + +// Submit edit feed form +Router\post_action('edit-feed', function() { + + $values = Request\values(); + list($valid, $errors) = Model\validate_feed_modification($values); + + if ($valid) { + + if (Model\save_feed($values)) { + Session\flash(t('Your subscription has been updated.')); + } + else { + Session\flash_error(t('Unable to edit your subscription.')); + } + + Response\redirect('?action=feeds'); + } + + Response\html(Template\layout('edit_feed', array( + 'values' => $values, + 'errors' => $errors, + 'menu' => 'feeds', + 'title' => t('Edit subscription') + ))); +}); + + // Disable content grabber for a feed Router\get_action('disable-grabber-feed', function() { diff --git a/locales/fr_FR/translations.php b/locales/fr_FR/translations.php index 432d2eb..6a4c774 100644 --- a/locales/fr_FR/translations.php +++ b/locales/fr_FR/translations.php @@ -1,6 +1,20 @@ 'L\'identifiant du flux est obligatoire', + 'The title is required' => 'Le titre est obligatoire', + 'The site url is required' => 'L\'URL du site web est obligatoire', + 'The feed url is required' => 'L\'URL du flux est obligatoire', + 'or' => 'ou', + 'edit' => 'modifier', + 'cancel' => 'annuler', + 'Edit' => 'Modifier', + 'Feed URL' => 'URL du flux', + 'Website URL' => 'URL du site web', + 'Title' => 'Titre', + 'Edit subscription' => 'Modifier l\'abonnement', + 'Unable to edit your subscription.' => 'Impossible de modifier votre abonnement.', + 'Your subscription has been updated.' => 'Votre abonnement a été mis à jour.', 'Older items first' => 'Plus anciens en premier', 'Most recent first' => 'Plus récents en premier', 'Default sorting order for items' => 'Ordre des éléments par défaut', diff --git a/model.php b/model.php index b101a1d..e4295f4 100644 --- a/model.php +++ b/model.php @@ -169,6 +169,19 @@ function export_feeds() } +function save_feed(array $values) +{ + return \PicoTools\singleton('db') + ->table('feeds') + ->eq('id', $values['id']) + ->save(array( + 'title' => $values['title'], + 'site_url' => $values['site_url'], + 'feed_url' => $values['feed_url'] + )); +} + + function import_feeds($content) { $import = new Import($content); @@ -529,6 +542,25 @@ function disable_grabber_feed($feed_id) } +function validate_feed_modification(array $values) +{ + $v = new Validator($values, array( + new Validators\Required('id', t('The feed id is required')), + new Validators\Required('title', t('The title is required')), + new Validators\Required('site_url', t('The site url is required')), + new Validators\Required('feed_url', t('The feed url is required')), + )); + + $result = $v->execute(); + $errors = $v->getErrors(); + + return array( + $result, + $errors + ); +} + + function get_items($status, $offset = null, $limit = null, $order_column = 'updated', $order_direction = 'desc') { return \PicoTools\singleton('db') diff --git a/templates/edit_feed.php b/templates/edit_feed.php new file mode 100644 index 0000000..364632f --- /dev/null +++ b/templates/edit_feed.php @@ -0,0 +1,27 @@ + + +
+ + + + + + + + + + + + +
+ +
+
\ No newline at end of file diff --git a/templates/feeds.php b/templates/feeds.php index a9c0292..937ab36 100644 --- a/templates/feeds.php +++ b/templates/feeds.php @@ -55,10 +55,12 @@ | - + | - + | + +

diff --git a/vendor/PicoTools/Helper.php b/vendor/PicoTools/Helper.php index 1815f58..a3ea708 100644 --- a/vendor/PicoTools/Helper.php +++ b/vendor/PicoTools/Helper.php @@ -51,7 +51,7 @@ function format_bytes($size, $precision = 2) function get_host_from_url($url) { - return escape(parse_url($url, PHP_URL_HOST)); + return escape(parse_url($url, PHP_URL_HOST)) ?: $url; } function summary($value, $min_length = 5, $max_length = 120, $end = '[...]')