Exemplo n.º 1
0
 public function action_edit()
 {
     if ($this->_auth->logged_in('technical')) {
         if ($this->request->param('id')) {
             $translation = ORM::factory('Translations', $this->request->param('id'));
             $translation_array = I18n::load($translation->language_symbol);
             $this->template->content = View::factory('template/admin/translations/edit');
             $this->template->content->bind('structure', $this->_structure_translation)->bind('category', $this->_category_translations)->bind('translation', $translation_array)->bind('translation_detail', $translation);
             if (isset($_POST['update_translation'])) {
                 try {
                     $this->_generate_translation_file($this->request->post('language_symbol'), $this->_generate_translation_array($this->request->post()));
                     sleep(3);
                     if (!is_file(DOCROOT . $this->_director . $this->request->post('language_symbol') . '.php')) {
                         $this->_set_message('error', __('ERORR_GENERATE_TRANSLATION_FILE'));
                     }
                     if (!empty($this->request->post('language_symbol'))) {
                         if (!$this->_compare_file_names($translation->language_symbol, $this->request->post('language_symbol'))) {
                             unlink(DOCROOT . $this->_director . $translation->language_symbol . '.php');
                         }
                     }
                     $translation->language = $this->request->post('language');
                     $translation->language_symbol = $this->request->post('language_symbol');
                     $translation->version = $this->request->post('version');
                     $translation->date_change = date("Y-m-d H:i:s");
                     $translation->user_id = $this->_auth->get_user()->pk();
                     $translation->save();
                     $this->_set_message('success', __('NO_ERROR_TRANSLATION_SUCCESS_EDIT'));
                     HTTP::redirect(URL::site($this->request->uri(), TRUE), 302);
                 } catch (ORM_Validation_Exception $e) {
                     $this->_set_message('error', $e->errors('avatar'));
                 }
             }
         }
     }
 }
Exemplo n.º 2
0
 private static function runlevel3(){
     Logger::enter_group('Runlevel 4');
     Logger::debug('Loading Application-Variables');
     require_once(APP_ROOT . '/defaults.php');
     I18n::load();
     Logger::leave_group();
 }
Exemplo n.º 3
0
 public function action_index()
 {
     /*
     $lbl = array();
     $lbl['cancel'] = __('Cancel');
     $lbl['import_loading_text'] = __('Importing new files.');
     
     $lbl['login'] = __('Login');
     $lbl['username'] = __('Username');
     $lbl['password'] = __('Password');
     $lbl['remember'] = __('Remember me');
     
     $lbl['validator_messages']["required"] = __("This field is required.");
     		$lbl['validator_messages']['remote'] = __('Please fix this field.');
     		$lbl['validator_messages']['email'] = __('Please enter a valid email address.');
     		$lbl['validator_messages']['url'] = __('Please enter a valid URL.');
     		$lbl['validator_messages']['date'] = __('Please enter a valid date.');
     		$lbl['validator_messages']['dateISO'] = __('Please enter a valid date (ISO).');
     		$lbl['validator_messages']['number'] = __('Please enter a valid number.');
     		$lbl['validator_messages']['digits'] = __('Please enter only digits.');
     		$lbl['validator_messages']['creditcard'] = __('Please enter a valid credit card number.');
     		$lbl['validator_messages']['equalTo'] = __('Please enter the same value again.');
     		$lbl['validator_messages']['accept'] = __('Please enter a value with a valid extension.');
     		$lbl['validator_messages']['maxlength'] = __('Please enter no more than {0} characters.');
     		$lbl['validator_messages']['minlength'] = __('Please enter at least {0} characters.');
     		$lbl['validator_messages']['rangelength'] = __('Please enter a value between {0} and {1} characters long.');
     		$lbl['validator_messages']['range'] = __('Please enter a value between {0} and {1}.');
     		$lbl['validator_messages']['max'] = __('Please enter a value less than or equal to {0}.');
     		$lbl['validator_messages']['min'] = __('Please enter a value greater than or equal to {0}.');
     */
     $this->json(I18n::load(I18n::$lang));
 }
Exemplo n.º 4
0
 public static function get_plural($string, $count)
 {
     // Load the translation table
     $table = I18n::load(I18n::$lang);
     $key = I18n::get_plural_key(I18n::$lang, $count);
     // Return the translated string if it exists
     return isset($table[$string][$key]) ? $table[$string][$key] : $string;
 }
Exemplo n.º 5
0
 public static function get($string, $lang = NULL)
 {
     if (!$lang) {
         $lang = I18n::$lang;
     }
     $table = I18n::load($lang);
     return isset($table[$string]) ? $table[$string] : $string;
 }
Exemplo n.º 6
0
Arquivo: i18n.php Projeto: ascseb/core
 /**
  * Returns translation of a string. If no translation exists, the original
  * string will be returned.
  *
  * @param   string   text to translate
  * @return  string
  */
 public static function get($string)
 {
     if (!isset(I18n::$_cache[I18n::$lang])) {
         // Load the translation table
         I18n::load(I18n::$lang);
     }
     // Return the translated string if it exists
     return isset(I18n::$_cache[I18n::$lang][$string]) ? I18n::$_cache[I18n::$lang][$string] : $string;
 }
Exemplo n.º 7
0
 /**
  * @param string $text text to translate
  * @param string $lang
  *
  * @return  string
  */
 public static function get($text, $lang = NULL)
 {
     if (!$lang) {
         $lang = I18n::$lang;
     }
     $table = I18n::load($lang);
     $alternative = I18n::load('en-us');
     return isset($table[$text]) ? $table[$text] : (isset($alternative[$text]) ? $alternative[$text] : $text);
 }
Exemplo n.º 8
0
 /**
  * Returns translation of a string. If no translation exists, the original
  * string will be returned. No parameters are replaced.
  *
  *     $hello = I18n::get('Hello friends, my name is :name');
  *
  * @param   string   text to translate
  * @param   string   target language
  * @return  string
  */
 public static function get($string, $lang = NULL)
 {
     if (!$lang) {
         // Use the global target language
         $lang = I18n::$lang;
     }
     // Load the translation table for this language
     $table = I18n::load($lang);
     // Return the translated string if it exists
     return isset($table[$string]) ? $table[$string] : $string;
 }
Exemplo n.º 9
0
 public function __construct($request)
 {
     parent::__construct($request);
     $this->template = View::factory('hmo_masterpage');
     $config = Kohana_Config::instance()->load("config");
     $this->site = $config['app_path'];
     $this->session = Session::instance();
     if ($this->authenticate) {
         $this->authenticate();
     }
     $this->message = I18n::load('en-us');
 }
Exemplo n.º 10
0
Arquivo: i18n.php Projeto: raku/MorCMS
 /**
  * Get value from db table
  * @param string $string
  * @param string $lang
  * @return string 
  */
 public static function get($string, $lang = null)
 {
     if (Kohana::$environment == Kohana::DEVELOPMENT) {
         if (!$lang) {
             // Use the global target language
             $lang = I18n::$lang;
         }
         // Load the translation table for this language
         $table = I18n::load($lang);
         // Return the translated string if it exists
         return isset($table[I18n::$view . '|' . $string]) ? $table[I18n::$view . '|' . $string] : I18n::add($string);
     } else {
         return parent::get($string, $lang);
     }
 }
Exemplo n.º 11
0
 public static function get($string, $lang = NULL)
 {
     if (!$lang) {
         // Use the global target language
         $lang = I18n::$lang;
     }
     // Load the translation table for this language
     $table = I18n::load($lang);
     // Если нет слова в словаре, добавляем его
     if (!isset($table[$string])) {
         self::append($string, $lang);
     }
     // Return the translated string if it exists
     return isset($table[$string]) ? $table[$string] : $string;
 }
Exemplo n.º 12
0
 /**
  * Edit module interface
  * (internationalization module)
  */
 protected function module_i18n()
 {
     if (!isset($this->cms_modules[$this->config_mod['cms_module']])) {
         return false;
     }
     $data = Arr::get($_POST, 'data', []);
     if ($this->request->is_post()) {
         $path = $this->cms_modules[$this->config_mod['cms_module']] . 'i18n' . DS . $this->language . EXT;
         File::var_export($data, $path);
         Message::success(__('settings.changes_saved'));
         HTTP::redirect(Route::url(Request::get('routename'), ['controller' => Request::get('controller'), 'action' => 'i18n']));
     }
     $group = str_replace('cms_', '', $this->config_mod['cms_module']);
     foreach (I18n::load($this->language) as $key => $val) {
         if (preg_match('/^' . $group . '\\./', $key)) {
             $data[$key] = $val;
         }
     }
     $this->title = $this->config_mod['cms_module'] == 'cms_settings' ? __('settings.i18n_edit_global') : __('settings.i18n_edit_iface');
     $this->content = View::factory('backend/v_i18n', ['data' => $data]);
 }
Exemplo n.º 13
0
 public static function get($string, $lang = NULL)
 {
     if (!$lang) {
         // Use the global target language
         $lang = I18n::$lang;
     }
     // Load the translation table for this language
     $table = I18n::load($lang);
     if (!isset($table[$string])) {
         $file = Kohana::find_file('i18n', 'nottranslated');
         //$f = fopen($file[0], 'r');
         $content = file_get_contents($file[0]);
         $lines = explode("\n", $content);
         if (!in_array($string, $lines)) {
             $lines[] = $string;
             $content = implode("\n", $lines);
             $f = fopen($file[0], 'w');
             fwrite($f, $content);
         }
     }
     // Return the translated string if it exists
     return isset($table[$string]) ? $table[$string] : $string;
 }
Exemplo n.º 14
0
<?php

defined('SYSPATH') or die('No direct script access.');
$GI18N = I18n::load(I18n::$lang);
?>
<table><caption>Applications list you have registered</caption><thead>
    <tr><th>API Key</th><th>API Secret</th><th>Redirect URI</th><th>Scope</th><th>SSH Key</th><th>OP</th></tr>
    </thead><tbody><?php 
foreach ($servers as $row) {
    ?>
<tr><td><a href="/server/register/<?php 
    echo $row['server_id'];
    ?>
"><?php 
    echo $row['client_id'];
    ?>
</a></td>
    <td><?php 
    echo $row['client_secret'];
    ?>
</td><td><?php 
    echo $row['redirect_uri'];
    ?>
</td>
    <td><?php 
    echo $row['scope'];
    ?>
</td><td><?php 
    echo $row['ssh_key'];
    ?>
</td><th>DEL</th></tr><?php 
Exemplo n.º 15
0
 /**
  * Translate month and weekday names in the string
  *
  *
  * @uses    I18n::load
  * @uses    I18n::$lang
  * @param   string  string to translate
  * @return  string
  */
 public static function date($string)
 {
     static $translate = array();
     if (empty($string)) {
         return $string;
     }
     $string = (string) $string;
     // Create a new message list
     $messages = array();
     if (!isset($translate[I18n::$lang])) {
         $translate[I18n::$lang] = array_intersect_key(I18n::load(I18n::$lang), Kohana::message('date'));
     }
     return strtr($string, $translate[I18n::$lang]);
 }
Exemplo n.º 16
0
<?php

defined('SYSPATH') or die('No direct access allowed.');
print Kohana::FILE_SECURITY . "\n\n";
print "// This file was generated by Kohana-I18nget, http://github.com/rafsoaken/kohana-i18nget\n\n";
print "return array(\n";
//load existing translation table - need that to check for keys that equal their translations
$table = I18n::load($language_code);
foreach ($data as $file) {
    print "\t// " . $file['filepath_human'] . "\n";
    foreach ($file['lines'] as $line) {
        $line['line_string'] = str_replace('<?php', '', $line['line_string']);
        $line['line_string'] = str_replace('<?', '', $line['line_string']);
        $line['line_string'] = str_replace('?>', '', $line['line_string']);
        $line['line_string'] = trim($line['line_string']);
        foreach ($line['phrases'] as $phrase) {
            $phrase_fixed = str_replace('\\\'', '\'', $phrase);
            $phrase_fixed = str_replace('\\"', '"', $phrase_fixed);
            if ($global_i18n) {
                //I18n::get() doesnt tell us if the key is equal to the translation
                $phrase_translated = Arr::get($table, $phrase_fixed, NULL);
            } else {
                $phrase_translated = Arr::get(file_exists($filename) ? Kohana::load($filename) : array(), $phrase_fixed, NULL);
            }
            $phrase_translated_fixed = str_replace('\'', '\\\'', (string) $phrase_translated);
            $not_translated = '';
            if (is_null($phrase_translated)) {
                $not_translated = '/// TODO';
                $phrase_translated_fixed = '';
            }
            // 			print($not_translated."\t'$phrase' => '".$phrase_translated_fixed."', // ".$line['line_number'].": ".$line['line_string']."\n");
Exemplo n.º 17
0
 private function import($file = 'en', $import_keys = TRUE, $import_strings = TRUE)
 {
     // Retrive the id of the wanted language
     $language = ORM::factory('langify_language')->where('file', '=', $file)->find();
     if (!$language->loaded()) {
         // Language was not found, we should redirect the user to create a language.
         return false;
     }
     // Load the translation file
     $i18n = I18n::load($file);
     foreach ($i18n as $k => $v) {
         $key = ORM::factory('langify_key')->where('key', '=', $k)->find();
         if ($import_keys === TRUE) {
             if (!$key->loaded()) {
                 $key = ORM::factory('langify_key');
                 $key->key = $k;
                 $key->save();
             }
         }
         if ($import_strings) {
             if (!$key->loaded()) {
                 // This isnt supposed to happen, lets just ignore it.
                 continue;
             }
             $string = ORM::factory('langify_string')->where('language_id', '=', $language->id)->and_where('key_id', '=', $key->id)->find();
             if (!$string->loaded()) {
                 $string = ORM::factory('langify_string');
                 $string->language_id = $language->id;
                 $string->key_id = $key->id;
                 $string->string = $v;
                 $string->save();
             }
         }
     }
 }
Exemplo n.º 18
0
<h1>I18n Dump</h1>

<?php 
foreach ($i18n as $path => $name) {
    echo "<h3>{$path}</h3>";
    try {
        echo Debug::vars(I18n::load($name));
    } catch (exception $e) {
        echo "Something went terribly wrong. Error message: " . Kohana::exception_text($e);
    }
}
Exemplo n.º 19
0
    function mailbox($param)
    {
        $this->layout_name = "admin";
        $this->data['options'] = array("all_mails", "inbox", "sent_mail", "trash", "compose", "msg");
        $this->data['display'] = array("All mails", "Inbox", "Sent mail", "Trash", "Compose", "Message");
        $this->data['request'] = $param[0];
        $this->data['send_to'] = $param;
        $db = $this->di['db']->sql(DB_DEFAULT);
        $user = $this->di['auth']->getUser();
        if (!in_array($param[0], $this->data['options'])) {
            exit;
        }
        $sql = "SELECT * FROM user_main a\r\n\t\tINNER JOIN geolocalisation_country b ON a.id_geolocalisation_country = b.id\r\n\t\tINNER JOIN geolocalisation_city c ON a.id_geolocalisation_city = c.id\r\n\t\t\r\nwhere a.id ='" . $db->sql_real_escape_string($user->id) . "'";
        $res = $db->sql_query($sql);
        $dfgwdfwdf = $db->sql_to_array($res);
        $this->data['user'] = $dfgwdfwdf[0];
        $i = 0;
        foreach ($this->data['options'] as $line) {
            if ($line === $this->data['request']) {
                $this->title = __($this->data['display'][$i]);
                $this->ariane = "> <a href=\"" . LINK . "user/\">" . __("Members") . "</a> > " . '<a href="' . LINK . 'user/profil/' . $user->id . '">' . $user->firstname . ' ' . $user->name . '</a>' . ' > ';
                $this->data['request'] != "all_mails" ? $this->ariane .= '<a href="' . LINK . 'user/mailbox/all_mails">' . __('Mailbox') . '</a>' : ($this->ariane .= __('Mailbox'));
                $this->data['request'] != "all_mails" ? $this->ariane .= ' > ' . $this->title : "";
                break;
            }
            $i++;
        }
        switch ($this->data['request']) {
            case "compose":
                if ($_SERVER['REQUEST_METHOD'] == "POST") {
                    if (!empty($_POST['mailbox_main']['id_user_main__to'])) {
                        $data = array();
                        $data['mailbox_main'] = $_POST['mailbox_main'];
                        $data['mailbox_main']['date'] = date('c');
                        $data['mailbox_main']['id_user_main__box'] = $user->id;
                        $data['mailbox_main']['id_user_main__from'] = $user->id;
                        $data['mailbox_main']['id_mailbox_etat'] = 2;
                        $data['mailbox_main']['id_history_etat'] = 1;
                        if ($db->sql_save($data)) {
                            $data['mailbox_main']['id_user_main__box'] = $_POST['mailbox_main']['id_user_main__to'];
                            if ($db->sql_save($data)) {
                                //send mail
                                I18n::SetDefault("en");
                                I18n::load("en");
                                $sql = "SELECT * FROM user_main WHERE id=" . $user->id;
                                $res = $db->sql_query($sql);
                                $ob = $db->sql_fetch_object($res);
                                $sql = "SELECT * FROM user_main WHERE id=" . $_POST['mailbox_main']['id_user_main__to'];
                                $res = $db->sql_query($sql);
                                $ob2 = $db->sql_fetch_object($res);
                                //send mail here
                                $subject = "[" . SITE_NAME . "] " . html_entity_decode($data['mailbox_main']['title'], ENT_COMPAT, 'UTF-8');
                                $msg = __('Hello') . ' ' . $ob2->firstname . ' ' . $ob2->name . ',<br />' . '<br /><br />' . '<a href="' . 'http://' . $_SERVER['SERVER_NAME'] . '/en/' . 'user/profil/inbox/' . $user->id . '">' . $ob->firstname . ' ' . $ob->name . '</a> sent you a message on Estrildidae.net.' . '<br /><br />' . '<b>Objet : ' . $data['mailbox_main']['title'] . '</b>' . '<br />' . '<b>Date : ' . date("F j, Y, H:i:s") . " CET</b>" . '<br /><br /><a href="' . 'http://' . $_SERVER['SERVER_NAME'] . '/en/' . 'user/mailbox/inbox/"><b>' . __('Click here to view the message') . '</b></a> ' . '<br /><br />' . __('You do not want to receive e-mails from Estrildidae member? Change notification settings for your account. Click here to report abuse.
Your use of Estrildidae is subject to the terms of use and privacy policy of Estrildidae! and the rules of the Estrildidae community.');
                                $headers = 'MIME-Version: 1.0' . "\r\n";
                                $headers .= 'Content-type: text/html; charset=utf-8' . "\r\n";
                                // En-tetes additionnels
                                $headers .= 'To: ' . $ob2->firstname . ' ' . $ob2->name . ' <' . $ob2->email . '>' . "\r\n";
                                $headers .= 'From: ' . $ob->firstname . ' ' . $ob->name . ' via Estrildidae.net (no-reply)<*****@*****.**>' . "\r\n";
                                $msg = I18n::getTranslation($msg);
                                mail($ob2->email, $subject, $msg, $headers) or die("error mail");
                                //end mail
                                I18n::SetDefault("en");
                                $msg = I18n::getTranslation(__("Your message has been sent."));
                                $title = I18n::getTranslation(__("Success"));
                                set_flash("success", $title, $msg);
                                header("location: " . LINK . "user/mailbox/inbox/");
                                exit;
                            } else {
                                die("Problem insertion boite 2");
                            }
                        } else {
                            die("Problem insertion boite 1");
                        }
                    }
                }
                $this->javascript = array("jquery.1.3.2.js", "jquery.autocomplete.min.js");
                $this->di['js']->code_javascript[] = '$("#mailbox_main-id_user_main__to-auto").autocomplete("' . LINK . 'user/user_main/", {
					
					mustMatch: true,
					autoFill: false,
					max: 100,
					scrollHeight: 302,
					delay:1
					});
					$("#mailbox_main-id_user_main__to-auto").result(function(event, data, formatted) {
						if (data)
							$("#mailbox_main-id_user_main__to").val(data[1]);
					});


					';
                break;
            case 'inbox':
                $sql = "SELECT a.id,a.title,a.date,id_mailbox_etat,\r\n\t\t\t\t\tb.id as to_id, b.firstname as to_firstname, b.name as to_name, x.iso as to_iso,\r\n\t\t\t\t\tc.id as from_id, c.firstname as from_firstname, c.name as from_name, y.iso as from_iso\r\n\t\t\t\t\tFROM mailbox_main a\r\n\t\t\t\t\tINNER JOIN user_main b ON a.id_user_main__to = b.id\r\n\t\t\t\t\tINNER JOIN geolocalisation_country x on b.id_geolocalisation_country = x.id\r\n\t\t\t\t\tINNER JOIN user_main c ON a.id_user_main__from = c.id\r\n\t\t\t\t\tINNER JOIN geolocalisation_country y on c.id_geolocalisation_country = y.id\r\n\t\t\t\t\t\r\n\t\t\t\t\t\tWHERE id_user_main__box = '" . $user->id . "'\r\n\t\t\t\t\t\tAND id_user_main__to = '" . $user->id . "'\r\n\t\t\t\t\t\t\tAND id_history_etat = 1\r\n\t\t\t\t\t\t\tORDER BY date DESC";
                $res = $db->sql_query($sql);
                $this->data['mail'] = $db->sql_to_array($res);
                break;
            case 'sent_mail':
                $sql = "SELECT a.id,a.title,a.date,id_mailbox_etat,\r\n\t\t\t\t\tb.id as to_id, b.firstname as to_firstname, b.name as to_name, x.iso as to_iso,\r\n\t\t\t\t\tc.id as from_id, c.firstname as from_firstname, c.name as from_name, y.iso as from_iso\r\n\t\t\t\t\tFROM mailbox_main a\r\n\t\t\t\t\tINNER JOIN user_main b ON a.id_user_main__to = b.id\r\n\t\t\t\t\tINNER JOIN geolocalisation_country x on b.id_geolocalisation_country = x.id\r\n\t\t\t\t\tINNER JOIN user_main c ON a.id_user_main__from = c.id\r\n\t\t\t\t\tINNER JOIN geolocalisation_country y on c.id_geolocalisation_country = y.id\r\n\t\t\t\t\t\tWHERE id_user_main__box = '" . $user->id . "'\r\n\t\t\t\t\t\tAND id_user_main__from = '" . $user->id . "'\r\n\t\t\t\t\t\t\tAND id_history_etat = 1\r\n\t\t\t\t\t\t\tORDER BY date DESC";
                $res = $db->sql_query($sql);
                $this->data['mail'] = $db->sql_to_array($res);
                break;
            case 'all_mails':
                $sql = "SELECT a.id,a.title,a.date,id_mailbox_etat,\r\n\t\t\t\t\tb.id as to_id, b.firstname as to_firstname, b.name as to_name, x.iso as to_iso,\r\n\t\t\t\t\tc.id as from_id, c.firstname as from_firstname, c.name as from_name, y.iso as from_iso\r\n\t\t\t\t\tFROM mailbox_main a\r\n\t\t\t\t\tINNER JOIN user_main b ON a.id_user_main__to = b.id\r\n\t\t\t\t\tINNER JOIN geolocalisation_country x on b.id_geolocalisation_country = x.id\r\n\t\t\t\t\tINNER JOIN user_main c ON a.id_user_main__from = c.id\r\n\t\t\t\t\tINNER JOIN geolocalisation_country y on c.id_geolocalisation_country = y.id\r\n\t\t\t\t\t\r\n\t\t\t\t\t\tWHERE id_user_main__box = '" . $user->id . "'\r\n\t\t\t\t\t\t\tAND id_history_etat = 1\r\n\t\t\t\t\t\t\tORDER BY date DESC";
                $res = $db->sql_query($sql);
                $this->data['mail'] = $db->sql_to_array($res);
                break;
            case 'trash':
                $sql = "SELECT a.id,a.title,a.date,id_mailbox_etat,\r\n\t\t\t\t\tb.id as to_id, b.firstname as to_firstname, b.name as to_name, x.iso as to_iso,\r\n\t\t\t\t\tc.id as from_id, c.firstname as from_firstname, c.name as from_name, y.iso as from_iso\r\n\t\t\t\t\tFROM mailbox_main a\r\n\t\t\t\t\tINNER JOIN user_main b ON a.id_user_main__to = b.id\r\n\t\t\t\t\tINNER JOIN geolocalisation_country x on b.id_geolocalisation_country = x.id\r\n\t\t\t\t\tINNER JOIN user_main c ON a.id_user_main__from = c.id\r\n\t\t\t\t\tINNER JOIN geolocalisation_country y on c.id_geolocalisation_country = y.id\r\n\t\t\t\t\t\tWHERE id_user_main__box = '" . $user->id . "'\r\n\t\t\t\t\t\t\tAND id_history_etat = 3\r\n\t\t\t\t\t\t\tORDER BY date DESC";
                $res = $db->sql_query($sql);
                $this->data['mail'] = $db->sql_to_array($res);
                break;
            case 'msg':
                $sql = "SELECT a.id,a.title,a.date,a.text as msg,id_mailbox_etat,id_user_main__from,id_user_main__to,\r\n\t\t\t\t\tb.id as to_id, b.firstname as to_firstname, b.name as to_name, x.iso as to_iso,\r\n\t\t\t\t\tc.id as from_id, c.firstname as from_firstname, c.name as from_name, y.iso as from_iso\r\n\t\t\t\t\tFROM mailbox_main a\r\n\t\t\t\t\tINNER JOIN user_main b ON a.id_user_main__to = b.id\r\n\t\t\t\t\tINNER JOIN geolocalisation_country x on b.id_geolocalisation_country = x.id\r\n\t\t\t\t\tINNER JOIN user_main c ON a.id_user_main__from = c.id\r\n\t\t\t\t\tINNER JOIN geolocalisation_country y on c.id_geolocalisation_country = y.id\r\n\t\t\t\t\t\r\n\t\t\t\t\t\tWHERE a.id = '" . $db->sql_real_escape_string($param[1]) . "' \r\n\t\t\t\t\t\tAND id_user_main__box = '" . $user->id . "'\r\n\t\t\t\t\t\t\t\r\n\t\t\t\t\t\t\tAND id_history_etat = 1\r\n\t\t\t\t\t\t\tORDER BY date DESC";
                $res = $db->sql_query($sql);
                $this->data['mail'] = $db->sql_to_array($res);
                if ($this->data['mail'][0]['id_mailbox_etat'] == 2 && $user->id != $this->data['mail'][0]['id_user_main__from']) {
                    $sql = "UPDATE mailbox_main SET id_mailbox_etat = 1, `read`=now()\r\n\t\t\t\t\t\tWHERE id_user_main__from = '" . $this->data['mail'][0]['id_user_main__from'] . "'\r\n\t\t\t\t\t\tAND id_user_main__to = '" . $this->data['mail'][0]['id_user_main__to'] . "'\r\n\t\t\t\t\t\tAND date = '" . $this->data['mail'][0]['date'] . "'";
                    $db->sql_query($sql);
                }
                break;
            case 'delete':
                $del = array();
                /*
                 foreach ()
                 {
                
                 }
                 $sql = "
                */
                break;
        }
        $this->set("data", $this->data);
    }
Exemplo n.º 20
0
 public function testLoadDirectory()
 {
     I18n::set(__DIR__ . '/../dir/');
     I18n::load('en_CA');
     $this->assertEquals('More Testing!', I18n::get('test.testing'));
 }
Exemplo n.º 21
0
 public function action_generate()
 {
     // Restrict to cli mode
     if (!Kohana::$is_cli) {
         echo "<pre>\nUsage: php index.php --uri=\"i18nget/generate\" or\n";
         echo "       php index.php --uri=\"i18nget/generate_for/mymodule\" or\n";
         echo "       php index.php --uri=\"i18nget/generate_for/mymodule/application\"\n</pre>";
         return;
     }
     $user_paths = array($this->request->param('from_path', 'application'));
     $user_paths[] = $this->request->param('to_path', $user_paths[0]);
     //if we should check all i18n files in the projetcs or just module files
     $global_i18n = $user_paths[1] == 'application';
     foreach ($user_paths as $idx => $path_to_check) {
         //application?
         if ($path_to_check == 'application') {
             $user_paths[$idx] = APPPATH;
             continue;
         }
         //module?
         $modules = array_slice(scandir(MODPATH), 2);
         if (!in_array($path_to_check, $modules)) {
             die("Your given option '{$path_to_check}' must either match 'application'" . " or one of the module names:\n  " . join("\n  ", $modules));
         } else {
             $user_paths[$idx] = MODPATH . $path_to_check;
         }
     }
     $this->auto_render = FALSE;
     $path = $user_paths[0];
     $output_path = rtrim($user_paths[1], DIRECTORY_SEPARATOR) . DIRECTORY_SEPARATOR;
     echo "\nGenerating files for \n'{$path}'\ninto\n'{$output_path}i18n'\n\n";
     $data = array();
     $unique_phrases_helper = array();
     $scan_files = $this->get_dir_files($path, array('php'));
     //echo Debug::dump($this->request, 9999);
     //print_r(Request::$current->uri());
     //print_r($user_paths);
     //print_r($scan_files); return;
     foreach ($scan_files as $file) {
         $file_path_human = substr($file, strlen($path));
         // 			echo Debug::dump($file_path_human, 9999);
         // Get each line of the file
         $file_lines = file($file, FILE_IGNORE_NEW_LINES);
         $data_file = array();
         foreach ($file_lines as $num_line => $file_line) {
             $num_line++;
             // 				echo Kohana::debug($num_line, $file_line, $file_path_human);
             // 				if (preg_match_all('/(?P<key>\w+):(?P<name>[\p{L}+|\D+])/u', $file_line, $matches))
             // 				if (preg_match('/^(?P<name>.*?[^(TO|COPYTO)]+)( TO (?P<assignedto>\w[^(COPYTO)]+))?( COPYTO (?P<copyto>\w[^(TO)]+))?$/u', trim($email['Subject']), $matches))
             // 				if (preg_match_all('/__\(\'(?P<phrase>.+)\'(, ?array\(.+\))?\)/u', $file_line, $matches))
             // 				if (preg_match_all('/__\(\'(?P<phrase>.*)(, ?array\(.+\))?\'\)/u', $file_line, $matches))
             // 				if (preg_match_all("/__\('(?P<phrase>.*?[^;])'\)/u", $file_line, $matches))
             // 				if (preg_match_all("/__\([^'.+'$]\)/u", $file_line, $matches))
             // 				if (preg_match_all("/__\([^_]+\)/u", $file_line, $matches))
             // 				if (preg_match_all("/__\([^\b__]+\)/u", $file_line, $matches))
             // 				if (preg_match_all("/__\((?P<phrase>((?!__).)+)\)/u", $file_line, $matches)) /// NOTE IT WORKS!!!
             // 				if (preg_match_all("/__\((?P<phrase>((?!__)|(?!array).)+)\)/u", $file_line, $matches))
             // 				if (preg_match_all("/__\(('|\")(?P<phrase>((?!__)|(?! ?array ?\().)+)('|\")/u", $file_line, $matches)) /// NOTE IT WORKS!!!
             if (preg_match_all("/__\\(('|\")(?P<phrase>((?!__)|(?! ?array ?\\().)+)('\\)|',|\"\\)|\",)/u", $file_line, $matches)) {
                 // 					echo Kohana::debug($file_path_human, $num_line, $file_line, $matches);
                 // 					echo Kohana::debug($file_path_human, $num_line, $file_line, $matches['phrase']);
                 // 					echo Kohana::debug($matches['phrase']);
                 $new_phrases = array_diff(array_unique($matches['phrase']), $unique_phrases_helper);
                 if ($new_phrases) {
                     $data_file[] = array('line_number' => $num_line, 'line_string' => $file_line, 'phrases' => $new_phrases);
                     $unique_phrases_helper = array_merge($new_phrases, $unique_phrases_helper);
                 }
             }
         }
         if ($data_file) {
             $data[] = array('filepath' => $file, 'filepath_human' => $file_path_human, 'lines' => $data_file);
         }
         /* if( strpos($file, 'format')!==False )
            {
                print_r($data_file);
                die('found');
            } */
     }
     //echo Debug::dump($data, 9999);
     $languages = Kohana::$config->load('i18nget.languages');
     $default_language = Kohana::$config->load('i18nget.default');
     $orphe_phrases = array();
     // Fix phrases
     foreach ($unique_phrases_helper as $key => $phrase) {
         $unique_phrases_helper[$key] = str_replace('\\\'', '\'', $unique_phrases_helper[$key]);
         $unique_phrases_helper[$key] = str_replace('\\"', '"', $unique_phrases_helper[$key]);
     }
     // Add phrases present in current i18n language files but are not present in current code
     foreach ($languages as $language_code => $language) {
         if ($global_i18n) {
             //only if we write to application we want to look at kohana's complete CFS for i18n files.
             $i18n_messages = array_keys(I18n::load($language_code));
         } else {
             //if we output in an i18n folder of a module, we are only interested in that modules current translations
             $lang_file = $this->lang_file_path($output_path, $language_code);
             if (file_exists($lang_file)) {
                 $i18n_messages = array_keys(Kohana::load($lang_file));
             } else {
                 $i18n_messages = array();
             }
         }
         $orphe_phrases = array_merge($orphe_phrases, array_diff($i18n_messages, $unique_phrases_helper));
     }
     $orphe_phrases = array_unique($orphe_phrases);
     //print_r($unique_phrases_helper);
     //print_r($i18n_messages);
     //print_r($orphe_phrases); //die();
     // Generate new i18n files
     foreach ($languages as $language_code => $language) {
         if ($default_language !== $language_code) {
             $filename = $this->lang_file_path($output_path, $language_code);
             //construct content before renaming original file
             $content = View::factory('i18nget/generate')->set(array('data' => $data, 'orphe_phrases' => $orphe_phrases, 'language_code' => $language_code, 'filename' => $filename, 'global_i18n' => $global_i18n))->render();
             //print_r($content);
             if (file_exists($filename) and Kohana::$config->load('i18nget.should_make_backups')) {
                 rename($filename, $backup_name = $filename . '.old_' . time());
                 echo "Backup file: " . substr($backup_name, strlen(DOCROOT)) . "\n";
             }
             if (FALSE === file_put_contents($filename, $content)) {
                 echo "There's an error writing the file: " . substr($filename, strlen(DOCROOT)) . "\n\n";
             } else {
                 echo "File written: " . substr($filename, strlen(DOCROOT)) . "\n\n";
             }
         }
     }
     // Fix permissions
     // 		system('chown marcalj:marcalj '.APPPATH.'logs/i18n/*');
     echo "Done!\n";
 }