File: b2options.php

package info (click to toggle)
b2evolution 0.9.2-3%2Betch1
  • links: PTS
  • area: main
  • in suites: etch
  • size: 12,972 kB
  • ctags: 5,460
  • sloc: php: 58,989; sh: 298; makefile: 36
file content (453 lines) | stat: -rw-r--r-- 15,207 bytes parent folder | download | duplicates (2)
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
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
<?php
/**
 * This file implements the settings page
 *
 * b2evolution - {@link http://b2evolution.net/}
 * Released under GNU GPL License - {@link http://b2evolution.net/about/license.html}
 * @copyright (c)2003-2005 by Francois PLANQUE - {@link http://fplanque.net/}
 *
 * @package admin
 */

/**
 * Includes:
 */
require( dirname(__FILE__). '/_header.php' );
$admin_tab = 'options';
$admin_pagetitle = T_('Settings');

param( 'action', 'string' );
param( 'tab', 'string', 'general' );
param( 'prioup', 'string', '' );
param( 'priodown', 'string', '' );
param( 'delete', 'string', '' );
param( 'notransext', 'integer', 0 );

switch( $tab )
{
	case 'general':
		$admin_pagetitle .= ' :: '. T_('General');
		break;
	case 'regional':
		$admin_pagetitle .= ' :: '. T_('Regional');
		break;
	case 'plugins':
		$admin_pagetitle .= ' :: '. T_('Plug-ins');
		break;
}

require( dirname(__FILE__). '/_menutop.php' );
require( dirname(__FILE__). '/_menutop_end.php' );


if( in_array( $action, array('update', 'reset', 'updatelocale', 'createlocale', 'extract' ))
		|| !empty($prioup) || !empty($priodown) || !empty($delete)
	)
{ // We have an action to do..
	// Check permission:
	$current_User->check_perm( 'options', 'edit', true );

	$status_update = array();

	// clear settings cache
	$cache_settings = '';

	switch( $tab )
	{
		case 'general':
			// UPDATE general settings:

			param( 'default_blog_ID', 'integer', true );
			$Settings->set( 'default_blog_ID', $default_blog_ID );
			param( 'default_blog_ID', 'integer', true );
			$Settings->set( 'default_blog_ID', $default_blog_ID );
			param( 'posts_per_page', 'integer', true );
			$Settings->set( 'posts_per_page', $posts_per_page );
			param( 'what_to_show', 'string', true );
			$Settings->set( 'what_to_show', $what_to_show );
			param( 'archive_mode', 'string', true );
			$Settings->set( 'archive_mode', $archive_mode );
			param( 'AutoBR', 'integer', 0 );
			$Settings->set( 'AutoBR', $AutoBR );
			param( 'newusers_canregister', 'integer', 0 );
			$Settings->set( 'newusers_canregister', $newusers_canregister );
			param( 'newusers_grp_ID', 'integer', true );
			$Settings->set( 'newusers_grp_ID', $newusers_grp_ID );
			param( 'newusers_level', 'integer', true );
			$Settings->set( 'newusers_level', $newusers_level );
			param( 'links_extrapath', 'integer', 0 );
			$Settings->set( 'links_extrapath', $links_extrapath );
			param( 'permalink_type', 'string', true );
			$Settings->set( 'permalink_type', $permalink_type );
			param( 'user_minpwdlen', 'integer', true );
			$Settings->set( 'user_minpwdlen', $user_minpwdlen );

			if( $Settings->updateDB() )
			{
				$status_update[] = T_('General settings updated.');
			}

			break;


		case 'regional':
		switch( $action )
		{ // in case of regional actions
			// UPDATE regional settings
			case 'update':
				param( 'newdefault_locale', 'string', true);
				param( 'newtime_difference', 'integer', true );

				locale_updateDB();
				$Settings->set( 'default_locale', $newdefault_locale );
				$Settings->set( 'time_difference', $newtime_difference );
				$Settings->updateDB();

				$status_update[] = T_('Regional settings updated.');
				break;


			// CREATE/EDIT locale
			case 'updatelocale':
			case 'createlocale':
				param( 'newloc_locale', 'string', true);
				if( empty($newloc_locale) )
				{
					$status_update[] = '<span class="error">'.T_('You must provide a locale code!').'</span>';
					break;
				}

				param( 'newloc_enabled', 'integer', 0);
				param( 'newloc_name', 'string', true);
				param( 'newloc_charset', 'string', true);
				param( 'newloc_datefmt', 'string', true);
				param( 'newloc_timefmt', 'string', true);
				param( 'newloc_messages', 'string', true);

				if( $action == 'updatelocale' )
				{
					param( 'oldloc_locale', 'string', true);

					$query = "SELECT loc_locale FROM $tablelocales WHERE loc_locale = '$oldloc_locale'";
					if( !$DB->get_var( $query ) )
					{ // old locale is not in DB yet. Insert and disable it.
						$query = "INSERT INTO $tablelocales
											( loc_locale, loc_charset, loc_datefmt, loc_timefmt, loc_name, loc_messages, loc_priority, loc_enabled )
											VALUES ( '$oldloc_locale',
											'{$locales[$oldloc_locale]['charset']}', '{$locales[$oldloc_locale]['datefmt']}',
											'{$locales[$oldloc_locale]['timefmt']}', '{$locales[$oldloc_locale]['name']}',
											'{$locales[$oldloc_locale]['messages']}', '{$locales[$oldloc_locale]['priority']}', 0)";
						$q = $DB->query($query);
						$status_update[] = sprintf(T_("Inserted locale '%s' into database."), $oldloc_locale);
					}

					if( $oldloc_locale != $newloc_locale )
					{ // locale key was renamed, we remember to create the new one
						$l_insertnew = 1;
					}
					else
					{	// update database
						$query = "UPDATE $tablelocales
											SET loc_locale = '$newloc_locale', loc_charset = '$newloc_charset', loc_datefmt = '$newloc_datefmt',
											loc_timefmt = '$newloc_timefmt', loc_name = '$newloc_name', loc_messages = '$newloc_messages',
											loc_enabled = '$newloc_enabled'
											WHERE loc_locale = '$oldloc_locale'";
						$q = $DB->query($query);
						$status_update[] = sprintf(T_("Updated locale '%s'."), $newloc_locale);
					}
				}

				if( $action == 'createlocale' || isset( $l_insertnew ) )
				{
					$query = "REPLACE INTO $tablelocales
										( loc_locale, loc_charset, loc_datefmt, loc_timefmt, loc_name, loc_messages, loc_priority, loc_enabled )
										VALUES ( '$newloc_locale', '$newloc_charset', '$newloc_datefmt',
										'$newloc_timefmt', '$newloc_name', '$newloc_messages', '1', '$newloc_enabled')";
					$q = $DB->query($query);
					$status_update[] = sprintf(T_("Saved locale '%s'."), $newloc_locale);
				}

				break;


			// RESET locales in DB
			case 'reset':
				// reload locales
				unset( $locales );
				include( dirname(__FILE__).'/'.$admin_dirout.'/'.$conf_subdir.'/_locales.php' );
				@include( dirname(__FILE__).'/'.$admin_dirout.'/'.$conf_subdir.'/_overrides_TEST.php' );

				// delete everything from locales table
				$query = "DELETE FROM $tablelocales WHERE 1";
				$q = $DB->query($query);

				// reset default_locale
				$Settings->set( 'default_locale', $default_locale );
				$Settings->updateDB();

				$status_update[] = T_('Locales table deleted, defaults from <code>/conf/_locales.php</code> loaded.');
				break;


			// EXTRACT locale
			case 'extract':
				param( 'locale', 'string', true );
				// Get PO file for that locale:
				echo '<div class="panelinfo">';
				echo '<h3>Extracting language file for ', $locale, '...</h3>';
				$po_file = dirname(__FILE__).'/'.$core_dirout.'/'.$locales_subdir.'/'.$locales[$locale]['messages'].'/LC_MESSAGES/messages.po';
				if( ! is_file( $po_file ) )
				{
					echo '<p class="error">'.sprintf(T_('File <code>%s</code> not found.'), '/'.$locales_subdir.'/'.$locales[$locale]['messages'].'/LC_MESSAGES/messages.po').'</p>';
				}
				else
				{	// File exists:
					// Get PO file for that locale:
					$lines = file( $po_file);
					$lines[] = '';	// Adds a blank line at the end in order to ensure complete handling of the file
					$all = 0;
					$fuzzy=0;
					$untranslated=0;
					$translated=0;
					$status='-';
					$matches = array();
					$sources = array();
					$loc_vars = array();
					$ttrans = array();
					foreach ($lines as $line)
					{
						// echo 'LINE:', $line, '<br />';
						if(trim($line) == '' )
						{	// Blank line, go back to base status:
							if( $status == 't' )
							{	// ** End of a translation **:
								if( $msgstr == '' )
								{
									$untranslated++;
									// echo 'untranslated: ', $msgid, '<br />';
								}
								else
								{
									$translated++;

									// Inspect where the string is used
									$sources = array_unique( $sources );
									// echo '<p>sources: ', implode( ', ', $sources ), '</p>';
									foreach( $sources as $source )
									{
										if( !isset( $loc_vars[$source]  ) ) $loc_vars[$source] = 1;
										else $loc_vars[$source] ++;
									}

									// Save the string
									// $ttrans[] = "\n\t'".str_replace( "'", "\'", str_replace( '\"', '"', $msgid ))."' => '".str_replace( "'", "\'", str_replace( '\"', '"', $msgstr ))."',";
									// $ttrans[] = "\n\t\"$msgid\" => \"$msgstr\",";
									$ttrans[] = "\n\t'".str_replace( "'", "\'", str_replace( '\"', '"', $msgid ))."' => \"".str_replace( '$', '\$', $msgstr)."\",";

								}
							}
							$status = '-';
							$msgid = '';
							$msgstr = '';
							$sources = array();
						}
						elseif( ($status=='-') && preg_match( '#^msgid "(.*)"#', $line, $matches))
						{	// Encountered an original text
							$status = 'o';
							$msgid = $matches[1];
							// echo 'original: "', $msgid, '"<br />';
							$all++;
						}
						elseif( ($status=='o') && preg_match( '#^msgstr "(.*)"#', $line, $matches))
						{	// Encountered a translated text
							$status = 't';
							$msgstr = $matches[1];
							// echo 'translated: "', $msgstr, '"<br />';
						}
						elseif( preg_match( '#^"(.*)"#', $line, $matches))
						{	// Encountered a followup line
							if ($status=='o')
								$msgid .= $matches[1];
							elseif ($status=='t')
								$msgstr .= $matches[1];
						}
						elseif( ($status=='-') && preg_match( '@^#:(.*)@', $line, $matches))
						{	// Encountered a source code location comment
							// echo $matches[0],'<br />';
							$sourcefiles = preg_replace( '@\\\\@', '/', $matches[1] );
							// $c = preg_match_all( '@ ../../../([^:]*):@', $sourcefiles, $matches);
							$c = preg_match_all( '@ ../../../([^/:]*)@', $sourcefiles, $matches);
							for( $i = 0; $i < $c; $i++ )
							{
								$sources[] = $matches[1][$i];
							}
							// echo '<br />';
						}
						elseif(strpos($line,'#, fuzzy') === 0)
							$fuzzy++;
					}

					ksort( $loc_vars );
					foreach( $loc_vars as $source => $c )
					{
						echo $source, ' = ', $c, '<br />';
					}

					$outfile = dirname(__FILE__).'/'.$core_dirout.'/'.$locales_subdir.'/'.$locales[$locale]['messages'].'/_global.php';
					$fp = fopen( $outfile, 'w+' );
					fwrite( $fp, "<?php\n" );
					fwrite( $fp, "/*\n" );
					fwrite( $fp, " * Global lang file\n" );
					fwrite( $fp, " * This file was generated automatically from messages.po\n" );
					fwrite( $fp, " */\n" );
					fwrite( $fp, "\n\$trans['".$locales[$locale]['messages']."'] = array(" );
					// echo '<pre>';
					foreach( $ttrans as $line )
					{
						// echo htmlspecialchars( $line );
						fwrite( $fp, $line );
					}
					// echo '</pre>';
					fwrite( $fp, "\n);\n?>" );
					fclose( $fp );
				}
				echo '</div>';

				break;

			default:
				$switchcond = NULL;
				// --- DELETE locale from DB
				if( !empty($delete) )
				{
					$query = "DELETE FROM $tablelocales WHERE loc_locale = '$delete'";
					$q = $DB->query( $query );

					// reload locales
					unset( $locales );
					require( dirname(__FILE__).'/'.$admin_dirout.'/'.$conf_subdir.'/_locales.php' );
					@include( dirname(__FILE__).'/'.$admin_dirout.'/'.$conf_subdir.'/_overrides_TEST.php' );

					$status_update[] = sprintf(T_("Deleted locale '%s' from database."), $delete);
				}

				// --- SWITCH PRIORITIES -----------------
				elseif( !empty($prioup) )
				{
					$switchcond = 'return ($lval[\'priority\'] > $i && $lval[\'priority\'] < $locales[ $prioup ][\'priority\']);';
					$i = -1;
					$lswitch = $prioup;
				}
				elseif( !empty($priodown) )
				{
					$switchcond = 'return ($lval[\'priority\'] < $i && $lval[\'priority\'] > $locales[ $priodown ][\'priority\']);';
					$i = 256;
					$lswitch = $priodown;
				}

				if( !empty($switchcond) )
				{ // we want to switch priorities

					foreach( $locales as $lkey => $lval )
					{ // find nearest priority
						if( eval($switchcond) )
						{
							// remember it
							$i = $lval['priority'];
							$lswitchwith = $lkey;
						}
					}
					if( $i > -1 && $i < 256 )
					{	// switch
						#echo 'Switching prio '.$locales[ $lswitchwith ]['priority'].' with '.$locales[ $lswitch ]['priority'].'<br />';
						$locales[ $lswitchwith ]['priority'] = $locales[ $lswitch ]['priority'];
						$locales[ $lswitch ]['priority'] = $i;

						$query = "REPLACE INTO $tablelocales ( loc_locale, loc_charset, loc_datefmt, loc_timefmt, loc_name, loc_messages, loc_priority, loc_enabled )	VALUES
							( '$lswitch', '{$locales[ $lswitch ]['charset']}', '{$locales[ $lswitch ]['datefmt']}', '{$locales[ $lswitch ]['timefmt']}', '{$locales[ $lswitch ]['name']}', '{$locales[ $lswitch ]['messages']}', '{$locales[ $lswitch ]['priority']}', '{$locales[ $lswitch ]['enabled']}'),
							( '$lswitchwith', '{$locales[ $lswitchwith ]['charset']}', '{$locales[ $lswitchwith ]['datefmt']}', '{$locales[ $lswitchwith ]['timefmt']}', '{$locales[ $lswitchwith ]['name']}', '{$locales[ $lswitchwith ]['messages']}', '{$locales[ $lswitchwith ]['priority']}', '{$locales[ $lswitchwith ]['enabled']}')";
						$q = $DB->query( $query );

						$status_update[] = T_('Switched priorities.');
					}

				}
				break;
			}
			locale_overwritefromDB();
			break;


		case 'plugins':
			// UPDATE plug-ins:
			break;

	}

	if( count($status_update) )
	{
		echo '<div class="panelinfo">';
		foreach( $status_update as $stmsg ) echo '<p>'.$stmsg.'</p>';
		echo '</div>';
	}
}

// Check permission:
$current_User->check_perm( 'options', 'view', true );
?>


	<div class="pt" >
		<ul class="hack">
			<li><!-- Yes, this empty UL is needed! It's a DOUBLE hack for correct CSS display --></li>
		</ul>
		<div class="panelblocktabs">
			<ul class="tabs">
			<?php
				if( $tab == 'general' )
					echo '<li class="current">';
				else
					echo '<li>';
				echo '<a href="b2options.php">'. T_('General'). '</a></li>';

				if( $tab == 'regional' )
					echo '<li class="current">';
				else
					echo '<li>';
				echo '<a href="b2options.php?tab=regional';
				if( $notransext ) echo '&amp;notransext=1';
				echo '">'. T_('Regional'). '</a></li>';

				if( $tab == 'plugins' )
					echo '<li class="current">';
				else
					echo '<li>';
				echo '<a href="b2options.php?tab=plugins">'. T_('Plug-ins'). '</a></li>';
			?>
			</ul>
		</div>
	</div>
	<div class="tabbedpanelblock">
	<?php
		switch( $tab )
		{
			case 'general':
				// ---------- GENERAL OPTIONS ----------
				require_once dirname(__FILE__).'/_set_general.form.php';
				break;

			case 'regional':
				// ---------- REGIONAL OPTIONS ----------
				require_once dirname(__FILE__).'/_set_regional.form.php';
				break;

			case 'plugins':
				// ---------- PLUGIN OPTIONS ----------
				require_once dirname(__FILE__).'/_set_plugins.form.php';
				break;
		}
		?>
	</div>
<?php
	require( dirname(__FILE__). '/_footer.php' );
?>