Release of v4.0.0-alpha8
Add power path override option on component level. Fix the sql build feature. #1032.
This commit is contained in:
@@ -0,0 +1,123 @@
|
||||
<?php
|
||||
/**
|
||||
* @package Joomla.Component.Builder
|
||||
*
|
||||
* @created 4th September, 2022
|
||||
* @author Llewellyn van der Merwe <https://dev.vdm.io>
|
||||
* @git Joomla Component Builder <https://git.vdm.dev/joomla/Component-Builder>
|
||||
* @copyright Copyright (C) 2015 Vast Development Method. All rights reserved.
|
||||
* @license GNU General Public License version 2 or later; see LICENSE.txt
|
||||
*/
|
||||
|
||||
namespace VDM\Joomla\Componentbuilder\Search\Abstraction;
|
||||
|
||||
|
||||
use VDM\Joomla\Componentbuilder\Search\Factory;
|
||||
use VDM\Joomla\Componentbuilder\Search\Config;
|
||||
|
||||
|
||||
/**
|
||||
* Search Engine
|
||||
*
|
||||
* @since 3.2.0
|
||||
*/
|
||||
abstract class Engine
|
||||
{
|
||||
/**
|
||||
* Search Config
|
||||
*
|
||||
* @var Config
|
||||
* @since 3.2.0
|
||||
*/
|
||||
protected Config $config;
|
||||
|
||||
/**
|
||||
* Search Value
|
||||
*
|
||||
* @var string|null
|
||||
* @since 3.2.0
|
||||
*/
|
||||
protected ?string $searchValue;
|
||||
|
||||
/**
|
||||
* Replace Value
|
||||
*
|
||||
* @var string
|
||||
* @since 3.2.0
|
||||
*/
|
||||
protected string $replaceValue;
|
||||
|
||||
/**
|
||||
* Search Should Match Case
|
||||
*
|
||||
* @var int
|
||||
* @since 3.2.0
|
||||
*/
|
||||
protected int $matchCase = 0;
|
||||
|
||||
/**
|
||||
* Search Should Match Whole Word
|
||||
*
|
||||
* @var int
|
||||
* @since 3.2.0
|
||||
*/
|
||||
protected int $wholeWord = 0;
|
||||
|
||||
/**
|
||||
* Start marker
|
||||
*
|
||||
* @var string
|
||||
* @since 3.2.0
|
||||
*/
|
||||
protected string $start = '';
|
||||
|
||||
/**
|
||||
* End marker
|
||||
*
|
||||
* @var string
|
||||
* @since 3.2.0
|
||||
*/
|
||||
protected string $end = '';
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @param Config|null $config The search config object.
|
||||
*
|
||||
* @since 3.2.0
|
||||
*/
|
||||
public function __construct(?Config $config = null)
|
||||
{
|
||||
$this->config = $config ?: Factory::_('Config');
|
||||
|
||||
// set search value
|
||||
$this->searchValue = $this->config->search_value;
|
||||
|
||||
// set replace value
|
||||
$this->replaceValue = $this->config->replace_value;
|
||||
|
||||
// set match case
|
||||
$this->matchCase = $this->config->match_case;
|
||||
|
||||
// set whole word
|
||||
$this->wholeWord = $this->config->whole_word;
|
||||
|
||||
// set start marker
|
||||
$this->start = $this->config->marker_start;
|
||||
|
||||
// set end marker
|
||||
$this->end = $this->config->marker_end;
|
||||
}
|
||||
|
||||
/**
|
||||
* we count every line being searched
|
||||
*
|
||||
* @since 3.2.0
|
||||
*/
|
||||
protected function lineCounter()
|
||||
{
|
||||
// we count every line we search
|
||||
$this->config->line_counter += 1;
|
||||
}
|
||||
}
|
||||
|
@@ -0,0 +1 @@
|
||||
<html><body bgcolor="#FFFFFF"></body></html>
|
@@ -0,0 +1,425 @@
|
||||
<?php
|
||||
/**
|
||||
* @package Joomla.Component.Builder
|
||||
*
|
||||
* @created 4th September, 2022
|
||||
* @author Llewellyn van der Merwe <https://dev.vdm.io>
|
||||
* @git Joomla Component Builder <https://git.vdm.dev/joomla/Component-Builder>
|
||||
* @copyright Copyright (C) 2015 Vast Development Method. All rights reserved.
|
||||
* @license GNU General Public License version 2 or later; see LICENSE.txt
|
||||
*/
|
||||
|
||||
namespace VDM\Joomla\Componentbuilder\Search;
|
||||
|
||||
|
||||
use Joomla\CMS\Language\Text;
|
||||
use VDM\Joomla\Componentbuilder\Search\Factory;
|
||||
use VDM\Joomla\Componentbuilder\Search\Config;
|
||||
use VDM\Joomla\Componentbuilder\Search\Database\Load;
|
||||
use VDM\Joomla\Componentbuilder\Search\Database\Insert;
|
||||
use VDM\Joomla\Componentbuilder\Search\Agent\Find;
|
||||
use VDM\Joomla\Componentbuilder\Search\Agent\Replace;
|
||||
use VDM\Joomla\Componentbuilder\Search\Agent\Search;
|
||||
use VDM\Joomla\Componentbuilder\Search\Agent\Update;
|
||||
use VDM\Joomla\Componentbuilder\Table;
|
||||
|
||||
|
||||
/**
|
||||
* Search Agent
|
||||
*
|
||||
* @since 3.2.0
|
||||
*/
|
||||
class Agent
|
||||
{
|
||||
/**
|
||||
* Search Config
|
||||
*
|
||||
* @var Config
|
||||
* @since 3.2.0
|
||||
*/
|
||||
protected Config $config;
|
||||
|
||||
/**
|
||||
* Search Load Database
|
||||
*
|
||||
* @var Load
|
||||
* @since 3.2.0
|
||||
*/
|
||||
protected Load $load;
|
||||
|
||||
/**
|
||||
* Search Insert Database
|
||||
*
|
||||
* @var Insert
|
||||
* @since 3.2.0
|
||||
*/
|
||||
protected Insert $insert;
|
||||
|
||||
/**
|
||||
* Search Find
|
||||
*
|
||||
* @var Find
|
||||
* @since 3.2.0
|
||||
*/
|
||||
protected Find $find;
|
||||
|
||||
/**
|
||||
* Search Replace
|
||||
*
|
||||
* @var Replace
|
||||
* @since 3.2.0
|
||||
*/
|
||||
protected Replace $replace;
|
||||
|
||||
/**
|
||||
* Search
|
||||
*
|
||||
* @var Search
|
||||
* @since 3.2.0
|
||||
*/
|
||||
protected Search $search;
|
||||
|
||||
/**
|
||||
* Update
|
||||
*
|
||||
* @var Update
|
||||
* @since 3.2.0
|
||||
*/
|
||||
protected Update $update;
|
||||
|
||||
/**
|
||||
* Table
|
||||
*
|
||||
* @var Table
|
||||
* @since 3.2.0
|
||||
*/
|
||||
protected Table $table;
|
||||
|
||||
/**
|
||||
* Return value to search view
|
||||
*
|
||||
* @var string
|
||||
* @since 3.2.0
|
||||
*/
|
||||
protected string $return;
|
||||
|
||||
/**
|
||||
* Marker start and end values
|
||||
*
|
||||
* @var array
|
||||
* @since 3.2.0
|
||||
*/
|
||||
protected array $marker;
|
||||
|
||||
/**
|
||||
* Marker start and end html values
|
||||
*
|
||||
* @var array
|
||||
* @since 3.2.0
|
||||
*/
|
||||
protected array $markerHtml;
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @param Config|null $config The search config object.
|
||||
* @param Load|null $load The search load database object.
|
||||
* @param Insert|null $insert The search insert database object.
|
||||
* @param Find|null $find The search find object.
|
||||
* @param Replace|null $replace The search replace object.
|
||||
* @param Search|null $search The search object.
|
||||
* @param Update|null $update The update object.
|
||||
* @param Table|null $table The table object.
|
||||
*
|
||||
* @since 3.2.0
|
||||
*/
|
||||
public function __construct(?Config $config = null, ?Load $load = null,
|
||||
?Insert $insert = null, ?Find $find = null, ?Replace $replace = null,
|
||||
?Search $search = null, ?Update $update = null, ?Table $table = null)
|
||||
{
|
||||
$this->config = $config ?: Factory::_('Config');
|
||||
$this->load = $load ?: Factory::_('Load.Database');
|
||||
$this->insert = $insert ?: Factory::_('Insert.Database');
|
||||
$this->find = $find ?: Factory::_('Agent.Find');
|
||||
$this->replace = $replace ?: Factory::_('Agent.Replace');
|
||||
$this->search = $search ?: Factory::_('Agent.Search');
|
||||
$this->update = $update ?: Factory::_('Agent.Update');
|
||||
$this->table = $table ?: Factory::_('Table');
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the value of a field in a row and table
|
||||
*
|
||||
* @param int $id The item ID
|
||||
* @param string $field The field key
|
||||
* @param mixed $line The field line
|
||||
* @param string|null $table The table
|
||||
* @param bool $update The switch to triger an update (default is false)
|
||||
*
|
||||
* @return string|null
|
||||
* @since 3.2.0
|
||||
*/
|
||||
public function getValue(int $id, string $field, $line = null,
|
||||
?string $table = null, bool $update = false): ?string
|
||||
{
|
||||
// set the table name
|
||||
if (empty($table))
|
||||
{
|
||||
$table = $this->config->table_name;
|
||||
}
|
||||
|
||||
if (($value = $this->load->value($id, $field, $table)) !== null)
|
||||
{
|
||||
// we only return strings that can load in an editor
|
||||
if (is_string($value))
|
||||
{
|
||||
// try to update the value if required
|
||||
if ($update && ($updated_value = $this->update->value($value, $line)) !== null)
|
||||
{
|
||||
return $updated_value;
|
||||
}
|
||||
|
||||
return $value;
|
||||
}
|
||||
|
||||
return '// VALUE CAN NOT BE LOADED (AT THIS TIME) SINCE ITS NOT A STRING';
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the value of a field in a row and table
|
||||
*
|
||||
* @param mixed $value The field value
|
||||
* @param int $id The item ID
|
||||
* @param string $field The field key
|
||||
* @param string|null $table The table
|
||||
*
|
||||
* @return bool
|
||||
* @since 3.2.0
|
||||
*/
|
||||
public function setValue($value, int $id, string $field, ?string $table = null): bool
|
||||
{
|
||||
// set the table name
|
||||
if (empty($table))
|
||||
{
|
||||
$table = $this->config->table_name;
|
||||
}
|
||||
|
||||
return $this->insert->value($value, $id, $field, $table);
|
||||
}
|
||||
|
||||
/**
|
||||
* Return Table Ready Search Results
|
||||
*
|
||||
* @param string|null $table The table being searched
|
||||
*
|
||||
* @return array|null
|
||||
* @since 3.2.0
|
||||
*/
|
||||
public function table(?string $table = null): ?array
|
||||
{
|
||||
// set the table name
|
||||
if (empty($table))
|
||||
{
|
||||
$table = $this->config->table_name;
|
||||
}
|
||||
|
||||
if(($values = $this->find($table)) !== null)
|
||||
{
|
||||
// build return value
|
||||
$this->setReturnValue();
|
||||
|
||||
// set the markers
|
||||
$this->setMarkers();
|
||||
|
||||
// start table bucket
|
||||
$table_rows = [];
|
||||
|
||||
foreach ($values as $id => $fields)
|
||||
{
|
||||
foreach ($fields as $field => $lines)
|
||||
{
|
||||
foreach ($lines as $line => $code)
|
||||
{
|
||||
$table_rows[] = $this->getRow($code, $table, $field, $id, $line);
|
||||
}
|
||||
}
|
||||
}
|
||||
return $table_rows;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Search the posted table for the search value and return all
|
||||
*
|
||||
* @param string|null $table The table being searched
|
||||
*
|
||||
* @return array|null
|
||||
* @since 3.2.0
|
||||
*/
|
||||
public function find(?string $table = null): ?array
|
||||
{
|
||||
// set the table name
|
||||
if (empty($table))
|
||||
{
|
||||
$table = $this->config->table_name;
|
||||
}
|
||||
|
||||
$set = 1;
|
||||
|
||||
// continue loading items until all are searched
|
||||
while(($items = $this->load->items($table, $set)) !== null)
|
||||
{
|
||||
$this->find->items($items, $table);
|
||||
$set++;
|
||||
}
|
||||
|
||||
return $this->search->get($table);
|
||||
}
|
||||
|
||||
/**
|
||||
* Search the posted table for the search value, and replace all
|
||||
*
|
||||
* @param string|null $table The table being searched
|
||||
*
|
||||
* @return int
|
||||
* @since 3.2.0
|
||||
*/
|
||||
public function replace(?string $table = null): int
|
||||
{
|
||||
// set the table name
|
||||
if (empty($table))
|
||||
{
|
||||
$table = $this->config->table_name;
|
||||
}
|
||||
|
||||
$set = 1;
|
||||
$replaced = 0;
|
||||
|
||||
// continue loading items until all was loaded
|
||||
while(($items = $this->load->items($table, $set)) !== null)
|
||||
{
|
||||
// search for items
|
||||
$this->find->items($items, $table);
|
||||
|
||||
// update those found
|
||||
$this->replace->items($this->find->get($table), $table);
|
||||
|
||||
// update the database
|
||||
if ($this->insert->items($this->replace->get($table), $table))
|
||||
{
|
||||
$replaced++;
|
||||
}
|
||||
|
||||
// reset found items
|
||||
$this->find->reset($table);
|
||||
$this->replace->reset($table);
|
||||
|
||||
$set++;
|
||||
}
|
||||
|
||||
// we return the number of times we replaced
|
||||
return $replaced;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return prepared code string for table
|
||||
*
|
||||
* @param string $code The code value fro the table
|
||||
* @param string|null $table The table
|
||||
* @param string $field The field key
|
||||
* @param int $id The the row id
|
||||
* @param mixed $line The code line where found
|
||||
*
|
||||
* @return array
|
||||
* @since 3.2.0
|
||||
*/
|
||||
protected function getRow(string $code, string $table, string $field, int $id, $line): array
|
||||
{
|
||||
return [
|
||||
'edit' => $this->getRowEditButton($table, $field, $id, $line),
|
||||
'code' => $this->getRowCode($code),
|
||||
'table' => $table,
|
||||
'field' => $field,
|
||||
'id' => $id,
|
||||
'line' => $line
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Return prepared code string for table
|
||||
*
|
||||
* @param string $code The code value fro the table
|
||||
*
|
||||
* @return string
|
||||
* @since 3.2.0
|
||||
*/
|
||||
protected function getRowCode(string $code): string
|
||||
{
|
||||
return str_replace($this->marker, $this->markerHtml, htmlentities($code));
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the Item button to edit an item
|
||||
*
|
||||
* @param string|null $view The single view
|
||||
* @param string $field The field key
|
||||
* @param int $id The the row id
|
||||
* @param mixed $line The code line where found
|
||||
*
|
||||
* @return string
|
||||
* @since 3.2.0
|
||||
*/
|
||||
protected function getRowEditButton(string $view, string $field, int $id, $line): string
|
||||
{
|
||||
// get list view
|
||||
$views = $this->table->get($view, $field, 'list');
|
||||
$tab = $this->table->get($view, $field, 'tab_name');
|
||||
|
||||
// return edit link
|
||||
return '<a class="hasTooltip btn btn-mini" href="index.php?option=com_componentbuilder' .
|
||||
'&view=' . $views .
|
||||
'&task=' . $view . '.edit' .
|
||||
'&id=' . $id .
|
||||
'&open_tab=' . $tab .
|
||||
'&open_field=' . $field .
|
||||
'&return=' . $this->return . '" title="' .
|
||||
Text::sprintf('COM_COMPONENTBUILDER_EDIT_S_S_DIRECTLY', $view, $field) . '." ><span class="icon-edit"></span></a>';
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the return value for this search
|
||||
*
|
||||
* @return void
|
||||
* @since 3.2.0
|
||||
*/
|
||||
protected function setReturnValue()
|
||||
{
|
||||
// set the return value so the search auto load on return
|
||||
$this->return = urlencode(base64_encode('index.php?option=com_componentbuilder&view=search' .
|
||||
'&type_search=' . (int) $this->config->type_search .
|
||||
'&match_case=' . (int) $this->config->match_case .
|
||||
'&whole_word=' . (int) $this->config->whole_word .
|
||||
'®ex_search=' . (int) $this->config->regex_search .
|
||||
'&search_value=' . (string) urlencode((string) $this->config->search_value) .
|
||||
'&replace_value=' . (string) urlencode((string) $this->config->replace_value)));
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the markers of the found code
|
||||
*
|
||||
* @return void
|
||||
* @since 3.2.0
|
||||
*/
|
||||
protected function setMarkers()
|
||||
{
|
||||
// set the markers
|
||||
$this->marker = [$this->config->marker_start, $this->config->marker_end];
|
||||
$this->markerHtml = ['<span class="found_code">','</span>'];
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -0,0 +1,180 @@
|
||||
<?php
|
||||
/**
|
||||
* @package Joomla.Component.Builder
|
||||
*
|
||||
* @created 4th September, 2022
|
||||
* @author Llewellyn van der Merwe <https://dev.vdm.io>
|
||||
* @git Joomla Component Builder <https://git.vdm.dev/joomla/Component-Builder>
|
||||
* @copyright Copyright (C) 2015 Vast Development Method. All rights reserved.
|
||||
* @license GNU General Public License version 2 or later; see LICENSE.txt
|
||||
*/
|
||||
|
||||
namespace VDM\Joomla\Componentbuilder\Search\Agent;
|
||||
|
||||
|
||||
use VDM\Joomla\Utilities\ArrayHelper;
|
||||
use VDM\Joomla\Utilities\ObjectHelper;
|
||||
use VDM\Joomla\Componentbuilder\Search\Factory;
|
||||
use VDM\Joomla\Componentbuilder\Search\Config;
|
||||
use VDM\Joomla\Componentbuilder\Search\Agent\Search;
|
||||
use VDM\Joomla\Componentbuilder\Search\Interfaces\FindInterface;
|
||||
|
||||
|
||||
/**
|
||||
* Search Agent Find
|
||||
*
|
||||
* @since 3.2.0
|
||||
*/
|
||||
class Find implements FindInterface
|
||||
{
|
||||
/**
|
||||
* Found Values
|
||||
*
|
||||
* @var array
|
||||
* @since 3.2.0
|
||||
*/
|
||||
protected array $found = [];
|
||||
|
||||
/**
|
||||
* Search Config
|
||||
*
|
||||
* @var Config
|
||||
* @since 3.2.0
|
||||
*/
|
||||
protected Config $config;
|
||||
|
||||
/**
|
||||
* Search
|
||||
*
|
||||
* @var Search
|
||||
* @since 3.2.0
|
||||
*/
|
||||
protected Search $search;
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @param Config|null $config The search config object.
|
||||
* @param Search|null $search The search object.
|
||||
*
|
||||
* @since 3.2.0
|
||||
*/
|
||||
public function __construct(?Config $config = null, ?Search $search = null)
|
||||
{
|
||||
$this->config = $config ?: Factory::_('Config');
|
||||
$this->search = $search ?: Factory::_('Agent.Search');
|
||||
}
|
||||
|
||||
/**
|
||||
* Get found values
|
||||
*
|
||||
* @param string|null $table The table being searched
|
||||
*
|
||||
* @return array|null
|
||||
* @since 3.2.0
|
||||
*/
|
||||
public function get(?string $table = null): ?array
|
||||
{
|
||||
// set the table name
|
||||
if (empty($table))
|
||||
{
|
||||
$table = $this->config->table_name;
|
||||
}
|
||||
|
||||
if (isset($this->found[$table]))
|
||||
{
|
||||
return $this->found[$table];
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Search over an item fields
|
||||
*
|
||||
* @param object $item The item object of fields to search through
|
||||
* @param int|null $id The item id
|
||||
* @param string|null $table The table being searched
|
||||
*
|
||||
* @return void
|
||||
* @since 3.2.0
|
||||
*/
|
||||
public function item(object $item, ?int $id =null, ?string $table = null)
|
||||
{
|
||||
// set the table name
|
||||
if (empty($table))
|
||||
{
|
||||
$table = $this->config->table_name;
|
||||
}
|
||||
|
||||
// set the item id
|
||||
if (empty($id))
|
||||
{
|
||||
$id = $item->id;
|
||||
}
|
||||
|
||||
if (ObjectHelper::check($item))
|
||||
{
|
||||
foreach ($item as $field => $value)
|
||||
{
|
||||
if ($field !== 'id' && $this->search->value($value, $id, $field, $table))
|
||||
{
|
||||
if (empty($this->found[$table][$id]))
|
||||
{
|
||||
$this->found[$table][$id] = new \stdClass();
|
||||
$this->found[$table][$id]->id = $id;
|
||||
}
|
||||
$this->found[$table][$id]->{$field} = $value;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Search over an array of items
|
||||
*
|
||||
* @param array|null $items The array of items to search through
|
||||
* @param string|null $table The table being searched
|
||||
*
|
||||
* @return void
|
||||
* @since 3.2.0
|
||||
*/
|
||||
public function items(?array $items = null, ?string $table = null)
|
||||
{
|
||||
// set the table name
|
||||
if (empty($table))
|
||||
{
|
||||
$table = $this->config->table_name;
|
||||
}
|
||||
|
||||
if (ArrayHelper::check($items))
|
||||
{
|
||||
foreach ($items as $id => $item)
|
||||
{
|
||||
$this->item($item, $id, $table);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Reset all found values of a table
|
||||
*
|
||||
* @param string|null $table The table being searched
|
||||
*
|
||||
* @return void
|
||||
* @since 3.2.0
|
||||
*/
|
||||
public function reset(?string $table = null)
|
||||
{
|
||||
// set the table name
|
||||
if (empty($table))
|
||||
{
|
||||
$table = $this->config->table_name;
|
||||
}
|
||||
|
||||
// empty or unset the table active values
|
||||
unset($this->found[$table]);
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -0,0 +1,181 @@
|
||||
<?php
|
||||
/**
|
||||
* @package Joomla.Component.Builder
|
||||
*
|
||||
* @created 4th September, 2022
|
||||
* @author Llewellyn van der Merwe <https://dev.vdm.io>
|
||||
* @git Joomla Component Builder <https://git.vdm.dev/joomla/Component-Builder>
|
||||
* @copyright Copyright (C) 2015 Vast Development Method. All rights reserved.
|
||||
* @license GNU General Public License version 2 or later; see LICENSE.txt
|
||||
*/
|
||||
|
||||
namespace VDM\Joomla\Componentbuilder\Search\Agent;
|
||||
|
||||
|
||||
use VDM\Joomla\Utilities\ArrayHelper;
|
||||
use VDM\Joomla\Utilities\ObjectHelper;
|
||||
use VDM\Joomla\Componentbuilder\Search\Factory;
|
||||
use VDM\Joomla\Componentbuilder\Search\Config;
|
||||
use VDM\Joomla\Componentbuilder\Search\Agent\Update;
|
||||
use VDM\Joomla\Componentbuilder\Search\Interfaces\ReplaceInterface;
|
||||
|
||||
|
||||
/**
|
||||
* Search Agent Replace
|
||||
*
|
||||
* @since 3.2.0
|
||||
*/
|
||||
class Replace implements ReplaceInterface
|
||||
{
|
||||
/**
|
||||
* Updated Values
|
||||
*
|
||||
* @var array
|
||||
* @since 3.2.0
|
||||
*/
|
||||
protected array $updated = [];
|
||||
|
||||
/**
|
||||
* Search Config
|
||||
*
|
||||
* @var Config
|
||||
* @since 3.2.0
|
||||
*/
|
||||
protected Config $config;
|
||||
|
||||
/**
|
||||
* Update
|
||||
*
|
||||
* @var Update
|
||||
* @since 3.2.0
|
||||
*/
|
||||
protected Update $update;
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @param Config|null $config The search config object.
|
||||
* @param Update|null $update The update object.
|
||||
*
|
||||
* @since 3.2.0
|
||||
*/
|
||||
public function __construct(?Config $config = null, ?Update $update = null)
|
||||
{
|
||||
$this->config = $config ?: Factory::_('Config');
|
||||
$this->update = $update ?: Factory::_('Agent.Update');
|
||||
}
|
||||
|
||||
/**
|
||||
* Get updated values
|
||||
*
|
||||
* @param string|null $table The table being searched
|
||||
*
|
||||
* @return array|null
|
||||
* @since 3.2.0
|
||||
*/
|
||||
public function get(?string $table = null): ?array
|
||||
{
|
||||
// set the table name
|
||||
if (empty($table))
|
||||
{
|
||||
$table = $this->config->table_name;
|
||||
}
|
||||
|
||||
if (isset($this->updated[$table]))
|
||||
{
|
||||
return $this->updated[$table];
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Search over an item fields
|
||||
*
|
||||
* @param object $item The item object of fields to search through
|
||||
* @param int|null $id The item id
|
||||
* @param string|null $table The table being searched
|
||||
*
|
||||
* @return void
|
||||
* @since 3.2.0
|
||||
*/
|
||||
public function item(object $item, ?int $id =null, ?string $table = null)
|
||||
{
|
||||
// set the table name
|
||||
if (empty($table))
|
||||
{
|
||||
$table = $this->config->table_name;
|
||||
}
|
||||
|
||||
// set the item id
|
||||
if (empty($id))
|
||||
{
|
||||
$id = $item->id;
|
||||
}
|
||||
|
||||
if (ObjectHelper::check($item))
|
||||
{
|
||||
foreach ($item as $field => $value)
|
||||
{
|
||||
if ($field !== 'id' && ($_value = $this->update->value($value)) !== null)
|
||||
{
|
||||
if (empty($this->updated[$table][$id]))
|
||||
{
|
||||
$this->updated[$table][$id] = new \stdClass();
|
||||
$this->updated[$table][$id]->id = $id;
|
||||
}
|
||||
// add updated value
|
||||
$this->updated[$table][$id]->{$field} = $_value;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Search over an array of items
|
||||
*
|
||||
* @param array|null $items The array of items to search through
|
||||
* @param string|null $table The table being searched
|
||||
*
|
||||
* @return void
|
||||
* @since 3.2.0
|
||||
*/
|
||||
public function items(?array $items = null, ?string $table = null)
|
||||
{
|
||||
// set the table name
|
||||
if (empty($table))
|
||||
{
|
||||
$table = $this->config->table_name;
|
||||
}
|
||||
|
||||
if (ArrayHelper::check($items))
|
||||
{
|
||||
foreach ($items as $id => $item)
|
||||
{
|
||||
$this->item($item, $id, $table);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Reset all updated values of a table
|
||||
*
|
||||
* @param string|null $table The table being searched
|
||||
*
|
||||
* @return void
|
||||
* @since 3.2.0
|
||||
*/
|
||||
public function reset(?string $table = null)
|
||||
{
|
||||
// set the table name
|
||||
if (empty($table))
|
||||
{
|
||||
$table = $this->config->table_name;
|
||||
}
|
||||
|
||||
// empty or unset the table active values
|
||||
unset($this->updated[$table]);
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -0,0 +1,302 @@
|
||||
<?php
|
||||
/**
|
||||
* @package Joomla.Component.Builder
|
||||
*
|
||||
* @created 4th September, 2022
|
||||
* @author Llewellyn van der Merwe <https://dev.vdm.io>
|
||||
* @git Joomla Component Builder <https://git.vdm.dev/joomla/Component-Builder>
|
||||
* @copyright Copyright (C) 2015 Vast Development Method. All rights reserved.
|
||||
* @license GNU General Public License version 2 or later; see LICENSE.txt
|
||||
*/
|
||||
|
||||
namespace VDM\Joomla\Componentbuilder\Search\Agent;
|
||||
|
||||
|
||||
use VDM\Joomla\Utilities\ArrayHelper;
|
||||
use VDM\Joomla\Utilities\StringHelper;
|
||||
use VDM\Joomla\Componentbuilder\Search\Factory;
|
||||
use VDM\Joomla\Componentbuilder\Search\Config;
|
||||
use VDM\Joomla\Componentbuilder\Search\Interfaces\SearchTypeInterface as SearchEngine;
|
||||
use VDM\Joomla\Componentbuilder\Search\Interfaces\SearchInterface;
|
||||
|
||||
|
||||
/**
|
||||
* Search Agent Search
|
||||
*
|
||||
* @since 3.2.0
|
||||
*/
|
||||
class Search implements SearchInterface
|
||||
{
|
||||
/**
|
||||
* Search results found
|
||||
*
|
||||
* @var array
|
||||
* @since 3.2.0
|
||||
*/
|
||||
protected array $found = [];
|
||||
|
||||
/**
|
||||
* Search Config
|
||||
*
|
||||
* @var Config
|
||||
* @since 3.2.0
|
||||
*/
|
||||
protected Config $config;
|
||||
|
||||
/**
|
||||
* Search Engine
|
||||
*
|
||||
* @var SearchEngine
|
||||
* @since 3.2.0
|
||||
*/
|
||||
protected SearchEngine $search;
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @param Config|null $config The search config object.
|
||||
* @param SearchEngine|null $search The search engine object.
|
||||
*
|
||||
* @since 3.2.0
|
||||
*/
|
||||
public function __construct(?Config $config = null, ?SearchEngine $search = null)
|
||||
{
|
||||
$this->config = $config ?: Factory::_('Config');
|
||||
$this->search = $search ?: Factory::_('Search');
|
||||
}
|
||||
|
||||
/**
|
||||
* Get found values
|
||||
*
|
||||
* @param string $table The table being searched
|
||||
*
|
||||
* @return array|null
|
||||
* @since 3.2.0
|
||||
*/
|
||||
public function get(string $table): ?array
|
||||
{
|
||||
if (isset($this->found[$table]))
|
||||
{
|
||||
return $this->found[$table];
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Search inside a value
|
||||
*
|
||||
* @param mixed $value The field value
|
||||
* @param int $id The item ID
|
||||
* @param string $field The field key
|
||||
* @param string $table The table
|
||||
*
|
||||
* @return bool
|
||||
* @since 3.2.0
|
||||
*/
|
||||
public function value($value, int $id, string $field, string $table): bool
|
||||
{
|
||||
// search the mixed value
|
||||
$found = $this->searchValue($value);
|
||||
|
||||
// check if we found any match
|
||||
if (ArrayHelper::check($found))
|
||||
{
|
||||
foreach ($found as $line => $line_value)
|
||||
{
|
||||
// may not be needed... but being old school
|
||||
$this->prep($id, $field, $table);
|
||||
|
||||
// load the detail into our multidimensional array... lol
|
||||
// Table->Item_id->Field_name->Line_number = marked_full_line
|
||||
// Search Example: soon...
|
||||
// Marked Line Example: Soon....
|
||||
$this->found[$table][$id][$field][$line] = $line_value;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Empty the found values
|
||||
*
|
||||
* @param string $table The table being searched
|
||||
*
|
||||
* @return void
|
||||
* @since 3.2.0
|
||||
*/
|
||||
public function reset(string $table)
|
||||
{
|
||||
unset($this->found[$table]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Search inside a string
|
||||
*
|
||||
* @param mixed $value The field value
|
||||
*
|
||||
* @return array|null
|
||||
* @since 3.2.0
|
||||
*/
|
||||
protected function searchValue($value): ?array
|
||||
{
|
||||
// check if this is an array
|
||||
$found = null;
|
||||
|
||||
// I know this is a little crazy... TODO refactor into recursion functions
|
||||
// the possibility of searching sub-forms in sub-forms
|
||||
if (ArrayHelper::check($value))
|
||||
{
|
||||
// first layer
|
||||
foreach ($value as $keys => $rows)
|
||||
{
|
||||
if (ArrayHelper::check($rows))
|
||||
{
|
||||
// second layer
|
||||
foreach ($rows as $key => $row)
|
||||
{
|
||||
if (ArrayHelper::check($row))
|
||||
{
|
||||
// third layer
|
||||
foreach ($row as $ke => $ro)
|
||||
{
|
||||
if (ArrayHelper::check($ro))
|
||||
{
|
||||
// forth layer
|
||||
foreach ($ro as $k => $r)
|
||||
{
|
||||
if (StringHelper::check($r) && ($_found = $this->string($r)) !== null)
|
||||
{
|
||||
foreach ($_found as $_n => $_f)
|
||||
{
|
||||
$found[$keys . '.' . $key . '.' . $ke . '.' . $k . '.' . $_n] = $_f;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
elseif (StringHelper::check($ro) && ($_found = $this->string($ro)) !== null)
|
||||
{
|
||||
foreach ($_found as $_n => $_f)
|
||||
{
|
||||
$found[$keys. '.' . $key . '.' . $ke . '.' . $_n] = $_f;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
elseif (StringHelper::check($row) && ($_found = $this->string($row)) !== null)
|
||||
{
|
||||
foreach ($_found as $_n => $_f)
|
||||
{
|
||||
$found[$keys. '.' . $key . '.' . $_n] = $_f;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
elseif (StringHelper::check($rows) && ($_found = $this->string($rows)) !== null)
|
||||
{
|
||||
foreach ($_found as $_n => $_f)
|
||||
{
|
||||
$found[$keys. '.' . $_n] = $_f;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
elseif (StringHelper::check($value))
|
||||
{
|
||||
$found = $this->string($value);
|
||||
}
|
||||
|
||||
return $found;
|
||||
}
|
||||
|
||||
/**
|
||||
* Search inside a string
|
||||
*
|
||||
* @param string $value The field value
|
||||
*
|
||||
* @return array|null
|
||||
* @since 3.2.0
|
||||
*/
|
||||
protected function string(string $value): ?array
|
||||
{
|
||||
// line counter
|
||||
$line = 1;
|
||||
|
||||
// we count every field we search
|
||||
$this->fieldCounter();
|
||||
|
||||
// check if string has a new line
|
||||
if (\preg_match('/\R/', $value))
|
||||
{
|
||||
$search_array = \preg_split('/\R/', $value);
|
||||
|
||||
// start search bucket
|
||||
$found = [];
|
||||
|
||||
// loop over the lines
|
||||
foreach ($search_array as $line_value)
|
||||
{
|
||||
if (($_found = $this->search->string($line_value)) !== null)
|
||||
{
|
||||
$found[$line] = $_found;
|
||||
}
|
||||
|
||||
// next line
|
||||
$line++;
|
||||
}
|
||||
|
||||
if (ArrayHelper::check($found))
|
||||
{
|
||||
return $found;
|
||||
}
|
||||
}
|
||||
elseif (($found = $this->search->string($value)) !== null)
|
||||
{
|
||||
return [$line => $found];
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Prep the bucket
|
||||
*
|
||||
* @param int $id The item ID
|
||||
* @param string $field The field key
|
||||
* @param string $table The table
|
||||
*
|
||||
* @return void
|
||||
* @since 3.2.0
|
||||
*/
|
||||
protected function prep(int $id, string $field, string $table)
|
||||
{
|
||||
if (empty($this->found[$table]))
|
||||
{
|
||||
$this->found[$table] = [];
|
||||
}
|
||||
if (empty($this->found[$table][$id]))
|
||||
{
|
||||
$this->found[$table][$id] = [];
|
||||
}
|
||||
if (empty($this->found[$table][$id][$field]))
|
||||
{
|
||||
$this->found[$table][$id][$field] = [];
|
||||
}
|
||||
// we should add a call to get the item name if the table has a name field TODO
|
||||
}
|
||||
|
||||
/**
|
||||
* we count every field being searched
|
||||
*
|
||||
* @since 3.2.0
|
||||
*/
|
||||
protected function fieldCounter()
|
||||
{
|
||||
// we count every field we search
|
||||
$this->config->field_counter += 1;
|
||||
}
|
||||
}
|
||||
|
@@ -0,0 +1,236 @@
|
||||
<?php
|
||||
/**
|
||||
* @package Joomla.Component.Builder
|
||||
*
|
||||
* @created 4th September, 2022
|
||||
* @author Llewellyn van der Merwe <https://dev.vdm.io>
|
||||
* @git Joomla Component Builder <https://git.vdm.dev/joomla/Component-Builder>
|
||||
* @copyright Copyright (C) 2015 Vast Development Method. All rights reserved.
|
||||
* @license GNU General Public License version 2 or later; see LICENSE.txt
|
||||
*/
|
||||
|
||||
namespace VDM\Joomla\Componentbuilder\Search\Agent;
|
||||
|
||||
|
||||
use VDM\Joomla\Utilities\ArrayHelper;
|
||||
use VDM\Joomla\Utilities\StringHelper;
|
||||
use VDM\Joomla\Componentbuilder\Search\Factory;
|
||||
use VDM\Joomla\Componentbuilder\Search\Interfaces\SearchTypeInterface as SearchEngine;
|
||||
|
||||
|
||||
/**
|
||||
* Search Agent Update
|
||||
*
|
||||
* @since 3.2.0
|
||||
*/
|
||||
class Update
|
||||
{
|
||||
/**
|
||||
* Search Engine
|
||||
*
|
||||
* @var SearchEngine
|
||||
* @since 3.2.0
|
||||
*/
|
||||
protected SearchEngine $search;
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @param SearchEngine|null $search The search engine object.
|
||||
*
|
||||
* @since 3.2.0
|
||||
*/
|
||||
public function __construct(?SearchEngine $search = null)
|
||||
{
|
||||
$this->search = $search ?: Factory::_('Search');
|
||||
}
|
||||
|
||||
/**
|
||||
* Update the value
|
||||
*
|
||||
* @param mixed $value The field value
|
||||
* @param mixed $line The line to update (0 = all)
|
||||
*
|
||||
* @return mixed
|
||||
* @since 3.2.0
|
||||
*/
|
||||
public function value($value, $line = 0)
|
||||
{
|
||||
// update the value
|
||||
$update = $this->updateValue($value, $line);
|
||||
|
||||
// was anything updated
|
||||
if ($value === $update)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
return $update;
|
||||
}
|
||||
|
||||
/**
|
||||
* Update all search-replace instances inside a value
|
||||
*
|
||||
* @param mixed $value The field value
|
||||
* @param mixed $line The line to update (0 = all)
|
||||
*
|
||||
* @return mixed
|
||||
* @since 3.2.0
|
||||
*/
|
||||
protected function updateValue($value, $line = 0)
|
||||
{
|
||||
// I know this is a little crazy... TODO refactor into recursion functions
|
||||
// the possibility of updating sub-forms in sub-forms
|
||||
if (ArrayHelper::check($value))
|
||||
{
|
||||
if (strpos((string) $line, '.') !== false)
|
||||
{
|
||||
$line = explode('.', (string) $line);
|
||||
}
|
||||
// first layer
|
||||
foreach ($value as $keys => &$rows)
|
||||
{
|
||||
if (ArrayHelper::check($rows))
|
||||
{
|
||||
// second layer
|
||||
foreach ($rows as $key => &$row)
|
||||
{
|
||||
if (ArrayHelper::check($row))
|
||||
{
|
||||
// third layer
|
||||
foreach ($row as $ke => &$ro)
|
||||
{
|
||||
if (ArrayHelper::check($ro))
|
||||
{
|
||||
// forth layer
|
||||
foreach ($ro as $k => &$r)
|
||||
{
|
||||
if (StringHelper::check($r) &&
|
||||
$this->validateUpdateKey($line, $keys, $key, $ke, $k))
|
||||
{
|
||||
$_line = (isset($line[4])) ? $line[4] : 0;
|
||||
$r = $this->string($r, $_line);
|
||||
}
|
||||
}
|
||||
}
|
||||
elseif (StringHelper::check($ro) &&
|
||||
$this->validateUpdateKey($line, $keys, $key, $ke))
|
||||
{
|
||||
$_line = (isset($line[3])) ? $line[3] : 0;
|
||||
$ro = $this->string($ro, $_line);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
elseif (StringHelper::check($row) &&
|
||||
$this->validateUpdateKey($line, $keys, $key))
|
||||
{
|
||||
$_line = (isset($line[2])) ? $line[2] : 0;
|
||||
$row = $this->string($row, $_line);
|
||||
}
|
||||
}
|
||||
}
|
||||
elseif (StringHelper::check($rows) &&
|
||||
$this->validateUpdateKey($line, $keys))
|
||||
{
|
||||
$_line = (isset($line[1])) ? $line[1] : 0;
|
||||
$rows = $this->string($rows, $_line);
|
||||
}
|
||||
}
|
||||
}
|
||||
elseif (StringHelper::check($value))
|
||||
{
|
||||
$value = $this->string($value, $line);
|
||||
}
|
||||
|
||||
return $value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if the keys are valid for search when working with arrays
|
||||
*
|
||||
* @param int $line The lines array
|
||||
* @param mixed $keys The line keys
|
||||
* @param mixed $key The line key
|
||||
* @param mixed $k The line ke
|
||||
* @param mixed $k The line k
|
||||
*
|
||||
* @return bool
|
||||
* @since 3.2.0
|
||||
*/
|
||||
protected function validateUpdateKey($line, $keys = null, $key = null, $ke = null, $k = null): bool
|
||||
{
|
||||
if (ArrayHelper::check($line))
|
||||
{
|
||||
$_keys = (isset($line[0])) ? $line[0] : null;
|
||||
$_key = (isset($line[1])) ? $line[1] : null;
|
||||
$_ke = (isset($line[2])) ? $line[2] : null;
|
||||
$_k = (isset($line[3])) ? $line[3] : null;
|
||||
|
||||
if ($keys && $_keys && $_keys !== $keys)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
if ($key && $_key && $_key !== $key)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
if ($ke && $_ke && $_ke !== $ke)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
if ($k && $_k && $_k !== $k)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Update all search-replace instances inside a string
|
||||
*
|
||||
* @param string $value The field value
|
||||
* @param int $line The line to update (0 = all)
|
||||
*
|
||||
* @return string
|
||||
* @since 3.2.0
|
||||
*/
|
||||
protected function string(string $value, int $line = 0): string
|
||||
{
|
||||
// check if string has a new line
|
||||
if (\preg_match('/\R/', $value) && $line > 0)
|
||||
{
|
||||
// line counter
|
||||
$line_number = 1;
|
||||
|
||||
$search_array = \preg_split('/\R/', $value);
|
||||
|
||||
// loop over the lines
|
||||
foreach ($search_array as $nr => $line_value)
|
||||
{
|
||||
if ($line_number == $line)
|
||||
{
|
||||
$search_array[$nr] = $this->search->replace($line_value);
|
||||
|
||||
// since we are targeting on line (and possibly one number)
|
||||
// this can only happen once, and so we return at this point
|
||||
return implode(PHP_EOL, $search_array);
|
||||
}
|
||||
// next line
|
||||
$line_number++;
|
||||
}
|
||||
|
||||
// no update took place so we just return the original value
|
||||
return $value;
|
||||
}
|
||||
|
||||
return $this->search->replace($value);
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -0,0 +1 @@
|
||||
<html><body bgcolor="#FFFFFF"></body></html>
|
@@ -0,0 +1,206 @@
|
||||
<?php
|
||||
/**
|
||||
* @package Joomla.Component.Builder
|
||||
*
|
||||
* @created 4th September, 2022
|
||||
* @author Llewellyn van der Merwe <https://dev.vdm.io>
|
||||
* @git Joomla Component Builder <https://git.vdm.dev/joomla/Component-Builder>
|
||||
* @copyright Copyright (C) 2015 Vast Development Method. All rights reserved.
|
||||
* @license GNU General Public License version 2 or later; see LICENSE.txt
|
||||
*/
|
||||
|
||||
namespace VDM\Joomla\Componentbuilder\Search;
|
||||
|
||||
|
||||
use Joomla\CMS\Factory;
|
||||
use Joomla\Input\Input;
|
||||
use VDM\Joomla\Abstraction\BaseConfig;
|
||||
|
||||
|
||||
/**
|
||||
* Search Configurations
|
||||
*
|
||||
* @since 3.2.0
|
||||
*/
|
||||
class Config extends BaseConfig
|
||||
{
|
||||
/**
|
||||
* Hold a JInput object for easier access to the input variables.
|
||||
*
|
||||
* @var Input
|
||||
* @since 3.2.0
|
||||
*/
|
||||
protected Input $input;
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @param Input|null $input Input
|
||||
*
|
||||
* @throws \Exception
|
||||
* @since 3.2.0
|
||||
*/
|
||||
public function __construct(?Input $input = null)
|
||||
{
|
||||
$this->input = $input ?: Factory::getApplication()->input;
|
||||
|
||||
// run parent constructor
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
/**
|
||||
* get type search being preformed
|
||||
*
|
||||
* @return int the search type 1 = search, 2 = search & replace
|
||||
* @since 3.2.0
|
||||
*/
|
||||
protected function getTypesearch(): ?int
|
||||
{
|
||||
return $this->input->get('type_search', 1, 'INT');
|
||||
}
|
||||
|
||||
/**
|
||||
* get posted search value
|
||||
*
|
||||
* @return string|null Raw search value
|
||||
* @since 3.2.0
|
||||
*/
|
||||
protected function getSearchvalue(): ?string
|
||||
{
|
||||
return $this->input->get('search_value', null, 'RAW');
|
||||
}
|
||||
|
||||
/**
|
||||
* get posted replace value
|
||||
*
|
||||
* @return string Raw replace value
|
||||
* @since 3.2.0
|
||||
*/
|
||||
protected function getReplacevalue(): string
|
||||
{
|
||||
return $this->input->get('replace_value', '', 'RAW');
|
||||
}
|
||||
|
||||
/**
|
||||
* get posted search match case
|
||||
*
|
||||
* @return int Match case
|
||||
* @since 3.2.0
|
||||
*/
|
||||
protected function getMatchcase(): int
|
||||
{
|
||||
return $this->input->get('match_case', 0, 'INT');
|
||||
}
|
||||
|
||||
/**
|
||||
* get posted search whole word
|
||||
*
|
||||
* @return int Whole word
|
||||
* @since 3.2.0
|
||||
*/
|
||||
protected function getWholeword(): int
|
||||
{
|
||||
return $this->input->get('whole_word', 0, 'INT');
|
||||
}
|
||||
|
||||
/**
|
||||
* get posted search regex
|
||||
*
|
||||
* @return int Regex
|
||||
* @since 3.2.0
|
||||
*/
|
||||
protected function getRegexsearch(): int
|
||||
{
|
||||
return $this->input->get('regex_search', 0, 'INT');
|
||||
}
|
||||
|
||||
/**
|
||||
* get posted component
|
||||
*
|
||||
* @return int Component ID
|
||||
* @since 3.2.0
|
||||
*/
|
||||
protected function getComponentid(): int
|
||||
{
|
||||
return $this->input->get('component_id', 0, 'INT');
|
||||
}
|
||||
|
||||
/**
|
||||
* get posted area/table
|
||||
*
|
||||
* @return string|null Table name
|
||||
* @since 3.2.0
|
||||
*/
|
||||
protected function getTablename(): ?string
|
||||
{
|
||||
return $this->input->get('table_name', null, 'word');
|
||||
}
|
||||
|
||||
/**
|
||||
* get posted field
|
||||
*
|
||||
* @return string|null Field name
|
||||
* @since 3.2.0
|
||||
*/
|
||||
protected function getFieldname(): ?string
|
||||
{
|
||||
return $this->input->get('field_name', null, 'word');
|
||||
}
|
||||
|
||||
/**
|
||||
* get posted item id
|
||||
*
|
||||
* @return int Item id
|
||||
* @since 3.2.0
|
||||
*/
|
||||
protected function getItemid(): int
|
||||
{
|
||||
return $this->input->get('item_id', 0, 'INT');
|
||||
}
|
||||
|
||||
/**
|
||||
* get field counter
|
||||
*
|
||||
* @return int we start at 0
|
||||
* @since 3.2.0
|
||||
*/
|
||||
protected function getFieldcounter(): int
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* get line counter
|
||||
*
|
||||
* @return int we start at 0
|
||||
* @since 3.2.0
|
||||
*/
|
||||
protected function getLinecounter(): int
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* get the start marker
|
||||
*
|
||||
* @return string The string to use as the start marker
|
||||
* @since 3.2.0
|
||||
*/
|
||||
protected function getMarkerstart(): string
|
||||
{
|
||||
return '{+' . '|' . '=[';
|
||||
}
|
||||
|
||||
/**
|
||||
* get the end marker
|
||||
*
|
||||
* @return string The string to use as the end marker
|
||||
* @since 3.2.0
|
||||
*/
|
||||
protected function getMarkerend(): string
|
||||
{
|
||||
return ']=' . '|' . '+}';
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -0,0 +1,186 @@
|
||||
<?php
|
||||
/**
|
||||
* @package Joomla.Component.Builder
|
||||
*
|
||||
* @created 4th September, 2022
|
||||
* @author Llewellyn van der Merwe <https://dev.vdm.io>
|
||||
* @git Joomla Component Builder <https://git.vdm.dev/joomla/Component-Builder>
|
||||
* @copyright Copyright (C) 2015 Vast Development Method. All rights reserved.
|
||||
* @license GNU General Public License version 2 or later; see LICENSE.txt
|
||||
*/
|
||||
|
||||
namespace VDM\Joomla\Componentbuilder\Search\Database;
|
||||
|
||||
|
||||
use Joomla\CMS\Factory as JoomlaFactory;
|
||||
use VDM\Joomla\Componentbuilder\Search\Factory;
|
||||
use VDM\Joomla\Componentbuilder\Search\Config;
|
||||
use VDM\Joomla\Componentbuilder\Table;
|
||||
use VDM\Joomla\Componentbuilder\Search\Model\Insert as Model;
|
||||
use VDM\Joomla\Utilities\ArrayHelper;
|
||||
use VDM\Joomla\Componentbuilder\Search\Interfaces\InsertInterface;
|
||||
|
||||
|
||||
/**
|
||||
* Search Database Set
|
||||
*
|
||||
* @since 3.2.0
|
||||
*/
|
||||
class Insert implements InsertInterface
|
||||
{
|
||||
/**
|
||||
* Search Config
|
||||
*
|
||||
* @var Config
|
||||
* @since 3.2.0
|
||||
*/
|
||||
protected Config $config;
|
||||
|
||||
/**
|
||||
* Search Table
|
||||
*
|
||||
* @var Table
|
||||
* @since 3.2.0
|
||||
*/
|
||||
protected Table $table;
|
||||
|
||||
/**
|
||||
* Search Model
|
||||
*
|
||||
* @var Model
|
||||
* @since 3.2.0
|
||||
*/
|
||||
protected Model $model;
|
||||
|
||||
/**
|
||||
* Database object to query local DB
|
||||
*
|
||||
* @since 3.2.0
|
||||
**/
|
||||
protected $db;
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @param Config|null $config The search config object.
|
||||
* @param Table|null $table The search table object.
|
||||
* @param Model|null $model The search get model object.
|
||||
*
|
||||
* @since 3.2.0
|
||||
*/
|
||||
public function __construct(?Config $config = null, ?Table $table = null,
|
||||
?Model $model = null)
|
||||
{
|
||||
$this->config = $config ?: Factory::_('Config');
|
||||
$this->table = $table ?: Factory::_('Table');
|
||||
$this->model = $model ?: Factory::_('Insert.Model');
|
||||
$this->db = JoomlaFactory::getDbo();
|
||||
}
|
||||
|
||||
/**
|
||||
* Set values to a given table
|
||||
* Example: $this->value(Value, 23, 'value_key', 'table_name');
|
||||
*
|
||||
* @param mixed $value The field value
|
||||
* @param int $id The item ID
|
||||
* @param string $field The field key
|
||||
* @param string|null $table The table
|
||||
*
|
||||
* @return bool
|
||||
* @since 3.2.0
|
||||
*/
|
||||
public function value($value, int $id, string $field, ?string $table = null): bool
|
||||
{
|
||||
// load the table
|
||||
if (empty($table))
|
||||
{
|
||||
$table = $this->config->table_name;
|
||||
}
|
||||
|
||||
// check if this is a valid field and table
|
||||
if ($id > 0 && ($name = $this->table->get($table, $field, 'name')) !== null)
|
||||
{
|
||||
// build the object
|
||||
$item = new \stdClass();
|
||||
$item->id = $id;
|
||||
$item->{$name} = $this->model->value($value, $name, $table);
|
||||
|
||||
// Update the column of this table using id as the primary key.
|
||||
return $this->db->updateObject('#__componentbuilder_' . $table, $item, 'id');
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set values to a given table
|
||||
* Example: $this->item(Object, 'table_name');
|
||||
*
|
||||
* @param object $item The item to save
|
||||
* @param string|null $table The table
|
||||
*
|
||||
* @return bool
|
||||
* @since 3.2.0
|
||||
*/
|
||||
public function item(object $item, ?string $table = null): bool
|
||||
{
|
||||
// load the table
|
||||
if (empty($table))
|
||||
{
|
||||
$table = $this->config->table_name;
|
||||
}
|
||||
|
||||
// check if this is a valid table
|
||||
if (($fields = $this->table->fields($table)) !== null)
|
||||
{
|
||||
// model the item values
|
||||
foreach ($fields as $field)
|
||||
{
|
||||
if (isset($item->{$field}))
|
||||
{
|
||||
$item->{$field} = $this->model->value($item->{$field}, $field, $table);
|
||||
}
|
||||
}
|
||||
|
||||
// Update the column of this table using id as the primary key.
|
||||
return $this->db->updateObject('#__componentbuilder_' . $table, $item, 'id');
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set values to a given table
|
||||
* Example: $this->items(Array, 'table_name');
|
||||
*
|
||||
* @param array|null $items The items being saved
|
||||
* @param string|null $table The table
|
||||
*
|
||||
* @return bool
|
||||
* @since 3.2.0
|
||||
*/
|
||||
public function items(?array $items, string $table = null): bool
|
||||
{
|
||||
// load the table
|
||||
if (empty($table))
|
||||
{
|
||||
$table = $this->config->table_name;
|
||||
}
|
||||
|
||||
// check if this is a valid table
|
||||
if (ArrayHelper::check($items))
|
||||
{
|
||||
$success = true;
|
||||
foreach ($items as $item)
|
||||
{
|
||||
if (!$this->item($item, $table))
|
||||
{
|
||||
$success = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
return $success;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -0,0 +1,305 @@
|
||||
<?php
|
||||
/**
|
||||
* @package Joomla.Component.Builder
|
||||
*
|
||||
* @created 4th September, 2022
|
||||
* @author Llewellyn van der Merwe <https://dev.vdm.io>
|
||||
* @git Joomla Component Builder <https://git.vdm.dev/joomla/Component-Builder>
|
||||
* @copyright Copyright (C) 2015 Vast Development Method. All rights reserved.
|
||||
* @license GNU General Public License version 2 or later; see LICENSE.txt
|
||||
*/
|
||||
|
||||
namespace VDM\Joomla\Componentbuilder\Search\Database;
|
||||
|
||||
|
||||
use Joomla\CMS\Factory as JoomlaFactory;
|
||||
use VDM\Joomla\Componentbuilder\Search\Factory;
|
||||
use VDM\Joomla\Componentbuilder\Search\Config;
|
||||
use VDM\Joomla\Componentbuilder\Table;
|
||||
use VDM\Joomla\Componentbuilder\Search\Model\Load as Model;
|
||||
use VDM\Joomla\Database\Load as Database;
|
||||
use VDM\Joomla\Componentbuilder\Search\Interfaces\LoadInterface;
|
||||
|
||||
|
||||
/**
|
||||
* Search Database Load
|
||||
*
|
||||
* @since 3.2.0
|
||||
*/
|
||||
class Load implements LoadInterface
|
||||
{
|
||||
/**
|
||||
* Bundle Size
|
||||
*
|
||||
* @var int
|
||||
* @since 3.2.0
|
||||
*/
|
||||
protected int $bundle = 300;
|
||||
|
||||
/**
|
||||
* Search Config
|
||||
*
|
||||
* @var Config
|
||||
* @since 3.2.0
|
||||
*/
|
||||
protected Config $config;
|
||||
|
||||
/**
|
||||
* Search Table
|
||||
*
|
||||
* @var Table
|
||||
* @since 3.2.0
|
||||
*/
|
||||
protected Table $table;
|
||||
|
||||
/**
|
||||
* Search Model
|
||||
*
|
||||
* @var Model
|
||||
* @since 3.2.0
|
||||
*/
|
||||
protected Model $model;
|
||||
|
||||
/**
|
||||
* Database load class
|
||||
*
|
||||
* @var Database
|
||||
* @since 3.2.0
|
||||
**/
|
||||
protected Database $load;
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @param Config|null $config The search config object.
|
||||
* @param Table|null $table The search table object.
|
||||
* @param Model|null $model The search get model object.
|
||||
* @param Database|null $load The database object.
|
||||
*
|
||||
* @since 3.2.0
|
||||
*/
|
||||
public function __construct(?Config $config = null, ?Table $table = null,
|
||||
?Model $model = null, ?Database $load = null)
|
||||
{
|
||||
$this->config = $config ?: Factory::_('Config');
|
||||
$this->table = $table ?: Factory::_('Table');
|
||||
$this->model = $model ?: Factory::_('Load.Model');
|
||||
$this->load = $load ?: Factory::_('Load');
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a value from a given table
|
||||
* Example: $this->value(23, 'value_key', 'table_name');
|
||||
*
|
||||
* @param int $id The item ID
|
||||
* @param string $field The field key
|
||||
* @param string|null $table The table
|
||||
*
|
||||
* @return mixed
|
||||
* @since 3.2.0
|
||||
*/
|
||||
public function value(int $id, string $field, string $table = null)
|
||||
{
|
||||
// load the table
|
||||
if (empty($table))
|
||||
{
|
||||
$table = $this->config->table_name;
|
||||
}
|
||||
|
||||
// check if this is a valid table
|
||||
if ($id > 0 && $this->table->exist($table, $field) &&
|
||||
($value = $this->load->value(
|
||||
["a.${field}" => $field], // select
|
||||
['a' => $table], // tables
|
||||
['a.id' => $id] // where
|
||||
)) !== null)
|
||||
{
|
||||
return $this->model->value(
|
||||
$value, $field, $table
|
||||
);
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get values from a given table
|
||||
* Example: $this->item(23, 'table_name');
|
||||
*
|
||||
* @param int $id The item ID
|
||||
* @param string| null $table The table
|
||||
*
|
||||
* @return object|null
|
||||
* @since 3.2.0
|
||||
*/
|
||||
public function item(int $id, string $table = null): ?object
|
||||
{
|
||||
// load the table
|
||||
if (empty($table))
|
||||
{
|
||||
$table = $this->config->table_name;
|
||||
}
|
||||
|
||||
// check if this is a valid table
|
||||
if ($id > 0 && ($fields = $this->setDatabaseFields($table)) !== null &&
|
||||
($item = $this->load->item(
|
||||
$fields, // select
|
||||
['a' => $table], // tables
|
||||
['a.id' => $id] // where
|
||||
)) !== null)
|
||||
{
|
||||
// return found values
|
||||
return $this->model->item($item, $table);
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get values from a given table
|
||||
* Example: $this->items('table_name');
|
||||
*
|
||||
* @param string|null $table The table
|
||||
* @param int $bundle The bundle to return (0 = all)
|
||||
*
|
||||
* @return array|null
|
||||
* @since 3.2.0
|
||||
*/
|
||||
public function items(string $table = null, int $bundle = 0): ?array
|
||||
{
|
||||
// load the table
|
||||
if (empty($table))
|
||||
{
|
||||
$table = $this->config->table_name;
|
||||
}
|
||||
|
||||
// check if this is a valid table
|
||||
if ( ($fields = $this->setDatabaseFields($table)) !== null)
|
||||
{
|
||||
// add a key to the selection return set
|
||||
$fields['key'] = 'id';
|
||||
// get the title value
|
||||
$title = $this->table->titleName($table);
|
||||
// set order
|
||||
$order = ['a.' . $title => 'ASC'];
|
||||
// select all
|
||||
$where = null;
|
||||
// no limit
|
||||
$limit = null;
|
||||
|
||||
// add limitation and pagination
|
||||
if ($bundle > 0)
|
||||
{
|
||||
// get the incremental number
|
||||
$where = ['a.id' => [
|
||||
'operator' => '>=',
|
||||
'value' => $this->next($table, $bundle)
|
||||
]
|
||||
];
|
||||
|
||||
// only return a limited number
|
||||
$limit = $this->bundle;
|
||||
}
|
||||
|
||||
if (($items = $this->load->items(
|
||||
$fields, // select
|
||||
['a' => $table], // tables
|
||||
$where,
|
||||
$order,
|
||||
$limit
|
||||
)) !== null)
|
||||
{
|
||||
// return found values
|
||||
return $this->model->items($items, $table);
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get next id to call
|
||||
*
|
||||
* @param string $table The table
|
||||
* @param int $bundle The bundle to return
|
||||
*
|
||||
* @return int
|
||||
* @since 3.2.0
|
||||
*/
|
||||
protected function next(string $table, int $bundle): int
|
||||
{
|
||||
if ($bundle == 1 || $bundle == 0)
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (($number = $this->model->last($table)) !== null)
|
||||
{
|
||||
return $number + 1;
|
||||
}
|
||||
|
||||
return $this->incremental($bundle);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get Incremental number where the set starts
|
||||
*
|
||||
* @param int $bundle The bundle to return
|
||||
*
|
||||
* @return int
|
||||
* @since 3.2.0
|
||||
*/
|
||||
protected function incremental(int $bundle): int
|
||||
{
|
||||
// just in case
|
||||
if ($bundle == 1 || $bundle == 0)
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
|
||||
/** Number two set starts at 301
|
||||
* 2 x 300 = 600
|
||||
* 600 - 300 = 300
|
||||
* 300 + 1 = 301 <--
|
||||
* Number five set starts at 1201
|
||||
* 5 x 300 = 1500
|
||||
* 1500 - 300 = 1200
|
||||
* 1200 + 1 = 1201 <--
|
||||
**/
|
||||
return (($bundle * $this->bundle) - $this->bundle) + 1;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get Fields ready to use in database call
|
||||
*
|
||||
* @param string $table The table which fields we want to get
|
||||
* @param string $key The table key to which the fields belong
|
||||
* @param bool $addId The switch to add ID
|
||||
*
|
||||
* @return array|null
|
||||
* @since 3.2.0
|
||||
*/
|
||||
protected function setDatabaseFields(string $table, string $key = 'a', bool $addId = true): ?array
|
||||
{
|
||||
if (($fields = $this->table->fields($table)) !== null)
|
||||
{
|
||||
// add the ID
|
||||
if ($addId)
|
||||
{
|
||||
array_unshift($fields , 'id');
|
||||
}
|
||||
|
||||
$bucket = [];
|
||||
foreach ($fields as $field)
|
||||
{
|
||||
$bucket[$key . '.' . $field] = $field;
|
||||
}
|
||||
|
||||
return $bucket;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -0,0 +1 @@
|
||||
<html><body bgcolor="#FFFFFF"></body></html>
|
@@ -0,0 +1,271 @@
|
||||
<?php
|
||||
/**
|
||||
* @package Joomla.Component.Builder
|
||||
*
|
||||
* @created 4th September, 2022
|
||||
* @author Llewellyn van der Merwe <https://dev.vdm.io>
|
||||
* @git Joomla Component Builder <https://git.vdm.dev/joomla/Component-Builder>
|
||||
* @copyright Copyright (C) 2015 Vast Development Method. All rights reserved.
|
||||
* @license GNU General Public License version 2 or later; see LICENSE.txt
|
||||
*/
|
||||
|
||||
namespace VDM\Joomla\Componentbuilder\Search\Engine;
|
||||
|
||||
|
||||
use VDM\Joomla\Componentbuilder\Search\Config;
|
||||
use VDM\Joomla\Utilities\StringHelper;
|
||||
use VDM\Joomla\Utilities\ArrayHelper;
|
||||
use VDM\Joomla\Componentbuilder\Search\Interfaces\SearchTypeInterface;
|
||||
use VDM\Joomla\Componentbuilder\Search\Abstraction\Engine;
|
||||
|
||||
|
||||
/**
|
||||
* Search Type String
|
||||
*
|
||||
* @since 3.2.0
|
||||
*/
|
||||
class Basic extends Engine implements SearchTypeInterface
|
||||
{
|
||||
/**
|
||||
* Regex Search Value
|
||||
*
|
||||
* @var string
|
||||
* @since 3.2.0
|
||||
*/
|
||||
protected string $regexValue = '';
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @param Config|null $config The search config object.
|
||||
*
|
||||
* @since 3.2.0
|
||||
*/
|
||||
public function __construct(?Config $config = null)
|
||||
{
|
||||
parent::__construct($config);
|
||||
|
||||
// quote all regular expression characters
|
||||
$searchValue = preg_quote((string) $this->searchValue, '/');
|
||||
|
||||
$start = ''; $end = '';
|
||||
|
||||
// if this is a whole word search we need to do some prep
|
||||
if ($this->wholeWord == 1)
|
||||
{
|
||||
// get first character of search string
|
||||
$first = mb_substr((string) $this->searchValue, 0, 1);
|
||||
// get last character of search string
|
||||
$last = mb_substr((string) $this->searchValue, -1);
|
||||
|
||||
// set the start boundary behavior
|
||||
$start = '(\b)';
|
||||
if (\preg_match("/\W/", $first))
|
||||
{
|
||||
$start = '(\b|\B)';
|
||||
}
|
||||
|
||||
// set the boundary behavior
|
||||
$end = '(\b)';
|
||||
if (\preg_match("/\W/", $last))
|
||||
{
|
||||
$end = '(\b|\B)';
|
||||
}
|
||||
}
|
||||
|
||||
// set search based on match case
|
||||
$case = '';
|
||||
if ($this->matchCase == 0)
|
||||
{
|
||||
$case = 'i';
|
||||
}
|
||||
|
||||
$this->regexValue = "/" . $start . '(' . $searchValue . ')' . $end . "/" . $case;
|
||||
}
|
||||
|
||||
/**
|
||||
* Search inside a string
|
||||
*
|
||||
* @param string $value The string value
|
||||
*
|
||||
* @return string|null The marked string if found, else null
|
||||
* @since 3.2.0
|
||||
*/
|
||||
public function string(string $value): ?string
|
||||
{
|
||||
// we count every line
|
||||
$this->lineCounter();
|
||||
|
||||
if (StringHelper::check($this->searchValue))
|
||||
{
|
||||
if ($this->wholeWord == 1)
|
||||
{
|
||||
return $this->searchWhole($value);
|
||||
}
|
||||
else
|
||||
{
|
||||
return $this->searchAll($value);
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Replace found instances inside string value
|
||||
*
|
||||
* @param string $value The string value to update
|
||||
*
|
||||
* @return string The updated string
|
||||
* @since 3.2.0
|
||||
*/
|
||||
public function replace(string $value): string
|
||||
{
|
||||
if (StringHelper::check($this->searchValue))
|
||||
{
|
||||
if ($this->wholeWord == 1)
|
||||
{
|
||||
return $this->replaceWhole($value);
|
||||
}
|
||||
else
|
||||
{
|
||||
return $this->replaceAll($value);
|
||||
}
|
||||
}
|
||||
return $value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Replace whole words
|
||||
*
|
||||
* @param string $value The string value
|
||||
*
|
||||
* @return string The marked string if found, else null
|
||||
* @since 3.2.0
|
||||
*/
|
||||
protected function replaceWhole(string $value): string
|
||||
{
|
||||
if ($this->match($value))
|
||||
{
|
||||
return preg_replace(
|
||||
$this->regexValue . 'm',
|
||||
"$1" . $this->replaceValue . "$3",
|
||||
$value
|
||||
);
|
||||
}
|
||||
|
||||
return $value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Search for whole words
|
||||
*
|
||||
* @param string $value The string value
|
||||
*
|
||||
* @return string|null The marked string if found, else null
|
||||
* @since 3.2.0
|
||||
*/
|
||||
protected function searchWhole(string $value): ?string
|
||||
{
|
||||
if ($this->match($value))
|
||||
{
|
||||
return trim(preg_replace(
|
||||
$this->regexValue . 'm',
|
||||
"$1" . $this->start . "$2" . $this->end . "$3",
|
||||
$value
|
||||
));
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Math the Regular Expression
|
||||
*
|
||||
* @param string $value The string value
|
||||
*
|
||||
* @return bool true if match is found
|
||||
* @since 3.0.9
|
||||
*/
|
||||
public function match(string $value): bool
|
||||
{
|
||||
$match = [];
|
||||
|
||||
preg_match($this->regexValue, $value, $match);
|
||||
|
||||
$match = array_filter(
|
||||
$match,
|
||||
fn($found) => !empty($found)
|
||||
);
|
||||
|
||||
return (bool) ArrayHelper::check($match);
|
||||
}
|
||||
|
||||
/**
|
||||
* Search for all instances
|
||||
*
|
||||
* @param string $value The string value
|
||||
*
|
||||
* @return string|null The marked string if found, else null
|
||||
* @since 3.2.0
|
||||
*/
|
||||
protected function searchAll(string $value): ?string
|
||||
{
|
||||
if ($this->matchCase == 1)
|
||||
{
|
||||
if (strpos($value, (string) $this->searchValue) !== false)
|
||||
{
|
||||
return trim(preg_replace(
|
||||
$this->regexValue . 'm',
|
||||
$this->start . "$1" . $this->end,
|
||||
$value
|
||||
));
|
||||
}
|
||||
}
|
||||
elseif (stripos($value, (string) $this->searchValue) !== false)
|
||||
{
|
||||
return trim(preg_replace(
|
||||
$this->regexValue . 'm',
|
||||
$this->start . "$1" . $this->end,
|
||||
$value
|
||||
));
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Replace for all instances
|
||||
*
|
||||
* @param string $value The string value
|
||||
*
|
||||
* @return string The marked string if found, else null
|
||||
* @since 3.2.0
|
||||
*/
|
||||
protected function replaceAll(string $value): string
|
||||
{
|
||||
if ($this->matchCase == 1)
|
||||
{
|
||||
if (strpos($value, (string) $this->searchValue) !== false)
|
||||
{
|
||||
return preg_replace(
|
||||
$this->regexValue . 'm',
|
||||
(string) $this->replaceValue,
|
||||
$value
|
||||
);
|
||||
}
|
||||
}
|
||||
elseif (stripos($value, (string) $this->searchValue) !== false)
|
||||
{
|
||||
return preg_replace(
|
||||
$this->regexValue . 'm',
|
||||
(string) $this->replaceValue,
|
||||
$value
|
||||
);
|
||||
}
|
||||
|
||||
return $value;
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -0,0 +1,128 @@
|
||||
<?php
|
||||
/**
|
||||
* @package Joomla.Component.Builder
|
||||
*
|
||||
* @created 4th September, 2022
|
||||
* @author Llewellyn van der Merwe <https://dev.vdm.io>
|
||||
* @git Joomla Component Builder <https://git.vdm.dev/joomla/Component-Builder>
|
||||
* @copyright Copyright (C) 2015 Vast Development Method. All rights reserved.
|
||||
* @license GNU General Public License version 2 or later; see LICENSE.txt
|
||||
*/
|
||||
|
||||
namespace VDM\Joomla\Componentbuilder\Search\Engine;
|
||||
|
||||
|
||||
use VDM\Joomla\Componentbuilder\Search\Config;
|
||||
use VDM\Joomla\Utilities\StringHelper;
|
||||
use VDM\Joomla\Utilities\ArrayHelper;
|
||||
use VDM\Joomla\Componentbuilder\Search\Interfaces\SearchTypeInterface;
|
||||
use VDM\Joomla\Componentbuilder\Search\Abstraction\Engine;
|
||||
|
||||
|
||||
/**
|
||||
* Search Type Regex
|
||||
*
|
||||
* @since 3.2.0
|
||||
*/
|
||||
class Regex extends Engine implements SearchTypeInterface
|
||||
{
|
||||
/**
|
||||
* Regex Search Value
|
||||
*
|
||||
* @var string
|
||||
* @since 3.2.0
|
||||
*/
|
||||
protected string $regexValue = '';
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @param Config|null $config The search config object.
|
||||
*
|
||||
* @since 3.2.0
|
||||
*/
|
||||
public function __construct(?Config $config = null)
|
||||
{
|
||||
parent::__construct($config);
|
||||
|
||||
// set search based on match case
|
||||
$case = '';
|
||||
if ($this->matchCase == 0)
|
||||
{
|
||||
$case = 'i';
|
||||
}
|
||||
|
||||
$this->regexValue = "/(" . $this->searchValue . ")/" . $case;
|
||||
}
|
||||
|
||||
/**
|
||||
* Search inside a string
|
||||
*
|
||||
* @param string $value The string value
|
||||
*
|
||||
* @return string|null The marked string if found, else null
|
||||
* @since 3.2.0
|
||||
*/
|
||||
public function string(string $value): ?string
|
||||
{
|
||||
// we count every line
|
||||
$this->lineCounter();
|
||||
|
||||
if (StringHelper::check($this->searchValue) && $this->match($value))
|
||||
{
|
||||
return trim(preg_replace(
|
||||
$this->regexValue . 'm',
|
||||
$this->start . "$1" . $this->end,
|
||||
$value
|
||||
));
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Replace found instances inside string value
|
||||
*
|
||||
* @param string $value The string value to update
|
||||
*
|
||||
* @return string The updated string
|
||||
* @since 3.2.0
|
||||
*/
|
||||
public function replace(string $value): string
|
||||
{
|
||||
if (StringHelper::check($this->searchValue) && $this->match($value))
|
||||
{
|
||||
return preg_replace(
|
||||
$this->regexValue . 'm',
|
||||
(string) $this->replaceValue,
|
||||
$value
|
||||
);
|
||||
}
|
||||
|
||||
return $value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Math the Regular Expression
|
||||
*
|
||||
* @param string $value The string value
|
||||
*
|
||||
* @return bool true if match is found
|
||||
* @since 3.0.9
|
||||
*/
|
||||
public function match(string $value): bool
|
||||
{
|
||||
$match = [];
|
||||
|
||||
preg_match($this->regexValue, $value, $match);
|
||||
|
||||
$match = array_filter(
|
||||
$match,
|
||||
fn($found) => !empty($found)
|
||||
);
|
||||
|
||||
return (bool) ArrayHelper::check($match);
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -0,0 +1 @@
|
||||
<html><body bgcolor="#FFFFFF"></body></html>
|
@@ -0,0 +1,83 @@
|
||||
<?php
|
||||
/**
|
||||
* @package Joomla.Component.Builder
|
||||
*
|
||||
* @created 4th September, 2022
|
||||
* @author Llewellyn van der Merwe <https://dev.vdm.io>
|
||||
* @git Joomla Component Builder <https://git.vdm.dev/joomla/Component-Builder>
|
||||
* @copyright Copyright (C) 2015 Vast Development Method. All rights reserved.
|
||||
* @license GNU General Public License version 2 or later; see LICENSE.txt
|
||||
*/
|
||||
|
||||
namespace VDM\Joomla\Componentbuilder\Search;
|
||||
|
||||
|
||||
use Joomla\DI\Container;
|
||||
use VDM\Joomla\Componentbuilder\Search\Service\Search;
|
||||
use VDM\Joomla\Componentbuilder\Search\Service\Model;
|
||||
use VDM\Joomla\Componentbuilder\Search\Service\Database;
|
||||
use VDM\Joomla\Componentbuilder\Search\Service\Agent;
|
||||
use VDM\Joomla\Interfaces\FactoryInterface;
|
||||
|
||||
|
||||
/**
|
||||
* Search Factory
|
||||
*
|
||||
* @since 3.2.0
|
||||
*/
|
||||
abstract class Factory implements FactoryInterface
|
||||
{
|
||||
/**
|
||||
* Global Search Container
|
||||
*
|
||||
* @var Container
|
||||
* @since 3.2.0
|
||||
**/
|
||||
protected static $container = null;
|
||||
|
||||
/**
|
||||
* Get any class from the search container
|
||||
*
|
||||
* @param string $key The container class key
|
||||
*
|
||||
* @return Mixed
|
||||
* @since 3.2.0
|
||||
*/
|
||||
public static function _(string $key)
|
||||
{
|
||||
return self::getContainer()->get($key);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the global search container
|
||||
*
|
||||
* @return Container
|
||||
* @since 3.2.0
|
||||
*/
|
||||
public static function getContainer(): Container
|
||||
{
|
||||
if (!self::$container)
|
||||
{
|
||||
self::$container = self::createContainer();
|
||||
}
|
||||
|
||||
return self::$container;
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a container object
|
||||
*
|
||||
* @return Container
|
||||
* @since 3.2.0
|
||||
*/
|
||||
protected static function createContainer(): Container
|
||||
{
|
||||
return (new Container())
|
||||
->registerServiceProvider(new Search())
|
||||
->registerServiceProvider(new Model())
|
||||
->registerServiceProvider(new Database())
|
||||
->registerServiceProvider(new Agent());
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -0,0 +1,66 @@
|
||||
<?php
|
||||
/**
|
||||
* @package Joomla.Component.Builder
|
||||
*
|
||||
* @created 4th September, 2022
|
||||
* @author Llewellyn van der Merwe <https://dev.vdm.io>
|
||||
* @git Joomla Component Builder <https://git.vdm.dev/joomla/Component-Builder>
|
||||
* @copyright Copyright (C) 2015 Vast Development Method. All rights reserved.
|
||||
* @license GNU General Public License version 2 or later; see LICENSE.txt
|
||||
*/
|
||||
|
||||
namespace VDM\Joomla\Componentbuilder\Search\Interfaces;
|
||||
|
||||
|
||||
/**
|
||||
* Search Find Interface
|
||||
*
|
||||
* @since 3.2.0
|
||||
*/
|
||||
interface FindInterface
|
||||
{
|
||||
/**
|
||||
* Get found values
|
||||
*
|
||||
* @param string|null $table The table being searched
|
||||
*
|
||||
* @return array|null
|
||||
* @since 3.2.0
|
||||
*/
|
||||
public function get(?string $table = null): ?array;
|
||||
|
||||
/**
|
||||
* Search over an item fields
|
||||
*
|
||||
* @param object $item The item object of fields to search through
|
||||
* @param int|null $id The item id
|
||||
* @param string|null $table The table being searched
|
||||
*
|
||||
* @return void
|
||||
* @since 3.2.0
|
||||
*/
|
||||
public function item(object $item, ?int $id =null, ?string $table = null);
|
||||
|
||||
/**
|
||||
* Search over an array of items
|
||||
*
|
||||
* @param array|null $items The array of items to search through
|
||||
* @param string|null $table The table being searched
|
||||
*
|
||||
* @return void
|
||||
* @since 3.2.0
|
||||
*/
|
||||
public function items(?array $items = null, ?string $table = null);
|
||||
|
||||
/**
|
||||
* Reset all found values of a table
|
||||
*
|
||||
* @param string|null $table The table being searched
|
||||
*
|
||||
* @return void
|
||||
* @since 3.2.0
|
||||
*/
|
||||
public function reset(?string $table = null);
|
||||
|
||||
}
|
||||
|
@@ -0,0 +1,60 @@
|
||||
<?php
|
||||
/**
|
||||
* @package Joomla.Component.Builder
|
||||
*
|
||||
* @created 4th September, 2022
|
||||
* @author Llewellyn van der Merwe <https://dev.vdm.io>
|
||||
* @git Joomla Component Builder <https://git.vdm.dev/joomla/Component-Builder>
|
||||
* @copyright Copyright (C) 2015 Vast Development Method. All rights reserved.
|
||||
* @license GNU General Public License version 2 or later; see LICENSE.txt
|
||||
*/
|
||||
|
||||
namespace VDM\Joomla\Componentbuilder\Search\Interfaces;
|
||||
|
||||
|
||||
/**
|
||||
* Search Database Insert Interface
|
||||
*
|
||||
* @since 3.2.0
|
||||
*/
|
||||
interface InsertInterface
|
||||
{
|
||||
/**
|
||||
* Set values to a given table
|
||||
* Example: $this->value(Value, 23, 'value_key', 'table_name');
|
||||
*
|
||||
* @param mixed $value The field value
|
||||
* @param int $id The item ID
|
||||
* @param string $field The field key
|
||||
* @param string|null $table The table
|
||||
*
|
||||
* @return bool
|
||||
* @since 3.2.0
|
||||
*/
|
||||
public function value($value, int $id, string $field, ?string $table = null): bool;
|
||||
|
||||
/**
|
||||
* Set values to a given table
|
||||
* Example: $this->item(Object, 23, 'table_name');
|
||||
*
|
||||
* @param object $item The item to save
|
||||
* @param string|null $table The table
|
||||
*
|
||||
* @return bool
|
||||
* @since 3.2.0
|
||||
*/
|
||||
public function item(object $item, ?string $table = null): bool;
|
||||
|
||||
/**
|
||||
* Set values to a given table
|
||||
* Example: $this->items(Array, 'table_name');
|
||||
*
|
||||
* @param array $items The items being saved
|
||||
* @param string|null $table The table
|
||||
*
|
||||
* @return bool
|
||||
* @since 3.2.0
|
||||
*/
|
||||
public function items(array $items, string $table = null): bool;
|
||||
}
|
||||
|
@@ -0,0 +1,60 @@
|
||||
<?php
|
||||
/**
|
||||
* @package Joomla.Component.Builder
|
||||
*
|
||||
* @created 4th September, 2022
|
||||
* @author Llewellyn van der Merwe <https://dev.vdm.io>
|
||||
* @git Joomla Component Builder <https://git.vdm.dev/joomla/Component-Builder>
|
||||
* @copyright Copyright (C) 2015 Vast Development Method. All rights reserved.
|
||||
* @license GNU General Public License version 2 or later; see LICENSE.txt
|
||||
*/
|
||||
|
||||
namespace VDM\Joomla\Componentbuilder\Search\Interfaces;
|
||||
|
||||
|
||||
/**
|
||||
* Search Database Load Interface
|
||||
*
|
||||
* @since 3.2.0
|
||||
*/
|
||||
interface LoadInterface
|
||||
{
|
||||
/**
|
||||
* Get a value from a given table
|
||||
* Example: $this->value(23, 'value_key', 'table_name');
|
||||
*
|
||||
* @param int $id The item ID
|
||||
* @param string $field The field key
|
||||
* @param string|null $table The table
|
||||
*
|
||||
* @return mixed
|
||||
* @since 3.2.0
|
||||
*/
|
||||
public function value(int $id, string $field, string $table = null);
|
||||
|
||||
/**
|
||||
* Get values from a given table
|
||||
* Example: $this->item(23, 'table_name');
|
||||
*
|
||||
* @param int $id The item ID
|
||||
* @param string| null $table The table
|
||||
*
|
||||
* @return object|null
|
||||
* @since 3.2.0
|
||||
*/
|
||||
public function item(int $id, string $table = null): ?object;
|
||||
|
||||
/**
|
||||
* Get values from a given table
|
||||
* Example: $this->items('table_name');
|
||||
*
|
||||
* @param string|null $table The table
|
||||
* @param int $bundle The bundle to return (0 = all)
|
||||
*
|
||||
* @return array|null
|
||||
* @since 3.2.0
|
||||
*/
|
||||
public function items(string $table = null, int $bundle = 0): ?array;
|
||||
|
||||
}
|
||||
|
@@ -0,0 +1,66 @@
|
||||
<?php
|
||||
/**
|
||||
* @package Joomla.Component.Builder
|
||||
*
|
||||
* @created 4th September, 2022
|
||||
* @author Llewellyn van der Merwe <https://dev.vdm.io>
|
||||
* @git Joomla Component Builder <https://git.vdm.dev/joomla/Component-Builder>
|
||||
* @copyright Copyright (C) 2015 Vast Development Method. All rights reserved.
|
||||
* @license GNU General Public License version 2 or later; see LICENSE.txt
|
||||
*/
|
||||
|
||||
namespace VDM\Joomla\Componentbuilder\Search\Interfaces;
|
||||
|
||||
|
||||
/**
|
||||
* Search Replace Interface
|
||||
*
|
||||
* @since 3.2.0
|
||||
*/
|
||||
interface ReplaceInterface
|
||||
{
|
||||
/**
|
||||
* Get updated values
|
||||
*
|
||||
* @param string|null $table The table being searched
|
||||
*
|
||||
* @return array|null
|
||||
* @since 3.2.0
|
||||
*/
|
||||
public function get(?string $table = null): ?array;
|
||||
|
||||
/**
|
||||
* Search over an item fields
|
||||
*
|
||||
* @param object $item The item object of fields to search through
|
||||
* @param int|null $id The item id
|
||||
* @param string|null $table The table being searched
|
||||
*
|
||||
* @return void
|
||||
* @since 3.2.0
|
||||
*/
|
||||
public function item(object $item, ?int $id =null, ?string $table = null);
|
||||
|
||||
/**
|
||||
* Search over an array of items
|
||||
*
|
||||
* @param array|null $items The array of items to search through
|
||||
* @param string|null $table The table being searched
|
||||
*
|
||||
* @return void
|
||||
* @since 3.2.0
|
||||
*/
|
||||
public function items(?array $items = null, ?string $table = null);
|
||||
|
||||
/**
|
||||
* Reset all updated values of a table
|
||||
*
|
||||
* @param string|null $table The table being searched
|
||||
*
|
||||
* @return void
|
||||
* @since 3.2.0
|
||||
*/
|
||||
public function reset(?string $table = null);
|
||||
|
||||
}
|
||||
|
@@ -0,0 +1,56 @@
|
||||
<?php
|
||||
/**
|
||||
* @package Joomla.Component.Builder
|
||||
*
|
||||
* @created 4th September, 2022
|
||||
* @author Llewellyn van der Merwe <https://dev.vdm.io>
|
||||
* @git Joomla Component Builder <https://git.vdm.dev/joomla/Component-Builder>
|
||||
* @copyright Copyright (C) 2015 Vast Development Method. All rights reserved.
|
||||
* @license GNU General Public License version 2 or later; see LICENSE.txt
|
||||
*/
|
||||
|
||||
namespace VDM\Joomla\Componentbuilder\Search\Interfaces;
|
||||
|
||||
|
||||
/**
|
||||
* Search Interface
|
||||
*
|
||||
* @since 3.2.0
|
||||
*/
|
||||
interface SearchInterface
|
||||
{
|
||||
/**
|
||||
* Get found values
|
||||
*
|
||||
* @param string $table The table being searched
|
||||
*
|
||||
* @return array|null
|
||||
* @since 3.2.0
|
||||
*/
|
||||
public function get(string $table): ?array;
|
||||
|
||||
/**
|
||||
* Search inside a value
|
||||
*
|
||||
* @param mixed $value The field value
|
||||
* @param int $id The item ID
|
||||
* @param string $field The field key
|
||||
* @param string $table The table
|
||||
*
|
||||
* @return bool
|
||||
* @since 3.2.0
|
||||
*/
|
||||
public function value($value, int $id, string $field, string $table): bool;
|
||||
|
||||
/**
|
||||
* Empty the found values
|
||||
*
|
||||
* @param string $table The table being searched
|
||||
*
|
||||
* @return void
|
||||
* @since 3.2.0
|
||||
*/
|
||||
public function reset(string $table);
|
||||
|
||||
}
|
||||
|
@@ -0,0 +1,43 @@
|
||||
<?php
|
||||
/**
|
||||
* @package Joomla.Component.Builder
|
||||
*
|
||||
* @created 4th September, 2022
|
||||
* @author Llewellyn van der Merwe <https://dev.vdm.io>
|
||||
* @git Joomla Component Builder <https://git.vdm.dev/joomla/Component-Builder>
|
||||
* @copyright Copyright (C) 2015 Vast Development Method. All rights reserved.
|
||||
* @license GNU General Public License version 2 or later; see LICENSE.txt
|
||||
*/
|
||||
|
||||
namespace VDM\Joomla\Componentbuilder\Search\Interfaces;
|
||||
|
||||
|
||||
/**
|
||||
* Search Type Interface
|
||||
*
|
||||
* @since 3.2.0
|
||||
*/
|
||||
interface SearchTypeInterface
|
||||
{
|
||||
/**
|
||||
* Search inside a string
|
||||
*
|
||||
* @param string $value The string value
|
||||
*
|
||||
* @return string|null The marked string if found, else null
|
||||
* @since 3.2.0
|
||||
*/
|
||||
public function string(string $value): ?string;
|
||||
|
||||
/**
|
||||
* Replace found instances inside string value
|
||||
*
|
||||
* @param string $value The string value to update
|
||||
*
|
||||
* @return string The updated string
|
||||
* @since 3.2.0
|
||||
*/
|
||||
public function replace(string $value): string;
|
||||
|
||||
}
|
||||
|
@@ -0,0 +1 @@
|
||||
<html><body bgcolor="#FFFFFF"></body></html>
|
@@ -0,0 +1,138 @@
|
||||
<?php
|
||||
/**
|
||||
* @package Joomla.Component.Builder
|
||||
*
|
||||
* @created 4th September, 2022
|
||||
* @author Llewellyn van der Merwe <https://dev.vdm.io>
|
||||
* @git Joomla Component Builder <https://git.vdm.dev/joomla/Component-Builder>
|
||||
* @copyright Copyright (C) 2015 Vast Development Method. All rights reserved.
|
||||
* @license GNU General Public License version 2 or later; see LICENSE.txt
|
||||
*/
|
||||
|
||||
namespace VDM\Joomla\Componentbuilder\Search\Model;
|
||||
|
||||
|
||||
use VDM\Joomla\Componentbuilder\Search\Factory;
|
||||
use VDM\Joomla\Componentbuilder\Table;
|
||||
use VDM\Joomla\Componentbuilder\Search\Config;
|
||||
use VDM\Joomla\Utilities\ArrayHelper;
|
||||
use VDM\Joomla\Interfaces\ModelInterface;
|
||||
use VDM\Joomla\Abstraction\Model;
|
||||
|
||||
|
||||
/**
|
||||
* Search Insert Model
|
||||
*
|
||||
* @since 3.2.0
|
||||
*/
|
||||
class Insert extends Model implements ModelInterface
|
||||
{
|
||||
/**
|
||||
* Search Config
|
||||
*
|
||||
* @var Config
|
||||
* @since 3.2.0
|
||||
*/
|
||||
protected Config $config;
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @param Config|null $config The search config object.
|
||||
* @param Table|null $table The search table object.
|
||||
*
|
||||
* @since 3.2.0
|
||||
*/
|
||||
public function __construct(?Config $config = null, ?Table $table = null)
|
||||
{
|
||||
parent::__construct($table ?? Factory::_('Table'));
|
||||
|
||||
$this->config = $config ?: Factory::_('Config');
|
||||
}
|
||||
|
||||
/**
|
||||
* Model the value
|
||||
* Example: $this->value(value, 'field_key', 'table_name');
|
||||
*
|
||||
* @param mixed $value The value to model
|
||||
* @param string $field The field key
|
||||
* @param string|null $table The table
|
||||
*
|
||||
* @return mixed
|
||||
* @since 3.2.0
|
||||
*/
|
||||
public function value($value, string $field, ?string $table = null)
|
||||
{
|
||||
// set the table name
|
||||
if (empty($table))
|
||||
{
|
||||
$table = $this->getTable();
|
||||
}
|
||||
|
||||
// check if this is a valid table
|
||||
if (($store = $this->table->get($table, $field, 'store')) !== null)
|
||||
{
|
||||
// open the value based on the store method
|
||||
switch($store)
|
||||
{
|
||||
case 'base64':
|
||||
$value = base64_encode((string) $value);
|
||||
break;
|
||||
case 'json':
|
||||
$value = json_encode($value, JSON_FORCE_OBJECT);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return $value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Validate before the value is modelled (basic, override in child class)
|
||||
*
|
||||
* @param mixed $value The field value
|
||||
* @param string|null $field The field key
|
||||
* @param string|null $table The table
|
||||
*
|
||||
* @return bool
|
||||
* @since 3.2.0
|
||||
*/
|
||||
protected function validateBefore(&$value, ?string $field = null, ?string $table = null): bool
|
||||
{
|
||||
// check values
|
||||
if (StringHelper::check($value) || ArrayHelper::check($value, true))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
// remove empty values
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Validate after the value is modelled (basic, override in child class)
|
||||
*
|
||||
* @param mixed $value The field value
|
||||
* @param string|null $field The field key
|
||||
* @param string|null $table The table
|
||||
*
|
||||
* @return bool
|
||||
* @since 3.2.0
|
||||
*/
|
||||
protected function validateAfter(&$value, ?string $field = null, ?string $table = null): bool
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the current active table
|
||||
*
|
||||
* @return string
|
||||
* @since 3.2.0
|
||||
*/
|
||||
protected function getTable(): string
|
||||
{
|
||||
return $this->config->table_name;
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -0,0 +1,165 @@
|
||||
<?php
|
||||
/**
|
||||
* @package Joomla.Component.Builder
|
||||
*
|
||||
* @created 4th September, 2022
|
||||
* @author Llewellyn van der Merwe <https://dev.vdm.io>
|
||||
* @git Joomla Component Builder <https://git.vdm.dev/joomla/Component-Builder>
|
||||
* @copyright Copyright (C) 2015 Vast Development Method. All rights reserved.
|
||||
* @license GNU General Public License version 2 or later; see LICENSE.txt
|
||||
*/
|
||||
|
||||
namespace VDM\Joomla\Componentbuilder\Search\Model;
|
||||
|
||||
|
||||
use VDM\Joomla\Componentbuilder\Search\Factory;
|
||||
use VDM\Joomla\Componentbuilder\Table;
|
||||
use VDM\Joomla\Componentbuilder\Search\Config;
|
||||
use VDM\Joomla\Utilities\ArrayHelper;
|
||||
use VDM\Joomla\Utilities\JsonHelper;
|
||||
use VDM\Joomla\Utilities\StringHelper;
|
||||
use VDM\Joomla\Interfaces\ModelInterface;
|
||||
use VDM\Joomla\Abstraction\Model;
|
||||
|
||||
|
||||
/**
|
||||
* Search Load Model
|
||||
*
|
||||
* @since 3.2.0
|
||||
*/
|
||||
class Load extends Model implements ModelInterface
|
||||
{
|
||||
/**
|
||||
* Search Config
|
||||
*
|
||||
* @var Config
|
||||
* @since 3.2.0
|
||||
*/
|
||||
protected Config $config;
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @param Config|null $config The search config object.
|
||||
* @param Table|null $table The search table object.
|
||||
*
|
||||
* @since 3.2.0
|
||||
*/
|
||||
public function __construct(?Config $config = null, ?Table $table = null)
|
||||
{
|
||||
parent::__construct($table ?? Factory::_('Table'));
|
||||
|
||||
$this->config = $config ?: Factory::_('Config');
|
||||
}
|
||||
|
||||
/**
|
||||
* Model the value
|
||||
* Example: $this->value(value, 'value_key', 'table_name');
|
||||
*
|
||||
* @param mixed $value The value to model
|
||||
* @param string $field The field key
|
||||
* @param string|null $table The table
|
||||
*
|
||||
* @return mixed
|
||||
* @since 3.2.0
|
||||
*/
|
||||
public function value($value, string $field, ?string $table = null)
|
||||
{
|
||||
// load the table
|
||||
if (empty($table))
|
||||
{
|
||||
$table = $this->getTable();
|
||||
}
|
||||
|
||||
// check if this is a valid table
|
||||
if (StringHelper::check($value) && ($store = $this->table->get($table, $field, 'store')) !== null)
|
||||
{
|
||||
// open the value based on the store method
|
||||
switch($store)
|
||||
{
|
||||
case 'base64':
|
||||
$value = base64_decode((string) $value);
|
||||
break;
|
||||
case 'json':
|
||||
// check if there is a json string
|
||||
if (JsonHelper::check($value))
|
||||
{
|
||||
$value = json_decode((string) $value, true);
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
return $value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Validate before the value is modelled (basic, override in child class)
|
||||
*
|
||||
* @param mixed $value The field value
|
||||
* @param string|null $field The field key
|
||||
* @param string|null $table The table
|
||||
*
|
||||
* @return bool
|
||||
* @since 3.2.0
|
||||
*/
|
||||
protected function validateBefore(&$value, ?string $field = null, ?string $table = null): bool
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Validate after the value is modelled (basic, override in child class)
|
||||
*
|
||||
* @param mixed $value The field value
|
||||
* @param string|null $field The field key
|
||||
* @param string|null $table The table
|
||||
*
|
||||
* @return bool
|
||||
* @since 3.2.0
|
||||
*/
|
||||
protected function validateAfter(&$value, ?string $field = null, ?string $table = null): bool
|
||||
{
|
||||
// Start note to self
|
||||
// Yes we don't search in the field->xml (field) PHP because the xml is messy
|
||||
// first of all we need to change that storage method :((( seriously
|
||||
// and the actual PHP is stored in the xml as base64 with a [__.o0=base64=Oo.__] key in front of it
|
||||
// if I can go back and drag you around by your ear... I will, but okay you did not know better.
|
||||
// Listen you have tried to fix this a few times already (I lost count) and by the time you realize how it works
|
||||
// two hours have been wasted, and you usually only then realize why it's not fixed in the first place... o boy... just walk now!
|
||||
// since unless you have three days don't even look further, this is a huge issue/mess
|
||||
// and while I agree it needs fixing, it will not take a few hours... but days
|
||||
// End note to self
|
||||
|
||||
// check values
|
||||
if (StringHelper::check($value) || ArrayHelper::check($value, true))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
// remove empty values
|
||||
return false;
|
||||
|
||||
// Start another note to self
|
||||
// If you're still here
|
||||
// the problem is not opening the PHP in the xml,
|
||||
// it is storing it with the updated changes... if any are made via the search-update methods
|
||||
// so the only way to fix this is to change the whole way the xml values in the field table is stored.
|
||||
// Yes, that is right... all the way back to the field view... and then to update all places you open that xml values
|
||||
// and get the values out of the xml string and use them, and if you've forgotten, that is nearly everywhere,
|
||||
// and so let the refactoring of the foundation begin... there I saved you another 3 hours.
|
||||
// End another note to self
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the current active table
|
||||
*
|
||||
* @return string
|
||||
* @since 3.2.0
|
||||
*/
|
||||
protected function getTable(): string
|
||||
{
|
||||
return $this->config->table_name;
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -0,0 +1 @@
|
||||
<html><body bgcolor="#FFFFFF"></body></html>
|
@@ -0,0 +1,143 @@
|
||||
<?php
|
||||
/**
|
||||
* @package Joomla.Component.Builder
|
||||
*
|
||||
* @created 4th September, 2022
|
||||
* @author Llewellyn van der Merwe <https://dev.vdm.io>
|
||||
* @git Joomla Component Builder <https://git.vdm.dev/joomla/Component-Builder>
|
||||
* @copyright Copyright (C) 2015 Vast Development Method. All rights reserved.
|
||||
* @license GNU General Public License version 2 or later; see LICENSE.txt
|
||||
*/
|
||||
|
||||
namespace VDM\Joomla\Componentbuilder\Search\Service;
|
||||
|
||||
|
||||
use Joomla\DI\Container;
|
||||
use Joomla\DI\ServiceProviderInterface;
|
||||
use VDM\Joomla\Componentbuilder\Search\Agent as SearchAgent;
|
||||
use VDM\Joomla\Componentbuilder\Search\Agent\Find;
|
||||
use VDM\Joomla\Componentbuilder\Search\Agent\Replace;
|
||||
use VDM\Joomla\Componentbuilder\Search\Agent\Search;
|
||||
use VDM\Joomla\Componentbuilder\Search\Agent\Update;
|
||||
|
||||
|
||||
/**
|
||||
* Agent Service Provider
|
||||
*
|
||||
* @since 3.2.0
|
||||
*/
|
||||
class Agent implements ServiceProviderInterface
|
||||
{
|
||||
/**
|
||||
* Registers the service provider with a DI container.
|
||||
*
|
||||
* @param Container $container The DI container.
|
||||
*
|
||||
* @return void
|
||||
* @since 3.2.0
|
||||
*/
|
||||
public function register(Container $container)
|
||||
{
|
||||
$container->alias(SearchAgent::class, 'Agent')
|
||||
->share('Agent', [$this, 'getAgent'], true);
|
||||
|
||||
$container->alias(Find::class, 'Agent.Find')
|
||||
->share('Agent.Find', [$this, 'getFind'], true);
|
||||
|
||||
$container->alias(Replace::class, 'Agent.Replace')
|
||||
->share('Agent.Replace', [$this, 'getReplace'], true);
|
||||
|
||||
$container->alias(Search::class, 'Agent.Search')
|
||||
->share('Agent.Search', [$this, 'getSearch'], true);
|
||||
|
||||
$container->alias(Update::class, 'Agent.Update')
|
||||
->share('Agent.Update', [$this, 'getUpdate'], true);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the Search Agent
|
||||
*
|
||||
* @param Container $container The DI container.
|
||||
*
|
||||
* @return SearchAgent
|
||||
* @since 3.2.0
|
||||
*/
|
||||
public function getAgent(Container $container): SearchAgent
|
||||
{
|
||||
return new SearchAgent(
|
||||
$container->get('Config'),
|
||||
$container->get('Load.Database'),
|
||||
$container->get('Insert.Database'),
|
||||
$container->get('Agent.Find'),
|
||||
$container->get('Agent.Replace'),
|
||||
$container->get('Agent.Search'),
|
||||
$container->get('Agent.Update'),
|
||||
$container->get('Table')
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the Search Agent Find
|
||||
*
|
||||
* @param Container $container The DI container.
|
||||
*
|
||||
* @return Find
|
||||
* @since 3.2.0
|
||||
*/
|
||||
public function getFind(Container $container): Find
|
||||
{
|
||||
return new Find(
|
||||
$container->get('Config'),
|
||||
$container->get('Agent.Search')
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the Search Agent Replace
|
||||
*
|
||||
* @param Container $container The DI container.
|
||||
*
|
||||
* @return Replace
|
||||
* @since 3.2.0
|
||||
*/
|
||||
public function getReplace(Container $container): Replace
|
||||
{
|
||||
return new Replace(
|
||||
$container->get('Config'),
|
||||
$container->get('Agent.Update')
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the Search Agent Search
|
||||
*
|
||||
* @param Container $container The DI container.
|
||||
*
|
||||
* @return Search
|
||||
* @since 3.2.0
|
||||
*/
|
||||
public function getSearch(Container $container): Search
|
||||
{
|
||||
return new Search(
|
||||
$container->get('Config'),
|
||||
$container->get('Search')
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the Search Agent Update
|
||||
*
|
||||
* @param Container $container The DI container.
|
||||
*
|
||||
* @return Update
|
||||
* @since 3.2.0
|
||||
*/
|
||||
public function getUpdate(Container $container): Update
|
||||
{
|
||||
return new Update(
|
||||
$container->get('Search')
|
||||
);
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -0,0 +1,98 @@
|
||||
<?php
|
||||
/**
|
||||
* @package Joomla.Component.Builder
|
||||
*
|
||||
* @created 4th September, 2022
|
||||
* @author Llewellyn van der Merwe <https://dev.vdm.io>
|
||||
* @git Joomla Component Builder <https://git.vdm.dev/joomla/Component-Builder>
|
||||
* @copyright Copyright (C) 2015 Vast Development Method. All rights reserved.
|
||||
* @license GNU General Public License version 2 or later; see LICENSE.txt
|
||||
*/
|
||||
|
||||
namespace VDM\Joomla\Componentbuilder\Search\Service;
|
||||
|
||||
|
||||
use Joomla\DI\Container;
|
||||
use Joomla\DI\ServiceProviderInterface;
|
||||
use VDM\Joomla\Database\Load;
|
||||
use VDM\Joomla\Componentbuilder\Search\Database\Load as LoadDatabase;
|
||||
use VDM\Joomla\Componentbuilder\Search\Database\Insert as InsertDatabase;
|
||||
|
||||
|
||||
/**
|
||||
* Database Service Provider
|
||||
*
|
||||
* @since 3.2.0
|
||||
*/
|
||||
class Database implements ServiceProviderInterface
|
||||
{
|
||||
/**
|
||||
* Registers the service provider with a DI container.
|
||||
*
|
||||
* @param Container $container The DI container.
|
||||
*
|
||||
* @return void
|
||||
* @since 3.2.0
|
||||
*/
|
||||
public function register(Container $container)
|
||||
{
|
||||
$container->alias(Load::class, 'Load')
|
||||
->share('Load', [$this, 'getLoad'], true);
|
||||
|
||||
$container->alias(LoadDatabase::class, 'Load.Database')
|
||||
->share('Load.Database', [$this, 'getDatabaseLoad'], true);
|
||||
|
||||
$container->alias(InsertDatabase::class, 'Insert.Database')
|
||||
->share('Insert.Database', [$this, 'getDatabaseInsert'], true);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the Core Load Database
|
||||
*
|
||||
* @param Container $container The DI container.
|
||||
*
|
||||
* @return Load
|
||||
* @since 3.2.0
|
||||
*/
|
||||
public function getLoad(Container $container): Load
|
||||
{
|
||||
return new Load();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the Load Database
|
||||
*
|
||||
* @param Container $container The DI container.
|
||||
*
|
||||
* @return LoadDatabase
|
||||
* @since 3.2.0
|
||||
*/
|
||||
public function getDatabaseLoad(Container $container): LoadDatabase
|
||||
{
|
||||
return new LoadDatabase(
|
||||
$container->get('Config'),
|
||||
$container->get('Table'),
|
||||
$container->get('Load.Model'),
|
||||
$container->get('Load')
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the Insert Database
|
||||
*
|
||||
* @param Container $container The DI container.
|
||||
*
|
||||
* @return InsertDatabase
|
||||
* @since 3.2.0
|
||||
*/
|
||||
public function getDatabaseInsert(Container $container): InsertDatabase
|
||||
{
|
||||
return new InsertDatabase(
|
||||
$container->get('Config'),
|
||||
$container->get('Table'),
|
||||
$container->get('Insert.Model')
|
||||
);
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -0,0 +1,77 @@
|
||||
<?php
|
||||
/**
|
||||
* @package Joomla.Component.Builder
|
||||
*
|
||||
* @created 4th September, 2022
|
||||
* @author Llewellyn van der Merwe <https://dev.vdm.io>
|
||||
* @git Joomla Component Builder <https://git.vdm.dev/joomla/Component-Builder>
|
||||
* @copyright Copyright (C) 2015 Vast Development Method. All rights reserved.
|
||||
* @license GNU General Public License version 2 or later; see LICENSE.txt
|
||||
*/
|
||||
|
||||
namespace VDM\Joomla\Componentbuilder\Search\Service;
|
||||
|
||||
|
||||
use Joomla\DI\Container;
|
||||
use Joomla\DI\ServiceProviderInterface;
|
||||
use VDM\Joomla\Componentbuilder\Search\Model\Load;
|
||||
use VDM\Joomla\Componentbuilder\Search\Model\Insert;
|
||||
|
||||
|
||||
/**
|
||||
* Model Service Provider
|
||||
*
|
||||
* @since 3.2.0
|
||||
*/
|
||||
class Model implements ServiceProviderInterface
|
||||
{
|
||||
/**
|
||||
* Registers the service provider with a DI container.
|
||||
*
|
||||
* @param Container $container The DI container.
|
||||
*
|
||||
* @return void
|
||||
* @since 3.2.0
|
||||
*/
|
||||
public function register(Container $container)
|
||||
{
|
||||
$container->alias(Load::class, 'Load.Model')
|
||||
->share('Load.Model', [$this, 'getModelLoad'], true);
|
||||
$container->alias(Insert::class, 'Insert.Model')
|
||||
->share('Insert.Model', [$this, 'getModelInsert'], true);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the Load Model
|
||||
*
|
||||
* @param Container $container The DI container.
|
||||
*
|
||||
* @return Load
|
||||
* @since 3.2.0
|
||||
*/
|
||||
public function getModelLoad(Container $container): Load
|
||||
{
|
||||
return new Load(
|
||||
$container->get('Config'),
|
||||
$container->get('Table')
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the Insert Model
|
||||
*
|
||||
* @param Container $container The DI container.
|
||||
*
|
||||
* @return Insert
|
||||
* @since 3.2.0
|
||||
*/
|
||||
public function getModelInsert(Container $container): Insert
|
||||
{
|
||||
return new Insert(
|
||||
$container->get('Config'),
|
||||
$container->get('Table')
|
||||
);
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -0,0 +1,149 @@
|
||||
<?php
|
||||
/**
|
||||
* @package Joomla.Component.Builder
|
||||
*
|
||||
* @created 4th September, 2022
|
||||
* @author Llewellyn van der Merwe <https://dev.vdm.io>
|
||||
* @git Joomla Component Builder <https://git.vdm.dev/joomla/Component-Builder>
|
||||
* @copyright Copyright (C) 2015 Vast Development Method. All rights reserved.
|
||||
* @license GNU General Public License version 2 or later; see LICENSE.txt
|
||||
*/
|
||||
|
||||
namespace VDM\Joomla\Componentbuilder\Search\Service;
|
||||
|
||||
|
||||
use Joomla\DI\Container;
|
||||
use Joomla\DI\ServiceProviderInterface;
|
||||
use VDM\Joomla\Componentbuilder\Search\Config;
|
||||
use VDM\Joomla\Componentbuilder\Table;
|
||||
use VDM\Joomla\Componentbuilder\Search\Interfaces\SearchTypeInterface as SearchEngine;
|
||||
use VDM\Joomla\Componentbuilder\Search\Engine\Regex;
|
||||
use VDM\Joomla\Componentbuilder\Search\Engine\Basic;
|
||||
|
||||
|
||||
/**
|
||||
* Search Service Provider
|
||||
*
|
||||
* @since 3.2.0
|
||||
*/
|
||||
class Search implements ServiceProviderInterface
|
||||
{
|
||||
/**
|
||||
* Selected search engine
|
||||
*
|
||||
* @var int
|
||||
* @since 3.2.0
|
||||
**/
|
||||
protected $searchEngine = 101;
|
||||
|
||||
/**
|
||||
* Registers the service provider with a DI container.
|
||||
*
|
||||
* @param Container $container The DI container.
|
||||
*
|
||||
* @return void
|
||||
* @since 3.2.0
|
||||
*/
|
||||
public function register(Container $container)
|
||||
{
|
||||
$container->alias(Config::class, 'Config')
|
||||
->share('Config', [$this, 'getConfig'], true);
|
||||
|
||||
$container->alias(Table::class, 'Table')
|
||||
->share('Table', [$this, 'getTable'], true);
|
||||
|
||||
$container->alias(Regex::class, 'Search.Regex')
|
||||
->share('Search.Regex', [$this, 'getRegex'], true);
|
||||
|
||||
$container->alias(Basic::class, 'Search.Basic')
|
||||
->share('Search.Basic', [$this, 'getBasic'], true);
|
||||
|
||||
$container->alias(SearchEngine::class, 'Search')
|
||||
->share('Search', [$this, 'getSearch'], true);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the Config
|
||||
*
|
||||
* @param Container $container The DI container.
|
||||
*
|
||||
* @return Config
|
||||
* @since 3.2.0
|
||||
*/
|
||||
public function getConfig(Container $container): Config
|
||||
{
|
||||
return new Config();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the Table
|
||||
*
|
||||
* @param Container $container The DI container.
|
||||
*
|
||||
* @return Table
|
||||
* @since 3.2.0
|
||||
*/
|
||||
public function getTable(Container $container): Table
|
||||
{
|
||||
return new Table();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the Regex Type Search Engine
|
||||
*
|
||||
* @param Container $container The DI container.
|
||||
*
|
||||
* @return Regex
|
||||
* @since 3.2.0
|
||||
*/
|
||||
public function getRegex(Container $container): Regex
|
||||
{
|
||||
return new Regex(
|
||||
$container->get('Config')
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the Basic Type Search Engine
|
||||
*
|
||||
* @param Container $container The DI container.
|
||||
*
|
||||
* @return Basic
|
||||
* @since 3.2.0
|
||||
*/
|
||||
public function getBasic(Container $container): Basic
|
||||
{
|
||||
return new Basic(
|
||||
$container->get('Config')
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the Search Engine
|
||||
*
|
||||
* @param Container $container The DI container.
|
||||
*
|
||||
* @return SearchEngine
|
||||
* @since 3.2.0
|
||||
*/
|
||||
public function getSearch(Container $container): SearchEngine
|
||||
{
|
||||
// set the search engine to use for this container
|
||||
if ($this->searchEngine == 101)
|
||||
{
|
||||
$this->searchEngine = (int) $container->get('Config')->regex_search;
|
||||
}
|
||||
|
||||
// get the correct type of search engine
|
||||
if ($this->searchEngine == 1)
|
||||
{
|
||||
return $container->get('Search.Regex');
|
||||
}
|
||||
|
||||
// the default is the basic
|
||||
return $container->get('Search.Basic');
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
@@ -0,0 +1 @@
|
||||
<html><body bgcolor="#FFFFFF"></body></html>
|
@@ -0,0 +1 @@
|
||||
<html><body bgcolor="#FFFFFF"></body></html>
|
Reference in New Issue
Block a user