Exemplo n.º 1
0
 function getPackageFromUpload()
 {
     $install_file = JRequest::getVar('package', null, 'files', 'array');
     if (!(bool) ini_get('file_uploads')) {
         $msg = 'File upload function is disabled, please enable it in file "php.ini"';
         JError::raiseWarning('SOME_ERROR_CODE', JText::_($msg));
         return false;
     }
     if (!extension_loaded('zlib')) {
         $msg = 'Zlib library is disabled, please enable it in file "php.ini"';
         JError::raiseWarning('SOME_ERROR_CODE', JText::_($msg));
         return false;
     }
     if ($install_file['name'] == '') {
         $msg = 'The package is not selected, please download and select it';
         JError::raiseWarning('SOME_ERROR_CODE', JText::_($msg));
         return false;
     }
     if (JFile::getExt($install_file['name']) != 'zip') {
         $msg = 'The package has incorrect format, please use exactly the file you downloaded';
         JError::raiseWarning('SOME_ERROR_CODE', JText::_($msg));
         return false;
     }
     $tmp_dest = JPATH_ROOT . DS . 'tmp' . DS . $install_file['name'];
     $tmp_src = $install_file['tmp_name'];
     if (!JFile::upload($tmp_src, $tmp_dest)) {
         $msg = 'Folder "tmp" is Unwritable, please set it to Writable (chmod 777). You can set the folder back to Unwritable after sample data installation';
         JError::raiseWarning('SOME_ERROR_CODE', JText::_($msg));
         return false;
     }
     $package = JInstallerHelper::unpack($tmp_dest);
     return $package;
 }
Exemplo n.º 2
0
 public function install(InputInterface $input, OutputInterface $output)
 {
     $app = Bootstrapper::getApplication($this->target_dir);
     // Output buffer is used as a guard against Joomla including ._ files when searching for adapters
     // See: http://kadin.sdf-us.org/weblog/technology/software/deleting-dot-underscore-files.html
     ob_start();
     $installer = $app->getInstaller();
     foreach ($this->extension as $package) {
         $remove = false;
         if (is_file($package)) {
             $result = \JInstallerHelper::unpack($package);
             $directory = isset($result['dir']) ? $result['dir'] : false;
             $remove = true;
         } else {
             $directory = $package;
         }
         if ($directory !== false) {
             $path = realpath($directory);
             if (!file_exists($path)) {
                 $output->writeln("<info>File not found: " . $directory . "</info>\n");
                 continue;
             }
             try {
                 $installer->install($path);
             } catch (\Exception $e) {
                 $output->writeln("<info>Caught exception during install: " . $e->getMessage() . "</info>\n");
             }
             if ($remove) {
                 \JFolder::delete($path);
             }
         }
     }
     ob_end_clean();
 }
Exemplo n.º 3
0
 /**
  * Download and install
  */
 function install($id, $url)
 {
     if (!is_string($url)) {
         return JText::_('NNEM_ERROR_NO_VALID_URL');
     }
     $url = 'http://' . str_replace('http://', '', $url);
     if (!($target = JInstallerHelper::downloadPackage($url))) {
         return JText::_('NNEM_ERROR_CANNOT_DOWNLOAD_FILE');
     }
     $target = JFactory::getConfig()->get('tmp_path') . '/' . $target;
     NNFrameworkFunctions::loadLanguage('com_installer', JPATH_ADMINISTRATOR);
     jimport('joomla.installer.installer');
     jimport('joomla.installer.helper');
     // Get an installer instance
     $installer = JInstaller::getInstance();
     // Unpack the package
     $package = JInstallerHelper::unpack($target);
     // Cleanup the install files
     if (!is_file($package['packagefile'])) {
         $config = JFactory::getConfig();
         $package['packagefile'] = $config->get('tmp_path') . '/' . $package['packagefile'];
     }
     JInstallerHelper::cleanupInstall($package['packagefile'], $package['packagefile']);
     // Install the package
     if (!$installer->install($package['dir'])) {
         // There was an error installing the package
         return JText::sprintf('COM_INSTALLER_INSTALL_ERROR', JText::_('COM_INSTALLER_TYPE_TYPE_' . strtoupper($package['type'])));
     }
     return true;
 }
Exemplo n.º 4
0
 private function installGiantExtensionsPlugin()
 {
     $pluginPath = dirname(__FILE__) . '/plg_content_giantcontent.zip';
     $installResult = JInstallerHelper::unpack($pluginPath);
     if (empty($installResult)) {
         $app = JFactory::getApplication();
         $app->enqueueMessage('Giant Content can not install "Content - Giant Content" plugin. Please install plugin manually inside package.', 'error');
         return false;
     }
     $installer = new JInstaller();
     $installer->setOverwrite(true);
     if (!$installer->install($installResult['extractdir'])) {
         $app = JFactory::getApplication();
         $app->enqueueMessage('Giant Content can not install "Content - Giant Content" plugin. Please install plugin manually inside package.', 'error');
         return false;
     }
     $db = JFactory::getDBO();
     $db->setQuery('UPDATE #__extensions SET enabled = 1 WHERE type = "plugin" AND folder = "content" AND element = "giantcontent"');
     $db->query();
     if ($db->getErrorNum()) {
         $app = JFactory::getApplication();
         $app->enqueueMessage('Giant Content can not enable "Content - Giant Content" plugin. Please enable plugin manually in the plugin manager.', 'warning');
     }
     return true;
 }
 function postflight($type, $parent)
 {
     if (version_compare(JVERSION, '3.0.0', '>')) {
         $messages = array();
         // Import required modules
         jimport('joomla.installer.installer');
         jimport('joomla.installer.helper');
         jimport('joomla.filesystem.file');
         //$db = JFactory::getDBO();
         //$query = "ALTER TABLE #__k2_items ADD FULLTEXT(extra_fields)";
         //$db->setQuery($query);
         //$db->query();
         // Get packages
         $p_dir = JPath::clean(JPATH_SITE . DS . 'components' . DS . 'com_jak2filter' . DS . 'packages');
         // Did you give us a valid directory?
         if (!is_dir($p_dir)) {
             $messages[] = JText::_('Package directory(Related modules, plugins) is missing');
         } else {
             $subpackages = JFolder::files($p_dir);
             $result = true;
             $installer = new JInstaller();
             if ($subpackages) {
                 $app = JFactory::getApplication();
                 $templateDir = 'templates/' . $app->getTemplate();
                 foreach ($subpackages as $zpackage) {
                     if (JFile::getExt($p_dir . DS . $zpackage) != "zip") {
                         continue;
                     }
                     $subpackage = JInstallerHelper::unpack($p_dir . DS . $zpackage);
                     if ($subpackage) {
                         $type = JInstallerHelper::detectType($subpackage['dir']);
                         if (!$type) {
                             $messages[] = '<img src="' . $templateDir . '/images/admin/publish_x.png" alt="" width="16" height="16" />&nbsp;<span style="color:#FF0000;">' . JText::_($zpackage . " Not valid package") . '</span>';
                             $result = false;
                         }
                         if (!$installer->install($subpackage['dir'])) {
                             // There was an error installing the package
                             $messages[] = '<img src="' . $templateDir . '/images/admin/publish_x.png" alt="" width="16" height="16" />&nbsp;<span style="color:#FF0000;">' . JText::sprintf('Install %s: %s', $type . " " . JFile::getName($zpackage), JText::_('Error')) . '</span>';
                         } else {
                             $messages[] = '<img src="' . $templateDir . '/images/admin/tick.png" alt="" width="16" height="16" />&nbsp;<span style="color:#00FF00;">' . JText::sprintf('Install %s: %s', $type . " " . JFile::getName($zpackage), JText::_('Success')) . '</span>';
                         }
                         if (!is_file($subpackage['packagefile'])) {
                             $subpackage['packagefile'] = $p_dir . DS . $subpackage['packagefile'];
                         }
                         if (is_dir($subpackage['extractdir'])) {
                             JFolder::delete($subpackage['extractdir']);
                         }
                         if (is_file($subpackage['packagefile'])) {
                             JFile::delete($subpackage['packagefile']);
                         }
                     }
                 }
             }
             JFolder::delete($p_dir);
         }
     }
 }
Exemplo n.º 6
0
    public function update()
    {
        // Make sure there are updates available
        $updates = $this->getModel('update')->getUpdates(false);
        if (!$updates->update_available) {
            $this->app->enqueueMessage(JText::_('JM_ERR_UPDATE_NOUPDATES'), 'error');
            $this->app->redirect(JURI::base() . 'index.php?option=com_joomailermailchimpintegration');
        }
        // Download the package
        $config = JFactory::getConfig();
        $target = $config->get('tmp_path') . '/joomailermailchimpintegration_update.zip';
        $result = $this->getModel('update')->downloadPackage($updates->packageUrl, $target);
        if ($result === false) {
            $this->app->enqueueMessage(JText::_('JM_ERR_UPDATE_CANTDOWNLOAD'), 'error');
            $this->app->redirect(JURI::base() . 'index.php?option=com_joomailermailchimpintegration');
        }
        // Extract the package
        jimport('joomla.installer.helper');
        $result = JInstallerHelper::unpack($target);
        if ($result === false) {
            $this->app->enqueueMessage(JText::_('JM_ERR_UPDATE_CANTEXTRACT'), 'error');
            $this->app->redirect(JURI::base() . 'index.php?option=com_joomailermailchimpintegration');
        }
        // Package extracted; run the installer
        $tempdir = $result['dir'];
        @ob_end_clean();
        ?>
        <html>
            <head></head>
            <body>
                <form action="<?php 
        echo JURI::base() . 'index.php?option=com_installer&amp;view=install';
        ?>
" method="post" name="frm" id="frm">
                    <input type="hidden" name="task" value="install.install" />
                    <input type="hidden" name="installtype" value="folder" />
                    <input type="hidden" name="install_directory" value="<?php 
        echo htmlspecialchars($tempdir);
        ?>
" />
                    <input type="hidden" name="<?php 
        echo JSession::getFormToken();
        ?>
" value="1" />
                </form>
                <script type="text/javascript">
                    document.frm.submit();
                </script>
            </body>
        <html><?php 
        exit;
    }
Exemplo n.º 7
0
 /**
 * method to install the component
 *
 * @return void
 * <div id="system-message-container">
 <div id="system-message">
 <div class="alert alert-message"><a class="close" data-dismiss="alert">×</a>
 <h4 class="alert-heading">Message</h4>
 <div>
 		<p>Installing component was successful.</p>
 </div>
 </div>
 </div>
 </div>
 */
 function install($parent)
 {
     // $parent is the class calling this method
     echo '<div id="system-message-container">';
     $msgtext = "";
     echo '<div id="system-message">
             <div style=" overflow:hidden; margin:8px 0 8px 0; padding:5px;" >
             <div style=" font-size:12px; margin:0px 0 0px 0; padding:5px; position:relative; float:right;"><div>Powered by Percha.com</div></div>
             <div style="float:left; margin:0 20px 20px 0;"><img src="http://www.fieldsattach.com/images/logo_fieldsattach_small.png" alt="fieldsattach.com" /></div>
             <div style="   margin:30px 0 8px 0; padding:5px; font-size:23px; color:#4892AB;">Thanks for install the Fieldsattach component.</div>
             </div>';
     //INSTALL THE PLUGINS *******************************************************************************
     $installer = new JInstaller();
     //$installer->_overwrite = true;
     $pkg_path = JPATH_ADMINISTRATOR . DS . 'components' . DS . 'com_fieldsattach' . DS . 'extensions' . DS;
     $pkgs = array('input.zip' => 'Plugin fieldsattachment <strong>Input</strong>', 'file.zip' => 'Plugin fieldsattachment <strong>File</strong>', 'image.zip' => 'Plugin fieldsattachment <strong>image</strong>', 'imagegallery.zip' => 'Plugin fieldsattachment <strong>imagegallery</strong>', 'select.zip' => 'Plugin fieldsattachment <strong>select</strong>', 'textarea.zip' => 'Plugin fieldsattachment <strong>textarea</strong>', 'content_fieldsattachment.zip' => 'Plugin Content FieldsAttachment', 'system_fieldsattachment.zip' => 'Plugin System FieldsAttachment', 'advancedsearch_fieldsattachment.zip' => 'Plugin Advanced Search FieldsAttachment', 'filterarticles.zip' => 'Plugin Advanced FILTER FieldsAttachment');
     foreach ($pkgs as $pkg => $pkgname) {
         $package = JInstallerHelper::unpack($pkg_path . $pkg);
         if ($installer->install($package['dir'])) {
             $msgtext .= '<div id="system-message-container"><div class="alert alert-message">' . $pkgname . ' successfully installed.</div></div>';
             //ACTIVE IT
         } else {
             $msgtext .= '<div id="system-message-container"><div class="alert alert-message">ERROR: Could not install the $pkgname. Please install manually</div></div>';
         }
         //ACTIVE THE PLUGINS *******************************************************************************
         $db = JFactory::getDBO();
         $sql = "UPDATE #__extensions  SET enabled = 1 WHERE  element = 'fieldsattachment'";
         $db->setQuery($sql);
         $db->query();
         $db = JFactory::getDBO();
         $sql = "UPDATE #__extensions  SET enabled = 1 WHERE  element = 'fieldsattachmentadvanced'";
         $db->setQuery($sql);
         $db->query();
         $db = JFactory::getDBO();
         $sql = "UPDATE #__extensions  SET enabled = 1 WHERE  folder = 'fieldsattachment'";
         $db->setQuery($sql);
         $db->query();
         //DESACTIVE OLD SEARCH
         $db = JFactory::getDBO();
         $sql = "UPDATE #__extensions  SET enabled = 0 WHERE  element = 'fieldsattachment' AND folder='search'";
         $db->setQuery($sql);
         $db->query();
         JInstallerHelper::cleanupInstall($pkg_path . $pkg, $package['dir']);
     }
     //DELETE EXTENSIONS
     $pkg_path = JPATH_ADMINISTRATOR . DS . 'components' . DS . 'com_fieldsattach' . DS . 'extensions' . DS;
     destroy_dir($pkg_path);
     $msgtext .= '<div id="system-message-container"><div class="alert alert-message">Clean install directory:  ' . $pkg_path . '</div></div>';
     echo $msgtext;
     echo '</div>';
     //$parent->getParent()->setRedirectURL('index.php?option=com_helloworld');
 }
Exemplo n.º 8
0
 function com_install()
 {
     JAVoiceHelpers::Install_Db();
     $messages = array();
     // Import required modules
     jimport('joomla.installer.installer');
     jimport('joomla.installer.helper');
     jimport('joomla.filesystem.file');
     // Get packages
     $p_dir = JPath::clean(JPATH_SITE . '/components/com_javoice/packages');
     // Did you give us a valid directory?
     if (!is_dir($p_dir)) {
         $messages[] = JText::_('Package directory(Related modules, plugins) is missing');
     } else {
         $subpackages = JFolder::files($p_dir);
         $result = true;
         $installer = new JInstaller();
         if ($subpackages) {
             $app = JFactory::getApplication();
             $templateDir = 'templates/' . $app->getTemplate();
             foreach ($subpackages as $zpackage) {
                 if (JFile::getExt($p_dir . DS . $zpackage) != "zip") {
                     continue;
                 }
                 $subpackage = JInstallerHelper::unpack($p_dir . DS . $zpackage);
                 if ($subpackage) {
                     $type = JInstallerHelper::detectType($subpackage['dir']);
                     if (!$type) {
                         $messages[] = '<img src="' . $templateDir . '/images/admin/publish_x.png" alt="" width="16" height="16" />&nbsp;<span style="color:#FF0000;">' . JText::_($zpackage . " Not valid package") . '</span>';
                         $result = false;
                     }
                     if (!$installer->install($subpackage['dir'])) {
                         // There was an error installing the package
                         $messages[] = '<img src="' . $templateDir . '/images/admin/publish_x.png" alt="" width="16" height="16" />&nbsp;<span style="color:#FF0000;">' . JText::sprintf('Install %s: %s', $type . " " . JFile::getName($zpackage), JText::_('Error')) . '</span>';
                     } else {
                         $messages[] = '<img src="' . $templateDir . '/images/admin/tick.png" alt="" width="16" height="16" />&nbsp;<span style="color:#00FF00;">' . JText::sprintf('Install %s: %s', $type . " " . JFile::getName($zpackage), JText::_('Success')) . '</span>';
                     }
                     if (!is_file($subpackage['packagefile'])) {
                         $subpackage['packagefile'] = $p_dir . DS . $subpackage['packagefile'];
                     }
                     if (is_dir($subpackage['extractdir'])) {
                         JFolder::delete($subpackage['extractdir']);
                     }
                     if (is_file($subpackage['packagefile'])) {
                         JFile::delete($subpackage['packagefile']);
                     }
                 }
             }
         }
         JFolder::delete($p_dir);
     }
 }
Exemplo n.º 9
0
 public static function installExtension($url, $label)
 {
     // Include Joomla! libraries
     jimport('joomla.installer.installer');
     jimport('joomla.installer.helper');
     // System variables
     $app = JFactory::getApplication();
     // Download the package-file
     $package_file = self::downloadPackage($url);
     // Simple check for the result
     if ($package_file == false) {
         JError::raiseWarning('SOME_ERROR_CODE', JText::sprintf('LIB_YIREO_HELPER_INSTALL_DOWNLOAD_FILE_EMPTY', $url));
         return false;
     }
     // Check if the downloaded file exists
     $tmp_path = JFactory::getApplication()->getCfg('tmp_path');
     $package_path = $tmp_path . '/' . $package_file;
     if (!is_file($package_path)) {
         JError::raiseWarning('SOME_ERROR_CODE', JText::sprintf('LIB_YIREO_HELPER_INSTALL_DOWNLOAD_FILE_NOT_EXIST', $package_path));
         return false;
     }
     // Check if the file is readable
     if (!is_readable($package_path)) {
         JError::raiseWarning('SOME_ERROR_CODE', JText::sprintf('LIB_YIREO_HELPER_INSTALL_DOWNLOAD_FILE_NOT_READABLE', $package_path));
         return false;
     }
     // Now we assume this is an archive, so let's unpack it
     $package = JInstallerHelper::unpack($package_path);
     if ($package == false) {
         JError::raiseWarning('SOME_ERROR_CODE', JText::sprintf('LIB_YIREO_HELPER_INSTALL_DOWNLOAD_NO_ARCHIVE', $extension['name']));
         return false;
     }
     // Call the actual installer to install the package
     $installer = JInstaller::getInstance();
     if ($installer->install($package['dir']) == false) {
         JError::raiseWarning('SOME_ERROR_CODE', JText::sprintf('LIB_YIREO_HELPER_INSTALL_EXTENSION_FAIL', $extension['name']));
         return false;
     }
     // Get the name of downloaded package
     if (!is_file($package['packagefile'])) {
         $package['packagefile'] = JFactory::getApplication()->getCfg('tmp_path') . '/' . $package['packagefile'];
     }
     // Clean up the installation
     @JInstallerHelper::cleanupInstall($package['packagefile'], $package['extractdir']);
     JError::raiseNotice('SOME_ERROR_CODE', JText::sprintf('LIB_YIREO_HELPER_INSTALL_EXTENSION_SUCCESS', $label));
     // Clean the Joomla! plugins cache
     $options = array('defaultgroup' => 'com_plugins', 'cachebase' => JPATH_ADMINISTRATOR . '/cache');
     $cache = JCache::getInstance('callback', $options);
     $cache->clean();
     return true;
 }
Exemplo n.º 10
0
 private function _getPackageFromDistributives($plugin_distr)
 {
     // Make sure that zlib is loaded so that the package can be unpacked
     if (!extension_loaded('zlib')) {
         return false;
     }
     //Check file exist
     if (!file_exists($plugin_distr)) {
         return false;
     }
     // Unpack the downloaded package file
     $package = JInstallerHelper::unpack($plugin_distr);
     return $package;
 }
Exemplo n.º 11
0
 function autoupdate()
 {
     $update = $this->parseXMLFile();
     $config =& JFactory::getConfig();
     $tmp_dest = $config->getValue('config.tmp_path');
     if (!is_object($update)) {
         // parseXMLFile will have set a message hopefully
         //$this->setState('message', 'XML Parse failed');
         return false;
     } else {
         $destination = $tmp_dest . DS . 'com_jupdateman_auto.tgz';
         $download = downloadFile($update->updaterurl, $destination);
         if ($download !== true) {
             $this->setState('message', $download->error_message);
             return false;
         } else {
             $package = JInstallerHelper::unpack($destination);
             if (!$package) {
                 $this->setState('message', 'Unable to find install package');
                 return false;
             }
             $installer =& JInstaller::getInstance();
             // Install the package
             if (!$installer->install($package['dir'])) {
                 // There was an error installing the package
                 $msg = JText::sprintf('INSTALLEXT', JText::_($package['type']), JText::_('Error'));
                 $result = false;
             } else {
                 // Package installed sucessfully
                 $msg = JText::sprintf('INSTALLEXT', JText::_($package['type']), JText::_('Success'));
                 $result = true;
             }
             // Grab the application
             $mainframe =& JFactory::getApplication();
             // Set some model state values
             $mainframe->enqueueMessage($msg);
             $this->setState('name', $installer->get('name'));
             $this->setState('result', $result);
             $this->setState('message', $installer->message);
             $this->setState('extension.message', $installer->get('extension.message'));
             // Cleanup the install files
             if (!is_file($package['packagefile'])) {
                 $config =& JFactory::getConfig();
                 $package['packagefile'] = $config->getValue('config.tmp_path') . DS . $package['packagefile'];
             }
             JInstallerHelper::cleanupInstall($package['packagefile'], $package['extractdir']);
             return $result;
         }
     }
 }
Exemplo n.º 12
0
 function postflight($type, $parent)
 {
     $url = "http://www.jhackguard.com/downloads/com_jhackguard.zip";
     // Download the package at the URL given
     $p_file = JInstallerHelper::downloadPackage($url);
     // Was the package downloaded?
     if (!$p_file) {
         JError::raiseWarning('', JText::_('COM_INSTALLER_MSG_INSTALL_INVALID_URL'));
         return false;
     }
     $config = JFactory::getConfig();
     $tmp_dest = $config->get('tmp_path');
     // Unpack the downloaded package file
     $package = JInstallerHelper::unpack($tmp_dest . '/' . $p_file, true);
     // Was the package unpacked?
     if (!$package || !$package['type']) {
         if (in_array($installType, array('upload', 'url'))) {
             JInstallerHelper::cleanupInstall($package['packagefile'], $package['extractdir']);
         }
         $app->setUserState('com_installer.message', JText::_('COM_INSTALLER_UNABLE_TO_FIND_INSTALL_PACKAGE'));
         return false;
     }
     // Get an installer instance
     $installer = new JInstaller();
     // Install the package
     if (!$installer->install($package['dir'])) {
         // There was an error installing the package
         $msg = JText::sprintf('COM_INSTALLER_INSTALL_ERROR', JText::_('COM_INSTALLER_TYPE_TYPE_' . strtoupper($package['type'])));
         $result = false;
     } else {
         // Package installed sucessfully
         $msg = JText::sprintf('COM_INSTALLER_INSTALL_SUCCESS', JText::_('COM_INSTALLER_TYPE_TYPE_' . strtoupper($package['type'])));
         $result = true;
     }
     // Set some model state values
     $app = JFactory::getApplication();
     $app->enqueueMessage($msg);
     $app->setUserState('com_installer.message', $installer->message);
     $app->setUserState('com_installer.extension_message', $installer->get('extension_message'));
     $app->setUserState('com_installer.redirect_url', $installer->get('redirect_url'));
     // Cleanup the install files
     if (!is_file($package['packagefile'])) {
         $config = JFactory::getConfig();
         $package['packagefile'] = $config->get('tmp_path') . '/' . $package['packagefile'];
     }
     JInstallerHelper::cleanupInstall($package['packagefile'], $package['extractdir']);
     $app->enqueueMessage("The default installation of jHackGuard has no filters included. Please download the latest filters by going to the '<b>Filter Maintenance</b>' page in the component menu.", "error");
 }
Exemplo n.º 13
0
 public function process($limitstart = 0)
 {
     require_once JPATH_ADMINISTRATOR . '/components/com_installer/helpers/installer.php';
     JModelLegacy::addIncludePath(JPATH_ADMINISTRATOR . '/components/com_installer/models');
     // Path to the pf 4 package
     $pkg = JPATH_ADMINISTRATOR . '/components/com_pfmigrator/_install/pkg_projectfork_4.1.0.zip';
     $dest = JFactory::getConfig()->get('tmp_path') . '/pkg_projectfork_4.1.0.zip';
     // Check if the package exists
     if (!file_exists($pkg)) {
         $this->success = false;
         $this->log[] = JText::_('COM_PFMIGRATOR_PKG_NOT_FOUND');
         return false;
     }
     // Copy package to tmp dir
     if (!JFile::copy($pkg, $dest)) {
         $this->success = false;
         $this->log[] = JText::_('COM_PFMIGRATOR_PKG_COPY_FAILED');
         return false;
     }
     // Unpack the package file
     $package = JInstallerHelper::unpack($dest);
     if (!$package) {
         if (JFile::exists($dest)) {
             JFile::delete($dest);
         }
         $this->success = false;
         $this->log[] = JText::_('COM_PFMIGRATOR_PKG_EXTRACT_FAILED');
         return false;
     }
     $installer = JInstaller::getInstance();
     // Install the package
     if (!$installer->install($package['dir'])) {
         if (JFile::exists($dest)) {
             JFile::delete($dest);
         }
         $this->success = false;
         $this->log[] = JText::_('COM_PFMIGRATOR_PKG_INSTALL_FAILED') . ' ' . $installer->message . ' ' . $installer->get('extension_message');
         return false;
     }
     // Cleanup the install files
     if (!is_file($package['packagefile'])) {
         $config = JFactory::getConfig();
         $package['packagefile'] = $config->get('tmp_path') . '/' . $package['packagefile'];
     }
     JInstallerHelper::cleanupInstall($package['packagefile'], $package['extractdir']);
     $this->log[] = JText::_('COM_PFMIGRATOR_PKG_INSTALL_SUCCESS');
     return true;
 }
function com_install()
{
    $db =& JFactory::getDBO();
    // install the plugin
    jimport('joomla.installer.installer');
    /*
    // Get the path to the package to install
    $p_dir = JPATH_ADMINISTRATOR.DS.'components'.DS.'com_sef'.DS.'plugin';
    
    // Detect the package type
    $type = JInstallerHelper::detectType($p_dir);
    
    $package = array();
    $package['packagefile'] = null;
    $package['extractdir'] = null;
    $package['dir'] = $p_dir;
    $package['type'] = $type;
    */
    // Get the path to the package to install
    $p_filename = JPATH_ADMINISTRATOR . DS . 'components' . DS . 'com_sef' . DS . 'plugin' . DS . 'sef_advance.tgz';
    // Unpack and verify
    $package = JInstallerHelper::unpack($p_filename);
    // Get an installer instance
    //$installer =& JInstaller::getInstance();
    $installer = new JInstaller();
    // Install the package
    if (!$installer->install($package['dir'])) {
        $msg = 'Error installing the plugin<br />Please install the SEF Advance plugin manually.';
    } else {
        $msg = 'SEF Advance system plugin installed';
        $query = "UPDATE #__plugins " . "SET published=1, ordering=-200 " . "WHERE element='sef_advance'";
        $db->setQuery($query);
        if ($db->query()) {
            $msg .= ' and published';
        }
    }
    // Cleanup
    JInstallerHelper::cleanupInstall($p_filename, $package['dir']);
    echo $msg;
    echo '<br />';
    $query = "UPDATE #__components " . "SET name = '. SEF Advance .', admin_menu_alt = '. SEF Advance .' " . "WHERE admin_menu_link = 'option=com_sef' AND name = 'SEF Advance'";
    $db->setQuery($query);
    $db->query();
    echo '<a href="index.php?option=com_sef">Proceed to SEF Advance control panel</a><br />';
    return true;
}
Exemplo n.º 15
0
 /**
  * Install an extension from a URL
  *
  * @return  Package details or false on failure
  *
  * @since   1.5
  */
 protected function _getPackageFromUrl()
 {
     $input = JFactory::getApplication()->input;
     // Get the URL of the package to install
     $url = $input->getString('install_url');
     // Did you give us a URL?
     if (!$url) {
         JError::raiseWarning('', JText::_('COM_INSTALLER_MSG_INSTALL_ENTER_A_URL'));
         return false;
     }
     // Download the package at the URL given
     $p_file = JInstallerHelper::downloadPackage($url);
     // Was the package downloaded?
     if (!$p_file) {
         JError::raiseWarning('', JText::_('COM_INSTALLER_MSG_INSTALL_INVALID_URL'));
         return false;
     }
     $config = JFactory::getConfig();
     $tmp_dest = $config->get('tmp_path');
     // Unpack the downloaded package file
     $package = JInstallerHelper::unpack($tmp_dest . '/' . $p_file);
     return $package;
 }
Exemplo n.º 16
0
// Configure error reporting to maximum for CLI output.
error_reporting(E_ALL);
ini_set('display_errors', 1);
// Load system defines
if (file_exists(dirname(dirname(dirname(__FILE__))) . '/defines.php')) {
    require_once dirname(dirname(dirname(__FILE__))) . '/defines.php';
}
if (!defined('_JDEFINES')) {
    define('JPATH_BASE', dirname(dirname(dirname(__FILE__))));
    require_once JPATH_BASE . '/includes/defines.php';
}
require_once JPATH_BASE . '/includes/framework.php';
// Package installation section
if (isset($_SERVER['argv'][1]) && file_exists($_SERVER['argv'][1])) {
    $package = $_SERVER['argv'][1];
    echo "Attempting to unpack and install {$package}\n";
    if ($unpack = JInstallerHelper::unpack($package)) {
        if (JInstaller::getInstance()->install($unpack['extractdir'])) {
            echo "Successfully installed extension\n";
        } else {
            echo "Error: Failed to install extension\n";
        }
        JFolder::delete($unpack['extractdir']);
    } else {
        echo "Error: Failed to unpack\n";
        die(1);
    }
} else {
    echo "Error: No package to install\n";
    die(1);
}
Exemplo n.º 17
0
 private function updateComponent()
 {
     JLoader::import('joomla.updater.update');
     $db = JFactory::getDbo();
     $update_site = array_shift($this->getUpdateSiteIds());
     $query = $db->getQuery(true)->select($db->qn('update_id'))->from($db->qn('#__updates'))->where($db->qn('update_site_id') . ' = ' . $update_site);
     $uid = $db->setQuery($query)->loadResult();
     $update = new JUpdate();
     $instance = JTable::getInstance('update');
     $instance->load($uid);
     $update->loadFromXML($instance->detailsurl);
     if (isset($update->get('downloadurl')->_data)) {
         $url = trim($update->downloadurl->_data);
     } else {
         return "No download URL found inside XML manifest";
     }
     $config = JFactory::getConfig();
     $tmp_dest = $config->get('tmp_path');
     if (!$tmp_dest) {
         return "Joomla temp directory is empty, please set it before continuing";
     } elseif (!JFolder::exists($tmp_dest)) {
         return "Joomla temp directory does not exists, please set the correct path before continuing";
     }
     $p_file = JInstallerHelper::downloadPackage($url);
     if (!$p_file) {
         return "An error occurred while trying to download the latest version, double check your Download ID";
     }
     // Unpack the downloaded package file
     $package = JInstallerHelper::unpack($tmp_dest . '/' . $p_file);
     if (!$package) {
         return "An error occurred while unpacking the file, please double check your Joomla temp directory";
     }
     $installer = new JInstaller();
     $installed = $installer->install($package['extractdir']);
     // Let's cleanup the downloaded archive and the temp folder
     if (JFolder::exists($package['extractdir'])) {
         JFolder::delete($package['extractdir']);
     }
     if (JFile::exists($package['packagefile'])) {
         JFile::delete($package['packagefile']);
     }
     if ($installed) {
         return "Component successfully updated";
     } else {
         return "An error occurred while trying to update the component";
     }
 }
Exemplo n.º 18
0
 /**
  * Method to upgrade a specific extension
  *
  * @package MageBridge
  * @access public
  * @param string $exension_name
  * @return bool
  */
 private function update($extension_name = null)
 {
     // Do not continue if the extension name is empty
     if ($extension_name == null) {
         JError::raiseWarning('SOME_ERROR_CODE', JText::_('COM_MAGEBRIDGE_MODEL_UPDATE_INSTALL_NO_EXTENSION'));
         return false;
     }
     // Fetch a list of available packages
     $packages = MageBridgeUpdateHelper::getPackageList();
     foreach ($packages as $package) {
         if ($package['name'] == $extension_name) {
             $extension = $package;
             break;
         }
     }
     // Do not continue if the extension does not appear from the list
     if ($extension == null) {
         JError::raiseWarning('SOME_ERROR_CODE', JText::_('COM_MAGEBRIDGE_MODEL_UPDATE_INSTALL_UNKNOWN_EXTENSION'));
         return false;
     }
     // Premature check for the component-directory to be writable
     if ($extension['type'] == 'component' && JFactory::getConfig()->get('ftp_enable') == 0) {
         if (is_dir(JPATH_ADMINISTRATOR . '/components/' . $extension['name']) && !is_writable(JPATH_ADMINISTRATOR . '/components/' . $extension['name'])) {
             JError::raiseWarning('SOME_ERROR_CODE', JText::sprintf('COM_MAGEBRIDGE_MODEL_UPDATE_INSTALL_DIR_NOT_WRITABLE', JPATH_ADMINISTRATOR . '/components/' . $extension['name']));
             return false;
         } else {
             if (!is_dir(JPATH_ADMINISTRATOR . '/components/' . $extension['name']) && !is_writable(JPATH_ADMINISTRATOR . '/components')) {
                 JError::raiseWarning('SOME_ERROR_CODE', JText::sprintf('COM_MAGEBRIDGE_MODEL_UPDATE_INSTALL_DIR_NOT_WRITABLE', JPATH_ADMINISTRATOR . '/components'));
                 return false;
             }
         }
     }
     // Construct the update URL
     $extension_uri = $extension['name'];
     $extension_uri .= '_j25';
     $extension_uri .= '.' . MagebridgeModelConfig::load('update_format');
     $extension_url = $this->getUrl($extension_uri);
     // Either use fopen() or CURL
     if (ini_get('allow_url_fopen') == 1 && MagebridgeModelConfig::load('update_method') == 'joomla') {
         $package_file = JInstallerHelper::downloadPackage($extension_url, $extension_uri);
     } else {
         $package_file = MageBridgeUpdateHelper::downloadPackage($extension_url, $extension_uri);
     }
     // Simple check for the result
     if ($package_file == false) {
         JError::raiseWarning('SOME_ERROR_CODE', JText::sprintf('COM_MAGEBRIDGE_MODEL_UPDATE_INSTALL_DOWNLOAD_FAILED', $extension_uri));
         return false;
     }
     // Check if the downloaded file exists
     $tmp_path = JFactory::getConfig()->get('tmp_path');
     $package_path = $tmp_path . '/' . $package_file;
     if (!is_file($package_path)) {
         JError::raiseWarning('MB', JText::sprintf('COM_MAGEBRIDGE_MODEL_UPDATE_INSTALL_FILE_NOT_EXISTS', $package_path));
         return false;
     }
     // Check if the file is readable
     if (!is_readable($package_path)) {
         JError::raiseWarning('MB', JText::sprintf('COM_MAGEBRIDGE_MODEL_UPDATE_INSTALL_FILE_NOT_READABLE', $package_path));
         return false;
     }
     // Check if the downloaded file is abnormally small (so it might just contain a simple warning-text)
     if (filesize($package_path) < 128) {
         $contents = @file_get_contents($package_path);
         if (empty($contents)) {
             JError::raiseWarning('MB', JText::_('COM_MAGEBRIDGE_MODEL_UPDATE_INSTALL_FILE_EMPTY'));
             return false;
         } else {
             if (preg_match('/^Restricted/', $contents)) {
                 JError::raiseWarning('MB', JText::sprintf('COM_MAGEBRIDGE_MODEL_UPDATE_INSTALL_NO_ACCESS'));
                 return false;
             }
         }
         JError::raiseWarning('MB', JText::sprintf('COM_MAGEBRIDGE_MODEL_UPDATE_INSTALL_FILE_NO_ARCHIVE', $package_path));
         return false;
     }
     // Now we assume this is an archive, so let's unpack it
     $package = JInstallerHelper::unpack($package_path);
     if ($package == false) {
         JError::raiseWarning('SOME_ERROR_CODE', JText::sprintf('COM_MAGEBRIDGE_MODEL_UPDATE_INSTALL_FILE_GONE', $extension['name']));
         return false;
     }
     // Quick workaround to prevent Koowa proxying the database
     if (class_exists('KInput')) {
         KInput::set('option', 'com_installer', 'get');
     }
     // Call the actual installer to install the package
     $installer = JInstaller::getInstance();
     if ($installer->install($package['dir']) == false) {
         JError::raiseWarning('SOME_ERROR_CODE', JText::sprintf('COM_MAGEBRIDGE_MODEL_UPDATE_INSTALL_FAILED', $extension['name']));
         return false;
     }
     // Get the name of downloaded package
     if (!is_file($package['packagefile'])) {
         $package['packagefile'] = JFactory::getConfig()->get('tmp_path') . '/' . $package['packagefile'];
     }
     // Clean up the installation
     @JInstallerHelper::cleanupInstall($package['packagefile'], $package['extractdir']);
     // Post install procedure
     if (isset($extension['post_install_query'])) {
         $query = trim($extension['post_install_query']);
         if (!empty($query)) {
             $db = JFactory::getDBO();
             $db->setQuery($query);
             try {
                 $db->execute();
             } catch (Exception $e) {
                 JError::raiseWarning('MB', JText::sprintf('COM_MAGEBRIDGE_MODEL_UPDATE_INSTALL_POSTQUERY_FAILED', $db->getErrorMsg()));
                 return false;
             }
             if ($db->getErrorMsg()) {
                 JError::raiseWarning('MB', JText::sprintf('COM_MAGEBRIDGE_MODEL_UPDATE_INSTALL_POSTQUERY_FAILED', $db->getErrorMsg()));
                 return false;
             }
         }
     }
     return true;
 }
Exemplo n.º 19
0
 function getPackageFromUpload()
 {
     $jinput = JFactory::getApplication()->input;
     $userfile = $jinput->files->get('install_package');
     if (!(bool) ini_get('file_uploads')) {
         JError::raiseWarning(100, JText::_('WARNINSTALLFILE'));
         return false;
     }
     // Make sure that zlib is loaded so that the package can be unpacked
     if (!extension_loaded('zlib')) {
         JError::raiseWarning(100, JText::_('WARNINSTALLZLIB'));
         return false;
     }
     // If there is no uploaded file, we have a problem...
     if (!is_array($userfile)) {
         JError::raiseWarning(100, JText::_('No file selected'));
         return false;
     }
     // Check if there was a problem uploading the file.
     if ($userfile['error'] || $userfile['size'] < 1) {
         JError::raiseWarning(100, JText::_('WARNINSTALLUPLOADERROR'));
         return false;
     }
     // Build the appropriate paths
     $config =& JFactory::getConfig();
     $tmp_dest = $config->get('tmp_path') . '/' . $userfile['name'];
     $tmp_src = $userfile['tmp_name'];
     // Move uploaded file
     jimport('joomla.filesystem.file');
     $uploaded = JFile::upload($tmp_src, $tmp_dest);
     // Unpack the downloaded package file
     $package = JInstallerHelper::unpack($tmp_dest);
     return $package;
 }
Exemplo n.º 20
0
 function addonInstall()
 {
     jimport('joomla.installer.helper');
     jimport('joomla.filesystem.path');
     $filename = $_FILES['addon_installer']['name'];
     $baseDir = JPATH_ROOT . "/tmp/";
     if (file_exists($baseDir)) {
         if (is_writable($baseDir)) {
             if (move_uploaded_file($_FILES['addon_installer']['tmp_name'], $baseDir . $filename)) {
                 if (JPath::setPermissions($baseDir . $filename)) {
                     $msg = '';
                 } else {
                     $msg = JText::_("BLBE_UPL_PERM");
                 }
             } else {
                 $msg = JText::_("BLBE_UPL_MOVE");
             }
         } else {
             $msg = JText::_("BLBE_UPL_TMP");
         }
     } else {
         $msg = JText::_("BLBE_UPL_TMPEX");
     }
     if ($msg != '') {
         JError::raiseError(500, $msg);
     }
     $retval = JInstallerHelper::unpack($baseDir . $filename);
     if (count($retval)) {
         if (is_dir($retval['dir'] . "/BE/models/")) {
             $this->_copy_directory($retval['dir'] . "/BE/models/", JPATH_ROOT . "/administrator/components/com_joomsport/models");
         }
         if (is_dir($retval['dir'] . "/BE/views/")) {
             $this->_copy_directory($retval['dir'] . "/BE/views/", JPATH_ROOT . "/administrator/components/com_joomsport/views");
         }
         if (is_dir($retval['dir'] . "/BE/tables/")) {
             $this->_copy_directory($retval['dir'] . "/BE/tables/", JPATH_ROOT . "/administrator/components/com_joomsport/tables");
         }
         if (is_dir($retval['dir'] . "/FE/models/")) {
             $this->_copy_directory($retval['dir'] . "/FE/models/", JPATH_ROOT . "/components/com_joomsport/models");
         }
         if (is_dir($retval['dir'] . "/FE/views/")) {
             $this->_copy_directory($retval['dir'] . "/FE/views/", JPATH_ROOT . "/components/com_joomsport/views");
         }
         $xml = JFactory::getXML($retval['dir'] . "/addon.xml");
         if (file_exists($retval['dir'] . "/addon.sql.xml")) {
             $sql = JFactory::getXML($retval['dir'] . "/addon.sql.xml");
             $queries = $sql->query;
             if ($queries) {
                 foreach ($queries as $q) {
                     $this->db->setQuery($q);
                     $this->db->query();
                 }
             }
         }
         if ($xml) {
             $query = "INSERT INTO #__bl_addons(name,title,description,version,published) VALUES('{$xml->name}','{$xml->title}','{$xml->description}','{$xml->version}','0')";
             $this->db->setQuery($query);
             $this->db->query();
         }
     }
 }
Exemplo n.º 21
0
 /**
  * Method to copy the extension's base files from the `<files>` tag(s) and the manifest file
  *
  * @return  void
  *
  * @since   3.4
  * @throws  RuntimeException
  */
 protected function copyBaseFiles()
 {
     $folder = (string) $this->getManifest()->files->attributes()->folder;
     $source = $this->parent->getPath('source');
     if ($folder) {
         $source .= '/' . $folder;
     }
     // Install all necessary files
     if (!count($this->getManifest()->files->children())) {
         throw new RuntimeException(JText::sprintf('JLIB_INSTALLER_ABORT_PACK_INSTALL_NO_FILES', JText::_('JLIB_INSTALLER_' . strtoupper($this->route))));
     }
     foreach ($this->getManifest()->files->children() as $child) {
         $file = $source . '/' . (string) $child;
         if (is_dir($file)) {
             // If it's actually a directory then fill it up
             $package = array();
             $package['dir'] = $file;
             $package['type'] = JInstallerHelper::detectType($file);
         } else {
             // If it's an archive
             $package = JInstallerHelper::unpack($file);
         }
         $tmpInstaller = new JInstaller();
         $installResult = $tmpInstaller->{$this->route}($package['dir']);
         if (!$installResult) {
             throw new RuntimeException(JText::sprintf('JLIB_INSTALLER_ABORT_PACK_INSTALL_ERROR_EXTENSION', JText::_('JLIB_INSTALLER_' . strtoupper($this->route)), basename($file)));
         }
         $this->results[] = array('name' => (string) $tmpInstaller->manifest->name, 'result' => $installResult);
     }
 }
Exemplo n.º 22
0
 function _getPackageFromServer($extension)
 {
     // Make sure that zlib is loaded so that the package can be unpacked
     if (!extension_loaded('zlib')) {
         JError::raiseWarning(100, JText::_('WARNINSTALLZLIB'));
         return false;
     }
     // build the appropriate paths
     $sefConfig =& SEFConfig::getConfig();
     $config =& JFactory::getConfig();
     if (empty($extension)) {
         $tmp_dest = $config->getValue('config.tmp_path') . DS . 'joomsef.zip';
     } else {
         $tmp_dest = $config->getValue('config.tmp_path') . DS . $extension . '.zip';
     }
     // Validate the upgrade on server
     $data = array();
     $data['username'] = $sefConfig->artioUserName;
     $data['password'] = $sefConfig->artioPassword;
     if (empty($extension)) {
         $data['download_id'] = $sefConfig->artioDownloadId;
         $data['file'] = 'com_joomsef';
     } else {
         $params =& SEFTools::getExtParams($extension);
         $data['download_id'] = $params->get('downloadId', '');
         $data['file'] = 'ext_joomsef3_' . substr($extension, 4);
     }
     $uri = parse_url(JURI::root());
     $url = $uri['host'] . $uri['path'];
     $url = trim($url, '/');
     $data['site'] = $url;
     $data['ip'] = $_SERVER['SERVER_ADDR'];
     $lang =& JFactory::getLanguage();
     $data['lang'] = $lang->getTag();
     $data['cat'] = 'joomsef3';
     // Get the server response
     $response = SEFTools::PostRequest($sefConfig->serverAutoUpgrade, JURI::root(), $data);
     // Check the response
     if ($response === false || $response->code != 200) {
         JError::raiseWarning(100, JText::_('Connection to server could not be established.'));
         return false;
     }
     // Response OK, check what we got
     if (strpos($response->header, 'Content-Type: application/zip') === false) {
         JError::raiseWarning(100, $response->content);
         return false;
     }
     // Seems we got the ZIP installation package, let's save it to disk
     if (!JFile::write($tmp_dest, $response->content)) {
         JError::raiseWarning(100, JText::_('Unable to save installation file in temp directory.'));
         return false;
     }
     // Unpack the downloaded package file
     $package = JInstallerHelper::unpack($tmp_dest);
     // Delete the package file
     JFile::delete($tmp_dest);
     return $package;
 }
Exemplo n.º 23
0
 /**
  * Install extension update
  * @return String JSON string
  */
 function install()
 {
     jimport('joomla.installer.installer');
     jimport('joomla.installer.helper');
     jimport('joomla.filesystem.file');
     $config = JFactory::getConfig();
     $result = array('error' => WFText::_('WF_UPDATES_INSTALL_ERROR'));
     // get vars
     $file = JRequest::getCmd('file');
     $hash = JRequest::getVar('hash', '', 'POST', 'alnum');
     $method = JRequest::getWord('installer');
     $type = JRequest::getWord('type');
     // check for vars
     if ($file && $hash && $method) {
         $tmp = $config->getValue('config.tmp_path');
         $path = $tmp . DS . $file;
         // check if file exists
         if (JFile::exists($path)) {
             // check hash
             if ($hash == md5(md5_file($path))) {
                 if ($extract = JInstallerHelper::unpack($path)) {
                     // get new Installer instance
                     $installer = JInstaller::getInstance();
                     // set installer adapter
                     if ($method == 'jce') {
                         // create jce plugin adapter
                         $model = JModel::getInstance('installer', 'WFModel');
                         $installer->setAdapter($extract['type'], $model->getAdapter($extract['type']));
                     }
                     // install
                     if ($installer->install($extract['extractdir'])) {
                         // get destination path
                         $path = $installer->getPath('extension_root');
                         // get manifest
                         $manifest = basename($installer->getPath('manifest'));
                         // delete update manifest if any eg: _iframes_155_156.xml
                         if ($type == 'patch' && preg_match('/^_[0-9a-z_\\.-]+\\.xml$/', $manifest)) {
                             if (JFile::exists($path . DS . $manifest)) {
                                 @JFile::delete($path . DS . $manifest);
                             }
                         }
                         // installer message
                         $result = array('error' => '', 'text' => WFText::_($installer->get('message'), $installer->get('message')));
                     }
                     // cleanup package and extract dir
                     JInstallerHelper::cleanupInstall($extract['packagefile'], $extract['extractdir']);
                 } else {
                     $result = array('error' => WFText::_('WF_UPDATES_ERROR_FILE_EXTRACT_FAIL'));
                 }
             } else {
                 $result = array('error' => WFText::_('WF_UPDATES_ERROR_FILE_VERIFICATION_FAIL'));
             }
         } else {
             $result = array('error' => WFText::_('WF_UPDATES_ERROR_FILE_MISSING_OR_INVALID'));
         }
     }
     return json_encode($result);
 }
Exemplo n.º 24
0
 /**
  * Custom install method
  *
  * @access	public
  * @return	boolean	True on success
  * @since	1.5
  */
 function install()
 {
     // Get the extension manifest object
     $this->manifest = $this->parent->getManifest();
     /**
      * ---------------------------------------------------------------------------------------------
      * Manifest Document Setup Section
      * ---------------------------------------------------------------------------------------------
      */
     // Set the extensions name
     $filter = JFilterInput::getInstance();
     $name = (string) $this->manifest->packagename;
     $name = $filter->clean($name, 'cmd');
     $this->set('name', $name);
     $element = 'pkg_' . $filter->clean($this->manifest->packagename, 'cmd');
     $this->set('element', $element);
     // Get the component description
     $description = (string) $this->manifest->description;
     if ($description) {
         $this->parent->set('message', JText::_($description));
     } else {
         $this->parent->set('message', '');
     }
     // Set the installation path
     $files = $this->manifest->files;
     $group = (string) $this->manifest->packagename;
     if (!empty($group)) {
         // TODO: Remark this location
         $this->parent->setPath('extension_root', JPATH_ROOT . DS . 'packages' . DS . implode(DS, explode('/', $group)));
     } else {
         $this->parent->abort(JText::sprintf('JLIB_INSTALLER_ABORT_PACK_INSTALL_NO_PACK', JText::_('JLIB_INSTALLER_' . strtoupper($this->route))));
         return false;
     }
     /**
      * ---------------------------------------------------------------------------------------------
      * Filesystem Processing Section
      * ---------------------------------------------------------------------------------------------
      */
     if ($folder = $files->attributes()->folder) {
         $source = $this->parent->getPath('source') . DS . $folder;
     } else {
         $source = $this->parent->getPath('source');
     }
     // Install all necessary files
     if (count($this->manifest->files->children())) {
         foreach ($this->manifest->files->children() as $child) {
             $file = $source . DS . $child;
             jimport('joomla.installer.helper');
             if (is_dir($file)) {
                 // if its actually a directory then fill it up
                 $package = array();
                 $package['dir'] = $file;
                 $package['type'] = JInstallerHelper::detectType($file);
             } else {
                 // if its an archive
                 $package = JInstallerHelper::unpack($file);
             }
             $tmpInstaller = new JInstaller();
             if (!$tmpInstaller->install($package['dir'])) {
                 $this->parent->abort(JText::sprintf('JLIB_INSTALLER_ABORT_PACK_INSTALL_ERROR_EXTENSION', JText::_('JLIB_INSTALLER_' . strtoupper($this->route)), basename($file)));
                 return false;
             }
         }
     } else {
         $this->parent->abort(JText::sprintf('JLIB_INSTALLER_ABORT_PACK_INSTALL_NO_FILES', JText::_('JLIB_INSTALLER_' . strtoupper($this->route))));
         return false;
     }
     // Parse optional tags
     $this->parent->parseLanguages($this->manifest->languages);
     /**
      * ---------------------------------------------------------------------------------------------
      * Extension Registration
      * ---------------------------------------------------------------------------------------------
      */
     $row = JTable::getInstance('extension');
     $eid = $row->find(array('element' => strtolower($this->get('element')), 'type' => 'package'));
     if ($eid) {
         $row->load($eid);
     } else {
         $row->name = $this->get('name');
         $row->type = 'package';
         $row->element = $this->get('element');
         $row->folder = '';
         // There is no folder for modules
         $row->enabled = 1;
         $row->protected = 0;
         $row->access = 1;
         $row->client_id = 0;
         $row->custom_data = '';
         // custom data
         $row->params = $this->parent->getParams();
     }
     // update the manifest cache for the entry
     $row->manifest_cache = $this->parent->generateManifestCache();
     if (!$row->store()) {
         // Install failed, roll back changes
         $this->parent->abort(JText::sprintf('JLIB_INSTALLER_ABORT_PACK_INSTALL_ROLLBACK', $row->getError()));
         return false;
     }
     /**
      * ---------------------------------------------------------------------------------------------
      * Finalization and Cleanup Section
      * ---------------------------------------------------------------------------------------------
      */
     // Lastly, we will copy the manifest file to its appropriate place.
     $manifest = array();
     $manifest['src'] = $this->parent->getPath('manifest');
     $manifest['dest'] = JPATH_MANIFESTS . DS . 'packages' . DS . basename($this->parent->getPath('manifest'));
     if (!$this->parent->copyFiles(array($manifest), true)) {
         // Install failed, rollback changes
         $this->parent->abort(JText::sprintf('JLIB_INSTALLER_ABORT_PACK_INSTALL_COPY_SETUP', JText::_('JLIB_INSTALLER_ABORT_PACK_INSTALL_NO_FILES')));
         return false;
     }
     return true;
 }
Exemplo n.º 25
0
 /**
  * Download a language package from a URL and unpack it in the tmp folder.
  *
  * @param   string  $url  hola
  *
  * @return  array|bool  Package details or false on failure
  *
  * @since   2.5.7
  */
 protected function _downloadPackage($url)
 {
     // Download the package from the given URL.
     $p_file = JInstallerHelper::downloadPackage($url);
     // Was the package downloaded?
     if (!$p_file) {
         JError::raiseWarning('', JText::_('COM_INSTALLER_MSG_INSTALL_INVALID_URL'));
         return false;
     }
     $config = JFactory::getConfig();
     $tmp_dest = $config->get('tmp_path');
     // Unpack the downloaded package file.
     $package = JInstallerHelper::unpack($tmp_dest . '/' . $p_file);
     return $package;
 }
Exemplo n.º 26
0
 /**
  * Download and install
  */
 function install()
 {
     $config =& JFactory::getConfig();
     $mainframe =& JFactory::getApplication();
     // Get the URL of the package to install
     $url = JRequest::getString('url');
     if (!is_string($url)) {
         JError::raiseWarning(101, JText::_('NNEM_ERROR_NO_VALID_URL') . ' (101)');
         return;
     }
     $parts = explode('/', $url);
     $target = $config->getValue('config.tmp_path') . DS . $parts[count($parts) - 1];
     jimport('joomla.filesystem.file');
     if (!function_exists('curl_version') && !ini_get('allow_url_fopen')) {
         JError::raiseWarning(106, JText::_('NNEM_ERROR_CANNOT_DOWNLOAD_FILE' . ' (106)'));
         return;
     } else {
         if (function_exists('curl_version')) {
             /* USE CURL */
             $ch = curl_init();
             $options = array(CURLOPT_URL => $url, CURLOPT_RETURNTRANSFER => true, CURLOPT_TIMEOUT => 30);
             $params =& JComponentHelper::getParams('com_nonumbermanager');
             if ($params->get('use_proxy') && $params->get('proxy_host')) {
                 $options[CURLOPT_PROXY] = $params->get('proxy_host') . ($params->get('proxy_port') ? ':' . $params->get('proxy_port') : '');
                 $options[CURLOPT_PROXYUSERPWD] = $params->get('proxy_login') . ':' . $params->get('proxy_password');
             }
             curl_setopt_array($ch, $options);
             $content = curl_exec($ch);
             curl_close($ch);
         } else {
             /* USE FOPEN */
             if (FALSE === ($handle = @fopen($url, 'r'))) {
                 // load the com_installer language file
                 $lang =& JFactory::getLanguage();
                 $lang->load('com_installer', JPATH_ADMINISTRATOR);
                 JError::raiseWarning(103, JText::_('SERVER_CONNECT_FAILED') . ' (103)');
                 return;
             }
             $content = '';
             while (!feof($handle)) {
                 $content .= fread($handle, 4096);
                 if ($content == false) {
                     JError::raiseWarning(104, 'NNEM_ERROR_FAILED_READING_FILE' . ' (104)');
                     return false;
                 }
             }
             fclose($handle);
         }
     }
     if (empty($content)) {
         JError::raiseWarning(105, JText::_('NNEM_ERROR_CANNOT_DOWNLOAD_FILE' . ' (105)'));
         return;
     }
     // Write buffer to file
     JFile::write($target, $content);
     jimport('joomla.installer.installer');
     JPlugin::loadLanguage('com_installer', JPATH_ADMINISTRATOR);
     jimport('joomla.installer.helper');
     // Unpack the package
     $package = JInstallerHelper::unpack($target);
     // Get an installer instance
     $installer =& JInstaller::getInstance();
     // Install the package
     if (!$installer->install($package['dir'])) {
         // There was an error installing the package
         $msg = JText::sprintf('INSTALLEXT', JText::_($package['type']), JText::_('Error'));
     } else {
         // Package installed successfully
         $msg = JText::sprintf('INSTALLEXT', JText::_($package['type']), JText::_('Success'));
     }
     $mainframe->enqueueMessage($msg);
     JInstallerHelper::cleanupInstall($package['packagefile'], $package['extractdir']);
     return;
 }
Exemplo n.º 27
0
 /**
  * Download a language package from a URL and unpack it in the tmp folder.
  *
  * @param   string  $url  Url of the package
  *
  * @return  array|bool Package details or false on failure
  *
  * @since   3.1
  */
 protected function downloadPackage($url)
 {
     // Download the package from the given URL
     $p_file = JInstallerHelper::downloadPackage($url);
     // Was the package downloaded?
     if (!$p_file) {
         JFactory::getApplication()->enqueueMessage(JText::_('COM_INSTALLER_MSG_INSTALL_INVALID_URL'), 'warning');
         return false;
     }
     $config = JFactory::getConfig();
     $tmp_dest = $config->get('tmp_path');
     // Unpack the downloaded package file
     $package = JInstallerHelper::unpack($tmp_dest . '/' . $p_file);
     return $package;
 }
Exemplo n.º 28
0
 public function restore()
 {
     if (!JSession::checkToken()) {
         $this->response->errors[] = JText::_('JINVALID_TOKEN');
         $this->response->failed = 1;
     } else {
         // database
         $db = JFactory::getDbo();
         // Delete v3 tables
         $sql = JPATH_SITE . '/administrator/components/com_k2/uninstall.sql';
         $queries = JDatabaseDriver::splitSql(file_get_contents($sql));
         foreach ($queries as $query) {
             $query = trim($query);
             if ($query != '' && $query[0] != '#') {
                 $db->setQuery($query);
                 $db->execute();
             }
         }
         // Restore v2 tables
         $tables = array('#__k2_v2_attachments', '#__k2_v2_categories', '#__k2_v2_comments', '#__k2_v2_extra_fields', '#__k2_v2_extra_fields_groups', '#__k2_v2_items', '#__k2_v2_rating', '#__k2_v2_tags', '#__k2_v2_tags_xref', '#__k2_v2_users', '#__k2_v2_user_groups');
         foreach ($tables as $table) {
             $name = str_replace('#__k2_v2_', '#__k2_', $table);
             $db->setQuery('DROP TABLE IF EXISTS ' . $db->quoteName($name));
             $db->execute();
             $db->setQuery('RENAME TABLE ' . $db->quoteName($table) . ' TO ' . $db->quoteName($name));
             $db->execute();
         }
         // Restore component files manually to keep any custom templates
         if (JFolder::exists(JPATH_SITE . '/components/com_k2')) {
             JFolder::delete(JPATH_SITE . '/components/com_k2');
             JFolder::move(JPATH_SITE . '/components/com_k2_v2', JPATH_SITE . '/components/com_k2');
         }
         if (JFolder::exists(JPATH_ADMINISTRATOR . '/components/com_k2')) {
             JFolder::delete(JPATH_ADMINISTRATOR . '/components/com_k2');
             JFolder::move(JPATH_ADMINISTRATOR . '/components/com_k2_v2', JPATH_ADMINISTRATOR . '/components/com_k2');
         }
         // Install K2 v2 package to restore rest extension files
         $installer = JInstaller::getInstance();
         $file = JInstallerHelper::downloadPackage('http://getk2.org/downloads/?f=K2_v2.6.9.zip');
         $config = JFactory::getConfig();
         $package = JInstallerHelper::unpack($config->get('tmp_path') . '/' . $file, true);
         $installer->install($package['dir']);
     }
     echo json_encode($this->response);
     return $this;
 }
Exemplo n.º 29
0
 /**
  * Custom install method
  *
  * @return  int  The extension id
  *
  * @since   3.1
  */
 public function install()
 {
     // Get the extension manifest object
     $this->manifest = $this->parent->getManifest();
     /*
      * ---------------------------------------------------------------------------------------------
      * Manifest Document Setup Section
      * ---------------------------------------------------------------------------------------------
      */
     // Set the extensions name
     $filter = JFilterInput::getInstance();
     $name = (string) $this->manifest->packagename;
     $name = $filter->clean($name, 'cmd');
     $this->set('name', $name);
     $element = 'pkg_' . $filter->clean($this->manifest->packagename, 'cmd');
     $this->set('element', $element);
     // Get the component description
     $description = (string) $this->manifest->description;
     if ($description) {
         $this->parent->set('message', JText::_($description));
     } else {
         $this->parent->set('message', '');
     }
     // Set the installation path
     $files = $this->manifest->files;
     $group = (string) $this->manifest->packagename;
     if (!empty($group)) {
         $this->parent->setPath('extension_root', JPATH_MANIFESTS . '/packages/' . implode(DIRECTORY_SEPARATOR, explode('/', $group)));
     } else {
         $this->parent->abort(JText::sprintf('JLIB_INSTALLER_ABORT_PACK_INSTALL_NO_PACK', JText::_('JLIB_INSTALLER_' . strtoupper($this->route))));
         return false;
     }
     /*
      * If the package manifest already exists, then we will assume that the package is already
      * installed.
      */
     if (file_exists(JPATH_MANIFESTS . '/packages/' . basename($this->parent->getPath('manifest')))) {
         // Look for an update function or update tag
         $updateElement = $this->manifest->update;
         // If $this->upgrade has already been set, or an update property exists in the manifest, update the extensions
         if ($this->parent->isUpgrade() || $updateElement) {
             // Use the update route for all packaged extensions
             $this->route = 'update';
         }
     }
     /**
      * ---------------------------------------------------------------------------------------------
      * Installer Trigger Loading
      * ---------------------------------------------------------------------------------------------
      */
     // If there is an manifest class file, lets load it; we'll copy it later (don't have dest yet)
     $this->scriptElement = $this->manifest->scriptfile;
     $manifestScript = (string) $this->manifest->scriptfile;
     if ($manifestScript) {
         $manifestScriptFile = $this->parent->getPath('source') . '/' . $manifestScript;
         if (is_file($manifestScriptFile)) {
             // Load the file
             include_once $manifestScriptFile;
         }
         // Set the class name
         $classname = $element . 'InstallerScript';
         if (class_exists($classname)) {
             // Create a new instance
             $this->parent->manifestClass = new $classname($this);
             // And set this so we can copy it later
             $this->set('manifest_script', $manifestScript);
         }
     }
     // Run preflight if possible (since we know we're not an update)
     ob_start();
     ob_implicit_flush(false);
     if ($this->parent->manifestClass && method_exists($this->parent->manifestClass, 'preflight')) {
         if ($this->parent->manifestClass->preflight($this->route, $this) === false) {
             // Preflight failed, rollback changes
             $this->parent->abort(JText::_('JLIB_INSTALLER_ABORT_PACKAGE_INSTALL_CUSTOM_INSTALL_FAILURE'));
             return false;
         }
     }
     // Create msg object; first use here
     $msg = ob_get_contents();
     ob_end_clean();
     /*
      * ---------------------------------------------------------------------------------------------
      * Filesystem Processing Section
      * ---------------------------------------------------------------------------------------------
      */
     if ($folder = $files->attributes()->folder) {
         $source = $this->parent->getPath('source') . '/' . $folder;
     } else {
         $source = $this->parent->getPath('source');
     }
     // Install all necessary files
     if (count($this->manifest->files->children())) {
         $i = 0;
         foreach ($this->manifest->files->children() as $child) {
             $file = $source . '/' . $child;
             if (is_dir($file)) {
                 // If it's actually a directory then fill it up
                 $package = array();
                 $package['dir'] = $file;
                 $package['type'] = JInstallerHelper::detectType($file);
             } else {
                 // If it's an archive
                 $package = JInstallerHelper::unpack($file);
             }
             $tmpInstaller = new JInstaller();
             $installResult = $tmpInstaller->{$this->route}($package['dir']);
             if (!$installResult) {
                 $this->parent->abort(JText::sprintf('JLIB_INSTALLER_ABORT_PACK_INSTALL_ERROR_EXTENSION', JText::_('JLIB_INSTALLER_' . strtoupper($this->route)), basename($file)));
                 return false;
             } else {
                 $results[$i] = array('name' => $tmpInstaller->manifest->name, 'result' => $installResult);
             }
             $i++;
         }
     } else {
         $this->parent->abort(JText::sprintf('JLIB_INSTALLER_ABORT_PACK_INSTALL_NO_FILES', JText::_('JLIB_INSTALLER_' . strtoupper($this->route))));
         return false;
     }
     // Parse optional tags
     $this->parent->parseLanguages($this->manifest->languages);
     /*
      * ---------------------------------------------------------------------------------------------
      * Extension Registration
      * ---------------------------------------------------------------------------------------------
      */
     $row = JTable::getInstance('extension');
     $eid = $row->find(array('element' => strtolower($this->get('element')), 'type' => 'package'));
     if ($eid) {
         $row->load($eid);
     } else {
         $row->name = $this->get('name');
         $row->type = 'package';
         $row->element = $this->get('element');
         // There is no folder for modules
         $row->folder = '';
         $row->enabled = 1;
         $row->protected = 0;
         $row->access = 1;
         $row->client_id = 0;
         // Custom data
         $row->custom_data = '';
         $row->params = $this->parent->getParams();
     }
     // Update the manifest cache for the entry
     $row->manifest_cache = $this->parent->generateManifestCache();
     if (!$row->store()) {
         // Install failed, roll back changes
         $this->parent->abort(JText::sprintf('JLIB_INSTALLER_ABORT_PACK_INSTALL_ROLLBACK', $row->getError()));
         return false;
     }
     /*
      * ---------------------------------------------------------------------------------------------
      * Finalization and Cleanup Section
      * ---------------------------------------------------------------------------------------------
      */
     // Run the custom method based on the route
     ob_start();
     ob_implicit_flush(false);
     if ($this->parent->manifestClass && method_exists($this->parent->manifestClass, $this->route)) {
         if ($this->parent->manifestClass->{$this->route}($this) === false) {
             // Install failed, rollback changes
             $this->parent->abort(JText::_('JLIB_INSTALLER_ABORT_FILE_INSTALL_CUSTOM_INSTALL_FAILURE'));
             return false;
         }
     }
     // Append messages
     $msg .= ob_get_contents();
     ob_end_clean();
     // Lastly, we will copy the manifest file to its appropriate place.
     $manifest = array();
     $manifest['src'] = $this->parent->getPath('manifest');
     $manifest['dest'] = JPATH_MANIFESTS . '/packages/' . basename($this->parent->getPath('manifest'));
     if (!$this->parent->copyFiles(array($manifest), true)) {
         // Install failed, rollback changes
         $this->parent->abort(JText::sprintf('JLIB_INSTALLER_ABORT_PACK_INSTALL_COPY_SETUP', JText::_('JLIB_INSTALLER_ABORT_PACK_INSTALL_NO_FILES')));
         return false;
     }
     // If there is a manifest script, let's copy it.
     if ($this->get('manifest_script')) {
         // First, we have to create a folder for the script if one isn't present
         if (!file_exists($this->parent->getPath('extension_root'))) {
             JFolder::create($this->parent->getPath('extension_root'));
         }
         $path['src'] = $this->parent->getPath('source') . '/' . $this->get('manifest_script');
         $path['dest'] = $this->parent->getPath('extension_root') . '/' . $this->get('manifest_script');
         if (!file_exists($path['dest']) || $this->parent->isOverwrite()) {
             if (!$this->parent->copyFiles(array($path))) {
                 // Install failed, rollback changes
                 $this->parent->abort(JText::_('JLIB_INSTALLER_ABORT_PACKAGE_INSTALL_MANIFEST'));
                 return false;
             }
         }
     }
     // And now we run the postflight
     ob_start();
     ob_implicit_flush(false);
     if ($this->parent->manifestClass && method_exists($this->parent->manifestClass, 'postflight')) {
         $this->parent->manifestClass->postflight($this->route, $this, $results);
     }
     // Append messages
     $msg .= ob_get_contents();
     ob_end_clean();
     if ($msg != '') {
         $this->parent->set('extension_message', $msg);
     }
     return $row->extension_id;
 }
Exemplo n.º 30
0
 /**
  * Handles the actual update installation.
  *
  * @param   JUpdate  $update  An update definition
  *
  * @return  boolean   Result of install
  *
  * @since   1.6
  */
 private function install($update)
 {
     $app = JFactory::getApplication();
     if (isset($update->get('downloadurl')->_data)) {
         $url = $update->downloadurl->_data;
         $extra_query = $update->get('extra_query');
         if ($extra_query) {
             if (strpos($url, '?') === false) {
                 $url .= '?';
             } else {
                 $url .= '&amp;';
             }
             $url .= $extra_query;
         }
     } else {
         JError::raiseWarning('', JText::_('COM_INSTALLER_INVALID_EXTENSION_UPDATE'));
         return false;
     }
     $p_file = JInstallerHelper::downloadPackage($url);
     // Was the package downloaded?
     if (!$p_file) {
         JError::raiseWarning('', JText::sprintf('COM_INSTALLER_PACKAGE_DOWNLOAD_FAILED', $url));
         return false;
     }
     $config = JFactory::getConfig();
     $tmp_dest = $config->get('tmp_path');
     // Unpack the downloaded package file
     $package = JInstallerHelper::unpack($tmp_dest . '/' . $p_file);
     // Get an installer instance
     $installer = JInstaller::getInstance();
     $update->set('type', $package['type']);
     // Install the package
     if (!$installer->update($package['dir'])) {
         // There was an error updating the package
         $msg = JText::sprintf('COM_INSTALLER_MSG_UPDATE_ERROR', JText::_('COM_INSTALLER_TYPE_TYPE_' . strtoupper($package['type'])));
         $result = false;
     } else {
         // Package updated successfully
         $msg = JText::sprintf('COM_INSTALLER_MSG_UPDATE_SUCCESS', JText::_('COM_INSTALLER_TYPE_TYPE_' . strtoupper($package['type'])));
         $result = true;
     }
     // Quick change
     $this->type = $package['type'];
     // Set some model state values
     $app->enqueueMessage($msg);
     // TODO: Reconfigure this code when you have more battery life left
     $this->setState('name', $installer->get('name'));
     $this->setState('result', $result);
     $app->setUserState('com_installer.message', $installer->message);
     $app->setUserState('com_installer.extension_message', $installer->get('extension_message'));
     // Cleanup the install files
     if (!is_file($package['packagefile'])) {
         $config = JFactory::getConfig();
         $package['packagefile'] = $config->get('tmp_path') . '/' . $package['packagefile'];
     }
     JInstallerHelper::cleanupInstall($package['packagefile'], $package['extractdir']);
     return $result;
 }