@Bloc the layers are sorted only just before being used.
You can forcefully sort them with:
$layers = Template_Layers::getInstance()->prepareContext();
Though you may want to do it as late as possible before the output, just to avoid missing something.
That said, probably you don't even need to sort them, I mean, you could just hook up somewhere before template_header being called (I guess call_integration_buffer is as good as any other), get all the layers defined up until that moment, filter those you want to move somewhere else, remove them, add your sidebar and render the layers in the sidebar.
Something like:
global $existing_layers;
$interested_in_layers = ['quickreply', 'pages', 'moderation', 'etc.'];
$existing_layers = [];
$layer_obj = Template_Layers::getInstance();
foreach ($layer_obj->getLayers() as $layer)
{
if (in_array($layer, $interested_in_layers))
{
$existing_layers[] = $layer;
$layer_obj->remove($layer);
}
}
$layer_obj->addBegin('my_sidebar');
function my_sidebar_above()
{
global $existing_layers;
echo '<your sidebar markup>';
// Sort to whatever order you want them to be
foreach ($existing_layers as $layer)
{
loadSubTemplate($layer . '_above', 'ignore');
}
// Reverse the sorting
foreach ($existing_layers as $layer)
{
loadSubTemplate($layer . '_below', 'ignore');
}
echo '</your sidebar markup>';
}
I can't guarantee it works (even more because I just wrote it here without any kind of validation nor testing, so...), but that should be the general idea.