Page Menu
Home
Code
Search
Configure Global Search
Log In
Files
F1133324
settings.php
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
2 KB
Subscribers
None
settings.php
View Options
<?php
/**
* Settings
*
* Zed. The immensity of stars. The HyperShip. The people.
*
* (c) 2010, Dereckson, some rights reserved.
* Released under BSD license.
*
* This controller allows user to set its preferences, according the Settings
* classes, and the preferences.xml document.
*
* It handles the /settings URL.
*
* @package Zed
* @subpackage Controllers
* @author Sébastien Santoro aka Dereckson <dereckson@espace-win.org>
* @copyright 2010 Sébastien Santoro aka Dereckson
* @license http://www.opensource.org/licenses/bsd-license.php BSD
* @version 0.1
* @link http://scherzo.dereckson.be/doc/zed
* @link http://zed.dereckson.be/
* @filesource
*
* @todo replace the on the fly preferences.xml code generation by a cached code generation
* @todo reduce the number of for loops in this controller
*/
use
Zed\Engines\Settings\SettingException
;
use
Zed\Engines\Settings\Settings
;
//
// Loads settings
//
lang_load
(
'settings.conf'
);
try
{
$settings
=
new
Settings
(
'data/settings/preferences.xml'
);
$settings
->
targets
=
[
"CurrentPerso"
=>
$CurrentPerso
,
"CurrentUser"
=>
$CurrentUser
,
];
}
catch
(
SettingException
$ex
)
{
message_die
(
GENERAL_ERROR
,
$ex
->
getMessage
(),
"Settings error"
);
}
///
/// Handle request
///
//Selects relevant settings page
$pages
=
$settings
->
pages
;
if
(
count
(
$url
)
>
1
)
{
//From url: /settings/account -> page account
if
(
array_key_exists
(
$url
[
1
],
$settings
->
pages
))
{
$page
=
$pages
[
$url
[
1
]];
}
else
{
message_die
(
GENERAL_ERROR
,
"/settings/$url[1] isn't a valid setting page"
);
}
}
else
{
//Default page
$page
=
array_shift
(
$pages
);
}
//Pages links
foreach
(
$settings
->
pages
as
$tmppage
)
{
$pagesLinks
[
$tmppage
->
id
]
=
$tmppage
->
title
;
}
//
// Handles form
//
if
(
array_key_exists
(
'settings_page'
,
$_POST
))
{
if
(
$_POST
[
'settings_page'
]
==
$page
->
id
)
{
//Updates settings
$errors
=
[];
$page
->
handleForm
(
$errors
);
if
(
count
(
$errors
))
{
//Prints error message
$smarty
->
assign
(
'WAP'
,
implode
(
'<br />'
,
$errors
));
}
}
else
{
//The field settings.page isn't the current page
//Prints an HACK_ERROR to avoid to save properties with the same names.
$id_current
=
$page
->
id
;
$id_toSave
=
$_POST
[
'settings_page'
];
message_die
(
HACK_ERROR
,
"You're on /settings/$id_current but you want to update /settings/$id_toSave"
);
}
}
//
// HTML output
//
//Serves header
define
(
'DIJIT'
,
true
);
$title
=
lang_get
(
'Settings'
);
$smarty
->
assign
(
'PAGE_TITLE'
,
$title
);
include
(
'header.php'
);
//Serves settings page;
$smarty
->
assign
(
'page'
,
$page
);
$smarty
->
assign
(
'pages'
,
$pagesLinks
);
$smarty
->
display
(
'settings_page.tpl'
);
//Servers footer
$smarty
->
assign
(
'screen'
,
"Settings > "
.
$page
->
title
);
include
(
'footer.php'
);
File Metadata
Details
Attached
Mime Type
text/x-php
Expires
Sun, Jun 29, 10:45 (1 d, 14 h)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
21447
Default Alt Text
settings.php (2 KB)
Attached To
rZED Zed
Event Timeline
Log In to Comment