/**
  * Return the Media Editor plugin by name
  *
  * @param string $pluginName
  *
  * @return JPlugin
  */
 private function getPluginByName($pluginName)
 {
     if (empty($pluginName)) {
         throw new RuntimeException(JText::_('COM_MEDIA_ERROR_UNKNOWN_PLUGIN'));
     }
     $plugin = MediaHelperEditor::loadPlugin($pluginName);
     if ($plugin == false) {
         throw new RuntimeException(JText::_('COM_MEDIA_ERROR_UNKNOWN_PLUGIN'));
     }
     if (method_exists($plugin, 'onMediaEditorDisplay') == false) {
         throw new RuntimeException(JText::_('COM_MEDIA_ERROR_UNKNOWN_PLUGIN'));
     }
     return $plugin;
 }
 /**
  * Post action that can be picked up upon by Media Editor plugins
  *
  * @since  3.6
  */
 public function post()
 {
     JSession::checkToken('request') or jexit(JText::_('JINVALID_TOKEN'));
     $file = $this->input->getString('file');
     $pluginName = $this->input->getCmd('plugin');
     $plugin = MediaHelperEditor::loadPlugin($pluginName);
     if ($plugin == false) {
         throw new RuntimeException(JText::_('COM_MEDIA_ERROR_UNKNOWN_PLUGIN'));
     }
     $filePath = COM_MEDIA_BASE . '/' . $file;
     $redirectUrl = $plugin->onMediaEditorProcess($filePath);
     $layout = new JLayoutFile('editor.close');
     $layoutData = array('redirectUrl' => $redirectUrl);
     echo $layout->render($layoutData);
     $app = JFactory::getApplication();
     $app->close();
 }
 /**
  * Add buttons per Media Editor plugin to the toolbar
  */
 private function addToolbarPluginButtons()
 {
     $toolbar = JToolbar::getInstance('toolbar');
     $plugins = JPluginHelper::getPlugin('media-editor');
     foreach ($plugins as $pluginData) {
         $pluginName = $pluginData->name;
         $plugin = MediaHelperEditor::loadPlugin($pluginName);
         if (method_exists($plugin, 'onMediaEditorAllowed')) {
             if ($plugin->onMediaEditorAllowed($this->fileType) == false) {
                 continue;
             }
         }
         $button = $this->getButtonFromPlugin($pluginName, $plugin);
         $toolbar->appendButton('Popup', $pluginName, $button->label, $button->url, $button->width, $button->height, 0, 0, null, $button->label);
     }
 }