Skip to content

Commit

Permalink
Adding hooks for color+html tag modifications
Browse files Browse the repository at this point in the history
Adding the possilibility to hook in and alter core colors (still css+html edits in templates necessary) for @ironmangary
  • Loading branch information
Oliver Brendel committed Oct 10, 2023
1 parent 3760921 commit 3b0df6a
Show file tree
Hide file tree
Showing 5 changed files with 88 additions and 14 deletions.
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
################################################################################
# Diese .gitignore-Datei wurde von Microsoft(R) Visual Studio automatisch erstellt.
################################################################################

/.vs
11 changes: 11 additions & 0 deletions common.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
11 changes: 11 additions & 0 deletions ext/lotgd_common.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
73 changes: 60 additions & 13 deletions lib/output.php
Original file line number Diff line number Diff line change
Expand Up @@ -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; //!<open spans, or whatever...we need to make sure that we close them on output
private $nestedeval; //!< if we need to execute module code, it is handled in this variable

/**
* Constructor. Fill our class with the colors and set all up.
Expand All @@ -23,6 +24,7 @@ class output_collector {
public function __construct() {
$this->output='';
$this->nestedtags=array();
$this->nestedtags_eval=array();
$this->block_new_output=false;
$this->nestedtags['font']=false;
$this->nestedtags['div']=false;
Expand Down Expand Up @@ -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
*
Expand Down Expand Up @@ -242,6 +238,12 @@ function appoencode($data,$priv=false){
else $this->nestedtags['font']=true;
$out.="<span class='".$this->colors[$data[$pos]]."'>";
} 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.="<br>\n";
Expand Down Expand Up @@ -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...
Expand Down Expand Up @@ -456,7 +507,3 @@ function appoencode($data,$priv=false) {
global $output;
return $output->appoencode($data,$priv);
}



?>
2 changes: 1 addition & 1 deletion modules.php
Original file line number Diff line number Diff line change
Expand Up @@ -292,7 +292,7 @@
rawoutput($moduleinfo[$i]['shortname'] . ".php");
rawoutput("</td>");
rawoutput("</tr>");
if (count($moduleinfo[$i]['requires'])){
if (isset($moduleinfo[$i]['requires']) && is_array($moduleinfo[$i]['requires']) && count($moduleinfo[$i]['requires']) > 0){
rawoutput("<tr class='".($i%2?"trlight":"trdark")."'>");
rawoutput("<td>&nbsp;</td>");
rawoutput("<td colspan='6'>");
Expand Down

0 comments on commit 3b0df6a

Please sign in to comment.