<?php
#header("Redirect: /blog/");
print '<head>';
#print '<meta name="ppe-verify" content="ppe-bfeb7488ead6ddbeb07f">';
#print '<a rel="me" href="https://infosec.exchange/@pg">Mastodon</a>';
print '<meta http-equiv="REFRESH" content="0;url=/blog/"></head><body> Redirecting to /blog/ </body>';
exit();

include './inc/config.php';
$_PG_TITLE = 'Paul Gregg';
include './inc/head.php';
include './inc/menu.php';


$_PG_articles = array();

/*
$_PG_featured = array();
$_PG_feature = array(
  'title'   => 'VMclone',
  'link'    => '/projects/vmclone/',
  'summary' => 'Want to clone a VMware ESX VM but you don\'t have VirtualCenter?',
);
array_push($_PG_featured, $_PG_feature);

$_PG_feature = array(
  'title'   => 'Email mailto and URL encoder',
  'link'    => '/projects/encode/htmlemail.php',
  'summary' => 'Protect your email address on a webpage without exposing it to spam harvesters.',
);
array_push($_PG_featured, $_PG_feature);

$_PG_feature = array(
  'title'   => 'PHP preg_find()',
  'link'    => '/forums/viewtopic.php?tid=73',
  'summary' => 'Ever found glob() just too limiting or want a really powerful, recursive, directory lister for PHP? preg_find() is the solution.',
);
array_push($_PG_featured, $_PG_feature);
*/



include '/web/common/magpierss/rss_fetch.inc';
define('MAGPIE_CACHE_DIR', '/web/common/cache');
define('MAGPIE_CACHE_AGE', 120);

require '/web/common/simplepie/current/autoloader.php';
$feed = new SimplePie();
$rss = 'http://pgregg.com/blog/feed/';
$feed->set_feed_url($rss);
$feed->set_cache_location('/web/common/cache');
$feed->init();
$feed->handle_content_type();


#$rss = fetch_rss('http://www.pgregg.com/forums/externnews.php?fid=1&action=new&type=rss');
if (isset($_GET['new'])) {

require '/web/common/simplepie/current/autoloader.php';
$feed = new SimplePie();
$rss = 'http://pgregg.com/blog/feed/';
$feed->set_feed_url($rss);
$feed->set_cache_location('/web/common/cache');
$feed->init();
$feed->handle_content_type();

} else {
	$rss = fetch_rss('http://pgregg.com/blog/atom.xml');
}
#$rss = fetch_rss('http://pgregg.com/blog/feed/');
$discussions_seen = array();
$article_count = 0;
#echo '<pre>';
#var_export($rss->items);
#echo '</pre>';
$_GET['new']=1;
if (isset($_GET['new'])) {
	foreach ($feed->get_items() as $idx => $item) {
		$args = array(
			'divid' => ($article_count==0 ? 'main_story' : 'sub_story'),
			'name' => ($article_count==0 ? 'main_story' : 'sub_story'),
			'h' => ($article_count==0 ? 'h2' : 'h3'),
			#'date' => $item->get_date('j F Y | g:i a'),
			'date' => strtotime($item->get_date('c')),
			'link' => $item->get_permalink(),
			'title' => '<a href="' . $item->get_permalink() . '">' . $item->get_title() .'</a>',
			'caption' => $item->get_author(0)->get_name() . ' at ' . $item->get_date('H:i a'),
			'summary' => $item->get_content(),
		);
  		array_push($_PG_articles, $args);
		#print '<pre>'; print_r($_PG_articles); print '</pre>';
  		$article_count++;
  		if ($article_count == 4) {
    			break;
  		}

	}
} else {
	foreach ($rss->items as $idx => $item) {
		#	print '<pre>'; var_dump($item); print '</pre>';
  		#if ($discussions_displayed == $DISPCOUNT_FORUMS) break;
  		#$tmp_date = strtotime($item['dc']['date']);
  		$tmp_date = strtotime($item['published']);
  		#$item['summary'] = str_replace('img/smilies', 'forums/img/smilies', $item['summary']);
  		$args = array(
    			#'divid' => ($article_count==0 ? 'main_story' : ($article_count&1==1 ? 'left_story' : 'right_story')),
    			'divid' => ($article_count==0 ? 'main_story' : 'sub_story'),
    			'name' => ($article_count==0 ? 'main_story' : 'sub_story'),
    			'h' => ($article_count==0 ? 'h2' : 'h3'),
    			'date' => $tmp_date,
    			'link' => $item['link'],
    			'title' => '<a href="' . $item['link'] . '">' . $item['title'] .'</a>',
    			'caption' => $item['author_name'] . ' at ' . date('H:i a', $tmp_date),
    			'summary' => $item['atom_content'],
  		);
  		array_push($_PG_articles, $args);
  		$article_count++;
  		if ($article_count == 4) {
    			break;
  		}
	}
}
#unset($discussions_seen, $discussions_displayed, $rss, $idx, $item, $tmp_title, $tmp_link);


$twitter_rss = fetch_rss('http://twitter.com/statuses/user_timeline/26985337.rss');
foreach ($twitter_rss->items as $idx => $item) {
  if (preg_match_all("/(https?:\/\/[\S]+)/", $item['title'], $matches)) {
	array_shift($matches);
#$item['title'] = "#" . $item['title'] . print_r($matches, 1);

	foreach ($matches as $match) {
		$item['title'] = str_replace($match[0],
			"<a href='$match[0]'>$match[0]</a>",
			$item['title']);
	}
  }
  $_PG_feature = array(
    'title'   => 'twitter.com/pgregg',
    'link'    => 'http://twitter.com/pgregg',
    'summary' => $item['title'],
  );
  array_push($_PG_featured, $_PG_feature);
  break;
}



/*
$article = array(
  'date' => time(),
  'divid' => '',
  'h' => 'h2',
  'title' => 'pg test',
  'caption' => 'by pgregg at 12:13:14',
  'summary' => 'summary',
  'link' => '#',
);
array_push($_PG_articles, $article);



$article = array(
  'date' => time()-726347,
  'divid' => 'right_story',
  'h' => 'h3',
  'title' => 'this is the right story',
  'caption' => 'by pgregg at '.date('h:i:s', time()-726347),
  'summary' => 'summary',
  'link' => '#',
);
array_push($_PG_articles, $article);

$article = array(
  'date' => time()-626347,
  'divid' => 'left_story',
  'h' => 'h3',
  'title' => 'this is the left story',
  'caption' => 'by pgregg at '.date('h:i:s', time()-626347),
  'summary' => 'summary',
  'link' => '#',
);
array_push($_PG_articles, $article);
*/
  
include './inc/content.php';


include './inc/foot.php';
