Jump to content
raiwa

admin Define Languages produces double blank lines

Recommended Posts

Posted (edited)

When using the language file editor in Admin : Tools : Define Languages duplicated CR's are introduced in the file.

This looks when edited in Notepad++ like this:

image.png.9d0109d323825e58b2b6a83df68f44f1.png

Tested with Phoenix 1.0.5.0 UNIX server and edited under Windows with Firefox..

This is probably an old problem which existed through all previous versions. As I do not use the built in editor I didn't realize the problem berfore.

Has this been discussed before. Is there any possibility to address this.

The original core file looks like this:

image.png.9f0e762e3a145a6df6d670e99ff8c82c.png

 

 

Edited by raiwa

Share this post


Link to post
Share on other sites

I wasn't able to duplicate this in 1.0.5.10 on a Linux server editing with Firefox on Windows.  It would convert from Unix to DOS line endings but it didn't go the next step to duplicating the carriage returns even when I edited the file repeatedly.  So I think there's more to this than you've diagnosed so far. 

Have you tried different versions of PHP/Apache? 


Always back up before making changes.

Share this post


Link to post
Share on other sites

Thanks Matt,

I checked with 2 more servers and different PHP and Phoneix versions and get everywhere the same result. Sure you checked the file in Notepad++ or similar after editing in admin/define language.php?

Server 1 (where the problem was discovered)

Apache 2.4.43
PHP     7.3.17 (Zend 3.3.17)

Tested with UNIX, Windows and Mac endlines in original file. All same result => duplicated CR’s

Also tested with Phoenix 1.0.5.9/10 admin/define_language.php => same result

Server 2:

Server OS    Linux 3.10.0-862.3.2.el7.x86_64
Apache (unknown)
PHP    7.1.33 (Zend 3.1.0)
Phoenix 1.0.5.1     

=> Same problem

Same Server with Pre Frozen EDGE version => same problem

Server 3

HTTP Server:    Apache/2.4.43
PHP Version:    7.2.30 (Zend: 3.2.0)
Phoenix v1.0.2.5

=> Same Problem
    

 

Share this post


Link to post
Share on other sites
24 minutes ago, raiwa said:

Sure you checked the file in Notepad++ or similar after editing in admin/define language.php?

I checked it with vim -b and xxd which showed me one CR per LF.  But as described, I shouldn't have had to do so to get the result that you did.  Because it should have showed me extra blank lines.  So even without any further checking, it should have been visible.  I checked on Apache/2.4.29 (Ubuntu) PHP 7.2.30, which seems similar enough to yours that it should have shown. 

Have you tried it in a different browser or in safe mode (without extensions) Firefox?  Or from a different computer? 

How do you get the file to Notepad++?  Does it load the file for you?  I wonder if you have it set in such a way that it tries to convert the file from Unix to Windows line endings, even if the file is already in Windows format.  You might try it on the Unix command line with something like xxd, which shows me

Quote

00000000: 3c3f 7068 700d 0a2f 2a0d 0a20 2024 4964  <?php../*..  $Id

The 0d of course is the carriage return and the 0a the line feed. 

If you want me to verify that I can view the doubled carriage returns, email me a copy of one of the corrupted files. 

Or you could try changing

            $file_contents = stripslashes($_POST['file_contents']);

to

            $file_contents = str_replace("\r\n", "\n", stripslashes($_POST['file_contents']));

I tried that on mine and it left things as Unix line endings.  Perhaps yours would leave it as Windows line endings. 


Always back up before making changes.

Share this post


Link to post
Share on other sites

When I try editing the corrupted version of the file, I get either CRLFCRLF or LFLF depending on whether I do the replace before saving.  A better replacement might be

$file_contents = preg_replace("{\r+\n}", "\n", stripslashes($_POST['file_contents']));

But I can't really test it, as I believe that the CRCRLF is getting converted to CRLFCRLF prior to that point. 

I'll let @burt make the decision about whether it is better to push to core or not.  And which version and when. 


Always back up before making changes.

Share this post


Link to post
Share on other sites

What's going on? 

  1. You are amending the file via the admin/define_language.php
  2. You are then downloading the file via FTP
  3. You are then amending the file in notepad++

At point 3, you see CR and LF etc everywhere ?

 


Help shape the future of Phoenix; join the Phoenix Club

Share this post


Link to post
Share on other sites
2 minutes ago, burt said:

What's going on? 

  1. You are amending the file via the admin/define_language.php
  2. You are then downloading the file via FTP
  3. You are then amending the file in notepad++

At point 3, you see CR and LF etc everywhere ?

 

Yes, I'm seeing then the first screenshot of my first message.

Share this post


Link to post
Share on other sites
9 minutes ago, ecartz said:

When I try editing the corrupted version of the file, I get either CRLFCRLF or LFLF depending on whether I do the replace before saving.  A better replacement might be


$file_contents = preg_replace("{\r+\n}", "\n", stripslashes($_POST['file_contents']));

 

Tested and works for my case.

Share this post


Link to post
Share on other sites

What I'd like to do is this;

  1. I will log into the Phoenix Demo and amend a file via the define_language
  2. I will FTP it down
  3. I will attach it here

At that point, you can open in your editor a let know what you see...


Help shape the future of Phoenix; join the Phoenix Club

Share this post


Link to post
Share on other sites

So is that file problematic ?  Forget the missing backslash, I forgot to backslash it.


Help shape the future of Phoenix; join the Phoenix Club

Share this post


Link to post
Share on other sites
Posted (edited)

This file is ok regarding the line ends.

I understand that you can't recreate the problem. But, I could see it in several occasions under different scenarios and from at least 3 different users like explained above.

It would be interesting to know if other users can reproduce it.

Edited by raiwa

Share this post


Link to post
Share on other sites

Hi all,  @raiwa  @ecartz  @burt

tried search long time about text editor, wasted lots of time, finally found out define languages...😓
in my list, it doens't come with sorting order, is there a way to asc desc, and how to change the code?

in CE 1.0.5.0 version, I have this addon JcM Background Video Hook V1.0  and it has admin/includes/languages/english/hooks/shop/siteWide/BackgroundVideo.php how to list this hooks language file? 

many thanks!  Lyn

Share this post


Link to post
Share on other sites
1 hour ago, ce7 said:

Hi all,  @raiwa  @ecartz  @burt

tried search long time about text editor, wasted lots of time, finally found out define languages...😓
in my list, it doens't come with sorting order, is there a way to asc desc, and how to change the code?

in CE 1.0.5.0 version, I have this addon JcM Background Video Hook V1.0  and it has admin/includes/languages/english/hooks/shop/siteWide/BackgroundVideo.php how to list this hooks language file? 

many thanks!  Lyn

You will need to contact a good developer and get it re-coded to suit your needs. 
If what is made is better than core, maybe you would then allow us to replace what is in core with your new version.


Help shape the future of Phoenix; join the Phoenix Club

Share this post


Link to post
Share on other sites

hi burt, @burt

thank you for the reply. i dont have budget to contact developer, i self-learning from forum or google these years 😞
I google "php sort filename" and found some tips, my way to sort define_language is as below for others who maybe also want to know

find:
            $result = array_merge($result, tep_opendir($path . $filename));
add below:
            // sort the filename  lowest to highest
            // ref: https://www.php.net/manual/en/function.sort.php
           // or can use asort($result);
            sort ($result); 

this gave me the result i want, the only thing, i can not figure out is there are few files not sorted at the bottom, and i dont understand why? check the file type, file size, file permission, file modified date and time, what else did i miss?
image.thumb.png.6eeb5bb0aab47bb0b10fe5bdca49b2b9.png


and the hook language files did come out on the list.    Lyn

Share this post


Link to post
Share on other sites

I would do it right before the return rather than where you're doing it, for efficiency's sake and to make sure you sort every file. 

I think that you are implicitly sorting by path most of the time but not always.  Try

usort($result, function ($a, $b) {
  return strcmp($a['name'], $b['name']);
});
return $result;

That explicitly sorts by path. 

Or even better might be to move it outside the function entirely. 

    foreach (tep_opendir(DIR_FS_CATALOG_LANGUAGES . $_GET['lngdir']) as $file) {

to

    $files = tep_opendir(DIR_FS_CATALOG_LANGUAGES . $_GET['lngdir']);
    usort($result, function ($a, $b) {
      return strcmp($a['name'], $b['name']);
    });
    foreach ($files as $file) {

 


Always back up before making changes.

Share this post


Link to post
Share on other sites

Hi Matt, @ecartz

thank you very much for your reply and the code modification, good learning for me....  👍  👏

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×