Вход Регистрация
Файл: adultscript-2.0.3-pro/files/admin/modules/language/components/install.php
Строк: 143
<?php
defined
('_VALID') or die('Restricted Access!');
class 
VComponent_Admin_language_install extends VModule_Admin_language
{
    public function 
__construct()
    {
    }
    
    public function 
render()
    {
        
$db         VF::factory('database');
        
$errors        = array();
        
$messages    = array();
        
$method        'clone';
        
$lang        = array('code' => '''name' => '''flag' => '''status' => 1'clone' => '');
        
$languages    $db->get_rows("SELECT code, name FROM #__language ORDER BY name ASC");
    
        if (isset(
$_POST['submit-install'])) {
            
$filter            VF::factory('filter');
            
$method            $filter->get('method');
            
            if (
$method == 'clone') {
                
$clone        $filter->get('clone');
                
$code        $filter->get('code');
                
$name        $filter->get('name');
                
$flag        $filter->get('flag');
                
$status        = (int) trim($_POST['status']);
                
                if (
$name == '') {
                    
$errors[]    = 'Language name field cannot be left blank!';
                } else {
                    
$lang['name']     = $name;
                }
                
                if (
$code == '') {
                    
$errors[]    = 'Language code field cannot be left blank!';
                } else {
                    
$lang['code']    = $code;
                }
                
                if (
$flag == '') {
                    
$errors[]     = 'Language flag field cannot be left blank!';
                } else {
                    
$lang['flag']    = $flag;
                }
                
                if (!
$errors) {
                    if (
$clone == '') {
                        
$errors[]    = 'Language clone cannot be left blank!';
                    } elseif (
$clone == $code) {
                        
$errors[]    = 'Language clone code cannot be the same as the new language code!';
                    } else {
                        
$db->query("SELECT name, description, type, file
                                    FROM #__language_files
                                    WHERE code = '"
.$db->escape($clone)."'");
                        if (
$db->affected_rows()) {
                            
$files $db->fetch_rows();
                        } else {
                            
$errors[]    = 'Invalid language clone code! What exactly did you select!?';
                        }
                    }
                    
                    if (!
$errors) {
                        
$db->query("INSERT INTO #__language
                                    SET code = '"
.$db->escape($code)."',
                                        name = '"
.$db->escape($name)."',
                                        flag = '"
.$db->escape($flag)."',
                                        status = '"
.$status."'");
                        if (
$db->affected_rows()) {
                            foreach (
$files as $file) {
                                
$db->query("INSERT INTO #__language_files
                                            SET code = '"
.$db->escape($code)."',
                                                name = '"
.$db->escape($file['name'])."',
                                                description = '"
.$db->escape($file['description'])."',
                                                type = '"
.$db->escape($file['type'])."',
                                                file = '"
.$db->escape($file['file'])."'");
                                
VF::cache_set($code.'.'.$file['type'].'.'.$file['name'],unserialize($file['file']), 'language'FALSE);
                            }
                            
                            
VF::cache_del('languages''config');
                            
                            
$messages[] = 'Language installed!';
                        } else {
                            throw new 
VException('Application Errror! Aborting...');
                        }
                    }
                }
            } elseif (
$method == 'xml') {
                if (!
$file VUpload::process('file_xml', (1024*1024*10), array('xml'))) {
                    
$errors array_merge($errorsVUpload::error());
                }
                
                if (!
$errors) {
                    
$filename    VText::random().'.xml';
                    
$dst         TMP_DIR.'/uploads/'.$filename;
                    if (
move_uploaded_file($file['path'], $dst)) {
                        
libxml_use_internal_errors(true);
                        
$xml    simplexml_load_file($dst);
                        if (!
$xml) {
                            foreach (
libxml_get_errors() as $error) {
                                
$errors[] = 'XML Error: '.$error->message;
                            }
                        }
                        
                        if (!isset(
$xml->name) OR
                            !isset(
$xml->code) OR
                            !isset(
$xml->flag) OR
                            !isset(
$xml->files)) {
                            
$errors[] = 'Invalid XML! Are you sure this XML is a language pack for Adult Script Pro?';
                        }

                        if (!
$errors) {                                                                            
                            
$db->query("SELECT code
                                          FROM #__language
                                          WHERE code = '"
.$db->escape($xml->code)."'
                                          LIMIT 1"
);
                            if (!
$db->affected_rows()) {
                                
$code    $xml->code;
                            
                                
$db->query("INSERT INTO #__language
                                            SET code = '"
.$db->escape($code)."',
                                                name = '"
.$db->escape($xml->name)."',
                                                flag = '"
.$db->escape($xml->flag)."',
                                                status = '1'"
);
                                if (
$db->affected_rows()) {
                                    foreach (
$xml->files->file as $file) {
                                        
$translation = array();
                                        foreach (
$file->translation->string as $simple) {
                                            
$key                = (string) $simple->attributes()->key;
                                            
$value                = (string) $simple->attributes()->value;
                                            
$translation[$key]     = str_replace("'"'&#039;'$value);
                                        }
                                        
                                        
$db->query("INSERT INTO #__language_files
                                                    SET code = '"
.$db->escape($code)."',
                                                        name = '"
.$db->escape($file->name)."',
                                                        description = '"
.$db->escape($file->description)."',
                                                        type = '"
.$db->escape($file->type)."',
                                                        file = '"
.$db->escape(serialize($translation))."'");
                                                    
                                    }
                                    
                                    
VFile::delete($dst);
                                    
VF::cache_del('languages''config');
                                    
                                    
$messages[] = 'Language pack imported!';
                                } else {
                                    
$errors[] = 'Failed to create language database entry (invalid XML)!?';
                                }
                            } else {
                                
$errors[] = 'Language '.$xml->code.' is already installed!';
                            }
                        }
                    } else {
                        
$errors[] = 'Failed to move uploaded file!';
                    }
                }
            } else {
                
$errors[]     = 'Invalid language install method! What exactly did you select!?';
            }
        }
    
        
$tpl    VF::factory('template');
        
$tpl->menu            'main';
        
$tpl->submenu        'extend';
        
$tpl->extramenu        'language_install';
        
$tpl->meta_title    'Language::Install';
        
$tpl->errors        $errors;
        
$tpl->messages        $messages;
        
$tpl->method        $method;
        
$tpl->lang            $lang;
        
$tpl->languages        $languages;
        
$tpl->load(array('header''language_install''footer'));
        
$tpl->display();
    }
}
Онлайн: 1
Реклама