Compare commits

..

No commits in common. "master" and "v1.0.1" have entirely different histories.

8 changed files with 254 additions and 561 deletions

View File

@ -1,4 +1,4 @@
# Version Calendar in SVG (2.0.1)
# Version Calendar in SVG (1.0.1)
> The original source code was taken from the [PHP supported versions](https://github.com/php/web-php/blob/master/images/supported-versions.php).
@ -8,6 +8,6 @@
+ *Author*: [Joomla! Project](mailto:admin@joomla.org)
+ *Name*: [Version Calendar svg](http://www.joomla.org)
+ *First Build*: 3rd September, 2022
+ *Version*: 2.0.1
+ *Version*: 1.0.1
+ *Copyright*: (C) 2022 Open Source Matters, Inc.
+ *License*: GNU General Public License version 2 or later; see LICENSE.txt

View File

@ -39,14 +39,6 @@ class ModVersion_Calendar_svgHelper
*/
protected $branches;
/**
* The Legend
*
* @var array
* @since 1.0
*/
protected $legend;
/**
* The Width
*
@ -140,102 +132,72 @@ class ModVersion_Calendar_svgHelper
/**
* Get Branches
*
* Fetches and processes the branches or versions from the parameters.
* It sanitizes the branch data, calculates their positions, sorts them, and then returns.
* If no valid branches or versions are found, it throws an exception.
*
* @return array
*
* @since 2.0.1
* @throws Exception If no valid branches or versions are found.
* @since 1.0.0
*/
public function branches(): array
{
if (empty($this->branches))
{
$branches = (array) $this->params->get('versions');
$branches = (array) $this->params->get('dates', null);
if (empty($branches))
if (is_array($branches) && count($branches) > 0)
{
throw new Exception("No versions found.");
}
$this->sanitize($branches);
$branch_height = $this->params->get('branch_height', 30);
$header_height = $this->params->get('header_height', 24);
if (empty($branches))
$i = 0;
foreach ($branches as $k => &$branch)
{
$branch->top = $header_height + ($branch_height * $i++);
}
$this->branches = $branches;
}
else
{
throw new Exception("No versions found.");
// we should add exception here
}
$this->setTop($branches);
$this->sort($branches);
$this->branches = $branches;
}
return $this->branches;
}
/**
* Get Legend values (by color)
*
* @return array
* @since 2.0.1
*/
public function legend(): array
{
if (empty($this->legend))
{
$branches = $this->branches();
foreach ($branches as $version)
{
foreach ($version->dates as $date)
{
$this->legend[$date->color] = $date;
}
}
}
return $this->legend;
}
/**
* Current state of a branch
*
* @param array $dates The branch dates
* @param stdClass $branch The branch values
*
* @return string|null
* @since 2.0.1
* @since 1.0.0
*/
public function state(array $dates): ?string
public function state(stdClass $branch): ?string
{
// Determine the current state.
$now = new DateTime();
$initial = new DateTime($branch->start);
$bug = new DateTime($branch->bug);
$security = new DateTime($branch->end);
// Check if today's date is before the earliest start date.
$earliestDate = DateTime::createFromFormat('d-m-Y', $dates[0]->start);
if ($now < $earliestDate)
if ($initial && $bug && $security)
{
return 'vcs-future';
}
$now = new DateTime;
// Check if today's date is after the latest end date.
$latestDate = DateTime::createFromFormat('d-m-Y', end($dates)->end);
if ($now > $latestDate)
{
return 'vcs-eol';
}
// Determine which state the current date falls under.
foreach ($dates as $date)
{
$initial = DateTime::createFromFormat('d-m-Y', $date->start);
$end = DateTime::createFromFormat('d-m-Y', $date->end);
if ($now >= $initial && $now <= $end)
if ($now >= $security)
{
return $date->state;
return 'eol';
}
if ($now >= $bug)
{
return 'security';
}
if ($now >= $initial)
{
return 'stable';
}
return 'future';
}
return null;
@ -289,120 +251,5 @@ class ModVersion_Calendar_svgHelper
(365.24 / $this->params->get('year_width', 120))
);
}
/**
* Sort Branches state's by date
*
* @param array $branches The branches
*
* @return void
* @since 2.0.1
*/
protected function sort(array &$branches): void
{
foreach ($branches as $key => &$branch)
{
usort($branch->dates, function($a, $b) {
$startDateA = DateTime::createFromFormat('d-m-Y', $a->start);
$startDateB = DateTime::createFromFormat('d-m-Y', $b->start);
if ($startDateA == $startDateB)
{
$endDateA = DateTime::createFromFormat('d-m-Y', $a->end);
$endDateB = DateTime::createFromFormat('d-m-Y', $b->end);
return $endDateA <=> $endDateB;
}
return $startDateA <=> $startDateB;
});
}
}
/**
* Set Top
*
* Calculates the top position for each branch based on parameters for branch height and header height.
*
* @param array $branches Reference to the branches array.
*
* @return void
* @since 2.0.1
*/
protected function setTop(array &$branches): void
{
$branch_height = $this->params->get('branch_height', 30);
$header_height = $this->params->get('header_height', 24);
$i = 0;
foreach ($branches as $key => &$branch)
{
$branch->top = $header_height + ($branch_height * $i++);
}
}
/**
* Sanitize
*
* Sanitizes the branches by checking the existence and type of 'dates' and 'date->state'.
* Also modifies the state of each date entry within a branch.
*
* @param array $branches Reference to the branches array.
*
* @return void
* @since 2.0.1
*/
protected function sanitize(array &$branches): void
{
foreach ($branches as $key => &$branch)
{
if (empty($branch->dates) || !is_object($branch->dates))
{
unset($branches[$key]);
continue;
}
$branch->dates = (array) $branch->dates;
$remove = false;
foreach ($branch->dates as $k => &$date)
{
if (empty($date->state))
{
$remove = true;
continue;
}
$date->state = $this->makeSafe($key . '-' . $date->state);
}
if ($remove)
{
unset($branches[$key]);
}
}
}
/**
* Get css safe class name
*
* @param string $name The string to make safe
*
* @return string
* @since 2.0.1
*/
protected function makeSafe(string $name): string
{
// Ensure it doesn't start with a digit
if (preg_match('/^[0-9]/', $name))
{
$name = 'vcs-' . $name;
}
// Replace any non-alphanumeric characters with hyphens
$name = preg_replace('/[^a-zA-Z0-9]+/', '-', $name);
// Convert to lowercase
$name = strtolower($name);
return $name;
}
}

View File

@ -1,52 +1,35 @@
MOD_VERSION_CALENDAR_SVG="Version Calendar Svg"
MOD_VERSION_CALENDAR_SVG_DESCRIPTION="Version Calendar in SVG"
MOD_VERSION_CALENDAR_SVG_XML_DESCRIPTION="<h1>Version Calendar Svg (v.2.0.1)</h1> <div style='clear: both;'></div><p>Version Calendar in SVG</p><p>Created by <a href='http://www.joomla.org' target='_blank'>Joomla! Project</a><br /><small>Development started 3rd September, 2022</small></p>"
MOD_VERSION_CALENDAR_SVG_TODAY="Today"
MOD_VERSION_CALENDAR_SVG_PLANNED_RELEASE_SCHEDULE="Planned release schedule"
MOD_VERSION_CALENDAR_SVG_FUTURE_RELEASES="Future Releases"
MOD_VERSION_CALENDAR_SVG_VERSION_END_OF_LIFE_SCHEDULE_EXPECT_NO_MORE_SUPPORT="Version End of Life schedule - expect no more support"
MOD_VERSION_CALENDAR_SVG_VERSION_AT_END_OF_LIFE="Version at End of Life"
MOD_VERSION_CALENDAR_SVG_XML_DESCRIPTION="<h1>Version Calendar Svg (v.1.0.1)</h1> <div style='clear: both;'></div><p>Version Calendar in SVG</p><p>Created by <a href='http://www.joomla.org' target='_blank'>Joomla! Project</a><br /><small>Development started 3rd September, 2022</small></p>"
MOD_VERSION_CALENDAR_SVG_DIMENTIONS="Dimentions"
MOD_VERSION_CALENDAR_SVG_STYLES="Styles"
MOD_VERSION_CALENDAR_SVG_VERSIONS="Versions"
MOD_VERSION_CALENDAR_SVG_DATES="Dates"
MOD_VERSION_CALENDAR_SVG_HEADER_HEIGHT_LABEL="Header Height"
MOD_VERSION_CALENDAR_SVG_BRANCH_HEIGHT_LABEL="Branch Height"
MOD_VERSION_CALENDAR_SVG_MARGIN_RIGHT_LABEL="Margin Right"
MOD_VERSION_CALENDAR_SVG_MARGIN_LEFT_LABEL="Margin Left"
MOD_VERSION_CALENDAR_SVG_YEAR_WIDTH_LABEL="Year Width"
MOD_VERSION_CALENDAR_SVG_FOOTER_HEIGHT_LABEL="Footer Height"
MOD_VERSION_CALENDAR_SVG_TEXT_COLOR_LABEL="Default Text Colour"
MOD_VERSION_CALENDAR_SVG_FUTURE_TEXT_COLOR_LABEL="Future Text Colour"
MOD_VERSION_CALENDAR_SVG_FUTURE_COLOR_LABEL="Future Background Colour"
MOD_VERSION_CALENDAR_SVG_END_OF_LIFE_TEXT_COLOR_LABEL="End of Life Text Colour"
MOD_VERSION_CALENDAR_SVG_END_OF_LIFE_COLOR_LABEL="End of Life Background Colour"
MOD_VERSION_CALENDAR_SVG_YEARS_LINE_COLOR_LABEL="Years Line Colour"
MOD_VERSION_CALENDAR_SVG_YEARS_TEXT_COLOR_LABEL="Years Text Colour"
MOD_VERSION_CALENDAR_SVG_TODAY_LINE_COLOR_LABEL="Today Line Colour"
MOD_VERSION_CALENDAR_SVG_TODAY_TEXT_COLOR_LABEL="Today Text Colour"
MOD_VERSION_CALENDAR_SVG_SHOW_LEGEND_LABEL="Show Legend"
MOD_VERSION_CALENDAR_SVG_SHOW_LEGEND_DESCRIPTION="Allow the legend to be shown below the calendar."
MOD_VERSION_CALENDAR_SVG_YES="Yes"
MOD_VERSION_CALENDAR_SVG_NO="No"
MOD_VERSION_CALENDAR_SVG_LEGEND_BACKGROUND_COLOR_LABEL="Legend Background Colour"
MOD_VERSION_CALENDAR_SVG_LEGEND_TEXT_COLOR_LABEL="Legend Text Colour"
MOD_VERSION_CALENDAR_SVG_TEXT_COLOR_LABEL="Default Text Color"
MOD_VERSION_CALENDAR_SVG_FUTURE_COLOR_LABEL="Future Background Color"
MOD_VERSION_CALENDAR_SVG_STABLE_COLOR_LABEL="Stable Background Color"
MOD_VERSION_CALENDAR_SVG_SECURITY_COLOR_LABEL="Security Background Color"
MOD_VERSION_CALENDAR_SVG_END_OF_LIFE_COLOR_LABEL="End of Life Background Color"
MOD_VERSION_CALENDAR_SVG_END_OF_LIFE_TEXT_COLOR_LABEL="End of Life Text Color"
MOD_VERSION_CALENDAR_SVG_YEARS_LINE_COLOR_LABEL="Years Line Color"
MOD_VERSION_CALENDAR_SVG_YEARS_TEXT_COLOR_LABEL="Years Text Color"
MOD_VERSION_CALENDAR_SVG_TODAY_LINE_COLOR_LABEL="Today Line Color"
MOD_VERSION_CALENDAR_SVG_TODAY_TEXT_COLOR_LABEL="Today Text Color"
MOD_VERSION_CALENDAR_SVG_MAX_YEARS_LABEL="Max Years"
MOD_VERSION_CALENDAR_SVG_MIN_YEARS_LABEL="Min Years"
MOD_VERSION_CALENDAR_SVG_VERSIONS_LABEL="Versions"
MOD_VERSION_CALENDAR_SVG_DATES_LABEL="Dates"
MOD_VERSION_CALENDAR_SVG_VERSION_LABEL="Version"
MOD_VERSION_CALENDAR_SVG_VERSION_DESCRIPTION="Name"
MOD_VERSION_CALENDAR_SVG_VERSION_MESSAGE="Error! Please add version here."
MOD_VERSION_CALENDAR_SVG_VERSION_HINT="1.0.0"
MOD_VERSION_CALENDAR_SVG_DATES_LABEL="Dates"
MOD_VERSION_CALENDAR_SVG_STATE_LABEL="State"
MOD_VERSION_CALENDAR_SVG_STATE_HINT="stable"
MOD_VERSION_CALENDAR_SVG_LABEL_LABEL="Label"
MOD_VERSION_CALENDAR_SVG_LABEL_HINT="State label"
MOD_VERSION_CALENDAR_SVG_DESCRIPTION_LABEL="Description"
MOD_VERSION_CALENDAR_SVG_DESCRIPTION_HINT="Describe the state"
MOD_VERSION_CALENDAR_SVG_COLOR_LABEL="Background"
MOD_VERSION_CALENDAR_SVG_COLOR_DESCRIPTION="Color"
MOD_VERSION_CALENDAR_SVG_START_LABEL="Start Date"
MOD_VERSION_CALENDAR_SVG_START_MESSAGE="Error! Please add date here."
MOD_VERSION_CALENDAR_SVG_BUG_LABEL="Bug Date"
MOD_VERSION_CALENDAR_SVG_BUG_MESSAGE="Error! Please add date here."
MOD_VERSION_CALENDAR_SVG_END_LABEL="End Date"
MOD_VERSION_CALENDAR_SVG_END_MESSAGE="Error! Please add date here."

View File

@ -1,52 +1,35 @@
MOD_VERSION_CALENDAR_SVG="Version Calendar Svg"
MOD_VERSION_CALENDAR_SVG_DESCRIPTION="Version Calendar in SVG"
MOD_VERSION_CALENDAR_SVG_XML_DESCRIPTION="<h1>Version Calendar Svg (v.2.0.1)</h1> <div style='clear: both;'></div><p>Version Calendar in SVG</p><p>Created by <a href='http://www.joomla.org' target='_blank'>Joomla! Project</a><br /><small>Development started 3rd September, 2022</small></p>"
MOD_VERSION_CALENDAR_SVG_TODAY="Today"
MOD_VERSION_CALENDAR_SVG_PLANNED_RELEASE_SCHEDULE="Planned release schedule"
MOD_VERSION_CALENDAR_SVG_FUTURE_RELEASES="Future Releases"
MOD_VERSION_CALENDAR_SVG_VERSION_END_OF_LIFE_SCHEDULE_EXPECT_NO_MORE_SUPPORT="Version End of Life schedule - expect no more support"
MOD_VERSION_CALENDAR_SVG_VERSION_AT_END_OF_LIFE="Version at End of Life"
MOD_VERSION_CALENDAR_SVG_XML_DESCRIPTION="<h1>Version Calendar Svg (v.1.0.1)</h1> <div style='clear: both;'></div><p>Version Calendar in SVG</p><p>Created by <a href='http://www.joomla.org' target='_blank'>Joomla! Project</a><br /><small>Development started 3rd September, 2022</small></p>"
MOD_VERSION_CALENDAR_SVG_DIMENTIONS="Dimentions"
MOD_VERSION_CALENDAR_SVG_STYLES="Styles"
MOD_VERSION_CALENDAR_SVG_VERSIONS="Versions"
MOD_VERSION_CALENDAR_SVG_DATES="Dates"
MOD_VERSION_CALENDAR_SVG_HEADER_HEIGHT_LABEL="Header Height"
MOD_VERSION_CALENDAR_SVG_BRANCH_HEIGHT_LABEL="Branch Height"
MOD_VERSION_CALENDAR_SVG_MARGIN_RIGHT_LABEL="Margin Right"
MOD_VERSION_CALENDAR_SVG_MARGIN_LEFT_LABEL="Margin Left"
MOD_VERSION_CALENDAR_SVG_YEAR_WIDTH_LABEL="Year Width"
MOD_VERSION_CALENDAR_SVG_FOOTER_HEIGHT_LABEL="Footer Height"
MOD_VERSION_CALENDAR_SVG_TEXT_COLOR_LABEL="Default Text Colour"
MOD_VERSION_CALENDAR_SVG_FUTURE_TEXT_COLOR_LABEL="Future Text Colour"
MOD_VERSION_CALENDAR_SVG_FUTURE_COLOR_LABEL="Future Background Colour"
MOD_VERSION_CALENDAR_SVG_END_OF_LIFE_TEXT_COLOR_LABEL="End of Life Text Colour"
MOD_VERSION_CALENDAR_SVG_END_OF_LIFE_COLOR_LABEL="End of Life Background Colour"
MOD_VERSION_CALENDAR_SVG_YEARS_LINE_COLOR_LABEL="Years Line Colour"
MOD_VERSION_CALENDAR_SVG_YEARS_TEXT_COLOR_LABEL="Years Text Colour"
MOD_VERSION_CALENDAR_SVG_TODAY_LINE_COLOR_LABEL="Today Line Colour"
MOD_VERSION_CALENDAR_SVG_TODAY_TEXT_COLOR_LABEL="Today Text Colour"
MOD_VERSION_CALENDAR_SVG_SHOW_LEGEND_LABEL="Show Legend"
MOD_VERSION_CALENDAR_SVG_SHOW_LEGEND_DESCRIPTION="Allow the legend to be shown below the calendar."
MOD_VERSION_CALENDAR_SVG_YES="Yes"
MOD_VERSION_CALENDAR_SVG_NO="No"
MOD_VERSION_CALENDAR_SVG_LEGEND_BACKGROUND_COLOR_LABEL="Legend Background Colour"
MOD_VERSION_CALENDAR_SVG_LEGEND_TEXT_COLOR_LABEL="Legend Text Colour"
MOD_VERSION_CALENDAR_SVG_TEXT_COLOR_LABEL="Default Text Color"
MOD_VERSION_CALENDAR_SVG_FUTURE_COLOR_LABEL="Future Background Color"
MOD_VERSION_CALENDAR_SVG_STABLE_COLOR_LABEL="Stable Background Color"
MOD_VERSION_CALENDAR_SVG_SECURITY_COLOR_LABEL="Security Background Color"
MOD_VERSION_CALENDAR_SVG_END_OF_LIFE_COLOR_LABEL="End of Life Background Color"
MOD_VERSION_CALENDAR_SVG_END_OF_LIFE_TEXT_COLOR_LABEL="End of Life Text Color"
MOD_VERSION_CALENDAR_SVG_YEARS_LINE_COLOR_LABEL="Years Line Color"
MOD_VERSION_CALENDAR_SVG_YEARS_TEXT_COLOR_LABEL="Years Text Color"
MOD_VERSION_CALENDAR_SVG_TODAY_LINE_COLOR_LABEL="Today Line Color"
MOD_VERSION_CALENDAR_SVG_TODAY_TEXT_COLOR_LABEL="Today Text Color"
MOD_VERSION_CALENDAR_SVG_MAX_YEARS_LABEL="Max Years"
MOD_VERSION_CALENDAR_SVG_MIN_YEARS_LABEL="Min Years"
MOD_VERSION_CALENDAR_SVG_VERSIONS_LABEL="Versions"
MOD_VERSION_CALENDAR_SVG_DATES_LABEL="Dates"
MOD_VERSION_CALENDAR_SVG_VERSION_LABEL="Version"
MOD_VERSION_CALENDAR_SVG_VERSION_DESCRIPTION="Name"
MOD_VERSION_CALENDAR_SVG_VERSION_MESSAGE="Error! Please add version here."
MOD_VERSION_CALENDAR_SVG_VERSION_HINT="1.0.0"
MOD_VERSION_CALENDAR_SVG_DATES_LABEL="Dates"
MOD_VERSION_CALENDAR_SVG_STATE_LABEL="State"
MOD_VERSION_CALENDAR_SVG_STATE_HINT="stable"
MOD_VERSION_CALENDAR_SVG_LABEL_LABEL="Label"
MOD_VERSION_CALENDAR_SVG_LABEL_HINT="State label"
MOD_VERSION_CALENDAR_SVG_DESCRIPTION_LABEL="Description"
MOD_VERSION_CALENDAR_SVG_DESCRIPTION_HINT="Describe the state"
MOD_VERSION_CALENDAR_SVG_COLOR_LABEL="Background"
MOD_VERSION_CALENDAR_SVG_COLOR_DESCRIPTION="Color"
MOD_VERSION_CALENDAR_SVG_START_LABEL="Start Date"
MOD_VERSION_CALENDAR_SVG_START_MESSAGE="Error! Please add date here."
MOD_VERSION_CALENDAR_SVG_BUG_LABEL="Bug Date"
MOD_VERSION_CALENDAR_SVG_BUG_MESSAGE="Error! Please add date here."
MOD_VERSION_CALENDAR_SVG_END_LABEL="End Date"
MOD_VERSION_CALENDAR_SVG_END_MESSAGE="Error! Please add date here."

View File

@ -14,25 +14,17 @@ defined('_JEXEC') or die('Restricted access');
// Include the helper functions only once
JLoader::register('ModVersion_Calendar_svgHelper', __DIR__ . '/helper.php');
try
{
// Get the Helper class
$helper = new ModVersion_Calendar_svgHelper($params);
// Get the Helper class
$helper = new ModVersion_Calendar_svgHelper($params);
// set the branches
$branches = $helper->branches();
// set the branches
$branches = $helper->branches();
// set branch qty
$qty = count($branches);
// set branch qty
$qty = count($branches);
// get the module class sfx (local)
$moduleclass_sfx = htmlspecialchars($params->get('moduleclass_sfx'), ENT_COMPAT, 'UTF-8');
// get the module class sfx (local)
$moduleclass_sfx = htmlspecialchars($params->get('moduleclass_sfx'), ENT_COMPAT, 'UTF-8');
// load the default Tmpl
require JModuleHelper::getLayoutPath('mod_version_calendar_svg', $params->get('layout', 'default'));
}
catch (Exception $e)
{
// Output a warning message along with the exception message
echo "Warning: " . $e->getMessage();
}
// load the default Tmpl
require JModuleHelper::getLayoutPath('mod_version_calendar_svg', $params->get('layout', 'default'));

View File

@ -1,13 +1,13 @@
<?xml version="1.0" encoding="utf-8"?>
<extension type="module" version="4" client="site" method="upgrade">
<name>MOD_VERSION_CALENDAR_SVG</name>
<creationDate>11th August, 2023</creationDate>
<creationDate>21st September, 2022</creationDate>
<author>Joomla! Project</author>
<authorEmail>admin@joomla.org</authorEmail>
<authorUrl>http://www.joomla.org</authorUrl>
<copyright>(C) 2020 Open Source Matters, Inc.</copyright>
<license>GNU General Public License version 2 or later; see LICENSE.txt</license>
<version>2.0.1</version>
<version>1.0.1</version>
<description>MOD_VERSION_CALENDAR_SVG_XML_DESCRIPTION</description>
<!-- Scripts to run on installation -->
@ -51,7 +51,7 @@
min="10"
max="80"
step="1"
validate="number"
validate="int"
/>
<!-- Branch_height Field. Type: Number. (joomla) -->
<field
@ -64,7 +64,7 @@
min="20"
max="100"
step="5"
validate="number"
validate="int"
/>
<!-- Margin_right Field. Type: Number. (joomla) -->
<field
@ -77,7 +77,7 @@
min="20"
max="100"
step="5"
validate="number"
validate="int"
/>
<!-- Margin_left Field. Type: Number. (joomla) -->
<field
@ -90,7 +90,7 @@
min="40"
max="140"
step="5"
validate="number"
validate="int"
/>
<!-- Year_width Field. Type: Number. (joomla) -->
<field
@ -103,7 +103,7 @@
min="50"
max="300"
step="5"
validate="number"
validate="int"
/>
<!-- Footer_height Field. Type: Number. (joomla) -->
<field
@ -116,7 +116,7 @@
min="10"
max="80"
step="1"
validate="number"
validate="int"
/>
</fieldset>
<!-- default paths of style fieldset points to the module -->
@ -132,14 +132,6 @@
label="MOD_VERSION_CALENDAR_SVG_TEXT_COLOR_LABEL"
required="true"
/>
<!-- Future_text_color Field. Type: Color. (joomla) -->
<field
type="color"
name="future_text_color"
default="#fbf3ef"
label="MOD_VERSION_CALENDAR_SVG_FUTURE_TEXT_COLOR_LABEL"
required="true"
/>
<!-- Future_color Field. Type: Color. (joomla) -->
<field
type="color"
@ -148,12 +140,20 @@
label="MOD_VERSION_CALENDAR_SVG_FUTURE_COLOR_LABEL"
required="true"
/>
<!-- End_of_life_text_color Field. Type: Color. (joomla) -->
<!-- Stable_color Field. Type: Color. (joomla) -->
<field
type="color"
name="end_of_life_text_color"
default="#ffffff"
label="MOD_VERSION_CALENDAR_SVG_END_OF_LIFE_TEXT_COLOR_LABEL"
name="stable_color"
default="#7ac143"
label="MOD_VERSION_CALENDAR_SVG_STABLE_COLOR_LABEL"
required="true"
/>
<!-- Security_color Field. Type: Color. (joomla) -->
<field
type="color"
name="security_color"
default="#f9a541"
label="MOD_VERSION_CALENDAR_SVG_SECURITY_COLOR_LABEL"
required="true"
/>
<!-- End_of_life_color Field. Type: Color. (joomla) -->
@ -164,6 +164,14 @@
label="MOD_VERSION_CALENDAR_SVG_END_OF_LIFE_COLOR_LABEL"
required="true"
/>
<!-- End_of_life_text_color Field. Type: Color. (joomla) -->
<field
type="color"
name="end_of_life_text_color"
default="#ffffff"
label="MOD_VERSION_CALENDAR_SVG_END_OF_LIFE_TEXT_COLOR_LABEL"
required="true"
/>
<!-- Years_line_color Field. Type: Color. (joomla) -->
<field
type="color"
@ -196,39 +204,9 @@
label="MOD_VERSION_CALENDAR_SVG_TODAY_TEXT_COLOR_LABEL"
required="true"
/>
<!-- Show_legend Field. Type: Radio. (joomla) -->
<field
type="radio"
name="show_legend"
label="MOD_VERSION_CALENDAR_SVG_SHOW_LEGEND_LABEL"
description="MOD_VERSION_CALENDAR_SVG_SHOW_LEGEND_DESCRIPTION"
class="btn-group btn-group-yesno"
default="1">
<!-- Option Set. -->
<option value="1">
MOD_VERSION_CALENDAR_SVG_YES</option>
<option value="0">
MOD_VERSION_CALENDAR_SVG_NO</option>
</field>
<!-- Legend_background_color Field. Type: Color. (joomla) -->
<field
type="color"
name="legend_background_color"
default="#494444"
label="MOD_VERSION_CALENDAR_SVG_LEGEND_BACKGROUND_COLOR_LABEL"
showon="show_legend:1"
/>
<!-- Legend_text_color Field. Type: Color. (joomla) -->
<field
type="color"
name="legend_text_color"
default="#fbf3ef"
label="MOD_VERSION_CALENDAR_SVG_LEGEND_TEXT_COLOR_LABEL"
showon="show_legend:1"
/>
</fieldset>
<!-- default paths of versions fieldset points to the module -->
<fieldset name="versions" label="MOD_VERSION_CALENDAR_SVG_VERSIONS"
<!-- default paths of dates fieldset points to the module -->
<fieldset name="dates" label="MOD_VERSION_CALENDAR_SVG_DATES"
addrulepath="/modules/mod_version_calendar_svg/rules"
addfieldpath="/modules/mod_version_calendar_svg/fields"
>
@ -243,7 +221,7 @@
min="1"
max="20"
step="1"
validate="number"
validate="int"
/>
<!-- Min_years Field. Type: Number. (joomla) -->
<field
@ -256,20 +234,20 @@
min="1"
max="10"
step="1"
validate="number"
validate="int"
/>
<!-- Versions Field. Type: Subform. (joomla) -->
<!-- Dates Field. Type: Subform. (joomla) -->
<field
type="subform"
name="versions"
label="MOD_VERSION_CALENDAR_SVG_VERSIONS_LABEL"
name="dates"
label="MOD_VERSION_CALENDAR_SVG_DATES_LABEL"
layout="joomla.form.field.subform.repeatable"
multiple="true"
buttons="add,remove,move"
icon="list"
max="10"
max="50"
min="1">
<form hidden="true" name="list_versions_modal" repeat="true">
<form hidden="true" name="list_dates_modal" repeat="true">
<!-- Version Field. Type: Text. (joomla) -->
<field
type="text"
@ -285,91 +263,39 @@
message="MOD_VERSION_CALENDAR_SVG_VERSION_MESSAGE"
hint="MOD_VERSION_CALENDAR_SVG_VERSION_HINT"
/>
<!-- Dates Field. Type: Subform. (joomla) -->
<!-- Start Field. Type: Calendar. (joomla) -->
<field
type="subform"
name="dates"
label="MOD_VERSION_CALENDAR_SVG_DATES_LABEL"
layout="joomla.form.field.subform.repeatable"
multiple="true"
buttons="add,remove,move"
icon="list"
max="10"
min="1"
nested_depth="1">
<form hidden="true" name="list_dates_modal" repeat="true">
<!-- State Field. Type: Text. (joomla) -->
<field
type="text"
name="state"
label="MOD_VERSION_CALENDAR_SVG_STATE_LABEL"
size="10"
maxlength="50"
class="text_area"
required="true"
filter="WORD"
hint="MOD_VERSION_CALENDAR_SVG_STATE_HINT"
autocomplete="on"
/>
<!-- Label Field. Type: Text. (joomla) -->
<field
type="text"
name="label"
label="MOD_VERSION_CALENDAR_SVG_LABEL_LABEL"
size="40"
maxlength="50"
class="text_area"
required="true"
filter="STRING"
hint="MOD_VERSION_CALENDAR_SVG_LABEL_HINT"
autocomplete="on"
/>
<!-- Description Field. Type: Text. (joomla) -->
<field
type="text"
name="description"
label="MOD_VERSION_CALENDAR_SVG_DESCRIPTION_LABEL"
size="50"
maxlength="150"
class="text_area"
required="false"
filter="STRING"
hint="MOD_VERSION_CALENDAR_SVG_DESCRIPTION_HINT"
autocomplete="on"
/>
<!-- Color Field. Type: Color. (joomla) -->
<field
type="color"
name="color"
default="#5091cd"
label="MOD_VERSION_CALENDAR_SVG_COLOR_LABEL"
description="MOD_VERSION_CALENDAR_SVG_COLOR_DESCRIPTION"
required="true"
/>
<!-- Start Field. Type: Calendar. (joomla) -->
<field
type="calendar"
name="start"
label="MOD_VERSION_CALENDAR_SVG_START_LABEL"
format="%d-%m-%Y"
filter="CMD"
message="MOD_VERSION_CALENDAR_SVG_START_MESSAGE"
size="40"
required="true"
/>
<!-- End Field. Type: Calendar. (joomla) -->
<field
type="calendar"
name="end"
label="MOD_VERSION_CALENDAR_SVG_END_LABEL"
format="%d-%m-%Y"
filter="CMD"
message="MOD_VERSION_CALENDAR_SVG_END_MESSAGE"
size="40"
required="true"
/>
</form>
</field>
type="calendar"
name="start"
label="MOD_VERSION_CALENDAR_SVG_START_LABEL"
format="%d-%m-%Y"
filter="CMD"
message="MOD_VERSION_CALENDAR_SVG_START_MESSAGE"
size="40"
required="true"
/>
<!-- Bug Field. Type: Calendar. (joomla) -->
<field
type="calendar"
name="bug"
label="MOD_VERSION_CALENDAR_SVG_BUG_LABEL"
format="%d-%m-%Y"
filter="CMD"
message="MOD_VERSION_CALENDAR_SVG_BUG_MESSAGE"
size="40"
required="true"
/>
<!-- End Field. Type: Calendar. (joomla) -->
<field
type="calendar"
name="end"
label="MOD_VERSION_CALENDAR_SVG_END_LABEL"
format="%d-%m-%Y"
filter="CMD"
message="MOD_VERSION_CALENDAR_SVG_END_MESSAGE"
size="40"
required="true"
/>
</form>
</field>
</fieldset>

55
rules/int.php Normal file
View File

@ -0,0 +1,55 @@
<?php
/**
* @package Joomla.CMS
* @maintainer Llewellyn van der Merwe <https://git.vdm.dev/Llewellyn>
*
* @created 29th July, 2020
* @copyright (C) 2020 Open Source Matters, Inc. <http://www.joomla.org>
* @license GNU General Public License version 2 or later; see LICENSE.txt
*/
// No direct access to this file
defined('JPATH_PLATFORM') or die;
use Joomla\CMS\Form\Form;
use Joomla\CMS\Form\FormRule;
use Joomla\Registry\Registry;
/**
* Form Rule (Int) class for the Joomla Platform.
*/
class JFormRuleInt extends FormRule
{
/**
* Method to test that an integer value was added.
*
* @param \SimpleXMLElement $element The SimpleXMLElement object representing the `<field>` tag for the form field object.
* @param mixed $value The form field value to validate.
* @param string $group The field name group control value. This acts as an array container for the field.
* For example if the field has name="foo" and the group value is set to "bar" then the
* full field name would end up being "bar[foo]".
* @param Registry $input An optional Registry object with the entire data set to validate against the entire form.
* @param Form $form The form object for which the field is being tested.
*
* @return boolean True if the value is valid integer, false otherwise.
*
*/
public function test(\SimpleXMLElement $element, $value, $group = null, Registry $input = null, Form $form = null)
{
// Check if the field is required.
$required = ((string) $element['required'] == 'true' || (string) $element['required'] == 'required');
// If the value is empty and the field is not required return True.
if (($value === '' || $value === null) && ! $required)
{
return true;
}
// now validate the value to be an integer
// we need to validate a string with the integer in it
// since this is how Joomla passes the value to the test method
// so we use type coercion along with is_numeric
return is_numeric($value) && is_int(+$value);
// if you have a better idea... lets hear it.
}
}

View File

@ -21,53 +21,61 @@ defined('_JEXEC') or die('Restricted access');
font-family: "Source Sans Pro", Helvetica, Arial, sans-serif;
font-size: <?php echo (2 / 3) * $params->get('header_height', 24); ?>px;
}
g.vcs-future rect,
.vcs-branches rect.vcs-future {
fill: <?php echo $params->get('future_color', '#5091cd'); ?>;
g.future rect,
.branches rect.future {
fill: <?php echo $params->get('future_color', '#000'); ?>;
}
g.vcs-future text {
fill: <?php echo $params->get('future_text_color', '#fff'); ?>;
}
g.vcs-eol rect,
.vcs-branches rect.vcs-eol {
g.eol rect,
.branches rect.eol {
fill: <?php echo $params->get('end_of_life_color', '#f33'); ?>;
}
g.vcs-eol text {
g.eol text {
fill: <?php echo $params->get('end_of_life_text_color', '#fff'); ?>;
}
<?php foreach ($branches as $version): ?>
<?php foreach ($version->dates as $date): ?>
g.<?php echo $date->state; ?> rect,
.vcs-branches rect.<?php echo $date->state; ?> {
fill: <?php echo $date->color; ?>;
}
<?php endforeach; ?>
<?php endforeach; ?>
.vcs-branch-labels text {
g.security rect,
.branches rect.security {
fill: <?php echo $params->get('security_color', '#f93'); ?>;
}
g.stable rect,
.branches rect.stable {
fill: <?php echo $params->get('stable_color', '#9c9'); ?>;
}
.branch-labels text {
dominant-baseline: central;
text-anchor: middle;
}
.vcs-today line {
.today line {
stroke: <?php echo $params->get('today_line_color', '#f33'); ?>;
stroke-dasharray: 7, 7;
stroke-width: 3px;
}
.vcs-today text {
.today text {
fill: <?php echo $params->get('today_text_color', '#f33'); ?>;
text-anchor: middle;
}
.vcs-years line {
.years line {
stroke: <?php echo $params->get('years_line_color', '#000'); ?>;
}
.vcs-years text {
.years text {
fill: <?php echo $params->get('years_text_color', '#000'); ?>;
text-anchor: middle;
}
</style>
<!-- Branch labels -->
<g class="vcs-branch-labels">
<?php foreach ($branches as $key => $branch): ?>
<g class="<?php echo $helper->state($branch->dates); ?>">
<g class="branch-labels">
<?php foreach ($branches as $branch): ?>
<g class="<?php echo $helper->state($branch); ?>">
<rect x="0" y="<?php echo $branch->top; ?>" width="<?php echo 0.5 * $params->get('margin_left', 80); ?>"
height="<?php echo $params->get('branch_height', 30); ?>"/>
<text x="<?php echo 0.25 * $params->get('margin_left', 80); ?>" y="<?php echo $branch->top + (0.5 * $params->get('branch_height', 30)); ?>">
@ -76,32 +84,24 @@ defined('_JEXEC') or die('Restricted access');
</g>
<?php endforeach; ?>
</g>
<!-- Branch blocks -->
<g class="vcs-branches">
<?php foreach ($branches as $key => $version): ?>
<g class="branches">
<?php foreach ($branches as $branch): ?>
<?php
$y = $version->top;
$height = $params->get('branch_height', 30);
$x_release = $helper->coordinates(new DateTime($branch->start));
$x_bug = $helper->coordinates(new DateTime($branch->bug));
$x_eol = $helper->coordinates(new DateTime($branch->end));
?>
<?php foreach ($version->dates as $date): ?>
<?php
$x_start = $helper->coordinates(new DateTime($date->start));
$x_end = $helper->coordinates(new DateTime($date->end));
?>
<g class="<?php echo $date->state; ?>">
<rect
x="<?php echo $x_start; ?>"
y="<?php echo $y; ?>"
width="<?php echo $x_end - $x_start; ?>"
height="<?php echo $height; ?>">
<title><?php echo htmlspecialchars($date->label); ?></title>
</rect>
</g>
<?php endforeach; ?>
<rect class="stable" x="<?php echo $x_release; ?>" y="<?php echo $branch->top; ?>"
width="<?php echo $x_bug - $x_release; ?>" height="<?php echo $params->get('branch_height', 30); ?>"/>
<rect class="security" x="<?php echo $x_bug; ?>" y="<?php echo $branch->top; ?>"
width="<?php echo $x_eol - $x_bug; ?>" height="<?php echo $params->get('branch_height', 30); ?>"/>
<?php endforeach; ?>
</g>
<!-- Year lines -->
<g class="vcs-years">
<g class="years">
<?php foreach ($helper->years() as $date): ?>
<line x1="<?php echo $helper->coordinates($date); ?>" y1="<?php echo $params->get('header_height', 24); ?>"
x2="<?php echo $helper->coordinates($date); ?>"
@ -111,8 +111,9 @@ defined('_JEXEC') or die('Restricted access');
</text>
<?php endforeach; ?>
</g>
<!-- Today -->
<g class="vcs-today">
<g class="today">
<?php
$now = new DateTime;
$x = $helper->coordinates($now);
@ -121,101 +122,7 @@ defined('_JEXEC') or die('Restricted access');
y2="<?php echo $params->get('header_height', 24) + ($qty * $params->get('branch_height', 30)); ?>"/>
<text x="<?php echo $x; ?>"
y="<?php echo $params->get('header_height', 24) + ($qty * $params->get('branch_height', 30)) + (0.8 * $params->get('footer_height', 24)); ?>">
<?php echo JText::_('MOD_VERSION_CALENDAR_SVG_TODAY') . ': ' . $now->format('j M Y'); ?>
<?php echo 'Today: ' . $now->format('j M Y'); ?>
</text>
</g>
</svg>
<?php if ($params->get('show_legend', 0) == 1): ?>
<?php
// get the legend values
$legend = $helper->legend();
?>
<style type="text/css">
/* Box Shadow */
.vcs-box-shadow-medium {
box-shadow: 0 10px 40px rgba(0, 0, 0, 0.15), 0 0.5rem 1.5rem rgba(0, 0, 0, 0.25);
}
/* Card Styles */
.vcs-card {
border-radius: 4px;
margin-top: 15px;
}
.vcs-card-legend {
background-color: <?php echo $params->get('legend_background_color', '#494444'); ?>;
color: <?php echo $params->get('legend_text_color', '#fbf3ef'); ?>;
}
.vcs-card-body {
padding: 4px;
}
/* Grid Styles */
.vcs-grid {
display: flex;
flex-wrap: wrap;
}
.vcs-grid-match > div {
padding: 5px;
min-height: 1px;
margin: 10px;
}
/* Flexbox Styles */
.vcs-flex {
display: flex;
align-items: center;
justify-content: space-between;
}
.vcs-flex-middle {
align-items: center;
}
/* Color Box Styles */
.vcs-color-box {
width: 20px;
height: 20px;
display: inline-block;
margin-right: 5px;
}
.vcs-future { background-color: <?php echo $params->get('future_color', '#000'); ?>; }
.vcs-eol { background-color: <?php echo $params->get('end_of_life_color', '#f33'); ?>; }
<?php foreach ($legend as $state): ?>
.<?php echo $state->state; ?> { background-color: <?php echo $state->color; ?>; }
<?php endforeach; ?>
/* Media Query for smaller screens */
@media (max-width: 768px) {
.vcs-grid {
flex-direction: column;
}
.vcs-flex {
display: block;
}
.vcs-grid-match > div {
margin: 4px;
padding: 0;
}
}
</style>
<div class="vcs-box-shadow-medium">
<div class="vcs-card vcs-card-legend vcs-card-body">
<div class="vcs-grid-match vcs-grid">
<div class="vcs-flex vcs-flex-middle">
<span
class="vcs-color-box vcs-future hasTooltip"
title="<?php echo JText::_('MOD_VERSION_CALENDAR_SVG_PLANNED_RELEASE_SCHEDULE'); ?>"
></span><?php echo JText::_('MOD_VERSION_CALENDAR_SVG_FUTURE_RELEASES'); ?>
</div>
<?php foreach ($legend as $state): ?>
<div class="vcs-flex vcs-flex-middle">
<span
class="vcs-color-box <?php echo $state->state; ?> hasTooltip"
title="<?php echo $state->description ?? ''; ?>"
></span><?php echo $state->label; ?>
</div>
<?php endforeach; ?>
<div class="vcs-flex vcs-flex-middle">
<span
class="vcs-color-box vcs-eol hasTooltip"
title="<?php echo JText::_('MOD_VERSION_CALENDAR_SVG_VERSION_END_OF_LIFE_SCHEDULE_EXPECT_NO_MORE_SUPPORT'); ?>"
></span><?php echo JText::_('MOD_VERSION_CALENDAR_SVG_VERSION_AT_END_OF_LIFE'); ?>
</div>
</div>
</div>
</div>
<?php endif; ?>
</svg>