Файл: adultscript-2.0.3-pro/files/admin/modules/language/components/files_install.php
Строк: 80
<?php
defined('_VALID') or die('Restricted Access!');
class VComponent_Admin_language_files_install extends VModule_Admin_language
{
public function __construct()
{
parent::__construct();
}
public function render()
{
$filter = VF::factory('filter');
$errors = array();
$messages = array();
$code = (isset($_GET['code'])) ? $filter->get('code', 'STRING', 'GET') : '';
$file = array(
'code' => '', 'name' => '', 'description' => '', 'type' => 'frontend'
);
if (isset($_POST['create-package'])) {
$code = $filter->get('code');
$type = $filter->get('type');
$name = $filter->get('name');
$description = $filter->get('description');
if ($code == '') {
$errors[] = 'Please select a language for this package!';
} else {
$file['code'] = $code;
}
if ($name == '') {
$errors[] = 'Please enter a name (SLUG) for this package!';
} elseif (!preg_match('/^[a-z0-9-]+$/', $name)) {
$errors[] = 'Package name (SLUG) can contain only letters, numbers and dashes!';
} else {
$this->db->query("SELECT file_id
FROM #__language_files
WHERE code = '".$this->db->escape($code)."'
AND name = '".$this->db->escape($name)."'
AND type = '".$this->db->escape($type)."'
LIMIT 1");
if ($this->db->affected_rows()) {
$errors[] = 'Package name is already used for another package (same code and type)!';
} else {
$file['name'] = $name;
}
}
if ($description == '') {
$errors[] = 'Please enter a description for this package!';
} else {
$file['description'] = $description;
}
$file['type'] = $type;
if (!$errors) {
$this->db->query("INSERT INTO #__language_files
SET code = '".$this->db->escape($code)."',
type = '".$this->db->escape($type)."',
name = '".$this->db->escape($name)."',
description = '".$this->db->escape($description)."',
file = ''");
$messages[] = 'Language file created!';
}
}
$tpl = VF::factory('template');
$tpl->menu = 'main';
$tpl->submenu = 'extend';
$tpl->extramenu = 'language_install';
$tpl->meta_title = 'Admin::Language::Install';
$tpl->errors = $errors;
$tpl->messages = $messages;
$tpl->code = $code;
$tpl->codes = $this->get_language_codes();
$tpl->file = $file;
$tpl->load(array('header', 'language_files_install', 'footer'));
$tpl->display();
}
private function get_language_codes()
{
$this->db->query("SELECT code, name FROM #__language ORDER BY name ASC");
if ($this->db->affected_rows()) {
return $this->db->fetch_rows();
}
throw new VException('Failed to load languages!');
}
}