1 |
3 |
ahitrov@rambler.ru |
package Contenido::State; |
2 |
|
|
|
3 |
|
|
# ---------------------------------------------------------------------------- |
4 |
|
|
# Contenido::State - �����, ����������� ������� ��������� �������. |
5 |
|
|
# ������ ����� ������ ��������� ��� ������ Apache-������� � ����������� |
6 |
|
|
# ������� �� handler.pl ��� startup.pl. ���������� ������ (����, URL, |
7 |
|
|
# ������ � �.�.) ���������� � startup.pl � ������� ������������ ��������� |
8 |
|
|
# sandbox (@@PORT@@). |
9 |
|
|
# ---------------------------------------------------------------------------- |
10 |
|
|
|
11 |
|
|
use strict; |
12 |
|
|
use vars qw($VERSION $AUTOLOAD); |
13 |
|
|
$VERSION = '4.2'; |
14 |
|
|
|
15 |
|
|
use Utils; |
16 |
|
|
use Contenido::Globals; |
17 |
|
|
|
18 |
|
|
use @MEMCACHED_BACKEND@; |
19 |
|
|
|
20 |
|
|
sub new |
21 |
|
|
{ |
22 |
|
|
my ($proto) = shift; |
23 |
|
|
my $class = ref($proto) || $proto; |
24 |
|
|
my $self = {}; |
25 |
|
|
bless($self, $class); |
26 |
|
|
|
27 |
|
|
$self->{project} = '@PROJECT@'; |
28 |
|
|
$self->{project_version} = '@PROJECT_VERSION@'; |
29 |
|
|
$self->{core_version} = '@CORE_VERSION@'; |
30 |
|
|
|
31 |
|
|
$self->{db_type} = lc('@DB_TYPE@') || 'single'; |
32 |
|
|
$self->{db_keepalive} = (lc('@PERSISTENT_CONN@') eq 'no') ? 0:1; |
33 |
|
|
$self->{db_host} = (($self->{db_type} eq 'remote') and '@BASE_HOST@') ? lc('@BASE_HOST@') : 'localhost'; |
34 |
|
|
$self->{db_name} = '@PGSQL_BASE@'; |
35 |
|
|
$self->{db_user} = '@BASE_USER@'; |
36 |
|
|
$self->{db_password} = '@BASE_PASSWD@'; |
37 |
|
|
$self->{db_port} = '@PGSQL_PORT@'; |
38 |
|
|
$self->{db_prepare} = lc('@PGSQL_REAL_PREPARE@') eq 'yes' ? 1 : 0; |
39 |
|
|
$self->{db_enable_utf8} = lc('@PGSQL_ENABLE_UTF@') eq 'yes' ? 1 : 0; |
40 |
|
|
$self->{db_client_encoding} = '@PGSQL_CLIENT_ENCODING@'; |
41 |
|
|
|
42 |
|
|
$self->{db_encode_data} = '@PGSQL_ENCODE_DATA@'; |
43 |
|
|
$self->{db_decode_data} = '@PGSQL_DECODE_DATA@' || 'utf-8'; |
44 |
|
|
|
45 |
|
|
$self->{master_db_host} = (($self->{db_type} eq 'remote') and '@MASTER_BASE_HOST@') ? lc('@MASTER_BASE_HOST@') : 'localhost'; |
46 |
|
|
$self->{master_db_name} = '@MASTER_BASE_NAME@'; |
47 |
|
|
$self->{master_db_user} = '@MASTER_BASE_USER@'; |
48 |
|
|
$self->{master_db_password} = '@MASTER_BASE_PASSWD@'; |
49 |
|
|
$self->{master_db_port} = '@MASTER_BASE_PORT@'; |
50 |
|
|
|
51 |
|
|
$self->{session_dir} = '@SESSIONS@'; |
52 |
|
|
$self->{session_directory} = '@SESSIONS@'; |
53 |
|
|
|
54 |
|
|
$self->{crosslinks_dir} = '@CROSSLINKS@'; |
55 |
|
|
$self->{crosslinks_directory} = '@CROSSLINKS@'; |
56 |
|
|
|
57 |
|
|
$self->{httpd_port} = '@HTTPD_PORT@'; |
58 |
|
|
$self->{httpd_server} = '@HTTPD_SERVER@'; |
59 |
|
|
$self->{httpd_root} = 'http://'.$self->{httpd_server}.'/'; |
60 |
|
|
|
61 |
|
|
$self->{plugins} = '@PLUGINS@'; |
62 |
|
|
|
63 |
|
|
$self->{prefix} = '@PREFIX@'; |
64 |
|
|
|
65 |
|
|
$self->{images_directory} = '@IMAGES@'; |
66 |
|
|
$self->{images_dir} = '@IMAGES@'; |
67 |
|
|
|
68 |
|
|
$self->{proxy_image_location} = '@PROXY_IMAGE_LOCATION@'; |
69 |
|
|
$self->{proxy_image_secret} = '@PROXY_IMAGE_SECRET@'; |
70 |
|
|
|
71 |
|
|
|
72 |
|
|
$self->{binary_directory} = '@BINARY@'; |
73 |
|
|
$self->{binary_dir} = '@BINARY@'; |
74 |
|
|
|
75 |
|
|
{ |
76 |
|
|
my $files_dir = '@FILES@'; |
77 |
|
|
$self->{files_dir} = [split /\s+/ms, $files_dir]; |
78 |
|
|
} |
79 |
|
|
|
80 |
|
|
$self->{convert_binary} = '@CONVERT@'; |
81 |
|
|
|
82 |
|
|
$self->{core_src} = '@CORE_SRC@'; |
83 |
|
|
$self->{plug_src} = '@PLUG_SRC@'; |
84 |
|
|
$self->{proj_src} = '@PROJ_SRC@'; |
85 |
|
|
|
86 |
|
|
$self->{log_dir} = '@PROJECT_LOG@'; |
87 |
|
|
$self->{run_dir} = '@PROJECT_RUN@'; |
88 |
|
|
$self->{tmp_dir} = '@PROJECT_TMP@'; |
89 |
|
|
$self->{usr_dir} = '@PROJECT_USR@'; |
90 |
|
|
|
91 |
|
|
$self->{var_dir} = '@PROJECT_VAR@'; |
92 |
|
|
$self->{data_dir} = $self->{var_dir}; |
93 |
|
|
$self->{data_directory} = $self->{var_dir}; |
94 |
|
|
|
95 |
|
|
$self->{preview} = '@PREVIEW@'; |
96 |
|
|
$self->{mason_comp} = '@MASON_COMP@'; |
97 |
|
|
|
98 |
|
|
$self->{auth_cookie} = '@AUTH_COOKIE@'; |
99 |
|
|
|
100 |
|
|
$self->{is_dev_server} = lc('@DEVELOPMENT@') eq 'yes'; |
101 |
|
|
$self->{development} = lc('@DEVELOPMENT@') eq 'yes'; |
102 |
|
|
|
103 |
|
|
$self->{contenido_version} = '@CONTENIDO_VERSION@' + 0; |
104 |
|
|
$self->{version} = $self->{contenido_version}; |
105 |
|
|
|
106 |
|
|
$self->{__debug__} = (lc('@DEBUG@') eq 'yes'); |
107 |
|
|
$self->{__debug_format__} = '@DEBUG_FORMAT@'; |
108 |
|
|
$self->{__debug_stack_trace__} = lc('@DEBUG_STACK_TRACE@') eq 'yes'; |
109 |
|
|
$self->{__debug_min_level__} = '@DEBUG_MIN_LEVEL@'; |
110 |
|
|
$self->{__debug_max_level__} = '@DEBUG_MAX_LEVEL@'; |
111 |
|
|
$self->{__sql_debug__} = lc('@DEBUG_SQL@') eq 'yes'; |
112 |
|
|
|
113 |
|
|
$self->{project_name} = '@PROJECT_NAME@'; |
114 |
|
|
$self->{multidomain} = lc('@MULTIDOMAIN@') eq 'yes'; |
115 |
|
|
$self->{stage} = 'REAL'; |
116 |
|
|
|
117 |
|
|
$state->{readonly} = (lc('@READONLY@') eq 'yes'); |
118 |
|
|
|
119 |
|
|
$self->{store_method} = lc('@STORE_METHOD@'); |
120 |
|
|
$Contenido::Globals::store_method = $self->{store_method}; |
121 |
|
|
|
122 |
|
|
$self->{cascade} = (lc('@CASCADE@') eq 'yes'); |
123 |
|
|
|
124 |
|
|
$self->{locale} = '@LOCALE@'; |
125 |
|
|
|
126 |
|
|
# ���������������� ��������� memcached |
127 |
|
|
$self->{memcached_backend} = '@MEMCACHED_BACKEND@'; |
128 |
|
|
$self->{memcached_enable} = lc( '@MEMCACHED_ENABLE@' ) eq 'yes' ? 1 : 0; |
129 |
|
|
$self->{memcached_select_timeout} = '@MEMCACHED_SELECT_TIMEOUT@' || 0.2; |
130 |
|
|
$self->{memcached_servers} = [ split(/\s+/, '@MEMCACHED_SERVERS@') ]; |
131 |
|
|
$self->{memcached_enable_compress} = lc( '@MEMCACHED_ENABLE_COMPRESS@' ) eq 'yes' ? 1 : 0; |
132 |
|
|
$self->{memcached_delayed} = lc('@MEMCACHED_DELAYED@') eq 'yes' ? 1 : 0; |
133 |
|
|
$self->{memcached_set_mode} = lc('@MEMCACHED_SET_MODE@') eq 'add' ? 'add' : 'set'; |
134 |
|
|
$self->{memcached_namespace} = lc( $self->{'project'} ).'|'; |
135 |
|
|
|
136 |
|
|
$self->{memcached_object_expire} = undef; |
137 |
|
|
|
138 |
|
|
$self->{options_expire} = '@OPTIONS_EXPIRE@'; |
139 |
|
|
|
140 |
|
|
$self->{preamble_handler} = '@PREAMBLE_HANDLER@'; |
141 |
|
|
$self->{preamble_handler_path} = '@PREAMBLE_HANDLER_PATH@'; |
142 |
|
|
|
143 |
|
|
$self->_refresh_(); |
144 |
|
|
$self->_init_(); |
145 |
|
|
|
146 |
|
|
my @plugins = split(/\s+/, $self->plugins()); |
147 |
|
|
for my $plugin ($self->{project}, @plugins) { |
148 |
|
|
$self->{lc($plugin)} = {}; |
149 |
|
|
$self->{attributes}->{lc($plugin)} = 'SCALAR'; |
150 |
|
|
|
151 |
|
|
my $class = $plugin.'::State'; |
152 |
|
|
eval ("use $class"); |
153 |
|
|
|
154 |
|
|
if ( $@ ) { |
155 |
|
|
warn "Contenido Error: �� ���� ���������� ��������� ������� $plugin ($class) �� ������� '$@'.\n"; |
156 |
|
|
} else { |
157 |
|
|
warn "Contenido Init: �������� ����� $class ��� ������� $plugin.\n" if ($self->debug()); |
158 |
|
|
eval { |
159 |
|
|
$self->{lc($plugin)} = $class->new(); |
160 |
|
|
}; |
161 |
|
|
if ( $@ ) { |
162 |
|
|
warn "Contenido Error: �� ���� ��������� ������������� ��������� ������� $plugin ($class) �� ������� '$@'.\n"; |
163 |
|
|
} |
164 |
|
|
} |
165 |
|
|
} |
166 |
|
|
|
167 |
|
|
|
168 |
|
|
|
169 |
|
|
|
170 |
|
|
return $self; |
171 |
|
|
} |
172 |
|
|
|
173 |
|
|
|
174 |
|
|
|
175 |
|
|
sub _refresh_ |
176 |
|
|
{ |
177 |
|
|
my $self = shift; |
178 |
|
|
$self->{debug} = $self->{__debug__}; |
179 |
|
|
#���������� $DEBUG � $DEBUG_SQL � ���������� ��������!!! |
180 |
|
|
$DEBUG_SQL = $self->{__sql_debug__}; |
181 |
|
|
$DEBUG = $self->{__debug__}; |
182 |
|
|
} |
183 |
|
|
|
184 |
|
|
|
185 |
|
|
# ---------------------------------------------------------------------------- |
186 |
|
|
# ����� ���������� �� �������... |
187 |
|
|
# ---------------------------------------------------------------------------- |
188 |
|
|
sub info |
189 |
|
|
{ |
190 |
|
|
my $self = shift; |
191 |
|
|
return undef unless ref($self); |
192 |
|
|
|
193 |
|
|
$log->info("������ Contenido::State �������� ���������� �����������:"); |
194 |
|
|
foreach my $attribute (sort (keys( %{ $self->{attributes} } ))) |
195 |
|
|
{ |
196 |
|
|
my $la = length($attribute); |
197 |
|
|
warn "\t".$attribute.("\t" x (2-int($la/8))).": ".$self->{$attribute}."\n"; |
198 |
|
|
} |
199 |
|
|
|
200 |
|
|
my @plugins = split(/\s+/, $self->plugins()); |
201 |
|
|
for my $plugin ($self->{project}, @plugins) { |
202 |
|
|
if (ref($self->{lc($plugin)})) { |
203 |
|
|
eval { |
204 |
|
|
$self->{lc($plugin)}->info(); |
205 |
|
|
}; |
206 |
|
|
} |
207 |
|
|
} |
208 |
|
|
} |
209 |
|
|
|
210 |
|
|
|
211 |
|
|
|
212 |
|
|
# ---------------------------------------------------------------------------- |
213 |
|
|
# �������������. |
214 |
|
|
# - ������� ������ ������� ��� � ������ ����� - ��� ����� ��� ������� |
215 |
|
|
# ������ ������ AUTOLOAD... |
216 |
|
|
# ---------------------------------------------------------------------------- |
217 |
|
|
sub _init_ |
218 |
|
|
{ |
219 |
|
|
my $self = shift; |
220 |
|
|
|
221 |
|
|
foreach my $attribute ( qw( |
222 |
|
|
project project_version |
223 |
|
|
|
224 |
|
|
httpd_port httpd_server httpd_root |
225 |
|
|
data_directory data_dir |
226 |
|
|
images_directory images_dir |
227 |
|
|
session_directory session_dir |
228 |
|
|
binary_directory binary_dir |
229 |
|
|
crosslinks_directory crosslinks_dir |
230 |
|
|
|
231 |
|
|
stage |
232 |
|
|
db_keepalive db_host db_name db_user db_password db_port db_type db_client_encoding db_enable_utf8 |
233 |
|
|
|
234 |
|
|
db_encode_data db_decode_data |
235 |
|
|
|
236 |
|
|
mason_comp |
237 |
|
|
multidomain |
238 |
|
|
project_name |
239 |
|
|
preview |
240 |
|
|
|
241 |
|
|
proxy_image_location |
242 |
|
|
proxy_image_secret |
243 |
|
|
|
244 |
|
|
debug |
245 |
|
|
auth_cookie |
246 |
|
|
|
247 |
|
|
plugins |
248 |
|
|
|
249 |
|
|
development |
250 |
|
|
is_dev_server |
251 |
|
|
|
252 |
|
|
contenido_version version |
253 |
|
|
|
254 |
|
|
store_method cascade |
255 |
|
|
|
256 |
|
|
readonly |
257 |
|
|
|
258 |
|
|
locale |
259 |
|
|
|
260 |
|
|
memcached_enable memcached_servers |
261 |
|
|
memcached_select_timeout |
262 |
|
|
memcached_backend memcached_enable_compress |
263 |
|
|
memcached_set_mode |
264 |
|
|
memcached_object_expire |
265 |
|
|
memcached_namespace |
266 |
|
|
convert_binary |
267 |
|
|
) ) |
268 |
|
|
{ |
269 |
|
|
$self->{attributes}->{ $attribute } = 'SCALAR'; |
270 |
|
|
} |
271 |
|
|
} |
272 |
|
|
|
273 |
|
|
|
274 |
|
|
|
275 |
|
|
# ---------------------------------------------------------------------------- |
276 |
|
|
# ��� ����� AUTOLOAD. ����� ������� ��� ���������/������ �����... |
277 |
|
|
# ������ 0.2 |
278 |
|
|
# ---------------------------------------------------------------------------- |
279 |
|
|
|
280 |
|
|
sub AUTOLOAD |
281 |
|
|
{ |
282 |
|
|
my $self = shift; |
283 |
|
|
my $attribute = $AUTOLOAD; |
284 |
|
|
|
285 |
|
|
$attribute =~ s/.*:://; |
286 |
|
|
return undef unless $attribute =~ /[^A-Z]/; # ��������� ������ ���� DESTROY |
287 |
|
|
|
288 |
|
|
if (! exists($self->{attributes}->{$attribute})) |
289 |
|
|
{ |
290 |
|
|
$log->error("����� ������, ��� �������� �� ���������� ��������������� ��������: ->$attribute()"); |
291 |
|
|
return undef; |
292 |
|
|
} |
293 |
|
|
|
294 |
|
|
$self->{ $attribute } = shift @_ if (scalar(@_) > 0); |
295 |
|
|
return $self->{ $attribute }; |
296 |
|
|
} |
297 |
|
|
|
298 |
|
|
|
299 |
|
|
1; |