Skip to content

Commit aa8fe71

Browse files
Joomla 5 compatibility
1 parent 54dfc91 commit aa8fe71

File tree

10 files changed

+70
-50
lines changed

10 files changed

+70
-50
lines changed

.github/workflows/mail.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,12 @@ jobs:
1515
uses: actions/checkout@v1
1616
- name: Build Joomla Package
1717
id: jxbuild
18-
uses: mavrosxristoforos/jxb@1.0
18+
uses: mavrosxristoforos/jxb@1.0.1
1919
with:
2020
build-file: 'build_quick_fields.jxb'
2121
- name: Get XML
2222
id: getxml
23-
uses: mavrosxristoforos/get-xml-info@1.0
23+
uses: mavrosxristoforos/get-xml-info@1.1.1
2424
with:
2525
xml-file: 'pkg_quick_fields.xml'
2626
xpath: '//version'

mod_quick_easyprofile_fields/fields/easyprofilefields.php

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9,19 +9,17 @@
99

1010
defined('JPATH_BASE') or die;
1111

12-
jimport('joomla.form.helper');
13-
jimport('joomla.form.formfield');
14-
jimport('joomla.html.html');
15-
JFormHelper::loadFieldClass('list');
16-
1712
use \Joomla\CMS\Factory;
13+
use \Joomla\CMS\Language\Text;
14+
use \Joomla\CMS\Form\FormHelper;
15+
use \Joomla\CMS\Form\Field\ListField;
1816

1917
/**
2018
* Shows a customized list of EasyProfile fields.
2119
*
2220
* @since 1.6
2321
*/
24-
class JFormFieldEasyProfileFields extends JFormFieldList
22+
class JFormFieldEasyProfileFields extends ListField
2523
{
2624
/**
2725
* The form field type.
@@ -32,13 +30,13 @@ class JFormFieldEasyProfileFields extends JFormFieldList
3230
protected $type = 'easyprofilefields';
3331

3432
public function getOptions() {
35-
$db = JFactory::getDBO();
33+
$db = Factory::getDBO();
3634
if ($db->setQuery('SHOW TABLES LIKE "%jsn_fields%"')->loadResult()) {
3735
$db->setQuery('SELECT a.`id` as `value`, a.`title` as `text` FROM `#__jsn_fields` AS a WHERE a.`alias` <> "root" AND (a.`published` IN (0, 1)) ORDER BY a.`lft` asc');
3836
$results = $db->loadObjectList();
3937
foreach($results as $result) {
40-
if (JText::_($result->text) != $result->text) {
41-
$result->text = JText::_($result->text);
38+
if (Text::_($result->text) != $result->text) {
39+
$result->text = Text::_($result->text);
4240
}
4341
}
4442
return $results;

mod_quick_easyprofile_fields/mod_quick_easyprofile_fields.php

Lines changed: 19 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -12,25 +12,32 @@
1212
-------------------------------------------------------------------------*/
1313

1414
// no direct access
15-
defined( '_JEXEC' ) or die( 'Restricted access' );
15+
\defined( '_JEXEC' ) or die( 'Restricted access' );
16+
17+
use \Joomla\CMS\Factory;
18+
use \Joomla\CMS\Helper\ModuleHelper;
19+
use \Joomla\CMS\HTML\HTMLHelper;
20+
use \Joomla\CMS\Form\Form;
21+
use \Joomla\Registry\Registry;
22+
//use \Joomla\CMS\Plugin\PluginHelper;
1623

1724
$field_ids = $params->get('fields', array());
1825

19-
$joomla_user = JFactory::getUser();
26+
$joomla_user = Factory::getUser();
2027
if ($joomla_user->guest) {
2128
// Requires login
2229
return;
2330
}
2431

25-
$db = JFactory::getDBO();
32+
$db = Factory::getDBO();
2633
$query = $db->getQuery(true);
2734
$query->select('a.*')->from('#__jsn_users AS a')->where('a.id = '.$joomla_user->id);
2835
$db->setQuery( $query );
2936
$jsn_user = $db->loadObject();
3037

3138
if (!$jsn_user) { return; } // EasyProfile user required!
3239

33-
$app = JFactory::getApplication();
40+
$app = Factory::getApplication();
3441

3542
if ($params->get('hide_on_other', '0') > '0') {
3643
if ((strtolower($app->input->getVar('option')) == 'com_jsn') && (strtolower($app->input->getVar('view')) == 'profile')) {
@@ -46,13 +53,13 @@
4653
$db->setQuery( $query );
4754
$fields = $db->loadObjectList();
4855

49-
//JPluginHelper::importPlugin('fields');
50-
JHtml::_('jquery.framework');
51-
JHtml::_('bootstrap.tooltip');
52-
JHtml::_('behavior.multiselect');
53-
JHtml::_('formbehavior.chosen', 'select');
56+
//PluginHelper::importPlugin('fields');
57+
HTMLHelper::_('jquery.framework');
58+
HTMLHelper::_('bootstrap.tooltip');
59+
HTMLHelper::_('behavior.multiselect');
60+
HTMLHelper::_('formbehavior.chosen', 'select');
5461

55-
$form = new JForm('easyprofile_quickfields');
62+
$form = new Form('easyprofile_quickfields');
5663
$xml = new DOMDocument('1.0', 'UTF-8');
5764
$fieldsNode = $xml->appendChild(new DOMElement('form'))->appendChild(new DOMElement('fields'));
5865
$fieldsNode->setAttribute('name', 'mod_quick_easyprofile_fields');
@@ -64,7 +71,7 @@
6471
JHtml::register('jsn.email', array('JsnUsermailFieldHelper', 'usermail'));
6572
}
6673
foreach($fields as $field) {
67-
$field->params = new JRegistry($field->params);
74+
$field->params = new Registry($field->params);
6875

6976
$class='Jsn'.ucfirst($field->type).'FieldHelper';
7077
if(class_exists($class)) $class::loadData($field, $jsn_user, $joomla_user);
@@ -119,7 +126,7 @@
119126
}
120127

121128
if ((is_array($form->getFieldset('easyprofile_quickfields'))) && (count($form->getFieldset('easyprofile_quickfields')) > 0)) {
122-
require JModuleHelper::getLayoutPath('mod_quick_easyprofile_fields');
129+
require ModuleHelper::getLayoutPath('mod_quick_easyprofile_fields');
123130
}
124131

125132
?>

mod_quick_easyprofile_fields/mod_quick_easyprofile_fields.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
<extension type="module" version="3.0" method="upgrade" client="site">
33
<name>Quick EasyProfile Fields</name>
44
<author>Christopher Mavros</author>
5-
<version>1.0.64</version>
5+
<version>1.0.70</version>
66
<creationDate>April 2020</creationDate>
77
<copyright>Copyright (C) 2020 Christopher Mavros. All rights reserved.</copyright>
88
<license>http://www.gnu.org/licenses/gpl-3.0.html GNU/GPL</license>

mod_quick_easyprofile_fields/tmpl/default.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
-------------------------------------------------------------------------*/
1313

1414
// no direct access
15-
defined( '_JEXEC' ) or die( 'Restricted access' );
15+
\defined( '_JEXEC' ) or die( 'Restricted access' );
1616

1717
?>
1818
<div class="mod_quick_fields <?php print $params->get('moduleclass_sfx', ''); ?>">

mod_quick_fields/helper.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,9 @@
1212
-------------------------------------------------------------------------*/
1313

1414
// no direct access
15-
defined( '_JEXEC' ) or die( 'Restricted access' );
15+
\defined( '_JEXEC' ) or die( 'Restricted access' );
1616

17-
use Joomla\CMS\MVC\Factory\MVCFactory; // Joomla 4 only!
17+
use \Joomla\CMS\MVC\Factory\MVCFactory; // Joomla 4 only!
1818

1919
class QFHelper {
2020

mod_quick_fields/mod_quick_fields.php

Lines changed: 35 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -12,18 +12,29 @@
1212
-------------------------------------------------------------------------*/
1313

1414
// no direct access
15-
defined( '_JEXEC' ) or die( 'Restricted access' );
15+
\defined( '_JEXEC' ) or die( 'Restricted access' );
16+
17+
use \Joomla\CMS\Factory;
18+
use \Joomla\CMS\Language\Text;
19+
use \Joomla\CMS\Helper\ModuleHelper;
20+
use \Joomla\CMS\HTML\HTMLHelper;
21+
use \Joomla\CMS\MVC\Model\BaseDatabaseModel;
22+
use \Joomla\CMS\Plugin\PluginHelper;
23+
use \Joomla\CMS\Form\Form;
24+
use \Joomla\Registry\Registry;
1625

1726
$field_ids = $params->get('fields', array());
1827

19-
JPluginHelper::importPlugin('fields');
20-
JHtml::_('jquery.framework');
21-
JHtml::_('bootstrap.tooltip');
22-
JHtml::_('behavior.multiselect');
23-
JHtml::_('formbehavior.chosen', 'select');
28+
PluginHelper::importPlugin('fields');
29+
HTMLHelper::_('jquery.framework');
30+
HTMLHelper::_('bootstrap.tooltip');
31+
HTMLHelper::_('behavior.multiselect');
32+
if (version_compare(JVERSION, '4', '<')) {
33+
HTMLHelper::_('formbehavior.chosen', 'select');
34+
}
2435

25-
$app = JFactory::getApplication();
26-
$form = new JForm('quickfields');
36+
$app = Factory::getApplication();
37+
$form = new Form('quickfields');
2738
$xml = new DOMDocument('1.0', 'UTF-8');
2839
$fieldsNode = $xml->appendChild(new DOMElement('form'))->appendChild(new DOMElement('fields'));
2940
$fieldsNode->setAttribute('name', 'mod_quickfields');
@@ -35,22 +46,22 @@
3546
$model = QFHelper::getModel();
3647
}
3748
else {
38-
JModelLegacy::addIncludePath(JPATH_ADMINISTRATOR.'/components/com_fields/models/');
39-
$model = JModelLegacy::getInstance('Field', 'FieldsModel');
49+
BaseDatabaseModel::addIncludePath(JPATH_ADMINISTRATOR.'/components/com_fields/models/');
50+
$model = BaseDatabaseModel::getInstance('Field', 'FieldsModel');
4051
}
4152

4253
if (!$model) {
43-
print JText::_('MOD_QUICK_FIELDS_MODEL_NOT_FOUND');
54+
print Text::_('MOD_QUICK_FIELDS_MODEL_NOT_FOUND');
4455
return;
4556
}
4657

47-
$user = JFactory::getUser();
58+
$user = Factory::getUser();
4859

4960
$fields = array();
5061
foreach($field_ids as $field_id) {
5162
$field = $model->getItem($field_id);
52-
$field->params = new JRegistry($field->params);
53-
$field->fieldparams = new JRegistry($field->fieldparams);
63+
$field->params = new Registry($field->params);
64+
$field->fieldparams = new Registry($field->fieldparams);
5465
if($field->context == 'com_users.user') {
5566
if (!$user->guest) {
5667
$fieldValues = $model->getFieldValues($field_ids, $user->id);
@@ -81,6 +92,9 @@
8192
$field->value = $value;
8293
}
8394
}
95+
else {
96+
$field->value = null;
97+
}
8498
}
8599
else {
86100
// This field requires log-in
@@ -124,6 +138,7 @@
124138
if (!is_null($data)) {
125139
$value = $model->getFieldValue($field->id, $data->id);
126140
if ($value === null) {
141+
$field->new_rawvalue = null;
127142
continue;
128143
}
129144
if (!is_array($value) && $value !== '') {
@@ -179,11 +194,11 @@
179194

180195
if ($msg_fields_body != '') {
181196
// Create email
182-
$msg_fields_body = '<table width="80%" border="1"><tr style="background-color: #ccc; font-weight: bold;"><td>'.JText::_('MOD_QUICK_FIELDS_NOTIFICATION_HEADER_FIELD_TITLE').'</td><td>'.JText::_('MOD_QUICK_FIELDS_NOTIFICATION_HEADER_PREVIOUS_VALUE').'</td><td>'.JText::_('MOD_QUICK_FIELDS_NOTIFICATION_HEADER_CURRENT_VALUE').'</td><td>'.JText::_('MOD_QUICK_FIELDS_NOTIFICATION_HEADER_CHANGED_ON').'</td></tr>'.$msg_fields_body.'</table>';
197+
$msg_fields_body = '<table width="80%" border="1"><tr style="background-color: #ccc; font-weight: bold;"><td>'.Text::_('MOD_QUICK_FIELDS_NOTIFICATION_HEADER_FIELD_TITLE').'</td><td>'.Text::_('MOD_QUICK_FIELDS_NOTIFICATION_HEADER_PREVIOUS_VALUE').'</td><td>'.Text::_('MOD_QUICK_FIELDS_NOTIFICATION_HEADER_CURRENT_VALUE').'</td><td>'.Text::_('MOD_QUICK_FIELDS_NOTIFICATION_HEADER_CHANGED_ON').'</td></tr>'.$msg_fields_body.'</table>';
183198

184199
if (trim($params->get('notification_email', '')) != '') {
185200
// TODO: Create Email!
186-
$mail = JFactory::getMailer();
201+
$mail = Factory::getMailer();
187202
$mail->isHTML(true);
188203
// Mail Recipients
189204
$recipients = $params->get('notification_email', '');
@@ -204,22 +219,22 @@
204219
$str_count = 0;
205220
$body = str_replace('%fields%', $msg_fields_body, $body, $str_count);
206221
if (($str_count + $preg_count) == 0) {
207-
$body .= JText::_('MOD_QUICK_FIELDS_NO_FIELDS_TAG_IN_BODY_WARNING');
222+
$body .= Text::_('MOD_QUICK_FIELDS_NO_FIELDS_TAG_IN_BODY_WARNING');
208223
}
209224
$mail->setBody($body);
210225

211226
if ($mail->Send() !== true) {
212-
print JText::_('MOD_QUICK_FIELDS_FAILED_SENDING_NOTIFICATION_EMAIL');
227+
print Text::_('MOD_QUICK_FIELDS_FAILED_SENDING_NOTIFICATION_EMAIL');
213228
}
214229
}
215230
else {
216-
print JText::_('MOD_QUICK_FIELDS_NOTIFICATION_EMAIL_COULD_NOT_BE_SENT_BECAUSE_NO_RECIPIENT_SPECIFIED');
231+
print Text::_('MOD_QUICK_FIELDS_NOTIFICATION_EMAIL_COULD_NOT_BE_SENT_BECAUSE_NO_RECIPIENT_SPECIFIED');
217232
}
218233
}
219234
}
220235

221236
if ((is_array($form->getFieldset('quickfields'))) && (count($form->getFieldset('quickfields')) > 0)) {
222-
require JModuleHelper::getLayoutPath('mod_quick_fields');
237+
require ModuleHelper::getLayoutPath('mod_quick_fields');
223238
}
224239

225240
?>

mod_quick_fields/mod_quick_fields.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
<extension type="module" version="3.0" method="upgrade" client="site">
33
<name>Quick Fields</name>
44
<author>Christopher Mavros</author>
5-
<version>1.0.64</version>
5+
<version>1.0.70</version>
66
<creationDate>April 2020</creationDate>
77
<copyright>Copyright (C) 2020 Christopher Mavros. All rights reserved.</copyright>
88
<license>http://www.gnu.org/licenses/gpl-3.0.html GNU/GPL</license>

mod_quick_fields/tmpl/default.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
-------------------------------------------------------------------------*/
1313

1414
// no direct access
15-
defined( '_JEXEC' ) or die( 'Restricted access' );
15+
\defined( '_JEXEC' ) or die( 'Restricted access' );
1616

1717
?>
1818
<div class="mod_quick_fields <?php print $params->get('moduleclass_sfx', ''); ?>">

pkg_quick_fields.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
<author>Christopher Mavros</author>
99
<authorEmail>mavrosxristoforos@gmail.com</authorEmail>
1010
<authorUrl>http://mavrosxristoforos.com</authorUrl>
11-
<version>1.0.64</version>
11+
<version>1.0.70</version>
1212
<description>Quick Fields - Show Custom Fields in a module with the ability to edit on spot</description>
1313
<files>
1414
<file type="module" id="mod_quick_fields">mod_quick_fields.zip</file>

0 commit comments

Comments
 (0)