Page 1 of 2 12 LastLast
Results 1 to 10 of 13
  1. #1
    Join Date
    Jul 2007
    Posts
    14
    Plugin Contributions
    0

    Default Updating Language constants dynamically

    Hi,

    I was wondering if it was possible to set up a way of allowing the store user to dynamically update the contents of the language files dynamically?

    For example ... I want to set up text boxes for some of the variables which are usually configured in the language files. I then want the store user/owner to be able to change the contents of these text boxes, press update and then the changes are updated in the .php files and therefore throughout the site. Is this possible and if so, can anyone give guidelines of how to go about to do this.

    eg. I want the store manager to be able to update variables such as

    define('DOWN_FOR_MAINTENANCE_TEXT_INFORMATION', 'The site is currently down for maintenance. Please excuse the dust, and try back later.');

    so that he can then place a reason, notes or whatever. This is not the only define I want to use (just an example) as I may also create some others for various reasons.

    Hope someone can help.

  2. #2
    Join Date
    Jan 2004
    Posts
    66,364
    Blog Entries
    7
    Plugin Contributions
    274

    Default Re: Updating Language constants dynamically

    There is no built-in facility for doing that at the present time.

    You'd need to write custom code for that.
    Keep in mind that empowering them to edit a .php file via the admin, and then just blindly writing that file back to the server isn't really any more effective than having them edit the file on their PC and upload via FTP, esp considering the fact that they can introduce PHP syntax errors just by adding a single-quote in their message, etc. It's about the same number of steps too.
    .

    Zen Cart - putting the dream of business ownership within reach of anyone!
    Donate to: DrByte directly or to the Zen Cart team as a whole

    Remember: Any code suggestions you see here are merely suggestions. You assume full responsibility for your use of any such suggestions, including any impact ANY alterations you make to your site may have on your PCI compliance.
    Furthermore, any advice you see here about PCI matters is merely an opinion, and should not be relied upon as "official". Official PCI information should be obtained from the PCI Security Council directly or from one of their authorized Assessors.

  3. #3
    Join Date
    Jul 2007
    Posts
    14
    Plugin Contributions
    0

    Default Re: Updating Language constants dynamically

    Hi, thanks for the reply.

    I thought that I would prob have to write custom code, but it is this I need guidance with.


    I intend to put in place a validation using javascript to make sure that any possible wrong characters cant be used and also I ill be advising the users of this.

    I dont want to give them access to the actual files via ftp and I also think that they would edit the wrong files or upload them in the wrong places etc.

    I know how to open and write to a file but what I am unsure of is how to search through the file for each define statement and return these, and change the appropriate ones where necessary.

    As i said before,
    If you can help at all by even telling me which functions php has which may make this possible I should be able to work out the rest hopefully.

  4. #4
    Join Date
    Jan 2004
    Posts
    66,364
    Blog Entries
    7
    Plugin Contributions
    274

    Default Re: Updating Language constants dynamically

    file() will read in the contents of a file, line by line
    file_get_contents() will read in the entire file
    fopen(), fput(), fclose() will open, write, and close files, respectively
    Parsing will likely need to be done via regular expressions ... ereg(), etc

    The secondary problem you'll have with this is security. In order to be able to write back to the files, they need to be world-writable, which leaves them open as prime targets for hackers.
    .

    Zen Cart - putting the dream of business ownership within reach of anyone!
    Donate to: DrByte directly or to the Zen Cart team as a whole

    Remember: Any code suggestions you see here are merely suggestions. You assume full responsibility for your use of any such suggestions, including any impact ANY alterations you make to your site may have on your PCI compliance.
    Furthermore, any advice you see here about PCI matters is merely an opinion, and should not be relied upon as "official". Official PCI information should be obtained from the PCI Security Council directly or from one of their authorized Assessors.

  5. #5
    Join Date
    Jul 2007
    Posts
    14
    Plugin Contributions
    0

    Default Re: Updating Language constants dynamically

    Thanks for you help.

    Good point on security.

    I was looking through the php for the admin pages for the shop configuration, and they seem to be set up to modify the database directly.

    Do you know if the values are usually taken from the database first and then placed into the files or are they never 'syncronised' and if not which values are taken as being the 'main' ones the database or the language files?

    I think an alternative may then be to set up the new defines to be canged to be changed in the database directly, and should I require to add custom defines then I can just add rows to the database tables where necessary / create a new custom table.

    what are your thoughts on this?

  6. #6
    Join Date
    Oct 2006
    Posts
    5,477
    Plugin Contributions
    11

    Default Re: Updating Language constants dynamically

    As far as I remember, constants set in configuration table are available anywhere, so you should check on that (Dr Byte would know the exact answer for this). You can have all the constants stored in db, then load and define them before anything else.
    I no longer provide installation support on forum for all my modules. However, if there are real bugs with the modules please feel free to contact me

  7. #7
    Join Date
    Jan 2004
    Posts
    66,364
    Blog Entries
    7
    Plugin Contributions
    274

    Default Re: Updating Language constants dynamically

    Since you're going to need to rewrite file contents, start with the define-pages-editor as a base. The configuration tool is not a good model for reading the entire file.
    Enhance its file-reading facility by adding line-parsing to identify each define statement.
    Build input fields on the screen for each one
    Collect all the info.
    Validate the info, and write the defines back to the file.

    If you want to rewrite the language infrastructure to use the database instead, keep in mind the need to support multiple languages and also to handle code upgrades. You'll still need to create a user interface to present and collect the information, then validate it and save it.
    .

    Zen Cart - putting the dream of business ownership within reach of anyone!
    Donate to: DrByte directly or to the Zen Cart team as a whole

    Remember: Any code suggestions you see here are merely suggestions. You assume full responsibility for your use of any such suggestions, including any impact ANY alterations you make to your site may have on your PCI compliance.
    Furthermore, any advice you see here about PCI matters is merely an opinion, and should not be relied upon as "official". Official PCI information should be obtained from the PCI Security Council directly or from one of their authorized Assessors.

  8. #8
    Join Date
    Jul 2007
    Posts
    14
    Plugin Contributions
    0

    Default Re: Updating Language constants dynamically

    DrByte, I just want to clarify to make sure I understand correctly.

    I should take a copy of the define-pages-editor page and alter this as a starting point and
    Then ammend it so that when it reads through the files it parses any instances of the define calls using parse function.
    For each instance of define() I should create an input field (to allow the editing)

    When submit, collect any changes and validate them (ie so no php errors etc caused) and then re-write the file the define statement came from?

    Is this what you are saying or have I missed the point somewhere?

    Thanks for you responses and help!

  9. #9
    Join Date
    Jan 2004
    Posts
    66,364
    Blog Entries
    7
    Plugin Contributions
    274

    Default Re: Updating Language constants dynamically

    Assuming you intend to proceed with editing language files and plan to deal with security concerns separately, then yes.
    .

    Zen Cart - putting the dream of business ownership within reach of anyone!
    Donate to: DrByte directly or to the Zen Cart team as a whole

    Remember: Any code suggestions you see here are merely suggestions. You assume full responsibility for your use of any such suggestions, including any impact ANY alterations you make to your site may have on your PCI compliance.
    Furthermore, any advice you see here about PCI matters is merely an opinion, and should not be relied upon as "official". Official PCI information should be obtained from the PCI Security Council directly or from one of their authorized Assessors.

  10. #10
    Join Date
    Jul 2007
    Posts
    14
    Plugin Contributions
    0

    Default Re: Updating Language constants dynamically

    If I want to do this without affecting security, is there a method of achieving this?

    Can you clarify the difference between the language files and the database configuration table, in terms of which one over-rides the other? If I changed the values in the database - are they reflected through the site or are they over-ridden by the language files?

    Thanks

 

 
Page 1 of 2 12 LastLast

Similar Threads

  1. v152 Forcing a script to use constants from a specific language
    By torvista in forum Addon Language Packs
    Replies: 3
    Last Post: 17 Jan 2014, 12:16 AM
  2. List constants from a specific language file?
    By torvista in forum General Questions
    Replies: 3
    Last Post: 8 Jul 2011, 08:15 PM
  3. Constants coming up instead of text assigned to constants
    By blk00xjc in forum General Questions
    Replies: 3
    Last Post: 25 Mar 2009, 10:11 PM
  4. Just finished updating Hebrew language pack
    By murlex in forum Templates, Stylesheets, Page Layout
    Replies: 4
    Last Post: 16 Jan 2009, 12:38 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
disjunctive-egg
Zen-Cart, Internet Selling Services, Klamath Falls, OR