```php
1 ) {
$gradient_points = array();
for($i = 0; $i < $n; $i++) {
$pc = round($i*(100.0/($n-1)));
array_push($gradient_points,"$colours[$i] ${pc}%");
}
$direction = "to bottom";
$gradient = "linear-gradient($direction, ".implode(", ",$gradient_points).")";
array_push($bg,$gradient);
}
$css = "background: url('/marble2.png'), ".implode(" ",$bg)." $repeat;";
return $css;
}
function make_gradient_background() {
if( file_exists("grad.txt") ) {
$lines = file("grad.txt");
$line = $lines[0];
$bg_colours = preg_split("/[\\s,]+/",trim($line));
} else {
$bg_colours = pseudo_random_gradient(getcwd());
}
$css_bg = make_gradient_bg_css($bg_colours);
$last_colour = $bg_colours[count($bg_colours)-1];
$r = hexdec(substr($last_colour,1,2));
$g = hexdec(substr($last_colour,3,2));
$b = hexdec(substr($last_colour,5,2));
if( (($r + $g + $b) / 3) > 128 ) {
$light_bg = true;
} else {
$light_bg = false;
}
$css = "
body {
$css_bg
}
";
if( $light_bg ) {
$css .= "footer {
color: black;
}
footer a {
color: #007;
}
footer a:visited {
color: #01a;
}
";
} else {
$css .= "footer {
color: hsl(0,0%,80%);
}
footer a {
color: white;
}
footer a:visited {
color: #dde;
}
";
}
$style = "";
return $style;
}
class WikiRendererParsedown1 extends WikiRenderer {
public function __construct() {
$this->protected = array();
$this->protected_prefix = strtolower(hash("sha256",time()));
}
public function render_view(array $vars): void {
$word = $vars["WIKI_WORD"];
$source = $vars["WIKI_PAGE_SOURCE"];
$vars["WIKI::FAVICON"] = '';
if( file_exists("favicon.png") ) {
$vars["WIKI::FAVICON"] = '';
}
if( file_exists("favicon_view.png") ) {
$vars["WIKI::FAVICON"] = '';
}
if( file_exists("bug.png") ) {
#$vars["BUG_BUG"] = '
';
$vars["BUG_BUG"] = '
';
} else if(file_exists("nobug") ) {
$vars["BUG_BUG"] = "";
} else {
$vars["BUG_BUG"] = get_random_bug(getcwd());
}
# convert tags
if( preg_match("@^tags:(.*)$@m",$source,$m) ) {
$tags = preg_split("@\s+@",trim($m[1]));
$source = explode("\n",$source,2)[1];
$t = [];
foreach($tags as $tag) {
switch($tag[0]) {
case "#":
$cls = "hashtag";
$x = substr($tag,1);
$h = "$tag";
break;
case "%":
$cls = "category";
$h = "$tag";
break;
case "@":
$cls = "user";
$h = "$tag";
break;
default:
$cls = "other";
$h = "$tag";
}
array_push($t,"
\n"; var_dump($vars); echo "\n"; $vars["GRAD_GRAD"] = make_gradient_background(); $source = preg_replace_callback("/^(```nohighlight\\s(.*?)^```)/ms",[$this,"protect_nohighlight_cb"],$source); if( $this->abcjs ) { $source = preg_replace_callback("/^(```abc\\s(.*?)^```)/ms",[$this,"protect_abc_cb"],$source); } $source = preg_replace_callback("/^(```(.*?)^```)/ms",[$this,"protect_block_cb"],$source); $source = preg_replace_callback("/(`+)(.*?)(\\1)/s",[$this,"protect_backquote_cb"],$source); $source = preg_replace_callback(HEADER_REGEX,[$this,"protect_header"],$source); $source = preg_replace_callback(YOUTUBE_REGEX,[$this,"protect_youtube"],$source); $source = preg_replace_callback(MD_IMGLINK_REGEX,[$this,"protect_mdimglink_cb"],$source); $source = preg_replace_callback(OB_LINK_REGEX,[$this,"protect_oblink_cb"],$source); $source = preg_replace_callback('@\[([^\]]*)\]\(\)@',[$this,"protect_unwiki_cb"],$source); $source = preg_replace_callback(MD_LINK_QUOTE_REGEX,[$this,"protect_mdlink_quote_cb"],$source); $source = preg_replace_callback(MD_LINK_REGEX,[$this,"protect_mdlink_cb"],$source); $source = preg_replace_callback(URL_REGEX,[$this,"protect_url_cb"],$source); $source = preg_replace_callback(WIKIWORD_REGEX, [$this,"WikiWord_to_link"],$source); foreach($this->protected as $id => $string) { $source = str_replace($id,$string,$source); } #echo "\n"; $vars['WIKI_PAGE_SOURCE'] = $source; $this->render_view_real($vars); } public function render_view_real(array $vars): void { $source = $vars['WIKI_PAGE_SOURCE']; #echo "\n"; # protect \(..\) and \[..\] from Parsedown $source = str_replace('\\[',MRFLIBBLE,$source); $source = str_replace('\\]',HEXVISION,$source); $source = str_replace('\\(',FRYLITTLEPIGGY,$source); $source = str_replace('\\)',FRYTHEEWELL,$source); $source = str_replace('\\{',COOKLITTLEPIGGY,$source); $source = str_replace('\\}',COOKTHEEWELL,$source); $this->protected = []; if( $this->abcjs ) { $source = preg_replace_callback("/^(?:```abc\\s(.*?)^```)/ms",[$this,"protect_abc_pd_cb"],$source); } $parsedown = new Parsedown(); $result = $parsedown->text($source); foreach($this->protected as $id => $string) { $result = str_replace($id,$string,$result); } $result = str_replace(MRFLIBBLE,'\\[',$result); $result = str_replace(HEXVISION,'\\]',$result); $result = str_replace(FRYLITTLEPIGGY,'\\(',$result); $result = str_replace(FRYTHEEWELL,'\\)',$result); $result = str_replace(COOKLITTLEPIGGY,'\\{',$result); $result = str_replace(COOKTHEEWELL,'\\}',$result); $result = preg_replace("/(?<=[^-])---(?=[^-])/","—",$result); $result = preg_replace("/(?<=[^-])--(?=[^-])/","–",$result); $vars["WIKI_PAGE_BODY"] = $result; if( preg_match("/Mobile/",$_SERVER["HTTP_USER_AGENT"]) ) { $template = file_get_contents("view_template_mob.html"); } else { $template = file_get_contents("view_template_md.html"); } $this->render_template($template,$vars); } public function render_edit(array $vars): void { $vars["WIKI::FAVICON"] = ''; if( file_exists("favicon.png") ) { $vars["WIKI::FAVICON"] = ''; } if( file_exists("favicon_edit.png") ) { $vars["WIKI::FAVICON"] = ''; } $vars["GRAD_GRAD"] = make_gradient_background(); if( $vars["WIKI_ERROR_STRING"] ) { $vars["WIKI_ERROR_MESSAGE"] = $this->format_error_message($vars["WIKI_ERROR_STRING"]); } else { $vars["WIKI_ERROR_MESSAGE"] = ""; } $template = file_get_contents("edit_template_mob.html"); $this->render_template($template,$vars); } public function render_versions(array $vars): void { $versions = $vars['WIKI_VERSIONS']; $word = $vars['WIKI_WORD']; $body = ""; if( count($versions) == 0) { $this->vars['WIKI_PAGE_SOURCE'] = "Word $word has no versions."; } else { foreach( $versions as $version) { $body .= "1. [".date(DATE_COOKIE,intval($version))."]($word?version=$version)\n"; } $body .= "1. [current]($word)\n"; } $parsedown = new Parsedown(); $rendered = $parsedown->text($body); $vars["WIKI_PAGE_BODY"] = $rendered; $template = file_get_contents("versions_template_md.html"); $this->render_template($template,$vars); } private function protect(string $content): string { $protid = strtolower(hash("sha256",$this->protect_count++)); $key = $this->protected_prefix.$protid; # generate unique string $this->protected[$key] = $content; return $key; } private function protect_cb(array $match): string { return $this->protect($match[0]); } private function protect_nohighlight_cb(array $match): string { return $this->protect($match[2]); } private function protect_abc_cb(array $match): string { # protect ABC from WikiWord return $this->protect($match[0]); } private function protect_abc_pd_cb(array $match): string { # protect ABC from Parsedown, convert to div.abc return $this->protect("
$err_msg
\n"; } } ```