The beginning

It works;
that's all I need
for the initial commit.
This commit is contained in:
Alexander Yakovlev 2012-07-02 19:38:50 +07:00
commit b7f2f24e23
32 changed files with 934 additions and 0 deletions

15
.gitmodules vendored Normal file
View File

@ -0,0 +1,15 @@
[submodule "system"]
path = system
url = git://github.com/kohana/core.git
[submodule "modules/database"]
path = modules/database
url = git://github.com/kohana/database.git
[submodule "modules/auth"]
path = modules/auth
url = git://github.com/kohana/auth.git
[submodule "modules/orm"]
path = modules/orm
url = git://github.com/kohana/orm
[submodule "modules/markdown"]
path = modules/markdown
url = git://github.com/aptgraph/kohana-markdown.git

128
application/bootstrap.php Normal file
View File

@ -0,0 +1,128 @@
<?php defined('SYSPATH') or die('No direct script access.');
// -- Environment setup --------------------------------------------------------
// Load the core Kohana class
require SYSPATH.'classes/kohana/core'.EXT;
if (is_file(APPPATH.'classes/kohana'.EXT))
{
// Application extends the core
require APPPATH.'classes/kohana'.EXT;
}
else
{
// Load empty core extension
require SYSPATH.'classes/kohana'.EXT;
}
/**
* Set the default time zone.
*
* @see http://kohanaframework.org/guide/using.configuration
* @see http://php.net/timezones
*/
date_default_timezone_set('Asia/Novosibirsk');
/**
* Set the default locale.
*
* @see http://kohanaframework.org/guide/using.configuration
* @see http://php.net/setlocale
*/
setlocale(LC_ALL, 'ru_RU.utf-8');
/**
* Enable the Kohana auto-loader.
*
* @see http://kohanaframework.org/guide/using.autoloading
* @see http://php.net/spl_autoload_register
*/
spl_autoload_register(array('Kohana', 'auto_load'));
/**
* Enable the Kohana auto-loader for unserialization.
*
* @see http://php.net/spl_autoload_call
* @see http://php.net/manual/var.configuration.php#unserialize-callback-func
*/
ini_set('unserialize_callback_func', 'spl_autoload_call');
// -- Configuration and initialization -----------------------------------------
/**
* Set the default language
*/
I18n::lang('ru');
/**
* Set Kohana::$environment if a 'KOHANA_ENV' environment variable has been supplied.
*
* Note: If you supply an invalid environment name, a PHP warning will be thrown
* saying "Couldn't find constant Kohana::<INVALID_ENV_NAME>"
*/
if (isset($_SERVER['KOHANA_ENV']))
{
Kohana::$environment = constant('Kohana::'.strtoupper($_SERVER['KOHANA_ENV']));
}
/**
* Initialize Kohana, setting the default options.
*
* The following options are available:
*
* - string base_url path, and optionally domain, of your application NULL
* - string index_file name of your index file, usually "index.php" index.php
* - string charset internal character set used for input and output utf-8
* - string cache_dir set the internal cache directory APPPATH/cache
* - boolean errors enable or disable error handling TRUE
* - boolean profile enable or disable internal profiling TRUE
* - boolean caching enable or disable internal caching FALSE
*/
Kohana::init(array(
'base_url' => '/',
'index_file' => FALSE,
'errors' => TRUE,
'profile' => (Kohana::$environment == Kohana::DEVELOPMENT),
'caching' => (Kohana::$environment == Kohana::PRODUCTION)
));
/**
* Attach the file write to logging. Multiple writers are supported.
*/
Kohana::$log->attach(new Log_File(APPPATH.'logs'));
/**
* Attach a file reader to config. Multiple readers are supported.
*/
Kohana::$config->attach(new Config_File);
/**
* Enable modules. Modules are referenced by a relative or absolute path.
*/
Kohana::modules(array(
'auth' => MODPATH.'auth', // Basic authentication
// 'cache' => MODPATH.'cache', // Caching with multiple backends
// 'codebench' => MODPATH.'codebench', // Benchmarking tool
'database' => MODPATH.'database', // Database access
// 'image' => MODPATH.'image', // Image manipulation
'orm' => MODPATH.'orm', // Object Relationship Mapping
// 'unittest' => MODPATH.'unittest', // Unit testing
// 'userguide' => MODPATH.'userguide', // User guide and API documentation
'markdown' => MODPATH.'markdown', // Markdown module
));
/**
* Set the routes. Each route must have a minimum of a name, a URI and a set of
* defaults for the URI.
*/
Route::set('error', 'error/<action>(/<message>)', array('action' => '[0-9]++','message' => '.+'))
->defaults(array(
'controller' => 'error',
));
Route::set('default', '(<controller>(/<action>(/<id>)))')
->defaults(array(
'controller' => 'error',
'action' => 'view',
));

1
application/cache/.gitignore vendored Normal file
View File

@ -0,0 +1 @@
[^.]*

View File

@ -0,0 +1,33 @@
<?php defined('SYSPATH') or die('No direct script access.');
class Controller_Error extends Controller_Template {
public $template = 'error';
/**
* Pre determine error display logic
*/
public function before() {
parent::before();
// Sub requests only!
if ($this->request->is_initial()) $this->request->action(404);
$this->response->status((int) $this->request->action());
}
/**
* Serves HTTP 404 error page
*/
//адрес страницы не выводится
public function action_404() {
$this->template->title = 'Страница не найдена';
$this->template->description = 'Запрошенная вами страница не найдена. Скорее всего, это была просто опечатка. Проверьте строку адреса.';
}
/**
* Serves HTTP 500 error page
*/
public function action_500() {
$this->template->description = 'Произошла внутренняя ошибка. Не волнуйтесь, её должны скоро исправить.';
$this->template->title ='Внутренняя ошибка сервера';
}
}

View File

@ -0,0 +1,7 @@
<?php defined('SYSPATH') or die('No direct script access.');
class Controller_Footer extends Controller_Template {
public $template = 'footer';
public function action_standard() { }
public function action_view(){$this->request->redirect('');}
}

View File

@ -0,0 +1,15 @@
<?php defined('SYSPATH') or die('No direct script access.');
class Controller_Header extends Controller_Template {
public $template = 'header';
public function action_standard() {
$this->template->title = $this->request->post('title');
$scripts = $this->request->post('scripts');
$temp = "";
if (is_array($scripts)) foreach($scripts as $script):
$temp .= '<script type="text/javascript" charset="utf-8" src="'.URL::site('assets/javascript/'.$script).'"></script>'."\n";
endforeach;
$this->template->scripts = $temp;
}
public function action_view(){$this->request->redirect('');}
}

View File

@ -0,0 +1,14 @@
<?php defined('SYSPATH') or die('No direct script access.');
class Controller_Login extends Controller_Template {
public $template = 'login';
public function action_view() {
if(Auth::instance()->logged_in()) return $this->request->redirect('');
if ($_POST){
$user = ORM::factory('user');
$status = Auth::instance()->login($this->request->post('login'), $this->request->post('password'));
if ($status) return $this->request->redirect('');
else $this->template->error = "Неверный логин или пароль.";
}
}
}

View File

@ -0,0 +1,8 @@
<?php defined('SYSPATH') or die('No direct script access.');
class Controller_Logout extends Controller {
public function action_view() {
if (Auth::instance()->logout()) return $this->request->redirect('login');
else $this->template->error = "Ошибка выхода пользователя.";
}
}

View File

@ -0,0 +1,17 @@
<?php defined('SYSPATH') or die('No direct script access.');
class Controller_Navigation extends Controller_Template {
public $template = 'navigation/actions';
public function action_actions() {
$this->template = new View('navigation/actions');
$login_or_logout = HTML::anchor('login', 'Вход');
$this->template->login_or_logout = $login_or_logout;
if (Auth::instance()->logged_in()){
$this->template->login_or_logout = HTML::anchor('logout', 'Выход');
}
if (Auth::instance()->logged_in('admin')){
$this->template->admin_actions = View::factory('navigation/admin')->render();
}
}
public function action_view(){$this->request->redirect('');}
}

View File

@ -0,0 +1,40 @@
<?php defined('SYSPATH') or die('No direct script access.');
class Kohana_Exception extends Kohana_Kohana_Exception {
public static function handler(Exception $e) {
// Throw errors when in development mode
if (Kohana::$environment === Kohana::DEVELOPMENT) {
parent::handler($e);
}
else {
try{
Kohana::$log->add(Log::ERROR, Kohana_Exception::text($e));
$attributes = array(
'action' => 500,
'message' => rawurlencode($e->getMessage())
);
if ($e instanceof Http_Exception) {
$attributes['action'] = $e->getCode();
}
// Error sub request
echo Request::factory(Route::get('error')->uri($attributes))
->execute()
->send_headers()
->body();
}
catch (Exception $e){
// Clean the output buffer if one exists
ob_get_level() and ob_clean();
// Display the exception text
echo parent::text($e);
// Exit with an error status
exit(1);
}
}
}
}

View File

@ -0,0 +1,42 @@
<?php defined('SYSPATH') OR die('No direct access allowed.');
class Model_User extends Model_Auth_User {
protected $_rules = array(
'username' => array(
'not_empty' => NULL,
'min_length' => array(4),
'max_length' => array(32),
'regex' => array('/^[-\pL\pN_.]++$/uD')
),
'password' => array(
'not_empty' => NULL,
'min_length' => array(5),
'max_length' => array(42)
),
'email' => array(
'not_empty' => NULL,
'min_length' => array(5),
'max_length' => array(127),
'validate::email' => NULL
)
);
protected $_callbacks = array(
'username' => array('username_available'),
'email' => array('email_available')
);
public function validate_create(&$array){
$array = Validate::factory($array)
->filter(TRUE, 'trim')
->rules('username', $this->_rules['username'])
->rules('password', $this->_rules['password'])
->rules('email', $this->_rules['email']);
foreach ($this->_callbacks as $field => $callbacks){
foreach ($callbacks as $callback){
$array->callback($field, array($this, $callback));
}
}
return $array;
}
}

View File

@ -0,0 +1,16 @@
<?php defined('SYSPATH') or die('No direct access allowed.');
return array(
'driver' => 'ORM',
'hash_method' => 'sha256',
'hash_key' => "3wj88uew hello uwri88 dshnber riweuri",
'lifetime' => 1209600,
'session_key' => 'auth_user',
// Username/password combinations for the Auth File driver
'users' => array(
// 'admin' => 'b3154acf3a344170077d11bdb5fff31532f679a1919e716a02',
),
);

View File

@ -0,0 +1,5 @@
<?php defined('SYSPATH') OR die('No direct access allowed.');
return array(
'title' => "Простой сайт",
);

View File

@ -0,0 +1,31 @@
<?php defined('SYSPATH') or die('No direct access allowed.');
return array
(
'default' => array
(
'type' => 'mysql',
'connection' => array(
/**
* The following options are available for MySQL:
*
* string hostname server hostname, or socket
* string database database name
* string username database username
* string password database password
* boolean persistent use persistent connections?
*
* Ports and sockets may be appended to the hostname.
*/
'hostname' => 'localhost',
'database' => 'plastek',
'username' => 'dandelion',
'password' => '',
'persistent' => FALSE,
),
'table_prefix' => '',
'charset' => 'utf8',
'caching' => TRUE,
'profiling' => FALSE,
),
);

View File

@ -0,0 +1,12 @@
<?php defined('SYSPATH') or die('No direct script access.');
return array
(
'default' => array
(
'type' => 'html', // html or xhtml
'tab_width' => 2, // Tab width for output
'no_entities' => FALSE,
'no_markup' => FALSE
)
);
?>

1
application/logs/.gitignore vendored Normal file
View File

@ -0,0 +1 @@
[^.]*

View File

@ -0,0 +1,4 @@
<?php echo Request::factory('header/standard')->post('title',$title)->execute() ?>
<h1><?php echo $title?></h1>
<p><?php echo $description?></p>
<?php echo Request::factory('footer/standard')->execute() ?>

View File

@ -0,0 +1,5 @@
</div>
<div id="footer"></div>
</div>
</body>
</html>

View File

@ -0,0 +1,18 @@
<!doctype html>
<html>
<head>
<title><?php echo $title ?></title>
<meta charset="utf-8">
<link href='<?php echo URL::site('favicon.ico')?>' rel='shortcut icon' type='image/x-icon'/>
<link rel="stylesheet" type="text/css" media="all" href="<?php echo URL::site('assets/stylesheets/main.css') ?>">
<?php echo $scripts ?>
</head>
<body>
<div id="main_container">
<div id="header">
<h1><?php echo Kohana::$config->load('common.title')?></h1>
</div>
<div id="menu">
<?php echo Request::factory('navigation/actions')->execute() ?>
</div>
<div id="column_text">

View File

@ -0,0 +1,12 @@
<?php echo Request::factory('header/standard')->post('title',"Вход в систему")->execute() ?>
<div id="error"><?php if(!empty($error)) echo $error;?></div>
<div id="message"><?php if(!empty($message)) echo $message;?></div>
<p>Введите логин и пароль для получения доступа к разделу.</p>
<?php echo form::open('login') ?>
<p><?php echo form::label('login','Логин: '); echo form::input('login','') ?></p>
<p><?php echo form::label('password','Пароль: '); echo form::password('password','') ?></p>
<p><?php echo form::submit('submit','Отправить') ?>
</p>
<?php echo form::close() ?>
<?php echo Request::factory('footer/standard')->execute() ?>

View File

@ -0,0 +1,4 @@
<ul>
<?php if (isset($admin_actions)) echo $admin_actions;?>
<li><?php echo $login_or_logout; ?></li>
</ul>

View File

@ -0,0 +1 @@
<li><?php echo HTML::anchor('pages', 'Страницы'); ?></li>

View File

@ -0,0 +1,180 @@
@basesize: 1em;
body{
font-family: "Lucida Sans", "Lucida Grande", "Lucida Sans Unicode", sans-serif;
margin: 0;
padding: 0;
font-size: @basesize;
}
#footer {
a{
font-size: 0.75 * @basesize;
}
}
#header #title{
float: right;
font-size: 3 * @basesize;
line-height: 1;
margin-bottom: 0.5 * @basesize;
margin-top: 0.5 * @basesize;
}
.authortext{
font-style: italic;
text-align: center;
margin: @basesize auto;
}
.actor{
text-align: center;
margin: @basesize auto;
}
/*---------------*/
/** Заголовки **/
/*---------------*/
h1,h2,h3,h4,h5,h6 {
font-weight: normal;
img{
margin: 0;
}
}
h1 {
font-size: 3 * @basesize;
line-height: 1;
margin-bottom: 0.5 * @basesize;
}
h2 {
font-size: 2 * @basesize;
margin-bottom: 0.75 * @basesize;
}
h3 {
font-size: 1.5 * @basesize;
line-height: 1;
margin-bottom: @basesize;
}
h4 {
font-size: 1.2 * @basesize;
line-height: 1.25;
margin-bottom: 1.25 * @basesize;
}
h5 {
font-size: @basesize;
font-weight: bold;
margin-bottom: 1.5em;
}
h6 {
font-size: @basesize;
font-weight: bold;
}
/*---------------*/
/** Текст **/
/*---------------*/
p {
margin: 0 0 1.5 * @basesize;
text-indent: 1 * @basesize;
}
.floatleft { float: left; }
.floatright { float: right; }
p .floatleft {
margin: 1.5 * @basesize 1.5 * @basesize 1.5 * @basesize 0;
padding: 0;
}
p .floatright {
margin: 1.5 * @basesize 0 1.5 * @basesize 1.5 * @basesize;
padding: 0;
}
a {
text-decoration:none;
img{
border:none;
}
}
a:hover {
text-decoration:underline;
}
blockquote {
margin: 1.5 * @basesize;
font-style: italic;
}
sup, sub {
line-height: 0;
}
pre {
margin: 1.5 * @basesize 0;
white-space: pre;
}
pre,code,tt {
font-family: "PT Mono", "Courier New", "Courier", monospace;
line-height: 1.5;
}
/*---------------*/
/** Списки **/
/*---------------*/
li ul,li ol {
margin: 0;
}
ul, ol {
margin: 0 1.5 * @basesize 1.5 * @basesize 0;
padding-left: 1.5 * @basesize;
}
ul {
list-style-type: disc;
}
ol {
list-style-type: decimal;
}
dl {
margin: 0 0 1.5 * @basesize 0;
dt{
font-weight: bold;
float: left;
margin: 0;
margin-right:1.5 * @basesize;
}
dd{
margin: 0;
}
}
/*---------------*/
/** Таблицы **/
/*---------------*/
table {
margin-bottom: 1.4 * @basesize;
width:100%;
}
th {
font-weight: bold;
}
th,td,caption {
padding: 0.3 * @basesize 0.7 * @basesize 0.3 * @basesize 0.4 * @basesize;
}
tfoot {
font-style: italic;
}

View File

@ -0,0 +1,168 @@
body {
font-family: "Lucida Sans", "Lucida Grande", "Lucida Sans Unicode", sans-serif;
margin: 0;
padding: 0;
font-size: 1em;
}
#footer a {
font-size: 0.75em;
}
#header #title {
float: right;
font-size: 3em;
line-height: 1;
margin-bottom: 0.5em;
margin-top: 0.5em;
}
.authortext {
font-style: italic;
text-align: center;
margin: 1em auto;
}
.actor {
text-align: center;
margin: 1em auto;
}
/*---------------*/
/** Заголовки **/
/*---------------*/
h1,
h2,
h3,
h4,
h5,
h6 {
font-weight: normal;
}
h1 img,
h2 img,
h3 img,
h4 img,
h5 img,
h6 img {
margin: 0;
}
h1 {
font-size: 3em;
line-height: 1;
margin-bottom: 0.5em;
}
h2 {
font-size: 2em;
margin-bottom: 0.75em;
}
h3 {
font-size: 1.5em;
line-height: 1;
margin-bottom: 1em;
}
h4 {
font-size: 1.2em;
line-height: 1.25;
margin-bottom: 1.25em;
}
h5 {
font-size: 1em;
font-weight: bold;
margin-bottom: 1.5em;
}
h6 {
font-size: 1em;
font-weight: bold;
}
/*---------------*/
/** Текст **/
/*---------------*/
p {
margin: 0 0 1.5em;
text-indent: 1em;
}
.floatleft {
float: left;
}
.floatright {
float: right;
}
p .floatleft {
margin: 1.5em 1.5em 1.5em 0;
padding: 0;
}
p .floatright {
margin: 1.5em 0 1.5em 1.5em;
padding: 0;
}
a {
text-decoration: none;
}
a img {
border: none;
}
a:hover {
text-decoration: underline;
}
blockquote {
margin: 1.5em;
font-style: italic;
}
sup,
sub {
line-height: 0;
}
pre {
margin: 1.5em 0;
white-space: pre;
}
pre,
code,
tt {
font-family: "PT Mono", "Courier New", "Courier", monospace;
line-height: 1.5;
}
/*---------------*/
/** Списки **/
/*---------------*/
li ul,
li ol {
margin: 0;
}
ul,
ol {
margin: 0 1.5em 1.5em 0;
padding-left: 1.5em;
}
ul {
list-style-type: disc;
}
ol {
list-style-type: decimal;
}
dl {
margin: 0 0 1.5em 0;
}
dl dt {
font-weight: bold;
float: left;
margin: 0;
margin-right: 1.5em;
}
dl dd {
margin: 0;
}
/*---------------*/
/** Таблицы **/
/*---------------*/
table {
margin-bottom: 1.4em;
width: 100%;
}
th {
font-weight: bold;
}
th,
td,
caption {
padding: 0.3em 0.7em 0.3em 0.4em;
}
tfoot {
font-style: italic;
}

4
assets/stylesheets/compile.sh Executable file
View File

@ -0,0 +1,4 @@
#!/bin/bash
lessc -x base.less >main.css
lessc -x layout.less >>main.css
lessc -x colors.less >>main.css

View File

@ -0,0 +1,36 @@
@pagewidth: 80%;
.centered(){
margin: 0 auto;
}
#container{
.centered;
width: @pagewidth;
}
#header{
width: 100%;
.centered;
width: @pagewidth;
}
#footer {
.centered;
width: @pagewidth;
padding:10px 0px 10px 0px;
text-align: center;
}
.content {
width: 98%;
margin: 4px auto;
padding: 2em;
}
#sidebar{
float: right;
ul{
list-style-type: none;
}
}

112
index.php Normal file
View File

@ -0,0 +1,112 @@
<?php
/**
* The directory in which your application specific resources are located.
* The application directory must contain the bootstrap.php file.
*
* @see http://kohanaframework.org/guide/about.install#application
*/
$application = 'application';
/**
* The directory in which your modules are located.
*
* @see http://kohanaframework.org/guide/about.install#modules
*/
$modules = 'modules';
/**
* The directory in which the Kohana resources are located. The system
* directory must contain the classes/kohana.php file.
*
* @see http://kohanaframework.org/guide/about.install#system
*/
$system = 'system';
/**
* The default extension of resource files. If you change this, all resources
* must be renamed to use the new extension.
*
* @see http://kohanaframework.org/guide/about.install#ext
*/
define('EXT', '.php');
/**
* Set the PHP error reporting level. If you set this in php.ini, you remove this.
* @see http://php.net/error_reporting
*
* When developing your application, it is highly recommended to enable notices
* and strict warnings. Enable them by using: E_ALL | E_STRICT
*
* In a production environment, it is safe to ignore notices and strict warnings.
* Disable them by using: E_ALL ^ E_NOTICE
*
* When using a legacy application with PHP >= 5.3, it is recommended to disable
* deprecated notices. Disable with: E_ALL & ~E_DEPRECATED
*/
error_reporting(E_ALL | E_STRICT);
ini_set('display_errors', 'On');
/**
* End of standard configuration! Changing any of the code below should only be
* attempted by those with a working knowledge of Kohana internals.
*
* @see http://kohanaframework.org/guide/using.configuration
*/
// Set the full path to the docroot
define('DOCROOT', realpath(dirname(__FILE__)).DIRECTORY_SEPARATOR);
// Make the application relative to the docroot, for symlink'd index.php
if ( ! is_dir($application) AND is_dir(DOCROOT.$application))
$application = DOCROOT.$application;
// Make the modules relative to the docroot, for symlink'd index.php
if ( ! is_dir($modules) AND is_dir(DOCROOT.$modules))
$modules = DOCROOT.$modules;
// Make the system relative to the docroot, for symlink'd index.php
if ( ! is_dir($system) AND is_dir(DOCROOT.$system))
$system = DOCROOT.$system;
// Define the absolute paths for configured directories
define('APPPATH', realpath($application).DIRECTORY_SEPARATOR);
define('MODPATH', realpath($modules).DIRECTORY_SEPARATOR);
define('SYSPATH', realpath($system).DIRECTORY_SEPARATOR);
// Clean up the configuration vars
unset($application, $modules, $system);
if (file_exists('install'.EXT))
{
// Load the installation check
return include 'install'.EXT;
}
/**
* Define the start time of the application, used for profiling.
*/
if ( ! defined('KOHANA_START_TIME'))
{
define('KOHANA_START_TIME', microtime(TRUE));
}
/**
* Define the memory usage at the start of the application, used for profiling.
*/
if ( ! defined('KOHANA_START_MEMORY'))
{
define('KOHANA_START_MEMORY', memory_get_usage());
}
// Bootstrap the application
require APPPATH.'bootstrap'.EXT;
/**
* Execute the main request. A source of the URI can be passed, eg: $_SERVER['PATH_INFO'].
* If no source is specified, the URI will be automatically detected.
*/
echo Request::factory()
->execute()
->send_headers()
->body();

1
modules/auth Submodule

@ -0,0 +1 @@
Subproject commit 24073ab4d4424ea51ceab01ef9021ee563051177

1
modules/database Submodule

@ -0,0 +1 @@
Subproject commit f0944e8586ef2f8230042d822a3781c4835c3a75

1
modules/markdown Submodule

@ -0,0 +1 @@
Subproject commit e0e0071949b4956d567e9a26f9c81249d45e1467

1
modules/orm Submodule

@ -0,0 +1 @@
Subproject commit bb5f9ef98e8f4a0cc7274f6331aa9eaebcba4b4d

1
system Submodule

@ -0,0 +1 @@
Subproject commit 44fcb1b68a760f4d9ab46607776671b2d40d3647