Пример #1
0
 /**
  * Builds a Google Sitemap of all public pages known to the indexer
  *
  * The map is placed in the cache directory named sitemap.xml.gz - This
  * file needs to be writable!
  *
  * @author Michael Hamann
  * @author Andreas Gohr
  * @link   https://www.google.com/webmasters/sitemaps/docs/en/about.html
  * @link   http://www.sitemaps.org/
  */
 public function generate()
 {
     global $conf;
     if ($conf['sitemap'] < 1 || !is_numeric($conf['sitemap'])) {
         return false;
     }
     $sitemap = Sitemapper::getFilePath();
     if (@file_exists($sitemap)) {
         if (!is_writable($sitemap)) {
             return false;
         }
     } else {
         if (!is_writable(dirname($sitemap))) {
             return false;
         }
     }
     if (@filesize($sitemap) && @filemtime($sitemap) > time() - $conf['sitemap'] * 86400) {
         // 60*60*24=86400
         dbglog('Sitemapper::generate(): Sitemap up to date');
         // FIXME: only in debug mode
         return false;
     }
     dbglog("Sitemapper::generate(): using {$sitemap}");
     // FIXME: Only in debug mode
     $pages = idx_getIndex('page', '');
     dbglog('Sitemapper::generate(): creating sitemap using ' . count($pages) . ' pages');
     $items = array();
     // build the sitemap items
     foreach ($pages as $id) {
         //skip hidden, non existing and restricted files
         if (isHiddenPage($id)) {
             continue;
         }
         if (auth_aclcheck($id, '', '') < AUTH_READ) {
             continue;
         }
         $item = SitemapItem::createFromID($id);
         if ($item !== NULL) {
             $items[] = $item;
         }
     }
     $eventData = array('items' => &$items, 'sitemap' => &$sitemap);
     $event = new Doku_Event('SITEMAP_GENERATE', $eventData);
     if ($event->advise_before(true)) {
         //save the new sitemap
         $result = io_saveFile($sitemap, Sitemapper::getXML($items));
     }
     $event->advise_after();
     return $result;
 }
Пример #2
0
/**
 * Builds a Google Sitemap of all public pages known to the indexer
 *
 * The map is placed in the root directory named sitemap.xml.gz - This
 * file needs to be writable!
 *
 * @author Andreas Gohr
 * @link   https://www.google.com/webmasters/sitemaps/docs/en/about.html
 */
function runSitemapper()
{
    print "runSitemapper(): started" . NL;
    $result = Sitemapper::generate() && Sitemapper::pingSearchEngines();
    print 'runSitemapper(): finished' . NL;
    return $result;
}
Пример #3
0
/**
 * Handle sitemap delivery
 *
 * @author Michael Hamann <*****@*****.**>
 */
function act_sitemap($act)
{
    global $conf;
    if ($conf['sitemap'] < 1 || !is_numeric($conf['sitemap'])) {
        header("HTTP/1.0 404 Not Found");
        print "Sitemap generation is disabled.";
        exit;
    }
    $sitemap = Sitemapper::getFilePath();
    if (strrchr($sitemap, '.') === '.gz') {
        $mime = 'application/x-gzip';
    } else {
        $mime = 'application/xml; charset=utf-8';
    }
    // Check if sitemap file exists, otherwise create it
    if (!is_readable($sitemap)) {
        Sitemapper::generate();
    }
    if (is_readable($sitemap)) {
        // Send headers
        header('Content-Type: ' . $mime);
        header('Content-Disposition: attachment; filename=' . basename($sitemap));
        http_conditionalRequest(filemtime($sitemap));
        // Send file
        //use x-sendfile header to pass the delivery to compatible webservers
        if (http_sendfile($sitemap)) {
            exit;
        }
        readfile($sitemap);
        exit;
    }
    header("HTTP/1.0 500 Internal Server Error");
    print "Could not read the sitemap file - bad permissions?";
    exit;
}
Пример #4
0
/**
 * Handle sitemap delivery
 *
 * @author Michael Hamann <*****@*****.**>
 *
 * @param string $act action command
 */
function act_sitemap($act)
{
    global $conf;
    if ($conf['sitemap'] < 1 || !is_numeric($conf['sitemap'])) {
        http_status(404);
        print "Sitemap generation is disabled.";
        exit;
    }
    $sitemap = Sitemapper::getFilePath();
    if (Sitemapper::sitemapIsCompressed()) {
        $mime = 'application/x-gzip';
    } else {
        $mime = 'application/xml; charset=utf-8';
    }
    // Check if sitemap file exists, otherwise create it
    if (!is_readable($sitemap)) {
        Sitemapper::generate();
    }
    if (is_readable($sitemap)) {
        // Send headers
        header('Content-Type: ' . $mime);
        header('Content-Disposition: attachment; filename=' . utf8_basename($sitemap));
        http_conditionalRequest(filemtime($sitemap));
        // Send file
        //use x-sendfile header to pass the delivery to compatible webservers
        http_sendfile($sitemap);
        readfile($sitemap);
        exit;
    }
    http_status(500);
    print "Could not read the sitemap file - bad permissions?";
    exit;
}