<?php

echo "<h2>Changelog</h2><table vspace=\"0\" hspace=\"0\" cellspacing=\"0\" cellpadding=\"0\" style=\"background-image:url(" . plugins_url('custom-tables/img/tab.png') . ");height:30px;\" ><tr>";
echo $this->tab_link($wcttab,'Stable','wct_changelog','');
echo $this->tab_link($wcttab,'Testing','wct_changelog','planned');
echo $this->tab_link($wcttab,'Beta','wct_changelog','beta');
echo "</tr></table>";

switch($_GET['wcttab2']) {
	case 'planned':

		/* This request is opening a TXT file, no PHP content or other stuff behind, also no user stats! But we dont wanted to send BETA changelog around the world on each server. No executable stuff can be added with this in any case, so no security problem! */
		$ch = curl_init("http://api.wuk.ch/changelogs/custom-tables.txt");
		curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
		$inhalt = curl_exec($ch);
		curl_close($ch);
		$ch = explode("== Changelog Beta ==\n\n",$inhalt);
		$ch = explode("== Planned Features ==",$ch[0]);

		$changelog = preg_replace("/\* (.*?)\n/","<li>$1</li>",$ch[1]);
		$changelog = preg_replace("/= (.*?) =/","</lu><strong>= $1 =</strong><lu>",$changelog);
		$changelog = preg_replace("/`(.*?)`/","<span style=\"background-color: #E1E1E1;\">$1</span>",$changelog);

		$changelog = preg_replace("/\[(.*?)\]\((.*?)\"(.*?)\"\)/","<a href=\"$2\" rel=\"external nofollow\" alt=\"$3\">$1</a>",$changelog);

		echo $changelog."</lu>";


	break;

	case 'beta':
		/* This request is opening a TXT file, no PHP content or other stuff behind, also no user stats! But we dont wanted to send BETA changelog around the world on each server. No executable stuff can be added with this in any case, so no security problem! */
		$ch = curl_init("http://api.wuk.ch/changelogs/custom-tables.txt");
		curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
		$inhalt = curl_exec($ch);
		curl_close($ch);
		$ch = explode("== Changelog Beta ==\n\n",$inhalt);
		$changelog = preg_replace("/\* (.*?)\n/","<li>$1</li>",$ch[1]);
		$changelog = preg_replace("/= (.*?) =/","</lu><strong>= $1 =</strong><lu>",$changelog);
		$changelog = preg_replace("/`(.*?)`/","<span style=\"background-color: #E1E1E1;\">$1</span>",$changelog);

		$changelog = preg_replace("/\[(.*?)\]\((.*?)\"(.*?)\"\)/","<a href=\"$2\" rel=\"external nofollow\" alt=\"$3\">$1</a>",$changelog);

		echo $changelog."</lu>";

	break;

	default:
		$fp = fopen(plugin_dir_path( __FILE__ ).'../readme.txt',"r");
		$inhalt = fread($fp,filesize(plugin_dir_path( __FILE__ ).'../readme.txt'));
		fclose($fp);
		$ch = explode("== Changelog ==\n\n",$inhalt);
		$ch = explode("\n== Upgrade Notice ==",$ch[1]);

		$changelog = preg_replace("/\* (.*?)\n/","<li>$1</li>",$ch[0]);
		$changelog = preg_replace("/= (.*?) =/","</lu><strong>= $1 =</strong><lu>",$changelog);
		$changelog = preg_replace("/`(.*?)`/","<span style=\"background-color: #E1E1E1;\">$1</span>",$changelog);

		$changelog = preg_replace("/\[(.*?)\]\((.*?)\"(.*?)\"\)/","<a href=\"$2\" rel=\"external nofollow\" alt=\"$3\">$1</a>",$changelog);

		echo $changelog."</lu>";
	break;
}
?>