From 3b0df6aaa62b72c84ec74ee97df3783f36cdc8a7 Mon Sep 17 00:00:00 2001 From: Oliver Brendel Date: Tue, 10 Oct 2023 19:31:58 +0200 Subject: [PATCH] Adding hooks for color+html tag modifications Adding the possilibility to hook in and alter core colors (still css+html edits in templates necessary) for @IronManGary --- .gitignore | 5 +++ common.php | 11 +++++++ ext/lotgd_common.php | 11 +++++++ lib/output.php | 73 ++++++++++++++++++++++++++++++++++++-------- modules.php | 2 +- 5 files changed, 88 insertions(+), 14 deletions(-) create mode 100644 .gitignore diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..2c31b73 --- /dev/null +++ b/.gitignore @@ -0,0 +1,5 @@ +################################################################################ +# Diese .gitignore-Datei wurde von Microsoft(R) Visual Studio automatisch erstellt. +################################################################################ + +/.vs diff --git a/common.php b/common.php index a48a647..9358246 100644 --- a/common.php +++ b/common.php @@ -466,6 +466,17 @@ } +// After setup, allow modification of colors and nested tags +$colors = modulehook("core-colors",$output->get_colors()); +$output->set_colors($colors); +// and nested tag handling +$nestedtags = modulehook("core-nestedtags",$output->get_nested_tags()); +$output->set_nested_tags($nestedtags); +// and nested tag eval +$nestedeval = modulehook("core-nestedtags-eval",$output->get_nested_tag_eval()); +$output->set_nested_tag_eval($nestedeval); + + // WARNING: // do not hook on this modulehook unless you really need your module to run // on every single page hit. This is called even when the user is not diff --git a/ext/lotgd_common.php b/ext/lotgd_common.php index 4dbfded..45749c6 100644 --- a/ext/lotgd_common.php +++ b/ext/lotgd_common.php @@ -445,6 +445,17 @@ } +// After setup, allow modification of colors and nested tags +$colors = modulehook("core-colors",$output->get_colors()); +$output->set_colors($colors); +// and nested tag handling +$nestedtags = modulehook("core-nestedtags",$output->get_nested_tags()); +$output->set_nested_tags($nestedtags); +// and nested tag eval +$nestedeval = modulehook("core-nestedtags-eval",$output->get_nested_tag_eval()); +$output->set_nested_tag_eval($nestedeval); + + // WARNING: // do not hook on this modulehook unless you really need your module to run // on every single page hit. This is called even when the user is not diff --git a/lib/output.php b/lib/output.php index fbaf8e9..e547a6b 100644 --- a/lib/output.php +++ b/lib/output.php @@ -15,6 +15,7 @@ class output_collector { private $colors; //!< the color codes=>CSS tags private $color_map,$colormap_esc; //!< the letters of color codes only, escaped and not escaped private $nestedtags; //!output=''; $this->nestedtags=array(); + $this->nestedtags_eval=array(); $this->block_new_output=false; $this->nestedtags['font']=false; $this->nestedtags['div']=false; @@ -76,15 +78,9 @@ public function __construct() { "M" => "coltan", ); //*cough* if you choose color codes like \ or whatnot... SENSITIVE codes like special programmer chars... then escape them. Sadly we have % (breaks sprintf i.e.) AND ) in it... (breaks regular expressions) - $cols=$this->colors; - $escape=array(')','$',"(","[","]","{","}"); - foreach ($escape as $letter) { - if (isset($cols[$letter])) $cols["\\".$letter]=$cols[$letter]; - unset($cols[$letter]); - } - $this->colormap_esc=array_keys($cols); //please, no empty color array. - $this->colormap=array_keys($this->colors); + $this->set_color_map(); } + /** * Raw output (unprocessed) appended to the output buffer * @@ -242,6 +238,12 @@ function appoencode($data,$priv=false){ else $this->nestedtags['font']=true; $out.=""; } else { + // Check if we have special nested tags + if (isset($this->nestedtags_eval[$data[$pos]])) { + $func = $this->nestedtags_eval[$data[$pos]]; + eval($func); + continue; + } switch($data[$pos]){ case "n": $out.="
\n"; @@ -336,16 +338,65 @@ function appoencode($data,$priv=false){ } return $out; } + + public function set_color_map() { + // internal array to escape special chars + $escape=array(')','$',"(","[","]","{","}"); + $cols=$this->colors; + foreach ($escape as $letter) { + if (isset($cols[$letter])) $cols["\\".$letter]=$cols[$letter]; + unset($cols[$letter]); + } + $this->colormap_esc=array_keys($cols); //please, no empty color array. + $this->colormap=array_keys($this->colors); + } /** * Returns the complete color array * @return an array with $colorcode=>$csstag format */ - public function get_colors() { return $this->colors; } + /** + * allow external setting of colors + */ + public function set_colors($colors) { + $this->colors = $colors; + $this->set_color_map(); + } + + /** + * Returns the nested tags array + * @return an array with $tagname=>$open format + */ + public function get_nested_tags() { + return $this->nestedtags; + } + + /** + * Sets the nested tags array + */ + public function set_nested_tags($tags) { + $this->nestedtags = $tags; + } + + /** + * Sets the nested tag eval array + */ + public function set_nested_tag_eval($nested_eval) { + $this->nestedtags_eval = $nested_eval; + } + + /** + * Returns the nested tag eval array + * @return an array with $colorcode=>$csstag format + */ + public function get_nested_tag_eval() { + return $this->nestedtags_eval; + } + /** * Colormap for use with sanitize commands * @return Returns only the codes with no spaces: $colorcode$colorcode... @@ -456,7 +507,3 @@ function appoencode($data,$priv=false) { global $output; return $output->appoencode($data,$priv); } - - - -?> diff --git a/modules.php b/modules.php index 143c5c7..659cfb6 100644 --- a/modules.php +++ b/modules.php @@ -292,7 +292,7 @@ rawoutput($moduleinfo[$i]['shortname'] . ".php"); rawoutput(""); rawoutput(""); - if (count($moduleinfo[$i]['requires'])){ + if (isset($moduleinfo[$i]['requires']) && is_array($moduleinfo[$i]['requires']) && count($moduleinfo[$i]['requires']) > 0){ rawoutput(""); rawoutput(" "); rawoutput("");