Skip to content

Commit 61efa5a

Browse files
committed
Date Filter
1 parent 33b924d commit 61efa5a

File tree

3 files changed

+63
-8
lines changed

3 files changed

+63
-8
lines changed

readme.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -277,6 +277,7 @@ This project is licensed under the GPL3 License.
277277
* Feature: Mastodon Logo Filter
278278
* Feature: Between Filter
279279
* Feature: Toot Content Filter
280+
* Feature: Date Filter
280281

281282
### 0.4 "Cassie Lang"
282283

tootpress_blog.php

Lines changed: 35 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -40,18 +40,13 @@ function tootpress_paint_toot( $mastodon_id, $date, $content, $media , $instance
4040
$toot_html.=tootpress_paint_elephant( $instance, $account, $mastodon_id,$backlink);
4141

4242
// Toot Date
43-
if(tootpress_is_language_german()) {
44-
$date=tootpress_convert_mysqldate_to_german_format($date);
45-
} else {
46-
$date=tootpress_convert_mysqldate_to_international_format($date);
47-
}
48-
49-
$toot_html.='<div class="toot-date"><p>'.esc_html($date).'</p></div>';
43+
$toot_html.=tootpress_paint_date($date);
5044

5145
// Toot Content
5246
$content=tootpress_remove_target_blank($content);
47+
$content=wp_kses($content, tootpress_escaping_allowed_html() );
5348
$content=tootpress_toot_content_filter_apply($content);
54-
$toot_html.='<div class="toot-content">'.wp_kses($content, tootpress_escaping_allowed_html() ).'</div>';
49+
$toot_html.='<div class="toot-content">'.$content.'</div>';
5550

5651
// Toot Image
5752
if($media){
@@ -157,6 +152,38 @@ function tootpress_paint_elephant( $instance, $account, $mastodon_id, $backlink)
157152

158153
}
159154

155+
/**
156+
* Paint the Date
157+
*
158+
* @since 0.5
159+
*
160+
* @param string Date (Format: )
161+
* @return string html
162+
*/
163+
164+
function tootpress_paint_date($date) {
165+
166+
// 2023-05-30 22:40:28
167+
168+
$mysqldate=$date;
169+
170+
$date=tootpress_date_filter_apply($date);
171+
172+
if($mysqldate==$date) {
173+
174+
if(tootpress_is_language_german()) {
175+
$date=tootpress_convert_mysqldate_to_german_format($date);
176+
} else {
177+
$date=tootpress_convert_mysqldate_to_international_format($date);
178+
}
179+
180+
}
181+
182+
$date_html.='<div class="toot-date"><p>'.esc_html($date).'</p></div>';
183+
return $date_html;
184+
185+
}
186+
160187
/**
161188
* Creates the Preamble
162189
*

tootpress_hooks.php

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -187,4 +187,31 @@ function tootpress_toot_content_filter_apply($content) {
187187
return $content;
188188
}
189189

190+
/**
191+
* Date Filter
192+
*
193+
* This filter overwrites the date output with custom format
194+
*
195+
* @since 0.5
196+
*
197+
* @param string Date
198+
* @return string Custom Format
199+
*/
200+
201+
function tootpress_date_filter_apply($date) {
202+
203+
// 2023-05-30 22:40:28
204+
205+
$year=substr($date,0,4);
206+
$month=substr($date,5,2);
207+
$day=substr($date,8,2);
208+
$hour=substr($date,11,2);
209+
$minute=substr($date,14,2);
210+
$second=substr($date,17,2);
211+
212+
$date=apply_filters( 'tootpress_date_filter', $date, $year, $month, $day, $hour, $minute, $second );
213+
214+
return $date;
215+
}
216+
190217
?>

0 commit comments

Comments
 (0)