From 0012eb82f8a821cc176ccb21a1cb37b00c42acb7 Mon Sep 17 00:00:00 2001 From: Aldo Latino Date: Sun, 14 Jun 2020 07:40:33 +0200 Subject: [PATCH 1/3] Opening 0.1.0, added method for links attributes --- CHANGELOG.md | 2 ++ README.md | 2 +- aldolat-twitter.php | 5 ++- changelog.txt | 4 +++ includes/class-aldolat-twitter-core.php | 43 +++++++++++++++++-------- includes/class-aldolat-twitter.php | 2 +- readme.txt | 2 +- 7 files changed, 43 insertions(+), 17 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index c794b7f..20aa7d2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,8 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/) and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html). ## [Unreleased] +### Added +* Added new method for getting links attributes. ## [0.0.4] - 2020-06-13 ### Added diff --git a/README.md b/README.md index 6d83ed1..263d6da 100644 --- a/README.md +++ b/README.md @@ -5,7 +5,7 @@ **Tags** twitter, sidebar, widget **Requires at least** 5.4 **Tested up to** 5.4 -**Stable tag** 0.0.4 +**Stable tag** 0.1.0 **License** GPLv3 or later **License URI** https://www.gnu.org/licenses/gpl-3.0.html diff --git a/aldolat-twitter.php b/aldolat-twitter.php index 6a782be..582a5c8 100644 --- a/aldolat-twitter.php +++ b/aldolat-twitter.php @@ -18,7 +18,7 @@ * Plugin URI: https://dev.aldolat.it/projects/aldolat-twitter/ * Author: Aldo Latino * Author URI: https://www.aldolat.it/ - * Version: 0.0.4 + * Version: 0.1.0 * License: GPLv3 or later * Text Domain: aldolat-twitter * Domain Path: /languages/ @@ -57,6 +57,9 @@ exit( 'No script kiddies please!' ); } +/** + * Run the class for setting up the plugin. + */ function aldolat_twitter_run() { require_once 'includes/class-aldolat-twitter.php'; $aldolat_twitter = new Aldolat_Twitter(); diff --git a/changelog.txt b/changelog.txt index 180817e..c12ef64 100644 --- a/changelog.txt +++ b/changelog.txt @@ -1,5 +1,9 @@ == Changelog == += 0.1.0 = + +* Added new method for getting links attributes. + = 0.0.4 = * Added tweet author. diff --git a/includes/class-aldolat-twitter-core.php b/includes/class-aldolat-twitter-core.php index e034c55..e00789f 100644 --- a/includes/class-aldolat-twitter-core.php +++ b/includes/class-aldolat-twitter-core.php @@ -1,6 +1,6 @@ connection->get( 'statuses/user_timeline', $params ); - // Grab the favorite tweets. + // Grab favorite tweets. //$resp = $this->connection->get( 'favorites/list', $params ); $tweets = json_decode( $resp ); set_transient( 'aldolat-twitter-tweets-' . $widget_id, $tweets, $this->plugin_settings['cache_duration'] * MINUTE_IN_SECONDS ); @@ -87,11 +90,7 @@ public function fetch() { $tweets = $feed; } - if ( $this->plugin_settings['new_tab'] ) { - $new_tab_text = 'rel="external noreferrer nofollow noopener" target="_blank" '; - } else { - $new_tab_text = ''; - } + $new_tab_text = $this->new_tab( $this->plugin_settings['new_tab'] ); foreach ( $tweets as $tweet ) { $html .= '
'; @@ -116,6 +115,7 @@ public function fetch() { * @param integer $t The formatted datetime of the tweet. * @return integer The difference in seconds * @since 0.0.1 + * @access private */ private function relative_time( $t ) { $new_tweet_time = strtotime( $t ); @@ -128,16 +128,13 @@ private function relative_time( $t ) { * @param object $tweet The object containing the tweet. * @return string $tweet_text The resulting tweet with HTML. * @since 0.0.1 + * @access private */ private function format( $tweet ) { $tweet_text = $tweet->full_text; $tweet_entities = array(); - if ( $this->plugin_settings['new_tab'] ) { - $new_tab_text = 'rel="external noreferrer nofollow noopener" target="_blank" '; - } else { - $new_tab_text = ''; - } + $new_tab_text = $this->new_tab( $this->plugin_settings['new_tab'] ); foreach ( $tweet->entities->urls as $url ) { $tweet_entities[] = array( @@ -181,6 +178,8 @@ private function format( $tweet ) { * * @param string $tweet_time The formatted time of the tweet. * @return string $time The datetime of the tweet or the '... ago' form. + * @since 0.0.1 + * @access private */ private function get_tweet_time( $tweet_time ) { // Get the local GMT offset and date/time formats. @@ -199,4 +198,22 @@ private function get_tweet_time( $tweet_time ) { return $time; } + + /** + * Get the HTML rel attribute for links. + * + * @param bool $new_tab Whether the browser should open links in a new tab. + * @return string $text The rel and target attributes for links. + * @since 0.1.0 + * @access private + */ + private function new_tab( $new_tab ) { + if ( $new_tab ) { + $text = 'rel="external noreferrer nofollow noopener" target="_blank" '; + } else { + $text = ''; + } + + return $text; + } } diff --git a/includes/class-aldolat-twitter.php b/includes/class-aldolat-twitter.php index 5533e52..eed6806 100644 --- a/includes/class-aldolat-twitter.php +++ b/includes/class-aldolat-twitter.php @@ -36,7 +36,7 @@ class Aldolat_Twitter { * @since 0.0.4 */ public function __construct() { - $this->plugin_version = '0.0.4'; + $this->plugin_version = '0.1.0'; $this->plugin_dir_path = trailingslashit( dirname( plugin_dir_path( __FILE__ ) ) ); $this->plugin_dirname = trailingslashit( dirname( plugin_basename( __FILE__ ), 2 ) ); } diff --git a/readme.txt b/readme.txt index 970178f..7777a74 100644 --- a/readme.txt +++ b/readme.txt @@ -4,7 +4,7 @@ Donate link: https://dev.aldolat.it/projects/aldolat-twitter/ Tags: twitter, sidebar, widget Requires at least: 5.4 Tested up to: 5.4 -Stable tag: 0.0.4 +Stable tag: 0.1.0 License: GPLv3 or later License URI: https://www.gnu.org/licenses/gpl-3.0.html From 2c5087c89a302787ed2b931c83865b1a1a9dc71d Mon Sep 17 00:00:00 2001 From: Aldo Latino Date: Sun, 14 Jun 2020 08:24:21 +0200 Subject: [PATCH 2/3] Separated fetch method from returning tweets --- includes/class-aldolat-twitter-core.php | 46 ++++++++++++++++------- includes/class-aldolat-twitter-widget.php | 2 +- 2 files changed, 33 insertions(+), 15 deletions(-) diff --git a/includes/class-aldolat-twitter-core.php b/includes/class-aldolat-twitter-core.php index e00789f..599df65 100644 --- a/includes/class-aldolat-twitter-core.php +++ b/includes/class-aldolat-twitter-core.php @@ -60,7 +60,7 @@ public function __construct( $args ) { /** * Fetch the tweets from Twitter. * - * @return string $html The final HTML with tweets. + * @return array $tweets The array with with tweets. * @since 0.0.1 * @access public */ @@ -73,8 +73,6 @@ public function fetch() { 'tweet_mode' => 'extended', ); - $html = '
'; - $widget_id = preg_replace( '/\D/', '', $this->plugin_settings['widget_id'] ); $feed = get_transient( 'aldolat-twitter-tweets-' . $widget_id ); @@ -90,23 +88,43 @@ public function fetch() { $tweets = $feed; } + return $tweets; + } + + /** + * Get the tweets. + * + * @return string $output The final HTML with tweets. + * @since 0.1.0 + * @access public + */ + public function get_tweets() { + $tweets = $this->fetch(); + + $output = '
'; + $new_tab_text = $this->new_tab( $this->plugin_settings['new_tab'] ); + $twitter_link = 'href="https://twitter.com/' . $this->plugin_settings['screen_name']; + foreach ( $tweets as $tweet ) { - $html .= '
'; - $html .= ''; - $html .= ''; - $html .= ''; - $html .= ''; - $html .= ' ' . esc_html__( 'by', 'aldolat-twitter' ) . ' ' . $this->plugin_settings['screen_name'] . ''; - $html .= ''; - $html .= '
' . $this->format( $tweet ) . '
'; - $html .= '
'; + $output .= '
'; + $output .= 'id_str . '">'; + $output .= ''; + $output .= ' '; + $output .= ''; + $output .= esc_html__( 'by', 'aldolat-twitter' ) . ' '; + $output .= ''; + $output .= $this->plugin_settings['screen_name']; + $output .= ''; + $output .= ''; + $output .= '
' . $this->format( $tweet ) . '
'; + $output .= '
'; } - $html .= '
'; + $output .= '
'; - return $html; + return $output; } /** diff --git a/includes/class-aldolat-twitter-widget.php b/includes/class-aldolat-twitter-widget.php index 3ad250d..2e0ea8c 100644 --- a/includes/class-aldolat-twitter-widget.php +++ b/includes/class-aldolat-twitter-widget.php @@ -91,7 +91,7 @@ public function widget( $args, $instance ) { 'widget_id' => $args['widget_id'], ); $aldolat_tweets = new Aldolat_Twitter_Core( $params ); - echo $aldolat_tweets->fetch(); + echo $aldolat_tweets->get_tweets(); echo $args['after_widget']; From 3abe964a9f34ff7186004f0dba5ae83d3d004e9a Mon Sep 17 00:00:00 2001 From: Aldo Latino Date: Sun, 14 Jun 2020 08:24:37 +0200 Subject: [PATCH 3/3] Releasing 0.1.0 --- CHANGELOG.md | 5 +++++ changelog.txt | 1 + languages/aldolat-twitter-it_IT.po | 6 +++--- languages/aldolat-twitter.pot | 8 ++++---- 4 files changed, 13 insertions(+), 7 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 20aa7d2..435f08e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,8 +6,11 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/) and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html). ## [Unreleased] + +## [0.1.0] - 2020-06-14 ### Added * Added new method for getting links attributes. +* Separated fetch method from returning tweets. ## [0.0.4] - 2020-06-13 ### Added @@ -29,5 +32,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0. * First release of the plugin. [Unreleased]: https://github.com/aldolat/aldolat-twitter/commits/develop +[0.1.0]: https://github.com/aldolat/aldolat-twitter/compare/0.0.4...0.1.0 +[0.0.4]: https://github.com/aldolat/aldolat-twitter/compare/0.0.3...0.0.4 [0.0.3]: https://github.com/aldolat/aldolat-twitter/compare/0.0.2...0.0.3 [0.0.2]: https://github.com/aldolat/aldolat-twitter/compare/0.0.1...0.0.2 diff --git a/changelog.txt b/changelog.txt index c12ef64..29dc701 100644 --- a/changelog.txt +++ b/changelog.txt @@ -3,6 +3,7 @@ = 0.1.0 = * Added new method for getting links attributes. +* Separated fetch method from returning tweets. = 0.0.4 = diff --git a/languages/aldolat-twitter-it_IT.po b/languages/aldolat-twitter-it_IT.po index 5cc0b17..674c45d 100644 --- a/languages/aldolat-twitter-it_IT.po +++ b/languages/aldolat-twitter-it_IT.po @@ -5,7 +5,7 @@ msgid "" msgstr "" "Project-Id-Version: Aldolat Twitter 0.0.1\n" "Report-Msgid-Bugs-To: https://wordpress.org/support/plugin/aldolat-twitter\n" -"POT-Creation-Date: 2020-06-13T22:19:00+02:00\n" +"POT-Creation-Date: 2020-06-14T08:22:12+02:00\n" "PO-Revision-Date: 2020-06-05 21:56+0200\n" "Last-Translator: Aldo Latino \n" "Language-Team: Italian \n" @@ -43,11 +43,11 @@ msgstr "https://www.aldolat.it/" msgid "My latest tweets" msgstr "I miei ultimi tweet" -#: includes/class-aldolat-twitter-core.php:102 +#: includes/class-aldolat-twitter-core.php:116 msgid "by" msgstr "di" -#: includes/class-aldolat-twitter-core.php:197 +#: includes/class-aldolat-twitter-core.php:214 msgid "ago" msgstr "fa" diff --git a/languages/aldolat-twitter.pot b/languages/aldolat-twitter.pot index 003de17..c7318a3 100644 --- a/languages/aldolat-twitter.pot +++ b/languages/aldolat-twitter.pot @@ -2,14 +2,14 @@ # This file is distributed under the same license as the Aldolat Twitter plugin. msgid "" msgstr "" -"Project-Id-Version: Aldolat Twitter 0.0.4\n" +"Project-Id-Version: Aldolat Twitter 0.1.0\n" "Report-Msgid-Bugs-To: https://wordpress.org/support/plugin/aldolat-twitter\n" "Last-Translator: FULL NAME \n" "Language-Team: LANGUAGE \n" "MIME-Version: 1.0\n" "Content-Type: text/plain; charset=UTF-8\n" "Content-Transfer-Encoding: 8bit\n" -"POT-Creation-Date: 2020-06-13T22:19:00+02:00\n" +"POT-Creation-Date: 2020-06-14T08:22:12+02:00\n" "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" "X-Generator: WP-CLI 2.4.0\n" "X-Domain: aldolat-twitter\n" @@ -40,11 +40,11 @@ msgstr "" msgid "My latest tweets" msgstr "" -#: includes/class-aldolat-twitter-core.php:102 +#: includes/class-aldolat-twitter-core.php:116 msgid "by" msgstr "" -#: includes/class-aldolat-twitter-core.php:197 +#: includes/class-aldolat-twitter-core.php:214 msgid "ago" msgstr ""