function pollpage($url) { $XMLdata = getTidy($url); $obj = new OutlineFromXOXO($XMLdata, array('classes' => array('xoxo', 'posts'))); $struct = $obj->toArray(); if (!count($struct)) { $obj = new OutlineFromHATOM($XMLdata); $struct = $obj->toArray(); } if (!count($struct)) { $obj = new OutlineFromXOXO($XMLdata, array('classes' => array())); $struct = $obj->toArray(); } //header('Content-Type: text/plain'); //var_dump($struct);exit; foreach ($struct as $structid => $node) { if (!is_numeric($structid)) { continue; } $postTitle = $node['text']; $postURL = $node['href']; foreach ($node as $id => $comment) { if (!is_numeric($id)) { continue; } $comment = array_change_key_case($comment); $url = $comment['href']; if ($url[0] == '#') { $url = $postURL . $url; } $query = XN_Query::create('Content')->filter('owner', '=')->filter('type', 'eic', 'Comment')->filter('my.url', '=', $url); $items = $query->execute(); if (count($items) > 0) { continue; } if ($comment['author']) { $theParser = xml_parser_create(); xml_parse_into_struct($theParser, $comment['author'], $tmp); xml_parser_free($theParser); $authorname = $tmp[0]['value']; $authorurl = $tmp[0]['attributes']['HREF']; } else { $authorname = $comment['text#1']; $authorurl = $comment['href#1']; } //end if-else comment[author] $time = (int) ($comment['title'] / 1000000000) < 100 ? (int) $comment['title'] : (int) ($comment['title'] / 1000000000); $obj = XN_Content::create('Comment')->my->add('content', $comment['body'])->my->add('url', $url)->my->add('authorname', $authorname)->my->add('authorurl', $authorurl)->my->add('time', $time)->my->add('posturl', $postURL)->my->add('posturl2', str_replace('-', '', str_replace('/', ' ', $postURL)))->my->add('posttitle', $postTitle); $obj->saveAnonymous(); } //end foreach node } //end foreach struct }
require_once 'xn-app://xoxotools/OutlineClasses/OutlineFromHATOM.php'; header('Content-Type: text/javascript;charset=utf-8'); $pagedata = file_get_contents($_REQUEST['url']); preg_match('/<!-- START ARCHIVE XOXO -->[^\\f]*?<!-- END ARCHIVE XOXO -->/', $pagedata, $xoxodata); $xoxodata = $xoxodata[0]; $xoxodata = preg_replace('/<(img|meta|link|hr|br)([^<>]*?)([\\/]?)>/i', '<$1$2 />', $xoxodata); $xoxodata = preg_replace('/&([^;]{10})/i', '&$1', $xoxodata); $xoxo = new OutlineFromXOXO($xoxodata, array('classes' => array('xoxo', 'posts'))); if (!$xoxo->getNumNodes()) { $xoxo = new OutlineFromXOXO($pagedata, array('classes' => array('xoxo', 'posts'))); } if (!$xoxo->getNumNodes()) { $xoxo = new OutlineFromHATOM($pagedata); } if (!$xoxo->getNumNodes()) { $xoxo = new OutlineFromXOXO($pagedata, array('classes' => array())); } if (!$xoxo->getNumNodes()) { die('No valid XOXO data found!'); } $tmp = $xoxo->getNode(0); if ($tmp->getField('rel') == 'home') { $xoxo->unsetNode(0); } $xoxo->reindexNodes(); for ($i = 0; $i < $xoxo->getNumNodes(); $i++) { $node =& $xoxo->getNode($i); $node->unsetAllNodes(); } //end for xoxo if (!isset($_REQUEST['raw']) && !$_REQUEST['callback']) {
foreach ($obj->getNodes() as $node) { if ($node->getField('href')) { echo ' <li><a href="' . $node->getField('href') . '" title="' . $node->getField('title') . '">' . $node->getField('text') . '</a>' . ($node->getField('href#1') ? ' <a href="' . $node->getField('href#1') . '" rel="alternate">[feed]</a>' : '') . '</li>' . "\n"; } if ($node->getNumNodes()) { process_reading_list($node); } } //end foreach nodes } //end function $readinglistdata = file_get_contents('http://www.awriterz.org/etcetc/boxtheweb/exportboxes.php?user=hash%3Afc6e6f4412f270b70b869cf7757122d4&format=xoxo&feedsonly=on'); if (stristr('<opml', $readinglistdata)) { $obj = new OutlineFromOPML($readinglistdata); } else { $obj = new OutlineFromXOXO($readinglistdata); } $obj->toOPMLfields(); $obj->toXOXOfields(); echo '<h2>Reading List</h2>' . "\n"; echo '<ul>' . "\n"; process_reading_list($obj); echo '</ul>' . "\n"; //Blogger require_once 'getBloggerProfile.php'; $bloggerdata = getBloggerProfile('http://www.blogger.com/profile/10992009'); echo '<h2>Blogger</h2>'; echo '<h1>' . $bloggerdata['name'] . '</h1>' . "\n"; echo '<img style="float:right;" src="' . $bloggerdata['photo'] . '" alt="" />'; echo '<h3>About Me</h3>' . "\n"; echo $bloggerdata['aboutme'];
//if passed a URL, fetch the URL and make it's contents == data $_REQUEST['data'] = file_get_contents($_REQUEST['url']); } if ($_REQUEST['classes']) { $classes = explode(' ', $_REQUEST['classes']); } else { $classes = array(); } //if we were passed classes, explode via space into array, otherwise classes is an empty array switch (TRUE) { //determine input format case stristr($_REQUEST['data'], '<opml'): $struct = new OutlineFromOPML($_REQUEST['data']); break; case stristr($_REQUEST['data'], '<ul') || stristr($_REQUEST['data'], '<ol'): $struct = new OutlineFromXOXO($_REQUEST['data'], array('classes' => $classes)); $tmp = $struct->getNode(0); if (!$tmp->getField('href') && !$tmp->getField('contents') && count($tmp->getFields()) > 1) { $struct->fieldsFromFirstNode(); } break; case stristr($_REQUEST['data'], '<rss'): $struct = new OutlineFromXML($_REQUEST['data'], array('rootel' => 'rss', 'itemel' => 'channel>item', 'collapsels' => array('title', 'description'))); break; case stristr($_REQUEST['data'], '<rdf'): $struct = new OutlineFromXML($_REQUEST['data'], array('rootel' => 'rdf:RDF', 'itemel' => 'item', 'collapsels' => array('title', 'description'))); break; case stristr($_REQUEST['data'], '<feed'): $struct = new OutlineFromXML($_REQUEST['data'], array('rootel' => 'feed', 'itemel' => 'entry', 'collapsels' => array('title', 'content', 'summary'))); break; case !checkXML($_REQUEST['data']):
$archivelist = preg_replace('/&([^;]{10})/i', '&$1', $archivelist); $xoxo = new OutlineFromXOXO($archivelist, array('classes' => array())); for ($i = 0; $i < $xoxo->getNumNodes(); $i++) { $node =& $xoxo->getNode($i); $archivepage = file_get_contents($node->getField('href')); preg_match('/<!-- START ARCHIVE XOXO -->[^\\f]*?<!-- END ARCHIVE XOXO -->/', $archivepage, $xoxodata); $xoxodata = $xoxodata[0]; if ($xoxodata) { $archivepage = $xoxodata; } $archivestruct = new OutlineFromXOXO($archivepage, array('classes' => array('xoxo', 'posts'))); if (!$archivestruct->getNumNodes()) { $archivestruct = new OutlineFromHATOM($archivepage); } if (!$archivestruct->getNumNodes()) { $archivestruct = new OutlineFromXOXO($archivepage, array('classes' => array())); } $tmp = $archivestruct->getNode(0); if ($tmp && is_a($tmp, 'Outline') && $tmp->getField('rel') == 'home') { $archivestruct->unsetNode(0); } $node->setField('count', $archivestruct->getNumNodes()); } //end for getNumNodes if (!isset($_REQUEST['raw']) && !$_REQUEST['callback']) { echo 'if(typeof(BloggerArchive) != "object") BloggerArchive = {};' . "\n"; echo 'BloggerArchive.list = '; } //end if ! raw && ! callback if ($_REQUEST['callback']) { echo $_REQUEST['callback'] . '(';
<?php //need filter (if we ever do count) if (!$_REQUEST['mainpage']) { die('<h2>Please specify a main page!</h2>'); } require_once 'getTidy.php'; require_once 'xn-app://xoxotools/OutlineClasses/OutlineFromXOXO.php'; $page = getTidy(str_replace('Main_Page', 'Special:Categories?limit=9999', $_REQUEST['mainpage'])); $xoxo = new OutlineFromXOXO($page, array('classes' => array('special'))); header('Content-type: text/javascript;charset=utf-8'); if ($_REQUEST['callback']) { echo $_REQUEST['callback'] . '('; } echo '{'; //Count is zero because we don't know foreach ($xoxo->getNodes() as $id => $item) { if ($id != 0) { echo ', '; } echo '"' . addslashes(str_replace("\n", ' ', str_replace("\r", '', $item->getField('text')))) . '":0'; } //end foreach echo '}'; if ($_REQUEST['callback']) { echo ')'; }
//get data preg_match('/<!-- START ARCHIVE XOXO -->[^\\f]*?<!-- END ARCHIVE XOXO -->/', $pagedata, $xoxodata); $xoxodata = $xoxodata[0]; //fix basic XML problems (hardly necessary if comments were used) $xoxodata = preg_replace('/<(img|meta|link|hr|br)([^<>]*?)([\\/]?)>/i', '<$1$2 />', $xoxodata); $xoxodata = preg_replace('/&([^;]{10})/i', '&$1', $xoxodata); $xoxo = new OutlineFromXOXO($xoxodata, array('classes' => array('xoxo', 'posts'))); //pull in XOXO/hAtom if (!$xoxo->getNumNodes()) { $xoxo = new OutlineFromXOXO($pagedata, array('classes' => array('xoxo', 'posts'))); } if (!$xoxo->getNumNodes()) { $xoxo = new OutlineFromHATOM($pagedata); } if (!$xoxo->getNumNodes()) { $xoxo = new OutlineFromXOXO($pagedata, array('classes' => array())); } if (!$xoxo->getNumNodes()) { //error if no data die('No valid XOXO data found!'); } $tmp = $xoxo->getNode(0); //strip rel=home, not needed for this dataset if ($tmp->getField('rel') == 'home') { $xoxo->unsetNode(0); } $xoxo->reindexNodes(); $final = new Outline(); //the outline we're pushing to for ($i = 0; $i < $xoxo->getNumNodes(); $i++) { //loop through nodes and get data
//end if ! url require_once 'OutlineClasses/OutlineFromXOXO.php'; require_once 'OutlineClasses/OutlineFromHATOM.php'; require_once 'xn-app://singpolymaplay/getTidy.php'; $data = getTidy($_GET['url']); preg_match('/<body>[^\\f]*?<\\/body>/', $data, $body); if ($body[0]) { $data = $body[0]; } //$data = preg_replace('/<(img|meta|link|hr|br)([^<>]*?)([\/]?)>/i','<$1$2 />', $data); //$data = preg_replace('/&([^;]{10})/i','&$1', $data); //$data = str_replace('<HEAD>','<head>',$data); //$data = str_replace('</HEAD>','</head>',$data); $xoxo = new OutlineFromXOXO($data, array('classes' => array('xoxo', 'posts'))); $hatom = new OutlineFromHATOM($data, array('resolve' => $_GET['url'])); $raw = new OutlineFromXOXO($data, array('classes' => array())); $site = false; if ($xoxo->getNumNodes() && in_array('home', explode(' ', $xoxo->getNode(0)->getField('rel')))) { $site = $xoxo->getNode(0)->toArray(); $xoxo->unsetNode(0); $xoxo->reindexNodes(); } if ($hatom->getNumNodes() && in_array('home', explode(' ', $hatom->getNode(0)->getField('rel')))) { $site = $hatom->getNode(0)->toArray(); $hatom->unsetNode(0); $hatom->reindexNodes(); } if ($raw->getNumNodes() && in_array('home', explode(' ', $raw->getNode(0)->getField('rel')))) { $site = $raw->getNode(0)->toArray(); $raw->unsetNode(0); $raw->reindexNodes();
function hatom2array($data, $resolve) { $pageurl = $resolve; $tmp = explode('/', $resolve); if (strstr(array_pop($tmp), '.')) { $resolve = implode('/', $tmp); } if (substr($resolve, -1, 1) != '/') { $resolve .= '/'; } $theParser = xml_parser_create(); if (!xml_parse_into_struct($theParser, $data, $vals)) { $errorcode = xml_get_error_code($theParser); if ($errorcode != XML_ERROR_NONE && $errorcode != 27) { $this->_errorcode = $errorcode; } } //end if ! parse xml_parser_free($theParser); $rtrn = array(); $inhatom = true; $rootel = ''; $subroots = 0; $entryel = false; $subentry = 0; $flattento = false; $flattentag = ''; $subflatten = 0; $entry = array(); $tmptitle = ''; $toabbr = false; $enteringentry = false; foreach ($vals as $el) { if ($el['attributes']['HREF']) { $el['attributes']['HREF'] = trim($el['attributes']['HREF']); if ($el['attributes']['HREF'][0] == '/') { $el['attributes']['HREF'] = substr($el['attributes']['HREF'], 1, strlen($el['attributes']['HREF']) - 1); } if (substr($el['attributes']['HREF'], 0, 4) != 'http' && $resolve) { $el['attributes']['HREF'] = $resolve . $el['attributes']['HREF']; } } //end if href if ($el['tag'] == 'TITLE') { $this->setField('text', trim($el['value'])); $this->setField('rel', 'home'); } $isopen = $el['type'] == 'open' || $el['type'] == 'complete'; //for readability $isclose = $el['type'] == 'close' || $el['type'] == 'complete'; if (!$inhatom && in_array('hfeed', explode(' ', $el['attributes']['CLASS'])) && $isopen) { //are we starting an hatom section? $inhatom = true; $rootel = $el['tag']; } //end if !inhatom and class~=hfeed if ($inhatom) { //if processing an hatom section if ($el['attributes']['REL'] && in_array('tag', explode(' ', $el['attributes']['REL']))) { $atag = array_reverse(explode('/', $el['attributes']['HREF'])); $atag = explode('#', $atag[0]); $atag = explode('?', $atag[0]); $entry['tags'][] = $atag[0]; } //end if rel=tag if ($el['tag'] == $rootel && $isopen) { $subroots++; } if ($el['tag'] == $rootel && $isclose) { if ($subroots) { $subroots--; } else { $inhatom = false; } } //end if tag == rootel && type == close if (!$entryel && in_array('hentry', explode(' ', $el['attributes']['CLASS'])) && $isopen) { $entryel = $el['tag']; $entry = array(); $entry['class'] = 'entry-title'; $entry['rel'] = 'bookmark'; if ($el['attributes']['ID']) { $entry['id'] = $el['attributes']['ID']; } $tmptitle = ''; $subentry = 0; $enteringentry = true; } //end if !entryel and class~=hentry if ($entryel) { //if in an entry if ($flattento !== false) { //if flattening tags if ($isopen && $flattentag == $el['tag']) { $subflatten++; } if ($isclose && $flattentag == $el['tag']) { if ($subflatten > 0) { $subflatten--; } else { $flattentag = ''; $subflatten = 0; unset($flattento); $flattento = false; } //end if-else subflatten } //end if isclose && if ($flattento !== false) { //flattento may have changed in previous section $emptytag = false; //assume not an empty tag if ($isopen) { //if opening tag $flattento .= ' <' . strtolower($el['tag']); //add open tag if ($el['attributes']) { //if attributes foreach ($el['attributes'] as $id => $val) { //loop through and add $flattento .= ' ' . strtolower($id) . '="' . htmlspecialchars($val) . '"'; } //end foreach } //end if attributes $emptytag = $el['type'] == 'complete' && !$el['value']; //is emptytag? $flattento .= $emptytag ? ' />' : '>'; //end tag if ($el['value']) { $flattento .= htmlspecialchars($el['value']); } //add contents, if any } //end if isopen if ($el['type'] == 'cdata') { //if cdata $flattento .= htmlspecialchars($el['value']); //add data } //end if cdata if ($isclose) { //if closing tag if (!$emptytag) { $flattento .= '</' . strtolower($el['tag']) . '>'; } //if not emptytag, write out end tag } //end if isclose } //end if flattento } //end if flattento //THIS ABBR SECTION MAY BE OBSOLETE if ($toabbr !== false && $el['tag'] == 'ABBR') { $toabbr = strtotime(trim($el['attributes']['TITLE'])); unset($toabbr); $toabbr = false; } //end if toabbr //close entry? if (!$enteringentry && $el['tag'] == $entryel && $isopen) { $subentry++; } if ($el['tag'] == $entryel && $isclose) { if ($subentry) { $subentry--; } else { if (stristr($entry['text#1'], '<')) { //process author $theParser = xml_parser_create(); xml_parse_into_struct($theParser, '<cnt>' . $entry['text#1'] . '</cnt>', $tmp); xml_parser_free($theParser); foreach ($tmp as $tmpel) { if (in_array('fn', explode(' ', $tmpel['attributes']['CLASS']))) { $entry['text#1'] = trim($tmpel['value']); } if (in_array('url', explode(' ', $tmpel['attributes']['CLASS']))) { $entry['href#1'] = $tmpel['attributes']['HREF'] ? trim($tmpel['attributes']['HREF']) : trim($tmpel['value']); } } //end foreach } //end if (process author) if ($entry['comments']) { //process comments $tmp = new OutlineFromXOXO('<ul class="xoxo comments">' . $entry['comments'] . '</ul>', array('xoxo', 'comments')); $entry = array_merge($entry, $tmp->toArray()); unset($entry['comments']); } //end if comments $entry['title'] = $entry['title'] ? $entry['title'] : $entry['updated']; $entry['updated'] = $entry['updated'] ? $entry['updated'] : $entry['title']; $entry['text'] = $entry['text'] ? strip_tags($entry['text']) : $tmptitle; if (!$entry['href'] && $entry['id']) { $entry['href'] = $pageurl . '#' . $entry['id']; } $rtrn[] = $entry; unset($entry); $entryel = false; $flattentag = ''; $subflatten = 0; unset($flattento); unset($toabbr); $flattento = false; $toabbr = false; $subentry = 0; continue; } //end if subentry } //end if tag == rootel && type == close //get title if (!$entry['text'] && in_array('entry-title', explode(' ', $el['attributes']['CLASS'])) && $isopen) { if ($el['tag'] == 'ABBR') { $entry['text'] = trim($el['attributes']['TITLE']); } else { $entry['text'] .= $el['value']; if (!$isclose) { //if there are tags in this tag $flattento =& $entry['text']; $flattentag = $el['tag']; } //end if ! isclose } //end if-else ABBR } //end if entry-title isopen if (!$entry['text'] && strlen($el['tag']) == 2 && $el['tag'][0] == 'h' && is_numeric($el['tag'][1]) && $isopen) { //if starting h# tag $tmptitle .= trim($el['value']); } //end if h# //get content if (in_array('entry-content', explode(' ', $el['attributes']['CLASS'])) && $isopen) { $entry['body'] .= $el['value']; if (!$isclose) { //if there are tags in this tag $flattento =& $entry['body']; $flattentag = $el['tag']; } //end if ! isclose } //end if content //get summary if (in_array('entry-summary', explode(' ', $el['attributes']['CLASS'])) && $isopen) { $entry['summary'] .= $el['value']; if (!$isclose) { //if there are tags in this tag $flattento =& $entry['summary']; $flattentag = $el['tag']; } //end if ! isclose } //end if excerpt isopen //get permalink if (!$entry['href'] && in_array('bookmark', explode(' ', $el['attributes']['REL'])) && $isopen) { $entry['href'] = $el['attributes']['HREF']; } //end if bookmark isopen //get timestamp if (!$entry['title'] && in_array('published', explode(' ', $el['attributes']['CLASS'])) && $isopen) { if (trim($el['value']) && strtotime(trim($el['value'])) > 0) { $entry['title'] = strtotime(trim($el['value'])); } if (trim($el['attributes']['TITLE']) && strtotime(trim($el['attributes']['TITLE'])) > 0) { $entry['title'] = strtotime(trim($el['attributes']['TITLE'])); } } //end if published isopen //get updated if (!$entry['updated'] && in_array('updated', explode(' ', $el['attributes']['CLASS'])) && $isopen) { if (trim($el['value']) && strtotime(trim($el['value'])) > 0) { $entry['updated'] = strtotime(trim($el['value'])); } if (trim($el['attributes']['TITLE']) && strtotime(trim($el['attributes']['TITLE'])) > 0) { $entry['updated'] = strtotime(trim($el['attributes']['TITLE'])); } } //end if updated isopen //get author if (!$entry['text#1'] && (in_array('author', explode(' ', $el['attributes']['CLASS'])) || $el['tag'] == 'ADDRESS') && $isopen) { $entry['rel#1'] = 'author'; if (trim($el['value'])) { $entry['text#1'] = trim($el['value']); if ($el['attributes']['HREF']) { $entry['href#1'] = trim($el['attributes']['HREF']); } } //end if if (in_array('fn', explode(' ', $el['attributes']['CLASS']))) { $entry['text#1'] = trim(strip_tags($el['value'])); } if (in_array('url', explode(' ', $el['attributes']['CLASS']))) { $entry['href#1'] = $el['attributes']['HREF'] ? trim($el['attributes']['HREF']) : trim($el['value']); } if (!$isclose) { //if there are tags in this tag $flattento =& $entry['text#1']; $flattentag = $el['tag']; } //end if ! isclose } //end if author isopen //get comments URL and count if (!$entry['text#2'] && in_array('comments', explode(' ', $el['attributes']['REL'])) && !in_array('alternate', explode(' ', $el['attributes']['REL'])) && $isopen) { $entry['rel#2'] = 'comments'; $entry['text#2'] = trim($el['value']); $entry['href#2'] = trim($el['attributes']['HREF']); } //end if comments isopen //get comments feed URL if (!$entry['href#3'] && in_array('comments', explode(' ', $el['attributes']['REL'])) && in_array('alternate', explode(' ', $el['attributes']['REL'])) && $isopen) { $entry['rel#3'] = 'comments alternate'; $entry['text#3'] = trim($el['value']); $entry['href#3'] = trim($el['attributes']['HREF']); } //end if comments && alternate isopen //get comments if (in_array('xoxo', explode(' ', $el['attributes']['CLASS'])) && in_array('comments', explode(' ', $el['attributes']['CLASS'])) && $isopen) { $entry['comments'] = ''; if (!$isclose) { //if there are tags in this tag $flattento =& $entry['comments']; $flattentag = $el['tag']; } //end if ! isclose } //end if content isopen $enteringentry = false; } //end if entryel } //end if $inhatom } //end foreach return $rtrn; }
} elseif ($_GET['data']) { $data = $_GET['data']; } else { ?> <form method="get" action="<?php echo $_SERVER['PHP_SELF']; ?> "><div> Enter a<br /> URL: <input type="text" name="url" /><br /> or<br /> Data: <textarea name="data"></textarea><br /> <input type="submit" name="submit" value="Validate!" /> </div></form> <?php exit; } //end if-elseif-else $struct = new OutlineFromXOXO($data); if ($struct->getError()) { echo '<h2 style="text-align:center;"><a href="http://www.hcrc.ed.ac.uk/~richard/xml-check.cgi?url=' . urlencode($_GET['url']) . '">Not Valid XML!</a> -- ' . xml_error_string($struct->getError()) . ' -- Error #' . $struct->getError() . '</h2>'; $data = getTidy($_GET['url']); $struct = new OutlineFromXOXO($data); } //end if error if ($struct->getNumNodes() || count($struct->getFields())) { echo '<h2 style="text-align:center;">Valid <a href="http://microformats.org/wiki/xoxo">XOXO</a> data found!</h2>'; } else { echo '<h2 style="text-align:center;">No valid <a href="http://microformats.org/wiki/xoxo">XOXO</a> data found</h2>'; } //end if count || count