deckarudo

Dotclear Gsitemap

Apr 8th, 2013
28
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <?php
  2.  
  3. # ***** BEGIN LICENSE BLOCK *****
  4.  
  5. # This file is part of Gsitemap, a plugin for DotClear.
  6.  
  7. # Copyright (c) 2005 Pep and contributors. All rights
  8.  
  9. # reserved.
  10.  
  11. #
  12.  
  13. # DotClear.
  14.  
  15. # Copyright (c) 2004 Olivier Meunier and contributors. All rights
  16.  
  17. # reserved.
  18.  
  19. #
  20.  
  21. # DotClear is free software; you can redistribute it and/or modify
  22.  
  23. # it under the terms of the GNU General Public License as published by
  24.  
  25. # the Free Software Foundation; either version 2 of the License, or
  26.  
  27. # (at your option) any later version.
  28.  
  29. #
  30.  
  31. # DotClear is distributed in the hope that it will be useful,
  32.  
  33. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  34.  
  35. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  36.  
  37. # GNU General Public License for more details.
  38.  
  39. #
  40.  
  41. # You should have received a copy of the GNU General Public License
  42.  
  43. # along with DotClear; if not, write to the Free Software
  44.  
  45. # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
  46.  
  47. #
  48.  
  49. # ***** END LICENSE BLOCK *****
  50.  
  51. class gsitemap {
  52.  
  53.     var $blog;
  54.  
  55.     var $urls;
  56.  
  57.     var $freqs;
  58.  
  59.     var $opts;
  60.  
  61.    
  62.  
  63.     function gsitemap(&$blog, $config)
  64.  
  65.     {
  66.  
  67.         $this->blog =& $blog;
  68.  
  69.         $this->urls  = array();
  70.  
  71.         $this->freqs = array('','always','hourly','daily','weekly','monthly','never');
  72.  
  73.         $this->opts = $config;
  74.  
  75.     }
  76.  
  77.  
  78.  
  79.     function getURLs()
  80.  
  81.     {
  82.  
  83.         if (!empty($this->opts['dc_gsitemap_active']) && empty($this->urls)) {
  84.  
  85.             $this->collectURLs();
  86.  
  87.         }
  88.  
  89.         return $this->urls;
  90.  
  91.     }
  92.  
  93.  
  94.  
  95.     function googleSitemap()
  96.  
  97.     {
  98.  
  99.         $urls = $this->getURLs();
  100.  
  101.         if (!empty($urls)) {
  102.  
  103.             $content = '';
  104.  
  105.             foreach ($urls as $url) {
  106.  
  107.                 $content .= "<url>\n";
  108.  
  109.                 $content .= '<loc>'.$url['loc']."</loc>\n";
  110.  
  111.                 if (!empty($url['priority'])) {
  112.  
  113.                     $content .= '<priority>'.$url['priority']."</priority>\n";
  114.  
  115.                 }
  116.  
  117.                 if (!empty($url['frequency'])) {
  118.  
  119.                     $content .= '<changefreq>'.$url['frequency']."</changefreq>\n";
  120.  
  121.                 }
  122.  
  123.                 if (!empty($url['lastmod'])) {
  124.  
  125.                     $content .= '<lastmod>'.$url['lastmod']."</lastmod>\n";
  126.  
  127.                 }
  128.  
  129.                 $content .= "</url>\n";
  130.  
  131.             }
  132.  
  133.  
  134.  
  135.             header('Content-Type: text/xml; charset=UTF-8');
  136.  
  137.  
  138.  
  139.             echo
  140.  
  141.             '<?xml version="1.0" encoding="UTF-8"?>'."\n".
  142.  
  143.             '<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">'."\n".
  144.  
  145.             $content.
  146.  
  147.             '</urlset>';
  148.  
  149.         }
  150.  
  151.         $this->blog->con->close();
  152.  
  153.         exit;
  154.  
  155.     }
  156.  
  157.  
  158.  
  159.     function yahooUrllist()
  160.  
  161.     {
  162.  
  163.         $urls = $this->getURLs();
  164.  
  165.         if (!empty($urls)) {
  166.  
  167.             $content = '';
  168.  
  169.             foreach ($urls as $url) {
  170.  
  171.                 $content .= $url['loc']."\n";
  172.  
  173.             }
  174.  
  175.  
  176.  
  177.             header('Content-Type: text/plain; charset=UTF-8');
  178.  
  179.  
  180.  
  181.             echo $content;
  182.  
  183.         }
  184.  
  185.         $this->blog->con->close();
  186.  
  187.         exit;
  188.  
  189.     }
  190.  
  191.  
  192.  
  193.     function addEntry($loc,$priority,$frequency,$lastmod = '')
  194.  
  195.     {
  196.  
  197.         $this->urls[] = array(
  198.  
  199.             'loc'     => $loc,
  200.  
  201.             'priority'  => $priority,
  202.  
  203.             'frequency' => $frequency,
  204.  
  205.             'lastmod'     => $lastmod
  206.  
  207.             );
  208.  
  209.     }
  210.  
  211.  
  212.  
  213.     function getPriority($value)
  214.  
  215.     {
  216.  
  217.         return(sprintf('%.1f',min(abs((float)$value),1)));
  218.  
  219.     }
  220.  
  221.  
  222.  
  223.     function getFrequency($value)
  224.  
  225.     {
  226.  
  227.         return $this->freqs[min(abs(intval($value)),6)];
  228.  
  229.     }
  230.  
  231.  
  232.  
  233.     function collectURLs()
  234.  
  235.     {
  236.  
  237.         // Homepage URL
  238.  
  239.         if (!empty($this->opts['dc_gsitemap_home']))
  240.  
  241.         {
  242.  
  243.             $freq = $this->getFrequency($this->opts['dc_gsitemap_home_pd']);
  244.  
  245.             $prio = $this->getPriority($this->opts['dc_gsitemap_home_pr']);
  246.  
  247.  
  248.  
  249.             $this->addEntry(util::getHost().dc_blog_url,$prio,$freq);
  250.  
  251.         }
  252.  
  253.  
  254.  
  255.         // Main syndication feeds URLs
  256.  
  257.         if (!empty($this->opts['dc_gsitemap_feeds']))
  258.  
  259.         {
  260.  
  261.             $freq = $this->getFrequency($this->opts['dc_gsitemap_feeds_pd']);
  262.  
  263.             $prio = $this->getPriority($this->opts['dc_gsitemap_feeds_pr']);
  264.  
  265.  
  266.  
  267.             $this->addEntry(util::getHost().dc_blog_rss,$prio,$freq);
  268.  
  269.             $this->addEntry(util::getHost().dc_blog_atom,$prio,$freq);      }
  270.  
  271.  
  272.  
  273.         // Posts entries URLs
  274.  
  275.         if (!empty($this->opts['dc_gsitemap_posts']))
  276.  
  277.         {
  278.  
  279.             $freq = $this->getFrequency($this->opts['dc_gsitemap_posts_pd']);
  280.  
  281.             $prio = $this->getPriority($this->opts['dc_gsitemap_posts_pr']);
  282.  
  283.  
  284.  
  285.             $query =
  286.  
  287.             "SELECT p.post_id, p.post_titre_url, p.post_dt, ".
  288.  
  289.             "p.post_upddt, MAX(c.comment_upddt) AS comments_dt ".  
  290.  
  291.             "FROM ".$this->blog->t_post." AS p ".
  292.  
  293.             "LEFT OUTER JOIN ".$this->blog->t_comment." AS c ON c.post_id = p.post_id ".
  294.  
  295.             "WHERE p.post_pub = 1 ".
  296.  
  297.             'GROUP BY p.post_id '.
  298.  
  299.             'ORDER BY p.post_dt ASC';
  300.  
  301.            
  302.  
  303.             $rs = $this->blog->con->select($query);
  304.  
  305.             while ($rs->fetch()) {
  306.  
  307.                 if ($rs->f('comments_dt') !== null) {
  308.  
  309.                     $last_ts = max(strtotime($rs->f('post_upddt')),strtotime($rs->f('comments_dt')));
  310.  
  311.                 } else {
  312.  
  313.                     $last_ts = strtotime($rs->f('post_upddt'));
  314.  
  315.                 }
  316.  
  317.                 $last_dt = dt::iso8601($last_ts);
  318.  
  319.                 $post_ts = strtotime($rs->f('post_dt'));
  320.  
  321.                 $url =
  322.  
  323.                 util::getHost().
  324.  
  325.                 sprintf(
  326.  
  327.                     $this->blog->front_url['post'],
  328.  
  329.                     date('Y', $post_ts), date('m',$post_ts),date('d',$post_ts),
  330.  
  331.                     $rs->f('post_id'),$rs->f('post_titre_url')
  332.  
  333.                 );
  334.  
  335.                    
  336.  
  337.                 $this->addEntry($url,$prio,$freq,$last_dt);
  338.  
  339.             }
  340.  
  341.         }
  342.  
  343.  
  344.  
  345.         // Categories URLs
  346.  
  347.         if (!empty($this->opts['dc_gsitemap_cats']))
  348.  
  349.         {
  350.  
  351.             $freq = $this->getFrequency($this->opts['dc_gsitemap_cats_pd']);
  352.  
  353.             $prio = $this->getPriority($this->opts['dc_gsitemap_cats_pr']);
  354.  
  355.  
  356.  
  357.             $cats = $this->blog->getCat('','cat_ord');
  358.  
  359.             while ($cats->fetch()) {
  360.  
  361.                 $this->addEntry(
  362.  
  363.                         util::getHost().sprintf($this->blog->front_url['cat'],$cats->f('cat_libelle_url')),
  364.  
  365.                         $prio,$freq);
  366.  
  367.             }
  368.  
  369.         }
  370.  
  371.  
  372.  
  373.         // Related pages URLs
  374.  
  375.         if (!empty($this->opts['dc_gsitemap_related']))
  376.  
  377.         {
  378.  
  379.             if (is_callable(array('dcRelatedPages','relatedIniToArray')))
  380.  
  381.             {
  382.  
  383.                 $freq = $this->getFrequency($this->opts['dc_gsitemap_related_pd']);
  384.  
  385.                 $prio = $this->getPriority($this->opts['dc_gsitemap_related_pr']);
  386.  
  387.                
  388.  
  389.                 $rel_pages = dcRelatedPages::relatedIniToArray();
  390.  
  391.                 foreach ($rel_pages as $url => $v) {
  392.  
  393.                     $this->addEntry(
  394.  
  395.                             util::getHost().dc_blog_url.(dc_url_scan == 'query_string' ? '?' : '').$url,
  396.  
  397.                             $prio,$freq);
  398.  
  399.                 }
  400.  
  401.             }
  402.  
  403.         }
  404.  
  405.     }
  406.  
  407. }
  408.  
  409. ?>
RAW Paste Data

Adblocker detected! Please consider disabling it...

We've detected AdBlock Plus or some other adblocking software preventing Pastebin.com from fully loading.

We don't have any obnoxious sound, or popup ads, we actively block these annoying types of ads!

Please add Pastebin.com to your ad blocker whitelist or disable your adblocking software.

×