Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- # ***** BEGIN LICENSE BLOCK *****
- # This file is part of Gsitemap, a plugin for DotClear.
- # Copyright (c) 2005 Pep and contributors. All rights
- # reserved.
- #
- # DotClear.
- # Copyright (c) 2004 Olivier Meunier and contributors. All rights
- # reserved.
- #
- # DotClear is free software; you can redistribute it and/or modify
- # it under the terms of the GNU General Public License as published by
- # the Free Software Foundation; either version 2 of the License, or
- # (at your option) any later version.
- #
- # DotClear is distributed in the hope that it will be useful,
- # but WITHOUT ANY WARRANTY; without even the implied warranty of
- # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- # GNU General Public License for more details.
- #
- # You should have received a copy of the GNU General Public License
- # along with DotClear; if not, write to the Free Software
- # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
- #
- # ***** END LICENSE BLOCK *****
- class gsitemap {
- var $blog;
- var $urls;
- var $freqs;
- var $opts;
- function gsitemap(&$blog, $config)
- {
- $this->blog =& $blog;
- $this->urls = array();
- $this->freqs = array('','always','hourly','daily','weekly','monthly','never');
- $this->opts = $config;
- }
- function getURLs()
- {
- if (!empty($this->opts['dc_gsitemap_active']) && empty($this->urls)) {
- $this->collectURLs();
- }
- return $this->urls;
- }
- function googleSitemap()
- {
- $urls = $this->getURLs();
- if (!empty($urls)) {
- $content = '';
- foreach ($urls as $url) {
- $content .= "<url>\n";
- $content .= '<loc>'.$url['loc']."</loc>\n";
- if (!empty($url['priority'])) {
- $content .= '<priority>'.$url['priority']."</priority>\n";
- }
- if (!empty($url['frequency'])) {
- $content .= '<changefreq>'.$url['frequency']."</changefreq>\n";
- }
- if (!empty($url['lastmod'])) {
- $content .= '<lastmod>'.$url['lastmod']."</lastmod>\n";
- }
- $content .= "</url>\n";
- }
- header('Content-Type: text/xml; charset=UTF-8');
- echo
- '<?xml version="1.0" encoding="UTF-8"?>'."\n".
- '<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">'."\n".
- $content.
- '</urlset>';
- }
- $this->blog->con->close();
- exit;
- }
- function yahooUrllist()
- {
- $urls = $this->getURLs();
- if (!empty($urls)) {
- $content = '';
- foreach ($urls as $url) {
- $content .= $url['loc']."\n";
- }
- header('Content-Type: text/plain; charset=UTF-8');
- echo $content;
- }
- $this->blog->con->close();
- exit;
- }
- function addEntry($loc,$priority,$frequency,$lastmod = '')
- {
- $this->urls[] = array(
- 'loc' => $loc,
- 'priority' => $priority,
- 'frequency' => $frequency,
- 'lastmod' => $lastmod
- );
- }
- function getPriority($value)
- {
- return(sprintf('%.1f',min(abs((float)$value),1)));
- }
- function getFrequency($value)
- {
- return $this->freqs[min(abs(intval($value)),6)];
- }
- function collectURLs()
- {
- // Homepage URL
- if (!empty($this->opts['dc_gsitemap_home']))
- {
- $freq = $this->getFrequency($this->opts['dc_gsitemap_home_pd']);
- $prio = $this->getPriority($this->opts['dc_gsitemap_home_pr']);
- $this->addEntry(util::getHost().dc_blog_url,$prio,$freq);
- }
- // Main syndication feeds URLs
- if (!empty($this->opts['dc_gsitemap_feeds']))
- {
- $freq = $this->getFrequency($this->opts['dc_gsitemap_feeds_pd']);
- $prio = $this->getPriority($this->opts['dc_gsitemap_feeds_pr']);
- $this->addEntry(util::getHost().dc_blog_rss,$prio,$freq);
- $this->addEntry(util::getHost().dc_blog_atom,$prio,$freq); }
- // Posts entries URLs
- if (!empty($this->opts['dc_gsitemap_posts']))
- {
- $freq = $this->getFrequency($this->opts['dc_gsitemap_posts_pd']);
- $prio = $this->getPriority($this->opts['dc_gsitemap_posts_pr']);
- $query =
- "SELECT p.post_id, p.post_titre_url, p.post_dt, ".
- "p.post_upddt, MAX(c.comment_upddt) AS comments_dt ".
- "FROM ".$this->blog->t_post." AS p ".
- "LEFT OUTER JOIN ".$this->blog->t_comment." AS c ON c.post_id = p.post_id ".
- "WHERE p.post_pub = 1 ".
- 'GROUP BY p.post_id '.
- 'ORDER BY p.post_dt ASC';
- $rs = $this->blog->con->select($query);
- while ($rs->fetch()) {
- if ($rs->f('comments_dt') !== null) {
- $last_ts = max(strtotime($rs->f('post_upddt')),strtotime($rs->f('comments_dt')));
- } else {
- $last_ts = strtotime($rs->f('post_upddt'));
- }
- $last_dt = dt::iso8601($last_ts);
- $post_ts = strtotime($rs->f('post_dt'));
- $url =
- util::getHost().
- sprintf(
- $this->blog->front_url['post'],
- date('Y', $post_ts), date('m',$post_ts),date('d',$post_ts),
- $rs->f('post_id'),$rs->f('post_titre_url')
- );
- $this->addEntry($url,$prio,$freq,$last_dt);
- }
- }
- // Categories URLs
- if (!empty($this->opts['dc_gsitemap_cats']))
- {
- $freq = $this->getFrequency($this->opts['dc_gsitemap_cats_pd']);
- $prio = $this->getPriority($this->opts['dc_gsitemap_cats_pr']);
- $cats = $this->blog->getCat('','cat_ord');
- while ($cats->fetch()) {
- $this->addEntry(
- util::getHost().sprintf($this->blog->front_url['cat'],$cats->f('cat_libelle_url')),
- $prio,$freq);
- }
- }
- // Related pages URLs
- if (!empty($this->opts['dc_gsitemap_related']))
- {
- if (is_callable(array('dcRelatedPages','relatedIniToArray')))
- {
- $freq = $this->getFrequency($this->opts['dc_gsitemap_related_pd']);
- $prio = $this->getPriority($this->opts['dc_gsitemap_related_pr']);
- $rel_pages = dcRelatedPages::relatedIniToArray();
- foreach ($rel_pages as $url => $v) {
- $this->addEntry(
- util::getHost().dc_blog_url.(dc_url_scan == 'query_string' ? '?' : '').$url,
- $prio,$freq);
- }
- }
- }
- }
- }
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement