includes/functions.php
changeset 209 8a00247d1dee
parent 193 ebe99e82a59a
child 210 2b283402e4e4
equal deleted inserted replaced
208:c75ad574b56d 209:8a00247d1dee
  3164   }
  3164   }
  3165   
  3165   
  3166   return $score;
  3166   return $score;
  3167 }
  3167 }
  3168 
  3168 
       
  3169 /**
       
  3170  * Installs a language.
       
  3171  * @param string The ISO-639-3 identifier for the language. Maximum of 6 characters, usually 3.
       
  3172  * @param string The name of the language in English (Spanish)
       
  3173  * @param string The name of the language natively (EspaƱol)
       
  3174  * @param string The path to the file containing the language's strings. Optional.
       
  3175  */
       
  3176 
       
  3177 function install_language($lang_code, $lang_name_neutral, $lang_name_local, $lang_file = false)
       
  3178 {
       
  3179   global $db, $session, $paths, $template, $plugins; // Common objects
       
  3180   
       
  3181   $q = $db->sql_query('SELECT 1 FROM '.table_prefix.'language WHERE lang_code = "' . $db->escape($lang_code) . '";');
       
  3182   if ( !$q )
       
  3183     $db->_die('functions.php - checking for language existence');
       
  3184   
       
  3185   if ( $db->numrows() > 0 )
       
  3186     // Language already exists
       
  3187     return false;
       
  3188   
       
  3189   $q = $db->sql_query('INSERT INTO ' . table_prefix . 'language(lang_code, lang_name_default, lang_name_native) 
       
  3190                          VALUES(
       
  3191                            "' . $db->escape($lang_code) . '",
       
  3192                            "' . $db->escape($lang_name_neutral) . '",
       
  3193                            "' . $db->escape($lang_name_native) . '"
       
  3194                          );');
       
  3195   if ( !$q )
       
  3196     $db->_die('functions.php - installing language');
       
  3197   
       
  3198   $lang_id = $db->insert_id();
       
  3199   if ( empty($lang_id) )
       
  3200     return false;
       
  3201   
       
  3202   // Do we also need to install a language file?
       
  3203   if ( is_string($lang_file) && file_exists($lang_file) )
       
  3204   {
       
  3205     $lang = new Language($lang_id);
       
  3206     $lang->import($lang_file);
       
  3207   }
       
  3208   else if ( is_string($lang_file) && !file_exists($lang_file) )
       
  3209   {
       
  3210     echo '<b>Notice:</b> Can\'t load language file, so the specified language wasn\'t fully installed.<br />';
       
  3211     return false;
       
  3212   }
       
  3213   return true;
       
  3214 }
       
  3215 
  3169 //die('<pre>Original:  01010101010100101010100101010101011010'."\nProcessed: ".uncompress_bitfield(compress_bitfield('01010101010100101010100101010101011010')).'</pre>');
  3216 //die('<pre>Original:  01010101010100101010100101010101011010'."\nProcessed: ".uncompress_bitfield(compress_bitfield('01010101010100101010100101010101011010')).'</pre>');
  3170 
  3217 
  3171 ?>
  3218 ?>