/** * The constructor */ public function __construct($config = array()) { parent::__construct(); $app = JFactory::getApplication(); if (!isset($config['item_id']) || empty($config['item_id'])) { throw new Exception($this->_name . ": No plugin id given"); } // Get plugin data $this->item = $this->getModel('plugin')->getItem($config['item_id']); $this->type = "plg_" . strtolower($this->item->folder) . "_" . strtolower($this->item->name); // Create plugin directory $this->createDir = $this->item->createDir; // Set template base dirs $this->templateDirs[0] = JDeveloperXTD . "/templates/plugin"; $this->templateDirs[1] = JDeveloperTEMPLATES . "/plugin"; $this->template = $this->getTemplate(); if ($this->template === false) { throw new JDeveloperException($this->getErrors()); } // Get the plugin header $params = JComponentHelper::getParams('com_jdeveloper'); $header = new JDeveloperTemplate(JDeveloperTEMPLATES . DS . 'fileheader.txt'); $header->addPlaceholders(array('Author' => $params->get('author'), 'Copyright' => $params->get('copyright'), 'Extension' => ucfirst($this->item->name), 'License' => $params->get('license'), 'Version' => $this->item->version)); self::$templateHeader = $header->getBuffer(); }
/** * Create ZIP file of plugins * * @param array $ids The primary keys of the items */ public function create($ids = array()) { // Initialize $user = JFactory::getUser(); $app = JFactory::getApplication(); $this->setRedirect(JRoute::_('index.php?option=com_jdeveloper&view=plugin', false)); if (empty($ids)) { $ids = $app->input->get('cid', array(), 'array'); } // Check access if (!$user->authorise('plugins.create', 'com_jdeveloper')) { $this->setMessage(JText::_('COM_JDEVELOPER_ACTION_NOT_ALLOWED'), 'warning'); return; } // Load classes JDeveloperLoader::import('archive'); JDeveloperLoader::import('template'); JDeveloperLoader::import('plugin', JDeveloperCREATE); jimport('joomla.filesystem.folder'); // Create Plugin for each id foreach ($ids as $id) { $plugin = $this->getModel()->getItem($id); $path = $plugin->createDir; // Delete old archive if exists JFile::exists($path . '.zip') ? JFile::delete($path . '.zip') : null; // Create Plugin try { JDeveloperCreatePlugin::execute(array("item_id" => $id)); } catch (JDeveloperException $e) { $this->setMessage($e->getMessage(), "error"); return; } // Create HTML files for each folder, zip the folder and delete the folder JDeveloperArchive::html($path); // Create ZIP archive and delete folder JDeveloperArchive::zip($path); JFolder::delete($path); } $this->setMessage(JText::sprintf('COM_JDEVELOPER_PLUGIN_MESSAGE_ZIP_CREATED', count($ids))); }
/** * @see JDeveloperCreate */ public function write($path = "") { $path = $this->createDir . "/" . $this->item->name . ".php"; return parent::write($path); }
protected function initialize() { $this->template->addPlaceHolders(array("author" => $this->item->get('author'), "author_email" => $this->item->get('author_email'), "author_url" => $this->item->get('author_url'), "configfields" => $this->getConfigFields(), "configform" => $this->getForm($this->item->form_id), "copyright" => $this->item->get('copyright'), "creationdate" => date("M Y"), "licence" => $this->item->get('licence'), "languages" => $this->lang(), "version" => $this->item->get('version'))); return parent::initialize(); }