本文整理汇总了PHP中F3::mock方法的典型用法代码示例。如果您正苦于以下问题:PHP F3::mock方法的具体用法?PHP F3::mock怎么用?PHP F3::mock使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类F3
的用法示例。
在下文中一共展示了F3::mock方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: sitemap
/**
Parse each URL recursively and generate sitemap
@param $_url string
@public
**/
public static function sitemap($_url = '/')
{
$_map =& F3::$global['SITEMAP'];
if (array_key_exists($_url, $_map) && $_map[$_url]['status'] !== NULL) {
// Already crawled
return;
}
preg_match('/^http[s]*:\\/\\/([^\\/$]+)/', $_url, $_host);
if (!empty($_host) && $_host[1] != $_SERVER['SERVER_NAME']) {
// Remote URL
$_map[$_url]['status'] = FALSE;
return;
}
F3::$global['QUIET'] = TRUE;
F3::mock('GET ' . $_url);
F3::run();
// Check if an error occurred or no HTTP response
if (F3::$global['ERROR'] || !F3::$global['RESPONSE']) {
$_map[$_url]['status'] = FALSE;
// Reset error flag for next page
unset(F3::$global['ERROR']);
return;
}
$_doc = new XMLTree('1.0', F3::$global['ENCODING']);
if ($_doc->loadHTML(F3::$global['RESPONSE'])) {
// Valid HTML; add to sitemap
if (!$_map[$_url]['level']) {
// Web root
$_map[$_url]['level'] = 0;
}
$_map[$_url]['status'] = TRUE;
$_map[$_url]['mod'] = time();
$_map[$_url]['freq'] = 0;
// Cached page
$_hash = 'url.' . F3::hashCode('GET ' . $_url);
$_cached = Cache::cached($_hash);
if ($_cached) {
$_map[$_url]['mod'] = $_cached['time'];
$_map[$_url]['freq'] = $_SERVER['REQUEST_TTL'];
}
// Parse all links
$_links = $_doc->getElementsByTagName('a');
foreach ($_links as $_link) {
$_ref = $_link->getAttribute('href');
$_rel = $_link->getAttribute('rel');
if (!$_ref || $_rel && preg_match('/nofollow/', $_rel)) {
// Don't crawl this link!
continue;
}
if (!array_key_exists($_ref, $_map)) {
$_map[$_ref] = array('level' => $_map[$_url]['level'] + 1, 'status' => NULL);
}
}
// Parse each link
array_walk(array_keys($_map), 'self::sitemap');
}
unset($_doc);
if (!$_map[$_url]['level']) {
// Finalize sitemap
$_depth = 1;
while ($_ref = current($_map)) {
// Find depest level while iterating
if (!$_ref['status']) {
// Remove remote URLs and pages with errors
unset($_map[key($_map)]);
} else {
$_depth = max($_depth, $_ref['level'] + 1);
next($_map);
}
}
// Create XML document
$_xml = simplexml_load_string('<?xml version="1.0" encoding="' . F3::$global['ENCODING'] . '"?>' . '<urlset xmlns="' . 'http://www.sitemaps.org/schemas/sitemap/0.9' . '"/>');
$_host = 'http://' . $_SERVER['SERVER_NAME'];
foreach ($_map as $_key => $_ref) {
// Add new URL
$_item = $_xml->addChild('url');
// Add URL elements
$_item->addChild('loc', $_host . $_key);
$_item->addChild('lastMod', date('c', $_ref['mod']));
$_item->addChild('changefreq', self::frequency($_ref['freq']));
$_item->addChild('priority', sprintf('%1.1f', 1 - $_ref['level'] / $_depth));
}
// Send output
F3::$global['QUIET'] = FALSE;
if (PHP_SAPI != 'cli' && !headers_sent()) {
header(F3::HTTP_Content . ': application/xhtml+xml; ' . 'charset=' . F3::$global['ENCODING']);
}
$_xml = dom_import_simplexml($_xml)->ownerDocument;
$_xml->formatOutput = TRUE;
echo $_xml->saveXML();
}
}