diff --git a/README.md b/README.md index a1d6920..a815096 100644 --- a/README.md +++ b/README.md @@ -43,9 +43,14 @@ This repository contains an index (see below) of all the approved powers within - **interface LoadInterface** | [Details](src/2ad31f74-f579-499d-b98b-c4f54fd615dd) | [Code](src/2ad31f74-f579-499d-b98b-c4f54fd615dd/code.php) | [Settings](src/2ad31f74-f579-499d-b98b-c4f54fd615dd/settings.json) | [2ad31f74-f579-499d-b98b-c4f54fd615dd](src/2ad31f74-f579-499d-b98b-c4f54fd615dd) - **interface Mapperdoubleinterface** | [Details](src/fbc58009-fa16-4d49-a0dd-419c3b62d42f) | [Code](src/fbc58009-fa16-4d49-a0dd-419c3b62d42f/code.php) | [Settings](src/fbc58009-fa16-4d49-a0dd-419c3b62d42f/settings.json) | [fbc58009-fa16-4d49-a0dd-419c3b62d42f](src/fbc58009-fa16-4d49-a0dd-419c3b62d42f) - **interface Mappersingleinterface** | [Details](src/78527c29-24ad-4735-ad4c-ec33a4952d9b) | [Code](src/78527c29-24ad-4735-ad4c-ec33a4952d9b/code.php) | [Settings](src/78527c29-24ad-4735-ad4c-ec33a4952d9b/settings.json) | [78527c29-24ad-4735-ad4c-ec33a4952d9b](src/78527c29-24ad-4735-ad4c-ec33a4952d9b) - - **interface ModelInterface** | [Details](src/8aef58c1-3f70-4bd4-b9e4-3f29fcd41cff) | [Code](src/8aef58c1-3f70-4bd4-b9e4-3f29fcd41cff/code.php) | [Settings](src/8aef58c1-3f70-4bd4-b9e4-3f29fcd41cff/settings.json) | [8aef58c1-3f70-4bd4-b9e4-3f29fcd41cff](src/8aef58c1-3f70-4bd4-b9e4-3f29fcd41cff) - **interface Serverinterface** | [Details](src/86ac0760-26f5-4746-9c7f-ce77860f80f8) | [Code](src/86ac0760-26f5-4746-9c7f-ce77860f80f8/code.php) | [Settings](src/86ac0760-26f5-4746-9c7f-ce77860f80f8/settings.json) | [86ac0760-26f5-4746-9c7f-ce77860f80f8](src/86ac0760-26f5-4746-9c7f-ce77860f80f8) - **interface Tableinterface** | [Details](src/2da6d6c4-eb29-4d69-8bc2-36d96e916adf) | [Code](src/2da6d6c4-eb29-4d69-8bc2-36d96e916adf/code.php) | [Settings](src/2da6d6c4-eb29-4d69-8bc2-36d96e916adf/settings.json) | [2da6d6c4-eb29-4d69-8bc2-36d96e916adf](src/2da6d6c4-eb29-4d69-8bc2-36d96e916adf) +- **Namespace**: [VDM\Joomla\Componentbuilder\Power](#vdm-joomla-componentbuilder-power) + + - **final class Grep** | [Details](src/6784dd52-0909-451a-a872-9a942a023c68) | [Code](src/6784dd52-0909-451a-a872-9a942a023c68/code.php) | [Settings](src/6784dd52-0909-451a-a872-9a942a023c68/settings.json) | [6784dd52-0909-451a-a872-9a942a023c68](src/6784dd52-0909-451a-a872-9a942a023c68) +- **Namespace**: [VDM\Joomla\Componentbuilder\Utilities](#vdm-joomla-componentbuilder-utilities) + + - **class Constantpaths** | [Details](src/e0c8c931-52a0-4171-9909-e8769505bb1f) | [Code](src/e0c8c931-52a0-4171-9909-e8769505bb1f/code.php) | [Settings](src/e0c8c931-52a0-4171-9909-e8769505bb1f/settings.json) | [e0c8c931-52a0-4171-9909-e8769505bb1f](src/e0c8c931-52a0-4171-9909-e8769505bb1f) - **Namespace**: [VDM\Joomla\Componentbuilder\Compiler\Adminview](#vdm-joomla-componentbuilder-compiler-adminview) - **class Data** | [Details](src/cef2815b-f72b-402a-b769-f028f676692d) | [Code](src/cef2815b-f72b-402a-b769-f028f676692d/code.php) | [Settings](src/cef2815b-f72b-402a-b769-f028f676692d/settings.json) | [cef2815b-f72b-402a-b769-f028f676692d](src/cef2815b-f72b-402a-b769-f028f676692d) @@ -194,7 +199,6 @@ This repository contains an index (see below) of all the approved powers within - **abstract class FieldHelper** | [Details](src/7a5fd3f3-199e-43ba-a8e8-f473d6c030ec) | [Code](src/7a5fd3f3-199e-43ba-a8e8-f473d6c030ec/code.php) | [Settings](src/7a5fd3f3-199e-43ba-a8e8-f473d6c030ec/settings.json) | [7a5fd3f3-199e-43ba-a8e8-f473d6c030ec](src/7a5fd3f3-199e-43ba-a8e8-f473d6c030ec) - **abstract class Indent** | [Details](src/a68c010b-e92e-47d5-8a44-d23cfddeb6c6) | [Code](src/a68c010b-e92e-47d5-8a44-d23cfddeb6c6/code.php) | [Settings](src/a68c010b-e92e-47d5-8a44-d23cfddeb6c6/settings.json) | [a68c010b-e92e-47d5-8a44-d23cfddeb6c6](src/a68c010b-e92e-47d5-8a44-d23cfddeb6c6) - **abstract class Line** | [Details](src/4e6ff11d-bebf-42f5-8fd7-b2f882857222) | [Code](src/4e6ff11d-bebf-42f5-8fd7-b2f882857222/code.php) | [Settings](src/4e6ff11d-bebf-42f5-8fd7-b2f882857222/settings.json) | [4e6ff11d-bebf-42f5-8fd7-b2f882857222](src/4e6ff11d-bebf-42f5-8fd7-b2f882857222) - - **abstract class Minify** | [Details](src/b591855d-d106-4fe5-90ad-8e706f6267cf) | [Code](src/b591855d-d106-4fe5-90ad-8e706f6267cf/code.php) | [Settings](src/b591855d-d106-4fe5-90ad-8e706f6267cf/settings.json) | [b591855d-d106-4fe5-90ad-8e706f6267cf](src/b591855d-d106-4fe5-90ad-8e706f6267cf) - **abstract class Placefix** | [Details](src/500f3a7f-c16d-4dd4-81b2-2df6776b5388) | [Code](src/500f3a7f-c16d-4dd4-81b2-2df6776b5388/code.php) | [Settings](src/500f3a7f-c16d-4dd4-81b2-2df6776b5388/settings.json) | [500f3a7f-c16d-4dd4-81b2-2df6776b5388](src/500f3a7f-c16d-4dd4-81b2-2df6776b5388) - **abstract class Unique** | [Details](src/f02fb1df-f4b6-4be1-9595-2e72084a5e6e) | [Code](src/f02fb1df-f4b6-4be1-9595-2e72084a5e6e/code.php) | [Settings](src/f02fb1df-f4b6-4be1-9595-2e72084a5e6e/settings.json) | [f02fb1df-f4b6-4be1-9595-2e72084a5e6e](src/f02fb1df-f4b6-4be1-9595-2e72084a5e6e) - **class Counter** | [Details](src/e6d871a6-bbe7-497d-af01-68f6bb9a87f4) | [Code](src/e6d871a6-bbe7-497d-af01-68f6bb9a87f4/code.php) | [Settings](src/e6d871a6-bbe7-497d-af01-68f6bb9a87f4/settings.json) | [e6d871a6-bbe7-497d-af01-68f6bb9a87f4](src/e6d871a6-bbe7-497d-af01-68f6bb9a87f4) @@ -266,6 +270,7 @@ namespace VDM\Joomla\Componentbuilder\Compiler #Olive { class Config #Gold { # JoomlaRegistry $config + __construct() + # getGiteatoken() : ?string # getAddcontributors() : bool # getAddajax() : bool # getAddsiteajax() : bool @@ -303,6 +308,7 @@ namespace VDM\Joomla\Componentbuilder\Compiler #Olive { # getCompilerpath() : string # getJcbpowerspath() : string # getLocalpowersrepositorypath() : string + # getApprovedpaths() : array # getBompath() : string # getCustomfolderpath() : string # getAddassetstablefix() : int @@ -312,6 +318,7 @@ namespace VDM\Joomla\Componentbuilder\Compiler #Olive { # getAddplaceholders() : bool # getAddpower() : bool # getAddsuperpowers() : bool + # getAddownpowers() : bool # getBuildtarget() : string # getCryptiontypes() : array # getBasicencryption() : bool @@ -464,9 +471,11 @@ namespace VDM\Joomla\Componentbuilder\Interfaces #Olive { } interface InsertInterface #Lavender { + + defaults() : void + rows() : bool + items() : bool + row() : bool + + item() : bool } interface LoadInterface #Lavender { @@ -495,13 +504,6 @@ namespace VDM\Joomla\Componentbuilder\Interfaces #Olive { + remove() : void } - interface ModelInterface #Lavender { - + value() : mixed - + item() : ?object - + items() : ?array - + last() : ?int - } - interface Serverinterface #Lavender { + set() : self + move() : bool @@ -518,6 +520,56 @@ namespace VDM\Joomla\Componentbuilder\Interfaces #Olive { } +@enduml +``` + +## VDM Joomla Componentbuilder Power +> namespace VDM\Joomla\Componentbuilder\Power +```uml +@startuml + +namespace VDM\Joomla\Componentbuilder\Power #Olive { + + + class Grep << (F,LightGreen) >> #Green { + + string $path + + ?array $paths + # Contents $contents + # CMSApplication $app + + __construct() + + get() : ?object + - searchLocal() : ?object + - searchRemote() : ?object + - getLocal() : ?object + - getRemote() : ?object + - init() : void + - localIndex() : void + - remoteIndex() : void + - loadRemoteFile() : mixed + - getCode() : ?string + - getLicense() : ?string + } +} + + +@enduml +``` + +## VDM Joomla Componentbuilder Utilities +> namespace VDM\Joomla\Componentbuilder\Utilities +```uml +@startuml + +namespace VDM\Joomla\Componentbuilder\Utilities #Olive { + + + class Constantpaths #Gold { + # array $paths + + get() : array|string|null + } +} + + @enduml ``` @@ -1607,6 +1659,7 @@ namespace VDM\Joomla\Componentbuilder\Compiler\Power #LightGreen { - setPowers() : void - index() : string - code() : string + - raw() : string - linker() : string } @@ -1832,6 +1885,7 @@ namespace VDM\Joomla\Componentbuilder\Compiler\Service #LightGreen { class Power #Gold { + register() : void + getPowers() : Powers + + getGrep() : Grep + getAutoloader() : Autoloader + getInfusion() : Infusion + getStructure() : Structure @@ -1911,11 +1965,6 @@ namespace VDM\Joomla\Componentbuilder\Compiler\Utilities #LightGreen { - {static} init() : void } - abstract Minify #Orange { - + {static} js() : string - + {static} css() : string - } - abstract Placefix #Orange { + {static} _() : string + {static} b() : string diff --git a/src/01411bb1-fdd6-4cca-84d7-1b62d93c70c1/code.power b/src/01411bb1-fdd6-4cca-84d7-1b62d93c70c1/code.power new file mode 100644 index 0000000..a16e1a0 --- /dev/null +++ b/src/01411bb1-fdd6-4cca-84d7-1b62d93c70c1/code.power @@ -0,0 +1,856 @@ + /** + * The placeholder keys + * + * @var array + * @since 3.2.0 + */ + protected array $PKeys + = [ + 1 => 'REPLACE<>$$$$]', + 2 => 'INSERT<>$$$$]', + 3 => 'REPLACED<>$$$$]', + 4 => 'INSERTED<>$$$$]' + ]; + + /** + * The custom code in local files that already exist in system + * + * @var array + * @since 3.2.0 + */ + protected array $existing = []; + + /** + * The custom code in local files that are new + * + * @var array + * @since 3.2.0 + */ + protected array $new = []; + + /** + * The index of code already loaded + * + * @var array + * @since 3.2.0 + */ + protected array $done = []; + + /** + * The search counter + * + * @var array + * @since 3.2.0 + */ + protected array $counter = [1 => 0, 2 => 0]; + + /** + * The file types to search + * + * @var array + * @since 3.2.0 + */ + protected array $fileTypes = ['\.php', '\.js', '\.xml']; + + /** + * The local placeholders + * + * @var array + * @since 3.2.0 + */ + protected array $placeholders; + + /** + * Today's date in SQL format + * + * @var string + * @since 3.2.0 + */ + protected string $today; + + /** + * Compiler Config + * + * @var Config + * @since 3.2.0 + **/ + protected Config $config; + + /** + * Compiler Customcode Gui + * + * @var Gui + * @since 3.2.0 + **/ + protected Gui $gui; + + /** + * Compiler Customcode Extractor Paths + * + * @var Paths + * @since 3.2.0 + **/ + protected Paths $paths; + + /** + * Compiler Placeholder Reverse + * + * @var Reverse + * @since 3.2.0 + **/ + protected Reverse $reverse; + + /** + * Compiler Component Placeholder + * + * @var Placeholder + * @since 3.2.0 + **/ + protected Placeholder $componentPlaceholder; + + /** + * Compiler Component Pathfix + * + * @var Pathfix + * @since 3.2.0 + **/ + protected Pathfix $pathfix; + + /** + * Current User Object + * + * @var User + * @since 3.2.0 + **/ + protected User $user; + + /** + * Database object to query local DB + * + * @var \JDatabaseDriver + * @since 3.2.0 + **/ + protected \JDatabaseDriver $db; + + /** + * Database object to query local DB + * + * @var CMSApplication + * @since 3.2.0 + **/ + protected CMSApplication $app; + + /** + * Constructor. + * + * @param Config|null $config The compiler config object. + * @param Gui|null $gui The compiler customcode gui object. + * @param Paths|null $paths The compiler customcode extractor paths object. + * @param Reverse|null $reverse The compiler placeholder reverse object. + * @param Placeholder|null $placeholder The compiler component placeholder object. + * @param Pathfix|null $pathfix The compiler path fixing object. + * @param User|null $user The current User object. + * @param \JDatabaseDriver|null $db The Database Driver object. + * @param CMSApplication|null $app The CMS Application object. + * + * @throws \Exception + * @since 3.2.0 + */ + public function __construct(?Config $config = null, ?Gui $gui = null, ?Paths $paths = null, + ?Reverse $reverse = null, ?Placeholder $placeholder = null, ?Pathfix $pathfix = null, + ?User $user = null, ?\JDatabaseDriver $db = null, ?CMSApplication $app = null) + { + $this->config = $config ?: Compiler::_('Config'); + $this->gui = $gui ?: Compiler::_('Customcode.Gui'); + $this->paths = $paths ?: Compiler::_('Customcode.Extractor.Paths'); + $this->reverse = $reverse ?: Compiler::_('Placeholder.Reverse'); + $this->componentPlaceholder = $placeholder ?: Compiler::_('Component.Placeholder'); + $this->pathfix = $pathfix ?: Compiler::_('Utilities.Pathfix'); + $this->user = $user ?: Factory::getUser(); + $this->db = $db ?: Factory::getDbo(); + $this->app = $app ?: Factory::getApplication(); + + // set today's date + $this->today = Factory::getDate()->toSql(); + + // set some local placeholders + $placeholders = array_flip( + $this->componentPlaceholder->get() + ); + + $placeholders[StringHelper::safe( + $this->config->component_code_name, 'F' + ) . 'Helper::'] = Placefix::_('Component') . 'Helper::'; + + $placeholders['COM_' . StringHelper::safe( + $this->config->component_code_name, 'U' + )] = 'COM_' . Placefix::_('COMPONENT'); + + $placeholders['com_' . $this->config->component_code_name] = 'com_' . Placefix::_('component'); + + // set the local placeholders + $this->placeholders = array_reverse($placeholders, true); + } + + /** + * get the custom code from the local files + * + * @return void + * @since 3.2.0 + */ + public function run() + { + // we must first store the current working directory + $joomla = getcwd(); + + foreach ($this->paths->active as $target => $path) + { + // we are changing the working directory to the component path + chdir($path); + foreach ($this->fileTypes as $type) + { + // get a list of files in the current directory tree (only PHP, JS and XML for now) + $files = Folder::files('.', $type, true, true); + + // check if files found + if (ArrayHelper::check($files)) + { + foreach ($files as $file) + { + // search the file + $this->searchFileContent($file, $target); + + // insert new code + $this->insert(100); + + // update existing custom code + $this->update(30); + } + } + } + } + + // change back to Joomla working directory + chdir($joomla); + + // make sure all code is stored + $this->insert(); + // update existing custom code + $this->update(); + } + + /** + * search a file for placeholders and store result + * + * @param string $file The file path to search + * + * @return array on success + * @since 3.2.0 + */ + protected function searchFileContent(&$file, &$target) + { + // we add a new search for the GUI CODE Blocks + $this->gui->search($file, $this->placeholders, $this->today, $target); + + // reset each time per file + $loadEndFingerPrint = false; + $endFingerPrint = []; + $fingerPrint = []; + $codeBucket = []; + $pointer = []; + $reading = []; + $reader = 0; + + // reset found Start type + $commentType = 0; + + // make sure we have the path correct (the script file is not in admin path for example) + // there may be more... will nead to keep our eye on this... since files could be moved during install + $file = str_replace('./', '', (string) $file); # TODO (windows path issues) + $path = $file !== 'script.php' ? $target . '/' . $file : $file; + + // now we go line by line + foreach (new \SplFileObject($file) as $lineNumber => $lineContent) + { + // we must keep last few lines to dynamic find target entry later + $fingerPrint[$lineNumber] = trim($lineContent); + + // load the end fingerprint + if ($loadEndFingerPrint) + { + $endFingerPrint[$lineNumber] = trim($lineContent); + } + + foreach ($this->PKeys as $type => $search) + { + $i = (int) ($type == 3 || $type == 4) ? 2 : 1; + $_type = (int) ($type == 1 || $type == 3) ? 1 : 2; + + if ($reader === 0 || $reader === $i) + { + $targetKey = $type; + + $start = '/***[' . $search . '***/'; + $end = '/***[/' . $search . '***/'; + $startHTML = ''; + $endHTML = ''; + + // check if the ending placeholder was found + if (isset($reading[$targetKey]) && $reading[$targetKey] + && ((trim((string) $lineContent) === $end + || strpos((string) $lineContent, $end) !== false) + || (trim((string) $lineContent) === $endHTML + || strpos((string) $lineContent, $endHTML) !== false))) + { + // trim the placeholder and if there is still data then load it + if (isset($endReplace) + && ($_line = $this->addLineChecker($endReplace, 2, $lineContent)) !== false) + { + $codeBucket[$pointer[$targetKey]][] = $_line; + } + + // deactivate the reader + $reading[$targetKey] = false; + + if ($_type == 2) + { + // deactivate search + $reader = 0; + } + else + { + // activate fingerPrint for replacement end target + $loadEndFingerPrint = true; + $backupTargetKey = $targetKey; + $backupI = $i; + } + + // all new records we can do a bulk insert + if ($i === 1) + { + // end the bucket info for this code block + $this->new[$pointer[$targetKey]][] + = $this->db->quote( + (int) $lineNumber + ); // 'toline' + + // first reverse engineer this code block + $c0de = $this->reverse->engine( + implode('', $codeBucket[$pointer[$targetKey]]), + $this->placeholders, $target + ); + + $this->new[$pointer[$targetKey]][] + = $this->db->quote( + base64_encode((string) $c0de) + ); // 'code' + + if ($_type == 2) + { + // load the last value + $this->new[$pointer[$targetKey]][] + = $this->db->quote(0); // 'hashendtarget' + } + } + // the record already exist so we must update instead + elseif ($i === 2) + { + // end the bucket info for this code block + $this->existing[$pointer[$targetKey]]['fields'][] + = $this->db->quoteName('to_line') . ' = ' + . $this->db->quote($lineNumber); + + // first reverse engineer this code block + $c0de = $this->reverse->engine( + implode('', $codeBucket[$pointer[$targetKey]]), + $this->placeholders, $target, + $this->existing[$pointer[$targetKey]]['id'] + ); + + $this->existing[$pointer[$targetKey]]['fields'][] + = $this->db->quoteName('code') . ' = ' + . $this->db->quote(base64_encode((string) $c0de)); + + if ($_type == 2) + { + // load the last value + $this->existing[$pointer[$targetKey]]['fields'][] + = $this->db->quoteName('hashendtarget') + . ' = ' . $this->db->quote(0); + } + } + } + + // check if the endfingerprint is ready to save + if (count((array) $endFingerPrint) === 3) + { + $hashendtarget = '3__' . md5( + implode('', $endFingerPrint) + ); + + // all new records we can do a bulk insert + if ($i === 1) + { + // load the last value + $this->new[$pointer[$targetKey]][] + = $this->db->quote( + $hashendtarget + ); // 'hashendtarget' + } + // the record already exist so we must update + elseif ($i === 2) + { + $this->existing[$pointer[$targetKey]]['fields'][] + = $this->db->quoteName('hashendtarget') . ' = ' + . $this->db->quote($hashendtarget); + } + + // reset the needed values + $endFingerPrint = []; + $loadEndFingerPrint = false; + + // deactivate reader (to allow other search) + $reader = 0; + } + + // then read in the code + if (isset($reading[$targetKey]) && $reading[$targetKey]) + { + $codeBucket[$pointer[$targetKey]][] = $lineContent; + } + + // see if the custom code line starts now with PHP/JS comment type + if ((!isset($reading[$targetKey]) || !$reading[$targetKey]) + && (($i === 1 && trim((string) $lineContent) === $start) + || strpos((string) $lineContent, $start) !== false)) + { + $commentType = 1; // PHP/JS type + $startReplace = $start; + $endReplace = $end; + } + // see if the custom code line starts now with HTML comment type + elseif ((!isset($reading[$targetKey]) + || !$reading[$targetKey]) + && (($i === 1 && trim((string) $lineContent) === $startHTML) + || strpos((string) $lineContent, $startHTML) !== false)) + { + $commentType = 2; // HTML type + $startReplace = $startHTML; + $endReplace = $endHTML; + } + + // check if the starting place holder was found + if ($commentType > 0) + { + // if we have all on one line we have a problem (don't load it TODO) + if (strpos((string) $lineContent, (string) $endReplace) !== false) + { + // reset found comment type + $commentType = 0; + $this->app->enqueueMessage( + Text::_('

Custom Codes Warning

'), + 'Warning' + ); + $this->app->enqueueMessage( + Text::sprintf('We found dynamic code all in one line, and ignored it! Please review (%s) for more details!', + $path + ), 'Warning' + ); + continue; + } + + // do a quick check to insure we have an id + $id = false; + if ($i === 2) + { + $id = $this->getSystemID( + $lineContent, + array(1 => $start, 2 => $startHTML), + $commentType + ); + } + + if ($i === 2 && $id > 0) + { + // make sure we update it only once even if found again. + if (isset($this->done[$id])) + { + // reset found comment type + $commentType = 0; + continue; + } + // store the id to avoid duplication + $this->done[$id] = (int) $id; + } + + // start replace + $startReplace = $this->setStartReplace( + $id, $commentType, $startReplace + ); + + // set active reader (to lock out other search) + $reader = $i; + + // set pointer + $pointer[$targetKey] = $this->counter[$i]; + + // activate the reader + $reading[$targetKey] = true; + + // start code bucket + $codeBucket[$pointer[$targetKey]] = []; + + // trim the placeholder and if there is still data then load it + if ($_line = $this->addLineChecker( + $startReplace, 1, $lineContent + )) + { + $codeBucket[$pointer[$targetKey]][] = $_line; + } + + // get the finger print around the custom code + $inFinger = count($fingerPrint); + $getFinger = $inFinger - 1; + $hasharray = array_slice( + $fingerPrint, -$inFinger, $getFinger, true + ); + $hasleng = count($hasharray); + $hashtarget = $hasleng . '__' . md5( + implode('', $hasharray) + ); + + // for good practice + $this->pathfix->set($path); + + // all new records we can do a bulk insert + if ($i === 1 || !$id) + { + // start the bucket for this code + $this->new[$pointer[$targetKey]] = []; + $this->new[$pointer[$targetKey]][] + = $this->db->quote( + $path + ); // 'path' + + $this->new[$pointer[$targetKey]][] + = $this->db->quote( + (int) $_type + ); // 'type' + + $this->new[$pointer[$targetKey]][] + = $this->db->quote( + 1 + ); // 'target' + + $this->new[$pointer[$targetKey]][] + = $this->db->quote( + $commentType + ); // 'comment_type' + + $this->new[$pointer[$targetKey]][] + = $this->db->quote( + (int) $this->config->component_id + ); // 'component' + + $this->new[$pointer[$targetKey]][] + = $this->db->quote( + 1 + ); // 'published' + + $this->new[$pointer[$targetKey]][] + = $this->db->quote( + $this->today + ); // 'created' + + $this->new[$pointer[$targetKey]][] + = $this->db->quote( + (int) $this->user->id + ); // 'created_by' + + $this->new[$pointer[$targetKey]][] + = $this->db->quote( + 1 + ); // 'version' + + $this->new[$pointer[$targetKey]][] + = $this->db->quote( + 1 + ); // 'access' + + $this->new[$pointer[$targetKey]][] + = $this->db->quote( + $hashtarget + ); // 'hashtarget' + + $this->new[$pointer[$targetKey]][] + = $this->db->quote( + (int) $lineNumber + ); // 'fromline' + + } + // the record already exist so we must update instead + elseif ($i === 2 && $id > 0) + { + // start the bucket for this code + $this->existing[$pointer[$targetKey]] = []; + $this->existing[$pointer[$targetKey]]['id'] + = (int) $id; + $this->existing[$pointer[$targetKey]]['conditions'] = []; + $this->existing[$pointer[$targetKey]]['conditions'][] + = $this->db->quoteName('id') . ' = ' + . $this->db->quote($id); + $this->existing[$pointer[$targetKey]]['fields'] = []; + $this->existing[$pointer[$targetKey]]['fields'][] + = $this->db->quoteName('path') . ' = ' + . $this->db->quote($path); + $this->existing[$pointer[$targetKey]]['fields'][] + = $this->db->quoteName('type') . ' = ' + . $this->db->quote($_type); + $this->existing[$pointer[$targetKey]]['fields'][] + = $this->db->quoteName('comment_type') . ' = ' + . $this->db->quote($commentType); + $this->existing[$pointer[$targetKey]]['fields'][] + = $this->db->quoteName('component') . ' = ' + . $this->db->quote($this->config->component_id); + $this->existing[$pointer[$targetKey]]['fields'][] + = $this->db->quoteName('from_line') . ' = ' + . $this->db->quote($lineNumber); + $this->existing[$pointer[$targetKey]]['fields'][] + = $this->db->quoteName('modified') . ' = ' + . $this->db->quote($this->today); + $this->existing[$pointer[$targetKey]]['fields'][] + = $this->db->quoteName('modified_by') . ' = ' + . $this->db->quote($this->user->id); + $this->existing[$pointer[$targetKey]]['fields'][] + = $this->db->quoteName('hashtarget') . ' = ' + . $this->db->quote($hashtarget); + } + else // this should actualy never happen + { + // de activate the reader + $reading[$targetKey] = false; + $reader = 0; + } + + // reset found comment type + $commentType = 0; + // update the counter + $this->counter[$i]++; + } + } + } + + // make sure only a few lines is kept at a time + if (count((array) $fingerPrint) > 10) + { + $fingerPrint = array_slice($fingerPrint, -6, 6, true); + } + } + + // if the code is at the end of the page and there were not three more lines + if (count((array) $endFingerPrint) > 0 || $loadEndFingerPrint) + { + if (count((array) $endFingerPrint) > 0) + { + $leng = count($endFingerPrint); + $hashendtarget = $leng . '__' . md5( + implode('', $endFingerPrint) + ); + } + else + { + $hashendtarget = 0; + } + + // all new records we can do a buldk insert + if ($backupI === 1) + { + // load the last value + $this->new[$pointer[$backupTargetKey]][] + = $this->db->quote($hashendtarget); // 'hashendtarget' + } + // the record already exist so we must use module to update + elseif ($backupI === 2) + { + $this->existing[$pointer[$backupTargetKey]]['fields'][] + = $this->db->quoteName('hashendtarget') . ' = ' + . $this->db->quote($hashendtarget); + } + } + } + + /** + * Insert the code + * + * @param int $when To set when to update + * + * @return void + * @since 3.2.0 + */ + protected function insert(int $when = 1) + { + if (ArrayHelper::check($this->new) >= $when) + { + // Create a new query object. + $query = $this->db->getQuery(true); + $continue = false; + // Insert columns. + $columns = array('path', 'type', 'target', 'comment_type', + 'component', 'published', 'created', 'created_by', + 'version', 'access', 'hashtarget', 'from_line', + 'to_line', 'code', 'hashendtarget'); + // Prepare the insert query. + $query->insert( + $this->db->quoteName('#__componentbuilder_custom_code') + ); + $query->columns($this->db->quoteName($columns)); + foreach ($this->new as $values) + { + if (count((array) $values) == 15) + { + $query->values(implode(',', $values)); + $continue = true; + } + else + { + // TODO line mismatch... should not happen + } + } + // clear the values array + $this->new = []; + if (!$continue) + { + return; // insure we don't continue if no values were loaded + } + // Set the query using our newly populated query object and execute it. + $this->db->setQuery($query); + $this->db->execute(); + } + } + + /** + * Update the code + * + * @param int $when To set when to update + * + * @return void + * @since 3.2.0 + */ + protected function update(int $when = 1) + { + if (ArrayHelper::check($this->existing) >= $when) + { + foreach ($this->existing as $code) + { + // Create a new query object. + $query = $this->db->getQuery(true); + // Prepare the update query. + $query->update( + $this->db->quoteName('#__componentbuilder_custom_code') + )->set($code['fields'])->where($code['conditions']); + // Set the query using our newly populated query object and execute it. + $this->db->setQuery($query); + $this->db->execute(); + } + // clear the values array + $this->existing = []; + } + } + + /** + * set the start replace placeholder + * + * @param int $id The comment id + * @param int $commentType The comment type + * @param string $startReplace The main replace string + * + * @return string on success + * @since 3.2.0 + */ + protected function setStartReplace(int $id, int $commentType, string $startReplace): string + { + if ($id > 0) + { + switch ($commentType) + { + case 1: // the PHP & JS type + $startReplace .= '/*' . $id . '*/'; + break; + case 2: // the HTML type + $startReplace .= ''; + break; + } + } + + return $startReplace; + } + + /** + * Check if this line should be added + * + * @param string $replaceKey The key to remove from line + * @param int $type The line type + * @param string $lineContent The line to check + * + * @return bool|int true on success + * @since 3.2.0 + */ + protected function addLineChecker(string $replaceKey, int $type, string $lineContent) + { + $check = explode($replaceKey, $lineContent); + switch ($type) + { + case 1: + // beginning of code + if (isset($check[1]) && StringHelper::check($check[1])) + { + return trim($check[1]); + } + break; + case 2: + // end of code + if (isset($check[0]) && StringHelper::check($check[0])) + { + return trim($check[0]); + } + break; + } + + return false; + } + + /** + * search for the system id in the line given + * + * @param string $lineContent The file path to search + * @param array $placeholders The values to search for + * @param int $commentType The comment type + * + * @return mixed on success + * @since 3.2.0 + */ + protected function getSystemID(string &$lineContent, array $placeholders, int $commentType) + { + $trim = '/'; + if ($commentType == 2) + { + $trim = ' + if ($this->config->get('add_placeholders', false) === true) + { + return [ + 'start' => '', + 'end' => '' + ]; + } + break; + case 22: + // + if ($this->config->get('add_placeholders', false) === true) + { + return [ + 'start' => '', + 'end' => '' + ]; + } + break; + case 33: + return ['start' => Placefix::h(), 'end' => Placefix::h()]; + break; + case 66: + return ['start' => Placefix::b(), 'end' => Placefix::d()]; + break; + } + + return [ 'start' => "", 'end' => ""]; + } diff --git a/src/071c7cff-4c88-4b80-bd99-066c572dcb71/code.power b/src/071c7cff-4c88-4b80-bd99-066c572dcb71/code.power new file mode 100644 index 0000000..4976c44 --- /dev/null +++ b/src/071c7cff-4c88-4b80-bd99-066c572dcb71/code.power @@ -0,0 +1,840 @@ + /** + * Compiler Joomla Module Data Class + * + * @var Module + * @since 3.2.0 + */ + protected Module $module; + + /** + * Compiler Component + * + * @var Component + * @since 3.2.0 + **/ + protected Component $component; + + /** + * Compiler Config + * + * @var Config + * @since 3.2.0 + */ + protected Config $config; + + /** + * The compiler registry + * + * @var Registry + * @since 3.2.0 + */ + protected Registry $registry; + + /** + * Compiler Customcode Dispenser + * + * @var Dispenser + * @since 3.2.0 + */ + protected Dispenser $dispenser; + + /** + * Compiler Event + * + * @var EventInterface + * @since 3.2.0 + */ + protected EventInterface $event; + + /** + * Compiler Counter + * + * @var Counter + * @since 3.2.0 + */ + protected Counter $counter; + + /** + * Compiler Utilities Folder + * + * @var Folder + * @since 3.2.0 + */ + protected Folder $folder; + + /** + * Compiler Utilities File + * + * @var File + * @since 3.2.0 + */ + protected File $file; + + /** + * Compiler Utilities Files + * + * @var Files + * @since 3.2.0 + */ + protected Files $files; + + /** + * Constructor + * + * @param Module|null $module The compiler Joomla module data object. + * @param Component|null $component The component class. + * @param Config|null $config The compiler config object. + * @param Registry|null $registry The compiler registry object. + * @param Dispenser|null $dispenser The compiler customcode dispenser object. + * @param EventInterface|null $event The compiler event api object. + * @param Counter|null $counter The compiler counter object. + * @param Folder|null $folder The compiler folder object. + * @param File|null $file The compiler file object. + * @param Files|null $files The compiler files object. + * + * @since 3.2.0 + */ + public function __construct(?Module $module = null, ?Component $component = null, + ?Config $config = null, ?Registry $registry = null, + ?Dispenser $dispenser = null, ?EventInterface $event = null, + ?Counter $counter = null, ?Folder $folder = null, + ?File $file = null, ?Files $files = null) + { + $this->module = $module ?: Compiler::_('Joomlamodule.Data'); + $this->component = $component ?: Compiler::_('Component'); + $this->config = $config ?: Compiler::_('Config'); + $this->registry = $registry ?: Compiler::_('Registry'); + $this->dispenser = $dispenser ?: Compiler::_('Customcode.Dispenser'); + $this->event = $event ?: Compiler::_('Event'); + $this->counter = $counter ?: Compiler::_('Utilities.Counter'); + $this->folder = $folder ?: Compiler::_('Utilities.Folder'); + $this->file = $file ?: Compiler::_('Utilities.File'); + $this->files = $files ?: Compiler::_('Utilities.Files'); + } + + /** + * Build the Modules files, folders, url's and config + * + * @return void + * @since 3.2.0 + */ + public function build() + { + if ($this->module->exists()) + { + // for plugin event TODO change event api signatures + $component_context = $this->config->component_context; + $modules = $this->module->get(); + // Trigger Event: jcb_ce_onBeforeSetModules + $this->event->trigger( + 'jcb_ce_onBeforeBuildModules', + array(&$component_context, &$modules) + ); + + foreach ($modules as $module) + { + if (ObjectHelper::check($module) + && isset($module->folder_name) + && StringHelper::check( + $module->folder_name + )) + { + // module path + $module->folder_path = $this->config->get('compiler_path', JPATH_COMPONENT_ADMINISTRATOR . '/compiler') . '/' + . $module->folder_name; + + // set the module paths + $this->registry->set('dynamic_paths.' . $module->key, $module->folder_path); + + // make sure there is no old build + $this->folder->remove($module->folder_path); + + // creat the main module folder + $this->folder->create($module->folder_path); + + // set main mod file + $fileDetails = array('path' => $module->folder_path . '/' + . $module->file_name . '.php', + 'name' => $module->file_name . '.php', + 'zip' => $module->file_name . '.php'); + $this->file->write( + $fileDetails['path'], + 'files->appendArray($module->key, $fileDetails); + + // count the file created + $this->counter->file++; + + // set custom_get + if ($module->custom_get) + { + $fileDetails = array( + 'path' => $module->folder_path . '/data.php', + 'name' => 'data.php', + 'zip' => 'data.php' + ); + $this->file->write( + $fileDetails['path'], + 'official_name . ' Data' + . PHP_EOL . + ' */' . PHP_EOL . + "class " . $module->class_data_name + . ' extends \JObject' . PHP_EOL . + "{" . Placefix::_h('DYNAMICGETS') . "}" + . PHP_EOL + ); + $this->files->appendArray($module->key, $fileDetails); + + // count the file created + $this->counter->file++; + } + + // set helper file + if ($module->add_class_helper >= 1) + { + $fileDetails = array('path' => $module->folder_path + . '/helper.php', + 'name' => 'helper.php', + 'zip' => 'helper.php'); + $this->file->write( + $fileDetails['path'], + 'files->appendArray($module->key, $fileDetails); + + // count the file created + $this->counter->file++; + } + + // set main xml file + $fileDetails = array('path' => $module->folder_path . '/' + . $module->file_name . '.xml', + 'name' => $module->file_name . '.xml', + 'zip' => $module->file_name . '.xml'); + $this->file->write( + $fileDetails['path'], + $this->getXML($module) + ); + $this->files->appendArray($module->key, $fileDetails); + + // count the file created + $this->counter->file++; + + // set tmpl folder + $this->folder->create($module->folder_path . '/tmpl'); + + // set default file + $fileDetails = array('path' => $module->folder_path + . '/tmpl/default.php', + 'name' => 'default.php', + 'zip' => 'tmpl/default.php'); + $this->file->write( + $fileDetails['path'], + 'files->appendArray($module->key, $fileDetails); + + // count the file created + $this->counter->file++; + + // set install script if needed + if ($module->add_install_script) + { + $fileDetails = [ + 'path' => $module->folder_path . '/script.php', + 'name' => 'script.php', + 'zip' => 'script.php' + ]; + $this->file->write( + $fileDetails['path'], + 'files->appendArray($module->key, $fileDetails); + + // count the file created + $this->counter->file++; + } + + // set readme if found + if ($module->addreadme) + { + $fileDetails = [ + 'path' => $module->folder_path . '/README.md', + 'name' => 'README.md', + 'zip' => 'README.md' + ]; + $this->file->write($fileDetails['path'], $module->readme); + $this->files->appendArray($module->key, $fileDetails); + + // count the file created + $this->counter->file++; + } + + // set the folders target path + $target_path = ''; + if ($module->target_client === 'administrator') + { + $target_path = '/administrator'; + } + + // check if we have custom fields needed for scripts + $module->add_scripts_field = false; + $field_script_bucket = []; + + // add any css from the fields + if (($css = $this->dispenser->get( + 'css_view', $module->key + )) !== null + && StringHelper::check($css)) + { + // make sure this script does not have PHP + if (strpos((string) $css, 'add_scripts_field = true; + + // create the css folder + $this->folder->create($module->folder_path . '/css'); + + // add the CSS file + $fileDetails = [ + 'path' => $module->folder_path . '/css/mod_admin.css', + 'name' => 'mod_admin.css', + 'zip' => 'mod_admin.css' + ]; + $this->file->write( + $fileDetails['path'], + Placefix::_h('BOM') . PHP_EOL + . PHP_EOL . $css + ); + $this->files->appendArray($module->key, $fileDetails); + + // count the file created + $this->counter->file++; + + // add the field script + $field_script_bucket[] = Indent::_(2) . "//" + . Line::_(__Line__, __Class__) . " Custom CSS"; + $field_script_bucket[] = Indent::_(2) + . "\$document->addStyleSheet('" . $target_path + . "/modules/" . $module->folder_name + . "/css/mod_admin.css', ['version' => 'auto', 'relative' => true]);"; + } + } + + // add any JavaScript from the fields + if (($javascript = $this->dispenser->get( + 'view_footer', $module->key + )) !== null + && StringHelper::check($javascript)) + { + // make sure this script does not have PHP + if (strpos((string) $javascript, 'add_scripts_field = true; + + // add the JavaScript file + $this->folder->create($module->folder_path . '/js'); + + // add the CSS file + $fileDetails = [ + 'path' => $module->folder_path . '/js/mod_admin.js', + 'name' => 'mod_admin.js', + 'zip' => 'mod_admin.js' + ]; + $this->file->write( + $fileDetails['path'], + Placefix::_h('BOM') . PHP_EOL + . PHP_EOL . $javascript + ); + $this->files->appendArray($module->key, $fileDetails); + + // count the file created + $this->counter->file++; + + // add the field script + $field_script_bucket[] = Indent::_(2) . "//" + . Line::_(__Line__, __Class__) . " Custom JS"; + $field_script_bucket[] = Indent::_(2) + . "\$document->addScript('" . $target_path + . "/modules/" . $module->folder_name + . "/js/mod_admin.js', ['version' => 'auto', 'relative' => true]);"; + } + } + + // set fields folders if needed + if ($module->add_scripts_field + || (isset($module->fields_rules_paths) + && $module->fields_rules_paths == 2)) + { + // create fields folder + $this->folder->create($module->folder_path . '/fields'); + + // add the custom script field + if ($module->add_scripts_field) + { + $fileDetails = [ + 'path' => $module->folder_path + . '/fields/modadminvvvvvvvdm.php', + 'name' => 'modadminvvvvvvvdm.php', + 'zip' => 'modadminvvvvvvvdm.php' + ]; + $this->file->write( + $fileDetails['path'], + $this->getCustomScriptField( + $field_script_bucket + ) + ); + $this->files->appendArray($module->key, $fileDetails); + + // count the file created + $this->counter->file++; + } + } + + // set rules folders if needed + if (isset($module->fields_rules_paths) + && $module->fields_rules_paths == 2) + { + // create rules folder + $this->folder->create($module->folder_path . '/rules'); + } + + // set forms folder if needed + if (isset($module->form_files) + && ArrayHelper::check( + $module->form_files + )) + { + // create forms folder + $this->folder->create($module->folder_path . '/forms'); + + // set the template files + foreach ($module->form_files as $file => $fields) + { + // set file details + $fileDetails = [ + 'path' => $module->folder_path . '/forms/' . $file . '.xml', + 'name' => $file . '.xml', + 'zip' => 'forms/' . $file . '.xml' + ]; + + // build basic XML + $xml = ''; + $xml .= PHP_EOL . ''; + + // search if we must add the component path + $add_component_path = false; + foreach ($fields as $field_name => $fieldsets) + { + if (!$add_component_path) + { + foreach ($fieldsets as $fieldset => $field) + { + if (!$add_component_path + && isset( + $module->fieldsets_paths[$file + . $field_name . $fieldset] + ) + && $module->fieldsets_paths[$file + . $field_name . $fieldset] == 1) + { + $add_component_path = true; + } + } + } + } + + // only add if part of the component field types path is required + if ($add_component_path) + { + $xml .= PHP_EOL . ''; + } + else + { + $xml .= PHP_EOL . '
'; + } + + // add the fields + foreach ($fields as $field_name => $fieldsets) + { + // check if we have an double fields naming set + $field_name_inner = ''; + $field_name_outer = $field_name; + if (strpos((string) $field_name, '.') !== false) + { + $field_names = explode('.', (string) $field_name); + if (count((array) $field_names) == 2) + { + $field_name_outer = $field_names[0]; + $field_name_inner = $field_names[1]; + } + } + $xml .= PHP_EOL . Indent::_(1) + . ''; + foreach ($fieldsets as $fieldset => $field) + { + // default to the field set name + $label = $fieldset; + if (isset($module->fieldsets_label[$file . $field_name . $fieldset])) + { + $label = $module->fieldsets_label[$file . $field_name . $fieldset]; + } + + // add path to module rules and custom fields + if (isset($module->fieldsets_paths[$file . $field_name . $fieldset]) + && ($module->fieldsets_paths[$file . $field_name . $fieldset] == 2 + || $module->fieldsets_paths[$file . $field_name . $fieldset] == 3)) + { + if ($module->target == 2) + { + if (!isset($module->add_rule_path[$file . $field_name . $fieldset])) + { + $module->add_rule_path[$file . $field_name . $fieldset] = + '/administrator/modules/' + . $module->file_name . '/rules'; + } + + if (!isset($module->add_field_path[$file . $field_name . $fieldset])) + { + $module->add_field_path[$file . $field_name . $fieldset] = + '/administrator/modules/' + . $module->file_name . '/fields'; + } + } + else + { + if (!isset($module->add_rule_path[$file . $field_name . $fieldset])) + { + $module->add_rule_path[$file . $field_name . $fieldset] = + '/modules/' . $module->file_name + . '/rules'; + } + + if (!isset($module->add_field_path[$file . $field_name . $fieldset])) + { + $module->add_field_path[$file . $field_name . $fieldset] = + '/modules/' . $module->file_name + . '/fields'; + } + } + } + + // add path to module rules and custom fields + if (isset($module->add_rule_path[$file . $field_name . $fieldset]) + || isset($module->add_field_path[$file . $field_name . $fieldset])) + { + + $xml .= PHP_EOL . Indent::_(1) . ''; + + $xml .= PHP_EOL . Indent::_(1) . '
add_rule_path[$file . $field_name . $fieldset])) + { + $xml .= PHP_EOL . Indent::_(2) + . 'addrulepath="' . $module->add_rule_path[$file . $field_name . $fieldset] . '"'; + } + + if (isset($module->add_field_path[$file . $field_name . $fieldset])) + { + $xml .= PHP_EOL . Indent::_(2) + . 'addfieldpath="' . $module->add_field_path[$file . $field_name . $fieldset] . '"'; + } + + $xml .= PHP_EOL . Indent::_(1) . '>'; + } + else + { + $xml .= PHP_EOL . Indent::_(1) . '
'; + } + + // check if we have an inner field set + if (StringHelper::check( + $field_name_inner + )) + { + $xml .= PHP_EOL . Indent::_(1) + . ''; + } + + // add the placeholder of the fields + $xml .= Placefix::_h('FIELDSET_' . $file + . $field_name . $fieldset ); + + // check if we have an inner field set + if (StringHelper::check( + $field_name_inner + )) + { + $xml .= PHP_EOL . Indent::_(1) + . ''; + } + $xml .= PHP_EOL . Indent::_(1) + . '
'; + } + $xml .= PHP_EOL . Indent::_(1) . ''; + } + $xml .= PHP_EOL . ''; + + // add xml to file + $this->file->write($fileDetails['path'], $xml); + $this->files->appendArray($module->key, $fileDetails); + + // count the file created + $this->counter->file++; + } + } + + // set SQL stuff if needed + if ($module->add_sql || $module->add_sql_uninstall) + { + // create SQL folder + $this->folder->create($module->folder_path . '/sql'); + + // create mysql folder + $this->folder->create( + $module->folder_path . '/sql/mysql' + ); + + // now set the install file + if ($module->add_sql) + { + $this->file->write( + $module->folder_path . '/sql/mysql/install.sql', + $module->sql + ); + + // count the file created + $this->counter->file++; + } + + // now set the uninstall file + if ($module->add_sql_uninstall) + { + $this->file->write( + $module->folder_path + . '/sql/mysql/uninstall.sql', + $module->sql_uninstall + ); + + // count the file created + $this->counter->file++; + } + } + + // creat the language folder + $this->folder->create($module->folder_path . '/language'); + // also create the lang tag folder + $this->folder->create( + $module->folder_path . '/language/' . $this->config->get('lang_tag', 'en-GB') + ); + + // check if this lib has files + if (isset($module->files) + && ArrayHelper::check($module->files)) + { + // add to component files + foreach ($module->files as $file) + { + // set the pathfinder + $file['target_type'] = $module->target_type; + $file['target_id'] = $module->id; + $this->component->appendArray('files', $file); + } + } + + // check if this lib has folders + if (isset($module->folders) + && ArrayHelper::check($module->folders)) + { + // add to component folders + foreach ($module->folders as $folder) + { + // set the pathfinder + $folder['target_type'] = $module->target_type; + $folder['target_id'] = $module->id; + $this->component->appendArray('folders', $folder); + } + } + + // check if this module has urls + if (isset($module->urls) + && ArrayHelper::check($module->urls)) + { + // add to component urls + foreach ($module->urls as $n => &$url) + { + // should we add the local folder + if (isset($url['type']) && $url['type'] > 1 + && isset($url['url']) + && StringHelper::check( + $url['url'] + )) + { + // set file name + $fileName = basename((string) $url['url']); + + // get the file contents + $data = FileHelper::getContent( + $url['url'] + ); + + // build sub path + if (strpos($fileName, '.js') !== false) + { + $path = '/js'; + } + elseif (strpos($fileName, '.css') !== false) + { + $path = '/css'; + } + else + { + $path = ''; + } + + // create sub media path if not set + $this->folder->create( + $module->folder_path . $path + ); + + // set the path to module file + $url['path'] = $module->folder_path . $path + . '/' . $fileName; // we need this for later + + // write data to path + $this->file->write($url['path'], $data); + + // count the file created + $this->counter->file++; + } + } + } + } + } + } + } + + /** + * get the module xml template + * + * @param object $module The module object + * + * @return string + * @since 3.2.0 + */ + protected function getXML(object &$module): string + { + $xml = ''; + $xml .= PHP_EOL . ''; + $xml .= PHP_EOL . Indent::_(1) . '' . $module->lang_prefix + . ''; + $xml .= PHP_EOL . Indent::_(1) . '' . Placefix::_h('BUILDDATE') . ''; + $xml .= PHP_EOL . Indent::_(1) . '' . Placefix::_h('AUTHOR') . ''; + $xml .= PHP_EOL . Indent::_(1) . '' . Placefix::_h('AUTHOREMAIL') . ''; + $xml .= PHP_EOL . Indent::_(1) . '' . Placefix::_h('AUTHORWEBSITE') . ''; + $xml .= PHP_EOL . Indent::_(1) . '' . Placefix::_h('COPYRIGHT') . ''; + $xml .= PHP_EOL . Indent::_(1) . '' . Placefix::_h('LICENSE') . ''; + $xml .= PHP_EOL . Indent::_(1) . '' . $module->module_version + . ''; + $xml .= PHP_EOL . Indent::_(1) . '' . $module->lang_prefix + . '_XML_DESCRIPTION'; + $xml .= Placefix::_h('MAINXML'); + $xml .= PHP_EOL . ''; + + return $xml; + } + + /** + * get the module admin custom script field + * + * @param array $fieldScriptBucket The field + * + * @return string + * @since 3.2.0 + * + */ + protected function getCustomScriptField(array $fieldScriptBucket): string + { + $form_field_class = []; + $form_field_class[] = Placefix::_h('BOM') . PHP_EOL; + $form_field_class[] = "//" . Line::_(__Line__, __Class__) + . " No direct access to this file"; + $form_field_class[] = "defined('_JEXEC') or die('Restricted access');"; + $form_field_class[] = PHP_EOL . "use Joomla\CMS\Form\FormField;"; + $form_field_class[] = "use Joomla\CMS\Factory;"; + $form_field_class[] = PHP_EOL + . "class JFormFieldModadminvvvvvvvdm extends FormField"; + $form_field_class[] = "{"; + $form_field_class[] = Indent::_(1) + . "protected \$type = 'modadminvvvvvvvdm';"; + $form_field_class[] = PHP_EOL . Indent::_(1) + . "protected function getLabel()"; + $form_field_class[] = Indent::_(1) . "{"; + $form_field_class[] = Indent::_(2) . "return;"; + $form_field_class[] = Indent::_(1) . "}"; + $form_field_class[] = PHP_EOL . Indent::_(1) + . "protected function getInput()"; + $form_field_class[] = Indent::_(1) . "{"; + $form_field_class[] = Indent::_(2) . "//" . Line::_(__Line__, __Class__) + . " Get the document"; + $form_field_class[] = Indent::_(2) + . "\$document = Factory::getDocument();"; + $form_field_class[] = implode(PHP_EOL, $fieldScriptBucket); + $form_field_class[] = Indent::_(2) . "return; // noting for now :)"; + $form_field_class[] = Indent::_(1) . "}"; + $form_field_class[] = "}"; + + return implode(PHP_EOL, $form_field_class); + } diff --git a/src/0d08c583-04d5-454e-b756-48ca05e1651a/code.power b/src/0d08c583-04d5-454e-b756-48ca05e1651a/code.power new file mode 100644 index 0000000..24709a7 --- /dev/null +++ b/src/0d08c583-04d5-454e-b756-48ca05e1651a/code.power @@ -0,0 +1,379 @@ + /** + * Power Objects + * + * @var Power + * @since 3.2.0 + **/ + protected Power $power; + + /** + * Compiler Powers Plantuml Builder + * + * @var Plantuml + * @since 3.2.0 + **/ + protected Plantuml $plantuml; + + /** + * Constructor. + * + * @param Power|null $power The power object. + * @param Plantuml|null $plantuml The powers plantuml builder object. + * + * @since 3.2.0 + */ + public function __construct(?Power $power = null, ?Plantuml $plantuml = null) + { + $this->power = $power ?: Compiler::_('Power'); + $this->plantuml = $plantuml ?: Compiler::_('Power.Plantuml'); + } + + /** + * Get Super Power Readme + * + * @param array $powers All powers of this super power. + * + * @return string + * @since 3.2.0 + */ + public function get(array $powers): string + { + // build readme + $readme = ["``` +███████╗██╗ ██╗██████╗ ███████╗██████╗ +██╔════╝██║ ██║██╔══██╗██╔════╝██╔══██╗ +███████╗██║ ██║██████╔╝█████╗ ██████╔╝ +╚════██║██║ ██║██╔═══╝ ██╔══╝ ██╔══██╗ +███████║╚██████╔╝██║ ███████╗██║ ██║ +╚══════╝ ╚═════╝ ╚═╝ ╚══════╝╚═╝ ╚═╝ +██████╗ ██████╗ ██╗ ██╗███████╗██████╗ ███████╗ +██╔══██╗██╔═══██╗██║ ██║██╔════╝██╔══██╗██╔════╝ +██████╔╝██║ ██║██║ █╗ ██║█████╗ ██████╔╝███████╗ +██╔═══╝ ██║ ██║██║███╗██║██╔══╝ ██╔══██╗╚════██║ +██║ ╚██████╔╝╚███╔███╔╝███████╗██║ ██║███████║ +╚═╝ ╚═════╝ ╚══╝╚══╝ ╚══════╝╚═╝ ╚═╝╚══════╝ +```"]; + + // default description of super powers + $readme[] = "\n### What is JCB Super Powers?\nThe Joomla Component Builder (JCB) Super Power features are designed to enhance JCB's functionality and streamline the development process. These Super Powers enable developers to efficiently manage and share their custom powers across multiple JCB instances through repositories hosted on [https://git.vdm.dev/[username]/[repository-name]](https://git.vdm.dev). JCB Super Powers are managed using a combination of layers, events, tasks, methods, switches, and algorithms, which work together to provide powerful customization and extensibility options. More details on JCB Super Powers can be found in the [Super Powers Documentation](https://git.vdm.dev/joomla/super-powers/wiki).\n\nIn summary, JCB Super Powers offer a flexible and efficient way to manage and share functionalities between JCB instances. By utilizing a sophisticated system of layers, events, tasks, methods, switches, and algorithms, developers can seamlessly integrate JCB core powers and their custom powers. For more information on how to work with JCB Super Powers, refer to the [Super Powers User Guide](https://git.vdm.dev/joomla/super-powers/wiki).\n\n### What can I find here?\nThis repository contains an index (see below) of all the approved powers within the JCB GUI. During the compilation of a component, these powers are automatically added to the repository, ensuring a well-organized and accessible collection of functionalities.\n"; + + // get the readme body + $readme[] = $this->readmeBuilder($powers); + + // yes you can remove this, but why? + $readme[] = "\n---\n``` + ██╗ ██████╗ ██████╗ ███╗ ███╗██╗ █████╗ + ██║██╔═══██╗██╔═══██╗████╗ ████║██║ ██╔══██╗ + ██║██║ ██║██║ ██║██╔████╔██║██║ ███████║ +██ ██║██║ ██║██║ ██║██║╚██╔╝██║██║ ██╔══██║ +╚█████╔╝╚██████╔╝╚██████╔╝██║ ╚═╝ ██║███████╗██║ ██║ + ╚════╝ ╚═════╝ ╚═════╝ ╚═╝ ╚═╝╚══════╝╚═╝ ╚═╝ + ██████╗ ██████╗ ███╗ ███╗██████╗ ██████╗ ███╗ ██╗███████╗███╗ ██╗████████╗ +██╔════╝██╔═══██╗████╗ ████║██╔══██╗██╔═══██╗████╗ ██║██╔════╝████╗ ██║╚══██╔══╝ +██║ ██║ ██║██╔████╔██║██████╔╝██║ ██║██╔██╗ ██║█████╗ ██╔██╗ ██║ ██║ +██║ ██║ ██║██║╚██╔╝██║██╔═══╝ ██║ ██║██║╚██╗██║██╔══╝ ██║╚██╗██║ ██║ +╚██████╗╚██████╔╝██║ ╚═╝ ██║██║ ╚██████╔╝██║ ╚████║███████╗██║ ╚████║ ██║ + ╚═════╝ ╚═════╝ ╚═╝ ╚═╝╚═╝ ╚═════╝ ╚═╝ ╚═══╝╚══════╝╚═╝ ╚═══╝ ╚═╝ +██████╗ ██╗ ██╗██╗██╗ ██████╗ ███████╗██████╗ +██╔══██╗██║ ██║██║██║ ██╔══██╗██╔════╝██╔══██╗ +██████╔╝██║ ██║██║██║ ██║ ██║█████╗ ██████╔╝ +██╔══██╗██║ ██║██║██║ ██║ ██║██╔══╝ ██╔══██╗ +██████╔╝╚██████╔╝██║███████╗██████╔╝███████╗██║ ██║ +╚═════╝ ╚═════╝ ╚═╝╚══════╝╚═════╝ ╚══════╝╚═╝ ╚═╝ +```\n> Build with [Joomla Component Builder](https://git.vdm.dev/joomla/Component-Builder)\n\n"; + + return implode("\n", $readme); + } + + /** + * The readme builder + * + * @param array $classes The powers. + * + * @return string + * @since 3.2.0 + */ + private function readmeBuilder(array &$powers): string + { + $classes = []; + foreach ($powers as $guid => $power) + { + $power_object = $this->power->get($guid); + if (is_array($power_object->parsed_class_code)) + { + // add to the sort bucket + $classes[] = [ + 'namespace' => $power['namespace'], + 'type' => $power['type'], + 'name' => $power['name'], + 'link' => $this->indexLinkPower($power), + 'diagram' => $this->plantuml->classBasicDiagram($power, $power_object->parsed_class_code) + ]; + } + } + + return $this->readmeModel($classes); + } + + /** + * Sort and model the readme classes + * + * @param array $classes The powers. + * + * @return string + * @since 3.2.0 + */ + private function readmeModel(array &$classes): string + { + $this->sortClasses($classes, $this->defineTypeOrder()); + + $result = $this->generateIndex($classes); + + $diagram_bucket = $this->generateDiagramBucket($classes); + + return $result . $diagram_bucket; + } + + /** + * Generate the index string for classes + * + * @param array $classes The sorted classes + * + * @return string The index string + */ + private function generateIndex(array &$classes): string + { + $result = "# Index of powers\n"; + $current_namespace = null; + + foreach ($classes as $class) + { + if ($class['namespace'] !== $current_namespace) + { + $current_namespace = $class['namespace']; + $result .= "\n- **Namespace**: [{$current_namespace}](#" . + strtolower(str_replace('\\', '-', $current_namespace)) . ")\n"; + } + + // Add the class details + $result .= "\n - " . $class['link']; + } + + return $result; + } + + /** + * Generate the diagram bucket string for classes + * + * @param array $classes The sorted classes + * + * @return string The diagram bucket string + */ + private function generateDiagramBucket(array &$classes): string + { + $diagram_bucket = "\n\n# Class Diagrams\n"; + $current_namespace = null; + $diagrams = ''; + + foreach ($classes as $class) + { + if ($class['namespace'] !== $current_namespace) + { + if ($current_namespace !== null) + { + $diagram_bucket .= $this->generateNamespaceDiagram($current_namespace, $diagrams); + } + $current_namespace = $class['namespace']; + $diagrams = ''; + } + + $diagrams .= $class['diagram']; + } + + // Add the last namespace diagram + $diagram_bucket .= $this->generateNamespaceDiagram($current_namespace, $diagrams); + + return $diagram_bucket; + } + + /** + * Define the order of types for sorting purposes + * + * @return array The order of types + * @since 3.2.0 + */ + private function defineTypeOrder(): array + { + return [ + 'interface' => 1, + 'abstract' => 2, + 'final' => 3, + 'class' => 4, + 'trait' => 5 + ]; + } + + /** + * Sort the flattened array using a single sorting function + * + * @param array $classes The classes to sort + * @param array $typeOrder The order of types + * @since 3.2.0 + */ + private function sortClasses(array &$classes, array $typeOrder): void + { + usort($classes, function ($a, $b) use ($typeOrder) { + $namespaceDiff = $this->compareNamespace($a, $b); + + if ($namespaceDiff !== 0) + { + return $namespaceDiff; + } + + $typeDiff = $this->compareType($a, $b, $typeOrder); + + if ($typeDiff !== 0) + { + return $typeDiff; + } + + return $this->compareName($a, $b); + }); + } + + /** + * Compare the namespace of two classes + * + * @param array $a First class + * @param array $b Second class + * + * @return int Comparison result + * @since 3.2.0 + */ + private function compareNamespace(array $a, array $b): int + { + $namespaceDepthDiff = substr_count($a['namespace'], '\\') - substr_count($b['namespace'], '\\'); + + if ($namespaceDepthDiff === 0) + { + return strcmp($a['namespace'], $b['namespace']); + } + + return $namespaceDepthDiff; + } + + /** + * Compare the type of two classes + * + * @param array $a First class + * @param array $b Second class + * @param array $typeOrder The order of types + * + * @return int Comparison result + * @since 3.2.0 + */ + private function compareType(array $a, array $b, array $typeOrder): int + { + return $typeOrder[$a['type']] - $typeOrder[$b['type']]; + } + + /** + * Compare the name of two classes + * + * @param array $a First class + * @param array $b Second class + * + * @return int Comparison result + * @since 3.2.0 + */ + private function compareName(array $a, array $b): int + { + return strcmp($a['name'], $b['name']); + } + + /** + * Generate a namespace diagram string + * + * @param string $current_namespace The current namespace + * @param string $diagrams The diagrams for the namespace + * + * @return string The namespace diagram string + */ + private function generateNamespaceDiagram(string $current_namespace, string $diagrams): string + { + $namespace_title = str_replace('\\', ' ', $current_namespace); + $diagram_code = "\n## {$namespace_title}\n> namespace {$current_namespace}\n"; + $diagram_code .= "```uml\n@startuml\n\n" . + $this->plantuml->namespaceDiagram($current_namespace, $diagrams) . "\n\n@enduml\n```\n"; + + return $diagram_code; + } + + /** + * Build the Link to the power in this repository + * + * @param string $power The power details. + * + * @return string + * @since 3.2.0 + */ + private function indexLinkPower(array &$power): string + { + return '**' . $power['type'] . ' ' . $power['name'] . "** | " + . $this->linkPowerRepo($power) . ' | ' + . $this->linkPowerCode($power) . ' | ' + . $this->linkPowerSettings($power) . ' | ' + . $this->linkPowerGuid($power); + } + + /** + * Build the Link to the power in this repository + * + * @param string $power The power details. + * + * @return string + * @since 3.2.0 + */ + private function linkPowerRepo(array &$power): string + { + return '[Details](' . $power['path'] . ')'; + } + + /** + * Build the Link to the power settings in this repository + * + * @param string $power The power details. + * + * @return string + * @since 3.2.0 + */ + private function linkPowerCode(array &$power): string + { + return '[Code](' . $power['code'] . ')'; + } + + /** + * Build the Link to the power settings in this repository + * + * @param string $power The power details. + * + * @return string + * @since 3.2.0 + */ + private function linkPowerSettings(array &$power): string + { + return '[Settings](' . $power['settings'] . ')'; + } + + /** + * Build the Link with GUID text to the power in this repository + * + * @param string $power The power details. + * + * @return string + * @since 3.2.0 + */ + private function linkPowerGuid(array &$power): string + { + return '[' . $power['guid'] . '](' . $power['path'] . ')'; + } diff --git a/src/0d71c2d9-2fc0-4c20-82c5-43c46b0fc6f7/code.power b/src/0d71c2d9-2fc0-4c20-82c5-43c46b0fc6f7/code.power new file mode 100644 index 0000000..fb33092 --- /dev/null +++ b/src/0d71c2d9-2fc0-4c20-82c5-43c46b0fc6f7/code.power @@ -0,0 +1,155 @@ + /** + * Compiler Config + * + * @var Config + * @since 3.2.0 + */ + protected Config $config; + + /** + * The compiler registry + * + * @var Registry + * @since 3.2.0 + */ + protected Registry $registry; + + /** + * Constructor + * + * @param Config|null $config The compiler config object. + * @param Registry|null $registry The compiler registry object. + * + * @since 3.2.0 + */ + public function __construct(?Config $config = null, ?Registry $registry = null) + { + $this->config = $config ?: Compiler::_('Config'); + $this->registry = $registry ?: Compiler::_('Registry'); + } + + /** + * Automatically load some stuff + * + * @param string $key The key mapper + * @param string $content The content to search through + * @param string|null $target The area being targeted + * + * @return void + * @since 3.2.0 + */ + public function set(string $key, string $content, ?string $target = null) + { + // set the target + $target = $target ?: $this->config->build_target; + + // check for footable + if (!$this->registry-> + exists('builder.footable_scripts.' . $target . '.' . $key)) + { + if ($this->getFootableScripts($content)) + { + $this->registry-> + set('builder.footable_scripts.' . $target . '.' . $key, true); + + $this->config->set('footable', true); + } + } + + // check for google chart + if (!$this->registry-> + exists('builder.google_chart.' . $target . '.' . $key)) + { + if ($this->getGoogleChart($content)) + { + $this->registry-> + set('builder.google_chart.' . $target . '.' . $key, true); + + $this->config->set('google_chart', true); + } + } + + // check for get module + if (!$this->registry-> + exists('builder.get_module.' . $target . '.' . $key)) + { + if ($this->getGetModule($content)) + { + $this->registry-> + set('builder.get_module.' . $target . '.' . $key, true); + } + } + } + + /** + * Automatically load uikit version 2 data files + * + * @param string $key The key mapper + * @param string $content The content to search through + * + * @return void + * @since 3.2.0 + */ + public function uikit(string $key, string $content) + { + // get/set uikit state + $uikit = false; + $uikit_ = $this->config->get('uikit', 0); + + // add uikit if required + if (2 == $uikit_ || 1 == $uikit_) + { + $uikit = true; + } + + // load uikit + if ($uikit) + { + // set uikit to views TODO: convert this getUikitComp to a class + if (($found = Helper::_('getUikitComp', + [$content, (array) $this->registry->get('builder.uikit_comp.' . $key, [])] + )) !== false) + { + $this->registry->set('builder.uikit_comp.' . $key, $found); + } + } + } + + /** + * Check for footable scripts + * + * @param string $content The content to check + * + * @return boolean True if found + * @since 3.2.0 + */ + protected function getFootableScripts(string &$content): bool + { + return strpos($content, 'footable') !== false; + } + + /** + * Check for getModules script + * + * @param string $content The content to check + * + * @return boolean True if found + * @since 3.2.0 + */ + protected function getGetModule(string &$content): bool + { + return strpos($content, 'this->getModules(') !== false; + } + + /** + * Check for get Google Chart script + * + * @param string $content The content to check + * + * @return boolean True if found + * @since 3.2.0 + */ + protected function getGoogleChart(string &$content): bool + { + return strpos($content, 'Chartbuilder(') !== false; + } diff --git a/src/0dabc67c-abec-4541-82bf-279abd3c9be1/code.power b/src/0dabc67c-abec-4541-82bf-279abd3c9be1/code.power new file mode 100644 index 0000000..b1c7981 --- /dev/null +++ b/src/0dabc67c-abec-4541-82bf-279abd3c9be1/code.power @@ -0,0 +1,21 @@ + /** + * Set the local tabs + * + * @param object $item The view data + * + * @return void + * @since 3.2.0 + */ + public function set(object &$item) + { + $item->addpermissions = (isset($item->addpermissions) + && JsonHelper::check($item->addpermissions)) + ? json_decode((string) $item->addpermissions, true) : null; + + if (ArrayHelper::check($item->addpermissions)) + { + $item->permissions = array_values($item->addpermissions); + } + + unset($item->addpermissions); + } diff --git a/src/1133c2d7-ba7e-4c95-8cde-01f084d04682/code.power b/src/1133c2d7-ba7e-4c95-8cde-01f084d04682/code.power new file mode 100644 index 0000000..e27f4a2 --- /dev/null +++ b/src/1133c2d7-ba7e-4c95-8cde-01f084d04682/code.power @@ -0,0 +1,20 @@ + /** + * load all the powers linked to this component + * + * @param array $guids The global unique ids of the linked powers + * + * @return void + * @since 3.2.0 + */ + public function load(array $guids); + + /** + * Get a power + * + * @param string $guid The global unique id of the power + * @param int $build Force build switch (to override global switch) + * + * @return mixed + * @since 3.2.0 + */ + public function get(string $guid, int $build = 0); \ No newline at end of file diff --git a/src/143ac6ea-b64f-4331-9a97-31e3fce2bb69/code.power b/src/143ac6ea-b64f-4331-9a97-31e3fce2bb69/code.power new file mode 100644 index 0000000..ef56d52 --- /dev/null +++ b/src/143ac6ea-b64f-4331-9a97-31e3fce2bb69/code.power @@ -0,0 +1,43 @@ + /** + * Set the local tabs + * + * @param object $item The view data + * + * @return void + * @since 3.2.0 + */ + public function set(object &$item) + { + $item->addtabs = (isset($item->addtabs) + && JsonHelper::check($item->addtabs)) + ? json_decode((string) $item->addtabs, true) : null; + + if (ArrayHelper::check($item->addtabs)) + { + $nr = 1; + foreach ($item->addtabs as $tab) + { + $item->tabs[$nr] = trim((string) $tab['name']); + $nr++; + } + } + + // if Details tab is not set, then set it here + if (!isset($item->tabs[1])) + { + $item->tabs[1] = 'Details'; + } + + // always make sure that publishing is lowercase + if (($removeKey = array_search( + 'publishing', array_map('strtolower', $item->tabs) + )) !== false) + { + $item->tabs[$removeKey] = 'publishing'; + } + + // make sure to set the publishing tab (just in case we need it) + $item->tabs[15] = 'publishing'; + + unset($item->addtabs); + } diff --git a/src/17a728e9-d6cf-4060-9efb-241b0ff2f981/code.power b/src/17a728e9-d6cf-4060-9efb-241b0ff2f981/code.power new file mode 100644 index 0000000..65ca78a --- /dev/null +++ b/src/17a728e9-d6cf-4060-9efb-241b0ff2f981/code.power @@ -0,0 +1,117 @@ + /** + * The compiler Config + * + * @var Config + * @since 3.2.0 + */ + protected Config $config; + + /** + * The compiler history + * + * @var HistoryInterface + * @since 3.2.0 + */ + protected HistoryInterface $history; + + /** + * The compiler update sql + * + * @var Updatesql + * @since 3.2.0 + */ + protected Updatesql $updatesql; + + /** + * Constructor + * + * @param Config|null $config The compiler config object. + * @param HistoryInterface|null $history The compiler history object. + * @param Updatesql|null $updatesql The compiler updatesql object. + * + * @since 3.2.0 + */ + public function __construct(?Config $config = null, ?HistoryInterface $history = null, + ?Updatesql $updatesql = null) + { + $this->config = $config ?: Compiler::_('Config'); + $this->history = $history ?: Compiler::_('History'); + $this->updatesql = $updatesql ?: Compiler::_('Model.Updatesql'); + } + + /** + * check if an update SQL is needed + * + * @param object $item The item data + * + * @return void + * @since 3.2.0 + */ + public function set(object &$item) + { + // update SQL for admin views + $this->setAdminView($item); + + // update SQL for component + $this->setComponent($item); + } + + /** + * check if an update SQL is needed + * + * @param object $item The item data + * + * @return void + * @since 3.2.0 + */ + private function setAdminView(object $item) + { + $old_admin_views = $this->history->get( + 'component_admin_views', $item->addadmin_views_id + ); + + // add new views if found + if ($old_admin_views && ObjectHelper::check($old_admin_views)) + { + if (isset($old_admin_views->addadmin_views) + && JsonHelper::check( + $old_admin_views->addadmin_views + )) + { + $this->updatesql->set( + json_decode((string) $old_admin_views->addadmin_views, true), + $item->addadmin_views, 'adminview' + ); + } + } + } + + /** + * Set the component history + * + * @param object $item The item data + * + * @return void + * @since 3.2.0 + */ + private function setComponent(object &$item) + { + $old_component = $this->history->get( + 'joomla_component', $this->config->component_id + ); + + // check if a new version was manually set + if ($old_component && ObjectHelper::check($old_component)) + { + $old_component_version = preg_replace( + '/[^0-9.]+/', '', (string) $old_component->component_version + ); + if ($old_component_version != $this->config->component_version) + { + // yes, this is a new version, this mean there may + // be manual sql and must be checked and updated + $item->old_component_version + = $old_component_version; + } + } + } diff --git a/src/1aefb8f5-486f-4f00-adf9-696340b3254e/code.power b/src/1aefb8f5-486f-4f00-adf9-696340b3254e/code.power new file mode 100644 index 0000000..1e41e81 --- /dev/null +++ b/src/1aefb8f5-486f-4f00-adf9-696340b3254e/code.power @@ -0,0 +1,23 @@ + /** + * The extension official name + * + * @return string + * @since 3.2.0 + */ + public function getOfficialName(): string; + + /** + * The extension class name + * + * @return string + * @since 3.2.0 + */ + public function getClassName(): string; + + /** + * The extension installer class name + * + * @return string + * @since 3.2.0 + */ + public function getInstallerClassName(): string; \ No newline at end of file diff --git a/src/1bd48df2-4f7e-4581-9fe9-4b54e59105e3/code.power b/src/1bd48df2-4f7e-4581-9fe9-4b54e59105e3/code.power new file mode 100644 index 0000000..4a5a78f --- /dev/null +++ b/src/1bd48df2-4f7e-4581-9fe9-4b54e59105e3/code.power @@ -0,0 +1,214 @@ + /** + * Compiler Config + * + * @var Config + * @since 3.2.0 + **/ + protected Config $config; + + /** + * Compiler Placeholder Reverse + * + * @var Reverse + * @since 3.2.0 + **/ + protected Reverse $reverse; + + /** + * Database object to query local DB + * + * @var \JDatabaseDriver + * @since 3.2.0 + **/ + protected \JDatabaseDriver $db; + + /** + * Database object to query local DB + * + * @var CMSApplication + * @since 3.2.0 + **/ + protected CMSApplication $app; + + /** + * Constructor. + * + * @param Config|null $config The compiler config object. + * @param Reverse|null $reverse The compiler placeholder reverse object. + * @param \JDatabaseDriver|null $db The Database Driver object. + * @param CMSApplication|null $app The CMS Application object. + * + * @throws \Exception + * @since 3.2.0 + */ + public function __construct(?Config $config = null, ?Reverse $reverse = null, + ?\JDatabaseDriver $db = null, ?CMSApplication $app = null) + { + $this->config = $config ?: Compiler::_('Config'); + $this->reverse = $reverse ?: Compiler::_('Placeholder.Reverse'); + $this->db = $db ?: Factory::getDbo(); + $this->app = $app ?: Factory::getApplication(); + } + + /** + * Set the JCB GUI code placeholder + * + * @param string $string The code string + * @param array $config The placeholder config values + * + * @return string + * @since 3.2.0 + */ + public function set(string $string, array $config): string + { + if (StringHelper::check($string)) + { + if ($this->config->get('add_placeholders', false) + && $this->check($string) && ArrayHelper::check($config) + && isset($config['table']) && StringHelper::check($config['table']) + && isset($config['field']) && StringHelper::check($config['field']) + && isset($config['type']) && StringHelper::check($config['type']) + && isset($config['id']) && is_numeric($config['id'])) + { + // if we have a key we must get the ID + if (isset($config['key']) && StringHelper::check($config['key']) && $config['key'] !== 'id') + { + if (($id = GetHelper::var($config['table'], $config['id'], $config['key'], 'id')) !== false && is_numeric($id)) + { + $config['id'] = $id; + } + else + { + // we must give a error message to inform the user of this issue. (should never happen) + $this->app->enqueueMessage( + Text::sprintf('ID mismatch was detected with the %s.%s.%s.%s GUI code field. So the placeholder was not set.', + $config['table'], $config['field'], + $config['key'], $config['id'] + ), 'Error' + ); + // check some config + if (!isset($config['prefix'])) + { + $config['prefix'] = ''; + } + + return $config['prefix'] . $string; + } + } + // check some config + if (!isset($config['prefix'])) + { + $config['prefix'] = PHP_EOL; + } + // add placeholder based on type of code + switch (strtolower((string) $config['type'])) + { + // adding with html commenting + case 'html': + $front = $config['prefix'] . '' . PHP_EOL; + $back = '' + ); + + if (($guiCode = ArrayHelper::merge($guiCode)) !== false + && ArrayHelper::check($guiCode, true)) + { + foreach ($guiCode as $code) + { + $first_line = strtok($code, PHP_EOL); + // get the GUI target details + $query = explode('.', trim($first_line, '.')); + // only continue if we have 3 values in the query + if (is_array($query) && count($query) >= 3) + { + // cleanup the newlines around the code + $code = trim(str_replace($first_line, '', (string) $code), PHP_EOL) + . PHP_EOL; + // set the ID + $id = (int) $query[2]; + // make the field name save + $field = FieldHelper::safe($query[1]); + // make the table name save + $table = StringHelper::safe($query[0]); + // reverse placeholder as much as we can + $code = $this->reverse->engine( + $code, $placeholders, $target, $id, $field, $table + ); + // update the GUI/Tables/Database + $object = new \stdClass(); + $object->id = $id; + $object->{$field} = base64_encode( + (string) $code + ); // (TODO) this may not always work... + // update the value in GUI + $this->db->updateObject( + '#__componentbuilder_' . (string) $table, $object, 'id' + ); + } + } + } + } + + /** + * search a code to see if there is already any custom + * code or other reasons not to add the GUI code placeholders + * + * @param string $code The code to check + * + * @return bool true if GUI code placeholders can be added + * @since 3.2.0 + */ + protected function check(string &$code): bool + { + // check for customcode placeholders + // we do not add GUI wrapper placeholder to code + // that already has any customcode placeholders + return strpos($code, '$$$$') === false; + } diff --git a/src/1cef0266-99e2-40d8-919f-c2ce32226b0a/code.power b/src/1cef0266-99e2-40d8-919f-c2ce32226b0a/code.power new file mode 100644 index 0000000..b1ccd03 --- /dev/null +++ b/src/1cef0266-99e2-40d8-919f-c2ce32226b0a/code.power @@ -0,0 +1,361 @@ + /** + * The external code/string to be added + * + * @var array + * @since 3.2.0 + */ + protected array $code = []; + + /** + * The external code/string cutter + * + * @var array + * @since 3.2.0 + */ + protected array $cutter = []; + + /** + * Compiler Placeholder + * + * @var Placeholder + * @since 3.2.0 + **/ + protected Placeholder $placeholder; + + /** + * Database object to query local DB + * + * @var \JDatabaseDriver + * @since 3.2.0 + **/ + protected \JDatabaseDriver $db; + + /** + * User object + * + * @var User + * @since 3.2.0 + **/ + protected User $user; + + /** + * Database object to query local DB + * + * @var CMSApplication + * @since 3.2.0 + **/ + protected CMSApplication $app; + + /** + * Constructor. + * + * @param Placeholder|null $placeholder The compiler placeholder object. + * @param \JDatabaseDriver|null $db The Database Driver object. + * @param User|null $user The User object. + * @param CMSApplication|null $app The CMS Application object. + * + * @throws \Exception + * @since 3.2.0 + */ + public function __construct(?Placeholder $placeholder = null, + ?\JDatabaseDriver $db = null, ?User $user = null, ?CMSApplication $app = null) + { + $this->placeholder = $placeholder ?: Compiler::_('Placeholder'); + $this->db = $db ?: Factory::getDbo(); + $this->user = $user ?: Factory::getUser(); + $this->app = $app ?: Factory::getApplication(); + } + + /** + * Set the external code string & load it in to string + * + * @param string $string The content to check + * @param int $debug The switch to debug the update + * + * @return string + * @since 3.2.0 + */ + public function set(string $string, int $debug = 0): string + { + // check if content has custom code placeholder + if (strpos($string, '[EXTERNA' . 'LCODE=') !== false) + { + // if debug + if ($debug) + { + echo 'External Code String:'; + var_dump($string); + } + // target content + $bucket = []; + $found = GetHelper::allBetween( + $string, '[EXTERNA' . 'LCODE=', ']' + ); + if (ArrayHelper::check($found)) + { + // build local bucket + foreach ($found as $target) + { + // check for cutting sequence + // example: >{3|4 + // will cut 3 rows at top and 4 rows at bottom + // if the external code has 8 or more lines + if (($pos = strpos((string) $target, '>{')) !== false) + { + // the length + $target_len = strlen((string) $target); + // where to cut + $cutting = $target_len - $pos; + // get the sequence + $sequence = substr((string) $target, "-$cutting"); + // remove from the URL + $target_url = str_replace($sequence, '', (string) $target); + // set the cut key for this target if not set + $this->cutter[trim((string) $target)] = str_replace('>{', '', $sequence); + } + else + { + $target_url = $target; + } + // check if the target is valid URL or path + if ((!filter_var($target_url, FILTER_VALIDATE_URL) === false + && FileHelper::exists($target_url)) + || (Path::clean($target_url) === $target_url + && FileHelper::exists($target_url))) + { + $this->getCode($target, $bucket); + } + // give notice that target is not a valid url/path + else + { + // set key + $key = '[EXTERNA' . 'LCODE=' . $target . ']'; + // set the notice + $this->app->enqueueMessage( + Text::_('

External Code Warning

' + ), 'Warning' + ); + $this->app->enqueueMessage( + Text::sprintf('The %s is not a valid url/path!', + $key + ), 'Warning' + ); + // remove the placeholder + $bucket[$key] = ''; + } + } + // now update local string if bucket has values + if (ArrayHelper::check($bucket)) + { + $string = $this->placeholder->update($string, $bucket); + } + } + // if debug + if ($debug) + { + echo 'External Code String After Update:'; + var_dump($string); + } + } + + return $string; + } + + /** + * Get the External Code/String + * + * @param string $string The content to check + * @param array $bucket The Placeholders bucket + * + * @return void + * @since 3.2.0 + */ + protected function getCode(string $target, array &$bucket) + { + // set URL key + $target_key = trim($target); + // set key + $key = '[EXTERNA' . 'LCODE=' . $target . ']'; + // remove the cut sequence from the url + if (isset($this->cutter[$target_key])) + { + // remove from the URL + $target_url = trim(str_replace('>{' . $this->cutter[$target_key], '', $target)); + } + else + { + $target_url = trim($target); + } + // check if we already fetched this + if (!isset($this->code[$target_key])) + { + // get the data string (code) + $this->code[$target_key] + = FileHelper::getContent($target_url); + // check if we must cut this + if (isset($this->cutter[$target_key]) && + $this->cutter[$target_key]) + { + $this->code[$target_key] = $this->cut( + $this->code[$target_key], + $this->cutter[$target_key], + $key + ); + } + // did we get any value + if (StringHelper::check( + $this->code[$target_key] + )) + { + // check for changes + $live_hash = md5($this->code[$target_key]); + // check if it exists local + if ($hash = GetHelper::var( + 'external_code', $target_key, 'target', 'hash' + )) + { + // must be an admin make a change to use EXTERNAL code (we may add a custom access switch - use ADMIN for now) + if ($hash !== $live_hash && $this->user->authorise( + 'core.admin', 'com_componentbuilder' + )) + { + // update the hash since it changed + $object = new \stdClass(); + $object->target = $target_key; + $object->hash = $live_hash; + // update local hash + $this->db->updateObject( + '#__componentbuilder_external_code', $object, + 'target' + ); + // give notice of the change + $this->app->enqueueMessage( + Text::_('

External Code Warning

'), + 'Warning' + ); + $this->app->enqueueMessage( + Text::sprintf('The code/string from %s has been changed since the last compilation. Please investigate to ensure the changes are safe! Should you not expect this change to the external code/string being added, then this is a serious issue! and requires immediate attention! Do not ignore this warning as it will only show once.', + $key + ), 'Warning' + ); + } + elseif ($hash !== $live_hash) + { + // set the notice + $this->app->enqueueMessage( + Text::_('

External Code Error

'), + 'Error' + ); + $this->app->enqueueMessage( + Text::sprintf('%s, we detected a change in EXTERNALCODE, but you do not have permission to allow this change so %s was removed from the compilation. Please contact your system administrator for more info!
(admin access required)', + $this->user->get('name'), $key + ), 'Error' + ); + // remove the code/string + $this->code[$target_key] = ''; + } + } + // only an admin can add new EXTERNAL code (we may add a custom access switch - use ADMIN for now) + elseif ($this->user->authorise( + 'core.admin', 'com_componentbuilder' + )) + { + // add the hash to track changes + $object = new \stdClass(); + $object->target = $target_key; + $object->hash = $live_hash; + // insert local hash + $this->db->insertObject( + '#__componentbuilder_external_code', $object + ); + // give notice the first time this is added + $this->app->enqueueMessage( + Text::_('

External Code Notice

'), + 'Warning' + ); + $this->app->enqueueMessage( + Text::sprintf('The code/string from %s has been added for the first time. Please investigate to ensure the correct code/string was used! Should you not know about this NEW external code/string being added, then this is a serious danger! and requires immediate attention! Do not ignore this warning as it will only show once.', + $key + ), 'Warning' + ); + } + else + { + // set the notice + $this->app->enqueueMessage( + Text::_('

External Code Error

'), + 'Error' + ); + $this->app->enqueueMessage( + Text::sprintf('%s, we detected NEW EXTERNALCODE, but you do not have permission to allow this new code/string so %s was removed from the compilation. Please contact you system administrator for more info!
(admin access required)', + $this->user->get('name'), $key + ), 'Error' + ); + // remove the code/string + $this->code[$target_key] = ''; + } + } + else + { + // set notice that we could not get a valid string from the target + $this->app->enqueueMessage( + Text::_('

External Code Warning

'), 'Error' + ); + $this->app->enqueueMessage( + Text::sprintf('The %s returned an invalid string!', $key + ), 'Error' + ); + } + } + + // add to local bucket + $bucket[$key] = $this->code[$target_key] ?? ''; + } + + /** + * Cut the External Code/String + * + * @param string $string The content to cut + * @param string $sequence The cutting sequence + * @param string $key The content key + * + * @return string + * @since 3.2.0 + */ + protected function cut(string $string, string $sequence, string $key): string + { + // we first break the string up in rows + $rows = (array) explode(PHP_EOL, $string); + // get the cutting sequence + $cutter = (array) explode('|', $sequence); + // we only continue if we have more rows than we have to cut + if (array_sum($cutter) < ArrayHelper::check($rows)) + { + // remove the rows at the bottom if needed + if (isset($cutter[1]) && $cutter[1] > 0) + { + array_splice($rows, "-$cutter[1]"); + } + // remove the rows at the top if needed + if ($cutter[0] > 0) + { + $rows = array_splice($rows, $cutter[0]); + } + + // return the remaining rows + return implode(PHP_EOL, $rows); + } + + // we set an error message about too few lines to cut + $this->app->enqueueMessage( + Text::_('

External Code Notice

'), + 'Error' + ); + $this->app->enqueueMessage( + Text::sprintf('The %s cut sequence failed on the returned external code/string as more lines has to be cut then was found in the code/string. We have completely removed the code. Please check this code/string!', + $key + ), 'Error' + ); + + return ''; + } diff --git a/src/1d0fd857-12ec-4f47-ab1c-124d85748e24/code.power b/src/1d0fd857-12ec-4f47-ab1c-124d85748e24/code.power new file mode 100644 index 0000000..f4bfbaa --- /dev/null +++ b/src/1d0fd857-12ec-4f47-ab1c-124d85748e24/code.power @@ -0,0 +1,51 @@ + /** + * Set version updates + * + * @param object $item The item data + * + * @return void + * @since 3.2.0 + */ + public function set(object &$item) + { + // set the version updates + $item->version_update = (isset($item->version_update) + && JsonHelper::check($item->version_update)) + ? json_decode((string) $item->version_update, true) : null; + if (ArrayHelper::check($item->version_update)) + { + $item->version_update = array_values( + $item->version_update + ); + + // set the change log details + $this->changelog($item); + } + } + + /** + * Set changelog values to component changelog + * + * @param object $item The item data + * + * @return void + * @since 3.2.0 + */ + protected function changelog(object &$item) + { + // set the version updates + $bucket = []; + foreach ($item->version_update as $update) + { + if (isset($update['change_log']) && StringHelper::check($update['change_log']) + && isset($update['version']) && StringHelper::check($update['version'])) + { + $bucket[] = '# v' . $update['version'] . PHP_EOL . PHP_EOL . $update['change_log']; + } + } + + if (ArrayHelper::check($bucket)) + { + $item->changelog = implode(PHP_EOL . PHP_EOL, $bucket); + } + } diff --git a/src/1d929017-a5de-4e0f-9b5a-838934857e26/code.power b/src/1d929017-a5de-4e0f-9b5a-838934857e26/code.power new file mode 100644 index 0000000..89c3249 --- /dev/null +++ b/src/1d929017-a5de-4e0f-9b5a-838934857e26/code.power @@ -0,0 +1,339 @@ + /** + * The extension + * + * @var InstallInterface|Object + * @since 3.2.0 + */ + protected object $extension; + + /** + * The methods + * + * @var array + * @since 3.2.0 + */ + protected array $methods = ['php_script', 'php_preflight', 'php_postflight', 'php_method']; + + /** + * The types + * + * @var array + * @since 3.2.0 + */ + protected array $types = ['construct', 'install', 'update', 'uninstall', 'discover_install']; + + /** + * The construct bucket + * + * @var array + * @since 3.2.0 + */ + protected array $construct = []; + + /** + * The install bucket + * + * @var array + * @since 3.2.0 + */ + protected array $install = []; + + /** + * The update bucket + * + * @var array + * @since 3.2.0 + */ + protected array $update = []; + + /** + * The uninstall bucket + * + * @var array + * @since 3.2.0 + */ + protected array $uninstall = []; + + /** + * The preflight switch + * + * @var bool + * @since 3.2.0 + */ + protected bool $preflightActive = false; + + /** + * The preflight bucket + * + * @var array + * @since 3.2.0 + */ + protected array $preflightBucket = ['install' => [], 'uninstall' => [], 'discover_install' => [], 'update' => []]; + + /** + * The postflight switch + * + * @var bool + * @since 3.2.0 + */ + protected bool $postflightActive = false; + + /** + * The postflight bucket + * + * @var array + * @since 3.2.0 + */ + protected array $postflightBucket = ['install' => [], 'uninstall' => [], 'discover_install' => [], 'update' => []]; + + /** + * get install script + * + * @param Object $extension The extension object + * + * @return string + * @since 3.2.0 + */ + public function get(object $extension): string + { + // loop over methods and types + foreach ($this->methods as $method) + { + foreach ($this->types as $type) + { + if (isset($extension->{'add_' . $method . '_' . $type}) + && $extension->{'add_' . $method . '_' . $type} == 1 + && StringHelper::check( + $extension->{$method . '_' . $type} + )) + { + // add to the main methods + if ('php_method' === $method || 'php_script' === $method) + { + $this->{$type}[] = $extension->{$method . '_' . $type}; + } + else + { + // get the flight key + $flight = str_replace('php_', '', (string) $method); + // load the script to our bucket + $this->{$flight . 'Bucket'}[$type][] = $extension->{$method . '_' . $type}; + // show that the method is active + $this->{$flight . 'Active'} = true; + } + } + } + } + + $this->extension = $extension; + + // return the class + return $this->build(); + } + + /** + * build the install class + * + * @return string + * @since 3.2.0 + */ + protected function build(): string + { + // start build + $script = $this->head(); + + // load constructor if set + $script .= $this->construct(); + + // load install method if set + $script .= $this->main('install'); + + // load update method if set + $script .= $this->main('update'); + + // load uninstall method if set + $script .= $this->main('uninstall'); + + // load preflight method if set + $script .= $this->flight('preflight'); + + // load postflight method if set + $script .= $this->flight('postflight'); + + // close the class + $script .= PHP_EOL . '}' . PHP_EOL; + + return $script; + } + + /** + * get install script head + * + * @return string + * @since 3.2.0 + */ + protected function head(): string + { + // get the extension + $extension = $this->extension; + + // start build + $script = PHP_EOL . '/**'; + $script .= PHP_EOL . ' * ' . $extension->official_name + . ' script file.'; + $script .= PHP_EOL . ' *'; + $script .= PHP_EOL . ' * @package ' . $extension->class_name; + $script .= PHP_EOL . ' */'; + $script .= PHP_EOL . 'class ' . $extension->installer_class_name; + $script .= PHP_EOL . '{'; + + return $script; + } + + /** + * get constructor + * + * @return string + * @since 3.2.0 + */ + protected function construct(): string + { + // return empty string if not set + if (!ArrayHelper::check($this->construct)) + { + return ''; + } + + // the __construct script + $script = PHP_EOL . PHP_EOL . Indent::_(1) . '/**'; + $script .= PHP_EOL . Indent::_(1) . ' * Constructor'; + $script .= PHP_EOL . Indent::_(1) . ' *'; + $script .= PHP_EOL . Indent::_(1) + . ' * @param Joomla\CMS\Installer\InstallerAdapter $adapter The object responsible for running this script'; + $script .= PHP_EOL . Indent::_(1) . ' */'; + $script .= PHP_EOL . Indent::_(1) + . 'public function __construct($adapter)'; + $script .= PHP_EOL . Indent::_(1) . '{'; + $script .= PHP_EOL . implode(PHP_EOL . PHP_EOL, $this->construct); + // close the function + $script .= PHP_EOL . Indent::_(1) . '}'; + + return $script; + } + + /** + * build main methods + * + * @param string $name the method being called + * + * @return string + * @since 3.2.0 + */ + protected function main(string $name): string + { + // return empty string if not set + if (!ArrayHelper::check($this->{$name})) + { + return ''; + } + // load the install method + $script = PHP_EOL . PHP_EOL . Indent::_(1) . '/**'; + $script .= PHP_EOL . Indent::_(1) . " * Called on $name"; + $script .= PHP_EOL . Indent::_(1) . ' *'; + $script .= PHP_EOL . Indent::_(1) + . ' * @param Joomla\CMS\Installer\InstallerAdapter $adapter The object responsible for running this script'; + $script .= PHP_EOL . Indent::_(1) . ' *'; + $script .= PHP_EOL . Indent::_(1) + . ' * @return boolean True on success'; + $script .= PHP_EOL . Indent::_(1) . ' */'; + $script .= PHP_EOL . Indent::_(1) . 'public function ' + . $name . '($adapter)'; + $script .= PHP_EOL . Indent::_(1) . '{'; + $script .= PHP_EOL . implode(PHP_EOL . PHP_EOL, $this->{$name}); + // return true + if ('uninstall' !== $name) + { + $script .= PHP_EOL . Indent::_(2) . 'return true;'; + } + // close the function + $script .= PHP_EOL . Indent::_(1) . '}'; + + return $script; + } + + /** + * build flight methods + * + * @param string $name the method being called + * + * @return string + * @since 3.2.0 + */ + protected function flight(string $name): string + { + // return empty string if not set + if (empty($this->{$name . 'Active'})) + { + return ''; + } + + // the pre/post function types + $script = PHP_EOL . PHP_EOL . Indent::_(1) . '/**'; + $script .= PHP_EOL . Indent::_(1) + . ' * Called before any type of action'; + $script .= PHP_EOL . Indent::_(1) . ' *'; + $script .= PHP_EOL . Indent::_(1) + . ' * @param string $route Which action is happening (install|uninstall|discover_install|update)'; + $script .= PHP_EOL . Indent::_(1) + . ' * @param Joomla\CMS\Installer\InstallerAdapter $adapter The object responsible for running this script'; + $script .= PHP_EOL . Indent::_(1) . ' *'; + $script .= PHP_EOL . Indent::_(1) + . ' * @return boolean True on success'; + $script .= PHP_EOL . Indent::_(1) . ' */'; + $script .= PHP_EOL . Indent::_(1) . 'public function ' + . $name . '($route, $adapter)'; + $script .= PHP_EOL . Indent::_(1) . '{'; + $script .= PHP_EOL . Indent::_(2) . '//' . Line::_(__Line__, __Class__) + . ' get application'; + $script .= PHP_EOL . Indent::_(2) + . '$app = JFactory::getApplication();' . PHP_EOL; + + // add the default version check (TODO) must make this dynamic + if ('preflight' === $name) + { + $script .= PHP_EOL . Indent::_(2) . '//' . Line::_(__Line__, __Class__) + .' the default for both install and update'; + $script .= PHP_EOL . Indent::_(2) + . '$jversion = new JVersion();'; + $script .= PHP_EOL . Indent::_(2) + . "if (!\$jversion->isCompatible('3.8.0'))"; + $script .= PHP_EOL . Indent::_(2) . '{'; + $script .= PHP_EOL . Indent::_(3) + . "\$app->enqueueMessage('Please upgrade to at least Joomla! 3.8.0 before continuing!', 'error');"; + $script .= PHP_EOL . Indent::_(3) . 'return false;'; + $script .= PHP_EOL . Indent::_(2) . '}' . PHP_EOL; + } + + // now add the scripts + foreach ($this->{$name . 'Bucket'} as $route => $_script) + { + if (ArrayHelper::check($_script)) + { + // set the if and script + $script .= PHP_EOL . Indent::_(2) . "if ('" . $route + . "' === \$route)"; + $script .= PHP_EOL . Indent::_(2) . '{'; + $script .= PHP_EOL . implode( + PHP_EOL . PHP_EOL, $_script + ); + $script .= PHP_EOL . Indent::_(2) . '}' . PHP_EOL; + } + } + + // return true + $script .= PHP_EOL . Indent::_(2) . 'return true;'; + // close the function + $script .= PHP_EOL . Indent::_(1) . '}'; + + return $script; + } diff --git a/src/1d967151-7c20-4ca7-9400-65233cdcd4db/code.power b/src/1d967151-7c20-4ca7-9400-65233cdcd4db/code.power new file mode 100644 index 0000000..69309b0 --- /dev/null +++ b/src/1d967151-7c20-4ca7-9400-65233cdcd4db/code.power @@ -0,0 +1 @@ +###CODEPOWER### \ No newline at end of file diff --git a/src/1efdded5-d6c8-452c-8f37-0374483a7b3f/code.power b/src/1efdded5-d6c8-452c-8f37-0374483a7b3f/code.power new file mode 100644 index 0000000..cb7f27d --- /dev/null +++ b/src/1efdded5-d6c8-452c-8f37-0374483a7b3f/code.power @@ -0,0 +1,274 @@ + /** + * Compiler Component Joomla Version Settings + * + * @var Settings + * @since 3.2.0 + */ + protected Settings $settings; + + /** + * Compiler Utilities Paths + * + * @var Paths + * @since 3.2.0 + */ + protected Paths $paths; + + /** + * Compiler Counter + * + * @var Counter + * @since 3.2.0 + */ + protected Counter $counter; + + /** + * Compiler Utilities File + * + * @var File + * @since 3.2.0 + */ + protected File $file; + + /** + * Compiler Utilities Files + * + * @var Files + * @since 3.2.0 + */ + protected Files $files; + + /** + * Database object to query local DB + * + * @var CMSApplication + * @since 3.2.0 + **/ + protected CMSApplication $app; + + /** + * Constructor. + * + * @param Settings|null $settings The compiler component joomla version settings object. + * @param Paths|null $paths The compiler paths object. + * @param Counter|null $counter The compiler counter object. + * @param File|null $file The compiler file object. + * @param Files|null $files The compiler files object. + * @param CMSApplication|null $app The CMS Application object. + * + * @since 3.2.0 + * @throws \Exception + */ + public function __construct(?Settings $settings = null, ?Paths $paths = null, + ?Counter $counter = null, ?File $file = null, ?Files $files = null, + ?CMSApplication $app = null) + { + $this->settings = $settings ?: Compiler::_('Component.Settings'); + $this->paths = $paths ?: Compiler::_('Utilities.Paths'); + $this->counter = $counter ?: Compiler::_('Utilities.Counter'); + $this->file = $file ?: Compiler::_('Utilities.File'); + $this->files = $files ?: Compiler::_('Utilities.Files'); + $this->app = $app ?: Factory::getApplication(); + } + + /** + * Build Structural Needed Files & Folders + * + * @param array $target The main target and name + * @param string $type The type in the target + * @param string|null $fileName The custom file name + * @param array|null $config To add more data to the files info + * + * @return bool true on success + * @since 3.2.0 + */ + public function build(array $target, string $type, + ?string $fileName = null, ?array $config = null): bool + { + // did we build the files (any number) + $build_status = false; + + // check that we have the target values + if (ArrayHelper::check($target)) + { + // search the target + foreach ($target as $main => $name) + { + // make sure it is lower case + $name = StringHelper::safe($name); + + // setup the files + foreach ($this->settings->multiple()->{$main} as $item => $details) + { + if ($details->type === $type) + { + $file_details = $this->getFileDetails( + $details, + (string) $item, + $name, + $fileName, + $config + ); + + if (is_array($file_details)) + { + // store the new files + $this->files->appendArray('dynamic.' . $file_details['view'], + $file_details); + + // we have build at least one + $build_status = true; + } + } + } + } + } + + return $build_status; + } + + /** + * Get the details + * + * @param object $details The item details + * @param string $item The item name + * @param string $name The given name + * @param string|null $fileName The custom file name + * @param array|null $config To add more data to the files info + * + * @return array|null The details + * @since 3.2.0 + */ + private function getFileDetails(object $details, string $item, + string $name, ?string $fileName = null, ?array $config = null): ?array + { + $zip_path = ''; + if (($path = $this->getPath($details, $zip_path, $name)) === null) + { + return null; + } + + // setup the folder + if (!Folder::exists($path)) + { + Folder::create($path); + $this->file->html($zip_path); + + // count the folder created + $this->counter->folder++; + } + + $new_name = $this->getNewName($details, $item, $name, $fileName); + + if (!JoomlaFile::exists($path . '/' . $new_name)) + { + // move the file to its place + JoomlaFile::copy( + $this->paths->template_path . '/' . $item, + $path . '/' . $new_name + ); + + // count the file created + $this->counter->file++; + } + + // we can't have dots in a view name + if (strpos($name, '.') !== false) + { + $name = preg_replace('/[\.]+/', '_', (string) $name); + } + + // setup array for new file + $file = [ + 'path' => $path . '/' . $new_name, + 'name' => $new_name, + 'view' => $name, + 'zip' => $zip_path . '/' . $new_name + ]; + + if (ArrayHelper::check($config)) + { + $file['config'] = $config; + } + + return $file; + } + + /** + * Get the path + * + * @param object $details The item details + * @param string $zipPath The zip path + * @param string $name The name + * + * @return string|null The path + * @since 3.2.0 + */ + private function getPath(object $details, string &$zipPath, string $name): ?string + { + // set destination path + if (strpos((string) $details->path, 'VIEW') !== false) + { + $path = str_replace('VIEW', $name, (string) $details->path); + } + else + { + $path = $details->path; + } + + // make sure we have component to replace + if (strpos((string) $path, 'c0mp0n3nt') !== false) + { + $zipPath = str_replace('c0mp0n3nt/', '', (string) $path); + + return str_replace( + 'c0mp0n3nt/', $this->paths->component_path . '/', (string) $path + ); + } + + $this->app->enqueueMessage( + Text::sprintf('

c0mp0n3nt issue found

The path (%s) could not be used.

', + $path + ), 'Error' + ); + + return null; + } + + /** + * Get the new name + * + * @param object $details The item details + * @param string $item The item name + * @param string $name The name + * @param string|null $fileName The custom file name + * + * @return string The new name + * @since 3.2.0 + */ + private function getNewName(object $details, string $item, + string &$name, ?string $fileName = null): string + { + // do the file need renaming + if ($details->rename) + { + if (!empty($fileName)) + { + $name = $name . '_' . $fileName; + + return str_replace( + $details->rename, $fileName, $item + ); + } + elseif ($details->rename === 'new') + { + return $details->newName; + } + + return str_replace( + $details->rename, $name, $item + ); + } + + return $item; + } diff --git a/src/1fcb13a2-f3f0-4fa8-b8c6-ff9dc546777a/code.power b/src/1fcb13a2-f3f0-4fa8-b8c6-ff9dc546777a/code.power new file mode 100644 index 0000000..e4efce5 --- /dev/null +++ b/src/1fcb13a2-f3f0-4fa8-b8c6-ff9dc546777a/code.power @@ -0,0 +1,10 @@ + /** + * Set the external code string & load it in to string + * + * @param string $string The content to check + * @param int $debug The switch to debug the update + * + * @return string + * @since 3.2.0 + */ + public function set(string $string, int $debug = 0): string; \ No newline at end of file diff --git a/src/20ed72b0-fcac-4344-aee1-8a65e3bf221d/code.power b/src/20ed72b0-fcac-4344-aee1-8a65e3bf221d/code.power new file mode 100644 index 0000000..cc0b570 --- /dev/null +++ b/src/20ed72b0-fcac-4344-aee1-8a65e3bf221d/code.power @@ -0,0 +1,10 @@ + /** + * Trigger an event + * + * @param string $event The event to trigger + * @param mixed $data The values to pass to the event/plugin + * + * @return void + * @since 3.2.0 + */ + public function trigger(string $event, $data); \ No newline at end of file diff --git a/src/23f2ca33-440a-4941-8e9a-4bc67522c0cb/code.power b/src/23f2ca33-440a-4941-8e9a-4bc67522c0cb/code.power new file mode 100644 index 0000000..bba0993 --- /dev/null +++ b/src/23f2ca33-440a-4941-8e9a-4bc67522c0cb/code.power @@ -0,0 +1,26 @@ + /** + * 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(Content::class, 'Content') + ->share('Content', [$this, 'getContent'], true); + } + + /** + * Get the Compiler Content + * + * @param Container $container The DI container. + * + * @return Content + * @since 3.2.0 + */ + public function getContent(Container $container): Content + { + return new Content(); + } diff --git a/src/24da9672-e47f-4bb1-b6c0-0ebfc17f0957/code.power b/src/24da9672-e47f-4bb1-b6c0-0ebfc17f0957/code.power new file mode 100644 index 0000000..04ba201 --- /dev/null +++ b/src/24da9672-e47f-4bb1-b6c0-0ebfc17f0957/code.power @@ -0,0 +1,87 @@ + /** + * Local Core Joomla Rules + * + * @var array|null + * @since 3.2.0 + **/ + protected ?array $rules = null; + + /** + * Local Core Joomla Rules Path + * + * @var string + * @since 3.2.0 + **/ + protected string $path; + + /** + * Constructor + * + * @since 3.2.0 + */ + public function __construct() + { + // set the path to the form validation rules + $this->path = JPATH_LIBRARIES . '/src/Form/Rule'; + } + + /** + * Get the Array of Existing Validation Rule Names + * + * @param bool $lowercase Switch to set rules lowercase + * + * @return array + * @since 3.2.0 + */ + public function get(bool $lowercase = false): array + { + if (!$this->rules) + { + // check if the path exist + if (!Folder::exists($this->path)) + { + return []; + } + + // we must first store the current working directory + $joomla = getcwd(); + + // go to that folder + chdir($this->path); + + // load all the files in this path + $rules = Folder::files('.', '\.php', true, true); + + // change back to Joomla working directory + chdir($joomla); + + // make sure we have an array + if (!ArrayHelper::check($rules)) + { + return false; + } + + // remove the Rule.php from the name + $this->rules = array_map( + fn($name): string => str_replace(array('./','Rule.php'), '', (string) $name), + $rules + ); + } + + // return rules if found + if (is_array($this->rules)) + { + // check if the names should be all lowercase + if ($lowercase) + { + return array_map( + fn($item): string => strtolower((string) $item), + $this->rules + ); + } + return $this->rules; + } + + // return empty array + return []; + } diff --git a/src/253317c7-3c3b-48a0-aec8-8af5e7a86504/code.power b/src/253317c7-3c3b-48a0-aec8-8af5e7a86504/code.power new file mode 100644 index 0000000..3b6c154 --- /dev/null +++ b/src/253317c7-3c3b-48a0-aec8-8af5e7a86504/code.power @@ -0,0 +1,59 @@ + /** + * 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(Data::class, 'Library.Data') + ->share('Library.Data', [$this, 'getData'], true); + + $container->alias(Structure::class, 'Library.Structure') + ->share('Library.Structure', [$this, 'getStructure'], true); + } + + /** + * Get the Compiler Library Data + * + * @param Container $container The DI container. + * + * @return Data + * @since 3.2.0 + */ + public function getData(Container $container): Data + { + return new Data( + $container->get('Config'), + $container->get('Registry'), + $container->get('Customcode'), + $container->get('Customcode.Gui'), + $container->get('Field.Data'), + $container->get('Model.Filesfolders') + ); + } + + /** + * Get the Compiler Library Structure Builder + * + * @param Container $container The DI container. + * + * @return Structure + * @since 3.2.0 + */ + public function getStructure(Container $container): Structure + { + return new Structure( + $container->get('Config'), + $container->get('Registry'), + $container->get('Event'), + $container->get('Component'), + $container->get('Content'), + $container->get('Utilities.Counter'), + $container->get('Utilities.Paths'), + $container->get('Utilities.Folder'), + $container->get('Utilities.File') + ); + } diff --git a/src/268b85ef-49f3-4c39-8187-bb12e38d19ee/code.power b/src/268b85ef-49f3-4c39-8187-bb12e38d19ee/code.power new file mode 100644 index 0000000..4cf7b48 --- /dev/null +++ b/src/268b85ef-49f3-4c39-8187-bb12e38d19ee/code.power @@ -0,0 +1,49 @@ + /** + * Compiler Placeholder + * + * @var Placeholder + * @since 3.2.0 + **/ + protected Placeholder $placeholder; + + /** + * Constant Paths + * + * @var array + * @since 3.2.0 + **/ + protected array $paths; + + /** + * Constructor. + * + * @param Placeholder|null $placeholder The Compiler Placeholder object. + * @param Constantpaths|null $paths The Constant Paths object. + * + * @since 3.2.0 + */ + public function __construct(?Placeholder $placeholder = null, ?Constantpaths $paths = null) + { + $this->placeholder = $placeholder ?: Compiler::_('Placeholder'); + $paths = $paths ?: Compiler::_('Utilities.Constantpaths'); + + // load the constant paths + $this->paths = $paths->get(); + } + + /** + * Update path with dynamic value + * + * @param string $path The path to update + * + * @return string The updated path + * @since 3.2.0 + */ + public function update(string $path): string + { + return $this->placeholder->update_( + $this->placeholder->update( + $path, $this->paths + ) + ); + } diff --git a/src/29455d3b-df2b-4e41-8684-1608060e37a4/code.power b/src/29455d3b-df2b-4e41-8684-1608060e37a4/code.power new file mode 100644 index 0000000..ad56234 --- /dev/null +++ b/src/29455d3b-df2b-4e41-8684-1608060e37a4/code.power @@ -0,0 +1,86 @@ + /** + * The areas add array + * + * @var array + * @since 3.2.0 + */ + protected array $areas = [ + 'javascript_file', + 'js_document' + ]; + + /** + * The gui mapper array + * + * @var array + * @since 3.2.0 + */ + protected array $guiMapper = [ + 'table' => null, + 'id' => null, + 'field' => null, + 'type' => 'js' + ]; + + /** + * Compiler Customcode + * + * @var Customcode + * @since 3.2.0 + */ + protected Customcode $customcode; + + /** + * Compiler Customcode in Gui + * + * @var Gui + * @since 3.2.0 + **/ + protected Gui $gui; + + /** + * Constructor + * + * @param Customcode|null $customcode The compiler customcode object. + * @param Gui|null $gui The compiler customcode gui. + * + * @since 3.2.0 + */ + public function __construct(?Customcode $customcode = null, ?Gui $gui = null) + { + $this->customcode = $customcode ?: Compiler::_('Customcode'); + $this->gui = $gui ?: Compiler::_('Customcode.Gui'); + } + + /** + * Set Javascript code + * + * @param object $item The item data + * @param string $table The table + * + * @return void + * @since 3.2.0 + */ + public function set(object &$item, string $table = 'site_view') + { + // set some gui mapper values + $this->guiMapper['table'] = $table; + $this->guiMapper['id'] = (int) $item->id; + + foreach ($this->areas as $area) + { + if (isset($item->{'add_' . $area}) + && $item->{'add_' . $area} == 1 + && StringHelper::check($item->{$area})) + { + // update GUI mapper field + $this->guiMapper['field'] = $area; + $item->{$area} = $this->gui->set( + $this->customcode->update( + base64_decode((string) $item->{$area}) + ), + $this->guiMapper + ); + } + } + } diff --git a/src/295186de-5954-4a65-a4c1-2f79ef305743/code.power b/src/295186de-5954-4a65-a4c1-2f79ef305743/code.power new file mode 100644 index 0000000..dd57761 --- /dev/null +++ b/src/295186de-5954-4a65-a4c1-2f79ef305743/code.power @@ -0,0 +1,64 @@ + /** + * 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(Data::class, 'Joomlamodule.Data') + ->share('Joomlamodule.Data', [$this, 'getData'], true); + + $container->alias(Structure::class, 'Joomlamodule.Structure') + ->share('Joomlamodule.Structure', [$this, 'getStructure'], true); + } + + /** + * Get the Joomla Module Data + * + * @param Container $container The DI container. + * + * @return Data + * @since 3.2.0 + */ + public function getData(Container $container): Data + { + return new Data( + $container->get('Config'), + $container->get('Customcode'), + $container->get('Customcode.Gui'), + $container->get('Placeholder'), + $container->get('Language'), + $container->get('Field'), + $container->get('Field.Name'), + $container->get('Model.Filesfolders'), + $container->get('Model.Libraries'), + $container->get('Dynamicget.Data') + ); + } + + /** + * Get the Joomla Module Structure Builder + * + * @param Container $container The DI container. + * + * @return Structure + * @since 3.2.0 + */ + public function getStructure(Container $container): Structure + { + return new Structure( + $container->get('Joomlamodule.Data'), + $container->get('Component'), + $container->get('Config'), + $container->get('Registry'), + $container->get('Customcode.Dispenser'), + $container->get('Event'), + $container->get('Utilities.Counter'), + $container->get('Utilities.Folder'), + $container->get('Utilities.File'), + $container->get('Utilities.Files') + ); + } diff --git a/src/2ad31f74-f579-499d-b98b-c4f54fd615dd/code.power b/src/2ad31f74-f579-499d-b98b-c4f54fd615dd/code.power new file mode 100644 index 0000000..bee23d7 --- /dev/null +++ b/src/2ad31f74-f579-499d-b98b-c4f54fd615dd/code.power @@ -0,0 +1,68 @@ + /** + * Load data rows as an array of associated arrays + * + * @param array $select Array of selection keys + * @param array $tables Array of tables to search + * @param array|null $where Array of where key=>value match exist + * @param array|null $order Array of how to order the data + * @param int|null $limit Limit the number of values returned + * + * @return array|null + * @since 3.2.0 + **/ + public function rows(array $select, array $tables, ?array $where = null, + ?array $order = null, ?int $limit = null): ?array; + + /** + * Load data rows as an array of objects + * + * @param array $select Array of selection keys + * @param array $tables Array of tables to search + * @param array|null $where Array of where key=>value match exist + * @param array|null $order Array of how to order the data + * @param int|null $limit Limit the number of values returned + * + * @return array|null + * @since 3.2.0 + **/ + public function items(array $select, array $tables, ?array $where = null, + ?array $order = null, ?int $limit = null): ?array; + + /** + * Load data row as an associated array + * + * @param array $select Array of selection keys + * @param array $tables Array of tables to search + * @param array|null $where Array of where key=>value match exist + * @param array|null $order Array of how to order the data + * + * @return array|null + * @since 3.2.0 + **/ + public function row(array $select, array $tables, ?array $where = null, ?array $order = null): ?array; + + /** + * Load data row as an object + * + * @param array $select Array of selection keys + * @param array $tables Array of tables to search + * @param array|null $where Array of where key=>value match exist + * @param array|null $order Array of how to order the data + * + * @return object|null + * @since 3.2.0 + **/ + public function item(array $select, array $tables, ?array $where = null, ?array $order = null): ?object; + + /** + * Load one value from a row + * + * @param array $select Array of selection keys + * @param array $tables Array of tables to search + * @param array|null $where Array of where key=>value match exist + * @param array|null $order Array of how to order the data + * + * @return mixed + * @since 3.2.0 + **/ + public function value(array $select, array $tables, ?array $where = null, ?array $order = null); diff --git a/src/2b5c9989-1d4e-4f59-8b95-5cd2f72f82d9/code.power b/src/2b5c9989-1d4e-4f59-8b95-5cd2f72f82d9/code.power new file mode 100644 index 0000000..4446ed9 --- /dev/null +++ b/src/2b5c9989-1d4e-4f59-8b95-5cd2f72f82d9/code.power @@ -0,0 +1,12 @@ + /** + * Model the key + * + * @param string $key The key to model + * + * @return string + * @since 3.2.0 + */ + protected function key(string $key): string + { + return preg_replace('/\s+/', '', $key); + } diff --git a/src/2c76c06e-a371-4b73-9fbe-b4d9b4df55d7/code.power b/src/2c76c06e-a371-4b73-9fbe-b4d9b4df55d7/code.power new file mode 100644 index 0000000..1973c3c --- /dev/null +++ b/src/2c76c06e-a371-4b73-9fbe-b4d9b4df55d7/code.power @@ -0,0 +1,26 @@ + /** + * 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(Mysql::class, 'Builder.Update.Mysql') + ->share('Builder.Update.Mysql', [$this, 'getMysql'], true); + } + + /** + * Get the Compiler Builder Mysql + * + * @param Container $container The DI container. + * + * @return Mysql + * @since 3.2.0 + */ + public function getMysql(Container $container): Mysql + { + return new Mysql(); + } diff --git a/src/2cc8517d-1105-4697-9743-048b4b7c089c/code.power b/src/2cc8517d-1105-4697-9743-048b4b7c089c/code.power new file mode 100644 index 0000000..768e242 --- /dev/null +++ b/src/2cc8517d-1105-4697-9743-048b4b7c089c/code.power @@ -0,0 +1,23 @@ + /** + * Set the JCB GUI code placeholder + * + * @param string $string The code string + * @param array $config The placeholder config values + * + * @return string + * @since 3.2.0 + */ + public function set(string $string, array $config): string; + + /** + * search a file for gui code blocks that were updated in the IDE + * + * @param string $file The file path to search + * @param array $placeholders The values to replace in the code being stored + * @param string $today The date for today + * @param string $target The target path type + * + * @return void + * @since 3.2.0 + */ + public function search(string &$file, array &$placeholders, string &$today, string &$target); \ No newline at end of file diff --git a/src/2da6d6c4-eb29-4d69-8bc2-36d96e916adf/code.power b/src/2da6d6c4-eb29-4d69-8bc2-36d96e916adf/code.power new file mode 100644 index 0000000..a85f73a --- /dev/null +++ b/src/2da6d6c4-eb29-4d69-8bc2-36d96e916adf/code.power @@ -0,0 +1,68 @@ + /** + * Get any value from a item/field/column of an area/view/table + * Example: $this->get('table_name', 'field_name', 'value_key'); + * Get an item/field/column of an area/view/table + * Example: $this->get('table_name', 'field_name'); + * Get all items/fields/columns of an area/view/table + * Example: $this->get('table_name'); + * Get all areas/views/tables with all their item/field/column details + * Example: $this->get(); + * + * @param string $table The table + * @param string|null $field The field + * @param string|null $key The value key + * + * @return mixed + * @since 3.2.0 + */ + public function get(string $table, ?string $field = null, ?string $key = null); + + /** + * Get title field from an area/view/table + * + * @param string|null $table The area + * + * @return ?array + * @since 3.2.0 + */ + public function title(string $table): ?array; + + /** + * Get title field name + * + * @param string|null $table The area + * + * @return string + * @since 3.2.0 + */ + public function titleName(string $table): string; + + /** + * Get all tables + * + * @return array + * @since 3.2.0 + */ + public function tables(): array; + + /** + * Check if a table (and field) exist + * + * @param string|null $table The area + * @param string|null $field The area + * + * @return bool + * @since 3.2.0 + */ + public function exist(string $table, ?string $field = null): bool; + + /** + * Get all fields of an area/view/table + * + * @param string $table The area + * @param bool $default Add the default fields + * + * @return array|null On success an array of fields + * @since 3.2.0 + */ + public function fields(string $table, bool $default = false): ?array; diff --git a/src/2dd1289a-4000-43cc-8c62-77ff32de56bf/code.power b/src/2dd1289a-4000-43cc-8c62-77ff32de56bf/code.power new file mode 100644 index 0000000..55dd436 --- /dev/null +++ b/src/2dd1289a-4000-43cc-8c62-77ff32de56bf/code.power @@ -0,0 +1,49 @@ + /** + * 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(AdminviewData::class, 'Adminview.Data') + ->share('Adminview.Data', [$this, 'getAdminviewData'], true); + } + + /** + * Get the Compiler Adminview Data + * + * @param Container $container The DI container. + * + * @return AdminviewData + * @since 3.2.0 + */ + public function getAdminviewData(Container $container): AdminviewData + { + return new AdminviewData( + $container->get('Config'), + $container->get('Registry'), + $container->get('Event'), + $container->get('Placeholder'), + $container->get('Customcode.Dispenser'), + $container->get('Model.Customtabs'), + $container->get('Model.Tabs'), + $container->get('Model.Fields'), + $container->get('Model.Historyadminview'), + $container->get('Model.Permissions'), + $container->get('Model.Conditions'), + $container->get('Model.Relations'), + $container->get('Model.Linkedviews'), + $container->get('Model.Javascriptadminview'), + $container->get('Model.Cssadminview'), + $container->get('Model.Phpadminview'), + $container->get('Model.Custombuttons'), + $container->get('Model.Customimportscripts'), + $container->get('Model.Ajaxadmin'), + $container->get('Model.Customalias'), + $container->get('Model.Sql'), + $container->get('Model.Mysqlsettings') + ); + } diff --git a/src/2e6731ba-3a03-4836-b2c2-4e50e38cb890/code.power b/src/2e6731ba-3a03-4836-b2c2-4e50e38cb890/code.power new file mode 100644 index 0000000..bb95599 --- /dev/null +++ b/src/2e6731ba-3a03-4836-b2c2-4e50e38cb890/code.power @@ -0,0 +1,9 @@ + /** + * get code to use + * + * @param Object $code The code object + * + * @return string + * @since 3.2.0 + */ + public function get(object $extension): string; \ No newline at end of file diff --git a/src/2f7b1998-bb93-4055-ae82-aa659ce8a37f/code.power b/src/2f7b1998-bb93-4055-ae82-aa659ce8a37f/code.power new file mode 100644 index 0000000..4e8f634 --- /dev/null +++ b/src/2f7b1998-bb93-4055-ae82-aa659ce8a37f/code.power @@ -0,0 +1,49 @@ + /** + * 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(CompilerPlaceholder::class, 'Placeholder') + ->share('Placeholder', [$this, 'getPlaceholder'], true); + + $container->alias(Reverse::class, 'Placeholder.Reverse') + ->share('Placeholder.Reverse', [$this, 'getPlaceholderReverse'], true); + } + + /** + * Get the Compiler Placeholder + * + * @param Container $container The DI container. + * + * @return CompilerPlaceholder + * @since 3.2.0 + */ + public function getPlaceholder(Container $container): CompilerPlaceholder + { + return new CompilerPlaceholder( + $container->get('Config') + ); + } + + /** + * Get the Compiler Placeholder Reverse + * + * @param Container $container The DI container. + * + * @return Worker + * @since 3.2.0 + */ + public function getPlaceholderReverse(Container $container): Reverse + { + return new Reverse( + $container->get('Config'), + $container->get('Placeholder'), + $container->get('Language'), + $container->get('Language.Extractor') + ); + } \ No newline at end of file diff --git a/src/313b43c4-98c3-4f62-9177-2d73ec8eba31/code.power b/src/313b43c4-98c3-4f62-9177-2d73ec8eba31/code.power new file mode 100644 index 0000000..9bcc3aa --- /dev/null +++ b/src/313b43c4-98c3-4f62-9177-2d73ec8eba31/code.power @@ -0,0 +1,598 @@ + /** + * The function name memory ids + * + * @var array + * @since 3.2.0 + **/ + public array $functionNameMemory = []; + + /** + * The active custom code + * + * @var array + * @since 3.2.0 + */ + public $active = []; + + /** + * The custom code memory + * + * @var array + * @since 3.2.0 + */ + public $memory = []; + + /** + * The placeholders for custom code keys + * + * @var array + */ + protected $keys + = array( + '[' => '[', + ']' => ']', + ',' => ',', + '+' => '+', + '=' => '=' + ); + + /** + * The custom code to be added + * + * @var array + * @since 3.2.0 + */ + protected $data = []; + + /** + * Compiler Config + * + * @var Config + * @since 3.2.0 + **/ + protected Config $config; + + /** + * Compiler Placeholder + * + * @var Placeholder + * @since 3.2.0 + **/ + protected Placeholder $placeholder; + + /** + * Compiler Language Extractor + * + * @var Extractor + * @since 3.2.0 + **/ + protected Extractor $extractor; + + /** + * Compiler Custom Code External + * + * @var External + * @since 3.2.0 + **/ + protected External $external; + + /** + * Database object to query local DB + * + * @var \JDatabaseDriver + * @since 3.2.0 + **/ + protected $db; + + /** + * Constructor. + * + * @param Config|null $config The compiler config object. + * @param Placeholder|null $placeholder The compiler placeholder object. + * @param Extractor|null $extractor The compiler language extractor object. + * @param External|null $external The compiler external custom code object. + * @param \JDatabaseDriver $db The Database Driver object. + * + * @since 3.2.0 + */ + public function __construct(?Config $config = null, ?Placeholder $placeholder = null, + ?Extractor $extractor = null, ?External $external = null, ?\JDatabaseDriver $db = null) + { + $this->config = $config ?: Compiler::_('Config'); + $this->placeholder = $placeholder ?: Compiler::_('Placeholder'); + $this->extractor = $extractor ?: Compiler::_('Language.Extractor'); + $this->external = $external ?: Compiler::_('Customcode.External'); + $this->db = $db ?: Factory::getDbo(); + } + + /** + * Update **ALL** dynamic values in a strings here + * + * @param string $string The content to check + * @param int $debug The switch to debug the update + * We can now at any time debug the + * dynamic build values if it gets broken + * + * @return string + * @since 3.2.0 + */ + public function update(string $string, int $debug = 0): string + { + if (StringHelper::check($string)) + { + $string = $this->extractor->engine( + $this->set( + $this->external->set($string, $debug), $debug + ) + ); + } + // if debug + if ($debug) + { + jexit(); + } + + return $string; + } + + /** + * Set the custom code data & can load it in to string + * + * @param string $string The content to check + * @param int $debug The switch to debug the update + * @param int|null $not The not switch + * + * @return string + * @since 3.2.0 + */ + public function set(string $string, int $debug = 0, ?int $not = null): string + { + // insure the code is loaded + $loaded = false; + // check if content has custom code place holder + if (strpos($string, '[CUSTO' . 'MCODE=') !== false) + { + // if debug + if ($debug) + { + echo 'Custom Code String:'; + var_dump($string); + } + // the ids found in this content + $bucket = []; + $found = GetHelper::allBetween( + $string, '[CUSTO' . 'MCODE=', ']' + ); + if (ArrayHelper::check($found)) + { + foreach ($found as $key) + { + // if debug + if ($debug) + { + echo '$key before update:'; + var_dump($key); + } + // check if we have args + if (is_numeric($key)) + { + $id = (int) $key; + } + elseif (StringHelper::check($key) + && strpos((string) $key, '+') === false) + { + $getFuncName = trim((string) $key); + if (!isset($this->functionNameMemory[$getFuncName])) + { + if (!$found_local = GetHelper::var( + 'custom_code', $getFuncName, 'function_name', + 'id' + )) + { + continue; + } + $this->functionNameMemory[$getFuncName] + = $found_local; + } + $id = (int) $this->functionNameMemory[$getFuncName]; + } + elseif (StringHelper::check($key) + && strpos( + (string) $key, '+' + ) !== false) + { + $array = explode('+', (string) $key); + // set ID + if (is_numeric($array[0])) + { + $id = (int) $array[0]; + } + elseif (StringHelper::check($array[0])) + { + $getFuncName = trim($array[0]); + if (!isset($this->functionNameMemory[$getFuncName])) + { + if (!$found_local + = GetHelper::var( + 'custom_code', $getFuncName, + 'function_name', 'id' + )) + { + continue; + } + $this->functionNameMemory[$getFuncName] + = $found_local; + } + $id = (int) $this->functionNameMemory[$getFuncName]; + } + else + { + continue; + } + // load args for this ID + if (isset($array[1])) + { + if (!isset($this->data[$id]['args'])) + { + $this->data[$id]['args'] = []; + } + // only load if not already loaded + if (!isset($this->data[$id]['args'][$key])) + { + if (strpos($array[1], ',') !== false) + { + // update the function values with the custom code key placeholders (this allow the use of [] + and , in the values) + $this->data[$id]['args'][$key] + = array_map( + fn($_key) => $this->placeholder->update( + $_key, + $this->keys + ), (array) explode(',', $array[1]) + ); + } + elseif (StringHelper::check( + $array[1] + )) + { + $this->data[$id]['args'][$key] + = []; + // update the function values with the custom code key placeholders (this allow the use of [] + and , in the values) + $this->data[$id]['args'][$key][] + = $this->placeholder->update( + $array[1], + $this->keys + ); + } + } + } + } + else + { + continue; + } + // make sure to remove the not if set + if ($not && is_numeric($not) && $not > 0 && $not == $id) + { + continue; + } + $bucket[$id] = $id; + } + } + // if debug + if ($debug) + { + echo 'Bucket:'; + var_dump($bucket); + } + // check if any custom code placeholders where found + if (ArrayHelper::check($bucket)) + { + $_tmpLang = $this->config->lang_target; + // insure we add the langs to both site and admin + $this->config->lang_target = 'both'; + // now load the code to memory + $loaded = $this->get($bucket, false, $debug); + // revert lang to current setting + $this->config->lang_target = $_tmpLang; + } + // if debug + if ($debug) + { + echo 'Loaded:'; + var_dump($loaded); + } + // when the custom code is loaded + if ($loaded === true) + { + $string = $this->insert($bucket, $string, $debug); + } + // if debug + if ($debug) + { + echo 'Custom Code String After Update:'; + var_dump($string); + } + } + + return $string; + } + + /** + * Load the custom code from the system + * + * @param array|null $ids The custom code ides if known + * @param bool $setLang The set lang switch + * @param int $debug The switch to debug the update + * + * @return bool + * @since 3.2.0 + */ + public function get(?array $ids = null, bool $setLang = true, $debug = 0): bool + { + // should the result be stored in memory + $loadInMemory = false; + // Create a new query object. + $query = $this->db->getQuery(true); + $query->from( + $this->db->quoteName('#__componentbuilder_custom_code', 'a') + ); + if (ArrayHelper::check($ids)) + { + if (($idArray = $this->check($ids)) !== false) + { + $query->select( + $this->db->quoteName( + array('a.id', 'a.code', 'a.comment_type') + ) + ); + $query->where( + $this->db->quoteName('a.id') . ' IN (' . implode( + ',', $idArray + ) . ')' + ); + $query->where( + $this->db->quoteName('a.target') . ' = 2' + ); // <--- to load the correct target + $loadInMemory = true; + } + else + { + // all values are already in memory continue + return true; + } + } + else + { + $query->select( + $this->db->quoteName( + array('a.id', 'a.code', 'a.comment_type', 'a.component', + 'a.from_line', 'a.hashtarget', 'a.hashendtarget', + 'a.path', 'a.to_line', 'a.type') + ) + ); + $query->where( + $this->db->quoteName('a.component') . ' = ' + . (int) $this->config->component_id + ); + $query->where( + $this->db->quoteName('a.target') . ' = 1' + ); // <--- to load the correct target + $query->order( + $this->db->quoteName('a.from_line') . ' ASC' + ); // <--- insure we always add code from top of file + // reset custom code + $this->active = []; + } + $query->where($this->db->quoteName('a.published') . ' >= 1'); + $this->db->setQuery($query); + $this->db->execute(); + if ($this->db->getNumRows()) + { + $bucket = $this->db->loadAssocList('id'); + // open the code + foreach ($bucket as $nr => &$customCode) + { + $customCode['code'] = base64_decode((string) $customCode['code']); + // always insure that the external code is loaded + $customCode['code'] = $this->external->set( + $customCode['code'] + ); + + // set the lang only if needed (we do the other later when we add it to the correct position) + if ($setLang) + { + $customCode['code'] = $this->extractor->engine( + $customCode['code'] + ); + } + // check for more custom code (since this is a custom code placeholder) + else + { + $customCode['code'] = $this->set( + $customCode['code'], $debug, $nr + ); + } + + // build the hash array + if (isset($customCode['hashtarget'])) + { + $customCode['hashtarget'] = explode( + "__", (string) $customCode['hashtarget'] + ); + // is this a replace code, set end has array + if ($customCode['type'] == 1 + && strpos((string) $customCode['hashendtarget'], '__') !== false) + { + $customCode['hashendtarget'] = explode( + "__", (string) $customCode['hashendtarget'] + ); + + // NOW see if this is an end of page target (TODO not sure if the string is always d41d8cd98f00b204e9800998ecf8427e) + // I know this fix is not air-tight, but it should work as the value of an empty line when md5'ed is ^^^^ + // Then if the line number is only >>>one<<< it is almost always end of the page. + // So I am using those two values to detect end of page replace ending, to avoid mismatching the ending target hash. + if ($customCode['hashendtarget'][0] == 1 + && 'd41d8cd98f00b204e9800998ecf8427e' === $customCode['hashendtarget'][1]) + { + // unset since this will force the replacement unto end of page. + unset($customCode['hashendtarget']); + } + } + } + } + + // load this code into memory if needed + if ($loadInMemory === true) + { + $this->memory = $this->memory + $bucket; + } + + // add to active set + $this->active = array_merge($this->active, $bucket); + + return true; + } + + return false; + } + + /** + * Insert the custom code into the string + * + * @param array|null $ids The custom code ides if known + * @param string $string The string to insert custom code into + * @param int $debug The switch to debug the update + * + * @return string on success + * @since 3.2.0 + */ + protected function insert(array $ids, string $string, int $debug = 0): string + { + $code = []; + // load the code + foreach ($ids as $id) + { + $this->buildPlaceholders( + $this->memory[$id], $code, $debug + ); + } + // if debug + if ($debug) + { + echo 'Place holders to Update String:'; + var_dump($code); + echo 'Custom Code String Before Update:'; + var_dump($string); + } + + // now update the string + return $this->placeholder->update($string, $code); + } + + /** + * Build custom code placeholders + * + * @param array $item The memory item + * @param array $code The custom code bucket + * @param int $debug The switch to debug the update + * + * @return void + * @since 3.2.0 + */ + protected function buildPlaceholders(array $item, array &$code, int $debug = 0) + { + // check if there is args for this code + if (isset($this->data[$item['id']]['args']) + && ArrayHelper::check( + $this->data[$item['id']]['args'] + )) + { + // since we have args we cant update this code via IDE (TODO) + $placeholder = $this->placeholder->keys(3, null); + // if debug + if ($debug) + { + echo 'Custom Code Placeholders:'; + var_dump($placeholder); + } + // we have args and so need to load each + foreach ( + $this->data[$item['id']]['args'] as $key => $args + ) + { + $this->placeholder->setType('arg', $args); + // if debug + if ($debug) + { + echo 'Custom Code Global Placeholders:'; + var_dump($this->placeholder->active); + } + $code['[CUSTOM' . 'CODE=' . $key . ']'] = $placeholder['start'] + . PHP_EOL . $this->placeholder->update_( + $item['code'] + ) . $placeholder['end']; + } + // always clear the args + $this->placeholder->clearType('arg'); + } + else + { + if (($keyPlaceholder = array_search( + $item['id'], $this->functionNameMemory + )) === false) + { + $keyPlaceholder = $item['id']; + } + // check what type of place holders we should load here + $placeholderType = (int) $item['comment_type'] . '2'; + if (stripos((string) $item['code'], Placefix::b() . 'view') !== false + || stripos((string) $item['code'], Placefix::b() . 'sview') !== false + || stripos((string) $item['code'], Placefix::b() . 'arg') !== false) + { + // if view is being set dynamicly then we can't update this code via IDE (TODO) + $placeholderType = 3; + } + // if now ars were found, clear it + $this->placeholder->clearType('arg'); + // load args for this code + $placeholder = $this->placeholder->keys( + $placeholderType, $item['id'] + ); + $code['[CUSTOM' . 'CODE=' . $keyPlaceholder . ']'] + = $placeholder['start'] . PHP_EOL + . $this->placeholder->update_( + $item['code'] + ) . $placeholder['end']; + } + } + + /** + * check if we already have these ids in local memory + * + * @param array $ids The custom code ids + * + * @return Mixed + * @since 3.2.0 + */ + protected function check(array $ids) + { + // reset custom code + $this->active = []; + + foreach ($ids as $pointer => $id) + { + if (isset($this->memory[$id])) + { + $this->active[] = $this->memory[$id]; + unset($ids[$pointer]); + } + } + + // check if any ids left to fetch + if (ArrayHelper::check($ids)) + { + return $ids; + } + + return false; + } diff --git a/src/324566de-0f7d-4b6e-9caf-8424d55013ae/code.php b/src/324566de-0f7d-4b6e-9caf-8424d55013ae/code.php index f2b85ae..5549fd9 100644 --- a/src/324566de-0f7d-4b6e-9caf-8424d55013ae/code.php +++ b/src/324566de-0f7d-4b6e-9caf-8424d55013ae/code.php @@ -345,7 +345,7 @@ class Structure // check if we should add the dynamic folder moving script to the installer script if (!$this->registry->get('set_move_folders_install_script')) { - // add the setDynamicF0ld3rs() method to the install scipt.php file + // add the setDynamicF0ld3rs() method to the install script.php file $this->registry->set('set_move_folders_install_script', true); // set message that this was done (will still add a tutorial link later) @@ -410,6 +410,10 @@ class Structure $this->createFile($bom . PHP_EOL . Placefix::_h('POWERCODE') . PHP_EOL, $path, 'code.php', $power->key); + // set the super power php RAW file + $this->createFile(Placefix::_h('CODEPOWER'), + $path, 'code.power', $power->key); + // set the super power json file $this->createFile(Placefix::_h('POWERLINKER'), $path, 'settings.json', $power->key); diff --git a/src/324566de-0f7d-4b6e-9caf-8424d55013ae/code.power b/src/324566de-0f7d-4b6e-9caf-8424d55013ae/code.power new file mode 100644 index 0000000..0de4b12 --- /dev/null +++ b/src/324566de-0f7d-4b6e-9caf-8424d55013ae/code.power @@ -0,0 +1,386 @@ + /** + * we track the creation of htaccess files + * + * @var array + * @since 3.2.0 + **/ + protected array $htaccess = []; + + /** + * Power Objects + * + * @var Power + * @since 3.2.0 + **/ + protected Power $power; + + /** + * Compiler Config + * + * @var Config + * @since 3.2.0 + */ + protected Config $config; + + /** + * The compiler registry + * + * @var Registry + * @since 3.2.0 + */ + protected Registry $registry; + + /** + * Compiler Event + * + * @var EventInterface + * @since 3.2.0 + */ + protected EventInterface $event; + + /** + * Compiler Counter + * + * @var Counter + * @since 3.2.0 + */ + protected Counter $counter; + + /** + * Compiler Utilities Paths + * + * @var Paths + * @since 3.2.0 + */ + protected Paths $paths; + + /** + * Compiler Utilities Folder + * + * @var Folder + * @since 3.2.0 + */ + protected Folder $folder; + + /** + * Compiler Utilities File + * + * @var File + * @since 3.2.0 + */ + protected File $file; + + /** + * Compiler Utilities Files + * + * @var Files + * @since 3.2.0 + */ + protected Files $files; + + /** + * Database object to query local DB + * + * @var CMSApplication + * @since 3.2.0 + **/ + protected CMSApplication $app; + + /** + * Constructor + * + * @param Power|null $power The power object. + * @param Config|null $config The compiler config object. + * @param Registry|null $registry The compiler registry object. + * @param EventInterface|null $event The compiler event api object. + * @param Counter|null $counter The compiler counter object. + * @param Paths|null $paths The compiler paths object. + * @param Folder|null $folder The compiler folder object. + * @param File|null $file The compiler file object. + * @param Files|null $files The compiler files object. + * @param CMSApplication|null $app The CMS Application object. + * + * @throws \Exception + * @since 3.2.0 + */ + public function __construct(?Power $power = null, ?Config $config = null, + ?Registry $registry = null, ?EventInterface $event = null, + ?Counter $counter = null, ?Paths $paths = null, ?Folder $folder = null, + ?File $file = null, ?Files $files = null, ?CMSApplication $app = null) + { + $this->power = $power ?: Compiler::_('Power'); + $this->config = $config ?: Compiler::_('Config'); + $this->registry = $registry ?: Compiler::_('Registry'); + $this->event = $event ?: Compiler::_('Event'); + $this->counter = $counter ?: Compiler::_('Utilities.Counter'); + $this->paths = $paths ?: Compiler::_('Utilities.Paths'); + $this->folder = $folder ?: Compiler::_('Utilities.Folder'); + $this->file = $file ?: Compiler::_('Utilities.File'); + $this->files = $files ?: Compiler::_('Utilities.Files'); + $this->app = $app ?: Factory::getApplication(); + } + + /** + * Build the Powers files, folders + * + * @return void + * @since 3.2.0 + */ + public function build() + { + if (ArrayHelper::check($this->power->active)) + { + // for plugin event TODO change event api signatures + $powers = $this->power->active; + $component_context = $this->config->component_context; + // Trigger Event: jcb_ce_onBeforeSetModules + $this->event->trigger( + 'jcb_ce_onBeforeBuildPowers', + array(&$component_context, &$powers) + ); + // for plugin event TODO change event api signatures + $this->power->active = $powers; + + // set super power details + $this->setSuperPowerDetails(); + + foreach ($this->power->active as $power) + { + if (ObjectHelper::check($power) + && isset($power->path) + && StringHelper::check( + $power->path + )) + { + // activate dynamic folders + $this->setDynamicFolders(); + + // power path + $power->full_path = $this->paths->component_path . '/' + . $power->path; + $power->full_path_jcb = $this->paths->component_path . '/' + . $power->path_jcb; + $power->full_path_parent = $this->paths->component_path . '/' + . $power->path_parent; + + // set the power paths + $this->registry->set('dynamic_paths.' . $power->key, $power->full_path_parent); + + // create the power folder if it does not exist + // we do it like this to add html files to each part + $this->folder->create($power->full_path_jcb); + $this->folder->create($power->full_path_parent); + $this->folder->create($power->full_path); + + $bom = 'add_licensing_template == 2) + { + $bom = 'licensing_template; + } + + // set the main power php file + $this->createFile($bom . PHP_EOL . Placefix::_h('POWERCODE') . PHP_EOL, + $power->full_path, $power->file_name . '.php', $power->key); + + // set super power files + $this->setSuperPowerFiles($power, $bom); + + // set htaccess once per path + $this->setHtaccess($power); + } + } + } + } + + /** + * Create a file with optional custom content and save it to the given path. + * + * @param string $content The content. + * @param string $fullPath The full path to the destination folder. + * @param string $fileName The file name without the extension. + * @param string $key The key to append the file details. + * + * @return void + * @since 3.2.0 + */ + private function createFile(string $content, string $fullPath, string $fileName, string $key) + { + $file_details = [ + 'path' => $fullPath . '/' . $fileName, + 'name' => $fileName, + 'zip' => $fileName + ]; + + // Write the content to the file + $this->file->write($file_details['path'], $content); + + // Append the file details to the files array + $this->files->appendArray($key, $file_details); + + // Increment the file counter + $this->counter->file++; + } + + /** + * Set the .htaccess for this power path + * + * @param object $power The power object + * + * @return void + * @since 3.2.0 + */ + private function setHtaccess(object &$power) + { + if (!isset($this->htaccess[$power->path_jcb])) + { + // set the htaccess data + $data = '# Apache 2.4+' . PHP_EOL . + '' . PHP_EOL . + ' Require all denied' . PHP_EOL . + '' . PHP_EOL . PHP_EOL . + '# Apache 2.0-2.2' . PHP_EOL . + '' . PHP_EOL . + ' Deny from all' . PHP_EOL . + '' . PHP_EOL; + + // now we must add the .htaccess file + $fileDetails = array('path' => $power->full_path_jcb . '/.htaccess', + 'name' => '.htaccess', + 'zip' => '.htaccess'); + $this->file->write( + $fileDetails['path'], $data + ); + $this->files->appendArray($power->key, $fileDetails); + + // count the file created + $this->counter->file++; + + // now we must add the htaccess.txt file where the zip package my not get the [.] files + $fileDetails = array('path' => $power->full_path_jcb . '/htaccess.txt', + 'name' => 'htaccess.txt', + 'zip' => 'htaccess.txt'); + $this->file->write( + $fileDetails['path'], $data + ); + $this->files->appendArray($power->key, $fileDetails); + + // count the file created + $this->counter->file++; + + // now we must add the web.config file + $fileDetails = array('path' => $power->full_path_jcb . '/web.config', + 'name' => 'web.config', + 'zip' => 'web.config'); + $this->file->write( + $fileDetails['path'], + '' . PHP_EOL . + ' ' . PHP_EOL . + ' ' . PHP_EOL . + ' ' . PHP_EOL . + ' ' . PHP_EOL . + ' ' . PHP_EOL . + '' . PHP_EOL + ); + $this->files->appendArray($power->key, $fileDetails); + + // count the file created + $this->counter->file++; + + // we set these files only once + $this->htaccess[$power->path_jcb] = true; + } + } + + /** + * Add the dynamic folders + * + * @return void + * @since 3.2.0 + */ + private function setDynamicFolders() + { + // check if we should add the dynamic folder moving script to the installer script + if (!$this->registry->get('set_move_folders_install_script')) + { + // add the setDynamicF0ld3rs() method to the install script.php file + $this->registry->set('set_move_folders_install_script', true); + + // set message that this was done (will still add a tutorial link later) + $this->app->enqueueMessage( + Text::_('

Dynamic folder(s) were detected.

'), + 'Notice' + ); + $this->app->enqueueMessage( + Text::sprintf('A method (setDynamicF0ld3rs) was added to the install script.php of this package to insure that the folder(s) are copied into the correct place when this component is installed!'), + 'Notice' + ); + } + } + + /** + * Set the super powers details structure + * + * @return void + * @since 3.2.0 + */ + private function setSuperPowerDetails() + { + if ($this->config->add_super_powers && ArrayHelper::check($this->power->superpowers)) + { + foreach ($this->power->superpowers as $path => $powers) + { + // create the path if it does not exist + $this->folder->create($path, false); + + $key = StringHelper::safe($path); + + // set the super powers readme file + $this->createFile(Placefix::_h('POWERREADME'), + $path, 'README.md', $key); + + // set the super power index file + $this->createFile(Placefix::_h('POWERINDEX'), $path, + 'super-powers.json', $key); + } + } + } + + /** + * Set the super power file paths + * + * @param object $power The power object + * @param string $bom The bom for the top of the PHP files + * + * @return void + * @since 3.2.0 + */ + private function setSuperPowerFiles(object &$power, string $bom) + { + if ($this->config->add_super_powers && is_array($power->super_power_paths) && $power->super_power_paths !== []) + { + foreach ($power->super_power_paths as $path) + { + // create the path if it does not exist + $this->folder->create($path, false); + + // set the super power php file + $this->createFile($bom . PHP_EOL . Placefix::_h('POWERCODE') . PHP_EOL, + $path, 'code.php', $power->key); + + // set the super power php RAW file + $this->createFile(Placefix::_h('CODEPOWER'), + $path, 'code.power', $power->key); + + // set the super power json file + $this->createFile(Placefix::_h('POWERLINKER'), $path, + 'settings.json', $power->key); + + // set the super power readme file + $this->createFile(Placefix::_h('POWERREADME'), $path, + 'README.md', $power->key); + } + } + } diff --git a/src/3283a89c-329a-47fb-a011-0df6c31a5c73/code.power b/src/3283a89c-329a-47fb-a011-0df6c31a5c73/code.power new file mode 100644 index 0000000..9f197fa --- /dev/null +++ b/src/3283a89c-329a-47fb-a011-0df6c31a5c73/code.power @@ -0,0 +1,50 @@ + /** + * The areas add array + * + * @var array + * @since 3.2.0 + */ + protected array $areas = ['css_document', 'css']; + + /** + * Compiler Customcode Class + * + * @var Customcode + * @since 3.2.0 + */ + protected Customcode $customcode; + + /** + * Constructor + * + * @param Customcode|null $customcode The compiler customcode object. + * + * @since 3.2.0 + */ + public function __construct(?Customcode $customcode = null) + { + $this->customcode = $customcode ?: Compiler::_('Customcode'); + } + + /** + * Set Css code + * + * @param object $item The item data + * + * @return void + * @since 3.2.0 + */ + public function set(object &$item) + { + foreach ($this->areas as $area) + { + if (isset($item->{'add_' . $area}) + && $item->{'add_' . $area} == 1 + && StringHelper::check($item->{$area})) + { + $item->{$area} = $this->customcode->update( + base64_decode((string) $item->{$area}) + ); + } + } + } diff --git a/src/33bdc535-0ff1-40c8-bb22-b5d44f1731c4/code.power b/src/33bdc535-0ff1-40c8-bb22-b5d44f1731c4/code.power new file mode 100644 index 0000000..3cab9cf --- /dev/null +++ b/src/33bdc535-0ff1-40c8-bb22-b5d44f1731c4/code.power @@ -0,0 +1,36 @@ + /** + * Update **ALL** dynamic values in a strings here + * + * @param string $string The content to check + * @param int $debug The switch to debug the update + * We can now at any time debug the + * dynamic build values if it gets broken + * + * @return string + * @since 3.2.0 + */ + public function update(string $string, int $debug = 0): string; + + /** + * Set the custom code data & can load it in to string + * + * @param string $string The content to check + * @param int $debug The switch to debug the update + * @param int|null $not The not switch + * + * @return string + * @since 3.2.0 + */ + public function set(string $string, int $debug = 0, ?int $not = null): string; + + /** + * Load the custom code from the system + * + * @param array|null $ids The custom code ides if known + * @param bool $setLang The set lang switch + * @param int $debug The switch to debug the update + * + * @return bool + * @since 3.2.0 + */ + public function get(?array $ids = null, bool $setLang = true, $debug = 0): bool; \ No newline at end of file diff --git a/src/35191b0c-f7f3-44d6-8ec1-c816b997bd4e/code.power b/src/35191b0c-f7f3-44d6-8ec1-c816b997bd4e/code.power new file mode 100644 index 0000000..6218757 --- /dev/null +++ b/src/35191b0c-f7f3-44d6-8ec1-c816b997bd4e/code.power @@ -0,0 +1,65 @@ + /** + * Compiler Config + * + * @var Config + * @since 3.2.0 + */ + protected Config $config; + + /** + * Compiler Registry + * + * @var Registry + * @since 3.2.0 + */ + protected Registry $registry; + + /** + * Constructor + * + * @param Config|null $config The compiler config. + * @param Registry|null $registry The compiler registry. + * + * @since 3.2.0 + */ + public function __construct(?Config $config = null, ?Registry $registry = null) + { + $this->config = $config ?: Compiler::_('Config'); + $this->registry = $registry ?: Compiler::_('Registry'); + } + + /** + * Set MySQL table settings + * + * @param object $item The item data + * + * @return void + * @since 3.2.0 + */ + public function set(object &$item) + { + foreach ( + $this->config->mysql_table_keys as $mysql_table_key => $mysql_table_val + ) + { + if (isset($item->{'mysql_table_' . $mysql_table_key}) + && StringHelper::check( + $item->{'mysql_table_' . $mysql_table_key} + ) + && !is_numeric($item->{'mysql_table_' . $mysql_table_key})) + { + $this->registry->set('builder.mysql_table_setting.' . $item->name_single_code . '.' . + $mysql_table_key, $item->{'mysql_table_' . $mysql_table_key} + ); + } + else + { + $this->registry->set('builder.mysql_table_setting.' . $item->name_single_code . '.' . + $mysql_table_key, $mysql_table_val['default'] + ); + } + + // remove the table values since we moved to another object + unset($item->{'mysql_table_' . $mysql_table_key}); + } + } diff --git a/src/39ea8150-f124-4e47-909d-641bf1c96d5e/code.power b/src/39ea8150-f124-4e47-909d-641bf1c96d5e/code.power new file mode 100644 index 0000000..178f75f --- /dev/null +++ b/src/39ea8150-f124-4e47-909d-641bf1c96d5e/code.power @@ -0,0 +1,204 @@ + /** + * Compiler Config + * + * @var Config + * @since 3.2.0 + */ + protected Config $config; + + /** + * The compiler registry + * + * @var Registry + * @since 3.2.0 + */ + protected Registry $registry; + + /** + * Compiler Alias Data + * + * @var AliasData + * @since 3.2.0 + */ + protected Aliasdata $alias; + + /** + * Constructor + * + * @param Config|null $config The compiler config object. + * @param Registry|null $registry The compiler registry object. + * @param Aliasdata|null $alias The compiler alias data object. + * + * @since 3.2.0 + */ + public function __construct(?Config $config = null, ?Registry $registry = null, + ?Aliasdata $alias = null) + { + $this->config = $config ?: Compiler::_('Config'); + $this->registry = $registry ?: Compiler::_('Registry'); + $this->alias = $alias ?: Compiler::_('Alias.Data'); + } + + /** + * Set Template and Layout Data + * + * @param string $content The content to check + * @param string $view The view code name + * @param bool $found The proof that something was found + * @param array $templates The option to pass templates keys (to avoid search) + * @param array $layouts The option to pass layout keys (to avoid search) + * + * @return bool if something was found true + * @since 3.2.0 + */ + public function set(string $content, string $view, bool $found = false, + array $templates = [], array $layouts = []): bool + { + // to check inside the templates + $again = []; + + // check if template keys were passed + if (!ArrayHelper::check($templates)) + { + // set the Template data + $temp1 = GetHelper::allBetween( + $content, "\$this->loadTemplate('", "')" + ); + $temp2 = GetHelper::allBetween( + $content, '$this->loadTemplate("', '")' + ); + if (ArrayHelper::check($temp1) + && ArrayHelper::check($temp2)) + { + $templates = array_merge($temp1, $temp2); + } + else + { + if (ArrayHelper::check($temp1)) + { + $templates = $temp1; + } + elseif (ArrayHelper::check($temp2)) + { + $templates = $temp2; + } + } + } + + // check if we found templates + if (ArrayHelper::check($templates, true)) + { + foreach ($templates as $template) + { + if (!$this->registry-> + get('builder.template_data.' . $this->config->build_target . '.' . $view . '.' . $template, null)) + { + $data = $this->alias->get( + $template, 'template', $view + ); + if (ArrayHelper::check($data)) + { + // load it to the template data array + $this->registry-> + set('builder.template_data.' . $this->config->build_target . '.' . $view . '.' . $template, $data); + // call self to get child data + $again[] = ['content' => $data['html'], 'view' => $view]; + $again[] = ['content' => $data['php_view'], 'view' => $view]; + } + } + + // check if we have the template set (and nothing yet found) + if (!$found && $this->registry-> + get('builder.template_data.' . $this->config->build_target . '.' . $view . '.' . $template, null)) + { + // something was found + $found = true; + } + } + } + + // check if layout keys were passed + if (!ArrayHelper::check($layouts)) + { + // set the Layout data + $lay1 = GetHelper::allBetween( + $content, "JLayoutHelper::render('", "'," + ); + $lay2 = GetHelper::allBetween( + $content, 'JLayoutHelper::render("', '",' + ); + if (ArrayHelper::check($lay1) + && ArrayHelper::check($lay2)) + { + $layouts = array_merge($lay1, $lay2); + } + else + { + if (ArrayHelper::check($lay1)) + { + $layouts = $lay1; + } + elseif (ArrayHelper::check($lay2)) + { + $layouts = $lay2; + } + } + } + + // check if we found layouts + if (ArrayHelper::check($layouts, true)) + { + // get the other target if both + $_target = null; + if ($this->config->lang_target === 'both') + { + $_target = ($this->config->build_target === 'admin') ? 'site' : 'admin'; + } + + foreach ($layouts as $layout) + { + if (!$this->registry-> + get('builder.layout_data.' . $this->config->build_target . '.' . $layout, null)) + { + $data = $this->alias->get($layout, 'layout', $view); + if (ArrayHelper::check($data)) + { + // load it to the layout data array + $this->registry-> + set('builder.layout_data.' . $this->config->build_target . '.' . $layout, $data); + // check if other target is set + if ($this->config->lang_target === 'both' && $_target) + { + $this->registry-> + set('builder.layout_data.' . $_target . '.' . $layout, $data); + } + // call self to get child data + $again[] = ['content' => $data['html'], 'view' => $view]; + $again[] = ['content' => $data['php_view'], 'view' => $view]; + } + } + + // check if we have the layout set (and nothing yet found) + if (!$found && $this->registry-> + get('builder.layout_data.' . $this->config->build_target . '.' . $layout, null)) + { + // something was found + $found = true; + } + } + } + + // check again + if (ArrayHelper::check($again)) + { + foreach ($again as $go) + { + $found = $this->set( + $go['content'], $go['view'], $found + ); + } + } + + // return the proof that something was found + return $found; + } diff --git a/src/3b6895da-d9eb-4164-90b1-4632a4cc2474/code.power b/src/3b6895da-d9eb-4164-90b1-4632a4cc2474/code.power new file mode 100644 index 0000000..a347ac8 --- /dev/null +++ b/src/3b6895da-d9eb-4164-90b1-4632a4cc2474/code.power @@ -0,0 +1,296 @@ + /** + * Admin views + * + * @var array + * @since 3.2.0 + */ + protected array $data; + + /** + * Compiler Config + * + * @var Config + * @since 3.2.0 + */ + protected Config $config; + + /** + * Compiler Event + * + * @var EventInterface + * @since 3.2.0 + */ + protected EventInterface $event; + + /** + * Compiler Customcode + * + * @var Customcode + * @since 3.2.0 + */ + protected Customcode $customcode; + + /** + * Compiler Customcode in Gui + * + * @var Gui + * @since 3.2.0 + **/ + protected Gui $gui; + + /** + * Compiler Libraries Model + * + * @var Libraries + * @since 3.2.0 + */ + protected Libraries $libraries; + + /** + * Compiler Template Layout + * + * @var Templatelayout + * @since 3.2.0 + */ + protected Templatelayout $templateLayout; + + /** + * Compiler Dynamic Get Data + * + * @var Dynamicget + * @since 3.2.0 + */ + protected Dynamicget $dynamic; + + /** + * Compiler Auto Loader + * + * @var Loader + * @since 3.2.0 + */ + protected Loader $loader; + + /** + * The modelling javascript + * + * @var Javascriptcustomview + * @since 3.2.0 + */ + protected Javascriptcustomview $javascript; + + /** + * The modelling css + * + * @var Csscustomview + * @since 3.2.0 + */ + protected Csscustomview $css; + + /** + * The modelling php admin view + * + * @var Phpcustomview + * @since 3.2.0 + */ + protected Phpcustomview $php; + + /** + * The modelling custom buttons + * + * @var Custombuttons + * @since 3.2.0 + */ + protected Custombuttons $custombuttons; + + /** + * The modelling ajax + * + * @var Ajaxcustomview + * @since 3.2.0 + */ + protected Ajaxcustomview $ajax; + + /** + * Database object to query local DB + * + * @var \JDatabaseDriver + * @since 3.2.0 + **/ + protected \JDatabaseDriver $db; + + /** + * Constructor + * + * @param Config|null $config The compiler config object. + * @param EventInterface|null $event The compiler event api object. + * @param Customcode|null $customcode The compiler customcode object. + * @param Gui|null $gui The compiler customcode gui. + * @param Libraries|null $libraries The compiler libraries model object. + * @param Templatelayout|null $templateLayout The compiler template layout object. + * @param Dynamicget|null $dynamic The compiler dynamic get data object. + * @param Loader|null $loader The compiler loader object. + * @param Javascriptcustomview|null $javascript The modelling javascript object. + * @param Csscustomview|null $css The modelling css object. + * @param Phpcustomview|null $php The modelling php admin view object. + * @param Ajaxcustomview|null $ajax The modelling ajax object. + * @param Custombuttons|null $custombuttons The modelling custombuttons object. + * @param \JDatabaseDriver|null $db The database object. + * + * @since 3.2.0 + */ + public function __construct(?Config $config = null, ?EventInterface $event = null, + ?Customcode $customcode = null, ?Gui $gui = null, ?Libraries $libraries = null, + ?Templatelayout $templateLayout = null, ?Dynamicget $dynamic = null, ?Loader $loader = null, + ?Javascriptcustomview $javascript = null, ?Csscustomview $css = null, ?Phpcustomview $php = null, + ?Ajaxcustomview $ajax = null, ?Custombuttons $custombuttons = null, ?\JDatabaseDriver $db = null) + { + $this->config = $config ?: Compiler::_('Config'); + $this->event = $event ?: Compiler::_('Event'); + $this->customcode = $customcode ?: Compiler::_('Customcode'); + $this->gui = $gui ?: Compiler::_('Customcode.Gui'); + $this->libraries = $libraries ?: Compiler::_('Model.Libraries'); + $this->templateLayout = $templateLayout ?: Compiler::_('Templatelayout.Data'); + $this->dynamic = $dynamic ?: Compiler::_('Dynamicget.Data'); + $this->loader = $loader ?: Compiler::_('Model.Loader'); + $this->javascript = $javascript ?: Compiler::_('Model.Javascriptcustomview'); + $this->css = $css ?: Compiler::_('Model.Csscustomview'); + $this->php = $php ?: Compiler::_('Model.Phpcustomview'); + $this->ajax = $ajax ?: Compiler::_('Model.Ajaxcustomview'); + $this->custombuttons = $custombuttons ?: Compiler::_('Model.Custombuttons'); + $this->db = $db ?: Factory::getDbo(); + } + + /** + * Get all Custom View Data + * + * @param int $id The view ID + * @param string $table The view table + * + * @return object|null The view data + * @since 3.2.0 + */ + public function get(int $id, string $table = 'site_view'): ?object + { + if (!isset($this->data[$id . $table])) + { + // Create a new query object. + $query = $this->db->getQuery(true); + + $query->select('a.*'); + $query->from('#__componentbuilder_' . $table . ' AS a'); + $query->where($this->db->quoteName('a.id') . ' = ' . (int) $id); + + // for plugin event TODO change event api signatures + $component_context = $this->config->component_context; + + // Trigger Event: jcb_ce_onBeforeQueryCustomViewData + $this->event->trigger( + 'jcb_ce_onBeforeQueryCustomViewData', + array(&$component_context, &$id, &$table, &$query, &$this->db) + ); + + // Reset the query using our newly populated query object. + $this->db->setQuery($query); + + // Load the results as a list of stdClass objects (see later for more options on retrieving data). + $item = $this->db->loadObject(); + + // fix alias to use in code + $item->code = Unique::code( + StringHelper::safe($item->codename), $this->config->build_target + ); + $item->Code = StringHelper::safe($item->code, 'F'); + $item->CODE = StringHelper::safe($item->code, 'U'); + + // Trigger Event: jcb_ce_onBeforeModelCustomViewData + $this->event->trigger( + 'jcb_ce_onBeforeModelCustomViewData', + array(&$component_context, &$item, &$id, &$table) + ); + + // set GUI mapper + $guiMapper = [ + 'table' => $table, + 'id' => (int) $id, + 'field' => 'default', + 'type' => 'html' + ]; + + // set the default data + $item->default = $this->gui->set( + $this->customcode->update(base64_decode((string) $item->default)), + $guiMapper + ); + + // load context if not set + if (!isset($item->context) + || !StringHelper::check( + $item->context + )) + { + $item->context = $item->code; + } + else + { + // always make sure context is a safe string + $item->context = StringHelper::safe($item->context); + } + + // set the libraries + $this->libraries->set($item->code, $item); + + // setup template and layout data + $this->templateLayout->set($item->default, $item->code); + + // set uikit version 2 + $this->loader->uikit($item->code, $item->default); + + // auto loaders + $this->loader->set($item->code, $item->default); + + // set the main get data + $main_get = $this->dynamic->get( + array($item->main_get), $item->code, $item->context + ); + $item->main_get = ArrayHelper::check($main_get) ? $main_get[0] : null; + + // set the custom_get data + $item->custom_get = (isset($item->custom_get) + && JsonHelper::check($item->custom_get)) + ? json_decode((string) $item->custom_get, true) : null; + + if (ArrayHelper::check($item->custom_get)) + { + $item->custom_get = $this->dynamic->get( + $item->custom_get, $item->code, $item->context + ); + } + + // set php scripts + $this->php->set($item, $table); + + // set javascript scripts + $this->javascript->set($item, $table); + + // set css scripts + $this->css->set($item); + + // set Ajax for this view + $this->ajax->set($item, $table); + + // set the custom buttons + $this->custombuttons->set($item, $table); + + // Trigger Event: jcb_ce_onAfterModelCustomViewData + $this->event->trigger( + 'jcb_ce_onAfterModelCustomViewData', + array(&$component_context, &$item) + ); + + // set the found data + $this->data[$id . $table] = $item; + } + + // return the found data + return $this->data[$id . $table]; + } diff --git a/src/4325745f-da1f-4d4d-a591-3189fe8c06e5/code.power b/src/4325745f-da1f-4d4d-a591-3189fe8c06e5/code.power new file mode 100644 index 0000000..9e7e560 --- /dev/null +++ b/src/4325745f-da1f-4d4d-a591-3189fe8c06e5/code.power @@ -0,0 +1,10 @@ + /** + * Get Item History object + * + * @param string $type The type of item + * @param int $id The item ID + * + * @return ?object The history item object + * @since 3.2.0 + */ + public function get(string $type, int $id): ?object; diff --git a/src/4815e1c7-a433-443d-a112-d1e03d7df84b/code.power b/src/4815e1c7-a433-443d-a112-d1e03d7df84b/code.power new file mode 100644 index 0000000..1101401 --- /dev/null +++ b/src/4815e1c7-a433-443d-a112-d1e03d7df84b/code.power @@ -0,0 +1,42 @@ + /** + * 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(Insert::class, 'Insert') + ->share('Insert', [$this, 'getInsert'], 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 Core Insert Database + * + * @param Container $container The DI container. + * + * @return Insert + * @since 3.2.0 + */ + public function getInsert(Container $container): Insert + { + return new Insert(); + } diff --git a/src/489da602-27c7-418c-bf59-1d45ad42bdcc/code.power b/src/489da602-27c7-418c-bf59-1d45ad42bdcc/code.power new file mode 100644 index 0000000..67e82b9 --- /dev/null +++ b/src/489da602-27c7-418c-bf59-1d45ad42bdcc/code.power @@ -0,0 +1,120 @@ + /** + * The areas add array + * + * @var array + * @since 3.2.0 + */ + protected array $areas = [ + 'php_view', + 'php_jview', + 'php_jview_display', + 'php_document' + ]; + + /** + * The gui mapper array + * + * @var array + * @since 3.2.0 + */ + protected array $guiMapper = [ + 'table' => null, + 'id' => null, + 'field' => null, + 'type' => 'php' + ]; + + /** + * Compiler Customcode + * + * @var Customcode + * @since 3.2.0 + */ + protected Customcode $customcode; + + /** + * Compiler Customcode in Gui + * + * @var Gui + * @since 3.2.0 + **/ + protected Gui $gui; + + /** + * Compiler Auto Loader + * + * @var Loader + * @since 3.2.0 + */ + protected Loader $loader; + + /** + * Compiler Template Layout Data + * + * @var Templatelayout + * @since 3.2.0 + */ + protected Templatelayout $templateLayout; + + /** + * Constructor + * + * @param Customcode|null $customcode The compiler customcode object. + * @param Gui|null $gui The compiler customcode gui. + * @param Loader|null $loader The compiler loader object. + * @param Templatelayout|null $templateLayout The template layout data. + * + * @since 3.2.0 + */ + public function __construct(?Customcode $customcode = null, ?Gui $gui = null, + ?Loader $loader = null, ?Templatelayout $templateLayout = null) + { + $this->customcode = $customcode ?: Compiler::_('Customcode'); + $this->gui = $gui ?: Compiler::_('Customcode.Gui'); + $this->loader = $loader ?: Compiler::_('Model.Loader'); + $this->templateLayout = $templateLayout ?: Compiler::_('Templatelayout.Data'); + } + + /** + * Set PHP code + * + * @param object $item The item data + * @param string $table The table + * + * @return void + * @since 3.2.0 + */ + public function set(object &$item, string $table = 'site_view') + { + // set some gui mapper values + $this->guiMapper['table'] = $table; + $this->guiMapper['id'] = (int) $item->id; + + foreach ($this->areas as $area) + { + if (isset($item->{'add_' . $area}) + && $item->{'add_' . $area} == 1 + && StringHelper::check($item->$area)) + { + // update GUI mapper field + $this->guiMapper['field'] = $area; + $item->{$area} = $this->gui->set( + $this->customcode->update( + base64_decode((string) $item->{$area}) + ), + $this->guiMapper + ); + + // check if we have template or layouts to load + $this->templateLayout->set( + $item->{$area}, $item->code + ); + + // auto loaders + $this->loader->set($item->code, $item->{$area}); + + // set uikit version 2 + $this->loader->uikit($item->code, $item->{$area}); + } + } + } diff --git a/src/4b86f62e-ce41-4325-a11a-08148807d0df/code.power b/src/4b86f62e-ce41-4325-a11a-08148807d0df/code.power new file mode 100644 index 0000000..06deba4 --- /dev/null +++ b/src/4b86f62e-ce41-4325-a11a-08148807d0df/code.power @@ -0,0 +1,71 @@ + /** + * event plugin trigger switch + * + * @var boolean + * @since 3.2.0 + */ + protected $activePlugins = false; + + /** + * Constructor + * + * @param Registry|null $params The component parameters + * + * @since 3.2.0 + */ + public function __construct(?Registry $params = null) + { + // Set the params + $params = $params ?: Helper::getParams('com_componentbuilder'); + // get active plugins + if (($plugins = $params->get('compiler_plugin', false)) + !== false) + { + foreach ($plugins as $plugin) + { + // get possible plugins + if (\JPluginHelper::isEnabled('extension', $plugin)) + { + // Import the appropriate plugin group. + \JPluginHelper::importPlugin('extension', $plugin); + // activate events + $this->activePlugins = true; + } + } + } + } + + /** + * Trigger and event + * + * @param string $event The event to trigger + * @param mixed $data The values to pass to the event/plugin + * + * @return void + * @throws \Exception + * @since 3.2.0 + */ + public function trigger(string $event, $data) + { + // only execute if plugins were loaded (active) + if ($this->activePlugins) + { + // Get the dispatcher. + $dispatcher = \JEventDispatcher::getInstance(); + + // Trigger this compiler event. + $results = $dispatcher->trigger($event, $data); + + // Check for errors encountered while trigger the event + if (count((array) $results) && in_array(false, $results, true)) + { + // Get the last error. + $error = $dispatcher->getError(); + + if (!($error instanceof \Exception)) + { + throw new \Exception($error); + } + } + } + } diff --git a/src/4e6ff11d-bebf-42f5-8fd7-b2f882857222/code.power b/src/4e6ff11d-bebf-42f5-8fd7-b2f882857222/code.power new file mode 100644 index 0000000..fb8cbec --- /dev/null +++ b/src/4e6ff11d-bebf-42f5-8fd7-b2f882857222/code.power @@ -0,0 +1,52 @@ + /** + * Should we add debug lines + * + * @since 3.2.0 + **/ + private static $add = 'check'; + + /** + * Set the line number in comments + * + * @param int $nr The line number + * @param string $class The class name + * + * @return string + * @since 3.2.0 + */ + public static function _(int $nr, string $class): string + { + if (self::add()) + { + return ' [' . $class . ' ' . $nr . ']'; + } + + return ''; + } + + /** + * Check if we should add the line number + * + * @return bool + * @since 3.2.0 + */ + private static function add(): bool + { + if (!is_bool(self::$add)) + { + self::init(); + } + + return self::$add; + } + + /** + * The constructor for add + * + * @return void + * @since 3.2.0 + */ + private static function init() + { + self::$add = Compiler::_('Config')->debug_line_nr; + } diff --git a/src/4f575bd6-de97-41f8-80d6-259c8a6dd9ad/code.power b/src/4f575bd6-de97-41f8-80d6-259c8a6dd9ad/code.power new file mode 100644 index 0000000..7e6aa9e --- /dev/null +++ b/src/4f575bd6-de97-41f8-80d6-259c8a6dd9ad/code.power @@ -0,0 +1,141 @@ + /** + * The gui mapper array + * + * @var array + * @since 3.2.0 + */ + protected array $guiMapper = [ + 'table' => 'admin_view', + 'id' => null, + 'field' => null, + 'type' => 'php' + ]; + + /** + * Compiler Config + * + * @var Config + * @since 3.2.0 + */ + protected Config $config; + + /** + * The compiler registry + * + * @var Registry + * @since 3.2.0 + */ + protected Registry $registry; + + /** + * Compiler Customcode Dispenser + * + * @var Dispenser + * @since 3.2.0 + */ + protected Dispenser $dispenser; + + /** + * Constructor + * + * @param Config|null $config The compiler config object. + * @param Registry|null $registry The compiler registry object. + * @param Dispenser|null $dispenser The compiler customcode dispenser + * + * @since 3.2.0 + */ + public function __construct(?Config $config = null, ?Registry $registry = null, ?Dispenser $dispenser = null) + { + $this->config = $config ?: Compiler::_('Config'); + $this->registry = $registry ?: Compiler::_('Registry'); + $this->dispenser = $dispenser ?: Compiler::_('Customcode.Dispenser'); + } + + /** + * Set Ajax Code + * + * @param object $item The item data + * @param string $table The table + * + * @return void + * @since 3.2.0 + */ + public function set(object &$item, string $table = 'admin_view') + { + // set some gui mapper values + $this->guiMapper['table'] = $table; + $this->guiMapper['id'] = (int) $item->id; + + if (isset($item->add_php_ajax) && $item->add_php_ajax == 1) + { + // insure the token is added to edit view at least + $this->dispenser->hub['token'][$item->name_single_code] + = true; + + $add_ajax_site = false; + + if ($this->registry->get('builder.site_edit_view.' . $item->id, false)) + { + // we should add this site ajax to front ajax + $add_ajax_site = true; + $this->config->set('add_site_ajax', true); + } + + // check if controller input as been set + $item->ajax_input = (isset($item->ajax_input) + && JsonHelper::check($item->ajax_input)) + ? json_decode((string) $item->ajax_input, true) : null; + + if (ArrayHelper::check($item->ajax_input)) + { + if ($add_ajax_site) + { + $this->dispenser->hub['site']['ajax_controller'][$item->name_single_code] + = array_values($item->ajax_input); + } + + $this->dispenser->hub['admin']['ajax_controller'][$item->name_single_code] + = array_values($item->ajax_input); + + $this->config->set('add_ajax', true); + + unset($item->ajax_input); + } + + if (StringHelper::check($item->php_ajaxmethod)) + { + // make sure we are still in PHP + $this->guiMapper['type'] = 'php'; + + // update GUI mapper field + $this->guiMapper['field'] = 'php_ajaxmethod'; + + $this->dispenser->set( + $item->php_ajaxmethod, + 'admin', + 'ajax_model', + $item->name_single_code, + $this->guiMapper + ); + + if ($add_ajax_site) + { + $this->dispenser->set( + $item->php_ajaxmethod, + 'site', + 'ajax_model', + $item->name_single_code, + $this->guiMapper, + false, + false + ); + } + + // switch ajax on + $this->config->set('add_ajax', true); + + // unset anyway + unset($item->php_ajaxmethod); + } + } + } diff --git a/src/500f3a7f-c16d-4dd4-81b2-2df6776b5388/code.power b/src/500f3a7f-c16d-4dd4-81b2-2df6776b5388/code.power new file mode 100644 index 0000000..33e700b --- /dev/null +++ b/src/500f3a7f-c16d-4dd4-81b2-2df6776b5388/code.power @@ -0,0 +1,82 @@ + /** + * The hash prefix and suffix + * + * @var string + * @since 3.2.0 + **/ + private static string $hhh = '#' . '#' . '#'; + + /** + * The open prefix + * + * @var string + * @since 3.2.0 + **/ + private static string $bbb = '[' . '[' . '['; + + /** + * The close suffix + * + * @var string + * @since 3.2.0 + **/ + private static string $ddd = ']' . ']' . ']'; + + /** + * Get a prefix and suffix added to given string + * + * @param string $class The class name + * + * @return string + * @since 3.2.0 + */ + public static function _(string $string): string + { + return self::b() . $string . self::d(); + } + + /** + * Get a open prefix + * + * @return string + * @since 3.2.0 + */ + public static function b(): string + { + return self::$bbb; + } + + /** + * Get a close suffix + * + * @return string + * @since 3.2.0 + */ + public static function d(): string + { + return self::$ddd; + } + + /** + * Get a hash prefix and suffix added to given string + * + * @param string $class The class name + * + * @return string + * @since 3.2.0 + */ + public static function _h(string $string): string + { + return self::h() . $string . self::h(); + } + + /** + * Get a hash-fix + * + * @return string + * @since 3.2.0 + */ + public static function h(): string + { + return self::$hhh; + } diff --git a/src/516f93b8-5fff-41c6-aeaf-2d93180a12cc/code.power b/src/516f93b8-5fff-41c6-aeaf-2d93180a12cc/code.power new file mode 100644 index 0000000..c0a7c93 --- /dev/null +++ b/src/516f93b8-5fff-41c6-aeaf-2d93180a12cc/code.power @@ -0,0 +1,173 @@ + /** + * 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(Folder::class, 'Utilities.Folder') + ->share('Utilities.Folder', [$this, 'getFolder'], true); + + $container->alias(File::class, 'Utilities.File') + ->share('Utilities.File', [$this, 'getFile'], true); + + $container->alias(Counter::class, 'Utilities.Counter') + ->share('Utilities.Counter', [$this, 'getCounter'], true); + + $container->alias(Paths::class, 'Utilities.Paths') + ->share('Utilities.Paths', [$this, 'getPaths'], true); + + $container->alias(Files::class, 'Utilities.Files') + ->share('Utilities.Files', [$this, 'getFiles'], true); + + $container->alias(Constantpaths::class, 'Utilities.Constantpaths') + ->share('Utilities.Constantpaths', [$this, 'getConstantpaths'], true); + + $container->alias(Dynamicpath::class, 'Utilities.Dynamicpath') + ->share('Utilities.Dynamicpath', [$this, 'getDynamicpath'], true); + + $container->alias(Pathfix::class, 'Utilities.Pathfix') + ->share('Utilities.Pathfix', [$this, 'getPathfix'], true); + + $container->alias(Structure::class, 'Utilities.Structure') + ->share('Utilities.Structure', [$this, 'getStructure'], true); + } + + /** + * Get the Compiler Folder + * + * @param Container $container The DI container. + * + * @return Folder + * @since 3.2.0 + */ + public function getFolder(Container $container): Folder + { + return new Folder( + $container->get('Utilities.Counter'), + $container->get('Utilities.File') + ); + } + + /** + * Get the Compiler File + * + * @param Container $container The DI container. + * + * @return File + * @since 3.2.0 + */ + public function getFile(Container $container): File + { + return new File( + $container->get('Utilities.Counter') + ); + } + + /** + * Get the Compiler Counter + * + * @param Container $container The DI container. + * + * @return Counter + * @since 3.2.0 + */ + public function getCounter(Container $container): Counter + { + return new Counter( + $container->get('Content') + ); + } + + /** + * Get the Compiler Paths + * + * @param Container $container The DI container. + * + * @return Paths + * @since 3.2.0 + */ + public function getPaths(Container $container): Paths + { + return new Paths( + $container->get('Config'), + $container->get('Component') + ); + } + + /** + * Get the Compiler Files Bucket + * + * @param Container $container The DI container. + * + * @return Files + * @since 3.2.0 + */ + public function getFiles(Container $container): Files + { + return new Files(); + } + + /** + * Get the Constant Paths + * + * @param Container $container The DI container. + * + * @return Constantpaths + * @since 3.2.0 + */ + public function getConstantpaths(Container $container): Constantpaths + { + return new Constantpaths(); + } + + /** + * Get the Compiler Dynamic Path + * + * @param Container $container The DI container. + * + * @return Dynamicpath + * @since 3.2.0 + */ + public function getDynamicpath(Container $container): Dynamicpath + { + return new Dynamicpath( + $container->get('Placeholder'), + $container->get('Utilities.Constantpaths') + ); + } + + /** + * Get the Compiler Path Fixer + * + * @param Container $container The DI container. + * + * @return Pathfix + * @since 3.2.0 + */ + public function getPathfix(Container $container): Pathfix + { + return new Pathfix(); + } + + /** + * Get the Compiler Structure Dynamic Builder + * + * @param Container $container The DI container. + * + * @return Structure + * @since 3.2.0 + */ + public function getStructure(Container $container): Structure + { + return new Structure( + $container->get('Component.Settings'), + $container->get('Utilities.Paths'), + $container->get('Utilities.Counter'), + $container->get('Utilities.File'), + $container->get('Utilities.Files') + ); + } diff --git a/src/53cf9828-7ad4-4856-aac1-7c4c67bd3121/code.power b/src/53cf9828-7ad4-4856-aac1-7c4c67bd3121/code.power new file mode 100644 index 0000000..2a4c105 --- /dev/null +++ b/src/53cf9828-7ad4-4856-aac1-7c4c67bd3121/code.power @@ -0,0 +1,24 @@ + /** + * Get the create date of an item + * + * @param mixed $item The item data + * + * @return string The create data + * @since 3.2.0 + */ + public function get(&$item): string + { + if (isset($item['settings']->created) + && StringHelper::check($item['settings']->created)) + { + // first set the main date + $date = strtotime((string) $item['settings']->created); + } + else + { + // first set the main date + $date = strtotime("now"); + } + + return Factory::getDate($date)->format('jS F, Y'); + } diff --git a/src/55e61314-ba10-4e2b-92dd-b44adebabce9/code.power b/src/55e61314-ba10-4e2b-92dd-b44adebabce9/code.power new file mode 100644 index 0000000..0cdfae3 --- /dev/null +++ b/src/55e61314-ba10-4e2b-92dd-b44adebabce9/code.power @@ -0,0 +1,139 @@ + /** + * Compiler Type Name + * + * @var TypeName + * @since 3.2.0 + */ + protected TypeName $typeName; + + /** + * Compiler Field Name + * + * @var FieldName + * @since 3.2.0 + */ + protected FieldName $fieldName; + + /** + * Constructor + * + * @param TypeName|null $typeName The compiler type name object. + * @param FieldName|null $fieldName The compiler field name object. + * + * @since 3.2.0 + */ + public function __construct(?TypeName $typeName = null, ?FieldName $fieldName = null) + { + $this->typeName = $typeName ?: Compiler::_('Field.Type.Name'); + $this->fieldName = $fieldName ?: Compiler::_('Field.Name'); + } + + /** + * Set the conditions + * + * @param object $item The view data + * + * @return void + * @since 3.2.0 + */ + public function set(object &$item) + { + $item->addconditions = (isset($item->addconditions) + && JsonHelper::check($item->addconditions)) + ? json_decode((string) $item->addconditions, true) : null; + + if (ArrayHelper::check($item->addconditions)) + { + $item->conditions = []; + $ne = 0; + foreach ($item->addconditions as $nr => $conditionValue) + { + if (ArrayHelper::check( + $conditionValue['target_field'] + ) && ArrayHelper::check($item->fields)) + { + foreach ( $conditionValue['target_field'] as $fieldKey => $fieldId) + { + foreach ($item->fields as $fieldValues) + { + if ((int) $fieldValues['field'] == (int) $fieldId) + { + // load the field details + $required = GetHelper::between( + $fieldValues['settings']->xml, + 'required="', '"' + ); + + $required = ($required === 'true' + || $required === '1') ? 'yes' : 'no'; + + $filter = GetHelper::between( + $fieldValues['settings']->xml, + 'filter="', '"' + ); + + $filter = StringHelper::check( + $filter + ) ? $filter : 'none'; + + // set the field name + $conditionValue['target_field'][$fieldKey] = [ + 'name' => $this->fieldName->get( + $fieldValues, $item->name_list_code + ), + 'type' => $this->typeName->get( + $fieldValues + ), + 'required' => $required, + 'filter' => $filter + ]; + + break; + } + } + } + } + + // load match field + if (ArrayHelper::check($item->fields) + && isset($conditionValue['match_field'])) + { + foreach ($item->fields as $fieldValue) + { + if ((int) $fieldValue['field'] == (int) $conditionValue['match_field']) + { + // set the type + $type = $this->typeName->get($fieldValue); + // set the field details + $conditionValue['match_name'] = $this->fieldName->get( + $fieldValue, $item->name_list_code + ); + $conditionValue['match_type'] = $type; + $conditionValue['match_xml'] = $fieldValue['settings']->xml; + + // if custom field load field being extended + if (!FieldHelper::check($type)) + { + $conditionValue['match_extends'] = GetHelper::between( + $fieldValue['settings']->xml, + 'extends="', '"' + ); + } + else + { + $conditionValue['match_extends'] = ''; + } + break; + } + } + } + + // set condition values + $item->conditions[$ne] = $conditionValue; + + $ne++; + } + } + + unset($item->addconditions); + } diff --git a/src/592aed4e-2c5f-4fc5-8f7a-409203d1af82/code.power b/src/592aed4e-2c5f-4fc5-8f7a-409203d1af82/code.power new file mode 100644 index 0000000..c49a96e --- /dev/null +++ b/src/592aed4e-2c5f-4fc5-8f7a-409203d1af82/code.power @@ -0,0 +1,119 @@ + /** + * The gui mapper array + * + * @var array + * @since 3.2.0 + */ + protected array $guiMapper = [ + 'table' => 'site_view', + 'id' => null, + 'field' => null, + 'type' => 'php' + ]; + + /** + * Compiler Config + * + * @var Config + * @since 3.2.0 + */ + protected Config $config; + + /** + * Compiler Customcode Dispenser + * + * @var Dispenser + * @since 3.2.0 + */ + protected Dispenser $dispenser; + + /** + * Constructor + * + * @param Config|null $config The compiler config object. + * @param Dispenser|null $dispenser The compiler customcode dispenser + * + * @since 3.2.0 + */ + public function __construct(?Config $config = null, ?Dispenser $dispenser = null) + { + $this->config = $config ?: Compiler::_('Config'); + $this->dispenser = $dispenser ?: Compiler::_('Customcode.Dispenser'); + } + + /** + * Set Ajax Code + * + * @param object $item The item data + * @param string $table The table + * + * @return void + * @since 3.2.0 + */ + public function set(object &$item, string $table = 'site_view') + { + // add_Ajax for this view + if (isset($item->add_php_ajax) && $item->add_php_ajax == 1) + { + // set some gui mapper values + $this->guiMapper['table'] = $table; + $this->guiMapper['id'] = (int) $item->id; + + // ajax target (since we only have two options really) + if ('site' === $this->config->build_target) + { + $target = 'site'; + } + else + { + $target = 'admin'; + } + + $add_ajax_site = false; + + // check if controller input as been set + $item->ajax_input = (isset($item->ajax_input) + && JsonHelper::check($item->ajax_input)) + ? json_decode((string) $item->ajax_input, true) : null; + + if (ArrayHelper::check($item->ajax_input)) + { + $this->dispenser->hub[$target]['ajax_controller'][$item->code] + = array_values($item->ajax_input); + + $add_ajax_site = true; + } + unset($item->ajax_input); + + // load the ajax class mathods (if set) + if (StringHelper::check($item->php_ajaxmethod)) + { + // set field + $this->guiMapper['field'] = 'php_ajaxmethod'; + $this->dispenser->set( + $item->php_ajaxmethod, + $target, + 'ajax_model', + $item->code, + $this->guiMapper + ); + + $add_ajax_site = true; + } + unset($item->php_ajaxmethod); + + // should ajax be set + if ($add_ajax_site) + { + // turn on ajax area + if ('site' === $this->config->build_target) + { + $this->config->set('add_site_ajax', true); + } + else + { + $this->config->set('add_ajax', true); + } + } + } + } diff --git a/src/59895f37-50c8-4af3-9dad-230e18841953/code.power b/src/59895f37-50c8-4af3-9dad-230e18841953/code.power new file mode 100644 index 0000000..88adc06 --- /dev/null +++ b/src/59895f37-50c8-4af3-9dad-230e18841953/code.power @@ -0,0 +1,83 @@ + /** + * Compiler Config + * + * @var Config + * @since 3.2.0 + */ + protected Config $config; + + /** + * Compiler Registry + * + * @var Registry + * @since 3.2.0 + */ + protected Registry $registry; + + /** + * Compiler Library Data + * + * @var Library + * @since 3.2.0 + */ + protected Library $library; + + /** + * Constructor + * + * @param Config|null $config The compiler config. + * @param Registry|null $registry The compiler registry. + * @param Library|null $library The compiler library data object. + * + * @since 3.2.0 + */ + public function __construct(?Config $config = null, ?Registry $registry = null, ?Library $library = null) + { + $this->config = $config ?: Compiler::_('Config'); + $this->registry = $registry ?: Compiler::_('Registry'); + $this->library = $library ?: Compiler::_('Library.Data'); + } + + /** + * Set Libraries + * + * @param string $key The key mapper + * @param object $item The item data + * @param string|null $target The area being targeted + * + * @return void + * @since 3.2.0 + */ + public function set(string $key, object &$item, string $target = null) + { + // set the target + $target = $target ?: $this->config->build_target; + + // make sure json become array + if (JsonHelper::check($item->libraries)) + { + $item->libraries = json_decode((string) $item->libraries, true); + } + + // if we have an array add it + if (ArrayHelper::check($item->libraries)) + { + foreach ($item->libraries as $library) + { + if (!$this->registry->exists('builder.library_manager.' . + $target . '.' . $key . '.' . (int) $library) && $this->library->get((int) $library)) + { + $this->registry->set('builder.library_manager.' . + $target . '.' . $key . '.' . (int) $library, true); + } + } + } + elseif (is_numeric($item->libraries) + && !$this->registry->exists('builder.library_manager.' . + $target . '.' . $key . '.' . (int) $item->libraries) + && $this->library->get((int) $item->libraries)) + { + $this->registry->set('builder.library_manager.' . + $target . '.' . $key . '.' . (int) $item->libraries, true); + } + } diff --git a/src/5b021139-dad0-4e9b-882a-2b4d807795af/code.power b/src/5b021139-dad0-4e9b-882a-2b4d807795af/code.power new file mode 100644 index 0000000..d9e3d84 --- /dev/null +++ b/src/5b021139-dad0-4e9b-882a-2b4d807795af/code.power @@ -0,0 +1,246 @@ + /** + * Admin view table names + * + * @var array + * @since 3.2.0 + */ + protected array $name; + + /** + * Compiler Config + * + * @var Config + * @since 3.2.0 + */ + protected Config $config; + + /** + * The compiler registry + * + * @var Registry + * @since 3.2.0 + */ + protected Registry $registry; + + /** + * Database object to query local DB + * + * @var \JDatabaseDriver + * @since 3.2.0 + **/ + protected \JDatabaseDriver $db; + + /** + * Constructor + * + * @param Config|null $config The compiler config object. + * @param Registry|null $registry The compiler registry object. + * @param \JDatabaseDriver|null $db The database object. + * + * @since 3.2.0 + */ + public function __construct(?Config $config = null, ?Registry $registry = null, + ?\JDatabaseDriver $db = null) + { + $this->config = $config ?: Compiler::_('Config'); + $this->registry = $registry ?: Compiler::_('Registry'); + $this->db = $db ?: Factory::getDbo(); + } + + /** + * Get Data Selection of the dynamic get + * + * @param string $methodKey The method unique key + * @param string $viewCode The code name of the view + * @param string $string The data string + * @param string $asset The asset in question + * @param string $as The as string + * @param string $type The target type (db||view) + * @param int|null $rowType The row type + * + * @return array|null the select query + * @since 3.2.0 + */ + public function get(string $methodKey, string $viewCode, + string $string, string $asset, string $as, string $type, ?int $rowType = null): ?array + { + if (StringHelper::check($string)) + { + if ('db' === $type) + { + $table = '#__' . $asset; + $queryName = $asset; + $view = ''; + } + elseif ('view' === $type) + { + $view = $this->name($asset); + $table = '#__' . $this->config->component_code_name . '_' . $view; + $queryName = $view; + } + else + { + return null; + } + + // just get all values from table if * is found + if ($string === '*' || strpos($string, '*') !== false) + { + if ($type == 'view') + { + // TODO move getViewTableColumns to its own class + $_string = Helper::_('getViewTableColumns', + [$asset, $as, $rowType] + ); + } + else + { + // TODO move getDbTableColumns to its own class + $_string = Helper::_('getDbTableColumns', + [$asset, $as, $rowType] + ); + } + + // get only selected values + $lines = explode(PHP_EOL, (string) $_string); + + // make sure to set the string to * + $string = '*'; + } + else + { + // get only selected values + $lines = explode(PHP_EOL, $string); + } + + // only continue if lines are available + if (ArrayHelper::check($lines)) + { + $gets = []; + $keys = []; + + // first load all options + foreach ($lines as $line) + { + if (strpos($line, 'AS') !== false) + { + $lineArray = explode("AS", $line); + } + elseif (strpos($line, 'as') !== false) + { + $lineArray = explode("as", $line); + } + else + { + $lineArray = array($line, null); + } + + // set the get and key + $get = trim($lineArray[0]); + $key = trim($lineArray[1]); + + // only add the view (we must adapt this) + if ($this->registry->exists('builder.get_as_lookup.' . $methodKey . '.' . $get) + && 'a' != $as + && is_numeric($rowType) && 1 == $rowType + && 'view' === $type + && strpos('#' . $key, '#' . $view . '_') === false) + { + // this is a problem (TODO) since we may want to not add the view name. + $key = $view . '_' . trim($key); + } + + // continue only if we have get + if (StringHelper::check($get)) + { + $gets[] = $this->db->quote($get); + if (StringHelper::check($key)) + { + $this->registry-> + set('builder.get_as_lookup.' . $methodKey . '.' . $get, $key); + } + else + { + $key = str_replace( + $as . '.', '', $get + ); + + $this->registry-> + set('builder.get_as_lookup.' . $methodKey . '.' . $get, $key); + } + + // set the keys + $keys[] = $this->db->quote( + $key + ); + + // make sure we have the view name + if (StringHelper::check($view)) + { + // prep the field name + $field = str_replace($as . '.', '', $get); + // load to the site fields memory bucket + $this->registry-> + set('builder.site_fields.' . $view . '.' . $field . '.' . $methodKey . '___' . $as, + ['site' => $viewCode, 'get' => $get, 'as' => $as, 'key' => $key]); + } + } + } + + if (ArrayHelper::check($gets) + && ArrayHelper::check($keys)) + { + // single joined selection needs the prefix to the values to avoid conflict in the names + // so we must still add then AS + if ($string == '*' && (is_null($rowType) || 1 != $rowType)) + { + $querySelect = "\$query->select('" . $as . ".*');"; + } + else + { + $querySelect = '$query->select($db->quoteName(' + . PHP_EOL . Indent::_(3) . 'array(' . implode( + ',', $gets + ) . '),' . PHP_EOL . Indent::_(3) . 'array(' + . implode(',', $keys) . ')));'; + } + $queryFrom = '$db->quoteName(' . $this->db->quote($table) + . ', ' . $this->db->quote($as) . ')'; + + // return the select query + return [ + 'select' => $querySelect, + 'from' => $queryFrom, + 'name' => $queryName, + 'table' => $table, + 'type' => $type, + 'select_gets' => $gets, + 'select_keys' => $keys + ]; + } + } + } + + return null; + } + + /** + * Get the Admin view table name + * + * @param int $id The item id to add + * + * @return string the admin view code name + * @since 3.2.0 + */ + protected function name(int $id): string + { + // get name if not set + if (!isset($this->name[$id])) + { + $this->name[$id] = StringHelper::safe( + GetHelper::var('admin_view', $id, 'id', 'name_single') + ); + } + + return $this->name[$id] ?? 'error'; + } diff --git a/src/5c75b455-3d4c-452a-867e-e90424a64c88/code.power b/src/5c75b455-3d4c-452a-867e-e90424a64c88/code.power new file mode 100644 index 0000000..442b433 --- /dev/null +++ b/src/5c75b455-3d4c-452a-867e-e90424a64c88/code.power @@ -0,0 +1,78 @@ + /** + * Compiler Utilities Counter + * + * @var Counter + * @since 3.2.0 + */ + protected Counter $counter; + + /** + * Compiler Utilities Paths + * + * @var Paths + * @since 3.2.0 + */ + protected Paths $paths; + + /** + * Constructor + * + * @param Counter|null $counter The compiler counter object. + * @param Paths|null $paths The compiler paths object. + * + * @since 3.2.0 + */ + public function __construct(?Counter $counter = null, ?Paths $paths = null) + { + $this->counter = $counter ?: Compiler::_('Utilities.Counter'); + $this->paths = $paths ?: Compiler::_('Utilities.Paths'); + } + + /** + * set HTML blank file to a path + * + * @param string $path The path to where to set the blank html file + * @param string $root The root path + * + * @return void + */ + public function html(string $path = '', string $root = 'component') + { + if ('component' === $root) + { + $root = $this->paths->component_path . '/'; + } + + // use path if exist + if (strlen($path) > 0) + { + JoomlaFile::copy( + $this->paths->template_path . '/index.html', + $root . $path . '/index.html' + ); + } + else + { + JoomlaFile::copy( + $this->paths->template_path . '/index.html', + $root . '/index.html' + ); + } + + // count the file created + $this->counter->file++; + } + + /** + * Create a file on the server if it does not exist, or Overwrite existing files + * + * @param string $path The path and file name where to safe the data + * @param string $data The data to safe + * + * @return bool true On success + * @since 3.2.0 + */ + public function write(string $path, string $data): bool + { + return FileHelper::write($path, $data); + } diff --git a/src/5f8e8fa6-3793-44af-882d-9cfb209434e9/code.power b/src/5f8e8fa6-3793-44af-882d-9cfb209434e9/code.power new file mode 100644 index 0000000..cc4343d --- /dev/null +++ b/src/5f8e8fa6-3793-44af-882d-9cfb209434e9/code.power @@ -0,0 +1,79 @@ + /** + * The compiler Registry + * + * @var Registry + * @since 3.2.0 + */ + protected Registry $registry; + + /** + * The compiler field name + * + * @var FieldName + * @since 3.2.0 + */ + protected FieldName $fieldName; + + /** + * Constructor + * + * @param Registry|null $registry The compiler registry object. + * @param FieldName|null $fieldName The compiler field name object. + * + * @since 3.2.0 + */ + public function __construct(?Registry $registry = null, ?FieldName $fieldName = null) + { + $this->registry = $registry ?: Compiler::_('Registry'); + $this->fieldName = $fieldName ?: Compiler::_('Field.Name'); + } + + /** + * Set activate alias builder + * + * @param object $item The item data + * + * @return void + * @since 3.2.0 + */ + public function set(object &$item) + { + if (!$this->registry->get('builder.custom_alias.' . $item->name_single_code, null) + && isset($item->alias_builder_type) && 2 == $item->alias_builder_type + && isset($item->alias_builder) && JsonHelper::check($item->alias_builder)) + { + // get the aliasFields + $alias_fields = (array) json_decode((string) $item->alias_builder, true); + + // get the active fields + $alias_fields = (array) array_filter( + $item->fields, function ($field) use ($alias_fields) { + // check if field is in view fields + if (in_array($field['field'], $alias_fields)) + { + return true; + } + + return false; + } + ); + + // check if all is well + if (ArrayHelper::check($alias_fields)) + { + // load the field names + $this->registry->set('builder.custom_alias.' . $item->name_single_code, + (array) array_map( + function ($field) use (&$item) { + return $this->fieldName->get( + $field, $item->name_list_code + ); + }, $alias_fields + ) + ); + } + } + + // unset + unset($item->alias_builder); + } diff --git a/src/63782f74-7b03-4745-aa40-0adf8ed4e704/code.power b/src/63782f74-7b03-4745-aa40-0adf8ed4e704/code.power new file mode 100644 index 0000000..510195c --- /dev/null +++ b/src/63782f74-7b03-4745-aa40-0adf8ed4e704/code.power @@ -0,0 +1,57 @@ + /** + * Current Joomla Version We are IN + * + * @var int + * @since 3.2.0 + **/ + protected $currentVersion; + + /** + * 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(J3History::class, 'J3.History') + ->share('J3.History', [$this, 'getJ3History'], true); + + $container->alias(HistoryInterface::class, 'History') + ->share('History', [$this, 'getHistory'], true); + } + + /** + * Get the History + * + * @param Container $container The DI container. + * + * @return HistoryInterface + * @since 3.2.0 + */ + public function getHistory(Container $container): HistoryInterface + { + if (empty($this->currentVersion)) + { + $this->currentVersion = Version::MAJOR_VERSION; + } + + return $container->get('J' . $this->currentVersion . '.History'); + } + + /** + * Get the Joomla 3 History + * + * @param Container $container The DI container. + * + * @return J3History + * @since 3.2.0 + */ + public function getJ3History(Container $container): J3History + { + return new J3History( + $container->get('Config') + ); + } diff --git a/src/63dabe82-0f4a-4ade-9851-8518ade23de2/code.power b/src/63dabe82-0f4a-4ade-9851-8518ade23de2/code.power new file mode 100644 index 0000000..c8f3b7f --- /dev/null +++ b/src/63dabe82-0f4a-4ade-9851-8518ade23de2/code.power @@ -0,0 +1,718 @@ + /** + * The standard folders + * + * @var array + * @since 3.2.0 + */ + protected array $standardFolders = [ + 'site', + 'admin', + 'media' + ]; + + /** + * The standard root files + * + * @var array + * @since 3.2.0 + */ + protected array $standardRootFiles = [ + 'access.xml', + 'config.xml', + 'controller.php', + 'index.html', + 'README.txt' + ]; + + /** + * Compiler Joomla Version Data + * + * @var object|null + * @since 3.2.0 + */ + protected ?object $data = null; + + /** + * Compiler Config + * + * @var Config + * @since 3.2.0 + */ + protected Config $config; + + /** + * The compiler registry + * + * @var Registry + * @since 3.2.0 + */ + protected Registry $registry; + + /** + * Compiler Event + * + * @var EventInterface + * @since 3.2.0 + */ + protected EventInterface $event; + + /** + * Compiler Placeholder + * + * @var Placeholder + * @since 3.2.0 + */ + protected Placeholder $placeholder; + + /** + * Compiler Component + * + * @var Component + * @since 3.2.0 + **/ + protected Component $component; + + /** + * Compiler Utilities Paths + * + * @var Paths + * @since 3.2.0 + */ + protected Paths $paths; + + /** + * Compiler Component Dynamic Path + * + * @var Dynamicpath + * @since 3.2.0 + **/ + protected Dynamicpath $dynamicpath; + + /** + * Compiler Component Pathfix + * + * @var Pathfix + * @since 3.2.0 + **/ + protected Pathfix $pathfix; + + /** + * Constructor + * + * @param Config|null $config The compiler config object. + * @param Registry|null $registry The compiler registry object. + * @param EventInterface|null $event The compiler event api object. + * @param Placeholder|null $placeholder The compiler placeholder object. + * @param Component|null $component The component class. + * @param Paths|null $paths The compiler paths object. + * @param Dynamicpath|null $dynamicpath The compiler dynamic path object. + * @param Pathfix|null $pathfix The compiler path fixing object. + * + * @since 3.2.0 + */ + public function __construct(?Config $config = null, ?Registry $registry = null, + ?EventInterface $event = null, ?Placeholder $placeholder = null, + ?Component $component = null, ?Paths $paths = null, + ?Dynamicpath $dynamicpath = null, ?Pathfix $pathfix = null) + { + $this->config = $config ?: Compiler::_('Config'); + $this->registry = $registry ?: Compiler::_('Registry'); + $this->event = $event ?: Compiler::_('Event'); + $this->placeholder = $placeholder ?: Compiler::_('Placeholder'); + $this->component = $component ?: Compiler::_('Component'); + $this->paths = $paths ?: Compiler::_('Utilities.Paths'); + $this->dynamicpath = $dynamicpath ?: Compiler::_('Utilities.Dynamicpath'); + $this->pathfix = $pathfix ?: Compiler::_('Utilities.Pathfix'); + + // add component endpoint file to stander list of root files + $this->standardRootFiles[] = $this->component->get('name_code') . '.php'; + } + + /** + * Check if data set is loaded + * + * @return bool + * @since 3.2.0 + */ + public function exists(): bool + { + if (!$this->isSet()) + { + // load the data + $this->data = $this->get(); + + if (!$this->isSet()) + { + return false; + } + } + + return true; + } + + /** + * Get Joomla - Folder Structure to Create + * + * @return object The version related structure + * @since 3.2.0 + */ + public function structure(): object + { + return $this->data->create; + } + + /** + * Get Joomla - Move Multiple Structure + * + * @return object The version related multiple structure + * @since 3.2.0 + */ + public function multiple(): object + { + return $this->data->move->dynamic; + } + + /** + * Get Joomla - Move Single Structure + * + * @return object The version related single structure + * @since 3.2.0 + */ + public function single(): object + { + return $this->data->move->static; + } + + /** + * Check if Folder is a Standard Folder + * + * @param string $folder The folder name + * + * @return bool true if the folder exists + * @since 3.2.0 + */ + public function standardFolder(string $folder): bool + { + return in_array($folder, $this->standardFolders); + } + + /** + * Check if File is a Standard Root File + * + * @param string $file The file name + * + * @return bool true if the file exists + * @since 3.2.0 + */ + public function standardRootFile(string $file): bool + { + return in_array($file, $this->standardRootFiles); + } + + /** + * Check if Data is Set + * + * @return bool + * @since 3.2.0 + */ + private function isSet(): bool + { + return is_object($this->data) && + isset($this->data->create) && + isset($this->data->move) && + isset($this->data->move->static) && + isset($this->data->move->dynamic); + } + + /** + * get the Joomla Version Data + * + * @return object|null The version data + * @since 3.2.0 + */ + private function get(): ?object + { + // override option + $customSettings = $this->paths->template_path . '/settings_' . + $this->config->component_code_name . '.json'; + + // get the data + $version_data = $this->readJsonFile($customSettings); + + if (is_null($version_data) || !$this->isValidData($version_data)) + { + return null; + } + + $this->loadExtraFolders(); + $this->loadExtraFiles(); + + $this->addFolders($version_data); + $this->addFiles($version_data); + + // for plugin event TODO change event api signatures + $component_context = $this->config->component_context; + + // Trigger Event: jcb_ce_onAfterSetJoomlaVersionData + $this->event->trigger( + 'jcb_ce_onAfterSetJoomlaVersionData', + array(&$component_context, &$version_data) + ); + + return $version_data; + } + + /** + * Read the Json file data + * + * @param string $filePath + * + * @return object|null The version data + * @since 3.2.0 + */ + private function readJsonFile(string $filePath): ?object + { + if (FileHelper::exists($filePath)) + { + $jsonContent = FileHelper::getContent($filePath); + } + else + { + $jsonContent = FileHelper::getContent($this->paths->template_path . '/settings.json'); + } + + if (JsonHelper::check($jsonContent)) + { + return json_decode((string) $jsonContent); + } + + return null; + } + + /** + * Check if this is valid data + * + * @param object $versionData + * + * @return bool + * @since 3.2.0 + */ + private function isValidData(object $versionData): bool + { + return isset($versionData->create) && + isset($versionData->move) && + isset($versionData->move->static) && + isset($versionData->move->dynamic); + } + + /** + * Add Extra/Dynamic folders + * + * @return void + * @since 3.2.0 + */ + private function loadExtraFolders() + { + if ($this->component->isArray('folders') || + $this->config->get('add_eximport', false) || + $this->config->get('uikit', 0) || + $this->config->get('footable', false)) + { + $this->addImportViewFolder(); + $this->addPhpSpreadsheetFolder(); + $this->addUikitFolder(); + $this->addFooTableFolder(); + } + } + + /** + * Add Import and Export Folder + * + * @return void + * @since 3.2.0 + */ + private function addImportViewFolder() + { + if ($this->config->get('add_eximport', false)) + { + $this->component->appendArray('folders', [ + 'folder' => 'importViews', + 'path' => 'admin/views/import', + 'rename' => 1 + ]); + } + } + + /** + * Add Php Spreadsheet Folder + * + * @return void + * @since 3.2.0 + */ + private function addPhpSpreadsheetFolder() + { + // move the phpspreadsheet Folder (TODO we must move this to a library package) + if ($this->config->get('add_eximport', false)) + { + $this->component->appendArray('folders', [ + 'folderpath' => 'JPATH_LIBRARIES/phpspreadsheet/vendor', + 'path' => '/libraries/phpspreadsheet/', + 'rename' => 0 + ]); + } + } + + /** + * Add Uikit Folders + * + * @return void + * @since 3.2.0 + */ + private function addUikitFolder() + { + $uikit = $this->config->get('uikit', 0); + if (2 == $uikit || 1 == $uikit) + { + // move the UIKIT Folder into place + $this->component->appendArray('folders', [ + 'folder' => 'uikit-v2', + 'path' => 'media', + 'rename' => 0 + ]); + } + if (2 == $uikit || 3 == $uikit) + { + // move the UIKIT-3 Folder into place + $this->component->appendArray('folders', [ + 'folder' => 'uikit-v3', + 'path' => 'media', + 'rename' => 0 + ]); + } + } + + /** + * Add Foo Table Folder + * + * @return void + * @since 3.2.0 + */ + private function addFooTableFolder() + { + if (!$this->config->get('footable', false)) + { + return; + } + + $footable_version = $this->config->get('footable_version', 2); + + if (2 == $footable_version) + { + // move the footable folder into place + $this->component->appendArray('folders', [ + 'folder' => 'footable-v2', + 'path' => 'media', + 'rename' => 0 + ]); + } + elseif (3 == $footable_version) + { + // move the footable folder into place + $this->component->appendArray('folders', [ + 'folder' => 'footable-v3', + 'path' => 'media', + 'rename' => 0 + ]); + } + } + + /** + * Add Extra/Dynamic files + * + * @return void + * @since 3.2.0 + */ + private function loadExtraFiles() + { + if ($this->component->isArray('files') || + $this->config->get('google_chart', false)) + { + $this->addGoogleChartFiles(); + } + } + + /** + * Add Google Chart Files + * + * @return void + * @since 3.2.0 + */ + private function addGoogleChartFiles() + { + if ($this->config->get('google_chart', false)) + { + // move the google chart files + $this->component->appendArray('files', [ + 'file' => 'google.jsapi.js', + 'path' => 'media/js', + 'rename' => 0 + ]); + $this->component->appendArray('files', [ + 'file' => 'chartbuilder.php', + 'path' => 'admin/helpers', + 'rename' => 0 + ]); + } + } + + /** + * Add Folders + * + * @param object $versionData + * + * @return void + * @since 3.2.0 + */ + private function addFolders(object &$versionData) + { + if (!$this->component->isArray('folders')) + { + return; + } + + // pointer tracker + $pointer_tracker = 'h'; + foreach ($this->component->get('folders') as $custom) + { + // check type of target type + $_target_type = 'c0mp0n3nt'; + if (isset($custom['target_type'])) + { + $_target_type = $custom['target_type']; + } + + // for good practice + $this->pathfix->set( + $custom, ['path', 'folder', 'folderpath'] + ); + + // fix custom path + if (isset($custom['path']) + && StringHelper::check($custom['path'])) + { + $custom['path'] = trim((string) $custom['path'], '/'); + } + + // by default custom path is true + $customPath = 'custom'; + + // set full path if this is a full path folder + if (!isset($custom['folder']) && isset($custom['folderpath'])) + { + // update the dynamic path + $custom['folderpath'] = $this->dynamicpath->update( + $custom['folderpath'] + ); + + // set the folder path with / if does not have a drive/windows full path + $custom['folder'] = (preg_match( + '/^[a-z]:/i', $custom['folderpath'] + )) ? trim($custom['folderpath'], '/') + : '/' . trim($custom['folderpath'], '/'); + + // remove the file path + unset($custom['folderpath']); + + // triget fullpath + $customPath = 'full'; + } + + // make sure we use the correct name + $pathArray = (array) explode('/', (string) $custom['path']); + $lastFolder = end($pathArray); + + // only rename folder if last has folder name + if (isset($custom['rename']) && $custom['rename'] == 1) + { + $custom['path'] = str_replace( + '/' . $lastFolder, '', (string) $custom['path'] + ); + $rename = 'new'; + $newname = $lastFolder; + } + elseif ('full' === $customPath) + { + // make sure we use the correct name + $folderArray = (array) explode('/', (string) $custom['folder']); + $lastFolder = end($folderArray); + $rename = 'new'; + $newname = $lastFolder; + } + else + { + $rename = false; + $newname = ''; + } + + // insure we have no duplicates + $key_pointer = StringHelper::safe( + $custom['folder'] + ) . '_f' . $pointer_tracker; + + $pointer_tracker++; + + // fix custom path + $custom['path'] = ltrim((string) $custom['path'], '/'); + + // set new folder to object + $versionData->move->static->{$key_pointer} = new \stdClass(); + $versionData->move->static->{$key_pointer}->naam = str_replace('//', '/', (string) $custom['folder']); + $versionData->move->static->{$key_pointer}->path = $_target_type . '/' . $custom['path']; + $versionData->move->static->{$key_pointer}->rename = $rename; + $versionData->move->static->{$key_pointer}->newName = $newname; + $versionData->move->static->{$key_pointer}->type = 'folder'; + $versionData->move->static->{$key_pointer}->custom = $customPath; + + // set the target if type and id is found + if (isset($custom['target_id']) && isset($custom['target_type'])) + { + $versionData->move->static->{$key_pointer}->_target = [ + 'key' => $custom['target_id'] . '_' . $custom['target_type'], + 'type' => $custom['target_type'] + ]; + } + } + + $this->component->remove('folders'); + } + + /** + * Add Files + * + * @param object $versionData + * + * @return void + * @since 3.2.0 + */ + private function addFiles(object &$versionData) + { + if (!$this->component->isArray('files')) { + return; + } + + // pointer tracker + $pointer_tracker = 'h'; + foreach ($this->component->get('files') as $custom) + { + // check type of target type + $_target_type = 'c0mp0n3nt'; + if (isset($custom['target_type'])) + { + $_target_type = $custom['target_type']; + } + + // for good practice + $this->pathfix->set( + $custom, ['path', 'file', 'filepath'] + ); + + // by default custom path is true + $customPath = 'custom'; + + // set full path if this is a full path file + if (!isset($custom['file']) && isset($custom['filepath'])) + { + // update the dynamic path + $custom['filepath'] = $this->dynamicpath->update( + $custom['filepath'] + ); + + // set the file path with / if does not have a drive/windows full path + $custom['file'] = (preg_match('/^[a-z]:/i', $custom['filepath'])) + ? trim($custom['filepath'], '/') : '/' . trim($custom['filepath'], '/'); + + // remove the file path + unset($custom['filepath']); + + // triget fullpath + $customPath = 'full'; + } + + // make sure we have not duplicates + $key_pointer = StringHelper::safe( + $custom['file'] + ) . '_g' . $pointer_tracker; + + $pointer_tracker++; + + // set new file to object + $versionData->move->static->{$key_pointer} = new \stdClass(); + $versionData->move->static->{$key_pointer}->naam = str_replace('//', '/', (string) $custom['file']); + + // update the dynamic component name placholders in file names + $custom['path'] = $this->placeholder->update_( + $custom['path'] + ); + + // get the path info + $pathInfo = pathinfo((string) $custom['path']); + if (isset($pathInfo['extension']) && $pathInfo['extension']) + { + $pathInfo['dirname'] = trim($pathInfo['dirname'], '/'); + + // set the info + $versionData->move->static->{$key_pointer}->path = $_target_type . '/' . $pathInfo['dirname']; + $versionData->move->static->{$key_pointer}->rename = 'new'; + $versionData->move->static->{$key_pointer}->newName = $pathInfo['basename']; + } + elseif ('full' === $customPath) + { + // fix custom path + $custom['path'] = ltrim((string) $custom['path'], '/'); + + // get file array + $fileArray = (array) explode('/', (string) $custom['file']); + + // set the info + $versionData->move->static->{$key_pointer}->path = $_target_type . '/' . $custom['path']; + $versionData->move->static->{$key_pointer}->rename = 'new'; + $versionData->move->static->{$key_pointer}->newName = end($fileArray); + } + else + { + // fix custom path + $custom['path'] = ltrim((string) $custom['path'], '/'); + + // set the info + $versionData->move->static->{$key_pointer}->path = $_target_type . '/' . $custom['path']; + $versionData->move->static->{$key_pointer}->rename = false; + } + + $versionData->move->static->{$key_pointer}->type = 'file'; + $versionData->move->static->{$key_pointer}->custom = $customPath; + + // set the target if type and id is found + if (isset($custom['target_id']) + && isset($custom['target_type'])) + { + $versionData->move->static->{$key_pointer}->_target = [ + 'key' => $custom['target_id'] . '_' . $custom['target_type'], + 'type' => $custom['target_type'] + ]; + } + + // check if file should be updated + if (!isset($custom['notnew']) || $custom['notnew'] == 0 + || $custom['notnew'] != 1) + { + $this->registry->appendArray('files.not.new', $key_pointer); + } + else + { + // update the file content + $this->registry->set('update.file.content.' . $key_pointer, true); + } + } + + $this->component->remove('files'); + } diff --git a/src/673954d3-78d3-445a-b99f-4b40d617c882/code.power b/src/673954d3-78d3-445a-b99f-4b40d617c882/code.power new file mode 100644 index 0000000..2ed3eb0 --- /dev/null +++ b/src/673954d3-78d3-445a-b99f-4b40d617c882/code.power @@ -0,0 +1,582 @@ + /** + * The new name + * + * @var string + * @since 3.2.0 + */ + protected string $newName; + + /** + * Current Full Path + * + * @var string + * @since 3.2.0 + */ + protected string $currentFullPath; + + /** + * Package Full Path + * + * @var string + * @since 3.2.0 + */ + protected string $packageFullPath; + + /** + * ZIP Full Path + * + * @var string + * @since 3.2.0 + */ + protected string $zipFullPath; + + /** + * Compiler Config + * + * @var Config + * @since 3.2.0 + */ + protected Config $config; + + /** + * The compiler registry + * + * @var Registry + * @since 3.2.0 + */ + protected Registry $registry; + + /** + * Compiler Component Joomla Version Settings + * + * @var Settings + * @since 3.2.0 + */ + protected Settings $settings; + + /** + * Compiler Component + * + * @var Component + * @since 3.2.0 + **/ + protected Component $component; + + /** + * Compiler Content + * + * @var Content + * @since 3.2.0 + **/ + protected Content $content; + + /** + * Compiler Counter + * + * @var Counter + * @since 3.2.0 + */ + protected Counter $counter; + + /** + * Compiler Paths + * + * @var Paths + * @since 3.2.0 + */ + protected Paths $paths; + + /** + * Compiler Utilities Files + * + * @var Files + * @since 3.2.0 + */ + protected Files $files; + + /** + * Application object. + * + * @var CMSApplication + * @since 3.2.0 + **/ + protected CMSApplication $app; + + /** + * Constructor + * + * @param Config|null $config The compiler config object. + * @param Registry|null $registry The compiler registry object. + * @param Settings|null $settings The compiler component Joomla version settings object. + * @param Component|null $component The component class. + * @param Content|null $content The compiler content object. + * @param Counter|null $counter The compiler counter object. + * @param Paths|null $paths The compiler paths object. + * @param Files|null $files The compiler files object. + * @param CMSApplication|null $app The CMS Application object. + * + * @throws \Exception + * @since 3.2.0 + */ + public function __construct(?Config $config = null, ?Registry $registry = null, + ?Settings $settings = null, ?Component $component = null, + ?Content $content = null, ?Counter $counter = null, ?Paths $paths = null, + ?Files $files = null, ?CMSApplication $app = null) + { + $this->config = $config ?: Compiler::_('Config'); + $this->registry = $registry ?: Compiler::_('Registry'); + $this->settings = $settings ?: Compiler::_('Component.Settings'); + $this->component = $component ?: Compiler::_('Component'); + $this->content = $content ?: Compiler::_('Content'); + $this->counter = $counter ?: Compiler::_('Utilities.Counter'); + $this->paths = $paths ?: Compiler::_('Utilities.Paths'); + $this->files = $files ?: Compiler::_('Utilities.Files'); + $this->app = $app ?: Factory::getApplication(); + } + + /** + * Build the Single Files & Folders + * + * @return bool + * @since 3.2.0 + */ + public function build(): bool + { + if ($this->settings->exists()) + { + // TODO needs more looking at this must be dynamic actually + $this->registry->appendArray('files.not.new', 'LICENSE.txt'); + + // do license check + $LICENSE = $this->doLicenseCheck(); + + // do README check + $README = $this->doReadmeCheck(); + + // do CHANGELOG check + $CHANGELOG = $this->doChangelogCheck(); + + // start moving + foreach ($this->settings->single() as $target => $details) + { + // if not gnu/gpl license dont add the LICENSE.txt file + if ($details->naam === 'LICENSE.txt' && !$LICENSE) + { + continue; + } + + // if not needed do not add + if (($details->naam === 'README.md' || $details->naam === 'README.txt') + && !$README) + { + continue; + } + + // if not needed do not add + if ($details->naam === 'CHANGELOG.md' && !$CHANGELOG) + { + continue; + } + + // set new name + $this->setNewName($details); + + // set all paths + $this->setPaths($details); + + // check if the path exists + if ($this->pathExist($details)) + { + // set the target + $this->setTarget($target, $details); + } + + // set dynamic target as needed + $this->setDynamicTarget($details); + } + + return true; + } + + return false; + } + + /** + * Check if license must be added + * + * @return bool + * @since 3.2.0 + */ + private function doLicenseCheck(): bool + { + $licenseChecker = strtolower((string) $this->component->get('license', '')); + + if (strpos($licenseChecker, 'gnu') !== false + && strpos( + $licenseChecker, '2' + ) !== false + && (strpos($licenseChecker, 'gpl') !== false + || strpos( + $licenseChecker, 'General public license' + ) !== false)) + { + return true; + } + + return false; + } + + /** + * Check if readme must be added + * + * @return bool + * @since 3.2.0 + */ + private function doReadmeCheck(): bool + { + return (bool) $this->component->get('addreadme', false); + } + + /** + * Check if changelog must be added + * + * @return bool + * @since 3.2.0 + */ + private function doChangelogCheck(): bool + { + return (bool) $this->component->get('changelog', false); + } + + /** + * Set the new name + * + * @param object $details + * + * @return void + * @since 3.2.0 + */ + private function setNewName(object $details) + { + // do the file renaming + if (isset($details->rename) && $details->rename) + { + if ($details->rename === 'new') + { + $this->newName = $details->newName; + } + else + { + $this->newName = str_replace( + $details->rename, + $this->config->component_code_name, + (string) $details->naam + ); + } + } + else + { + $this->newName = $details->naam; + } + } + + /** + * Set all needed paths + * + * @param object $details + * + * @return void + * @since 3.2.0 + */ + private function setPaths(object $details) + { + // check if we have a target value + if (isset($details->_target)) + { + // set destination path + $zipPath = str_replace( + $details->_target['type'] . '/', '', (string) $details->path + ); + $path = str_replace( + $details->_target['type'] . '/', + $this->registry->get('dynamic_paths.' . $details->_target['key'], '') . '/', + (string) $details->path + ); + } + else + { + // set destination path + $zipPath = str_replace('c0mp0n3nt/', '', (string) $details->path); + $path = str_replace( + 'c0mp0n3nt/', $this->paths->component_path . '/', (string) $details->path + ); + } + + // set the template folder path + $templatePath = (isset($details->custom) && $details->custom) + ? (($details->custom !== 'full') ? $this->paths->template_path_custom + . '/' : '') : $this->paths->template_path . '/'; + + // set the final paths + $currentFullPath = (preg_match('/^[a-z]:/i', (string) $details->naam)) ? $details->naam + : $templatePath . '/' . $details->naam; + + $this->currentFullPath = str_replace('//', '/', (string) $currentFullPath); + + $this->packageFullPath = str_replace('//', '/', $path . '/' . $this->newName); + + $this->zipFullPath = str_replace( + '//', '/', $zipPath . '/' . $this->newName + ); + } + + /** + * Check if path exists + * + * @param object $details + * + * @return bool + * @since 3.2.0 + */ + private function pathExist(object $details): bool + { + // check if this has a type + if (!isset($details->type)) + { + return false; + } + // take action based on type + elseif ($details->type === 'file' && !File::exists($this->currentFullPath)) + { + $this->app->enqueueMessage( + Text::_('

File Path Error

'), 'Error' + ); + $this->app->enqueueMessage( + Text::sprintf('The file path: %s does not exist, and was not added!', + $this->currentFullPath + ), 'Error' + ); + + return false; + } + elseif ($details->type === 'folder' && !Folder::exists($this->currentFullPath)) + { + $this->app->enqueueMessage( + Text::_('

Folder Path Error

'), + 'Error' + ); + $this->app->enqueueMessage( + Text::sprintf('The folder path: %s does not exist, and was not added!', + $this->currentFullPath + ), 'Error' + ); + + return false; + } + + return true; + } + + /** + * Set the target based on target type + * + * @param string $target + * @param object $details + * + * @return void + * @since 3.2.0 + */ + private function setTarget(string $target, object $details) + { + // take action based on type + if ($details->type === 'file') + { + // move the file + $this->moveFile(); + + // register the file + $this->registerFile($target, $details); + } + elseif ($details->type === 'folder') + { + // move the folder to its place + Folder::copy( + $this->currentFullPath, $this->packageFullPath, '', true + ); + + // count the folder created + $this->counter->folder++; + } + } + + /** + * Move/Copy the file into place + * + * @return void + * @since 3.2.0 + */ + private function moveFile() + { + // get base name && get the path only + $packageFullPath0nly = str_replace( + basename($this->packageFullPath), '', $this->packageFullPath + ); + + // check if path exist, if not creat it + if (!Folder::exists($packageFullPath0nly)) + { + Folder::create($packageFullPath0nly); + } + + // move the file to its place + File::copy($this->currentFullPath, $this->packageFullPath); + + // count the file created + $this->counter->file++; + } + + /** + * Register the file + * + * @param string $target + * @param object $details + * + * @return void + * @since 3.2.0 + */ + private function registerFile(string $target, object $details) + { + // store the new files + if (!in_array($target, $this->registry->get('files.not.new', []))) + { + if (isset($details->_target)) + { + $this->files->appendArray($details->_target['key'], + [ + 'path' => $this->packageFullPath, + 'name' => $this->newName, + 'zip' => $this->zipFullPath + ] + ); + } + else + { + $this->files->appendArray('static', + [ + 'path' => $this->packageFullPath, + 'name' => $this->newName, + 'zip' => $this->zipFullPath + ] + ); + } + } + + // ensure we update this file if needed + if ($this->registry->exists('update.file.content.' . $target)) + { + // remove the pointer + $this->registry->remove('update.file.content.' . $target); + + // set the full path + $this->registry->set('update.file.content.' . $this->packageFullPath, $this->packageFullPath); + } + } + + /** + * Set Dynamic Target + * + * @param object $details + * + * @return void + * @since 3.2.0 + */ + private function setDynamicTarget(object $details) + { + // only add if no target found since those belong to plugins and modules + if (!isset($details->_target)) + { + // check if we should add the dynamic folder moving script to the installer script + $checker = array_values((array) explode('/', $this->zipFullPath)); + + // TODO <-- this may not be the best way, will keep an eye on this. + // We basicly only want to check if a folder is added that is not in the stdFolders array + if (isset($checker[0]) + && StringHelper::check($checker[0]) + && !$this->settings->standardFolder($checker[0])) + { + // activate dynamic folders + $this->setDynamicFolders(); + } + elseif (count((array) $checker) == 2 + && StringHelper::check($checker[0])) + { + $add_to_extra = false; + + // set the target + $eNAME = 'FILES'; + $ename = 'filename'; + + // this should not happen and must have been caught by the above if statment + if ($details->type === 'folder') + { + // only folders outside the standard folder are added + $eNAME = 'FOLDERS'; + $ename = 'folder'; + $add_to_extra = true; + } + // if this is a file, it can only be added to the admin/site/media folders + // all other folders are moved as a whole so their files do not need to be declared + elseif ($this->settings->standardFolder($checker[0]) + && !$this->settings->standardRootFile($checker[1])) + { + $add_to_extra = true; + } + + // add if valid folder/file + if ($add_to_extra) + { + // set the tab + $eTab = Indent::_(2); + if ('admin' === $checker[0]) + { + $eTab = Indent::_(3); + } + + // set the xml file + $key_ = 'EXSTRA_' + . StringHelper::safe( + $checker[0], 'U' + ) . '_' . $eNAME; + $this->content->add($key_, + PHP_EOL . $eTab . "<" . $ename . ">" + . $checker[1] . ""); + } + } + } + } + + /** + * Add the dynamic folders + * + * @return void + * @since 3.2.0 + */ + private function setDynamicFolders() + { + // check if we should add the dynamic folder moving script to the installer script + if (!$this->registry->get('set_move_folders_install_script')) + { + // add the setDynamicF0ld3rs() method to the install scipt.php file + $this->registry->set('set_move_folders_install_script', true); + + // set message that this was done (will still add a tutorial link later) + $this->app->enqueueMessage( + Text::_('

Dynamic folder(s) were detected.

'), + 'Notice' + ); + $this->app->enqueueMessage( + Text::sprintf('A method (setDynamicF0ld3rs) was added to the install script.php of this package to insure that the folder(s) are copied into the correct place when this component is installed!'), + 'Notice' + ); + } + } diff --git a/src/6784dd52-0909-451a-a872-9a942a023c68/README.md b/src/6784dd52-0909-451a-a872-9a942a023c68/README.md new file mode 100644 index 0000000..ea57ab7 --- /dev/null +++ b/src/6784dd52-0909-451a-a872-9a942a023c68/README.md @@ -0,0 +1,138 @@ +``` +██████╗ ██████╗ ██╗ ██╗███████╗██████╗ +██╔══██╗██╔═══██╗██║ ██║██╔════╝██╔══██╗ +██████╔╝██║ ██║██║ █╗ ██║█████╗ ██████╔╝ +██╔═══╝ ██║ ██║██║███╗██║██╔══╝ ██╔══██╗ +██║ ╚██████╔╝╚███╔███╔╝███████╗██║ ██║ +╚═╝ ╚═════╝ ╚══╝╚══╝ ╚══════╝╚═╝ ╚═╝ +``` +# final class Grep (Details) +> namespace: **VDM\Joomla\Componentbuilder\Power** +```uml +@startuml +class Grep << (F,LightGreen) >> #Green { + + string $path + + ?array $paths + # Contents $contents + # CMSApplication $app + + __construct(string $path, array $paths, ...) + + get(string $guid, array $order = ['Local', 'Remote']) : ?object + - searchLocal(string $guid) : ?object + - searchRemote(string $guid) : ?object + - getLocal(object $path, string $guid) : ?object + - getRemote(object $path, string $guid) : ?object + - init() : void + - localIndex(object $path) : void + - remoteIndex(object $path) : void + - loadRemoteFile(string $owner, string $repo, ...) : mixed + - getCode(string $code) : ?string + - getLicense(string $code) : ?string +} + +note right of Grep::__construct + Constructor. + + since: 3.2.0 + + arguments: + string $path + array $paths + Contents $contents + ?CMSApplication $app = null +end note + +note left of Grep::get + Get a power + + since: 3.2.0 + return: ?object +end note + +note right of Grep::searchLocal + Search for a local power + + since: 3.2.0 + return: ?object +end note + +note left of Grep::searchRemote + Search for a remote power + + since: 3.2.0 + return: ?object +end note + +note right of Grep::getLocal + Get a local power + + since: 3.2.0 + return: ?object +end note + +note left of Grep::getRemote + Get a remote power + + since: 3.2.0 + return: ?object +end note + +note right of Grep::init + Set path details + + since: 3.2.0 + return: void +end note + +note left of Grep::localIndex + Load the local repository index of powers + + since: 3.2.0 + return: void +end note + +note right of Grep::remoteIndex + Load the remote repository index of powers + + since: 3.2.0 + return: void +end note + +note left of Grep::loadRemoteFile + Load the remote file + + since: 3.2.0 + return: mixed + + arguments: + string $owner + string $repo + string $path + ?string $branch +end note + +note right of Grep::getCode + Get the class body + + return: ?string +end note + +note left of Grep::getLicense + Get the class license + + return: ?string +end note + +@enduml +``` + +--- +``` + ██╗ ██████╗██████╗ + ██║██╔════╝██╔══██╗ + ██║██║ ██████╔╝ +██ ██║██║ ██╔══██╗ +╚█████╔╝╚██████╗██████╔╝ + ╚════╝ ╚═════╝╚═════╝ +``` +> Build with [Joomla Component Builder](https://git.vdm.dev/joomla/Component-Builder) + diff --git a/src/6784dd52-0909-451a-a872-9a942a023c68/code.php b/src/6784dd52-0909-451a-a872-9a942a023c68/code.php new file mode 100644 index 0000000..2003855 --- /dev/null +++ b/src/6784dd52-0909-451a-a872-9a942a023c68/code.php @@ -0,0 +1,454 @@ + + * @git 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\Power; + + +use Joomla\CMS\Factory; +use Joomla\CMS\Filesystem\Folder; +use Joomla\CMS\Application\CMSApplication; +use Joomla\CMS\Language\Text; +use VDM\Joomla\Gitea\Repository\Contents; +use VDM\Joomla\Utilities\FileHelper; +use VDM\Joomla\Utilities\JsonHelper; + + +/** + * Power Grep + * The Grep feature will try to find your power in the repositories listed in the global + * Options of JCB in the super powers tab, and if it can't be found there will try the global core + * Super powers of JCB. All searches are performed according the the [algorithm:cascading] + * See documentation for more details: https://git.vdm.dev/joomla/super-powers/wiki + * + * @since 3.2.0 + */ +final class Grep +{ + /** + * The local path + * + * @var array + * @since 3.2.0 + **/ + public string $path; + + /** + * All approved paths + * + * @var array + * @since 3.2.0 + **/ + public ?array $paths; + + /** + * Gitea Repository Contents + * + * @var Contents + * @since 3.2.0 + **/ + protected Contents $contents; + + /** + * Joomla Application object + * + * @var CMSApplication + * @since 3.2.0 + **/ + protected CMSApplication $app; + + /** + * Constructor. + * + * @param string $path The the local path + * @param array $paths The the approved paths + * @param Contents $contents The Gitea Repository Contents object. + * @param CMSApplication|null $app The CMS Application object. + * + * @throws \Exception + * @since 3.2.0 + */ + public function __construct(string $path, array $paths, Contents $contents, ?CMSApplication $app = null) + { + $this->path = $path; + $this->paths = $paths; + $this->contents = $contents; + $this->app = $app ?: Factory::getApplication(); + + $this->init(); + } + + /** + * Get a power + * + * @param string $guid The global unique id of the power + * @param array $order The search order + * + * @return object|null + * @since 3.2.0 + */ + public function get(string $guid, $order = ['Local', 'Remote']): ?object + { + // we can only search if we have paths + if (is_array($this->paths) && $this->paths !== []) + { + foreach ($order as $target) + { + if (($power = $this->{'search' . $target}($guid)) !== null) + { + return $power; + } + } + } + + return null; + } + + /** + * Search for a local power + * + * @param string $guid The global unique id of the power + * + * @return object|null + * @since 3.2.0 + */ + private function searchLocal(string $guid): ?object + { + // we can only search if we have paths + if ($this->path && $this->paths) + { + foreach ($this->paths as $path) + { + // get local index + $this->localIndex($path); + + if (!empty($path->local) && isset($path->local->{$guid})) + { + return $this->getLocal($path, $guid); + } + } + } + + return null; + } + + /** + * Search for a remote power + * + * @param string $guid The global unique id of the power + * + * @return object|null + * @since 3.2.0 + */ + private function searchRemote(string $guid): ?object + { + // we can only search if we have paths + if ($this->path && $this->paths) + { + foreach ($this->paths as $path) + { + // get local index + $this->remoteIndex($path); + + if (!empty($path->index) && isset($path->index->{$guid})) + { + return $this->getRemote($path, $guid); + } + } + } + + return null; + } + + /** + * Get a local power + * + * @param object $path The repository path details + * @param string $guid The global unique id of the power + * + * @return object|null + * @since 3.2.0 + */ + private function getLocal(object $path, string $guid): ?object + { + if (empty($path->local->{$guid}->settings) || empty($path->local->{$guid}->code)) + { + return null; + } + + // get the settings + if (($settings = FileHelper::getContent($this->full_path . '/' . $path->local->{$guid}->settings, null)) !== null && + JsonHelper::check($settings)) + { + $power = json_decode($settings); + + // get the code + if (($code = FileHelper::getContent($this->full_path . '/' . $path->local->{$guid}->code, null)) !== null) + { + $power->main_class_code = $this->getCode($code); + $power->licensing_template = $this->getLicense($code); + + return $power; + } + } + + return null; + } + + /** + * Get a remote power + * + * @param object $path The repository path details + * @param string $guid The global unique id of the power + * + * @return object|null + * @since 3.2.0 + */ + private function getRemote(object $path, string $guid): ?object + { + if (empty($path->index->{$guid}->settings) || empty($path->index->{$guid}->code)) + { + return null; + } + + // get the settings + if (($power = $this->loadRemoteFile($path->owner, $path->repo, $path->index->{$guid}->settings, $path->branch)) !== null && + isset($power->guid)) + { + // get the code + if (($code = $this->loadRemoteFile($path->owner, $path->repo, $path->index->{$guid}->code, $path->branch)) !== null) + { + $power->main_class_code = $this->getCode($code); + $power->licensing_template = $this->getLicense($code); + + return $power; + } + } + + return null; + } + + /** + * Set path details + * + * @return void + * @since 3.2.0 + */ + private function init() + { + if (!Folder::exists($this->path)) + { + $this->path = null; + } + + if (is_array($this->paths) && $this->paths !== []) + { + foreach ($this->paths as $n => &$path) + { + if (isset($path->owner) && strlen($path->owner) > 1 && + isset($path->repo) && strlen($path->repo) > 1) + { + // build the path + $path->path = trim($path->owner) . '/' . trim($path->repo); + + // update the branch + if ($path->branch === 'default' || empty($path->branch)) + { + $path->branch = null; + } + + // set local path + if ($this->path && Folder::exists($this->path . '/' . $path->path)) + { + $this->full_path = $this->path . '/' . $path->path; + } + } + else + { + unset($this->paths[$n]); + } + } + + // if we still have paths + if ($this->paths !== []) + { + return; + } + } + + $this->paths = null; + } + + /** + * Load the local repository index of powers + * + * @param object $path The repository path details + * + * @return void + * @since 3.2.0 + */ + private function localIndex(object &$path) + { + if (isset($path->local) || !isset($this->full_path)) + { + return; + } + + if (($content = FileHelper::getContent($this->full_path . '/super-powers.json', null)) !== null && + JsonHelper::check($content)) + { + $path->local = json_decode($content); + + return; + } + + $path->local = null; + } + + /** + * Load the remote repository index of powers + * + * @param object $path The repository path details + * + * @return void + * @since 3.2.0 + */ + private function remoteIndex(object &$path) + { + if (isset($path->index)) + { + return; + } + + try + { + $path->index = $this->contents->get($path->owner, $path->repo, 'super-powers.json', $path->branch); + } + catch (\DomainException $e) + { + $this->app->enqueueMessage( + Text::sprintf('COM_COMPONENTBUILDER_PSUPER_POWERB_REPOSITORY_AT_BGITVDMDEVSB_GAVE_THE_FOLLOWING_ERRORBR_SP', $path->path, $e->getMessage()), + 'Error' + ); + + $path->index = null; + } + } + + /** + * Load the remote file + * + * @param string $owner The repository owner + * @param string $repo The repository name + * @param string $path The repository path to file + * @param string|null $branch The repository branch name + * + * @return mixed + * @since 3.2.0 + */ + private function loadRemoteFile(string $owner, string $repo, string $path, ?string $branch) + { + try + { + $data = $this->contents->get($owner, $repo, $path, $branch); + } + catch (\DomainException $e) + { + $this->app->enqueueMessage( + Text::sprintf('COM_COMPONENTBUILDER_PFILE_AT_BGITEAREMOTESB_GAVE_THE_FOLLOWING_ERRORBR_SP', $path, $e->getMessage()), + 'Error' + ); + + return null; + } + + return $data; + } + + /** + * Get the class body + * + * @param string $code The class + * + * @return string|null The class body, or null if not found + **/ + private function getCode($code): ?string + { + // Match class, final class, abstract class, interface, and trait + $pattern = '/(?:class|final class|abstract class|interface|trait)\s+[a-zA-Z0-9_]+\s*(?:extends\s+[a-zA-Z0-9_]+\s*)?(?:implements\s+[a-zA-Z0-9_]+(?:\s*,\s*[a-zA-Z0-9_]+)*)?\s*\{/s'; + + // Split the input code based on the class declaration pattern + $parts = preg_split($pattern, $code, 2, PREG_SPLIT_DELIM_CAPTURE); + $body = $parts[1] ?? ''; + + if ($body !== '') + { + // Remove leading and trailing white space + $body = trim($body); + + // Remove the first opening curly brace if it exists + if (mb_substr($body, 0, 1) === '{') + { + $body = mb_substr($body, 1); + } + + // Remove the last closing curly brace if it exists + if (mb_substr($body, -1) === '}') + { + $body = mb_substr($body, 0, -1); + } + + return $body; + } + + // No class body found, return null + return null; + } + + /** + * Get the class license + * + * @param string $code The class + * + * @return string|null The class license, or null if not found + **/ + private function getLicense($code): ?string + { + // Check if the file starts with 'path = $path; + $this->paths = $paths; + $this->contents = $contents; + $this->app = $app ?: Factory::getApplication(); + + $this->init(); + } + + /** + * Get a power + * + * @param string $guid The global unique id of the power + * @param array $order The search order + * + * @return object|null + * @since 3.2.0 + */ + public function get(string $guid, $order = ['Local', 'Remote']): ?object + { + // we can only search if we have paths + if (is_array($this->paths) && $this->paths !== []) + { + foreach ($order as $target) + { + if (($power = $this->{'search' . $target}($guid)) !== null) + { + return $power; + } + } + } + + return null; + } + + /** + * Search for a local power + * + * @param string $guid The global unique id of the power + * + * @return object|null + * @since 3.2.0 + */ + private function searchLocal(string $guid): ?object + { + // we can only search if we have paths + if ($this->path && $this->paths) + { + foreach ($this->paths as $path) + { + // get local index + $this->localIndex($path); + + if (!empty($path->local) && isset($path->local->{$guid})) + { + return $this->getLocal($path, $guid); + } + } + } + + return null; + } + + /** + * Search for a remote power + * + * @param string $guid The global unique id of the power + * + * @return object|null + * @since 3.2.0 + */ + private function searchRemote(string $guid): ?object + { + // we can only search if we have paths + if ($this->path && $this->paths) + { + foreach ($this->paths as $path) + { + // get local index + $this->remoteIndex($path); + + if (!empty($path->index) && isset($path->index->{$guid})) + { + return $this->getRemote($path, $guid); + } + } + } + + return null; + } + + /** + * Get a local power + * + * @param object $path The repository path details + * @param string $guid The global unique id of the power + * + * @return object|null + * @since 3.2.0 + */ + private function getLocal(object $path, string $guid): ?object + { + if (empty($path->local->{$guid}->settings) || empty($path->local->{$guid}->code)) + { + return null; + } + + // get the settings + if (($settings = FileHelper::getContent($this->full_path . '/' . $path->local->{$guid}->settings, null)) !== null && + JsonHelper::check($settings)) + { + $power = json_decode($settings); + + // get the code + if (($code = FileHelper::getContent($this->full_path . '/' . $path->local->{$guid}->code, null)) !== null) + { + $power->main_class_code = $this->getCode($code); + $power->licensing_template = $this->getLicense($code); + + return $power; + } + } + + return null; + } + + /** + * Get a remote power + * + * @param object $path The repository path details + * @param string $guid The global unique id of the power + * + * @return object|null + * @since 3.2.0 + */ + private function getRemote(object $path, string $guid): ?object + { + if (empty($path->index->{$guid}->settings) || empty($path->index->{$guid}->code)) + { + return null; + } + + // get the settings + if (($power = $this->loadRemoteFile($path->owner, $path->repo, $path->index->{$guid}->settings, $path->branch)) !== null && + isset($power->guid)) + { + // get the code + if (($code = $this->loadRemoteFile($path->owner, $path->repo, $path->index->{$guid}->code, $path->branch)) !== null) + { + $power->main_class_code = $this->getCode($code); + $power->licensing_template = $this->getLicense($code); + + return $power; + } + } + + return null; + } + + /** + * Set path details + * + * @return void + * @since 3.2.0 + */ + private function init() + { + if (!Folder::exists($this->path)) + { + $this->path = null; + } + + if (is_array($this->paths) && $this->paths !== []) + { + foreach ($this->paths as $n => &$path) + { + if (isset($path->owner) && strlen($path->owner) > 1 && + isset($path->repo) && strlen($path->repo) > 1) + { + // build the path + $path->path = trim($path->owner) . '/' . trim($path->repo); + + // update the branch + if ($path->branch === 'default' || empty($path->branch)) + { + $path->branch = null; + } + + // set local path + if ($this->path && Folder::exists($this->path . '/' . $path->path)) + { + $this->full_path = $this->path . '/' . $path->path; + } + } + else + { + unset($this->paths[$n]); + } + } + + // if we still have paths + if ($this->paths !== []) + { + return; + } + } + + $this->paths = null; + } + + /** + * Load the local repository index of powers + * + * @param object $path The repository path details + * + * @return void + * @since 3.2.0 + */ + private function localIndex(object &$path) + { + if (isset($path->local) || !isset($this->full_path)) + { + return; + } + + if (($content = FileHelper::getContent($this->full_path . '/super-powers.json', null)) !== null && + JsonHelper::check($content)) + { + $path->local = json_decode($content); + + return; + } + + $path->local = null; + } + + /** + * Load the remote repository index of powers + * + * @param object $path The repository path details + * + * @return void + * @since 3.2.0 + */ + private function remoteIndex(object &$path) + { + if (isset($path->index)) + { + return; + } + + try + { + $path->index = $this->contents->get($path->owner, $path->repo, 'super-powers.json', $path->branch); + } + catch (\DomainException $e) + { + $this->app->enqueueMessage( + Text::sprintf('

Super Power repository at git.vdm.dev/%s gave the following error!
%s

', $path->path, $e->getMessage()), + 'Error' + ); + + $path->index = null; + } + } + + /** + * Load the remote file + * + * @param string $owner The repository owner + * @param string $repo The repository name + * @param string $path The repository path to file + * @param string|null $branch The repository branch name + * + * @return mixed + * @since 3.2.0 + */ + private function loadRemoteFile(string $owner, string $repo, string $path, ?string $branch) + { + try + { + $data = $this->contents->get($owner, $repo, $path, $branch); + } + catch (\DomainException $e) + { + $this->app->enqueueMessage( + Text::sprintf('

File at gitea.remote/%s gave the following error!
%s

', $path, $e->getMessage()), + 'Error' + ); + + return null; + } + + return $data; + } + + /** + * Get the class body + * + * @param string $code The class + * + * @return string|null The class body, or null if not found + **/ + private function getCode($code): ?string + { + // Match class, final class, abstract class, interface, and trait + $pattern = '/(?:class|final class|abstract class|interface|trait)\s+[a-zA-Z0-9_]+\s*(?:extends\s+[a-zA-Z0-9_]+\s*)?(?:implements\s+[a-zA-Z0-9_]+(?:\s*,\s*[a-zA-Z0-9_]+)*)?\s*\{/s'; + + // Split the input code based on the class declaration pattern + $parts = preg_split($pattern, $code, 2, PREG_SPLIT_DELIM_CAPTURE); + $body = $parts[1] ?? ''; + + if ($body !== '') + { + // Remove leading and trailing white space + $body = trim($body); + + // Remove the first opening curly brace if it exists + if (mb_substr($body, 0, 1) === '{') + { + $body = mb_substr($body, 1); + } + + // Remove the last closing curly brace if it exists + if (mb_substr($body, -1) === '}') + { + $body = mb_substr($body, 0, -1); + } + + return $body; + } + + // No class body found, return null + return null; + } + + /** + * Get the class license + * + * @param string $code The class + * + * @return string|null The class license, or null if not found + **/ + private function getLicense($code): ?string + { + // Check if the file starts with 'counter = $counter ?: Compiler::_('Utilities.Counter'); + $this->file = $file ?: Compiler::_('Utilities.File'); + } + + /** + * Create Path if not exist + * + * @param string $path The path to folder to create + * @param bool $addHtml The the switch to add the HTML + * + * @return void + * @since 3.2.0 + */ + public function create(string $path, bool $addHtml = true) + { + // check if the path exist + if (!JoomlaFolder::exists($path)) + { + // create the path + JoomlaFolder::create( + $path + ); + + // count the folder created + $this->counter->folder++; + + if ($addHtml) + { + // add index.html (boring I know) + $this->file->html( + $path, '' + ); + } + } + } + + /** + * Remove folders with files + * + * @param string $path The path to folder to remove + * @param array|null $ignore The folders and files to ignore and not remove + * + * @return boolean True if all are removed + * @since 3.2.0 + */ + public function remove(string $path, ?array $ignore = null): bool + { + if (JoomlaFolder::exists($path)) + { + $it = new \RecursiveDirectoryIterator($path); + $it = new \RecursiveIteratorIterator($it, \RecursiveIteratorIterator::CHILD_FIRST); + + // remove ending / + $path = rtrim($path, '/'); + + // now loop the files & folders + foreach ($it as $file) + { + if ('.' === $file->getBasename() || '..' === $file->getBasename()) continue; + + // set file dir + $file_dir = $file->getPathname(); + + // check if this is a dir or a file + if ($file->isDir()) + { + $keeper = false; + if (ArrayHelper::check($ignore)) + { + foreach ($ignore as $keep) + { + if (strpos((string) $file_dir, $path . '/' . $keep) !== false) + { + $keeper = true; + } + } + } + + if ($keeper) + { + continue; + } + + JoomlaFolder::delete($file_dir); + } + else + { + $keeper = false; + if (ArrayHelper::check($ignore)) + { + foreach ($ignore as $keep) + { + if (strpos((string) $file_dir, $path . '/'. $keep) !== false) + { + $keeper = true; + } + } + } + + if ($keeper) + { + continue; + } + + JoomlaFile::delete($file_dir); + } + } + + // delete the root folder if ignore not set + if (!ArrayHelper::check($ignore)) + { + return JoomlaFolder::delete($path); + } + + return true; + } + return false; + } diff --git a/src/6c89c663-78f5-4078-9fac-7047f2eaaf96/code.power b/src/6c89c663-78f5-4078-9fac-7047f2eaaf96/code.power new file mode 100644 index 0000000..bc53851 --- /dev/null +++ b/src/6c89c663-78f5-4078-9fac-7047f2eaaf96/code.power @@ -0,0 +1,87 @@ + /** + * Compiler Component Joomla Version Settings + * + * @var Settings + * @since 3.2.0 + */ + protected Settings $settings; + + /** + * Compiler Paths + * + * @var Paths + * @since 3.2.0 + */ + protected Paths $paths; + + /** + * Compiler Utilities Folder + * + * @var Folder + * @since 3.2.0 + */ + protected Folder $folder; + + /** + * Constructor + * + * @param Settings|null $settings The compiler component joomla version settings object. + * @param Paths|null $paths The compiler paths object. + * @param Folder|null $folder The compiler folder object. + * + * @since 3.2.0 + */ + public function __construct(?Settings $settings = null, ?Paths $paths = null, ?Folder $folder = null) + { + $this->settings = $settings ?: Compiler::_('Component.Settings'); + $this->paths = $paths ?: Compiler::_('Utilities.Paths'); + $this->folder = $folder ?: Compiler::_('Utilities.Folder'); + } + + /** + * Build the Component Structure + * + * @return bool + * @since 3.2.0 + */ + public function build(): bool + { + if ($this->settings->exists()) + { + // setup the main component path + $this->folder->create($this->paths->component_path); + + // build the version structure + $this->folders( + $this->settings->structure(), + $this->paths->component_path + ); + + return true; + } + + return false; + } + + /** + * Create the folder and subfolders + * + * @param object $folders The object[] of folders + * @param string $path The path + * + * @return void + * @since 3.2.0 + */ + protected function folders(object $folders, string $path) + { + foreach ($folders as $folder => $sub_folders) + { + $new_path = $path . '/' . $folder; + $this->folder->create($new_path); + + if (ObjectHelper::check($sub_folders)) + { + $this->folders($sub_folders, $new_path); + } + } + } diff --git a/src/6da2afa5-6087-46dd-80a0-74c6434bcb18/code.power b/src/6da2afa5-6087-46dd-80a0-74c6434bcb18/code.power new file mode 100644 index 0000000..f84aa49 --- /dev/null +++ b/src/6da2afa5-6087-46dd-80a0-74c6434bcb18/code.power @@ -0,0 +1,7 @@ + /** + * get the custom code from the local files + * + * @return void + * @since 3.2.0 + */ + public function run(); \ No newline at end of file diff --git a/src/6dfbf568-f3cd-4ea7-af04-6859447b5462/code.power b/src/6dfbf568-f3cd-4ea7-af04-6859447b5462/code.power new file mode 100644 index 0000000..b04ad9c --- /dev/null +++ b/src/6dfbf568-f3cd-4ea7-af04-6859447b5462/code.power @@ -0,0 +1,95 @@ + /** + * The compiler Config + * + * @var Config + * @since 3.2.0 + */ + protected Config $config; + + /** + * The compiler history + * + * @var HistoryInterface + * @since 3.2.0 + */ + protected HistoryInterface $history; + + /** + * The compiler update sql + * + * @var Updatesql + * @since 3.2.0 + */ + protected Updatesql $updatesql; + + /** + * Constructor + * + * @param Config|null $config The compiler config object. + * @param HistoryInterface|null $history The compiler history object. + * @param Updatesql|null $updatesql The compiler updatesql object. + * + * @since 3.2.0 + */ + public function __construct(?Config $config = null, ?HistoryInterface $history = null, + ?Updatesql $updatesql = null) + { + $this->config = $config ?: Compiler::_('Config'); + $this->history = $history ?: Compiler::_('History'); + $this->updatesql = $updatesql ?: Compiler::_('Model.Updatesql'); + } + + /** + * check if an update SQL is needed + * + * @param object $item The item data + * + * @return void + * @since 3.2.0 + */ + public function set(object &$item) + { + if (($old = $this->history->get('admin_view', $item->id)) !== null) + { + // check if the view name changed + if (StringHelper::check($old->name_single)) + { + $this->updatesql->set( + StringHelper::safe( + $old->name_single + ), $item->name_single_code, 'table_name', + $item->name_single_code + ); + } + + // loop the mysql table settings + foreach ($this->config->mysql_table_keys as $mysql_table_key => $mysql_table_val) + { + // check if the table engine changed + if (isset($old->{'mysql_table_' . $mysql_table_key}) + && isset($item->{'mysql_table_' . $mysql_table_key})) + { + $this->updatesql->set( + $old->{'mysql_table_' . $mysql_table_key}, + $item->{'mysql_table_' . $mysql_table_key}, + 'table_' . $mysql_table_key, $item->name_single_code + ); + } + // check if there is no history on table engine, and it changed from the default/global + elseif (isset($item->{'mysql_table_' . $mysql_table_key}) + && StringHelper::check( + $item->{'mysql_table_' . $mysql_table_key} + ) + && !is_numeric( + $item->{'mysql_table_' . $mysql_table_key} + )) + { + $this->updatesql->set( + $mysql_table_val['default'], + $item->{'mysql_table_' . $mysql_table_key}, + 'table_' . $mysql_table_key, $item->name_single_code + ); + } + } + } + } diff --git a/src/6e64917c-d687-4ef3-a655-811319f5a81e/code.power b/src/6e64917c-d687-4ef3-a655-811319f5a81e/code.power new file mode 100644 index 0000000..f071271 --- /dev/null +++ b/src/6e64917c-d687-4ef3-a655-811319f5a81e/code.power @@ -0,0 +1,381 @@ + /** + * Power Objects + * + * @var Power + * @since 3.2.0 + **/ + protected Power $power; + + /** + * Compiler Config + * + * @var Config + * @since 3.2.0 + **/ + protected Config $config; + + /** + * Compiler Content + * + * @var Content + * @since 3.2.0 + **/ + protected Content $content; + + /** + * Helper Class Autoloader + * + * @var string + * @since 3.2.0 + **/ + protected string $helper = ''; + + /** + * Constructor. + * + * @param Power|null $power The power object. + * @param Config|null $config The compiler config object. + * @param Content|null $content The compiler content object. + * + * @since 3.2.0 + */ + public function __construct(?Power $power = null, ?Config $config = null, ?Content $content = null) + { + $this->power = $power ?: Compiler::_('Power'); + $this->config = $config ?: Compiler::_('Config'); + $this->content = $content ?: Compiler::_('Content'); + + // reset all autoloaders power placeholders + $this->content->set('ADMIN_POWER_HELPER', ''); + $this->content->set('SITE_POWER_HELPER', ''); + $this->content->set('CUSTOM_POWER_AUTOLOADER', ''); + } + + /** + * Set the autoloader into the active content array + * + * @return void + * @since 3.2.0 + */ + public function set() + { + if (ArrayHelper::check($this->power->namespace)) + { + /************************* IMPORTANT SORT NOTICE *********************************************** + * make sure the name space values are sorted from the longest string to the shortest + * so that the search do not mistakenly match a shorter namespace before a longer one + * that has the same short namespace for example: + * NameSpace\SubName\Sub <- will always match first + * NameSpace\SubName\SubSubName + * Should the shorter namespace be listed [first] it will match both of these: + * NameSpace\SubName\Sub\ClassName + * ^^^^^^^^^^^^^^^^^^^^^^ + * NameSpace\SubName\SubSubName\ClassName + * ^^^^^^^^^^^^^^^^^^^^^^ + ***********************************************************************************************/ + uksort($this->power->namespace, fn($a, $b) => strlen((string) $b) - strlen((string) $a)); + + // check if we are using a plugin + if ($this->loadPluginAutoloader()) + { + $this->content->set('PLUGIN_POWER_AUTOLOADER', $this->getPluginAutoloader()); + } + + // load to the helper class + if ($this->loadHelperAutoloader()) + { + // load to admin helper class + $this->content->add('ADMIN_POWER_HELPER', $this->getHelperAutoloader()); + + // load to site helper class if needed + if ($this->loadSiteAutoloader()) + { + $this->content->add('SITE_POWER_HELPER', $this->getHelperAutoloader()); + } + } + + // to add to custom files + $this->content->add('CUSTOM_POWER_AUTOLOADER', $this->getHelperAutoloader()); + } + } + + /** + * Should we load the plugin autoloader + * + * @return bool + * @since 3.2.0 + */ + private function loadPluginAutoloader(): bool + { + return $this->content->exist('PLUGIN_POWER_AUTOLOADER'); + } + + /** + * Should we load the helper class autoloader + * + * @return bool + * @since 3.2.0 + */ + private function loadHelperAutoloader(): bool + { + // for now we load it if the plugin is not loaded + // but we may want to add a switch that + // controls this behaviour. + return !$this->loadPluginAutoloader(); + } + + /** + * Should we load the autoloader in site area + * + * @return bool + * @since 3.2.0 + */ + private function loadSiteAutoloader(): bool + { + return (!$this->config->remove_site_folder || !$this->config->remove_site_edit_folder); + } + + /** + * Get helper autoloader code + * + * @return string + * @since 3.2.0 + */ + private function getPluginAutoloader(): string + { + // load the code + $code = []; + + // if we should not load in the site are + if (($script = $this->getBLockSiteLoading()) !== null) + { + $code[] = $script; + } + + // add the composer stuff here + if (($script = $this->getComposer(2)) !== null) + { + $code[] = $script; + } + + // get the helper autoloader + if (($script = $this->getAutoloader(2)) !== null) + { + $code[] = $script; + } + + // if we have any + if (!empty($code)) + { + return PHP_EOL . PHP_EOL . implode(PHP_EOL . PHP_EOL, $code); + } + + return ''; + } + + /** + * Get helper autoloader code + * + * @return string + * @since 3.2.0 + */ + private function getHelperAutoloader(): string + { + // check if it was already build + if (!empty($this->helper)) + { + return $this->helper; + } + + // load the code + $code = []; + + // add the composer stuff here + if (($script = $this->getComposer(0)) !== null) + { + $code[] = $script; + } + + // get the helper autoloader + if (($script = $this->getAutoloader(0)) !== null) + { + $code[] = $script; + } + + // if we have any + if (!empty($code)) + { + $this->helper = PHP_EOL . PHP_EOL . implode(PHP_EOL . PHP_EOL, $code); + } + + return $this->helper; + } + + /** + * Get code that will block the plugin from loading + * the autoloader in the site area + * + * @return string|null + * @since 3.2.0 + */ + private function getBLockSiteLoading(): ?string + { + // if we should not load in the site are + if (!$this->loadSiteAutoloader()) + { + // we add code to prevent this plugin from triggering on the site area + $not_site = []; + $not_site[] = Indent::_(2) . '//' + . Line::_(__Line__, __Class__) . ' do not run the autoloader in the site area'; + $not_site[] = Indent::_(2) . 'if ($this->app->isClient(\'site\'))'; + $not_site[] = Indent::_(2) . '{'; + $not_site[] = Indent::_(3) . 'return;'; + $not_site[] = Indent::_(2) . '}'; + + return implode(PHP_EOL, $not_site); + } + + return null; + } + + /** + * Get autoloader code + * + * @param int $tabSpace The dynamic tab spacer + * + * @return string|null + * @since 3.2.0 + */ + private function getAutoloader(int $tabSpace): ?string + { + if (($size = ArrayHelper::check($this->power->namespace)) > 0) + { + // we start building the spl_autoload_register function call + $autoload_method = []; + $autoload_method[] = Indent::_($tabSpace) . '//' + . Line::_(__Line__, __Class__) . ' register this component namespace'; + $autoload_method[] = Indent::_($tabSpace) . 'spl_autoload_register(function ($class) {'; + $autoload_method[] = Indent::_($tabSpace) . Indent::_(1) . '//' + . Line::_(__Line__, __Class__) . ' project-specific base directories and namespace prefix'; + $autoload_method[] = Indent::_($tabSpace) . Indent::_(1) . '$search = ['; + + // counter to manage the comma in the actual array + $counter = 1; + foreach ($this->power->namespace as $base_dir => $prefix) + { + // don't add the ending comma on last value + if ($size == $counter) + { + $autoload_method[] = Indent::_($tabSpace) . Indent::_(2) . "'" . $this->config->get('jcb_powers_path', 'libraries/jcb_powers') . "/$base_dir' => '" . implode('\\\\', $prefix) . "'"; + } + else + { + $autoload_method[] = Indent::_($tabSpace) . Indent::_(2) . "'" . $this->config->get('jcb_powers_path', 'libraries/jcb_powers') . "/$base_dir' => '" . implode('\\\\', $prefix) . "',"; + } + $counter++; + } + $autoload_method[] = Indent::_($tabSpace) . Indent::_(1) . '];'; + $autoload_method[] = Indent::_($tabSpace) . Indent::_(1) . '// Start the search and load if found'; + $autoload_method[] = Indent::_($tabSpace) . Indent::_(1) . '$found = false;'; + $autoload_method[] = Indent::_($tabSpace) . Indent::_(1) . '$found_base_dir = "";'; + $autoload_method[] = Indent::_($tabSpace) . Indent::_(1) . '$found_len = 0;'; + $autoload_method[] = Indent::_($tabSpace) . Indent::_(1) . 'foreach ($search as $base_dir => $prefix)'; + $autoload_method[] = Indent::_($tabSpace) . Indent::_(1) . '{'; + $autoload_method[] = Indent::_($tabSpace) . Indent::_(2) . '//' + . Line::_(__Line__, __Class__) . ' does the class use the namespace prefix?'; + $autoload_method[] = Indent::_($tabSpace) . Indent::_(2) . '$len = strlen($prefix);'; + $autoload_method[] = Indent::_($tabSpace) . Indent::_(2) . 'if (strncmp($prefix, $class, $len) === 0)'; + $autoload_method[] = Indent::_($tabSpace) . Indent::_(2) . '{'; + $autoload_method[] = Indent::_($tabSpace) . Indent::_(3) . '//' + . Line::_(__Line__, __Class__) . ' we have a match so load the values'; + $autoload_method[] = Indent::_($tabSpace) . Indent::_(3) . '$found = true;'; + $autoload_method[] = Indent::_($tabSpace) . Indent::_(3) . '$found_base_dir = $base_dir;'; + $autoload_method[] = Indent::_($tabSpace) . Indent::_(3) . '$found_len = $len;'; + $autoload_method[] = Indent::_($tabSpace) . Indent::_(3) . '//' + . Line::_(__Line__, __Class__) . ' done here'; + $autoload_method[] = Indent::_($tabSpace) . Indent::_(3) . 'break;'; + $autoload_method[] = Indent::_($tabSpace) . Indent::_(2) . '}'; + $autoload_method[] = Indent::_($tabSpace) . Indent::_(1) . '}'; + + $autoload_method[] = Indent::_($tabSpace) . Indent::_(1) . '//' + . Line::_(__Line__, __Class__) . ' check if we found a match'; + $autoload_method[] = Indent::_($tabSpace) . Indent::_(1) . 'if (!$found)'; + $autoload_method[] = Indent::_($tabSpace) . Indent::_(1) . '{'; + + $autoload_method[] = Indent::_($tabSpace) . Indent::_(2) . '//' + . Line::_(__Line__, __Class__) . ' not found so move to the next registered autoloader'; + $autoload_method[] = Indent::_($tabSpace) . Indent::_(2) . 'return;'; + + $autoload_method[] = Indent::_($tabSpace) . Indent::_(1) . '}'; + + $autoload_method[] = Indent::_($tabSpace) . Indent::_(1) . '//' + . Line::_(__Line__, __Class__) . ' get the relative class name'; + $autoload_method[] = Indent::_($tabSpace) . Indent::_(1) . '$relative_class = substr($class, $found_len);'; + $autoload_method[] = Indent::_($tabSpace) . Indent::_(1) . '//' + . Line::_(__Line__, __Class__) . ' replace the namespace prefix with the base directory, replace namespace'; + $autoload_method[] = Indent::_($tabSpace) . Indent::_(1) . '// separators with directory separators in the relative class name, append'; + $autoload_method[] = Indent::_($tabSpace) . Indent::_(1) . '// with .php'; + $autoload_method[] = Indent::_($tabSpace) . Indent::_(1) . "\$file = JPATH_ROOT . '/' . \$found_base_dir . '/src' . str_replace('\\\\', '/', \$relative_class) . '.php';"; + $autoload_method[] = Indent::_($tabSpace) . Indent::_(1) . '//' + . Line::_(__Line__, __Class__) . ' if the file exists, require it'; + $autoload_method[] = Indent::_($tabSpace) . Indent::_(1) . 'if (file_exists($file))'; + $autoload_method[] = Indent::_($tabSpace) . Indent::_(1) . '{'; + $autoload_method[] = Indent::_($tabSpace) . Indent::_(2) . 'require $file;'; + $autoload_method[] = Indent::_($tabSpace) . Indent::_(1) . '}'; + $autoload_method[] = Indent::_($tabSpace) . '});'; + + return implode(PHP_EOL, $autoload_method); + } + + return null; + } + + /** + * Get the composer autoloader routine + * + * @param int $tabSpace The dynamic tab spacer + * + * @return string|null + * @since 3.2.0 + */ + private function getComposer(int $tabSpace): ?string + { + if (ArrayHelper::check($this->power->composer)) + { + // load the composer routine + $composer_routine = []; + + // counter to manage the comma in the actual array + $add_once = []; + foreach ($this->power->composer as $access_point) + { + // don't add the ending comma on last value + if (empty($add_once[$access_point])) + { + $composer_routine[] = Indent::_($tabSpace) . "\$composer_autoloader = JPATH_LIBRARIES . '/$access_point';"; + $composer_routine[] = Indent::_($tabSpace) . 'if (file_exists($composer_autoloader))'; + $composer_routine[] = Indent::_($tabSpace) . "{"; + $composer_routine[] = Indent::_($tabSpace) . Indent::_(1) . 'require_once $composer_autoloader;'; + $composer_routine[] = Indent::_($tabSpace) . "}"; + + $add_once[$access_point] = true; + } + } + + // this is just about the [autoloader or autoloaders] in the comment ;) + if (count($add_once) == 1) + { + array_unshift($composer_routine, Indent::_($tabSpace) . '//' + . Line::_(__Line__, __Class__) . ' add the autoloader for the composer classes'); + } + else + { + array_unshift($composer_routine, Indent::_($tabSpace) . '//' + . Line::_(__Line__, __Class__) . ' add the autoloaders for the composer classes'); + } + + return implode(PHP_EOL, $composer_routine); + } + + return null; + } diff --git a/src/6f20369a-8536-4870-a1a3-cda254c939c8/code.power b/src/6f20369a-8536-4870-a1a3-cda254c939c8/code.power new file mode 100644 index 0000000..b3fae3c --- /dev/null +++ b/src/6f20369a-8536-4870-a1a3-cda254c939c8/code.power @@ -0,0 +1,173 @@ + /** + * Compiler Config + * + * @var Config + * @since 3.2.0 + **/ + protected Config $config; + + /** + * Compiler Component + * + * @var Component + * @since 3.2.0 + **/ + protected Component $component; + + /** + * Constructor + * + * @param Config|null $config The compiler config object. + * @param Component|null $component The component class. + * + * @since 3.2.0 + */ + public function __construct(?Config $config = null, ?Component $component = null) + { + $this->config = $config ?: Compiler::_('Config'); + $this->component = $component ?: Compiler::_('Component'); + + // set the template path + $this->setTemplatePath(); + + // set component sales name + $this->setComponentSalesName(); + + // set component backup name + $this->setComponentBackupName(); + + // set component folder name + $this->setComponentFolderName(); + + // set component path + $this->setComponentPath(); + + // set the template path for custom + $this->setTemplatePathCustom(); + } + + /** + * getting any valid paths + * + * @param string $key The value's key/path name + * + * @return string The path found as a string + * @since 3.2.0 + * @throws \InvalidArgumentException If $key is not a valid function name. + */ + public function __get(string $key): string + { + // check if it has been set + if ($this->exist($key)) + { + return $this->get($key); + } + + throw new \InvalidArgumentException(sprintf('Path %s could not be found in the Paths Class.', $key)); + } + + /** + * Model the key + * + * @param string $key The key to model + * + * @return string + * @since 3.2.0 + */ + protected function key(string $key): string + { + return $key; + } + + /** + * Set the template path + * + * @return void + * + * @since 3.2.0 + */ + private function setTemplatePath(): void + { + $this->set('template_path', + $this->config->get('compiler_path', JPATH_COMPONENT_ADMINISTRATOR . '/compiler') . '/joomla_' + . $this->config->joomla_versions[$this->config->joomla_version]['folder_key'] + ); + } + + /** + * Set component sales name + * + * @return void + * + * @since 3.2.0 + */ + private function setComponentSalesName(): void + { + $this->set('component_sales_name', + 'com_' . $this->component->get('sales_name') . '__J' + . $this->config->joomla_version + ); + } + + /** + * Set component backup name + * + * @return void + * + * @since 3.2.0 + */ + private function setComponentBackupName(): void + { + $this->set('component_backup_name', + 'com_' . $this->component->get('sales_name') . '_v' . str_replace( + '.', '_', (string) $this->component->get('component_version') + ) . '__J' . $this->config->joomla_version + ); + } + + /** + * Set component folder name + * + * @return void + * + * @since 3.2.0 + */ + private function setComponentFolderName(): void + { + $this->set('component_folder_name', + 'com_' . $this->component->get('name_code') . '_v' . str_replace( + '.', '_', (string) $this->component->get('component_version') + ) . '__J' . $this->config->joomla_version + ); + } + + /** + * Set component path + * + * @return void + * + * @since 3.2.0 + */ + private function setComponentPath(): void + { + $this->set('component_path', + $this->config->get('compiler_path', JPATH_COMPONENT_ADMINISTRATOR . '/compiler') . '/' + . $this->get('component_folder_name') + ); + } + + /** + * set the template path for custom TODO: just use custom_folder_path in config + * + * @return void + * + * @since 3.2.0 + */ + private function setTemplatePathCustom(): void + { + $this->set('template_path_custom', + $this->config->get( + 'custom_folder_path', JPATH_COMPONENT_ADMINISTRATOR . '/custom' + ) + ); + } diff --git a/src/7175c1cd-2071-4cd7-b499-23881e168c3f/code.power b/src/7175c1cd-2071-4cd7-b499-23881e168c3f/code.power new file mode 100644 index 0000000..a5ae32b --- /dev/null +++ b/src/7175c1cd-2071-4cd7-b499-23881e168c3f/code.power @@ -0,0 +1,319 @@ + /** + * Compiler Config + * + * @var Config + * @since 3.2.0 + */ + protected Config $config; + + /** + * The compiler registry + * + * @var Registry + * @since 3.2.0 + */ + protected Registry $registry; + + /** + * Compiler Customcode + * + * @var Customcode + * @since 3.2.0 + */ + protected Customcode $customcode; + + /** + * Compiler Customcode in Gui + * + * @var Gui + * @since 3.2.0 + **/ + protected Gui $gui; + + /** + * Compiler Field Data + * + * @var FieldData + * @since 3.2.0 + */ + protected FieldData $field; + + /** + * Compiler Files Folders + * + * @var Filesfolders + * @since 3.2.0 + */ + protected Filesfolders $filesFolders; + + /** + * Database object to query local DB + * + * @var \JDatabaseDriver + * @since 3.2.0 + **/ + protected \JDatabaseDriver $db; + + /** + * Constructor + * + * @param Config|null $config The compiler config object. + * @param Registry|null $registry The compiler registry object. + * @param Customcode|null $customcode The compiler customcode object. + * @param Gui|null $gui The compiler customcode gui. + * @param FieldData|null $field The compiler field data object. + * @param Filesfolders|null $filesFolders The compiler files folders object. + * @param \JDatabaseDriver|null $db The database object. + * + * @since 3.2.0 + */ + public function __construct(?Config $config = null, ?Registry $registry = null, + ?Customcode $customcode = null, ?Gui $gui = null, + ?FieldData $field = null, ?Filesfolders $filesFolders = null, + ?\JDatabaseDriver $db = null) + { + $this->config = $config ?: Compiler::_('Config'); + $this->registry = $registry ?: Compiler::_('Registry'); + $this->customcode = $customcode ?: Compiler::_('Customcode'); + $this->gui = $gui ?: Compiler::_('Customcode.Gui'); + $this->field = $field ?: Compiler::_('Field.Data'); + $this->filesFolders = $filesFolders ?: Compiler::_('Model.Filesfolders'); + $this->db = $db ?: Factory::getDbo(); + } + + /** + * Get Media Library Data and store globally in registry + * + * @param int $id the library id + * + * @return object|bool object on success + * @since 3.2.0 + */ + public function get(int $id) + { + // check if the lib has already been set + if (!$this->registry->exists("builder.libraries.$id")) + { + // get some switches + $uikit = $this->config->get('uikit', 0); + $footable_version = $this->config->get('footable_version', 0); + + // make sure we should continue and that the lib is not already being loaded + switch ($id) + { + case 1: // No Library + return false; + break; + case 3: // Uikit v3 + if (2 == $uikit || 3 == $uikit) + { + // already being loaded + $this->registry->set("builder.libraries.$id", false); + } + break; + case 4: // Uikit v2 + if (2 == $uikit || 1 == $uikit) + { + // already being loaded + $this->registry->set("builder.libraries.$id", false); + } + break; + case 5: // FooTable v2 + if (2 == $footable_version) + { + // already being loaded + $this->registry->set("builder.libraries.$id", false); + } + break; + case 6: // FooTable v3 + if (3 == $footable_version) + { + // already being loaded + $this->registry->set("builder.libraries.$id", false); + } + break; + } + } + + // check if the lib has already been set + if (!$this->registry->exists("builder.libraries.$id")) + { + $query = $this->db->getQuery(true); + + $query->select('a.*'); + $query->select( + $this->db->quoteName( + array( + 'a.id', + 'a.name', + 'a.how', + 'a.type', + 'a.addconditions', + 'b.addconfig', + 'c.addfiles', + 'c.addfolders', + 'c.addfilesfullpath', + 'c.addfoldersfullpath', + 'c.addurls', + 'a.php_setdocument' + ), array( + 'id', + 'name', + 'how', + 'type', + 'addconditions', + 'addconfig', + 'addfiles', + 'addfolders', + 'addfilesfullpath', + 'addfoldersfullpath', + 'addurls', + 'php_setdocument' + ) + ) + ); + + // from these tables + $query->from('#__componentbuilder_library AS a'); + $query->join( + 'LEFT', + $this->db->quoteName('#__componentbuilder_library_config', 'b') + . ' ON (' . $this->db->quoteName('a.id') . ' = ' + . $this->db->quoteName('b.library') . ')' + ); + $query->join( + 'LEFT', $this->db->quoteName( + '#__componentbuilder_library_files_folders_urls', 'c' + ) . ' ON (' . $this->db->quoteName('a.id') . ' = ' + . $this->db->quoteName('c.library') . ')' + ); + $query->where($this->db->quoteName('a.id') . ' = ' . (int) $id); + $query->where($this->db->quoteName('a.target') . ' = 1'); + + // Reset the query using our newly populated query object. + $this->db->setQuery($query); + + // Load the results as a list of stdClass objects + $library = $this->db->loadObject(); + + // check if this lib uses build-in behaviour + if ($library->how == 4) + { + // fall back on build-in features + $buildin = [ + 3 => ['uikit' => 3], + 4 => ['uikit' => 1], + 5 => ['footable_version' => 2, 'footable' => true], + 6 => ['footable_version' => 3, 'footable' => true] + ]; + + if (isset($buildin[$library->id]) + && ArrayHelper::check( + $buildin[$library->id] + )) + { + // set the lib switch + foreach ($buildin[$library->id] as $lib => $val) + { + // ---- we are targeting these ---- + // $this->config->uikit + // $this->config->footable_version + // $this->config->footable + $this->config->set($lib, $val); + } + // since we are falling back on build-in feature + $library->how = 0; + } + else + { + // since we did not find build in behaviour we must load always. + $library->how = 1; + } + } + + // check if this lib has dynamic behaviour + if ($library->how > 0) + { + // set files and folders + $this->filesFolders->set($library); + + // add config fields only if needed + if ($library->how > 1) + { + // set the config data + $library->addconfig = (isset($library->addconfig) + && JsonHelper::check( + $library->addconfig + )) ? json_decode((string) $library->addconfig, true) : null; + + if (ArrayHelper::check($library->addconfig)) + { + $library->config = array_map( + function ($array) { + $array['alias'] = 0; + $array['title'] = 0; + $array['settings'] = $this->field->get( + $array['field'] + ); + + return $array; + }, array_values($library->addconfig) + ); + } + } + // if this lib is controlled by custom script + if (3 == $library->how) + { + // set Needed PHP + if (isset($library->php_setdocument) + && StringHelper::check( + $library->php_setdocument + )) + { + $library->document = $this->gui->set( + $this->customcode->update( + base64_decode((string) $library->php_setdocument) + ), + array( + 'table' => 'library', + 'field' => 'php_setdocument', + 'id' => (int) $id, + 'type' => 'php') + ); + } + } + // if this lib is controlled by conditions + elseif (2 == $library->how) + { + // set the addconditions data + $library->addconditions = (isset($library->addconditions) + && JsonHelper::check( + $library->addconditions + )) ? json_decode((string) $library->addconditions, true) : null; + + if (ArrayHelper::check( + $library->addconditions + )) + { + $library->conditions = array_values( + $library->addconditions + ); + } + } + + unset($library->php_setdocument); + unset($library->addconditions); + unset($library->addconfig); + + // load to global lib + $this->registry->set("builder.libraries.$id", $library); + } + else + { + $this->registry->set("builder.libraries.$id", false); + } + } + + // if set return + return $this->registry->get("builder.libraries.$id", false); + } diff --git a/src/766a9524-37df-4604-91a7-b98a6150ee26/code.power b/src/766a9524-37df-4604-91a7-b98a6150ee26/code.power new file mode 100644 index 0000000..c0b064c --- /dev/null +++ b/src/766a9524-37df-4604-91a7-b98a6150ee26/code.power @@ -0,0 +1,838 @@ + /** + * Compiler Joomla Plugins Data + * + * @var array + * @since 3.2.0 + */ + protected array $data = []; + + /** + * Compiler Config + * + * @var Config + * @since 3.2.0 + */ + protected Config $config; + + /** + * Compiler Customcode + * + * @var Customcode + * @since 3.2.0 + */ + protected Customcode $customcode; + + /** + * Compiler Customcode in Gui + * + * @var Gui + * @since 3.2.0 + **/ + protected Gui $gui; + + /** + * Compiler Placeholder + * + * @var Placeholder + * @since 3.2.0 + **/ + protected Placeholder $placeholder; + + /** + * Compiler Language + * + * @var Language + * @since 3.2.0 + **/ + protected Language $language; + + /** + * Compiler Field + * + * @var Field + * @since 3.2.0 + */ + protected Field $field; + + /** + * Compiler field name + * + * @var FieldName + * @since 3.2.0 + */ + protected FieldName $fieldName; + + /** + * Compiler Files Folders + * + * @var Filesfolders + * @since 3.2.0 + */ + protected Filesfolders $filesFolders; + + /** + * Database object to query local DB + * + * @var \JDatabaseDriver + * @since 3.2.0 + **/ + protected \JDatabaseDriver $db; + + /** + * Constructor + * + * @param Config|null $config The compiler config object. + * @param Customcode|null $customcode The compiler customcode object. + * @param Gui|null $gui The compiler customcode gui. + * @param Placeholder|null $placeholder The compiler placeholder object. + * @param Language|null $language The compiler Language object. + * @param Field|null $field The compiler field data object. + * @param FieldName|null $fieldName The compiler field name object. + * @param Filesfolders|null $filesFolders The compiler files folders object. + * @param \JDatabaseDriver|null $db The database object. + * + * @since 3.2.0 + */ + public function __construct(?Config $config = null, ?Customcode $customcode = null, + ?Gui $gui = null, ?Placeholder $placeholder = null, + ?Language $language = null, ?Field $field = null, ?FieldName $fieldName = null, + ?Filesfolders $filesFolders = null, ?\JDatabaseDriver $db = null) + { + $this->config = $config ?: Compiler::_('Config'); + $this->customcode = $customcode ?: Compiler::_('Customcode'); + $this->gui = $gui ?: Compiler::_('Customcode.Gui'); + $this->placeholder = $placeholder ?: Compiler::_('Placeholder'); + $this->language = $language ?: Compiler::_('Language'); + $this->field = $field ?: Compiler::_('Field'); + $this->fieldName = $fieldName ?: Compiler::_('Field.Name'); + $this->filesFolders = $filesFolders ?: Compiler::_('Model.Filesfolders'); + $this->db = $db ?: Factory::getDbo(); + } + + /** + * Get the Joomla Plugin/s + * + * @param int|null $id the plugin id + * + * @return object|array|null if ID found it returns object, if no ID given it returns all set + * @since 3.2.0 + */ + public function get(int $id = null) + { + if (is_null($id) && $this->exists()) + { + return $this->data; + } + elseif ($this->exists($id)) + { + return $this->data[$id]; + } + + return null; + } + + /** + * Check if the Joomla Plugin/s exists + * + * @param int|null $id the plugin id + * + * @return bool if ID found it returns true, if no ID given it returns true if any are set + * @since 3.2.0 + */ + public function exists(int $id = null): bool + { + if (is_null($id)) + { + return ArrayHelper::check($this->data); + } + elseif (isset($this->data[$id])) + { + return true; + } + + return $this->set($id); + } + + /** + * Set the Joomla Plugin + * + * @param int $id the plugin id + * + * @return bool true on success + * @since 3.2.0 + */ + public function set(int $id): bool + { + if (isset($this->data[$id])) + { + return true; + } + else + { + // Create a new query object. + $query = $this->db->getQuery(true); + + $query->select('a.*'); + $query->select( + $this->db->quoteName( + array( + 'g.name', + 'e.name', + 'e.head', + 'e.comment', + 'e.id', + 'f.addfiles', + 'f.addfolders', + 'f.addfilesfullpath', + 'f.addfoldersfullpath', + 'f.addurls', + 'u.version_update', + 'u.id' + ), array( + 'group', + 'extends', + 'class_head', + 'comment', + 'class_id', + 'addfiles', + 'addfolders', + 'addfilesfullpath', + 'addfoldersfullpath', + 'addurls', + 'version_update', + 'version_update_id' + ) + ) + ); + // from these tables + $query->from('#__componentbuilder_joomla_plugin AS a'); + $query->join( + 'LEFT', $this->db->quoteName( + '#__componentbuilder_joomla_plugin_group', 'g' + ) . ' ON (' . $this->db->quoteName('a.joomla_plugin_group') + . ' = ' . $this->db->quoteName('g.id') . ')' + ); + $query->join( + 'LEFT', + $this->db->quoteName('#__componentbuilder_class_extends', 'e') + . ' ON (' . $this->db->quoteName('a.class_extends') . ' = ' + . $this->db->quoteName('e.id') . ')' + ); + $query->join( + 'LEFT', $this->db->quoteName( + '#__componentbuilder_joomla_plugin_updates', 'u' + ) . ' ON (' . $this->db->quoteName('a.id') . ' = ' + . $this->db->quoteName('u.joomla_plugin') . ')' + ); + $query->join( + 'LEFT', $this->db->quoteName( + '#__componentbuilder_joomla_plugin_files_folders_urls', 'f' + ) . ' ON (' . $this->db->quoteName('a.id') . ' = ' + . $this->db->quoteName('f.joomla_plugin') . ')' + ); + $query->where($this->db->quoteName('a.id') . ' = ' . (int) $id); + $query->where($this->db->quoteName('a.published') . ' >= 1'); + $this->db->setQuery($query); + $this->db->execute(); + if ($this->db->getNumRows()) + { + // get the plugin data + $plugin = $this->db->loadObject(); + + // tweak system to set stuff to the plugin domain + $_backup_target = $this->config->build_target; + $_backup_lang = $this->config->lang_target; + $_backup_langPrefix = $this->config->lang_prefix; + + // set some keys + $plugin->target_type = 'P|uG!n'; + $plugin->key = $plugin->id . '_' . $plugin->target_type; + + // update to point to plugin + $this->config->build_target = $plugin->key; + $this->config->lang_target = $plugin->key; + + // set version if not set + if (empty($plugin->plugin_version)) + { + $plugin->plugin_version = '1.0.0'; + } + + // set GUI mapper + $guiMapper = array('table' => 'joomla_plugin', + 'id' => (int) $id, 'type' => 'php'); + + // update the name if it has dynamic values + $plugin->name = $this->placeholder->update_( + $this->customcode->update($plugin->name) + ); + + // update the name if it has dynamic values + $plugin->code_name + = ClassfunctionHelper::safe( + $plugin->name + ); + + // set official name + $plugin->official_name = ucwords( + $plugin->group . ' - ' . $plugin->name + ); + + // set lang prefix + $plugin->lang_prefix = PluginHelper::safeLangPrefix( + $plugin->code_name, + $plugin->group + ); + + // set langPrefix + $this->config->lang_prefix = $plugin->lang_prefix; + + // set plugin class name + $plugin->class_name + = PluginHelper::safeClassName( + $plugin->code_name, + $plugin->group + ); + + // set plugin install class name + $plugin->installer_class_name + = PluginHelper::safeInstallClassName( + $plugin->code_name, + $plugin->group + ); + + // set plugin folder name + $plugin->folder_name + = PluginHelper::safeFolderName( + $plugin->code_name, + $plugin->group + ); + + // set the zip name + $plugin->zip_name = $plugin->folder_name . '_v' . str_replace( + '.', '_', (string) $plugin->plugin_version + ) . '__J' . $this->config->joomla_version; + + // set plugin file name + $plugin->file_name = strtolower((string) $plugin->code_name); + + // set plugin context + $plugin->context = $plugin->folder_name . '.' . $plugin->id; + + // set official_name lang strings + $this->language->set( + $plugin->key, $this->config->lang_prefix, $plugin->official_name + ); + + // set some placeholder for this plugin + $this->placeholder->set('Plugin_name', $plugin->official_name); + $this->placeholder->set('PLUGIN_NAME', $plugin->official_name); + $this->placeholder->set('Plugin', ucfirst((string) $plugin->code_name)); + $this->placeholder->set('plugin', strtolower((string) $plugin->code_name)); + $this->placeholder->set('Plugin_group', ucfirst((string) $plugin->group)); + $this->placeholder->set('plugin_group', strtolower((string) $plugin->group)); + $this->placeholder->set('plugin.version', $plugin->plugin_version); + $this->placeholder->set('VERSION', $plugin->plugin_version); + $this->placeholder->set('plugin_version', str_replace( + '.', '_', (string) $plugin->plugin_version + )); + + // set description + $this->placeholder->set('DESCRIPTION', ''); + if (!isset($plugin->description) + || !StringHelper::check( + $plugin->description + )) + { + $plugin->description = ''; + } + else + { + $plugin->description = $this->placeholder->update_( + $this->customcode->update($plugin->description) + ); + $this->language->set( + $plugin->key, $plugin->lang_prefix . '_DESCRIPTION', + $plugin->description + ); + // set description + $this->placeholder->set('DESCRIPTION', $plugin->description); + $plugin->description = '

' . $plugin->description . '

'; + } + + // get author name + $project_author = $this->config->project_author; + + // we can only set these if the component was passed + $plugin->xml_description = "

" . $plugin->official_name + . " (v." . $plugin->plugin_version + . ")

" + . $plugin->description . "

Created by " . trim( + (string) OutputFilter::cleanText($project_author) + ) . "
Development started " + . Factory::getDate($plugin->created)->format("jS F, Y") + . "

"; + + // set xml discription + $this->language->set( + $plugin->key, $plugin->lang_prefix . '_XML_DESCRIPTION', + $plugin->xml_description + ); + + // update the readme if set + if ($plugin->addreadme == 1 && !empty($plugin->readme)) + { + $plugin->readme = $this->placeholder->update_( + $this->customcode->update(base64_decode((string) $plugin->readme)) + ); + } + else + { + $plugin->addreadme = 0; + unset($plugin->readme); + } + + // open some base64 strings + if (!empty($plugin->main_class_code)) + { + // set GUI mapper field + $guiMapper['field'] = 'main_class_code'; + // base64 Decode main_class_code. + $plugin->main_class_code = $this->gui->set( + $this->placeholder->update_( + $this->customcode->update( + base64_decode((string) $plugin->main_class_code) + ) + ), + $guiMapper + ); + } + + // set the head :) + if ($plugin->add_head == 1 && !empty($plugin->head)) + { + // set GUI mapper field + $guiMapper['field'] = 'head'; + // base64 Decode head. + $plugin->head = $this->gui->set( + $this->placeholder->update_( + $this->customcode->update( + base64_decode((string) $plugin->head) + ) + ), + $guiMapper + ); + } + elseif (!empty($plugin->class_head)) + { + // base64 Decode head. + $plugin->head = $this->gui->set( + $this->placeholder->update_( + $this->customcode->update( + base64_decode((string) $plugin->class_head) + ) + ), + array( + 'table' => 'class_extends', + 'field' => 'head', + 'id' => (int) $plugin->class_id, + 'type' => 'php') + ); + } + unset($plugin->class_head); + + // set the comment + if (!empty($plugin->comment)) + { + // base64 Decode comment. + $plugin->comment = $this->gui->set( + $this->placeholder->update_( + $this->customcode->update( + base64_decode((string) $plugin->comment) + ) + ), + array( + 'table' => 'class_extends', + 'field' => 'comment', + 'id' => (int) $plugin->class_id, + 'type' => 'php') + ); + } + + // start the config array + $plugin->config_fields = []; + // create the form arrays + $plugin->form_files = []; + $plugin->fieldsets_label = []; + $plugin->fieldsets_paths = []; + $plugin->add_rule_path = []; + $plugin->add_field_path = []; + // set global fields rule to default component path + $plugin->fields_rules_paths = 1; + // set the fields data + $plugin->fields = (isset($plugin->fields) + && JsonHelper::check($plugin->fields)) + ? json_decode((string) $plugin->fields, true) : null; + if (ArrayHelper::check($plugin->fields)) + { + // ket global key + $key = $plugin->key; + $dynamic_fields = array('fieldset' => 'basic', + 'fields_name' => 'params', + 'file' => 'config'); + foreach ($plugin->fields as $n => &$form) + { + if (isset($form['fields']) + && ArrayHelper::check( + $form['fields'] + )) + { + // make sure the dynamic_field is set to dynamic_value by default + foreach ( + $dynamic_fields as $dynamic_field => + $dynamic_value + ) + { + if (!isset($form[$dynamic_field]) + || !StringHelper::check( + $form[$dynamic_field] + )) + { + $form[$dynamic_field] = $dynamic_value; + } + else + { + if ('fields_name' === $dynamic_field + && strpos((string) $form[$dynamic_field], '.') + !== false) + { + $form[$dynamic_field] + = $form[$dynamic_field]; + } + else + { + $form[$dynamic_field] + = StringHelper::safe( + $form[$dynamic_field] + ); + } + } + } + // check if field is external form file + if (!isset($form['plugin']) || $form['plugin'] != 1) + { + // now build the form key + $unique = $form['file'] . $form['fields_name'] + . $form['fieldset']; + } + else + { + // now build the form key + $unique = $form['fields_name'] + . $form['fieldset']; + } + // set global fields rule path switchs + if ($plugin->fields_rules_paths == 1 + && isset($form['fields_rules_paths']) + && $form['fields_rules_paths'] == 2) + { + $plugin->fields_rules_paths = 2; + } + // set where to path is pointing + $plugin->fieldsets_paths[$unique] + = $form['fields_rules_paths']; + // add the label if set to lang + if (isset($form['label']) + && StringHelper::check( + $form['label'] + )) + { + $plugin->fieldsets_label[$unique] + = $this->language->key($form['label']); + } + // check for extra rule paths + if (isset($form['addrulepath']) + && ArrayHelper::check($form['addrulepath'])) + { + foreach ($form['addrulepath'] as $add_rule_path) + { + if (StringHelper::check($add_rule_path['path'])) + { + $plugin->add_rule_path[$unique] = $add_rule_path['path']; + } + } + } + // check for extra field paths + if (isset($form['addfieldpath']) + && ArrayHelper::check($form['addfieldpath'])) + { + foreach ($form['addfieldpath'] as $add_field_path) + { + if (StringHelper::check($add_field_path['path'])) + { + $plugin->add_field_path[$unique] = $add_field_path['path']; + } + } + } + // build the fields + $form['fields'] = array_map( + function ($field) use ($key, $unique) { + // make sure the alias and title is 0 + $field['alias'] = 0; + $field['title'] = 0; + // set the field details + $this->field->set( + $field, $key, $key, $unique + ); + // update the default if set + if (StringHelper::check( + $field['custom_value'] + ) + && isset($field['settings'])) + { + if (($old_default + = GetHelper::between( + $field['settings']->xml, + 'default="', '"', false + )) !== false) + { + // replace old default + $field['settings']->xml + = str_replace( + 'default="' . $old_default + . '"', 'default="' + . $field['custom_value'] . '"', + (string) $field['settings']->xml + ); + } + else + { + // add the default (hmmm not ideal but okay it should work) + $field['settings']->xml + = 'default="' + . $field['custom_value'] . '" ' + . $field['settings']->xml; + } + } + unset($field['custom_value']); + + // return field + return $field; + }, array_values($form['fields']) + ); + // check if field is external form file + if (!isset($form['plugin']) || $form['plugin'] != 1) + { + // load the form file + if (!isset($plugin->form_files[$form['file']])) + { + $plugin->form_files[$form['file']] + = []; + } + if (!isset($plugin->form_files[$form['file']][$form['fields_name']])) + { + $plugin->form_files[$form['file']][$form['fields_name']] + = []; + } + if (!isset($plugin->form_files[$form['file']][$form['fields_name']][$form['fieldset']])) + { + $plugin->form_files[$form['file']][$form['fields_name']][$form['fieldset']] + = []; + } + // do some house cleaning (for fields) + foreach ($form['fields'] as $field) + { + // so first we lock the field name in + $this->fieldName->get( + $field, $plugin->key, $unique + ); + // add the fields to the global form file builder + $plugin->form_files[$form['file']][$form['fields_name']][$form['fieldset']][] + = $field; + } + // remove form + unset($plugin->fields[$n]); + } + else + { + // load the config form + if (!isset($plugin->config_fields[$form['fields_name']])) + { + $plugin->config_fields[$form['fields_name']] + = []; + } + if (!isset($plugin->config_fields[$form['fields_name']][$form['fieldset']])) + { + $plugin->config_fields[$form['fields_name']][$form['fieldset']] + = []; + } + // do some house cleaning (for fields) + foreach ($form['fields'] as $field) + { + // so first we lock the field name in + $this->fieldName->get( + $field, $plugin->key, $unique + ); + // add the fields to the config builder + $plugin->config_fields[$form['fields_name']][$form['fieldset']][] + = $field; + } + // remove form + unset($plugin->fields[$n]); + } + } + else + { + unset($plugin->fields[$n]); + } + } + } + unset($plugin->fields); + + // set files and folders + $this->filesFolders->set($plugin); + + // add PHP in plugin install + $plugin->add_install_script = true; + $addScriptMethods = [ + 'php_preflight', + 'php_postflight', + 'php_method' + ]; + $addScriptTypes = [ + 'install', + 'update', + 'uninstall' + ]; + foreach ($addScriptMethods as $scriptMethod) + { + foreach ($addScriptTypes as $scriptType) + { + if (isset( $plugin->{'add_' . $scriptMethod . '_' . $scriptType}) + && $plugin->{'add_' . $scriptMethod . '_' . $scriptType} == 1 + && StringHelper::check( + $plugin->{$scriptMethod . '_' . $scriptType} + )) + { + // set GUI mapper field + $guiMapper['field'] = $scriptMethod . '_' . $scriptType; + $plugin->{$scriptMethod . '_' . $scriptType} = $this->gui->set( + $this->placeholder->update_( + $this->customcode->update( + base64_decode( + (string) $plugin->{$scriptMethod . '_' . $scriptType} + ) + ) + ), + $guiMapper + ); + } + else + { + unset($plugin->{$scriptMethod . '_' . $scriptType}); + $plugin->{'add_' . $scriptMethod . '_' . $scriptType} = 0; + } + } + } + + // add_sql + if ($plugin->add_sql == 1 + && StringHelper::check($plugin->sql)) + { + $plugin->sql = $this->placeholder->update_( + $this->customcode->update(base64_decode((string) $plugin->sql)) + ); + } + else + { + unset($plugin->sql); + $plugin->add_sql = 0; + } + + // add_sql_uninstall + if ($plugin->add_sql_uninstall == 1 + && StringHelper::check( + $plugin->sql_uninstall + )) + { + $plugin->sql_uninstall = $this->placeholder->update_( + $this->customcode->update( + base64_decode((string) $plugin->sql_uninstall) + ) + ); + } + else + { + unset($plugin->sql_uninstall); + $plugin->add_sql_uninstall = 0; + } + + // update the URL of the update_server if set + if ($plugin->add_update_server == 1 + && StringHelper::check( + $plugin->update_server_url + )) + { + $plugin->update_server_url = $this->placeholder->update_( + $this->customcode->update($plugin->update_server_url) + ); + } + + // add the update/sales server FTP details if that is the expected protocol + $serverArray = array('update_server', 'sales_server'); + foreach ($serverArray as $server) + { + if ($plugin->{'add_' . $server} == 1 + && is_numeric( + $plugin->{$server} + ) + && $plugin->{$server} > 0) + { + // get the server protocol + $plugin->{$server . '_protocol'} + = GetHelper::var( + 'server', (int) $plugin->{$server}, 'id', 'protocol' + ); + } + else + { + $plugin->{$server} = 0; + // only change this for sales server (update server can be added locally to the zip file) + if ('sales_server' === $server) + { + $plugin->{'add_' . $server} = 0; + } + $plugin->{$server . '_protocol'} = 0; + } + } + + // set the update server stuff (TODO) + // update_server_xml_path + // update_server_xml_file_name + + // rest globals + $this->config->build_target = $_backup_target; + $this->config->lang_target = $_backup_lang; + $this->config->set('lang_prefix', $_backup_langPrefix); + + $this->placeholder->remove('Plugin_name'); + $this->placeholder->remove('Plugin'); + $this->placeholder->remove('plugin'); + $this->placeholder->remove('Plugin_group'); + $this->placeholder->remove('plugin_group'); + $this->placeholder->remove('plugin.version'); + $this->placeholder->remove('plugin_version'); + $this->placeholder->remove('VERSION'); + $this->placeholder->remove('DESCRIPTION'); + $this->placeholder->remove('PLUGIN_NAME'); + + $this->data[$id] = $plugin; + + return true; + } + } + + return false; + } diff --git a/src/78527c29-24ad-4735-ad4c-ec33a4952d9b/code.power b/src/78527c29-24ad-4735-ad4c-ec33a4952d9b/code.power new file mode 100644 index 0000000..e600907 --- /dev/null +++ b/src/78527c29-24ad-4735-ad4c-ec33a4952d9b/code.power @@ -0,0 +1,60 @@ + /** + * Check if any values are set in the active array + * + * @return bool Returns true if the active array is not empty, false otherwise + * @since 3.2.0 + */ + public function isActive(): bool; + + /** + * Set content + * + * @param string $key The main string key + * @param mixed $value The values to set + * + * @return void + * @since 3.2.0 + */ + public function set(string $key, $value); + + /** + * Get content + * + * @param string $key The main string key + * @param mixed $value The values to set + * + * @return mixed + * @since 3.2.0 + */ + public function get(string $key); + + /** + * Does key exist + * + * @param string $key The main string key + * + * @return bool + * @since 3.2.0 + */ + public function exist(string $key): bool; + + /** + * Add content + * + * @param string $key The main string key + * @param mixed $value The values to set + * + * @return void + * @since 3.2.0 + */ + public function add(string $key, $value); + + /** + * Remove content + * + * @param string $key The main string key + * + * @return void + * @since 3.2.0 + */ + public function remove(string $key); diff --git a/src/79740ee8-4d10-4b51-9ff5-18e1386ec1c6/code.power b/src/79740ee8-4d10-4b51-9ff5-18e1386ec1c6/code.power new file mode 100644 index 0000000..71d2c2b --- /dev/null +++ b/src/79740ee8-4d10-4b51-9ff5-18e1386ec1c6/code.power @@ -0,0 +1,546 @@ + /** + * The joint types + * + * @var array + * @since 3.2.0 + */ + protected array $jointer = [ + 1 => 'LEFT', + 2 => 'LEFT OUTER', + 3 => 'INNER', + 4 => 'RIGHT', + 5 => 'RIGHT OUTER' + ]; + + /** + * The operator types + * + * @var array + * @since 3.2.0 + */ + protected array $operator = [ + 1 => '=', + 2 => '!=', + 3 => '<>', + 4 => '>', + 5 => '<', + 6 => '>=', + 7 => '<=', + 8 => '!<', + 9 => '!>', + 10 => 'IN', + 11 => 'NOT IN' + ]; + + /** + * The gui mapper array + * + * @var array + * @since 3.2.0 + */ + protected array $guiMapper = [ + 'table' => 'dynamic_get', + 'id' => null, + 'field' => null, + 'type' => 'php' + ]; + + /** + * Compiler Config + * + * @var Config + * @since 3.2.0 + */ + protected Config $config; + + /** + * The compiler registry + * + * @var Registry + * @since 3.2.0 + */ + protected Registry $registry; + + /** + * Compiler Customcode + * + * @var Customcode + * @since 3.2.0 + */ + protected Customcode $customcode; + + /** + * Compiler Customcode in Gui + * + * @var Gui + * @since 3.2.0 + **/ + protected Gui $gui; + + /** + * Compiler Placeholder + * + * @var Placeholder + * @since 3.2.0 + **/ + protected Placeholder $placeholder; + + /** + * Compiler Dynamic Get Selection + * + * @var Selection + * @since 3.2.0 + **/ + protected Selection $selection; + + /** + * Constructor + * + * @param Config|null $config The compiler config. + * @param Registry|null $registry The compiler registry. + * @param Customcode|null $customcode The compiler customcode object. + * @param Gui|null $gui The compiler customcode gui. + * @param Placeholder|null $placeholder The compiler placeholder object. + * @param Selection|null $selection The compiler dynamic get selection object. + * + * @since 3.2.0 + */ + public function __construct(?Config $config = null, ?Registry $registry = null, ?Customcode $customcode = null, + ?Gui $gui = null, ?Placeholder $placeholder = null, ?Selection $selection = null) + { + $this->config = $config ?: Compiler::_('Config'); + $this->registry = $registry ?: Compiler::_('Registry'); + $this->customcode = $customcode ?: Compiler::_('Customcode'); + $this->gui = $gui ?: Compiler::_('Customcode.Gui'); + $this->placeholder = $placeholder ?: Compiler::_('Placeholder'); + $this->selection = $selection ?: Compiler::_('Dynamicget.Selection'); + } + + /** + * Set Dynamic Get + * + * @param object $item The item data + * @param string $view_code The view code name + * @param string $context The context for events + * + * @return void + * @since 3.2.0 + */ + public function set(object &$item, string $view_code, string $context) + { + // reset buckets + $item->main_get = []; + $item->custom_get = []; + + // should joined and other tweaks be added + $add_tweaks_joints = true; + + // set source data + switch ($item->main_source) + { + case 1: + // check if auto sync is set + if ($item->select_all == 1) + { + $item->view_selection = '*'; + } + // set the view data + $item->main_get[0]['selection'] = $this->selection->get( + $item->key, $view_code, + $item->view_selection, + $item->view_table_main, 'a', 'view' + ); + $item->main_get[0]['as'] = 'a'; + $item->main_get[0]['key'] = $item->key; + $item->main_get[0]['context'] = $context; + unset($item->view_selection); + break; + case 2: + // check if auto sync is set + if ($item->select_all == 1) + { + $item->db_selection = '*'; + } + // set the database data + $item->main_get[0]['selection'] = $this->selection->get( + $item->key, $view_code, + $item->db_selection, + $item->db_table_main, 'a', 'db' + ); + $item->main_get[0]['as'] = 'a'; + $item->main_get[0]['key'] = $item->key; + $item->main_get[0]['context'] = $context; + unset($item->db_selection); + break; + case 3: + // set GUI mapper field + $this->guiMapper['field'] = 'php_custom_get'; + // get the custom query + $customQueryString + = $this->gui->set( + $this->customcode->update( + base64_decode((string) $item->php_custom_get) + ), + $this->guiMapper + ); + + // get the table name + $_searchQuery + = GetHelper::between( + $customQueryString, '$query->from(', ')' + ); + + if (StringHelper::check( + $_searchQuery + ) + && strpos((string) $_searchQuery, '#__') !== false) + { + $_queryName = GetHelper::between( + $_searchQuery, '#__', "'" + ); + + if (!StringHelper::check( + $_queryName + )) + { + $_queryName = GetHelper::between( + $_searchQuery, '#__', '"' + ); + } + } + + // set to blank if not found + if (!isset($_queryName) + || !StringHelper::check( + $_queryName + )) + { + $_queryName = ''; + } + + // set custom script + $item->main_get[0]['selection'] = [ + 'select' => $customQueryString, + 'from' => '', 'table' => '', 'type' => '', + 'name' => $_queryName]; + $item->main_get[0]['as'] = 'a'; + $item->main_get[0]['key'] = $item->key; + $item->main_get[0]['context'] = $context; + + // do not add + $add_tweaks_joints = false; + + break; + } + + // only add if main source is not custom + if ($add_tweaks_joints) + { + // set join_view_table details + $item->join_view_table = json_decode( + (string) $item->join_view_table, true + ); + + if (ArrayHelper::check( + $item->join_view_table + )) + { + // start the part of a table bucket + $_part_of_a = []; + // build relationship + $_relationship = array_map( + function ($op) use (&$_part_of_a) { + $bucket = []; + // array(on_field_as, on_field) + $bucket['on_field'] = array_map( + 'trim', + explode('.', (string) $op['on_field']) + ); + // array(join_field_as, join_field) + $bucket['join_field'] = array_map( + 'trim', + explode('.', (string) $op['join_field']) + ); + // triget filed that has table a relationship + if ($op['row_type'] == 1 + && ($bucket['on_field'][0] === 'a' + || isset($_part_of_a[$bucket['on_field'][0]]) + || isset($_part_of_a[$bucket['join_field'][0]]))) + { + $_part_of_a[$op['as']] = $op['as']; + } + + return $bucket; + }, $item->join_view_table + ); + + // loop joints + foreach ( + $item->join_view_table as $nr => &$option + ) + { + if (StringHelper::check( + $option['selection'] + )) + { + // convert the type + $option['type'] + = $this->jointer[$option['type']]; + // convert the operator + $option['operator'] + = $this->operator[$option['operator']]; + // get the on field values + $on_field + = $_relationship[$nr]['on_field']; + // get the join field values + $join_field + = $_relationship[$nr]['join_field']; + // set selection + $option['selection'] + = $this->selection->get( + $item->key, + $view_code, + $option['selection'], + $option['view_table'], + $option['as'], + 'view', + $option['row_type'] + ); + $option['key'] = $item->key; + $option['context'] = $context; + // load to the getters + if ($option['row_type'] == 1) + { + $item->main_get[] = $option; + if ($on_field[0] === 'a' + || isset($_part_of_a[$join_field[0]]) + || isset($_part_of_a[$on_field[0]])) + { + $this->registry-> + set('builder.site_main_get.' . $this->config->build_target . + '.' . $view_code . '.' . $option['as'], $option['as']); + } + else + { + $this->registry-> + set('builder.site_dynamic_get.' . $this->config->build_target . + '.' . $view_code . '.' . $option['as'] . '.' . $join_field[1], $on_field[0]); + } + } + elseif ($option['row_type'] == 2) + { + $item->custom_get[] = $option; + if ($on_field[0] != 'a') + { + $this->registry-> + set('builder.site_dynamic_get.' . $this->config->build_target . + '.' . $view_code . '.' . $option['as'] . '.' . $join_field[1], $on_field[0]); + } + } + } + unset($item->join_view_table[$nr]); + } + } + unset($item->join_view_table); + + // set join_db_table details + $item->join_db_table = json_decode( + (string) $item->join_db_table, true + ); + + if (ArrayHelper::check( + $item->join_db_table + )) + { + // start the part of a table bucket + $_part_of_a = []; + // build relationship + $_relationship = array_map( + function ($op) use (&$_part_of_a) { + $bucket = []; + // array(on_field_as, on_field) + $bucket['on_field'] = array_map( + 'trim', + explode('.', (string) $op['on_field']) + ); + // array(join_field_as, join_field) + $bucket['join_field'] = array_map( + 'trim', + explode('.', (string) $op['join_field']) + ); + // triget filed that has table a relationship + if ($op['row_type'] == 1 + && ($bucket['on_field'][0] === 'a' + || isset($_part_of_a[$bucket['on_field'][0]]) + || isset($_part_of_a[$bucket['join_field'][0]]))) + { + $_part_of_a[$op['as']] = $op['as']; + } + + return $bucket; + }, $item->join_db_table + ); + + // loop joints + foreach ( + $item->join_db_table as $nr => &$option1 + ) + { + if (StringHelper::check( + $option1['selection'] + )) + { + // convert the type + $option1['type'] + = $this->jointer[$option1['type']]; + // convert the operator + $option1['operator'] + = $this->operator[$option1['operator']]; + // get the on field values + $on_field + = $_relationship[$nr]['on_field']; + // get the join field values + $join_field + = $_relationship[$nr]['join_field']; + // set selection + $option1['selection'] + = $this->selection->get( + $item->key, + $view_code, + $option1['selection'], + $option1['db_table'], + $option1['as'], + 'db', + $option1['row_type'] + ); + $option1['key'] = $item->key; + $option1['context'] = $context; + // load to the getters + if ($option1['row_type'] == 1) + { + $item->main_get[] = $option1; + if ($on_field[0] === 'a' + || isset($_part_of_a[$join_field[0]]) + || isset($_part_of_a[$on_field[0]])) + { + $this->registry-> + set('builder.site_main_get.' . $this->config->build_target . + '.' . $view_code . '.' . $option1['as'], $option1['as']); + } + else + { + $this->registry-> + set('builder.site_dynamic_get.' . $this->config->build_target . + '.' . $view_code . '.' . $option1['as'] . '.' . $join_field[1], $on_field[0]); + } + } + elseif ($option1['row_type'] == 2) + { + $item->custom_get[] = $option1; + if ($on_field[0] != 'a') + { + $this->registry-> + set('builder.site_dynamic_get.' . $this->config->build_target . + '.' . $view_code . '.' . $option1['as'] . '.' . $join_field[1], $on_field[0]); + } + } + } + unset($item->join_db_table[$nr]); + } + } + unset($item->join_db_table); + + // set filter details + $item->filter = json_decode( + (string) $item->filter, true + ); + + if (ArrayHelper::check( + $item->filter + )) + { + foreach ($item->filter as $nr => &$option2) + { + if (isset($option2['operator'])) + { + $option2['operator'] = $this->operator[$option2['operator']]; + $option2['state_key'] = $this->placeholder->update_( + $this->customcode->update( + $option2['state_key'] + ) + ); + $option2['key'] = $item->key; + } + else + { + unset($item->filter[$nr]); + } + } + } + + // set where details + $item->where = json_decode((string) $item->where, true); + if (ArrayHelper::check( + $item->where + )) + { + foreach ($item->where as $nr => &$option3) + { + if (isset($option3['operator'])) + { + $option3['operator'] + = $this->operator[$option3['operator']]; + } + else + { + unset($item->where[$nr]); + } + } + } + else + { + unset($item->where); + } + + // set order details + $item->order = json_decode((string) $item->order, true); + if (!ArrayHelper::check( + $item->order + )) + { + unset($item->order); + } + + // set grouping + $item->group = json_decode((string) $item->group, true); + if (!ArrayHelper::check( + $item->group + )) + { + unset($item->group); + } + + // set global details + $item->global = json_decode( + (string) $item->global, true + ); + + if (!ArrayHelper::check( + $item->global + )) + { + unset($item->global); + } + } + else + { + // when we have a custom query script we do not add the dynamic options + unset($item->join_view_table); + unset($item->join_db_table); + unset($item->filter); + unset($item->where); + unset($item->order); + unset($item->group); + unset($item->global); + } + } diff --git a/src/797579e8-b272-41ed-91de-428cb0b3e089/code.power b/src/797579e8-b272-41ed-91de-428cb0b3e089/code.power new file mode 100644 index 0000000..bbdda32 --- /dev/null +++ b/src/797579e8-b272-41ed-91de-428cb0b3e089/code.power @@ -0,0 +1,80 @@ + /** + * Compiler Placeholder + * + * @var Placeholder + * @since 3.2.0 + **/ + protected Placeholder $placeholder; + + /** + * Constructor. + * + * @param Placeholder|null $placeholder The compiler placeholder object. + * + * @since 3.2.0 + */ + public function __construct(?Placeholder $placeholder = null) + { + $this->placeholder = $placeholder ?: Compiler::_('Placeholder'); + } + + /** + * Set the MD5 hashed string or file or string + * + * @param string $script The code string + * + * @return string + * @since 3.2.0 + */ + public function set(string $script): string + { + // check if we should hash a string + if (strpos($script, 'HASH' . 'STRING((((') !== false) + { + // get the strings + $values = GetHelper::allBetween( + $script, 'HASH' . 'STRING((((', '))))' + ); + $locker = []; + // convert them + foreach ($values as $value) + { + $locker['HASH' . 'STRING((((' . $value . '))))'] + = md5((string) $value); + } + + // update the script + return $this->placeholder->update($script, $locker); + } + // check if we should hash a file + if (strpos($script, 'HASH' . 'FILE((((') !== false) + { + // get the strings + $values = GetHelper::allBetween( + $script, 'HASH' . 'FILE((((', '))))' + ); + $locker = []; + // convert them + foreach ($values as $path) + { + // we first get the file if it exist + if ($value = FileHelper::getContent($path)) + { + // now we hash the file content + $locker['HASH' . 'FILE((((' . $path . '))))'] + = md5((string) $value); + } + else + { + // could not retrieve the file so we show error + $locker['HASH' . 'FILE((((' . $path . '))))'] + = 'ERROR'; + } + } + + // update the script + return $this->placeholder->update($script, $locker); + } + + return $script; + } diff --git a/src/7a5fd3f3-199e-43ba-a8e8-f473d6c030ec/code.power b/src/7a5fd3f3-199e-43ba-a8e8-f473d6c030ec/code.power new file mode 100644 index 0000000..79489fb --- /dev/null +++ b/src/7a5fd3f3-199e-43ba-a8e8-f473d6c030ec/code.power @@ -0,0 +1,59 @@ + /** + * Field Grouping https://docs.joomla.org/Form_field + **/ + protected static $fields = [ + 'default' => [ + 'accesslevel', 'cachehandler', 'calendar', 'captcha', 'category', 'checkbox', 'checkboxes', 'chromestyle', + 'color', 'combo', 'componentlayout', 'contentlanguage', 'contenttype', 'databaseconnection', 'components', + 'editor', 'editors', 'email', 'file', 'file', 'filelist', 'folderlist', 'groupedlist', 'headertag', 'helpsite', 'hidden', 'imagelist', + 'integer', 'language', 'list', 'media', 'menu', 'modal_menu', 'menuitem', 'meter', 'modulelayout', 'moduleorder', 'moduleposition', + 'moduletag', 'note', 'number', 'password', 'plugins', 'predefinedlist', 'radio', 'range', 'repeatable', 'rules', + 'sessionhandler', 'spacer', 'sql', 'subform', 'tag', 'tel', 'templatestyle', 'text', 'textarea', 'timezone', 'url', 'user', 'usergroup' + ], + 'plain' => [ + 'cachehandler', 'calendar', 'checkbox', 'chromestyle', 'color', 'componentlayout', 'contenttype', 'editor', 'editors', 'captcha', + 'email', 'file', 'headertag', 'helpsite', 'hidden', 'integer', 'language', 'media', 'menu', 'modal_menu', 'menuitem', 'meter', 'modulelayout', 'templatestyle', + 'moduleorder', 'moduletag', 'number', 'password', 'range', 'rules', 'tag', 'tel', 'text', 'textarea', 'timezone', 'url', 'user', 'usergroup' + ], + 'option' => [ + 'accesslevel', 'category', 'checkboxes', 'combo', 'contentlanguage', 'databaseconnection', 'components', + 'filelist', 'folderlist', 'imagelist', 'list', 'plugins', 'predefinedlist', 'radio', 'sessionhandler', 'sql', 'groupedlist' + ], + 'text' => [ + 'calendar', 'color', 'editor', 'email', 'number', 'password', 'range', 'tel', 'text', 'textarea', 'url' + ], + 'list' => [ + 'checkbox', 'checkboxes', 'list', 'radio', 'groupedlist', 'combo' + ], + 'dynamic' => [ + 'category', 'file', 'filelist', 'folderlist', 'headertag', 'imagelist', 'integer', 'media', 'meter', 'rules', 'tag', 'timezone', 'user' + ], + 'spacer' => [ + 'note', 'spacer' + ], + 'special' => [ + 'contentlanguage', 'moduleposition', 'plugin', 'repeatable', 'subform' + ], + 'search' => [ + 'editor', 'email', 'tel', 'text', 'textarea', 'url', 'subform' + ] + ]; + + /** + * Field Checker + * + * @param string $type The field type + * @param string $option The field grouping + * + * @return bool if the field was found + */ + public static function check(string $type, string $option = 'default'): bool + { + // now check + if (isset(self::$fields[$option]) && + in_array($type, self::$fields[$option])) + { + return true; + } + return false; + } diff --git a/src/7c07c9d6-34cd-4491-934a-ef0a83f414c0/code.power b/src/7c07c9d6-34cd-4491-934a-ef0a83f414c0/code.power new file mode 100644 index 0000000..52fe5ac --- /dev/null +++ b/src/7c07c9d6-34cd-4491-934a-ef0a83f414c0/code.power @@ -0,0 +1,55 @@ + /** + * Compiler Placeholder + * + * @var Placeholder + * @since 3.2.0 + **/ + protected Placeholder $placeholder; + + /** + * Constructor. + * + * @param Placeholder|null $placeholder The compiler placeholder object. + * + * @since 3.2.0 + */ + public function __construct(?Placeholder $placeholder = null) + { + $this->placeholder = $placeholder ?: Compiler::_('Placeholder'); + } + + /** + * Set a string as bsae64 (basic) + * + * @param string $script The code string + * + * @return string + * @since 3.2.0 + */ + public function set(string $script): string + { + if (\strpos($script, 'LOCK'.'BASE64((((') !== false) + { + // get the strings + $values = GetHelper::allBetween( + $script, 'LOCK'.'BASE64((((', '))))' + ); + $locker = []; + // convert them + foreach ($values as $value) + { + $locker['LOCK'.'BASE64((((' . $value . '))))'] + = "base64_decode( preg_replace('/\s+/', ''," . + PHP_EOL . Indent::_(2) . "'" . + wordwrap( + base64_encode((string) $value), 64, PHP_EOL . Indent::_(2), true + ) . + "'))"; + } + + // update the script + return $this->placeholder->update($script, $locker); + } + + return $script; + } diff --git a/src/81de8f57-dd9c-4a17-964f-848cd4a0743b/code.power b/src/81de8f57-dd9c-4a17-964f-848cd4a0743b/code.power new file mode 100644 index 0000000..0c1470e --- /dev/null +++ b/src/81de8f57-dd9c-4a17-964f-848cd4a0743b/code.power @@ -0,0 +1,21 @@ + /** + * Encrypt a string as needed + * + * @param string $string The string to encrypt + * @param string $key The encryption key + * + * @return string + * @since 3.2.0 + **/ + public function encrypt(string $string, string $key): string; + + /** + * Decrypt a string as needed + * + * @param string $string The string to decrypt + * @param string $key The decryption key + * + * @return string + * @since 3.2.0 + **/ + public function decrypt(string $string, string $key): string; diff --git a/src/86ac0760-26f5-4746-9c7f-ce77860f80f8/code.power b/src/86ac0760-26f5-4746-9c7f-ce77860f80f8/code.power new file mode 100644 index 0000000..0e7dfc4 --- /dev/null +++ b/src/86ac0760-26f5-4746-9c7f-ce77860f80f8/code.power @@ -0,0 +1,20 @@ + /** + * set the server details + * + * @param object $details The server details + * + * @return self + * @since 3.2.0 + **/ + public function set(object $details); + + /** + * move a file to server with the FTP client + * + * @param string $localPath The full local path to the file + * @param string $fileName The file name + * + * @return bool + * @since 3.2.0 + **/ + public function move(string $localPath, string $fileName): bool; diff --git a/src/87db51b9-1126-4c21-858b-53dbd3a68b61/code.power b/src/87db51b9-1126-4c21-858b-53dbd3a68b61/code.power new file mode 100644 index 0000000..3aa1539 --- /dev/null +++ b/src/87db51b9-1126-4c21-858b-53dbd3a68b61/code.power @@ -0,0 +1,200 @@ + /** + * History Item Object + * + * @var object|null + * @since 3.2.0 + */ + protected ?object $tmp; + + /** + * Compiler Config + * + * @var Config + * @since 3.2.0 + */ + protected Config $config; + + /** + * Database object to query local DB + * + * @var \JDatabaseDriver + * @since 3.2.0 + */ + protected \JDatabaseDriver $db; + + /** + * Constructor + * + * @param Config|null $config The compiler config object. + * @param \JDatabaseDriver|null $db The Database Driver object. + * + * @since 3.2.0 + */ + public function __construct(?Config $config = null, ?\JDatabaseDriver $db = null) + { + $this->config = $config ?: Compiler::_('Config'); + $this->db = $db ?: Factory::getDbo(); + } + + /** + * Get Item History object + * + * @param string $type The type of item + * @param int $id The item ID + * + * @return ?object The history + * @since 3.2.0 + */ + public function get(string $type, int $id): ?object + { + // quick class object to store old history object + $this->tmp = null; + // Create a new query object. + $query = $this->db->getQuery(true); + + $query->select('h.*'); + $query->from('#__ucm_history AS h'); + $query->where( + $this->db->quoteName('h.ucm_item_id') . ' = ' . (int) $id + ); + // Join over the content type for the type id + $query->join( + 'LEFT', '#__content_types AS ct ON ct.type_id = h.ucm_type_id' + ); + $query->where( + 'ct.type_alias = ' . $this->db->quote( + 'com_componentbuilder.' . $type + ) + ); + $query->order('h.save_date DESC'); + $this->db->setQuery($query, 0, 1); + $this->db->execute(); + if ($this->db->getNumRows()) + { + // new version of this item found + // so we need to mark it as the last compiled version + $newActive = $this->db->loadObject(); + // set the new version watch + $this->set($newActive, 1); + } + // Get last compiled verion + $query = $this->db->getQuery(true); + + $query->select('h.*'); + $query->from('#__ucm_history AS h'); + $query->where( + $this->db->quoteName('h.ucm_item_id') . ' = ' . (int) $id + ); + $query->where('h.keep_forever = 1'); + $query->where('h.version_note LIKE ' . $this->db->quote('%component%')); + // make sure it does not return the active version + if (isset($newActive) && isset($newActive->version_id)) + { + $query->where('h.version_id != ' . (int) $newActive->version_id); + } + // Join over the content type for the type id + $query->join( + 'LEFT', '#__content_types AS ct ON ct.type_id = h.ucm_type_id' + ); + $query->where( + 'ct.type_alias = ' . $this->db->quote( + 'com_componentbuilder.' . $type + ) + ); + $query->order('h.save_date DESC'); + $this->db->setQuery($query); + $this->db->execute(); + if ($this->db->getNumRows()) + { + // the old active version was found + // so we may need to do an SQL update + // and unmark the old compiled version + $oldActives = $this->db->loadObjectList(); + foreach ($oldActives as $oldActive) + { + // remove old version watch + $this->set($oldActive, 0); + } + } + + // return the last used history record or null. + return $this->tmp; + } + + /** + * Set Item History Watch + * + * @param Object $object The history object + * @param int $action The action to take + * 0 = remove watch + * 1 = add watch + * + * @return bool + * @since 3.2.0 + */ + protected function set(object $object, int $action): bool + { + // check the note + if (JsonHelper::check($object->version_note)) + { + $version_note = json_decode((string) $object->version_note, true); + } + else + { + $version_note = array('component' => []); + } + // set watch + switch ($action) + { + case 0: + // remove watch + if (isset($version_note['component']) + && ($key = array_search( + $this->config->component_id, $version_note['component'] + )) !== false) + { + // last version that was used to build/compile + $this->tmp = json_decode((string) $object->version_data); + // remove it from this component + unset($version_note['component'][$key]); + } + else + { + // since it was not found, no need to update anything + return true; + } + break; + case 1: + // add watch + if (!in_array($this->config->component_id, $version_note['component'])) + { + $version_note['component'][] = $this->config->component_id; + } + else + { + // since it is there already, no need to update anything + return true; + } + break; + } + // check if we need to still keep this locked + if (isset($version_note['component']) + && ArrayHelper::check($version_note['component'])) + { + // insure component ids are only added once per item + $version_note['component'] = array_unique( + $version_note['component'] + ); + // we may change this, little risky (but since JCB does not have history notes it should be okay for now) + $object->version_note = json_encode($version_note); + $object->keep_forever = '1'; + } + else + { + $object->version_note = ''; + $object->keep_forever = '0'; + } + + // run the update + return $this->db->updateObject('#__ucm_history', $object, 'version_id'); + } diff --git a/src/87faa133-4cac-4816-ae41-5c3f9a2f76aa/code.power b/src/87faa133-4cac-4816-ae41-5c3f9a2f76aa/code.power new file mode 100644 index 0000000..0e7a5c0 --- /dev/null +++ b/src/87faa133-4cac-4816-ae41-5c3f9a2f76aa/code.power @@ -0,0 +1,83 @@ + /** + * 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(CustomviewData::class, 'Customview.Data') + ->share('Customview.Data', [$this, 'getCustomviewData'], true); + + $container->alias(DynamicgetData::class, 'Dynamicget.Data') + ->share('Dynamicget.Data', [$this, 'getDynamicgetData'], true); + + $container->alias(DynamicgetSelection::class, 'Dynamicget.Selection') + ->share('Dynamicget.Selection', [$this, 'getDynamicgetSelection'], true); + } + + /** + * Get the Compiler Customview Data + * + * @param Container $container The DI container. + * + * @return CustomviewData + * @since 3.2.0 + */ + public function getCustomviewData(Container $container): CustomviewData + { + return new CustomviewData( + $container->get('Config'), + $container->get('Event'), + $container->get('Customcode'), + $container->get('Customcode.Gui'), + $container->get('Model.Libraries'), + $container->get('Templatelayout.Data'), + $container->get('Dynamicget.Data'), + $container->get('Model.Loader'), + $container->get('Model.Javascriptcustomview'), + $container->get('Model.Csscustomview'), + $container->get('Model.Phpcustomview'), + $container->get('Model.Ajaxcustomview'), + $container->get('Model.Custombuttons') + ); + } + + /** + * Get the Compiler Dynamicget Data + * + * @param Container $container The DI container. + * + * @return DynamicgetData + * @since 3.2.0 + */ + public function getDynamicgetData(Container $container): DynamicgetData + { + return new DynamicgetData( + $container->get('Config'), + $container->get('Registry'), + $container->get('Event'), + $container->get('Customcode'), + $container->get('Customcode.Dispenser'), + $container->get('Customcode.Gui'), + $container->get('Model.Dynamicget') + ); + } + + /** + * Get the Compiler Dynamicget Selection + * + * @param Container $container The DI container. + * + * @return DynamicgetSelection + * @since 3.2.0 + */ + public function getDynamicgetSelection(Container $container): DynamicgetSelection + { + return new DynamicgetSelection( + $container->get('Config'), + $container->get('Registry') + ); + } diff --git a/src/8a63e87b-b39b-4a15-8044-9b2a2f4fb61c/code.power b/src/8a63e87b-b39b-4a15-8044-9b2a2f4fb61c/code.power new file mode 100644 index 0000000..095dc7d --- /dev/null +++ b/src/8a63e87b-b39b-4a15-8044-9b2a2f4fb61c/code.power @@ -0,0 +1,196 @@ + /** + * 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(CompilerComponent::class, 'Component') + ->share('Component', [$this, 'getComponent'], true); + + $container->alias(Settings::class, 'Component.Settings') + ->share('Component.Settings', [$this, 'getSettings'], true); + + $container->alias(Dashboard::class, 'Component.Dashboard') + ->share('Component.Dashboard', [$this, 'getDashboard'], true); + + $container->alias(Placeholder::class, 'Component.Placeholder') + ->share('Component.Placeholder', [$this, 'getPlaceholder'], true); + + $container->alias(Data::class, 'Component.Data') + ->share('Component.Data', [$this, 'getData'], true); + + $container->alias(Structure::class, 'Component.Structure') + ->share('Component.Structure', [$this, 'getStructure'], true); + + $container->alias(Structuresingle::class, 'Component.Structure.Single') + ->share('Component.Structure.Single', [$this, 'getStructuresingle'], true); + + $container->alias(Structuremultiple::class, 'Component.Structure.Multiple') + ->share('Component.Structure.Multiple', [$this, 'getStructuremultiple'], true); + } + + /** + * Get the Component + * + * @param Container $container The DI container. + * + * @return CompilerComponent + * @since 3.2.0 + */ + public function getComponent(Container $container): CompilerComponent + { + return new CompilerComponent( + $container->get('Component.Data') + ); + } + + /** + * Get the Compiler Component (version) Settings + * + * @param Container $container The DI container. + * + * @return Settings + * @since 3.2.0 + */ + public function getSettings(Container $container): Settings + { + return new Settings( + $container->get('Config'), + $container->get('Registry'), + $container->get('Event'), + $container->get('Placeholder'), + $container->get('Component'), + $container->get('Utilities.Paths'), + $container->get('Utilities.Dynamicpath'), + $container->get('Utilities.Pathfix') + ); + } + + /** + * Get the Compiler Component Dynamic Dashboard + * + * @param Container $container The DI container. + * + * @return Dashboard + * @since 3.2.0 + */ + public function getDashboard(Container $container): Dashboard + { + return new Dashboard( + $container->get('Registry'), + $container->get('Component') + ); + } + + /** + * Get the Component Placeholders + * + * @param Container $container The DI container. + * + * @return Placeholder + * @since 3.2.0 + */ + public function getPlaceholder(Container $container): Placeholder + { + return new Placeholder( + $container->get('Config') + ); + } + + /** + * Get the Component Data + * + * @param Container $container The DI container. + * + * @return Data + * @since 3.2.0 + */ + public function getData(Container $container): Data + { + return new Data( + $container->get('Config'), + $container->get('Event'), + $container->get('Placeholder'), + $container->get('Component.Placeholder'), + $container->get('Customcode.Dispenser'), + $container->get('Customcode'), + $container->get('Customcode.Gui'), + $container->get('Field'), + $container->get('Field.Name'), + $container->get('Field.Unique.Name'), + $container->get('Model.Filesfolders'), + $container->get('Model.Historycomponent'), + $container->get('Model.Whmcs'), + $container->get('Model.Sqltweaking'), + $container->get('Model.Adminviews'), + $container->get('Model.Siteviews'), + $container->get('Model.Customadminviews'), + $container->get('Model.Updateserver'), + $container->get('Model.Joomlamodules'), + $container->get('Model.Joomlaplugins') + ); + } + + /** + * Get the Compiler Structure + * + * @param Container $container The DI container. + * + * @return Structure + * @since 3.2.0 + */ + public function getStructure(Container $container): Structure + { + return new Structure( + $container->get('Component.Settings'), + $container->get('Utilities.Paths'), + $container->get('Utilities.Folder') + ); + } + + /** + * Get the Compiler Structure Single + * + * @param Container $container The DI container. + * + * @return Structuresingle + * @since 3.2.0 + */ + public function getStructuresingle(Container $container): Structuresingle + { + return new Structuresingle( + $container->get('Config'), + $container->get('Registry'), + $container->get('Component.Settings'), + $container->get('Component'), + $container->get('Content'), + $container->get('Utilities.Counter'), + $container->get('Utilities.Paths'), + $container->get('Utilities.Files') + ); + } + + /** + * Get the Compiler Structure Multiple + * + * @param Container $container The DI container. + * + * @return Structuremultiple + * @since 3.2.0 + */ + public function getStructuremultiple(Container $container): Structuremultiple + { + return new Structuremultiple( + $container->get('Config'), + $container->get('Registry'), + $container->get('Component.Settings'), + $container->get('Component'), + $container->get('Model.Createdate'), + $container->get('Model.Modifieddate'), + $container->get('Utilities.Structure') + ); + } diff --git a/src/8c018533-e967-4bf2-9bd9-9e92966fcb5e/code.power b/src/8c018533-e967-4bf2-9bd9-9e92966fcb5e/code.power new file mode 100644 index 0000000..d1cdca5 --- /dev/null +++ b/src/8c018533-e967-4bf2-9bd9-9e92966fcb5e/code.power @@ -0,0 +1,83 @@ + /** + * The compiler registry + * + * @var Registry + * @since 3.2.0 + */ + protected Registry $registry; + + /** + * Constructor + * + * @param Registry|null $registry The compiler registry object. + * + * @since 3.2.0 + */ + public function __construct(?Registry $registry = null) + { + $this->registry = $registry ?: Compiler::_('Registry'); + } + + /** + * Count how many times the same field is used per view + * + * @param string $name The name of the field + * @param string $view The name of the view + * + * @return void + * @since 3.2.0 + */ + public function set(string $name, string $view) + { + if (($number = $this->registry->get("unique.names.${view}.counter.${name}")) === null) + { + $this->registry->set("unique.names.${view}.counter.${name}", 1); + + return; + } + + // count how many times the field is used + $this->registry->set("unique.names.${view}.counter.${name}", ++$number); + + return; + } + + /** + * Naming each field with an unique name + * + * @param string $name The name of the field + * @param string $view The name of the view + * + * @return string the name + * @since 3.2.0 + */ + public function get(string $name, string $view): string + { + // only increment if the field name is used multiple times + if ($this->registry->get("unique.names.${view}.counter.${name}") > 1) + { + $counter = 1; + // set the unique name + $unique_name = FieldHelper::safe( + $name . '_' . $counter + ); + + while ($this->registry->get("unique.names.${view}.names.${unique_name}") !== null) + { + // increment the number + $counter++; + // try again + $unique_name = FieldHelper::safe( + $name . '_' . $counter + ); + } + + // set the new name number + $this->registry->set("unique.names.${view}.names.${unique_name}", $counter); + + // return the unique name + return $unique_name; + } + + return $name; + } diff --git a/src/8eee7df5-2775-41a9-9372-c46c5939a252/code.power b/src/8eee7df5-2775-41a9-9372-c46c5939a252/code.power new file mode 100644 index 0000000..383aeed --- /dev/null +++ b/src/8eee7df5-2775-41a9-9372-c46c5939a252/code.power @@ -0,0 +1,171 @@ + /** + * The language content + * + * @var array + * @since 3.2.0 + **/ + protected array $content = []; + + /** + * Compiler Config + * + * @var Config + * @since 3.2.0 + **/ + protected Config $config; + + /** + * Constructor. + * + * @param Config|null $config The compiler config object. + * + * @since 3.2.0 + */ + public function __construct(?Config $config = null) + { + $this->config = $config ?: Compiler::_('Config'); + } + + /** + * Get the language string key + * + * @param string $string The plan text string (English) + * + * @return string The key language string (all uppercase) + * @since 3.2.0 + */ + public function key($string): string + { + // this is there to insure we don't break already added Language strings + if (StringHelper::safe($string, 'U', '_', false, false) + === $string) + { + return false; + } + + // build language key + $key_lang = $this->config->lang_prefix . '_' . StringHelper::safe( + $string, 'U' + ); + + // set the language string + $this->set($this->config->lang_target, $key_lang, $string); + + return $key_lang; + } + + /** + * check if the language string exist + * + * @param string $target The target area for the language string + * @param string|null $language The language key string + * + * @return bool + * @since 3.2.0 + */ + public function exist(string $target, ?string $language = null): bool + { + if ($language) + { + return isset($this->content[$target][$language]); + } + + return isset($this->content[$target]); + } + + /** + * get the language string + * + * @param string $target The target area for the language string + * @param string|null $language The language key string + * + * @return Mixed The language string found or empty string if none is found + * @since 3.2.0 + */ + public function get(string $target, string $language): string + { + if (isset($this->content[$target][$language])) + { + return $this->content[$target][$language]; + } + + return ''; + } + + /** + * get target array + * + * @param string $target The target area for the language string + * + * @return array The target array or empty array if none is found + * @since 3.2.0 + */ + public function getTarget(string $target): array + { + if (isset($this->content[$target]) && ArrayHelper::check($this->content[$target])) + { + return $this->content[$target]; + } + + return []; + } + + /** + * set target array + * + * @param string $target The target area for the language string + * @param array|null $content The language content string + * + * @return void + * @since 3.2.0 + */ + public function setTarget(string $target, ?array $content) + { + $this->content[$target] = $content; + } + + /** + * set the language content values to language content array + * + * @param string $target The target area for the language string + * @param string $language The language key string + * @param string $string The language string + * @param bool $addPrefix The switch to add langPrefix + * + * @return void + * @since 3.2.0 + */ + public function set(string $target, string $language, string $string, bool $addPrefix = false) + { + if ($addPrefix && empty( + $this->content[$target][$this->config->lang_prefix . '_' . $language] + )) + { + $this->content[$target][$this->config->lang_prefix . '_' . $language] + = $this->fix($string); + } + elseif (empty($this->content[$target][$language])) + { + $this->content[$target][$language] = $this->fix( + $string + ); + } + } + + /** + * We need to remove all text breaks from all language strings + * + * @param string $string The language string + * + * @return string + * @since 3.2.0 + */ + protected function fix(string $string): string + { + if ($this->config->remove_line_breaks) + { + return trim(str_replace(array(PHP_EOL, "\r", "\n"), '', $string)); + } + + return trim($string); + } diff --git a/src/9127e428-5dee-46cb-b3a9-ab5b91ea6df3/code.power b/src/9127e428-5dee-46cb-b3a9-ab5b91ea6df3/code.power new file mode 100644 index 0000000..5adf567 --- /dev/null +++ b/src/9127e428-5dee-46cb-b3a9-ab5b91ea6df3/code.power @@ -0,0 +1,125 @@ + /** + * The array of last modified dates + * + * @var array + * @since 3.2.0 + */ + protected array $last = []; + + /** + * Get the last modified date of an item + * + * @param array $item The item data + * + * @return string The modified date + * @since 3.2.0 + */ + public function get(array $item): string + { + $key = $this->getKey($item); + + if (!isset($this->last[$key])) + { + $date = max($this->getDate($item), $this->getModified($item)); + + $this->last[$key] = Factory::getDate($date)->format( + 'jS F, Y' + ); + } + + return $this->last[$key]; + } + + /** + * Get the last modified date of an item + * + * @param array $item The item data + * + * @return int The modified date as int + * @since 3.2.0 + */ + protected function getDate(array $item): int + { + if (isset($item['settings']) && isset($item['settings']->modified) + && StringHelper::check($item['settings']->modified) + && '0000-00-00 00:00:00' !== $item['settings']->modified) + { + return strtotime((string) $item['settings']->modified); + } + + return strtotime("now"); + } + + /** + * Get the last modified date of an item's sub items + * + * @param array $item The item data + * + * @return int The modified date as int + * @since 3.2.0 + */ + protected function getModified(array $item): int + { + $date = 0; + + // if not settings is found + if (!isset($item['settings']) || !ObjectHelper::check($item['settings'])) + { + return $date; + } + + // check if we have fields + if (isset($item['settings']->fields) && ArrayHelper::check($item['settings']->fields)) + { + foreach ($item['settings']->fields as $field) + { + if (isset($field['settings']) + && ObjectHelper::check($field['settings']) + && isset($field['settings']->modified) + && StringHelper::check($field['settings']->modified) + && '0000-00-00 00:00:00' !== $field['settings']->modified) + { + $modified = strtotime((string) $field['settings']->modified); + $date = max($date, $modified); + } + } + } + // check if we have a main dynamic get + elseif (isset($item['settings']->main_get) + && ObjectHelper::check($item['settings']->main_get) + && isset($item['settings']->main_get->modified) + && StringHelper::check($item['settings']->main_get->modified) + && '0000-00-00 00:00:00' !== $item['settings']->main_get->modified) + { + $modified = strtotime((string) $item['settings']->main_get->modified); + $date = max($date, $modified); + } + + return $date; + } + + /** + * Get the key for an item + * + * @param array $item The item data + * + * @return string The key + * @since 3.2.0 + */ + protected function getKey(array $item): string + { + if (isset($item['adminview'])) + { + return $item['adminview'] . 'admin'; + } + elseif (isset($item['siteview'])) + { + return $item['siteview'] . 'site'; + } + elseif (isset($item['customadminview'])) + { + return $item['customadminview'] . 'customadmin'; + } + + return 'error'; + } diff --git a/src/9387215f-a965-4421-acf3-5e8f9d11382f/code.power b/src/9387215f-a965-4421-acf3-5e8f9d11382f/code.power new file mode 100644 index 0000000..f953505 --- /dev/null +++ b/src/9387215f-a965-4421-acf3-5e8f9d11382f/code.power @@ -0,0 +1,199 @@ + /** + * The compiler registry + * + * @var Registry + * @since 3.2.0 + */ + protected Registry $registry; + + /** + * Unique Field Names + * + * @var array + * @since 3.2.0 + */ + protected array $unique; + + /** + * Compiler Placeholder + * + * @var Placeholder + * @since 3.2.0 + */ + protected Placeholder $placeholder; + + /** + * Compiler Field Unique Name + * + * @var UniqueName + * @since 3.2.0 + */ + protected UniqueName $uniqueName; + + /** + * Constructor + * + * @param Placeholder|null $placeholder The compiler component placeholder object. + * @param UniqueName|null $uniqueName The compiler field unique name object. + * @param Registry|null $registry The compiler registry object. + * + * @since 3.2.0 + */ + public function __construct(?Placeholder $placeholder = null, ?UniqueName $uniqueName = null, ?Registry $registry = null) + { + $this->placeholder = $placeholder ?: Compiler::_('Placeholder'); + $this->uniqueName = $uniqueName ?: Compiler::_('Field.Unique.Name'); + $this->registry = $registry ?: Compiler::_('Registry'); + } + + /** + * Get the field's actual name + * + * @param array $field The field array + * @param string|null $listViewName The list view name + * @param string $amicably The peaceful resolve (for fields in subforms in same view :) + * + * @return string Success returns field name + * @since 3.2.0 + */ + public function get(array &$field, ?string $listViewName = null, string $amicably = ''): string + { + // return the unique name if already set + if ($listViewName && StringHelper::check($listViewName) + && isset($field['hash']) + && isset( + $this->unique[$listViewName . $amicably . $field['hash']] + )) + { + return $this->unique[$listViewName . $amicably . $field['hash']]; + } + + // always make sure we have a field name and type + if (!isset($field['settings']) || !isset($field['settings']->type_name) + || !isset($field['settings']->name)) + { + return 'error'; + } + + // set the type name + $type_name = TypeHelper::safe( + $field['settings']->type_name + ); + + // set the name of the field + $name = FieldHelper::safe($field['settings']->name); + + // check that we have the properties + if (ArrayHelper::check($field['settings']->properties)) + { + foreach ($field['settings']->properties as $property) + { + if ($property['name'] === 'name') + { + // if category then name must be catid (only one per view) + if ($type_name === 'category') + { + // quick check if this is a category linked to view page + $requeSt_id = GetHelper::between( + $field['settings']->xml, 'name="', '"' + ); + if (strpos($requeSt_id, '_request_id') !== false + || strpos($requeSt_id, '_request_catid') !== false) + { + // keep it then, don't change + $name = $this->placeholder->update_( + $requeSt_id + ); + } + else + { + $name = 'catid'; + } + + // if list view name is set + if (StringHelper::check($listViewName)) + { + // check if we should use another Text Name as this views name + $otherName = $this->placeholder->update_( + GetHelper::between( + $field['settings']->xml, 'othername="', '"' + ) + ); + $otherViews = $this->placeholder->update_( + GetHelper::between( + $field['settings']->xml, 'views="', '"' + ) + ); + $otherView = $this->placeholder->update_( + GetHelper::between( + $field['settings']->xml, 'view="', '"' + ) + ); + // This is to link other view category + if (StringHelper::check($otherName) + && StringHelper::check( + $otherViews + ) && StringHelper::check( + $otherView + )) + { + // set other category details + $this->registry->set("category.other.name.${listViewName}", [ + 'name' => FieldHelper::safe( + $otherName + ), + 'views' => StringHelper::safe( + $otherViews + ), + 'view' => StringHelper::safe( + $otherView + ) + ]); + } + } + } + // if tag is set then enable all tag options for this view (only one per view) + elseif ($type_name === 'tag') + { + $name = 'tags'; + } + // if the field is set as alias it must be called alias + elseif (isset($field['alias']) && $field['alias']) + { + $name = 'alias'; + } + else + { + // get value from xml + $xml = FieldHelper::safe( + $this->placeholder->update_( + GetHelper::between( + $field['settings']->xml, 'name="', '"' + ) + ) + ); + // check if a value was found + if (StringHelper::check($xml)) + { + $name = $xml; + } + } + // exit foreach loop + break; + } + } + } + + // return the value unique + if (StringHelper::check($listViewName) && isset($field['hash'])) + { + $this->unique[$listViewName . $amicably . $field['hash']] + = $this->uniqueName->get($name, $listViewName . $amicably); + + // now return the unique name + return $this->unique[$listViewName . $amicably . $field['hash']]; + } + + // fall back to global + return $name; + } diff --git a/src/95d0e03f-24fd-4412-bc2e-f0899fcc3205/code.power b/src/95d0e03f-24fd-4412-bc2e-f0899fcc3205/code.power new file mode 100644 index 0000000..8400e0d --- /dev/null +++ b/src/95d0e03f-24fd-4412-bc2e-f0899fcc3205/code.power @@ -0,0 +1,406 @@ + /** + * Get properties and method declarations and other details from the given code. + * + * @param string $code The code containing class properties & methods + * + * @return array An array of properties & method declarations of the given code + * @since 3.2.0 + */ + public function code(string $code): array + { + return [ + 'properties' => $this->properties($code), + 'methods' => $this->methods($code) + ]; + } + + /** + * Extracts properties declarations and other details from the given code. + * + * @param string $code The code containing class properties + * + * @return array|null An array of properties declarations and details + * @since 3.2.0 + */ + private function properties(string $code): ?array + { + // regex to target all properties + $access = '(?var|public|protected|private)'; + $type = '(?(?:\?|)[\p{L}0-9\\\\]*\s+)?'; + $static = '(?static)?'; + $name = '\$(?\p{L}[\p{L}0-9]*)'; + $default = '(?:\s*=\s*(?\[[^\]]*\]|\d+|\'[^\']*?\'|"[^"]*?"|false|true|null))?'; + $property_pattern = "/\b{$access}\s*{$type}{$static}\s*{$name}{$default};/u"; + + preg_match_all($property_pattern, $code, $matches, PREG_SET_ORDER); + + if ($matches != []) + { + $properties = []; + foreach ($matches as $n => $match) + { + $declaration = $match[0] ?? null; + + if (is_string($declaration)) + { + $comment = $this->extractDocBlock($code, $declaration); + $declaration = trim(preg_replace('/\s{2,}/', ' ', + preg_replace('/[\r\n]+/', ' ', $declaration))); + + $properties[] = [ + 'name' => isset($match['name']) ? '$' . $match['name'] : 'error', + 'access' => $match['access'] ?? 'public', + 'type' => isset($match['type']) ? trim($match['type']) : null, + 'static' => (bool) $match['static'] ?? false, + 'default' => $match['default'] ?? null, + 'comment' => $comment, + 'declaration' => $declaration + ]; + } + } + + return $properties; + } + + return null; + } + + /** + * Extracts method declarations and other details from the given code. + * + * @param string $code The code containing class methods + * + * @return array|null An array of method declarations and details + * @since 3.2.0 + */ + private function methods(string $code): ?array + { + // regex to target all methods/functions + $final_modifier = '(?Pfinal)?\s*'; + $abstract_modifier = '(?Pabstract)?\s*'; + $access_modifier = '(?Ppublic|protected|private)?\s*'; + $static_modifier = '(?Pstatic)?\s*'; + $modifier = "{$final_modifier}{$abstract_modifier}{$access_modifier}{$static_modifier}"; + $name = '(?P\w+)'; + $arguments = '(?P\(.*?\))?'; + $return_type = '(?P\s*:\s*(?:\?[\w\\\\]+|\\\\?[\w\\\\]+(?:\|\s*(?:\?[\w\\\\]+|\\\\?[\w\\\\]+))*)?)?'; + $method_pattern = "/(^\s*?\b{$modifier}function\s+{$name}{$arguments}{$return_type})/sm"; + + preg_match_all($method_pattern, $code, $matches, PREG_SET_ORDER); + + if ($matches != []) + { + $methods = []; + foreach ($matches as $n => $match) + { + $full_declaration = $match[0] ?? null; + + if (is_string($full_declaration)) + { + $comment = $this->extractDocBlock($code, $full_declaration); + + $full_declaration = trim(preg_replace('/\s{2,}/', ' ', + preg_replace('/[\r\n]+/', ' ', $full_declaration))); + + // now load what we found + $methods[] = [ + 'name' => $match['name'] ?? 'error', + 'access' => $match['access_modifier'] ?? 'public', + 'static' => (bool) $match['static_modifier'] ?? false, + 'final' => (bool) $match['final_modifier'] ?? false, + 'abstract' => (bool) $match['abstract_modifier'] ?? false, + 'return_type' => $this->extractReturnType($match['return_type'] ?? null, $comment), + 'since' => $this->extractSinceVersion($comment), + 'deprecated' => $this->extractDeprecatedVersion($comment), + 'arguments' => $this->extractFunctionArgumentDetails($comment, $match['arguments'] ?? null), + 'comment' => $comment, + 'declaration' => str_replace(["\r\n", "\r", "\n"], '', $full_declaration) + ]; + } + } + + return $methods; + } + + return null; + } + + /** + * Extracts the PHPDoc block for a given function declaration. + * + * @param string $code The source code containing the function + * @param string $declaration The part of the function declaration + * + * @return string|null The PHPDoc block, or null if not found + * @since 3.2.0 + */ + private function extractDocBlock(string $code, string $declaration): ?string + { + // Split the code string with the function declaration + $parts = explode($declaration, $code); + if (count($parts) < 2) + { + // Function declaration not found in the code + return null; + } + + // Get the part with the comment (if any) + $comment = $parts[0]; + + // Split the last part using the comment block start marker + $commentParts = preg_split('/(})?\s+(?=\s*\/\*)(\*)?/', $comment); + + // Get the last comment block + $lastCommentPart = end($commentParts); + + // Search for the comment block in the last comment part + if (preg_match('/(\/\*\*[\s\S]*?\*\/)\s*$/u', $lastCommentPart, $matches)) + { + $comment = $matches[1] ?? null; + // check if we actually have a comment + if ($comment) + { + return $this->removeWhiteSpaceFromComment($comment); + } + } + + return null; + } + + /** + * Extracts the function argument details. + * + * @param string|null $comment The function comment if found + * @param string|null $arguments The arguments found on function declaration + * + * @return array|null The function argument details + * @since 3.2.0 + */ + private function extractFunctionArgumentDetails(?string $comment, ?string $arguments): ?array + { + $arg_types_from_declaration = $this->extractArgTypesArguments($arguments); + $arg_types_from_comments = null; + + if ($comment) + { + $arg_types_from_comments = $this->extractArgTypesFromComment($comment); + } + + // merge the types + if ($arg_types_from_declaration) + { + return $this->mergeArgumentTypes($arg_types_from_declaration, $arg_types_from_comments); + } + + return null; + } + + /** + * Extracts the function return type. + * + * @param string|null $returnType The return type found in declaration + * @param string|null $comment The function comment if found + * + * @return string|null The function return type + * @since 3.2.0 + */ + private function extractReturnType(?string $returnType, ?string $comment): ?string + { + if ($returnType === null && $comment) + { + return $this->extractReturnTypeFromComment($comment); + } + + return trim(trim($returnType, ':')); + } + + /** + * Extracts argument types from a given comment. + * + * @param string $comment The comment containing the argument types + * + * @return array|null An array of argument types + * @since 3.2.0 + */ + private function extractArgTypesFromComment(string $comment): ?array + { + preg_match_all('/@param\s+((?:[^\s|]+(?:\|)?)+)?\s+\$([^\s]+)/', $comment, $matches, PREG_SET_ORDER); + + if ($matches !== []) + { + $arg_types = []; + + foreach ($matches as $match) + { + $arg = $match[2] ?? null; + $type = $match[1] ?: null; + if (is_string($arg)) + { + $arg_types['$' .$arg] = $type; + } + } + + return $arg_types; + } + + return null; + } + + /** + * Extracts argument types from a given declaration. + * + * @param string|null $arguments The arguments found on function declaration + * + * @return array|null An array of argument types + * @since 3.2.0 + */ + private function extractArgTypesArguments(?string $arguments): ?array + { + if ($arguments) + { + $args = preg_split('/,(?![^()\[\]]*(\)|\]))/', trim($arguments, '()')); + if ($args !== []) + { + $argument_types = []; + foreach ($args as $arg) + { + $eqPos = strpos($arg, '='); + + if ($eqPos !== false) + { + $arg_parts = [ + substr($arg, 0, $eqPos), + substr($arg, $eqPos + 1) + ]; + } + else + { + $arg_parts = [$arg]; + } + + if (preg_match('/(?:(\??(?:\w+|\\\\[\w\\\\]+)(?:\|\s*\??(?:\w+|\\\\[\w\\\\]+))*)\s+)?\$(\w+)/', $arg_parts[0], $arg_matches)) + { + $type = $arg_matches[1] ?: null; + $name = $arg_matches[2] ?: null; + $default = isset($arg_parts[1]) ? preg_replace('/\s{2,}/', ' ', + preg_replace('/[\r\n]+/', ' ', trim($arg_parts[1]))) : null; + + if (is_string($name)) + { + $argument_types['$' . $name] = [ + 'type' => $type, + 'default' => $default, + ]; + } + } + } + + return $argument_types; + } + } + + return null; + } + + /** + * Extracts return type from a given declaration. + * + * @param string $comment The comment containing the return type + * + * @return string|null The return type + * @since 3.2.0 + */ + private function extractReturnTypeFromComment(string $comment): ?string + { + if (preg_match('/@return\s+((?:[^\s|]+(?:\|)?)+)/', $comment, $matches)) + { + return $matches[1] ?: null; + } + + return null; + } + + /** + * Extracts the version number from the @since tag in the given comment. + * + * @param string|null $comment The comment containing the @since tag and version number + * + * @return string|null The extracted version number or null if not found + * @since 3.2.0 + */ + private function extractSinceVersion(?string $comment): ?string + { + if (is_string($comment) && preg_match('/@since\s+(v?\d+(?:\.\d+)*(?:-(?:alpha|beta|rc)\d*)?)/', $comment, $matches)) + { + return $matches[1] ?: null; + } + + return null; + } + + /** + * Extracts the version number from the deprecated tag in the given comment. + * + * @param string|null $comment The comment containing the deprecated tag and version number + * + * @return string|null The extracted version number or null if not found + * @since 3.2.0 + */ + private function extractDeprecatedVersion(?string $comment): ?string + { + if (is_string($comment) && preg_match('/@deprecated\s+(v?\d+(?:\.\d+)*(?:-(?:alpha|beta|rc)\d*)?)/', $comment, $matches)) + { + return $matches[1] ?: null; + } + + return null; + } + + /** + * Remove all white space from each line of the comment + * + * @param string $comment The function declaration containing the return type + * + * @return string The return comment + * @since 3.2.0 + */ + private function removeWhiteSpaceFromComment(string $comment): string + { + // Remove comment markers and leading/trailing whitespace + $comment = preg_replace('/^\/\*\*[\r\n\s]*|[\r\n\s]*\*\/$/m', '', $comment); + $comment = preg_replace('/^[\s]*\*[\s]?/m', '', $comment); + + // Split the comment into lines + $lines = preg_split('/\r\n|\r|\n/', $comment); + + // Remove white spaces from each line + $trimmedLines = array_map('trim', $lines); + + // Join the lines back together + return implode("\n", array_filter($trimmedLines)); + } + + /** + * Merges the types from the comments and the arguments. + * + * @param array $argTypesFromDeclaration An array of argument types and default values from the declaration + * @param array|null $argTypesFromComments An array of argument types from the comments + * + * @return array A merged array of argument information + * @since 3.2.0 + */ + private function mergeArgumentTypes(array $argTypesFromDeclaration, ?array $argTypesFromComments): array + { + $mergedArguments = []; + + foreach ($argTypesFromDeclaration as $name => $declarationInfo) + { + $mergedArguments[$name] = [ + 'name' => $name, + 'type' => $declarationInfo['type'] ?: $argTypesFromComments[$name] ?? null, + 'default' => $declarationInfo['default'] ?: null, + ]; + } + + return $mergedArguments; + } diff --git a/src/97698747-c2ce-4e09-a470-acf6d8e86281/code.power b/src/97698747-c2ce-4e09-a470-acf6d8e86281/code.power new file mode 100644 index 0000000..262dfec --- /dev/null +++ b/src/97698747-c2ce-4e09-a470-acf6d8e86281/code.power @@ -0,0 +1,8 @@ + /** + * get all System Placeholders + * + * @return array The global placeholders + * + * @since 3.2.0 + */ + public function get(): array; \ No newline at end of file diff --git a/src/99368a6f-2f64-4d4e-ad3a-544d4020ecc6/code.power b/src/99368a6f-2f64-4d4e-ad3a-544d4020ecc6/code.power new file mode 100644 index 0000000..b222866 --- /dev/null +++ b/src/99368a6f-2f64-4d4e-ad3a-544d4020ecc6/code.power @@ -0,0 +1,73 @@ + /** + * The compiler registry + * + * @var Registry + * @since 3.2.0 + */ + protected Registry $registry; + + /** + * Constructor + * + * @param Registry|null $config The compiler registry object. + * + * @since 3.2.0 + */ + public function __construct(?Registry $registry = null) + { + $this->registry = $registry ?: Compiler::_('Registry'); + } + + /** + * get the field database name and AS prefix + * + * @param string $nameListCode The list view name + * @param int $fieldId The field ID + * @param string $targetArea The area being targeted + * + * @return string|null + * @since 3.2.0 + */ + public function get(string $nameListCode, int $fieldId, string $targetArea = 'builder.list'): ?string + { + if (($fields = $this->registry->get("${targetArea}.${nameListCode}")) !== null) + { + if ($fieldId < 0) + { + switch ($fieldId) + { + case -1: + return 'a.id'; + case -2: + return 'a.ordering'; + case -3: + return 'a.published'; + } + } + foreach ($fields as $field) + { + if ($field['id'] == $fieldId) + { + // now check if this is a category + if ($field['type'] === 'category') + { + return 'c.title'; + } + // set the custom code + elseif (ArrayHelper::check( + $field['custom'] + )) + { + return $field['custom']['db'] . "." + . $field['custom']['text']; + } + else + { + return 'a.' . $field['code']; + } + } + } + } + + return null; + } diff --git a/src/9eba241c-af90-42dd-ae05-92ff4d8391d3/code.power b/src/9eba241c-af90-42dd-ae05-92ff4d8391d3/code.power new file mode 100644 index 0000000..261453c --- /dev/null +++ b/src/9eba241c-af90-42dd-ae05-92ff4d8391d3/code.power @@ -0,0 +1,62 @@ + /** + * 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(Data::class, 'Joomlaplugin.Data') + ->share('Joomlaplugin.Data', [$this, 'getData'], true); + + $container->alias(Structure::class, 'Joomlaplugin.Structure') + ->share('Joomlaplugin.Structure', [$this, 'getStructure'], true); + } + + /** + * Get the Joomla Plugin Data + * + * @param Container $container The DI container. + * + * @return Data + * @since 3.2.0 + */ + public function getData(Container $container): Data + { + return new Data( + $container->get('Config'), + $container->get('Customcode'), + $container->get('Customcode.Gui'), + $container->get('Placeholder'), + $container->get('Language'), + $container->get('Field'), + $container->get('Field.Name'), + $container->get('Model.Filesfolders') + ); + } + + /** + * Get the Joomla Plugin Structure Builder + * + * @param Container $container The DI container. + * + * @return Structure + * @since 3.2.0 + */ + public function getStructure(Container $container): Structure + { + return new Structure( + $container->get('Joomlaplugin.Data'), + $container->get('Component'), + $container->get('Config'), + $container->get('Registry'), + $container->get('Customcode.Dispenser'), + $container->get('Event'), + $container->get('Utilities.Counter'), + $container->get('Utilities.Folder'), + $container->get('Utilities.File'), + $container->get('Utilities.Files') + ); + } diff --git a/src/9f00e793-86f8-4ef9-b775-a3eb129f83c0/code.power b/src/9f00e793-86f8-4ef9-b775-a3eb129f83c0/code.power new file mode 100644 index 0000000..af4f11b --- /dev/null +++ b/src/9f00e793-86f8-4ef9-b775-a3eb129f83c0/code.power @@ -0,0 +1,48 @@ + /** + * 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(CompilerLanguage::class, 'Language') + ->share('Language', [$this, 'getLanguage'], true); + + $container->alias(Extractor::class, 'Language.Extractor') + ->share('Language.Extractor', [$this, 'getLanguageExtractor'], true); + } + + /** + * Get the Compiler Language + * + * @param Container $container The DI container. + * + * @return CompilerLanguage + * @since 3.2.0 + */ + public function getLanguage(Container $container): CompilerLanguage + { + return new CompilerLanguage( + $container->get('Config') + ); + } + + /** + * Get the Compiler Language Extractor + * + * @param Container $container The DI container. + * + * @return Extractor + * @since 3.2.0 + */ + public function getLanguageExtractor(Container $container): Extractor + { + return new Extractor( + $container->get('Config'), + $container->get('Language'), + $container->get('Placeholder') + ); + } diff --git a/src/a356d103-74f3-49ca-8e4f-3bd37746f089/code.power b/src/a356d103-74f3-49ca-8e4f-3bd37746f089/code.power new file mode 100644 index 0000000..31cd5fa --- /dev/null +++ b/src/a356d103-74f3-49ca-8e4f-3bd37746f089/code.power @@ -0,0 +1,203 @@ + /** + * Tracking the update of fields per/view + * + * @var array + * @since 3.2.0 + */ + protected array $views; + + /** + * Compiler Customcode Dispenser + * + * @var Dispenser + * @since 3.2.0 + */ + protected Dispenser $dispenser; + + /** + * Constructor + * + * @param Dispenser|null $dispenser The compiler customcode dispenser object. + * + * @since 3.2.0 + */ + public function __construct(?Dispenser $dispenser = null) + { + $this->dispenser = $dispenser ?: Compiler::_('Customcode.Dispenser'); + } + + /** + * Update field customcode + * + * @param int $id The field id + * @param object $field The field object + * @param string|null $singleViewName The view edit or single name + * @param string|null $listViewName The view list name + * + * @return void + * @since 3.2.0 + */ + public function update(int $id, object &$field, $singleViewName = null, $listViewName = null) + { + // check if we should load scripts for single view + if ($singleViewName && StringHelper::check($singleViewName) + && !isset($this->views[$singleViewName][$id])) + { + // add_javascript_view_footer + if ($field->add_javascript_view_footer == 1 + && StringHelper::check( + $field->javascript_view_footer + )) + { + $convert__ = true; + if (isset($field->javascript_view_footer_decoded) + && $field->javascript_view_footer_decoded) + { + $convert__ = false; + } + $this->dispenser->set( + $field->javascript_view_footer, + 'view_footer', + $singleViewName, + null, + array( + 'table' => 'field', + 'id' => (int) $id, + 'field' => 'javascript_view_footer', + 'type' => 'js', + 'prefix' => PHP_EOL), + $convert__, + $convert__, + true + ); + if (!isset($field->javascript_view_footer_decoded)) + { + $field->javascript_view_footer_decoded + = true; + } + + if (strpos((string) $field->javascript_view_footer, "token") !== false + || strpos((string) $field->javascript_view_footer, "task=ajax") !== false) + { + if (!isset($this->dispenser->hub['token'])) + { + $this->dispenser->hub['token'] = []; + } + if (!isset($this->dispenser->hub['token'][$singleViewName]) + || !$this->dispenser->hub['token'][$singleViewName]) + { + $this->dispenser->hub['token'][$singleViewName] + = true; + } + } + } + + // add_css_view + if ($field->add_css_view == 1) + { + $convert__ = true; + if (isset($field->css_view_decoded) + && $field->css_view_decoded) + { + $convert__ = false; + } + $this->dispenser->set( + $field->css_view, + 'css_view', + $singleViewName, + null, + array('prefix' => PHP_EOL), + $convert__, + $convert__, + true + ); + if (!isset($field->css_view_decoded)) + { + $field->css_view_decoded = true; + } + } + + // add this only once to single view. + $this->views[$singleViewName][$id] = true; + } + + // check if we should load scripts for list views + if ($listViewName && StringHelper::check($listViewName) + && !isset($this->views[$listViewName][$id])) + { + // add_javascript_views_footer + if ($field->add_javascript_views_footer == 1 + && StringHelper::check( + $field->javascript_views_footer + )) + { + $convert__ = true; + if (isset($field->javascript_views_footer_decoded) + && $field->javascript_views_footer_decoded) + { + $convert__ = false; + } + $this->dispenser->set( + $field->javascript_views_footer, + 'views_footer', + $singleViewName, + null, + array( + 'table' => 'field', + 'id' => (int) $id, + 'field' => 'javascript_views_footer', + 'type' => 'js', + 'prefix' => PHP_EOL), + $convert__, + $convert__, + true + ); + if (!isset($field->javascript_views_footer_decoded)) + { + $field->javascript_views_footer_decoded = true; + } + if (strpos((string) $field->javascript_views_footer, "token") !== false + || strpos((string) $field->javascript_views_footer, "task=ajax") !== false) + { + if (!isset($this->dispenser->hub['token'])) + { + $this->dispenser->hub['token'] = []; + } + if (!isset($this->dispenser->hub['token'][$listViewName]) + || !$this->dispenser->hub['token'][$listViewName]) + { + $this->dispenser->hub['token'][$listViewName] + = true; + } + } + } + + // add_css_views + if ($field->add_css_views == 1) + { + $convert__ = true; + if (isset($field->css_views_decoded) + && $field->css_views_decoded) + { + $convert__ = false; + } + $this->dispenser->set( + $field->css_views, + 'css_views', + $singleViewName, + null, + array('prefix' => PHP_EOL), + $convert__, + $convert__, + true + ); + if (!isset($field->css_views_decoded)) + { + $field->css_views_decoded = true; + } + } + + // add this only once to list view. + $this->views[$listViewName][$id] = true; + } + } diff --git a/src/a3c515f5-4adf-4eb3-b637-0a1add550da6/code.power b/src/a3c515f5-4adf-4eb3-b637-0a1add550da6/code.power new file mode 100644 index 0000000..46cd4c4 --- /dev/null +++ b/src/a3c515f5-4adf-4eb3-b637-0a1add550da6/code.power @@ -0,0 +1,9 @@ + /** + * Set a string as bsae64 (basic) + * + * @param string $script The code string + * + * @return string + * @since 3.2.0 + */ + public function set(string $script): string; \ No newline at end of file diff --git a/src/a68c010b-e92e-47d5-8a44-d23cfddeb6c6/code.power b/src/a68c010b-e92e-47d5-8a44-d23cfddeb6c6/code.power new file mode 100644 index 0000000..7446139 --- /dev/null +++ b/src/a68c010b-e92e-47d5-8a44-d23cfddeb6c6/code.power @@ -0,0 +1,63 @@ + /** + * Spacer bucket (to speed-up the build) + * + * @var array + * @since 3.2.0 + */ + private static array $bucket = []; + + /** + * The indentation string + * + * @var string + * @since 3.2.0 + */ + private static string $indent; + + /** + * Set the space + * + * @param int $nr The number of spaces + * + * @return string + * @since 3.2.0 + */ + public static function _(int $nr): string + { + // check if we already have the string + if (!isset(self::$bucket[$nr])) + { + // get the string + self::$bucket[$nr] = str_repeat(self::indent(), (int) $nr); + } + // return stored indentation + return self::$bucket[$nr]; + } + + /** + * Get the indentation string + * + * @return string + * @since 3.2.0 + */ + private static function indent(): string + { + if (empty(self::$indent)) + { + self::init(); + } + + return self::$indent; + } + + /** + * The constructor for indent + * + * @return void + * @since 3.2.0 + */ + private static function init() + { + // the default is TAB + self::$indent = Compiler::_('Config')->indentation_value; + } diff --git a/src/a6cdd935-c038-4a54-8446-54bed87f003c/code.power b/src/a6cdd935-c038-4a54-8446-54bed87f003c/code.power new file mode 100644 index 0000000..788041a --- /dev/null +++ b/src/a6cdd935-c038-4a54-8446-54bed87f003c/code.power @@ -0,0 +1,216 @@ + /** + * Set content + * + * @param string $key The main string key + * @param mixed $value The values to set + * @param bool $hash Add the hash around the key + * + * @return void + * @since 3.2.0 + */ + public function set(string $key, $value, bool $hash = true); + + /** + * Get content by key + * + * @param string $key The main string key + * + * @return mixed + * @since 3.2.0 + */ + public function get(string $key); + + /** + * Does key exist at all in any variation + * + * @param string $key The main string key + * + * @return bool + * @since 3.2.0 + */ + public function exist(string $key): bool; + + /** + * Add content + * + * @param string $key The main string key + * @param mixed $value The values to set + * @param bool $hash Add the hash around the key + * + * @return void + * @since 3.2.0 + */ + public function add(string $key, $value, bool $hash = true); + + /** + * Remove content + * + * @param string $key The main string key + * + * @return void + * @since 3.2.0 + */ + public function remove(string $key); + + /** + * Set content with [ [ [ ... ] ] ] hash + * + * @param string $key The main string key + * @param mixed $value The values to set + * + * @return void + * @since 3.2.0 + */ + public function set_(string $key, $value); + + /** + * Get content with [ [ [ ... ] ] ] hash + * + * @param string $key The main string key + * + * @return mixed + * @since 3.2.0 + */ + public function get_(string $key); + + /** + * Does key exist with [ [ [ ... ] ] ] hash + * + * @param string $key The main string key + * + * @return bool + * @since 3.2.0 + */ + public function exist_(string $key): bool; + + /** + * Add content with [ [ [ ... ] ] ] hash + * + * @param string $key The main string key + * @param mixed $value The values to set + * + * @return void + * @since 3.2.0 + */ + public function add_(string $key, $value); + + /** + * Remove content with [ [ [ ... ] ] ] hash + * + * @param string $key The main string key + * + * @return void + * @since 3.2.0 + */ + public function remove_(string $key); + + /** + * Set content with # # # hash + * + * @param string $key The main string key + * @param mixed $value The values to set + * + * @return void + * @since 3.2.0 + */ + public function set_h(string $key, $value); + + /** + * Get content with # # # hash + * + * @param string $key The main string key + * + * @return mixed + * @since 3.2.0 + */ + public function get_h(string $key); + + /** + * Does key exist with # # # hash + * + * @param string $key The main string key + * + * @return bool + * @since 3.2.0 + */ + public function exist_h(string $key): bool; + + /** + * Add content with # # # hash + * + * @param string $key The main string key + * @param mixed $value The values to set + * + * @return void + * @since 3.2.0 + */ + public function add_h(string $key, $value); + + /** + * Remove content with # # # hash + * + * @param string $key The main string key + * + * @return void + * @since 3.2.0 + */ + public function remove_h(string $key); + + /** + * Set a type of placeholder with set of values + * + * @param string $key The main string for placeholder key + * @param array $values The values to add + * + * @return void + * @since 3.2.0 + */ + public function setType(string $key, array $values); + + /** + * Remove a type of placeholder by main key + * + * @param string $key The main string for placeholder key + * + * @return void + * @since 3.2.0 + */ + public function clearType(string $key); + + /** + * Update the data with the placeholders + * + * @param string $data The actual data + * @param array $placeholder The placeholders + * @param int $action The action to use + * + * THE ACTION OPTIONS ARE + * 1 -> Just replace (default) + * 2 -> Check if data string has placeholders + * 3 -> Remove placeholders not in data string + * + * @return string + * @since 3.2.0 + */ + public function update(string $data, array $placeholder, int $action = 1): string; + + /** + * Update the data with the active placeholders + * + * @param string $data The actual data + * + * @return string + * @since 3.2.0 + */ + public function update_(string $data): string; + + /** + * return the placeholders for inserted and replaced code + * + * @param int $type The type of placement + * @param int|null $id The code id in the system + * + * @return array with start and end keys + * @since 3.2.0 + */ + public function keys(int $type, ?int $id = null): array; diff --git a/src/a6e1227c-1efe-407d-84ef-03c6989a6a88/code.power b/src/a6e1227c-1efe-407d-84ef-03c6989a6a88/code.power new file mode 100644 index 0000000..4be3abd --- /dev/null +++ b/src/a6e1227c-1efe-407d-84ef-03c6989a6a88/code.power @@ -0,0 +1,289 @@ + /** + * The compiler registry + * + * @var Registry + * @since 3.2.0 + */ + protected Registry $registry; + + /** + * Database object to query local DB + * + * @var \JDatabaseDriver + * @since 3.2.0 + **/ + protected \JDatabaseDriver $db; + + /** + * Constructor + * + * @param Registry|null $registry The compiler registry object. + * @param \JDatabaseDriver|null $db The database object. + + * @since 3.2.0 + */ + public function __construct(?Registry $registry = null, ?\JDatabaseDriver $db = null) + { + $this->registry = $registry ?: Compiler::_('Registry'); + $this->db = $db ?: Factory::getDbo(); + } + + /** + * Get SQL Dump + * + * @param array $tables The tables to use in build + * @param string $view The target view/table to dump in + * @param int $view_id The id of the target view + * + * @return string|null The data found with the alias + * @since 3.2.0 + */ + public function get(array $tables, string $view, int $view_id): ?string + { + // first build a query statement to get all the data (insure it must be added - check the tweaking) + if (ArrayHelper::check($tables) + && $this->registry-> // default is to add + get('builder.sql_tweak.' . (int) $view_id . '.add', true)) + { + $counter = 'a'; + + // Create a new query object. + $query = $this->db->getQuery(true); + + // switch to only trigger the run of the query if we have tables to query + $run_query = false; + foreach ($tables as $table) + { + if (isset($table['table'])) + { + if ($counter === 'a') + { + // the main table fields + if (strpos((string) $table['sourcemap'], PHP_EOL) !== false) + { + $fields = explode(PHP_EOL, (string) $table['sourcemap']); + if (ArrayHelper::check($fields)) + { + // reset array buckets + $sourceArray = []; + $targetArray = []; + foreach ($fields as $field) + { + if (strpos($field, "=>") !== false) + { + list($source, $target) = explode( + "=>", $field + ); + $sourceArray[] = $counter . '.' . trim( + $source + ); + $targetArray[] = trim($target); + } + } + if (ArrayHelper::check( + $sourceArray + ) + && ArrayHelper::check( + $targetArray + )) + { + // add to query + $query->select( + $this->db->quoteName( + $sourceArray, $targetArray + ) + ); + $query->from( + '#__' . $table['table'] . ' AS a' + ); + $run_query = true; + } + // we may need to filter the selection + if (($ids_ = $this->registry-> + get('builder.sql_tweak.' . (int) $view_id . '.where', null)) !== null) + { + // add to query the where filter + $query->where( + 'a.id IN (' . $ids_ . ')' + ); + } + } + } + } + else + { + // the other tables + if (strpos((string) $table['sourcemap'], PHP_EOL) !== false) + { + $fields = explode(PHP_EOL, (string) $table['sourcemap']); + if (ArrayHelper::check($fields)) + { + // reset array buckets + $sourceArray = []; + $targetArray = []; + foreach ($fields as $field) + { + if (strpos($field, "=>") !== false) + { + list($source, $target) = explode( + "=>", $field + ); + $sourceArray[] = $counter . '.' . trim( + $source + ); + $targetArray[] = trim($target); + } + if (strpos($field, "==") !== false) + { + list($aKey, $bKey) = explode( + "==", $field + ); + // add to query + $query->join( + 'LEFT', $this->db->quoteName( + '#__' . $table['table'], + $counter + ) . ' ON (' . $this->db->quoteName( + 'a.' . trim($aKey) + ) . ' = ' . $this->db->quoteName( + $counter . '.' . trim($bKey) + ) . ')' + ); + } + } + if (ArrayHelper::check( + $sourceArray + ) + && ArrayHelper::check( + $targetArray + )) + { + // add to query + $query->select( + $this->db->quoteName( + $sourceArray, $targetArray + ) + ); + } + } + } + } + $counter++; + } + else + { + // see where + // var_dump($view); + // jexit(); + } + } + + // check if we should run query + if ($run_query) + { + // now get the data + $this->db->setQuery($query); + $this->db->execute(); + if ($this->db->getNumRows()) + { + // get the data + $data = $this->db->loadObjectList(); + + // start building the MySql dump + $dump = "--"; + $dump .= PHP_EOL . "-- Dumping data for table `#__" + . Placefix::_("component") . "_" . $view + . "`"; + $dump .= PHP_EOL . "--"; + $dump .= PHP_EOL . PHP_EOL . "INSERT INTO `#__" . Placefix::_("component") . "_" . $view . "` ("; + foreach ($data as $line) + { + $comaSet = 0; + foreach ($line as $fieldName => $fieldValue) + { + if ($comaSet == 0) + { + $dump .= $this->db->quoteName($fieldName); + } + else + { + $dump .= ", " . $this->db->quoteName( + $fieldName + ); + } + $comaSet++; + } + break; + } + $dump .= ") VALUES"; + $coma = 0; + foreach ($data as $line) + { + if ($coma == 0) + { + $dump .= PHP_EOL . "("; + } + else + { + $dump .= "," . PHP_EOL . "("; + } + $comaSet = 0; + foreach ($line as $fieldName => $fieldValue) + { + if ($comaSet == 0) + { + $dump .= $this->escape($fieldValue); + } + else + { + $dump .= ", " . $this->escape( + $fieldValue + ); + } + $comaSet++; + } + $dump .= ")"; + $coma++; + } + $dump .= ";"; + + // return build dump query + return $dump; + } + } + } + + return null; + } + + /** + * Escape the values for a SQL dump + * + * @param string|array $value the value to escape + * + * @return string|array on success with escaped string + * @since 3.2.0 + */ + protected function escape($value) + { + // if array then return mapped + if (ArrayHelper::check($value)) + { + return array_map(__METHOD__, $value); + } + + // if string make sure it is correctly escaped + if (StringHelper::check($value) && !is_numeric($value)) + { + return $this->db->quote($value); + } + + // if empty value return place holder + if (empty($value)) + { + return "''"; + } + + // if not array or string then return number + return $value; + } diff --git a/src/a74ac3b7-bb79-4639-8f14-54a8021be68b/code.power b/src/a74ac3b7-bb79-4639-8f14-54a8021be68b/code.power new file mode 100644 index 0000000..6d96b0c --- /dev/null +++ b/src/a74ac3b7-bb79-4639-8f14-54a8021be68b/code.power @@ -0,0 +1,171 @@ + /** + * 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(CompilerCustomcode::class, 'Customcode') + ->share('Customcode', [$this, 'getCustomcode'], true); + + $container->alias(External::class, 'Customcode.External') + ->share('Customcode.External', [$this, 'getExternal'], true); + + $container->alias(Gui::class, 'Customcode.Gui') + ->share('Customcode.Gui', [$this, 'getGui'], true); + + $container->alias(Hash::class, 'Customcode.Hash') + ->share('Customcode.Hash', [$this, 'getHash'], true); + + $container->alias(LockBase::class, 'Customcode.LockBase') + ->share('Customcode.LockBase', [$this, 'getLockBase'], true); + + $container->alias(Dispenser::class, 'Customcode.Dispenser') + ->share('Customcode.Dispenser', [$this, 'getDispenser'], true); + + $container->alias(Paths::class, 'Customcode.Extractor.Paths') + ->share('Customcode.Extractor.Paths', [$this, 'getPaths'], true); + + $container->alias(Extractor::class, 'Customcode.Extractor') + ->share('Customcode.Extractor', [$this, 'getExtractor'], true); + } + + /** + * Get the Compiler Customcode + * + * @param Container $container The DI container. + * + * @return CustomcodeInterface + * @since 3.2.0 + */ + public function getCustomcode(Container $container): CustomcodeInterface + { + return new CompilerCustomcode( + $container->get('Config'), + $container->get('Placeholder'), + $container->get('Language.Extractor'), + $container->get('Customcode.External') + ); + } + + /** + * Get the Compiler Customcode External + * + * @param Container $container The DI container. + * + * @return External + * @since 3.2.0 + */ + public function getExternal(Container $container): External + { + return new External( + $container->get('Placeholder') + ); + } + + /** + * Get the Compiler Customcode Gui + * + * @param Container $container The DI container. + * + * @return Gui + * @since 3.2.0 + */ + public function getGui(Container $container): Gui + { + return new Gui( + $container->get('Config'), + $container->get('Placeholder.Reverse') + ); + } + + /** + * Get the Customcode Hash + * + * @param Container $container The DI container. + * + * @return Hash + * @since 3.2.0 + */ + public function getHash(Container $container): Hash + { + return new Hash( + $container->get('Placeholder') + ); + } + + /** + * Get the Customcode LockBase64 + * + * @param Container $container The DI container. + * + * @return LockBase + * @since 3.2.0 + */ + public function getLockBase(Container $container): LockBase + { + return new LockBase( + $container->get('Placeholder') + ); + } + + /** + * Get the Customcode Dispenser + * + * @param Container $container The DI container. + * + * @return Dispenser + * @since 3.2.0 + */ + public function getDispenser(Container $container): Dispenser + { + return new Dispenser( + $container->get('Placeholder'), + $container->get('Customcode'), + $container->get('Customcode.Gui'), + $container->get('Customcode.Hash'), + $container->get('Customcode.LockBase') + ); + } + + /** + * Get the Customcode Extractor Paths + * + * @param Container $container The DI container. + * + * @return Paths + * @since 3.2.0 + */ + public function getPaths(Container $container): Paths + { + return new Paths( + $container->get('Config'), + $container->get('Placeholder'), + $container->get('Component.Placeholder'), + $container->get('Customcode'), + $container->get('Language.Extractor') + ); + } + + /** + * Get the Customcode Extractor + * + * @param Container $container The DI container. + * + * @return Extractor + * @since 3.2.0 + */ + public function getExtractor(Container $container): Extractor + { + return new Extractor( + $container->get('Config'), + $container->get('Customcode.Gui'), + $container->get('Customcode.Extractor.Paths'), + $container->get('Placeholder.Reverse'), + $container->get('Component.Placeholder'), + $container->get('Utilities.Pathfix') + ); + } diff --git a/src/a8eb2fb1-88ed-4af8-842d-898eb915b588/code.power b/src/a8eb2fb1-88ed-4af8-842d-898eb915b588/code.power new file mode 100644 index 0000000..c709302 --- /dev/null +++ b/src/a8eb2fb1-88ed-4af8-842d-898eb915b588/code.power @@ -0,0 +1,143 @@ + /** + * Compiler Config + * + * @var Config + * @since 3.2.0 + */ + protected Config $config; + + /** + * The compiler registry + * + * @var Registry + * @since 3.2.0 + */ + protected Registry $registry; + + /** + * Compiler Language + * + * @var Language + * @since 3.2.0 + **/ + protected Language $language; + + /** + * Compiler Customcode + * + * @var Customcode + * @since 3.2.0 + */ + protected Customcode $customcode; + + /** + * Constructor + * + * @param Config|null $config The compiler config object. + * @param Registry|null $registry The compiler registry object. + * @param Language|null $language The compiler Language object. + * @param Customcode|null $customcode The compiler customcode object. + * + * @since 3.2.0 + */ + public function __construct(?Config $config = null, ?Registry $registry = null, + ?Language $language = null, ?Customcode $customcode = null) + { + $this->config = $config ?: Compiler::_('Config'); + $this->registry = $registry ?: Compiler::_('Registry'); + $this->language = $language ?: Compiler::_('Language'); + $this->customcode = $customcode ?: Compiler::_('Customcode'); + } + + /** + * Set the relations + * + * @param object $item The view data + * + * @return void + * @since 3.2.0 + */ + public function set(object &$item) + { + $item->addrelations = (isset($item->addrelations) + && JsonHelper::check($item->addrelations)) + ? json_decode((string) $item->addrelations, true) : null; + + if (ArrayHelper::check($item->addrelations)) + { + foreach ($item->addrelations as $nr => $relationsValue) + { + // only add if list view field is selected and joined fields are set + if (isset($relationsValue['listfield']) + && is_numeric( + $relationsValue['listfield'] + ) + && $relationsValue['listfield'] > 0 + && isset($relationsValue['area']) + && is_numeric($relationsValue['area']) + && $relationsValue['area'] > 0) + { + // do a dynamic update on the set values + if (isset($relationsValue['set']) + && StringHelper::check( + $relationsValue['set'] + )) + { + $relationsValue['set'] = $this->customcode->update( + $relationsValue['set'] + ); + } + + // load the field relations + $this->registry->set('builder.field_relations.' + . $item->name_list_code . '.' . (int) $relationsValue['listfield'] + . '.' . (int) $relationsValue['area'], $relationsValue); + + // load the list joints + if (isset($relationsValue['joinfields']) + && ArrayHelper::check( + $relationsValue['joinfields'] + )) + { + foreach ($relationsValue['joinfields'] as $join) + { + $this->registry->set('builder.list_join.' . $item->name_list_code . '.' . (int) $join, (int) $join); + } + } + + // set header over-ride + if (isset($relationsValue['column_name']) + && StringHelper::check( + $relationsValue['column_name'] + )) + { + $check_column_name = trim( + strtolower((string) $relationsValue['column_name']) + ); + + // confirm it should really make the over ride + if ('default' !== $check_column_name) + { + $column_name_lang = $this->config->lang_prefix . '_' + . StringHelper::safe( + $item->name_list_code, 'U' + ) . '_' . StringHelper::safe( + $relationsValue['column_name'], 'U' + ); + $this->language->set( + 'admin', $column_name_lang, + $relationsValue['column_name'] + ); + $this->registry->set('builder.list_head_override.' . + $item->name_list_code . '.' . (int) $relationsValue['listfield'], + $column_name_lang + ); + + } + } + } + } + } + + unset($item->addrelations); + } diff --git a/src/a900b836-f2eb-4f13-8f28-b7cac839c7ff/code.power b/src/a900b836-f2eb-4f13-8f28-b7cac839c7ff/code.power new file mode 100644 index 0000000..606d8ac --- /dev/null +++ b/src/a900b836-f2eb-4f13-8f28-b7cac839c7ff/code.power @@ -0,0 +1,581 @@ + /** + * Compiler Joomla Plugin Data Class + * + * @var Plugin + * @since 3.2.0 + */ + protected Plugin $plugin; + + /** + * Compiler Component + * + * @var Component + * @since 3.2.0 + **/ + protected Component $component; + + /** + * Compiler Config + * + * @var Config + * @since 3.2.0 + */ + protected Config $config; + + /** + * The compiler registry + * + * @var Registry + * @since 3.2.0 + */ + protected Registry $registry; + + /** + * Compiler Customcode Dispenser + * + * @var Dispenser + * @since 3.2.0 + */ + protected Dispenser $dispenser; + + /** + * Compiler Event + * + * @var EventInterface + * @since 3.2.0 + */ + protected EventInterface $event; + + /** + * Compiler Counter + * + * @var Counter + * @since 3.2.0 + */ + protected Counter $counter; + + /** + * Compiler Utilities Folder + * + * @var Folder + * @since 3.2.0 + */ + protected Folder $folder; + + /** + * Compiler Utilities File + * + * @var File + * @since 3.2.0 + */ + protected File $file; + + /** + * Compiler Utilities Files + * + * @var Files + * @since 3.2.0 + */ + protected Files $files; + + /** + * Constructor + * + * @param Plugin|null $plugin The compiler Joomla plugin data object. + * @param Component|null $component The component class. + * @param Config|null $config The compiler config object. + * @param Registry|null $registry The compiler registry object. + * @param Dispenser|null $dispenser The compiler customcode dispenser object. + * @param EventInterface|null $event The compiler event api object. + * @param Counter|null $counter The compiler counter object. + * @param Folder|null $folder The compiler folder object. + * @param File|null $file The compiler file object. + * @param Files|null $files The compiler files object. + * + * @since 3.2.0 + */ + public function __construct(?Plugin $plugin = null, ?Component $component = null, + ?Config $config = null, ?Registry $registry = null, + ?Dispenser $dispenser = null, ?EventInterface $event = null, + ?Counter $counter = null, ?Folder $folder = null, + ?File $file = null, ?Files $files = null) + { + $this->plugin = $plugin ?: Compiler::_('Joomlaplugin.Data'); + $this->component = $component ?: Compiler::_('Component'); + $this->config = $config ?: Compiler::_('Config'); + $this->registry = $registry ?: Compiler::_('Registry'); + $this->dispenser = $dispenser ?: Compiler::_('Customcode.Dispenser'); + $this->event = $event ?: Compiler::_('Event'); + $this->counter = $counter ?: Compiler::_('Utilities.Counter'); + $this->folder = $folder ?: Compiler::_('Utilities.Folder'); + $this->file = $file ?: Compiler::_('Utilities.File'); + $this->files = $files ?: Compiler::_('Utilities.Files'); + } + + /** + * Build the Plugins files, folders, url's and config + * + * @return void + * @since 3.2.0 + */ + public function build() + { + if ($this->plugin->exists()) + { + // for plugin event TODO change event api signatures + $component_context = $this->config->component_context; + $plugins = $this->plugin->get(); + // Trigger Event: jcb_ce_onBeforeSetPlugins + $this->event->trigger( + 'jcb_ce_onBeforeBuildPlugins', + array(&$component_context, &$plugins) + ); + foreach ($plugins as $plugin) + { + if (ObjectHelper::check($plugin) + && isset($plugin->folder_name) + && StringHelper::check( + $plugin->folder_name + )) + { + // plugin path + $plugin->folder_path = $this->config->get('compiler_path', JPATH_COMPONENT_ADMINISTRATOR . '/compiler') . '/' + . $plugin->folder_name; + + // set the plugin paths + $this->registry->set('dynamic_paths.' . $plugin->key, $plugin->folder_path); + + // make sure there is no old build + $this->folder->remove($plugin->folder_path); + + // creat the main component folder + $this->folder->create($plugin->folder_path); + + // set main class file + $fileDetails = array('path' => $plugin->folder_path . '/' + . $plugin->file_name . '.php', + 'name' => $plugin->file_name . '.php', + 'zip' => $plugin->file_name . '.php'); + $this->file->write( + $fileDetails['path'], + 'files->appendArray($plugin->key, $fileDetails); + + // count the file created + $this->counter->file++; + + // set main xml file + $fileDetails = array('path' => $plugin->folder_path . '/' + . $plugin->file_name . '.xml', + 'name' => $plugin->file_name . '.xml', + 'zip' => $plugin->file_name . '.xml'); + $this->file->write( + $fileDetails['path'], + $this->getXML($plugin) + ); + $this->files->appendArray($plugin->key, $fileDetails); + + // count the file created + $this->counter->file++; + + // set install script if needed + if ($plugin->add_install_script) + { + $fileDetails = [ + 'path' => $plugin->folder_path . '/script.php', + 'name' => 'script.php', + 'zip' => 'script.php' + ]; + $this->file->write( + $fileDetails['path'], + 'files->appendArray($plugin->key, $fileDetails); + + // count the file created + $this->counter->file++; + } + + // set readme if found + if ($plugin->addreadme) + { + $fileDetails = [ + 'path' => $plugin->folder_path . '/README.md', + 'name' => 'README.md', + 'zip' => 'README.md' + ]; + $this->file->write($fileDetails['path'], $plugin->readme); + $this->files->appendArray($plugin->key, $fileDetails); + + // count the file created + $this->counter->file++; + } + + // set fields & rules folders if needed + if (isset($plugin->fields_rules_paths) + && $plugin->fields_rules_paths == 2) + { + // create fields folder + $this->folder->create($plugin->folder_path . '/fields'); + + // create rules folder + $this->folder->create($plugin->folder_path . '/rules'); + } + + // set forms folder if needed + if (isset($plugin->form_files) + && ArrayHelper::check( + $plugin->form_files + )) + { + // create forms folder + $this->folder->create($plugin->folder_path . '/forms'); + + // set the template files + foreach ($plugin->form_files as $file => $fields) + { + // set file details + $fileDetails = [ + 'path' => $plugin->folder_path . '/forms/' . $file . '.xml', + 'name' => $file . '.xml', + 'zip' => 'forms/' . $file . '.xml' + ]; + + // build basic XML + $xml = ''; + $xml .= PHP_EOL . ''; + + // search if we must add the component path + $add_component_path = false; + foreach ($fields as $field_name => $fieldsets) + { + if (!$add_component_path) + { + foreach ($fieldsets as $fieldset => $field) + { + if (!$add_component_path + && isset( + $plugin->fieldsets_paths[$file + . $field_name . $fieldset] + ) + && $plugin->fieldsets_paths[$file + . $field_name . $fieldset] == 1) + { + $add_component_path = true; + } + } + } + } + + // only add if part of the component field types path is required + if ($add_component_path) + { + $xml .= PHP_EOL . ''; + } + else + { + $xml .= PHP_EOL . '
'; + } + + // add the fields + foreach ($fields as $field_name => $fieldsets) + { + // check if we have an double fields naming set + $field_name_inner = ''; + $field_name_outer = $field_name; + if (strpos((string) $field_name, '.') !== false) + { + $field_names = explode('.', (string) $field_name); + if (count((array) $field_names) == 2) + { + $field_name_outer = $field_names[0]; + $field_name_inner = $field_names[1]; + } + } + $xml .= PHP_EOL . Indent::_(1) + . ''; + foreach ($fieldsets as $fieldset => $field) + { + // default to the field set name + $label = $fieldset; + if (isset($plugin->fieldsets_label[$file . $field_name . $fieldset])) + { + $label = $plugin->fieldsets_label[$file . $field_name . $fieldset]; + } + + // add path to plugin rules and custom fields + if (isset($plugin->fieldsets_paths[$file . $field_name . $fieldset]) + && ($plugin->fieldsets_paths[$file . $field_name . $fieldset] == 2 + || $plugin->fieldsets_paths[$file . $field_name . $fieldset] == 3)) + { + if (!isset($plugin->add_rule_path[$file . $field_name . $fieldset])) + { + $plugin->add_rule_path[$file . $field_name . $fieldset] = + '/plugins/' . strtolower((string) $plugin->group + ) . '/' . strtolower((string) $plugin->code_name) + . '/rules'; + } + + if (!isset($plugin->add_field_path[$file . $field_name . $fieldset])) + { + $plugin->add_field_path[$file . $field_name . $fieldset] = + '/plugins/' . strtolower((string) $plugin->group + ) . '/' . strtolower((string) $plugin->code_name) + . '/fields'; + } + } + + // add path to plugin rules and custom fields + if (isset($plugin->add_rule_path[$file . $field_name . $fieldset]) + || isset($plugin->add_field_path[$file . $field_name . $fieldset])) + { + $xml .= PHP_EOL . Indent::_(1) . ''; + + $xml .= PHP_EOL . Indent::_(1) . '
add_rule_path[$file . $field_name . $fieldset])) + { + $xml .= PHP_EOL . Indent::_(2) + . 'addrulepath="' . $plugin->add_rule_path[$file . $field_name . $fieldset] . '"'; + } + + if (isset($plugin->add_field_path[$file . $field_name . $fieldset])) + { + $xml .= PHP_EOL . Indent::_(2) + . 'addfieldpath="' . $plugin->add_field_path[$file . $field_name . $fieldset] . '"'; + } + + $xml .= PHP_EOL . Indent::_(1) . '>'; + } + else + { + $xml .= PHP_EOL . Indent::_(1) . '
'; + } + + // check if we have an inner field set + if (StringHelper::check( + $field_name_inner + )) + { + $xml .= PHP_EOL . Indent::_(1) + . ''; + } + + // add the placeholder of the fields + $xml .= Placefix::_h('FIELDSET_' . $file + . $field_name . $fieldset ); + + // check if we have an inner field set + if (StringHelper::check( + $field_name_inner + )) + { + $xml .= PHP_EOL . Indent::_(1) + . ''; + } + $xml .= PHP_EOL . Indent::_(1) + . '
'; + } + $xml .= PHP_EOL . Indent::_(1) . ''; + } + $xml .= PHP_EOL . ''; + + // add xml to file + $this->file->write($fileDetails['path'], $xml); + $this->files->appendArray($plugin->key, $fileDetails); + + // count the file created + $this->counter->file++; + } + } + + // set SQL stuff if needed + if ($plugin->add_sql || $plugin->add_sql_uninstall) + { + // create SQL folder + $this->folder->create($plugin->folder_path . '/sql'); + + // create mysql folder + $this->folder->create( + $plugin->folder_path . '/sql/mysql' + ); + + // now set the install file + if ($plugin->add_sql) + { + $this->file->write( + $plugin->folder_path . '/sql/mysql/install.sql', + $plugin->sql + ); + + // count the file created + $this->counter->file++; + } + + // now set the uninstall file + if ($plugin->add_sql_uninstall) + { + $this->file->write( + $plugin->folder_path + . '/sql/mysql/uninstall.sql', + $plugin->sql_uninstall + ); + + // count the file created + $this->counter->file++; + } + } + + // creat the language folder path + $this->folder->create($plugin->folder_path . '/language'); + + // also creat the lang tag folder path + $this->folder->create( + $plugin->folder_path . '/language/' . $this->config->get('lang_tag', 'en-GB') + ); + + // check if this lib has files + if (isset($plugin->files) + && ArrayHelper::check($plugin->files)) + { + // add to component files + foreach ($plugin->files as $file) + { + // set the path finder + $file['target_type'] = $plugin->target_type; + $file['target_id'] = $plugin->id; + $this->component->appendArray('files', $file); + } + } + + // check if this lib has folders + if (isset($plugin->folders) + && ArrayHelper::check($plugin->folders)) + { + // add to component folders + foreach ($plugin->folders as $folder) + { + // set the path finder + $folder['target_type'] = $plugin->target_type; + $folder['target_id'] = $plugin->id; + $this->component->appendArray('folders', $folder); + } + } + + // check if this plugin has urls + if (isset($plugin->urls) + && ArrayHelper::check($plugin->urls)) + { + // add to component urls + foreach ($plugin->urls as $n => &$url) + { + // should we add the local folder + if (isset($url['type']) && $url['type'] > 1 + && isset($url['url']) + && StringHelper::check( + $url['url'] + )) + { + // set file name + $fileName = basename((string) $url['url']); + + // get the file contents + $data = FileHelper::getContent( + $url['url'] + ); + + // build sub path + if (strpos($fileName, '.js') !== false) + { + $path = '/js'; + } + elseif (strpos($fileName, '.css') !== false) + { + $path = '/css'; + } + else + { + $path = ''; + } + + // create sub media media folder path if not set + $this->folder->create( + $plugin->folder_path . $path + ); + + // set the path to plugin file + $url['path'] = $plugin->folder_path . $path + . '/' . $fileName; // we need this for later + + // write data to path + $this->file->write($url['path'], $data); + + // count the file created + $this->counter->file++; + } + } + } + } + } + } + } + + /** + * get the plugin xml template + * + * @param object $module The plugin object + * + * @return string + * @since 3.2.0 + */ + protected function getXML(object &$plugin): string + { + $xml = ''; + $xml .= PHP_EOL . ''; + $xml .= PHP_EOL . Indent::_(1) . '' . $plugin->lang_prefix + . ''; + $xml .= PHP_EOL . Indent::_(1) . '' . Placefix::_h('BUILDDATE') . ''; + $xml .= PHP_EOL . Indent::_(1) . '' . Placefix::_h('AUTHOR') . ''; + $xml .= PHP_EOL . Indent::_(1) . '' . Placefix::_h('AUTHOREMAIL') . ''; + $xml .= PHP_EOL . Indent::_(1) . '' . Placefix::_h('AUTHORWEBSITE') . ''; + $xml .= PHP_EOL . Indent::_(1) . '' . Placefix::_h('COPYRIGHT') . ''; + $xml .= PHP_EOL . Indent::_(1) . '' . Placefix::_h('LICENSE') . ''; + $xml .= PHP_EOL . Indent::_(1) . '' . $plugin->plugin_version + . ''; + $xml .= PHP_EOL . Indent::_(1) . '' . $plugin->lang_prefix + . '_XML_DESCRIPTION'; + $xml .= Placefix::_h('MAINXML'); + $xml .= PHP_EOL . ''; + + return $xml; + } diff --git a/src/ad12ca1c-d3ce-4e7f-88c5-c6c92bdedc48/README.md b/src/ad12ca1c-d3ce-4e7f-88c5-c6c92bdedc48/README.md index 077ff53..f17b3ba 100644 --- a/src/ad12ca1c-d3ce-4e7f-88c5-c6c92bdedc48/README.md +++ b/src/ad12ca1c-d3ce-4e7f-88c5-c6c92bdedc48/README.md @@ -11,32 +11,53 @@ ```uml @startuml interface InsertInterface #Lavender { - + rows(array $data, string $table) : bool - + items(array $data, array $columns, ...) : bool + + defaults(bool $trigger = true) : void + + rows(array $data, string $table, ...) : bool + + items(array $data, string $table, ...) : bool + row(array $data, string $table) : bool + + item(object $data, string $table) : bool } -note right of InsertInterface::rows - Set rows to the database +note right of InsertInterface::defaults + Switch to prevent/allow defaults from being added. since: 3.2.0 - return: bool + return: void end note -note right of InsertInterface::items - Set items to the database +note right of InsertInterface::rows + Insert rows to the database (with remapping and filtering columns option) since: 3.2.0 return: bool arguments: array $data - array $columns string $table + array $columns = [] +end note + +note right of InsertInterface::items + Insert items to the database (with remapping and filtering columns option) + + since: 3.2.0 + return: bool + + arguments: + array $data + string $table + array $columns = [] end note note right of InsertInterface::row - Set row to the database + Insert row to the database + + since: 3.2.0 + return: bool +end note + +note right of InsertInterface::item + Insert item to the database since: 3.2.0 return: bool diff --git a/src/ad12ca1c-d3ce-4e7f-88c5-c6c92bdedc48/code.php b/src/ad12ca1c-d3ce-4e7f-88c5-c6c92bdedc48/code.php index 59481ae..d00fc58 100644 --- a/src/ad12ca1c-d3ce-4e7f-88c5-c6c92bdedc48/code.php +++ b/src/ad12ca1c-d3ce-4e7f-88c5-c6c92bdedc48/code.php @@ -20,30 +20,41 @@ namespace VDM\Joomla\Componentbuilder\Interfaces; interface InsertInterface { /** - * Set rows to the database + * Switch to prevent/allow defaults from being added. + * + * @param bool $trigger toggle the defaults + * + * @return void + * @since 3.2.0 + **/ + public function defaults(bool $trigger = true); + + /** + * Insert rows to the database (with remapping and filtering columns option) * * @param array $data Dataset to store in database [array of arrays (key => value)] * @param string $table The table where the data is being added + * @param array $columns Data columns for remapping and filtering * * @return bool * @since 3.2.0 **/ - public function rows(array $data, string $table): bool; + public function rows(array $data, string $table, array $columns = []): bool; /** - * Set items to the database + * Insert items to the database (with remapping and filtering columns option) * * @param array $data Data to store in database (array of objects) - * @param array $columns Data columns - * @param string $table The table where the data is being added + * @param string $table The table where the data is being added + * @param array $columns Data columns for remapping and filtering * * @return bool * @since 3.2.0 **/ - public function items(array $data, array $columns, string $table): bool; + public function items(array $data, string $table, array $columns = []): bool; /** - * Set row to the database + * Insert row to the database * * @param array $data Dataset to store in database (key => value) * @param string $table The table where the data is being added @@ -52,6 +63,17 @@ interface InsertInterface * @since 3.2.0 **/ public function row(array $data, string $table): bool; + + /** + * Insert item to the database + * + * @param object $data Dataset to store in database (key => value) + * @param string $table The table where the data is being added + * + * @return bool + * @since 3.2.0 + **/ + public function item(object $data, string $table): bool; } diff --git a/src/ad12ca1c-d3ce-4e7f-88c5-c6c92bdedc48/code.power b/src/ad12ca1c-d3ce-4e7f-88c5-c6c92bdedc48/code.power new file mode 100644 index 0000000..8d6c7c5 --- /dev/null +++ b/src/ad12ca1c-d3ce-4e7f-88c5-c6c92bdedc48/code.power @@ -0,0 +1,55 @@ + /** + * Switch to prevent/allow defaults from being added. + * + * @param bool $trigger toggle the defaults + * + * @return void + * @since 3.2.0 + **/ + public function defaults(bool $trigger = true); + + /** + * Insert rows to the database (with remapping and filtering columns option) + * + * @param array $data Dataset to store in database [array of arrays (key => value)] + * @param string $table The table where the data is being added + * @param array $columns Data columns for remapping and filtering + * + * @return bool + * @since 3.2.0 + **/ + public function rows(array $data, string $table, array $columns = []): bool; + + /** + * Insert items to the database (with remapping and filtering columns option) + * + * @param array $data Data to store in database (array of objects) + * @param string $table The table where the data is being added + * @param array $columns Data columns for remapping and filtering + * + * @return bool + * @since 3.2.0 + **/ + public function items(array $data, string $table, array $columns = []): bool; + + /** + * Insert row to the database + * + * @param array $data Dataset to store in database (key => value) + * @param string $table The table where the data is being added + * + * @return bool + * @since 3.2.0 + **/ + public function row(array $data, string $table): bool; + + /** + * Insert item to the database + * + * @param object $data Dataset to store in database (key => value) + * @param string $table The table where the data is being added + * + * @return bool + * @since 3.2.0 + **/ + public function item(object $data, string $table): bool; diff --git a/src/adfbe68a-6d22-43e5-aee8-2787e8c47e75/code.power b/src/adfbe68a-6d22-43e5-aee8-2787e8c47e75/code.power new file mode 100644 index 0000000..8702c06 --- /dev/null +++ b/src/adfbe68a-6d22-43e5-aee8-2787e8c47e75/code.power @@ -0,0 +1,38 @@ + /** + * Model the key + * + * @param string $key The key to model + * + * @return string + * @since 3.2.0 + */ + protected function key(string $key): string + { + return Placefix::_h($key); + } + + /** + * Model the first key + * + * @param string $key The first key to model + * + * @return string + * @since 3.2.0 + */ + protected function firstKey(string $key): string + { + return $key; + } + + /** + * Model the second key + * + * @param string $key The second key to model + * + * @return string + * @since 3.2.0 + */ + protected function secondKey(string $key): string + { + return Placefix::_h($key); + } \ No newline at end of file diff --git a/src/ae1fa148-91be-4f80-89a9-69d91ba9d575/code.power b/src/ae1fa148-91be-4f80-89a9-69d91ba9d575/code.power new file mode 100644 index 0000000..c144ff2 --- /dev/null +++ b/src/ae1fa148-91be-4f80-89a9-69d91ba9d575/code.power @@ -0,0 +1,46 @@ + /** + * The compiler registry + * + * @var Registry + * @since 3.2.0 + */ + protected Registry $registry; + + /** + * Constructor + * + * @param Registry|null $registry The compiler registry object. + * + * @since 3.2.0 + */ + public function __construct(?Registry $registry = null) + { + $this->registry = $registry ?: Compiler::_('Registry'); + } + + /** + * Set the linked views + * + * @param object $item The view data + * + * @return void + * @since 3.2.0 + */ + public function set(object &$item) + { + $item->addlinked_views = (isset($item->addlinked_views) + && JsonHelper::check($item->addlinked_views)) + ? json_decode((string) $item->addlinked_views, true) : null; + + if (ArrayHelper::check($item->addlinked_views)) + { + // setup linked views to global data sets + $this->registry->set('builder.linked_admin_views.' . $item->name_single_code, + array_values( + $item->addlinked_views + ) + ); + } + + unset($item->addlinked_views); + } diff --git a/src/aecc17ba-0b0f-4e5c-ae43-71be063a3dcb/code.power b/src/aecc17ba-0b0f-4e5c-ae43-71be063a3dcb/code.power new file mode 100644 index 0000000..a8991d6 --- /dev/null +++ b/src/aecc17ba-0b0f-4e5c-ae43-71be063a3dcb/code.power @@ -0,0 +1,110 @@ + /** + * Placeholders + * + * @var array + * @since 3.2.0 + **/ + protected $placeholders = null; + + /** + * Compiler Config + * + * @var Config + * @since 3.2.0 + **/ + protected $config; + + /** + * Database object to query local DB + * + * @var \JDatabaseDriver + * @since 3.2.0 + **/ + protected $db; + + /** + * Constructor. + * + * @param Config $config The compiler config object. + * @param \JDatabaseDriver $db The Database Driver object. + * + * @since 3.2.0 + **/ + public function __construct(?Config $config = null, ?\JDatabaseDriver $db = null) + { + $this->config = $config ?: Compiler::_('Config'); + $this->db = $db ?: Factory::getDbo(); + } + + /** + * get all System Placeholders + * + * @return array The global placeholders + * + * @since 3.2.0 + */ + public function get(): array + { + // set only once + if (is_array($this->placeholders)) + { + return $this->placeholders; + } + + // load the config + $config = $this->config; + // load the db + $db = $this->db; + // reset bucket + $bucket = []; + // Create a new query object. + $query = $db->getQuery(true); + $query->select($db->quoteName(array('a.target', 'a.value'))); + // from these tables + $query->from('#__componentbuilder_placeholder AS a'); + // Reset the query using our newly populated query object. + $db->setQuery($query); + + // Load the items + $db->execute(); + if ($db->getNumRows()) + { + $bucket = $db->loadAssocList('target', 'value'); + // open all the code + foreach ($bucket as $key => &$code) + { + $code = base64_decode((string) $code); + } + } + + // set component place holders + $bucket[Placefix::_h('component')] = $config->component_code_name; + $bucket[Placefix::_h('Component')] = StringHelper::safe($config->component_code_name, 'F'); + $bucket[Placefix::_h('COMPONENT')] = StringHelper::safe($config->component_code_name, 'U'); + $bucket[Placefix::_('component')] = $bucket[Placefix::_h('component')]; + $bucket[Placefix::_('Component')] = $bucket[Placefix::_h('Component')]; + $bucket[Placefix::_('COMPONENT')] = $bucket[Placefix::_h('COMPONENT')]; + $bucket[Placefix::_h('LANG_PREFIX')] = $config->lang_prefix; + $bucket[Placefix::_('LANG_PREFIX')] = $bucket[Placefix::_h('LANG_PREFIX')]; + + // get the current components overrides + if (($_placeholders = GetHelper::var( + 'component_placeholders', $config->component_id, + 'joomla_component', 'addplaceholders' + )) !== false + && JsonHelper::check($_placeholders)) + { + $_placeholders = json_decode((string) $_placeholders, true); + if (ArrayHelper::check($_placeholders)) + { + foreach ($_placeholders as $row) + { + $bucket[$row['target']] = $row['value']; + } + } + } + + $this->placeholders = $bucket; + + return $bucket; + } diff --git a/src/af5beb21-214a-44f6-9090-7ea24c22e649/code.power b/src/af5beb21-214a-44f6-9090-7ea24c22e649/code.power new file mode 100644 index 0000000..6c79a8b --- /dev/null +++ b/src/af5beb21-214a-44f6-9090-7ea24c22e649/code.power @@ -0,0 +1,45 @@ + /** + * Set whmcs links if needed + * + * @param object $item The extension data + * + * @return void + * @since 3.2.0 + */ + public function set(object &$item) + { + if (1 == $item->add_license + && (!isset($item->whmcs_buy_link) + || !StringHelper::check( + $item->whmcs_buy_link + ))) + { + // update with the whmcs url + if (isset($item->whmcs_url) + && StringHelper::check($item->whmcs_url)) + { + $item->whmcs_buy_link = $item->whmcs_url; + } + // use the company website + elseif (isset($item->website) + && StringHelper::check($item->website)) + { + $item->whmcs_buy_link = $item->website; + $item->whmcs_url = rtrim((string) $item->website, '/') + . '/whmcs'; + } + // none set + else + { + $item->whmcs_buy_link = '#'; + $item->whmcs_url = '#'; + } + } + // since the license details are not set clear + elseif (0 == $item->add_license) + { + $item->whmcs_key = ''; + $item->whmcs_buy_link = ''; + $item->whmcs_url = ''; + } + } diff --git a/src/b69a23db-0a62-4840-a9c5-b2d8d63ecc6c/code.power b/src/b69a23db-0a62-4840-a9c5-b2d8d63ecc6c/code.power new file mode 100644 index 0000000..c2f0b4b --- /dev/null +++ b/src/b69a23db-0a62-4840-a9c5-b2d8d63ecc6c/code.power @@ -0,0 +1,319 @@ + /** + * Compiler Config + * + * @var Config + * @since 3.2.0 + */ + protected Config $config; + + /** + * The compiler registry + * + * @var Registry + * @since 3.2.0 + */ + protected Registry $registry; + + /** + * Compiler Component Joomla Version Settings + * + * @var Settings + * @since 3.2.0 + */ + protected Settings $settings; + + /** + * Compiler Component + * + * @var Component + * @since 3.2.0 + **/ + protected Component $component; + + /** + * Compiler Model Createdate + * + * @var Createdate + * @since 3.2.0 + **/ + protected Createdate $createdate; + + /** + * Compiler Model Modifieddate + * + * @var Modifieddate + * @since 3.2.0 + **/ + protected Modifieddate $modifieddate; + + /** + * Compiler Utility to Build Structure + * + * @var Structure + * @since 3.2.0 + **/ + protected Structure $structure; + + /** + * Constructor + * + * @param Config|null $config The compiler config object. + * @param Registry|null $registry The compiler registry object. + * @param Settings|null $settings The compiler component Joomla version settings object. + * @param Component|null $component The component class. + * @param Createdate|null $createdate The compiler model to get create date class. + * @param Modifieddate|null $modifieddate The compiler model to get modified date class. + * @param Structure|null $structure The compiler structure to build dynamic folder and files class. + * + * @since 3.2.0 + */ + public function __construct(?Config $config = null, ?Registry $registry = null, + ?Settings $settings = null, ?Component $component = null, + ?Createdate $createdate = null, ?Modifieddate $modifieddate = null, + ?Structure $structure = null) + { + $this->config = $config ?: Compiler::_('Config'); + $this->registry = $registry ?: Compiler::_('Registry'); + $this->settings = $settings ?: Compiler::_('Component.Settings'); + $this->component = $component ?: Compiler::_('Component'); + $this->createdate = $createdate ?: Compiler::_('Model.Createdate'); + $this->modifieddate = $modifieddate ?: Compiler::_('Model.Modifieddate'); + $this->structure = $structure ?: Compiler::_('Utilities.Structure'); + } + + /** + * Build the Multiple Files & Folders + * + * @return bool + * @since 3.2.0 + */ + public function build(): bool + { + $success = false; + + if ($this->settings->exists()) + { + $success = $this->admin(); + $success = $this->site() || $success; + $success = $this->custom() || $success; + } + + return $success; + } + + /** + * Build the Dynamic Admin Files & Folders + * + * @return bool + * @since 3.2.0 + */ + protected function admin(): bool + { + if (!$this->component->isArray('admin_views')) + { + return false; + } + + // check if we have a dynamic dashboard + if (!$this->registry->get('build.dashboard')) + { + // setup the default dashboard + $target = ['admin' => $this->component->get('name_code')]; + $this->structure->build($target, 'dashboard'); + } + + $config = []; + $checkin = false; + + foreach ($this->component->get('admin_views') as $view) + { + if (!$this->isValidAdminView($view, $config)) + { + continue; + } + + $this->buildAdminView($view, $config); + + // quick set of checkin once + if (!$checkin && isset($view['checkin']) && $view['checkin'] == 1) + { + // switch to add checking to config + $checkin = true; + $this->config->set('add_checkin', $checkin); + } + } + + return true; + } + + /** + * Build the Dynamic Site Files & Folders + * + * @return bool + * @since 3.2.0 + */ + protected function site(): bool + { + if (!$this->component->isArray('site_views')) + { + return false; + } + + $config = []; + + foreach ($this->component->get('site_views') as $view) + { + if (!$this->isValidView($view, $config)) + { + continue; + } + + $this->buildView($view, $config, 'site'); + } + + return true; + } + + /** + * Build the Dynamic Custom Admin Files & Folders + * + * @return bool + * @since 3.2.0 + */ + protected function custom(): bool + { + if (!$this->component->isArray('custom_admin_views')) + { + return false; + } + + $config = []; + + foreach ($this->component->get('custom_admin_views') as $view) + { + if (!$this->isValidView($view, $config)) + { + continue; + } + + $this->buildView($view, $config, 'custom_admin'); + } + + return true; + } + + /** + * Check if the view is a valid view + * + * @param array $view + * @param array $config + * + * @return bool + * @since 3.2.0 + */ + private function isValidAdminView(array $view, array &$config): bool + { + if (!isset($view['settings']) || !ObjectHelper::check($view['settings']) + || ((!isset($view['settings']->name_list) || $view['settings']->name_list == 'null') + && (!isset($view['settings']->name_single) || $view['settings']->name_single == 'null'))) + { + return false; + } + + $created = $this->createdate->get($view); + $modified = $this->modifieddate->get($view); + + $config = [ + Placefix::_h('CREATIONDATE') => $created, + Placefix::_h('BUILDDATE') => $modified, + Placefix::_h('VERSION') => $view['settings']->version + ]; + + return true; + } + + /** + * Check if the view is a valid view + * + * @param array $view + * @param array $config + * + * @return bool + * @since 3.2.0 + */ + private function isValidView(array $view, array &$config): bool + { + if (!isset($view['settings']) || !ObjectHelper::check($view['settings']) + || !isset($view['settings']->main_get) + || !ObjectHelper::check($view['settings']->main_get) + || !isset($view['settings']->main_get->gettype) + || ($view['settings']->main_get->gettype != 1 && $view['settings']->main_get->gettype != 2)) + { + return false; + } + + $created = $this->createdate->get($view); + $modified = $this->modifieddate->get($view); + + $config = [ + Placefix::_h('CREATIONDATE') => $created, + Placefix::_h('BUILDDATE') => $modified, + Placefix::_h('VERSION') => $view['settings']->version + ]; + + return true; + } + + /** + * Build the admin view + * + * @param array $view + * @param array $config + * + * @return void + * @since 3.2.0 + */ + private function buildAdminView(array $view, array $config) + { + // build the admin edit view + if ($view['settings']->name_single != 'null') + { + $target = ['admin' => $view['settings']->name_single]; + $this->structure->build($target, 'single', false, $config); + + // build the site edit view (of this admin view) + if (isset($view['edit_create_site_view']) + && is_numeric($view['edit_create_site_view']) + && $view['edit_create_site_view'] > 0) + { + // setup the front site edit-view files + $target = ['site' => $view['settings']->name_single]; + $this->structure->build($target, 'edit', false, $config); + } + } + + // build the list view + if ($view['settings']->name_list != 'null') + { + $target = ['admin' => $view['settings']->name_list]; + $this->structure->build($target, 'list', false, $config); + } + } + + /** + * Build the custom view + * + * @param array $view + * @param array $config + * @param string $type + * + * @return void + * @since 3.2.0 + */ + private function buildView(array $view, array $config, string $type) + { + $target = [$type => $view['settings']->code]; + $view_type = ($view['settings']->main_get->gettype == 1) ? 'single' : 'list'; + + $this->structure->build($target, $view_type, false, $config); + } diff --git a/src/b80296eb-4718-4ed3-894d-69f3ac293733/code.power b/src/b80296eb-4718-4ed3-894d-69f3ac293733/code.power new file mode 100644 index 0000000..d548723 --- /dev/null +++ b/src/b80296eb-4718-4ed3-894d-69f3ac293733/code.power @@ -0,0 +1,228 @@ + /** + * The admin view names + * + * @var array + * @since 3.2.0 + */ + protected array $name = []; + + /** + * The compiler registry + * + * @var Registry + * @since 3.2.0 + */ + protected Registry $registry; + + /** + * Constructor + * + * @param Registry|null $registry The compiler registry object. + * + * @since 3.2.0 + */ + public function __construct(?Registry $registry = null) + { + $this->registry = $registry ?: Compiler::_('Registry'); + } + + /** + * check if an update SQL is needed + * + * @param mixed $old The old values + * @param mixed $new The new values + * @param string $type The type of values + * @param mixed $key The id/key where values changed + * @param array|null $ignore The ids to ignore + * + * @return void + * @since 3.2.0 + */ + public function set($old, $new, string $type, $key = null, ?array $ignore = null) + { + // check if there were new items added + if (ArrayHelper::check($new) && ArrayHelper::check($old)) + { + // check if this is old repeatable field + if (isset($new[$type])) + { + foreach ($new[$type] as $item) + { + $newItem = true; + + // check if this is an id to ignore + if (ArrayHelper::check($ignore) + && in_array( + $item, $ignore + )) + { + // don't add ignored ids + $newItem = false; + } + // check if this is old repeatable field + elseif (isset($old[$type]) + && ArrayHelper::check($old[$type])) + { + if (!in_array($item, $old[$type])) + { + // we have a new item, lets add to SQL + $this->add($type, $item, $key); + } + + // add only once + $newItem = false; + } + elseif (!isset($old[$type])) + { + // we have new values + foreach ($old as $oldItem) + { + if (isset($oldItem[$type])) + { + if ($oldItem[$type] == $item[$type]) + { + $newItem = false; + break; + } + } + else + { + $newItem = false; + break; + } + } + } + else + { + $newItem = false; + } + + // add if new + if ($newItem) + { + // we have a new item, lets add to SQL + $this->add($type, $item[$type], $key); + } + } + } + else + { + foreach ($new as $item) + { + if (isset($item[$type])) + { + // search to see if this is a new value + $newItem = true; + + // check if this is an id to ignore + if (ArrayHelper::check($ignore) + && in_array($item[$type], $ignore)) + { + // don't add ignored ids + $newItem = false; + } + // check if this is old repeatable field + elseif (isset($old[$type]) + && ArrayHelper::check($old[$type])) + { + if (in_array($item[$type], $old[$type])) + { + $newItem = false; + } + } + elseif (!isset($old[$type])) + { + // we have new values + foreach ($old as $oldItem) + { + if (isset($oldItem[$type])) + { + if ($oldItem[$type] == $item[$type]) + { + $newItem = false; + break; + } + } + else + { + $newItem = false; + break; + } + } + } + else + { + $newItem = false; + } + + // add if new + if ($newItem) + { + // we have a new item, lets add to SQL + $this->add($type, $item[$type], $key); + } + } + } + } + } + elseif ($key && ((StringHelper::check($new) && StringHelper::check($old)) + || (is_numeric($new) && is_numeric($old))) && $new !== $old) + { + // set at key + $this->registry->set('builder.update_sql.' . $type . '.' . $key, ['old' => $old, 'new' => $new]); + } + } + + /** + * Set the add sql + * + * @param string $type The type of values + * @param int $item The item id to add + * @param mixed $key The id/key where values changed + * + * @return void + * @since 3.2.0 + */ + protected function add(string $type, int $item, $key = null) + { + // add key if found + if ($key) + { + $this->registry->set('builder.add_sql.' . $type . '.' . $key . '.' . $item, $item); + } + else + { + // convert admin view id to name + if ('adminview' === $type) + { + $this->registry->set('builder.add_sql.' . $type . '.' . $this->name($item), + $item + ); + } + else + { + $this->registry->set('builder.add_sql.' . $type, $item); + } + } + } + + /** + * Get the Admin view table name + * + * @param int $id The item id to add + * + * @return string the admin view code name + * @since 3.2.0 + */ + protected function name(int $id): string + { + // get name if not set + if (!isset($this->name[$id])) + { + $this->name[$id] = StringHelper::safe( + GetHelper::var('admin_view', $id, 'id', 'name_single') + ); + } + + return $this->name[$id] ?? 'error'; + } diff --git a/src/b836c1b1-b6b1-44f7-b8a2-9a763a4185b1/code.php b/src/b836c1b1-b6b1-44f7-b8a2-9a763a4185b1/code.php index e03fbed..f093d90 100644 --- a/src/b836c1b1-b6b1-44f7-b8a2-9a763a4185b1/code.php +++ b/src/b836c1b1-b6b1-44f7-b8a2-9a763a4185b1/code.php @@ -925,6 +925,11 @@ class Power implements PowerInterface { if (StringHelper::check($this->active[$guid]->main_class_code)) { + // keep this back for super powers ( we need the unchanged code in the super powers ) + $this->active[$guid]->raw_class_code = base64_decode( + (string) $this->active[$guid]->main_class_code + ); + // set GUI mapper field $guiMapper['field'] = 'main_class_code'; @@ -932,9 +937,7 @@ class Power implements PowerInterface $this->active[$guid]->main_class_code = $this->gui->set( $this->placeholder->update_( $this->customcode->update( - base64_decode( - (string) $this->active[$guid]->main_class_code - ) + $this->active[$guid]->raw_class_code ) ), $guiMapper @@ -966,6 +969,13 @@ class Power implements PowerInterface // update all paths $this->active[$guid]->super_power_paths = array_map(function($path) use($global_path, $guid) { + + // remove branch + if (($pos = strpos($path, ':')) !== false) + { + $path = substr($path, 0, $pos); + } + // set the repo path $repo = $global_path . '/' . $path; diff --git a/src/b836c1b1-b6b1-44f7-b8a2-9a763a4185b1/code.power b/src/b836c1b1-b6b1-44f7-b8a2-9a763a4185b1/code.power new file mode 100644 index 0000000..93e5d07 --- /dev/null +++ b/src/b836c1b1-b6b1-44f7-b8a2-9a763a4185b1/code.power @@ -0,0 +1,966 @@ + /** + * All loaded powers + * + * @var array + * @since 3.2.0 + **/ + public array $active = []; + + /** + * All power namespaces + * + * @var array + * @since 3.2.0 + **/ + public array $namespace = []; + + /** + * All composer namespaces + * + * @var array + * @since 3.2.0 + **/ + public array $composer = []; + + /** + * All super powers of this build + * + * @var array + * @since 3.2.0 + **/ + public array $superpowers = []; + + /** + * The url to the power, if there is an error. + * + * @var string + * @since 3.2.0 + **/ + protected string $fixUrl; + + /** + * The state of all loaded powers + * + * @var array + * @since 3.2.0 + **/ + protected array $state = []; + + /** + * Compiler Config + * + * @var Config + * @since 3.2.0 + **/ + protected Config $config; + + /** + * Compiler Placeholder + * + * @var Placeholder + * @since 3.2.0 + **/ + protected Placeholder $placeholder; + + /** + * Compiler Customcode + * + * @var Customcode + * @since 3.2.0 + **/ + protected Customcode $customcode; + + /** + * Compiler Customcode in Gui + * + * @var Gui + * @since 3.2.0 + **/ + protected Gui $gui; + + /** + * Database object to query local DB + * + * @var \JDatabaseDriver + * @since 3.2.0 + **/ + protected \JDatabaseDriver $db; + + /** + * Database object to query local DB + * + * @var CMSApplication + * @since 3.2.0 + **/ + protected CMSApplication $app; + + /** + * Constructor. + * + * @param Config|null $config The compiler config object. + * @param Placeholder|null $placeholder The compiler placeholder object. + * @param Customcode|null $customcode The compiler customcode object. + * @param Gui|null $gui The compiler customcode gui object. + * @param \JDatabaseDriver|null $db The Database Driver object. + * @param CMSApplication|null $app The CMS Application object. + * + * @throws \Exception + * @since 3.2.0 + */ + public function __construct(?Config $config = null, ?Placeholder $placeholder = null, + ?Customcode $customcode = null, ?Gui $gui = null, + ?\JDatabaseDriver $db = null, ?CMSApplication $app = null) + { + $this->config = $config ?: Compiler::_('Config'); + $this->placeholder = $placeholder ?: Compiler::_('Placeholder'); + $this->customcode = $customcode ?: Compiler::_('Customcode'); + $this->gui = $gui ?: Compiler::_('Customcode.Gui'); + $this->db = $db ?: Factory::getDbo(); + $this->app = $app ?: Factory::getApplication(); + } + + /** + * load all the powers linked to this component + * + * @param array $guids The global unique ids of the linked powers + * + * @return void + * @since 3.2.0 + */ + public function load(array $guids) + { + if (ArrayHelper::check($guids)) + { + foreach ($guids as $guid => $build) + { + $this->get($guid, $build); + } + } + } + + /** + * Get a power + * + * @param string $guid The global unique id of the power + * @param int $build Force build switch (to override global switch) + * + * @return object|null + * @since 3.2.0 + */ + public function get(string $guid, int $build = 0): ?object + { + if (($this->config->get('add_power', true) || $build == 1) && $this->set($guid)) + { + return $this->active[$guid]; + } + + return null; + } + + /** + * Set a power + * + * @param string $guid The global unique id of the power + * + * @return bool true on successful setting of a power + * @since 3.2.0 + */ + private function set(string $guid): bool + { + // check if we have been here before + if ($this->isPowerSet($guid)) + { + return $this->state[$guid]; + } + elseif ($this->isGuidValid($guid)) + { + // get the power data + $this->active[$guid] = $this->getPowerData($guid); + + if (is_object($this->active[$guid])) + { + // make sure that in recursion we + // don't try to load this power again + // since during the load of a power we also load + // all powers linked to it + $this->state[$guid] = true; + + // make sure to add any language strings found to all language files + // since we can't know where this is used at this point + $tmp_lang_target = $this->config->lang_target; + $this->config->lang_target = 'both'; + + // we set the fix url if needed + $this->fixUrl + = '"index.php?option=com_componentbuilder&view=powers&task=power.edit&id=' + . $this->active[$guid]->id . '" target="_blank"'; + + // set some keys + $this->active[$guid]->target_type = 'P0m3R!'; + $this->active[$guid]->key = $this->active[$guid]->id . '_' . $this->active[$guid]->target_type; + + // reserve some values for the linker + $this->active[$guid]->unchanged_namespace = $this->active[$guid]->namespace; + $this->active[$guid]->unchanged_description = $this->active[$guid]->description; + + // now set the name + $this->active[$guid]->name = $this->placeholder->update_( + $this->customcode->update($this->active[$guid]->name) + ); + + // now set the code_name and class name + $this->active[$guid]->code_name = $this->active[$guid]->class_name = ClassfunctionHelper::safe( + $this->active[$guid]->name + ); + + // set official name + $this->active[$guid]->official_name = StringHelper::safe( + $this->active[$guid]->name, 'W' + ); + + // set name space + if (!$this->setNamespace($guid)) + { + $this->state[$guid] = false; + unset($this->active[$guid]); + // reset back to starting value + $this->config->lang_target = $tmp_lang_target; + + return false; + } + + // load use ids + $use = []; + $as = []; + + // set extra classes + $this->setLoadSelection($guid); + + // set use classes + $this->setUseSelection($guid, $use, $as); + + // set implement interfaces + $this->setImplements($guid, $use); + + // set extend class + $this->setExtend($guid, $use); + + // set GUI mapper + $guiMapper = [ + 'table' => 'power', + 'id' => (int) $this->active[$guid]->id, + 'type' => 'php' + ]; + + // add the licensing template + $this->setLicensingTemplate($guid, $guiMapper); + + // add the header script + $this->setHeader($guid, $guiMapper); + + // set composer + $this->setComposer($guid); + + // now set the description + $this->active[$guid]->description = (StringHelper::check($this->active[$guid]->description)) ? $this->placeholder->update_( + $this->customcode->update($this->active[$guid]->description), + ) : ''; + + // add the main code if set + $this->setMainClassCode($guid, $guiMapper); + + // load the use classes + $this->setUseAs($guid, $use, $as); + + // reset back to starting value + $this->config->lang_target = $tmp_lang_target; + + // set the approved super power values + $this->setSuperPowers($guid); + + return true; + } + } + + // we failed to get the power, + // so we raise an error message + // only if guid is valid + if ($this->isGuidValid($guid)) + { + $this->app->enqueueMessage( + Text::sprintf('

Power guid:%s not found!

', $guid), + 'Error' + ); + } + + // let's not try again + $this->state[$guid] = false; + + return false; + } + + /** + * Check if the power is already set + * + * @param string $guid The global unique id of the power + * + * @return bool true if the power is already set + * @since 3.2.0 + */ + private function isPowerSet(string $guid): bool + { + return isset($this->state[$guid]); + } + + /** + * Validate the GUID + * + * @param string $guid The global unique id of the power + * + * @return bool true if the GUID is valid + * @since 3.2.0 + */ + private function isGuidValid(string $guid): bool + { + return GuidHelper::valid($guid); + } + + /** + * Get the power data from the database + * + * @param string $guid The global unique id of the power + * + * @return object|null The power data + * @since 3.2.0 + */ + private function getPowerData(string $guid): ?object + { + $query = $this->db->getQuery(true); + $query->select('a.*'); + $query->from('#__componentbuilder_power AS a'); + $query->where($this->db->quoteName('a.guid') . ' = ' . $this->db->quote($guid)); + + $this->db->setQuery($query); + $this->db->execute(); + + if ($this->db->getNumRows()) + { + return $this->db->loadObject(); + } + + return null; + } + + /** + * Set the namespace for this power + * + * @param string $guid The global unique id of the power + * + * @return bool + * @since 3.2.0 + */ + private function setNamespace(string $guid): bool + { + // set namespace + $this->active[$guid]->namespace = $this->placeholder->update_( + $this->active[$guid]->namespace + ); + + // validate namespace + if (strpos($this->active[$guid]->namespace, '\\') === false) + { + // we raise an error message + $this->app->enqueueMessage( + Text::sprintf('

%s namespace error (%s)

You must at-least have two sections in your namespace, you just have one. This is an unacceptable action, please see psr-4 for more info.

This %s was therefore removed, click here to fix this issue.

', + ucfirst((string) $this->active[$guid]->type), $this->active[$guid]->name, $this->active[$guid]->namespace, + '"https://www.php-fig.org/psr/psr-4/" target="_blank"', $this->active[$guid]->type, + $this->fixUrl), + 'Error' + ); + + // we break out here + return false; + } + + // setup the path array + $path_array = (array) explode('\\', $this->active[$guid]->namespace); + + // make sure all sub folders in src dir is set and remove all characters that will not work in folders naming + $this->active[$guid]->namespace = $this->getCleanNamespace(str_replace('.', '\\', $this->active[$guid]->namespace)); + + // make sure it has two or more + if (ArrayHelper::check($path_array) <= 1) + { + // we raise an error message + $this->app->enqueueMessage( + Text::sprintf('

%s namespace error (%s)

You must at-least have two sections in your namespace, you just have one (%s). This is an unacceptable action, please see psr-4 for more info.

This %s was therefore removed, click here to fix this issue.

', + ucfirst((string) $this->active[$guid]->type), $this->active[$guid]->name, $this->active[$guid]->namespace, + '"https://www.php-fig.org/psr/psr-4/" target="_blank"', $this->active[$guid]->type, + $this->fixUrl), + 'Error' + ); + + // we break out here + return false; + } + + // get the file and class name (the last value in array) + $file_name = array_pop($path_array); + + // src array bucket + $src_array = []; + + // do we have src folders + if (strpos($file_name, '.') !== false) + { + // we have src folders in the namespace + $src_array = (array) explode('.', $file_name); + + // get the file and class name (the last value in array) + $this->active[$guid]->file_name = array_pop($src_array); + + // namespace array + $namespace_array = [...$path_array, ...$src_array]; + } + else + { + // set the file name + $this->active[$guid]->file_name = $file_name; + + // namespace array + $namespace_array = $path_array; + } + + // the last value is the same as the class name + if ($this->active[$guid]->file_name !== $this->active[$guid]->class_name) + { + // we raise an error message + $this->app->enqueueMessage( + Text::sprintf('

%s naming mismatch error (%s)

The %s name is %s and the ending file name in the namespace is %s. This is bad convention, please see psr-4 for more info.

Click here to fix this issue.

', + ucfirst((string) $this->active[$guid]->type), $this->active[$guid]->name, $this->active[$guid]->type, $this->active[$guid]->class_name, $this->active[$guid]->file_name, + '"https://www.php-fig.org/psr/psr-4/" target="_blank"', + $this->fixUrl), + 'Error' + ); + + // we break out here + return false; + } + + // make sure the arrays are namespace safe + $path_array = + array_map( + fn($val) => $this->getCleanNamespace($val), + $path_array + ); + $namespace_array = + array_map( + fn($val) => $this->getCleanNamespace($val), + $namespace_array + ); + + // set the actual class namespace + $this->active[$guid]->_namespace = implode('\\', $namespace_array); + + // set global namespaces for autoloader + $this->namespace[implode('.', $path_array)] = $path_array; + + // get the parent folder (the first value in array) + $prefix_folder = implode('.', $path_array); + + // make sub folders if still found + $sub_folder = ''; + if (ArrayHelper::check($src_array)) + { + // make sure the arrays are namespace safe + $sub_folder = '/' . implode('/', + array_map( + fn($val) => $this->getCleanNamespace($val), + $src_array + ) + ); + } + + // now we set the paths + $this->active[$guid]->path_jcb = $this->config->get('jcb_powers_path', 'libraries/jcb_powers'); + $this->active[$guid]->path_parent = $this->active[$guid]->path_jcb . '/' . $prefix_folder; + $this->active[$guid]->path = $this->active[$guid]->path_parent . '/src' . $sub_folder; + + return true; + } + + /** + * Set Use Classess + * + * @param string $guid The global unique id of the power + * @param array $use The use array + * @param array $as The use as array + * + * @return void + * @since 3.2.0 + */ + private function setUseSelection(string $guid, array &$use, array &$as) + { + // check if we have use selection + $this->active[$guid]->use_selection = (isset($this->active[$guid]->use_selection) + && JsonHelper::check( + $this->active[$guid]->use_selection + )) ? json_decode((string) $this->active[$guid]->use_selection, true) : null; + + if (ArrayHelper::check($this->active[$guid]->use_selection)) + { + $use = array_values(array_map(function ($u) use(&$as) { + // track the AS options + $as[$u['use']] = empty($u['as']) ? 'default' : (string) $u['as']; + // return the guid + return $u['use']; + }, $this->active[$guid]->use_selection)); + } + else + { + $this->active[$guid]->use_selection = null; + } + } + + /** + * Load Extra Classes + * + * @param string $guid The global unique id of the power + * + * @return void + * @since 3.2.0 + */ + private function setLoadSelection(string $guid) + { + // check if we have load selection + $this->active[$guid]->load_selection = (isset($this->active[$guid]->load_selection) + && JsonHelper::check( + $this->active[$guid]->load_selection + )) ? json_decode((string) $this->active[$guid]->load_selection, true) : null; + + if (ArrayHelper::check($this->active[$guid]->load_selection)) + { + // load use ids + array_map( + // just load it directly and be done with it + fn($power) => $this->set($power['load']), + $this->active[$guid]->load_selection + ); + } + else + { + $this->active[$guid]->load_selection = null; + } + } + + /** + * Set Composer Linked Use and Access Point + * + * @param string $guid The global unique id of the power + * + * @return void + * @since 3.2.0 + */ + private function setComposer(string $guid) + { + // does this have composer powers + $_composer = (isset($this->active[$guid]->composer) + && JsonHelper::check( + $this->active[$guid]->composer + )) ? json_decode((string) $this->active[$guid]->composer, true) : null; + + unset($this->active[$guid]->composer); + + if (ArrayHelper::check($_composer)) + { + // reserve composer values for the linker + $this->active[$guid]->unchanged_composer = $_composer; + + foreach ($_composer as $composer) + { + if (isset($composer['access_point']) && StringHelper::check($composer['access_point']) && + isset($composer['namespace']) && ArrayHelper::check($composer['namespace'])) + { + foreach ($composer['namespace'] as $_namespace) + { + // make sure we have a valid namespace + if (isset($_namespace['use']) && StringHelper::check($_namespace['use']) && + strpos((string) $_namespace['use'], '\\') !== false) + { + // add the namespace to this access point + $as = 'default'; + if (strpos((string) $_namespace['use'], ' as ') !== false) + { + $namespace_as = explode(' as ', (string) $_namespace['use']); + // make sure the AS value is set + if (count($namespace_as) == 2) + { + $as = trim(trim($namespace_as[1], ';')); + } + $namespace = $this->getCleanNamespace($namespace_as[0], false); + } + else + { + // trim possible use or ; added to the namespace + $namespace = $this->getCleanNamespace($_namespace['use'], false); + } + + // check if still valid + if (!StringHelper::check($namespace)) + { + continue; + } + + // add to the header of the class + $this->addToHeader($guid, $this->getUseNamespace($namespace, $as)); + + // add composer namespaces for autoloader + $this->composer[$namespace] = $composer['access_point']; + } + } + } + } + } + } + + /** + * Set Implements Interface classes + * + * @param string $guid The global unique id of the power + * @param array $use The use array + * + * @return void + * @since 3.2.0 + */ + private function setImplements(string $guid, array &$use) + { + // see if we have implements + $this->active[$guid]->implement_names = []; + + // does this implement + $this->active[$guid]->implements = (isset($this->active[$guid]->implements) + && JsonHelper::check( + $this->active[$guid]->implements + )) ? json_decode((string) $this->active[$guid]->implements, true) : null; + + if ($this->active[$guid]->implements) + { + foreach ($this->active[$guid]->implements as $implement) + { + if ($implement == -1 + && StringHelper::check($this->active[$guid]->implements_custom)) + { + $this->active[$guid]->implement_names[] = $this->placeholder->update_( + $this->customcode->update($this->active[$guid]->implements_custom) + ); + // just add this once + unset($this->active[$guid]->implements_custom); + } + // does this extend existing + elseif (GuidHelper::valid($implement)) + { + // check if it was set + if ($this->set($implement)) + { + // get the name + $this->active[$guid]->implement_names[] = $this->get($implement, 1)->class_name; + // add to use + $use[] = $implement; + } + } + } + } + } + + /** + * Set Extend Class + * + * @param string $guid The global unique id of the power + * @param array $use The use array + * + * @return void + * @since 3.2.0 + */ + private function setExtend(string $guid, array &$use) + { + // does this extend something + $this->active[$guid]->extends_name = null; + + // we first check for custom extending options + if ($this->active[$guid]->extends == -1 + && StringHelper::check($this->active[$guid]->extends_custom)) + { + $this->active[$guid]->extends_name = $this->placeholder->update_( + $this->customcode->update($this->active[$guid]->extends_custom) + ); + // just add once + unset($this->active[$guid]->extends_custom); + } + // does this extend existing + elseif (GuidHelper::valid($this->active[$guid]->extends)) + { + // check if it was set + if ($this->set($this->active[$guid]->extends)) + { + // get the name + $this->active[$guid]->extends_name = $this->get($this->active[$guid]->extends, 1)->class_name; + // add to use + $use[] = $this->active[$guid]->extends; + } + } + } + + /** + * Set Extra Use Classes + * + * @param string $guid The global unique id of the power + * @param array $use The use array + * @param array $as The use as array + * + * @return void + * @since 3.2.0 + */ + private function setUseAs(string $guid, array $use, array $as) + { + // now add all the extra use statements + if (ArrayHelper::check($use)) + { + foreach (array_unique($use) as $u) + { + if ($this->set($u)) + { + // get the namespace + $namespace = $this->get($u, 1)->namespace; + + // check if it has an AS option + if (isset($as[$u]) && StringHelper::check($as[$u])) + { + // add to the header of the class + $this->addToHeader($guid, $this->getUseNamespace($namespace, $as[$u])); + } + else + { + // add to the header of the class + $this->addToHeader($guid, $this->getUseNamespace($namespace)); + } + } + } + } + } + + /** + * Get Clean Namespace without use or ; as part of the name space + * + * @param string $namespace The actual name space + * @param bool $removeNumbers The switch to remove numbers + * + * @return string + * @since 3.2.0 + */ + private function getCleanNamespace(string $namespace, bool $removeNumbers = true): string + { + // trim possible (use) or (;) or (starting or ending \) added to the namespace + return NamespaceHelper::safe(str_replace(['use ', ';'], '', $namespace), $removeNumbers); + } + + /** + * Get [use Namespace\Class;] + * + * @param string $namespace The actual name space + * @param string $as The use as name (default is none) + * + * @return string + * @since 3.2.0 + */ + private function getUseNamespace(string $namespace, string $as = 'default'): string + { + // check if it has an AS option + if ($as !== 'default') + { + return 'use ' . $namespace . ' as ' . $as . ';'; + } + return 'use ' . $namespace . ';'; + } + + /** + * Add to class header + * + * @param string $guid The global unique id of the power + * @param string $string The string to add to header + * + * @return void + * @since 3.2.0 + */ + private function addToHeader(string $guid, string $string) + { + // check if it is already added manually + if (isset($this->active[$guid]->head) && + strpos((string) $this->active[$guid]->head, $string) === false) + { + $this->active[$guid]->head .= $string . PHP_EOL; + } + } + + /** + * Set the power licensing template + * + * @param string $guid The global unique id of the power + * @param array $guiMapper The gui mapper array + * + * @return void + * @since 3.2.0 + */ + private function setLicensingTemplate(string $guid, array $guiMapper): void + { + if ($this->active[$guid]->add_licensing_template == 2 && + StringHelper::check($this->active[$guid]->licensing_template)) + { + // set GUI mapper field + $guiMapper['field'] = 'licensing_template'; + + // base64 Decode code + $this->active[$guid]->licensing_template = $this->gui->set( + $this->placeholder->update_( + $this->customcode->update( + base64_decode( + (string) $this->active[$guid]->licensing_template + ) + ) + ), + $guiMapper + ); + } + else + { + $this->active[$guid]->add_licensing_template = 1; + $this->active[$guid]->licensing_template = ''; + } + } + + /** + * Set the power header script + * + * @param string $guid The global unique id of the power + * @param array $guiMapper The gui mapper array + * + * @return void + * @since 3.2.0 + */ + private function setHeader(string $guid, array $guiMapper): void + { + if ($this->active[$guid]->add_head == 1) + { + // set GUI mapper field + $guiMapper['field'] = 'head'; + + $head = base64_decode( + (string) $this->active[$guid]->head + ); + + // reserve header for the linker + $this->active[$guid]->unchanged_head = $head; + + // base64 Decode code + $this->active[$guid]->head = $this->gui->set( + $this->placeholder->update_( + $this->customcode->update($head) + ), + $guiMapper + ) . PHP_EOL; + } + else + { + $this->active[$guid]->head = ''; + } + } + + /** + * Set the power main class code + * + * @param string $guid The global unique id of the power + * @param array $guiMapper The gui mapper array + * + * @return void + * @since 3.2.0 + */ + private function setMainClassCode(string $guid, array $guiMapper): void + { + if (StringHelper::check($this->active[$guid]->main_class_code)) + { + // keep this back for super powers ( we need the unchanged code in the super powers ) + $this->active[$guid]->raw_class_code = base64_decode( + (string) $this->active[$guid]->main_class_code + ); + + // set GUI mapper field + $guiMapper['field'] = 'main_class_code'; + + // base64 Decode code + $this->active[$guid]->main_class_code = $this->gui->set( + $this->placeholder->update_( + $this->customcode->update( + $this->active[$guid]->raw_class_code + ) + ), + $guiMapper + ); + } + } + + /** + * Set the super powers of this power + * + * @param string $guid The global unique id of the power + * + * @return void + * @since 3.2.0 + */ + private function setSuperPowers(string $guid): void + { + // set the approved super power values + if ($this->config->add_super_powers && $this->active[$guid]->approved == 1) + { + $this->active[$guid]->approved_paths = (isset($this->active[$guid]->approved_paths) + && JsonHelper::check( + $this->active[$guid]->approved_paths + )) ? json_decode((string) $this->active[$guid]->approved_paths, true) : null; + + if (ArrayHelper::check($this->active[$guid]->approved_paths)) + { + $global_path = $this->config->local_powers_repository_path; + + // update all paths + $this->active[$guid]->super_power_paths = array_map(function($path) use($global_path, $guid) { + + // remove branch + if (($pos = strpos($path, ':')) !== false) + { + $path = substr($path, 0, $pos); + } + + // set the repo path + $repo = $global_path . '/' . $path; + + // set the global super power + $this->superpowers[$repo][$guid] = [ + 'name' => $this->active[$guid]->code_name, + 'type' => $this->active[$guid]->type, + 'namespace' => $this->active[$guid]->_namespace, + 'code' => 'src/' . $guid . '/code.php', + 'settings' => 'src/' . $guid . '/settings.json', + 'path' => 'src/' . $guid, + 'guid' => $guid + ]; + + return $repo . '/src/' . $guid; + }, array_values($this->active[$guid]->approved_paths)); + + return; + } + } + + // reset all to avoid any misunderstanding down steam + $this->active[$guid]->super_power_paths = null; + $this->active[$guid]->approved_paths = null; + $this->active[$guid]->approved = null; + } diff --git a/src/b94aaedb-6774-4739-a63f-8f87141a85db/code.power b/src/b94aaedb-6774-4739-a63f-8f87141a85db/code.power new file mode 100644 index 0000000..1d69ff5 --- /dev/null +++ b/src/b94aaedb-6774-4739-a63f-8f87141a85db/code.power @@ -0,0 +1,55 @@ + /** + * Current Joomla Version We are IN + * + * @var int + * @since 3.2.0 + **/ + protected $currentVersion; + + /** + * 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(J3Event::class, 'J3.Event') + ->share('J3.Event', [$this, 'getJ3Event'], true); + + $container->alias(EventInterface::class, 'Event') + ->share('Event', [$this, 'getEvent'], true); + } + + /** + * Get the Event + * + * @param Container $container The DI container. + * + * @return EventInterface + * @since 3.2.0 + */ + public function getEvent(Container $container): EventInterface + { + if (empty($this->currentVersion)) + { + $this->currentVersion = Version::MAJOR_VERSION; + } + + return $container->get('J' . $this->currentVersion . '.Event'); + } + + /** + * Get the Joomla 3 Event + * + * @param Container $container The DI container. + * + * @return J3Event + * @since 3.2.0 + */ + public function getJ3Event(Container $container): J3Event + { + return new J3Event(); + } diff --git a/src/b9f05dc4-d23a-499a-a826-9749b81818ed/code.power b/src/b9f05dc4-d23a-499a-a826-9749b81818ed/code.power new file mode 100644 index 0000000..848a334 --- /dev/null +++ b/src/b9f05dc4-d23a-499a-a826-9749b81818ed/code.power @@ -0,0 +1,9 @@ + /** + * Get the Array of Existing Validation Rule Names + * + * @param bool $lowercase Switch to set rules lowercase + * + * @return array + * @since 3.2.0 + */ + public function get(bool $lowercase = false): array; \ No newline at end of file diff --git a/src/bfdc4ce5-cb12-4fc6-9023-51cede25edd0/code.power b/src/bfdc4ce5-cb12-4fc6-9023-51cede25edd0/code.power new file mode 100644 index 0000000..3743ab0 --- /dev/null +++ b/src/bfdc4ce5-cb12-4fc6-9023-51cede25edd0/code.power @@ -0,0 +1,54 @@ + /** + * Compiler Joomla Module Data Class + * + * @var Module + * @since 3.2.0 + */ + protected Module $module; + + /** + * Constructor + * + * @param Module|null $module The compiler Joomla module data object. + * + * @since 3.2.0 + */ + public function __construct(?Module $module = null) + { + $this->module = $module ?: Compiler::_('Joomlamodule.Data'); + } + + /** + * Set Joomla Module + * + * @param object $item The item data + * + * @return void + * @since 3.2.0 + */ + public function set(object &$item) + { + // get all modules + $item->addjoomla_modules = (isset($item->addjoomla_modules) + && JsonHelper::check($item->addjoomla_modules)) + ? json_decode((string) $item->addjoomla_modules, true) : null; + + if (ArrayHelper::check($item->addjoomla_modules)) + { + $joomla_modules = array_map( + function ($array) use (&$item) { + // only load the modules whose target association calls for it + if (!isset($array['target']) || $array['target'] != 2) + { + return $this->module->set( + $array['module'], $item + ); + } + + return null; + }, array_values($item->addjoomla_modules) + ); + } + + unset($item->addjoomla_modules); + } diff --git a/src/c20a63e0-0eeb-4424-9d08-b1bf0f049dfe/code.power b/src/c20a63e0-0eeb-4424-9d08-b1bf0f049dfe/code.power new file mode 100644 index 0000000..77c2042 --- /dev/null +++ b/src/c20a63e0-0eeb-4424-9d08-b1bf0f049dfe/code.power @@ -0,0 +1,110 @@ + /** + * The areas add array + * + * @var array + * @since 3.2.0 + */ + protected array $areas = [ + 'php_getitem', + 'php_before_save', + 'php_save', + 'php_getform', + 'php_postsavehook', + 'php_getitems', + 'php_getitems_after_all', + 'php_getlistquery', + 'php_allowadd', + 'php_allowedit', + 'php_before_cancel', + 'php_after_cancel', + 'php_before_delete', + 'php_after_delete', + 'php_before_publish', + 'php_after_publish', + 'php_batchcopy', + 'php_batchmove', + 'php_document' + ]; + + /** + * The gui mapper array + * + * @var array + * @since 3.2.0 + */ + protected array $guiMapper = [ + 'table' => 'admin_view', + 'id' => null, + 'field' => null, + 'type' => 'php' + ]; + + /** + * Compiler Customcode Dispenser + * + * @var Dispenser + * @since 3.2.0 + */ + protected Dispenser $dispenser; + + /** + * Compiler Template Layout Data + * + * @var Templatelayout + * @since 3.2.0 + */ + protected Templatelayout $templateLayout; + + /** + * Constructor + * + * @param Dispenser|null $dispenser The compiler customcode dispenser + * @param Templatelayout|null $templateLayout The template layout data + * + * @since 3.2.0 + */ + public function __construct(?Dispenser $dispenser = null, ?Templatelayout $templateLayout = null) + { + $this->dispenser = $dispenser ?: Compiler::_('Customcode.Dispenser'); + $this->templateLayout = $templateLayout ?: Compiler::_('Templatelayout.Data'); + } + + /** + * Set PHP code + * + * @param object $item The item data + * @param string $table The table + * + * @return void + * @since 3.2.0 + */ + public function set(object &$item, string $table = 'admin_view') + { + // set some gui mapper values + $this->guiMapper['table'] = $table; + $this->guiMapper['id'] = (int) $item->id; + + foreach ($this->areas as $area) + { + if (isset($item->{'add_' . $area}) + && $item->{'add_' . $area} == 1) + { + // update GUI mapper field + $this->guiMapper['field'] = $area; + $this->dispenser->set( + $item->{$area}, + $area, + $item->name_single_code, + null, + $this->guiMapper + ); + + // check if we have template or layouts to load + $this->templateLayout->set( + $item->{$area}, $item->name_single_code + ); + + unset($item->{$area}); + } + } + } diff --git a/src/c6c30d66-3106-44eb-9272-b2cf7ec74613/code.power b/src/c6c30d66-3106-44eb-9272-b2cf7ec74613/code.power new file mode 100644 index 0000000..37cc1ed --- /dev/null +++ b/src/c6c30d66-3106-44eb-9272-b2cf7ec74613/code.power @@ -0,0 +1,212 @@ + /** + * Current Joomla Version Being Build + * + * @var int + * @since 3.2.0 + **/ + protected $targetVersion; + + /** + * 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(CompilerField::class, 'Field') + ->share('Field', [$this, 'getField'], true); + + $container->alias(Data::class, 'Field.Data') + ->share('Field.Data', [$this, 'getData'], true); + + $container->alias(Validation::class, 'Field.Validation') + ->share('Field.Validation', [$this, 'getValidation'], true); + + $container->alias(J3CoreValidation::class, 'J3.Field.Core.Validation') + ->share('J3.Field.Core.Validation', [$this, 'getJ3CoreValidation'], true); + + $container->alias(CoreValidationInterface::class, 'Field.Core.Validation') + ->share('Field.Core.Validation', [$this, 'getCoreValidation'], true); + + $container->alias(Customcode::class, 'Field.Customcode') + ->share('Field.Customcode', [$this, 'getCustomcode'], true); + + $container->alias(Name::class, 'Field.Name') + ->share('Field.Name', [$this, 'getFieldName'], true); + + $container->alias(TypeName::class, 'Field.Type.Name') + ->share('Field.Type.Name', [$this, 'getFieldTypeName'], true); + + $container->alias(UniqueName::class, 'Field.Unique.Name') + ->share('Field.Unique.Name', [$this, 'getFieldUniqueName'], true); + + $container->alias(DatabaseName::class, 'Field.Database.Name') + ->share('Field.Database.Name', [$this, 'getFieldDatabaseName'], true); + } + + /** + * Get the Compiler Field + * + * @param Container $container The DI container. + * + * @return CompilerField + * @since 3.2.0 + */ + public function getField(Container $container): CompilerField + { + return new CompilerField( + $container->get('Field.Data'), + $container->get('Field.Name'), + $container->get('Field.Type.Name'), + $container->get('Field.Unique.Name') + ); + } + + /** + * Get the Compiler Field Data + * + * @param Container $container The DI container. + * + * @return Data + * @since 3.2.0 + */ + public function getData(Container $container): Data + { + return new Data( + $container->get('Config'), + $container->get('Event'), + $container->get('History'), + $container->get('Placeholder'), + $container->get('Customcode'), + $container->get('Field.Customcode'), + $container->get('Field.Validation') + ); + } + + /** + * Get the Compiler Field Validation + * + * @param Container $container The DI container. + * + * @return Validation + * @since 3.2.0 + */ + public function getValidation(Container $container): Validation + { + return new Validation( + $container->get('Registry'), + $container->get('Customcode.Gui'), + $container->get('Placeholder'), + $container->get('Customcode'), + $container->get('Field.Core.Validation') + ); + } + + /** + * Get the Compiler Field Joomla 3 Validation + * + * @param Container $container The DI container. + * + * @return J3CoreValidation + * @since 3.2.0 + */ + public function getJ3CoreValidation(Container $container): J3CoreValidation + { + return new J3CoreValidation(); + } + + /** + * Get the Compiler Field Core Validation + * + * @param Container $container The DI container. + * + * @return CoreValidationInterface + * @since 3.2.0 + */ + public function getCoreValidation(Container $container): CoreValidationInterface + { + if (empty($this->targetVersion)) + { + $this->targetVersion = $container->get('Config')->joomla_version; + } + + return $container->get('J' . $this->targetVersion . '.Field.Core.Validation'); + } + + /** + * Get the Compiler Field Customcode + * + * @param Container $container The DI container. + * + * @return Customcode + * @since 3.2.0 + */ + public function getCustomcode(Container $container): Customcode + { + return new Customcode( + $container->get('Customcode.Dispenser') + ); + } + + /** + * Get the Compiler Field Name + * + * @param Container $container The DI container. + * + * @return Name + * @since 3.2.0 + */ + public function getFieldName(Container $container): Name + { + return new Name( + $container->get('Placeholder'), + $container->get('Field.Unique.Name'), + $container->get('Registry') + ); + } + + /** + * Get the Compiler Field Type Name + * + * @param Container $container The DI container. + * + * @return TypeName + * @since 3.2.0 + */ + public function getFieldTypeName(Container $container): TypeName + { + return new TypeName(); + } + + /** + * Get the Compiler Field Unique Name + * + * @param Container $container The DI container. + * + * @return UniqueName + * @since 3.2.0 + */ + public function getFieldUniqueName(Container $container): UniqueName + { + return new UniqueName( + $container->get('Registry') + ); + } + + /** + * Get the Compiler Field Database Name + * + * @param Container $container The DI container. + * + * @return DatabaseName + * @since 3.2.0 + */ + public function getFieldDatabaseName(Container $container): DatabaseName + { + return new DatabaseName( + $container->get('Registry') + ); + } diff --git a/src/c871fb4a-4c33-4302-bb79-a9cd7ef4a557/code.power b/src/c871fb4a-4c33-4302-bb79-a9cd7ef4a557/code.power new file mode 100644 index 0000000..84806ac --- /dev/null +++ b/src/c871fb4a-4c33-4302-bb79-a9cd7ef4a557/code.power @@ -0,0 +1,134 @@ + /** + * Compiler registry + * + * @var Registry + * @since 3.2.0 + */ + protected Registry $registry; + + /** + * Compiler Gui + * + * @var Gui + * @since 3.2.0 + */ + protected Gui $gui; + + /** + * Compiler Placeholder + * + * @var Placeholder + * @since 3.2.0 + */ + protected Placeholder $placeholder; + + /** + * Compiler Customcode + * + * @var Customcode + * @since 3.2.0 + */ + protected Customcode $customcode; + + /** + * Compiler Field Core Validation + * + * @var CoreValidationInterface + * @since 3.2.0 + */ + protected CoreValidationInterface $validation; + + /** + * Constructor + * + * @param Registry|null $registry The compiler registry object. + * @param Gui|null $gui The compiler customcode gui object. + * @param Placeholder|null $placeholder The compiler placeholder object. + * @param Customcode|null $customcode The compiler customcode object. + * @param CoreValidationInterface|null $validation The core validation rule object. + * + * @since 3.2.0 + */ + public function __construct(?Registry $registry = null, ?Gui $gui = null, ?Placeholder $placeholder = null, + ?Customcode $customcode = null, ?CoreValidationInterface $validation = null) + { + $this->registry = $registry ?: Compiler::_('Registry'); + $this->gui = $gui ?: Compiler::_('Customcode.Gui'); + $this->placeholder = $placeholder ?: Compiler::_('Placeholder'); + $this->customcode = $customcode ?: Compiler::_('Customcode'); + $this->validation = $validation ?: Compiler::_('Field.Core.Validation'); + } + + /** + * Set the validation rule + * + * @param int $id The field id + * @param string $field The field string + * + * @return void + * @since 3.2.0 + */ + public function set(int $id, string $field) + { + // check if we have validate (validation rule set) + $validation_rule = GetHelper::between( + $field, 'validate="', '"' + ); + + if (StringHelper::check($validation_rule)) + { + // make sure it is lowercase + $validation_rule = StringHelper::safe( + $validation_rule + ); + + // link this field to this validation (don't move this down) + $this->registry->set("validation.linked.${id}", $validation_rule); + + // make sure it is not already set + if ($this->registry->get("validation.rules.${validation_rule}") === null) + { + // get joomla core validation names and make sure this rule is not a core validation rule + if (!in_array($validation_rule, (array) $this->validation->get(true))) + { + // get the class methods for this rule if it exists + if (($php_code = GetHelper::var( + 'validation_rule', $validation_rule, 'name', 'php' + )) !== false) + { + // open and set the validation rule + $this->registry->set("validation.rules.${validation_rule}", + $this->gui->set( + $this->placeholder->update_( + $this->customcode->update( + base64_decode( + (string) $php_code + ) + ) + ), + array( + 'table' => 'validation_rule', + 'field' => 'php', + 'id' => GetHelper::var( + 'validation_rule', + $validation_rule, 'name', 'id' + ), + 'type' => 'php' + ) + ) + ); + } + else + { + // TODO set the notice that this validation rule is custom and was not found + $this->registry->remove("validation.linked.${id}"); + } + } + else + { + // remove link (we only want custom validations linked) + $this->registry->remove("validation.linked.${id}"); + } + } + } + } diff --git a/src/ca111518-e47c-4049-b1b2-cb010f23866f/code.power b/src/ca111518-e47c-4049-b1b2-cb010f23866f/code.power new file mode 100644 index 0000000..bea6465 --- /dev/null +++ b/src/ca111518-e47c-4049-b1b2-cb010f23866f/code.power @@ -0,0 +1,203 @@ + /** + * Compiler Config + * + * @var Config + * @since 3.2.0 + **/ + protected Config $config; + + /** + * Compiler Placeholder + * + * @var Placeholder + * @since 3.2.0 + **/ + protected Placeholder $placeholder; + + /** + * Compiler Language + * + * @var Language + * @since 3.2.0 + **/ + protected Language $language; + + /** + * Compiler Language Extractor + * + * @var Extractor + * @since 3.2.0 + **/ + protected Extractor $extractor; + + /** + * Constructor. + * + * @param Config|null $config The compiler config object. + * @param Placeholder|null $placeholder The compiler placeholder object. + * @param Language|null $language The compiler language object. + * @param Extract|null $extractor The compiler language extractor object. + * + * @since 3.2.0 + */ + public function __construct( + ?Config $config = null, ?Placeholder $placeholder = null, + ?Language $language = null, ?Extractor $extractor = null) + { + $this->config = $config ?: Compiler::_('Config'); + $this->placeholder = $placeholder ?: Compiler::_('Placeholder'); + $this->language = $language ?: Compiler::_('Language'); + $this->extractor = $extractor ?: Compiler::_('Language.Extractor'); + } + + /** + * Reverse Engineer the dynamic placeholders (TODO hmmmm this is not ideal) + * + * @param string $string The string to revers + * @param array $placeholders The values to search for + * @param string $target The target path type + * @param int|null $id The custom code id + * @param string $field The field name + * @param string $table The table name + * + * @return string + * @since 3.2.0 + */ + public function engine(string $string, array &$placeholders, + string $target, ?int $id = null, string $field = 'code', string $table = 'custom_code'): string + { + // get local code if set + if ($id > 0 && $code = base64_decode( + (string) GetHelper::var($table, $id, 'id', $field) + )) + { + $string = $this->setReverse( + $string, $code, $target + ); + } + + return $this->placeholder->update($string, $placeholders, 2); + } + + /** + * Set the language strings for the reveres process + * + * @param string $updateString The string to update + * @param string $string The string to use language update + * @param string $target The target path type + * + * @return string + * @since 3.2.0 + */ + protected function setReverse(string $updateString, string $string, string $target): string + { + // get targets to search for + $lang_string_targets = array_filter( + $this->config->lang_string_targets, + fn($get): bool => strpos($string, (string) $get) !== false + ); + // check if we should continue + if (ArrayHelper::check($lang_string_targets)) + { + // start lang holder + $lang_holders = []; + // set the lang for both since we don't know what area is being targeted + $_tmp = $this->config->lang_target; + // set the lang based on target + if (strpos($target, 'module') !== false) + { + // backup lang prefix + $_tmp_lang_prefix = $this->config->lang_prefix; + // set the new lang prefix + $lang_prefix = strtoupper( + str_replace('module', 'mod', $target) + ); + $this->config->set('lang_prefix', $lang_prefix); + // now set the lang + if (isset($this->extractor->langKeys[$this->config->lang_prefix])) + { + $this->config->lang_target = $this->extractor->langKeys[$this->config->lang_prefix]; + } + else + { + $this->config->lang_target = 'module'; + } + } + elseif (strpos($target, 'plugin') !== false) + { + // backup lang prefix + $_tmp_lang_prefix = $this->config->lang_prefix; + // set the new lang prefix + $lang_prefix = strtoupper( + str_replace('plugin', 'plg', $target) + ); + $this->config->set('lang_prefix', $lang_prefix); + // now set the lang + if (isset($this->extractor->langKeys[$this->config->lang_prefix])) + { + $this->config->lang_target = $this->extractor->langKeys[$this->config->lang_prefix]; + } + else + { + $this->config->lang_target = 'plugin'; + } + } + else + { + $this->config->lang_target = 'both'; + } + // set language data + foreach ($lang_string_targets as $lang_string_target) + { + $lang_check[] = GetHelper::allBetween( + $string, $lang_string_target . "'", "'" + ); + $lang_check[] = GetHelper::allBetween( + $string, $lang_string_target . "'", "'" + ); + } + // merge arrays + $lang_array = ArrayHelper::merge($lang_check); + // continue only if strings were found + if (ArrayHelper::check( + $lang_array + )) //<-- not really needed hmmm + { + foreach ($lang_array as $lang) + { + $_key_lang = StringHelper::safe($lang, 'U'); + // this is there to insure we dont break already added Language strings + if ($_key_lang === $lang) + { + continue; + } + // build lang key + $key_lang = $this->config->lang_prefix . '_' . $_key_lang; + // set lang content string + $this->language->set($this->config->lang_target, $key_lang, $lang); + // reverse the placeholders + foreach ($lang_string_targets as $lang_string_target) + { + $lang_holders[$lang_string_target . "'" . $key_lang . "'"] + = $lang_string_target . "'" . $lang . "'"; + $lang_holders[$lang_string_target . '"' . $key_lang . '"'] + = $lang_string_target . '"' . $lang . '"'; + } + } + // return the found placeholders + $updateString = $this->placeholder->update( + $updateString, $lang_holders + ); + } + // reset the lang + $this->config->lang_target = $_tmp; + // also rest the lang prefix if set + if (isset($_tmp_lang_prefix)) + { + $lang_prefix = $_tmp_lang_prefix; + $this->config->set('lang_prefix', $_tmp_lang_prefix); + } + } + + return $updateString; + } diff --git a/src/caf33c5d-858c-4f9a-894f-ab302ec5445a/code.power b/src/caf33c5d-858c-4f9a-894f-ab302ec5445a/code.power new file mode 100644 index 0000000..5a394fe --- /dev/null +++ b/src/caf33c5d-858c-4f9a-894f-ab302ec5445a/code.power @@ -0,0 +1,17 @@ + /** + * Get any class from the container + * + * @param string $key The container class key + * + * @return Mixed + * @since 3.2.0 + */ + public static function _(string $key); + + /** + * Get the global container + * + * @return Container + * @since 3.2.0 + */ + public static function getContainer(): Container; diff --git a/src/cb11e8d9-69c2-4095-831c-59908ea402e7/code.power b/src/cb11e8d9-69c2-4095-831c-59908ea402e7/code.power new file mode 100644 index 0000000..e5f2b0b --- /dev/null +++ b/src/cb11e8d9-69c2-4095-831c-59908ea402e7/code.power @@ -0,0 +1,913 @@ + /** + * Compiler Joomla Plugins Data + * + * @var array + * @since 3.2.0 + */ + protected array $data = []; + + /** + * Compiler Config + * + * @var Config + * @since 3.2.0 + */ + protected Config $config; + + /** + * Compiler Customcode + * + * @var Customcode + * @since 3.2.0 + */ + protected Customcode $customcode; + + /** + * Compiler Customcode in Gui + * + * @var Gui + * @since 3.2.0 + **/ + protected Gui $gui; + + /** + * Compiler Placeholder + * + * @var Placeholder + * @since 3.2.0 + **/ + protected Placeholder $placeholder; + + /** + * Compiler Language + * + * @var Language + * @since 3.2.0 + **/ + protected Language $language; + + /** + * Compiler Field + * + * @var Field + * @since 3.2.0 + */ + protected Field $field; + + /** + * Compiler field name + * + * @var FieldName + * @since 3.2.0 + */ + protected FieldName $fieldName; + + /** + * Compiler Files Folders + * + * @var Filesfolders + * @since 3.2.0 + */ + protected Filesfolders $filesFolders; + + /** + * Compiler Libraries Model + * + * @var Libraries + * @since 3.2.0 + */ + protected Libraries $libraries; + + /** + * Compiler Dynamic Get Data + * + * @var Dynamicget + * @since 3.2.0 + */ + protected Dynamicget $dynamic; + + /** + * Database object to query local DB + * + * @var \JDatabaseDriver + * @since 3.2.0 + **/ + protected \JDatabaseDriver $db; + + /** + * Constructor + * + * @param Config|null $config The compiler config object. + * @param Customcode|null $customcode The compiler customcode object. + * @param Gui|null $gui The compiler customcode gui. + * @param Placeholder|null $placeholder The compiler placeholder object. + * @param Language|null $language The compiler Language object. + * @param Field|null $field The compiler field data object. + * @param FieldName|null $fieldName The compiler field name object. + * @param Filesfolders|null $filesFolders The compiler files folders object. + * @param Libraries|null $libraries The compiler libraries model object. + * @param Dynamicget|null $dynamic The compiler dynamic get data object. + * @param \JDatabaseDriver|null $db The database object. + * + * @since 3.2.0 + */ + public function __construct(?Config $config = null, ?Customcode $customcode = null, + ?Gui $gui = null, ?Placeholder $placeholder = null, + ?Language $language = null, ?Field $field = null, ?FieldName $fieldName = null, + ?Filesfolders $filesFolders = null, ?Libraries $libraries = null, + ?Dynamicget $dynamic = null, ?\JDatabaseDriver $db = null) + { + $this->config = $config ?: Compiler::_('Config'); + $this->customcode = $customcode ?: Compiler::_('Customcode'); + $this->gui = $gui ?: Compiler::_('Customcode.Gui'); + $this->placeholder = $placeholder ?: Compiler::_('Placeholder'); + $this->language = $language ?: Compiler::_('Language'); + $this->field = $field ?: Compiler::_('Field'); + $this->fieldName = $fieldName ?: Compiler::_('Field.Name'); + $this->filesFolders = $filesFolders ?: Compiler::_('Model.Filesfolders'); + $this->libraries = $libraries ?: Compiler::_('Model.Libraries'); + $this->dynamic = $dynamic ?: Compiler::_('Dynamicget.Data'); + $this->db = $db ?: Factory::getDbo(); + } + + /** + * Get the Joomla Module/s + * + * @param int|null $id the module id + * + * @return object|array|null if ID found it returns object, if no ID given it returns all set + * @since 3.2.0 + */ + public function get(int $id = null) + { + if (is_null($id) && $this->exists()) + { + return $this->data; + } + elseif ($this->exists($id)) + { + return $this->data[$id]; + } + + return null; + } + + /** + * Check if the Joomla Module/s exists + * + * @param int|null $id the module id + * + * @return bool if ID found it returns true, if no ID given it returns true if any are set + * @since 3.2.0 + */ + public function exists(int $id = null): bool + { + if (is_null($id)) + { + return ArrayHelper::check($this->data); + } + elseif (isset($this->data[$id])) + { + return true; + } + + return $this->set($id); + } + + /** + * Set the Joomla Module + * + * @param int $id the module id + * + * @return bool true on success + * @since 3.2.0 + */ + public function set(int $id): bool + { + if (isset($this->data[$id])) + { + return true; + } + else + { + // Create a new query object. + $query = $this->db->getQuery(true); + + $query->select('a.*'); + $query->select( + $this->db->quoteName( + array( + 'f.addfiles', + 'f.addfolders', + 'f.addfilesfullpath', + 'f.addfoldersfullpath', + 'f.addurls', + 'u.version_update', + 'u.id' + ), array( + 'addfiles', + 'addfolders', + 'addfilesfullpath', + 'addfoldersfullpath', + 'addurls', + 'version_update', + 'version_update_id' + ) + ) + ); + // from these tables + $query->from('#__componentbuilder_joomla_module AS a'); + $query->join( + 'LEFT', $this->db->quoteName( + '#__componentbuilder_joomla_module_updates', 'u' + ) . ' ON (' . $this->db->quoteName('a.id') . ' = ' + . $this->db->quoteName('u.joomla_module') . ')' + ); + $query->join( + 'LEFT', $this->db->quoteName( + '#__componentbuilder_joomla_module_files_folders_urls', 'f' + ) . ' ON (' . $this->db->quoteName('a.id') . ' = ' + . $this->db->quoteName('f.joomla_module') . ')' + ); + $query->where($this->db->quoteName('a.id') . ' = ' . (int) $id); + $query->where($this->db->quoteName('a.published') . ' >= 1'); + $this->db->setQuery($query); + $this->db->execute(); + if ($this->db->getNumRows()) + { + // get the module data + $module = $this->db->loadObject(); + + // tweak system to set stuff to the module domain + $_backup_target = $this->config->build_target; + $_backup_lang = $this->config->lang_target; + $_backup_langPrefix = $this->config->lang_prefix; + + // set some keys + $module->target_type = 'M0dU|3'; + $module->key = $module->id . '_' . $module->target_type; + + // update to point to module + $this->config->build_target = $module->key; + $this->config->lang_target = $module->key; + + // set version if not set + if (empty($module->module_version)) + { + $module->module_version = '1.0.0'; + } + + // set target client + if ($module->target == 2) + { + $module->target_client = 'administrator'; + } + else + { + // default is site area + $module->target_client = 'site'; + } + + // set GUI mapper + $guiMapper = array('table' => 'joomla_module', + 'id' => (int) $id, 'type' => 'php'); + // update the name if it has dynamic values + $module->name = $this->placeholder->update_( + $this->customcode->update($module->name) + ); + + // set safe class function name + $module->code_name + = ClassfunctionHelper::safe( + $module->name + ); + + // alias of code name + $module->class_name = $module->code_name; + // set official name + $module->official_name = StringHelper::safe( + $module->name, 'W' + ); + $this->config->set('lang_prefix', 'MOD_' . strtoupper((string) $module->code_name)); + + // set lang prefix + $module->lang_prefix = $this->config->lang_prefix; + + // set module class name + $module->class_helper_name = 'Mod' . ucfirst((string) $module->code_name) + . 'Helper'; + $module->class_data_name = 'Mod' . ucfirst((string) $module->code_name) + . 'Data'; + + // set module install class name + $module->installer_class_name = 'mod_' . ucfirst( + (string) $module->code_name + ) . 'InstallerScript'; + + // set module folder name + $module->folder_name = 'mod_' . strtolower((string) $module->code_name); + + // set the zip name + $module->zip_name = $module->folder_name . '_v' . str_replace( + '.', '_', (string) $module->module_version + ) . '__J' . $this->config->joomla_version; + + // set module file name + $module->file_name = $module->folder_name; + + // set module context + $module->context = $module->file_name . '.' . $module->id; + + // set official_name lang strings + $this->language->set( + $module->key, $this->config->lang_prefix, $module->official_name + ); + + // set some placeholder for this module + $this->placeholder->set('Module_name', $module->official_name); + $this->placeholder->set('Module', ucfirst( + (string) $module->code_name + )); + $this->placeholder->set('module', strtolower( + (string) $module->code_name + )); + $this->placeholder->set('module.version', $module->module_version); + $this->placeholder->set('module_version', str_replace( + '.', '_', (string) $module->module_version + )); + // set description (TODO) add description field to module + if (!isset($module->description) + || !StringHelper::check( + $module->description + )) + { + $module->description = ''; + } + else + { + $module->description = $this->placeholder->update_( + $this->customcode->update($module->description) + ); + $this->language->set( + $module->key, $module->lang_prefix . '_DESCRIPTION', + $module->description + ); + $module->description = '

' . $module->description + . '

'; + } + + // get author name + $project_author = $this->config->project_author; + + // set the description + $module->xml_description = "

" . $module->official_name + . " (v." . $module->module_version + . ")

" + . $module->description . "

Created by " . trim( + (string) OutputFilter::cleanText($project_author) + ) . "
Development started " + . Factory::getDate($module->created)->format("jS F, Y") + . "

"; + + // set xml description + $this->language->set( + $module->key, $module->lang_prefix . '_XML_DESCRIPTION', + $module->xml_description + ); + + // update the readme if set + if ($module->addreadme == 1 && !empty($module->readme)) + { + $module->readme = $this->placeholder->update_( + $this->customcode->update(base64_decode((string) $module->readme)) + ); + } + else + { + $module->addreadme = 0; + unset($module->readme); + } + + // get the custom_get + $module->custom_get = (isset($module->custom_get) + && JsonHelper::check($module->custom_get)) + ? json_decode((string) $module->custom_get, true) : null; + + if (ArrayHelper::check($module->custom_get)) + { + $module->custom_get = $this->dynamic->get( + $module->custom_get, $module->key, $module->key + ); + } + else + { + $module->custom_get = null; + } + + // set helper class details + if ($module->add_class_helper >= 1 + && StringHelper::check( + $module->class_helper_code + )) + { + if ($module->add_class_helper_header == 1 + && StringHelper::check( + $module->class_helper_header + )) + { + // set GUI mapper field + $guiMapper['field'] = 'class_helper_header'; + // base64 Decode code + $module->class_helper_header = PHP_EOL + . $this->gui->set( + $this->placeholder->update_( + $this->customcode->update( + base64_decode( + (string) $module->class_helper_header + ) + ) + ), + $guiMapper + ) . PHP_EOL; + } + else + { + $module->add_class_helper_header = 0; + $module->class_helper_header = ''; + } + // set GUI mapper field + $guiMapper['field'] = 'class_helper_code'; + // base64 Decode code + $module->class_helper_code = $this->gui->set( + $this->placeholder->update_( + $this->customcode->update( + base64_decode((string) $module->class_helper_code) + ) + ), + $guiMapper + ); + // set class type + if ($module->add_class_helper == 2) + { + $module->class_helper_type = 'abstract class '; + } + else + { + $module->class_helper_type = 'class '; + } + } + else + { + $module->add_class_helper = 0; + $module->class_helper_code = ''; + $module->class_helper_header = ''; + } + + // base64 Decode mod_code + if (isset($module->mod_code) + && StringHelper::check($module->mod_code)) + { + // set GUI mapper field + $guiMapper['field'] = 'mod_code'; + $module->mod_code = $this->gui->set( + $this->placeholder->update_( + $this->customcode->update( + base64_decode((string) $module->mod_code) + ) + ), + $guiMapper + ); + } + else + { + $module->mod_code = "// get the module class sfx"; + $module->mod_code .= PHP_EOL + . "\$moduleclass_sfx = htmlspecialchars(\$params->get('moduleclass_sfx'), ENT_COMPAT, 'UTF-8');"; + $module->mod_code .= PHP_EOL . "// load the default Tmpl"; + $module->mod_code .= PHP_EOL + . "require JModuleHelper::getLayoutPath('mod_" + . strtolower((string) $module->code_name) + . "', \$params->get('layout', 'default'));"; + } + + // base64 Decode default header + if (isset($module->default_header) + && StringHelper::check( + $module->default_header + )) + { + // set GUI mapper field + $guiMapper['field'] = 'default_header'; + $module->default_header = $this->gui->set( + $this->placeholder->update_( + $this->customcode->update( + base64_decode((string) $module->default_header) + ) + ), + $guiMapper + ); + } + else + { + $module->default_header = ''; + } + + // base64 Decode default + if (isset($module->default) + && StringHelper::check($module->default)) + { + // set GUI mapper field + $guiMapper['field'] = 'default'; + $guiMapper['type'] = 'html'; + $module->default = $this->gui->set( + $this->placeholder->update_( + $this->customcode->update( + base64_decode((string) $module->default) + ) + ), + $guiMapper + ); + } + else + { + $module->default = '

No Tmpl set

'; + } + + // start the config array + $module->config_fields = []; + // create the form arrays + $module->form_files = []; + $module->fieldsets_label = []; + $module->fieldsets_paths = []; + $module->add_rule_path = []; + $module->add_field_path = []; + // set global fields rule to default component path + $module->fields_rules_paths = 1; + // set the fields data + $module->fields = (isset($module->fields) + && JsonHelper::check($module->fields)) + ? json_decode((string) $module->fields, true) : null; + if (ArrayHelper::check($module->fields)) + { + // ket global key + $key = $module->key; + $dynamic_fields = array('fieldset' => 'basic', + 'fields_name' => 'params', + 'file' => 'config'); + foreach ($module->fields as $n => &$form) + { + if (isset($form['fields']) + && ArrayHelper::check( + $form['fields'] + )) + { + // make sure the dynamic_field is set to dynamic_value by default + foreach ( + $dynamic_fields as $dynamic_field => + $dynamic_value + ) + { + if (!isset($form[$dynamic_field]) + || !StringHelper::check( + $form[$dynamic_field] + )) + { + $form[$dynamic_field] = $dynamic_value; + } + else + { + if ('fields_name' === $dynamic_field + && strpos((string) $form[$dynamic_field], '.') + !== false) + { + $form[$dynamic_field] + = $form[$dynamic_field]; + } + else + { + $form[$dynamic_field] + = StringHelper::safe( + $form[$dynamic_field] + ); + } + } + } + // check if field is external form file + if (!isset($form['module']) || $form['module'] != 1) + { + // now build the form key + $unique = $form['file'] . $form['fields_name'] + . $form['fieldset']; + } + else + { + // now build the form key + $unique = $form['fields_name'] + . $form['fieldset']; + } + // set global fields rule path switches + if ($module->fields_rules_paths == 1 + && isset($form['fields_rules_paths']) + && $form['fields_rules_paths'] == 2) + { + $module->fields_rules_paths = 2; + } + // set where to path is pointing + $module->fieldsets_paths[$unique] + = $form['fields_rules_paths']; + // check for extra rule paths + if (isset($form['addrulepath']) + && ArrayHelper::check($form['addrulepath'])) + { + foreach ($form['addrulepath'] as $add_rule_path) + { + if (StringHelper::check($add_rule_path['path'])) + { + $module->add_rule_path[$unique] = $add_rule_path['path']; + } + } + } + // check for extra field paths + if (isset($form['addfieldpath']) + && ArrayHelper::check($form['addfieldpath'])) + { + foreach ($form['addfieldpath'] as $add_field_path) + { + if (StringHelper::check($add_field_path['path'])) + { + $module->add_field_path[$unique] = $add_field_path['path']; + } + } + } + // add the label if set to lang + if (isset($form['label']) + && StringHelper::check( + $form['label'] + )) + { + $module->fieldsets_label[$unique] + = $this->language->key($form['label']); + } + // build the fields + $form['fields'] = array_map( + function ($field) use ($key, $unique) { + // make sure the alias and title is 0 + $field['alias'] = 0; + $field['title'] = 0; + // set the field details + $this->field->set( + $field, $key, $key, $unique + ); + // update the default if set + if (StringHelper::check( + $field['custom_value'] + ) + && isset($field['settings'])) + { + if (($old_default + = GetHelper::between( + $field['settings']->xml, + 'default="', '"', false + )) !== false) + { + // replace old default + $field['settings']->xml + = str_replace( + 'default="' . $old_default + . '"', 'default="' + . $field['custom_value'] . '"', + (string) $field['settings']->xml + ); + } + else + { + // add the default (hmmm not ideal but okay it should work) + $field['settings']->xml + = 'default="' + . $field['custom_value'] . '" ' + . $field['settings']->xml; + } + } + unset($field['custom_value']); + + // return field + return $field; + }, array_values($form['fields']) + ); + // check if field is external form file + if (!isset($form['module']) || $form['module'] != 1) + { + // load the form file + if (!isset($module->form_files[$form['file']])) + { + $module->form_files[$form['file']] + = []; + } + if (!isset($module->form_files[$form['file']][$form['fields_name']])) + { + $module->form_files[$form['file']][$form['fields_name']] + = []; + } + if (!isset($module->form_files[$form['file']][$form['fields_name']][$form['fieldset']])) + { + $module->form_files[$form['file']][$form['fields_name']][$form['fieldset']] + = []; + } + // do some house cleaning (for fields) + foreach ($form['fields'] as $field) + { + // so first we lock the field name in + $this->fieldName->get( + $field, $module->key, $unique + ); + // add the fields to the global form file builder + $module->form_files[$form['file']][$form['fields_name']][$form['fieldset']][] + = $field; + } + // remove form + unset($module->fields[$n]); + } + else + { + // load the config form + if (!isset($module->config_fields[$form['fields_name']])) + { + $module->config_fields[$form['fields_name']] + = []; + } + if (!isset($module->config_fields[$form['fields_name']][$form['fieldset']])) + { + $module->config_fields[$form['fields_name']][$form['fieldset']] + = []; + } + // do some house cleaning (for fields) + foreach ($form['fields'] as $field) + { + // so first we lock the field name in + $this->fieldName->get( + $field, $module->key, $unique + ); + // add the fields to the config builder + $module->config_fields[$form['fields_name']][$form['fieldset']][] + = $field; + } + // remove form + unset($module->fields[$n]); + } + } + else + { + unset($module->fields[$n]); + } + } + } + unset($module->fields); + + // set files and folders + $this->filesFolders->set($module); + + // set libraries + $this->libraries->set($module->code_name, $module); + + // add PHP in module install + $module->add_install_script = true; + $addScriptMethods = [ + 'php_script', + 'php_preflight', + 'php_postflight', + 'php_method' + ]; + $addScriptTypes = [ + 'install', + 'update', + 'uninstall' + ]; + // the next are php placeholders + $guiMapper['type'] = 'php'; + foreach ($addScriptMethods as $scriptMethod) + { + foreach ($addScriptTypes as $scriptType) + { + if (isset($module->{'add_' . $scriptMethod . '_' . $scriptType}) + && $module->{'add_' . $scriptMethod . '_' . $scriptType} == 1 + && StringHelper::check( + $module->{$scriptMethod . '_' . $scriptType} + )) + { + // set GUI mapper field + $guiMapper['field'] = $scriptMethod . '_' . $scriptType; + $module->{$scriptMethod . '_' . $scriptType} = $this->gui->set( + $this->placeholder->update_( + $this->customcode->update( + base64_decode( + (string) $module->{$scriptMethod . '_' . $scriptType} + ) + ) + ), + $guiMapper + ); + } + else + { + unset($module->{$scriptMethod . '_' . $scriptType}); + $module->{'add_' . $scriptMethod . '_' . $scriptType} = 0; + } + } + } + + // add_sql + if ($module->add_sql == 1 + && StringHelper::check($module->sql)) + { + $module->sql = $this->placeholder->update_( + $this->customcode->update(base64_decode((string) $module->sql)) + ); + } + else + { + unset($module->sql); + $module->add_sql = 0; + } + + // add_sql_uninstall + if ($module->add_sql_uninstall == 1 + && StringHelper::check( + $module->sql_uninstall + )) + { + $module->sql_uninstall = $this->placeholder->update_( + $this->customcode->update( + base64_decode((string) $module->sql_uninstall) + ) + ); + } + else + { + unset($module->sql_uninstall); + $module->add_sql_uninstall = 0; + } + + // update the URL of the update_server if set + if ($module->add_update_server == 1 + && StringHelper::check( + $module->update_server_url + )) + { + $module->update_server_url = $this->placeholder->update_( + $this->customcode->update($module->update_server_url) + ); + } + + // add the update/sales server FTP details if that is the expected protocol + $serverArray = array('update_server', 'sales_server'); + foreach ($serverArray as $server) + { + if ($module->{'add_' . $server} == 1 + && is_numeric( + $module->{$server} + ) + && $module->{$server} > 0) + { + // get the server protocol + $module->{$server . '_protocol'} + = GetHelper::var( + 'server', (int) $module->{$server}, 'id', 'protocol' + ); + } + else + { + $module->{$server} = 0; + // only change this for sales server (update server can be added loacaly to the zip file) + if ('sales_server' === $server) + { + $module->{'add_' . $server} = 0; + } + $module->{$server . '_protocol'} = 0; + } + } + + // set the update server stuff (TODO) + // update_server_xml_path + // update_server_xml_file_name + + // rest globals + $this->config->build_target = $_backup_target; + $this->config->lang_target = $_backup_lang; + $this->config->lang_prefix = $_backup_langPrefix; + + $this->placeholder->remove('Module_name'); + $this->placeholder->remove('Module'); + $this->placeholder->remove('module'); + $this->placeholder->remove('module.version'); + $this->placeholder->remove('module_version'); + + $this->data[$id] = $module; + + return true; + } + } + + return false; + } diff --git a/src/cdc9b06d-8333-4fa7-ab4d-b810dd90f95f/code.power b/src/cdc9b06d-8333-4fa7-ab4d-b810dd90f95f/code.power new file mode 100644 index 0000000..30e35d4 --- /dev/null +++ b/src/cdc9b06d-8333-4fa7-ab4d-b810dd90f95f/code.power @@ -0,0 +1,33 @@ + /** + * Fix the path to work in the JCB script <-- (main issue here) + * Since we need / slash in all paths, for the JCB script even if it is Windows + * and since MS works with both forward and back slashes + * we just convert all slashes to forward slashes + * + * THIS is just my hack (fix) if you know a better way! speak-up! + * + * @param mixed $values the array of paths or the path as a string + * @param array $targets paths to target + * + * @return void + * @since 3.2.0 + */ + public function set(&$values, array $targets = []) + { + // if multiple to gets searched and fixed + if (ArrayHelper::check($values) && ArrayHelper::check($targets)) + { + foreach ($targets as $target) + { + if (isset($values[$target])) + { + $this->set($values[$target], $targets); + } + } + } + // if just a string + elseif (StringHelper::check($values) && strpos((string) $values, '\\') !== false) + { + $values = str_replace('\\', '/', (string) $values); + } + } diff --git a/src/ce826b66-0f2d-43da-8005-41b8e4cb21ee/code.power b/src/ce826b66-0f2d-43da-8005-41b8e4cb21ee/code.power new file mode 100644 index 0000000..0b77a60 --- /dev/null +++ b/src/ce826b66-0f2d-43da-8005-41b8e4cb21ee/code.power @@ -0,0 +1,291 @@ + /** + * Compiler Fields + * + * @var array + * @since 3.2.0 + */ + protected array $fields; + + /** + * Compiler Config + * + * @var Config + * @since 3.2.0 + */ + protected Config $config; + + /** + * Compiler Event + * + * @var EventInterface + * @since 3.2.0 + */ + protected EventInterface $event; + + /** + * Compiler History + * + * @var HistoryInterface + * @since 3.2.0 + */ + protected HistoryInterface $history; + + /** + * Compiler Placeholder + * + * @var Placeholder + * @since 3.2.0 + */ + protected Placeholder $placeholder; + + /** + * Compiler Customcode + * + * @var Customcode + * @since 3.2.0 + */ + protected Customcode $customcode; + + /** + * Compiler Field Customcode + * + * @var FieldCustomcode + * @since 3.2.0 + */ + protected FieldCustomcode $fieldCustomcode; + + /** + * Compiler Field Validation + * + * @var Validation + * @since 3.2.0 + */ + protected Validation $validation; + + /** + * Database object to query local DB + * + * @var \JDatabaseDriver + * @since 3.2.0 + **/ + protected \JDatabaseDriver $db; + + /** + * Constructor + * + * @param Config|null $config The compiler config object. + * @param EventInterface|null $event The compiler event api object. + * @param HistoryInterface|null $history The compiler history object. + * @param Placeholder|null $placeholder The compiler placeholder object. + * @param Customcode|null $customcode The compiler customcode object. + * @param FieldCustomcode|null $fieldCustomcode The field customcode object. + * @param Validation|null $validation The field validation rule object. + * @param \JDatabaseDriver|null $db The database object. + * + * @since 3.2.0 + */ + public function __construct(?Config $config = null, ?EventInterface $event = null, ?HistoryInterface $history = null, + ?Placeholder $placeholder = null, ?Customcode $customcode = null, ?FieldCustomcode $fieldCustomcode = null, + ?Validation $validation = null, ?\JDatabaseDriver $db = null) + { + $this->config = $config ?: Compiler::_('Config'); + $this->event = $event ?: Compiler::_('Event'); + $this->history = $history ?: Compiler::_('History'); + $this->placeholder = $placeholder ?: Compiler::_('Placeholder'); + $this->customcode = $customcode ?: Compiler::_('Customcode'); + $this->fieldCustomcode = $fieldCustomcode ?: Compiler::_('Field.Customcode'); + $this->validation = $validation ?: Compiler::_('Field.Validation'); + $this->db = $db ?: Factory::getDbo(); + } + + /** + * Get all Field Data + * + * @param int $id The field ID + * @param string|null $singleViewName The view edit or single name + * @param string|null $listViewName The view list name + * + * @return object|null The field data + * @since 3.2.0 + */ + public function get(int $id, ?string $singleViewName = null, ?string $listViewName = null): ?object + { + if ($id > 0 && !isset($this->fields[$id])) + { + // Create a new query object. + $query = $this->db->getQuery(true); + + // Select all the values in the field + $query->select('a.*'); + $query->select( + $this->db->quoteName( + array('c.name', 'c.properties'), + array('type_name', 'properties') + ) + ); + $query->from('#__componentbuilder_field AS a'); + $query->join( + 'LEFT', + $this->db->quoteName('#__componentbuilder_fieldtype', 'c') + . ' ON (' . $this->db->quoteName('a.fieldtype') . ' = ' + . $this->db->quoteName('c.id') . ')' + ); + $query->where( + $this->db->quoteName('a.id') . ' = ' . $this->db->quote($id) + ); + + // TODO we need to update the event signatures + $context = $this->config->component_context; + + // Trigger Event: jcb_ce_onBeforeQueryFieldData + $this->event->trigger( + 'jcb_ce_onBeforeQueryFieldData', + array(&$context, &$id, &$query, &$this->db) + ); + + // Reset the query using our newly populated query object. + $this->db->setQuery($query); + $this->db->execute(); + if ($this->db->getNumRows()) + { + // Load the results as a list of stdClass objects (see later for more options on retrieving data). + $field = $this->db->loadObject(); + + // Trigger Event: jcb_ce_onBeforeModelFieldData + $this->event->trigger( + 'jcb_ce_onBeforeModelFieldData', + array(&$context, &$field) + ); + + // adding a fix for the changed name of type to fieldtype + $field->type = $field->fieldtype; + + // load the values form params + $field->xml = $this->customcode->update(json_decode((string) $field->xml)); + + // check if we have validate (validation rule and set it if found) + $this->validation->set($id, $field->xml); + + // load the type values form type params + $field->properties = (isset($field->properties) + && JsonHelper::check($field->properties)) + ? json_decode((string) $field->properties, true) : null; + if (ArrayHelper::check($field->properties)) + { + $field->properties = array_values($field->properties); + } + + // check if we have WHMCS encryption + if (4 == $field->store + && !$this->config->whmcs_encryption) + { + $this->config->whmcs_encryption = true; + } + // check if we have basic encryption + elseif (3 == $field->store + && !$this->config->basic_encryption) + { + $this->config->basic_encryption = true; + } + // check if we have better encryption + elseif (5 == $field->store + && $this->config->medium_encryption) + { + $this->config->medium_encryption = true; + } + // check if we have better encryption + elseif (6 == $field->store + && StringHelper::check( + $field->on_get_model_field + ) + && StringHelper::check( + $field->on_save_model_field + )) + { + // add only if string lenght found + if (StringHelper::check( + $field->initiator_on_save_model + )) + { + $field->initiator_save_key = md5( + (string) $field->initiator_on_save_model + ); + $field->initiator_save = explode( + PHP_EOL, $this->placeholder->update_( + $this->customcode->update( + base64_decode( + (string) $field->initiator_on_save_model + ) + ) + ) + ); + } + if (StringHelper::check( + $field->initiator_on_save_model + )) + { + $field->initiator_get_key = md5( + (string) $field->initiator_on_get_model + ); + $field->initiator_get = explode( + PHP_EOL, $this->placeholder->update_( + $this->customcode->update( + base64_decode( + (string) $field->initiator_on_get_model + ) + ) + ) + ); + } + // set the field modelling + $field->model_field['save'] = explode( + PHP_EOL, $this->placeholder->update_( + $this->customcode->update( + base64_decode((string) $field->on_save_model_field) + ) + ) + ); + $field->model_field['get'] = explode( + PHP_EOL, $this->placeholder->update_( + $this->customcode->update( + base64_decode((string) $field->on_get_model_field) + ) + ) + ); + // remove the original values + unset( + $field->on_save_model_field, + $field->on_get_model_field, + $field->initiator_on_save_model, + $field->initiator_on_get_model + ); + } + + // get the last used version + $field->history = $this->history->get('field', $id); + + // Trigger Event: jcb_ce_onAfterModelFieldData + $this->event->trigger( + 'jcb_ce_onAfterModelFieldData', + array(&$context, &$field) + ); + + $this->fields[$id] = $field; + } + else + { + return null; + } + } + + if ($id > 0 && isset($this->fields[$id])) + { + // update the customcode of the field + $this->fieldCustomcode->update($id, $this->fields[$id], $singleViewName, $listViewName); + + // return the field + return $this->fields[$id]; + } + + return null; + } diff --git a/src/cebdcccb-24c5-46db-92de-63453852dcb8/code.power b/src/cebdcccb-24c5-46db-92de-63453852dcb8/code.power new file mode 100644 index 0000000..0cc9452 --- /dev/null +++ b/src/cebdcccb-24c5-46db-92de-63453852dcb8/code.power @@ -0,0 +1,151 @@ + /** + * Component Admin view Data + * + * @var Adminview + * @since 3.2.0 + **/ + protected Adminview $admin; + + /** + * Compiler registry + * + * @var Registry + * @since 3.2.0 + */ + protected Registry $registry; + + /** + * Compiler Config + * + * @var Config + * @since 3.2.0 + **/ + protected Config $config; + + /** + * Constructor + * + * @param Adminview|null $admin The admin view data object. + * @param Registry|null $registry The compiler registry object. + * @param Config|null $config The compiler config object. + * + * @since 3.2.0 + */ + public function __construct(?Adminview $admin = null, ?Registry $registry = null, ?Config $config = null) + { + $this->admin = $admin ?: Compiler::_('Adminview.Data'); + $this->registry = $registry ?: Compiler::_('Registry'); + $this->config = $config ?: Compiler::_('Config'); + } + + /** + * Set admin view data + * + * @param object $item The extension data + * + * @return void + * @since 3.2.0 + */ + public function set(object &$item) + { + $item->addadmin_views = (isset($item->addadmin_views) + && JsonHelper::check($item->addadmin_views)) + ? json_decode((string) $item->addadmin_views, true) : null; + + if (ArrayHelper::check($item->addadmin_views)) + { + $this->config->lang_target = 'admin'; + $this->config->build_target = 'admin'; + + // sort the views according to order + usort( + $item->addadmin_views, function ($a, $b) { + if ($a['order'] != 0 && $b['order'] != 0) + { + return $a['order'] - $b['order']; + } + elseif ($b['order'] != 0 && $a['order'] == 0) + { + return 1; + } + elseif ($a['order'] != 0 && $b['order'] == 0) + { + return 0; + } + + return 1; + } + ); + + // build the admin_views settings + $item->admin_views = array_map( + function ($array) { + $array = array_map( + function ($value) { + if (!ArrayHelper::check($value) + && !ObjectHelper::check($value) + && strval($value) === strval(intval($value))) + { + return (int) $value; + } + + return $value; + }, $array + ); + + // check if we must add to site + if (isset($array['edit_create_site_view']) + && is_numeric( + $array['edit_create_site_view'] + ) && $array['edit_create_site_view'] > 0) + { + $this->registry->set('builder.site_edit_view.' . $array['adminview'], true); + $this->config->lang_target = 'both'; + } + + // set the import/export option for this view + if (isset($array['port']) && $array['port']) + { + $this->config->set('add_eximport', true); + } + + // set the history tracking option for this view + if (isset($array['history']) && $array['history']) + { + $this->config->set('set_tag_history', true); + } + + // set the custom field integration for this view + if (isset($array['joomla_fields']) && $array['joomla_fields']) + { + $this->config->set('set_joomla_fields', true); + } + + // has become a legacy issue, can't remove this + $array['view'] = $array['adminview']; + + // get the admin settings/data + $array['settings'] = $this->admin->get( + $array['view'] + ); + + // set the filter option for this view + $this->registry-> // Side (old) [default for now] + set('builder.admin_filter_type.' . $array['settings']->name_list_code, 1); + + if (isset($array['filter']) + && is_numeric( + $array['filter'] + ) && $array['filter'] > 0) + { + $this->registry-> + set('builder.admin_filter_type.' . $array['settings']->name_list_code, + (int) $array['filter']); + } + + return $array; + + }, array_values($item->addadmin_views) + ); + } + } diff --git a/src/cef2815b-f72b-402a-b769-f028f676692d/code.power b/src/cef2815b-f72b-402a-b769-f028f676692d/code.power new file mode 100644 index 0000000..ba94cf1 --- /dev/null +++ b/src/cef2815b-f72b-402a-b769-f028f676692d/code.power @@ -0,0 +1,492 @@ + /** + * Admin views + * + * @var array + * @since 3.2.0 + */ + protected array $data; + + /** + * Compiler Config + * + * @var Config + * @since 3.2.0 + */ + protected Config $config; + + /** + * The compiler registry + * + * @var Registry + * @since 3.2.0 + */ + protected Registry $registry; + + /** + * Compiler Event + * + * @var EventInterface + * @since 3.2.0 + */ + protected EventInterface $event; + + /** + * Compiler Placeholder + * + * @var Placeholder + * @since 3.2.0 + */ + protected Placeholder $placeholder; + + /** + * Compiler Customcode Dispenser + * + * @var Dispenser + * @since 3.2.0 + */ + protected Dispenser $dispenser; + + /** + * The modelling customtabs + * + * @var Customtabs + * @since 3.2.0 + */ + protected Customtabs $customtabs; + + /** + * The modelling tabs + * + * @var Tabs + * @since 3.2.0 + */ + protected Tabs $tabs; + + /** + * The modelling fields + * + * @var Fields + * @since 3.2.0 + */ + protected Fields $fields; + + /** + * The modelling admin view history + * + * @var Historyadminview + * @since 3.2.0 + */ + protected Historyadminview $history; + + /** + * The modelling permissions + * + * @var Permissions + * @since 3.2.0 + */ + protected Permissions $permissions; + + /** + * The modelling conditions + * + * @var Conditions + * @since 3.2.0 + */ + protected Conditions $conditions; + + /** + * The modelling relations + * + * @var Relations + * @since 3.2.0 + */ + protected Relations $relations; + + /** + * The modelling linked views + * + * @var Linkedviews + * @since 3.2.0 + */ + protected Linkedviews $linkedviews; + + /** + * The modelling javascript + * + * @var Javascriptadminview + * @since 3.2.0 + */ + protected Javascriptadminview $javascript; + + /** + * The modelling css + * + * @var Cssadminview + * @since 3.2.0 + */ + protected Cssadminview $css; + + /** + * The modelling php admin view + * + * @var Phpadminview + * @since 3.2.0 + */ + protected Phpadminview $php; + + /** + * The modelling custom buttons + * + * @var Custombuttons + * @since 3.2.0 + */ + protected Custombuttons $custombuttons; + + /** + * The modelling custom import scripts + * + * @var Customimportscripts + * @since 3.2.0 + */ + protected Customimportscripts $customimportscripts; + + /** + * The modelling ajax + * + * @var Ajaxadmin + * @since 3.2.0 + */ + protected Ajaxadmin $ajax; + + /** + * The modelling custom alias + * + * @var Customalias + * @since 3.2.0 + */ + protected Customalias $customalias; + + /** + * The modelling sql + * + * @var Sql + * @since 3.2.0 + */ + protected Sql $sql; + + /** + * The modelling mysql settings + * + * @var Mysqlsettings + * @since 3.2.0 + */ + protected Mysqlsettings $mysqlsettings; + + /** + * Database object to query local DB + * + * @var \JDatabaseDriver + * @since 3.2.0 + **/ + protected \JDatabaseDriver $db; + + /** + * Constructor + * + * @param Config|null $config The compiler config object. + * @param Registry|null $registry The compiler registry object. + * @param EventInterface|null $event The compiler event api object. + * @param Placeholder|null $placeholder The compiler placeholder object. + * @param Dispenser|null $dispenser The compiler customcode dispenser object. + * @param Customtabs|null $customtabs The modelling customtabs object. + * @param Tabs|null $tabs The modelling tabs object. + * @param Fields|null $fields The modelling fields object. + * @param Historyadminview|null $history The modelling admin view history object. + * @param Permissions|null $permissions The modelling permissions object. + * @param Conditions|null $conditions The modelling conditions object. + * @param Relations|null $relations The modelling relations object. + * @param Linkedviews|null $linkedviews The modelling linked views object. + * @param Javascriptadminview|null $javascript The modelling javascript object. + * @param Cssadminview|null $css The modelling css object. + * @param Phpadminview|null $php The modelling php admin view object. + * @param Custombuttons|null $custombuttons The modelling custom buttons object. + * @param Customimportscripts|null $customimportscripts The modelling custom import scripts object. + * @param Ajaxadmin|null $ajax The modelling ajax object. + * @param Customalias|null $customalias The modelling custom alias object. + * @param Sql|null $sql The modelling sql object. + * @param Mysqlsettings|null $mysqlsettings The modelling mysql settings object. + * @param \JDatabaseDriver|null $db The database object. + * + * @since 3.2.0 + */ + public function __construct(?Config $config = null, ?Registry $registry = null, + ?EventInterface $event = null, ?Placeholder $placeholder = null, ?Dispenser $dispenser = null, + ?Customtabs $customtabs = null, ?Tabs $tabs = null, ?Fields $fields = null, + ?Historyadminview $history = null, ?Permissions $permissions = null, + ?Conditions $conditions = null, Relations $relations = null, ?Linkedviews $linkedviews = null, + ?Javascriptadminview $javascript = null, ?Cssadminview $css = null, ?Phpadminview $php = null, + ?Custombuttons $custombuttons = null, ?Customimportscripts $customimportscripts = null, + ?Ajaxadmin $ajax = null, ?Customalias $customalias = null, ?Sql $sql = null, + ?Mysqlsettings $mysqlsettings = null, ?\JDatabaseDriver $db = null) + { + $this->config = $config ?: Compiler::_('Config'); + $this->registry = $registry ?: Compiler::_('Registry'); + $this->event = $event ?: Compiler::_('Event'); + $this->placeholder = $placeholder ?: Compiler::_('Placeholder'); + $this->dispenser = $dispenser ?: Compiler::_('Customcode.Dispenser'); + $this->customtabs = $customtabs ?: Compiler::_('Model.Customtabs'); + $this->tabs = $tabs ?: Compiler::_('Model.Tabs'); + $this->fields = $fields ?: Compiler::_('Model.Fields'); + $this->history = $history ?: Compiler::_('Model.Historyadminview'); + $this->permissions = $permissions ?: Compiler::_('Model.Permissions'); + $this->conditions = $conditions ?: Compiler::_('Model.Conditions'); + $this->relations = $relations ?: Compiler::_('Model.Relations'); + $this->linkedviews = $linkedviews ?: Compiler::_('Model.Linkedviews'); + $this->javascript = $javascript ?: Compiler::_('Model.Javascriptadminview'); + $this->css = $css ?: Compiler::_('Model.Cssadminview'); + $this->php = $php ?: Compiler::_('Model.Phpadminview'); + $this->custombuttons = $custombuttons ?: Compiler::_('Model.Custombuttons'); + $this->customimportscripts = $customimportscripts ?: Compiler::_('Model.Customimportscripts'); + $this->ajax = $ajax ?: Compiler::_('Model.Ajaxadmin'); + $this->customalias = $customalias ?: Compiler::_('Model.Customalias'); + $this->sql = $sql ?: Compiler::_('Model.Sql'); + $this->mysqlsettings = $mysqlsettings ?: Compiler::_('Model.Mysqlsettings'); + $this->db = $db ?: Factory::getDbo(); + } + + /** + * Get Admin View Data + * + * @param int $id The view ID + * + * @return object|null The view data + * @since 3.2.0 + */ + public function get(int $id): ?object + { + if (!isset($this->data[$id])) + { + // Create a new query object. + $query = $this->db->getQuery(true); + + $query->select('a.*'); + $query->select( + $this->db->quoteName( + array( + 'b.addfields', + 'b.id', + 'c.addconditions', + 'c.id', + 'r.addrelations', + 't.tabs' + ), array( + 'addfields', + 'addfields_id', + 'addconditions', + 'addconditions_id', + 'addrelations', + 'customtabs' + ) + ) + ); + + $query->from('#__componentbuilder_admin_view AS a'); + $query->join( + 'LEFT', + $this->db->quoteName('#__componentbuilder_admin_fields', 'b') + . ' ON (' . $this->db->quoteName('a.id') . ' = ' + . $this->db->quoteName('b.admin_view') . ')' + ); + + $query->join( + 'LEFT', $this->db->quoteName( + '#__componentbuilder_admin_fields_conditions', 'c' + ) . ' ON (' . $this->db->quoteName('a.id') . ' = ' + . $this->db->quoteName('c.admin_view') . ')' + ); + + $query->join( + 'LEFT', $this->db->quoteName( + '#__componentbuilder_admin_fields_relations', 'r' + ) . ' ON (' . $this->db->quoteName('a.id') . ' = ' + . $this->db->quoteName('r.admin_view') . ')' + ); + + $query->join( + 'LEFT', $this->db->quoteName( + '#__componentbuilder_admin_custom_tabs', 't' + ) . ' ON (' . $this->db->quoteName('a.id') . ' = ' + . $this->db->quoteName('t.admin_view') . ')' + ); + + $query->where($this->db->quoteName('a.id') . ' = ' . (int) $id); + + // for plugin event TODO change event api signatures + $component_context = $this->config->component_context; + // Trigger Event: jcb_ce_onBeforeQueryViewData + $this->event->trigger( + 'jcb_ce_onBeforeQueryViewData', + array(&$component_context, &$id, &$query, &$this->db) + ); + + // Reset the query using our newly populated query object. + $this->db->setQuery($query); + + // Load the results as a list of stdClass objects (see later for more options on retrieving data). + $view = $this->db->loadObject(); + + // setup single view code names to use in storing the data + $view->name_single_code = 'oops_hmm_' . $id; + if (isset($view->name_single) && $view->name_single != 'null') + { + $view->name_single_code = StringHelper::safe( + $view->name_single + ); + } + + // setup list view code name to use in storing the data + $view->name_list_code = 'oops_hmmm_' . $id; + if (isset($view->name_list) && $view->name_list != 'null') + { + $view->name_list_code = StringHelper::safe( + $view->name_list + ); + } + + // check the length of the view name (+5 for com_ and _) + $name_length = $this->config->component_code_name_length + strlen( + (string) $view->name_single_code + ) + 5; + // when the name is larger than 49 we need to add the assets' table name fix + if ($name_length > 49) + { + $this->config->set('add_assets_table_name_fix', true); + } + + // setup token check + if (!isset($this->dispenser->hub['token'])) + { + $this->dispenser->hub['token'] = []; + } + $this->dispenser->hub['token'][$view->name_single_code] = false; + $this->dispenser->hub['token'][$view->name_list_code] = false; + + // set some placeholders + $this->placeholder->set('view', $view->name_single_code); + $this->placeholder->set('views', $view->name_list_code); + $this->placeholder->set('View', StringHelper::safe( + $view->name_single, 'F' + )); + $this->placeholder->set('Views', StringHelper::safe( + $view->name_list, 'F' + )); + $this->placeholder->set('VIEW', StringHelper::safe( + $view->name_single, 'U' + )); + $this->placeholder->set('VIEWS', StringHelper::safe( + $view->name_list, 'U' + )); + + // for plugin event TODO change event api signatures + $placeholders = $this->placeholder->active; + $component_context = $this->config->component_context; + + // Trigger Event: jcb_ce_onBeforeModelViewData + $this->event->trigger( + 'jcb_ce_onBeforeModelViewData', + array(&$component_context, &$view, &$placeholders) + ); + unset($placeholders); + + // add the tables + $view->addtables = (isset($view->addtables) + && JsonHelper::check($view->addtables)) + ? json_decode((string) $view->addtables, true) : null; + if (ArrayHelper::check($view->addtables)) + { + $view->tables = array_values($view->addtables); + } + unset($view->addtables); + + // set custom tabs + $this->customtabs->set($view); + + // set the local tabs + $this->tabs->set($view); + + // set permissions + $this->permissions->set($view); + + // set fields + $this->fields->set($view); + + // build update SQL + $this->history->set($view); + + // set the conditions + $this->conditions->set($view); + + // set the relations + $this->relations->set($view); + + // set linked views + $this->linkedviews->set($view); + + // set the lang target + $this->config->lang_target = 'admin'; + if ($this->registry->get('builder.site_edit_view.' . $id, false)) + { + $this->config->lang_target = 'both'; + } + + // set javascript + $this->javascript->set($view); + + // set css + $this->css->set($view); + + // set php + $this->php->set($view); + + // set custom buttons + $this->custombuttons->set($view); + + // set custom import scripts + $this->customimportscripts->set($view); + + // set Ajax for this view + $this->ajax->set($view); + + // activate alias builder + $this->customalias->set($view); + + // set sql + $this->sql->set($view); + + // set mySql Table Settings + $this->mysqlsettings->set($view); + + // for plugin event TODO change event api signatures + $placeholders = $this->placeholder->active; + + // Trigger Event: jcb_ce_onAfterModelViewData + $this->event->trigger( + 'jcb_ce_onAfterModelViewData', + array(&$component_context, &$view, &$placeholders) + ); + + // clear placeholders + $this->placeholder->remove('view'); + $this->placeholder->remove('views'); + $this->placeholder->remove('View'); + $this->placeholder->remove('Views'); + $this->placeholder->remove('VIEW'); + $this->placeholder->remove('VIEWS'); + + // store this view to class object + $this->data[$id] = $view; + } + + // return the found view data + return $this->data[$id]; + } diff --git a/src/cfe62a32-8818-4bfb-8751-2f1e109b5336/code.power b/src/cfe62a32-8818-4bfb-8751-2f1e109b5336/code.power new file mode 100644 index 0000000..c1bca51 --- /dev/null +++ b/src/cfe62a32-8818-4bfb-8751-2f1e109b5336/code.power @@ -0,0 +1,179 @@ + /** + * The compiler registry + * + * @var Registry + * @since 3.2.0 + */ + protected Registry $registry; + + /** + * Compiler Component + * + * @var Component + * @since 3.2.0 + **/ + protected Component $component; + + /** + * Application object. + * + * @var CMSApplication + * @since 3.2.0 + **/ + protected CMSApplication $app; + + /** + * Constructor + * + * @param Registry|null $registry The compiler registry object. + * @param Component|null $component The component class. + * @param CMSApplication|null $app The app object. + * + * @since 3.2.0 + */ + public function __construct(?Registry $registry = null, ?Component $component = null, + ?CMSApplication $app = null) + { + $this->registry = $registry ?: Compiler::_('Registry'); + $this->component = $component ?: Compiler::_('Component'); + $this->app = $app ?: Factory::getApplication(); + } + + /** + * Set the Dynamic Dashboard + * + * @return void + * @since 3.2.0 + */ + public function set() + { + // only add the dynamic dashboard if all checks out + if ($this->component->get('dashboard_type', 0) == 2 + && ($dashboard_ = $this->component->get('dashboard')) !== null + && StringHelper::check($dashboard_) + && strpos((string) $dashboard_, '_') !== false) + { + // set the default view + $getter = explode('_', (string) $dashboard_); + if (count((array) $getter) == 2 && is_numeric($getter[1])) + { + // the pointers + $t = StringHelper::safe($getter[0], 'U'); + $id = (int) $getter[1]; + + // the dynamic stuff + $targets = array('A' => 'admin_views', + 'C' => 'custom_admin_views'); + $names = array('A' => 'admin view', + 'C' => 'custom admin view'); + $types = array('A' => 'adminview', 'C' => 'customadminview'); + $keys = array('A' => 'name_list', 'C' => 'code'); + + // check the target values + if (isset($targets[$t]) && $id > 0) + { + // set the type name + $type_names = StringHelper::safe( + $targets[$t], 'w' + ); + // set the dynamic dash + if (($target_ = $this->component->get($targets[$t])) !== null + && ArrayHelper::check($target_)) + { + // search the target views + $dashboard = (array) array_filter( + $target_, + function ($view) use ($id, $t, $types) { + if (isset($view[$types[$t]]) + && $id == $view[$types[$t]]) + { + return true; + } + + return false; + } + ); + + // set dashboard + if (ArrayHelper::check($dashboard)) + { + $dashboard = array_values($dashboard)[0]; + } + + // check if view was found (this should be true) + if (isset($dashboard['settings']) + && isset($dashboard['settings']->{$keys[$t]})) + { + $this->registry->set('build.dashboard', + StringHelper::safe( + $dashboard['settings']->{$keys[$t]} + ) + ); + $this->registry->set('build.dashboard.type', + $targets[$t] + ); + } + else + { + // set massage that something is wrong + $this->app->enqueueMessage( + Text::_('

Dashboard Error

'), + 'Error' + ); + $this->app->enqueueMessage( + Text::sprintf('The %s (%s) is not available in your component! Please insure to only used %s, for a dynamic dashboard, that are still linked to your component.', + $names[$t], $dashboard_, + $type_names + ), 'Error' + ); + } + } + else + { + // set massage that something is wrong + $this->app->enqueueMessage( + Text::_('

Dashboard Error

'), 'Error' + ); + $this->app->enqueueMessage( + Text::sprintf('The %s (%s) is not available in your component! Please insure to only used %s, for a dynamic dashboard, that are still linked to your component.', + $names[$t], $dashboard_, + $type_names + ), 'Error' + ); + } + } + else + { + // the target value is wrong + $this->app->enqueueMessage( + Text::_('

Dashboard Error

'), 'Error' + ); + $this->app->enqueueMessage( + Text::sprintf('The %s value for the dynamic dashboard is invalid.', + $dashboard_ + ), 'Error' + ); + } + } + else + { + // the target value is wrong + $this->app->enqueueMessage( + Text::_('

Dashboard Error

'), 'Error' + ); + $this->app->enqueueMessage( + Text::sprintf('The %s value for the dynamic dashboard is invalid.', + $dashboard_ + ), 'Error' + ); + } + + // if default was changed to dynamic dashboard the remove default tab and methods + if ($this->registry->get('build.dashboard')) + { + // dynamic dashboard is used + $this->component->remove('dashboard_tab'); + $this->component->remove('php_dashboard_methods'); + } + } + } diff --git a/src/d33b9278-c409-4aec-a047-b72f56712391/code.power b/src/d33b9278-c409-4aec-a047-b72f56712391/code.power new file mode 100644 index 0000000..8084592 --- /dev/null +++ b/src/d33b9278-c409-4aec-a047-b72f56712391/code.power @@ -0,0 +1,214 @@ + /** + * The lang keys for extensions + * + * @var array + * @since 3.2.0 + **/ + public array $langKeys = []; + + /** + * The Language JS matching check + * + * @var array + * @since 3.2.0 + **/ + public array $langMismatch = []; + + /** + * The Language SC matching check + * + * @var array + * @since 3.2.0 + **/ + public array $langMatch = []; + + /** + * Compiler Config + * + * @var Config + * @since 3.2.0 + **/ + protected Config $config; + + /** + * Compiler Placeholder + * + * @var Placeholder + * @since 3.2.0 + **/ + protected Placeholder $placeholder; + + /** + * Compiler Language + * + * @var Language + * @since 3.2.0 + **/ + protected Language $language; + + /** + * Constructor. + * + * @param Config|null $config The compiler config object. + * @param Language|null $language The compiler Language object. + * @param Placeholder|null $placeholder The compiler placeholder object. + * + * @since 3.2.0 + */ + public function __construct(?Config $config = null, ?Language $language = null, ?Placeholder $placeholder = null) + { + $this->config = $config ?: Compiler::_('Config'); + $this->language = $language ?: Compiler::_('Language'); + $this->placeholder = $placeholder ?: Compiler::_('Placeholder'); + } + + /** + * Extract Language Strings + * + * @param string $content The content + * + * @return string The content with the updated Language place holder + * @since 3.2.0 + */ + public function engine(string $content): string + { + // get targets to search for + $lang_string_targets = array_filter( + $this->config->lang_string_targets, fn($get): bool => strpos($content, (string) $get) !== false + ); + // check if we should continue + if (ArrayHelper::check($lang_string_targets)) + { + // insure string is not broken + $content = $this->placeholder->update_($content); + // reset some buckets + $lang_holders = []; + $lang_check = []; + $lang_only = []; + $js_text = []; + $sc_text = []; + // first get the Joomla .JText._() + if (in_array('Joomla' . '.JText._(', $lang_string_targets)) + { + $js_text[] = GetHelper::allBetween( + $content, "Joomla" . ".JText._('", "'" + ); + $js_text[] = GetHelper::allBetween( + $content, 'Joomla' . '.JText._("', '"' + ); + // combine into one array + $js_text = ArrayHelper::merge($js_text); + // we need to add a check to insure these JavaScript lang matchup + if (ArrayHelper::check( + $js_text + )) //<-- not really needed hmmm + { + // load the JS text to mismatch array + $lang_check[] = $js_text; + $this->langMismatch = ArrayHelper::merge( + array($js_text, $this->langMismatch) + ); + } + } + // now get the JText: :script() + if (in_array('JText:' . ':script(', $lang_string_targets)) + { + $sc_text[] = GetHelper::allBetween( + $content, "JText:" . ":script('", "'" + ); + $sc_text[] = GetHelper::allBetween( + $content, 'JText:' . ':script("', '"' + ); + // combine into one array + $sc_text = ArrayHelper::merge($sc_text); + // we need to add a check to insure these JavaScript lang matchup + if (ArrayHelper::check($sc_text)) + { + // load the Script text to match array + $lang_check[] = $sc_text; + $this->langMatch = ArrayHelper::merge( + array($sc_text, $this->langMatch) + ); + } + } + // now do the little trick for JustTEXT: :_('Just uppercase text'); + if (in_array('JustTEXT:' . ':_(', $lang_string_targets)) + { + $lang_only[] = GetHelper::allBetween( + $content, "JustTEXT:" . ":_('", "')" + ); + $lang_only[] = GetHelper::allBetween( + $content, 'JustTEXT:' . ':_("', '")' + ); + // merge lang only + $lang_only = ArrayHelper::merge($lang_only); + } + // set language data + foreach ($lang_string_targets as $lang_string_target) + { + // need some special treatment here + if ($lang_string_target === 'Joomla' . '.JText._(' + || $lang_string_target === 'JText:' . ':script(' + || $lang_string_target === 'JustTEXT:' . ':_(') + { + continue; + } + $lang_check[] = GetHelper::allBetween( + $content, $lang_string_target . "'", "'" + ); + $lang_check[] = GetHelper::allBetween( + $content, $lang_string_target . '"', '"' + ); + } + // the normal loading of the language strings + $lang_check = ArrayHelper::merge($lang_check); + if (ArrayHelper::check( + $lang_check + )) //<-- not really needed hmmm + { + foreach ($lang_check as $string) + { + if ($key_lang = $this->language->key($string)) + { + // load the language targets + foreach ($lang_string_targets as $lang_string_target) + { + // need some special treatment here + if ($lang_string_target === 'JustTEXT:' . ':_(') + { + continue; + } + $lang_holders[$lang_string_target . "'" . $string + . "'"] + = $lang_string_target . "'" . $key_lang . "'"; + $lang_holders[$lang_string_target . '"' . $string + . '"'] + = $lang_string_target . '"' . $key_lang . '"'; + } + } + } + } + // the uppercase loading only (for arrays and other tricks) + if (ArrayHelper::check($lang_only)) + { + foreach ($lang_only as $string) + { + if ($key_lang = $this->language->key($string)) + { + // load the language targets + $lang_holders["JustTEXT:" . ":_('" . $string . "')"] + = "'" . $key_lang . "'"; + $lang_holders['JustTEXT:' . ':_("' . $string . '")'] + = '"' . $key_lang . '"'; + } + } + } + // only continue if we have value to replace + if (ArrayHelper::check($lang_holders)) + { + $content = $this->placeholder->update($content, $lang_holders); + } + } + + return $content; + } diff --git a/src/d3ce5763-4d00-4245-a175-54fc2e80e9b7/code.power b/src/d3ce5763-4d00-4245-a175-54fc2e80e9b7/code.power new file mode 100644 index 0000000..792a29d --- /dev/null +++ b/src/d3ce5763-4d00-4245-a175-54fc2e80e9b7/code.power @@ -0,0 +1,276 @@ + /** + * Compiler Config + * + * @var Config + * @since 3.2.0 + */ + protected Config $config; + + /** + * The compiler registry + * + * @var Registry + * @since 3.2.0 + */ + protected Registry $registry; + + /** + * Compiler Event + * + * @var EventInterface + * @since 3.2.0 + */ + protected EventInterface $event; + + /** + * Compiler Component + * + * @var Component + * @since 3.2.0 + **/ + protected Component $component; + + /** + * Compiler Content + * + * @var Content + * @since 3.2.0 + **/ + protected Content $content; + + /** + * Compiler Counter + * + * @var Counter + * @since 3.2.0 + */ + protected Counter $counter; + + /** + * Compiler Utilities Paths + * + * @var Paths + * @since 3.2.0 + */ + protected Paths $paths; + + /** + * Compiler Utilities Folder + * + * @var Folder + * @since 3.2.0 + */ + protected Folder $folder; + + /** + * Compiler Utilities File + * + * @var File + * @since 3.2.0 + */ + protected File $file; + + /** + * Constructor + * + * @param Config|null $config The compiler config object. + * @param Registry|null $registry The compiler registry object. + * @param EventInterface|null $event The compiler event api object. + * @param Component|null $component The component class. + * @param Content|null $content The compiler content object. + * @param Counter|null $counter The compiler counter object. + * @param Paths|null $paths The compiler paths object. + * @param Folder|null $folder The compiler folder object. + * @param File|null $file The compiler file object. + * + * @since 3.2.0 + */ + public function __construct(?Config $config = null, ?Registry $registry = null, + ?EventInterface $event = null, ?Component $component = null, + ?Content $content = null,?Counter $counter = null, + ?Paths $paths = null, ?Folder $folder = null, + ?File $file = null) + { + $this->config = $config ?: Compiler::_('Config'); + $this->registry = $registry ?: Compiler::_('Registry'); + $this->event = $event ?: Compiler::_('Event'); + $this->component = $component ?: Compiler::_('Component'); + $this->content = $content ?: Compiler::_('Content'); + $this->counter = $counter ?: Compiler::_('Utilities.Counter'); + $this->paths = $paths ?: Compiler::_('Utilities.Paths'); + $this->folder = $folder ?: Compiler::_('Utilities.Folder'); + $this->file = $file ?: Compiler::_('Utilities.File'); + } + + /** + * Build the Libraries files, folders, url's and config + * + * @return void + * @since 3.2.0 + */ + public function build() + { + if (($libraries_ = $this->registry->get('builder.libraries')) !== null) + { + // for plugin event TODO change event api signatures + $component_context = $this->config->component_context; + + // Trigger Event: jcb_ce_onBeforeSetLibraries + $this->event->trigger( + 'jcb_ce_onBeforeSetLibraries', + array(&$component_context, &$libraries_) + ); + + // creat the main component folder + if (!JoomlaFolder::exists($this->paths->component_path)) + { + JoomlaFolder::create($this->paths->component_path); + + // count the folder created + $this->counter->folder++; + $this->file->html(''); + } + + // create media path if not set + $this->folder->create($this->paths->component_path . '/media'); + foreach ($libraries_ as $id => &$library) + { + if (ObjectHelper::check($library)) + { + // check if this lib has files + if (isset($library->files) + && ArrayHelper::check($library->files)) + { + // add to component files + foreach ($library->files as $file) + { + $this->component->appendArray('files', $file); + } + } + + // check if this lib has folders + if (isset($library->folders) + && ArrayHelper::check( + $library->folders + )) + { + // add to component folders + foreach ($library->folders as $folder) + { + $this->component->appendArray('folders', $folder); + } + } + + // check if this lib has urls + if (isset($library->urls) + && ArrayHelper::check($library->urls)) + { + // build media folder path + $libFolder = strtolower( + preg_replace( + '/\s+/', '-', + (string) StringHelper::safe( + $library->name, 'filename', ' ', false + ) + ) + ); + $mediaPath = '/media/' . $libFolder; + + // should we add the local folder + $addLocalFolder = false; + + // add to component urls + foreach ($library->urls as $n => &$url) + { + if (isset($url['type']) && $url['type'] > 1 + && isset($url['url']) + && StringHelper::check( + $url['url'] + )) + { + // create media/lib path if not set + $this->folder->create( + $this->paths->component_path . $mediaPath + ); + + // add local folder + $addLocalFolder = true; + + // set file name + $fileName = basename((string) $url['url']); + + // get the file contents + $data = FileHelper::getContent( + $url['url'] + ); + + // build sub path + if (strpos($fileName, '.js') !== false) + { + $path = '/js'; + } + elseif (strpos($fileName, '.css') !== false) + { + $path = '/css'; + } + else + { + $path = ''; + } + + // create sub media path if not set + $this->folder->create( + $this->paths->component_path . $mediaPath . $path + ); + + // set the path to library file + $url['path'] = $mediaPath . $path . '/' + . $fileName; // we need this for later + + // set full path + $path = $this->paths->component_path . $url['path']; + + // write data to path + $this->file->write($path, $data); + + // count the file created + $this->counter->file++; + } + } + + // only add if local + if ($addLocalFolder) + { + // add folder to xml of media folders + $this->content->add('EXSTRA_MEDIA_FOLDERS', + PHP_EOL . Indent::_(2) . "" + . $libFolder . ""); + } + } + + // if config fields are found load into component config (avoiding duplicates) + if (isset($library->how) && $library->how > 1 + && isset($library->config) + && ArrayHelper::check($library->config)) + { + foreach ($library->config as $cofig) + { + $found = array_filter( + $this->component->get('config'), + fn($item) => $item['field'] == $cofig['field'] + ); + + // set the config data if not found + if (!ArrayHelper::check($found)) + { + $this->component->appendArray('config', $cofig); + } + } + } + + // update the global value just in case for now + $this->registry->set("builder.libraries.$id", $library); + } + } + } + } diff --git a/src/d4b418a7-bf9b-4768-969d-e07c36916fd2/code.power b/src/d4b418a7-bf9b-4768-969d-e07c36916fd2/code.power new file mode 100644 index 0000000..5dcf419 --- /dev/null +++ b/src/d4b418a7-bf9b-4768-969d-e07c36916fd2/code.power @@ -0,0 +1,68 @@ + /** + * Compiler Customcode Dispenser + * + * @var Dispenser + * @since 3.2.0 + */ + protected Dispenser $dispenser; + + /** + * Compiler SQL Dump + * + * @var Sqldump + * @since 3.2.0 + */ + protected Sqldump $dump; + + /** + * Constructor + * + * @param Dispenser|null $dispenser The compiler customcode dispenser. + * @param Sqldump|null $dump The compiler SQL dump. + * + * @since 3.2.0 + */ + public function __construct(?Dispenser $dispenser = null, ?Sqldump $dump = null) + { + $this->dispenser = $dispenser ?: Compiler::_('Customcode.Dispenser'); + $this->dump = $dump ?: Compiler::_('Model.Sqldump'); + } + + /** + * Set sql + * + * @param object $item The item data + * + * @return void + * @since 3.2.0 + */ + public function set(object &$item) + { + if (isset($item->add_sql) && $item->add_sql == 1 && isset($item->source)) + { + if ($item->source == 1 && isset($item->tables) && + ($string = $this->dump->get( + $item->tables, $item->name_single_code, $item->id + )) !== null) + { + // build and add the SQL dump + // we add this directly to avoid + // dynamic set behaviour + // TODO: create a function in dispenser to manage these + $this->dispenser->hub['sql'][$item->name_single_code] + = $string; + } + elseif ($item->source == 2 && isset($item->sql)) + { + // add the SQL dump string + $this->dispenser->set( + $item->sql, + 'sql', + $item->name_single_code + ); + } + } + + unset($item->tables); + unset($item->sql); + } diff --git a/src/d6592c9b-93a6-41b3-83c7-c43a0a80cb83/code.power b/src/d6592c9b-93a6-41b3-83c7-c43a0a80cb83/code.power new file mode 100644 index 0000000..2b92d0d --- /dev/null +++ b/src/d6592c9b-93a6-41b3-83c7-c43a0a80cb83/code.power @@ -0,0 +1,65 @@ + /** + * Get the language string key + * + * @param string $string The plan text string (English) + * + * @return string The key language string (all uppercase) + * @since 3.2.0 + */ + public function key($string): string; + + /** + * check if the language string exist + * + * @param string $target The target area for the language string + * @param string|null $language The language key string + * + * @return bool + * @since 3.2.0 + */ + public function exist(string $target, ?string $language = null): bool; + + /** + * get the language string + * + * @param string $target The target area for the language string + * @param string|null $language The language key string + * + * @return Mixed The language string found or empty string if none is found + * @since 3.2.0 + */ + public function get(string $target, string $language): string; + + /** + * get target array + * + * @param string $target The target area for the language string + * + * @return array The target array or empty array if none is found + * @since 3.2.0 + */ + public function getTarget(string $target): array; + + /** + * set target array + * + * @param string $target The target area for the language string + * @param array|null $content The language content string + * + * @return void + * @since 3.2.0 + */ + public function setTarget(string $target, ?array $content); + + /** + * set the language content values to language content array + * + * @param string $target The target area for the language string + * @param string $language The language key string + * @param string $string The language string + * @param bool $addPrefix The switch to add langPrefix + * + * @return void + * @since 3.2.0 + */ + public function set(string $target, string $language, string $string, bool $addPrefix = false); diff --git a/src/d7ba2d5d-10b6-470d-978d-9f91ea65ee75/code.power b/src/d7ba2d5d-10b6-470d-978d-9f91ea65ee75/code.power new file mode 100644 index 0000000..3ce6189 --- /dev/null +++ b/src/d7ba2d5d-10b6-470d-978d-9f91ea65ee75/code.power @@ -0,0 +1,110 @@ + /** + * Compiler Field Data + * + * @var Data + * @since 3.2.0 + **/ + protected Data $data; + + /** + * Compiler Field Name + * + * @var Name + * @since 3.2.0 + **/ + protected Name $name; + + /** + * Compiler Field Type Name + * + * @var TypeName + * @since 3.2.0 + **/ + protected TypeName $typeName; + + /** + * Compiler Field Unique Name + * + * @var UniqueName + * @since 3.2.0 + **/ + protected UniqueName $uniqueName; + + /** + * Constructor + * + * @param Data|null $data The compiler field data object. + * @param Name|null $name The compiler field name object. + * @param TypeName|null $typeName The compiler field type name object. + * @param UniqueName|null $uniqueName The compiler field unique name object. + * + * @since 3.2.0 + */ + public function __construct(?Data $data = null, ?Name $name = null, ?TypeName $typeName = null, ?UniqueName $uniqueName = null) + { + $this->data = $data ?: Compiler::_('Field.Data'); + $this->name = $name ?: Compiler::_('Field.Name'); + $this->typeName = $typeName ?: Compiler::_('Field.Type.Name'); + $this->uniqueName = $uniqueName ?: Compiler::_('Field.Unique.Name'); + } + + /** + * set Field details + * + * @param array $field The field array. + * @param string|null $singleViewName The single view name. + * @param string|null $listViewName The list view name. + * @param string $amicably The peaceful resolve. + * + * @return void + * @since 3.2.0 + */ + public function set(array &$field, ?string $singleViewName = null, ?string $listViewName = null, string $amicably = '') + { + // set hash + static $hash = 123467890; + + // load hash if not found + if (!isset($field['hash'])) + { + $field['hash'] = \md5($field['field'] . $hash); + // increment hash + $hash++; + } + + // set the settings + if (!isset($field['settings'])) + { + $field['settings'] = $this->data->get( + $field['field'], $singleViewName, $listViewName + ); + } + + // set real field name + if (!isset($field['base_name'])) + { + $field['base_name'] = $this->name->get($field); + } + + // set code name for field type + if (!isset($field['type_name'])) + { + $field['type_name'] = $this->typeName->get($field); + } + + // check if value is array + if (isset($field['permission']) + && !ArrayHelper::check($field['permission']) + && is_numeric($field['permission']) && $field['permission'] > 0) + { + $field['permission'] = array($field['permission']); + } + + // set unique name keeper + if ($listViewName) + { + $this->uniqueName->set( + $field['base_name'], $listViewName . $amicably + ); + } + } diff --git a/src/d910d8b8-4c23-4f3e-8cda-438f2d2bd7ac/code.php b/src/d910d8b8-4c23-4f3e-8cda-438f2d2bd7ac/code.php index 7a2ed9e..6bdd6ce 100644 --- a/src/d910d8b8-4c23-4f3e-8cda-438f2d2bd7ac/code.php +++ b/src/d910d8b8-4c23-4f3e-8cda-438f2d2bd7ac/code.php @@ -36,6 +36,17 @@ use VDM\Joomla\Componentbuilder\Compiler\Service\Joomlamodule; use VDM\Joomla\Componentbuilder\Compiler\Service\Joomlaplugin; use VDM\Joomla\Componentbuilder\Compiler\Service\Utilities; use VDM\Joomla\Componentbuilder\Compiler\Service\Builder; +use VDM\Joomla\Componentbuilder\Service\Gitea; +use VDM\Joomla\Gitea\Service\Utilities as GiteaUtilities; +use VDM\Joomla\Gitea\Service\Settings as GiteaSettings; +use VDM\Joomla\Gitea\Service\Organization as GiteaOrg; +use VDM\Joomla\Gitea\Service\User as GiteaUser; +use VDM\Joomla\Gitea\Service\Repository as GiteaRepo; +use VDM\Joomla\Gitea\Service\Package as GiteaPackage; +use VDM\Joomla\Gitea\Service\Issue as GiteaIssue; +use VDM\Joomla\Gitea\Service\Notifications as GiteNotifi; +use VDM\Joomla\Gitea\Service\Miscellaneous as GiteaMisc; +use VDM\Joomla\Gitea\Service\Admin as GiteaAdmin; use VDM\Joomla\Componentbuilder\Interfaces\FactoryInterface; @@ -140,7 +151,18 @@ abstract class Factory implements FactoryInterface ->registerServiceProvider(new Joomlamodule()) ->registerServiceProvider(new Joomlaplugin()) ->registerServiceProvider(new Utilities()) - ->registerServiceProvider(new Builder()); + ->registerServiceProvider(new Builder()) + ->registerServiceProvider(new Gitea()) + ->registerServiceProvider(new GiteaUtilities()) + ->registerServiceProvider(new GiteaSettings()) + ->registerServiceProvider(new GiteaOrg()) + ->registerServiceProvider(new GiteaUser()) + ->registerServiceProvider(new GiteaRepo()) + ->registerServiceProvider(new GiteaPackage()) + ->registerServiceProvider(new GiteaIssue()) + ->registerServiceProvider(new GiteNotifi()) + ->registerServiceProvider(new GiteaMisc()) + ->registerServiceProvider(new GiteaAdmin()); } } diff --git a/src/d910d8b8-4c23-4f3e-8cda-438f2d2bd7ac/code.power b/src/d910d8b8-4c23-4f3e-8cda-438f2d2bd7ac/code.power new file mode 100644 index 0000000..218164c --- /dev/null +++ b/src/d910d8b8-4c23-4f3e-8cda-438f2d2bd7ac/code.power @@ -0,0 +1,107 @@ + /** + * Global Compiler Container + * + * @var Container + * @since 3.2.0 + **/ + protected static $container = null; + + /** + * Current Joomla Version Being Build + * + * @var int + * @since 3.2.0 + **/ + protected static $JoomlaVersion; + + /** + * Get any class from the compiler container + * + * @param string $key The container class key + * + * @return mixed + * @since 3.2.0 + */ + public static function _($key) + { + return self::getContainer()->get($key); + } + + /** + * Get version specific class from the compiler container + * + * @param string $key The container class key + * + * @return mixed + * @since 3.2.0 + */ + public static function _J($key) + { + if (empty(self::$JoomlaVersion)) + { + self::$JoomlaVersion = self::getContainer()->get('Config')->joomla_version; + } + + return self::getContainer()->get('J' . self::$JoomlaVersion . '.' . $key); + } + + /** + * Get the global compiler 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 Crypt()) + ->registerServiceProvider(new Server()) + ->registerServiceProvider(new Database()) + ->registerServiceProvider(new Model()) + ->registerServiceProvider(new Mapper()) + ->registerServiceProvider(new Compiler()) + ->registerServiceProvider(new Event()) + ->registerServiceProvider(new History()) + ->registerServiceProvider(new Language()) + ->registerServiceProvider(new Placeholder()) + ->registerServiceProvider(new Customcode()) + ->registerServiceProvider(new Power()) + ->registerServiceProvider(new Component()) + ->registerServiceProvider(new Adminview()) + ->registerServiceProvider(new Library()) + ->registerServiceProvider(new Customview()) + ->registerServiceProvider(new Templatelayout()) + ->registerServiceProvider(new Extension()) + ->registerServiceProvider(new Field()) + ->registerServiceProvider(new Joomlamodule()) + ->registerServiceProvider(new Joomlaplugin()) + ->registerServiceProvider(new Utilities()) + ->registerServiceProvider(new Builder()) + ->registerServiceProvider(new Gitea()) + ->registerServiceProvider(new GiteaUtilities()) + ->registerServiceProvider(new GiteaSettings()) + ->registerServiceProvider(new GiteaOrg()) + ->registerServiceProvider(new GiteaUser()) + ->registerServiceProvider(new GiteaRepo()) + ->registerServiceProvider(new GiteaPackage()) + ->registerServiceProvider(new GiteaIssue()) + ->registerServiceProvider(new GiteNotifi()) + ->registerServiceProvider(new GiteaMisc()) + ->registerServiceProvider(new GiteaAdmin()); + } diff --git a/src/d910d8b8-4c23-4f3e-8cda-438f2d2bd7ac/settings.json b/src/d910d8b8-4c23-4f3e-8cda-438f2d2bd7ac/settings.json index 902f6b9..cd6a0ab 100644 --- a/src/d910d8b8-4c23-4f3e-8cda-438f2d2bd7ac/settings.json +++ b/src/d910d8b8-4c23-4f3e-8cda-438f2d2bd7ac/settings.json @@ -104,6 +104,50 @@ "use_selection22": { "use": "2c76c06e-a371-4b73-9fbe-b4d9b4df55d7", "as": "default" + }, + "use_selection24": { + "use": "71acf8d6-32b8-4173-8277-eb9cda29fd64", + "as": "default" + }, + "use_selection23": { + "use": "6edf0cf3-c2b0-45c9-84d2-c6ef1c5d434c", + "as": "GiteaUtilities" + }, + "use_selection25": { + "use": "f4d00907-c94a-49b7-8727-d64c1fa74cf5", + "as": "GiteaSettings" + }, + "use_selection26": { + "use": "3d25ea99-4f33-489a-934c-0e42027e6114", + "as": "GiteaOrg" + }, + "use_selection27": { + "use": "0a69cfc5-3223-4afb-8c9a-75f4bacf3c0e", + "as": "GiteaUser" + }, + "use_selection28": { + "use": "0bb2b72f-ebcd-46fe-844b-ac5fe715c230", + "as": "GiteaRepo" + }, + "use_selection29": { + "use": "808da4eb-b467-46cf-a767-e7e714f46b5a", + "as": "GiteaPackage" + }, + "use_selection30": { + "use": "44396eb8-e14c-47d9-9bdc-8205c0fd2bba", + "as": "GiteaIssue" + }, + "use_selection31": { + "use": "be57f70f-1214-4d69-8d33-7cd4e312ff70", + "as": "GiteNotifi" + }, + "use_selection32": { + "use": "012af7d0-3436-4cae-b856-be49bdc39a3e", + "as": "GiteaMisc" + }, + "use_selection33": { + "use": "ddced4c5-667d-4559-873d-d716c17fd85b", + "as": "GiteaAdmin" } }, "namespace": "VDM\\Joomla\\Componentbuilder.Compiler.Factory", diff --git a/src/de01527a-6586-46ea-92e7-11ea3de1cedb/README.md b/src/de01527a-6586-46ea-92e7-11ea3de1cedb/README.md index 3603002..310534f 100644 --- a/src/de01527a-6586-46ea-92e7-11ea3de1cedb/README.md +++ b/src/de01527a-6586-46ea-92e7-11ea3de1cedb/README.md @@ -13,6 +13,7 @@ class Power #Gold { + register(Container $container) : void + getPowers(Container $container) : Powers + + getGrep(Container $container) : Grep + getAutoloader(Container $container) : Autoloader + getInfusion(Container $container) : Infusion + getStructure(Container $container) : Structure @@ -36,49 +37,56 @@ note left of Power::getPowers return: Powers end note -note right of Power::getAutoloader +note right of Power::getGrep + Get the Grep + + since: 3.2.0 + return: Grep +end note + +note left of Power::getAutoloader Get the Compiler Autoloader since: 3.2.0 return: Autoloader end note -note left of Power::getInfusion +note right of Power::getInfusion Get the Compiler Power Infusion since: 3.2.0 return: Infusion end note -note right of Power::getStructure +note left of Power::getStructure Get the Compiler Power Structure Builder since: 3.2.0 return: Structure end note -note left of Power::getParser +note right of Power::getParser Get the Compiler Power Parser since: 3.2.0 return: Parser end note -note right of Power::getPlantuml +note left of Power::getPlantuml Get the Compiler Power Plantuml Builder since: 3.2.0 return: Plantuml end note -note left of Power::getRepoReadme +note right of Power::getRepoReadme Get the Compiler Power Repo Readme Builder since: 3.2.0 return: RepoReadme end note -note right of Power::getReposReadme +note left of Power::getReposReadme Get the Compiler Power Repos Readme Builder since: 3.2.0 diff --git a/src/de01527a-6586-46ea-92e7-11ea3de1cedb/code.php b/src/de01527a-6586-46ea-92e7-11ea3de1cedb/code.php index 2c4a9de..c605d54 100644 --- a/src/de01527a-6586-46ea-92e7-11ea3de1cedb/code.php +++ b/src/de01527a-6586-46ea-92e7-11ea3de1cedb/code.php @@ -15,6 +15,7 @@ namespace VDM\Joomla\Componentbuilder\Compiler\Service; use Joomla\DI\Container; use Joomla\DI\ServiceProviderInterface; use VDM\Joomla\Componentbuilder\Compiler\Power as Powers; +use VDM\Joomla\Componentbuilder\Power\Grep; use VDM\Joomla\Componentbuilder\Compiler\Power\Infusion; use VDM\Joomla\Componentbuilder\Compiler\Power\Autoloader; use VDM\Joomla\Componentbuilder\Compiler\Power\Structure; @@ -44,6 +45,9 @@ class Power implements ServiceProviderInterface $container->alias(Powers::class, 'Power') ->share('Power', [$this, 'getPowers'], true); + $container->alias(Grep::class, 'Power.Grep') + ->share('Grep', [$this, 'getGrep'], true); + $container->alias(Autoloader::class, 'Power.Autoloader') ->share('Power.Autoloader', [$this, 'getAutoloader'], true); @@ -84,6 +88,19 @@ class Power implements ServiceProviderInterface ); } + /** + * Get the Grep + * + * @param Container $container The DI container. + * + * @return Grep + * @since 3.2.0 + */ + public function getGrep(Container $container): Grep + { + return new Grep(); + } + /** * Get the Compiler Autoloader * diff --git a/src/de01527a-6586-46ea-92e7-11ea3de1cedb/code.power b/src/de01527a-6586-46ea-92e7-11ea3de1cedb/code.power new file mode 100644 index 0000000..d5d6a65 --- /dev/null +++ b/src/de01527a-6586-46ea-92e7-11ea3de1cedb/code.power @@ -0,0 +1,189 @@ + /** + * 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(Powers::class, 'Power') + ->share('Power', [$this, 'getPowers'], true); + + $container->alias(Grep::class, 'Power.Grep') + ->share('Grep', [$this, 'getGrep'], true); + + $container->alias(Autoloader::class, 'Power.Autoloader') + ->share('Power.Autoloader', [$this, 'getAutoloader'], true); + + $container->alias(Infusion::class, 'Power.Infusion') + ->share('Power.Infusion', [$this, 'getInfusion'], true); + + $container->alias(Structure::class, 'Power.Structure') + ->share('Power.Structure', [$this, 'getStructure'], true); + + $container->alias(Parser::class, 'Power.Parser') + ->share('Power.Parser', [$this, 'getParser'], true); + + $container->alias(Plantuml::class, 'Power.Plantuml') + ->share('Power.Plantuml', [$this, 'getPlantuml'], true); + + $container->alias(RepoReadme::class, 'Power.Repo.Readme') + ->share('Power.Repo.Readme', [$this, 'getRepoReadme'], true); + + $container->alias(ReposReadme::class, 'Power.Repos.Readme') + ->share('Power.Repos.Readme', [$this, 'getReposReadme'], true); + } + + /** + * Get the Powers + * + * @param Container $container The DI container. + * + * @return Powers + * @since 3.2.0 + */ + public function getPowers(Container $container): Powers + { + return new Powers( + $container->get('Config'), + $container->get('Placeholder'), + $container->get('Customcode'), + $container->get('Customcode.Gui') + ); + } + + /** + * Get the Grep + * + * @param Container $container The DI container. + * + * @return Grep + * @since 3.2.0 + */ + public function getGrep(Container $container): Grep + { + return new Grep(); + } + + /** + * Get the Compiler Autoloader + * + * @param Container $container The DI container. + * + * @return Autoloader + * @since 3.2.0 + */ + public function getAutoloader(Container $container): Autoloader + { + return new Autoloader( + $container->get('Power'), + $container->get('Config'), + $container->get('Content') + ); + } + + /** + * Get the Compiler Power Infusion + * + * @param Container $container The DI container. + * + * @return Infusion + * @since 3.2.0 + */ + public function getInfusion(Container $container): Infusion + { + return new Infusion( + $container->get('Config'), + $container->get('Power'), + $container->get('Content'), + $container->get('Power.Autoloader'), + $container->get('Power.Parser'), + $container->get('Power.Repo.Readme'), + $container->get('Power.Repos.Readme'), + $container->get('Placeholder'), + $container->get('Event') + ); + } + + /** + * Get the Compiler Power Structure Builder + * + * @param Container $container The DI container. + * + * @return Structure + * @since 3.2.0 + */ + public function getStructure(Container $container): Structure + { + return new Structure( + $container->get('Power'), + $container->get('Config'), + $container->get('Registry'), + $container->get('Event'), + $container->get('Utilities.Counter'), + $container->get('Utilities.Paths'), + $container->get('Utilities.Folder'), + $container->get('Utilities.File'), + $container->get('Utilities.Files') + ); + } + + /** + * Get the Compiler Power Parser + * + * @param Container $container The DI container. + * + * @return Structure + * @since 3.2.0 + */ + public function getParser(Container $container): Parser + { + return new Parser(); + } + + /** + * Get the Compiler Power Plantuml Builder + * + * @param Container $container The DI container. + * + * @return Plantuml + * @since 3.2.0 + */ + public function getPlantuml(Container $container): Plantuml + { + return new Plantuml(); + } + + /** + * Get the Compiler Power Repo Readme Builder + * + * @param Container $container The DI container. + * + * @return RepoReadme + * @since 3.2.0 + */ + public function getRepoReadme(Container $container): RepoReadme + { + return new RepoReadme( + $container->get('Power'), + $container->get('Power.Plantuml') + ); + } + + /** + * Get the Compiler Power Repos Readme Builder + * + * @param Container $container The DI container. + * + * @return ReposReadme + * @since 3.2.0 + */ + public function getReposReadme(Container $container): ReposReadme + { + return new ReposReadme( + $container->get('Power'), + $container->get('Power.Plantuml') + ); + } diff --git a/src/de01527a-6586-46ea-92e7-11ea3de1cedb/settings.json b/src/de01527a-6586-46ea-92e7-11ea3de1cedb/settings.json index 1c5560f..334de3b 100644 --- a/src/de01527a-6586-46ea-92e7-11ea3de1cedb/settings.json +++ b/src/de01527a-6586-46ea-92e7-11ea3de1cedb/settings.json @@ -16,6 +16,10 @@ "use": "b836c1b1-b6b1-44f7-b8a2-9a763a4185b1", "as": "Powers" }, + "use_selection8": { + "use": "6784dd52-0909-451a-a872-9a942a023c68", + "as": "default" + }, "use_selection1": { "use": "0419081e-4cb3-4c65-8c6a-ffe941fb0f1c", "as": "default" diff --git a/src/dfd3c893-0296-46eb-9ae4-a0348713cd8f/code.power b/src/dfd3c893-0296-46eb-9ae4-a0348713cd8f/code.power new file mode 100644 index 0000000..100be0f --- /dev/null +++ b/src/dfd3c893-0296-46eb-9ae4-a0348713cd8f/code.power @@ -0,0 +1,99 @@ + /** + * The scripter add array + * + * @var array + * @since 3.2.0 + */ + protected array $scripter = [ + 'javascript_view_file', + 'javascript_view_footer', + 'javascript_views_file', + 'javascript_views_footer' + ]; + + /** + * The gui mapper array + * + * @var array + * @since 3.2.0 + */ + protected array $guiMapper = [ + 'table' => 'admin_view', + 'id' => null, + 'field' => null, + 'type' => 'js', + 'prefix' => PHP_EOL + ]; + + /** + * Compiler Customcode Dispenser + * + * @var Dispenser + * @since 3.2.0 + */ + protected Dispenser $dispenser; + + /** + * Constructor + * + * @param Dispenser|null $dispenser The compiler customcode dispenser + * + * @since 3.2.0 + */ + public function __construct(?Dispenser $dispenser = null) + { + $this->dispenser = $dispenser ?: Compiler::_('Customcode.Dispenser'); + } + + /** + * Set Admin View Javascript + * + * @param object $item The item data + * @param object $table The table + * + * @return void + * @since 3.2.0 + */ + public function set(object &$item, string $table = 'admin_view') + { + // set some gui mapper values + $this->guiMapper['table'] = $table; + $this->guiMapper['id'] = (int) $item->id; + + foreach ($this->scripter as $scripter) + { + if (isset($item->{'add_' . $scripter}) + && $item->{'add_' . $scripter} == 1 + && StringHelper::check($item->$scripter)) + { + $scripter_target = str_replace( + 'javascript_', '', (string) $scripter + ); + + // update GUI mapper field + $this->guiMapper['field'] = $scripter; + $this->dispenser->set( + $item->{$scripter}, + $scripter_target, + $item->name_single_code, + null, + $this->guiMapper, + true, + true, + true + ); + + // check if a token must be set + if ((strpos((string) $item->$scripter, "token") !== false + || strpos( + (string) $item->$scripter, "task=ajax" + ) !== false) && !$this->dispenser->hub['token'][$item->name_single_code]) + { + $this->dispenser->hub['token'][$item->name_single_code] + = true; + } + + unset($item->{$scripter}); + } + } + } diff --git a/src/e0075978-315d-4807-8507-ce9c6922a885/code.power b/src/e0075978-315d-4807-8507-ce9c6922a885/code.power new file mode 100644 index 0000000..5e097d8 --- /dev/null +++ b/src/e0075978-315d-4807-8507-ce9c6922a885/code.power @@ -0,0 +1,77 @@ + /** + * Component Site view Data + * + * @var Customview + * @since 3.2.0 + **/ + protected Customview $site; + + /** + * Compiler Config + * + * @var Config + * @since 3.2.0 + **/ + protected Config $config; + + /** + * Constructor + * + * @param Customview|null $site The site view data object. + * @param Config|null $config The compiler config object. + * + * @since 3.2.0 + */ + public function __construct(?Customview $site = null, ?Config $config = null) + { + $this->site = $site ?: Compiler::_('Customview.Data'); + $this->config = $config ?: Compiler::_('Config'); + } + + /** + * Set site view data + * + * @param object $item The item data + * + * @return void + * @since 3.2.0 + */ + public function set(object &$item) + { + $item->addsite_views = (isset($item->addsite_views) + && JsonHelper::check($item->addsite_views)) + ? json_decode((string) $item->addsite_views, true) : null; + + if (ArrayHelper::check($item->addsite_views)) + { + $this->config->lang_target = 'site'; + $this->config->build_target = 'site'; + + // build the site_views settings + $item->site_views = array_map( + function ($array) { + // has become a legacy issue, can't remove this + $array['view'] = $array['siteview']; + $array['settings'] = $this->site->get( + $array['view'] + ); + + return array_map( + function ($value) { + if (!ArrayHelper::check($value) + && !ObjectHelper::check($value) + && strval($value) === strval(intval($value))) + { + return (int) $value; + } + + return $value; + }, $array + ); + }, array_values($item->addsite_views) + ); + + // unset original value + unset($item->addsite_views); + } + } diff --git a/src/e0c8c931-52a0-4171-9909-e8769505bb1f/README.md b/src/e0c8c931-52a0-4171-9909-e8769505bb1f/README.md new file mode 100644 index 0000000..6df0da3 --- /dev/null +++ b/src/e0c8c931-52a0-4171-9909-e8769505bb1f/README.md @@ -0,0 +1,38 @@ +``` +██████╗ ██████╗ ██╗ ██╗███████╗██████╗ +██╔══██╗██╔═══██╗██║ ██║██╔════╝██╔══██╗ +██████╔╝██║ ██║██║ █╗ ██║█████╗ ██████╔╝ +██╔═══╝ ██║ ██║██║███╗██║██╔══╝ ██╔══██╗ +██║ ╚██████╔╝╚███╔███╔╝███████╗██║ ██║ +╚═╝ ╚═════╝ ╚══╝╚══╝ ╚══════╝╚═╝ ╚═╝ +``` +# class Constantpaths (Details) +> namespace: **VDM\Joomla\Componentbuilder\Utilities** +```uml +@startuml +class Constantpaths #Gold { + # array $paths + + get(?string $path = null) : array|string|null +} + +note right of Constantpaths::get + get array of constant paths or just one constant path + + since: 3.2.0 + return: array|string|null +end note + +@enduml +``` + +--- +``` + ██╗ ██████╗██████╗ + ██║██╔════╝██╔══██╗ + ██║██║ ██████╔╝ +██ ██║██║ ██╔══██╗ +╚█████╔╝╚██████╗██████╔╝ + ╚════╝ ╚═════╝╚═════╝ +``` +> Build with [Joomla Component Builder](https://git.vdm.dev/joomla/Component-Builder) + diff --git a/src/e0c8c931-52a0-4171-9909-e8769505bb1f/code.php b/src/e0c8c931-52a0-4171-9909-e8769505bb1f/code.php new file mode 100644 index 0000000..3773d87 --- /dev/null +++ b/src/e0c8c931-52a0-4171-9909-e8769505bb1f/code.php @@ -0,0 +1,93 @@ + + * @git 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\Utilities; + + +/** + * Utilities Constant Paths + * + * @since 3.2.0 + */ +class Constantpaths +{ + /** + * The array of constant paths + * + * JPATH_SITE is meant to represent the root path of the JSite application, + * just as JPATH_ADMINISTRATOR is mean to represent the root path of the JAdministrator application. + * + * JPATH_BASE is the root path for the current requested application.... so if you are in the administrator application: + * + * JPATH_BASE == JPATH_ADMINISTRATOR + * + * If you are in the site application: + * + * JPATH_BASE == JPATH_SITE + * + * If you are in the installation application: + * + * JPATH_BASE == JPATH_INSTALLATION. + * + * JPATH_ROOT is the root path for the Joomla install and does not depend upon any application. + * + * @var array + * @since 3.2.0 + */ + protected array $paths = [ + // The path to the administrator folder. + 'JPATH_ADMINISTRATOR' => JPATH_ADMINISTRATOR, + // The path to the installed Joomla! site, or JPATH_ROOT/administrator if executed from the backend. + 'JPATH_BASE' => JPATH_BASE, + // The path to the cache folder. + 'JPATH_CACHE' => JPATH_CACHE, + // The path to the administration folder of the current component being executed. + 'JPATH_COMPONENT_ADMINISTRATOR' => JPATH_COMPONENT_ADMINISTRATOR, + // The path to the site folder of the current component being executed. + 'JPATH_COMPONENT_SITE' => JPATH_COMPONENT_SITE, + // The path to the current component being executed. + 'JPATH_COMPONENT' => JPATH_COMPONENT, + // The path to folder containing the configuration.php file. + 'JPATH_CONFIGURATION' => JPATH_CONFIGURATION, + // The path to the installation folder. + 'JPATH_INSTALLATION' => JPATH_INSTALLATION, + // The path to the libraries folder. + 'JPATH_LIBRARIES' => JPATH_LIBRARIES, + // The path to the plugins folder. + 'JPATH_PLUGINS' => JPATH_PLUGINS, + // The path to the installed Joomla! site. + 'JPATH_ROOT' => JPATH_ROOT, + // The path to the installed Joomla! site. + 'JPATH_SITE' => JPATH_SITE, + // The path to the templates folder. + 'JPATH_THEMES' => JPATH_THEMES + ]; + + /** + * get array of constant paths or just one constant path + * + * @param string|null $path The path to get + * + * @return array|string|null + * @since 3.2.0 + */ + public function get(?string $path = null) + { + if (is_null($path)) + { + return $this->paths; + } + + return $this->paths[$path] ?? null; + } + +} + diff --git a/src/e0c8c931-52a0-4171-9909-e8769505bb1f/code.power b/src/e0c8c931-52a0-4171-9909-e8769505bb1f/code.power new file mode 100644 index 0000000..d72e4fd --- /dev/null +++ b/src/e0c8c931-52a0-4171-9909-e8769505bb1f/code.power @@ -0,0 +1,69 @@ + /** + * The array of constant paths + * + * JPATH_SITE is meant to represent the root path of the JSite application, + * just as JPATH_ADMINISTRATOR is mean to represent the root path of the JAdministrator application. + * + * JPATH_BASE is the root path for the current requested application.... so if you are in the administrator application: + * + * JPATH_BASE == JPATH_ADMINISTRATOR + * + * If you are in the site application: + * + * JPATH_BASE == JPATH_SITE + * + * If you are in the installation application: + * + * JPATH_BASE == JPATH_INSTALLATION. + * + * JPATH_ROOT is the root path for the Joomla install and does not depend upon any application. + * + * @var array + * @since 3.2.0 + */ + protected array $paths = [ + // The path to the administrator folder. + 'JPATH_ADMINISTRATOR' => JPATH_ADMINISTRATOR, + // The path to the installed Joomla! site, or JPATH_ROOT/administrator if executed from the backend. + 'JPATH_BASE' => JPATH_BASE, + // The path to the cache folder. + 'JPATH_CACHE' => JPATH_CACHE, + // The path to the administration folder of the current component being executed. + 'JPATH_COMPONENT_ADMINISTRATOR' => JPATH_COMPONENT_ADMINISTRATOR, + // The path to the site folder of the current component being executed. + 'JPATH_COMPONENT_SITE' => JPATH_COMPONENT_SITE, + // The path to the current component being executed. + 'JPATH_COMPONENT' => JPATH_COMPONENT, + // The path to folder containing the configuration.php file. + 'JPATH_CONFIGURATION' => JPATH_CONFIGURATION, + // The path to the installation folder. + 'JPATH_INSTALLATION' => JPATH_INSTALLATION, + // The path to the libraries folder. + 'JPATH_LIBRARIES' => JPATH_LIBRARIES, + // The path to the plugins folder. + 'JPATH_PLUGINS' => JPATH_PLUGINS, + // The path to the installed Joomla! site. + 'JPATH_ROOT' => JPATH_ROOT, + // The path to the installed Joomla! site. + 'JPATH_SITE' => JPATH_SITE, + // The path to the templates folder. + 'JPATH_THEMES' => JPATH_THEMES + ]; + + /** + * get array of constant paths or just one constant path + * + * @param string|null $path The path to get + * + * @return array|string|null + * @since 3.2.0 + */ + public function get(?string $path = null) + { + if (is_null($path)) + { + return $this->paths; + } + + return $this->paths[$path] ?? null; + } diff --git a/src/e0c8c931-52a0-4171-9909-e8769505bb1f/settings.json b/src/e0c8c931-52a0-4171-9909-e8769505bb1f/settings.json new file mode 100644 index 0000000..04a37de --- /dev/null +++ b/src/e0c8c931-52a0-4171-9909-e8769505bb1f/settings.json @@ -0,0 +1,16 @@ +{ + "add_head": "0", + "extends": "0", + "extends_custom": "JoomlaRegistry", + "guid": "e0c8c931-52a0-4171-9909-e8769505bb1f", + "implements": null, + "implements_custom": "", + "load_selection": null, + "name": "Constantpaths", + "power_version": "1.0.0", + "system_name": "JCB.Utilities.Constantpaths", + "type": "class", + "use_selection": null, + "namespace": "VDM\\Joomla\\Componentbuilder.Utilities.Constantpaths", + "description": "Utilities Constant Paths\r\n\r\n@since 3.2.0" +} \ No newline at end of file diff --git a/src/e0e24173-a808-4dd5-8e26-de971d014f86/code.power b/src/e0e24173-a808-4dd5-8e26-de971d014f86/code.power new file mode 100644 index 0000000..24233bb --- /dev/null +++ b/src/e0e24173-a808-4dd5-8e26-de971d014f86/code.power @@ -0,0 +1,77 @@ + /** + * Component custom admin view Data + * + * @var Customview + * @since 3.2.0 + **/ + protected Customview $customadmin; + + /** + * Compiler Config + * + * @var Config + * @since 3.2.0 + **/ + protected Config $config; + + /** + * Constructor + * + * @param Customview|null $customadmin The custom admin view data object. + * @param Config|null $config The compiler config object. + * + * @since 3.2.0 + */ + public function __construct(?Customview $customadmin = null, ?Config $config = null) + { + $this->customadmin = $customadmin ?: Compiler::_('Customview.Data'); + $this->config = $config ?: Compiler::_('Config'); + } + + /** + * Set custom admin view data + * + * @param object $item The item data + * + * @return void + * @since 3.2.0 + */ + public function set(object &$item) + { + $item->addcustom_admin_views = (isset($item->addcustom_admin_views) + && JsonHelper::check($item->addcustom_admin_views)) + ? json_decode((string) $item->addcustom_admin_views, true) : null; + + if (ArrayHelper::check($item->addcustom_admin_views)) + { + $this->config->lang_target = 'admin'; + $this->config->build_target = 'custom_admin'; + + // build the site_views settings + $item->custom_admin_views = array_map( + function ($array) { + // has become a legacy issue, can't remove this + $array['view'] = $array['customadminview']; + $array['settings'] = $this->customadmin->get( + $array['view'], 'custom_admin_view' + ); + + return array_map( + function ($value) { + if (!ArrayHelper::check($value) + && !ObjectHelper::check($value) + && strval($value) === strval(intval($value))) + { + return (int) $value; + } + + return $value; + }, $array + ); + }, array_values($item->addcustom_admin_views) + ); + + // unset original value + unset($item->addcustom_admin_views); + } + } diff --git a/src/e2472b22-a329-44d8-b4a2-ae3ba99e17a0/code.power b/src/e2472b22-a329-44d8-b4a2-ae3ba99e17a0/code.power new file mode 100644 index 0000000..0a0eef9 --- /dev/null +++ b/src/e2472b22-a329-44d8-b4a2-ae3ba99e17a0/code.power @@ -0,0 +1,31 @@ + /** + * Constructor + * + * @param Data|null $component The component data class. + * + * @since 3.2.0 + */ + public function __construct(?Data $component = null) + { + $component = $component ?: Compiler::_('Component.Data'); + + parent::__construct($component->get()); + } + + /** + * getting any valid value + * + * @param string $path The value's key/path name + * + * @since 3.2.0 + */ + public function __get(string $path) + { + // check if it has been set + if (($value = $this->get($path, '__N0T_S3T_Y3T_')) !== '__N0T_S3T_Y3T_') + { + return $value; + } + + return null; + } diff --git a/src/e50cbac5-9c9d-4fd4-aa7a-5e830719ed26/code.power b/src/e50cbac5-9c9d-4fd4-aa7a-5e830719ed26/code.power new file mode 100644 index 0000000..609ac30 --- /dev/null +++ b/src/e50cbac5-9c9d-4fd4-aa7a-5e830719ed26/code.power @@ -0,0 +1,149 @@ + /** + * Compiler registry + * + * @var Registry + * @since 3.2.0 + */ + protected Registry $registry; + + /** + * Constructor + * + * @param Registry|null $registry The compiler registry object. + * + * @since 3.2.0 + */ + public function __construct(?Registry $registry = null) + { + $this->registry = $registry ?: Compiler::_('Registry'); + } + + /** + * Set sql tweaking if needed + * + * @param object $item The extension data + * + * @return void + * @since 3.2.0 + */ + public function set(object &$item) + { + // set the sql_tweak data + $item->sql_tweak = (isset($item->sql_tweak) + && JsonHelper::check($item->sql_tweak)) + ? json_decode((string) $item->sql_tweak, true) : null; + + if (ArrayHelper::check($item->sql_tweak)) + { + // build the tweak settings + $this->tweak( + array_map( + fn($array) => array_map( + function ($value) { + if (!ArrayHelper::check($value) + && !ObjectHelper::check( + $value + ) + && strval($value) === strval( + intval($value) + )) + { + return (int) $value; + } + + return $value; + }, $array + ), array_values($item->sql_tweak) + ) + ); + } + + unset($item->sql_tweak); + } + + /** + * To limit the SQL Demo data build in the views + * + * @param array $settings Tweaking array. + * + * @return void + * @since 3.2.0 + */ + protected function tweak($settings) + { + if (ArrayHelper::check($settings)) + { + foreach ($settings as $setting) + { + // should sql dump be added + if (1 == $setting['add_sql']) + { + // add sql (by option) + if (2 == $setting['add_sql_options']) + { + // rest always + $id_array = []; + + // by id (first remove backups) + $ids = $setting['ids']; + + // now get the ids + if (strpos((string) $ids, ',') !== false) + { + $id_array = (array) array_map( + 'trim', explode(',', (string) $ids) + ); + } + else + { + $id_array[] = trim((string) $ids); + } + $id_array_new = []; + + // check for ranges + foreach ($id_array as $key => $id) + { + if (strpos($id, '=>') !== false) + { + $id_range = (array) array_map( + 'trim', explode('=>', $id) + ); + unset($id_array[$key]); + // build range + if (count((array) $id_range) == 2) + { + $range = range( + $id_range[0], $id_range[1] + ); + $id_array_new = [...$id_array_new, ...$range]; + } + } + } + + if (ArrayHelper::check($id_array_new)) + { + $id_array = [...$id_array_new, ...$id_array]; + } + + // final fixing to array + if (ArrayHelper::check($id_array)) + { + // unique + $id_array = array_unique($id_array, SORT_NUMERIC); + // sort + sort($id_array, SORT_NUMERIC); + // now set it to global + $this->registry-> + set('builder.sql_tweak.' . (int) $setting['adminview'] . '.where', implode(',', $id_array)); + } + } + } + else + { + // do not add sql dump options + $this->registry-> + set('builder.sql_tweak.' . (int) $setting['adminview'] . '.add', false); + } + } + } + } diff --git a/src/e5d9804f-0eb0-4ee9-b406-ad4e8cdbc1f6/code.power b/src/e5d9804f-0eb0-4ee9-b406-ad4e8cdbc1f6/code.power new file mode 100644 index 0000000..3b30afe --- /dev/null +++ b/src/e5d9804f-0eb0-4ee9-b406-ad4e8cdbc1f6/code.power @@ -0,0 +1,73 @@ + /** + * Default indentation value + * + * @var int + * @since 1.0 + */ + protected $indent = 2; + + /** + * Method to export a set of values to a PHP array + * + * @param string $path Registry path (e.g. joomla.content.showauthor) + * @param int $default The default indentation + * + * @return ?string The var set being exported as a PHP array + * + * @since 3.4.0 + */ + public function varExport(string $path, int $default = 2): ?string + { + // check if we have data + if (($data = $this->extract($path)) !== null) + { + // set the default indentation value + $this->indent = $default; + + // convert to array + $data = $data->toArray(); + + // convert to string + $data = var_export($data, true); + + // replace all space with system indentation + $data = preg_replace_callback("/^(\s{2})(\s{2})?(\s{2})?(\s{2})?(\s{2})?(\s{2})?(\s{2})?(\s{2})?(\s{2})?(\s{2})?(\s{2})?(.*)/m", [$this, 'convertIndent'], $data); + + // convert all array to [] + $array = preg_split("/\r\n|\n|\r/", $data); + $array = preg_replace(["/\s*array\s\($/", "/\)(,)?$/", "/\s=>\s$/"], [NULL, ']$1', ' => ['], $array); + $data = implode(PHP_EOL, array_filter(["["] + $array)); + + // add needed indentation to the last ] + $data = preg_replace("/^(\])/m", Indent::_($default) . '$1', $data); + + return $data; + } + return null; + } + + /** + * Method to convert found of grouped spaces to system indentation + * + * @param array $matches The regex array of matching values + * + * @return string The resulting string. + * + * @since 3.4.0 + */ + protected function convertIndent(array $matches): string + { + // set number to indent by default + $indent = Indent::_($this->indent); + + // update each found space (group) with one indentation + foreach (range(1, 11) as $space) + { + if (strlen((string) $matches[$space]) > 0) + { + $indent .= Indent::_(1); + } + } + + return $indent . $matches[12]; + } diff --git a/src/e6a64c41-405e-4bbc-9722-27402c22bbea/code.power b/src/e6a64c41-405e-4bbc-9722-27402c22bbea/code.power new file mode 100644 index 0000000..91e0be4 --- /dev/null +++ b/src/e6a64c41-405e-4bbc-9722-27402c22bbea/code.power @@ -0,0 +1,301 @@ + /** + * Compiler Config + * + * @var Config + * @since 3.2.0 + */ + protected Config $config; + + /** + * The compiler registry + * + * @var Registry + * @since 3.2.0 + */ + protected Registry $registry; + + /** + * Compiler History + * + * @var HistoryInterface + * @since 3.2.0 + */ + protected HistoryInterface $history; + + /** + * Compiler Customcode + * + * @var Customcode + * @since 3.2.0 + */ + protected Customcode $customcode; + + /** + * Compiler Field + * + * @var Field + * @since 3.2.0 + */ + protected Field $field; + + /** + * Compiler Field Name + * + * @var FieldName + * @since 3.2.0 + */ + protected FieldName $fieldName; + + /** + * Compiler Update Sql + * + * @var UpdateSql + * @since 3.2.0 + */ + protected UpdateSql $updateSql; + + /** + * Application object. + * + * @var CMSApplication + * @since 3.2.0 + **/ + protected CMSApplication $app; + + /** + * Constructor + * + * @param Config|null $config The compiler config object. + * @param Registry|null $registry The compiler registry object. + * @param HistoryInterface|null $history The compiler history object. + * @param Customcode|null $customcode The compiler customcode object. + * @param Field|null $field The compiler field object. + * @param FieldName|null $fieldName The compiler field name object. + * @param UpdateSql|null $updateSql The compiler field name object. + * @param CMSApplication|null $app The app object. + * + * @since 3.2.0 + */ + public function __construct(?Config $config = null, ?Registry $registry = null, + ?HistoryInterface $history = null, ?Customcode $customcode = null, + ?Field $field = null, ?FieldName $fieldName = null, + ?UpdateSql $updateSql = null, ?CMSApplication $app = null) + { + $this->config = $config ?: Compiler::_('Config'); + $this->registry = $registry ?: Compiler::_('Registry'); + $this->history = $history ?: Compiler::_('History'); + $this->customcode = $customcode ?: Compiler::_('Customcode'); + $this->field = $field ?: Compiler::_('Field'); + $this->fieldName = $fieldName ?: Compiler::_('Field.Name'); + $this->updateSql = $updateSql ?: Compiler::_('Model.Updatesql'); + $this->app = $app ?: Factory::getApplication(); + } + + /** + * Set fields + * + * @param object $item The view data + * + * @return void + * @since 3.2.0 + */ + public function set(object &$item) + { + $item->fields = []; + + $item->addfields = (isset($item->addfields) + && JsonHelper::check($item->addfields)) + ? json_decode((string) $item->addfields, true) : null; + + if (ArrayHelper::check($item->addfields)) + { + $ignore_fields = []; + $default_fields = $this->config->default_fields; + + // load the field data + $item->fields = array_map( + function ($field) use ( + &$item, &$ignore_fields, &$default_fields + ) { + // set the field details + $this->field->set( + $field, $item->name_single_code, + $item->name_list_code + ); + + // check if this field is a default field OR + // check if this is none database related field + if (in_array($field['base_name'], $default_fields) + || FieldHelper::check($field['type_name'], 'spacer') + || (isset($field['list']) && $field['list'] == 2)) // 2 = none database + { + $ignore_fields[$field['field']] = $field['field']; + } + + // return field + return $field; + + }, array_values($item->addfields) + ); + + // build update SQL + if ($old_view = $this->history->get( + 'admin_fields', $item->addfields_id + )) + { + // add new fields were added + if (isset($old_view->addfields) + && JsonHelper::check( + $old_view->addfields + )) + { + $this->updateSql->set( + json_decode((string) $old_view->addfields, true), + $item->addfields, 'field', $item->name_single_code, + $ignore_fields + ); + } + // clear this data + unset($old_view); + } + + // sort the fields according to order + usort( + $item->fields, function ($a, $b) { + if (isset($a['order_list']) && isset($b['order_list'])) + { + if ($a['order_list'] != 0 && $b['order_list'] != 0) + { + return $a['order_list'] - $b['order_list']; + } + elseif ($b['order_list'] != 0 && $a['order_list'] == 0) + { + return 1; + } + elseif ($a['order_list'] != 0 && $b['order_list'] == 0) + { + return 0; + } + + return 1; + } + + return 0; + } + ); + + // do some house cleaning (for fields) + foreach ($item->fields as $field) + { + // so first we lock the field name in + $field_name = $this->fieldName->get( + $field, $item->name_list_code + ); + + // check if the field changed since the last compilation + // (default fields never change and are always added) + if (!isset($ignore_fields[$field['field']]) + && ObjectHelper::check( + $field['settings']->history + )) + { + // check if the datatype changed + if (isset($field['settings']->history->datatype)) + { + $this->updateSql->set( + $field['settings']->history->datatype, + $field['settings']->datatype, 'field.datatype', + $item->name_single_code . '.' . $field_name + ); + } + + // check if the datatype lenght changed + if (isset($field['settings']->history->datalenght) + && isset($field['settings']->history->datalenght_other)) + { + $this->updateSql->set( + $field['settings']->history->datalenght + . $field['settings']->history->datalenght_other, + $field['settings']->datalenght + . $field['settings']->datalenght_other, + 'field.lenght', + $item->name_single_code . '.' . $field_name + ); + } + + // check if the name changed + if (isset($field['settings']->history->xml) + && JsonHelper::check( + $field['settings']->history->xml + )) + { + // only run if this is not an alias or a tag + if ((!isset($field['alias']) || !$field['alias']) + && 'tag' !== $field['settings']->type_name) + { + // build temp field bucket + $tmpfield = []; + $tmpfield['settings'] = new \stdClass(); + + // convert the xml json string to normal string + $tmpfield['settings']->xml + = $this->customcode->update( + json_decode( + (string) $field['settings']->history->xml + ) + ); + + // add properties from current field as it is generic + $tmpfield['settings']->properties + = $field['settings']->properties; + // add the old name + $tmpfield['settings']->name + = $field['settings']->history->name; + // add the field type from current field since it is generic + $tmpfield['settings']->type_name + = $field['settings']->type_name; + // get the old name + $old_field_name = $this->fieldName->get( + $tmpfield + ); + + // only run this if not a multi field + if ($this->registry->get('unique.names.' . $item->name_list_code . '.names.' . $field_name) === null) + { + // this only works when the field is + // not multiple of the same field + $this->updateSql->set( + $old_field_name, $field_name, + 'field.name', + $item->name_single_code . '.' + . $field_name + ); + } + elseif ($old_field_name !== $field_name) + { + // give a notice atleast that the multi fields + // could have changed and no DB update was done + $this->app->enqueueMessage( + Text::_('

Field Notice

'), + 'Notice' + ); + $this->app->enqueueMessage( + Text::sprintf( + 'You have a field called %s that has been added multiple times to the %s view, the name of that field has changed to %s. Normaly we would automaticly add the update SQL to your component, but with multiple fields this does not work automaticly since it could be that noting changed and it just seems like it did. Therefore you will have to do this manualy if it actualy did change!', + $field_name, + $item->name_single_code, + $old_field_name + ), 'Notice' + ); + } + + // remove tmp + unset($tmpfield); + } + } + } + } + } + + unset($item->addfields); + } diff --git a/src/e6d871a6-bbe7-497d-af01-68f6bb9a87f4/code.power b/src/e6d871a6-bbe7-497d-af01-68f6bb9a87f4/code.power new file mode 100644 index 0000000..e27efc8 --- /dev/null +++ b/src/e6d871a6-bbe7-497d-af01-68f6bb9a87f4/code.power @@ -0,0 +1,375 @@ + /** + * The folder counter + * + * @var int + * @since 3.2.0 + */ + public int $folder = 0; + + /** + * The file counter + * + * @var int + * @since 3.2.0 + */ + public int $file = 0; + + /** + * The page counter + * + * @var int + * @since 3.2.0 + */ + public int $page = 0; + + /** + * The line counter + * + * @var int + * @since 3.2.0 + */ + public int $line = 0; + + /** + * The field counter + * + * @var int + * @since 3.2.0 + */ + public int $field = 0; + + /** + * The seconds counter + * + * @var int + * @since 3.2.0 + */ + protected int $seconds = 0; + + /** + * The actual seconds counter + * + * @var float + * @since 3.2.0 + */ + protected float $actualSeconds = 0; + + /** + * The folder seconds counter + * + * @var int + * @since 3.2.0 + */ + protected int $folderSeconds = 0; + + /** + * The file seconds counter + * + * @var int + * @since 3.2.0 + */ + protected int $fileSeconds = 0; + + /** + * The line seconds counter + * + * @var int + * @since 3.2.0 + */ + protected int $lineSeconds = 0; + + /** + * The seconds debugging counter + * + * @var float + * @since 3.2.0 + */ + protected float $secondsDebugging = 0; + + /** + * The seconds planning counter + * + * @var float + * @since 3.2.0 + */ + protected float $secondsPlanning = 0; + + /** + * The seconds mapping counter + * + * @var float + * @since 3.2.0 + */ + protected float $secondsMapping = 0; + + /** + * The seconds office counter + * + * @var float + * @since 3.2.0 + */ + protected float $secondsOffice = 0; + + /** + * The total hours counter + * + * @var int + * @since 3.2.0 + */ + protected int $totalHours = 0; + + /** + * The debugging hours counter + * + * @var int + * @since 3.2.0 + */ + protected int $debuggingHours = 0; + + /** + * The planning hours counter + * + * @var int + * @since 3.2.0 + */ + protected int $planningHours = 0; + + /** + * The mapping hours counter + * + * @var int + * @since 3.2.0 + */ + protected int $mappingHours = 0; + + /** + * The office hours counter + * + * @var int + * @since 3.2.0 + */ + protected int $officeHours = 0; + + /** + * The actual Total Hours counter + * + * @var int + * @since 3.2.0 + */ + protected int $actualTotalHours = 0; + + /** + * The actual hours spent counter + * + * @var int + * @since 3.2.0 + */ + protected int $actualHoursSpent = 0; + + /** + * The actual days spent counter + * + * @var int + * @since 3.2.0 + */ + protected int $actualDaysSpent = 0; + + /** + * The total days counter + * + * @var int + * @since 3.2.0 + */ + protected int $totalDays = 0; + + /** + * The actual Total Days counter + * + * @var int + * @since 3.2.0 + */ + protected int $actualTotalDays = 0; + + /** + * The project week time counter + * + * @var float + * @since 3.2.0 + */ + protected float $projectWeekTime = 0; + + /** + * The project month time counter + * + * @var float + * @since 3.2.0 + */ + protected float $projectMonthTime = 0; + + /** + * The compiler start timer + * + * @var float + * @since 3.2.0 + */ + protected float $start = 0; + + /** + * The compiler end timer + * + * @var float + * @since 3.2.0 + */ + protected float $end = 0; + + /** + * The compiler timer + * + * @var float + * @since 3.2.0 + */ + protected float $timer = 0; + + /** + * Compiler Content + * + * @var Content + * @since 3.2.0 + **/ + protected Content $content; + + /** + * Constructor + * + * @param Content|null $content The compiler content object. + * + * @since 3.2.0 + */ + public function __construct(?Content $content = null) + { + $this->content = $content ?: Compiler::_('Content'); + } + + /** + * Start the timer + * + * @return void + * @since 3.2.0 + */ + public function start() + { + $this->start = microtime(true); + } + + /** + * End the timer + * + * @return void + * @since 3.2.0 + */ + public function end() + { + $this->end = microtime(true); + + // calculate the lenght + $this->timer = $this->end - $this->start; + + // compiler time + $this->content->set('COMPILER_TIMER_END', $this->end); + $this->content->set('COMPILER_TIMER', $this->timer); + } + + /** + * Set all the time values + * + * @return void + * @since 3.2.0 + */ + public function set() + { + // calculate all the values + $this->calculate(); + + // set some defaults + $this->content->set('LINE_COUNT', $this->line); + $this->content->set('FIELD_COUNT', $this->field); + $this->content->set('FILE_COUNT', $this->file); + $this->content->set('FOLDER_COUNT', $this->folder); + $this->content->set('PAGE_COUNT', $this->page); + $this->content->set('folders', $this->folderSeconds); + $this->content->set('foldersSeconds', $this->folderSeconds); + $this->content->set('files', $this->fileSeconds); + $this->content->set('filesSeconds', $this->fileSeconds); + $this->content->set('lines', $this->lineSeconds); + $this->content->set('linesSeconds', $this->lineSeconds); + $this->content->set('seconds', $this->actualSeconds); + $this->content->set('actualSeconds', $this->actualSeconds); + $this->content->set('totalHours', $this->totalHours); + $this->content->set('totalDays', $this->totalDays); + $this->content->set('debugging', $this->secondsDebugging); + $this->content->set('secondsDebugging', $this->secondsDebugging); + $this->content->set('planning', $this->secondsPlanning); + $this->content->set('secondsPlanning', $this->secondsPlanning); + $this->content->set('mapping', $this->secondsMapping); + $this->content->set('secondsMapping', $this->secondsMapping); + $this->content->set('office', $this->secondsOffice); + $this->content->set('secondsOffice', $this->secondsOffice); + $this->content->set('actualTotalHours', $this->actualTotalHours); + $this->content->set('actualTotalDays', $this->actualTotalDays); + $this->content->set('debuggingHours', $this->debuggingHours); + $this->content->set('planningHours', $this->planningHours); + $this->content->set('mappingHours', $this->mappingHours); + $this->content->set('officeHours', $this->officeHours); + $this->content->set('actualHoursSpent', $this->actualHoursSpent); + $this->content->set('actualDaysSpent', $this->actualDaysSpent); + $this->content->set('projectWeekTime', $this->projectWeekTime); + $this->content->set('projectMonthTime', $this->projectMonthTime); + + // compiler time + $this->content->set('COMPILER_TIMER_START', $this->start); + } + + /** + * Calculate all the time values + * + * @return void + * @since 3.2.0 + */ + protected function calculate() + { + // what is the size in terms of an A4 book + $this->page = round($this->line / 56); + + // setup the unrealistic numbers + $this->folderSeconds = $this->folder * 5; + $this->fileSeconds = $this->file * 5; + $this->lineSeconds = $this->line * 10; + $this->seconds = $this->folderSeconds + $this->fileSeconds + + $this->lineSeconds; + $this->totalHours = round($this->seconds / 3600); + $this->totalDays = round($this->totalHours / 8); + + // setup the more realistic numbers + $this->secondsDebugging = $this->seconds / 4; + $this->secondsPlanning = $this->seconds / 7; + $this->secondsMapping = $this->seconds / 10; + $this->secondsOffice = $this->seconds / 6; + $this->actualSeconds = $this->folderSeconds + $this->fileSeconds + + $this->lineSeconds + $this->secondsDebugging + + $this->secondsPlanning + $this->secondsMapping + + $this->secondsOffice; + $this->actualTotalHours = round($this->actualSeconds / 3600); + $this->actualTotalDays = round($this->actualTotalHours / 8); + $this->debuggingHours = round($this->secondsDebugging / 3600); + $this->planningHours = round($this->secondsPlanning / 3600); + $this->mappingHours = round($this->secondsMapping / 3600); + $this->officeHours = round($this->secondsOffice / 3600); + + // the actual time spent + $this->actualHoursSpent = $this->actualTotalHours - $this->totalHours; + $this->actualDaysSpent = $this->actualTotalDays - $this->totalDays; + + // calculate the projects actual time frame of completion + $this->projectWeekTime = round($this->actualTotalDays / 5, 1); + $this->projectMonthTime = round($this->actualTotalDays / 24, 1); + } diff --git a/src/e79842d3-51b7-4282-93c7-3487cd8b61ab/code.power b/src/e79842d3-51b7-4282-93c7-3487cd8b61ab/code.power new file mode 100644 index 0000000..f75d4c4 --- /dev/null +++ b/src/e79842d3-51b7-4282-93c7-3487cd8b61ab/code.power @@ -0,0 +1,61 @@ + /** + * The areas add array + * + * @var array + * @since 3.2.0 + */ + protected array $areas = [ + 'css_view', 'css_views' + ]; + + /** + * Compiler Customcode Dispenser + * + * @var Dispenser + * @since 3.2.0 + */ + protected Dispenser $dispenser; + + /** + * Constructor + * + * @param Dispenser|null $dispenser The compiler customcode dispenser + * + * @since 3.2.0 + */ + public function __construct(?Dispenser $dispenser = null) + { + $this->dispenser = $dispenser ?: Compiler::_('Customcode.Dispenser'); + } + + /** + * Set Admin View Css + * + * @param object $item The item data + * + * @return void + * @since 3.2.0 + */ + public function set(object &$item) + { + foreach ($this->areas as $area) + { + if (isset($item->{'add_' . $area}) + && $item->{'add_' . $area} == 1 + && StringHelper::check($item->{$area})) + { + $this->dispenser->set( + $item->{$area}, + $area, + $item->name_single_code, + null, + ['prefix' => PHP_EOL], + true, + true, + true + ); + + unset($item->{$area}); + } + } + } diff --git a/src/ea5ed06e-72ae-4906-9167-1cc0fa32fe69/code.power b/src/ea5ed06e-72ae-4906-9167-1cc0fa32fe69/code.power new file mode 100644 index 0000000..c08bfc2 --- /dev/null +++ b/src/ea5ed06e-72ae-4906-9167-1cc0fa32fe69/code.power @@ -0,0 +1,59 @@ + /** + * 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(Registry::class, 'Registry') + ->share('Registry', [$this, 'getRegistry'], true); + + $container->alias(Table::class, 'Table') + ->share('Table', [$this, 'getTable'], true); + } + + /** + * Get the Compiler Configurations + * + * @param Container $container The DI container. + * + * @return Config + * @since 3.2.0 + */ + public function getConfig(Container $container): Config + { + return new Config(); + } + + /** + * Get the Compiler Registry + * + * @param Container $container The DI container. + * + * @return Registry + * @since 3.2.0 + */ + public function getRegistry(Container $container): Registry + { + return new Registry(); + } + + /** + * Get the Table + * + * @param Container $container The DI container. + * + * @return Table + * @since 3.2.0 + */ + public function getTable(Container $container): Table + { + return new Table(); + } + diff --git a/src/eb33420d-359d-44a5-852e-613aef1feaae/code.power b/src/eb33420d-359d-44a5-852e-613aef1feaae/code.power new file mode 100644 index 0000000..1468483 --- /dev/null +++ b/src/eb33420d-359d-44a5-852e-613aef1feaae/code.power @@ -0,0 +1,96 @@ + /** + * Get the field's actual type + * + * @param object $field The field object + * + * @return string Success returns field type + * @since 3.2.0 + */ + public function get(&$field) + { + // check if we have done this already + if (isset($field['type_name'])) + { + return $field['type_name']; + } + + // check that we have the properties + if (isset($field['settings']) + && ObjectHelper::check( + $field['settings'] + ) + && isset($field['settings']->properties) + && ArrayHelper::check( + $field['settings']->properties + )) + { + // search for own custom fields + if (strpos((string) $field['settings']->type_name, '@') !== false) + { + // set own custom field + $field['settings']->own_custom = $field['settings']->type_name; + $field['settings']->type_name = 'Custom'; + } + + // set the type name + $type_name = TypeHelper::safe( + $field['settings']->type_name + ); + + // if custom (we must use the xml value) + if (strtolower((string) $type_name) === 'custom' + || strtolower((string) $type_name) === 'customuser') + { + $type = TypeHelper::safe( + GetHelper::between( + $field['settings']->xml, 'type="', '"' + ) + ); + } + else + { + // loop over properties looking for the type value + foreach ($field['settings']->properties as $property) + { + if ($property['name'] + === 'type') // type field is never adjustable (unless custom) + { + // force the default value + if (isset($property['example']) + && StringHelper::check( + $property['example'] + )) + { + $type = TypeHelper::safe( + $property['example'] + ); + } + // fall back on the xml settings (not ideal) + else + { + $type = TypeHelper::safe( + GetHelper::between( + $field['settings']->xml, 'type="', '"' + ) + ); + } + // exit foreach loop + break; + } + } + } + // check if the value is set + if (isset($type) && StringHelper::check($type)) + { + return $type; + } + // fallback on type name set in name field (not ideal) + else + { + return $type_name; + } + } + + // fall back to text + return 'text'; + } diff --git a/src/ebe3287d-bfa0-4519-b663-f442f4dea432/code.power b/src/ebe3287d-bfa0-4519-b663-f442f4dea432/code.power new file mode 100644 index 0000000..721bbe9 --- /dev/null +++ b/src/ebe3287d-bfa0-4519-b663-f442f4dea432/code.power @@ -0,0 +1,125 @@ + /** + * The areas add array + * + * @var array + * @since 3.2.0 + */ + protected array $areas = [ + 'php_model', + 'php_controller', + 'php_model_list', + 'php_controller_list' + ]; + + /** + * The gui mapper array + * + * @var array + * @since 3.2.0 + */ + protected array $guiMapper = [ + 'table' => 'admin_view', + 'id' => null, + 'field' => null, + 'type' => 'php' + ]; + + /** + * Compiler Customcode + * + * @var Customcode + * @since 3.2.0 + */ + protected Customcode $customcode; + + /** + * Compiler Customcode in Gui + * + * @var Gui + * @since 3.2.0 + **/ + protected Gui $gui; + + /** + * Compiler Template Layout + * + * @var Templatelayout + * @since 3.2.0 + */ + protected Templatelayout $templateLayout; + + /** + * Constructor + * + * @param Customcode|null $customcode The compiler customcode object. + * @param Gui|null $gui The compiler customcode gui. + * @param Templatelayout|null $templateLayout The compiler template layout object. + * + * @since 3.2.0 + */ + public function __construct(?Customcode $customcode = null, ?Gui $gui = null, + ?Templatelayout $templateLayout = null) + { + $this->customcode = $customcode ?: Compiler::_('Customcode'); + $this->gui = $gui ?: Compiler::_('Customcode.Gui'); + $this->templateLayout = $templateLayout ?: Compiler::_('Templatelayout.Data'); + } + + /** + * Set Custom Buttons and Model/Controllers + * + * @param object $item The item data + * @param object $table The table + * + * @return void + * @since 3.2.0 + */ + public function set(object &$item, string $table = 'admin_view') + { + if (isset($item->add_custom_button) + && $item->add_custom_button == 1) + { + // set some gui mapper values + $this->guiMapper['table'] = $table; + $this->guiMapper['id'] = (int) $item->id; + + // get the code + $code = $item->name_single_code ?? $item->code ?? 'error'; + + // set for the code + foreach ($this->areas as $area) + { + if (isset($item->{$area}) + && StringHelper::check( + $item->{$area} + )) + { + // set field + $this->guiMapper['field'] = $area; + $item->{$area} = $this->gui->set( + $this->customcode->update( + base64_decode((string) $item->{$area}) + ), + $this->guiMapper + ); + + // check if we have template or layouts to load + $this->templateLayout->set( + $item->{$area}, $code + ); + } + } + + // set the button array + $item->custom_button = (isset($item->custom_button) + && JsonHelper::check($item->custom_button)) + ? json_decode((string) $item->custom_button, true) : null; + + if (ArrayHelper::check($item->custom_button)) + { + $item->custom_buttons = array_values($item->custom_button); + } + + unset($item->custom_button); + } + } diff --git a/src/ed9591cb-0a03-400a-bf47-eaf78ab19b9d/code.power b/src/ed9591cb-0a03-400a-bf47-eaf78ab19b9d/code.power new file mode 100644 index 0000000..41824d8 --- /dev/null +++ b/src/ed9591cb-0a03-400a-bf47-eaf78ab19b9d/code.power @@ -0,0 +1,55 @@ + /** + * Current Joomla Version Being Build + * + * @var int + * @since 3.2.0 + **/ + protected $targetVersion; + + /** + * 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(GetScriptInterface::class, 'Extension.InstallScript') + ->share('Extension.InstallScript', [$this, 'getExtensionInstallScript'], true); + + $container->alias(J3InstallScript::class, 'J3.Extension.InstallScript') + ->share('J3.Extension.InstallScript', [$this, 'getJ3ExtensionInstallScript'], true); + } + + /** + * Get the Joomla 3 Extension Install Script + * + * @param Container $container The DI container. + * + * @return J3InstallScript + * @since 3.2.0 + */ + public function getJ3ExtensionInstallScript(Container $container): J3InstallScript + { + return new J3InstallScript(); + } + + /** + * Get the Joomla Extension Install Script + * + * @param Container $container The DI container. + * + * @return GetScriptInterface + * @since 3.2.0 + */ + public function getExtensionInstallScript(Container $container): GetScriptInterface + { + if (empty($this->targetVersion)) + { + $this->targetVersion = $container->get('Config')->joomla_version; + } + + return $container->get('J' . $this->targetVersion . '.Extension.InstallScript'); + } diff --git a/src/ef687e42-dc25-4423-9dd4-ec6e9743cfb0/code.power b/src/ef687e42-dc25-4423-9dd4-ec6e9743cfb0/code.power new file mode 100644 index 0000000..b46af5a --- /dev/null +++ b/src/ef687e42-dc25-4423-9dd4-ec6e9743cfb0/code.power @@ -0,0 +1,38 @@ + /** + * Set the script for the customcode dispenser + * + * @param string $script The script + * @param string $first The first key + * @param string|null $second The second key (if not set we use only first key) + * @param string|null $third The third key (if not set we use only first and second key) + * @param array $config The config options + * @param bool $base64 The switch to decode base64 the script + * default: true + * @param bool $dynamic The switch to dynamic update the script + * default: true + * @param bool $add The switch to add to exiting instead of replace + * default: false + * + * @return bool true on success + * @since 3.2.0 + */ + public function set(&$script, string $first, ?string $second = null, ?string $third = null, + array $config = [], bool $base64 = true, bool $dynamic = true, bool $add = false): bool; + + /** + * Get the script from the customcode dispenser + * + * @param string $first The first key + * @param string $second The second key + * @param string $prefix The prefix to add in front of the script if found + * @param string|null $note The switch/note to add to the script + * @param bool $unset The switch to unset the value if found + * @param mixed|null $default The switch/string to use as default return if script not found + * @param string $suffix The suffix to add after the script if found + * + * @return mixed The string/script if found or the default value if not found + * + * @since 3.2.0 + */ + public function get(string $first, string $second, string $prefix = '', ?string $note = null, + bool $unset = false, $default = null, string $suffix = ''); diff --git a/src/ef9578e5-4c9d-46bf-866f-3a94bdc7b753/code.power b/src/ef9578e5-4c9d-46bf-866f-3a94bdc7b753/code.power new file mode 100644 index 0000000..8a81487 --- /dev/null +++ b/src/ef9578e5-4c9d-46bf-866f-3a94bdc7b753/code.power @@ -0,0 +1,825 @@ + /** + * Compiler Config + * + * @var Config + * @since 3.2.0 + */ + protected Config $config; + + /** + * Compiler Event + * + * @var EventInterface + * @since 3.2.0 + */ + protected EventInterface $event; + + /** + * Compiler Placeholder + * + * @var Placeholder + * @since 3.2.0 + */ + protected Placeholder $placeholder; + + /** + * Compiler Component Placeholder + * + * @var ComponentPlaceholder + * @since 3.2.0 + **/ + protected ComponentPlaceholder $componentPlaceholder; + + /** + * Compiler Customcode Dispenser + * + * @var Dispenser + * @since 3.2.0 + */ + protected Dispenser $dispenser; + + /** + * Compiler Customcode + * + * @var Customcode + * @since 3.2.0 + */ + protected Customcode $customcode; + + /** + * Compiler Customcode in Gui + * + * @var Gui + * @since 3.2.0 + **/ + protected Gui $gui; + + /** + * Compiler Field + * + * @var Field + * @since 3.2.0 + */ + protected Field $field; + + /** + * Compiler field name + * + * @var FieldName + * @since 3.2.0 + */ + protected FieldName $fieldName; + + /** + * Compiler Field Unique Name + * + * @var UniqueName + * @since 3.2.0 + **/ + protected UniqueName $uniqueName; + + /** + * Compiler Files Folders + * + * @var Filesfolders + * @since 3.2.0 + */ + protected Filesfolders $filesFolders; + + /** + * The modelling component history + * + * @var Historycomponent + * @since 3.2.0 + */ + protected Historycomponent $history; + + /** + * The modelling whmcs + * + * @var Whmcs + * @since 3.2.0 + */ + protected Whmcs $whmcs; + + /** + * The modelling Sql Tweaking + * + * @var Sqltweaking + * @since 3.2.0 + */ + protected Sqltweaking $sqltweaking; + + /** + * The modelling Admin Views + * + * @var Adminviews + * @since 3.2.0 + */ + protected Adminviews $adminviews; + + /** + * The modelling Site Views + * + * @var Siteviews + * @since 3.2.0 + */ + protected Siteviews $siteviews; + + /** + * The modelling Custom Admin Views + * + * @var Customadminviews + * @since 3.2.0 + */ + protected Customadminviews $customadminviews; + + /** + * The modelling Update Server + * + * @var Updateserver + * @since 3.2.0 + */ + protected Updateserver $updateserver; + + /** + * The modelling Joomla Modules + * + * @var Joomlamodules + * @since 3.2.0 + */ + protected Joomlamodules $modules; + + /** + * The modelling Joomla Plugins + * + * @var Joomlaplugins + * @since 3.2.0 + */ + protected Joomlaplugins $plugins; + + /** + * Database object to query local DB + * + * @var \JDatabaseDriver + * @since 3.2.0 + **/ + protected \JDatabaseDriver $db; + + /** + * Constructor + * + * @param Config|null $config The compiler config object. + * @param EventInterface|null $event The compiler event api object. + * @param Placeholder|null $placeholder The compiler placeholder object. + * @param ComponentPlaceholder|null $componentPlaceholder The compiler component placeholder object. + * @param Dispenser|null $dispenser The compiler customcode dispenser object. + * @param Customcode|null $customcode The compiler customcode object. + * @param Gui|null $gui The compiler customcode gui. + * @param Field|null $field The compiler field object. + * @param FieldName|null $fieldName The compiler field name object. + * @param UniqueName|null $uniqueName The compiler field unique name object. + * @param Filesfolders|null $filesFolders The compiler files folders object. + * @param Historycomponent|null $history The modelling component history object. + * @param Whmcs|null $whmcs The modelling whmcs object. + * @param Sqltweaking|null $sqltweaking The modelling sql tweaking object. + * @param Adminviews|null $adminviews The modelling adminviews object. + * @param Siteviews|null $siteviews The modelling siteviews object. + * @param Customadminviews|null $customadminviews The modelling customadminviews object. + * @param Updateserver|null $updateserver The modelling update server object. + * @param Joomlamodules|null $modules The modelling modules object. + * @param Joomlaplugins|null $plugins The modelling plugins object. + * @param \JDatabaseDriver|null $db The database object. + * + * @since 3.2.0 + */ + public function __construct(?Config $config = null, ?EventInterface $event = null, + ?Placeholder $placeholder = null, ?ComponentPlaceholder $componentPlaceholder = null, + ?Dispenser $dispenser = null, ?Customcode $customcode = null, ?Gui $gui = null, + ?Field $field = null, ?FieldName $fieldName = null, ?UniqueName $uniqueName = null, + ?Filesfolders $filesFolders = null, ?Historycomponent $history = null, ?Whmcs $whmcs = null, + ?Sqltweaking $sqltweaking = null, ?Adminviews $adminviews = null, ?Siteviews $siteviews = null, + ?Customadminviews $customadminviews = null, ?Updateserver $updateserver = null, + ?Joomlamodules $modules = null, ?Joomlaplugins $plugins = null, ?\JDatabaseDriver $db = null) + { + $this->config = $config ?: Compiler::_('Config'); + $this->event = $event ?: Compiler::_('Event'); + $this->placeholder = $placeholder ?: Compiler::_('Placeholder'); + $this->componentPlaceholder = $componentPlaceholder ?: Compiler::_('Component.Placeholder'); + $this->dispenser = $dispenser ?: Compiler::_('Customcode.Dispenser'); + $this->customcode = $customcode ?: Compiler::_('Customcode'); + $this->gui = $gui ?: Compiler::_('Customcode.Gui'); + $this->field = $field ?: Compiler::_('Field'); + $this->fieldName = $fieldName ?: Compiler::_('Field.Name'); + $this->uniqueName = $uniqueName ?: Compiler::_('Field.Unique.Name'); + $this->filesFolders = $filesFolders ?: Compiler::_('Model.Filesfolders'); + $this->history = $history ?: Compiler::_('Model.Historycomponent'); + $this->whmcs = $whmcs ?: Compiler::_('Model.Whmcs'); + $this->sqltweaking = $sqltweaking ?: Compiler::_('Model.Sqltweaking'); + $this->adminviews = $adminviews ?: Compiler::_('Model.Adminviews'); + $this->siteviews = $siteviews ?: Compiler::_('Model.Siteviews'); + $this->customadminviews = $customadminviews ?: Compiler::_('Model.Customadminviews'); + $this->updateserver = $updateserver ?: Compiler::_('Model.Updateserver'); + $this->modules = $modules ?: Compiler::_('Model.Joomlamodules'); + $this->plugins = $plugins ?: Compiler::_('Model.Joomlaplugins'); + $this->db = $db ?: Factory::getDbo(); + } + + /** + * get current component data + * + * @return object|null The component data + * @since 3.2.0 + */ + public function get(): ?object + { + // Create a new query object. + $query = $this->db->getQuery(true); + + // selection + $selection = array( + 'b.addadmin_views' => 'addadmin_views', + 'b.id' => 'addadmin_views_id', + 'h.addconfig' => 'addconfig', + 'd.addcustom_admin_views' => 'addcustom_admin_views', + 'g.addcustommenus' => 'addcustommenus', + 'j.addfiles' => 'addfiles', + 'j.addfolders' => 'addfolders', + 'j.addfilesfullpath' => 'addfilesfullpath', + 'j.addfoldersfullpath' => 'addfoldersfullpath', + 'c.addsite_views' => 'addsite_views', + 'l.addjoomla_plugins' => 'addjoomla_plugins', + 'k.addjoomla_modules' => 'addjoomla_modules', + 'i.dashboard_tab' => 'dashboard_tab', + 'i.php_dashboard_methods' => 'php_dashboard_methods', + 'i.params' => 'dashboard_params', + 'i.id' => 'component_dashboard_id', + 'f.sql_tweak' => 'sql_tweak', + 'e.version_update' => 'version_update', + 'e.id' => 'version_update_id' + ); + $query->select('a.*'); + $query->select( + $this->db->quoteName( + array_keys($selection), array_values($selection) + ) + ); + + // from this table + $query->from('#__componentbuilder_joomla_component AS a'); + + // jointer-map + $joiners = array( + 'b' => 'component_admin_views', + 'c' => 'component_site_views', + 'd' => 'component_custom_admin_views', + 'e' => 'component_updates', + 'f' => 'component_mysql_tweaks', + 'g' => 'component_custom_admin_menus', + 'h' => 'component_config', + 'i' => 'component_dashboard', + 'j' => 'component_files_folders', + 'l' => 'component_plugins', + 'k' => 'component_modules' + ); + + // load the joins + foreach ($joiners as $as => $join) + { + $query->join( + 'LEFT', + $this->db->quoteName('#__componentbuilder_' . $join, $as) + . ' ON (' . $this->db->quoteName('a.id') . ' = ' + . $this->db->quoteName($as . '.joomla_component') . ')' + ); + } + $query->where( + $this->db->quoteName('a.id') . ' = ' . (int) $this->config->component_id + ); + + // for plugin event TODO change event api signatures + $component_context = $this->config->component_context; + $component_id = $this->config->component_id; + + // Trigger Event: jcb_ce_onBeforeQueryComponentData + $this->event->trigger( + 'jcb_ce_onBeforeQueryComponentData', + array(&$component_context, &$component_id, &$query, + &$this->db) + ); + + // Reset the query using our newly populated query object. + $this->db->setQuery($query); + + // Load the results as a list of stdClass objects + $component = $this->db->loadObject(); + + // make sure we got a component loaded + if (!is_object($component) || !isset($component->system_name)) + { + return null; + } + + // Trigger Event: jcb_ce_onBeforeModelComponentData + $this->event->trigger( + 'jcb_ce_onBeforeModelComponentData', + array(&$component_context, &$component) + ); + + // load the global placeholders + $this->placeholder->active = $this->componentPlaceholder->get(); + + // set component sales name + $component->sales_name = StringHelper::safe( + $component->system_name + ); + + // set the component name_code + $component->name_code = StringHelper::safe( + $component->name_code + ); + + // ensure version naming is correct + $this->config->set('component_version', preg_replace( + '/[^0-9.]+/', '', (string) $component->component_version + ) + ); + + // set the website and autor for global use (default to VDM if not found) + $this->config->set('project_website', $component->website ?? 'https://dev.vdm.io'); + $this->config->set('project_author', $component->author ?? 'VDM'); + + // set the files and folders + $this->filesFolders->set($component); + + // set the uikit switch + $this->config->set('uikit', $component->adduikit); + + // set whmcs links if needed + $this->whmcs->set($component); + + // set the footable switch + if ($component->addfootable > 0) + { + // force add footable + $this->config->set('footable', true); + // add the version + $this->config->set('footable_version', (3 == $component->addfootable) ? 3 : 2); + } + + // set the addcustommenus data + $component->addcustommenus = (isset($component->addcustommenus) + && JsonHelper::check($component->addcustommenus)) + ? json_decode((string) $component->addcustommenus, true) : null; + if (ArrayHelper::check($component->addcustommenus)) + { + $component->custommenus = array_values($component->addcustommenus); + } + unset($component->addcustommenus); + + // set the sql tweak data + $this->sqltweaking->set($component); + + // set the admin view data + $this->adminviews->set($component); + + // set the site view data + $this->siteviews->set($component); + + // set the custom_admin_views data + $this->customadminviews->set($component); + + // set the config data + $component->addconfig = (isset($component->addconfig) + && JsonHelper::check($component->addconfig)) + ? json_decode((string) $component->addconfig, true) : null; + if (ArrayHelper::check($component->addconfig)) + { + $component->config = array_map( + function ($field) { + // make sure the alias and title is 0 + $field['alias'] = 0; + $field['title'] = 0; + // set the field details + $this->field->set($field); + // set unique name counter + $this->uniqueName->set($field['base_name'], 'configs'); + + // return field + return $field; + }, array_values($component->addconfig) + ); + + // do some house cleaning (for fields) + foreach ($component->config as $field) + { + // so first we lock the field name in + $this->fieldName->get($field, 'configs'); + } + // unset original value + unset($component->addconfig); + } + + // set the add contributors + $component->addcontributors = (isset($component->addcontributors) + && JsonHelper::check($component->addcontributors)) + ? json_decode((string) $component->addcontributors, true) : null; + if (ArrayHelper::check($component->addcontributors)) + { + $this->config->set('add_contributors', true); + $component->contributors = array_values( + $component->addcontributors + ); + } + unset($component->addcontributors); + + // set the version updates + $this->updateserver->set($component); + + // build the build date + if ($this->config->get('add_build_date', 1) == 3) + { + if (empty($this->component->modified) || + $this->component->modified == '0000-00-00' || + $this->component->modified == '0000-00-00 00:00:00') + { + $this->config->set('build_date', $this->component->created); + } + else + { + $this->config->set('build_date', $this->component->modified); + } + } + + // build update SQL + $this->history->set($component); + + // set GUI mapper + $guiMapper = [ + 'table' => 'joomla_component', + 'id' => (int) $this->config->component_id, + 'field' => 'javascript', + 'type' => 'js' + ]; + + // add_javascript + if ($component->add_javascript == 1) + { + $this->dispenser->set( + $component->javascript, + 'component_js', + null, + null, + $guiMapper + ); + } + else + { + $this->dispenser->hub['component_js'] = ''; + } + unset($component->javascript); + + // add global CSS + $addGlobalCss = ['admin', 'site']; + foreach ($addGlobalCss as $area) + { + // add_css if found + if (isset($component->{'add_css_' . $area}) + && $component->{'add_css_' . $area} == 1 + && isset($component->{'css_' . $area}) + && StringHelper::check( + $component->{'css_' . $area} + )) + { + $this->dispenser->set( + $component->{'css_' . $area}, + 'component_css_' . $area + ); + } + else + { + $this->dispenser->hub['component_css_' . $area] = ''; + } + unset($component->{'css_' . $area}); + } + + // set the lang target + $this->config->lang_target = 'admin'; + + // add PHP in ADMIN + $addScriptMethods = [ + 'php_preflight', + 'php_postflight', + 'php_method' + ]; + $addScriptTypes = [ + 'install', + 'update', + 'uninstall' + ]; + // update GUI mapper + $guiMapper['type'] = 'php'; + foreach ($addScriptMethods as $scriptMethod) + { + foreach ($addScriptTypes as $scriptType) + { + if (isset($component->{'add_' . $scriptMethod . '_' . $scriptType}) + && $component->{'add_' . $scriptMethod . '_' . $scriptType} == 1 + && StringHelper::check( + $component->{$scriptMethod . '_' . $scriptType} + )) + { + // set GUI mapper field + $guiMapper['field'] = $scriptMethod . '_' . $scriptType; + $this->dispenser->set( + $component->{$scriptMethod . '_' . $scriptType}, + $scriptMethod, + $scriptType, + null, + $guiMapper + ); + } + else + { + $this->dispenser->hub[$scriptMethod][$scriptType] = ''; + } + unset($component->{$scriptMethod . '_' . $scriptType}); + } + } + + // add_php_helper + if ($component->add_php_helper_admin == 1 + && StringHelper::check( + $component->php_helper_admin + )) + { + $this->config->lang_target = 'admin'; + // update GUI mapper + $guiMapper['field'] = 'php_helper_admin'; + $guiMapper['prefix'] = PHP_EOL . PHP_EOL; + $this->dispenser->set( + $component->php_helper_admin, + 'component_php_helper_admin', + null, + null, + $guiMapper + ); + unset($guiMapper['prefix']); + } + else + { + $this->dispenser->hub['component_php_helper_admin'] = ''; + } + unset($component->php_helper); + + // add_admin_event + if ($component->add_admin_event == 1 + && StringHelper::check($component->php_admin_event)) + { + $this->config->lang_target = 'admin'; + // update GUI mapper field + $guiMapper['field'] = 'php_admin_event'; + $this->dispenser->set( + $component->php_admin_event, + 'component_php_admin_event', + null, + null, + $guiMapper + ); + } + else + { + $this->dispenser->hub['component_php_admin_event'] = ''; + } + unset($component->php_admin_event); + + // add_php_helper_both + if ($component->add_php_helper_both == 1 + && StringHelper::check($component->php_helper_both)) + { + $this->config->lang_target = 'both'; + // update GUI mapper field + $guiMapper['field'] = 'php_helper_both'; + $guiMapper['prefix'] = PHP_EOL . PHP_EOL; + $this->dispenser->set( + $component->php_helper_both, + 'component_php_helper_both', + null, + null, + $guiMapper + ); + unset($guiMapper['prefix']); + } + else + { + $this->dispenser->hub['component_php_helper_both'] = ''; + } + + // add_php_helper_site + if ($component->add_php_helper_site == 1 + && StringHelper::check($component->php_helper_site)) + { + $this->config->lang_target = 'site'; + // update GUI mapper field + $guiMapper['field'] = 'php_helper_site'; + $guiMapper['prefix'] = PHP_EOL . PHP_EOL; + $this->dispenser->set( + $component->php_helper_site, + 'component_php_helper_site', + null, + null, + $guiMapper + ); + unset($guiMapper['prefix']); + } + else + { + $this->dispenser->hub['component_php_helper_site'] = ''; + } + unset($component->php_helper); + + // add_site_event + if ($component->add_site_event == 1 + && StringHelper::check($component->php_site_event)) + { + $this->config->lang_target = 'site'; + // update GUI mapper field + $guiMapper['field'] = 'php_site_event'; + $this->dispenser->set( + $component->php_site_event, + 'component_php_site_event', + null, + null, + $guiMapper + ); + } + else + { + $this->dispenser->hub['component_php_site_event'] = ''; + } + unset($component->php_site_event); + + // add_sql + if ($component->add_sql == 1) + { + $this->dispenser->set( + $component->sql, + 'sql', + 'component_sql' + ); + } + unset($component->sql); + + // add_sql_uninstall + if ($component->add_sql_uninstall == 1) + { + $this->dispenser->set( + $component->sql_uninstall, + 'sql_uninstall' + ); + } + unset($component->sql_uninstall); + + // bom + if (StringHelper::check($component->bom)) + { + $this->config->set('bom_path', + $this->config->get('compiler_path', JPATH_COMPONENT_ADMINISTRATOR . '/compiler') . '/' . $component->bom + ); + } + unset($component->bom); + + // README + $component->readme = + $component->addreadme ? + $this->customcode->update( + base64_decode((string) $component->readme) + ) : ''; + + // set lang now + $nowLang = $this->config->lang_target; + $this->config->lang_target = 'admin'; + + // dashboard methods + $component->dashboard_tab = (isset($component->dashboard_tab) + && JsonHelper::check($component->dashboard_tab)) + ? json_decode((string) $component->dashboard_tab, true) : null; + if (ArrayHelper::check($component->dashboard_tab)) + { + $component->dashboard_tab = array_map( + function ($array) { + $array['html'] = $this->customcode->update($array['html']); + + return $array; + }, array_values($component->dashboard_tab) + ); + } + else + { + $component->dashboard_tab = ''; + } + + // add the php of the dashboard if set + if (isset($component->php_dashboard_methods) + && StringHelper::check( + $component->php_dashboard_methods + )) + { + // load the php for the dashboard model + $component->php_dashboard_methods = $this->gui->set( + $this->customcode->update( + base64_decode((string) $component->php_dashboard_methods) + ), + [ + 'table' => 'component_dashboard', + 'field' => 'php_dashboard_methods', + 'id' => (int) $component->component_dashboard_id, + 'type' => 'php' + ] + ); + } + else + { + $component->php_dashboard_methods = ''; + } + + // reset back to now lang + $this->config->lang_target = $nowLang; + + // catch empty URL to update server TODO: we need to fix this in better way later + if (empty($component->add_update_server) || ($component->add_update_server == 1 && $component->update_server_target != 3 + && ( + !StringHelper::check($component->update_server_url) + || strpos($component->update_server_url, 'http') === false + ))) + { + // we fall back to other, since we can't work with an empty update server URL + $component->add_update_server = 0; + $component->update_server_target = 3; + $component->update_server_url = ''; + } + + // add the update/sales server FTP details if that is the expected protocol + $serverArray = array('update_server', 'sales_server'); + foreach ($serverArray as $server) + { + if ($component->{'add_' . $server} == 1 + && is_numeric($component->{$server}) + && $component->{$server} > 0) + { + // get the server protocol + $component->{$server . '_protocol'} + = GetHelper::var( + 'server', (int) $component->{$server}, 'id', 'protocol' + ); + } + else + { + $component->{$server} = 0; + // only change this for sales server (update server can be added loacaly to the zip file) + if ('sales_server' === $server) + { + $component->{'add_' . $server} = 0; + } + $component->{$server . '_protocol'} = 0; + } + } + + // set the ignore folders for repo if found + if (isset($component->toignore) + && StringHelper::check( + $component->toignore + )) + { + if (strpos((string) $component->toignore, ',') !== false) + { + $component->toignore = array_map( + 'trim', (array) explode(',', (string) $component->toignore) + ); + } + else + { + $component->toignore = array(trim((string) $component->toignore)); + } + } + else + { + // the default is to ignore the repo folder + $component->toignore = array('.git'); + } + + // set all modules + $this->modules->set($component); + + // set all plugins + $this->plugins->set($component); + + // Trigger Event: jcb_ce_onAfterModelComponentData + $this->event->trigger( + 'jcb_ce_onAfterModelComponentData', + array(&$component_context, &$component) + ); + + // return found component data + return $component; + } diff --git a/src/ef97b03e-1018-447a-8d7e-30401b0257bb/code.power b/src/ef97b03e-1018-447a-8d7e-30401b0257bb/code.power new file mode 100644 index 0000000..6a9a983 --- /dev/null +++ b/src/ef97b03e-1018-447a-8d7e-30401b0257bb/code.power @@ -0,0 +1,54 @@ + /** + * Compiler Joomla Plugin Data Class + * + * @var Plugin + * @since 3.2.0 + */ + protected Plugin $plugin; + + /** + * Constructor + * + * @param Plugin|null $plugin The compiler Joomla plugin data object. + * + * @since 3.2.0 + */ + public function __construct(?Plugin $plugin = null) + { + $this->plugin = $plugin ?: Compiler::_('Joomlaplugin.Data'); + } + + /** + * Set Joomla Plugins + * + * @param object $item The item data + * + * @return void + * @since 3.2.0 + */ + public function set(object &$item) + { + // get all plugins + $item->addjoomla_plugins = (isset($item->addjoomla_plugins) + && JsonHelper::check($item->addjoomla_plugins)) + ? json_decode((string) $item->addjoomla_plugins, true) : null; + + if (ArrayHelper::check($item->addjoomla_plugins)) + { + $joomla_plugins = array_map( + function ($array) use (&$item) { + // only load the plugins whose target association calls for it + if (!isset($array['target']) || $array['target'] != 2) + { + return $this->plugin->set( + $array['plugin'], $item + ); + } + + return null; + }, array_values($item->addjoomla_plugins) + ); + } + + unset($item->addjoomla_plugins); + } diff --git a/src/efb1d0f8-2d14-4d2c-8b5f-4fcdd9df45a5/code.power b/src/efb1d0f8-2d14-4d2c-8b5f-4fcdd9df45a5/code.power new file mode 100644 index 0000000..066a878 --- /dev/null +++ b/src/efb1d0f8-2d14-4d2c-8b5f-4fcdd9df45a5/code.power @@ -0,0 +1,76 @@ + /** + * Power Objects + * + * @var Power + * @since 3.2.0 + **/ + protected Power $power; + + /** + * Compiler Powers Plantuml Builder + * + * @var Plantuml + * @since 3.2.0 + **/ + protected Plantuml $plantuml; + + /** + * Constructor. + * + * @param Power|null $power The power object. + * @param Plantuml|null $plantuml The powers plantuml builder object. + * + * @since 3.2.0 + */ + public function __construct(?Power $power = null, ?Plantuml $plantuml = null) + { + $this->power = $power ?: Compiler::_('Power'); + $this->plantuml = $plantuml ?: Compiler::_('Power.Plantuml'); + } + + /** + * Get a Power Readme + * + * @param object $power A power details. + * + * @return string + * @since 3.2.0 + */ + public function get(object $power): string + { + // build readme + $readme = ["``` +██████╗ ██████╗ ██╗ ██╗███████╗██████╗ +██╔══██╗██╔═══██╗██║ ██║██╔════╝██╔══██╗ +██████╔╝██║ ██║██║ █╗ ██║█████╗ ██████╔╝ +██╔═══╝ ██║ ██║██║███╗██║██╔══╝ ██╔══██╗ +██║ ╚██████╔╝╚███╔███╔╝███████╗██║ ██║ +╚═╝ ╚═════╝ ╚══╝╚══╝ ╚══════╝╚═╝ ╚═╝ +```"]; + // add the class diagram + if (isset($power->parsed_class_code) && is_array($power->parsed_class_code)) + { + $readme[] = "# " . $power->type . " " . $power->code_name . " (Details)"; + $readme[] = "> namespace: **" . $power->_namespace . "**"; + $readme[] = "```uml\n@startuml" . $this->plantuml->classDetailedDiagram( + ['name' => $power->code_name, 'type' => $power->type], + $power->parsed_class_code + ) . " \n@enduml\n```"; + } + else + { + $readme[] = "> Error adding class diagram"; + } + + // yes you can remove this, but why? + $readme[] = "\n---\n``` + ██╗ ██████╗██████╗ + ██║██╔════╝██╔══██╗ + ██║██║ ██████╔╝ +██ ██║██║ ██╔══██╗ +╚█████╔╝╚██████╗██████╔╝ + ╚════╝ ╚═════╝╚═════╝ +```\n> Build with [Joomla Component Builder](https://git.vdm.dev/joomla/Component-Builder)\n\n"; + + return implode("\n", $readme); + } diff --git a/src/f02fb1df-f4b6-4be1-9595-2e72084a5e6e/code.power b/src/f02fb1df-f4b6-4be1-9595-2e72084a5e6e/code.power new file mode 100644 index 0000000..3e32cc9 --- /dev/null +++ b/src/f02fb1df-f4b6-4be1-9595-2e72084a5e6e/code.power @@ -0,0 +1,69 @@ + /** + * Unique Code/Strings + * + * @var array + * @since 3.2.0 + */ + protected static array $unique = []; + + /** + * Unique Areas Code/Strings + * + * @var array + * @since 3.2.0 + */ + protected static array $areas = []; + + /** + * Creating an unique local key + * + * @param int $size The key size + * + * @return string The unique local key + * + */ + public static function get($size): string + { + $unique = (isset(self::$unique[$size])) ? end(self::$unique[$size]) : null; + + if(!$unique) + { + $unique = substr("vvvvvvvvvvvvvvvvvvvvvvvvvvvvvv", 0, $size); + + self::$unique[$size] = []; + } + + while(in_array($unique, self::$unique[$size])) + { + $unique++; + } + + self::$unique[$size][] = $unique; + + return $unique; + } + + /** + * Creating an Unique Code + * + * @param string $code + * @param string $target + * + * @return string + * @since 3.2.0 + */ + public static function code(string $code, string $target = 'both'): string + { + if (!isset(self::$areas[$target]) + || !in_array( + $code, self::$areas[$target] + )) + { + self::$areas[$target][] = $code; + + return $code; + } + + // make sure it is unique + return self::code($code . self::get(1)); + } diff --git a/src/f05ac28d-44f4-4e6d-a1be-5c8ae6baf69c/code.power b/src/f05ac28d-44f4-4e6d-a1be-5c8ae6baf69c/code.power new file mode 100644 index 0000000..172fdc7 --- /dev/null +++ b/src/f05ac28d-44f4-4e6d-a1be-5c8ae6baf69c/code.power @@ -0,0 +1,229 @@ + /** + * Compiler Config + * + * @var Config + * @since 3.2.0 + */ + protected Config $config; + + /** + * The compiler registry + * + * @var Registry + * @since 3.2.0 + */ + protected Registry $registry; + + /** + * Compiler Customcode + * + * @var Customcode + * @since 3.2.0 + */ + protected Customcode $customcode; + + /** + * Compiler Customcode in Gui + * + * @var Gui + * @since 3.2.0 + **/ + protected Gui $gui; + + /** + * Compiler Auto Loader + * + * @var Loader + * @since 3.2.0 + */ + protected Loader $loader; + + /** + * Compiler Libraries Model + * + * @var Libraries + * @since 3.2.0 + */ + protected Libraries $libraries; + + /** + * Database object to query local DB + * + * @var \JDatabaseDriver + * @since 3.2.0 + **/ + protected \JDatabaseDriver $db; + + /** + * Constructor + * + * @param Config|null $config The compiler config object. + * @param Registry|null $registry The compiler registry object. + * @param Customcode|null $customcode The compiler customcode object. + * @param Gui|null $gui The compiler customcode gui. + * @param Loader|null $load The compiler loader object. + * @param Libraries|null $libraries The compiler libraries model object. + * @param \JDatabaseDriver|null $db The database object. + * + * @since 3.2.0 + */ + public function __construct(?Config $config = null, ?Registry $registry = null, + ?Customcode $customcode = null, ?Gui $gui = null, + ?Loader $loader = null, ?Libraries $libraries = null, + ?\JDatabaseDriver $db = null) + { + $this->config = $config ?: Compiler::_('Config'); + $this->registry = $registry ?: Compiler::_('Registry'); + $this->customcode = $customcode ?: Compiler::_('Customcode'); + $this->gui = $gui ?: Compiler::_('Customcode.Gui'); + $this->loader = $loader ?: Compiler::_('Model.Loader'); + $this->libraries = $libraries ?: Compiler::_('Model.Libraries'); + $this->db = $db ?: Factory::getDbo(); + } + + /** + * Get Data by Alias + * + * @param string $alias The alias name + * @param string $table The table where to find the alias + * @param string $view The view code name + * + * @return array|null The data found with the alias + * @since 3.2.0 + */ + public function get(string $alias, string $table, string $view): ?array + { + // if not set, get all keys in table and set by ID + $this->set($table); + + // now check if key is found + $name = preg_replace("/[^A-Za-z]/", '', $alias); + + if (($id = $this->registry->get('builder.data_with_alias_keys.' . $table . '.' . $name, null)) === null && + ($id = $this->registry->get('builder.data_with_alias_keys.' . $table . '.' . $alias, null)) === null) + { + return null; + } + + // Create a new query object. + $query = $this->db->getQuery(true); + $query->select('a.*'); + $query->from('#__componentbuilder_' . $table . ' AS a'); + $query->where( + $this->db->quoteName('a.id') . ' = ' . (int) $id + ); + + // get the row + $this->db->setQuery($query); + $item = $this->db->loadObject(); + + // get the other target if both + $targets = [$this->config->build_target]; + + if ($this->config->lang_target === 'both') + { + $targets = ['site', 'admin']; + } + + // we load this layout + $php_view = ''; + if ($item->add_php_view == 1 + && StringHelper::check($item->php_view)) + { + $php_view = $this->gui->set( + $this->customcode->update(base64_decode((string) $item->php_view)), + array( + 'table' => $table, + 'field' => 'php_view', + 'id' => (int) $item->id, + 'type' => 'php') + ); + } + + $content = $this->gui->set( + $this->customcode->update(base64_decode((string) $item->{$table})), + array( + 'table' => $table, + 'field' => $table, + 'id' => (int) $item->id, + 'type' => 'html') + ); + + // load all targets + foreach ($targets as $target) + { + // set libraries + $this->libraries->set($view, $item, $target); + + // auto loaders + $this->loader->set($view, $content, $target); + $this->loader->set($view, $php_view, $target); + } + + // load uikit version 2 if required + $this->loader->uikit($view, $content); + $this->loader->uikit($view, $php_view); + + return [ + 'id' => $item->id, + 'html' => $this->gui->set( + $content, + [ + 'table' => $table, + 'field' => $table, + 'id' => $item->id, + 'type' => 'html' + ] + ), + 'php_view' => $this->gui->set( + $php_view, + [ + 'table' => $table, + 'field' => 'php_view', + 'id' => $item->id, + 'type' => 'php' + ] + ) + ]; + } + + /** + * Load all alias and ID's of a table + * + * @param string $table The table where to find the alias + * + * @return void + * @since 3.2.0 + */ + protected function set(string $table) + { + // now check if key is found + if (!$this->registry->get('builder.data_with_alias_keys.' . $table, null)) + { + // Create a new query object. + $query = $this->db->getQuery(true); + $query->select(array('a.id', 'a.alias')); + $query->from('#__componentbuilder_' . $table . ' AS a'); + $this->db->setQuery($query); + $items = $this->db->loadObjectList(); + + // check if we have an array + if (ArrayHelper::check($items)) + { + foreach ($items as $item) + { + // build the key + $k_ey = StringHelper::safe($item->alias); + $key = preg_replace("/[^A-Za-z]/", '', (string) $k_ey); + + // set the keys + $this->registry-> + set('builder.data_with_alias_keys.' . $table . '.' . $item->alias, $item->id); + $this->registry-> + set('builder.data_with_alias_keys.' . $table . '.' . $k_ey, $item->id); + $this->registry-> + set('builder.data_with_alias_keys.' . $table . '.' . $key, $item->id); + } + } + } + } diff --git a/src/f1dc6430-fb54-452e-aa53-ce32ae93db88/code.power b/src/f1dc6430-fb54-452e-aa53-ce32ae93db88/code.power new file mode 100644 index 0000000..ab9d6a9 --- /dev/null +++ b/src/f1dc6430-fb54-452e-aa53-ce32ae93db88/code.power @@ -0,0 +1,250 @@ + /** + * Customcode Dispenser Hub + * + * @var array + * @since 3.2.0 + **/ + public array $hub; + + /** + * Compiler Placeholder + * + * @var Placeholder + * @since 3.2.0 + **/ + protected Placeholder $placeholder; + + /** + * Compiler Customcode + * + * @var Customcode + * @since 3.2.0 + **/ + protected Customcode $customcode; + + /** + * Compiler Customcode in Gui + * + * @var Gui + * @since 3.2.0 + **/ + protected Gui $gui; + + /** + * Compiler Customcode to Hash + * + * @var Hash + * @since 3.2.0 + **/ + protected Hash $hash; + + /** + * Compiler Customcode to LockBase + * + * @var LockBase + * @since 3.2.0 + **/ + protected LockBase $base64; + + /** + * Constructor. + * + * @param Placeholder|null $placeholder The compiler placeholder object. + * @param Customcode|null $customcode The compiler customcode object. + * @param Gui|null $gui The compiler customcode gui object. + * @param Hash|null $hash The compiler customcode hash object. + * @param LockBase|null $base64 The compiler customcode lock base64 object. + * + * @since 3.2.0 + */ + public function __construct(?Placeholder $placeholder = null, ?Customcode $customcode = null, + ?Gui $gui = null, ?Hash $hash = null, ?LockBase $base64 = null) + { + $this->placeholder = $placeholder ?: Compiler::_('Placeholder'); + $this->customcode = $customcode ?: Compiler::_('Customcode'); + $this->gui = $gui ?: Compiler::_('Customcode.Gui'); + $this->hash = $hash ?: Compiler::_('Customcode.Hash'); + $this->base64 = $base64 ?: Compiler::_('Customcode.LockBase'); + } + + /** + * Set the script for the customcode dispenser + * + * @param string $script The script + * @param string $first The first key + * @param string|null $second The second key (if not set we use only first key) + * @param string|null $third The third key (if not set we use only first and second key) + * @param array $config The config options + * @param bool $base64 The switch to decode base64 the script + * default: true + * @param bool $dynamic The switch to dynamic update the script + * default: true + * @param bool $add The switch to add to exiting instead of replace + * default: false + * + * @return bool true on success + * @since 3.2.0 + */ + public function set(&$script, string $first, ?string $second = null, ?string $third = null, + array $config = [], bool $base64 = true, bool $dynamic = true, bool $add = false): bool + { + // only load if we have a string + if (!StringHelper::check($script)) + { + return false; + } + // this needs refactoring (TODO) + if (!isset($this->hub[$first]) + || ($second + && !isset($this->hub[$first][$second]))) + { + // check if the script first key is set + if ($second && !isset($this->hub[$first])) + { + $this->hub[$first] = []; + } + elseif ($add && !$second + && !isset($this->hub[$first])) + { + $this->hub[$first] = ''; + } + // check if the script second key is set + if ($second && $third + && !isset($this->hub[$first][$second])) + { + $this->hub[$first][$second] = []; + } + elseif ($add && $second && !$third + && !isset($this->hub[$first][$second])) + { + $this->hub[$first][$second] = ''; + } + // check if the script third key is set + if ($add && $second && $third + && !isset($this->hub[$first][$second][$third])) + { + $this->hub[$first][$second][$third] = ''; + } + } + // prep the script string + if ($base64 && $dynamic) + { + $script = $this->customcode->update(base64_decode($script)); + } + elseif ($base64) + { + $script = base64_decode($script); + } + elseif ($dynamic) // this does not happen (just incase) + { + $script = $this->customcode->update($script); + } + // check if we still have a string + if (StringHelper::check($script)) + { + // now load the placeholder snippet if needed + if ($base64 || $dynamic) + { + $script = $this->gui->set($script, $config); + } + // add Dynamic HASHING option of a file/string + $script = $this->hash->set($script); + // add base64 locking option of a string + $script = $this->base64->set($script); + // load the script + if ($first && $second && $third) + { + // now act on loading option + if ($add) + { + $this->hub[$first][$second][$third] + .= $script; + } + else + { + $this->hub[$first][$second][$third] + = $script; + } + } + elseif ($first && $second) + { + // now act on loading option + if ($add) + { + $this->hub[$first][$second] .= $script; + } + else + { + $this->hub[$first][$second] = $script; + } + } + else + { + // now act on loading option + if ($add) + { + $this->hub[$first] .= $script; + } + else + { + $this->hub[$first] = $script; + } + } + + return true; + } + + return false; + } + + /** + * Get the script from the customcode dispenser + * + * @param string $first The first key + * @param string $second The second key + * @param string $prefix The prefix to add in front of the script if found + * @param string|null $note The switch/note to add to the script + * @param bool $unset The switch to unset the value if found + * @param mixed|null $default The switch/string to use as default return if script not found + * @param string $suffix The suffix to add after the script if found + * + * @return mixed The string/script if found or the default value if not found + * + * @since 3.2.0 + */ + public function get(string $first, string $second, string $prefix = '', ?string $note = null, + bool $unset = false, $default = null, string $suffix = '') + { + // default is to return an empty string + $script = ''; + // check if there is any custom script + if (isset($this->hub[$first][$second]) + && StringHelper::check( + $this->hub[$first][$second] + )) + { + // add not if set + if ($note) + { + $script .= $note; + } + // load the actual script + $script .= $prefix . str_replace( + array_keys($this->placeholder->active), + array_values($this->placeholder->active), + (string) $this->hub[$first][$second] + ) . $suffix; + // clear some memory + if ($unset) + { + unset($this->hub[$first][$second]); + } + } + // if not found return default + if (!StringHelper::check($script) && $default) + { + return $default; + } + + return $script; + } diff --git a/src/f4578c04-a81e-4218-b80d-b0612196eaf0/code.power b/src/f4578c04-a81e-4218-b80d-b0612196eaf0/code.power new file mode 100644 index 0000000..92c19fe --- /dev/null +++ b/src/f4578c04-a81e-4218-b80d-b0612196eaf0/code.power @@ -0,0 +1,53 @@ + /** + * Compiler Files Folders + * + * @var array + * @since 3.2.0 + */ + protected array $keys = [ + 'files' => 'files', + 'folders' => 'folders', + 'urls' => 'urls', + 'filesfullpath' => 'files', + 'foldersfullpath' => 'folders' + ]; + + /** + * Set the file and folder data + * + * @param object $item The item data + * + * @return void + * @since 3.2.0 + */ + public function set(object &$item) + { + foreach ($this->keys as $target => $value) + { + // set the add target data + $item->{'add' . $target} = (isset($item->{'add' . $target}) && + JsonHelper::check($item->{'add' . $target})) ? + json_decode((string) $item->{'add' . $target}, true) : null; + + // only continue if there are values + if (ArrayHelper::check($item->{'add' . $target})) + { + if (isset($item->{$value}) + && ArrayHelper::check($item->{$value})) + { + foreach ($item->{'add' . $target} as $taget) + { + $item->{$value}[] = $taget; + } + } + else + { + $item->{$value} = array_values( + $item->{'add' . $target} + ); + } + } + + unset($item->{'add' . $target}); + } + } diff --git a/src/fa4bf18e-301e-42e3-91fb-6e0096c07adc/README.md b/src/fa4bf18e-301e-42e3-91fb-6e0096c07adc/README.md index 49622c5..c0d2767 100644 --- a/src/fa4bf18e-301e-42e3-91fb-6e0096c07adc/README.md +++ b/src/fa4bf18e-301e-42e3-91fb-6e0096c07adc/README.md @@ -13,6 +13,7 @@ class Config #Gold { # JoomlaRegistry $config + __construct(?Input $input = null, ?JoomlaRegistry $params = null, ...) + # getGiteatoken() : ?string # getAddcontributors() : bool # getAddajax() : bool # getAddsiteajax() : bool @@ -50,6 +51,7 @@ class Config #Gold { # getCompilerpath() : string # getJcbpowerspath() : string # getLocalpowersrepositorypath() : string + # getApprovedpaths() : array # getBompath() : string # getCustomfolderpath() : string # getAddassetstablefix() : int @@ -59,6 +61,7 @@ class Config #Gold { # getAddplaceholders() : bool # getAddpower() : bool # getAddsuperpowers() : bool + # getAddownpowers() : bool # getBuildtarget() : string # getCryptiontypes() : array # getBasicencryption() : bool @@ -83,265 +86,279 @@ note right of Config::__construct ?JoomlaRegistry $config = null end note -note left of Config::getAddcontributors +note left of Config::getGiteatoken + get Gitea Access Token + + since: 3.2.0 + return: ?string +end note + +note right of Config::getAddcontributors get add contributors switch since: 3.2.0 return: bool end note -note right of Config::getAddajax +note left of Config::getAddajax get Add Ajax Switch since: 3.2.0 return: bool end note -note left of Config::getAddsiteajax +note right of Config::getAddsiteajax get Add Site Ajax Switch since: 3.2.0 return: bool end note -note right of Config::getAddeximport +note left of Config::getAddeximport get add eximport since: 3.2.0 return: bool end note -note left of Config::getAddcheckin +note right of Config::getAddcheckin get add checkin since: 3.2.0 return: bool end note -note right of Config::getComponentid +note left of Config::getComponentid get posted component id since: 3.2.0 return: int end note -note left of Config::getComponentversion +note right of Config::getComponentversion get component version since: 3.2.0 return: string end note -note right of Config::getComponentcodename +note left of Config::getComponentcodename get components code name since: 3.2.0 return: string end note -note left of Config::getComponentcontext +note right of Config::getComponentcontext get component context since: 3.2.0 return: string end note -note right of Config::getComponentcodenamelength +note left of Config::getComponentcodenamelength get component code name length since: 3.2.0 return: int end note -note left of Config::getJoomlaversion +note right of Config::getJoomlaversion get posted Joomla version since: 3.2.0 return: int end note -note right of Config::getJoomlaversions +note left of Config::getJoomlaversions get Joomla versions since: 3.2.0 return: array end note -note left of Config::getJoomlaversionname +note right of Config::getJoomlaversionname get posted Joomla version name since: 3.2.0 return: string end note -note right of Config::getSetjoomlafields +note left of Config::getSetjoomlafields set joomla fields since: 3.2.0 return: bool end note -note left of Config::getShowadvancedoptions +note right of Config::getShowadvancedoptions get show advanced options switch since: 3.2.0 return: bool end note -note right of Config::getIndentationvalue +note left of Config::getIndentationvalue get indentation value since: 3.2.0 return: string end note -note left of Config::getAddbuilddate +note right of Config::getAddbuilddate get add build date switch since: 3.2.0 return: int end note -note right of Config::getBuilddate +note left of Config::getBuilddate get build date since: 3.2.0 return: string end note -note left of Config::getBackup +note right of Config::getBackup get posted backup switch since: 3.2.0 return: int end note -note right of Config::getRepository +note left of Config::getRepository get posted repository switch since: 3.2.0 return: int end note -note left of Config::getDebuglinenr +note right of Config::getDebuglinenr get posted debuglinenr switch since: 3.2.0 return: int end note -note right of Config::getMinify +note left of Config::getMinify get posted minify switch since: 3.2.0 return: int end note -note left of Config::getRemovelinebreaks +note right of Config::getRemovelinebreaks get posted remove line breaks switch since: 3.2.0 return: bool end note -note right of Config::getTidy +note left of Config::getTidy get system tidy state since: 3.2.0 return: bool end note -note left of Config::getSettidywarning +note right of Config::getSettidywarning add tidy warning since: 3.2.0 return: bool end note -note right of Config::getSettaghistory +note left of Config::getSettaghistory get history tag switch since: 3.2.0 return: bool end note -note left of Config::getLangtag +note right of Config::getLangtag get language tag since: 3.2.0 return: string end note -note right of Config::getLangprefix +note left of Config::getLangprefix get language prefix since: 3.2.0 return: string end note -note left of Config::getLangtarget +note right of Config::getLangtarget get language target since: 3.2.0 return: string end note -note right of Config::getLangstringtargets +note left of Config::getLangstringtargets get language string targets since: 3.2.0 return: array end note -note left of Config::getLangstringkeytargets +note right of Config::getLangstringkeytargets get language string targets (by key name) since: 3.2.0 return: array end note -note right of Config::getFieldbuildertype +note left of Config::getFieldbuildertype get field builder type since: 3.2.0 return: int end note -note left of Config::getDefaultfields +note right of Config::getDefaultfields get default fields since: 3.2.0 return: array end note -note right of Config::getTmppath +note left of Config::getTmppath get temporary path since: 3.2.0 return: string end note -note left of Config::getCompilerpath +note right of Config::getCompilerpath get compiler path since: 3.2.0 return: string end note -note right of Config::getJcbpowerspath +note left of Config::getJcbpowerspath get jcb powers path since: 3.2.0 return: string end note -note left of Config::getLocalpowersrepositorypath +note right of Config::getLocalpowersrepositorypath Get local super powers repository path since: 3.2.0 return: string end note +note left of Config::getApprovedpaths + Get super power approved paths + + since: 3.2.0 + return: array +end note + note right of Config::getBompath get bom path @@ -405,77 +422,84 @@ note right of Config::getAddsuperpowers return: bool end note -note left of Config::getBuildtarget +note left of Config::getAddownpowers + Get switch to add own super powers + + since: 3.2.0 + return: bool +end note + +note right of Config::getBuildtarget get switch build target switch since: 3.2.0 return: string end note -note right of Config::getCryptiontypes +note left of Config::getCryptiontypes get encryption types since: 3.2.0 return: array end note -note left of Config::getBasicencryption +note right of Config::getBasicencryption get basic encryption switch since: 3.2.0 return: bool end note -note right of Config::getMediumencryption +note left of Config::getMediumencryption get medium encryption switch since: 3.2.0 return: bool end note -note left of Config::getWhmcsencryption +note right of Config::getWhmcsencryption get whmcs encryption switch since: 3.2.0 return: bool end note -note right of Config::getRemovesitefolder +note left of Config::getRemovesitefolder Should we remove the site folder since: 3.2.0 return: bool end note -note left of Config::getRemovesiteeditfolder +note right of Config::getRemovesiteeditfolder Should we remove the site edit folder since: 3.2.0 return: bool end note -note right of Config::getUikit +note left of Config::getUikit The Uikit switch since: 3.2.0 return: int end note -note left of Config::getGooglechart +note right of Config::getGooglechart The google chart switch since: 3.2.0 return: bool end note -note right of Config::getFootable +note left of Config::getFootable The footable switch since: 3.2.0 return: bool end note -note left of Config::getFootableversion +note right of Config::getFootableversion The footable version since: 3.2.0 diff --git a/src/fa4bf18e-301e-42e3-91fb-6e0096c07adc/code.php b/src/fa4bf18e-301e-42e3-91fb-6e0096c07adc/code.php index ec15d72..e55249d 100644 --- a/src/fa4bf18e-301e-42e3-91fb-6e0096c07adc/code.php +++ b/src/fa4bf18e-301e-42e3-91fb-6e0096c07adc/code.php @@ -57,6 +57,17 @@ class Config extends BaseConfig $this->config = $config ?: JoomlaFactory::getConfig(); } + /** + * get Gitea Access Token + * + * @return string the access token + * @since 3.2.0 + */ + protected function getGiteatoken(): ?string + { + return $this->params->get('access.token'); + } + /** * get add contributors switch * @@ -567,6 +578,39 @@ class Config extends BaseConfig : $global; } + /** + * Get super power approved paths + * + * @return array The approved paths to the repositories on Gitea + * @since 3.2.0 + */ + protected function getApprovedpaths(): array + { + $default = (object) ['owner' => 'joomla', 'repo' => 'super-powers', 'branch' => 'master']; + + if (!$this->add_own_powers) + { + return [$default]; + } + + $paths = $this->params->get('approved_paths'); + + $approved = []; + if (!empty($paths)) + { + foreach ($paths as $path) + { + // we make sure to get only the objects + $approved[] = $path; + } + } + + // finally we add the default + $approved[] = $default; + + return $approved; + } + /** * get bom path * @@ -710,6 +754,22 @@ class Config extends BaseConfig return $value == 2 ? $default : (bool) $value; } + /** + * Get switch to add own super powers + * + * @return bool Switch to add own super powers + * @since 3.2.0 + */ + protected function getAddownpowers(): bool + { + if ($this->add_super_powers) + { + return (bool) $this->params->get('super_powers_repositories', 0); + } + + return false; + } + /** * get switch build target switch * diff --git a/src/fa4bf18e-301e-42e3-91fb-6e0096c07adc/code.power b/src/fa4bf18e-301e-42e3-91fb-6e0096c07adc/code.power new file mode 100644 index 0000000..6afccda --- /dev/null +++ b/src/fa4bf18e-301e-42e3-91fb-6e0096c07adc/code.power @@ -0,0 +1,860 @@ + /** + * The Global Joomla Configuration + * + * @var JoomlaRegistry + * @since 3.2.0 + */ + protected JoomlaRegistry $config; + + /** + * Constructor + * + * @param Input|null $input Input + * @param Registry|null $params The component parameters + * @param Registry|null $config The Joomla configuration + * + * @throws \Exception + * @since 3.2.0 + */ + public function __construct(?Input $input = null, ?JoomlaRegistry $params = null, ?JoomlaRegistry $config = null) + { + parent::__construct($input, $params); + + $this->config = $config ?: JoomlaFactory::getConfig(); + } + + /** + * get Gitea Access Token + * + * @return string the access token + * @since 3.2.0 + */ + protected function getGiteatoken(): ?string + { + return $this->params->get('access.token'); + } + + /** + * get add contributors switch + * + * @return bool Add contributors switch + * @since 3.2.0 + */ + protected function getAddcontributors(): bool + { + return false; // default is false + } + + /** + * get Add Ajax Switch + * + * @return bool Add Ajax Switch + * @since 3.2.0 + */ + protected function getAddajax(): bool + { + return false; // default is false + } + + /** + * get Add Site Ajax Switch + * + * @return bool Add Site Ajax Switch + * @since 3.2.0 + */ + protected function getAddsiteajax(): bool + { + return false; // default is false + } + + /** + * get add eximport + * + * @return bool add eximport switch + * @since 3.2.0 + */ + protected function getAddeximport(): bool + { + return false; // default is false + } + + /** + * get add checkin + * + * @return bool add checkin switch + * @since 3.2.0 + */ + protected function getAddcheckin(): bool + { + return false; // default is false + } + + /** + * get posted component id + * + * @return int Component id + * @since 3.2.0 + */ + protected function getComponentid(): int + { + return $this->input->post->get('component_id', 0, 'INT'); + } + + /** + * get component version + * + * @return string Component version + * @since 3.2.0 + */ + protected function getComponentversion(): string + { + return '1.0.0'; + } + + /** + * get components code name + * + * @return string The components code name + * @since 3.2.0 + */ + protected function getComponentcodename(): string + { + // get components code name + return StringHelper::safe(GetHelper::var( + 'joomla_component', $this->component_id, 'id', 'name_code' + )); + } + + /** + * get component context + * + * @return string The component context + * @since 3.2.0 + */ + protected function getComponentcontext(): string + { + // get component context + return $this->component_code_name . '.' . $this->component_id; + } + + /** + * get component code name length + * + * @return int The component code name length + * @since 3.2.0 + */ + protected function getComponentcodenamelength(): int + { + // get component name length + return strlen((string) $this->component_code_name); + } + + /** + * get posted Joomla version + * + * @return int Joomla version code + * @since 3.2.0 + */ + protected function getJoomlaversion(): int + { + return 3; // $this->input->post->get('joomla_version', 3, 'INT'); + } + + /** + * get Joomla versions + * + * @return array Joomla versions + * @since 3.2.0 + */ + protected function getJoomlaversions(): array + { + return [ + 3 => ['folder_key' => 3, 'xml_version' => 3.9], // only joomla 3 + 3.10 => ['folder_key' => 3, 'xml_version' => 4.0] // legacy joomla 4 + ]; + } + + /** + * get posted Joomla version name + * + * @return string Joomla version code name + * @since 3.2.0 + */ + protected function getJoomlaversionname(): string + { + return StringHelper::safe($this->joomla_version); + } + + /** + * set joomla fields + * + * @return bool set joomla fields + * @since 3.2.0 + */ + protected function getSetjoomlafields(): bool + { + return false; + } + + /** + * get show advanced options switch + * + * @return bool show advanced options + * @since 3.2.0 + */ + protected function getShowadvancedoptions(): bool + { + return (bool) $this->input->post->get('show_advanced_options', 0, 'INT'); + } + + /** + * get indentation value + * + * @return string Indentation value + * @since 3.2.0 + */ + protected function getIndentationvalue(): string + { + // if advanced options is active + if ($this->show_advanced_options) + { + $indentation_value = $this->input->post->get('indentation_value', 1, 'INT'); + + switch($indentation_value) + { + case 2: + // two spaces + return " "; + break; + case 4: + // four spaces + return " "; + break; + } + } + + return "\t"; + } + + /** + * get add build date switch + * + * @return int add build date options + * @since 3.2.0 + */ + protected function getAddbuilddate(): int + { + // if advanced options is active + if ($this->show_advanced_options) + { + // 1=default 2=manual 3=component + return $this->input->post->get('add_build_date', 1, 'INT'); + } + + return 1; + } + + /** + * get build date + * + * @return string build date + * @since 3.2.0 + */ + protected function getBuilddate(): string + { + // if advanced options is active and manual date selected + if ($this->show_advanced_options && $this->add_build_date == 2) + { + return $this->input->post->get('build_date', 'now', 'STRING'); + } + + return "now"; + } + + /** + * get posted backup switch + * + * @return int Backup switch number + * @since 3.2.0 + */ + protected function getBackup(): int + { + return $this->input->post->get('backup', 0, 'INT'); + } + + /** + * get posted repository switch + * + * @return int Repository switch number + * @since 3.2.0 + */ + protected function getRepository(): int + { + return $this->input->post->get('repository', 0, 'INT'); + } + + /** + * get posted debuglinenr switch + * + * @return int Debuglinenr switch number + * @since 3.2.0 + */ + protected function getDebuglinenr(): int + { + // get posted value + $value = $this->input->post->get('debug_line_nr', 2, 'INT'); + // get global value + if ($value > 1) + { + return (int) GetHelper::var('joomla_component', $this->component_id, 'id', 'debug_linenr'); + } + return $value; + } + + /** + * get posted minify switch + * + * @return int Minify switch number + * @since 3.2.0 + */ + protected function getMinify(): int + { + // get posted value + $minify = $this->input->post->get('minify', 2, 'INT'); + + // if value is 2 use global value + return ($minify != 2) ? $minify : $this->params->get('minify', 0); + } + + /** + * get posted remove line breaks switch + * + * @return bool Remove line breaks switch number + * @since 3.2.0 + */ + protected function getRemovelinebreaks(): bool + { + // get posted value + $value = $this->input->post->get('remove_line_breaks', 2, 'INT'); + // get global + if ($value > 1) + { + return (bool) GetHelper::var('joomla_component', $this->component_id, 'id', 'remove_line_breaks'); + } + return (bool) $value; + } + + /** + * get system tidy state + * + * @return bool Tidy is active + * @since 3.2.0 + */ + protected function getTidy(): bool + { + // check if we have Tidy enabled + return \extension_loaded('Tidy'); + } + + /** + * add tidy warning + * + * @return bool Set tidy warning + * @since 3.2.0 + */ + protected function getSettidywarning(): bool + { + // add warning once + return true; + } + + /** + * get history tag switch + * + * @return bool get history tag switch + * @since 3.2.0 + */ + protected function getSettaghistory(): bool + { + // add warning once + return true; + } + + /** + * get language tag + * + * @return string The active language tag + * @since 3.2.0 + */ + protected function getLangtag(): string + { + // get the global language + return $this->params->get('language', 'en-GB'); + } + + /** + * get language prefix + * + * @return string The language prefix + * @since 3.2.0 + */ + protected function getLangprefix(): string + { + // get components code name + return 'COM_' . StringHelper::safe(GetHelper::var( + 'joomla_component', $this->component_id, 'id', 'name_code' + ), 'U'); + } + + /** + * get language target + * + * @return string The language active target + * @since 3.2.0 + */ + protected function getLangtarget(): string + { + // we start with admin + // but this is a switch value and is changed many times + return 'admin'; + } + + /** + * get language string targets + * + * @return array The language prefix + * @since 3.2.0 + */ + protected function getLangstringtargets(): array + { + // these strings are used to search for language strings in all content + return array_values($this->lang_string_key_targets); + } + + /** + * get language string targets (by key name) + * + * @return array The language prefix + * @since 3.2.0 + */ + protected function getLangstringkeytargets(): array + { + // these strings are used to search for language strings in all content + return [ + 'jjt' => 'Joomla' . '.JText._(', + 'js' => 'JText:' . ':script(', + 't' => 'Text:' . ':_(', // namespace and J version will be found + 'ts' => 'Text:' . ':sprintf(', // namespace and J version will be found + 'jt' => 'JustTEXT:' . ':_(' + ]; + } + + /** + * get field builder type + * + * @return int The field builder type + * @since 3.2.0 + */ + protected function getFieldbuildertype(): int + { + // get the field type builder + return $this->params->get( + 'compiler_field_builder_type', 2 + ); + } + + /** + * get default fields + * + * @return array The default fields + * @since 3.2.0 + */ + protected function getDefaultfields(): array + { + // get the field type builder + return ['created', 'created_by', 'modified', 'modified_by', 'published', + 'ordering', 'access', 'version', 'hits', 'id']; + } + + /** + * get temporary path + * + * @return string The temporary path + * @since 3.2.0 + */ + protected function getTmppath(): string + { + // get the temporary path + return $this->config->get('tmp_path'); + } + + /** + * get compiler path + * + * @return string The compiler path + * @since 3.2.0 + */ + protected function getCompilerpath(): string + { + // get the compiler path + return $this->params->get( + 'compiler_folder_path', + JPATH_COMPONENT_ADMINISTRATOR . '/compiler' + ); + } + + /** + * get jcb powers path + * + * @return string The jcb powers path + * @since 3.2.0 + */ + protected function getJcbpowerspath(): string + { + // get jcb powers path + return $this->params->get('jcb_powers_path', 'libraries/jcb_powers'); + } + + /** + * Get local super powers repository path + * + * @return string The path to the local repository + * @since 3.2.0 + */ + protected function getLocalpowersrepositorypath(): string + { + $default = $this->tmp_path . '/super_powers'; + + if (!$this->add_super_powers) + { + return $default; + } + + $global = $this->params->get('local_powers_repository_path', $default); + + if (!$this->show_advanced_options) + { + return $global; + } + + $value = $this->input->post->get('powers_repository', 2, 'INT'); + + return $value == 1 + ? $this->input->post->get('local_powers_repository_path', $global, 'PATH') + : $global; + } + + /** + * Get super power approved paths + * + * @return array The approved paths to the repositories on Gitea + * @since 3.2.0 + */ + protected function getApprovedpaths(): array + { + $default = (object) ['owner' => 'joomla', 'repo' => 'super-powers', 'branch' => 'master']; + + if (!$this->add_own_powers) + { + return [$default]; + } + + $paths = $this->params->get('approved_paths'); + + $approved = []; + if (!empty($paths)) + { + foreach ($paths as $path) + { + // we make sure to get only the objects + $approved[] = $path; + } + } + + // finally we add the default + $approved[] = $default; + + return $approved; + } + + /** + * get bom path + * + * @return string The bom path + * @since 3.2.0 + */ + protected function getBompath(): string + { + // get default bom path + return $this->compiler_path . '/default.txt'; + } + + /** + * get custom folder path + * + * @return string The custom folder path + * @since 3.2.0 + */ + protected function getCustomfolderpath(): string + { + // get the custom folder path + return $this->params->get( + 'custom_folder_path', + JPATH_COMPONENT_ADMINISTRATOR . '/custom' + ); + } + + /** + * get switch to add assets table fix + * + * @return int Switch number to add assets table fix + * @since 3.2.0 + */ + protected function getAddassetstablefix(): int + { + // get global add assets table fix + $global = $this->params->get( + 'assets_table_fix', 1 + ); + + // get component value + return (($add_assets_table_fix = (int) GetHelper::var( + 'joomla_component', $this->component_id, 'id', + 'assets_table_fix' + )) == 3) ? $global : $add_assets_table_fix; + } + + /** + * get switch to add assets table name fix + * + * @return bool Switch number to add assets table name fix + * @since 3.2.0 + */ + protected function getAddassetstablenamefix(): bool + { + // get global is false + return false; + } + + /** + * get access worse case size + * + * @return int access worse case size + * @since 3.2.0 + */ + protected function getAccessworsecase(): int + { + // we start at zero + return 0; + } + + /** + * get mysql table keys + * + * @return array + * @since 3.2.0 + */ + protected function getMysqltablekeys(): array + { + return [ + 'engine' => ['default' => 'MyISAM'], + 'charset' => ['default' => 'utf8'], + 'collate' => ['default' => 'utf8_general_ci'], + 'row_format' => ['default' => ''] + ]; + } + + /** + * get switch add placeholders + * + * @return bool Switch to add placeholders + * @since 3.2.0 + */ + protected function getAddplaceholders(): bool + { + // get posted value + $value = $this->input->post->get('add_placeholders', 2, 'INT'); + // get global value + if ($value > 1) + { + return (bool) GetHelper::var('joomla_component', $this->component_id, 'id', 'add_placeholders'); + } + return (bool) $value; + } + + /** + * get switch add power + * + * @return bool Switch to add power + * @since 3.2.0 + */ + protected function getAddpower(): bool + { + // get posted value + $value = $this->input->post->get('powers', 2, 'INT'); + // get global value + if ($value > 1) + { + return (bool) GetHelper::var('joomla_component', $this->component_id, 'id', 'add_powers'); + } + return (bool) $value; + } + + /** + * Get switch to add super powers + * + * @return bool Switch to add super powers + * @since 3.2.0 + */ + protected function getAddsuperpowers(): bool + { + $default = (bool) $this->params->get('powers_repository', 0); + + if (!$this->show_advanced_options) + { + return $default; + } + + $value = $this->input->post->get('powers_repository', 2, 'INT'); + + return $value == 2 ? $default : (bool) $value; + } + + /** + * Get switch to add own super powers + * + * @return bool Switch to add own super powers + * @since 3.2.0 + */ + protected function getAddownpowers(): bool + { + if ($this->add_super_powers) + { + return (bool) $this->params->get('super_powers_repositories', 0); + } + + return false; + } + + /** + * get switch build target switch + * + * @return string Switch to control the build flow + * @since 3.2.0 + */ + protected function getBuildtarget(): string + { + // we start with admin + // but this is a switch value and is changed many times + return 'admin'; + } + + /** + * get encryption types + * + * @return array encryption types + * @since 3.2.0 + */ + protected function getCryptiontypes(): array + { + return ['basic', 'medium', 'whmcs', 'expert']; + } + + /** + * get basic encryption switch + * + * @return bool Switch to control the encryption + * @since 3.2.0 + */ + protected function getBasicencryption(): bool + { + return false; + } + + /** + * get medium encryption switch + * + * @return bool Switch to control the encryption + * @since 3.2.0 + */ + protected function getMediumencryption(): bool + { + return false; + } + + /** + * get whmcs encryption switch + * + * @return bool Switch to control the encryption + * @since 3.2.0 + */ + protected function getWhmcsencryption(): bool + { + return false; + } + + /** + * Should we remove the site folder + * + * @return bool Switch to control the removal + * @since 3.2.0 + */ + protected function getRemovesitefolder(): bool + { + return false; + } + + /** + * Should we remove the site edit folder + * + * @return bool Switch to control the removal + * @since 3.2.0 + */ + protected function getRemovesiteeditfolder(): bool + { + return true; + } + + /** + * The Uikit switch + * + * @return int Switch to control the adding uikit + * @since 3.2.0 + */ + protected function getUikit(): int + { + return 0; // default its not added + } + + /** + * The google chart switch + * + * @return bool Switch to control the adding googlechart + * @since 3.2.0 + */ + protected function getGooglechart(): bool + { + return false; // default its not added + } + + /** + * The footable switch + * + * @return bool Switch to control the adding footable + * @since 3.2.0 + */ + protected function getFootable(): bool + { + return false; // default its not added + } + + /** + * The footable version + * + * @return int Switch to control the adding footable + * @since 3.2.0 + */ + protected function getFootableversion(): int + { + return 2; // default is version 2 + } diff --git a/src/fa8c1125-d370-4cb6-a7ff-eb32193c198c/code.power b/src/fa8c1125-d370-4cb6-a7ff-eb32193c198c/code.power new file mode 100644 index 0000000..15c9256 --- /dev/null +++ b/src/fa8c1125-d370-4cb6-a7ff-eb32193c198c/code.power @@ -0,0 +1,206 @@ + /** + * Compiler Config + * + * @var Config + * @since 3.2.0 + */ + protected Config $config; + + /** + * The compiler registry + * + * @var Registry + * @since 3.2.0 + */ + protected Registry $registry; + + /** + * Compiler Language + * + * @var Language + * @since 3.2.0 + **/ + protected Language $language; + + /** + * Compiler Placeholder + * + * @var Placeholder + * @since 3.2.0 + */ + protected Placeholder $placeholder; + + /** + * Compiler Customcode + * + * @var Customcode + * @since 3.2.0 + */ + protected Customcode $customcode; + + /** + * Constructor + * + * @param Config|null $config The compiler config object. + * @param Registry|null $registry The compiler registry object. + * @param Language|null $language The compiler Language object. + * @param Placeholder|null $placeholder The compiler placeholder object. + * @param Customcode|null $customcode The compiler customcode object. + * + * @since 3.2.0 + */ + public function __construct(?Config $config = null, ?Registry $registry = null, + ?Language $language = null, ?Placeholder $placeholder = null, ?Customcode $customcode = null) + { + $this->config = $config ?: Compiler::_('Config'); + $this->registry = $registry ?: Compiler::_('Registry'); + $this->language = $language ?: Compiler::_('Language'); + $this->placeholder = $placeholder ?: Compiler::_('Placeholder'); + $this->customcode = $customcode ?: Compiler::_('Customcode'); + } + + /** + * Set custom tabs + * + * @param object $item The view data + * + * @return void + * @since 3.2.0 + */ + public function set(object &$item) + { + $item->customtabs = (isset($item->customtabs) + && JsonHelper::check($item->customtabs)) + ? json_decode((string) $item->customtabs, true) : null; + + if (ArrayHelper::check($item->customtabs)) + { + // get the name + $name = $item->name_single_code; + + // setup custom tabs to global data sets + $this->registry->set('builder.custom_tabs.' . $name, + array_map( + function ($tab) use (&$name) { + + // set the view name + $tab['view'] = $name; + + // load the dynamic data + $tab['html'] = $this->placeholder->update_( + $this->customcode->update($tab['html']) + ); + + // set the tab name + $tab['name'] = (isset($tab['name']) + && StringHelper::check( + $tab['name'] + )) ? $tab['name'] : 'Tab'; + + // set lang + $tab['lang'] = $this->config->lang_prefix . '_' + . StringHelper::safe( + $tab['view'], 'U' + ) . '_' . StringHelper::safe( + $tab['name'], 'U' + ); + $this->language->set( + 'both', $tab['lang'], $tab['name'] + ); + + // set code name + $tab['code'] = StringHelper::safe( + $tab['name'] + ); + + // check if the permissions for the tab should be added + $_tab = ''; + if (isset($tab['permission']) + && $tab['permission'] == 1) + { + $_tab = Indent::_(1); + } + + // check if the php of the tab is set, if not load it now + if (strpos((string) $tab['html'], 'bootstrap.addTab') === false + && strpos((string) $tab['html'], 'bootstrap.endTab') + === false) + { + // add the tab + $tmp = PHP_EOL . $_tab . Indent::_(1) + . ""; + $tmp .= PHP_EOL . $_tab . Indent::_(2) + . '
'; + $tmp .= PHP_EOL . $_tab . Indent::_(3) + . '
'; + $tmp .= PHP_EOL . $_tab . Indent::_(4) . implode( + PHP_EOL . $_tab . Indent::_(4), + (array) explode(PHP_EOL, trim((string) $tab['html'])) + ); + $tmp .= PHP_EOL . $_tab . Indent::_(3) . '
'; + $tmp .= PHP_EOL . $_tab . Indent::_(2) . '
'; + $tmp .= PHP_EOL . $_tab . Indent::_(1) + . ""; + + // update html + $tab['html'] = $tmp; + } + else + { + $tab['html'] = PHP_EOL . $_tab . Indent::_(1) + . implode( + PHP_EOL . $_tab . Indent::_(1), + (array) explode(PHP_EOL, trim((string) $tab['html'])) + ); + } + + // add the permissions if needed + if (isset($tab['permission']) + && $tab['permission'] == 1) + { + $tmp = PHP_EOL . Indent::_(1) + . "canDo->get('" + . $tab['view'] . "." . $tab['code'] + . ".viewtab')) : ?>"; + $tmp .= $tab['html']; + $tmp .= PHP_EOL . Indent::_(1) . ""; + // update html + $tab['html'] = $tmp; + // set lang for permissions + $tab['lang_permission'] = $tab['lang'] + . '_TAB_PERMISSION'; + $tab['lang_permission_desc'] = $tab['lang'] + . '_TAB_PERMISSION_DESC'; + $tab['lang_permission_title'] + = $this->placeholder->get('Views') . ' View ' + . $tab['name'] . ' Tab'; + $this->language->set( + 'both', $tab['lang_permission'], + $tab['lang_permission_title'] + ); + $this->language->set( + 'both', $tab['lang_permission_desc'], + 'Allow the users in this group to view ' + . $tab['name'] . ' Tab of ' + . $this->placeholder->get('views') + ); + // set the sort key + $tab['sortKey'] + = StringHelper::safe( + $tab['lang_permission_title'] + ); + } + + // return tab + return $tab; + + }, array_values($item->customtabs) + ) + ); + } + + unset($item->customtabs); + } diff --git a/src/fbc58009-fa16-4d49-a0dd-419c3b62d42f/code.power b/src/fbc58009-fa16-4d49-a0dd-419c3b62d42f/code.power new file mode 100644 index 0000000..064b36f --- /dev/null +++ b/src/fbc58009-fa16-4d49-a0dd-419c3b62d42f/code.power @@ -0,0 +1,66 @@ + /** + * Check if any values are set in the active array. + * + * @param string|null $firstKey Optional. The first key to check for values. + * + * @return bool True if the active array or the specified subarray is not empty, false otherwise. + * @since 3.2.0 + */ + public function isActive_(string $firstKey = null): bool; + + /** + * Set dynamic content + * + * @param string $firstKey The first key + * @param string $secondKey The second key + * @param mixed $value The values to set + * + * @return void + * @since 3.2.0 + */ + public function set_(string $firstKey, string $secondKey, $value); + + /** + * Get dynamic content + * + * @param string $firstKey The first key + * @param string $secondKey The second key + * + * @return mixed + * @since 3.2.0 + */ + public function get_(string $firstKey, ?string $secondKey = null); + + /** + * Does keys exist + * + * @param string $firstKey The first key + * @param string|null $secondKey The second key + * + * @return bool + * @since 3.2.0 + */ + public function exist_(string $firstKey, ?string $secondKey = null): bool; + + /** + * Add dynamic content + * + * @param string $firstKey The first key + * @param string $secondKey The second key + * @param mixed $value The values to set + * + * @return void + * @since 3.2.0 + */ + public function add_(string $firstKey, string $secondKey, $value); + + /** + * Remove dynamic content + * + * @param string $firstKey The first key + * @param string|null $secondKey The second key + * + * @return void + * @since 3.2.0 + */ + public function remove_(string $firstKey, ?string $secondKey = null); diff --git a/src/ff5e9e63-86d0-4691-ab59-d4b9d9154096/code.php b/src/ff5e9e63-86d0-4691-ab59-d4b9d9154096/code.php index 3b7e7c4..27ed05d 100644 --- a/src/ff5e9e63-86d0-4691-ab59-d4b9d9154096/code.php +++ b/src/ff5e9e63-86d0-4691-ab59-d4b9d9154096/code.php @@ -321,7 +321,6 @@ class Plantuml { $plant_uml = ""; $note_count = count($notes); - $note_index = 0; $positions = ['right', 'left']; $position_index = 0; @@ -341,8 +340,6 @@ class Plantuml $plant_uml .= "\nnote $position of {$area}\n"; $plant_uml .= " " . implode("\n ", $note) . "\n"; $plant_uml .= "end note\n"; - - $note_index++; } return $plant_uml; diff --git a/src/ff5e9e63-86d0-4691-ab59-d4b9d9154096/code.power b/src/ff5e9e63-86d0-4691-ab59-d4b9d9154096/code.power new file mode 100644 index 0000000..3ed7c97 --- /dev/null +++ b/src/ff5e9e63-86d0-4691-ab59-d4b9d9154096/code.power @@ -0,0 +1,436 @@ + /** + * Get a namespace diagram of a group of class + * + * @param string $namespace the namespace name + * @param string $classes the ready build class uml + * + * @return string + * @since 3.2.0 + */ + public function namespaceDiagram(string $namespace, string $classes): string + { + $namespace_depth = substr_count($namespace, '\\'); + $namespace_color = $this->getNamespaceColor($namespace_depth); + + // Set the scale of the diagram + // $plant_uml = "scale 0.8\n\n"; + + // Add namespace + $plant_uml = "namespace $namespace #$namespace_color {\n\n"; + + // Add class + $plant_uml .= $classes; + + $plant_uml .= "}\n"; + + return $plant_uml; + } + + /** + * Get a class basic diagram of a class + * + * @param array $power the class being built + * @param array $code the class code being built + * + * @return string + * @since 3.2.0 + */ + public function classBasicDiagram(array $power, array $code): string + { + // Set some global values + $class_name = $power['name']; + $class_type = $power['type']; + + // set the class color + $class_color = $this->getClassColor($class_type); + + // set the class type label + $type_label = $this->getClassTypeLable($class_type); + + // set the class type tag + $type_tag = $this->getClassTypeTag($class_type); + + // Add class + $plant_uml = "\n $type_label $class_name $type_tag #$class_color {\n"; + + // Add properties + if ($code['properties']) + { + $plant_uml .= $this->generatePropertiesPlantUML($code['properties'], ' '); + } + + // Add methods + if ($code['methods']) + { + $plant_uml .= $this->generateBasicMethodsPlantUML($code['methods']); + } + + $plant_uml .= " }\n"; + + return $plant_uml; + } + + /** + * Get a class detailed diagram of a class + * + * @param array $power the class being built + * @param array $code the class code being built + * + * @return string + * @since 3.2.0 + */ + public function classDetailedDiagram(array $power, array $code): string + { + // Set some global values + $class_name = $power['name']; + $class_type = $power['type']; + + // set the class color + $class_color = $this->getClassColor($class_type); + + // set the class type label + $type_label = $this->getClassTypeLable($class_type); + + // set the class type tag + $type_tag = $this->getClassTypeTag($class_type); + + // Add class + $plant_uml = "\n$type_label $class_name $type_tag #$class_color {\n"; + + // Add properties + if ($code['properties']) + { + $plant_uml .= $this->generatePropertiesPlantUML($code['properties'], ' '); + } + + // Add methods + if ($code['methods']) + { + list($methods_plant_uml, $notes) = $this->generateDetailedMethodsPlantUML($code['methods'], $class_name); + $plant_uml .= $methods_plant_uml; + } + + $plant_uml .= "}\n"; + + if (!empty($notes)) + { + $plant_uml .= $this->generateNotesPlantUML($notes); + } + + return $plant_uml; + } + + /** + * Generate properties PlantUML + * + * @param array $properties + * @param string $space + * + * @return string + * @since 3.2.0 + */ + private function generatePropertiesPlantUML(array $properties, string $space): string + { + $plant_uml = ""; + + foreach ($properties as $property) + { + $access_sign = $this->getAccessSign($property['access']); + $static = $property['static'] ? '{static} ' : ''; + $type = $property['type'] ? $property['type'] . ' ' : ''; + $plant_uml .= "{$space}$access_sign $static{$type}{$property['name']}\n"; + } + + return $plant_uml; + } + + /** + * Generate detailed methods PlantUML + * + * @param array $methods + * @param string $class_name + * + * @return array + * @since 3.2.0 + */ + private function generateDetailedMethodsPlantUML(array $methods, string $class_name): array + { + $plant_uml = ""; + $notes = []; + + foreach ($methods as $method) + { + $notes = $this->generateMethodNotes($method, $class_name, $notes); + + $access_sign = $this->getAccessSign($method['access']); + + $arguments = ''; + if ($method['arguments']) + { + $arguments = $this->generateMethodArgumentsAndNotes( + $method['arguments'], $class_name, $method['name'], $notes); + + $arguments = implode(', ', $arguments); + } + + $static = $method['static'] ? '{static} ' : ''; + $abstract = $method['abstract'] ? '{abstract} ' : ''; + $return_type = $method['return_type'] ? " : {$method['return_type']}" : ''; + + $plant_uml .= " $access_sign {$abstract}$static{$method['name']}({$arguments})$return_type\n"; + } + + return [$plant_uml, $notes]; + } + + /** + * Generate basic methods PlantUML + * + * @param array $properties + * + * @return string + * @since 3.2.0 + */ + private function generateBasicMethodsPlantUML(array $methods): string + { + $plant_uml = ""; + + foreach ($methods as $method) + { + $access_sign = $this->getAccessSign($method['access']); + $static = $method['static'] ? '{static} ' : ''; + $abstract = $method['abstract'] ? '{abstract} ' : ''; + $return_type = $method['return_type'] ? " : {$method['return_type']}" : ''; + $plant_uml .= " $access_sign {$abstract}$static{$method['name']}()$return_type\n"; + } + + return $plant_uml; + } + + /** + * Generate method arguments and notes + * + * @param array $arguments + * @param string $class_name + * @param string $method_name + * @param array $notes + * + * @return array + * @since 3.2.0 + */ + private function generateMethodArgumentsAndNotes(array $arguments, string $class_name, + string $method_name, array &$notes): array + { + $formatted_arguments = []; + $notes_bucket = []; + $limit = 2; + + foreach ($arguments as $name => $arg) + { + $arg_type = $arg['type'] ? "{$arg['type']} " : ''; + $arg_default = $arg['default'] ? " = {$arg['default']}" : ''; + $arg_statment = "{$arg_type}$name{$arg_default}"; + + if ($limit == 0) + { + $formatted_arguments[] = "..."; + $limit = -1; + } + elseif ($limit > 0) + { + $formatted_arguments[] = $arg_statment; + $limit--; + } + + $notes_bucket[] = $arg_statment; + } + + if ($limit == -1) + { + $notes["{$class_name}::{$method_name}"][] = "\n arguments:\n " . implode("\n ", $notes_bucket); + } + + return $formatted_arguments; + } + + /** + * Generate method notes + * + * @param array $method + * @param string $class_name + * @param array $notes + * + * @return array + */ + private function generateMethodNotes(array $method, string $class_name, array &$notes): array + { + $notes_key = "{$class_name}::{$method['name']}"; + + if (is_string($method['comment']) && strlen($method['comment']) > 4) + { + $notes[$notes_key][] = trim(preg_replace("/^@.*[\r\n]*/m", '', $method['comment'])) . "\n"; + } + + if (is_string($method['since']) && strlen($method['since']) > 3) + { + $notes[$notes_key][] = "since: {$method['since']}"; + } + + if (is_string($method['return_type']) && strlen($method['return_type']) > 1) + { + $notes[$notes_key][] = "return: {$method['return_type']}"; + } + + if (is_string($method['deprecated']) && strlen($method['deprecated']) > 3) + { + $notes[$notes_key][] = "deprecated: {$method['deprecated']}"; + } + + return $notes; + } + + /** + * Generate notes PlantUML + * + * @param array $notes + * + * @return string + * @since 3.2.0 + */ + private function generateNotesPlantUML(array $notes): string + { + $plant_uml = ""; + $note_count = count($notes); + + $positions = ['right', 'left']; + $position_index = 0; + + foreach ($notes as $area => $note) + { + if ($note_count <= 7) + { + $position = 'right'; + } + else + { + $position = $positions[$position_index % 2]; + $position_index++; + } + + $plant_uml .= "\nnote $position of {$area}\n"; + $plant_uml .= " " . implode("\n ", $note) . "\n"; + $plant_uml .= "end note\n"; + } + + return $plant_uml; + } + + /** + * Get the access sign based on the access level. + * + * @param string $access The access level. + * + * @return string The corresponding access sign. + * @since 3.2.0 + */ + private function getAccessSign(string $access): string + { + switch ($access) + { + case 'private': + return '-'; + case 'protected': + return '#'; + case 'public': + return '+'; + case 'var': + return '+'; + default: + return ''; + } + } + + /** + * Get the correct class type. + * + * @param string $type The class type. + * + * @return string The correct class type label. + * @since 3.2.0 + */ + private function getClassTypeLable(string $type): string + { + $class_type_updater = [ + 'final class' => 'class', + 'abstract class' => 'abstract', + 'trait' => 'class' + ]; + + return $class_type_updater[$type] ?? $type; + } + + /** + * Get the extra class type tag. + * + * @param string $type The class type. + * + * @return string The correct class type label. + * @since 3.2.0 + */ + private function getClassTypeTag(string $type): string + { + $class_type_updater = [ + 'final class' => '<< (F,LightGreen) >>', + 'trait' => '<< (T,Orange) >>' + ]; + + return $class_type_updater[$type] ?? ''; + } + + /** + * Get class color based on class type. + * + * @param string $classType The class type. + * + * @return string The corresponding color. + * @since 3.2.0 + */ + private function getClassColor(string $classType): string + { + $class_colors = [ + 'class' => 'Gold', + 'final' => 'RoyalBlue', + 'abstract class' => 'Orange', + 'interface' => 'Lavender', + 'trait' => 'Turquoise' + ]; + + return $class_colors[$classType] ?? 'Green'; + } + + /** + * Get namespace color based on namespace depth. + * + * @param int $namespaceDepth The depth of the namespace. + * + * @return string The corresponding color. + * @since 3.2.0 + */ + private function getNamespaceColor(int $namespaceDepth): string + { + $namespace_colors = [ + 'lightgrey', + 'Azure', + 'DarkCyan', + 'Olive', + 'LightGreen', + 'DeepSkyBlue', + 'Wheat', + 'Coral', + 'Beige', + 'DeepPink', + 'DeepSkyBlue' + ]; + + return $namespace_colors[$namespaceDepth % count($namespace_colors)] ?? 'lightgrey'; + } diff --git a/src/fff3255d-c493-4c21-a48f-73b3ebf8ba05/code.power b/src/fff3255d-c493-4c21-a48f-73b3ebf8ba05/code.power new file mode 100644 index 0000000..bf28863 --- /dev/null +++ b/src/fff3255d-c493-4c21-a48f-73b3ebf8ba05/code.power @@ -0,0 +1,53 @@ + /** + * 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(TemplatelayoutData::class, 'Templatelayout.Data') + ->share('Templatelayout.Data', [$this, 'getTemplatelayoutData'], true); + + $container->alias(AliasData::class, 'Alias.Data') + ->share('Alias.Data', [$this, 'getAliasData'], true); + } + + /** + * Get the Compiler Templatelayout Data + * + * @param Container $container The DI container. + * + * @return TemplatelayoutData + * @since 3.2.0 + */ + public function getTemplatelayoutData(Container $container): TemplatelayoutData + { + return new TemplatelayoutData( + $container->get('Config'), + $container->get('Registry'), + $container->get('Alias.Data') + ); + } + + /** + * Get the Compiler Alias Data + * + * @param Container $container The DI container. + * + * @return AliasData + * @since 3.2.0 + */ + public function getAliasData(Container $container): AliasData + { + return new AliasData( + $container->get('Config'), + $container->get('Registry'), + $container->get('Customcode'), + $container->get('Customcode.Gui'), + $container->get('Model.Loader'), + $container->get('Model.Libraries') + ); + } diff --git a/super-powers.json b/super-powers.json index ef925da..13dca90 100644 --- a/super-powers.json +++ b/super-powers.json @@ -44,15 +44,6 @@ "path": "src\/2da6d6c4-eb29-4d69-8bc2-36d96e916adf", "guid": "2da6d6c4-eb29-4d69-8bc2-36d96e916adf" }, - "8aef58c1-3f70-4bd4-b9e4-3f29fcd41cff": { - "name": "ModelInterface", - "type": "interface", - "namespace": "VDM\\Joomla\\Componentbuilder\\Interfaces", - "code": "src\/8aef58c1-3f70-4bd4-b9e4-3f29fcd41cff\/code.php", - "settings": "src\/8aef58c1-3f70-4bd4-b9e4-3f29fcd41cff\/settings.json", - "path": "src\/8aef58c1-3f70-4bd4-b9e4-3f29fcd41cff", - "guid": "8aef58c1-3f70-4bd4-b9e4-3f29fcd41cff" - }, "4815e1c7-a433-443d-a112-d1e03d7df84b": { "name": "Database", "type": "class", @@ -62,15 +53,6 @@ "path": "src\/4815e1c7-a433-443d-a112-d1e03d7df84b", "guid": "4815e1c7-a433-443d-a112-d1e03d7df84b" }, - "b591855d-d106-4fe5-90ad-8e706f6267cf": { - "name": "Minify", - "type": "abstract class", - "namespace": "VDM\\Joomla\\Componentbuilder\\Compiler\\Utilities", - "code": "src\/b591855d-d106-4fe5-90ad-8e706f6267cf\/code.php", - "settings": "src\/b591855d-d106-4fe5-90ad-8e706f6267cf\/settings.json", - "path": "src\/b591855d-d106-4fe5-90ad-8e706f6267cf", - "guid": "b591855d-d106-4fe5-90ad-8e706f6267cf" - }, "fa4bf18e-301e-42e3-91fb-6e0096c07adc": { "name": "Config", "type": "class", @@ -980,6 +962,15 @@ "path": "src\/b836c1b1-b6b1-44f7-b8a2-9a763a4185b1", "guid": "b836c1b1-b6b1-44f7-b8a2-9a763a4185b1" }, + "6784dd52-0909-451a-a872-9a942a023c68": { + "name": "Grep", + "type": "final class", + "namespace": "VDM\\Joomla\\Componentbuilder\\Power", + "code": "src\/6784dd52-0909-451a-a872-9a942a023c68\/code.php", + "settings": "src\/6784dd52-0909-451a-a872-9a942a023c68\/settings.json", + "path": "src\/6784dd52-0909-451a-a872-9a942a023c68", + "guid": "6784dd52-0909-451a-a872-9a942a023c68" + }, "4e6ff11d-bebf-42f5-8fd7-b2f882857222": { "name": "Line", "type": "abstract class", @@ -1124,6 +1115,15 @@ "path": "src\/de01527a-6586-46ea-92e7-11ea3de1cedb", "guid": "de01527a-6586-46ea-92e7-11ea3de1cedb" }, + "e0c8c931-52a0-4171-9909-e8769505bb1f": { + "name": "Constantpaths", + "type": "class", + "namespace": "VDM\\Joomla\\Componentbuilder\\Utilities", + "code": "src\/e0c8c931-52a0-4171-9909-e8769505bb1f\/code.php", + "settings": "src\/e0c8c931-52a0-4171-9909-e8769505bb1f\/settings.json", + "path": "src\/e0c8c931-52a0-4171-9909-e8769505bb1f", + "guid": "e0c8c931-52a0-4171-9909-e8769505bb1f" + }, "268b85ef-49f3-4c39-8187-bb12e38d19ee": { "name": "Dynamicpath", "type": "class",