Skip to content

Commit

Permalink
Joomla 5 compatibility
Browse files Browse the repository at this point in the history
  • Loading branch information
mavrosxristoforos committed Jan 23, 2024
1 parent 54dfc91 commit aa8fe71
Show file tree
Hide file tree
Showing 10 changed files with 70 additions and 50 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/mail.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,12 @@ jobs:
uses: actions/checkout@v1
- name: Build Joomla Package
id: jxbuild
uses: mavrosxristoforos/[email protected]
uses: mavrosxristoforos/[email protected].1
with:
build-file: 'build_quick_fields.jxb'
- name: Get XML
id: getxml
uses: mavrosxristoforos/get-xml-info@1.0
uses: mavrosxristoforos/get-xml-info@1.1.1
with:
xml-file: 'pkg_quick_fields.xml'
xpath: '//version'
Expand Down
16 changes: 7 additions & 9 deletions mod_quick_easyprofile_fields/fields/easyprofilefields.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,19 +9,17 @@

defined('JPATH_BASE') or die;

jimport('joomla.form.helper');
jimport('joomla.form.formfield');
jimport('joomla.html.html');
JFormHelper::loadFieldClass('list');

use \Joomla\CMS\Factory;
use \Joomla\CMS\Language\Text;
use \Joomla\CMS\Form\FormHelper;
use \Joomla\CMS\Form\Field\ListField;

/**
* Shows a customized list of EasyProfile fields.
*
* @since 1.6
*/
class JFormFieldEasyProfileFields extends JFormFieldList
class JFormFieldEasyProfileFields extends ListField
{
/**
* The form field type.
Expand All @@ -32,13 +30,13 @@ class JFormFieldEasyProfileFields extends JFormFieldList
protected $type = 'easyprofilefields';

public function getOptions() {
$db = JFactory::getDBO();
$db = Factory::getDBO();
if ($db->setQuery('SHOW TABLES LIKE "%jsn_fields%"')->loadResult()) {
$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');
$results = $db->loadObjectList();
foreach($results as $result) {
if (JText::_($result->text) != $result->text) {
$result->text = JText::_($result->text);
if (Text::_($result->text) != $result->text) {
$result->text = Text::_($result->text);
}
}
return $results;
Expand Down
31 changes: 19 additions & 12 deletions mod_quick_easyprofile_fields/mod_quick_easyprofile_fields.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,25 +12,32 @@
-------------------------------------------------------------------------*/

// no direct access
defined( '_JEXEC' ) or die( 'Restricted access' );
\defined( '_JEXEC' ) or die( 'Restricted access' );

use \Joomla\CMS\Factory;
use \Joomla\CMS\Helper\ModuleHelper;
use \Joomla\CMS\HTML\HTMLHelper;
use \Joomla\CMS\Form\Form;
use \Joomla\Registry\Registry;
//use \Joomla\CMS\Plugin\PluginHelper;

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

$joomla_user = JFactory::getUser();
$joomla_user = Factory::getUser();
if ($joomla_user->guest) {
// Requires login
return;
}

$db = JFactory::getDBO();
$db = Factory::getDBO();
$query = $db->getQuery(true);
$query->select('a.*')->from('#__jsn_users AS a')->where('a.id = '.$joomla_user->id);
$db->setQuery( $query );
$jsn_user = $db->loadObject();

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

$app = JFactory::getApplication();
$app = Factory::getApplication();

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

//JPluginHelper::importPlugin('fields');
JHtml::_('jquery.framework');
JHtml::_('bootstrap.tooltip');
JHtml::_('behavior.multiselect');
JHtml::_('formbehavior.chosen', 'select');
//PluginHelper::importPlugin('fields');
HTMLHelper::_('jquery.framework');
HTMLHelper::_('bootstrap.tooltip');
HTMLHelper::_('behavior.multiselect');
HTMLHelper::_('formbehavior.chosen', 'select');

$form = new JForm('easyprofile_quickfields');
$form = new Form('easyprofile_quickfields');
$xml = new DOMDocument('1.0', 'UTF-8');
$fieldsNode = $xml->appendChild(new DOMElement('form'))->appendChild(new DOMElement('fields'));
$fieldsNode->setAttribute('name', 'mod_quick_easyprofile_fields');
Expand All @@ -64,7 +71,7 @@
JHtml::register('jsn.email', array('JsnUsermailFieldHelper', 'usermail'));
}
foreach($fields as $field) {
$field->params = new JRegistry($field->params);
$field->params = new Registry($field->params);

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

if ((is_array($form->getFieldset('easyprofile_quickfields'))) && (count($form->getFieldset('easyprofile_quickfields')) > 0)) {
require JModuleHelper::getLayoutPath('mod_quick_easyprofile_fields');
require ModuleHelper::getLayoutPath('mod_quick_easyprofile_fields');
}

?>
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<extension type="module" version="3.0" method="upgrade" client="site">
<name>Quick EasyProfile Fields</name>
<author>Christopher Mavros</author>
<version>1.0.64</version>
<version>1.0.70</version>
<creationDate>April 2020</creationDate>
<copyright>Copyright (C) 2020 Christopher Mavros. All rights reserved.</copyright>
<license>http://www.gnu.org/licenses/gpl-3.0.html GNU/GPL</license>
Expand Down
2 changes: 1 addition & 1 deletion mod_quick_easyprofile_fields/tmpl/default.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
-------------------------------------------------------------------------*/

// no direct access
defined( '_JEXEC' ) or die( 'Restricted access' );
\defined( '_JEXEC' ) or die( 'Restricted access' );

?>
<div class="mod_quick_fields <?php print $params->get('moduleclass_sfx', ''); ?>">
Expand Down
4 changes: 2 additions & 2 deletions mod_quick_fields/helper.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@
-------------------------------------------------------------------------*/

// no direct access
defined( '_JEXEC' ) or die( 'Restricted access' );
\defined( '_JEXEC' ) or die( 'Restricted access' );

use Joomla\CMS\MVC\Factory\MVCFactory; // Joomla 4 only!
use \Joomla\CMS\MVC\Factory\MVCFactory; // Joomla 4 only!

class QFHelper {

Expand Down
55 changes: 35 additions & 20 deletions mod_quick_fields/mod_quick_fields.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,18 +12,29 @@
-------------------------------------------------------------------------*/

// no direct access
defined( '_JEXEC' ) or die( 'Restricted access' );
\defined( '_JEXEC' ) or die( 'Restricted access' );

use \Joomla\CMS\Factory;
use \Joomla\CMS\Language\Text;
use \Joomla\CMS\Helper\ModuleHelper;
use \Joomla\CMS\HTML\HTMLHelper;
use \Joomla\CMS\MVC\Model\BaseDatabaseModel;
use \Joomla\CMS\Plugin\PluginHelper;
use \Joomla\CMS\Form\Form;
use \Joomla\Registry\Registry;

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

JPluginHelper::importPlugin('fields');
JHtml::_('jquery.framework');
JHtml::_('bootstrap.tooltip');
JHtml::_('behavior.multiselect');
JHtml::_('formbehavior.chosen', 'select');
PluginHelper::importPlugin('fields');
HTMLHelper::_('jquery.framework');
HTMLHelper::_('bootstrap.tooltip');
HTMLHelper::_('behavior.multiselect');
if (version_compare(JVERSION, '4', '<')) {
HTMLHelper::_('formbehavior.chosen', 'select');
}

$app = JFactory::getApplication();
$form = new JForm('quickfields');
$app = Factory::getApplication();
$form = new Form('quickfields');
$xml = new DOMDocument('1.0', 'UTF-8');
$fieldsNode = $xml->appendChild(new DOMElement('form'))->appendChild(new DOMElement('fields'));
$fieldsNode->setAttribute('name', 'mod_quickfields');
Expand All @@ -35,22 +46,22 @@
$model = QFHelper::getModel();
}
else {
JModelLegacy::addIncludePath(JPATH_ADMINISTRATOR.'/components/com_fields/models/');
$model = JModelLegacy::getInstance('Field', 'FieldsModel');
BaseDatabaseModel::addIncludePath(JPATH_ADMINISTRATOR.'/components/com_fields/models/');
$model = BaseDatabaseModel::getInstance('Field', 'FieldsModel');
}

if (!$model) {
print JText::_('MOD_QUICK_FIELDS_MODEL_NOT_FOUND');
print Text::_('MOD_QUICK_FIELDS_MODEL_NOT_FOUND');
return;
}

$user = JFactory::getUser();
$user = Factory::getUser();

$fields = array();
foreach($field_ids as $field_id) {
$field = $model->getItem($field_id);
$field->params = new JRegistry($field->params);
$field->fieldparams = new JRegistry($field->fieldparams);
$field->params = new Registry($field->params);
$field->fieldparams = new Registry($field->fieldparams);
if($field->context == 'com_users.user') {
if (!$user->guest) {
$fieldValues = $model->getFieldValues($field_ids, $user->id);
Expand Down Expand Up @@ -81,6 +92,9 @@
$field->value = $value;
}
}
else {
$field->value = null;
}
}
else {
// This field requires log-in
Expand Down Expand Up @@ -124,6 +138,7 @@
if (!is_null($data)) {
$value = $model->getFieldValue($field->id, $data->id);
if ($value === null) {
$field->new_rawvalue = null;
continue;
}
if (!is_array($value) && $value !== '') {
Expand Down Expand Up @@ -179,11 +194,11 @@

if ($msg_fields_body != '') {
// Create email
$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>';
$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>';

if (trim($params->get('notification_email', '')) != '') {
// TODO: Create Email!
$mail = JFactory::getMailer();
$mail = Factory::getMailer();
$mail->isHTML(true);
// Mail Recipients
$recipients = $params->get('notification_email', '');
Expand All @@ -204,22 +219,22 @@
$str_count = 0;
$body = str_replace('%fields%', $msg_fields_body, $body, $str_count);
if (($str_count + $preg_count) == 0) {
$body .= JText::_('MOD_QUICK_FIELDS_NO_FIELDS_TAG_IN_BODY_WARNING');
$body .= Text::_('MOD_QUICK_FIELDS_NO_FIELDS_TAG_IN_BODY_WARNING');
}
$mail->setBody($body);

if ($mail->Send() !== true) {
print JText::_('MOD_QUICK_FIELDS_FAILED_SENDING_NOTIFICATION_EMAIL');
print Text::_('MOD_QUICK_FIELDS_FAILED_SENDING_NOTIFICATION_EMAIL');
}
}
else {
print JText::_('MOD_QUICK_FIELDS_NOTIFICATION_EMAIL_COULD_NOT_BE_SENT_BECAUSE_NO_RECIPIENT_SPECIFIED');
print Text::_('MOD_QUICK_FIELDS_NOTIFICATION_EMAIL_COULD_NOT_BE_SENT_BECAUSE_NO_RECIPIENT_SPECIFIED');
}
}
}

if ((is_array($form->getFieldset('quickfields'))) && (count($form->getFieldset('quickfields')) > 0)) {
require JModuleHelper::getLayoutPath('mod_quick_fields');
require ModuleHelper::getLayoutPath('mod_quick_fields');
}

?>
2 changes: 1 addition & 1 deletion mod_quick_fields/mod_quick_fields.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<extension type="module" version="3.0" method="upgrade" client="site">
<name>Quick Fields</name>
<author>Christopher Mavros</author>
<version>1.0.64</version>
<version>1.0.70</version>
<creationDate>April 2020</creationDate>
<copyright>Copyright (C) 2020 Christopher Mavros. All rights reserved.</copyright>
<license>http://www.gnu.org/licenses/gpl-3.0.html GNU/GPL</license>
Expand Down
2 changes: 1 addition & 1 deletion mod_quick_fields/tmpl/default.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
-------------------------------------------------------------------------*/

// no direct access
defined( '_JEXEC' ) or die( 'Restricted access' );
\defined( '_JEXEC' ) or die( 'Restricted access' );

?>
<div class="mod_quick_fields <?php print $params->get('moduleclass_sfx', ''); ?>">
Expand Down
2 changes: 1 addition & 1 deletion pkg_quick_fields.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
<author>Christopher Mavros</author>
<authorEmail>[email protected]</authorEmail>
<authorUrl>http://mavrosxristoforos.com</authorUrl>
<version>1.0.64</version>
<version>1.0.70</version>
<description>Quick Fields - Show Custom Fields in a module with the ability to edit on spot</description>
<files>
<file type="module" id="mod_quick_fields">mod_quick_fields.zip</file>
Expand Down

0 comments on commit aa8fe71

Please sign in to comment.