includes/functions.php
changeset 371 dc6026376919
parent 362 02d315d1cc58
child 372 5bd429428101
equal deleted inserted replaced
370:b251818286b1 371:dc6026376919
  3230 
  3230 
  3231 function install_language($lang_code, $lang_name_neutral, $lang_name_local, $lang_file = false)
  3231 function install_language($lang_code, $lang_name_neutral, $lang_name_local, $lang_file = false)
  3232 {
  3232 {
  3233   global $db, $session, $paths, $template, $plugins; // Common objects
  3233   global $db, $session, $paths, $template, $plugins; // Common objects
  3234   
  3234   
  3235   $q = $db->sql_query('SELECT 1 FROM '.table_prefix.'language WHERE lang_code = "' . $db->escape($lang_code) . '";');
  3235   $q = $db->sql_query('SELECT 1 FROM '.table_prefix.'language WHERE lang_code = \'' . $db->escape($lang_code) . '\';');
  3236   if ( !$q )
  3236   if ( !$q )
  3237     $db->_die('functions.php - checking for language existence');
  3237     $db->_die('functions.php - checking for language existence');
  3238   
  3238   
  3239   if ( $db->numrows() > 0 )
  3239   if ( $db->numrows() > 0 )
  3240     // Language already exists
  3240     // Language already exists
  3241     return false;
  3241     return false;
  3242   
  3242   
  3243   $q = $db->sql_query('INSERT INTO ' . table_prefix . 'language(lang_code, lang_name_default, lang_name_native) 
  3243   $q = $db->sql_query('INSERT INTO ' . table_prefix . 'language(lang_code, lang_name_default, lang_name_native) 
  3244                          VALUES(
  3244                          VALUES(
  3245                            "' . $db->escape($lang_code) . '",
  3245                            \'' . $db->escape($lang_code) . '\',
  3246                            "' . $db->escape($lang_name_neutral) . '",
  3246                            \'' . $db->escape($lang_name_neutral) . '\',
  3247                            "' . $db->escape($lang_name_native) . '"
  3247                            \'' . $db->escape($lang_name_native) . '\'
  3248                          );');
  3248                          );');
  3249   if ( !$q )
  3249   if ( !$q )
  3250     $db->_die('functions.php - installing language');
  3250     $db->_die('functions.php - installing language');
  3251   
  3251   
  3252   $lang_id = $db->insert_id();
  3252   if ( ENANO_DBLAYER == 'PGSQL' )
  3253   if ( empty($lang_id) || $lang_id == 0 )
  3253   {
  3254   {
  3254     // exception for Postgres, which doesn't support insert IDs
  3255     $db->_die('functions.php - invalid returned lang_id');
  3255     // This will cause the Language class to just load by lang code
       
  3256     // instead of by numeric ID
       
  3257     $lang_id = $lang_code;
       
  3258   }
       
  3259   else
       
  3260   {
       
  3261     $lang_id = $db->insert_id();
       
  3262     if ( empty($lang_id) || $lang_id == 0 )
       
  3263     {
       
  3264       $db->_die('functions.php - invalid returned lang_id');
       
  3265     }
  3256   }
  3266   }
  3257   
  3267   
  3258   // Do we also need to install a language file?
  3268   // Do we also need to install a language file?
  3259   if ( is_string($lang_file) && file_exists($lang_file) )
  3269   if ( is_string($lang_file) && file_exists($lang_file) )
  3260   {
  3270   {