Finished theme manager to the point where it's in a working state in Firefox and hopefully IE.
--- a/includes/clientside/static/theme-manager.js Sat Mar 01 18:54:33 2008 -0500
+++ b/includes/clientside/static/theme-manager.js Sat Mar 01 18:55:30 2008 -0500
@@ -40,36 +40,56 @@
var status = document.createElement('div');
status.className = 'status';
thediv.appendChild(status);
- setTimeout(function()
+
+ var req = toJSONString({
+ mode: 'install',
+ theme_id: theme_id
+ });
+ // we've finished nukeing the existing interface, request editor data
+ ajaxPost(makeUrlNS('Admin', 'ThemeManager/action.json'), 'r=' + ajaxEscape(req), function()
{
- var theme_list = document.getElementById('theme_list_edit');
-
- var btn = document.createElement('div');
- btn.className = 'themebutton';
- btn.style.backgroundImage = thediv.style.backgroundImage;
- btn.id = 'themebtn_edit_' + theme_id;
-
- var a = document.createElement('a');
- a.className = 'tb-inner';
- a.appendChild(document.createTextNode($lang.get('acptm_btn_theme_edit')));
- a.appendChild(document.createTextNode("\n"));
- a.theme_id = theme_id;
- a.onclick = function()
+ if ( ajax.readyState == 4 && ajax.status == 200 )
{
- ajaxEditTheme(this.theme_id);
- return false;
+ var response = String(ajax.responseText + '');
+ if ( response.substr(0, 1) == '{' )
+ {
+ response = parseJSON(response);
+ if ( response.mode == 'error' )
+ {
+ alert(response.error);
+ return false;
+ }
+ }
+
+ var theme_list = document.getElementById('theme_list_edit');
+
+ var btn = document.createElement('div');
+ btn.className = 'themebutton';
+ btn.style.backgroundImage = thediv.style.backgroundImage;
+ btn.id = 'themebtn_edit_' + theme_id;
+
+ var a = document.createElement('a');
+ a.className = 'tb-inner';
+ a.appendChild(document.createTextNode($lang.get('acptm_btn_theme_edit')));
+ a.appendChild(document.createTextNode("\n"));
+ a.theme_id = theme_id;
+ a.onclick = function()
+ {
+ ajaxEditTheme(this.theme_id);
+ return false;
+ }
+ a.href = '#';
+ var span = document.createElement('span');
+ span.className = 'themename';
+ span.appendChild(document.createTextNode(thediv.getAttribute('enano:themename')));
+ a.appendChild(span);
+ btn.appendChild(a);
+ btn.setAttribute('enano:themename', thediv.getAttribute('enano:themename'));
+ theme_list.appendChild(btn);
+
+ thediv.parentNode.removeChild(thediv);
}
- a.href = '#';
- var span = document.createElement('span');
- span.className = 'themename';
- span.appendChild(document.createTextNode(thediv.getAttribute('enano:themename')));
- a.appendChild(span);
- btn.appendChild(a);
- btn.setAttribute('enano:themename', thediv.getAttribute('enano:themename'));
- theme_list.appendChild(btn);
-
- thediv.parentNode.removeChild(thediv);
- }, 3000);
+ });
}
function ajaxEditTheme(theme_id)
@@ -78,15 +98,24 @@
// ajax request to the theme manager for the theme info via JSON
var theme_list = document.getElementById('theme_list_edit').parentNode;
var backgroundImage = document.getElementById('themebtn_edit_' + theme_id).style.backgroundImage;
+ /*
for ( var i = 0; i < theme_list.childNodes.length; i++ )
{
var el = theme_list.childNodes[i];
if ( el.tagName )
domOpacity(el, 100, 0, 1000);
}
+ */
+ var thediv = document.getElementById('themebtn_edit_' + theme_id);
+ if ( !thediv )
+ return false;
+ thediv.removeChild(thediv.getElementsByTagName('a')[0]);
+ var status = document.createElement('div');
+ status.className = 'status';
+ thediv.appendChild(status);
+
setTimeout(function()
{
- theme_list.innerHTML = '';
var req = toJSONString({
mode: 'fetch_theme',
theme_id: theme_id
@@ -96,6 +125,7 @@
{
if ( ajax.readyState == 4 && ajax.status == 200 )
{
+ theme_list.innerHTML = '';
var response = String(ajax.responseText + '');
if ( response.substr(0, 1) != '{' )
{
@@ -112,7 +142,7 @@
ajaxBuildThemeEditor(response, theme_list);
}
});
- }, 1050);
+ }, 200);
}
function ajaxBuildThemeEditor(data, target)
@@ -152,6 +182,7 @@
target.appendChild(l_name);
target.appendChild(document.createElement('br'));
+ target.appendChild(document.createElement('br'));
// Field: default style
var l_style = document.createElement('label');
@@ -177,6 +208,7 @@
target.appendChild(l_style);
target.appendChild(document.createElement('br'));
+ target.appendChild(document.createElement('br'));
// Default theme
target.appendChild(document.createTextNode($lang.get('acptm_field_default_theme') + ' '));
@@ -196,21 +228,433 @@
}
target.appendChild(l_default);
+ target.appendChild(document.createElement('br'));
+ target.appendChild(document.createElement('br'));
+
+ // Disable theme
+ var disable_span = document.createElement('span');
+ disable_span.appendChild(document.createTextNode($lang.get('acptm_field_disable_title') + ' '));
+ target.appendChild(disable_span);
+ var l_disable = document.createElement('label');
+ var f_disable = document.createElement('input');
+ f_disable.type = 'checkbox';
+ f_disable.id = 'themeed_field_disable';
+ if ( !data.enabled )
+ f_disable.setAttribute('checked', 'checked');
+ l_disable.style.fontWeight = 'bold';
+ l_disable.appendChild(f_disable);
+ l_disable.appendChild(document.createTextNode($lang.get('acptm_field_disable')));
+ target.appendChild(l_disable);
+
// Availability policy
var h3 = document.createElement('h3');
h3.appendChild(document.createTextNode($lang.get('acptm_heading_theme_groups')));
target.appendChild(h3);
+ // Label for the whole field
+ var p_d_policy = document.createElement('p');
+ p_d_policy.style.fontWeight = 'bold';
+ p_d_policy.appendChild(document.createTextNode($lang.get('acptm_field_policy')));
+ target.appendChild(p_d_policy);
+
+ // Wrapper for options
+ var p_f_policy = document.createElement('p');
+
+ // Option: allow all
+ var l_policy_allow_all = document.createElement('label');
+ var f_policy_allow_all = document.createElement('input');
+ f_policy_allow_all.type = 'radio';
+ f_policy_allow_all.id = 'themeed_field_policy_allow_all';
+ f_policy_allow_all.name = 'themeed_field_policy';
+ f_policy_allow_all.value = 'allow_all';
+ l_policy_allow_all.appendChild(f_policy_allow_all);
+ l_policy_allow_all.appendChild(document.createTextNode(' ' + $lang.get('acptm_field_policy_allow_all')));
+ if ( data.group_policy == 'allow_all' )
+ {
+ f_policy_allow_all.setAttribute('checked', 'checked');
+ }
+
+ // Option: whitelist
+ var l_policy_whitelist = document.createElement('label');
+ var f_policy_whitelist = document.createElement('input');
+ f_policy_whitelist.type = 'radio';
+ f_policy_whitelist.id = 'themeed_field_policy_whitelist';
+ f_policy_whitelist.name = 'themeed_field_policy';
+ f_policy_whitelist.value = 'whitelist';
+ l_policy_whitelist.appendChild(f_policy_whitelist);
+ l_policy_whitelist.appendChild(document.createTextNode(' ' + $lang.get('acptm_field_policy_whitelist')));
+ if ( data.group_policy == 'whitelist' )
+ {
+ f_policy_whitelist.setAttribute('checked', 'checked');
+ }
+
+ // Option: blacklist
+ var l_policy_blacklist = document.createElement('label');
+ var f_policy_blacklist = document.createElement('input');
+ f_policy_blacklist.type = 'radio';
+ f_policy_blacklist.id = 'themeed_field_policy_blacklist';
+ f_policy_blacklist.name = 'themeed_field_policy';
+ f_policy_blacklist.value = 'blacklist';
+ l_policy_blacklist.appendChild(f_policy_blacklist);
+ l_policy_blacklist.appendChild(document.createTextNode(' ' + $lang.get('acptm_field_policy_blacklist')));
+ if ( data.group_policy == 'blacklist' )
+ {
+ f_policy_blacklist.setAttribute('checked', 'checked');
+ }
+ f_policy_allow_all.onclick = ajaxThemeManagerHandlePolicyClick;
+ f_policy_whitelist.onclick = ajaxThemeManagerHandlePolicyClick;
+ f_policy_blacklist.onclick = ajaxThemeManagerHandlePolicyClick;
+
+ p_f_policy.appendChild(l_policy_allow_all);
+ p_f_policy.appendChild(document.createElement('br'));
+ p_f_policy.appendChild(l_policy_whitelist);
+ p_f_policy.appendChild(document.createElement('br'));
+ p_f_policy.appendChild(l_policy_blacklist);
+
+ target.appendChild(p_d_policy);
+ target.appendChild(p_f_policy);
+
+ var div_acl = document.createElement('div');
+ div_acl.id = 'themeed_acl_box';
+ div_acl.style.margin = '0 0 10px 30px';
+
+ var h3_g = document.createElement('h3');
+ h3_g.appendChild(document.createTextNode($lang.get('acptm_field_acl_heading_groups')));
+ div_acl.appendChild(h3_g);
+
+ var div_groups = document.createElement('div');
+ div_groups.style.border = '1px solid #E8E8E8';
+ div_groups.id = 'themeed_group_list';
+
+ // Group list
+ for ( var i in data.group_names )
+ {
+ var g_name = data.group_names[i];
+ var check = document.createElement('input');
+ check.type = 'checkbox';
+ if ( in_array("g:" + i, data.group_list) )
+ {
+ check.setAttribute('checked', 'checked');
+ }
+ check.group_id = parseInt(i);
+ var lbl_g_acl = document.createElement('label');
+ lbl_g_acl.appendChild(check);
+ // FIXME: l10n on group name
+ lbl_g_acl.appendChild(document.createTextNode(g_name));
+ div_groups.appendChild(lbl_g_acl);
+ div_groups.appendChild(document.createElement('br'));
+ }
+ div_acl.appendChild(div_groups);
+
+ var h3_u = document.createElement('h3');
+ h3_u.appendChild(document.createTextNode($lang.get('acptm_field_acl_heading_users')));
+ div_acl.appendChild(h3_u);
+
+ // User addition field
+ var frm = document.createElement('form');
+ frm.action = 'javascript:ajaxThemeManagerHandleUserAdd();';
+ frm.appendChild(document.createTextNode($lang.get('acptm_field_acl_add_user')));
+ var f_useradd = document.createElement('input');
+ f_useradd.type = 'text';
+ f_useradd.id = 'themeed_field_adduser';
+ f_useradd.onkeyup = function(e)
+ {
+ new AutofillUsername(this, e, false);
+ }
+
+ frm.appendChild(f_useradd);
+ div_acl.appendChild(frm);
+
+ div_acl.appendChild(document.createElement('br'));
+
+ // User list
+ var div_users = document.createElement('div');
+ div_users.style.border = '1px solid #E8E8E8';
+ div_users.style.padding = '4px';
+ div_users.id = 'themeed_user_list';
for ( var i = 0; i < data.group_list.length; i++ )
{
+ var id = data.group_list[i];
+ if ( id.substr(0, 2) != 'u:' )
+ continue;
+ var uid = id.substr(2);
+ var username = data.usernames[uid];
+ var useritem = document.createElement('span');
+ useritem.appendChild(document.createTextNode(username + ' '));
+ useritem.userid = parseInt(uid);
+ var deleter = document.createElement('a');
+ deleter.href = '#';
+ deleter.onclick = function()
+ {
+ ajaxThemeManagerHandleUserRemoval(this);
+ return false;
+ }
+ deleter.appendChild(document.createTextNode('[X]'));
+ useritem.appendChild(deleter);
+ div_users.appendChild(useritem);
+ div_users.appendChild(document.createElement('br'));
}
+ div_acl.appendChild(div_users);
+
+ target.appendChild(div_acl);
+
+ ajaxThemeManagerHandlePolicyClick();
var clearer = document.createElement('span');
clearer.className = 'menuclear';
target.appendChild(clearer);
+ // Theme ID
+ var tid = document.createElement('input');
+ tid.type = 'hidden';
+ tid.id = 'themeed_theme_id';
+ tid.value = data.theme_id;
+ target.appendChild(tid);
+
+ // Save button
+ var raquo = unescape('%BB');
+ var savebtn = document.createElement('input');
+ savebtn.type = 'button';
+ savebtn.style.fontWeight = 'bold';
+ savebtn.value = $lang.get('etc_save_changes') + ' ' + raquo;
+ savebtn.onclick = function()
+ {
+ ajaxThemeManagerHandleSaveRequest();
+ }
+ target.appendChild(savebtn);
+
+ target.appendChild(document.createTextNode(' '));
+
+ // Cancel button
+ var savebtn = document.createElement('input');
+ savebtn.type = 'button';
+ savebtn.value = $lang.get('etc_cancel');
+ savebtn.onclick = function()
+ {
+ ajaxPage(namespace_list['Admin'] + 'ThemeManager');
+ }
+ target.appendChild(savebtn);
+
+ target.appendChild(document.createTextNode(' '));
+
+ // Uninstall button
+ var savebtn = document.createElement('input');
+ savebtn.type = 'button';
+ savebtn.value = $lang.get('acptm_btn_uninstall_theme');
+ savebtn.style.color = '#D84308';
+ savebtn.onclick = function()
+ {
+ if ( !confirm($lang.get('acptm_msg_uninstall_confirm')) )
+ return false;
+ ajaxThemeManagerHandleUninstallClick();
+ }
+ target.appendChild(savebtn);
+
// Fade it all in
domOpacity(target, 0, 100, 500);
f_name.focus();
}
+
+function ajaxThemeManagerHandlePolicyClick()
+{
+ if ( document.getElementById('themeed_field_policy_allow_all').checked )
+ {
+ document.getElementById('themeed_acl_box').style.display = 'none';
+ }
+ else if ( document.getElementById('themeed_field_policy_whitelist').checked || document.getElementById('themeed_field_policy_blacklist').checked )
+ {
+ document.getElementById('themeed_acl_box').style.display = 'block';
+ }
+}
+
+function ajaxThemeManagerHandleUserAdd()
+{
+ var f_useradd = document.getElementById('themeed_field_adduser');
+ f_useradd.setAttribute('disabled', 'disabled');
+ var parent = f_useradd.parentNode;
+ var img = document.createElement('img');
+ img.src = ajax_load_icon;
+ img.id = 'themeed_useradd_status';
+ img.style.marginLeft = '10px';
+ insertAfter(parent, img, f_useradd);
+
+ var req = toJSONString({
+ mode: 'uid_lookup',
+ username: f_useradd.value
+ });
+ ajaxPost(makeUrlNS('Admin', 'ThemeManager/action.json'), 'r=' + ajaxEscape(req), function()
+ {
+ if ( ajax.readyState == 4 && ajax.status == 200 )
+ {
+ var img = document.getElementById('themeed_useradd_status');
+ var f_useradd = document.getElementById('themeed_field_adduser');
+
+ f_useradd.disabled = null;
+ img.parentNode.removeChild(img);
+
+ // process response
+ var response = String(ajax.responseText + '');
+ if ( response.substr(0, 1) != '{' )
+ {
+ alert(response);
+ return false;
+ }
+ response = parseJSON(response);
+ if ( response.mode == 'error' )
+ {
+ alert(response.error);
+ return false;
+ }
+
+ var uid = parseInt(response.uid);
+ var username = response.username;
+
+ // Loop through the list of users and remove any existing ones with the same uid
+ var div_users = document.getElementById('themeed_user_list');
+ var children = div_users.getElementsByTagName('span');
+ for ( var i = 0; i < children.length; i++ )
+ {
+ var child = children[i];
+ if ( child.userid == uid )
+ {
+ // the sister is the br element next to the span with the checkbox/text
+ var sister = child.nextSibling;
+ div_users.removeChild(child);
+ div_users.removeChild(sister);
+ break;
+ }
+ }
+
+ var useritem = document.createElement('span');
+ useritem.appendChild(document.createTextNode(username + ' '));
+ useritem.userid = parseInt(uid);
+ var deleter = document.createElement('a');
+ deleter.href = '#';
+ deleter.onclick = function()
+ {
+ ajaxThemeManagerHandleUserRemoval(this);
+ return false;
+ }
+ deleter.appendChild(document.createTextNode('[X]'));
+ useritem.appendChild(deleter);
+ div_users.appendChild(useritem);
+ div_users.appendChild(document.createElement('br'));
+ }
+ });
+}
+
+function ajaxThemeManagerHandleUserRemoval(el)
+{
+ var parent = el.parentNode;
+ var uid = parent.userid;
+
+ var grandparent = parent.parentNode;
+ var sister = parent.nextSibling;
+ grandparent.removeChild(parent);
+ grandparent.removeChild(sister);
+}
+
+function ajaxThemeManagerHandleSaveRequest()
+{
+ // Build a JSON condensed request
+ var md = false;
+ if ( document.getElementById('themeed_field_default') )
+ {
+ if ( document.getElementById('themeed_field_default').checked )
+ {
+ md = true;
+ }
+ }
+ var policy = 'allow_all';
+ if ( document.getElementById('themeed_field_policy_whitelist').checked )
+ policy = 'whitelist';
+ else if ( document.getElementById('themeed_field_policy_blacklist').checked )
+ policy = 'blacklist';
+ var json_packet = {
+ theme_id: document.getElementById('themeed_theme_id').value,
+ theme_name: document.getElementById('themeed_field_name').value,
+ default_style: document.getElementById('themeed_field_style').value,
+ make_default: md,
+ group_policy: policy,
+ enabled: ( document.getElementById('themeed_field_disable').checked ? false : true )
+ };
+ var acl_list = [];
+ var checks = document.getElementById('themeed_group_list').getElementsByTagName('input');
+ for ( var i = 0; i < checks.length; i++ )
+ {
+ if ( checks[i].checked )
+ acl_list.push('g:' + checks[i].group_id);
+ }
+ var spans = document.getElementById('themeed_user_list').getElementsByTagName('span');
+ for ( var i = 0; i < spans.length; i++ )
+ {
+ if ( spans[i].userid )
+ acl_list.push('u:' + spans[i].userid);
+ }
+ json_packet.group_list = acl_list;
+
+ var json_send = {
+ mode: 'save_theme',
+ theme_data: json_packet
+ };
+
+ json_send = ajaxEscape(toJSONString(json_send));
+
+ // Request the save
+ var parent = document.getElementById('ajaxPageContainer');
+ ajaxPost(makeUrlNS('Admin', 'ThemeManager/action.json'), 'r=' + json_send, function()
+ {
+ if ( ajax.readyState == 4 && ajax.status == 200 )
+ {
+ // process response
+ var response = String(ajax.responseText + '');
+ if ( response.substr(0, 1) != '{' )
+ {
+ // For this we actually *expect* an HTML response.
+ parent.innerHTML = response;
+ return false;
+ }
+ response = parseJSON(response);
+ if ( response.mode == 'error' )
+ {
+ alert(response.error);
+ return false;
+ }
+ }
+ });
+}
+
+function ajaxThemeManagerHandleUninstallClick()
+{
+ var theme_id = document.getElementById('themeed_theme_id').value;
+ var json_send = {
+ mode: 'uninstall',
+ theme_id: theme_id
+ };
+
+ json_send = ajaxEscape(toJSONString(json_send));
+
+ // Request the action
+ var parent = document.getElementById('ajaxPageContainer');
+ ajaxPost(makeUrlNS('Admin', 'ThemeManager/action.json'), 'r=' + json_send, function()
+ {
+ if ( ajax.readyState == 4 && ajax.status == 200 )
+ {
+ // process response
+ var response = String(ajax.responseText + '');
+ if ( response.substr(0, 1) != '{' )
+ {
+ // For this we actually *expect* an HTML response.
+ parent.innerHTML = response;
+ return false;
+ }
+ response = parseJSON(response);
+ if ( response.mode == 'error' )
+ {
+ alert(response.error);
+ return false;
+ }
+ }
+ });
+}
--- a/language/english/admin.json Sat Mar 01 18:54:33 2008 -0500
+++ b/language/english/admin.json Sat Mar 01 18:55:30 2008 -0500
@@ -211,6 +211,10 @@
field_disablesite: 'Disable this site',
field_disablesite_message: 'Message to show to users:',
+ // Section: default theme
+ heading_default_theme: 'Visual defaults',
+ field_defualt_theme: 'Default theme for guests and new users:',
+
// Main section: users and communication
heading_users: 'Users and communication',
@@ -317,7 +321,7 @@
// Section Defective By Design link
heading_dbd: 'Defective By Design Anti-DRM button',
dbd_intro: 'The Enano project is strongly against Digital Restrictions Management.',
- dbd_explain: 'DRM removes the freedoms that every consumer should have: to freely copy and use digital media items they legally purchased to their own devices. Showing your opposition to DRM is as easy as checking the box below to place a link to <a href="http://www.defectivebydesign.org">DefectiveByDesign.org</a> on your sidebar.',
+ dbd_explain: 'DRM removes the freedoms that every consumer should have: to freely copy and use digital media items they legally purchased to their own devices. Furthermore, DRM technologies can lock you into a specific brand or product, thus stifling interoperability. Showing your opposition to DRM is as easy as checking the box below to place a link to <a href="http://www.defectivebydesign.org">DefectiveByDesign.org</a> on your sidebar.',
field_stopdrm: 'Help stop DRM by placing a link to DBD on the sidebar!',
// Save button
@@ -449,7 +453,28 @@
field_default_theme: 'Site-wide default theme:',
field_default_msg_current: 'This is the current default',
field_default_btn_make_default: 'Make this the default theme when I click Save',
+ field_disable_title: 'Disable theme: ',
+ field_disable: 'Prevent all users and guests from using this theme',
heading_theme_groups: 'User and group policy',
+ field_policy: 'Theme access policy:',
+ field_policy_allow_all: 'Allow everyone to use this theme',
+ field_policy_whitelist: 'Only allow the users and groups I select below',
+ field_policy_blacklist: 'Allow everyone except what I select below',
+ field_acl_heading_groups: 'Groups',
+ field_acl_heading_users: 'Users',
+ field_acl_add_user: 'Add a user: ',
+ btn_uninstall_theme: 'Uninstall theme',
+ msg_uninstall_confirm: 'Are you sure you want to uninstall this theme?',
+
+ err_invalid_username: 'Please enter a valid username.',
+ err_username_not_found: 'The user you entered does not exist.',
+ err_save_validation_failed: 'One or more of the fields in the form is incorrect. Please ensure that you have entered a proper value for all of the fields in the theme editing form, and then click %this.etc_save_changes% again.',
+ err_uninstalling_default: 'You cannot uninstall the default theme.',
+ err_uninstalling_oxygen: 'You cannot uninstall the Oxygen theme because it\'s used for important functions such as database errors.',
+ warn_cant_disable_default: 'Please note that the theme was not disabled because it is currently the default.',
+ warn_access_with_default: 'If you selected to whitelist or blacklist certain users, that choice will not apply to guests because this is the default theme.',
+ msg_save_success: 'Your changes to this theme have been saved.',
+ msg_uninstall_success: 'The selected theme has been uninstalled.',
},
acpdb: {
err_not_supported_title: 'Not supported',
--- a/plugins/SpecialAdmin.php Sat Mar 01 18:54:33 2008 -0500
+++ b/plugins/SpecialAdmin.php Sat Mar 01 18:55:30 2008 -0500
@@ -275,6 +275,10 @@
setConfig('pw_strength_minimum', $strength);
}
+ // Default theme
+ $default_theme = ( isset($template->named_theme_list[@$_POST['default_theme']]) ) ? $_POST['default_theme'] : $template->theme_list[0]['theme_id'];
+ setConfig('theme_default', $default_theme);
+
setConfig('register_tou', RenderMan::preprocess_text($_POST['register_tou'], true, false));
// Account lockout policy
@@ -495,6 +499,28 @@
</td>
</tr>
+ <!-- Default theme -->
+
+ <tr><th class="subhead" colspan="2"><?php echo $lang->get('acpgc_heading_default_theme'); ?></th></tr>
+
+ <tr>
+ <td class="row2">
+ <?php echo $lang->get('acpgc_field_defualt_theme'); ?>
+ </td>
+ <td class="row2">
+ <select name="default_theme">
+ <?php
+ foreach ( $template->named_theme_list as $theme_id => $theme_data )
+ {
+ $theme_name = htmlspecialchars($theme_data['theme_name']);
+ $selected = ( $theme_id === getConfig('theme_default') ) ? ' selected="selected"' : '';
+ echo " <option value=\"$theme_id\"$selected>$theme_name</option>\n ";
+ }
+ ?>
+ </select>
+ </td>
+ </tr>
+
</table>
</div>
--- a/plugins/admin/ThemeManager.php Sat Mar 01 18:54:33 2008 -0500
+++ b/plugins/admin/ThemeManager.php Sat Mar 01 18:55:30 2008 -0500
@@ -12,7 +12,7 @@
* warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for details.
*/
-function page_Admin_ThemeManager()
+function page_Admin_ThemeManager($force_no_json = false)
{
global $db, $session, $paths, $template, $plugins; // Common objects
global $lang;
@@ -83,7 +83,7 @@
$installable = array_flip($installable);
// AJAX code
- if ( $paths->getParam(0) === 'action.json' )
+ if ( $paths->getParam(0) === 'action.json' && !$force_no_json )
{
return ajaxServlet_Admin_ThemeManager($themes);
}
@@ -209,290 +209,211 @@
// Build a list of group names
$row['group_names'] = array();
- foreach ( $row['group_list'] as $group_id )
+ $q = $db->sql_query('SELECT group_id, group_name FROM ' . table_prefix . 'groups;');
+ if ( !$q )
+ $db->die_json();
+ while ( $gr = $db->fetchrow() )
{
- $row['group_names'][$group_id] = '';
+ $row['group_names'][ intval($gr['group_id']) ] = $gr['group_name'];
}
- if ( count($row['group_names']) > 0 )
+ $db->free_result();
+
+ // Build a list of usernames
+ $row['usernames'] = array();
+ foreach ( $row['group_list'] as $el )
{
- $idlist = 'group_id = ' . implode(' OR group_id = ', array_keys($row['group_names']));
- $q = $db->sql_query('SELECT group_id, group_name FROM ' . table_prefix . "groups WHERE $idlist;");
+ if ( !preg_match('/^u:([0-9]+)$/', $el, $match) )
+ continue;
+ $uid =& $match[1];
+ $q = $db->sql_query('SELECT username FROM ' . table_prefix . "users WHERE user_id = $uid;");
if ( !$q )
$db->die_json();
- while ( $gr = $db->fetchrow_num() )
+ if ( $db->numrows() < 1 )
{
- list($group_id, $group_name) = $gr;
- $row['group_names'][$group_id] = $group_name;
+ $db->free_result();
+ continue;
}
+ list($username) = $db->fetchrow_num();
+ $row['usernames'][$uid] = $username;
+ $db->free_result();
}
echo enano_json_encode($row);
break;
+ case 'uid_lookup':
+ $username = @$request['username'];
+ if ( empty($username) )
+ {
+ die(enano_json_encode(array(
+ 'mode' => 'error',
+ 'error' => $lang->get('acptm_err_invalid_username')
+ )));
+ }
+ $username = $db->escape(strtolower($username));
+ $q = $db->sql_query('SELECT user_id, username FROM ' . table_prefix . "users WHERE " . ENANO_SQLFUNC_LOWERCASE . "(username) = '$username';");
+ if ( !$q )
+ $db->die_json();
+
+ if ( $db->numrows() < 1 )
+ {
+ die(enano_json_encode(array(
+ 'mode' => 'error',
+ 'error' => $lang->get('acptm_err_username_not_found')
+ )));
+ }
+
+ list($uid, $username_real) = $db->fetchrow_num();
+ $db->free_result();
+
+ echo enano_json_encode(array(
+ 'uid' => $uid,
+ 'username' => $username_real
+ ));
+ break;
+ case 'save_theme':
+ if ( !isset($request['theme_data']) )
+ {
+ die(enano_json_encode(array(
+ 'mode' => 'error',
+ 'error' => 'No theme data in request'
+ )));
+ }
+ $theme_data =& $request['theme_data'];
+ // Perform integrity check on theme data
+ $chk_theme_exists = isset($themes[@$theme_data['theme_id']]);
+ $theme_data['theme_name'] = trim(@$theme_data['theme_name']);
+ $chk_name_good = !empty($theme_data['theme_name']);
+ $chk_policy_good = in_array(@$theme_data['group_policy'], array('allow_all', 'whitelist', 'blacklist'));
+ $chk_grouplist_good = true;
+ foreach ( $theme_data['group_list'] as $acl_entry )
+ {
+ if ( !preg_match('/^(u|g):[0-9]+$/', $acl_entry) )
+ {
+ $chk_grouplist_good = false;
+ break;
+ }
+ }
+ $chk_style_good = @in_array(@$theme_data['default_style'], @$themes[@$theme_data['theme_id']]['css']);
+ if ( !$chk_theme_exists || !$chk_name_good || !$chk_policy_good || !$chk_grouplist_good || !$chk_style_good )
+ {
+ die(enano_json_encode(array(
+ 'mode' => 'error',
+ 'error' => $lang->get('acptm_err_save_validation_failed')
+ )));
+ }
+
+ $enable = ( $theme_data['enabled'] ) ? '1' : '0';
+ $theme_default = getConfig('theme_default');
+ $warn_default = ( $theme_default === $theme_data['theme_id'] || $theme_data['make_default'] ) ?
+ ' ' . $lang->get('acptm_warn_access_with_default') . ' ' :
+ ' ';
+ if ( $enable == 0 && ( $theme_default === $theme_data['theme_id'] || $theme_data['make_default'] ) )
+ {
+ $enable = '1';
+ $warn_default .= $lang->get('acptm_warn_cant_disable_default');
+ }
+
+ // We're good. Update the theme...
+ $q = $db->sql_query('UPDATE ' . table_prefix . 'themes SET
+ theme_name = \'' . $db->escape($theme_data['theme_name']) . '\',
+ default_style = \'' . $db->escape($theme_data['default_style']) . '\',
+ group_list = \'' . $db->escape(enano_json_encode($theme_data['group_list'])) . '\',
+ group_policy = \'' . $db->escape($theme_data['group_policy']) . '\',
+ enabled = ' . $enable . '
+ WHERE theme_id = \'' . $db->escape($theme_data['theme_id']) . '\';');
+ if ( !$q )
+ $db->die_json();
+
+ if ( $theme_data['make_default'] )
+ {
+ setConfig('theme_default', $theme_data['theme_id']);
+ }
+
+ echo '<div class="info-box"><b>' . $lang->get('acptm_msg_save_success') . '</b>' . $warn_default . '</div>';
+
+ page_Admin_ThemeManager(true);
+ break;
+ case 'install':
+ $theme_id =& $request['theme_id'];
+ if ( !isset($themes[$theme_id]) )
+ {
+ die(enano_json_encode(array(
+ 'mode' => 'error',
+ 'error' => 'Theme was deleted from themes/ directory or couldn\'t read theme metadata from filesystem'
+ )));
+ }
+ if ( !isset($themes[$theme_id]['css'][0]) )
+ {
+ die(enano_json_encode(array(
+ 'mode' => 'error',
+ 'error' => 'Theme doesn\'t have any files in css/, thus it can\'t be installed. (translators: l10n?)'
+ )));
+ }
+ // build dataset
+ $theme_name = $db->escape($themes[$theme_id]['theme_name']);
+ $default_style = $db->escape($themes[$theme_id]['css'][0]);
+ $theme_id = $db->escape($theme_id);
+
+ // insert it
+ $q = $db->sql_query('INSERT INTO ' . table_prefix . "themes(theme_id, theme_name, default_style, enabled, group_list, group_policy)\n"
+ . " VALUES( '$theme_id', '$theme_name', '$default_style', 1, '[]', 'allow_all' );");
+ if ( !$q )
+ $db->die_json();
+
+ // The response isn't processed unless it's in JSON.
+ echo 'Roger that, over and out.';
+
+ break;
+ case 'uninstall':
+ $theme_id =& $request['theme_id'];
+ $theme_default = getConfig('theme_default');
+
+ // Validation
+ if ( !isset($themes[$theme_id]) )
+ {
+ die(enano_json_encode(array(
+ 'mode' => 'error',
+ 'error' => 'Theme was deleted from themes/ directory or couldn\'t read theme metadata from filesystem'
+ )));
+ }
+
+ if ( $theme_id == $theme_default )
+ {
+ die(enano_json_encode(array(
+ 'mode' => 'error',
+ 'error' => $lang->get('acptm_err_uninstalling_default')
+ )));
+ }
+
+ if ( $theme_id == 'oxygen' )
+ {
+ die(enano_json_encode(array(
+ 'mode' => 'error',
+ 'error' => $lang->get('acptm_err_uninstalling_oxygen')
+ )));
+ }
+
+ $theme_id = $db->escape($theme_id);
+
+ $q = $db->sql_query('DELETE FROM ' . table_prefix . "themes WHERE theme_id = '$theme_id';");
+ if ( !$q )
+ $db->die_json();
+
+ // Change all the users that were on that theme to the default
+ $default_style = $themes[$theme_default]['default_style'];
+ $default_style = preg_replace('/\.css$/', '', $default_style);
+
+ $theme_default = $db->escape($theme_default);
+ $default_style = $db->escape($default_style);
+
+ $q = $db->sql_query('UPDATE ' . table_prefix . "users SET theme = '$theme_default', style = '$default_style' WHERE theme = '$theme_id';");
+ if ( !$q )
+ $db->die_json();
+
+ echo '<div class="info-box">' . $lang->get('acptm_msg_uninstall_success') . '</div>';
+
+ page_Admin_ThemeManager(true);
+ break;
}
}
-function page_Admin_ThemeManagerOld()
-{
- global $db, $session, $paths, $template, $plugins; // Common objects
- global $lang;
- if ( $session->auth_level < USER_LEVEL_ADMIN || $session->user_level < USER_LEVEL_ADMIN )
- {
- $login_link = makeUrlNS('Special', 'Login/' . $paths->nslist['Special'] . 'Administration', 'level=' . USER_LEVEL_ADMIN, true);
- echo '<h3>' . $lang->get('adm_err_not_auth_title') . '</h3>';
- echo '<p>' . $lang->get('adm_err_not_auth_body', array( 'login_link' => $login_link )) . '</p>';
- return;
- }
-
-
- // Get the list of styles in the themes/ dir
- $h = opendir('./themes');
- $l = Array();
- if(!$h) die('Error opening directory "./themes" for reading.');
- while(false !== ($n = readdir($h))) {
- if($n != '.' && $n != '..' && is_dir('./themes/'.$n))
- $l[] = $n;
- }
- closedir($h);
- echo('
- <h3>Theme Management</h3>
- <p>Install, uninstall, and manage Enano themes.</p>
- ');
- if(isset($_POST['disenable'])) {
- $q = 'SELECT enabled FROM '.table_prefix.'themes WHERE theme_id=\'' . $db->escape($_POST['theme_id']) . '\'';
- $s = $db->sql_query($q);
- if(!$s) die('Error selecting enabled/disabled state value: '.$db->get_error().'<br /><u>SQL:</u><br />'.$q);
- $r = $db->fetchrow_num($s);
- $db->free_result();
- if($r[0] == 1) $e = 0;
- else $e = 1;
- $s=true;
- if($e==0)
- {
- $c = $db->sql_query('SELECT * FROM '.table_prefix.'themes WHERE enabled=1');
- if(!$c) $db->_die('The backup check for having at least on theme enabled failed.');
- if($db->numrows() <= 1) { echo '<div class="warning-box">You cannot disable the last remaining theme.</div>'; $s=false; }
- }
- $db->free_result();
- if($s) {
- $q = 'UPDATE '.table_prefix.'themes SET enabled='.$e.' WHERE theme_id=\'' . $db->escape($_POST['theme_id']) . '\'';
- $a = $db->sql_query($q);
- if(!$a) die('Error updating enabled/disabled state value: '.$db->get_error().'<br /><u>SQL:</u><br />'.$q);
- else echo('<div class="info-box">The theme "'.$_POST['theme_id'].'" has been '. ( ( $e == '1' ) ? 'enabled' : 'disabled' ).'.</div>');
- }
- }
- elseif(isset($_POST['edit'])) {
-
- $dir = './themes/'.$_POST['theme_id'].'/css/';
- $list = Array();
- // Open a known directory, and proceed to read its contents
- if (is_dir($dir)) {
- if ($dh = opendir($dir)) {
- while (($file = readdir($dh)) !== false) {
- if(preg_match('#^(.*?)\.css$#is', $file) && $file != '_printable.css') {
- $list[$file] = capitalize_first_letter(substr($file, 0, strlen($file)-4));
- }
- }
- closedir($dh);
- }
- }
- $lk = array_keys($list);
-
- $q = 'SELECT theme_name,default_style FROM '.table_prefix.'themes WHERE theme_id=\''.$db->escape($_POST['theme_id']).'\'';
- $s = $db->sql_query($q);
- if(!$s) die('Error selecting name value: '.$db->get_error().'<br /><u>SQL:</u><br />'.$q);
- $r = $db->fetchrow_num($s);
- $db->free_result();
- acp_start_form();
- echo('<div class="question-box">
- Theme name displayed to users: <input type="text" name="name" value="'.$r[0].'" /><br /><br />
- Default stylesheet: <select name="defaultcss">');
- foreach ($lk as $l)
- {
- if($r[1] == $l) $v = ' selected="selected"';
- else $v = '';
- echo "<option value='{$l}'$v>{$list[$l]}</option>";
- }
- echo('</select><br /><br />
- <input type="submit" name="editsave" value="OK" /><input type="hidden" name="theme_id" value="'.$_POST['theme_id'].'" />
- </div>');
- echo('</form>');
- }
- elseif(isset($_POST['editsave'])) {
- $q = 'UPDATE '.table_prefix.'themes SET theme_name=\'' . $db->escape($_POST['name']) . '\',default_style=\''.$db->escape($_POST['defaultcss']).'\' WHERE theme_id=\'' . $db->escape($_POST['theme_id']) . '\'';
- $s = $db->sql_query($q);
- if(!$s) die('Error updating name value: '.$db->get_error().'<br /><u>SQL:</u><br />'.$q);
- else echo('<div class="info-box">Theme data updated.</div>');
- }
- elseif(isset($_POST['up'])) {
- // If there is only one theme or if the selected theme is already at the top, do nothing
- $q = 'SELECT theme_order FROM '.table_prefix.'themes ORDER BY theme_order;';
- $s = $db->sql_query($q);
- if(!$s) die('Error selecting order information: '.$db->get_error().'<br /><u>SQL:</u><br />'.$q);
- $q = 'SELECT theme_order FROM '.table_prefix.'themes WHERE theme_id=\''.$db->escape($_POST['theme_id']).'\'';
- $sn = $db->sql_query($q);
- if(!$sn) die('Error selecting order information: '.$db->get_error().'<br /><u>SQL:</u><br />'.$q);
- $r = $db->fetchrow_num($sn);
- if( /* check for only one theme... */ $db->numrows($s) < 2 || $r[0] == 1 /* ...and check if this theme is already at the top */ ) { echo('<div class="warning-box">This theme is already at the top of the list, or there is only one theme installed.</div>'); } else {
- // Get the order IDs of the selected theme and the theme before it
- $q = 'SELECT theme_order FROM '.table_prefix.'themes WHERE theme_id=\'' . $db->escape($_POST['theme_id']) . '\'';
- $s = $db->sql_query($q);
- if(!$s) die('Error selecting order information: '.$db->get_error().'<br /><u>SQL:</u><br />'.$q);
- $r = $db->fetchrow_num($s);
- $r = $r[0];
- $rb = $r - 1;
- // Thank God for jEdit's rectangular selection and the ablity to edit multiple lines at the same time ;)
- $q = 'UPDATE '.table_prefix.'themes SET theme_order=0 WHERE theme_order='.$rb.''; /* Check for errors... <sigh> */ $s = $db->sql_query($q); if(!$s) die('Error updating order information: '.$db->get_error().'<br /><u>SQL:</u><br />'.$q);
- $q = 'UPDATE '.table_prefix.'themes SET theme_order='.$rb.' WHERE theme_order='.$r.''; /* Check for errors... <sigh> */ $s = $db->sql_query($q); if(!$s) die('Error updating order information: '.$db->get_error().'<br /><u>SQL:</u><br />'.$q);
- $q = 'UPDATE '.table_prefix.'themes SET theme_order='.$r.' WHERE theme_order=0'; /* Check for errors... <sigh> */ $s = $db->sql_query($q); if(!$s) die('Error updating order information: '.$db->get_error().'<br /><u>SQL:</u><br />'.$q);
- echo('<div class="info-box">Theme moved up.</div>');
- }
- $db->free_result($s);
- $db->free_result($sn);
- }
- elseif(isset($_POST['down'])) {
- // If there is only one theme or if the selected theme is already at the top, do nothing
- $q = 'SELECT theme_order FROM '.table_prefix.'themes ORDER BY theme_order;';
- $s = $db->sql_query($q);
- if(!$s) die('Error selecting order information: '.$db->get_error().'<br /><u>SQL:</u><br />'.$q);
- $r = $db->fetchrow_num($s);
- if( /* check for only one theme... */ $db->numrows($s) < 2 || $r[0] == $db->numrows($s) /* ...and check if this theme is already at the bottom */ ) { echo('<div class="warning-box">This theme is already at the bottom of the list, or there is only one theme installed.</div>'); } else {
- // Get the order IDs of the selected theme and the theme before it
- $q = 'SELECT theme_order FROM '.table_prefix.'themes WHERE theme_id=\''.$db->escape($_POST['theme_id']).'\'';
- $s = $db->sql_query($q);
- if(!$s) die('Error selecting order information: '.$db->get_error().'<br /><u>SQL:</u><br />'.$q);
- $r = $db->fetchrow_num($s);
- $r = $r[0];
- $rb = $r + 1;
- // Thank God for jEdit's rectangular selection and the ablity to edit multiple lines at the same time ;)
- $q = 'UPDATE '.table_prefix.'themes SET theme_order=0 WHERE theme_order='.$rb.''; /* Check for errors... <sigh> */ $s = $db->sql_query($q); if(!$s) die('Error updating order information: '.$db->get_error().'<br /><u>SQL:</u><br />'.$q);
- $q = 'UPDATE '.table_prefix.'themes SET theme_order='.$rb.' WHERE theme_order='.$r.''; /* Check for errors... <sigh> */ $s = $db->sql_query($q); if(!$s) die('Error updating order information: '.$db->get_error().'<br /><u>SQL:</u><br />'.$q);
- $q = 'UPDATE '.table_prefix.'themes SET theme_order='.$r.' WHERE theme_order=0'; /* Check for errors... <sigh> */ $s = $db->sql_query($q); if(!$s) die('Error updating order information: '.$db->get_error().'<br /><u>SQL:</u><br />'.$q);
- echo('<div class="info-box">Theme moved down.</div>');
- }
- }
- else if(isset($_POST['uninstall']))
- {
- $q = 'SELECT * FROM '.table_prefix.'themes;';
- $s = $db->sql_query($q);
- if ( !$s )
- {
- die('Error getting theme count: '.$db->get_error().'<br /><u>SQL:</u><br />'.$q);
- }
- $n = $db->numrows($s);
- $db->free_result();
-
- if ( $_POST['theme_id'] == 'oxygen' )
- {
- echo '<div class="error-box">The Oxygen theme is used by Enano for installation, upgrades, and error messages, and cannot be uninstalled.</div>';
- }
- else
- {
- if($n < 2)
- {
- echo '<div class="error-box">The theme could not be uninstalled because it is the only theme left.</div>';
- }
- else
- {
- $q = 'DELETE FROM '.table_prefix.'themes WHERE theme_id=\''.$db->escape($_POST['theme_id']).'\' LIMIT 1;';
- $s = $db->sql_query($q);
- if ( !$s )
- {
- die('Error deleting theme data: '.$db->get_error().'<br /><u>SQL:</u><br />'.$q);
- }
- else
- {
- echo('<div class="info-box">Theme uninstalled.</div>');
- }
- }
- }
- }
- elseif(isset($_POST['install'])) {
- $q = 'SELECT theme_id FROM '.table_prefix.'themes;';
- $s = $db->sql_query($q);
- if(!$s) die('Error getting theme count: '.$db->get_error().'<br /><u>SQL:</u><br />'.$q);
- $n = $db->numrows($s);
- $n++;
- $theme_id = $_POST['theme_id'];
- $theme = Array();
- include('./themes/'.$theme_id.'/theme.cfg');
- if ( !isset($theme['theme_id']) )
- {
- echo '<div class="error-box">Could not load theme.cfg (theme metadata file)</div>';
- }
- else
- {
- $default_style = false;
- if ( $dh = opendir('./themes/' . $theme_id . '/css') )
- {
- while ( $file = readdir($dh) )
- {
- if ( $file != '_printable.css' && preg_match('/\.css$/i', $file) )
- {
- $default_style = $file;
- break;
- }
- }
- closedir($dh);
- }
- else
- {
- die('The /css subdirectory could not be located in the theme\'s directory');
- }
-
- if ( $default_style )
- {
- $q = 'INSERT INTO '.table_prefix.'themes(theme_id,theme_name,theme_order,enabled,default_style) VALUES(\''.$db->escape($theme['theme_id']).'\', \''.$db->escape($theme['theme_name']).'\', '.$n.', 1, \'' . $db->escape($default_style) . '\')';
- $s = $db->sql_query($q);
- if(!$s) die('Error inserting theme data: '.$db->get_error().'<br /><u>SQL:</u><br />'.$q);
- else echo('<div class="info-box">Theme "'.$theme['theme_name'].'" installed.</div>');
- }
- else
- {
- echo '<div class="error-box">Could not determine the default style for the theme.</div>';
- }
- }
- }
- echo('
- <h3>Currently installed themes</h3>
- <form action="'.makeUrl($paths->nslist['Special'].'Administration', 'module='.$paths->cpage['module']).'" method="post">
- <p>
- <select name="theme_id">
- ');
- $q = 'SELECT theme_id,theme_name,enabled FROM '.table_prefix.'themes ORDER BY theme_order';
- $s = $db->sql_query($q);
- if(!$s) die('Error selecting theme data: '.$db->get_error().'<br /><u>Attempted SQL:</u><br />'.$q);
- while ( $r = $db->fetchrow_num($s) ) {
- if($r[2] < 1) $r[1] .= ' (disabled)';
- echo('<option value="'.$r[0].'">'.$r[1].'</option>');
- }
- $db->free_result();
- echo('
- </select> <input type="submit" name="disenable" value="Enable/Disable" /> <input type="submit" name="edit" value="Change settings" /> <input type="submit" name="up" value="Move up" /> <input type="submit" name="down" value="Move down" /> <input type="submit" name="uninstall" value="Uninstall" style="color: #DD3300; font-weight: bold;" />
- </p>
- </form>
- <h3>Install a new theme</h3>
- ');
- $theme = Array();
- $obb = '';
- for($i=0;$i<sizeof($l);$i++) {
- if(is_file('./themes/'.$l[$i].'/theme.cfg') && file_exists('./themes/'.$l[$i].'/theme.cfg')) {
- include('./themes/'.$l[$i].'/theme.cfg');
- $q = 'SELECT * FROM '.table_prefix.'themes WHERE theme_id=\''.$theme['theme_id'].'\'';
- $s = $db->sql_query($q);
- if(!$s) die('Error selecting list of currently installed themes: '.$db->get_error().'<br /><u>Attempted SQL:</u><br />'.$q);
- if($db->numrows($s) < 1) {
- $obb .= '<option value="'.$theme['theme_id'].'">'.$theme['theme_name'].'</option>';
- }
- $db->free_result();
- }
- }
- if($obb != '') {
- echo('<form action="'.makeUrl($paths->nslist['Special'].'Administration', 'module='.$paths->cpage['module']).'" method="post"><p>');
- echo('<select name="theme_id">');
- echo($obb);
- echo('</select>');
- echo('
- <input type="submit" name="install" value="Install this theme" />
- </p></form>');
- } else echo('<p>All themes are currently installed.</p>');
-}