Ability to edit a subscription

This commit is contained in:
Frédéric Guillot 2013-12-05 21:23:46 -05:00
parent 8291e7f64e
commit 5f7ca89496
6 changed files with 119 additions and 3 deletions

View File

@ -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 // Disable content grabber for a feed
Router\get_action('disable-grabber-feed', function() { Router\get_action('disable-grabber-feed', function() {

View File

@ -1,6 +1,20 @@
<?php <?php
return array( return array(
'The feed id is required' => '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', 'Older items first' => 'Plus anciens en premier',
'Most recent first' => 'Plus récents en premier', 'Most recent first' => 'Plus récents en premier',
'Default sorting order for items' => 'Ordre des éléments par défaut', 'Default sorting order for items' => 'Ordre des éléments par défaut',

View File

@ -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) function import_feeds($content)
{ {
$import = new Import($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') function get_items($status, $offset = null, $limit = null, $order_column = 'updated', $order_direction = 'desc')
{ {
return \PicoTools\singleton('db') return \PicoTools\singleton('db')

27
templates/edit_feed.php Normal file
View File

@ -0,0 +1,27 @@
<div class="page-header">
<h2><?= t('Edit subscription') ?></h2>
<ul>
<li><a href="?action=add"><?= t('add') ?></a></li>
<li><a href="?action=feeds"><?= t('feeds') ?></a></li>
<li><a href="?action=import"><?= t('import') ?></a></li>
<li><a href="?action=export"><?= t('export') ?></a></li>
</ul>
</div>
<form method="post" action="?action=edit-feed" autocomplete="off">
<?= Helper\form_hidden('id', $values) ?>
<?= Helper\form_label(t('Title'), 'title') ?>
<?= Helper\form_text('title', $values, $errors, array('required')) ?>
<?= Helper\form_label(t('Website URL'), 'site_url') ?>
<?= Helper\form_text('site_url', $values, $errors, array('required', 'placeholder="http://..."')) ?>
<?= Helper\form_label(t('Feed URL'), 'feed_url') ?>
<?= Helper\form_text('feed_url', $values, $errors, array('required', 'placeholder="http://..."')) ?>
<div class="form-actions">
<button type="submit" class="btn btn-blue"><?= t('Edit') ?></button> <?= t('or') ?> <a href="?action=feeds"><?= t('cancel') ?></a>
</div>
</form>

View File

@ -55,10 +55,12 @@
<?php if ($feed['enabled']): ?> <?php if ($feed['enabled']): ?>
<span class="hide-mobile"><a href="?action=confirm-disable-feed&amp;feed_id=<?= $feed['id'] ?>"><?= t('disable') ?></a> |</span> <span class="hide-mobile"><a href="?action=confirm-disable-feed&amp;feed_id=<?= $feed['id'] ?>"><?= t('disable') ?></a> |</span>
<a href="?action=refresh-feed&amp;feed_id=<?= $feed['id'] ?>" data-feed-id="<?= $feed['id'] ?>" data-action="refresh-feed"><?= t('refresh') ?></a> <a href="?action=refresh-feed&amp;feed_id=<?= $feed['id'] ?>" data-feed-id="<?= $feed['id'] ?>" data-action="refresh-feed"><?= t('refresh') ?></a> |
<?php else: ?> <?php else: ?>
<span class="hide-mobile"><a href="?action=enable-feed&amp;feed_id=<?= $feed['id'] ?>"><?= t('enable') ?></a></span> <span class="hide-mobile"><a href="?action=enable-feed&amp;feed_id=<?= $feed['id'] ?>"><?= t('enable') ?></a> |</span>
<?php endif ?> <?php endif ?>
<span class="hide-mobile"><a href="?action=edit-feed&amp;feed_id=<?= $feed['id'] ?>"><?= t('edit') ?></a></span>
</p> </p>
</article> </article>
<?php endforeach ?> <?php endforeach ?>

View File

@ -51,7 +51,7 @@ function format_bytes($size, $precision = 2)
function get_host_from_url($url) 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 = '[...]') function summary($value, $min_length = 5, $max_length = 120, $end = '[...]')