[ Index ]

PHP Cross Reference of phpwcms V1.4.7 _r403 (01.11.10)

title

Body

[close]

/ -> sitemap.php (source)

   1  <?php
   2  /*************************************************************************************
   3     Copyright notice
   4     
   5     (c) 2002-2010 Oliver Georgi (oliver@phpwcms.de) // All rights reserved.
   6   
   7     This script is part of PHPWCMS. The PHPWCMS web content management system is
   8     free software; you can redistribute it and/or modify it under the terms of
   9     the GNU General Public License as published by the Free Software Foundation;
  10     either version 2 of the License, or (at your option) any later version.
  11    
  12     The GNU General Public License can be found at http://www.gnu.org/copyleft/gpl.html
  13     A copy is found in the textfile GPL.txt and important notices to the license 
  14     from the author is found in LICENSE.txt distributed with these scripts.
  15    
  16     This script is distributed in the hope that it will be useful, but WITHOUT ANY 
  17     WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
  18     PARTICULAR PURPOSE.  See the GNU General Public License for more details.
  19   
  20     This copyright notice MUST APPEAR in all copies of the script!
  21  *************************************************************************************/
  22  
  23  // build Google Sitemap based on available articles
  24  
  25  $phpwcms = array();
  26  require_once ('config/phpwcms/conf.inc.php');
  27  
  28  // set neccessary charset
  29  $phpwcms["charset"] = 'utf-8';
  30  require_once  ('include/inc_lib/default.inc.php');
  31  define('VISIBLE_MODE', 0);
  32  require_once  (PHPWCMS_ROOT.'/include/inc_lib/dbcon.inc.php');
  33  require_once  (PHPWCMS_ROOT.'/config/phpwcms/conf.indexpage.inc.php');
  34  require_once  (PHPWCMS_ROOT.'/include/inc_lib/general.inc.php');
  35  require_once  (PHPWCMS_ROOT.'/include/inc_front/front.func.inc.php');
  36  
  37  // start XML 
  38  echo '<?xml version="1.0" encoding="utf-8"?>'.LF;
  39  echo '<urlset xmlns="http://www.google.com/schemas/sitemap/0.84" 
  40      xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
  41      xsi:schemaLocation="http://www.google.com/schemas/sitemap/0.84 
  42      http://www.google.com/schemas/sitemap/0.84/sitemap.xsd">'.LF;
  43  echo '    <!-- Google Sitemap, http://www.google.com/webmasters/sitemaps/ -->'.LF.LF;
  44  
  45  
  46  //reads complete structure as array
  47  $struct    = get_struct_data();
  48  
  49  // fallback value when no article available
  50  $base    = true;
  51  
  52  // now retrieve all articles
  53  $sql  =    "SELECT article_id, article_cid, DATE_FORMAT(article_tstamp, '%Y-%m-%d') AS article_tstamp, ";
  54  $sql .= "article_title, article_redirect, article_aliasid, article_alias ";
  55  $sql .= "FROM ".DB_PREPEND."phpwcms_article WHERE ";
  56  $sql .= "article_public=1 AND article_aktiv=1 AND article_deleted=0 AND article_nosearch!='1' AND ";
  57  $sql .= "article_nositemap=1 AND article_begin < NOW() AND article_end > NOW() ";
  58  $sql .= "ORDER BY article_tstamp DESC";
  59  
  60  if($result = mysql_query($sql, $db)) {
  61  
  62      while($data = mysql_fetch_assoc($result)) {
  63      
  64          // first proof if this article is within an "public" structure section
  65          $_CAT = $struct[$data['article_cid']];
  66          if($_CAT['acat_regonly'] || $_CAT['acat_nosearch']=='1' || !$_CAT['acat_nositemap']) {
  67              // no it is no public article - so jump to next entry
  68              continue;
  69          }
  70          
  71          // now add article URL to Google sitemap
  72          if(empty($phpwcms['rewrite_url']) || empty($data['article_alias'])) {
  73              $_link = PHPWCMS_URL.'index.php?'.setGetArticleAid( $data );
  74          } else {
  75              $_link = PHPWCMS_URL.rawurlencode($data['article_alias']).'.phtml';
  76          }
  77          echo '    <url>'.LF;
  78          echo '        <loc>'.$_link.'</loc>'.LF;
  79          echo '        <lastmod>'.$data["article_tstamp"].'</lastmod>'.LF;
  80          echo '    </url>'.LF;  
  81          
  82          // yes we have a minimum of 1 article link
  83          $base = false;
  84  
  85      }
  86  }
  87  
  88  echo LF.'    <!-- try to add custom URLs from INI file... ';
  89  $_addURL = parse_ini_file (PHPWCMS_ROOT.'/config/phpwcms/sitemap.custom.ini', true);
  90  echo '-->'.LF;
  91  
  92  if(is_array($_addURL) && count($_addURL)) {
  93      
  94      foreach($_addURL as $value) {
  95      
  96          $_link = empty($value['url']) ? '' : trim($value['url']);
  97          if(empty($_link)) {
  98              continue;
  99          }
 100          $_lastmod = empty($value['date']) ? '' : trim($value['date']);
 101          if(empty($value['date'])) {
 102              $_lastmod = date('Y-m-d');
 103          }
 104          echo '    <url>'.LF;
 105          echo '        <loc>'.$_link.'</loc>'.LF;
 106          echo '        <lastmod>'.$_lastmod.'</lastmod>'.LF;
 107          echo '    </url>'.LF;  
 108      
 109      }
 110      
 111  } else {
 112      echo '    <!-- ...no custom URL available for inclusion -->'.LF.LF;
 113  }
 114  
 115  if($base) {
 116      // just return the main URL
 117      echo '    <url>'.LF;
 118      echo '        <loc>'.PHPWCMS_URL.'</loc>'.LF;
 119      echo '        <lastmod>'.date('Y-m-d').'</lastmod>'.LF;
 120      echo '    </url>'.LF;  
 121  }
 122  
 123  echo '</urlset>';
 124  
 125  ?>


Generated: Tue Nov 16 22:51:00 2010 Cross-referenced by PHPXref 0.7