Пример #1
0
/**
 * Parses a sitemap entry
 * @param  XTemplate $t      CoTemplate object
 * @param  int       &$items Total items count
 * @param  array     $item   Item to be rendered
 */
function sitemap_parse($t, &$items, $item)
{
    global $cfg;
    $perpage = (int) $cfg['plugin']['sitemap']['perpage'];
    if ($items > 0 && $items % $perpage == 0) {
        // Save previous page
        $d = $items / $perpage - 1;
        $t->parse();
        sitemap_save($t->text(), $d);
        // Start another
        $t->reset();
    }
    // Parse another row
    $t->assign(array('SITEMAP_ROW_URL' => strpos($item['url'], '://') === false ? COT_ABSOLUTE_URL . $item['url'] : $item['url'], 'SITEMAP_ROW_DATE' => sitemap_date($item['date']), 'SITEMAP_ROW_FREQ' => sitemap_freq($item['freq']), 'SITEMAP_ROW_PRIO' => sitemap_prio($item['prio'])));
    $t->parse('MAIN.SITEMAP_ROW');
    $items++;
}
Пример #2
0
            sitemap_parse($t, $items, array('url' => cot_url('users', array('m' => 'details', 'id' => $row['user_id'], 'u' => $row['user_name'])), 'date' => '', 'freq' => $cfg['plugin']['sitemap']['users_freq'], 'prio' => $cfg['plugin']['sitemap']['users_prio']));
        }
    }
    /* === Hook === */
    foreach (cot_getextplugins('sitemap.main') as $pl) {
        include $pl;
    }
    /* ===== */
    // Save the last page
    $t->parse();
    sitemap_save($t->text(), (int) ceil($items / $perpage) - 1);
    // Save count file
    file_put_contents($count_file, $items);
}
if ($a == 'index') {
    // Show sitemap index
    $t = new XTemplate(cot_tplfile('sitemap.index', 'plug'));
    $pages = (int) ceil($items / $perpage);
    foreach (range(0, $pages - 1) as $pg) {
        $durl = $pg > 0 ? "&d={$pg}" : '';
        $filename = $pg > 0 ? $cfg['cache_dir'] . "/sitemap/sitemap.{$pg}.xml" : $cfg['cache_dir'] . "/sitemap/sitemap.xml";
        $t->assign(array('SITEMAP_ROW_URL' => COT_ABSOLUTE_URL . cot_url('plug', 'r=sitemap' . $durl), 'SITEMAP_ROW_DATE' => sitemap_date(filemtime($filename))));
        $t->parse('MAIN.SITEMAP_ROW');
    }
    $t->parse();
    echo sitemap_compress($t->text());
} else {
    // Show requested sitemap
    sitemap_load($items, $d);
}
exit;
Пример #3
0
$_SERVER['backend_start'] = microtime(true);
include __DIR__ . '/backend/include/all.php';
autoload([__DIR__ . '/classes', __DIR__ . '/controllers']);
$config = json_config(__DIR__ . '/config/application.json');
$bootstrap = new Bootstrap($config);
function sitemap_date($t)
{
    return date('c', $t);
}
$url = 'http://' . $_SERVER['HTTP_HOST'] . '/';
$sitemap = [];
$sitemap[] = ['loc' => $url, 'priority' => 1, 'lastmod' => sitemap_date(strtotime(date('Y-m-d')))];
$map = json_decode(file_get_contents(Tools::saveRoot('map.json')), true);
foreach ($map as $from => $reg) {
    foreach (array_keys($reg) as $r) {
        $sitemap[] = ['loc' => $url . $r . '/' . $from, 'priority' => 0.9, 'lastmod' => sitemap_date(strtotime(date('Y-m-d')))];
    }
}
if (isset($_SERVER['HTTP_USER_AGENT']) && isset($_SERVER['REQUEST_URI'])) {
    Tools::log('bots', ['agent' => $_SERVER['HTTP_USER_AGENT'], 'uri' => $_SERVER['REQUEST_URI']]);
}
header('Content-type: application/xml; charset=utf-8');
?>
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9" xmlns:image="http://www.google.com/schemas/sitemap-image/1.1" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.sitemaps.org/schemas/sitemap/0.9 http://www.sitemaps.org/schemas/sitemap/0.9/sitemap.xsd">  
<?php 
foreach ($sitemap as $url) {
    ?>
  <url>
    <loc><?php 
    echo $url['loc'];
    ?>
Пример #4
0
$hosts = [];
foreach ($events as $e) {
    $date = $e['d_change'] ?: strtotime(date('Y-m-d'));
    $reviews = $rate->event_reviews($e['event_id'], true, 1) ?: [];
    if (isset($reviews[0]) && $reviews[0]['d_create'] > $date) {
        $date = $reviews[0]['d_create'];
    }
    $sitemap[] = ['loc' => $url . $e['host_url'] . '/' . $e['event_url'], 'priority' => 0.8, 'lastmod' => sitemap_date($date)];
    if (isset($hosts[$e['host_url']])) {
        $hosts[$e['host_url']] = max($hosts[$e['host_url']], $date);
    } else {
        $hosts[$e['host_url']] = $date;
    }
}
foreach ($hosts as $host => $date) {
    $sitemap[] = ['loc' => $url . $host, 'priority' => 0.7, 'lastmod' => sitemap_date($date)];
}
if (isset($_SERVER['HTTP_USER_AGENT']) && isset($_SERVER['REQUEST_URI'])) {
    Tools::log('bots', ['agent' => $_SERVER['HTTP_USER_AGENT'], 'uri' => $_SERVER['REQUEST_URI']]);
}
header('Content-type: application/xml; charset=utf-8');
?>
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9" xmlns:image="http://www.google.com/schemas/sitemap-image/1.1" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.sitemaps.org/schemas/sitemap/0.9 http://www.sitemaps.org/schemas/sitemap/0.9/sitemap.xsd">  
<?php 
foreach ($sitemap as $url) {
    ?>
  <url>
    <loc><?php 
    echo $url['loc'];
    ?>
</loc>