Skip to content

Commit ea878cb

Browse files
committed
Forgot to add the new fields
1 parent 73f3cc3 commit ea878cb

File tree

2 files changed

+280
-0
lines changed

2 files changed

+280
-0
lines changed

models/fields/releases.php

Lines changed: 138 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,138 @@
1+
<?php
2+
/**
3+
* @package Mod_ttm_diif_tool_of
4+
* @subpackage models
5+
*
6+
* @copyright Copyright (C) 2005 - 2015 Open Source Matters, Inc. All rights reserved.
7+
* @license GNU General Public License version 2 or later; see LICENSE.txt
8+
*/
9+
10+
defined('_JEXEC') or die;
11+
12+
use Joomla\Github\Github;
13+
14+
JFormHelper::loadFieldClass('list');
15+
16+
/**
17+
* Form Field Place class.
18+
*
19+
* @package Extensions.Components
20+
* @subpackage Localise
21+
*
22+
* @since 1.0
23+
*/
24+
class JFormFieldReleases extends JFormFieldList
25+
{
26+
/**
27+
* The field type.
28+
*
29+
* @var string
30+
*/
31+
protected $type = 'Releases';
32+
33+
/**
34+
* Method to get the field input.
35+
*
36+
* @return string The field input.
37+
*/
38+
protected function getOptions()
39+
{
40+
require_once JPATH_SITE . '/modules/mod_ttm_diff_tool_otf/vendor/autoload.php';
41+
42+
$attributes = '';
43+
44+
$gh_user = 'joomla';
45+
$gh_project = 'joomla-cms';
46+
47+
$options = new JRegistry;
48+
49+
// Trying with a 'read only' public repositories token
50+
// But base 64 encoded to avoid Github alarms sharing it.
51+
$gh_token = base64_decode('MzY2NzYzM2ZkMzZmMWRkOGU5NmRiMTdjOGVjNTFiZTIyMzk4NzVmOA==');
52+
$options->set('gh.token', $gh_token);
53+
$github = new Github($options);
54+
55+
try
56+
{
57+
$releases = $github->repositories->get(
58+
$gh_user,
59+
$gh_project . '/releases'
60+
);
61+
62+
foreach ($releases as $release)
63+
{
64+
$tag_name = $release->tag_name;
65+
$tag_part = explode(".", $tag_name);
66+
$undoted = str_replace('.', '', $tag_name);
67+
$excluded = 0;
68+
69+
if (version_compare(JVERSION[0], '2', 'eq'))
70+
{
71+
$excluded = 1;
72+
}
73+
elseif (version_compare(JVERSION[0], '3', 'eq'))
74+
{
75+
if ($tag_part[0] != '3')
76+
{
77+
$excluded = 1;
78+
}
79+
}
80+
elseif (version_compare(JVERSION[0], '4', 'ge'))
81+
{
82+
if ($tag_part[0] == '4' || $tag_part[0] == '3')
83+
{
84+
$excluded = 0;
85+
}
86+
else
87+
{
88+
$excluded = 1;
89+
}
90+
}
91+
92+
// Filtering by "is_numeric" disable betas or similar releases.
93+
if (is_numeric($undoted) && $excluded == 0)
94+
{
95+
$versions[] = $tag_name;
96+
}
97+
}
98+
}
99+
catch (Exception $e)
100+
{
101+
JFactory::getApplication()->enqueueMessage(
102+
JText::_('ERROR_GITHUB_GETTING_RELEASES'),
103+
'warning');
104+
}
105+
106+
arsort($versions);
107+
108+
if ($v = (string) $this->element['onchange'])
109+
{
110+
$attributes .= ' onchange="' . $v . '"';
111+
}
112+
113+
$options = array();
114+
115+
foreach ($this->element->children() as $option)
116+
{
117+
$options[] = JHtml::_('select.option', $option->attributes('value'), JText::_(trim($option)),
118+
array('option.attr' => 'attributes', 'attr' => '')
119+
);
120+
}
121+
122+
$options[] = JHtml::_('select.option', 'CUSTOM_SR', JText::_('MOD_TTM_DIFF_TOOL_OTF_SR_OPTION_CUSTOM'),
123+
array('option.attr' => 'attributes')
124+
);
125+
126+
foreach ($versions as $version)
127+
{
128+
if (!empty($version))
129+
{
130+
$options[] = JHtml::_('select.option', $version, sprintf('Joomla %s', $version),
131+
array('option.attr' => 'attributes')
132+
);
133+
}
134+
}
135+
136+
return $options;
137+
}
138+
}

models/fields/targetreleases.php

Lines changed: 142 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,142 @@
1+
<?php
2+
/**
3+
* @package Mod_ttm_diif_tool_of
4+
* @subpackage models
5+
*
6+
* @copyright Copyright (C) 2005 - 2015 Open Source Matters, Inc. All rights reserved.
7+
* @license GNU General Public License version 2 or later; see LICENSE.txt
8+
*/
9+
10+
defined('_JEXEC') or die;
11+
12+
use Joomla\Github\Github;
13+
14+
JFormHelper::loadFieldClass('list');
15+
16+
/**
17+
* Form Field Place class.
18+
*
19+
* @package Extensions.Components
20+
* @subpackage Localise
21+
*
22+
* @since 1.0
23+
*/
24+
class JFormFieldTargetReleases extends JFormFieldList
25+
{
26+
/**
27+
* The field type.
28+
*
29+
* @var string
30+
*/
31+
protected $type = 'Targetreleases';
32+
33+
/**
34+
* Method to get the field input.
35+
*
36+
* @return string The field input.
37+
*/
38+
protected function getOptions()
39+
{
40+
require_once JPATH_SITE . '/modules/mod_ttm_diff_tool_otf/vendor/autoload.php';
41+
42+
$attributes = '';
43+
44+
$gh_user = 'joomla';
45+
$gh_project = 'joomla-cms';
46+
47+
$options = new JRegistry;
48+
49+
// Trying with a 'read only' public repositories token
50+
// But base 64 encoded to avoid Github alarms sharing it.
51+
$gh_token = base64_decode('MzY2NzYzM2ZkMzZmMWRkOGU5NmRiMTdjOGVjNTFiZTIyMzk4NzVmOA==');
52+
$options->set('gh.token', $gh_token);
53+
$github = new Github($options);
54+
55+
try
56+
{
57+
$releases = $github->repositories->get(
58+
$gh_user,
59+
$gh_project . '/releases'
60+
);
61+
62+
foreach ($releases as $release)
63+
{
64+
$tag_name = $release->tag_name;
65+
$tag_part = explode(".", $tag_name);
66+
$undoted = str_replace('.', '', $tag_name);
67+
$excluded = 0;
68+
69+
if (version_compare(JVERSION[0], '2', 'eq'))
70+
{
71+
$excluded = 1;
72+
}
73+
elseif (version_compare(JVERSION[0], '3', 'eq'))
74+
{
75+
if ($tag_part[0] != '3')
76+
{
77+
$excluded = 1;
78+
}
79+
}
80+
elseif (version_compare(JVERSION[0], '4', 'ge'))
81+
{
82+
if ($tag_part[0] == '4' || $tag_part[0] == '3')
83+
{
84+
$excluded = 0;
85+
}
86+
else
87+
{
88+
$excluded = 1;
89+
}
90+
}
91+
92+
// Filtering by "is_numeric" disable betas or similar releases.
93+
if (is_numeric($undoted) && $excluded == 0)
94+
{
95+
$versions[] = $tag_name;
96+
}
97+
}
98+
}
99+
catch (Exception $e)
100+
{
101+
JFactory::getApplication()->enqueueMessage(
102+
JText::_('ERROR_GITHUB_GETTING_RELEASES'),
103+
'warning');
104+
}
105+
106+
arsort($versions);
107+
108+
if ($v = (string) $this->element['onchange'])
109+
{
110+
$attributes .= ' onchange="' . $v . '"';
111+
}
112+
113+
$options = array();
114+
115+
foreach ($this->element->children() as $option)
116+
{
117+
$options[] = JHtml::_('select.option', $option->attributes('value'), JText::_(trim($option)),
118+
array('option.attr' => 'attributes', 'attr' => '')
119+
);
120+
}
121+
122+
$options[] = JHtml::_('select.option', 'STS_DEV', JText::_('MOD_TTM_DIFF_TOOL_OTF_TR_OPTION_STS_DEV'),
123+
array('option.attr' => 'attributes')
124+
);
125+
126+
$options[] = JHtml::_('select.option', 'CUSTOM_TR', JText::_('MOD_TTM_DIFF_TOOL_OTF_TR_OPTION_CUSTOM'),
127+
array('option.attr' => 'attributes')
128+
);
129+
130+
foreach ($versions as $version)
131+
{
132+
if (!empty($version))
133+
{
134+
$options[] = JHtml::_('select.option', $version, sprintf('Joomla %s', $version),
135+
array('option.attr' => 'attributes')
136+
);
137+
}
138+
}
139+
140+
return $options;
141+
}
142+
}

0 commit comments

Comments
 (0)