Index: admin/media.php
===================================================================
--- admin/media.php	(revision 2720)
+++ admin/media.php	(revision 2751)
@@ -28,4 +28,5 @@
 }
 $d = isset($_REQUEST['d']) ? $_REQUEST['d'] : null;
+$plugin_id = isset($_REQUEST['plugin_id']) ? html::sanitizeURL($_REQUEST['plugin_id']) : '';
 $dir = null;
 
@@ -74,5 +75,5 @@
 $popup = (integer) !empty($_GET['popup']);
 
-$page_url = $core->adminurl->get("admin.media",array('popup' => $popup,'post_id' => $post_id));
+$page_url = $core->adminurl->get("admin.media",array('popup' => $popup,'post_id' => $post_id, 'plugin_id' => $plugin_id));
 if (($temp = $core->callBehavior('adminMediaURL',$page_url))!='') {
 	$page_url = $temp;
@@ -144,5 +145,5 @@
 # Adding a file
 if ($dir && !empty($_FILES['upfile'])) {
-  // only one file per request : @see option singleFileUploads in admin/js/jsUpload/jquery.fileupload
+	// only one file per request : @see option singleFileUploads in admin/js/jsUpload/jquery.fileupload
 	$upfile = array('name' => $_FILES['upfile']['name'][0],
 		'type' => $_FILES['upfile']['type'][0],
@@ -160,8 +161,9 @@
 			$new_file_id = $core->media->uploadFile($upfile['tmp_name'], $upfile['name']);
 
-			$message['files'][] = array('name' => $upfile['name'],
+			$message['files'][] = array(
+				'name' => $upfile['name'],
 				'size' => $upfile['size'],
-				'html' => mediaItemLine($core->media->getFile($new_file_id), 1)
-				);
+				'html' => mediaItemLine($core->media->getFile($new_file_id), 1, $plugin_id)
+			);
 		} catch (Exception $e) {
 			$message['files'][] = array('name' => $upfile['name'],
@@ -379,5 +381,5 @@
 $fmt_form_media = '<form action="'.$core->adminurl->get("admin.media").'" method="post" id="form-medias">'.
 	'<div class="files-group">%s</div>'.
-	'<p class="hidden">'.$core->formNonce() . form::hidden(array('d'),$d).'</p>';
+	'<p class="hidden">'.$core->formNonce() . form::hidden(array('d'),$d).form::hidden(array('plugin_id'),$plugin_id).'</p>';
 
 if (!$popup) {
@@ -410,4 +412,5 @@
 	'<input type="submit" value="'.__('OK').'" />'.
 	form::hidden(array('popup'),$popup).
+	form::hidden(array('plugin_id'),$plugin_id).
 	form::hidden(array('post_id'),$post_id).
 	'</p>'.
@@ -420,7 +423,7 @@
 	{
 		if ($items[$i]->d) {
-			$dgroup .= mediaItemLine($items[$i],$j);
+			$dgroup .= mediaItemLine($items[$i],$j,$plugin_id);
 		} else {
-			$fgroup .= mediaItemLine($items[$i],$j);
+			$fgroup .= mediaItemLine($items[$i],$j,$plugin_id);
 		}
 	}
@@ -561,5 +564,5 @@
 
 /* ----------------------------------------------------- */
-function mediaItemLine($f,$i)
+function mediaItemLine($f,$i,$plugin_id)
 {
 	global $core, $page_url, $popup, $post_id;
@@ -578,8 +581,16 @@
 		}
 	} else {
-		$link = $core->adminurl->get("admin.media.item", array('id' => $f->media_id,'popup' => $popup,'post_id' => $post_id));
-        if (($temp = $core->callBehavior('adminMediaURL',$link))!='') {
-            $link = $temp;
-        }
+		$link = $core->adminurl->get(
+			'admin.media.item',
+			array(
+				'id' => $f->media_id,
+				'plugin_id' => $plugin_id,
+				'popup' => $popup,
+				'post_id' => $post_id
+			)
+		);
+		if (($temp = $core->callBehavior('adminMediaURL',$link))!='') {
+			$link = $temp;
+		}
 	}
 
Index: admin/media_item.php
===================================================================
--- admin/media_item.php	(revision 2749)
+++ admin/media_item.php	(revision 2751)
@@ -29,4 +29,5 @@
 $file = null;
 $popup = (integer) !empty($_GET['popup']);
+$plugin_id = isset($_REQUEST['plugin_id']) ? html::sanitizeURL($_REQUEST['plugin_id']) : '';
 $page_url = $core->adminurl->get("admin.media.item",array('popup' => $popup,'post_id' => $post_id));
 $media_page_url = $core->adminurl->get("admin.media",array('popup' => $popup,'post_id' => $post_id));
@@ -83,5 +84,5 @@
 
 		dcPage::addSuccessNotice(__('File has been successfully updated.'));
-		http::redirect($page_url.'&id='.$id);
+		http::redirect($page_url.'&id='.$id.'&plugin_id='.$plugin_id);
 	} catch (Exception $e) {
 		$core->error->add($e->getMessage());
@@ -112,5 +113,5 @@
 
 		dcPage::addSuccessNotice(__('File has been successfully updated.'));
-		http::redirect($page_url.'&id='.$id.'&tab=media-details-tab');
+		http::redirect($page_url.'&id='.$id.'&plugin_id='.$plugin_id.'&tab=media-details-tab');
 	} catch (Exception $e) {
 		$core->error->add($e->getMessage());
@@ -126,5 +127,5 @@
 
 		dcPage::addSuccessNotice(__('Thumbnails have been successfully updated.'));
-		http::redirect($page_url.'&id='.$id.'&tab=media-details-tab');
+		http::redirect($page_url.'&id='.$id.'&plugin_id='.$plugin_id.'&tab=media-details-tab');
 	} catch (Exception $e) {
 		$core->error->add($e->getMessage());
@@ -139,5 +140,5 @@
 
 		dcPage::addSuccessNotice(__('Zip file has been successfully extracted.'));
-		http::redirect($media_page_url.'&d='.$unzip_dir);
+		http::redirect($media_page_url.'&d='.$unzip_dir.'&plugin_id='.$plugin_id);
 	} catch (Exception $e) {
 		$core->error->add($e->getMessage());
@@ -164,5 +165,5 @@
 
 	dcPage::addSuccessNotice(__('Default media insertion settings have been successfully updated.'));
-	http::redirect($page_url.'&id='.$id);
+	http::redirect($page_url.'&id='.$id.'&plugin_id='.$plugin_id);
 }
 
@@ -207,10 +208,6 @@
 	"</script>".
 	dcPage::jsLoad('js/_media_item.js');
-if ($popup) {
-	// perhaps better to put active editor in session
-	$post_format = $core->auth->getOption('post_format');
-	$post_editor = $core->auth->getOption('editor');
-
-	$starting_scripts .= $core->callBehavior('adminPopupMedia', $post_editor[$post_format]);
+if ($popup && !empty($plugin_id)) {
+	$starting_scripts .= $core->callBehavior('adminPopupMedia', $plugin_id);
 }
 call_user_func($open_f,__('Media manager'),
@@ -422,4 +419,5 @@
 		form::hidden(array('pref_insertion'),'').
 		form::hidden(array('id'),$id).
+		form::hidden(array('plugin_id'),$plugin_id).
 		$core->formNonce().'</p>'.
 		'</form>'.'</div>';
@@ -464,7 +462,7 @@
 		$strong_link = ($s == $thumb_size) ? '<strong>%s</strong>' : '%s';
 		printf($strong_link,'<a href="'.html::escapeURL($page_url).
-		'&amp;id='.$id.'&amp;size='.$s.'&amp;tab=media-details-tab">'.$core->media->thumb_sizes[$s][2].'</a> | ');
-	}
-	echo '<a href="'.html::escapeURL($page_url).'&amp;id='.$id.'&amp;size=o&amp;tab=media-details-tab">'.__('original').'</a>';
+		'&amp;id='.$id.'&amp;plugin_id='.$plugin_id.'&amp;size='.$s.'&amp;tab=media-details-tab">'.$core->media->thumb_sizes[$s][2].'</a> | ');
+	}
+	echo '<a href="'.html::escapeURL($page_url).'&amp;id='.$id.'&amp;plugin_id='.$plugin_id.'&amp;size=o&amp;tab=media-details-tab">'.__('original').'</a>';
 	echo '</p>';
 }
@@ -492,5 +490,5 @@
 {
 	echo
-	'<p><a class="button" href="'.html::escapeHTML($page_url).'&amp;id='.$id.'&amp;find_posts=1&amp;tab=media-details-tab">'.
+	'<p><a class="button" href="'.html::escapeHTML($page_url).'&amp;id='.$id.'&plugin_id='.$plugin_id.'&amp;find_posts=1&amp;tab=media-details-tab">'.
 	__('Show entries containing this media').'</a></p>';
 }
@@ -592,4 +590,5 @@
 		'<p><input type="submit" name="thumbs" value="'.__('Update thumbnails').'" />'.
 		form::hidden(array('id'),$id).
+		form::hidden(array('plugin_id'),$plugin_id).
 		$core->formNonce().'</p>'.
 		'</form>';
@@ -616,4 +615,5 @@
 		'<input type="submit" name="unzip" value="'.__('Extract').'" />'.
 		form::hidden(array('id'),$id).
+		form::hidden(array('plugin_id'),$plugin_id).
 		$core->formNonce().'</p>'.
 		'</form>';
@@ -635,4 +635,5 @@
 	'<p><input type="submit" accesskey="s" value="'.__('Save').'" />'.
 	form::hidden(array('id'),$id).
+	form::hidden(array('plugin_id'),$plugin_id).
 	$core->formNonce().'</p>'.
 	'</form>';
@@ -648,4 +649,5 @@
 	'<p><input type="submit" value="'.__('Send').'" />'.
 	form::hidden(array('id'),$id).
+	form::hidden(array('plugin_id'),$plugin_id).
 	$core->formNonce().'</p>'.
 	'</form>';
@@ -655,4 +657,5 @@
 		'<form id="delete-form" method="post" action="'.html::escapeURL($media_page_url).
 		'&amp;d='.rawurlencode(dirname($file->relname)).
+		'&amp;plugin_id='.$plugin_id.
 		'&amp;remove='.rawurlencode($file->basename).'">'.
 		'<p><input name="delete" type="submit" class="delete" value="'.__('Delete this media').'" />'.
Index: plugins/dcCKEditor/_post_config.php
===================================================================
--- plugins/dcCKEditor/_post_config.php	(revision 2738)
+++ plugins/dcCKEditor/_post_config.php	(revision 2751)
@@ -31,11 +31,12 @@
 			}
 		}
-		
+
 		return url;
 	};
 
-	/* Retrieve editor name from URL */
-	$.getEditorName = function getEditorName(url) {
-		return url.replace(/.*editor=([^&]*)(&.*)?/,'$1');
+	/* Retrieve editor from popup */
+    $.active_editor = null;
+	$.getEditorName = function getEditorName() {
+		return $.active_editor;
 	}
 })(jQuery);
@@ -49,9 +50,9 @@
 	CKEDITOR.config.skin = 'dotclear,'+dotclear.dcckeditor_plugin_url+'/js/ckeditor-skins/dotclear/';
 
-<?php if (!empty($dcckeditor_cancollapse_button)):?>    
+<?php if (!empty($dcckeditor_cancollapse_button)):?>
 	CKEDITOR.config.toolbarCanCollapse = true;
 <?php endif;?>
-	
-	CKEDITOR.plugins.addExternal('entrylink',dotclear.dcckeditor_plugin_url+'/js/ckeditor-plugins/entrylink/');	
+
+	CKEDITOR.plugins.addExternal('entrylink',dotclear.dcckeditor_plugin_url+'/js/ckeditor-plugins/entrylink/');
 	CKEDITOR.plugins.addExternal('dclink',dotclear.dcckeditor_plugin_url+'/js/ckeditor-plugins/dclink/');
 	CKEDITOR.plugins.addExternal('media',dotclear.dcckeditor_plugin_url+'/js/ckeditor-plugins/media/');
@@ -75,5 +76,5 @@
 		extraPlugins: '<?php echo $defautExtraPlugins;?>',
 
-		<?php if (!empty($dcckeditor_format_select)):?>				
+		<?php if (!empty($dcckeditor_format_select)):?>
 		// format tags
 		format_tags: 'p;h1;h2;h3;h4;h5;h6;pre;address',
@@ -102,5 +103,5 @@
 <?php endif;?>
 					'Bold','Italic','Underline','Strike','Subscript','Superscript','Code','Blockquote',
-					
+
 <?php if (!empty($dcckeditor_list_buttons)):?>
 					'NumberedList', 'BulletedList',
@@ -135,5 +136,5 @@
                 ,'TextColor'
 <?php endif;?>
-				] 
+				]
 			},
 			<?php // add extra buttons comming from dotclear plugins
@@ -156,8 +157,15 @@
 			$('#cke_post_excerpt').addClass('hide');
 		}
-		
+
 		$('#excerpt-area label').click(function() {
 			$('#cke_post_excerpt').toggleClass('hide',$('#post_excerpt').hasClass('hide'));
 		});
 	});
+
+	// @TODO: find a better way to retrieve active editor
+	for (var id in CKEDITOR.instances) {
+		CKEDITOR.instances[id].on('focus', function(e) {
+			$.active_editor = e.editor.name;
+		});
+	}
 });
Index: plugins/dcCKEditor/js/ckeditor-plugins/dclink/plugin.js
===================================================================
--- plugins/dcCKEditor/js/ckeditor-plugins/dclink/plugin.js	(revision 2743)
+++ plugins/dcCKEditor/js/ckeditor-plugins/dclink/plugin.js	(revision 2751)
@@ -6,5 +6,5 @@
 				exec: function(editor) {
 					if (editor.getSelection().getNative().toString().replace(/\s*/,'')!='') {
-						$.toolbarPopup('popup_link.php?editor='+editor.name);
+						$.toolbarPopup('popup_link.php?plugin_id=dcCKEditor');
 					}
 				}
@@ -26,5 +26,5 @@
 						editor.getSelection().selectElement(element);
 
-						var popup_url = 'popup_link.php?editor='+editor.name;
+						var popup_url = 'popup_link.php?plugin_id=dcCKEditor';
 						if (element.getAttribute('href')) {
 							popup_url += '&href='+element.getAttribute('href');
Index: plugins/dcCKEditor/js/ckeditor-plugins/entrylink/plugin.js
===================================================================
--- plugins/dcCKEditor/js/ckeditor-plugins/entrylink/plugin.js	(revision 2743)
+++ plugins/dcCKEditor/js/ckeditor-plugins/entrylink/plugin.js	(revision 2751)
@@ -6,5 +6,5 @@
 				exec: function(editor) {
 					if (editor.getSelection().getNative().toString().replace(/\s*/,'')!='') {
-						$.toolbarPopup('popup_posts.php?popup=1&editor='+editor.name);
+						$.toolbarPopup('popup_posts.php?popup=1&plugin_id=dcCKEditor');
 					}
 				}
@@ -18,5 +18,5 @@
 
 			editor.on('doubleclick',function(e) {
-				var element = CKEDITOR.plugins.link.getSelectedLink( editor ) || e.data.element;
+				var element = CKEDITOR.plugins.link.getSelectedLink(editor) || e.data.element;
 				if (!element.isReadOnly()) {
 					if (element.is('a')
@@ -25,5 +25,5 @@
 						editor.getSelection().selectElement(element);
 
-						$.toolbarPopup('popup_posts.php?popup=1&editor='+editor.name);
+						$.toolbarPopup('popup_posts.php?popup=1&plugin_id=dcCKEditor');
 						return false;
 					}
Index: plugins/dcCKEditor/js/ckeditor-plugins/media/plugin.js
===================================================================
--- plugins/dcCKEditor/js/ckeditor-plugins/media/plugin.js	(revision 2743)
+++ plugins/dcCKEditor/js/ckeditor-plugins/media/plugin.js	(revision 2751)
@@ -5,5 +5,5 @@
 			editor.addCommand('mediaCommand', {
 				exec: function(editor) {
-					$.toolbarPopup('media.php?popup=1&editor='+editor.name);
+					$.toolbarPopup('media.php?popup=1&plugin_id=dcCKEditor');
 				}
 			});
@@ -19,5 +19,5 @@
 				if (!element.isReadOnly()) {
 					if (element.is('img') || (element.is('a') && element.hasClass('media-link'))) {
-						$.toolbarPopup('media.php?popup=1&editor='+editor.name);
+						$.toolbarPopup('media.php?popup=1&plugin_id=dcCKEditor');
 						return false;
 					}
Index: plugins/dcCKEditor/js/popup_link.js
===================================================================
--- plugins/dcCKEditor/js/popup_link.js	(revision 2738)
+++ plugins/dcCKEditor/js/popup_link.js	(revision 2751)
@@ -6,11 +6,11 @@
 	$('#link-insert-ok').click(function() {
 		var insert_form = $('#link-insert-form').get(0);
-		if (insert_form == undefined) { 
-			return; 
+		if (insert_form == undefined) {
+			return;
 		}
 
-		var editor_name = window.opener.$.getEditorName(document.location.search),
+		var editor_name = window.opener.$.getEditorName(),
 		editor = window.opener.CKEDITOR.instances[editor_name],
-		link = '',	
+		link = '',
 		selected_text = editor.getSelection().getNative().toString();
 
Index: plugins/dcCKEditor/js/popup_media.js
===================================================================
--- plugins/dcCKEditor/js/popup_media.js	(revision 2738)
+++ plugins/dcCKEditor/js/popup_media.js	(revision 2751)
@@ -3,12 +3,12 @@
 		window.close();
 	});
-	
+
 	$('#media-insert-ok').click(function() {
 		var insert_form = $('#media-insert-form').get(0);
-		if (insert_form === undefined) { 
-			return; 
+		if (insert_form === undefined) {
+			return;
 		}
 
-		var editor_name = window.opener.$.getEditorName(document.location.search),
+		var editor_name = window.opener.$.getEditorName(),
 		editor = window.opener.CKEDITOR.instances[editor_name],
 		type = insert_form.elements.type.value,
@@ -47,5 +47,5 @@
 					element = window.opener.CKEDITOR.dom.element.createFromHtml(img);
 				}
-					
+
 				editor.insertElement(element);
 			}
Index: plugins/dcCKEditor/js/popup_posts.js
===================================================================
--- plugins/dcCKEditor/js/popup_posts.js	(revision 2738)
+++ plugins/dcCKEditor/js/popup_posts.js	(revision 2751)
@@ -6,5 +6,5 @@
 	$('#form-entries tr>td.maximal>a').click(function(e) {
 		e.preventDefault();
-		var editor_name = window.opener.$.getEditorName(document.location.search),
+		var editor_name = window.opener.$.getEditorName(),
 		editor = window.opener.CKEDITOR.instances[editor_name],
 		link = '',
Index: plugins/dcLegacyEditor/js/_post_editor.js
===================================================================
--- plugins/dcLegacyEditor/js/_post_editor.js	(revision 2705)
+++ plugins/dcLegacyEditor/js/_post_editor.js	(revision 2751)
@@ -1,12 +1,4 @@
 $(function() {
 	if ($('#edit-entry').length==0) {return;}
-
-	// remove editor prefix
-	var getPostFormat = function getPostFormat(post_format) {
-		return post_format.replace(/[^:]*:/,'');
-	};
-	var getPostEditor = function getPostEditor(post_format) {
-		return post_format.replace(/:.*/,'');
-	};
 
 	// Get document format and prepare toolbars
@@ -14,7 +6,7 @@
 	var last_post_format = $(formatField).val();
 	$(formatField).change(function() {
-		if (getPostEditor(this.value)!='dcLegacyEditor') { return;}
+		if (this.value!='dcLegacyEditor') { return;}
 
-		var post_format = getPostFormat(this.value);
+		var post_format = this.value;
 
 		// Confirm post format change
@@ -37,5 +29,5 @@
 
 	$('.format_control > *').addClass('hide');
-	$('.format_control:not(.control_no_'+getPostFormat(last_post_format)+') > *').removeClass('hide');
+	$('.format_control:not(.control_no_'+last_post_format+') > *').removeClass('hide');
 
 	if ($('#comment_content').length>0) {
@@ -61,5 +53,5 @@
 				excerpt: excerpt_content,
 				content: post_content,
-				format: getPostFormat($('#post_format').get(0).value),
+				format: $('#post_format').get(0).value,
 				lang: $('#post_lang').get(0).value
 			};
@@ -111,6 +103,6 @@
 
 		// Load toolbars
-		contentTb.switchMode(getPostFormat(formatField.value));
-		excerptTb.switchMode(getPostFormat(formatField.value));
+		contentTb.switchMode(formatField.value);
+		excerptTb.switchMode(formatField.value);
 
 		// Check unsaved changes before XHTML conversion
Index: plugins/dcLegacyEditor/js/jsToolBar/jsToolBar.dotclear.js
===================================================================
--- plugins/dcLegacyEditor/js/jsToolBar/jsToolBar.dotclear.js	(revision 2614)
+++ plugins/dcLegacyEditor/js/jsToolBar/jsToolBar.dotclear.js	(revision 2751)
@@ -5,5 +5,5 @@
 jsToolBar.prototype.elements.link.open_url = 'popup_link.php';
 
-jsToolBar.prototype.elements.link.popup = function (args) {
+jsToolBar.prototype.elements.link.popup = function(args) {
 	window.the_toolbar = this;
 	args = args || '';
@@ -155,5 +155,5 @@
 	fn: {},
 	fncall: {},
-	open_url: 'media.php?popup=1',
+	open_url: 'media.php?popup=1&plugin_id=dcLegacyEditor',
 	data: {},
 	popup: function() {
@@ -355,5 +355,5 @@
 	title: 'Link to an entry',
 	fn: {},
-	open_url: 'popup_posts.php',
+	open_url: 'popup_posts.php?plugin_id=dcLegacyEditor',
 	data: {},
 	popup: function() {
Index: plugins/tags/_admin.php
===================================================================
--- plugins/tags/_admin.php	(revision 2680)
+++ plugins/tags/_admin.php	(revision 2751)
@@ -40,5 +40,5 @@
 $core->addBehavior('adminPageHelpBlock', array('tagsBehaviors', 'adminPageHelpBlock'));
 
-$core->addBehavior('ckeditorExtraPlugins', array('tagsBehaviors', 'ckeditorExtraPlugins'));
+//$core->addBehavior('ckeditorExtraPlugins', array('tagsBehaviors', 'ckeditorExtraPlugins'));
 
 # BEHAVIORS
