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').'" />'.
