Index: trunk/extensions/WikiTweet/WikiTweet.i18n.php |
— | — | @@ -30,6 +30,15 @@ |
31 | 31 | 'wikitweet-tweets-tagged' => 'Tweets tagged', |
32 | 32 | 'wikitweet-back-timeline' => 'Back to the timeline', |
33 | 33 | 'wikitweet-tweets-from-room' => 'Tweets from room', |
| 34 | + 'wikitweet-timeago' => '%time% ago', // Do not translate the string "%time%", it is a keyword |
| 35 | + 'wikitweet-hour' => 'hour', |
| 36 | + 'wikitweet-hours' => 'hours', |
| 37 | + 'wikitweet-minute' => 'minute', |
| 38 | + 'wikitweet-minutes' => 'minutes', |
| 39 | + 'wikitweet-second' => 'second', |
| 40 | + 'wikitweet-seconds' => 'seconds', |
| 41 | + 'wikitweet-inthefuture' => 'In the future !!', |
| 42 | + 'wikitweet-fewsecondsago' => 'Few seconds ago' |
34 | 43 | ); |
35 | 44 | |
36 | 45 | /** Message documentation (Message documentation) |
— | — | @@ -92,6 +101,15 @@ |
93 | 102 | 'wikitweet-tweets-tagged' => 'Tweets taggés', |
94 | 103 | 'wikitweet-back-timeline' => 'Retour au flux', |
95 | 104 | 'wikitweet-tweets-from-room' => 'Tweets de la room', |
| 105 | + 'wikitweet-timeago' => 'Il y a %time%', |
| 106 | + 'wikitweet-hour' => 'heure', |
| 107 | + 'wikitweet-hours' => 'heures', |
| 108 | + 'wikitweet-minute' => 'minute', |
| 109 | + 'wikitweet-minutes' => 'minutes', |
| 110 | + 'wikitweet-second' => 'seconde', |
| 111 | + 'wikitweet-seconds' => 'secondes', |
| 112 | + 'wikitweet-inthefuture' => 'Dans le futur !!', |
| 113 | + 'wikitweet-fewsecondsago' => 'Il y a quelques secondes' |
96 | 114 | ); |
97 | 115 | |
98 | 116 | /** Colognian (Ripoarisch) |
Index: trunk/extensions/WikiTweet/WikiTweet.php |
— | — | @@ -45,6 +45,8 @@ |
46 | 46 | $wgAutoloadClasses['ApiQueryWikiTweet'] = "$dir/WikiTweet.api.php"; |
47 | 47 | $wgAPIListModules['wikitweet'] = 'ApiQueryWikiTweet'; |
48 | 48 | |
| 49 | +$wgAutoloadClasses['WikiTweetFunctions'] = "$dir/WikiTweet.functions.php"; |
| 50 | + |
49 | 51 | function wikiTweeter() |
50 | 52 | { |
51 | 53 | global $wgExtensionMessagesFiles, $wgParser, $wgMessageCache; |
Index: trunk/extensions/WikiTweet/WikiTweet.functions.php |
— | — | @@ -1,5 +1,8 @@ |
2 | 2 | <?php |
3 | | -function sendWithPear($mailer, $dest, $headers, $body) |
| 3 | +if ( !defined( 'MEDIAWIKI' ) ) |
| 4 | + die(); |
| 5 | +class WikiTweetFunctions { |
| 6 | + public static function sendWithPear($mailer, $dest, $headers, $body) |
4 | 7 | { |
5 | 8 | $mailResult = $mailer->send($dest, $headers, $body); |
6 | 9 | if( PEAR::isError( $mailResult ) ) { |
— | — | @@ -8,11 +11,12 @@ |
9 | 12 | return true; |
10 | 13 | } |
11 | 14 | } |
12 | | -function send( $to, $from, $subject, $body, $replyto=null ) { |
| 15 | + public static function send( $to, $from, $subject, $body, $replyto=null ) |
| 16 | + { |
13 | 17 | $wgOutputEncoding = 'UTF-8'; |
14 | 18 | $wgEnotifImpersonal = false; |
15 | 19 | $wgErrorString = ''; |
16 | | - $wgEnotifMaxRecips=500; |
| 20 | + $wgEnotifMaxRecips = 500; |
17 | 21 | include('WikiTweet.config.php'); |
18 | 22 | if (is_array( $wgWikiTweet )) { |
19 | 23 | require_once( 'Mail.php' ); |
— | — | @@ -48,10 +52,85 @@ |
49 | 53 | } |
50 | 54 | $chunks = array_chunk( (array)$dest, $wgEnotifMaxRecips ); |
51 | 55 | foreach ($chunks as $chunk) { |
52 | | - $e = sendWithPear($mail_object, $chunk, $headers, $body); |
| 56 | + $e = WikiTweetFunctions::sendWithPear($mail_object, $chunk, $headers, $body); |
53 | 57 | if( $e != true) |
54 | 58 | return $e; |
55 | 59 | } |
56 | 60 | } |
57 | 61 | } |
58 | | -?> |
\ No newline at end of file |
| 62 | + |
| 63 | + public static function str_global_replace( $i__string, $i__array ) |
| 64 | + { |
| 65 | + $o__string = $i__string ; |
| 66 | + foreach($i__array as $l__key => $l__item) |
| 67 | + { |
| 68 | + $o__string = str_replace($l__key, $l__value, $o__string ); |
| 69 | + } |
| 70 | + return $o__string; |
| 71 | + } |
| 72 | + public static function Convert_Date ( $i__old_date ) |
| 73 | + { |
| 74 | + // function to convert a date in a countdown |
| 75 | + $l__nber_seconds = 0 ; |
| 76 | + $l__nber_minutes = 0 ; |
| 77 | + $l__nber_hours = 0 ; |
| 78 | + $l__diff_date = 0 ; |
| 79 | + |
| 80 | + |
| 81 | + $l__diff_date = time() - $i__old_date ; |
| 82 | + if ( $l__diff_date < 0 ) |
| 83 | + { |
| 84 | + // theorically impossible |
| 85 | + $result = wfMsg ( 'wikitweet-inthefuture' ) ; |
| 86 | + } |
| 87 | + elseif ( $l__diff_date < 10 ) |
| 88 | + { |
| 89 | + // less than 10 seconds is "few" |
| 90 | + $result = wfMsg ( 'wikitweet-fewsecondsago' ) ; |
| 91 | + } |
| 92 | + elseif ( $l__diff_date >= 60 ) |
| 93 | + { |
| 94 | + // real conversion |
| 95 | + $l__nber_seconds = $l__diff_date % 60 ; |
| 96 | + $l__new_diff = $l__diff_date - $l__nber_seconds ; |
| 97 | + $l__nber_minutes = $l__new_diff / 60 ; |
| 98 | + if ($l__nber_minutes >= 60) |
| 99 | + { |
| 100 | + $l__old_nber_minutes = $l__nber_minutes ; |
| 101 | + $l__nber_minutes = $l__nber_minutes % 60 ; |
| 102 | + $l__new_nber_minutes = $l__old_nber_minutes - $l__nber_minutes ; |
| 103 | + $l__nber_hours = $l__new_nber_minutes / 60 ; |
| 104 | + } |
| 105 | + } |
| 106 | + else |
| 107 | + { |
| 108 | + $l__nber_seconds = $l__diff_date ; |
| 109 | + } |
| 110 | + //plurals |
| 111 | + $seconds = ( $l__nber_seconds == 1 ) ? wfMsg( 'wikitweet-second' ) : wfMsg( 'wikitweet-seconds' ) ; |
| 112 | + $minutes = ( $l__nber_minutes == 1 ) ? wfMsg( 'wikitweet-minute' ) : wfMsg( 'wikitweet-minutes' ) ; |
| 113 | + $hours = ( $l__nber_hours == 1 ) ? wfMsg( 'wikitweet-hour' ) : wfMsg( 'wikitweet-hours' ) ; |
| 114 | + |
| 115 | + if ($l__nber_hours !=0 && $l__nber_minutes != 0 ) |
| 116 | + { |
| 117 | + $result = str_replace( "%time%" , "$l__nber_hours $hours $l__nber_minutes $minutes" , wfMsg( 'wikitweet-timeago' ) ); // "%time% ago" |
| 118 | + } |
| 119 | + elseif (($l__nber_hours != 0 && $l__nber_minutes == 0 ) || ($l__nber_hours >= 5 ) ) |
| 120 | + { |
| 121 | + $result = str_replace( "%time%" , "$l__nber_hours $hours" , wfMsg( 'wikitweet-timeago' ) ); // "%time% ago" |
| 122 | + } |
| 123 | + elseif (($l__nber_minutes >= 5) || ($l__nber_minutes != 0 && $l__nber_seconds == 0 ) ) |
| 124 | + { |
| 125 | + $result = str_replace( "%time%" , "$l__nber_minutes $minutes" , wfMsg( 'wikitweet-timeago' ) ); // "%time% ago" |
| 126 | + } |
| 127 | + elseif ($l__nber_minutes != 0 && $l__nber_seconds != 0 ) |
| 128 | + { |
| 129 | + $result = str_replace( "%time%" , "$l__nber_minutes $minutes $l__nber_seconds $seconds" , wfMsg( 'wikitweet-timeago' ) ); // "%time% ago" |
| 130 | + } |
| 131 | + elseif ($l__nber_seconds !=0 ) |
| 132 | + { |
| 133 | + $result = str_replace( "%time%" , "$l__nber_seconds $seconds" , wfMsg( 'wikitweet-timeago' ) ); // "%time% ago" |
| 134 | + } |
| 135 | + return $result ; // a string |
| 136 | + } |
| 137 | +} |
Index: trunk/extensions/WikiTweet/WikiTweet.api.php |
— | — | @@ -168,8 +168,8 @@ |
169 | 169 | } |
170 | 170 | |
171 | 171 | $dateSrc = $date.' GMT'; |
172 | | - // TODO : "x hours ago, today, etc" |
173 | | - $date_to_display = date('H:i, F jS', strtotime($dateSrc)); |
| 172 | + $date_to_display = WikiTweetFunctions::Convert_Date(strtotime($dateSrc)); |
| 173 | + //$date_to_display = date('H:i, F jS', strtotime($dateSrc)); |
174 | 174 | |
175 | 175 | $res2 = $dbr->select('wikitweet_avatar','avatar',"`user`='".mysql_real_escape_string($tweetuser)."' ",__METHOD__,false); |
176 | 176 | $row2 = $dbr->fetchObject ( $res2 ); |
— | — | @@ -284,7 +284,6 @@ |
285 | 285 | |
286 | 286 | $dest=array(); |
287 | 287 | $user_email = $wgWikiTweet['wikimail']; |
288 | | - include('WikiTweet.functions.php'); |
289 | 288 | if($tomail==1 or $tomail==2){ |
290 | 289 | $res = $dbr->select('user','user_email',"user_name = '$user' "); |
291 | 290 | if ($dbr->numRows($res) > 0){ |
— | — | @@ -326,7 +325,7 @@ |
327 | 326 | $lenlist += strlen($destmail); |
328 | 327 | } |
329 | 328 | if($lenlist>0){ |
330 | | - send( $dest, $user_email, "A new tweet for or about you !", $status); |
| 329 | + WikiTweetFunctions::send( $dest, $user_email, "A new tweet for or about you !", $status); |
331 | 330 | $text .= 'mail sent'; |
332 | 331 | } |
333 | 332 | |
— | — | @@ -443,4 +442,4 @@ |
444 | 443 | public function getVersion() { |
445 | 444 | return __CLASS__ . ': $Id: WikiTweet.api.php xxxxx 2010-05-09 13:42:00Z Faure.thomas $'; |
446 | 445 | } |
447 | | -} |
\ No newline at end of file |
| 446 | +} |