Page 1 of 2

Flatpress 1.2.1 issue #132 - Months are displayed in the wrong language in the search

Posted: Sun Sep 18, 2022 10:28 am
by laborix
Hi,

a quick solution for the Flatpress 1.2.1 problem described in the Flatpress Github here:
-> https://github.com/flatpressblog/flatpress/issues/132

Download the file "/fp-includes/smarty/plugins/function.html_select_date.php", edit it with a UTF-8 Editor and replace the lines 227 - 230

Code: Select all

for ($i = 1; $i <= 31; $i++) {
  $days[] = sprintf($day_format, $i);
  $day_values[] = sprintf($day_value_format, $i);
}
with this "quick" solution:

Code: Select all

/*
 * Flatpress issue #132
 * Months are displayed in the wrong language in the search
 *
 * Debug: 2022-09-18 
 * Using now the month_names from the Flatpress language files
 */
global $lang;
    
$replace_month_names = array();
$replace_month_names[0] = '-';
$fp_lang_months = array();
$fp_lang_months = $lang['date']['month'];
$fplm = 0;
for ($lm = 1; $lm <= 12; $lm++) {      
  $replace_month_names[$lm] = $fp_lang_months[$fplm];
  $fplm++;
}
for ($i = 1; $i <= 12; $i++) {
  $month_names[$i] = $replace_month_names[$i];
  $month_values[$i] = date($month_value_format, mktime(0, 0, 0, $i, 1, 2000));
}
save this changes and upload the file "/fp-includes/smarty/plugins/function.html_select_date.php" into your Flatpress 1.2.1 Online version. No more changes are needed, the Month in the search list box are now shown with the current Flatpress 1.2.1 language.

Tested with Flatpress 1.2.1 on a Web server with PHP 8.0.23.

Re: Flatpress 1.2.1 issue #132 - Months are displayed in the wrong language in the search

Posted: Sat Sep 24, 2022 6:17 am
by laborix
Sorry, I posted the wrong lines to replace :roll:

Please replace lines 190 - 193 in the file "/fp-includes/smarty/plugins/function.html_select_date.php"

Code: Select all

        for ($i = 1; $i <= 12; $i++) {
            $month_names[$i] = strftime($month_format, mktime(0, 0, 0, $i, 1, 2000));
            $month_values[$i] = strftime($month_value_format, mktime(0, 0, 0, $i, 1, 2000));
        }
with the same code from my last posting:

Code: Select all

/*
 * Flatpress issue #132
 * Months are displayed in the wrong language in the search
 *
 * Debug: 2022-09-18 
 * Using now the month_names from the Flatpress language files
 */
global $lang;
    
$replace_month_names = array();
$replace_month_names[0] = '-';
$fp_lang_months = array();
$fp_lang_months = $lang['date']['month'];
$fplm = 0;
for ($lm = 1; $lm <= 12; $lm++) {      
  $replace_month_names[$lm] = $fp_lang_months[$fplm];
  $fplm++;
}
for ($i = 1; $i <= 12; $i++) {
  $month_names[$i] = $replace_month_names[$i];
  $month_values[$i] = date($month_value_format, mktime(0, 0, 0, $i, 1, 2000));
}

Re: Flatpress 1.2.1 issue #132 - Months are displayed in the wrong language in the search

Posted: Sun Sep 25, 2022 12:14 am
by fraenkiman
Hello @laborix,

thank you for your support.
I haven't been able to test the solution yet - will do so in the next few days.
I've added your solution to the issue. Maybe Arvid has the possibility to install the PHP8.1 compatible right away.

Best Regards

Re: Flatpress 1.2.1 issue #132 - Months are displayed in the wrong language in the search

Posted: Sun Sep 25, 2022 6:56 am
by laborix
fraenkiman wrote: Sun Sep 25, 2022 12:14 am... the PHP8.1 compatible ...
The solution work fine on PHP 7.x and PHP 8.x, no matter, you only need a FlatPress Version higher than 1.0 :)

Re: Flatpress 1.2.1 issue #132 - Months are displayed in the wrong language in the search

Posted: Mon Sep 26, 2022 9:42 pm
by fraenkiman
Hello @laborix,

I tested your solution. The translation in the set language works wonderfully.
However, the search then no longer works as expected.
In my case, there is a post from September 13th.
I'm looking for the following setting:
Keyword: ist
full-text search
Date: September 13, 2022
"Start search" button

I then get all the posts that appear to contain the word "ist".

But I should only get one post as a result from the viewfinder.

Would you like to take a look there again?
My flatpress version: FlatPress fp-1.3.dev [master]
PHP Version 7.4.30

Best Regards

Re: Flatpress 1.2.1 issue #132 - Months are displayed in the wrong language in the search

Posted: Tue Sep 27, 2022 3:51 pm
by laborix
fraenkiman wrote: Mon Sep 26, 2022 9:42 pm...
Keyword: ist
full-text search
Date: September 13, 2022
"Start search" button

I then get all the posts that appear to contain the word "ist".

But I should only get one post as a result from the viewfinder.
...
Ok, very interesting what FlatPress generates from/with PHP commands in combination with the Smarty Engine 2.6.

Here is the complete correction again to avoid errors:

Replace the lines 190 - 193 in the file "/fp-includes/smarty/plugins/function.html_select_date.php"

Code: Select all

for ($i = 1; $i <= 12; $i++) {
  $month_names[$i] = strftime($month_format, mktime(0, 0, 0, $i, 1, 2000));
  $month_values[$i] = strftime($month_value_format, mktime(0, 0, 0, $i, 1, 2000));
}
with this code:

Code: Select all

/*
 * Flatpress issue #132
 * Months are displayed in the wrong language in the search
 *
 * Debug: 2022-09-27 
 * Using now the month_names from the Flatpress language files
 */
global $lang;
    
$replace_month_names = array();
$replace_month_names[0] = '-';
$replace_month_value_format = array("00","01","02","03","04","05","06","07","08","09","10","11","12");
$fp_lang_months = array();
$fp_lang_months = $lang['date']['month'];
$fplm = 0;
for ($lm = 1; $lm <= 12; $lm++) {      
  $replace_month_names[$lm] = $fp_lang_months[$fplm];
  $fplm++;
}
for ($i = 1; $i <= 12; $i++) {
  $month_names[$i] = $replace_month_names[$i];
  $month_values[$i] = $replace_month_value_format[$i];
}
The correct search results should now appear (tested with FlatPress 1.2.1 under PHP 8.0) and run under PHP 7.x, as well as PHP 8.0 and PHP 8.1.

Re: Flatpress 1.2.1 issue #132 - Months are displayed in the wrong language in the search

Posted: Tue Sep 27, 2022 9:58 pm
by fraenkiman
Hello @laborix,

this looks very good. The search now works again as expected and also the translation of the months into the respective language.

I added your solution as a comment to the issue.

Thank you very much for your solution

Best regards and have a restful night
Frank

Re: Flatpress 1.2.1 issue #132 - Months are displayed in the wrong language in the search

Posted: Sat Oct 01, 2022 11:01 am
by Arvid
Thank you both very much, I changed the code according to your suggestions with 225e3b1. Works nicely :)

All the best,
Arvid

Re: Flatpress 1.2.1 issue #132 - Months are displayed in the wrong language in the search

Posted: Sat Oct 08, 2022 1:45 pm
by Arvid
Unfortunately, updating Smarty changed the code of function.html_select_date.php significantly - we'll have to adapt the fix to the new Smarty code. Please see my posting here.
I opened a new issue.

All the best,
Arvid

Re: Flatpress 1.2.1 issue #132 - Months are displayed in the wrong language in the search

Posted: Sat Oct 08, 2022 8:50 pm
by fraenkiman
Hello @laborix,

can you please look at lines 290 to 325 in the function.html_select_date.php file?
I've tried to put your previous code there, to no avail.

Best regards
Frank