-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBbiiModule.php
More file actions
147 lines (136 loc) · 4.65 KB
/
Copy pathBbiiModule.php
File metadata and controls
147 lines (136 loc) · 4.65 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
<?php
class BbiiModule extends CWebModule {
public $defaultController = 'forum';
public $version = '1.0.5';
public $adminId = false; // must be overridden to assign admin rights to user id
public $avatarStorage = '/avatar'; // directory in the webroot must exist and allow read/write access
public $forumTitle = 'BBii Forum';
public $userClass = 'User';
public $userIdColumn = 'id';
public $userNameColumn = 'username';
public $userMailColumn = false;
public $dbName = false;
public $topicsPerPage = 20;
public $postsPerPage = 20;
public $purifierOptions = array(
'HTML.SafeIframe'=>true,
'URI.SafeIframeRegexp'=>'%^http://(www.youtube.com/embed/|player.vimeo.com/video/)%',
);
public $editorToolbar = array(
array('Cut','Copy','Paste','PasteText','PasteFromWord','-','Undo','Redo'),
array('Find','Replace','-','SelectAll'),
array('Bold', 'Italic','Underline','Strike','Subscript','Superscript','-','RemoveFormat'),
'-',
array('NumberedList','BulletedList','-','Outdent','Indent','-','Blockquote','CreateDiv',
'-','JustifyLeft','JustifyCenter','JustifyRight','JustifyBlock'),
'/',
array('Styles','Format','Font','FontSize'),
array('TextColor','BGColor'),
array('HorizontalRule','Smiley','SpecialChar','-','ShowBlocks'),
array('Link', 'Unlink','Image','Iframe')
);
public $editorSkin = 'moono';
public $editorUIColor = '';
public $editorContentsCss = array();
public $juiTheme = 'base';
public $bbiiTheme = 'base';
private $_assetsUrl;
public function init() {
$this->registerAssets();
Yii::app()->setComponents(
array(
'errorHandler'=>array(
'errorAction'=>'forum/forum/error',
),
)
);
// import the module-level models and components
$this->setImport(array(
$this->id.'.models.*',
$this->id.'.components.*',
));
}
/**
* @return string base URL that contains all published asset files of this module.
*/
public function getAssetsUrl() {
if($this->_assetsUrl == null) {
$this->_assetsUrl = Yii::app()->assetManager->publish(Yii::getPathOfAlias($this->id.'.assets')
// Comment the line below out in production.
,false,-1,true
);
}
return $this->_assetsUrl;
}
/**
* Register the CSS and JS files for the module
*/
public function registerAssets() {
Yii::app()->clientScript->registerCssFile($this->getAssetsUrl() . '/css/' . $this->bbiiTheme . '/forum.css');
Yii::app()->getClientScript()->registerCoreScript('jquery.ui');
Yii::app()->clientScript->registerScriptFile($this->getAssetsUrl() . '/js/bbii.js', CClientScript::POS_HEAD);
}
/**
* Retrieve url of image in the assets
* @param string filename of the image
* @return string source URL of image
*/
public function getRegisteredImage($filename) {
return $this->getAssetsUrl() .'/images/'. $filename;
}
public function beforeControllerAction($controller, $action)
{
if(parent::beforeControllerAction($controller, $action)) {
// this method is called before any module controller action is performed
// you may place customized code here
// register last visit by member
if(Yii::app()->user->id) {
$model = BbiiMember::model()->findByPk(Yii::app()->user->id);
if($model !== null) {
$model->last_visit = date('Y-m-d H:i:s');
$model->save();
} else {
$criteria = new CDbCriteria;
$criteria->condition = $this->userIdColumn . '=:id';
$criteria->params = array(':id'=>Yii::app()->user->id);
$class = new $this->userClass;
$user = $class::model()->find($criteria);
$username = $user->getAttribute($this->userNameColumn);
$model = new BbiiMember;
$model->id = Yii::app()->user->id;
$model->member_name = $username;
$model->first_visit = date('Y-m-d H:i:s');
$model->last_visit = date('Y-m-d H:i:s');
$model->save();
}
}
// register visit by webspider
if(isset($_SERVER['HTTP_USER_AGENT'])) {
$spider = BbiiSpider::model()->findByAttributes(array('user_agent'=>$_SERVER['HTTP_USER_AGENT']));
} else {
$spider = null;
}
if($spider !== null) {
$spider->setScenario('visit');
$spider->hits++;
$spider->last_visit = null;
$spider->save();
} else {
// register visit by guest (when not a webspider)
$model = BbiiSession::model()->findByPk(Yii::app()->session->sessionID);
if($model === null) {
$model = new BbiiSession;
$model->id = Yii::app()->session->sessionID;
}
$model->save();
}
// delete older session entries
$criteria = new CDbCriteria;
$criteria->condition = 'last_visit < "' . date('Y-m-d H:i:s', (time() - 24*3600)). '"';
BbiiSession::model()->deleteAll($criteria);
return true;
}
else
return false;
}
}