/[drupal]/contributions/modules/transliteration/transliteration.module
ViewVC logotype

Diff of /contributions/modules/transliteration/transliteration.module

Parent Directory Parent Directory | Revision Log Revision Log | View Revision Graph Revision Graph | View Patch Patch

revision 1.5.2.2, Fri Oct 9 12:03:29 2009 UTC revision 1.5.2.3, Thu Oct 15 20:00:04 2009 UTC
# Line 1  Line 1 
1  <?php  <?php
2  // $Id: transliteration.module,v 1.5.2.1 2009/09/24 19:19:41 smk Exp $  // $Id: transliteration.module,v 1.5.2.2 2009/10/09 12:03:29 smk Exp $
3    
4  /**  /**
5   * @file   * @file
# Line 10  Line 10 
10   */   */
11    
12  /**  /**
13     * Sanitize a file path.
14     *
15     * Additionally removes invalid characters from a file name (which may include
16     * sub-directories) after transliteration.
17     *
18     * @param $filename
19     *   A file name.
20     * @param $source_langcode
21     *   Optional ISO 639 language code that denotes the language of the input.
22     *   Used to apply language-specific variations and defaults to the current
23     *   display language. If transliteration takes place during output (instead
24     *   of creation) and the source language is not known at that time, it is
25     *   recommended to set this argument to 'en' to produce consistent results
26     *   for all enabled languages.
27     * @return
28     *   Cleaned file name.
29     */
30    function transliteration_clean_filename($filename, $source_langcode = NULL) {
31      // Transliterate.
32      $filename = transliteration_get($filename, '', $source_langcode);
33      // Replace whitespace.
34      $filename = str_replace(' ', '_', $filename);
35      // Remove remaining unsafe characters.
36      $filename = preg_replace('![^0-9A-Za-z_./-]!', '', $filename);
37      // Force lowercase to prevent issues on case-insensitive file systems.
38      $filename = strtolower($filename);
39    
40      return $filename;
41    }
42    
43    /**
44   * Transliterate UTF-8 text to ASCII.   * Transliterate UTF-8 text to ASCII.
45   *   *
46   * Takes an input string in any language and character set, and tries to   * Takes an input string in any language and character set, and tries to
# Line 43  function transliteration_get($input, $un Line 74  function transliteration_get($input, $un
74   */   */
75  function transliteration_init() {  function transliteration_init() {
76    if (!empty($_FILES['files'])) {    if (!empty($_FILES['files'])) {
     module_load_include('inc', 'transliteration');  
   
77      // Figure out language, which is available for node form submits.      // Figure out language, which is available for node form submits.
78      $langcode = NULL;      $langcode = NULL;
79      if (!empty($_POST['language'])) {      if (!empty($_POST['language'])) {
# Line 53  function transliteration_init() { Line 82  function transliteration_init() {
82          $langcode = $_POST['language'];          $langcode = $_POST['language'];
83        }        }
84      }      }
85        // Process file uploads.
86      foreach ($_FILES['files']['name'] as $field => $filename) {      foreach ($_FILES['files']['name'] as $field => $filename) {
87        // Keep a copy of the unaltered file name.        // Keep a copy of the unaltered file name.
88        $_FILES['files']['orig_name'][$field] = $filename;        $_FILES['files']['orig_name'][$field] = $filename;

Legend:
Removed from v.1.5.2.2  
changed lines
  Added in v.1.5.2.3

  ViewVC Help
Powered by ViewVC 1.1.2