From 003757285e0a14de097b911828bc1d8b0a701112 Mon Sep 17 00:00:00 2001
From: Oreolek
Date: Wed, 17 Apr 2013 09:00:16 +0700
Subject: [PATCH] WiP fixation
---
application/classes/Controller/Games.php | 17 +++
application/classes/Model/User.php | 8 +-
application/classes/Model/game.php | 14 ++
application/classes/Model/rating.php | 12 ++
application/views/games/add.php | 13 ++
application/views/install.php | 17 +++
modules/editor/classes/editor.php | 3 +
modules/editor/classes/editor/ckeditor.php | 3 +
modules/editor/classes/editor/markitup.php | 3 +
modules/editor/classes/editor/tinymce.php | 3 +
modules/editor/classes/kohana/editor.php | 122 ++++++++++++++++++
.../editor/classes/kohana/editor/ckeditor.php | 90 +++++++++++++
.../editor/classes/kohana/editor/markitup.php | 101 +++++++++++++++
.../editor/classes/kohana/editor/tinymce.php | 96 ++++++++++++++
modules/editor/config/editor.php | 46 +++++++
modules/editor/config/editor/tinymce.php | 33 +++++
16 files changed, 577 insertions(+), 4 deletions(-)
create mode 100644 application/classes/Controller/Games.php
create mode 100644 application/classes/Model/game.php
create mode 100644 application/classes/Model/rating.php
create mode 100644 application/views/games/add.php
create mode 100644 application/views/install.php
create mode 100644 modules/editor/classes/editor.php
create mode 100644 modules/editor/classes/editor/ckeditor.php
create mode 100644 modules/editor/classes/editor/markitup.php
create mode 100644 modules/editor/classes/editor/tinymce.php
create mode 100644 modules/editor/classes/kohana/editor.php
create mode 100644 modules/editor/classes/kohana/editor/ckeditor.php
create mode 100644 modules/editor/classes/kohana/editor/markitup.php
create mode 100644 modules/editor/classes/kohana/editor/tinymce.php
create mode 100644 modules/editor/config/editor.php
create mode 100644 modules/editor/config/editor/tinymce.php
diff --git a/application/classes/Controller/Games.php b/application/classes/Controller/Games.php
new file mode 100644
index 0000000..f426629
--- /dev/null
+++ b/application/classes/Controller/Games.php
@@ -0,0 +1,17 @@
+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 = "Недостаточно прав для добавления игры. Обратитесь за помощью к администратору сервиса.";
+ }
+ }
+}
diff --git a/application/classes/Model/User.php b/application/classes/Model/User.php
index c134ca6..2f76537 100644
--- a/application/classes/Model/User.php
+++ b/application/classes/Model/User.php
@@ -1,9 +1,9 @@
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']);
diff --git a/application/classes/Model/game.php b/application/classes/Model/game.php
new file mode 100644
index 0000000..ace6e2c
--- /dev/null
+++ b/application/classes/Model/game.php
@@ -0,0 +1,14 @@
+ 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')
+ );
+}
diff --git a/application/classes/Model/rating.php b/application/classes/Model/rating.php
new file mode 100644
index 0000000..0f3810c
--- /dev/null
+++ b/application/classes/Model/rating.php
@@ -0,0 +1,12 @@
+ 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'),
+ );
+}
diff --git a/application/views/games/add.php b/application/views/games/add.php
new file mode 100644
index 0000000..097a161
--- /dev/null
+++ b/application/views/games/add.php
@@ -0,0 +1,13 @@
+post('title',"Добавить игру")->post('styles','main.css')->execute() ?>
+
+
+
+Добавление игры
+
+ 'multipart/form-data')) ?>
+
+
+
+
+
+execute() ?>
diff --git a/application/views/install.php b/application/views/install.php
new file mode 100644
index 0000000..b2404a9
--- /dev/null
+++ b/application/views/install.php
@@ -0,0 +1,17 @@
+post('title','Установка движка')->post('styles','main.css')->execute() ?>
+ Установка движка
+
+
+ Внимание! При продолжении база данных будет переписана.
+ Предполагается, что база данных MySQL находится по адресу localhost и использует кодировку UTF-8. Вы можете поменять настройки в файле config/database.php.
+
+
+
+
+
+
+
+
+
+
+ execute() ?>
\ No newline at end of file
diff --git a/modules/editor/classes/editor.php b/modules/editor/classes/editor.php
new file mode 100644
index 0000000..695231f
--- /dev/null
+++ b/modules/editor/classes/editor.php
@@ -0,0 +1,3 @@
+
+* @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);
+ }
+
+}
\ No newline at end of file
diff --git a/modules/editor/classes/kohana/editor/ckeditor.php b/modules/editor/classes/kohana/editor/ckeditor.php
new file mode 100644
index 0000000..ad443e5
--- /dev/null
+++ b/modules/editor/classes/kohana/editor/ckeditor.php
@@ -0,0 +1,90 @@
+
+ * @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 .= '';
+
+ 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;
+ }
+
+}
diff --git a/modules/editor/classes/kohana/editor/markitup.php b/modules/editor/classes/kohana/editor/markitup.php
new file mode 100644
index 0000000..fa89273
--- /dev/null
+++ b/modules/editor/classes/kohana/editor/markitup.php
@@ -0,0 +1,101 @@
+
+ * @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 .= '';
+
+ 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);
+ }
+}
\ No newline at end of file
diff --git a/modules/editor/classes/kohana/editor/tinymce.php b/modules/editor/classes/kohana/editor/tinymce.php
new file mode 100644
index 0000000..4c8977f
--- /dev/null
+++ b/modules/editor/classes/kohana/editor/tinymce.php
@@ -0,0 +1,96 @@
+
+ * @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 .= '';
+
+ 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);
+ }
+
+}
\ No newline at end of file
diff --git a/modules/editor/config/editor.php b/modules/editor/config/editor.php
new file mode 100644
index 0000000..3c366e0
--- /dev/null
+++ b/modules/editor/config/editor.php
@@ -0,0 +1,46 @@
+ 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',
+ ),
+ ),
+);
\ No newline at end of file
diff --git a/modules/editor/config/editor/tinymce.php b/modules/editor/config/editor/tinymce.php
new file mode 100644
index 0000000..de5b775
--- /dev/null
+++ b/modules/editor/config/editor/tinymce.php
@@ -0,0 +1,33 @@
+ 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(),
+ ),
+
+);
\ No newline at end of file