Peninsula Papers

Peninsula Papers is the local “parish magazine” containing news and information for the communities of Dale, St Ishmaels, Hasguard, Herbrandston, Robeston West, Marloes and St Brides. The links below are for PDF versions of the magazine (hosted on the Marloes village web site).

 

[insert_php]

define(‘URL_MARLOES’,’http://www.marloes.org.uk/’);
define(‘URL_PENINSUAL_PAPERS’, ‘http://www.marloes.org.uk/page7.html’);

$links = getLinks(URL_PENINSUAL_PAPERS);
if (count($links)>0) {
foreach($links as $link) {
//print_r($link);
$target = $link[‘url’];
$title = $link[‘text’];
$path_parts = pathinfo($target);
if(isset($path_parts[‘extension’])) {
$extension = strtoupper($path_parts[‘extension’]);
} else {
$extension = ”;
}
if($extension == ‘PDF’) {
$pdflink = URL_MARLOES . $target;
$pdftitle = ucwords(strtolower(str_replace(‘/’,’ / ‘,$title)));
echo “” . $pdftitle . “” . ‘
‘;
}
}
}

function getLinks($pageUrl) {
// $html = file_get_contents($pageUrl);
$html = get_content($pageUrl);
$doc = new DOMDocument();
@$doc->loadHTML($html);
$tags = $doc->getElementsByTagName(‘a’);
// Find all links to PDF files
foreach ($tags as $link) {
$url = trim($link->getAttribute(‘href’));
$text = trim($link->nodeValue);
$links[] = array(‘url’ => $url, ‘text’ => $text);
//echo $link->getAttribute(‘href’) . ‘ :: ‘ . $link->nodeValue . “\n”;
}
return($links);
}

// Function from Stackoverflow article (avoids issues with file_get_contents())
// http://stackoverflow.com/questions/3488425/php-ini-file-get-contents-external-url
function get_content($URL){
$ch = curl_init();
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_URL, $URL);
$data = curl_exec($ch);
curl_close($ch);
return $data;
}

[/insert_php]