# HG changeset patch # User Dan # Date 1280515144 14400 # Node ID 673a1b6712fa3c13385d9871634d70cf35d53b83 # Parent 3351055b467e583fee9d9533f62d141ede8dae60 Moved sidebar editor into the admin CP. Icon still needs to be added, no Internet right now to go find one. Also fixed a few template related things. diff -r 3351055b467e -r 673a1b6712fa includes/clientside/sbedit.js --- a/includes/clientside/sbedit.js Fri Jul 30 14:37:05 2010 -0400 +++ b/includes/clientside/sbedit.js Fri Jul 30 14:39:04 2010 -0400 @@ -18,8 +18,25 @@ }); }; +addOnloadHook(function() + { + attachHook('admin_page_onload', 'sbedit_conditional_init(t, qs);'); + }); + +// if the page was loaded directly this will be used instead addOnloadHook(sbedit_load); +function sbedit_conditional_init(t, qs) +{ + if ( t != namespace_list.Admin + 'EditSidebar' ) + return false; + + if ( qs == '&action=new&id=0' ) + setType(document.getElementById('sbedit_create_select_type')); + else + sbedit_load(); +} + function serialize_sidebar() { var columns = {}; @@ -84,7 +101,7 @@ var whitey = whiteOutElement(this); $(this).append(''); $(this).append('
' + $lang.get('etc_save_changes') + ' | ' + $lang.get('etc_cancel') + '
'); - $.get(makeUrlNS('Special', 'EditSidebar', 'action=getsource&noheaders&id=' + item_id), {}, function(response, statustext) + $.get(makeUrlNS('Admin', 'EditSidebar', 'action=getsource&noheaders&id=' + item_id), {}, function(response, statustext) { $('textarea', box).val(response); $(whitey).remove(); @@ -100,7 +117,7 @@ var box = a.parentNode.parentNode; var parent = document.getElementById('block:' + $(box).attr('enano:item_id')); var whitey = whiteOutElement(box); - $.post(makeUrlNS('Special', 'EditSidebar', 'noheaders&action=save&id=' + $(box).attr('enano:item_id')), { content: $('textarea', box).attr('value') }, function(response, statustext) + $.post(makeUrlNS('Admin', 'EditSidebar', 'noheaders&action=save&id=' + $(box).attr('enano:item_id')), { content: $('textarea', box).attr('value') }, function(response, statustext) { whiteOutReportSuccess(whitey); setTimeout(function() @@ -187,7 +204,7 @@ var id = parseInt($(parent).attr('id').replace(/^block:/, '')); var whitey = whiteOutElement(parent); - $.get(makeUrlNS('Special', 'EditSidebar', 'action=delete&ajax=true&noheaders&id=' + id), function(response, statustext) + $.get(makeUrlNS('Admin', 'EditSidebar', 'action=delete&ajax=true&noheaders&id=' + id), function(response, statustext) { if ( response == 'GOOD' ) { @@ -223,7 +240,7 @@ var whitey = whiteOutElement(this.parentNode); var me = this; var id = parseInt($(parent).attr('id').replace(/^block:/, '')); - $.post(makeUrlNS('Special', 'EditSidebar', 'ajax&noheaders&action=rename&id='+id), { newname: $(this).attr('value') }, function(response, statustext) + $.post(makeUrlNS('Admin', 'EditSidebar', 'ajax&noheaders&action=rename&id='+id), { newname: $(this).attr('value') }, function(response, statustext) { if ( response == 'GOOD' ) { @@ -256,7 +273,7 @@ { var parent = sbedit_get_parent(a); var whitey = whiteOutElement(parent); - $.get(makeUrlNS('Special', 'EditSidebar', 'action=disenable&ajax=true&noheaders&id=' + parseInt($(parent).attr('id').replace(/^block:/, ''))), {}, function(response, statustext) + $.get(makeUrlNS('Admin', 'EditSidebar', 'action=disenable&ajax=true&noheaders&id=' + parseInt($(parent).attr('id').replace(/^block:/, ''))), {}, function(response, statustext) { if ( response == 'GOOD' ) { @@ -301,7 +318,7 @@ unsetAjaxLoading(); return false; } - $.post(makeUrlNS('Special', 'EditSidebar', 'update_order'), { order: ser }, function(response, statustext) + $.post(makeUrlNS('Admin', 'EditSidebar', 'update_order'), { order: ser }, function(response, statustext) { var msg = document.createElement('div'); $(msg) @@ -319,3 +336,17 @@ }, 'json'); } +function setType(input) +{ + val = input.value; + if(!val) + { + return false; + } + var divs = getElementsByClassName(document, 'div', 'sbadd_block'); + for(var i in divs) + { + if(divs[i].id == 'blocktype_'+val) divs[i].style.display = 'block'; + else divs[i].style.display = 'none'; + } +} diff -r 3351055b467e -r 673a1b6712fa includes/paths.php --- a/includes/paths.php Fri Jul 30 14:37:05 2010 -0400 +++ b/includes/paths.php Fri Jul 30 14:39:04 2010 -0400 @@ -97,6 +97,7 @@ $this->addAdminNode('adm_cat_content', 'adm_page_pg_groups', 'PageGroups', array(4, 3)); $this->addAdminNode('adm_cat_appearance', 'adm_page_themes', 'ThemeManager', array(4, 4)); $this->addAdminNode('adm_cat_appearance', 'adm_page_plugins', 'PluginManager', array(2, 4)); + $this->addAdminNode('adm_cat_appearance', 'adm_page_editsidebar', 'EditSidebar' ); $this->addAdminNode('adm_cat_appearance', 'adm_page_db_backup', 'DBBackup', array(1, 2)); $this->addAdminNode('adm_cat_appearance', 'adm_page_lang_manager', 'LangManager', array(1, 3)); $this->addAdminNode('adm_cat_appearance', 'adm_page_cache_manager', 'CacheManager', array(3, 1)); diff -r 3351055b467e -r 673a1b6712fa includes/template.php --- a/includes/template.php Fri Jul 30 14:37:05 2010 -0400 +++ b/includes/template.php Fri Jul 30 14:39:04 2010 -0400 @@ -417,6 +417,8 @@ function set_page($page_id_or_pp, $namespace = false) { + global $paths; + if ( is_object($page_id_or_pp) && get_class($page_id_or_pp) === 'PageProcessor' ) { $this->page_initted = false; @@ -442,6 +444,9 @@ { return false; } + $this->assign_vars(array( + 'PAGE_URLNAME' => $paths->get_pathskey($this->page_id, $this->namespace) + )); return true; } @@ -699,13 +704,8 @@ $admin_link = $parser->run(); - $parser->assign_vars(Array( - 'HREF'=>makeUrlNS('Special', 'EditSidebar'), - 'FLAGS'=>'onclick="if ( !KILL_SWITCH ) { void(ajaxLoginNavTo(\'Special\', \'EditSidebar\', ' . USER_LEVEL_ADMIN . ')); return false; }"', - 'TEXT'=>$lang->get('sidebar_btn_editsidebar'), - )); - - $sidebar_link = $parser->run(); + // We're leaving this in for now, just blanked out, to avoid compatibility issues. + $sidebar_link = ''; $this->assign_vars(array( 'ADMIN_LINK' => $admin_link, @@ -2830,6 +2830,7 @@ global $db, $session, $paths, $template, $plugins; // Common objects $this->tpl_code = $text; $this->tpl_strings = $template->tpl_strings; + // echo 'templateIndividual init. Using strings:' . htmlspecialchars(print_r($this->tpl_strings, true)) . ''; $this->tpl_bool = $template->tpl_bool; } /** diff -r 3351055b467e -r 673a1b6712fa language/english/admin.json --- a/language/english/admin.json Fri Jul 30 14:37:05 2010 -0400 +++ b/language/english/admin.json Fri Jul 30 14:39:04 2010 -0400 @@ -62,6 +62,7 @@ page_themes: 'Manage themes', page_plugins: 'Manage plugins', + page_editsidebar: 'Edit sidebar', page_db_backup: 'Backup database', page_lang_manager: 'Language manager', page_cache_manager: 'Cache settings', @@ -1165,7 +1166,7 @@ msg_logout_complete: 'You will continue to be logged into the website, but you will need to re-authenticate before you can access the administration panel again.
Return to the Main Page.', }, sbedit: { - header_msg: 'This control panel allows you to organize the sidebars, the collections of links and dynamic blocks that provide navigation for your site. Drag and drop blocks to move them between the left and right sidebars; changes will be saved automatically. Red blocks are disabled. This panel only works if you have Javascript enabled and working in your browser. Create a new block.', + header_msg: 'This control panel allows you to organize the sidebars, the collections of links and dynamic blocks that provide navigation for your site. Drag and drop blocks to move them between the left and right sidebars; changes will be saved automatically. Red blocks are disabled. This panel only works if you have Javascript enabled and working in your browser. Create a new block.', msg_order_update_success: 'The sidebar order information was updated successfully.', err_demo_php_disable: 'Adding PHP code blocks in the Enano administration demo has been disabled for security reasons.', diff -r 3351055b467e -r 673a1b6712fa plugins/SpecialAdmin.php --- a/plugins/SpecialAdmin.php Fri Jul 30 14:37:05 2010 -0400 +++ b/plugins/SpecialAdmin.php Fri Jul 30 14:39:04 2010 -0400 @@ -30,7 +30,6 @@ global $paths; register_special_page('Administration', 'specialpage_administration'); - register_special_page('EditSidebar', 'specialpage_manage_sidebar'); } $plugins->attachHook('base_classes_initted', 'SpecialAdmin_include();'); @@ -2011,6 +2010,7 @@ $template->preload_js('jquery-ui'); $template->preload_js('autofill'); $template->preload_js('admin-menu'); + $template->add_header(''); $output->header(); @@ -2214,505 +2214,485 @@ } } -function page_Special_EditSidebar() +function page_Admin_EditSidebar() { global $db, $session, $paths, $template, $plugins; // Common objects global $lang; global $cache; - if($session->auth_level < USER_LEVEL_ADMIN) + if ( $session->auth_level < USER_LEVEL_ADMIN || $session->user_level < USER_LEVEL_ADMIN ) { - redirect(makeUrlNS('Special', 'Login/'.$paths->page, 'level='.USER_LEVEL_ADMIN), '', '', false); - exit; + $login_link = makeUrlNS('Special', 'Login/' . $paths->nslist['Special'] . 'Administration', 'level=' . USER_LEVEL_ADMIN, true); + echo '
' . $lang->get('adm_err_not_auth_body', array( 'login_link' => $login_link )) . '
'; + return; } - else + + if ( isset($_GET['update_order']) ) { - if ( isset($_GET['update_order']) ) + header('Content-type: text/javascript'); + $order = @$_POST['order']; + try { - header('Content-type: text/javascript'); - $order = @$_POST['order']; - try - { - $order = enano_json_decode($order); - } - catch ( Zend_Json_Exception $e ) - { - return print enano_json_encode(array( - 'mode' => 'error', - 'error' => 'bad order' - )); - } - - foreach ( $order as $sidebar_id => $blocks ) - { - foreach ( $blocks as $order => $block_id ) - { - $sbid = intval($sidebar_id); - $order = intval($order); - $block_id = intval($block_id); - $q = $db->sql_query('UPDATE ' . table_prefix . "sidebar SET sidebar_id = $sbid, item_order = $order WHERE item_id = $block_id;"); - if ( !$q ) - $db->die_json(); - } - } - + $order = enano_json_decode($order); + } + catch ( Zend_Json_Exception $e ) + { return print enano_json_encode(array( - 'mode' => 'success' + 'mode' => 'error', + 'error' => 'bad order' )); } - $template->preload_js(array('l10n', 'jquery', 'jquery-ui')); - $template->add_header(''); - - $template->header(); - - if(isset($_POST['save'])) + foreach ( $order as $sidebar_id => $blocks ) { - // Write the new block order to the database - // The only way to do this is with tons of queries (one per block + one select query at the start to count everything) but afaik its safe... - // Anyone know a better way to do this? - $q = $db->sql_query('SELECT item_order,item_id,sidebar_id FROM '.table_prefix.'sidebar ORDER BY sidebar_id ASC, item_order ASC;'); - if ( !$q ) - { - $db->_die('The sidebar order data could not be selected.'); - } - $orders = Array(); - while($row = $db->fetchrow()) + foreach ( $blocks as $order => $block_id ) { - $orders[] = Array( - count($orders), - $row['item_id'], - $row['sidebar_id'], - ); - } - $db->free_result(); - - // We now have an array with each sidebar ID in its respective order. Explode the order string in $_POST['order_(left|right)'] and use it to build a set of queries. - $ol = explode(',', $_POST['order_left']); - $odr = explode(',', $_POST['order_right']); - $om = array_merge($ol, $odr); - unset($ol, $odr); - $queries = Array(); - foreach($orders as $k => $v) - { - $queries[] = 'UPDATE '.table_prefix.'sidebar SET item_order='.intval($om[$k]).' WHERE item_id='.intval($v[1]).';'; - } - foreach($queries as $sql) - { - $q = $db->sql_query($sql); - if(!$q) - { - $t = $db->get_error(); - echo $t; - $template->footer(); - exit; - } + $sbid = intval($sidebar_id); + $order = intval($order); + $block_id = intval($block_id); + $q = $db->sql_query('UPDATE ' . table_prefix . "sidebar SET sidebar_id = $sbid, item_order = $order WHERE item_id = $block_id;"); + if ( !$q ) + $db->die_json(); } - $cache->purge('anon_sidebar'); - echo '+ get('sbedit_create_intro'); ?> +
++ +
+ +
+
+ get('sbedit_field_block_title'); ?>
+ get('sbedit_field_block_sidebar'); ?>
+
-