From c3f0ce703dbf5ff3a93ea254de41c9f2001bf1e6 Mon Sep 17 00:00:00 2001 From: Marco Hitschler Date: Sun, 25 May 2025 12:24:06 +0200 Subject: [PATCH 01/20] Afterloop Filter --- readme.md | 5 +++++ tootpress_blog.php | 28 ++++++++++++++++++++++++++++ tootpress_hooks.php | 36 ++++++++++++++++++++++++++++++++++++ tootpress_loop.php | 3 +++ 4 files changed, 72 insertions(+) diff --git a/readme.md b/readme.md index 13a2670..8bac3d9 100644 --- a/readme.md +++ b/readme.md @@ -207,6 +207,11 @@ This project is licensed under the GPL3 License. ## Changelog +### 0.5 "xxx" + +* xxx 2025 +* Feature: Afterloop Filter + ### 0.4 "Cassie Lang" * June 2024 diff --git a/tootpress_blog.php b/tootpress_blog.php index 460c8e7..cb6f509 100644 --- a/tootpress_blog.php +++ b/tootpress_blog.php @@ -181,4 +181,32 @@ function tootpress_paint_preamble($tootpress_current_page) { } +/** + * Creates the Afterloop Content + * + * @since 0.5 + * + * @param int TootPress Current Page + * @return string html + */ + + function tootpress_paint_afterloop($tootpress_current_page) { + + $content=''; + $lastpage=tootpress_amount_of_pages(); + + if($tootpress_current_page==$lastpage) { + + $content.=tootpress_afterloop_filter_apply($content); + + if($content) { + $content='
'.$content.'
'; + } + + } + + return $content; + +} + ?> \ No newline at end of file diff --git a/tootpress_hooks.php b/tootpress_hooks.php index 547d6fd..e012f7f 100644 --- a/tootpress_hooks.php +++ b/tootpress_hooks.php @@ -81,4 +81,40 @@ function tootpress_preamble_filter_apply($preamble) { * */ +/** + * Afterloop Filter + * + * This filter outputs html content after the toot loop. + * + * @since 0.5 + * + * @param string Unfiltered Content + * @return html Filtered Content + */ + +function tootpress_afterloop_filter_apply($content) { + $content.=apply_filters( 'tootpress_afterloop_filter', $content ); + return $content; +} + +/** + * Filter Example: tootpress_afterloop_filter + * + * @since 0.5 + * + * @param string Unfiltered Content + * @return html Filtered Content + * + * function tootpress_afterloop_add( $content ) { + * + * // Add your filter code here + * // Example: $content='

Hello World.

'; + * + * return $content; + * + * } + * add_filter( 'tootpress_afterloop_filter', 'tootpress_afterloop_add', 10, 1 ); + * + */ + ?> \ No newline at end of file diff --git a/tootpress_loop.php b/tootpress_loop.php index 6a8b8d5..3643ff8 100644 --- a/tootpress_loop.php +++ b/tootpress_loop.php @@ -38,6 +38,9 @@ function tootpress_content($content) { // TootPress Loop $tootpress_content.=tootpress_loop($tootpress_current_page); + // TootPress Afterloop + $tootpress_content.=tootpress_paint_afterloop($tootpress_current_page); + // TootPress Bottom Navigation $tootpress_content.=tootpress_create_menu($tootpress_current_page); From e6c65dffd0eab0154c89e4f8c1cb5543dfea2170 Mon Sep 17 00:00:00 2001 From: Marco Hitschler Date: Thu, 29 May 2025 11:08:39 +0200 Subject: [PATCH 02/20] Closing Filter Name --- readme.md | 23 +++++++++++++++++++---- readme.txt | 16 +++++++++++++++- tootpress_blog.php | 10 +++++----- tootpress_hooks.php | 24 ++++++++++++------------ tootpress_loop.php | 2 +- 5 files changed, 52 insertions(+), 23 deletions(-) diff --git a/readme.md b/readme.md index 8bac3d9..4130736 100644 --- a/readme.md +++ b/readme.md @@ -115,9 +115,9 @@ You can use the following code. ### Filter -#### tootpress_preamble_add +#### tootpress_preamble_filter -This filter outputs html content before the toot loop. +This filter outputs html content before the initial toot loop. You can use the following code. function tootpress_preamble_add( $preamble ) { @@ -130,6 +130,21 @@ You can use the following code. } add_filter( 'tootpress_preamble_filter', 'tootpress_preamble_add', 10, 1 ); +#### tootpress_closing_filter + +This filter outputs html content after the last toot loop. +You can use the following code. + + function tootpress_closing_add( $content ) { + + // Add your filter code here + // Example: $content='

Hello World.

'; + + return $content; + + } + add_filter( 'tootpress_closing_filter', 'tootpress_closing_add', 10, 1 ); + ## WordPress Framework Following components of WordPress are used in TootPress. @@ -209,8 +224,8 @@ This project is licensed under the GPL3 License. ### 0.5 "xxx" -* xxx 2025 -* Feature: Afterloop Filter +* xxx +* Feature: Closing Filter ### 0.4 "Cassie Lang" diff --git a/readme.txt b/readme.txt index 6b4cb76..7c26f2e 100644 --- a/readme.txt +++ b/readme.txt @@ -116,7 +116,7 @@ You can use the following code. `}` `add_action('tootpress_toots_update', 'tootpress_toots_update_postprocessing');` -**Filter: tootpress_preamble_add** +**Filter: tootpress_preamble_filter** It outputs html content before the toot loop. You can use the following code. @@ -130,6 +130,20 @@ You can use the following code. `}` `add_filter( 'tootpress_preamble_filter', 'tootpress_preamble_add', 10, 1 );` +**Filter: tootpress_closing_filter** +It outputs html content after the last toot loop. +You can use the following code. + +`function tootpress_closing_add( $content ) {` +`` +` // Add your filter code here` +` // Example: $content='

Hello World.

';` +`` +` return $content;` +`` +`}` +`add_filter( 'tootpress_closing_filter', 'tootpress_closing_add', 10, 1 );` + = Related Links = * [Source Code @ GitHub](https://github.com/circuscode/tootpress) diff --git a/tootpress_blog.php b/tootpress_blog.php index cb6f509..7b53b5f 100644 --- a/tootpress_blog.php +++ b/tootpress_blog.php @@ -182,25 +182,25 @@ function tootpress_paint_preamble($tootpress_current_page) { } /** - * Creates the Afterloop Content + * Creates the Closing Filter Content * * @since 0.5 * * @param int TootPress Current Page - * @return string html + * @return string Content */ - function tootpress_paint_afterloop($tootpress_current_page) { + function tootpress_paint_closing($tootpress_current_page) { $content=''; $lastpage=tootpress_amount_of_pages(); if($tootpress_current_page==$lastpage) { - $content.=tootpress_afterloop_filter_apply($content); + $content.=tootpress_closing_filter_apply($content); if($content) { - $content='
'.$content.'
'; + $content='
'.$content.'
'; } } diff --git a/tootpress_hooks.php b/tootpress_hooks.php index e012f7f..0268912 100644 --- a/tootpress_hooks.php +++ b/tootpress_hooks.php @@ -48,7 +48,7 @@ function tootpress_fire_toots_update() { /** * Preample * - * This filter outputs html content before the toot loop. + * This filter outputs html content before the initial toot loop. * * @since 0.4 * @@ -82,30 +82,30 @@ function tootpress_preamble_filter_apply($preamble) { */ /** - * Afterloop Filter + * Closing Filter * - * This filter outputs html content after the toot loop. + * This filter outputs content after the last toot loop. * * @since 0.5 * - * @param string Unfiltered Content - * @return html Filtered Content + * @param string Content + * @return string Filtered Content */ -function tootpress_afterloop_filter_apply($content) { - $content.=apply_filters( 'tootpress_afterloop_filter', $content ); +function tootpress_closing_filter_apply($content) { + $content.=apply_filters( 'tootpress_closing_filter', $content ); return $content; } /** - * Filter Example: tootpress_afterloop_filter + * Filter Example: tootpress_closing_filter * * @since 0.5 * - * @param string Unfiltered Content - * @return html Filtered Content + * @param string Content + * @return string Filtered Content * - * function tootpress_afterloop_add( $content ) { + * function tootpress_closing_add( $content ) { * * // Add your filter code here * // Example: $content='

Hello World.

'; @@ -113,7 +113,7 @@ function tootpress_afterloop_filter_apply($content) { * return $content; * * } - * add_filter( 'tootpress_afterloop_filter', 'tootpress_afterloop_add', 10, 1 ); + * add_filter( 'tootpress_closing_filter', 'tootpress_closing_add', 10, 1 ); * */ diff --git a/tootpress_loop.php b/tootpress_loop.php index 3643ff8..a82875f 100644 --- a/tootpress_loop.php +++ b/tootpress_loop.php @@ -39,7 +39,7 @@ function tootpress_content($content) { $tootpress_content.=tootpress_loop($tootpress_current_page); // TootPress Afterloop - $tootpress_content.=tootpress_paint_afterloop($tootpress_current_page); + $tootpress_content.=tootpress_paint_closing($tootpress_current_page); // TootPress Bottom Navigation $tootpress_content.=tootpress_create_menu($tootpress_current_page); From cd5374b75c7279272becb9a7b24e2b8c9d1a8648 Mon Sep 17 00:00:00 2001 From: Marco Hitschler Date: Fri, 30 May 2025 14:58:11 +0200 Subject: [PATCH 03/20] Forward Filter --- readme.md | 16 ++++++++++++++++ readme.txt | 14 ++++++++++++++ tootpress_hooks.php | 34 ++++++++++++++++++++++++++++++++++ tootpress_menu.php | 14 ++++++++++---- 4 files changed, 74 insertions(+), 4 deletions(-) diff --git a/readme.md b/readme.md index 4130736..9895eda 100644 --- a/readme.md +++ b/readme.md @@ -145,6 +145,21 @@ You can use the following code. } add_filter( 'tootpress_closing_filter', 'tootpress_closing_add', 10, 1 ); +#### tootpress_menu_forward_label + +This filter overwrites the forward label in the bottom navigation. +You can use the following code. + + function tootpress_menu_forward_label_change( $label ) { + + // Add your filter code here + // Example: $label='Newer Posts'; + + return $label; + + } + add_filter( 'tootpress_menu_forward_label', 'tootpress_menu_forward_label_change', 10, 1 ); + ## WordPress Framework Following components of WordPress are used in TootPress. @@ -226,6 +241,7 @@ This project is licensed under the GPL3 License. * xxx * Feature: Closing Filter +* Feature: Move Forward Label Filter ### 0.4 "Cassie Lang" diff --git a/readme.txt b/readme.txt index 7c26f2e..8c0f1ea 100644 --- a/readme.txt +++ b/readme.txt @@ -144,6 +144,20 @@ You can use the following code. `}` `add_filter( 'tootpress_closing_filter', 'tootpress_closing_add', 10, 1 );` +**Filter: tootpress_menu_forward_label** +This filter overwrites the forward label in the bottom navigation. +You can use the following code. + +`function tootpress_menu_forward_label_change( $label ) {` +`` +` // Add your filter code here` +` // Example: $label='Newer Posts';` +`` +` return $label;` +`` +`}` +`add_filter( 'tootpress_menu_forward_label', 'tootpress_menu_forward_label_change', 10, 1 );` + = Related Links = * [Source Code @ GitHub](https://github.com/circuscode/tootpress) diff --git a/tootpress_hooks.php b/tootpress_hooks.php index 0268912..f043fb1 100644 --- a/tootpress_hooks.php +++ b/tootpress_hooks.php @@ -117,4 +117,38 @@ function tootpress_closing_filter_apply($content) { * */ +/** + * Move Forward Filter + * + * This filter overwrites the forward label in the menu + * + * @since 0.5 + * + * @param string Label Forward + * @return string New Label + */ + +function tootpress_menu_forward_filter_apply($label) { + $label=apply_filters( 'tootpress_menu_forward_label', $label ); + return $label; +} + +/** + * Usage Example: tootpress_menu_forward_label + * + * @param string Label Forward + * @return string New Label + * + * function tootpress_menu_forward_label_change( $label ) { + * + * // Add your filter code here + * // Example: $label='Newer Posts'; + * + * return $label; + * + * } + * add_filter( 'tootpress_menu_forward_label', 'tootpress_menu_forward_label_change', 10, 1 ); + * + */ + ?> \ No newline at end of file diff --git a/tootpress_menu.php b/tootpress_menu.php index fd1f477..20994b4 100644 --- a/tootpress_menu.php +++ b/tootpress_menu.php @@ -276,21 +276,27 @@ function tootpress_label_older_toots() { } /** - * Creates Newer Toots Label + * Create Newer Toots Label * * @since 0.1 * * @return string Label */ - function tootpress_label_newer_toots() { +function tootpress_label_newer_toots() { + + $label=''; if(tootpress_is_language_german()) { - return 'Neuere Toots'; + $label='Neuere Toots'; } else { - return 'Newer Toots'; + $label='Newer Toots'; } + // Apply Filter + $label=tootpress_menu_forward_filter_apply($label); + + return $label; } ?> \ No newline at end of file From 64e69eabc0c533bba386cccfe7f7e033c29b13e4 Mon Sep 17 00:00:00 2001 From: Marco Hitschler Date: Fri, 30 May 2025 15:19:22 +0200 Subject: [PATCH 04/20] Backward Label Filter --- readme.md | 16 ++++++++++++++++ readme.txt | 14 ++++++++++++++ tootpress_hooks.php | 34 ++++++++++++++++++++++++++++++++++ tootpress_menu.php | 11 +++++++++-- 4 files changed, 73 insertions(+), 2 deletions(-) diff --git a/readme.md b/readme.md index 9895eda..c57471b 100644 --- a/readme.md +++ b/readme.md @@ -160,6 +160,21 @@ You can use the following code. } add_filter( 'tootpress_menu_forward_label', 'tootpress_menu_forward_label_change', 10, 1 ); +#### tootpress_menu_backward_label + +This filter overwrites the backward label in the bottom navigation. +You can use the following code. + + function tootpress_menu_backward_label_change( $label ) { + + // Add your filter code here + // Example: $label='Older Posts'; + + return $label; + + } + add_filter( 'tootpress_menu_backward_label', 'tootpress_menu_backward_label_change', 10, 1 ); + ## WordPress Framework Following components of WordPress are used in TootPress. @@ -242,6 +257,7 @@ This project is licensed under the GPL3 License. * xxx * Feature: Closing Filter * Feature: Move Forward Label Filter +* Feature: Move Backward Label Filter ### 0.4 "Cassie Lang" diff --git a/readme.txt b/readme.txt index 8c0f1ea..c90c0ef 100644 --- a/readme.txt +++ b/readme.txt @@ -158,6 +158,20 @@ You can use the following code. `}` `add_filter( 'tootpress_menu_forward_label', 'tootpress_menu_forward_label_change', 10, 1 );` +**Filter: tootpress_menu_backward_label** +This filter overwrites the backward label in the bottom navigation. +You can use the following code. + +`function tootpress_menu_backward_label_change( $label ) {` +`` +` // Add your filter code here` +` // Example: $label='Older Posts';` +`` +` return $label;` +`` +`}` +`add_filter( 'tootpress_menu_backward_label', 'tootpress_menu_backward_label_change', 10, 1 );` + = Related Links = * [Source Code @ GitHub](https://github.com/circuscode/tootpress) diff --git a/tootpress_hooks.php b/tootpress_hooks.php index f043fb1..7f4f956 100644 --- a/tootpress_hooks.php +++ b/tootpress_hooks.php @@ -150,5 +150,39 @@ function tootpress_menu_forward_filter_apply($label) { * add_filter( 'tootpress_menu_forward_label', 'tootpress_menu_forward_label_change', 10, 1 ); * */ + +/** + * Move Backward Filter + * + * This filter overwrites the backward label in the menu + * + * @since 0.5 + * + * @param string Label Backward + * @return string New Label + */ + +function tootpress_menu_backward_filter_apply($label) { + $label=apply_filters( 'tootpress_menu_backward_label', $label ); + return $label; +} + +/** + * Usage Example: tootpress_menu_backward_label + * + * @param string Label Backward + * @return string New Label + * + * function tootpress_menu_backward_label_change( $label ) { + * + * // Add your filter code here + * // Example: $label='Older Posts'; + * + * return $label; + * + * } + * add_filter( 'tootpress_menu_backward_label', 'tootpress_menu_backward_label_change', 10, 1 ); + * + */ ?> \ No newline at end of file diff --git a/tootpress_menu.php b/tootpress_menu.php index 20994b4..c965ddc 100644 --- a/tootpress_menu.php +++ b/tootpress_menu.php @@ -267,12 +267,19 @@ function tootpress_amount_of_pages() { function tootpress_label_older_toots() { + $label=''; + if(tootpress_is_language_german()) { - return 'Ältere Toots'; + $label='Ältere Toots'; } else { - return 'Older Toots'; + $label='Older Toots'; } + // Apply Filter + $label=tootpress_menu_backward_filter_apply($label); + + return $label; + } /** From ae8d3429ccff87d151e8af3b3baa40c4fc949f92 Mon Sep 17 00:00:00 2001 From: Marco Hitschler Date: Sat, 31 May 2025 17:45:29 +0200 Subject: [PATCH 05/20] Before Loop Filter --- readme.md | 16 ++++++++++++++++ readme.txt | 14 ++++++++++++++ tootpress_blog.php | 21 +++++++++++++++++++++ tootpress_hooks.php | 41 ++++++++++++++++++++++++++++++++++++++++- tootpress_loop.php | 5 ++++- 5 files changed, 95 insertions(+), 2 deletions(-) diff --git a/readme.md b/readme.md index c57471b..b486a7f 100644 --- a/readme.md +++ b/readme.md @@ -175,6 +175,21 @@ You can use the following code. } add_filter( 'tootpress_menu_backward_label', 'tootpress_menu_backward_label_change', 10, 1 ); +#### tootpress_beforeloop_filter + +This filter outputs content before the toot loop (on all tootpress pages). +You can use the following code. + + function tootpress_beforeloop_filter_add( $content, $page_number ) { + + // Add your filter code here + // Example: $content='

Page '.$page_number.'

'; + + return $label; + + } + add_filter( 'tootpress_beforeloop_filter', 'tootpress_beforeloop_filter_add', 10, 2 ); + ## WordPress Framework Following components of WordPress are used in TootPress. @@ -258,6 +273,7 @@ This project is licensed under the GPL3 License. * Feature: Closing Filter * Feature: Move Forward Label Filter * Feature: Move Backward Label Filter +* Feature: Before Loop Filter ### 0.4 "Cassie Lang" diff --git a/readme.txt b/readme.txt index c90c0ef..4606f39 100644 --- a/readme.txt +++ b/readme.txt @@ -172,6 +172,20 @@ You can use the following code. `}` `add_filter( 'tootpress_menu_backward_label', 'tootpress_menu_backward_label_change', 10, 1 );` +**Filter: tootpress_beforeloop_filter** +This filter outputs content before the toot loop (on all tootpress pages). +You can use the following code. + +`function tootpress_beforeloop_filter_add( $content, $page_number ) {` +`` +` // Add your filter code here` +` // Example: $content='

Page '.$page_number.'

';` +`` +` return $label;` +`` +`}` +`add_filter( 'tootpress_beforeloop_filter', 'tootpress_beforeloop_filter_add', 10, 2 );` + = Related Links = * [Source Code @ GitHub](https://github.com/circuscode/tootpress) diff --git a/tootpress_blog.php b/tootpress_blog.php index 7b53b5f..a9cfc44 100644 --- a/tootpress_blog.php +++ b/tootpress_blog.php @@ -209,4 +209,25 @@ function tootpress_paint_closing($tootpress_current_page) { } +/** + * Create the Before Loop Content. + * + * @since 0.5 + * + * @param int TootPress Current Page + * @return string Content + */ + +function tootpress_paint_beforeloop($tootpress_current_page) { + + $content=tootpress_beforeloop_filter_apply($tootpress_current_page); + + if($content) { + $content='
'.$content.'
'; + } + + return $content; + +} + ?> \ No newline at end of file diff --git a/tootpress_hooks.php b/tootpress_hooks.php index 7f4f956..da6f64e 100644 --- a/tootpress_hooks.php +++ b/tootpress_hooks.php @@ -184,5 +184,44 @@ function tootpress_menu_backward_filter_apply($label) { * add_filter( 'tootpress_menu_backward_label', 'tootpress_menu_backward_label_change', 10, 1 ); * */ - + +/** + * Before Loop Filter + * + * This filter outputs content before the toot loop. + * It will be applied on all tootpress pages. + * + * @since 0.5 + * + * @param int TootPress Page Number + * @return string Content + */ + +function tootpress_beforeloop_filter_apply($page_number) { + + $content=''; + + $content=apply_filters( 'tootpress_beforeloop_filter', $content, $page_number ); + + return $content; +} + +/** + * Usage Example: tootpress_beforeloop_filter + * + * @param string Content (empty) + * @param int TootPress Page Number + * @return string Content (filtered) + * + * function tootpress_beforeloop_filter_add( $content, $page_number ) { + * + * // Add your filter code here + * // Example: $content='

Page '.$page_number.'

'; + * + * return $content; + * + * } + * add_filter( 'tootpress_beforeloop_filter', 'tootpress_beforeloop_filter_add', 10, 2 ); + */ + ?> \ No newline at end of file diff --git a/tootpress_loop.php b/tootpress_loop.php index a82875f..57da83a 100644 --- a/tootpress_loop.php +++ b/tootpress_loop.php @@ -35,10 +35,13 @@ function tootpress_content($content) { // TootPress Preamble $tootpress_content.=tootpress_paint_preamble($tootpress_current_page); + // TootPress Before Loop + $tootpress_content.=tootpress_paint_beforeloop($tootpress_current_page); + // TootPress Loop $tootpress_content.=tootpress_loop($tootpress_current_page); - // TootPress Afterloop + // TootPress Closing $tootpress_content.=tootpress_paint_closing($tootpress_current_page); // TootPress Bottom Navigation From 4a1fc0feb213b8084a5a746d1e66057e2d56771f Mon Sep 17 00:00:00 2001 From: Marco Hitschler Date: Tue, 3 Jun 2025 22:40:06 +0200 Subject: [PATCH 06/20] Refactoring --- tootpress.php | 3 ++ tootpress_hooks.php | 127 ++++---------------------------------------- 2 files changed, 13 insertions(+), 117 deletions(-) diff --git a/tootpress.php b/tootpress.php index b06586e..292a3e2 100644 --- a/tootpress.php +++ b/tootpress.php @@ -42,6 +42,9 @@ require_once('tootpress_developer.php'); require_once('tootpress_script.php'); +// Dev +// require_once('tootpress_filter.php'); + // Ensure that all required functions are available during setup require_once( ABSPATH . 'wp-admin/includes/upgrade.php'); diff --git a/tootpress_hooks.php b/tootpress_hooks.php index da6f64e..fe3e098 100644 --- a/tootpress_hooks.php +++ b/tootpress_hooks.php @@ -17,7 +17,7 @@ /** * Fires when new toots are loaded * - * This hook can be used by other plugins to process after load functions. + * This action will be fired after toot update to execute custom post-processing. * For example: Cache Refresh * * @since 0.1 @@ -27,20 +27,6 @@ function tootpress_fire_toots_update() { do_action( 'tootpress_toots_update' ); } -/** - * Action Example: tootpress_toots_update - * - * @since 0.4 - * - * function tootpress_toots_update_postprocessing() { - * - * // Add your code to be executed here - * - * } - * add_action('tootpress_toots_update', 'tootpress_toots_update_postprocessing'); - * - */ - /** * Filter */ @@ -52,35 +38,15 @@ function tootpress_fire_toots_update() { * * @since 0.4 * - * @param string Unfiltered Preample + * @param string Empty Preample * @return html Filtered Preample */ function tootpress_preamble_filter_apply($preamble) { - $preamble.=apply_filters( 'tootpress_preamble_filter', $preamble ); + $preamble=apply_filters( 'tootpress_preamble_filter', $preamble ); return $preamble; } -/** - * Filter Example: tootpress_preamble_filter - * - * @since 0.4 - * - * @param string Unfiltered Preample - * @return html Filtered Preample - * - * function tootpress_preamble_add( $preamble ) { - * - * // Add your filter code here - * // Example: $preamble='

Hello World.

'; - * - * return $preamble; - * - * } - * add_filter( 'tootpress_preamble_filter', 'tootpress_preamble_add', 10, 1 ); - * - */ - /** * Closing Filter * @@ -88,35 +54,15 @@ function tootpress_preamble_filter_apply($preamble) { * * @since 0.5 * - * @param string Content + * @param string Empty Content * @return string Filtered Content */ function tootpress_closing_filter_apply($content) { - $content.=apply_filters( 'tootpress_closing_filter', $content ); + $content=apply_filters( 'tootpress_closing_filter', $content ); return $content; } -/** - * Filter Example: tootpress_closing_filter - * - * @since 0.5 - * - * @param string Content - * @return string Filtered Content - * - * function tootpress_closing_add( $content ) { - * - * // Add your filter code here - * // Example: $content='

Hello World.

'; - * - * return $content; - * - * } - * add_filter( 'tootpress_closing_filter', 'tootpress_closing_add', 10, 1 ); - * - */ - /** * Move Forward Filter * @@ -124,7 +70,7 @@ function tootpress_closing_filter_apply($content) { * * @since 0.5 * - * @param string Label Forward + * @param string Original Label * @return string New Label */ @@ -133,24 +79,6 @@ function tootpress_menu_forward_filter_apply($label) { return $label; } -/** - * Usage Example: tootpress_menu_forward_label - * - * @param string Label Forward - * @return string New Label - * - * function tootpress_menu_forward_label_change( $label ) { - * - * // Add your filter code here - * // Example: $label='Newer Posts'; - * - * return $label; - * - * } - * add_filter( 'tootpress_menu_forward_label', 'tootpress_menu_forward_label_change', 10, 1 ); - * - */ - /** * Move Backward Filter * @@ -158,7 +86,7 @@ function tootpress_menu_forward_filter_apply($label) { * * @since 0.5 * - * @param string Label Backward + * @param string Original Backward * @return string New Label */ @@ -167,24 +95,6 @@ function tootpress_menu_backward_filter_apply($label) { return $label; } -/** - * Usage Example: tootpress_menu_backward_label - * - * @param string Label Backward - * @return string New Label - * - * function tootpress_menu_backward_label_change( $label ) { - * - * // Add your filter code here - * // Example: $label='Older Posts'; - * - * return $label; - * - * } - * add_filter( 'tootpress_menu_backward_label', 'tootpress_menu_backward_label_change', 10, 1 ); - * - */ - /** * Before Loop Filter * @@ -197,31 +107,14 @@ function tootpress_menu_backward_filter_apply($label) { * @return string Content */ -function tootpress_beforeloop_filter_apply($page_number) { +function tootpress_beforeloop_filter_apply($current_page_number) { $content=''; + $last_page_number=tootpress_amount_of_pages(); - $content=apply_filters( 'tootpress_beforeloop_filter', $content, $page_number ); + $content=apply_filters( 'tootpress_beforeloop_filter', $content, $current_page_number, $last_page_number ); return $content; } -/** - * Usage Example: tootpress_beforeloop_filter - * - * @param string Content (empty) - * @param int TootPress Page Number - * @return string Content (filtered) - * - * function tootpress_beforeloop_filter_add( $content, $page_number ) { - * - * // Add your filter code here - * // Example: $content='

Page '.$page_number.'

'; - * - * return $content; - * - * } - * add_filter( 'tootpress_beforeloop_filter', 'tootpress_beforeloop_filter_add', 10, 2 ); - */ - ?> \ No newline at end of file From faefe3d5a43c1a0fac6a8338a009fa0b53324cc6 Mon Sep 17 00:00:00 2001 From: Marco Hitschler Date: Tue, 3 Jun 2025 23:04:39 +0200 Subject: [PATCH 07/20] After Loop Filter --- tootpress_blog.php | 21 +++++++++++++++++++++ tootpress_hooks.php | 24 +++++++++++++++++++++++- tootpress_loop.php | 3 +++ 3 files changed, 47 insertions(+), 1 deletion(-) diff --git a/tootpress_blog.php b/tootpress_blog.php index a9cfc44..4f9bac0 100644 --- a/tootpress_blog.php +++ b/tootpress_blog.php @@ -230,4 +230,25 @@ function tootpress_paint_beforeloop($tootpress_current_page) { } +/** + * Create the After Loop Content. + * + * @since 0.5 + * + * @param int TootPress Current Page + * @return string Content + */ + +function tootpress_paint_afterloop($tootpress_current_page) { + + $content=tootpress_afterloop_filter_apply($tootpress_current_page); + + if($content) { + $content='
'.$content.'
'; + } + + return $content; + +} + ?> \ No newline at end of file diff --git a/tootpress_hooks.php b/tootpress_hooks.php index fe3e098..0045af8 100644 --- a/tootpress_hooks.php +++ b/tootpress_hooks.php @@ -103,7 +103,7 @@ function tootpress_menu_backward_filter_apply($label) { * * @since 0.5 * - * @param int TootPress Page Number + * @param int TootPress Current Page Number * @return string Content */ @@ -117,4 +117,26 @@ function tootpress_beforeloop_filter_apply($current_page_number) { return $content; } +/** + * After Loop Filter + * + * This filter outputs content after the toot loop. + * It will be applied on all tootpress pages. + * + * @since 0.5 + * + * @param int TootPress Current Page Number + * @return string Content + */ + +function tootpress_afterloop_filter_apply($current_page_number) { + + $content=''; + $last_page_number=tootpress_amount_of_pages(); + + $content=apply_filters( 'tootpress_afterloop_filter', $content, $current_page_number, $last_page_number ); + + return $content; +} + ?> \ No newline at end of file diff --git a/tootpress_loop.php b/tootpress_loop.php index 57da83a..f99f0dc 100644 --- a/tootpress_loop.php +++ b/tootpress_loop.php @@ -41,6 +41,9 @@ function tootpress_content($content) { // TootPress Loop $tootpress_content.=tootpress_loop($tootpress_current_page); + // TootPress After Loop + $tootpress_content.=tootpress_paint_afterloop($tootpress_current_page); + // TootPress Closing $tootpress_content.=tootpress_paint_closing($tootpress_current_page); From 3f47ec00f03bb863763a5f1a8082080d9f6ffadd Mon Sep 17 00:00:00 2001 From: Marco Hitschler Date: Wed, 4 Jun 2025 21:59:02 +0200 Subject: [PATCH 08/20] Elephant Filter --- readme.md | 2 ++ tootpress_blog.php | 4 +++- tootpress_hooks.php | 16 ++++++++++++++++ 3 files changed, 21 insertions(+), 1 deletion(-) diff --git a/readme.md b/readme.md index b486a7f..c5b672e 100644 --- a/readme.md +++ b/readme.md @@ -274,6 +274,8 @@ This project is licensed under the GPL3 License. * Feature: Move Forward Label Filter * Feature: Move Backward Label Filter * Feature: Before Loop Filter +* Feature: After Loop Filter +* Feature: Mastodon Logo Filter ### 0.4 "Cassie Lang" diff --git a/tootpress_blog.php b/tootpress_blog.php index 4f9bac0..0ae73e4 100644 --- a/tootpress_blog.php +++ b/tootpress_blog.php @@ -144,7 +144,9 @@ function tootpress_paint_elephant( $instance, $account, $mastodon_id, $backlink) } // The Elephant - $elephant_html.='Toot Symbol'; + $elephant_img='Toot Symbol'; + $elephant_img=tootpress_mastodon_logo_filter_apply($elephant_img); + $elephant_html.=$elephant_img; if($backlink) { $elephant_html.=''; diff --git a/tootpress_hooks.php b/tootpress_hooks.php index 0045af8..36bc282 100644 --- a/tootpress_hooks.php +++ b/tootpress_hooks.php @@ -139,4 +139,20 @@ function tootpress_afterloop_filter_apply($current_page_number) { return $content; } +/** + * Mastodon Logo Filter + * + * This filter overwrites the Mastodon Logo with Custom Logo + * + * @since 0.5 + * + * @param string img HTML Tag (Mastodon Logo) + * @return string img HTML Tag (Custom Logo) + */ + +function tootpress_mastodon_logo_filter_apply($img) { + $img=apply_filters( 'tootpress_mastodon_logo_filter', $img ); + return $img; +} + ?> \ No newline at end of file From d7712b2fd8daf7b05f3f046416cb4ed0a7e4d2fd Mon Sep 17 00:00:00 2001 From: Marco Hitschler Date: Thu, 5 Jun 2025 23:23:40 +0200 Subject: [PATCH 09/20] Between Filter --- readme.md | 2 +- tootpress_blog.php | 35 ++++++++++++++++++++++++++++++++--- tootpress_hooks.php | 30 +++++++++++++++++++++++------- tootpress_loop.php | 7 +++++++ 4 files changed, 63 insertions(+), 11 deletions(-) diff --git a/readme.md b/readme.md index c5b672e..4f71007 100644 --- a/readme.md +++ b/readme.md @@ -269,13 +269,13 @@ This project is licensed under the GPL3 License. ### 0.5 "xxx" -* xxx * Feature: Closing Filter * Feature: Move Forward Label Filter * Feature: Move Backward Label Filter * Feature: Before Loop Filter * Feature: After Loop Filter * Feature: Mastodon Logo Filter +* Feature: Between Filter ### 0.4 "Cassie Lang" diff --git a/tootpress_blog.php b/tootpress_blog.php index 0ae73e4..341dda7 100644 --- a/tootpress_blog.php +++ b/tootpress_blog.php @@ -171,7 +171,7 @@ function tootpress_paint_preamble($tootpress_current_page) { if($tootpress_current_page==1) { - $preamble.=tootpress_preamble_filter_apply($preamble); + $preamble=tootpress_preamble_filter_apply($preamble); if($preamble) { $preamble='
'.$preamble.'
'; @@ -216,13 +216,15 @@ function tootpress_paint_closing($tootpress_current_page) { * * @since 0.5 * + * @param string empty * @param int TootPress Current Page * @return string Content */ function tootpress_paint_beforeloop($tootpress_current_page) { - $content=tootpress_beforeloop_filter_apply($tootpress_current_page); + $content=''; + $content=tootpress_beforeloop_filter_apply($content, $tootpress_current_page); if($content) { $content='
'.$content.'
'; @@ -237,13 +239,15 @@ function tootpress_paint_beforeloop($tootpress_current_page) { * * @since 0.5 * + * @param string empty * @param int TootPress Current Page * @return string Content */ function tootpress_paint_afterloop($tootpress_current_page) { - $content=tootpress_afterloop_filter_apply($tootpress_current_page); + $content=''; + $content=tootpress_afterloop_filter_apply($content, $tootpress_current_page); if($content) { $content='
'.$content.'
'; @@ -253,4 +257,29 @@ function tootpress_paint_afterloop($tootpress_current_page) { } +/** + * Create the Between Element. + * + * @since 0.5 + * + * @param int Open Loops + * @return string Between Element + */ + +function tootpress_paint_between($open_loops) { + + $content=''; + + if ($open_loops>1) { + $content=tootpress_between_filter_apply($content); + } + + if($content) { + $content='
'.$content.'
'; + } + + return $content; + +} + ?> \ No newline at end of file diff --git a/tootpress_hooks.php b/tootpress_hooks.php index 36bc282..cc08beb 100644 --- a/tootpress_hooks.php +++ b/tootpress_hooks.php @@ -38,8 +38,8 @@ function tootpress_fire_toots_update() { * * @since 0.4 * - * @param string Empty Preample - * @return html Filtered Preample + * @param string Empty + * @return string Filtered Preample */ function tootpress_preamble_filter_apply($preamble) { @@ -54,7 +54,7 @@ function tootpress_preamble_filter_apply($preamble) { * * @since 0.5 * - * @param string Empty Content + * @param string Empty * @return string Filtered Content */ @@ -103,13 +103,13 @@ function tootpress_menu_backward_filter_apply($label) { * * @since 0.5 * + * @param string empty * @param int TootPress Current Page Number * @return string Content */ -function tootpress_beforeloop_filter_apply($current_page_number) { +function tootpress_beforeloop_filter_apply($content, $current_page_number) { - $content=''; $last_page_number=tootpress_amount_of_pages(); $content=apply_filters( 'tootpress_beforeloop_filter', $content, $current_page_number, $last_page_number ); @@ -125,13 +125,13 @@ function tootpress_beforeloop_filter_apply($current_page_number) { * * @since 0.5 * + * @param string empty * @param int TootPress Current Page Number * @return string Content */ -function tootpress_afterloop_filter_apply($current_page_number) { +function tootpress_afterloop_filter_apply($content, $current_page_number) { - $content=''; $last_page_number=tootpress_amount_of_pages(); $content=apply_filters( 'tootpress_afterloop_filter', $content, $current_page_number, $last_page_number ); @@ -155,4 +155,20 @@ function tootpress_mastodon_logo_filter_apply($img) { return $img; } +/** + * Between Filter + * + * This filter adds custom HTML between the toots + * + * @since 0.5 + * + * @param string Empty + * @return string Between Content + */ + +function tootpress_between_filter_apply($content) { + $content=apply_filters( 'tootpress_between_filter', $content ); + return $content; +} + ?> \ No newline at end of file diff --git a/tootpress_loop.php b/tootpress_loop.php index f99f0dc..ca005d7 100644 --- a/tootpress_loop.php +++ b/tootpress_loop.php @@ -80,6 +80,7 @@ function tootpress_loop($range) { $toot_cache=array(); $toot_cache=tootpress_get_toots_from_database($amount_toots_page, $range); $amount_toots_cache=count($toot_cache); + $open_loops=$amount_toots_cache; // Get Configuration $mastodon_instance=tootpress_get_mastodon_instance(); @@ -94,6 +95,12 @@ function tootpress_loop($range) { // Paint $tootloop.=tootpress_paint_toot( $toot['toot_mastodon_id'], $toot['toot_date'], $toot['toot_content'], $toot['toot_media'], $mastodon_instance, $mastodon_account, $tootpress_backlink); + // Between Filter + $tootloop.=tootpress_paint_between($open_loops); + + // -1 + $open_loops=($open_loops-1); + } } From 33b924dfd0510fa97dc6327ce3692117785262a8 Mon Sep 17 00:00:00 2001 From: Marco Hitschler Date: Sat, 7 Jun 2025 16:37:47 +0200 Subject: [PATCH 10/20] Content Filter --- readme.md | 3 ++- tootpress_blog.php | 1 + tootpress_hooks.php | 16 ++++++++++++++++ tootpress_plugin.php | 1 + 4 files changed, 20 insertions(+), 1 deletion(-) diff --git a/readme.md b/readme.md index 4f71007..ffee1d9 100644 --- a/readme.md +++ b/readme.md @@ -267,7 +267,7 @@ This project is licensed under the GPL3 License. ## Changelog -### 0.5 "xxx" +### 0.5 "Echo" * Feature: Closing Filter * Feature: Move Forward Label Filter @@ -276,6 +276,7 @@ This project is licensed under the GPL3 License. * Feature: After Loop Filter * Feature: Mastodon Logo Filter * Feature: Between Filter +* Feature: Toot Content Filter ### 0.4 "Cassie Lang" diff --git a/tootpress_blog.php b/tootpress_blog.php index 341dda7..bbeda00 100644 --- a/tootpress_blog.php +++ b/tootpress_blog.php @@ -50,6 +50,7 @@ function tootpress_paint_toot( $mastodon_id, $date, $content, $media , $instance // Toot Content $content=tootpress_remove_target_blank($content); + $content=tootpress_toot_content_filter_apply($content); $toot_html.='
'.wp_kses($content, tootpress_escaping_allowed_html() ).'
'; // Toot Image diff --git a/tootpress_hooks.php b/tootpress_hooks.php index cc08beb..51dd0a6 100644 --- a/tootpress_hooks.php +++ b/tootpress_hooks.php @@ -171,4 +171,20 @@ function tootpress_between_filter_apply($content) { return $content; } +/** + * Toot Content Filter + * + * This filter can be used to manipulate the toot content + * + * @since 0.5 + * + * @param string Content + * @return string Filtered Content + */ + +function tootpress_toot_content_filter_apply($content) { + $content=apply_filters( 'tootpress_toot_content_filter', $content ); + return $content; +} + ?> \ No newline at end of file diff --git a/tootpress_plugin.php b/tootpress_plugin.php index 98ada49..c132717 100644 --- a/tootpress_plugin.php +++ b/tootpress_plugin.php @@ -97,6 +97,7 @@ function tootpress_escaping_allowed_html() { 'class' => array(), 'href' => array(), 'rel' => array(), + 'target' => array(), ), ); } From 61efa5ad50b69d044d15e6e39fbac5c2a6a4888c Mon Sep 17 00:00:00 2001 From: Marco Hitschler Date: Sat, 7 Jun 2025 21:02:09 +0200 Subject: [PATCH 11/20] Date Filter --- readme.md | 1 + tootpress_blog.php | 43 +++++++++++++++++++++++++++++++++++-------- tootpress_hooks.php | 27 +++++++++++++++++++++++++++ 3 files changed, 63 insertions(+), 8 deletions(-) diff --git a/readme.md b/readme.md index ffee1d9..ed6086e 100644 --- a/readme.md +++ b/readme.md @@ -277,6 +277,7 @@ This project is licensed under the GPL3 License. * Feature: Mastodon Logo Filter * Feature: Between Filter * Feature: Toot Content Filter +* Feature: Date Filter ### 0.4 "Cassie Lang" diff --git a/tootpress_blog.php b/tootpress_blog.php index bbeda00..6f0d380 100644 --- a/tootpress_blog.php +++ b/tootpress_blog.php @@ -40,18 +40,13 @@ function tootpress_paint_toot( $mastodon_id, $date, $content, $media , $instance $toot_html.=tootpress_paint_elephant( $instance, $account, $mastodon_id,$backlink); // Toot Date - if(tootpress_is_language_german()) { - $date=tootpress_convert_mysqldate_to_german_format($date); - } else { - $date=tootpress_convert_mysqldate_to_international_format($date); - } - - $toot_html.='

'.esc_html($date).'

'; + $toot_html.=tootpress_paint_date($date); // Toot Content $content=tootpress_remove_target_blank($content); + $content=wp_kses($content, tootpress_escaping_allowed_html() ); $content=tootpress_toot_content_filter_apply($content); - $toot_html.='
'.wp_kses($content, tootpress_escaping_allowed_html() ).'
'; + $toot_html.='
'.$content.'
'; // Toot Image if($media){ @@ -157,6 +152,38 @@ function tootpress_paint_elephant( $instance, $account, $mastodon_id, $backlink) } +/** + * Paint the Date + * + * @since 0.5 + * + * @param string Date (Format: ) + * @return string html + */ + + function tootpress_paint_date($date) { + + // 2023-05-30 22:40:28 + + $mysqldate=$date; + + $date=tootpress_date_filter_apply($date); + + if($mysqldate==$date) { + + if(tootpress_is_language_german()) { + $date=tootpress_convert_mysqldate_to_german_format($date); + } else { + $date=tootpress_convert_mysqldate_to_international_format($date); + } + + } + + $date_html.='

'.esc_html($date).'

'; + return $date_html; + +} + /** * Creates the Preamble * diff --git a/tootpress_hooks.php b/tootpress_hooks.php index 51dd0a6..07c9f2d 100644 --- a/tootpress_hooks.php +++ b/tootpress_hooks.php @@ -187,4 +187,31 @@ function tootpress_toot_content_filter_apply($content) { return $content; } +/** + * Date Filter + * + * This filter overwrites the date output with custom format + * + * @since 0.5 + * + * @param string Date + * @return string Custom Format + */ + +function tootpress_date_filter_apply($date) { + + // 2023-05-30 22:40:28 + + $year=substr($date,0,4); + $month=substr($date,5,2); + $day=substr($date,8,2); + $hour=substr($date,11,2); + $minute=substr($date,14,2); + $second=substr($date,17,2); + + $date=apply_filters( 'tootpress_date_filter', $date, $year, $month, $day, $hour, $minute, $second ); + + return $date; +} + ?> \ No newline at end of file From d41c45efd3d919601f1305597ef9ceeeb15149c7 Mon Sep 17 00:00:00 2001 From: Marco Hitschler Date: Sat, 7 Jun 2025 23:42:59 +0200 Subject: [PATCH 12/20] Image Filter --- readme.md | 1 + tootpress_blog.php | 54 +++++++++++++++++++++++++++++++------------- tootpress_hooks.php | 20 ++++++++++++++++ tootpress_plugin.php | 2 +- 4 files changed, 60 insertions(+), 17 deletions(-) diff --git a/readme.md b/readme.md index ed6086e..917796d 100644 --- a/readme.md +++ b/readme.md @@ -278,6 +278,7 @@ This project is licensed under the GPL3 License. * Feature: Between Filter * Feature: Toot Content Filter * Feature: Date Filter +* Feature: Image Filter ### 0.4 "Cassie Lang" diff --git a/tootpress_blog.php b/tootpress_blog.php index 6f0d380..95dc159 100644 --- a/tootpress_blog.php +++ b/tootpress_blog.php @@ -95,20 +95,7 @@ function tootpress_paint_image($tootid){ } $image_html.='">'; - $image_html.=''; + $date_html='

'.esc_html($date).'

'; return $date_html; } diff --git a/tootpress_hooks.php b/tootpress_hooks.php index 07c9f2d..4a84d32 100644 --- a/tootpress_hooks.php +++ b/tootpress_hooks.php @@ -214,4 +214,24 @@ function tootpress_date_filter_apply($date) { return $date; } +/** + * Image Filter + * + * This filter can be used to manipulate image tags + * + * @since 0.5 + * + * @param string Image Tag + * @param int Amount of Images + * @param int Image Number + * @return string Filtered Image Tag + */ + +function tootpress_image_filter_apply($img_tag,$amount_of_images,$image_number) { + + $img_tag=apply_filters( 'tootpress_image_filter', $img_tag, $amount_of_images, $image_number); + + return $img_tag; +} + ?> \ No newline at end of file diff --git a/tootpress_plugin.php b/tootpress_plugin.php index c132717..16686ce 100644 --- a/tootpress_plugin.php +++ b/tootpress_plugin.php @@ -87,6 +87,7 @@ function tootpress_escaping_allowed_html() { 'img' => array( 'src' => array(), 'alt' => array(), + 'class' => array(), ), 'br' => array(), 'strong' => array(), @@ -97,7 +98,6 @@ function tootpress_escaping_allowed_html() { 'class' => array(), 'href' => array(), 'rel' => array(), - 'target' => array(), ), ); } From fbd00eafa7dc548f5815a6b088c018732b21cfa6 Mon Sep 17 00:00:00 2001 From: Marco Hitschler Date: Sun, 8 Jun 2025 00:55:12 +0200 Subject: [PATCH 13/20] Escaping / Update Process --- readme.md | 1 + tootpress.php | 2 +- tootpress_blog.php | 4 ++-- tootpress_healthy.php | 2 +- tootpress_update.php | 10 ++++++++++ 5 files changed, 15 insertions(+), 4 deletions(-) diff --git a/readme.md b/readme.md index 917796d..f416ac1 100644 --- a/readme.md +++ b/readme.md @@ -279,6 +279,7 @@ This project is licensed under the GPL3 License. * Feature: Toot Content Filter * Feature: Date Filter * Feature: Image Filter +* Security: Better Output Escaping ### 0.4 "Cassie Lang" diff --git a/tootpress.php b/tootpress.php index 292a3e2..98f2bcf 100644 --- a/tootpress.php +++ b/tootpress.php @@ -3,7 +3,7 @@ /* Plugin Name: TootPress Description: TootPress copies your Toots from Mastodon to WordPress. -Version: 0.4 +Version: 0.5 Author: Marco Hitschler Author URI: https://www.unmus.de/ License: GPL3 diff --git a/tootpress_blog.php b/tootpress_blog.php index 95dc159..0c4d4ae 100644 --- a/tootpress_blog.php +++ b/tootpress_blog.php @@ -31,13 +31,13 @@ function tootpress_paint_toot( $mastodon_id, $date, $content, $media , $instance $toot_html=''; // Toot ID as HTML Comment - $toot_html.=''; + $toot_html.=''; // Toot Start $toot_html.='
'; // Toot Elephant - $toot_html.=tootpress_paint_elephant( $instance, $account, $mastodon_id,$backlink); + $toot_html.=tootpress_paint_elephant( $instance, $account, $mastodon_id, $backlink); // Toot Date $toot_html.=tootpress_paint_date($date); diff --git a/tootpress_healthy.php b/tootpress_healthy.php index d2a7bf7..1eec527 100644 --- a/tootpress_healthy.php +++ b/tootpress_healthy.php @@ -127,7 +127,7 @@ function tootpress_healthy_check() { // Required to build the backlinks $mastodon_account_name=tootpress_get_mastodon_account_name(); if ($mastodon_account_name) { - $output.='Mastodon Account Name has been retrieved: @'.$mastodon_account_name; + $output.='Mastodon Account Name has been retrieved: @'.esc_html($mastodon_account_name); } else { $output.=' Warning:  Mastodon Account Name could not be retrieved.'; } diff --git a/tootpress_update.php b/tootpress_update.php index 3680650..1a14086 100644 --- a/tootpress_update.php +++ b/tootpress_update.php @@ -42,6 +42,16 @@ function tootpress_update() { } add_option('tootpress_rewrite_update','0'); } + + /* Update Process Version 0.4 */ + if($tootpress_previous_version==4) { + update_option('tootpress_plugin_version', "5"); + } + + /* Update Process Version 0.5 */ + if($tootpress_previous_version==5) { + update_option('tootpress_plugin_version', "6"); + } } add_action( 'plugins_loaded', 'tootpress_update' ); From e21ba1df1f8eb658df3b0db438c13673c3679e4b Mon Sep 17 00:00:00 2001 From: Marco Hitschler Date: Sun, 8 Jun 2025 13:42:43 +0200 Subject: [PATCH 14/20] Better Escaping --- tootpress_blog.php | 15 +++++++-------- tootpress_plugin.php | 1 - 2 files changed, 7 insertions(+), 9 deletions(-) diff --git a/tootpress_blog.php b/tootpress_blog.php index 0c4d4ae..8d99abe 100644 --- a/tootpress_blog.php +++ b/tootpress_blog.php @@ -44,13 +44,12 @@ function tootpress_paint_toot( $mastodon_id, $date, $content, $media , $instance // Toot Content $content=tootpress_remove_target_blank($content); - $content=wp_kses($content, tootpress_escaping_allowed_html() ); - $content=tootpress_toot_content_filter_apply($content); - $toot_html.='
'.$content.'
'; + $content=tootpress_toot_content_filter_apply($content); + $toot_html.='
'.wp_kses_post($content).'
'; // Toot Image if($media){ - $toot_html.=wp_kses(tootpress_paint_image($mastodon_id), tootpress_escaping_allowed_html() ); + $toot_html.=tootpress_paint_image($mastodon_id); } // Toot End @@ -87,15 +86,15 @@ function tootpress_paint_image($tootid){ if($amount_of_images>1) { // Galleries $image_html.='toot-image-gallery '; - $image_html.='toot-image-gallery-'.$amount_of_images.' '; - $image_html.='toot-image-'.($i+1); + $image_html.='toot-image-gallery-'.(int) $amount_of_images.' '; + $image_html.='toot-image-'.(int) ($i+1); } else { // Single Images $image_html.='toot-image-single '; } $image_html.='">'; - $image_html.=tootpress_create_image_tag($toot_image[$i]['attachment_file'],$toot_image[$i]['attachment_description'],$amount_of_images,($i+1)); + $image_html.=tootpress_paint_image_tag($toot_image[$i]['attachment_file'],$toot_image[$i]['attachment_description'],$amount_of_images,($i+1)); $image_html.='
'; } @@ -115,7 +114,7 @@ function tootpress_paint_image($tootid){ * @return string Image Tag */ -function tootpress_create_image_tag($filename, $description, $amount_of_images, $image_number) { +function tootpress_paint_image_tag($filename, $description, $amount_of_images, $image_number) { $image_tag=' array( 'src' => array(), 'alt' => array(), - 'class' => array(), ), 'br' => array(), 'strong' => array(), From 9e9b0fccfb90d1cc5c5c60a873f29adc9db23062 Mon Sep 17 00:00:00 2001 From: Marco Hitschler Date: Mon, 9 Jun 2025 01:09:41 +0200 Subject: [PATCH 15/20] Escaping --- tootpress_blog.php | 14 ++++++----- tootpress_hooks.php | 60 ++++++++++++++++++++++++++++++--------------- tootpress_menu.php | 24 +++++++++--------- tootpress_url.php | 3 +++ 4 files changed, 63 insertions(+), 38 deletions(-) diff --git a/tootpress_blog.php b/tootpress_blog.php index 8d99abe..4ec37b7 100644 --- a/tootpress_blog.php +++ b/tootpress_blog.php @@ -94,7 +94,7 @@ function tootpress_paint_image($tootid){ } $image_html.='">'; - $image_html.=tootpress_paint_image_tag($toot_image[$i]['attachment_file'],$toot_image[$i]['attachment_description'],$amount_of_images,($i+1)); + $image_html.=tootpress_paint_image_tag($toot_image[$i]['attachment_file'],$toot_image[$i]['attachment_description'],$toot_image[$i]['attachment_width'],$toot_image[$i]['attachment_height'],$amount_of_images,($i+1)); $image_html.=''; } @@ -109,20 +109,22 @@ function tootpress_paint_image($tootid){ * * @param string Image File Name * @param string Image Description + * @param int Image Width + * @param int Image Height * @param int Amount of Images * @param int Image Number * @return string Image Tag */ -function tootpress_paint_image_tag($filename, $description, $amount_of_images, $image_number) { +function tootpress_paint_image_tag($filename, $description, $width, $height, $amount_of_images, $image_number) { $image_tag='1) { $menu_html.=' Date: Mon, 9 Jun 2025 18:44:44 +0200 Subject: [PATCH 16/20] DOM --- readme.md | 2 ++ tootpress_blog.php | 44 ++++++++++++++++++++++++++++++-------------- tootpress_toots.css | 4 ++-- 3 files changed, 34 insertions(+), 16 deletions(-) diff --git a/readme.md b/readme.md index f416ac1..4ff64ca 100644 --- a/readme.md +++ b/readme.md @@ -279,6 +279,8 @@ This project is licensed under the GPL3 License. * Feature: Toot Content Filter * Feature: Date Filter * Feature: Image Filter +* Changed: DOM Structure +* Renamed: CSS Classes * Security: Better Output Escaping ### 0.4 "Cassie Lang" diff --git a/tootpress_blog.php b/tootpress_blog.php index 4ec37b7..ac91787 100644 --- a/tootpress_blog.php +++ b/tootpress_blog.php @@ -77,28 +77,37 @@ function tootpress_paint_image($tootid){ // Amount of Images $amount_of_images=sizeof($toot_image); - for($i=0;$i<$amount_of_images;$i++) { + // DOM Structure + $image_html.='
'; + $image_html.='
'; + return $image_html; } @@ -118,6 +127,10 @@ function tootpress_paint_image($tootid){ function tootpress_paint_image_tag($filename, $description, $width, $height, $amount_of_images, $image_number) { + // ALT + if($description==FALSE) {$description='Sorry! No image description created.';} + + // Image Tag $image_tag='Toot Symbol'; + $elephant_img='Toot Symbol'; $elephant_img=tootpress_mastodon_logo_filter_apply($elephant_img); $elephant_html.=$elephant_img; @@ -171,6 +185,8 @@ function tootpress_paint_elephant( $instance, $account, $mastodon_id, $backlink) $elephant_html.='
'; } + $elephant_html.=''; + return $elephant_html; } diff --git a/tootpress_toots.css b/tootpress_toots.css index 1aae05e..1dcf2b0 100644 --- a/tootpress_toots.css +++ b/tootpress_toots.css @@ -7,7 +7,7 @@ TootPress CSS @ Blog clear:both; } -.tootpress-toot-symbol { +.toot-symbol { float:left !important; margin-top:5px; } @@ -32,7 +32,7 @@ TootPress CSS @ Blog max-width: 100%; } -.toot-image-gallery { +.toot-gallery-image { margin-bottom:5px; } From fbce3636770cb752afa6b6b0bedba0d072f19a47 Mon Sep 17 00:00:00 2001 From: Marco Hitschler Date: Tue, 10 Jun 2025 19:43:57 +0200 Subject: [PATCH 17/20] Code Review --- tootpress_blog.php | 35 +++++++++++++++++------------------ tootpress_install.php | 2 +- tootpress_plugin.php | 2 +- 3 files changed, 19 insertions(+), 20 deletions(-) diff --git a/tootpress_blog.php b/tootpress_blog.php index ac91787..b6bc619 100644 --- a/tootpress_blog.php +++ b/tootpress_blog.php @@ -73,11 +73,9 @@ function tootpress_paint_image($tootid){ $toot_image=array(); $toot_image=tootpress_get_media_from_database($tootid); $image_html=''; - - // Amount of Images $amount_of_images=sizeof($toot_image); - // DOM Structure + // DOM $image_html.='
'; $image_html.='
'; + // Image Loop for($i=0;$i<$amount_of_images;$i++) { - // Classes + // Gallery if($amount_of_images>1) { - // Galleries $image_html.='';} } @@ -122,18 +120,19 @@ function tootpress_paint_image($tootid){ * @param int Image Height * @param int Amount of Images * @param int Image Number - * @return string Image Tag + * @return html Image Tag */ function tootpress_paint_image_tag($filename, $description, $width, $height, $amount_of_images, $image_number) { - // ALT + // Preparation if($description==FALSE) {$description='Sorry! No image description created.';} + $image_dir=tootpress_get_url_image_directory(); // Image Tag $image_tag=' Date: Tue, 10 Jun 2025 21:34:06 +0200 Subject: [PATCH 18/20] Code Review --- tootpress.php | 3 --- tootpress_toots.css | 5 +---- 2 files changed, 1 insertion(+), 7 deletions(-) diff --git a/tootpress.php b/tootpress.php index 98f2bcf..0566793 100644 --- a/tootpress.php +++ b/tootpress.php @@ -42,9 +42,6 @@ require_once('tootpress_developer.php'); require_once('tootpress_script.php'); -// Dev -// require_once('tootpress_filter.php'); - // Ensure that all required functions are available during setup require_once( ABSPATH . 'wp-admin/includes/upgrade.php'); diff --git a/tootpress_toots.css b/tootpress_toots.css index 1dcf2b0..6ac8eb1 100644 --- a/tootpress_toots.css +++ b/tootpress_toots.css @@ -16,11 +16,8 @@ TootPress CSS @ Blog margin-left:60px; } -.toot-date { - font-size:85%; -} - .toot-date p { + font-size:80%; margin-bottom:0px; } From 498cd19132403377acc4dcb95c20733bfaf184d7 Mon Sep 17 00:00:00 2001 From: Marco Hitschler Date: Sat, 19 Jul 2025 15:35:20 +0200 Subject: [PATCH 19/20] Update readme --- readme.md | 138 +++++++++++++++++++++++++++++++++++++++++++++++--- readme.txt | 144 ++++++++++++++++++++++++++++++++++++++++++++++++++++- 2 files changed, 274 insertions(+), 8 deletions(-) diff --git a/readme.md b/readme.md index 4ff64ca..f3c1c09 100644 --- a/readme.md +++ b/readme.md @@ -16,7 +16,7 @@ TootPress copies your toots from Mastodon to WordPress continuously. The toots c ## Installation -1. Download the plugin from the GitHub Repository (see latest Release) +1. Download the plugin from the GitHub Repository (latest Release) 2. Rename the downloaded folder to "tootpress" 2. Upload the folder to the WordPress Plugin Directory 3. Activate the plugin in WordPress @@ -66,8 +66,8 @@ Following toot objects are not supported. * Audio * Video * Poll -* Emojis * Teaser +* Quotes ## Excluded Toot Types @@ -180,15 +180,125 @@ You can use the following code. This filter outputs content before the toot loop (on all tootpress pages). You can use the following code. - function tootpress_beforeloop_filter_add( $content, $page_number ) { + function tootpress_beforeloop_add( $content, $current_page_number, $last_page_number ) { + + // Add your filter code here + // Example: $content='

Page '.$current_page_number.' of '.$last_page_number.'

'; + + return $content; + + } + add_filter( 'tootpress_beforeloop_filter', 'tootpress_beforeloop_add', 10, 3 ); + +#### tootpress_afterloop_filter + +This filter outputs content after the toot loop (on all tootpress pages). +You can use the following code. + + function tootpress_afterloop_add( $content, $current_page_number, $last_page_number ) { + + // Add your filter code here + // Example: $content='

Page '.$current_page_number.' of '.$last_page_number.'

'; + + return $content; + + } + add_filter( 'tootpress_afterloop_filter', 'tootpress_afterloop_add', 10, 3 ); + +#### tootpress_mastodon_logo_filter + +This filter overwrites the Mastodon Logo with Custom Logo. +You can use the following code. + + function tootpress_mastodon_logo_change ( $img ) { + + // Standard Value + // Toot Symbol + + // Add your filter code here + // Example: $img='Custom Toot Symbol'; + + return $img; + + } + add_filter( 'tootpress_mastodon_logo_filter', 'tootpress_mastodon_logo_change', 10, 1 ); + +#### tootpress_between_filter + +This filter adds custom HTML between the toots. +You can use the following code. + + function tootpress_create_element_between ( $content ) { + + // Add your filter code here + // $content='
'; + + return $content; + + } + add_filter( 'tootpress_between_filter', 'tootpress_create_element_between', 10, 1 ); + +#### tootpress_toot_content_filter + +This filter can be used to manipulate the toot content. +You can use the following code. + + function tootpress_manipulate_content ( $content ) { + + // Add your filter code here + // $content=str_replace('href=','target="_blank" href=',$content); + return $content; + + } + add_filter( 'tootpress_toot_content_filter', 'tootpress_manipulate_content', 10, 1 ); + +#### tootpress_date_filter + +This filter overwrites the date output with custom format. +You can use the following code. + + function tootpress_date_custom_format ( $date, $year, $month, $day, $hour, $minute, $second ) { + + // $date = 2023-05-30 22:40:28 + // $year = 2023 + // $month = 05 + // $day = 30 + // $hour = 22 + // $minute = 40 + // $second = 28 + // Add your filter code here - // Example: $content='

Page '.$page_number.'

'; + // $date=$day.'.'.$month.'.'.$year.' '.$hour.':'.$minute.':'.$second; + + return $date; - return $label; + } + add_filter( 'tootpress_date_filter', 'tootpress_date_custom_format', 10, 7 ); + +#### tootpress_image_filter + +This filter can be used to manipulate image tags. +You can use the following code. + + function tootpress_image_manipulate ($img_tag,$filename,$description,$width,$height,$image_directory_path,$amount_of_images,$image_number) { + + // Amount of Images + // ---------------- + // 1 = Single Image + // >1 = Gallery + Size of Gallery + + // Image Number + // ------------ + // This number indicates position within the gallery + + // Add your filter code here + // $img_tag=str_replace('alt=','class="tootpress-image" alt=',$img_tag); + + return $img_tag; } - add_filter( 'tootpress_beforeloop_filter', 'tootpress_beforeloop_filter_add', 10, 2 ); + add_filter( 'tootpress_image_filter', 'tootpress_image_manipulate', 1, 8 ); ## WordPress Framework @@ -229,6 +339,22 @@ Backlinks to Mastodon can be activated in the plugin settings. In this case, the No. TootPress does not support the WordPress Multisite Feature. The plugin is working on the master-site, but is not working on all other child sites within the wordpress network. +### Are the toots included in the WordPress Search? + +Unfortunately not. + +### Is there any possiblity to modify the outputs on the user interface? + +Almost every content element, which is created by TootPress in the FrontEnd, can be modified. For example, you can replace the Mastodon Logo with another image. Enabeling this, the plugin is providing a bunch of filters. Please read the documentation of the filter above. + +### Does TootPress recognize, if a published Toot was edited on Mastodon? + +The plugin does not sync the Toots between Mastodon and WordPress. TootPress is copying the toots just once after they are published on Mastodon. So if a published toot is edited on Mastodon later, TootPress does not recognized this change anymore, if the toot was already copied to WordPress. Reflecting the edit in WordPress there is only the possibility to make the same edit again directly in the WordPress database. The toots are stored in the table tootpress_toots. + +### Can toots be loaded from several Mastodon instances? + +No. The plugin does currently not support several Mastodon instances. The architecture is designed to load toots from one single instance. Independent from this, if your toot history is spread over several instances and the timelines does not overlap, you can try to load the timelines one after another. This is not officially supported or tested, but based on user feedback this seems to work surprisingly. + ## Maturity Grade * Low maturity level diff --git a/readme.txt b/readme.txt index 4606f39..6412742 100644 --- a/readme.txt +++ b/readme.txt @@ -3,7 +3,7 @@ Contributors: unmus Tags: mastodon, toots, microblogging, blog, fediverse Requires at least: 6.1 Tested up to: 6.8 -Stable tag: 0.4 +Stable tag: 0.5 License: GNU General Public License v3 or later License URI: https://www.gnu.org/licenses/gpl-3.0.html @@ -72,8 +72,8 @@ Following toot objects are not supported. * Audio * Video * Poll -* Emojis * Teaser +* Quotes = Excluded Toot Types = @@ -186,6 +186,110 @@ You can use the following code. `}` `add_filter( 'tootpress_beforeloop_filter', 'tootpress_beforeloop_filter_add', 10, 2 );` +**Filter: tootpress_afterloop_filter** +This filter outputs content after the toot loop (on all tootpress pages). +You can use the following code. + +`function tootpress_afterloop_add( $content, $current_page_number, $last_page_number ) {` +`` +` // Add your filter code here` +` // Example: $content='

Page '.$current_page_number.' of '.$last_page_number.'

';` +`` +` return $content;` +`` +`}` +`add_filter( 'tootpress_afterloop_filter', 'tootpress_afterloop_add', 10, 3 );` + +**Filter: tootpress_mastodon_logo_filter** +This filter overwrites the Mastodon Logo with Custom Logo. +You can use the following code. + +`function tootpress_mastodon_logo_change ( $img ) {` +`` +` // Standard Value` +` // Toot Symbol` +`` +` // Add your filter code here` +` // Example: $img='Custom Toot Symbol';` +`` +` return $img;` +`` +`}` +`add_filter( 'tootpress_mastodon_logo_filter', 'tootpress_mastodon_logo_change', 10, 1 );` + +**Filter: tootpress_between_filter** +This filter adds custom HTML between the toots. +You can use the following code. + +`function tootpress_create_element_between ( $content ) {` +`` +` // Add your filter code here` +` // $content='
';` +`` +` return $content;` +`` +`} +`add_filter( 'tootpress_between_filter', 'tootpress_create_element_between', 10, 1 );` + +**Filter: tootpress_toot_content_filter** +This filter can be used to manipulate the toot content. +You can use the following code. + +`function tootpress_manipulate_content ( $content ) {` +`` +` // Add your filter code here` +` // $content=str_replace('href=','target="_blank" href=',$content); ` +`` +` return $content;` +`` +`} +`add_filter( 'tootpress_toot_content_filter', 'tootpress_manipulate_content', 10, 1 );` + +**Filter: tootpress_date_filter** +This filter overwrites the date output with custom format. +You can use the following code. + +`function tootpress_date_custom_format ( $date, $year, $month, $day, $hour, $minute, $second ) {` +`` +` // $date = 2023-05-30 22:40:28` +` // $year = 2023` +` // $month = 05` +` // $day = 30` +` // $hour = 22` +` // $minute = 40` +` // $second = 28` +`` +` // Add your filter code here` +` // $date=$day.'.'.$month.'.'.$year.' '.$hour.':'.$minute.':'.$second;` +`` +` return $date;` +`` +`} +`add_filter( 'tootpress_date_filter', 'tootpress_date_custom_format', 10, 7 );` + +**Filter: tootpress_image_filter** +This filter can be used to manipulate image tags. +You can use the following code. + +`function tootpress_image_manipulate ($img_tag,$filename,$description,$width,$height,$image_directory_path,$amount_of_images,$image_number) {` +`` +` // Amount of Images` +` // ----------------` +` // 1 = Single Image` +` // >1 = Gallery + Size of Gallery` +`` +` // Image Number` +` // ------------` +` // This number indicates position within the gallery` +`` +` // Add your filter code here` +` // $img_tag=str_replace('alt=','class="tootpress-image" alt=',$img_tag);` +`` +` return $img_tag;` +`` +`} +`add_filter( 'tootpress_image_filter', 'tootpress_image_manipulate', 1, 8 );` + = Related Links = * [Source Code @ GitHub](https://github.com/circuscode/tootpress) @@ -219,8 +323,41 @@ Backlinks to Mastodon can be activated in the plugin settings. In this case, the No. TootPress does not support the WordPress Multisite Feature. The plugin is working on the master-site, but is not working on all other child sites within the wordpress network. += Are the toots included in the WordPress Search? = + +Unfortunately not. + += Is there any possiblity to modify the outputs on the user interface? = + +Almost every content element, which is created by TootPress in the FrontEnd, can be modified. For example, you can replace the Mastodon Logo with another image. Enabeling this, the plugin is providing a bunch of filters. Please read the documentation of the filter above. + += Does TootPress recognize, if a published Toot was edited on Mastodon? = + +The plugin does not sync the Toots between Mastodon and WordPress. TootPress is copying the toots just once after they are published on Mastodon. So if a published toot is edited on Mastodon later, TootPress does not recognized this change anymore, if the toot was already copied to WordPress. Reflecting the edit in WordPress there is only the possibility to make the same edit again directly in the WordPress database. The toots are stored in the table tootpress_toots. + += Can toots be loaded from several Mastodon instances? = + +No. The plugin does currently not support several Mastodon instances. The architecture is designed to load toots from one single instance. Independent from this, if your toot history is spread over several instances and the timelines does not overlap, you can try to load the timelines one after another. This is not officially supported or tested, but based on user feedback this seems to work surprisingly. + == Changelog == += 0.5 "Echo" = + +* July 2025 +* Feature: Closing Filter +* Feature: Move Forward Label Filter +* Feature: Move Backward Label Filter +* Feature: Before Loop Filter +* Feature: After Loop Filter +* Feature: Mastodon Logo Filter +* Feature: Between Filter +* Feature: Toot Content Filter +* Feature: Date Filter +* Feature: Image Filter +* Changed: DOM Structure +* Renamed: CSS Classes +* Security: Better Output Escaping + = 0.4 "Cassie Lang" = * June 2024 @@ -256,6 +393,9 @@ No. TootPress does not support the WordPress Multisite Feature. The plugin is wo == Upgrade Notice == += 0.5 = +This version brings a bunch of filters enabling customization. + = 0.4 = This version includes a preamble filter. From b318aa96f1d1dede4b783ad7e100904fb291dbad Mon Sep 17 00:00:00 2001 From: Marco Hitschler Date: Sat, 19 Jul 2025 15:40:24 +0200 Subject: [PATCH 20/20] Update readme.md --- readme.md | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/readme.md b/readme.md index f3c1c09..e1cfb95 100644 --- a/readme.md +++ b/readme.md @@ -147,7 +147,7 @@ You can use the following code. #### tootpress_menu_forward_label -This filter overwrites the forward label in the bottom navigation. +This filter overwrites the forward label in the bottom navigation. You can use the following code. function tootpress_menu_forward_label_change( $label ) { @@ -162,7 +162,7 @@ You can use the following code. #### tootpress_menu_backward_label -This filter overwrites the backward label in the bottom navigation. +This filter overwrites the backward label in the bottom navigation. You can use the following code. function tootpress_menu_backward_label_change( $label ) { @@ -395,6 +395,7 @@ This project is licensed under the GPL3 License. ### 0.5 "Echo" +* July 2025 * Feature: Closing Filter * Feature: Move Forward Label Filter * Feature: Move Backward Label Filter