Skip to content
This repository has been archived by the owner on Apr 16, 2023. It is now read-only.

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
aldolat committed Jun 14, 2020
2 parents b519bb2 + 3abe964 commit f3dc1ea
Show file tree
Hide file tree
Showing 10 changed files with 89 additions and 39 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,11 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.

## [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
* Added tweet author.
Expand All @@ -27,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
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
5 changes: 4 additions & 1 deletion aldolat-twitter.php
Original file line number Diff line number Diff line change
Expand Up @@ -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/
Expand Down Expand Up @@ -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();
Expand Down
5 changes: 5 additions & 0 deletions changelog.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
== Changelog ==

= 0.1.0 =

* Added new method for getting links attributes.
* Separated fetch method from returning tweets.

= 0.0.4 =

* Added tweet author.
Expand Down
89 changes: 62 additions & 27 deletions includes/class-aldolat-twitter-core.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php
/**
* The plugin core class.
* The plugin class for managing tweets.
*
* @since 0.0.1
* @package AldolatTwitter
Expand Down Expand Up @@ -31,12 +31,14 @@ class Aldolat_Twitter_Core {
* @access private
* @since 0.0.4
*/
private $plugin_settings = array();
private $plugin_settings;

/**
* Constructon method.
*
* @param array $args The default parameters.
* @since 0.0.1
* @access public
*/
public function __construct( $args ) {
$defaults = aldolat_twitter_get_defaults();
Expand All @@ -58,8 +60,9 @@ 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
*/
public function fetch() {
$params = array(
Expand All @@ -70,44 +73,58 @@ public function fetch() {
'tweet_mode' => 'extended',
);

$html = '<div id="twitter-feed">';

$widget_id = preg_replace( '/\D/', '', $this->plugin_settings['widget_id'] );

$feed = get_transient( 'aldolat-twitter-tweets-' . $widget_id );

if ( false === $feed ) {
// Grab user timeline.
$resp = $this->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 );
} else {
$tweets = $feed;
}

if ( $this->plugin_settings['new_tab'] ) {
$new_tab_text = 'rel="external noreferrer nofollow noopener" target="_blank" ';
} else {
$new_tab_text = '';
}
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 = '<div id="twitter-feed">';

$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 .= '<div class="tweet">';
$html .= '<a ' . $new_tab_text . 'href="https://twitter.com/' . $this->plugin_settings['screen_name'] . '/status/' . $tweet->id_str . '">';
$html .= '<time class="tweet-date">' . $this->get_tweet_time( $tweet->created_at ) . '</time>';
$html .= '</a>';
$html .= '<span class="tweet-author">';
$html .= ' ' . esc_html__( 'by', 'aldolat-twitter' ) . ' <a ' . $new_tab_text . 'href="https://twitter.com/' . $this->plugin_settings['screen_name'] . '">' . $this->plugin_settings['screen_name'] . '</a>';
$html .= '</span>';
$html .= '<div class="tweet-body">' . $this->format( $tweet ) . '</div>';
$html .= '</div>';
$output .= '<div class="tweet">';
$output .= '<a ' . $new_tab_text . $twitter_link . '/status/' . $tweet->id_str . '">';
$output .= '<time class="tweet-date">' . $this->get_tweet_time( $tweet->created_at ) . '</time>';
$output .= '</a> ';
$output .= '<span class="tweet-author">';
$output .= esc_html__( 'by', 'aldolat-twitter' ) . ' ';
$output .= '<a ' . $new_tab_text . $twitter_link . '">';
$output .= $this->plugin_settings['screen_name'];
$output .= '</a>';
$output .= '</span>';
$output .= '<div class="tweet-body">' . $this->format( $tweet ) . '</div>';
$output .= '</div>';
}

$html .= '</div>';
$output .= '</div>';

return $html;
return $output;
}

/**
Expand All @@ -116,6 +133,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 );
Expand All @@ -128,16 +146,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(
Expand Down Expand Up @@ -181,6 +196,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.
Expand All @@ -199,4 +216,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;
}
}
2 changes: 1 addition & 1 deletion includes/class-aldolat-twitter-widget.php
Original file line number Diff line number Diff line change
Expand Up @@ -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'];

Expand Down
2 changes: 1 addition & 1 deletion includes/class-aldolat-twitter.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 ) );
}
Expand Down
6 changes: 3 additions & 3 deletions languages/aldolat-twitter-it_IT.po
Original file line number Diff line number Diff line change
Expand Up @@ -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 <[email protected]>\n"
"Language-Team: Italian <[email protected]>\n"
Expand Down Expand Up @@ -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"

Expand Down
8 changes: 4 additions & 4 deletions languages/aldolat-twitter.pot
Original file line number Diff line number Diff line change
Expand Up @@ -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 <EMAIL@ADDRESS>\n"
"Language-Team: LANGUAGE <[email protected]>\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"
Expand Down Expand Up @@ -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 ""

Expand Down
2 changes: 1 addition & 1 deletion readme.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down

0 comments on commit f3dc1ea

Please sign in to comment.