Exemplo n.º 1
0
 /**
  * Create ZIP file of template
  *
  * @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=template', false));
     if (empty($ids)) {
         $ids = $app->input->get('cid', array(), 'array');
     }
     // Check access
     if (!$user->authorise('templates.create', 'com_jdeveloper')) {
         $this->setMessage(JText::_('COM_JDEVELOPER_ACTION_NOT_ALLOWED'), 'warning');
         return;
     }
     // Load classes
     JDeveloperLoader::import('archive');
     JDeveloperLoader::import('template');
     JDeveloperLoader::import('template', JDeveloperCREATE);
     jimport('joomla.filesystem.folder');
     // Create template for each id
     foreach ($ids as $id) {
         $template = $this->getModel()->getItem($id);
         $path = $template->createDir;
         // Delete old archive if exists
         JFile::exists($path . '.zip') ? JFile::delete($path . '.zip') : null;
         // Create template
         try {
             JDeveloperCreateTemplate::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_TEMPLATE_MESSAGE_ZIP_CREATED', count($ids)));
 }
Exemplo n.º 2
0
 /**
  * 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 template id given");
     }
     // Get template data
     $this->item = $this->getModel('template')->getItem($config['item_id']);
     // Create template directory
     $this->createDir = $this->item->createDir;
     // Set template base dirs
     $this->templateDirs[0] = JDeveloperXTD . "/templates/template";
     $this->templateDirs[1] = JDeveloperTEMPLATES . "/template";
     $this->template = $this->getTemplate();
     if ($this->template === false) {
         throw new JDeveloperException($this->getErrors());
     }
     // Get the template header
     $params = JComponentHelper::getParams('com_jdeveloper');
     $header = new JDeveloperTemplate(JDeveloperTEMPLATES . '/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();
 }
Exemplo n.º 3
0
 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'), 'version' => $this->item->get('version'), 'languages' => $this->lang()));
     return parent::initialize();
 }