/** Singleton instance */
 public static function get_instance()
 {
     if (!isset(self::$instance)) {
         self::$instance = new self();
     }
     return self::$instance;
 }
function HandleM2MOptions ($pagename, $auth='read') {
	global $M2MDataDir, $M2MDir, $M2MUrl;
	$formats = WikiConverterFactory::availableTargetFormats();
	$targetformat = $_REQUEST['targetformat'];

	// read default options
	$options = new StylesheetOptions();
	$options->readXML("$M2MDir/options/$targetformat.xml");
	$datadir = "$M2MDataDir/$pagename";
	if (file_exists("$datadir/{$targetformat}opt.xml"))
		$options->readXML("$datadir/{$targetformat}opt.xml");

	print "<html><head><title>media2mult options</title>";
	print "<link rel='stylesheet' type='text/css' href='$M2MUrl/options/options.css'>";
	print "<body>";
	OptionPage::showForm($options, $formats[$targetformat], "$_SERVER[PHP_SELF]?n=$pagename&action=m2m-saveoptions", 3);
	print "</body></html>";
}
	function showForm (&$options, $formatdescr, $targeturl, $columns) {
		global $M2MDir, $M2MUrl;
		$categories = $options->getCategories();
?>
		<script language='JavaScript'>
		function expand (id, val) {
			var catElem = document.getElementById('cat'+id);
			var bodyElem = document.getElementById('catbody'+id);
			if (catElem && bodyElem) {
				if (val == 'open') {
					catElem.className = 'open';
					bodyElem.style.display = '';
				}
				else if (val == 'close') {
					catElem.className = 'close';
					bodyElem.style.display = 'none';
				}
				else {
					catElem.className = (catElem.className == 'open' ? 'close' : 'open');
					bodyElem.style.display = (bodyElem.style.display == 'none' ? '' : 'none');
				}
			}
		}

		function expandAll (open) {
			var i;
			for (i=0; i < <?php 
echo count($categories);
?>
; i++)
				expand(i, open ? 'open' : 'close');
		}
		</script>
	<table class='bgtable' cellpadding="10" width="95%" align="center"><tr><td>
	<form action='<?php 
echo $targeturl;
?>
' method='post' enctype='multipart/form-data'>
	<table class='cattable' cellpadding="5" width="100%">
	<tr bgcolor='#555555'>
	<td colspan='<?php 
echo $columns;
?>
'>
	<div class='title'>Optionen f&uuml;r Zielformat <?php 
echo $formatdescr;
?>
</div>
	<div class='openclose'>
		<img src='<?php 
echo $M2MUrl;
?>
/images/plus.gif' onClick="expandAll(true)">
		<img src='<?php 
echo $M2MUrl;
?>
/images/minus.gif' onClick="expandAll(false)">
	</div>
	</td></tr>
<?
		$catcount = 0;
		foreach ($categories as $c) {
			$col = 0;
			$optclass = 'opt1';
			if ($c['title'] == 'hidden')
				foreach ($c['options'] as $o)
					echo "<input type='hidden' name='$o[name]' value='$o[value]'>\n";	
			else {
				echo "<tr class='catrow'><td colspan='$columns'>";
				echo "<a id='cat$catcount' class='open' onClick='expand($catcount)'>$c[title]</a></td></tr>\n";
				echo "<tbody id='catbody$catcount'>\n";
				foreach ($c['options'] as $o) {
					if ($col == 0)
						echo "<tr class='$optclass'>";
					echo "<td>"; 
					if (is_array($o['value'])) {
						echo htmlentities($o['description']).":<br>";
						foreach ($o['value'] as $k=>$v)
							echo OptionPage::getHtmlInputElement("$o[name][$k]", $v['type'], "$o[indexdescr] $k", $v['value']) . "<br>\n";
					}
					else
						echo OptionPage::getHtmlInputElement($o['name'], $o['type'], $o['description'], $o['value']) . "</td>\n";
					if ($col++ >= $columns-1) {
						$col = 0;
						$optclass = ($optclass == 'opt1' ? 'opt2' : 'opt1');
						echo "</tr>";					
					}
				}
				for ($col %= $columns; $col > 0; $col = ($col+1) % $columns)
					echo "<td class='$optclass'></td>";
				$catcount++;
				echo "</tbody>\n";
			}
		}
?>
	</table></td></tr><tr><td>
	<input type="submit" name="submit" value="OK" class="button">
	<input type="reset" name="submit" value="Zur&uuml;cksetzen" class="button">
	<input type="button" value="Abbrechen" class="button" onClick="window.close()">
	</td></tr>
	</form></table>
<?
	}
    private function generateTwitterCardTags()
    {
        $imgUrl = self::getImageUrl($this->imageId, 'twitter');
        ?>
        <!-- Twitter -->
        <meta property="twitter:card" content="summary_large_image"/>
        <meta property="twitter:title" content="<?php 
        echo esc_attr($this->title);
        ?>
"/>
        <meta property="twitter:description" content="<?php 
        echo esc_attr($this->pledgeText);
        ?>
"/>
        <meta property="twitter:image" content="<?php 
        echo esc_attr($imgUrl);
        ?>
"/>
        <?php 
        $via = OptionPage::getAWCOption(OptionPage::OPTION_TWITTER_SCREENNAME);
        if ($via) {
            ?>
            <meta property="twitter:site" content="@<?php 
            echo esc_attr($via);
            ?>
"/><?php 
        }
    }