Latest News: (loading..)
mattjt83

Edit content module language files from admin/modules_content

18 posts in this topic

You can find the code here: https://github.com/mattjt83/Responsive-osCommerce/tree/Edit_content_modules_language_files

 

This was just a fun little project to use an admin hook to be able to edit the language file that goes with each content module right from admin/modules_content.php.

 

Feedback is welcome and improvements as well.

altoid, Moxamint, multimixer and 1 other like this

Share this post


Link to post
Share on other sites

Thanks @@mattjt83

Good hooks point to extend module configs.

Hooks calls would be more general like this:
 

$OSCOM_Hooks->register('contentModuleEditors');

so we could edit attached css or script files like in wordpress.

 


 

Share this post


Link to post
Share on other sites

Nice! This whole languages thing is somehting to look at as a priority.

mattjt83 likes this

Share this post


Link to post
Share on other sites

@@burt

 

 

Nice! This whole languages thing is somehting to look at as a priority.

 

Is there a particular direction for "the whole language thing" to be directed towards? I don't mind using some of my free time to work on it as long as I know what to be working towards.

 

The reason I came up with what I did here was mostly because I think shop-owners (me included) want to be able to manage the content modules from the admin in their entirety. The same thing done with the language file here could probably be done with the template pages that come with content modules as well.

Share this post


Link to post
Share on other sites

Turns out it's pretty easy to be able to add template file editing as well. Screenshot attached.

post-289095-0-70716900-1462801878_thumb.png

altoid likes this

Share this post


Link to post
Share on other sites

@@mattjt83 - either INI files or Database - to be decided at some point.

 

I wonder if your code works OK with multi language shops ?

Share this post


Link to post
Share on other sites

@@burt

 

Not sure on the multi language shops. Right now it just grabs whatever language you are using and loads that file. I'm sure it could be done if someone wanted to work on it.

 

This solution is by no means perfect and I guess it is just a temp solution for me as things with the language files will evolve at some point.

 

I'm adding syntax highlighting and the ability to edit the module template file and I think that's all I will do on it for now. Works for my shop so I figured I would share with others if they want to use it.

Share this post


Link to post
Share on other sites

Absolutely - super cool that you're sharing things

Share this post


Link to post
Share on other sites

It's really interesting @@mattjt83! This solves problems when installing modules in non-english shops.

 

It's easy to make it multilingual by editing the hooks functions this way:

    function listen_outputModuleFileContents() {
        global $_GET, $language, $modules;
        
        $output = '';
        
        $languages = tep_get_languages();
          for ($i=0, $n=sizeof($languages); $i<$n; $i++) {

          foreach ( $modules['installed'] as $array_key => $array ) {
          foreach ( $array as $key => $value ) {
              if ( $key == 'code' && $value == $_GET['module'] ){
                  $module_group = $modules['installed'][$array_key]['group'];
              }
          }
        }
        
        $module_file_name = DIR_FS_CATALOG_LANGUAGES . $languages[$i]['directory'] . '/modules/content/' . $module_group . '/' . $_GET['module'] . '.php';
        
        if (file_exists($module_file_name)) { 
          require_once DIR_WS_LANGUAGES . $languages[$i]['directory'] . '/define_language.php'; //helper text TEXT_EDIT_NOTE
          $header = '<br><br><strong>Edit Language File</strong><br>Edit the content module language file here<br><br>' . TEXT_EDIT_NOTE;

          $file_array = file($module_file_name);
          $contents   = implode('', $file_array);
          if (tep_is_writable($module_file_name)) {
            $output .= '<br /><br />' .tep_image(tep_catalog_href_link(DIR_WS_LANGUAGES . $languages[$i]['directory'] . '/images/' . $languages[$i]['image'], '', 'SSL'), $languages[$i]['name']) . ' ' . '<strong>' . $languages[$i]['name'] . '</strong>';
            $output .= tep_draw_textarea_field('file_contents', 'soft', '80', '25', $contents, ' style="width: 99%;min-width:600px;"');
            $output .= tep_draw_hidden_field('file_name', $module_file_name);
          }
        }
      }
      $output = $header . $output;
      return $output;
    }
  }

Forms has to be moved inside the function too, because it needs a form for each language.

Share this post


Link to post
Share on other sites

I see you also faced the problem of non-standard module names: https://github.com/mattjt83/Responsive-osCommerce/commit/30d2657115e802cdd27a91c2d5ee1d8755f92400

As i mentioned in http://forums.oscommerce.com/topic/409328-discussion-about-content-module-width-and-placement/#entry1742231

some kind of naming and common functions conventions should be written; otherwise it will be almost impossible to develop tools like this one in the future.

Share this post


Link to post
Share on other sites

@@piernas

 

The naming convention caught me a bit off-guard and is why I wrote a patch for it. If you want to get the thing working with multi-languages would you consider coding it up and sending it to me? There will need to be additions to the processing logic as well to handle everything.

 

This whole thing is pretty handy I think for most shop-owners but is not something that will *probably* ever make it into the core code. It works well for my shop and has already proven to be very handy for quick adjustments, which is why I decided to share it.

altoid likes this

Share this post


Link to post
Share on other sites

Nice set of tools, easy to add on to the shop admin, especially if hooks are already in place. :thumbsup:

mattjt83 likes this

Share this post


Link to post
Share on other sites

@@piernas

 

The naming convention caught me a bit off-guard and is why I wrote a patch for it. If you want to get the thing working with multi-languages would you consider coding it up and sending it to me? There will need to be additions to the processing logic as well to handle everything.

 

This whole thing is pretty handy I think for most shop-owners but is not something that will *probably* ever make it into the core code. It works well for my shop and has already proven to be very handy for quick adjustments, which is why I decided to share it.

 

Of course, I'll work on it and send it to you as soon as I finish some things I'm working on.

I've been thinking on how to deal with non-conventional or badly written modules for this addon: http://addons.oscommerce.com/info/9458 and found the way for most of the (but not all). I'll take a look at your code to see if it gives me some ideas.

Share this post


Link to post
Share on other sites

Just used this to do some css work in template files.  Easy!! Nice!!  Saved a bit of time having to fire up the FTP utility to make the same changes.

mattjt83 likes this

Share this post


Link to post
Share on other sites

@@altoid

 

It's pretty handy to have around. Especially for those small code tweaks.

Edited by mattjt83
altoid likes this

Share this post


Link to post
Share on other sites

@@piernas

 

If you want to get the thing working with multi-languages would you consider coding it up and sending it to me? There will need to be additions to the processing logic as well to handle everything.

 

Just added the multi-language support and pushed to your github, see https://github.com/mattjt83/Responsive-osCommerce/pull/6 . Checks for modified files still needs to be added.

 

May I add the ability to this addon? http://addons.oscommerce.com/info/9458

Edited by piernas

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