Skip to content

Commit

Permalink
Bug fix, code style
Browse files Browse the repository at this point in the history
  • Loading branch information
NunoLopesPT committed Aug 4, 2017
1 parent cfa97d1 commit 9ccbfcd
Show file tree
Hide file tree
Showing 12 changed files with 49 additions and 47 deletions.
Expand Up @@ -7,15 +7,18 @@
* @license GNU General Public License version 2 or later; see LICENSE.txt
*/
namespace Joomla\Component\Installer\Administrator\Controller;

defined('_JEXEC') or die;

use Joomla\CMS\Controller\Admin;
use Joomla\CMS\Mvc\Factory\MvcFactoryInterface;

/**
* Installer Update Sites Controller
* Installer Download Keys Controller
*
* @package Joomla.Administrator
* @subpackage com_installer
* @since 3.4
* @since __DEPLOY_VERSION__
*/
class Downloadkeys extends Admin
{
Expand All @@ -27,7 +30,7 @@ class Downloadkeys extends Admin
* @param CMSApplication $app The JApplication for the dispatcher
* @param \JInput $input Input
*
* @since 1.6
* @since __DEPLOY_VERSION__
* @see \JControllerLegacy
*/
public function __construct($config = array(), MvcFactoryInterface $factory = null, $app = null, $input = null)
Expand Down
18 changes: 8 additions & 10 deletions administrator/components/com_installer/Helper/InstallerHelper.php
Expand Up @@ -174,14 +174,12 @@ public static function getStateOptions()
*/
public static function getInstallationXML($extension)
{
$path = JPATH_ROOT;

if ($extension->client_id)
{
$path = JPATH_ADMINISTRATOR;
}
else
{
$path = JPATH_ROOT;
}

switch ($extension->type)
{
Expand Down Expand Up @@ -221,25 +219,25 @@ public static function getInstallationXML($extension)
*/
public static function getDownloadKey($extension)
{
$installXmlFile = getInstallationXML($extension);
$installXmlFile = self::getInstallationXML($extension);

if (!isset($installXmlFile->dlid))
{
return null;
}

$prefix = (string) $installXmlFile->dlid['prefix'];
$sufix = (string) $installXmlFile->dlid['sufix'];
$value = substr($extension->extra_query, strlen($prefix));
$suffix = (string) $installXmlFile->dlid['suffix'];
$value = substr($extension->extra_query, strlen($prefix));

if ($sufix != null)
if ($suffix != null)
{
$value = substr($value, 0, -strlen($sufix));
$value = substr($value, 0, -strlen($suffix));
}

$downloadKey = array(
'prefix' => $prefix,
'sufix' => $sufix,
'suffix' => $suffix,
'value' => $value
);

Expand Down
20 changes: 7 additions & 13 deletions administrator/components/com_installer/Model/Downloadkey.php
Expand Up @@ -95,20 +95,18 @@ public function getItem($pk = null)
)
)
)
->from('#__update_sites AS s')
->innerJoin('#__update_sites_extensions AS se ON (se.update_site_id = s.update_site_id)')
->innerJoin('#__extensions AS e ON (e.extension_id = se.extension_id)')
->where('s.update_site_id' . ' = ' . $item->update_site_id);
->from($db->quoteName('#__update_sites', 's'))
->innerJoin($db->quoteName('#__update_sites_extensions', 'se') . ' ON ' . $db->quoteName('se.update_site_id') . ' = ' . $db->quoteName('s.update_site_id'))
->innerJoin($db->quoteName('#__extensions', 'e') . ' ON ' . $db->quoteName('e.extension_id') . ' = ' . $db->quoteName('se.extension_id'))
->where($db->quoteName('s.update_site_id') . ' = ' . $db->quote($item->update_site_id));
$db->setQuery($query);
$extension = $db->loadObject();

$downloadKey = InstallerHelper::getDownloadKey($extension);

$app = \JFactory::getApplication();
$app->setUserState('prefix', $downloadKey['prefix']);
$app->setUserState('suffix', $downloadKey['dlidsuffix']);

$item->extra_query = $downloadKey['value'];
$item->dlidprefix = $downloadKey['prefix'];
$item->dlidsuffix = $downloadKey['suffix'];

return $item;
}
Expand All @@ -124,11 +122,7 @@ public function getItem($pk = null)
*/
public function save($data)
{
$app = \JFactory::getApplication();
$prefix = $app->getUserState('prefix');
$suffix = $app->getUserState('suffix');

$data['extra_query'] = $prefix . $data['extra_query'] . $suffix;
$data['extra_query'] = $data['dlidprefix'] . $data['extra_query'] . $data['dlidsuffix'];

return parent::save($data);
}
Expand Down
16 changes: 8 additions & 8 deletions administrator/components/com_installer/Model/Downloadkeys.php
Expand Up @@ -120,9 +120,9 @@ protected function getListQuery()
'e.manifest_cache',
)
)
->from('#__update_sites AS s')
->innerJoin('#__update_sites_extensions AS se ON (se.update_site_id = s.update_site_id)')
->innerJoin('#__extensions AS e ON (e.extension_id = se.extension_id)')
->from($db->quoteName('#__update_sites', 's'))
->innerJoin($db->quoteName('#__update_sites_extensions', 'se') . ' ON ' . $db->quoteName('se.update_site_id') . ' = ' . $db->quoteName('s.update_site_id'))
->innerJoin($db->quoteName('#__extensions', 'e') . ' ON ' . $db->quoteName('e.extension_id') . ' = ' . $db->quoteName('se.extension_id'))
->where('location not like \'%.joomla.org/%\''
);

Expand All @@ -134,30 +134,30 @@ protected function getListQuery()

if ($enabled != '')
{
$query->where('s.enabled = ' . (int) $enabled);
$query->where($db->quoteName('s.enabled') . ' = ' . $db->quote((int) $enabled));
}

if ($type)
{
$query->where('e.type = ' . $this->_db->quote($type));
$query->where($db->quoteName('e.type') . ' = ' . $db->quote($type));
}

if ($clientId != '')
{
$query->where('e.client_id = ' . (int) $clientId);
$query->where($db->quoteName('e.client_id') . ' = ' . $db->quote((int) $clientId));
}

if ($folder != '' && in_array($type, array('plugin', 'library', '')))
{
$query->where('e.folder = ' . $this->_db->quote($folder == '*' ? '' : $folder));
$query->where($db->quoteName('e.folder') . ' = ' . $db->quote($folder == '*' ? '' : $folder));
}

// Process search filter (update site id).
$search = $this->getState('filter.search');

if (!empty($search) && stripos($search, 'id:') === 0)
{
$query->where('s.update_site_id = ' . (int) substr($search, 3));
$query->where($db->quoteName('s.update_site_id') . ' = ' . $db->quote((int) substr($search, 3)));
}

// Note: The search for name, ordering and pagination are processed by the parent InstallerModel class (in extension.php).
Expand Down
Expand Up @@ -19,7 +19,6 @@
*/
class Downloadkey extends Table
{

/**
* Constructor
*
Expand Down
Expand Up @@ -13,7 +13,7 @@
use Joomla\CMS\View\HtmlView;

/**
* View to edit a contact.
* View to edit a download key.
*
* @since __DEPLOY_VERSION__
*/
Expand Down Expand Up @@ -52,11 +52,7 @@ public function display($tpl = null)
$this->form = $this->get('Form');
$this->item = $this->get('Item');

// Inject into form dlid prefix and sufix so can be easier
// to load the DownloadKey field if they exist
$jinput = \JFactory::getApplication()->input;
$this->form->dlidprefix = $jinput->getString('dlidprefix');
$this->form->dlidsufix = $jinput->getString('dlidsufix');
$this->modal = $jinput->getString('tmpl', '');

// Check for errors.
Expand Down
Expand Up @@ -7,7 +7,9 @@
* @license GNU General Public License version 2 or later; see LICENSE.txt
*/
namespace Joomla\Component\Installer\Administrator\View\Downloadkeys;

defined('_JEXEC') or die;

use Joomla\CMS\Helper\ContentHelper;
use Joomla\CMS\Toolbar\ToolbarHelper;
use Joomla\Component\Installer\Administrator\View\Installer\Html as InstallerViewDefault;
Expand Down
8 changes: 8 additions & 0 deletions administrator/components/com_installer/forms/downloadkey.xml
Expand Up @@ -26,5 +26,13 @@
class="input-xxlarge"
default=""
/>
<field
name="dlidprefix"
type="hidden"
/>
<field
name="dlidsuffix"
type="hidden"
/>
</fieldset>
</form>
2 changes: 1 addition & 1 deletion administrator/components/com_modules/View/Module/Html.php
Expand Up @@ -160,7 +160,7 @@ protected function addToolbar()

if (isset($this->item->xml->dlid))
{
\JToolbarHelper::downloadkey('Download Key', null, $this->item->module);
\JToolbarHelper::downloadkey('JGLOBAL_DOWNLOAD_KEY_MODAL_BUTTON', null, $this->item->module);
}
}
}
2 changes: 1 addition & 1 deletion administrator/components/com_plugins/View/Plugin/Html.php
Expand Up @@ -114,7 +114,7 @@ protected function addToolbar()

if (isset($this->item->xml->dlid))
{
\JToolbarHelper::downloadkey('Download Key', $this->item->extension_id);
\JToolbarHelper::downloadkey('JGLOBAL_DOWNLOAD_KEY_MODAL_BUTTON', $this->item->extension_id);
}
}
}
2 changes: 2 additions & 0 deletions administrator/language/en-GB/en-GB.ini
Expand Up @@ -335,6 +335,8 @@ JGLOBAL_DISPLAY_NUM="Display #"
JGLOBAL_DISPLAY_SELECT_DESC="Show or hide the Display Select dropdown listbox."
JGLOBAL_DISPLAY_SELECT_LABEL="Display Select"
JGLOBAL_DOWN="Down"
JGLOBAL_DOWNLOAD_KEY_MODAL_BUTTON="Download key"
JGLOBAL_DOWNLOAD_KEY_MODAL_TITLE="Download key modal"
JGLOBAL_EDIT_ITEM="Edit item"
JGLOBAL_EDIT_PREFERENCES="Edit Preferences"
JGLOBAL_EMAIL="Email"
Expand Down
10 changes: 5 additions & 5 deletions libraries/src/CMS/Toolbar/ToolbarHelper.php
Expand Up @@ -718,7 +718,7 @@ public static function modal($targetModalId, $icon, $alt)
}

/**
* Displays a modal button
* Displays a modal button for the extensions that have a download key
*
* @param string $alt Title for the modal button.
* @param string $extensionId Id of the extension.
Expand All @@ -733,9 +733,9 @@ public static function downloadkey($alt, $extensionId, $module = null)
$db = \JFactory::getDbo();
$query = $db->getQuery(true)
->select($db->quoteName('s.update_site_id'))
->from('#__update_sites AS s')
->innerJoin('#__update_sites_extensions AS se ON (se.update_site_id = s.update_site_id)')
->innerJoin('#__extensions AS e ON (e.extension_id = se.extension_id)');
->from($db->quoteName('#__update_sites', 's'))
->innerJoin($db->quoteName('#__update_sites_extensions', 'se') . ' ON ' . $db->quoteName('se.update_site_id') . ' = ' . $db->quoteName('s.update_site_id'))
->innerJoin($db->quoteName('#__extensions', 'e') . ' ON ' . $db->quoteName('e.extension_id') . ' = ' . $db->quoteName('se.extension_id'));

if ($module == null)
{
Expand All @@ -761,7 +761,7 @@ public static function downloadkey($alt, $extensionId, $module = null)
'bootstrap.renderModal',
'download_key_modal',
array(
'title' => 'Download key modal',
'title' => \JText::_('JGLOBAL_DOWNLOAD_KEY_MODAL_TITLE'),
'bodyHeight' => '45',
'modalWidth' => '80',
'footer' => '<a role="button" class="btn btn-secondary" aria-hidden="true"'
Expand Down

0 comments on commit 9ccbfcd

Please sign in to comment.