Ejemplo n.º 1
0
 public function invoke(Validate $array, $field)
 {
     $value = $array[$field];
     if (!is_array($value)) {
         return TRUE;
     }
     $cache = Cache::instance();
     $surfix = Kohana::config('torn')->surfix->temp;
     $cached = $this->model->get($field . $surfix);
     $current = $this->model->get($field, FALSE);
     $used_cached = FALSE;
     $empty_check = FALSE;
     if (!Upload::not_empty($value) and empty($cached) and !empty($current)) {
         $this->model->set($field, $current);
         $array[$field] = $current;
         return TRUE;
     }
     if (!Upload::not_empty($value) and preg_match('/^[a-z0-9]{32}-[a-z0-9]{32}$/iD', $cached)) {
         $value = Arr::get($cache->get($cached), 'upload', $value);
         $used_cached = TRUE;
     }
     $modified_rules = $this->rules;
     foreach ($this->rules as $rule => $params) {
         if (!utf8::strcasecmp($rule, 'Upload::not_empty')) {
             unset($modified_rules[$rule]);
             $modified_rules['Torn_Uploader::not_empty'] = NULL;
             break;
         }
     }
     $validate = Validate::factory(array($field => $value))->filters($field, $this->filters)->rules($field, $modified_rules)->callbacks($field, $this->callbacks);
     if (!$validate->check()) {
         foreach ($validate->errors() as $v) {
             list($error, $params) = $v;
             $array->error($field, $error, $params);
         }
         return FALSE;
     }
     $validate = $array->as_array();
     $value = $validate[$field];
     if ($tmp_name = Torn_Uploader::upload_to_cache($value, $field) and !$used_cached) {
         $array[$field] = $tmp_name;
     } else {
         $array[$field] = Arr::get($_POST, $field . $surfix, $value);
     }
     $this->model->set($field, $array[$field]);
     return TRUE;
 }
Ejemplo n.º 2
0
 public function translate()
 {
     // Get URI vars
     $plugin = uri::segment(5);
     $language = uri::segment(6);
     // Get plugin
     if (!config::item('plugins', 'core', $plugin)) {
         view::setError(__('no_plugin', 'system_plugins'));
         router::redirect('cp/system/languages/plugins/' . $language);
     }
     // Is this a system language?
     if ($language == 'system') {
         $language = array('keyword' => 'system', 'name' => 'System');
     } elseif (!($language = $this->languages_model->getLanguage($language))) {
         view::setError(__('no_language', 'system_languages'));
         router::redirect('cp/system/languages');
     }
     // Get default language data
     if (!($default = $this->languages_model->getLanguageData('system', $plugin))) {
         view::setError(__('no_language', 'system_languages'));
         router::redirect('cp/system/languages');
     }
     // Get language data
     if (!($data = $this->languages_model->getLanguageData($language['keyword'], $plugin, true))) {
         view::setError(__('no_language', 'system_languages'));
         router::redirect('cp/system/languages');
     }
     // Set language sections
     $sections = array();
     foreach ($data as $section => $groups) {
         foreach ($groups as $group => $types) {
             $translated = $total = 0;
             foreach ($types as $type => $items) {
                 foreach ($items as $index => $value) {
                     if (utf8::strcasecmp($default[$section][$group][$type][$index], $value)) {
                         $translated++;
                     }
                     $total++;
                 }
             }
             $translated = $translated ? round($translated / $total * 100) : 0;
             $translated = $translated > 100 ? 100 : $translated;
             if (__('language_' . $group, $plugin . '_config') !== false) {
                 $name = __('language_' . $group, $plugin . '_config');
             } elseif (__('language_' . $group, 'users_config') !== false) {
                 $name = __('language_' . $group, 'users_config');
             } elseif (__('language_' . $group, 'system_config') !== false) {
                 $name = __('language_' . $group, 'system_config');
             } elseif ($section == $group) {
                 $name = __('language_system', 'system_config');
             } else {
                 $name = '!' . $group;
             }
             $sections[$section . '_' . $group] = '[' . config::item('plugins', 'core', $section, 'name') . '] ' . $name . ($language['keyword'] != 'english' ? ' - ' . $translated . '%' : '') . (config::item('devmode', 'system') == 2 ? ' [' . $group . ']' : '');
         }
     }
     asort($sections);
     // Assign vars
     view::assign(array('plugin' => $plugin, 'default' => $default, 'sections' => $sections, 'language' => $data));
     // Process form values
     if (input::post('do_save_language')) {
         $this->_saveLanguageData($plugin, $language['keyword'], $default);
     }
     // Set title
     view::setTitle(__('language_translate', 'system_languages'));
     // Set trail
     view::setTrail('cp/system/languages/plugins/' . $language['keyword'], __('language_translate', 'system_languages') . ' - ' . text_helper::entities($language['name']));
     view::setTrail('cp/system/languages/translate/' . $plugin . '/' . $language['keyword'], text_helper::entities(config::item('plugins', 'core', $plugin, 'name')));
     // Load view
     view::load('cp/system/languages/translate');
 }
Ejemplo n.º 3
0
 /**
  * Tests the tutf8::strcasecmp() function.
  * @dataProvider strcasecmp_provider
  * @group core.helpers.utf8.strcasecmp
  * @test
  */
 public function strcasecmp($str, $str2, $expected_result)
 {
     $result = utf8::strcasecmp($str, $str2);
     $this->assertEquals($expected_result, $result);
 }
Ejemplo n.º 4
0
_<?php 
                echo $keyword;
                ?>
">
									<?php 
                echo isset($default[$section][$group][$type][$keyword]) ? $default[$section][$group][$type][$keyword] : "!{$section}-{$group}-{$keyword}!";
                ?>
								</label>
								<div class="field" <?php 
                echo config::item('devmode', 'system') == 2 ? 'style="position:relative"' : '';
                ?>
>

									<div class="input-wrap">
										<?php 
                echo form_helper::text($group . '_' . $keyword, form_helper::setValue($group . '_' . $keyword, isset($value) ? $value : ''), array('class' => 'text input-wide ' . (uri::segment(6) == 'english' || isset($default[$section][$group][$type][$keyword]) && utf8::strcasecmp($default[$section][$group][$type][$keyword], $value) ? 'translated' : 'untranslated'), 'id' => 'input_edit_' . $group . '_' . $keyword));
                ?>
										<?php 
                if (config::item('devmode', 'system') == 2) {
                    ?>
											<?php 
                    echo form_helper::text($group . '_' . $keyword . '___key', $keyword, array('class' => 'text', 'style' => 'width:130px;position:absolute;right:-160px;top:0;'));
                    ?>
										<?php 
                }
                ?>
									</div>

									<?php 
                if (form_helper::error($group . '_' . $keyword)) {
                    ?>