From b10b01949404aab8f0ace9334ae4e617cfe43031 Mon Sep 17 00:00:00 2001 From: Michael Richey Date: Sun, 3 Dec 2017 19:24:53 -0600 Subject: [PATCH 1/4] Implement onContentPrepare --- admin/helpers/compiler/e_Interpretation.php | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/admin/helpers/compiler/e_Interpretation.php b/admin/helpers/compiler/e_Interpretation.php index 9374bc27e..d954cdeb3 100644 --- a/admin/helpers/compiler/e_Interpretation.php +++ b/admin/helpers/compiler/e_Interpretation.php @@ -1658,8 +1658,12 @@ class Interpretation extends Fields if (strpos($get['selection']['select'], $field) !== false) { // build decoder string - $fieldUikit .= PHP_EOL."\t".$tab."\t//".$this->setLine(__LINE__)." Make sure the content prepare plugins fire on ".$field." (TODO)"; - $fieldUikit .= PHP_EOL."\t".$tab."\t".$string."->".$field." = JHtml::_('content.prepare',".$string."->".$field.");"; + if(!$runplugins) { + $runplugins = PHP_EOL."\t".$tab."\tJPluginHelper::importPlugin('content');\n"; + $runplugins .= PHP_EOL."\t".$tab."\t".'$dispatcher = JEventDispatcher::getInstance();'; + } + $fieldUikit .= PHP_EOL."\t".$tab."\t//".$this->setLine(__LINE__)." Make sure the content prepare plugins fire on ".$field; + $fieldUikit .= PHP_EOL."\t".$tab."\t".'$dispatcher->trigger("onContentPrepare",array("com_'.$this->fileContentStatic['###component###'].'.'.$this->fileContentStatic['###view###'].'",&'.$string.'->'.$field.',$item->params));'; // only load for uikit version 2 (TODO) we may need to add another check here if (2 == $this->uikit || 1 == $this->uikit) { @@ -1668,7 +1672,7 @@ class Interpretation extends Fields } } } - return $fieldUikit; + return ($runplugins?:'').$fieldUikit; } public function setCustomViewCustomJoin(&$gets,$string,$code,&$asBucket,$tab = '') From 102ed837c2bb576f8ec6a2cd32b4ac65f65870f7 Mon Sep 17 00:00:00 2001 From: Michael Richey Date: Sun, 3 Dec 2017 19:43:45 -0600 Subject: [PATCH 2/4] automatic context based on available vars --- admin/helpers/compiler/e_Interpretation.php | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/admin/helpers/compiler/e_Interpretation.php b/admin/helpers/compiler/e_Interpretation.php index d954cdeb3..ce5b4e68b 100644 --- a/admin/helpers/compiler/e_Interpretation.php +++ b/admin/helpers/compiler/e_Interpretation.php @@ -1653,6 +1653,13 @@ class Interpretation extends Fields public function setCustomViewFieldUikitChecker(&$get, $checker, $string, $code, $tab = '') { $fieldUikit = ''; + $runplugins = false; + $context = array(); + foreach(array('###component###','###view###') as $key) { + if(array_key_exists($key,$this->fileContentStatic)) { + $context[] = $this->fileContentStatic[$key]; + } + } foreach ($checker as $field => $array) { if (strpos($get['selection']['select'], $field) !== false) @@ -1663,7 +1670,7 @@ class Interpretation extends Fields $runplugins .= PHP_EOL."\t".$tab."\t".'$dispatcher = JEventDispatcher::getInstance();'; } $fieldUikit .= PHP_EOL."\t".$tab."\t//".$this->setLine(__LINE__)." Make sure the content prepare plugins fire on ".$field; - $fieldUikit .= PHP_EOL."\t".$tab."\t".'$dispatcher->trigger("onContentPrepare",array("com_'.$this->fileContentStatic['###component###'].'.'.$this->fileContentStatic['###view###'].'",&'.$string.'->'.$field.',$item->params));'; + $fieldUikit .= PHP_EOL."\t".$tab."\t".'$dispatcher->trigger("onContentPrepare",array("com_'.implode('.',$context).'",&'.$string.'->'.$field.',$item->params));'; // only load for uikit version 2 (TODO) we may need to add another check here if (2 == $this->uikit || 1 == $this->uikit) { From 9a6ad66e32812fcba53e94afa1d9ffd8325d1921 Mon Sep 17 00:00:00 2001 From: Michael Richey Date: Sun, 3 Dec 2017 19:53:05 -0600 Subject: [PATCH 3/4] Fixed context --- admin/helpers/compiler/e_Interpretation.php | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/admin/helpers/compiler/e_Interpretation.php b/admin/helpers/compiler/e_Interpretation.php index ce5b4e68b..36a075a7d 100644 --- a/admin/helpers/compiler/e_Interpretation.php +++ b/admin/helpers/compiler/e_Interpretation.php @@ -1654,12 +1654,6 @@ class Interpretation extends Fields { $fieldUikit = ''; $runplugins = false; - $context = array(); - foreach(array('###component###','###view###') as $key) { - if(array_key_exists($key,$this->fileContentStatic)) { - $context[] = $this->fileContentStatic[$key]; - } - } foreach ($checker as $field => $array) { if (strpos($get['selection']['select'], $field) !== false) @@ -1670,7 +1664,7 @@ class Interpretation extends Fields $runplugins .= PHP_EOL."\t".$tab."\t".'$dispatcher = JEventDispatcher::getInstance();'; } $fieldUikit .= PHP_EOL."\t".$tab."\t//".$this->setLine(__LINE__)." Make sure the content prepare plugins fire on ".$field; - $fieldUikit .= PHP_EOL."\t".$tab."\t".'$dispatcher->trigger("onContentPrepare",array("com_'.implode('.',$context).'",&'.$string.'->'.$field.',$item->params));'; + $fieldUikit .= PHP_EOL."\t".$tab."\t".'$dispatcher->trigger("onContentPrepare",array($this->_context,&'.$string.'->'.$field.',$item->params));'; // only load for uikit version 2 (TODO) we may need to add another check here if (2 == $this->uikit || 1 == $this->uikit) { From fa83ea7bc9855aa69d83f7aa5f805c0fec2d4abb Mon Sep 17 00:00:00 2001 From: Llewellyn van der Merwe Date: Mon, 4 Dec 2017 17:57:19 +0200 Subject: [PATCH 4/4] moved the dispatcher out of the loop --- admin/helpers/compiler/e_Interpretation.php | 28 +++++++++++++++------ 1 file changed, 21 insertions(+), 7 deletions(-) diff --git a/admin/helpers/compiler/e_Interpretation.php b/admin/helpers/compiler/e_Interpretation.php index 36a075a7d..3e6b844fe 100644 --- a/admin/helpers/compiler/e_Interpretation.php +++ b/admin/helpers/compiler/e_Interpretation.php @@ -1660,11 +1660,12 @@ class Interpretation extends Fields { // build decoder string if(!$runplugins) { - $runplugins = PHP_EOL."\t".$tab."\tJPluginHelper::importPlugin('content');\n"; - $runplugins .= PHP_EOL."\t".$tab."\t".'$dispatcher = JEventDispatcher::getInstance();'; + $runplugins = PHP_EOL.$tab."\t//".$this->setLine(__LINE__)." Load the JEvent Dispatcher"; + $runplugins .= PHP_EOL.$tab."\tJPluginHelper::importPlugin('content');"; + $runplugins .= PHP_EOL.$tab."\t".'$this->_dispatcher = JEventDispatcher::getInstance();'; } $fieldUikit .= PHP_EOL."\t".$tab."\t//".$this->setLine(__LINE__)." Make sure the content prepare plugins fire on ".$field; - $fieldUikit .= PHP_EOL."\t".$tab."\t".'$dispatcher->trigger("onContentPrepare",array($this->_context,&'.$string.'->'.$field.',$item->params));'; + $fieldUikit .= PHP_EOL."\t".$tab."\t".'$this->_dispatcher->trigger("onContentPrepare",array($this->_context,&'.$string.'->'.$field.',$item->params));'; // only load for uikit version 2 (TODO) we may need to add another check here if (2 == $this->uikit || 1 == $this->uikit) { @@ -1673,7 +1674,10 @@ class Interpretation extends Fields } } } - return ($runplugins?:'').$fieldUikit; + // load dispatcher + $this->JEventDispatcher = array('###DISPATCHER###' => ($runplugins?:'')); + // return UIKIT fix + return $fieldUikit; } public function setCustomViewCustomJoin(&$gets,$string,$code,&$asBucket,$tab = '') @@ -2128,6 +2132,8 @@ class Interpretation extends Fields $getItem .= PHP_EOL."\t".$tab."\t\treturn false;"; } $getItem .= PHP_EOL."\t".$tab."\t}"; + // dispatcher placholder + $getItem .= "###DISPATCHER###"; if (ComponentbuilderHelper::checkArray($get->main_get)) { $asBucket = array(); @@ -2208,7 +2214,8 @@ class Interpretation extends Fields $getItem .= PHP_EOL.PHP_EOL."\t".$tab."\t//".$this->setLine(__LINE__)." set data object to item."; $getItem .= PHP_EOL."\t".$tab."\t\$this->_item[\$pk] = \$data;"; } - return $getItem; + // check if the dispather should be added + return str_replace(array_keys($this->JEventDispatcher), array_values($this->JEventDispatcher), $getItem); } return PHP_EOL."\t".$tab."\t//".$this->setLine(__LINE__)."add your custom code here."; } @@ -2531,6 +2538,8 @@ class Interpretation extends Fields $methods .= PHP_EOL.PHP_EOL."\t\t//".$this->setLine(__LINE__)." check if there was data returned"; $methods .= PHP_EOL."\t\tif (\$db->getNumRows())"; $methods .= PHP_EOL."\t\t{"; + // set dispatcher placeholder + $methods .= "###DISPATCHER###"; // set decoding of needed fields if (isset($this->siteFieldData['decode'][$default['code']][$get['key']][$default['as']])) { @@ -2634,13 +2643,15 @@ class Interpretation extends Fields $script .= PHP_EOL."\t\t//".$this->setLine(__LINE__)." Get the encryption object."; $script .= PHP_EOL."\t\t\$advanced = new FOFEncryptAes(\$advancedkey, 256);".PHP_EOL; } - $methods = str_replace('###CRYPT###',$script,$methods); + $methods = str_replace('###CRYPT###', $script, $methods); } } + // insure the crypt placeholder is removed $methods = str_replace('###CRYPT###','',$methods); } } - return $methods.PHP_EOL; + // check if the dispatcher must be set + return str_replace(array_keys($this->JEventDispatcher), array_values($this->JEventDispatcher), $methods).PHP_EOL; } public function setCustomViewMethodDefaults($get,$code) @@ -2739,6 +2750,7 @@ class Interpretation extends Fields $getItem .= PHP_EOL.PHP_EOL."\t\t//".$this->setLine(__LINE__)." Convert the parameter fields into objects."; $getItem .= PHP_EOL."\t\tif (".$Component."Helper::checkArray(\$items))"; $getItem .= PHP_EOL."\t\t{"; + $getItem .= "###DISPATCHER###"; $getItem .= PHP_EOL."\t\t\tforeach (\$items as \$nr => &\$item)"; $getItem .= PHP_EOL."\t\t\t{"; $getItem .= PHP_EOL."\t\t\t\t//".$this->setLine(__LINE__)." Always create a slug for sef URL's"; @@ -2778,6 +2790,8 @@ class Interpretation extends Fields $asBucket[] = $main_get['as']; } } + // check if we should load the dispatcher + $getItem = str_replace(array_keys($this->JEventDispatcher), array_values($this->JEventDispatcher), $getItem); // setup Globals $getItem .= $this->setCustomViewGlobals($get->global,'$item',$asBucket,"\t\t"); // setup the custom gets that returns multipal values