From 49fe68b0ebbfb0199e5a46cdef28224d3c90eadb Mon Sep 17 00:00:00 2001 From: Bruce Scherzinger <16126098+bascherz@users.noreply.github.com> Date: Sun, 30 Oct 2022 17:36:50 -0400 Subject: [PATCH] Add files via upload Removed the dependence on Regular Labs Sourcerer. --- j4/manifest.xml | 4 +-- j4/mod_tabledump.xml | 5 +-- j4/src/Helper/TableDumpHelper.php | 53 +++++++++++++++++++++++++++---- 3 files changed, 52 insertions(+), 10 deletions(-) diff --git a/j4/manifest.xml b/j4/manifest.xml index 509a4f4..1518f5c 100644 --- a/j4/manifest.xml +++ b/j4/manifest.xml @@ -9,8 +9,8 @@ site https://github.com/bascherz/Table-Dump-Module/releases/tag/2.0 - https://github.com/bascherz/Table-Dump-Module/releases/download/2.0/mod_tabledump_2.0.zip + https://github.com/bascherz/Table-Dump-Module/releases/download/j4/mod_tabledump_2.0.zip - + \ No newline at end of file diff --git a/j4/mod_tabledump.xml b/j4/mod_tabledump.xml index 8fa3815..ed00dc3 100644 --- a/j4/mod_tabledump.xml +++ b/j4/mod_tabledump.xml @@ -2,6 +2,7 @@ Table Dump Bruce Scherzinger + 2022-10-23 2.0 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. Joomla\Module\TableDump @@ -136,6 +137,6 @@ - https://raw.githubusercontent.com/bascherz/Table-Dump-Module/master/j4/manifest.xml + https://raw.githubusercontent.com/bascherz/Table-Dump-Module/master/manifest.xml - + \ No newline at end of file diff --git a/j4/src/Helper/TableDumpHelper.php b/j4/src/Helper/TableDumpHelper.php index 43703c5..bff6191 100644 --- a/j4/src/Helper/TableDumpHelper.php +++ b/j4/src/Helper/TableDumpHelper.php @@ -13,15 +13,49 @@ */ 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 { + /* + * $html = string containing PHP code between two delimiters. code is expected to produce output. + * $start = the starting delimiter + * $stop = the ending delimiter + * $count = code strings to replace (0=all) + * returns $html with strings generated by + */ + public static function executePHP($html,$start="{php}",$stop="{/php}",$count=0) + { + // Repeat the following until no more $start delimiters are found. + $done = false; + while (!$done) + { + $locStart = strpos($html,$start); + if ($locStart === false) + { + // starting delimiter not found. we are done. + $done = true; + } + else + { + // found a starting delimiter. now look for the ending one. + $locStop = strpos($html,$stop); + if ($locStop === false || $locStop < $locStart) + { + // ending delimiter not found. we are done. should report an error, but something else will. + $done = true; + } + else + { + $phpstring = substr($html,$locStart,($locStop+strlen($stop))-$locStart); + $myPHP = str_replace(array($start,$stop),"",$phpstring); + $output = eval($myPHP); + $html = str_replace($phpstring,$output,$html); + } + } + } + return $html; + } /** * Retrieves one row of record column data and outputs a table with the column data filled into the user template * @@ -35,7 +69,7 @@ public static function getTableDump($params) $db = Factory::getDbo(); // Retrieve the various parameters - $fieldnames = explode(",",preg_replace("/\s+/",",",$params->get('fieldnames'))); + $fieldnames = explode(",",preg_replace("/\,+/",",",preg_replace("/\s+/",",",$params->get('fieldnames')))); $tablequery = $params->get('tablequery'); $errormessage = $params->get('errormessage'); $tableprefix = $params->get('tableprefix',''); @@ -54,6 +88,7 @@ public static function getTableDump($params) try { $records = $db->loadObjectList(); + $tablehtml = ""; } catch (Exception $e) { @@ -99,6 +134,12 @@ public static function getTableDump($params) $tablehtml .= $thisgrouphead.$thisrow; } } + // Execute any embedded PHP code. + if ($params->get('prepare_content')) + { + $tablehtml = TableDumpHelper::executePHP($tablehtml); + } + // Replace the special tags. if (!$groupby) $tableprefix = html_entity_decode(str_replace("{tablerows}",count($records),$tableprefix),ENT_QUOTES);