aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGravatar Alexandre Alapetite <alexandre@alapetite.fr> 2014-02-23 21:26:38 +0100
committerGravatar Alexandre Alapetite <alexandre@alapetite.fr> 2014-02-23 21:26:38 +0100
commit86846e7b97acb44a2ea0460d7951f7ef90558afd (patch)
tree606a266e2fc8198c2851abf7488c02a2afebf608
parentdb120b4ed41584c7e33bfe63015f948e6230f1ab (diff)
parent27764b36353b3066a9e92da2a96ac17b546295be (diff)
Merge pull request #433 from aledeg/share
Improve sharing
-rwxr-xr-xapp/Controllers/configureController.php12
-rw-r--r--app/Models/Configuration.php56
-rw-r--r--app/Models/Share.php44
-rw-r--r--app/i18n/en.php3
-rw-r--r--app/i18n/fr.php3
-rw-r--r--app/views/configure/sharing.phtml77
-rw-r--r--app/views/helpers/view/normal_view.phtml73
-rw-r--r--data/shares.php75
-rw-r--r--p/scripts/main.js28
9 files changed, 219 insertions, 152 deletions
diff --git a/app/Controllers/configureController.php b/app/Controllers/configureController.php
index ad8bc546a..104fa8900 100755
--- a/app/Controllers/configureController.php
+++ b/app/Controllers/configureController.php
@@ -192,16 +192,8 @@ class FreshRSS_configure_Controller extends Minz_ActionController {
public function sharingAction () {
if (Minz_Request::isPost ()) {
- $this->view->conf->_sharing (array(
- 'shaarli' => Minz_Request::param ('shaarli', false),
- 'wallabag' => Minz_Request::param ('wallabag', false),
- 'diaspora' => Minz_Request::param ('diaspora', false),
- 'twitter' => Minz_Request::param ('twitter', false),
- 'g+' => Minz_Request::param ('g+', false),
- 'facebook' => Minz_Request::param ('facebook', false),
- 'email' => Minz_Request::param ('email', false),
- 'print' => Minz_Request::param ('print', false),
- ));
+ $params = Minz_Request::params();
+ $this->view->conf->_sharing ($params['share']);
$this->view->conf->save();
invalidateHttpCache();
diff --git a/app/Models/Configuration.php b/app/Models/Configuration.php
index 2b719c370..052e28ba8 100644
--- a/app/Models/Configuration.php
+++ b/app/Models/Configuration.php
@@ -48,16 +48,7 @@ class FreshRSS_Configuration {
'bottomline_tags' => true,
'bottomline_date' => true,
'bottomline_link' => true,
- 'sharing' => array(
- 'shaarli' => '',
- 'wallabag' => '',
- 'diaspora' => '',
- 'twitter' => true,
- 'g+' => true,
- 'facebook' => true,
- 'email' => true,
- 'print' => true,
- ),
+ 'sharing' => array(),
);
private $available_languages = array(
@@ -65,8 +56,10 @@ class FreshRSS_Configuration {
'fr' => 'Français',
);
- public function __construct ($user) {
- $this->filename = DATA_PATH . '/' . $user . '_user.php';
+ private $shares;
+
+ public function __construct($user) {
+ $this->filename = DATA_PATH . DIRECTORY_SEPARATOR . $user . '_user.php';
$data = @include($this->filename);
if (!is_array($data)) {
@@ -80,10 +73,20 @@ class FreshRSS_Configuration {
}
}
$this->data['user'] = $user;
+
+ $this->shares = DATA_PATH . DIRECTORY_SEPARATOR . 'shares.php';
+
+ $shares = @include($this->shares);
+ if (!is_array($shares)) {
+ throw new Minz_PermissionDeniedException($this->shares);
+ }
+
+ $this->data['shares'] = $shares;
}
public function save() {
@rename($this->filename, $this->filename . '.bak.php');
+ unset($this->data['shares']); // Remove shares because it is not intended to be stored in user configuration
if (file_put_contents($this->filename, "<?php\n return " . var_export($this->data, true) . ';', LOCK_EX) === false) {
throw new Minz_PermissionDeniedException($this->filename);
}
@@ -104,16 +107,6 @@ class FreshRSS_Configuration {
}
}
- public function sharing($key = false) {
- if ($key === false) {
- return $this->data['sharing'];
- }
- if (isset($this->data['sharing'][$key])) {
- return $this->data['sharing'][$key];
- }
- return false;
- }
-
public function availableLanguages() {
return $this->available_languages;
}
@@ -187,24 +180,23 @@ class FreshRSS_Configuration {
}
}
public function _sharing ($values) {
- $are_url = array ('shaarli', 'wallabag', 'diaspora');
- foreach ($values as $key => $value) {
- if (in_array($key, $are_url)) {
+ $this->data['sharing'] = array();
+ foreach ($values as $value) {
+ if (array_key_exists('url', $value)) {
$is_url = (
- filter_var ($value, FILTER_VALIDATE_URL) ||
+ filter_var ($value['url'], FILTER_VALIDATE_URL) ||
(version_compare(PHP_VERSION, '5.3.3', '<') &&
(strpos($value, '-') > 0) &&
($value === filter_var($value, FILTER_SANITIZE_URL)))
); //PHP bug #51192
-
if (!$is_url) {
- $value = '';
+ continue;
+ }
+ if (!array_key_exists('name', $value) || strcmp($value['name'], '') === 0) {
+ $value['name'] = $value['type'];
}
- } elseif (!is_bool($value)) {
- $value = true;
}
-
- $this->data['sharing'][$key] = $value;
+ $this->data['sharing'][] = $value;
}
}
public function _theme($value) {
diff --git a/app/Models/Share.php b/app/Models/Share.php
new file mode 100644
index 000000000..b146db722
--- /dev/null
+++ b/app/Models/Share.php
@@ -0,0 +1,44 @@
+<?php
+
+class FreshRSS_Share {
+
+ static public function generateUrl($options, $selected, $link, $title) {
+ $share = $options[$selected['type']];
+ $matches = array(
+ '~URL~',
+ '~TITLE~',
+ '~LINK~',
+ );
+ $replaces = array(
+ $selected['url'],
+ self::transformData($title, self::getTransform($share, 'title')),
+ self::transformData($link, self::getTransform($share, 'link')),
+ );
+ $url = str_replace($matches, $replaces, $share['url']);
+ return $url;
+ }
+
+ static private function transformData($data, $transform) {
+ if (!is_array($transform)) {
+ return $data;
+ }
+ if (count($transform) === 0) {
+ return $data;
+ }
+ foreach ($transform as $action) {
+ $data = call_user_func($action, $data);
+ }
+ return $data;
+ }
+
+ static private function getTransform($options, $type) {
+ $transform = $options['transform'];
+
+ if (array_key_exists($type, $transform)) {
+ return $transform[$type];
+ }
+
+ return $transform;
+ }
+
+}
diff --git a/app/i18n/en.php b/app/i18n/en.php
index 932513588..d4fd491a3 100644
--- a/app/i18n/en.php
+++ b/app/i18n/en.php
@@ -166,6 +166,8 @@ return array (
'http_username' => 'HTTP username',
'http_password' => 'HTTP password',
'blank_to_disable' => 'Leave blank to disable',
+ 'share_name' => 'Share name to display',
+ 'share_url' => 'Share URL to use',
'not_yet_implemented' => 'Not yet implemented',
'access_protected_feeds' => 'Connection allows to access HTTP protected RSS feeds',
'no_selected_feed' => 'No feed selected.',
@@ -230,6 +232,7 @@ return array (
'more_information' => 'More information',
'activate_sharing' => 'Activate sharing',
'shaarli' => 'Shaarli',
+ 'blogotext' => 'Blogotext',
'wallabag' => 'wallabag',
'diaspora' => 'Diaspora*',
'twitter' => 'Twitter',
diff --git a/app/i18n/fr.php b/app/i18n/fr.php
index ab7843d12..7420e2fdd 100644
--- a/app/i18n/fr.php
+++ b/app/i18n/fr.php
@@ -166,6 +166,8 @@ return array (
'http_username' => 'Identifiant HTTP',
'http_password' => 'Mot de passe HTTP',
'blank_to_disable' => 'Laissez vide pour désactiver',
+ 'share_name' => 'Nom du partage à afficher',
+ 'share_url' => 'URL du partage à utiliser',
'not_yet_implemented' => 'Pas encore implémenté',
'access_protected_feeds' => 'La connexion permet d’accéder aux flux protégés par une authentification HTTP',
'no_selected_feed' => 'Aucun flux sélectionné.',
@@ -230,6 +232,7 @@ return array (
'more_information' => 'Plus d’informations',
'activate_sharing' => 'Activer le partage',
'shaarli' => 'Shaarli',
+ 'blogotext' => 'Blogotext',
'wallabag' => 'wallabag',
'diaspora' => 'Diaspora*',
'twitter' => 'Twitter',
diff --git a/app/views/configure/sharing.phtml b/app/views/configure/sharing.phtml
index e3ea11665..e46284955 100644
--- a/app/views/configure/sharing.phtml
+++ b/app/views/configure/sharing.phtml
@@ -3,54 +3,41 @@
<div class="post">
<a href="<?php echo _url ('index', 'index'); ?>"><?php echo Minz_Translate::t ('back_to_rss_feeds'); ?></a>
- <form method="post" action="<?php echo _url ('configure', 'sharing'); ?>">
+ <form method="post" action="<?php echo _url ('configure', 'sharing'); ?>"
+ data-simple='<div class="form-group"><label class="group-name">##label##</label><div class="group-controls"><a href="#" class="share remove"><?php echo FreshRSS_Themes::icon('close'); ?></a>
+ <input type="hidden" id="share_##key##_type" name="share[##key##][type]" value="##type##" /></div></div>'
+ data-advanced='<div class="form-group"><label class="group-name">##label##</label><div class="group-controls"><a href="#" class="share remove"><?php echo FreshRSS_Themes::icon('close'); ?></a>
+ <input type="hidden" id="share_##key##_type" name="share[##key##][type]" value="##type##" />
+ <input type="text" id="share_##key##_name" name="share[##key##][name]" class="extend" value="" placeholder="<?php echo Minz_Translate::t ('share_name'); ?>" size="64" />
+ <input type="url" id="share_##key##_url" name="share[##key##][url]" class="extend" value="" placeholder="<?php echo Minz_Translate::t ('share_url'); ?>" size="64" />
+ <?php echo FreshRSS_Themes::icon('help'); ?> <a target="_blank" href="##help##"><?php echo Minz_Translate::t ('more_information'); ?></a></div></div>'>
<legend><?php echo Minz_Translate::t ('sharing'); ?></legend>
- <div class="form-group">
- <label class="group-name" for="shaarli">
- <?php echo Minz_Translate::t ('your_shaarli'); ?>
- </label>
- <div class="group-controls">
- <input type="url" id="shaarli" name="shaarli" class="extend" value="<?php echo $this->conf->sharing ('shaarli'); ?>" placeholder="<?php echo Minz_Translate::t ('blank_to_disable'); ?>" size="64" />
-
- <?php echo FreshRSS_Themes::icon('help'); ?> <a target="_blank" href="http://sebsauvage.net/wiki/doku.php?id=php:shaarli"><?php echo Minz_Translate::t ('more_information'); ?></a>
- </div>
- </div>
-
- <div class="form-group">
- <label class="group-name" for="wallabag">
- <?php echo Minz_Translate::t ('your_wallabag'); ?>
- </label>
- <div class="group-controls">
- <input type="url" id="wallabag" name="wallabag" class="extend" value="<?php echo $this->conf->sharing ('wallabag'); ?>" placeholder="<?php echo Minz_Translate::t ('blank_to_disable'); ?>" size="64" />
-
- <?php echo FreshRSS_Themes::icon('help'); ?> <a target="_blank" href="http://www.wallabag.org"><?php echo Minz_Translate::t ('more_information'); ?></a>
- </div>
- </div>
-
- <div class="form-group">
- <label class="group-name" for="diaspora">
- <?php echo Minz_Translate::t ('your_diaspora_pod'); ?>
- </label>
- <div class="group-controls">
- <input type="url" id="diaspora" name="diaspora" class="extend" value="<?php echo $this->conf->sharing ('diaspora'); ?>" placeholder="<?php echo Minz_Translate::t ('blank_to_disable'); ?>" size="64" />
-
- <?php echo FreshRSS_Themes::icon('help'); ?> <a target="_blank" href="https://diasporafoundation.org/"><?php echo Minz_Translate::t ('more_information'); ?></a>
+ <?php foreach ($this->conf->sharing as $key => $sharing): ?>
+ <?php $share = $this->conf->shares[$sharing['type']]; ?>
+ <div class="form-group">
+ <label class="group-name">
+ <?php echo Minz_Translate::t ($sharing['type']); ?>
+ </label>
+ <div class="group-controls">
+ <a href='#' class='share remove'><?php echo FreshRSS_Themes::icon('close'); ?></a>
+ <input type='hidden' id='share_<?php echo $key;?>_type' name="share[<?php echo $key;?>][type]" value='<?php echo $sharing['type']?>' />
+ <?php if ($share['form'] === 'advanced'):?>
+ <input type="text" id="share_<?php echo $key;?>_name" name="share[<?php echo $key;?>][name]" class="extend" value="<?php echo $sharing['name']?>" placeholder="<?php echo Minz_Translate::t ('share_name'); ?>" size="64" />
+ <input type="url" id="share_<?php echo $key;?>_url" name="share[<?php echo $key;?>][url]" class="extend" value="<?php echo $sharing['url']?>" placeholder="<?php echo Minz_Translate::t ('share_url'); ?>" size="64" />
+ <?php echo FreshRSS_Themes::icon('help'); ?> <a target="_blank" href="<?php echo $share['help']?>"><?php echo Minz_Translate::t ('more_information'); ?></a>
+ <?php endif;?>
+ </div>
</div>
- </div>
+ <?php endforeach;?>
- <div class="form-group">
- <label class="group-name"><?php echo Minz_Translate::t ('activate_sharing'); ?></label>
+ <div class="form-group form-actions">
<div class="group-controls">
- <?php
- $services = array ('twitter', 'g+', 'facebook', 'email', 'print');
-
- foreach ($services as $service) {
- ?>
- <label class="checkbox" for="<?php echo $service; ?>">
- <input type="checkbox" name="<?php echo $service; ?>" id="<?php echo $service; ?>" value="1"<?php echo $this->conf->sharing($service) ? ' checked="checked"' : ''; ?> />
- <?php echo Minz_Translate::t ($service); ?>
- </label>
- <?php } ?>
+ <a href='#' class='share add'><?php echo FreshRSS_Themes::icon('add'); ?></a>
+ <select>
+ <?php foreach($this->conf->shares as $key => $params):?>
+ <option value='<?php echo $key?>' data-form='<?php echo $params['form']?>' data-help='<?php echo $params['help']?>'><?php echo Minz_Translate::t($key) ?></option>
+ <?php endforeach; ?>
+ </select>
</div>
</div>
@@ -61,4 +48,4 @@
</div>
</div>
</form>
-</div>
+</div> \ No newline at end of file
diff --git a/app/views/helpers/view/normal_view.phtml b/app/views/helpers/view/normal_view.phtml
index ae93b627c..f27984025 100644
--- a/app/views/helpers/view/normal_view.phtml
+++ b/app/views/helpers/view/normal_view.phtml
@@ -8,19 +8,10 @@ if (!empty($this->entries)) {
$display_yesterday = true;
$display_others = true;
if ($this->loginOk) {
- $shaarli = $this->conf->sharing ('shaarli');
- $wallabag = $this->conf->sharing ('wallabag');
- $diaspora = $this->conf->sharing ('diaspora');
+ $sharing = $this->conf->sharing;
} else {
- $shaarli = '';
- $wallabag = '';
- $diaspora = '';
+ $sharing = array();
}
- $twitter = $this->conf->sharing ('twitter');
- $google_plus = $this->conf->sharing ('g+');
- $facebook = $this->conf->sharing ('facebook');
- $email = $this->conf->sharing ('email');
- $print = $this->conf->sharing ('print');
$hidePosts = !$this->conf->display_posts;
$lazyload = $this->conf->lazyload;
$topline_read = $this->conf->topline_read;
@@ -29,9 +20,7 @@ if (!empty($this->entries)) {
$topline_link = $this->conf->topline_link;
$bottomline_read = $this->conf->bottomline_read;
$bottomline_favorite = $this->conf->bottomline_favorite;
- $bottomline_sharing = $this->conf->bottomline_sharing && (
- $shaarli || $wallabag || $diaspora || $twitter ||
- $google_plus || $facebook || $email || $print);
+ $bottomline_sharing = $this->conf->bottomline_sharing && (count($sharing));
$bottomline_tags = $this->conf->bottomline_tags;
$bottomline_date = $this->conf->bottomline_date;
$bottomline_link = $this->conf->bottomline_link;
@@ -146,55 +135,13 @@ if (!empty($this->entries)) {
<ul class="dropdown-menu">
<li class="dropdown-close"><a href="#close">❌</a></li>
- <?php if ($shaarli) { ?>
- <li class="item share">
- <a target="_blank" href="<?php echo $shaarli . '?post=' . $link . '&amp;title=' . $title . '&amp;source=FreshRSS'; ?>">
- <?php echo Minz_Translate::t ('shaarli'); ?>
- </a>
- </li>
- <?php } if ($wallabag) { ?>
- <li class="item share">
- <a target="_blank" href="<?php echo $wallabag . '?action=add&amp;url=' . base64_encode (urldecode($link)); ?>">
- <?php echo Minz_Translate::t ('wallabag'); ?>
- </a>
- </li>
- <?php } if ($diaspora) { ?>
- <li class="item share">
- <a target="_blank" href="<?php echo $diaspora . '/bookmarklet?url=' . $link . '&amp;title=' . $title; ?>">
- <?php echo Minz_Translate::t ('diaspora'); ?>
- </a>
- </li>
- <?php } if ($twitter) { ?>
- <li class="item share">
- <a target="_blank" href="https://twitter.com/share?url=<?php echo $link; ?>&amp;text=<?php echo $title; ?>">
- <?php echo Minz_Translate::t ('twitter'); ?>
- </a>
- </li>
- <?php } if ($google_plus) { ?>
- <li class="item share">
- <a target="_blank" href="https://plus.google.com/share?url=<?php echo $link; ?>">
- <?php echo Minz_Translate::t ('g+'); ?>
- </a>
- </li>
- <?php } if ($facebook) { ?>
- <li class="item share">
- <a target="_blank" href="https://www.facebook.com/sharer.php?u=<?php echo $link; ?>&amp;t=<?php echo $title; ?>">
- <?php echo Minz_Translate::t ('facebook'); ?>
- </a>
- </li>
- <?php } if ($email) { ?>
- <li class="item share">
- <a href="mailto:?subject=<?php echo urldecode($title); ?>&amp;body=<?php echo $link; ?>">
- <?php echo Minz_Translate::t ('by_email'); ?>
- </a>
- </li>
- <?php } if ($print) { ?>
- <li class="item share">
- <a href="#" class="print-article">
- <?php echo Minz_Translate::t ('print'); ?>
- </a>
- </li>
- <?php } ?>
+ <?php foreach ($sharing as $share) :?>
+ <li class="item share">
+ <a target="_blank" href="<?php echo FreshRSS_Share::generateUrl($this->conf->shares, $share, $item->link(), $item->title() . ' . ' . $feed->name())?>">
+ <?php echo (array_key_exists('name', $share)) ? $share['name'] : Minz_Translate::t ($share['type']);?>
+ </a>
+ </li>
+ <?php endforeach;?>
</ul>
</div>
<?php } ?>
diff --git a/data/shares.php b/data/shares.php
new file mode 100644
index 000000000..44176f1bf
--- /dev/null
+++ b/data/shares.php
@@ -0,0 +1,75 @@
+<?php
+
+/*
+ * This is a configuration file. You shouldn't modify it unless you know what
+ * you are doing. If you want to add a share type, this is where you need to do
+ * it.
+ *
+ * For each share there is different configuration options. Here is the description
+ * of those options:
+ * - url is a mandatory option. It is a string representing the share URL. It
+ * supports 3 different placeholders for custom data. The ~URL~ placeholder
+ * represents the URL of the system used to share, it is configured by the
+ * user. The ~LINK~ placeholder represents the link of the shared article.
+ * The ~TITLE~ placeholder represents the title of the shared article.
+ * - transform is an array of transformation to apply on links and titles
+ * - help is a URL to a help page
+ */
+
+return array(
+ 'shaarli' => array(
+ 'url' => '~URL~?post=~LINK~&amp;title=~TITLE~&amp;source=FreshRSS',
+ 'transform' => array('urlencode'),
+ 'help' => 'http://sebsauvage.net/wiki/doku.php?id=php:shaarli',
+ 'form' => 'advanced',
+ ),
+ 'blogotext' => array(
+ 'url' => '~URL~/admin/links.php?url=~LINK~',
+ 'transform' => array(),
+ 'help' => 'http://lehollandaisvolant.net/blogotext/fr/',
+ 'form' => 'advanced',
+ ),
+ 'wallabag' => array(
+ 'url' => '~URL~?action=add&amp;url=~LINK~',
+ 'transform' => array(
+ 'link' => array('base64_encode'),
+ 'title' => array(),
+ ),
+ 'help' => 'http://www.wallabag.org/',
+ 'form' => 'advanced',
+ ),
+ 'diaspora' => array(
+ 'url' => '~URL~/bookmarklet?url=~LINK~&amp;title=~TITLE~',
+ 'transform' => array('urlencode'),
+ 'help' => 'https://diasporafoundation.org/',
+ 'form' => 'advanced',
+ ),
+ 'twitter' => array(
+ 'url' => 'https://twitter.com/share?url=~LINK~&amp;text=~TITLE~',
+ 'transform' => array('urlencode'),
+ 'form' => 'simple',
+ ),
+ 'g+' => array(
+ 'url' => 'https://plus.google.com/share?url=~LINK~',
+ 'transform' => array('urlencode'),
+ 'form' => 'simple',
+ ),
+ 'facebook' => array(
+ 'url' => 'https://www.facebook.com/sharer.php?u=~LINK~&amp;t=~TITLE~',
+ 'transform' => array('urlencode'),
+ 'form' => 'simple',
+ ),
+ 'email' => array(
+ 'url' => 'mailto:?subject=~TITLE~&amp;body=~LINK~',
+ 'transform' => array(
+ 'link' => array('urlencode'),
+ 'title' => array(),
+ ),
+ 'form' => 'simple',
+ ),
+ 'print' => array(
+ 'url' => '#',
+ 'transform' => array(),
+ 'form' => 'simple',
+ ),
+);
diff --git a/p/scripts/main.js b/p/scripts/main.js
index beb77a19c..ec27bd50c 100644
--- a/p/scripts/main.js
+++ b/p/scripts/main.js
@@ -1,6 +1,7 @@
"use strict";
var $stream = null,
- isCollapsed = true;
+ isCollapsed = true,
+ shares = 0;
function is_normal_mode() {
return $stream.hasClass('normal');
@@ -945,7 +946,7 @@ function init_confirm_action() {
}
function init_print_action() {
- $('.print-article').click(function () {
+ $('.item.share > a[href="#"]').click(function () {
var content = "<html><head><style>"
+ "body { font-family: Serif; text-align: justify; }"
+ "a { color: #000; text-decoration: none; }"
@@ -965,6 +966,27 @@ function init_print_action() {
});
}
+function init_share_observers() {
+ shares = $('.form-group:not(".form-actions")').length;
+
+ $('.post').on('click', '.share.remove', function(e){
+ e.preventDefault();
+ $(this).parents('.form-group').remove();
+ });
+
+ $('.share.add').on('click',function(e){
+ e.preventDefault();
+ var opt = $(this).siblings('select').find(':selected');
+ var row = $(this).parents('form').data(opt.data('form'));
+ row = row.replace('##label##', opt.html(), 'g');
+ row = row.replace('##type##', opt.val(), 'g');
+ row = row.replace('##help##', opt.data('help'), 'g');
+ row = row.replace('##key##', shares, 'g');
+ $(this).parents('.form-actions').before(row);
+ shares++;
+ });
+};
+
function init_all() {
if (!(window.$ && window.url_freshrss && ((!full_lazyload) || $.fn.lazyload))) {
if (window.console) {
@@ -994,6 +1016,8 @@ function init_all() {
init_shortcuts();
init_print_action();
window.setInterval(refreshUnreads, 120000);
+ } else {
+ init_share_observers();
}
if (window.console) {