b2evolution PHP Cross Reference Blogging Systems

Source: /inc/locales/translation.ctrl.php - 198 lines - 6594 bytes - Text - Print

Description: This file implements the UI controller for translation management.

   1  <?php
   2  /**

   3   * This file implements the UI controller for translation management.

   4   *

   5   * This file is part of the evoCore framework - {@link http://evocore.net/}

   6   * See also {@link http://sourceforge.net/projects/evocms/}.

   7   *

   8   * @copyright (c)2003-2014 by Francois Planque - {@link http://fplanque.com/}

   9   *

  10   * @package admin

  11   *

  12   * {@internal Below is a list of authors who have contributed to design/coding of this file: }}

  13   * @author fplanque: Francois PLANQUE

  14   *

  15   * @version $Id: translation.ctrl.php 985 2012-04-16 21:59:17Z yura $

  16   */
  17  if( !defined('EVO_MAIN_INIT') ) die( 'Please, do not access this page directly.' );
  18  
  19  // Check minimum permission:

  20  $current_User->check_perm( 'options', 'view', true );
  21  
  22  load_funcs('locales/model/_translation.funcs.php');
  23  
  24  $AdminUI->set_path( 'options', 'regional', 'locales' );
  25  
  26  param_action();
  27  param( 'edit_locale', 'string', '', true );
  28  
  29  // Load all available locale defintions:

  30  locales_load_available_defs();
  31  
  32  if( !isset( $locales[$edit_locale] ) )
  33  {    // Check for correct locale
  34      $Messages->add( T_('The locale is incorrect!'), 'error' );
  35      header_redirect( '?ctrl=locales&loc_transinfo=1', 303 );
  36  }
  37  
  38  /* Set charset of edited locale in order to display the special UTF symbols correctly */

  39  global $locales, $io_charset, $evo_charset;
  40  if( $locales[$edit_locale]['charset'] == 'utf-8' && $io_charset != 'utf-8' )
  41  {
  42      // Set encoding for MySQL connection

  43      $DB->set_connection_charset( $locales[$edit_locale]['charset'] );
  44      // Set charset for html format

  45      $io_charset = $locales[$edit_locale]['charset'];
  46      $evo_charset = $locales[$edit_locale]['charset'];
  47  }
  48  
  49  switch( $action )
  50  {
  51      case 'import_pot':
  52          // Check that this action request is not a CSRF hacked request:

  53          $Session->assert_received_crumb( 'translation' );
  54  
  55          if( translation_update_table_pot() )
  56          {
  57              $Messages->add( T_('The file .POT was imported into database successfully'), 'success' );
  58          }
  59          header_redirect( '?ctrl=translation&edit_locale='.$edit_locale, 303 );
  60          break;
  61  
  62      case 'import_po':
  63          // Check that this action request is not a CSRF hacked request:

  64          $Session->assert_received_crumb( 'translation' );
  65  
  66          if( translation_update_table_po( $edit_locale ) )
  67          {
  68              $Messages->add( T_('The file .PO was imported into database successfully'), 'success' );
  69          }
  70          header_redirect( '?ctrl=translation&edit_locale='.$edit_locale, 303 );
  71          break;
  72  
  73      case 'generate_pot':
  74          // Check that this action request is not a CSRF hacked request:

  75          $Session->assert_received_crumb( 'translation' );
  76  
  77          if( translation_generate_pot_file() )
  78          {
  79              $Messages->add( T_('The file .POT was generated successfully'), 'success' );
  80          }
  81          header_redirect( '?ctrl=translation&edit_locale='.$edit_locale, 303 );
  82          break;
  83  
  84      case 'generate_po':
  85          // Check that this action request is not a CSRF hacked request:

  86          $Session->assert_received_crumb( 'translation' );
  87  
  88          if( translation_generate_po_file( $edit_locale ) )
  89          {
  90              $Messages->add( T_('The file .PO was generated successfully'), 'success' );
  91          }
  92          header_redirect( '?ctrl=translation&edit_locale='.$edit_locale, 303 );
  93          break;
  94  
  95      case 'new':
  96          param( 'iost_ID', 'integer', 0, true );
  97  
  98          $SQL = new SQL();
  99          $SQL->SELECT( '*, "'.$edit_locale.'" AS itst_locale, "" AS itst_standard' );
 100          $SQL->FROM( 'T_i18n_original_string' );
 101          $SQL->WHERE( 'iost_ID = '.$DB->quote( $iost_ID ) );
 102          $edited_String = $DB->get_row( $SQL->get() );
 103          break;
 104  
 105      case 'edit':
 106          param( 'itst_ID', 'integer', 0, true );
 107  
 108          $SQL = new SQL();
 109          $SQL->SELECT( '*' );
 110          $SQL->FROM( 'T_i18n_translated_string' );
 111          $SQL->FROM_add( 'LEFT JOIN T_i18n_original_string ON iost_ID = itst_iost_ID' );
 112          $SQL->WHERE( 'itst_ID = '.$DB->quote( $itst_ID ) );
 113          $edited_String = $DB->get_row( $SQL->get() );
 114          break;
 115  
 116      case 'update':
 117          // Check that this action request is not a CSRF hacked request:

 118          $Session->assert_received_crumb( 'translation' );
 119  
 120          param( 'itst_ID', 'integer' );
 121          param( 'itst_standard', 'string' );
 122  
 123          if( $itst_ID > 0 )
 124          {    // Update translated string
 125              $DB->query( 'UPDATE T_i18n_translated_string
 126                    SET itst_standard = '.$DB->quote( $itst_standard ).'
 127                  WHERE itst_ID = '.$DB->quote( $itst_ID ) );
 128  
 129              $Messages->add( T_('A translated string was updated.'), 'success' );
 130              header_redirect( '?ctrl=translation&edit_locale='.$edit_locale, 303 );
 131          }
 132          else
 133          {    // Insert new translated string
 134              param( 'iost_ID', 'integer' );
 135  
 136              $DB->query( 'INSERT T_i18n_translated_string
 137                  ( itst_iost_ID, itst_locale, itst_standard, itst_inpofile ) VALUES
 138                  ( '.$iost_ID.', '.$DB->quote( $edit_locale ).', '.$DB->quote( $itst_standard ).', 1 )' );
 139  
 140              $Messages->add( T_('New translated string was added.'), 'success' );
 141              header_redirect( '?ctrl=translation&edit_locale='.$edit_locale, 303 );
 142          }
 143          break;
 144  
 145      case 'delete':
 146          // Check that this action request is not a CSRF hacked request:

 147          $Session->assert_received_crumb( 'translation' );
 148  
 149          param( 'itst_ID', 'integer' );
 150  
 151          $DB->query( 'DELETE FROM T_i18n_translated_string WHERE itst_ID = '.$DB->quote( $itst_ID ) );
 152  
 153          $Messages->add( T_('A translated string was deleted.'), 'success' );
 154          header_redirect( '?ctrl=translation&edit_locale='.$edit_locale, 303 );
 155          break;
 156  }
 157  
 158  $AdminUI->breadcrumbpath_init( false );
 159  $AdminUI->breadcrumbpath_add( T_('System'), '?ctrl=system',
 160          T_('Global settings are shared between all blogs; see Blog settings for more granular settings.') );
 161  $AdminUI->breadcrumbpath_add( T_('Regional settings'), '?ctrl=locales' );
 162  $AdminUI->breadcrumbpath_add( T_('Locales'), '?ctrl=locales' );
 163  $AdminUI->breadcrumbpath_add( T_('Translation editor'), '?ctrl=translation&locale='.$locale );
 164  
 165  // Display <html><head>...</head> section! (Note: should be done early if actions do not redirect)

 166  $AdminUI->disp_html_head();
 167  
 168  // Display title, menu, messages, etc. (Note: messages MUST be displayed AFTER the actions)

 169  $AdminUI->disp_body_top();
 170  
 171  // Begin payload block:

 172  $AdminUI->disp_payload_begin();
 173  
 174  // Display VIEW:

 175  switch( $action )
 176  {
 177      case 'new_strings':
 178          param( 'action', 'string', '', true );
 179          $AdminUI->disp_view( 'locales/views/_translation_new.view.php' );
 180          break;
 181  
 182      case 'new':
 183      case 'edit':
 184          $AdminUI->disp_view( 'locales/views/_translation.form.php' );
 185          break;
 186  
 187      default:
 188          $AdminUI->disp_view( 'locales/views/_translation.view.php' );
 189          break;
 190  }
 191  
 192  // End payload block:

 193  $AdminUI->disp_payload_end();
 194  
 195  // Display body bottom, debug info and close </html>:

 196  $AdminUI->disp_global_footer();
 197  
 198  ?>

title

Description

title

Description

title

Description

title

title

Body