Skip to content

Commit

Permalink
Merge pull request #6 from acemir/master
Browse files Browse the repository at this point in the history
Now the tweet text create links from hashtags, mentions, urls.
Added new field that parse the tweet time to get Twitter style "time ago".
  • Loading branch information
borisaguilar committed Nov 18, 2014
2 parents 369858c + 3faf40d commit 6a80cb0
Show file tree
Hide file tree
Showing 12 changed files with 233 additions and 33 deletions.
1 change: 1 addition & 0 deletions database.xml
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
id_user INT UNSIGNED NOT NULL,
id_tweet VARCHAR(255) NOT NULL,
screen_name VARCHAR(255) NOT NULL,
created_at VARCHAR(255) NOT NULL,
userurl VARCHAR(255) NULL,
text VARCHAR(260),
PRIMARY KEY (id_user,id_tweet)
Expand Down
37 changes: 37 additions & 0 deletions language/br/twitter_lang.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
<?php
/**
* Ionize Module lang file
* Lang terms must always be prefixed by "module_<module_name>"
* to avoid conflict with core / other translations items
*
*/

$lang['module_twitter_title'] = "Módulo Twitter";
$lang['module_twitter_about'] = "Informações sobre o módulo Twitter...";
$lang['module_twitter_button_create_user'] = "Adicionar usuário twitter";
$lang['module_twitter_title_edit_user'] = "Editar usuário";
$lang['module_twitter_label_username'] = "Nome da conta";
$lang['module_twitter_label_accesstoken'] = "Access Token";
$lang['module_twitter_label_accesstokensecret'] = "Access Token Secret";
$lang['module_twitter_label_consumerkey'] = "API Key";
$lang['module_twitter_label_consumersecret'] = "API Secret";
$lang['module_twitter_label_max_time_difference'] = "Intervalo de atualização (segundos)";

$lang['module_twitter_about_time'] = 'cerca de ';
$lang['module_twitter_ago'] = ' atrás';
$lang['module_twitter_now'] = 'agora';
$lang['module_twitter_second'] = 'segundo';
$lang['module_twitter_seconds'] = 'segundos';
$lang['module_twitter_minute'] = 'minuto';
$lang['module_twitter_minutes'] = 'minutos';
$lang['module_twitter_hour'] = 'hora';
$lang['module_twitter_hours'] = 'horas';
$lang['module_twitter_day'] = 'dia';
$lang['module_twitter_days'] = 'dias';
$lang['module_twitter_week'] = 'semana';
$lang['module_twitter_weeks'] = 'semanas';
$lang['module_twitter_month'] = 'mês';
$lang['module_twitter_months'] = 'meses';
$lang['module_twitter_year'] = 'ano';
$lang['module_twitter_years'] = 'anos';
?>
10 changes: 0 additions & 10 deletions language/en/index.html

This file was deleted.

34 changes: 27 additions & 7 deletions language/en/twitter_lang.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,30 @@
$lang['module_twitter_title'] = "Twitter module";
$lang['module_twitter_about'] = "About the Twitter module...";
$lang['module_twitter_button_create_user'] = "Add twitter user";
$lang['ionize_module_twitter_label_username'] = "Twitter Account Name";
$lang['ionize_module_twitter_label_accesstoken'] = "Twitter Api Access Token";
$lang['ionize_module_twitter_label_accesstokensecret'] = "Access Token Secret";
$lang['ionize_module_twitter_label_consumerkey'] = "Consumer Key";
$lang['ionize_module_twitter_label_consumersecret'] = "Consumer Secret";
$lang['ionize_module_twitter_label_max_time_difference'] = "Tweet update interval (seconds)";
$lang['ionize_module_twitter_title_edit_user'] = "Edit User Account";
$lang['module_twitter_title_edit_user'] = "Edit User Account";
$lang['module_twitter_label_username'] = "Twitter Account Name";
$lang['module_twitter_label_accesstoken'] = "Twitter Api Access Token";
$lang['module_twitter_label_accesstokensecret'] = "Access Token Secret";
$lang['module_twitter_label_consumerkey'] = "Consumer Key";
$lang['module_twitter_label_consumersecret'] = "Consumer Secret";
$lang['module_twitter_label_max_time_difference'] = "Tweet update interval (seconds)";

$lang['module_twitter_about_time'] = 'about ';
$lang['module_twitter_ago'] = ' ago';
$lang['module_twitter_now'] = 'just now';
$lang['module_twitter_second'] = 'second';
$lang['module_twitter_seconds'] = 'seconds';
$lang['module_twitter_minute'] = 'minute';
$lang['module_twitter_minutes'] = 'minutes';
$lang['module_twitter_hour'] = 'hour';
$lang['module_twitter_hours'] = 'hours';
$lang['module_twitter_day'] = 'day';
$lang['module_twitter_days'] = 'days';
$lang['module_twitter_week'] = 'week';
$lang['module_twitter_weeks'] = 'weeks';
$lang['module_twitter_month'] = 'month';
$lang['module_twitter_months'] = 'months';
$lang['module_twitter_year'] = 'year';
$lang['module_twitter_years'] = 'years';

?>
47 changes: 47 additions & 0 deletions language/es/twitter_lang.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
<?php
/**
* Ionize Module lang file
* Lang terms must always be prefixed by "module_<module_name>"
* to avoid conflict with core / other translations items
*
*/

$lang['module_twitter_title'] = "Twitter module";
$lang['module_twitter_about'] = "About the Twitter module...";
$lang['module_twitter_button_create_user'] = "Add twitter user";
$lang['module_twitter_title_edit_user'] = "Edit User Account";
$lang['module_twitter_label_username'] = "Twitter Account Name";
$lang['module_twitter_label_accesstoken'] = "Twitter Api Access Token";
$lang['module_twitter_label_accesstokensecret'] = "Access Token Secret";
$lang['module_twitter_label_consumerkey'] = "Consumer Key";
$lang['module_twitter_label_consumersecret'] = "Consumer Secret";
$lang['module_twitter_label_max_time_difference'] = "Tweet update interval (seconds)";

$lang['module_twitter_less_then_three_seconds'] = "ahora";
$lang['module_twitter_less_then_minute'] = " s";
$lang['module_twitter_less_then_two_minutes'] = "1 m";
$lang['module_twitter_less_then_hour'] = " m";
$lang['module_twitter_less_then_two_hours'] = "1 h";
$lang['module_twitter_less_then_day'] = " h";
$lang['module_twitter_less_then_two_days'] = "ayer";
$lang['module_twitter_less_then_year'] = " d";
$lang['module_twitter_more_then_year'] = "+1 a";

$lang['module_twitter_about_time'] = 'hace cerca de ';
$lang['module_twitter_ago'] = ' ';
$lang['module_twitter_now'] = 'ahora';
$lang['module_twitter_second'] = 'segundo';
$lang['module_twitter_seconds'] = 'segundos';
$lang['module_twitter_minute'] = 'minuto';
$lang['module_twitter_minutes'] = 'minutos';
$lang['module_twitter_hour'] = 'hora';
$lang['module_twitter_hours'] = 'horas';
$lang['module_twitter_day'] = 'día';
$lang['module_twitter_days'] = 'días';
$lang['module_twitter_week'] = 'semana';
$lang['module_twitter_weeks'] = 'semanas';
$lang['module_twitter_month'] = 'mes';
$lang['module_twitter_months'] = 'meses';
$lang['module_twitter_year'] = 'año';
$lang['module_twitter_years'] = 'años';
?>
38 changes: 38 additions & 0 deletions language/it/twitter_lang.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
<?php
/**
* Ionize Module lang file
* Lang terms must always be prefixed by "module_<module_name>"
* to avoid conflict with core / other translations items
*
*/

$lang['module_twitter_title'] = "Modulo Twitter";
$lang['module_twitter_about'] = "Informazioni sul modulo Twitter...";
$lang['module_twitter_button_create_user'] = "Aggiungi utente twitter";
$lang['module_twitter_title_edit_user'] = "Modifica dati account";
$lang['module_twitter_label_username'] = "Nome utente Twitter";
$lang['module_twitter_label_accesstoken'] = "Api Access Token Twitter";
$lang['module_twitter_label_accesstokensecret'] = "Access Token Secret";
$lang['module_twitter_label_consumerkey'] = "Consumer Key";
$lang['module_twitter_label_consumersecret'] = "Consumer Secret";
$lang['module_twitter_label_max_time_difference'] = "Intervallo aggiornamento Tweet (secondi)";

$lang['module_twitter_about_time'] = 'circa ';
$lang['module_twitter_ago'] = ' fa';
$lang['module_twitter_now'] = 'adesso';
$lang['module_twitter_second'] = 'secondo';
$lang['module_twitter_seconds'] = 'secondi';
$lang['module_twitter_minute'] = 'minuto';
$lang['module_twitter_minutes'] = 'minuti';
$lang['module_twitter_hour'] = 'ore';
$lang['module_twitter_hours'] = 'ore';
$lang['module_twitter_day'] = 'giorno';
$lang['module_twitter_days'] = 'giorni';
$lang['module_twitter_week'] = 'settimana';
$lang['module_twitter_weeks'] = 'settimane';
$lang['module_twitter_month'] = 'mese';
$lang['module_twitter_months'] = 'mesi';
$lang['module_twitter_year'] = 'anno';
$lang['module_twitter_years'] = 'anni';

?>
38 changes: 38 additions & 0 deletions language/pt/twitter_lang.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
<?php
/**
* Ionize Module lang file
* Lang terms must always be prefixed by "module_<module_name>"
* to avoid conflict with core / other translations items
*
*/

$lang['module_twitter_title'] = "Módulo Twitter";
$lang['module_twitter_about'] = "Informações sobre o módulo Twitter...";
$lang['module_twitter_button_create_user'] = "Adicionar usuário twitter";
$lang['module_twitter_title_edit_user'] = "Editar usuário";
$lang['module_twitter_label_username'] = "Nome da conta";
$lang['module_twitter_label_accesstoken'] = "Access Token";
$lang['module_twitter_label_accesstokensecret'] = "Access Token Secret";
$lang['module_twitter_label_consumerkey'] = "API Key";
$lang['module_twitter_label_consumersecret'] = "API Secret";
$lang['module_twitter_label_max_time_difference'] = "Intervalo de atualização (segundos)";

$lang['module_twitter_about_time'] = 'cerca de ';
$lang['module_twitter_ago'] = ' atrás';
$lang['module_twitter_now'] = 'agora';
$lang['module_twitter_second'] = 'segundo';
$lang['module_twitter_seconds'] = 'segundos';
$lang['module_twitter_minute'] = 'minuto';
$lang['module_twitter_minutes'] = 'minutos';
$lang['module_twitter_hour'] = 'hora';
$lang['module_twitter_hours'] = 'horas';
$lang['module_twitter_day'] = 'dia';
$lang['module_twitter_days'] = 'dias';
$lang['module_twitter_week'] = 'semana';
$lang['module_twitter_weeks'] = 'semanas';
$lang['module_twitter_month'] = 'mês';
$lang['module_twitter_months'] = 'meses';
$lang['module_twitter_year'] = 'ano';
$lang['module_twitter_years'] = 'anos';

?>
44 changes: 36 additions & 8 deletions libraries/twitter_tags.php
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ public static function tag_tweets(FTL_Binding $tag)
* @return String Tag attribute or ''
*
* @usage <ion:twitter:tweets>
* <ion:tweet field="id_user|id_tweet|screen_name|userurl|text" />
* <ion:tweet field="id_user|id_tweet|screen_name|userurl|created_at|text" />
* </ion:twitter:tweets>
*
*/
Expand All @@ -141,14 +141,42 @@ public static function tag_tweet(FTL_Binding $tag)
$text = self::output_value($tag, $tweet[$field]);

if ($field == 'text') {
$text = preg_replace("%www\.%", "http://www.", $text);
$text = preg_replace("%http://http://www\.%", "http://www.", $text);
$text = preg_replace("%https://http://www\.%", "https://www.", $text);
$exUrl = "/(http|https|ftp|ftps)\:\/\/[a-zA-Z0-9\-\.]+\.[a-zA-Z]{2,3}(\/\S*)?/";
preg_match_all($exUrl, $text, $url);
foreach($url[0] as $k=>$v) $text = str_replace($url[0][$k], '<a href="'.$url[0][$k].'" target="_blank" rel="nofollow">'.$url[0][$k].'</a>', $text);
$text = preg_replace('/(https?:\/\/[^\s"<>]+)/','<a href="$1" target="_blank" rel="nofollow">$1</a>', $text);
$text = preg_replace('/(^|[\n\s])@([^\s"\t\n\r<:]*)/is', '$1<a href="http://twitter.com/$2" target="_blank" rel="nofollow">@$2</a>', $text);
$text = preg_replace('/(^|[\n\s])#([^\s"\t\n\r<:]*)/is', '$1<a href="http://twitter.com/search?q=%23$2" target="_blank" rel="nofollow">#$2</a>', $text);
}

if ($field == 'created_at') {
$format = $tag->getAttribute('format');
$d = time()-strtotime($text);
$t = array(
'year'=>31556926,
'month'=>2629744,
'week'=>604800,
'day'=>86400,
'hour'=>3600,
'minute'=>60,
'second'=>1
);

if ($format == 'short' || $format == 'medium' || $format == 'long' || $format == 'complete') {
$text = date(lang('dateformat_'.$format), strtotime($text));
// TODO >> This value is not being translated. Should behave like <ion:date format="complete" />
}
else {
// Simple function to get "time ago"
$text=lang('module_twitter_now');

foreach($t as $u=>$s){
if($s<=$d){
$v=floor($d/$s);
$text=lang('module_twitter_about_time').$v.' '.lang('module_twitter_'.$u.($v==1?'':'s')).lang('module_twitter_ago');
break;
}
}
}
}

return $text;
}

Expand Down
1 change: 1 addition & 0 deletions models/twitter_user_model.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ public function update_user($id_user, $content){
'id_tweet' => $tweet->id_str,
'screen_name' => $tweet->user->screen_name,
'userurl' => $tweet->user->url,
'created_at' => $tweet->created_at,
'text' => $tweet->text
);
$this->{$this->db_group}->insert($this->_tweets_table, $data);
Expand Down
2 changes: 1 addition & 1 deletion views/admin/toolboxes/twitter_toolbox.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
admin_url + 'module/twitter/user/create',
{
'width':350,
'height':250
'height':220
}
);
});
Expand Down
12 changes: 6 additions & 6 deletions views/admin/user_detail.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
<!-- username -->
<dl class="small">
<dt>
<label for="username<?php echo $id ?>"><?php echo lang('ionize_module_twitter_label_username')?></label>
<label for="username<?php echo $id ?>"><?php echo lang('module_twitter_label_username')?></label>
</dt>
<dd>
<!--
Expand All @@ -26,7 +26,7 @@
<!-- accesstoken -->
<dl class="small">
<dt>
<label for="accesstoken<?php echo $id ?>"><?php echo lang('ionize_module_twitter_label_accesstoken')?></label>
<label for="accesstoken<?php echo $id ?>"><?php echo lang('module_twitter_label_accesstoken')?></label>
</dt>
<dd>
<input id="accesstoken<?php echo $id ?>" name="accesstoken" class="inputtext required" type="text" value="<?php echo $accesstoken ?>" data-validators="required"/>
Expand All @@ -36,7 +36,7 @@
<!-- accesstokensecret -->
<dl class="small">
<dt>
<label for="accesstokensecret<?php echo $id ?>"><?php echo lang('ionize_module_twitter_label_accesstokensecret')?></label>
<label for="accesstokensecret<?php echo $id ?>"><?php echo lang('module_twitter_label_accesstokensecret')?></label>
</dt>
<dd>
<input id="accesstokensecret<?php echo $id ?>" name="accesstokensecret" class="inputtext required" type="text" value="<?php echo $accesstokensecret ?>" data-validators="required"/>
Expand All @@ -46,7 +46,7 @@
<!-- consumerkey -->
<dl class="small">
<dt>
<label for="consumerkey<?php echo $id ?>"><?php echo lang('ionize_module_twitter_label_consumerkey')?></label>
<label for="consumerkey<?php echo $id ?>"><?php echo lang('module_twitter_label_consumerkey')?></label>
</dt>
<dd>
<input id="consumerkey<?php echo $id ?>" name="consumerkey" class="inputtext required" type="text" value="<?php echo $consumerkey ?>" data-validators="required"/>
Expand All @@ -56,7 +56,7 @@
<!-- consumersecret -->
<dl class="small">
<dt>
<label for="consumersecret<?php echo $id ?>"><?php echo lang('ionize_module_twitter_label_consumersecret')?></label>
<label for="consumersecret<?php echo $id ?>"><?php echo lang('module_twitter_label_consumersecret')?></label>
</dt>
<dd>
<input id="consumersecret<?php echo $id ?>" name="consumersecret" class="inputtext required" type="text" value="<?php echo $consumersecret ?>" data-validators="required"/>
Expand All @@ -66,7 +66,7 @@
<!-- max_time_difference -->
<dl class="small">
<dt>
<label for="max_time_difference<?php echo $id ?>"><?php echo lang('ionize_module_twitter_label_max_time_difference')?></label>
<label for="max_time_difference<?php echo $id ?>"><?php echo lang('module_twitter_label_max_time_difference')?></label>
</dt>
<dd>
<input id="max_time_difference<?php echo $id ?>" name="max_time_difference" class="inputtext required" type="text" value="<?php echo $max_time_difference ?>" data-validators="validate-integer required"/>
Expand Down
2 changes: 1 addition & 1 deletion views/admin/user_list.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
'module/twitter/user/get/' + id, // URL of the controller
{
'width':350,
'height':200
'height':220
}
);
});
Expand Down

0 comments on commit 6a80cb0

Please sign in to comment.