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 Jul 26, 2020
2 parents b974057 + 02f1641 commit 9c58189
Show file tree
Hide file tree
Showing 11 changed files with 218 additions and 69 deletions.
5 changes: 5 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.3.0] - 2020-07-26
### Changed
* Removed use of gmdate() in favour of wp_date().
* General improvements in the output strings.

## [0.2.0] - 2020-06-20
### Added
* Added option to select type of tweets to retrieve.
Expand Down
5 changes: 4 additions & 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.2.0
**Stable tag** 0.3.0
**License** GPLv3 or later
**License URI** https://www.gnu.org/licenses/gpl-3.0.html

Expand All @@ -23,6 +23,9 @@ Display your Tweets in a widget.

This plugin provides a widget where to display your tweets.

This plugin uses a modified version of the original script made by [Gabriele Romanato](https://gabrieleromanato.com/2018/06/wordpress-creare-un-plugin-per-reperire-i-dati-da-twitter). Thanks to him for his work.


## Filing Bugs

If you have found a bug, please report it on [GitHub](https://github.com/aldolat/aldolat-twitter/issues).
Expand Down
2 changes: 1 addition & 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.2.0
* Version: 0.3.0
* License: GPLv3 or later
* Text Domain: aldolat-twitter
* Domain Path: /languages/
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.3.0 =

* Removed use of gmdate() in favour of wp_date().
* General improvements in the output strings.

= 0.2.0 =

* Added option to select type of tweets to retrieve.
Expand Down
5 changes: 3 additions & 2 deletions includes/aldolat-twitter-widget-form-functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,10 @@ function aldolat_twitter_form_label( $label, $id ) {
* @param string $comment An optional comment to display. It is displayed below the input form.
* @param string $style An optional inline style.
* @param string $class An optional CSS class.
* @param string $type The type of input.
* @uses aldolat_twitter_form_label
*/
function aldolat_twitter_form_input_text( $label, $id, $name, $value, $placeholder = '', $comment = '', $style = '', $class = '' ) {
function aldolat_twitter_form_input_text( $label, $id, $name, $value, $placeholder = '', $comment = '', $style = '', $class = '', $type = 'text' ) {
$class = rtrim( 'widefat aldolat-twitter-input ' . $class );

if ( $style ) {
Expand All @@ -52,7 +53,7 @@ function aldolat_twitter_form_input_text( $label, $id, $name, $value, $placehold
aldolat_twitter_form_label( $label, $id );

?>
<input type="text"
<input type="<?php echo esc_attr( $type ); ?>"
id="<?php echo esc_attr( $id ); ?>"
name="<?php echo esc_attr( $name ); ?>"
value="<?php echo esc_attr( $value ); ?>"
Expand Down
147 changes: 104 additions & 43 deletions includes/class-aldolat-twitter-core.php
Original file line number Diff line number Diff line change
Expand Up @@ -136,44 +136,92 @@ private function get_response() {
* @since 0.1.0
* @access public
*/
public function get_tweets() {
$tweets = $this->fetch();

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

public function the_tweets() {
$tweets = $this->fetch();
$new_tab_text = $this->new_tab( $this->plugin_settings['new_tab'] );

foreach ( $tweets as $tweet ) {
$output .= '<div class="tweet">';
$output .= '<a ' . $new_tab_text . 'href="https://twitter.com/' . $tweet->user->screen_name . '/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 . 'href="https://twitter.com/' . $tweet->user->screen_name . '">';
$output .= $tweet->user->name;
$output .= '</a>';
$output .= '</span>';
$output .= '<div class="tweet-body">' . $this->format( $tweet ) . '</div>';
$output .= '</div>';
}

$output .= '</div>';

return $output;
}

/**
* Returns the difference in seconds between the tweet time and now.
*
* @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 );
return human_time_diff( $new_tweet_time, time() );
?>

<div id="twitter-feed">
<?php
foreach ( $tweets as $tweet ) {
?>
<div class="tweet">
<?php
if ( isset( $tweet->retweeted_status ) ) {
$tweet_screen_name = $tweet->retweeted_status->user->screen_name;
$tweet_user_image = $tweet->retweeted_status->user->profile_image_url_https;
} else {
$tweet_screen_name = $tweet->user->screen_name;
$tweet_user_image = $tweet->user->profile_image_url_https;
}
?>
<p class="tweet-user-image">
<a <?php echo esc_html( $new_tab_text ); ?>href="https://twitter.com/<?php echo esc_html( $tweet_screen_name ); ?>">
<img src="<?php echo esc_html( $tweet_user_image ); ?>" alt="profile picture" width="32" height="32" />
</a>
</p>
<p class="tweet-body">
<?php echo $this->format( $tweet ); ?>
</p>
<?php
if ( $tweet->in_reply_to_status_id ) {
?>
<p class="tweet-in-reply-to">
<?php
printf(
// translators: The original tweet author name and link.
esc_html__( 'In reply to %s', 'aldolat-twitter' ),
'<a href="https://twitter.com/' . esc_html( $tweet->in_reply_to_screen_name ) . '/status/' . esc_html( $tweet->in_reply_to_status_id ) . '">@' . esc_html( $tweet->in_reply_to_screen_name ) . '</a>'
);
?>
</p>
<?php
}
?>
<p class="tweet-date-author">
<?php
if ( isset( $tweet->retweeted_status ) ) {
$tweet_user = $tweet->retweeted_status->user->screen_name;
$tweet_name = $tweet->retweeted_status->user->name;
$tweet_id = $tweet->retweeted_status->id_str;
$tweet_time = $tweet->retweeted_status->created_at;
} else {
$tweet_user = $tweet->user->screen_name;
$tweet_name = $tweet->user->name;
$tweet_id = $tweet->id_str;
$tweet_time = $tweet->created_at;
}
?>
<span class="tweet-date">
<a <?php echo esc_html( $new_tab_text ); ?>href="https://twitter.com/<?php echo esc_html( $tweet_user ); ?>/status/<?php echo esc_html( $tweet_id ); ?>">
<time>
<?php echo esc_html( $this->get_tweet_time( $tweet_time ) ); ?>
</time>
</a>
</span>
<span class="tweet-author">
<?php esc_html_e( 'by', 'aldolat-twitter' ); ?>
<a <?php echo esc_html( $new_tab_text ); ?>href="https://twitter.com/<?php echo esc_html( $tweet_user ); ?>">
<?php echo esc_html( $tweet_name ); ?>
</a>
</span>
<?php
if ( isset( $tweet->retweeted_status ) ) {
printf(
// translators: date and tweet author name
' ' . esc_html__( '(RT on %1$s by %2$s)', 'aldolat-twitter' ),
'<a ' . esc_html( $new_tab_text ) . 'href="https://twitter.com/' . esc_html( $tweet->user->screen_name ) . '/status/' . esc_html( $tweet->id_str ) . '">' . esc_html( $this->get_tweet_time( $tweet->created_at ) ) . '</a>',
'<a ' . esc_html( $new_tab_text ) . 'href="https://twitter.com/' . esc_html( $tweet->user->screen_name ) . '">' . esc_html( $tweet->user->name ) . '</a>'
);
}
?>
</p>
</div>
<?php
}
?>
</div>
<?php
}

/**
Expand Down Expand Up @@ -236,23 +284,36 @@ private function format( $tweet ) {
* @access private
*/
private function get_tweet_time( $tweet_time ) {
// Get the local GMT offset and date/time formats.
$local_offset = (int) get_option( 'gmt_offset' ) * HOUR_IN_SECONDS;
// Get the local date/time formats.
$datetime_format = get_option( 'date_format' ) . ' ' . get_option( 'time_format' );

// Convert tweet time into UNIX timestamp and add local offset.
$unix_tweet_time = strtotime( $tweet_time ) + $local_offset;
// Convert tweet time into UNIX timestamp.
$unix_tweet_time = strtotime( $tweet_time );

// The tweet date/time is returned in the "... ago" form if the tweet is up to a day old.
if ( DAY_IN_SECONDS < ( time() - $unix_tweet_time ) ) {
$time = gmdate( $datetime_format, $unix_tweet_time );
$time = wp_date( $datetime_format, $unix_tweet_time );
} else {
$time = $this->relative_time( $tweet_time ) . ' ' . esc_html__( 'ago', 'aldolat-twitter' );
$time = $this->relative_time( $tweet_time );
}

return $time;
}

/**
* Returns the difference in seconds between the tweet time and now,
* including the '... ago' string.
*
* @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 ) {
$tweet_time = strtotime( $t );
return human_time_diff( $tweet_time, time() ) . ' ' . esc_html__( 'ago', 'aldolat-twitter' );
}

/**
* Get the HTML rel attribute for links.
*
Expand Down
30 changes: 25 additions & 5 deletions 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( $instance );
echo $aldolat_tweets->get_tweets();
$aldolat_tweets->the_tweets();

echo $args['after_widget'];

Expand Down Expand Up @@ -273,28 +273,48 @@ public function form( $instance ) {
esc_html__( 'Consumer Key:', 'aldolat-twitter' ),
$this->get_field_id( 'consumer_key' ),
$this->get_field_name( 'consumer_key' ),
esc_attr( $instance['consumer_key'] )
esc_attr( $instance['consumer_key'] ),
'',
__( 'Insert Consumer Key', 'aldolat-twitter' ),
'',
'',
'password'
);
// Consumer secret.
aldolat_twitter_form_input_text(
esc_html__( 'Consumer secret:', 'aldolat-twitter' ),
$this->get_field_id( 'consumer_secret' ),
$this->get_field_name( 'consumer_secret' ),
esc_attr( $instance['consumer_secret'] )
esc_attr( $instance['consumer_secret'] ),
'',
__( 'Insert Consumer Secret', 'aldolat-twitter' ),
'',
'',
'password'
);
// Oauth token.
aldolat_twitter_form_input_text(
esc_html__( 'Oauth token:', 'aldolat-twitter' ),
$this->get_field_id( 'oauth_token' ),
$this->get_field_name( 'oauth_token' ),
esc_attr( $instance['oauth_token'] )
esc_attr( $instance['oauth_token'] ),
'',
__( 'Insert Oauth Token', 'aldolat-twitter' ),
'',
'',
'password'
);
// Oauth token secret.
aldolat_twitter_form_input_text(
esc_html__( 'Oauth token secret:', 'aldolat-twitter' ),
$this->get_field_id( 'oauth_token_secret' ),
$this->get_field_name( 'oauth_token_secret' ),
esc_attr( $instance['oauth_token_secret'] )
esc_attr( $instance['oauth_token_secret'] ),
'',
__( 'Insert Oauth Token Secret', 'aldolat-twitter' ),
'',
'',
'password'
);
?>
</div>
Expand Down
Binary file modified languages/aldolat-twitter-it_IT.mo
Binary file not shown.
44 changes: 35 additions & 9 deletions languages/aldolat-twitter-it_IT.po
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,15 @@ 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-20T14:19:07+02:00\n"
"PO-Revision-Date: 2020-06-20 13:03+0200\n"
"POT-Creation-Date: 2020-07-26T12:56:32+02:00\n"
"PO-Revision-Date: 2020-07-26 12:35+0200\n"
"Last-Translator: Aldo Latino <[email protected]>\n"
"Language-Team: Italian <[email protected]>\n"
"Language: it\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n"
"X-Generator: Lokalize 20.04.2\n"
"X-Generator: Lokalize 20.04.3\n"
"X-Domain: aldolat-twitter\n"
"Plural-Forms: nplurals=2; plural=(n != 1);\n"

Expand Down Expand Up @@ -43,11 +43,21 @@ msgstr "https://www.aldolat.it/"
msgid "My latest tweets"
msgstr "I miei ultimi tweet"

#: includes/class-aldolat-twitter-core.php:152
#. translators: The original tweet author name and link.
#: includes/class-aldolat-twitter-core.php:173
msgid "In reply to %s"
msgstr "In risposta a %s"

#: includes/class-aldolat-twitter-core.php:203
msgid "by"
msgstr "di"
msgstr "da"

#. translators: date and tweet author name
#: includes/class-aldolat-twitter-core.php:212
msgid "(RT on %1$s by %2$s)"
msgstr "(RT il %1$s da %2$s)"

#: includes/class-aldolat-twitter-core.php:250
#: includes/class-aldolat-twitter-core.php:314
msgid "ago"
msgstr "fa"

Expand Down Expand Up @@ -135,14 +145,30 @@ msgstr "Autenticazione su Twitter"
msgid "Consumer Key:"
msgstr "Consumer Key:"

#: includes/class-aldolat-twitter-widget.php:280
#: includes/class-aldolat-twitter-widget.php:278
msgid "Insert Consumer Key"
msgstr "Inserisci la Consumer Key:"

#: includes/class-aldolat-twitter-widget.php:285
msgid "Consumer secret:"
msgstr "Consumer secret:"

#: includes/class-aldolat-twitter-widget.php:287
#: includes/class-aldolat-twitter-widget.php:290
msgid "Insert Consumer Secret"
msgstr "Inserisci il Consumer secret:"

#: includes/class-aldolat-twitter-widget.php:297
msgid "Oauth token:"
msgstr "Oauth token:"

#: includes/class-aldolat-twitter-widget.php:294
#: includes/class-aldolat-twitter-widget.php:302
msgid "Insert Oauth Token"
msgstr "Inserisci l'Oauth token:"

#: includes/class-aldolat-twitter-widget.php:309
msgid "Oauth token secret:"
msgstr "Oauth token secret:"

#: includes/class-aldolat-twitter-widget.php:314
msgid "Insert Oauth Token Secret"
msgstr "Inserisci l'Oauth token secret:"
Loading

0 comments on commit 9c58189

Please sign in to comment.