Rewrote change theme dialog; a few minor stability fixes here and there; fixed IE + St Patty background image
--- a/TODO Wed Jun 27 12:09:02 2007 -0400
+++ b/TODO Thu Jun 28 11:13:39 2007 -0400
@@ -26,8 +26,9 @@
[x] Make Special:Login remember parameters (target level, target page) even on auth fail
[x] Register users_extra table in system tables list (already done?)
[x] Trigger form submit on press of enter in Dynano login form
-[ ] Rewrite the change theme dialog - it's archaic code that hasn't changed since beta 1!
- [ ] This should be the next-to-last step in phasing out the JWS code, which should be removed in the first 1.1 alpha
+[x] Rewrite the change theme dialog - it's archaic code that hasn't changed since beta 1!
+ [ ] Come up with some alternative to the "formatting help" link for 1.1
+ [ ] By 1.1, all JWS code should be phased out and removed!
[ ] Get the new page ID cleaner code working 100% perfectly - this is the core of Enano and should be completely bug free
--- a/ajax.php Wed Jun 27 12:09:02 2007 -0400
+++ b/ajax.php Thu Jun 28 11:13:39 2007 -0400
@@ -186,6 +186,31 @@
$parms = ( isset($_POST['acl_params']) ) ? rawurldecode($_POST['acl_params']) : false;
echo PageUtils::acl_json($parms);
break;
+ case "change_theme":
+ if ( !isset($_POST['theme_id']) || !isset($_POST['style_id']) )
+ {
+ die('Invalid input');
+ }
+ if ( !preg_match('/^([a-z0-9_-]+)$/i', $_POST['theme_id']) || !preg_match('/^([a-z0-9_-]+)$/i', $_POST['style_id']) )
+ {
+ die('Invalid input');
+ }
+ if ( !file_exists(ENANO_ROOT . '/themes/' . $_POST['theme_id'] . '/css/' . $_POST['style_id'] . '.css') )
+ {
+ die('Can\'t find theme file: ' . ENANO_ROOT . '/themes/' . $_POST['theme_id'] . '/css/' . $_POST['style_id'] . '.css');
+ }
+ if ( !$session->user_logged_in )
+ {
+ die('You must be logged in to change your theme');
+ }
+ // Just in case something slipped through...
+ $theme_id = $db->escape($_POST['theme_id']);
+ $style_id = $db->escape($_POST['style_id']);
+ $e = $db->sql_query('UPDATE ' . table_prefix . "users SET theme='$theme_id', style='$style_id' WHERE user_id=$session->user_id;");
+ if ( !$e )
+ die( $db->get_error() );
+ die('GOOD');
+ break;
default:
die('Hacking attempt');
break;
--- a/includes/clientside/static/ajax.js Wed Jun 27 12:09:02 2007 -0400
+++ b/includes/clientside/static/ajax.js Thu Jun 28 11:13:39 2007 -0400
@@ -473,7 +473,127 @@
function ajaxChangeStyle()
{
var inner_html = '';
- inner_html += '';
+ inner_html += '<p><label>Theme: ';
+ inner_html += ' <select id="chtheme_sel_theme" onchange="ajaxGetStyles(this.value);">';
+ inner_html += ' <option value="_blank" selected="selected">[Select]</option>';
+ inner_html += ENANO_THEME_LIST;
+ inner_html += ' </select>';
+ inner_html += '</label></p>';
+ var chtheme_mb = new messagebox(MB_OKCANCEL|MB_ICONQUESTION, 'Change your theme', inner_html);
+ chtheme_mb.onbeforeclick['OK'] = ajaxChangeStyleComplete;
+}
+
+function ajaxGetStyles(id)
+{
+ var thediv = document.getElementById('chtheme_sel_style_parent');
+ if ( thediv )
+ {
+ thediv.parentNode.removeChild(thediv);
+ }
+ if ( id == '_blank' )
+ {
+ return null;
+ }
+ ajaxGet(stdAjaxPrefix + '&_mode=getstyles&id=' + id, function() {
+ if ( ajax.readyState == 4 )
+ {
+ // IE doesn't like substr() on ajax.responseText
+ var response = String(ajax.responseText + ' ');
+ response = response.substr(0, response.length - 1);
+ if ( response.substr(0,1) != '[' )
+ {
+ alert('Invalid or unexpected JSON response from server:\n' + response);
+ return null;
+ }
+
+ // Build a selector and matching label
+ var data = parseJSON(response);
+ var options = new Array();
+ for( var i in data )
+ {
+ var item = data[i];
+ var title = themeid_to_title(item);
+ var option = document.createElement('option');
+ option.value = item;
+ option.appendChild(document.createTextNode(title));
+ options.push(option);
+ }
+ var p_parent = document.createElement('p');
+ var label = document.createElement('label');
+ p_parent.id = 'chtheme_sel_style_parent';
+ label.appendChild(document.createTextNode('Style: '));
+ var select = document.createElement('select');
+ select.id = 'chtheme_sel_style';
+ for ( var i in options )
+ {
+ select.appendChild(options[i]);
+ }
+ label.appendChild(select);
+ p_parent.appendChild(label);
+
+ // Stick it onto the messagebox
+ var div = document.getElementById('messageBox');
+ var kid = div.firstChild.nextSibling;
+
+ kid.appendChild(p_parent);
+
+ }
+ });
+}
+
+function ajaxChangeStyleComplete()
+{
+ var theme = $('chtheme_sel_theme');
+ var style = $('chtheme_sel_style');
+ if ( !theme.object || !style.object )
+ {
+ alert('Please select a theme from the list.');
+ return true;
+ }
+ var theme_id = theme.object.value;
+ var style_id = style.object.value;
+
+ if ( typeof(theme_id) != 'string' || typeof(style_id) != 'string' )
+ {
+ alert('Couldn\'t get theme or style ID');
+ return true;
+ }
+
+ if ( theme_id.length < 1 || style_id.length < 1 )
+ {
+ alert('Theme or style ID is zero length');
+ return true;
+ }
+
+ ajaxPost(stdAjaxPrefix + '&_mode=change_theme', 'theme_id=' + escape(theme_id) + '&style_id=' + escape(style_id), function()
+ {
+ if ( ajax.readyState == 4 )
+ {
+ if ( ajax.responseText == 'GOOD' )
+ {
+ var c = confirm('Your theme preference has been changed.\nWould you like to reload the page now to see the changes?');
+ if ( c )
+ window.location.reload();
+ }
+ else
+ {
+ alert('Error occurred during attempt to change theme:\n' + ajax.responseText);
+ }
+ }
+ });
+
+ return true;
+
+}
+
+function themeid_to_title(id)
+{
+ if ( typeof(id) != 'string' )
+ return false;
+ id = id.substr(0, 1).toUpperCase() + id.substr(1);
+ id = id.replace(/_/g, ' ');
+ id = id.replace(/-/g, ' ');
+ return id;
}
/*
--- a/includes/clientside/static/comments.js Wed Jun 27 12:09:02 2007 -0400
+++ b/includes/clientside/static/comments.js Thu Jun 28 11:13:39 2007 -0400
@@ -309,12 +309,15 @@
{
document.getElementById('subject_' + data.id).innerHTML += ' <span style="color: #D84308">(Unapproved)</span>';
}
- if ( data.approved )
+ if ( data.approved && ( typeof(data.approve_updated) == 'string' && data.approve_updated == 'yes' ) )
{
var appr = ( data.approved == '1' ) ? 'Unapprove' : 'Approve';
document.getElementById('comment_approve_'+data.id).innerHTML = appr;
+
+ // Update approval status
var p = document.getElementById('comment_status');
var count = p.firstChild.nodeValue.split(' ')[2];
+
if ( p.firstChild.nextSibling )
{
var span = p.firstChild.nextSibling;
--- a/includes/clientside/static/dynano.js Wed Jun 27 12:09:02 2007 -0400
+++ b/includes/clientside/static/dynano.js Thu Jun 28 11:13:39 2007 -0400
@@ -8,6 +8,11 @@
function DNobj(id)
{
this.object = ( typeof(id) == 'object' ) ? id : document.getElementById(id);
+ if ( !this.object )
+ {
+ this.object = false;
+ return this;
+ }
this.height = __DNObjGetHeight(this.object);
this.width = __DNObjGetWidth(this.object);
--- a/includes/comment.php Wed Jun 27 12:09:02 2007 -0400
+++ b/includes/comment.php Thu Jun 28 11:13:39 2007 -0400
@@ -344,7 +344,8 @@
'mode' => 'redraw',
'approved' => $appr,
'subj' => $row['subject'],
- 'id' => $data['local_id']
+ 'id' => $data['local_id'],
+ 'approve_updated' => 'yes'
);
break;
--- a/includes/pageutils.php Wed Jun 27 12:09:02 2007 -0400
+++ b/includes/pageutils.php Thu Jun 28 11:13:39 2007 -0400
@@ -1333,13 +1333,15 @@
}
/**
- * Gets a list of styles for a given theme name.
+ * Gets a list of styles for a given theme name. As of Banshee, this returns JSON.
* @param $id the name of the directory for the theme
- * @return string Javascript code
+ * @return string JSON string with an array containing a list of themes
*/
function getstyles()
{
+ $json = new Services_JSON(SERVICES_JSON_LOOSE_TYPE);
+
$dir = './themes/'.$_GET['id'].'/css/';
$list = Array();
// Open a known directory, and proceed to read its contents
@@ -1355,14 +1357,13 @@
}
closedir($dh);
}
- } else return($dir.' is not a dir');
- $l = 'var list = new Array();';
- $i = -1;
- foreach($list as $li) {
- $i++;
- $l .= "list[$i] = '$li';";
}
- return $l;
+ else
+ {
+ return(Array('mode' => 'error', 'error' => $dir.' is not a dir'));
+ }
+
+ return $json->encode($list);
}
/**
--- a/includes/template.php Wed Jun 27 12:09:02 2007 -0400
+++ b/includes/template.php Thu Jun 28 11:13:39 2007 -0400
@@ -678,7 +678,7 @@
if($t['enabled'])
{
$js_dynamic .= '<option value="'.$t['theme_id'].'"';
- if($t['theme_id'] == $session->theme) $js_dynamic .= ' selected="selected"';
+ // if($t['theme_id'] == $session->theme) $js_dynamic .= ' selected="selected"';
$js_dynamic .= '>'.$t['theme_name'].'</option>';
}
}
--- a/themes/stpatty/css-extra/ie-fixes.css Wed Jun 27 12:09:02 2007 -0400
+++ b/themes/stpatty/css-extra/ie-fixes.css Thu Jun 28 11:13:39 2007 -0400
@@ -10,7 +10,7 @@
background-image: none;
}
div#title {
- background-image: none;
+ /* background-image: none; */
}
div#rap {
background-image: url(../images/rap-ie.gif);