Пример #1
0
	public function download()
	{
		// Get the path to Joomla!'s temporary directory
		$jreg =& JFactory::getConfig();
		$tmpdir = $jreg->getValue('config.tmp_path');
		
		jimport('joomla.filesystem.folder');
		// Make sure the user doesn't use the system-wide tmp directory. You know, the one that's
		// being erased periodically and will cause a real mess while installing extensions (Grrr!)
		if(realpath($tmpdir) == '/tmp') {
			// Someone inform the user that what he's doing is insecure and stupid, please. In the
			// meantime, I will fix what is broken.
			$tmpdir = JPATH_SITE.DS.'tmp';
		} // Make sure that folder exists (users do stupid things too often; you'd be surprised)
		elseif(!JFolder::exists($tmpdir)) {
			// Darn it, user! WTF where you thinking? OK, let's use a directory I know it's there...
			$tmpdir = JPATH_SITE.DS.'tmp';
		}

		// Oki. Let's get the URL of the package
		$updateInfo = LiveUpdate::getUpdateInformation();
		$config = LiveUpdateConfig::getInstance();
		$auth = $config->getAuthorization();
		$url = $updateInfo->downloadURL;
		
		// Sniff the package type. If sniffing is impossible, I'll assume a ZIP package
		$basename = basename($url);
		if(strstr($basename,'?')) {
			$basename = substr($basename, strstr($basename,'?')+1);
		}
		if(substr($basename,-4) == '.zip') {
			$type = 'zip';
		} elseif(substr($basename,-4) == '.tar') {
			$type = 'tar';
		} elseif(substr($basename,-4) == '.tgz') {
			$type = 'tar.gz';
		} elseif(substr($basename,-7) == '.tar.gz') {
			$type = 'tar.gz';
		} else {
			$type = 'zip';
		}
		
		// Cache the path to the package file and the temp installation directory in the session
		$target = $tmpdir.DS.$updateInfo->extInfo->name.'.update.'.$type;
		$tempdir = $tmpdir.DS.$updateInfo->extInfo->name.'_update';
		
		$session = JFactory::getSession();
		$session->set('target', $target, 'liveupdate');
		$session->set('tempdir', $tempdir, 'liveupdate');
		
		// Let's download!
		require_once dirname(__FILE__).'/download.php';
		return LiveUpdateDownloadHelper::download($url, $target);
	}
Пример #2
0
 /**
  * Retrieves the update data from the server, unless previous runs indicate
  * that the download process gets stuck and ends up in a WSOD.
  * 
  * @param bool $force Set to true to force fetching new data no matter if the process is marked as stuck
  * @return stdClass
  */
 private function getUpdateData($force = false)
 {
     $ret = array('supported' => false, 'stuck' => true, 'version' => '', 'date' => '', 'stability' => '', 'downloadURL' => '', 'infoURL' => '', 'releasenotes' => '');
     // If the process is marked as "stuck", we won't bother fetching data again; well,
     // unless you really force me to, by setting $force = true.
     if ($this->storage->get('stuck', 0) != 0 && !$force) {
         return (object) $ret;
     }
     $ret['stuck'] = false;
     require_once dirname(__FILE__) . '/download.php';
     // First we mark Live Updates as getting stuck. This way, if fetching the update
     // fails with a server error, reloading the page will not result to a White Screen
     // of Death again. Hey, Joomla! core team, are you listening? Some hosts PRETEND to
     // support cURL or URL fopen() wrappers but using them throws an immediate WSOD.
     $this->storage->set('stuck', 1);
     $this->storage->save();
     $config = LiveUpdateConfig::getInstance();
     $extInfo = $config->getExtensionInformation();
     $url = $extInfo['updateurl'];
     $rawData = LiveUpdateDownloadHelper::downloadAndReturn($url);
     // Now that we have some data returned, let's unmark the process as being stuck ;)
     $this->storage->set('stuck', 0);
     $this->storage->save();
     // If we didn't get anything, assume Live Update is not supported (communication error)
     if (empty($rawData) || $rawData == false) {
         return (object) $ret;
     }
     // TODO Detect the content type of the returned update stream. For now, I will pretend it's an INI file.
     $data = $this->parseINI($rawData);
     $ret['supported'] = true;
     return (object) array_merge($ret, $data);
 }
Пример #3
0
 function display($tpl = null)
 {
     $mainframe = JFactory::getApplication();
     $option = 'com_j2store';
     $ns = 'com_j2store.payment';
     $task = $mainframe->input->getCmd('task');
     $session = JFactory::getSession();
     $db = JFactory::getDBO();
     $uri = JFactory::getURI();
     $params = JComponentHelper::getParams('com_j2store');
     $filter_order = $mainframe->getUserStateFromRequest($ns . 'filter_order', 'filter_order', 'tbl.id', 'cmd');
     $filter_order_Dir = $mainframe->getUserStateFromRequest($ns . 'filter_order_Dir', 'filter_order_Dir', '', 'word');
     $filter_orderstate = $mainframe->getUserStateFromRequest($ns . 'filter_orderstate', 'filter_orderstate', '', 'string');
     $filter_name = $mainframe->getUserStateFromRequest($ns . 'filter_name', 'filter_name', 'tbl.name', 'cmd');
     $search = $mainframe->getUserStateFromRequest($ns . 'search', 'search', '', 'string');
     if (strpos($search, '"') !== false) {
         $search = str_replace(array('=', '<'), '', $search);
     }
     $search = JString::strtolower($search);
     $model = $this->getModel('payment');
     // Get data from the model
     $items = $model->getList();
     $total = $model->getTotal();
     $pagination = $model->getPagination();
     // table ordering
     $lists['order_Dir'] = $filter_order_Dir;
     $lists['order'] = $filter_order;
     $lists['filter_name'] = $filter_name;
     $update = array();
     $warning = '';
     //only call once per session. Dont call this often
     if (!$session->has('plugin_update_data', 'j2store')) {
         try {
             require_once JPATH_COMPONENT_ADMINISTRATOR . '/liveupdate/classes/download.php';
             $xmlfile = 'http://cdn.j2store.org/extensions.xml';
             $result = LiveUpdateDownloadHelper::downloadAndReturn($xmlfile);
             if ($result) {
                 $extensions = simplexml_load_string($result, 'SimpleXMLElement');
                 $type = (string) $extensions->extension->attributes()->type;
                 if ($type == 'payment') {
                     $plugins = $extensions->extension->plugins->plugin;
                     foreach ($plugins as $plugin) {
                         $update[(string) $plugin->attributes()->element] = (array) $plugin;
                     }
                 }
                 if (count($update)) {
                     $session->set('plugin_update_data', $update, 'j2store');
                 }
             }
         } catch (Exception $e) {
             $warning = JText::_('J2STORE_PAYMENT_XML_REMOTE_ERROR');
             $this->assignRef('warning', $warning);
         }
     } else {
         $update = $session->get('plugin_update_data', array(), 'j2store');
     }
     $this->assignRef('update', $update);
     // search filter
     $lists['search'] = $search;
     $this->assignRef('lists', $lists);
     $this->assignRef('items', $items);
     $this->assignRef('pagination', $pagination);
     JToolBarHelper::title(JText::_('J2STORE_PAYMENT_PLUGINS'), 'j2store-logo');
     $toolbar = new J2StoreToolBar();
     $toolbar->renderLinkbar();
     parent::display($tpl);
 }