WiP fixation

This commit is contained in:
Alexander Yakovlev 2013-04-17 09:00:16 +07:00
parent e6eb849de0
commit 003757285e
16 changed files with 577 additions and 4 deletions

View File

@ -0,0 +1,17 @@
<?php defined('SYSPATH') or die('No direct script access.');
class Controller_Games extends Controller_Template {
public $template = 'games/add';
public function action_add() {
//$this->template = 'games/add';
if ($_POST){
$user = ORM::factory('user');
if (Auth::instance()->login('author')){
$game = ORM::factory('game');
$game->values($this->request->post());
$game->create();
}
else $this->template->error = "Недостаточно прав для добавления игры. Обратитесь за помощью к администратору сервиса.";
}
}
}

View File

@ -1,9 +1,9 @@
<?php defined('SYSPATH') OR die('No direct access allowed.');
class Model_User extends Model_Auth_User {
protected $_rules = array(
'username' => array(
'display_name' => array(
'not_empty' => NULL,
'min_length' => array(4),
'min_length' => array(2),
'max_length' => array(32),
'regex' => array('/^[-\pL\pN_.]++$/uD')
),
@ -21,14 +21,14 @@ class Model_User extends Model_Auth_User {
);
protected $_callbacks = array(
'username' => array('username_available'),
'email' => array('email_available')
'display_name' => array('display_name_available')
);
public function validate_create(&$array){
$array = Validate::factory($array)
->filter(TRUE, 'trim')
->rules('username', $this->_rules['username'])
->rules('display_name', $this->_rules['display_name'])
->rules('password', $this->_rules['password'])
->rules('email', $this->_rules['email']);

View File

@ -0,0 +1,14 @@
<?php defined('SYSPATH') or die('No direct script access.');
class Model_Game extends ORM {
protected $_table_columns = array(
'id' => array('data_type' => 'int', 'is_nullable' => FALSE),
'name' => array('data_type' => 'string', 'is_nullable' => FALSE),
'description' => array('data_type' => 'mediumtext', 'is_nullable' => FALSE),
'file' => array('data_type' => 'file', 'is_nullable' => FALSE),
'group' => array('data_type' => 'int', 'is_nullable' => TRUE),
);
protected $has_many = array(
'author' => array('model'=>'user')
);
}

View File

@ -0,0 +1,12 @@
<?php defined('SYSPATH') or die('No direct script access.');
class Model_Rating extends ORM {
protected $_table_columns = array(
'id' => array('data_type' => 'int', 'is_nullable' => FALSE),
'value' => array('data_type' => 'int', 'is_nullable' => FALSE),
);
protected $has_many = array(
'author' => array('model'=>'user'),
'game' => array('model'=>'game'),
);
}

View File

@ -0,0 +1,13 @@
<?php echo Request::factory('header/standard')->post('title',"Добавить игру")->post('styles','main.css')->execute() ?>
<div id="error"><?php if(!empty($error)) echo $error;?></div>
<div id="message"><?php if(!empty($message)) echo $message;?></div>
<h2>Добавление игры</h2>
<?php echo form::open('games/add', array('enctype' => 'multipart/form-data')) ?>
<p><?php echo form::label('name','Название: '); echo form::input('name','') ?></p>
<p><?php echo form::label('description','Описание: '); echo form::input('description','') ?></p>
<p><?php echo form::label('file','Файл с игрой: '); echo form::file('file'); ?></p>
<p><?php echo form::submit('submit','Отправить') ?></p>
<?php echo form::close() ?>
<?php echo Request::factory('footer/standard')->execute() ?>

View File

@ -0,0 +1,17 @@
<?php echo Request::factory('header/standard')->post('title','Установка движка')->post('styles','main.css')->execute() ?>
<h1>Установка движка</h1>
<div id="message"><?php if(!empty($message)) echo $message;?></div>
<div id="error"><?php if(!empty($error)) echo $error;?></div>
<p>Внимание! При продолжении база данных будет переписана.</p>
<p>Предполагается, что база данных MySQL находится по адресу localhost и использует кодировку UTF-8. Вы можете поменять настройки в файле config/database.php.</p>
<?php echo form::open('install') ?>
<p><?php echo form::label('create','Создать базу данных'); echo form::checkbox('create','') ?></p>
<p><?php echo form::label('username','Имя пользователя администратора [admin]: '); echo form::input('username','admin') ?></p>
<p><?php echo form::label('password','Пароль администратора [password]: '); echo form::password('password','password') ?></p>
<p><?php echo form::label('password_confirm','Подтверждение пароля: '); echo form::password('password_confirm','password') ?></p>
<p><?php echo form::label('email','e-mail администратора: '); echo form::input('email','admin@example.com') ?></p>
<p><?php echo form::submit('submit','Отправить') ?>
<p></p>
</p>
<?php echo form::close() ?>
<?php echo Request::factory('footer/standard')->execute() ?>

View File

@ -0,0 +1,3 @@
<?php defined('SYSPATH') OR die('No direct access allowed.');
abstract class Editor extends Kohana_Editor { }

View File

@ -0,0 +1,3 @@
<?php defined('SYSPATH') or die('No direct script access.');
class Editor_Ckeditor extends Kohana_Editor_Ckeditor { }

View File

@ -0,0 +1,3 @@
<?php defined('SYSPATH') or die('No direct script access.');
class Editor_Markitup extends Kohana_Editor_Markitup { }

View File

@ -0,0 +1,3 @@
<?php defined('SYSPATH') or die('No direct script access.');
class Editor_Tinymce extends Kohana_Editor_Tinymce { }

View File

@ -0,0 +1,122 @@
<?php defined('SYSPATH') OR die('No direct access allowed.');
/**
* Class for providing most known Text Editors like Tiny_MCE and FCKeditor
*
* @package Editor
* @author Brotkin Ivan (BIakaVeron) <BIakaVeron@gmail.com>
* @copyright Copyright (c) 2009 Brotkin Ivan
*
*/
abstract class Kohana_Editor {
public static $default_driver = 'markitup';
public static $language = 'en';
public static function factory($name = 'default')
{
$config = Kohana::config('editor')->$name;
if ( ! isset($config['driver']) )
{
$config['driver'] = Editor::$default_driver;
}
$config['name'] = $name;
$driver = 'Editor_'.ucfirst($config['driver']);
$editor = new $driver($name, $config);
return $editor/*->init($config)*/;
}
protected $_styles = NULL;
protected $_scripts = NULL;
protected $_driver = FALSE;
protected $_name;
public $width = 500;
public $height = 200;
public $fieldname = 'text';
public $value = '';
/**
* Constructor
*
* @param mixed configuration array or profile name
* @return void
*/
public function __construct($name, $config = array())
{
$this->_driver = $driver = $config['driver'];
$this->_name = $name;
foreach($config as $field => $value)
{
if ( ! is_array($value))
{
$this->set($field, $value);
}
}
$config['params'] = Kohana::config('editor/'.$driver)->get($name, array());
if (isset($config['params']))
{
foreach($config['params'] as $key => $value)
{
$this->set($key, $value);
}
}
return $this;
}
public function set($field, $value)
{
if (in_array($field, array('width', 'height', 'fieldname', 'value')))
{
$this->$field = $value;
}
return $this;
}
public function css()
{
// no CSS in use
return array();
}
public function js()
{
// no JS in use
return array();
}
/**
* Display text redactor or returns redactor code
*
* @param bool outputs code directly if TRUE
* @param bool creates textarea field if TRUE
* @return mixed returns output code if $print==FALSE
*/
abstract public function render($print = TRUE, $create_field = TRUE);
public function __toString()
{
return $this->render(TRUE);
}
}

View File

@ -0,0 +1,90 @@
<?php defined('SYSPATH') OR die('No direct access allowed.');
/**
* @link http://ckeditor.com
*
* CKEditor driver library
*
* @package Editor
* @author Brotkin Ivan (BIakaVeron) <BIakaVeron@gmail.com>
* @copyright Copyright (c) 2009 Brotkin Ivan
*/
class Kohana_Editor_Ckeditor extends Editor
{
public static $path = 'media/ckeditor';
public static $scriptname = 'ckeditor.js';
public static $configfile = 'config.js';
public $skin = 'kama';
public $theme = 'default';
public $toolbar = 'Basic';
public function js()
{
return array(self::$path.'/'.self::$scriptname);
}
public function render($print = TRUE, $create_field = TRUE)
{
if ( FALSE === self::$language)
{
self::$language = substr(I18n::$lang, 0, 2);
}
$result = '';
if (TRUE == $create_field)
{
// Create textarea with some config values
$result.= form::textarea($this->fieldname, $this->value, array('width'=>$this->width, 'height'=>$this->height, 'id'=>$this->fieldname))."\r\n";
}
$result .= '<script type="text/javascript">
//<![CDATA[
CKEDITOR.replace( "'.$this->fieldname.'",
{
language: "'.self::$language.'",
skin : "'.$this->skin.'",
theme: "'.$this->theme.'",
toolbar: "'.ucfirst($this->toolbar).'",
width: "'.intval($this->width).'",
height: "'.intval($this->height).'",
customConfig: "'.url::base().self::$path.'/'.self::$configfile.'"
});
//]]>
</script>';
if ($print===TRUE)
{
// Echo code
echo $result;
}
// return generated code
return $result;
}
public function set($field, $value)
{
if (in_array($field, array('skin', 'theme', 'toolbar')))
{
$this->$field = $value;
}
elseif ($field == 'configfile')
{
self::$$field = $value;
}
else
{
return parent::set($field, $value);
}
return $this;
}
}

View File

@ -0,0 +1,101 @@
<?php defined('SYSPATH') OR die('No direct access allowed.');
/**
*
* @link http://markitup.jaysalvat.com
*
* MarkItUp! driver library
*
* @package Editor
* @author Brotkin Ivan (BIakaVeron) <BIakaVeron@gmail.com>
* @copyright Copyright (c) 2009 Brotkin Ivan
*/
class Kohana_Editor_Markitup extends Editor
{
public static $path = 'media/markitup';
public static $setspath = 'sets';
public static $skinspath = 'skins';
public static $scriptname = 'jquery.markitup.pack.js';
public static $jquerypath = 'media/jquery.pack.js';
public static $use_jquery = TRUE;
public $toolbarset = 'default';
public $skin = 'markitup';
public function css()
{
if (is_null($this->_styles))
{
$this->_styles = array
(
self::$path.'/'.self::$setspath.'/'.$this->toolbarset.'/style.css',
self::$path.'/'.self::$skinspath.'/'.$this->skin.'/style.css',
);
}
return $this->_styles;
}
public function js()
{
if (is_null($this->_scripts))
{
$this->_scripts = array();
if (self::$use_jquery)
{
$this->_scripts[] = self::$jquerypath;
}
$this->_scripts[] = self::$path.'/'.self::$scriptname;
$this->_scripts[] = self::$path.'/'.self::$setspath.'/'.$this->toolbarset.'/set.js';
}
return $this->_scripts;
}
public function render($print = TRUE, $create_field = TRUE)
{
$result = '';
if (TRUE == $create_field) {
// Create textarea with some config values
$result.= form::textarea($this->fieldname, $this->value, array('width'=>$this->width, 'height'=>$this->height, 'id'=>$this->fieldname))."\r\n";
}
// Init redactor object
// Array settings should be joined into a string
$result .= '<script language="javascript" type="text/javascript">
<!--
$(document).ready(function() {
// $("textarea").markItUp( { Settings }, { OptionalExtraSettings } );
$("#'.$this->fieldname.'").markItUp(mySettings);
});
-->
</script>';
if ($print===TRUE)
{
// Echo code
echo $result;
}
// return generated code
return $result;
}
public function set($field, $value)
{
if (in_array($field, array('toolbarset', 'skin')))
{
$this->$field = $value;
return $this;
}
return parent::set($field, $value);
}
}

View File

@ -0,0 +1,96 @@
<?php defined('SYSPATH') OR die('No direct access allowed.');
/**
*
* @link http://tinymce.moxiecode.com
*
* Tiny_MCE driver library
*
* @package Editor
* @author Brotkin Ivan (BIakaVeron) <BIakaVeron@gmail.com>
* @copyright Copyright (c) 2009 Brotkin Ivan
*/
class Kohana_Editor_Tinymce extends Editor {
public static $path = 'media/tinymce';
public static $scriptname = 'tiny_mce.js';
public $theme = 'advanced';
public $mode = 'exact';
public $toolbar = array
(
'location' => 'top',
'align' => 'left',
);
public $plugins = array();
public $buttons1 = array
(
'bold', 'italic', 'underline', 'strikethrough', '|',
'justifyleft', 'justifycenter', 'justifyright', 'justifyfull',
'bullist', 'numlist', 'outdent', 'indent'
);
public $buttons2 = array();
public $buttons3 = array();
public function css()
{
return array();
}
public function js()
{
return array(self::$path.'/'.self::$scriptname);
}
public function render($print = TRUE, $create_field = TRUE)
{
$result = '';
if (TRUE == $create_field)
{
// Create textarea with some config values
$result.= form::textarea($this->fieldname, $this->value, array('width'=>$this->width, 'height'=>$this->height, 'id'=>$this->fieldname))."\r\n";
}
// Init redactor object
// Array settings should be joined into a string
$result .= '<script language="javascript" type="text/javascript">
tinyMCE.init({
theme : "'.$this->theme.'",
mode: "'.$this->mode.'",
language: "'.self::$language.'",
elements : "'.$this->fieldname.'",
plugins : "'.implode(",", $this->plugins).'",
theme_advanced_toolbar_location : "'.$this->toolbar["location"].'",
theme_advanced_toolbar_align : "'.$this->toolbar["align"].'",
theme_advanced_buttons1 : "'.implode(",", $this->buttons1).'",
theme_advanced_buttons2 : "'.implode(",", $this->buttons2).'",
theme_advanced_buttons3 : "'.implode(",", $this->buttons3).'",
height:"'.$this->height.'px",
width:"'.$this->width.'px"
});
</script>';
if ($print===TRUE)
{
// Echo code
echo $result;
}
// return generated code
return $result;
}
public function set($field, $value)
{
if (in_array($field, array('plugins', 'mode', 'theme', 'toolbar', 'buttons1', 'buttons2', 'buttons3')))
{
$this->$field = $value;
return $this;
}
return parent::set($field, $value);
}
}

View File

@ -0,0 +1,46 @@
<?php defined('SYSPATH') OR die('No direct access allowed.');
/**
* Use this configuration file for advanced settings.
* For example, here you can define editor params (path, scriptname):
*
* Editor_Markitup::$path = 'media/markitup';
*
*/
Editor::$language = strtolower(substr(I18n::$lang, 0, 2));
// set your editor profiles
// NOTE: when MarkItUp! used, you should set its size at PATH/skins/SKINNAME/style.css
return array
(
'default' => array
(
'width' => 300,
'height' => 1000,
),
'tinymce' => array
(
'driver' => 'tinymce',
'width' => 500,
'height' => 300,
'fieldname' => 'text',
/* 'params' => array
(
),*/
),
'ckeditor' => array
(
'driver' => 'ckeditor',
'width' => 400,
'height' => 600,
'fieldname' => 'text',
'params' => array
(
'skin' => 'kama',
),
),
);

View File

@ -0,0 +1,33 @@
<?php defined('SYSPATH') or die('No direct script access.');
$poor_buttons = array
(
'bold', 'italic', 'underline', 'strikethrough',
);
$rich_buttons = $poor_buttons + array
(
'|',
'justifyleft', 'justifycenter', 'justifyright', 'justifyfull',
'bullist', 'numlist', 'outdent', 'indent',
);
return array
(
'forum_post' => array
(
'theme' => 'advanced',
'plugins' => array('emotions', 'table', 'paste', 'searchreplace'),
'buttons1' => $rich_buttons,
'buttons2' => array('emotions', 'tablecontrols', 'pasteword', 'search,replace'),
),
'forum_comment' => array
(
'plugins' => array('emotions'),
'buttons1' => array_merge($poor_buttons, array('emotions')),
'buttons2' => array(),
),
);