Skip to content

Commit

Permalink
Merge pull request #21 from wilsonge/development
Browse files Browse the repository at this point in the history
Changes for version 1.3.3
  • Loading branch information
C-Lodder committed Sep 1, 2013
2 parents 17206fa + 18c3547 commit ee075df
Show file tree
Hide file tree
Showing 4 changed files with 289 additions and 6 deletions.
3 changes: 3 additions & 0 deletions changelog.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@

Version 1.3.3
^ Slide colour now a colour form field
# Undefined variable when module on right hand side of screen and jQuery enabled
$ Language string changes RTL settings
^ Google jQuery version updated to 1.10.2

Version 1.3.2
+ Ability to support RTL templates improved with dedicated option
Expand Down
4 changes: 2 additions & 2 deletions mod_social_slider/mod_social_slider.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
if (!JFactory::getApplication()->get('jquery'))
{
JFactory::getApplication()->set('jquery', true);
$document->addScript("http://ajax.googleapis.com/ajax/libs/jquery/1.10.1/jquery.min.js");
$document->addScript("http://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js");
}
}
elseif ($params->get('jquery') == 1)
Expand All @@ -57,7 +57,7 @@
}

$style1 = 'ul#jj_sl_navigation li a {'
. 'background-color:#' . $params->get('slide_colour') . ';'
. 'background-color:' . $params->get('slide_colour') . ';'
. 'text-align:' . $position . ';'
. '}';
$document->addStyleDeclaration($style1);
Expand Down
9 changes: 5 additions & 4 deletions mod_social_slider/mod_social_slider.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,7 @@
<license>http://www.gnu.org/licenses/gpl-3.0.html</license>
<authorEmail>[email protected]</authorEmail>
<authorUrl>http://www.joomjunk.co.uk</authorUrl>
<version>1.3.2</version>
<description>JJ_SOCIAL_SLIDER_DESC</description>
<version>1.3.3</version>

<files>
<filename module="mod_social_slider">mod_social_slider.php</filename>
Expand All @@ -21,7 +20,9 @@
<updateservers>
<server type="extension" name="JJ Social Slider" priority="1">http://www.joomjunk.co.uk/updates/social_slider_update.xml</server>
</updateservers>


<scriptfile>script.php</scriptfile>

<languages folder="language">
<language tag="en-GB">en-GB/en-GB.mod_social_slider.ini</language>
<language tag="en-GB">en-GB/en-GB.mod_social_slider.sys.ini</language>
Expand Down Expand Up @@ -205,7 +206,7 @@
</fieldset>

<fieldset name="Other" addfieldpath="/modules/mod_social_slider/fields">
<field name="slide_colour" type="color" default="33353B" label="JJ_SOCIAL_SLIDER_SLIDE_COLOUR" description="JJ_SOCIAL_SLIDER_SLIDE_COLOUR_DESC" />
<field name="slide_colour" type="color" default="#33353B" label="JJ_SOCIAL_SLIDER_SLIDE_COLOUR" description="JJ_SOCIAL_SLIDER_SLIDE_COLOUR_DESC" />
<field name="position" type="list" default="left" label="JJ_SOCIAL_SLIDER_POSITION" description="JJ_SOCIAL_SLIDER_POSITION_DESC">
<option value="left">JJ_SOCIAL_SLIDER_LEFT</option>
<option value="right">JJ_SOCIAL_SLIDER_RIGHT</option>
Expand Down
279 changes: 279 additions & 0 deletions mod_social_slider/script.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,279 @@
<?php
/**
* @package JJ_Social_Slider
* @author JoomJunk <[email protected]>
* @copyright Copyright (C) 2011 - 2013 JoomJunk. All Rights Reserved
* @license GPL v3.0 or later http://www.gnu.org/licenses/gpl-3.0.html
*/
// No direct access to this file
defined('_JEXEC') or die('Restricted access');

/**
* Social Slider installation script class.
*
* @since 1.3.3
*/
class Mod_Social_SliderInstallerScript
{
/**
* @var string The version number of the module.
* @since 1.3.3
*/
protected $release = '';

/**
* @var string The table the parameters are stored in.
* @since 1.3.3
*/
protected $paramTable = '#__modules';

/**
* @var string The extension name.
* @since 1.3.3
*/
protected $extension = 'mod_social_slider';

/**
* Function called before module installation/update/removal procedure commences
*
* @param string $type The type of change (install, update or discover_install
* , not uninstall)
* @param JInstallerAdapterModule $parent The class calling this method
*
* @return mixed void on success and false on failure
*
* @since 1.3.3
*/
public function preflight($type, $parent)
{
// Module manifest file version
$this->release = $parent->get("manifest")->version;

// Abort if the module being installed is not newer than the currently installed version
if ($type == 'Update')
{
$manifest = $this->getItemArray('manifest_cache', '#__extensions', 'element', $this->extension);
$oldRelease = $manifest['version'];

if (version_compare($oldRelease, $this->release, '<'))
{
// Update to reflect colour form field change in 1.3.2
if (version_compare($oldRelease, '1.3.2', '<='))
{
$this->update132();
}
}
}
}

/**
* Function called on install of module
*
* @param JInstallerAdapterModule $parent The class calling this method
*
* @return void
*
* @since 1.3.3
*/
public function install($parent)
{
echo '<p>' . JText::_('JJ_SOCIAL_SLIDER_DESC') . '</p>';
}

/**
* Function called on update of module
*
* @param JInstallerAdapterModule $parent The class calling this method
*
* @return void
*
* @since 1.3.3
*/
public function update($parent)
{
echo '<p>' . JText::_('JJ_SOCIAL_SLIDER_DESC') . '</p>';
}

/**
* Gets each instance of a module in the #__modules table
* For all other extensions see alternate query
*
* @param string $extensionType The type of extension (Component, Module or Plugin)
*
* @return array An array of ID's of the extension
*
* @since 1.3.3
* @see getExtensionInstance
*/
protected function getInstances($extensionType)
{
$db = JFactory::getDbo();
$query = $db->getQuery(true);

// Select the item(s) and retrieve the id
$query->select($db->quoteName('id'));

if ($extensionType == 'module')
{
$query->from($db->quoteName('#__modules'))
->where('module = ' . $db->Quote($this->extension));
}
else
{
$query->from($db->quoteName('#__extensions'))
->where('element = ' . $db->Quote($this->extension));
}

// Set the query and obtain an array of id's
$db->setQuery($query);
$items = $db->loadColumn();

return $items;
}

/**
* Gets parameter value in the extensions row of the extension table
*
* @param string $name The name of the parameter to be retrieved
* @param integer $id The id of the item in the Param Table
*
* @return string The parameter desired
*
* @since 1.3.3
*/
protected function getParam($name, $id = 0)
{
if (!is_int($id) || $id == 0)
{
// Return false if there is no item given
return false;
}

$params = $this->getItemArray('params', $this->paramTable, 'id', $id);

return $params[$name];
}

/**
* Sets parameter values in the extensions row of the extension table. Note that the
* this must be called separately for deleting and editing. Note if edit is called as a
* type then if the param doesn't exist it will be created
*
* @param array $param_array The array of parameters to be added/edited/removed
* @param string $type The type of change to be made to the param (edit/remove)
* @param integer $id The id of the item in the relevant table
*
* @return mixed false on failure, void otherwise
*/
protected function setParams($param_array = null, $type = 'edit', $id = 0)
{
if (!is_int($id) || $id == 0)
{
// Return false if there is no valid item given
return false;
}

$params = $this->getItemArray('params', $this->paramTable, 'id', $id);

if ($param_array)
{
foreach ($param_array as $name => $value)
{
if ($type == 'edit')
{
// Add or edit the new variable(s) to the existing params
$params[(string) $name] = (string) $value;
}
elseif ($type == 'remove')
{
// Unset the parameter from the array
unset($params[(string) $name]);
}
}
}

// Store the combined new and existing values back as a JSON string
$paramsString = json_encode($params);

$db = JFactory::getDbo();
$query = $db->getQuery(true);
$query->update($db->quoteName($this->paramTable))
->set('params = ' . $db->quote($paramsString))
->where('id = ' . $id);

// Update table
$db->setQuery($query);

if (version_compare(JVERSION, '3.0.0', 'ge'))
{
$db->execute();
}
else
{
$db->query();
}
}

/**
* Builds a standard select query to produce better DRY code in this script.
* This should produce a single unique cell which is json encoded
*
* @param string $element The element to get from the query
* @param string $table The table to search for the data in
* @param string $column The column of the database to search from
* @param string $identifier The property of the column to search for
*
* @return array associated array containing data from the cell
*
* @since 1.3.3
*/
protected function getItemArray($element, $table, $column, $identifier)
{
// Get the DB and query objects
$db = JFactory::getDbo();
$query = $db->getQuery(true);

// Build the query
$query->select($db->quoteName($element))
->from($db->quoteName($table))
->where($column . ' = ' . $db->Quote($identifier));
$db->setQuery($query);

// Load the single cell and json_decode data
$array = json_decode($db->loadResult(), true);

return $array;
}

/**
* Function to update the file structure and params for the Social Slider Version 1.3.2 updates
*
* @return void
*
* @since 1.3.3
*/
protected function update132()
{
/*
* We have moved to use the colour form field so a hash must be applied
* to the parameters for them to function as expected still.
*/
$modules = $this->getInstances('module');

foreach ($modules as $module)
{
// Convert string to integer
$module = (int) $module;

// Create array of params to change
$colours = array();
$colours['slide_colour'] = '#' . $this->getParam('slide_colour', $module);

// Set the param values
$this->setParams($colours, 'edit', $module);

// Unset the array for the next loop
unset($colours);
}
}
}

0 comments on commit ee075df

Please sign in to comment.