function smarty_function_articletext($input) { global $imageCredits, $smarty, $CONF; $output = preg_replace('/\\n(-{7,})\\n(.*?)\\n(-{7,})/es', "article_make_table('\$2')", str_replace("\r", '', $input)); if ($CONF['CONTENT_HOST'] != $_SERVER['HTTP_HOST']) { $output = str_replace($CONF['CONTENT_HOST'], $_SERVER['HTTP_HOST'], $output); } $output = preg_replace('/\\!(\\[+)/e', 'str_repeat("¬",strlen("$1"))', $output); $output = str_replace(array('[b]', '[/b]', '[big]', '[/big]', '[small]', '[/small]', '[i]', '[/i]', '[h2]', '[/h2]', '[h3]', '[/h3]', '[h4]', '[/h4]', '[tt]', '[/tt]', '[float]', '[/float]', '[br/]', '[hr/]', '[reveal]', '[/reveal]'), array('<b>', '</b>', '<big>', '</big>', '<small>', '</small>', '<i>', '</i>', '<h2>', '</h2>', '<h3>', '</h3>', '<h4>', '</h4>', '<tt>', '</tt>', '<div style="float:left;padding-right:10px;padding-bottom:10px;position:relative">', '</div>', '<br style="clear:both"/>', '<hr align="center" width="75%"/>', '<span style="color:white">', '</span>'), $output); $pattern = array(); $replacement = array(); if (preg_match_all('/<h(\\d)>([^\\n]+?)<\\/h(\\d)>/', $output, $matches)) { $list = array(); foreach ($matches[1] as $i => $level) { $list[] = "<li class=\"h{$level}\"><a href=\"#p{$i}\">{$matches[2][$i]}</a></li>"; $pattern[] = '/<h(' . $level . ')>(' . preg_quote($matches[2][$i], '/') . ')<\\/h(' . $level . ')>/'; $replacement[] = '<h$1><a name="p' . $i . '"></a>$2</h$3>'; } $list = implode("\n", $list); $smarty->assign("tableContents", $list); } $pattern[] = '/<\\/h(\\d)>\\n(?!\\*)/'; $replacement[] = '</h$1>'; $pattern[] = '/(?<!["\'\\[\\/\\!\\w])([STNH]?[A-Z]{1}\\d{4,10}|[A-Z]{3}\\d{4,10})(?!["\'\\]\\/\\!\\w])/'; $replacement[] = "<a href=\"http://{$_SERVER['HTTP_HOST']}/gridref/\\1\" target=\"_blank\">\\1</a>"; $pattern[] = '/\\[image id=(\\d+) text=([^\\]]+)\\]/e'; $replacement[] = "smarty_function_gridimage(array(id => '\$1',extra => '\$2'))"; $pattern[] = '/(\\!)([STNH]?[A-Z]{1}\\d{4,10}|[A-Z]{3}\\d{4,10})(?!["\'\\]\\/\\!\\w])/'; $replacement[] = "\\2"; $pattern[] = '/\\[img=([^\\] ]+)(| [^\\]]+)\\]/'; $replacement[] = '<img src="\\1" alt="\\2" title="\\2"/>'; $pattern[] = '/\\[mooflow=(\\d+)\\]/'; $replacement[] = '<iframe src="/search.php?i=\\1&temp_displayclass=mooflow_embed" width="750" height="430"></iframe>'; $pattern[] = '/\\n\\* ?([^\\n]+)(\\n{2})?/e'; $replacement[] = "'<ul style=\"margin-bottom:0px;margin-top:0px\"><li>'.stripslashes('\$1').'</li></ul>'.('\$2'?'\n':'')"; $pattern[] = '/<\\/ul>\\n?<ul style=\\"margin-bottom:0px;margin-top:0px\\">/'; $replacement[] = ''; //fix a bug where double spacing on a previous match would swallow the newline needed for the next $pattern[] = '/\\n\\n(<\\w{1,3}>)\\#/'; $replacement[] = "\n\$1#"; $pattern[] = '/\\n\\n\\#/'; $replacement[] = "\n\r\n\$1#"; $pattern[] = '/\\n(<\\w{1,3}>)?\\#([\\w]{1,2})? ([^\\n]+)(<\\/\\w{1,3}>)?(\\n{2})?/e'; $replacement[] = "'<ol style=\"margin-bottom:0px;'.('\$1'?'':'margin-top:0px').'\"'.('\$2'?' start=\"\$2\"':'').'><li>\$1\$3\$4</li></ol>'.('\$5'?'\n':'')"; $pattern[] = '/<\\/ol>\\n?<ol style=\\"margin-bottom:0px;margin-top:0px\\">/'; $replacement[] = ''; $pattern[] = "/\\[url[=]?\\](.+?)\\[\\/url\\]/i"; $replacement[] = '\\1'; $pattern[] = "/\\[url=((f|ht)tp[s]?:\\/\\/[^<> \n]+?)\\](.+?)\\[\\/url\\]/ie"; $replacement[] = "smarty_function_external(array('href'=>\"\$1\",'text'=>'\$3','title'=>\"\$1\"))"; $pattern[] = "/\n/"; $replacement[] = "<br/>\n"; $output = preg_replace($pattern, $replacement, $output); $output = GeographLinks($output, true); $pattern = array(); $replacement = array(); if (preg_match_all('/\\[(small|)map *([STNH]?[A-Z]{1}[ \\.]*\\d{2,5}[ \\.]*\\d{2,5}|[A-Z]{3}[ \\.]*\\d{2,5}[ \\.]*\\d{2,5})( \\w+|)\\]/', $output, $m)) { foreach ($m[0] as $i => $full) { //lets add an rastermap too $square = new Gridsquare(); $square->setByFullGridRef($m[2][$i], true); $square->grid_reference_full = $m[2][$i]; if (!empty($_GET['epoch'])) { $rastermap = new RasterMap($square, false, true, false, $_GET['epoch']); } elseif (!empty($m[3][$i])) { $rastermap = new RasterMap($square, false, true, false, trim($m[3][$i])); } else { $rastermap = new RasterMap($square, false); } if ($rastermap->service == 'OS50k') { if ($m[1][$i]) { $rastermap->service = 'OS50k-small'; $rastermap->width = 125; } $pattern[] = "/" . preg_quote($full, '/') . "/"; $replacement[] = $rastermap->getImageTag(); } } } $output = preg_replace($pattern, $replacement, $output); $output = str_replace('¬', '[', $output); if (count($m[0])) { $smarty->assign("copyright", '<div class="copyright">Great Britain 1:50 000 Scale Colour Raster Mapping Extracts © Crown copyright Ordnance Survey. All Rights Reserved. Educational licence 100045616.</div>'); } if (count($imageCredits)) { arsort($imageCredits); $imageCreditsStr = implode(', ', array_keys($imageCredits)); $imageCreditsStr = preg_replace('/, ([^,]+)$/', ' and $1', $imageCreditsStr); $smarty->assign("imageCredits", $imageCreditsStr); } return $output; }
echo $distance; exit; } die('unknown error'); } elseif (isset($_GET['map'])) { if (empty($ok) || !$ok) { die("Game Expired, please start again"); } if (!$game->l) { die("Game Expired, please start again"); } $square = new GridSquare(); $grid_ok = $square->setByFullGridRef($_GET['grid_reference'], true); if ($grid_ok && $square->grid_reference) { $rastermap = new RasterMap($square, false, $square->natspecified); print $rastermap->getImageTag(); print '<br/>Map for <b>' . htmlspecialchars($_GET['grid_reference']) . '</b>'; exit; } else { die('<span style="color:red">Please enter a Grid Reference</span>'); } } elseif (isset($_REQUEST['next']) || isset($_REQUEST['save'])) { if (empty($ok) || !$ok) { die("Game Expired, please start again"); } if (empty($_REQUEST['grid_reference'])) { } else { $square = new GridSquare(); $grid_ok = $square->setByFullGridRef($_REQUEST['grid_reference'], true); $match = $game->image->grid_reference == $square->grid_reference; if (!empty($_REQUEST['points']) && $match) {