From 27764b36353b3066a9e92da2a96ac17b546295be Mon Sep 17 00:00:00 2001 From: Alexis Degrugillier Date: Sat, 22 Feb 2014 16:53:51 -0500 Subject: Improve sharing Previously, the share page can handle only a limited number of shares and only one of each type. Now the configuration has been change to be more flexible and allows an unlimited number of shares. The share description is located in an array and the share configuration is stored along with the user configuration. Note: I tried to include the specific javascript code in a separate file but I did not succeded to import it. --- app/Models/Share.php | 44 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) create mode 100644 app/Models/Share.php (limited to 'app/Models/Share.php') 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 @@ + Date: Sun, 2 Mar 2014 09:24:02 -0500 Subject: Add a default URL value --- app/Models/Share.php | 3 +++ 1 file changed, 3 insertions(+) (limited to 'app/Models/Share.php') diff --git a/app/Models/Share.php b/app/Models/Share.php index b146db722..887fcef05 100644 --- a/app/Models/Share.php +++ b/app/Models/Share.php @@ -3,6 +3,9 @@ class FreshRSS_Share { static public function generateUrl($options, $selected, $link, $title) { + if (!array_key_exists('url', $selected)) { + $selected['url'] = ''; + } $share = $options[$selected['type']]; $matches = array( '~URL~', -- cgit v1.2.3 From e9eca6aff6c7e2e2349b3b6cf714e2e7eb99405e Mon Sep 17 00:00:00 2001 From: Alexis Degrugillier Date: Wed, 5 Mar 2014 20:22:03 -0500 Subject: Sharing optimization Change the storage and display of sharings to improve the time needed to generate the page. Instead of looking for a default value when displaying the sharing links, they are added during the configuration. --- app/Models/Configuration.php | 15 +++++++++++---- app/Models/Share.php | 3 --- app/views/helpers/view/normal_view.phtml | 2 +- 3 files changed, 12 insertions(+), 8 deletions(-) (limited to 'app/Models/Share.php') diff --git a/app/Models/Configuration.php b/app/Models/Configuration.php index 827a1d166..85e891b64 100644 --- a/app/Models/Configuration.php +++ b/app/Models/Configuration.php @@ -193,7 +193,9 @@ class FreshRSS_Configuration { if (!is_array($value)) { continue; } - if (array_key_exists('url', $value)) { + + // Verify URL and add default value when needed + if (array_key_exists('url', $value) && $value['url'] !== null) { $is_url = ( filter_var ($value['url'], FILTER_VALIDATE_URL) || (version_compare(PHP_VERSION, '5.3.3', '<') && @@ -203,10 +205,15 @@ class FreshRSS_Configuration { if (!$is_url) { continue; } - if (!array_key_exists('name', $value) || strcmp($value['name'], '') === 0) { - $value['name'] = $value['type']; - } + } else { + $value['url'] = null; } + + // Add a default name + if (!array_key_exists('name', $value) || strcmp($value['name'], '') === 0) { + $value['name'] = $value['type']; + } + $this->data['sharing'][] = $value; } } diff --git a/app/Models/Share.php b/app/Models/Share.php index 887fcef05..b146db722 100644 --- a/app/Models/Share.php +++ b/app/Models/Share.php @@ -3,9 +3,6 @@ class FreshRSS_Share { static public function generateUrl($options, $selected, $link, $title) { - if (!array_key_exists('url', $selected)) { - $selected['url'] = ''; - } $share = $options[$selected['type']]; $matches = array( '~URL~', diff --git a/app/views/helpers/view/normal_view.phtml b/app/views/helpers/view/normal_view.phtml index ff535c60a..9fd06ebae 100644 --- a/app/views/helpers/view/normal_view.phtml +++ b/app/views/helpers/view/normal_view.phtml @@ -138,7 +138,7 @@ if (!empty($this->entries)) { -- cgit v1.2.3 From 0140448a562b97859be0b9a6e480e1f6aa4d1b1d Mon Sep 17 00:00:00 2001 From: Marien Fressinaud Date: Wed, 7 Jan 2015 14:59:18 +0100 Subject: Refactor FreshRSS_Share object to be more usable - FreshRSS_Share is the only object we manipulate - Add a way to register new share options easily - Move some i18n keys from index.php to gen.php See https://github.com/FreshRSS/FreshRSS/issues/730 --- app/FreshRSS.php | 3 + app/Models/Share.php | 232 +++++++++++++++++++++++++++++++++++--- app/i18n/en/gen.php | 11 ++ app/i18n/en/index.php | 13 +-- app/i18n/fr/conf.php | 2 +- app/i18n/fr/gen.php | 11 ++ app/i18n/fr/index.php | 13 +-- app/views/configure/sharing.phtml | 27 +++-- app/views/index/normal.phtml | 28 +++-- p/scripts/main.js | 2 +- 10 files changed, 272 insertions(+), 70 deletions(-) (limited to 'app/Models/Share.php') diff --git a/app/FreshRSS.php b/app/FreshRSS.php index 06976c88b..254e35fee 100644 --- a/app/FreshRSS.php +++ b/app/FreshRSS.php @@ -32,6 +32,9 @@ class FreshRSS extends Minz_FrontController { FreshRSS_Context::init(); $this->initI18n(); + + FreshRSS_Share::load(join_path(DATA_PATH, 'shares.php')); + $this->loadStylesAndScripts(); $this->loadNotifications(); $this->loadExtensions(); diff --git a/app/Models/Share.php b/app/Models/Share.php index b146db722..db6feda19 100644 --- a/app/Models/Share.php +++ b/app/Models/Share.php @@ -1,44 +1,240 @@ $share_options) { + $share_options['type'] = $share_type; + self::register($share_options); + } + } + + /** + * Return the list of sharing options. + * @return an array of FreshRSS_Share objects. + */ + public static function enum() { + return self::$list_sharing; + } + + /** + * Return FreshRSS_Share object related to the given type. + * @param $type the share type, null if $type is not registered. + */ + public static function get($type) { + if (!isset(self::$list_sharing[$type])) { + return null; + } + + return self::$list_sharing[$type]; + } + + /** + * + */ + private $type = ''; + private $name = ''; + private $url_transform = ''; + private $transform = array(); + private $form_type = 'simple'; + private $help_url = ''; + private $custom_name = null; + private $base_url = null; + private $title = null; + private $link = null; + + /** + * Create a FreshRSS_Share object. + * @param $type is a unique string defining the kind of share option. + * @param $url_transform defines the url format to use in order to share. + * @param $transform is an array of transformations to apply on link and title. + * @param $form_type defines which form we have to use to complete. "simple" + * is typically for a centralized service while "advanced" is for + * decentralized ones. + * @param $help_url is an optional url to give help on this option. + */ + private function __construct($type, $url_transform, $transform = array(), + $form_type, $help_url = '') { + $this->type = $type; + $this->name = _t('gen.share.' . $type); + $this->url_transform = $url_transform; + $this->help_url = $help_url; + + if (!is_array($transform)) { + $transform = array(); + } + $this->transform = $transform; + + if (!in_array($form_type, array('simple', 'advanced'))) { + $form_type = 'simple'; + } + $this->form_type = $form_type; + } + + /** + * Update a FreshRSS_Share object with information from an array. + * @param $options is a list of informations to update where keys should be + * in this list: name, url, title, link. + */ + public function update($options) { + $available_options = array( + 'name' => 'custom_name', + 'url' => 'base_url', + 'title' => 'title', + 'link' => 'link', + ); + + foreach ($options as $key => $value) { + if (!isset($available_options[$key])) { + continue; + } + + $this->$available_options[$key] = $value; + } + } + + /** + * Return the current type of the share option. + */ + public function type() { + return $this->type; + } + + /** + * Return the current form type of the share option. + */ + public function formType() { + return $this->form_type; + } + + /** + * Return the current help url of the share option. + */ + public function help() { + return $this->help_url; + } + + /** + * Return the current name of the share option. + */ + public function name($real = false) { + if ($real || is_null($this->custom_name)) { + return $this->name; + } else { + return $this->custom_name; + } + } + + /** + * Return the current base url of the share option. + */ + public function baseUrl() { + return $this->base_url; + } + + /** + * Return the current url by merging url_transform and base_url. + */ + public function url() { $matches = array( '~URL~', '~TITLE~', '~LINK~', ); $replaces = array( - $selected['url'], - self::transformData($title, self::getTransform($share, 'title')), - self::transformData($link, self::getTransform($share, 'link')), + $this->base_url, + $this->title(), + $this->link(), ); - $url = str_replace($matches, $replaces, $share['url']); - return $url; + return str_replace($matches, $replaces, $this->url_transform); } - static private function transformData($data, $transform) { - if (!is_array($transform)) { - return $data; + /** + * Return the title. + * @param $raw true if we should get the title without transformations. + */ + public function title($raw = false) { + if ($raw) { + return $this->title; } - if (count($transform) === 0) { + + return $this->transform($this->title, $this->getTransform('title')); + } + + /** + * Return the link. + * @param $raw true if we should get the link without transformations. + */ + public function link($raw = false) { + if ($raw) { + return $this->link; + } + + return $this->transform($this->link, $this->getTransform('link')); + } + + /** + * Transform a data with the given functions. + * @param $data the data to transform. + * @param $tranform an array containing a list of functions to apply. + * @return the transformed data. + */ + private static function transform($data, $transform) { + if (!is_array($transform) || empty($transform)) { 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]; + /** + * Get the list of transformations for the given attribute. + * @param $attr the attribute of which we want the transformations. + * @return an array containing a list of transformations to apply. + */ + private function getTransform($attr) { + if (array_key_exists($attr, $this->transform)) { + return $this->transform[$attr]; } - return $transform; + return $this->transform; } - } diff --git a/app/i18n/en/gen.php b/app/i18n/en/gen.php index 43f94f1bc..4a6f8a71b 100644 --- a/app/i18n/en/gen.php +++ b/app/i18n/en/gen.php @@ -128,6 +128,17 @@ return array( 'nothing_to_load' => 'There are no more articles', 'previous' => 'Previous', ), + 'share' => array( + 'blogotext' => 'Blogotext', + 'diaspora' => 'Diaspora*', + 'email' => 'Email', + 'facebook' => 'Facebook', + 'g+' => 'Google+', + 'print' => 'Print', + 'shaarli' => 'Shaarli', + 'twitter' => 'Twitter', + 'wallabag' => 'wallabag', + ), 'short' => array( 'attention' => 'Attention!', 'blank_to_disable' => 'Leave blank to disable', diff --git a/app/i18n/en/index.php b/app/i18n/en/index.php index 941388b68..8e7d81db8 100644 --- a/app/i18n/en/index.php +++ b/app/i18n/en/index.php @@ -55,18 +55,7 @@ return array( 'subscription' => 'Subscriptions management', 'unread' => 'Show only unread', ), - 'share' => array( - '_' => 'Share', - 'blogotext' => 'Blogotext', - 'diaspora' => 'Diaspora*', - 'email' => 'Email', - 'facebook' => 'Facebook', - 'g+' => 'Google+', - 'print' => 'Print', - 'shaarli' => 'Shaarli', - 'twitter' => 'Twitter', - 'wallabag' => 'wallabag', - ), + 'share' => 'Share', 'tag' => array( 'related' => 'Related tags', ), diff --git a/app/i18n/fr/conf.php b/app/i18n/fr/conf.php index 62d6342e9..e91aeb66a 100644 --- a/app/i18n/fr/conf.php +++ b/app/i18n/fr/conf.php @@ -121,7 +121,7 @@ return array( '_' => 'Partage', 'blogotext' => 'Blogotext', 'diaspora' => 'Diaspora*', - 'email' => 'Email', + 'email' => 'Courriel', 'facebook' => 'Facebook', 'g+' => 'Google+', 'more_information' => 'Plus d’informations', diff --git a/app/i18n/fr/gen.php b/app/i18n/fr/gen.php index bb4478360..d990dad4a 100644 --- a/app/i18n/fr/gen.php +++ b/app/i18n/fr/gen.php @@ -128,6 +128,17 @@ return array( 'nothing_to_load' => 'Fin des articles', 'previous' => 'Précédent', ), + 'share' => array( + 'blogotext' => 'Blogotext', + 'diaspora' => 'Diaspora*', + 'email' => 'Courriel', + 'facebook' => 'Facebook', + 'g+' => 'Google+', + 'print' => 'Imprimer', + 'shaarli' => 'Shaarli', + 'twitter' => 'Twitter', + 'wallabag' => 'wallabag', + ), 'short' => array( 'attention' => 'Attention !', 'blank_to_disable' => 'Laissez vide pour désactiver', diff --git a/app/i18n/fr/index.php b/app/i18n/fr/index.php index 3279543bd..f9975c593 100644 --- a/app/i18n/fr/index.php +++ b/app/i18n/fr/index.php @@ -55,18 +55,7 @@ return array( 'subscription' => 'Gestion des abonnements', 'unread' => 'Afficher les non lus', ), - 'share' => array( - '_' => 'Partager', - 'blogotext' => 'Blogotext', - 'diaspora' => 'Diaspora*', - 'email' => 'Courriel', - 'facebook' => 'Facebook', - 'g+' => 'Google+', - 'print' => 'Imprimer', - 'shaarli' => 'Shaarli', - 'twitter' => 'Twitter', - 'wallabag' => 'wallabag', - ), + 'share' => 'Partager', 'tag' => array( 'related' => 'Tags associés', ), diff --git a/app/views/configure/sharing.phtml b/app/views/configure/sharing.phtml index f5c133f07..da7557480 100644 --- a/app/views/configure/sharing.phtml +++ b/app/views/configure/sharing.phtml @@ -15,22 +15,25 @@ '> - sharing as $key => $sharing) { ?> - shares[$sharing['type']]; ?> -
+ sharing as $key => $share_options) { + $share = FreshRSS_Share::get($share_options['type']); + $share->update($share_options); + ?> +
- ' /> - + + formType() === 'advanced') { ?>
- - + +
- + @@ -41,8 +44,10 @@
diff --git a/app/views/index/normal.phtml b/app/views/index/normal.phtml index c2cf7c887..8c6ddd1ee 100644 --- a/app/views/index/normal.phtml +++ b/app/views/index/normal.phtml @@ -129,8 +129,6 @@ if (!empty($this->entries)) { } ?>
  • link()); - $title = urlencode($item->title() . ' · ' . $feed->name()); ?>
  • 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); + ?>
    Date: Sat, 14 Feb 2015 11:00:26 -0500 Subject: Harmonize share configuration view. Before, for shares that don't need options, only a button to remove it was visible. It was source of confusion for users. I changed the look of those shares by using the same layout as others (minus the help). As there is no configuration possible for the url, the field is disabled but it is possible to change the name of the share. See #787 --- app/Models/Share.php | 2 +- app/i18n/de/gen.php | 1 + app/i18n/en/gen.php | 1 + app/i18n/fr/gen.php | 1 + app/views/configure/sharing.phtml | 20 +++++++++++--------- p/scripts/main.js | 2 +- 6 files changed, 16 insertions(+), 11 deletions(-) (limited to 'app/Models/Share.php') diff --git a/app/Models/Share.php b/app/Models/Share.php index db6feda19..2a05f2ee9 100644 --- a/app/Models/Share.php +++ b/app/Models/Share.php @@ -152,7 +152,7 @@ class FreshRSS_Share { * Return the current name of the share option. */ public function name($real = false) { - if ($real || is_null($this->custom_name)) { + if ($real || is_null($this->custom_name) || empty($this->custom_name)) { return $this->name; } else { return $this->custom_name; diff --git a/app/i18n/de/gen.php b/app/i18n/de/gen.php index f3479ed53..3170b29c2 100644 --- a/app/i18n/de/gen.php +++ b/app/i18n/de/gen.php @@ -156,6 +156,7 @@ return array( 'damn' => 'Verdammt!', 'default_category' => 'Unkategorisiert', 'no' => 'Nein', + 'not_applicable' => 'N/A', 'ok' => 'OK!', 'or' => 'oder', 'yes' => 'Ja', diff --git a/app/i18n/en/gen.php b/app/i18n/en/gen.php index 2143822ed..420e73f36 100644 --- a/app/i18n/en/gen.php +++ b/app/i18n/en/gen.php @@ -156,6 +156,7 @@ return array( 'damn' => 'Damn!', 'default_category' => 'Uncategorized', 'no' => 'No', + 'not_applicable' => 'N/A', 'ok' => 'Ok!', 'or' => 'or', 'yes' => 'Yes', diff --git a/app/i18n/fr/gen.php b/app/i18n/fr/gen.php index 1cfec6969..ae946ce0c 100644 --- a/app/i18n/fr/gen.php +++ b/app/i18n/fr/gen.php @@ -156,6 +156,7 @@ return array( 'damn' => 'Arf !', 'default_category' => 'Sans catégorie', 'no' => 'Non', + 'not_applicable' => 'N/A', 'ok' => 'Ok !', 'or' => 'ou', 'yes' => 'Oui', diff --git a/app/views/configure/sharing.phtml b/app/views/configure/sharing.phtml index da7557480..deb1ed6b7 100644 --- a/app/views/configure/sharing.phtml +++ b/app/views/configure/sharing.phtml @@ -4,7 +4,8 @@
    + data-simple='
    +
    ' data-advanced='
    @@ -26,16 +27,17 @@
    +
    + formType() === 'advanced') { ?> -
    - - - -
    - - + - + + + +
    + formType() === 'advanced') { ?> +
    diff --git a/p/scripts/main.js b/p/scripts/main.js index 1be75bb12..7fb583d39 100644 --- a/p/scripts/main.js +++ b/p/scripts/main.js @@ -1097,7 +1097,7 @@ function init_share_observers() { $('.share.add').on('click', function(e) { 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('##label##', opt.html().trim(), 'g'); row = row.replace('##type##', opt.val(), 'g'); row = row.replace('##help##', opt.data('help'), 'g'); row = row.replace('##key##', shares, 'g'); -- cgit v1.2.3 From b501fd6514253d3f7e14e2f09421a614641d3e7f Mon Sep 17 00:00:00 2001 From: Alexandre Alapetite Date: Sat, 27 Feb 2016 14:53:03 +0100 Subject: PHP7 share bug https://github.com/FreshRSS/FreshRSS/issues/1072 --- app/Models/Share.php | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) (limited to 'app/Models/Share.php') diff --git a/app/Models/Share.php b/app/Models/Share.php index 2a05f2ee9..1c8a7e767 100644 --- a/app/Models/Share.php +++ b/app/Models/Share.php @@ -119,11 +119,9 @@ class FreshRSS_Share { ); foreach ($options as $key => $value) { - if (!isset($available_options[$key])) { - continue; + if (isset($available_options[$key])) { + $this->{$available_options[$key]} = $value; } - - $this->$available_options[$key] = $value; } } -- cgit v1.2.3