Skip to content

Commit 96f27be

Browse files
committed
Init commit
0 parents  commit 96f27be

File tree

1,079 files changed

+60304
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

1,079 files changed

+60304
-0
lines changed

.gitignore

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
/.idea/*
2+
/log/*
3+
/www/index.php
4+
/www/robots.txt
5+
/www/assets/*
6+
/www/upload/*
7+
/protected/yiic.php
8+
/protected/runtime/*
9+
/protected/config/local.php
10+
!.gitignore

protected/.htaccess

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
deny from all
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
<?php
2+
3+
/**
4+
* Gets modules information
5+
*/
6+
class ModulesInformationBehavior extends CBehavior
7+
{
8+
/**
9+
* @var array $modulesMenus List of paths for modules menu widgets
10+
*/
11+
public $modulesMenus = array();
12+
13+
function __construct()
14+
{
15+
foreach (Yii::app()->modules as $module => $value)
16+
{
17+
$path = 'application.modules.' . $module . '.components.' . ucwords($module) . 'AdminmenuWidget';
18+
if (file_exists(YiiBase::getPathOfAlias($path) . '.php'))
19+
$this->modulesMenus[$module] = $path;
20+
}
21+
}
22+
}
23+
?>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
<?php
2+
3+
/**
4+
* Custom web application behavior
5+
*/
6+
class WebApplicationBranchBehavior extends CBehavior
7+
{
8+
/**
9+
* @var string $branch Default branch name
10+
*/
11+
public $branch = "frontend";
12+
13+
/**
14+
* Run Web Application on a current branch
15+
*/
16+
public function runBranch()
17+
{
18+
$this->onModuleCreate = array($this, 'changeModulesBranch');
19+
$this->onModuleCreate(new CEvent ($this->owner));
20+
$this->owner->run();
21+
}
22+
23+
/**
24+
* Custom modules create event
25+
*/
26+
public function onModuleCreate($event)
27+
{
28+
$this->raiseEvent('onModuleCreate', $event);
29+
}
30+
31+
/**
32+
* Changes file paths for controllers and views
33+
*/
34+
protected function changeModulesBranch($event)
35+
{
36+
$event->sender->controllerPath .= DIRECTORY_SEPARATOR . $this->branch;
37+
$event->sender->viewPath .= DIRECTORY_SEPARATOR . $this->branch;
38+
}
39+
}
40+
?>
+38
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
<?php
2+
/**
3+
* Controller is the customized backend controller class.
4+
* All backend controller classes for this application should extend from this base class.
5+
*/
6+
class BackEndController extends BaseController
7+
{
8+
public $layout = '//layouts/column2';
9+
10+
public function filters()
11+
{
12+
return array(
13+
'accessControl',
14+
);
15+
}
16+
17+
public function accessRules()
18+
{
19+
return array(
20+
array('allow',
21+
'roles' => array('admin'),
22+
),
23+
array('deny',
24+
'users' => array('*'),
25+
),
26+
);
27+
}
28+
29+
public function menuWidgets()
30+
{
31+
if (file_exists(YiiBase::getPathOfAlias("application.widgets.AdminmenuWidget") . '.php'))
32+
$this->widget("application.widgets.AdminmenuWidget");
33+
34+
foreach(Yii::app()->modulesMenus as $path)
35+
$this->widget($path);
36+
}
37+
}
38+
?>
+38
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
<?php
2+
3+
/**
4+
* Controller is the customized base controller class.
5+
* All controller classes for this application should extend from this base class.
6+
*/
7+
class BaseController extends CController
8+
{
9+
/**
10+
* @var string the default layout for the controller view. Defaults to '//layouts/column1',
11+
* meaning using a single column layout. See 'protected/views/layouts/column1.php'.
12+
*/
13+
public $layout = "//layouts/main";
14+
15+
/**
16+
* @var array context menu items. This property will be assigned to {@link CMenu::items}.
17+
*/
18+
public $menu = array();
19+
20+
/**
21+
* @var array the breadcrumbs of the current page. The value of this property will
22+
* be assigned to {@link CBreadcrumbs::links}. Please refer to {@link CBreadcrumbs::links}
23+
* for more details on how to specify this property.
24+
*/
25+
public $breadcrumbs = array();
26+
27+
public $title;
28+
public $keywords;
29+
public $description;
30+
31+
public function metaInfoGenerate($title = "", $keywords = "", $description = "")
32+
{
33+
$this->title = $title;
34+
$this->keywords = $keywords;
35+
$this->description = $description;
36+
}
37+
}
38+
?>

protected/components/CConfig.php

+33
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
<?php
2+
/**
3+
* Site configuration component
4+
*/
5+
class CConfig extends CApplicationComponent
6+
{
7+
/**
8+
* $var array $_params
9+
*/
10+
private $_params = array();
11+
12+
/**
13+
* Component initialization
14+
*/
15+
public function init()
16+
{
17+
if ($config = Config::model()->find())
18+
$this->_params = $config->attributes;
19+
}
20+
21+
/**
22+
* Redefine magic get
23+
* @param string $param
24+
* @return mixed|null
25+
*/
26+
public function __get($param)
27+
{
28+
if (array_key_exists($param, $this->_params))
29+
return $this->_params[$param];
30+
else
31+
return parent::__get($param);
32+
}
33+
}
+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
<?php
2+
/**
3+
* Db authorization manager class
4+
*/
5+
class DbAuthManager extends CDbAuthManager
6+
{
7+
/**
8+
* @var string $userTable Users table name
9+
*/
10+
public $userTable = "user";
11+
12+
/**
13+
* Checks access for user
14+
* @param string $itemName
15+
* @param integer $userId
16+
* @return boolean
17+
*/
18+
public function checkAccess($itemName, $userId, $params = array())
19+
{
20+
$role = $this->db->createCommand()->select("role")->from($this->userTable)->where('id=:id', array(':id' => $userId))->queryScalar();
21+
return ($role and $role === $itemName);
22+
}
23+
}
24+
?>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
<?php
2+
/**
3+
* Controller is the customized frontend controller class.
4+
* All frontend controller classes for this application should extend from this base class.
5+
*/
6+
class FrontEndController extends BaseController
7+
{
8+
public function beforeAction(CAction $action)
9+
{
10+
// Если заход на страницу авторизации или на заглушку - пускаем
11+
if (in_array($action->id, array('login', 'cap')))
12+
return parent::beforeAction($action);
13+
// Если установлено "Закрыть общий доступ к сайту" и при этом смотрит не админ -
14+
// Показываем заглушку
15+
if (Yii::app()->config->adminonly and Yii::app()->user->isGuest)
16+
$this->redirect('/site/cap');
17+
18+
return parent::beforeAction($action);
19+
}
20+
}
21+
?>
+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
<?php
2+
/**
3+
* Getting routing rules from application modules
4+
*/
5+
class ModulesUrlRules
6+
{
7+
public function getModuleRules($event)
8+
{
9+
$route = Yii::app()->getRequest()->getPathInfo();
10+
$module = substr($route, 0, strpos($route, '/'));
11+
if (Yii::app()->hasModule($module))
12+
{
13+
$module = Yii::app()->getModule($module);
14+
if (isset($module->urlRules))
15+
Yii::app()->getUrlManager()->addRules($module->urlRules);
16+
}
17+
return true;
18+
}
19+
}
20+
?>

protected/components/PageUrlRule.php

+52
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
<?php
2+
3+
/**
4+
* Custom page url rule
5+
*/
6+
class PageUrlRule extends CBaseUrlRule
7+
{
8+
/**
9+
* @var boolean $lastSlashEnabled Enable slash bonding
10+
*/
11+
public $lastSlashEnabled = false;
12+
13+
/**
14+
* @var integer $lastSlashType Slash bonding type
15+
*/
16+
public $lastSlashType = null;
17+
18+
/**
19+
* Parse url
20+
*/
21+
public function parseUrl($manager, $request, $pathInfo, $rawPathInfo)
22+
{
23+
if ($pages = preg_split("/\//",$pathInfo))
24+
{
25+
$element = end($pages);
26+
if ($page = Page::model()->findByAttributes(array('link' => $element)))
27+
{
28+
$link = $page->getFullLink();
29+
if ($this->lastSlashEnabled and $this->lastSlashType == ADD_LAST_SLASH)
30+
$link .= "/";
31+
32+
if (!$this->lastSlashEnabled and (strrpos($request->requestUri, "/") + 1) === strlen($request->requestUri))
33+
$link .= "/";
34+
35+
if ($link !== $request->requestUri)
36+
$request->redirect($link, true, 301);
37+
else
38+
return "/page/view/id/" . $page->id;
39+
}
40+
}
41+
return false;
42+
}
43+
44+
/**
45+
* Create url
46+
*/
47+
public function createUrl($manager, $route, $params, $ampersand)
48+
{
49+
return false;
50+
}
51+
}
52+
?>

protected/components/UserIdentity.php

+36
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
<?php
2+
3+
/**
4+
* UserIdentity represents the data needed to identity a user.
5+
* It contains the authentication method that checks if the provided
6+
* data can identity the user.
7+
*/
8+
class UserIdentity extends CUserIdentity
9+
{
10+
const ERROR_STATUS_NOTACTIVE = 4;
11+
const ERROR_STATUS_BAN = 5;
12+
const ERROR_ROLE_INVALID = 6;
13+
14+
public function authenticate()
15+
{
16+
$username = strtolower($this->username);
17+
$user = User::model()->find('LOWER(username)=?',array($username));
18+
if ($user === null)
19+
$this->errorCode = self::ERROR_USERNAME_INVALID;
20+
elseif (!$user->validatePassword($this->password))
21+
$this->errorCode = self::ERROR_PASSWORD_INVALID;
22+
elseif ($user->status == 0)
23+
$this->errorCode = self::ERROR_STATUS_NOTACTIVE;
24+
elseif ($user->status == -1)
25+
$this->errorCode = self::ERROR_STATUS_BAN;
26+
elseif (!$user->validateRole($user->role))
27+
$this->errorCode = self::ERROR_ROLE_INVALID;
28+
else
29+
{
30+
$this->setState('__id', $user->id);
31+
$this->setState('__name', $username);
32+
$this->errorCode = self::ERROR_NONE;
33+
}
34+
return $this->errorCode == self::ERROR_NONE;
35+
}
36+
}

protected/config/backend.php

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
<?php
2+
return array(
3+
'components' => array(
4+
'user' => array(
5+
'loginUrl' => array('main/login'),
6+
'returnUrl' => "/manage",
7+
),
8+
'urlManager' => array(
9+
'rules' => array(
10+
'manage' => 'main/index',
11+
'manage/<_c>' => '<_c>',
12+
'manage/<_c>/<_a>' => '<_c>/<_a>',
13+
'manage/<_m>/<_c>/<_a>' => '<_m>/<_c>/<_a>',
14+
),
15+
),
16+
'errorHandler' => array(
17+
'errorAction' => 'main/error',
18+
),
19+
)
20+
);
21+
?>

protected/config/console.php

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<?php
2+
3+
// This is the configuration for yiic console application.
4+
// Any writable CConsoleApplication properties can be configured here.
5+
return CMap::mergeArray(
6+
array(
7+
'basePath' => dirname(__FILE__).DIRECTORY_SEPARATOR.'..',
8+
'name' => 'Console Application',
9+
),
10+
require(dirname(__FILE__).'/local.php')
11+
);

0 commit comments

Comments
 (0)