Skip to content

Commit

Permalink
Add files via upload
Browse files Browse the repository at this point in the history
First working Joomla 4 version (2.0)
  • Loading branch information
bascherz authored Oct 23, 2022
1 parent c7e6528 commit 07e5efb
Show file tree
Hide file tree
Showing 7 changed files with 306 additions and 0 deletions.
1 change: 1 addition & 0 deletions j4/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<html><body bgcolor="#FFFFFF"></body></html>
16 changes: 16 additions & 0 deletions j4/manifest.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?xml version="1.0" encoding="utf-8"?>
<updates>
<update>
<name>Table Dump Module</name>
<description>Joomla! Table Dump Module</description>
<element>mod_tabledump</element>
<type>module</type>
<version>2.0</version>
<client>site</client>
<infourl title="Table Dump Module">https://github.com/bascherz/Table-Dump-Module/releases/tag/2.0</infourl>
<downloads>
<downloadurl type="full" format="zip">https://github.com/bascherz/Table-Dump-Module/releases/download/2.0/mod_tabledump_2.0.zip</downloadurl>
</downloads>
<targetplatform name="joomla" version="4.[0123456789]" />
</update>
</updates>
30 changes: 30 additions & 0 deletions j4/mod_tabledump.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<?php
/**
* Table Dump Module Entry Point
*
* @package Table Dump
* @subpackage Modules
* @license GNU/GPL, see LICENSE.php
* @link http://docs.joomla.org/J3.x:Creating_a_simple_module/Developing_a_Basic_Module
* mod_sitemembers is free software. This version may have been modified pursuant
* to the GNU General Public License, and as distributed it includes or
* is derivative of works licensed under the GNU General Public License or
* other free or open source software licenses.
*/

// No direct access
defined('_JEXEC') or die;

use Joomla\CMS\Helper\ModuleHelper;
use Joomla\CMS\HTML\HTMLHelper;
use Joomla\CMS\Plugin\PluginHelper;
use Joomla\Module\TableDump\Site\Helper\TableDumpHelper;

$tablehtml = TableDumpHelper::getTableDump($params);

if ($params->def('prepare_content', 1)) {
PluginHelper::importPlugin('content');
$module->content = HTMLHelper::_('content.prepare', $module->content, '', 'mod_custom.content');
}

require ModuleHelper::getLayoutPath('mod_tabledump', $params->get('layout', 'default'));
141 changes: 141 additions & 0 deletions j4/mod_tabledump.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,141 @@
<?xml version="1.0" encoding="utf-8"?>
<extension type="module" version="4.0" client="site" method="upgrade">
<name>Table Dump</name>
<author>Bruce Scherzinger</author>
<version>2.0</version>
<description>Extracts rows of data from the database and replaces field data in an HTML table structure. A special tag {tablerows} can be placed in either the header or footer and is replaced by the total rows returned by the query.</description>
<namespace path="src">Joomla\Module\TableDump</namespace>
<files>
<filename module="mod_tabledump">mod_tabledump.php</filename>
<folder>src</folder>
<folder>tmpl</folder>
</files>
<config>
<fields name="params">
<fieldset name="basic">
<field
name="prepare_content"
type="radio"
label="Prepare Content:"
description="Optionally prepare the content with the Joomla content plugins. This applies to all HTML; header, rows, and footer."
class="btn-group btn-group-yesno"
default="0"
>
<option value="1">JYES</option>
<option value="0">JNO</option>
</field>
<field
name="hard_spaces"
type="radio"
label="Hard Spaces:"
description="Optionally replace all spaces, hyphens, and newlines with non-breaking HTML entities. This applies only to data in rows."
class="btn-group btn-group-yesno"
default="0"
>
<option value="1">JYES</option>
<option value="0">JNO</option>
</field>
</fieldset>
<fieldset name="query" label="Query">
<field
name="fieldnames"
description="Enter the field names to be returned from your query separated by whitespace."
type="editor"
editor="None"
height="60"
width="800"
default=""
label="Field Names:" />
<field
name="tablequery"
description="MySQL query that returns fields with the names provided above. Query can return multiple rows."
type="editor"
editor="None"
height="200"
width="800"
default=""
label="MySQL Query:" />
<field
name="errormessage"
description="HTML to output if the query returns nothing."
type="editor"
editor="None"
height="40"
width="800"
default=""
filter="raw"
label="Error Message:" />
</fieldset>
<fieldset name="headfoot" label="Head/Foot/Group">
<field
name="tableprefix"
description="HTML code for your table prefix. Do not use field names in this section as they will not be replaced. Defaults to plain table."
type="editor"
editor="None"
height="50"
width="1000"
default=""
filter="raw"
label="Table Prefix HTML:" />
<field
name="tablehead"
description="HTML code for the actual first row of your table. Do not use field names in this section as they will not be replaced."
type="editor"
editor="None"
height="200"
width="1000"
default=""
filter="raw"
label="Table Heading HTML:" />
<field
name="groupby"
description="Optional column name for grouping. If left empty, no group sub-headers will appear. Must be a single column name."
type="text"
editor="None"
width="100"
default=""
filter="raw"
label="Group By:" />
<field
name="grouphead"
description="HTML code optionally containing placeholders for your group heading. You can use field names in this section."
type="editor"
editor="None"
height="200"
width="1000"
default=""
filter="raw"
label="Group Heading HTML:" />
<field
name="tablefoot"
description="Optional HTML code containing placeholders for your table heading. Do not use field names in this section as they will not be replaced. If left empty, a basic table terminator will be added for you."
type="editor"
editor="None"
height="80"
width="1000"
default=""
filter="raw"
label="Table Ending HTML:" />
</fieldset>
<fieldset name="rows" label="Rows">
<field
name="tablerow"
description="HTML code containing field names for your table data. This section will be used to format each row of data fetched from your table."
type="editor"
editor="None"
height="300"
width="1000"
default=""
filter="raw"
label="Table Row HTML:" />
</fieldset>
</fields>
</config>
<install>
</install>
<uninstall>
</uninstall>
<updateservers>
<server type="extension" name="Table Dump Module Update Site">https://raw.githubusercontent.com/bascherz/Table-Dump-Module/master/manifest.xml</server>
</updateservers>
</extension>
111 changes: 111 additions & 0 deletions j4/src/Helper/TableDumpHelper.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
<?php
/**
* Helper class for Table Dump module
*
* @package Table Dump
* @subpackage Modules
* @link http://docs.joomla.org/J3.x:Creating_a_simple_module/Developing_a_Basic_Module
* @license GNU/GPL, see LICENSE.php
* mod_tabledump is free software. This version may have been modified pursuant
* to the GNU General Public License, and as distributed it includes or
* is derivative of works licensed under the GNU General Public License or
* other free or open source software licenses.
*/
namespace Joomla\Module\TableDump\Site\Helper;

use Joomla\CMS\Application\CMSApplication;
use Joomla\CMS\Factory;
use Joomla\CMS\HTML\HTMLHelper;
use Joomla\CMS\Language\Multilanguage;
use Joomla\CMS\Language\Text;
use Joomla\Registry\Registry;

class TableDumpHelper
{
/**
* Retrieves one row of record column data and outputs a table with the column data filled into the user template
*
* @param array $params An object containing the module parameters
*
* @access public
*/
public static function getTableDump($params)
{
// Obtain a database connection.
$db = Factory::getDbo();

// Retrieve the various parameters
$fieldnames = explode(",",preg_replace("/\s+/",",",$params->get('fieldnames')));
$tablequery = $params->get('tablequery');
$errormessage = $params->get('errormessage');
$tableprefix = $params->get('tableprefix','<table>');
$tablehead = $params->get('tablehead');
$tablerow = $params->get('tablerow');
$tablefoot = $params->get('tablefoot','</tbody></table>');
$hardspaces = $params->get('hard_spaces');
$groupby = trim($params->get('groupby'));
$grouphead = $params->get('grouphead');
$hard_spaces = $params->get('hard_spaces');

// Prepare the query
$db->setQuery($tablequery);

// Load the row.
try
{
$records = $db->loadObjectList();
}
catch (Exception $e)
{
$tablehtml = $errormessage;
}

// Replace tags in rows
$lastgroup = "";
$thisgrouphead = "";
if ($records)
{
// Iterate over every row in the database recordset returned.
foreach ($records as $record)
{
// See if we need a group header and if it's time to output one.
if ($groupby)
{
$thisgroup = $record->$groupby;
$thisgrouphead = "";
if ($thisgroup != $lastgroup)
{
if ($hard_spaces)
$thisgrouphard = html_entity_decode(str_replace(array(" ","-","\n"),array("&nbsp;","&#8209;","<br/>"),$thisgroup),ENT_QUOTES);
else
$thisgrouphard = $thisgroup;

$thisgrouphead = html_entity_decode(str_replace("{".$groupby."}",$thisgrouphard,$grouphead),ENT_QUOTES);
}
$lastgroup = $thisgroup;
}

// Get the HTML for the next row ready.
$thisrow = $tablerow;

// Go through the list of field names and replace each {fieldname} in the user-provided HTML for this row.
foreach ($fieldnames as $fieldname)
{
$fielddata = $record->$fieldname;
if ($hard_spaces) $fielddata = html_entity_decode(str_replace(array(" ","-","\n"),array("&nbsp;","&#8209;","<br/>"),$fielddata),ENT_QUOTES);
$thisrow = html_entity_decode(str_replace("{".$fieldname."}",$fielddata,$thisrow),ENT_QUOTES);
}
// Add the processed row to the growing structure.
$tablehtml .= $thisgrouphead.$thisrow;
}
}
// Replace the special tags.
if (!$groupby)
$tableprefix = html_entity_decode(str_replace("{tablerows}",count($records),$tableprefix),ENT_QUOTES);
$tablefoot = html_entity_decode(str_replace("{tablerows}",count($records),$tablefoot),ENT_QUOTES);

// Return the table with all fieldname substitutions made and footer appended.
return $tableprefix.$tablehead.$tablehtml.($tablefoot ? $tablefoot : "</tbody></table>");
}
}
?>
6 changes: 6 additions & 0 deletions j4/tmpl/default.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<?php
// No direct access
defined('_JEXEC') or die;

echo $tablehtml;
?>
1 change: 1 addition & 0 deletions j4/tmpl/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<html><body bgcolor="#FFFFFF"></body></html>

0 comments on commit 07e5efb

Please sign in to comment.