[ Index ]

PHP Cross Reference of phpwcms V1.4.3 _r380 (23.11.09)

title

Body

[close]

/ -> sitemap.php (source)

   1  <?php
   2  /*************************************************************************************
   3     Copyright notice
   4     
   5     (c) 2002-2009 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  require_once ('config/phpwcms/conf.inc.php');
  26  
  27  // set neccessary charset
  28  $phpwcms["charset"] = 'utf-8';
  29  require_once  ('include/inc_lib/default.inc.php');
  30  
  31  init_frontend_edit();
  32  
  33  require_once  (PHPWCMS_ROOT.'/include/inc_lib/dbcon.inc.php');
  34  require_once  (PHPWCMS_ROOT.'/config/phpwcms/conf.indexpage.inc.php');
  35  require_once  (PHPWCMS_ROOT.'/include/inc_lib/general.inc.php');
  36  require_once  (PHPWCMS_ROOT.'/include/inc_front/front.func.inc.php');
  37  
  38  // start XML 
  39  echo '<?xml version="1.0" encoding="utf-8"?>'.LF;
  40  echo '<urlset xmlns="http://www.google.com/schemas/sitemap/0.84" 
  41      xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
  42      xsi:schemaLocation="http://www.google.com/schemas/sitemap/0.84 
  43      http://www.google.com/schemas/sitemap/0.84/sitemap.xsd">'.LF;
  44  echo '    <!-- Google Sitemap, http://www.google.com/webmasters/sitemaps/ -->'.LF.LF;
  45  
  46  
  47  //reads complete structure as array
  48  $struct    = get_struct_data();
  49  
  50  // fallback value when no article available
  51  $base    = true;
  52  
  53  // now retrieve all articles
  54  $sql  =    "SELECT article_id, article_cid, DATE_FORMAT(article_tstamp, '%Y-%m-%d') AS article_tstamp, ";
  55  $sql .= "article_title, article_redirect, article_aliasid, article_alias ";
  56  $sql .= "FROM ".DB_PREPEND."phpwcms_article WHERE ";
  57  $sql .= "article_public=1 AND article_aktiv=1 AND article_deleted=0 AND article_nosearch!='1' AND ";
  58  $sql .= "article_nositemap=1 AND article_begin < NOW() AND article_end > NOW() ";
  59  $sql .= "ORDER BY article_tstamp DESC";
  60  
  61  if($result = mysql_query($sql, $db)) {
  62  
  63      while($data = mysql_fetch_assoc($result)) {
  64      
  65          // first proof if this article is within an "public" structure section
  66          $_CAT = $struct[$data['article_cid']];
  67          if($_CAT['acat_regonly'] || $_CAT['acat_nosearch']=='1' || !$_CAT['acat_nositemap']) {
  68              // no it is no public article - so jump to next entry
  69              continue;
  70          }
  71          
  72          // now add article URL to Google sitemap
  73          $_link = PHPWCMS_URL.'index.php?'.setGetArticleAid( $data );
  74          echo '    <url>'.LF;
  75          echo '        <loc>'.$_link.'</loc>'.LF;
  76          echo '        <lastmod>'.$data["article_tstamp"].'</lastmod>'.LF;
  77          echo '    </url>'.LF;  
  78          
  79          // yes we have a minimum of 1 article link
  80          $base = false;
  81  
  82      }
  83  }
  84  
  85  echo LF.'    <!-- try to add custom URLs from INI file... ';
  86  $_addURL = parse_ini_file (PHPWCMS_ROOT.'/config/phpwcms/sitemap.custom.ini', true);
  87  echo '-->'.LF;
  88  
  89  if(is_array($_addURL) && count($_addURL)) {
  90      
  91      foreach($_addURL as $value) {
  92      
  93          $_link = empty($value['url']) ? '' : trim($value['url']);
  94          if(empty($_link)) {
  95              continue;
  96          }
  97          $_lastmod = empty($value['date']) ? '' : trim($value['date']);
  98          if(empty($value['date'])) {
  99              $_lastmod = date('Y-m-d');
 100          }
 101          echo '    <url>'.LF;
 102          echo '        <loc>'.$_link.'</loc>'.LF;
 103          echo '        <lastmod>'.$_lastmod.'</lastmod>'.LF;
 104          echo '    </url>'.LF;  
 105      
 106      }
 107      
 108  } else {
 109      echo '    <!-- ...no custom URL available for inclusion -->'.LF.LF;
 110  }
 111  
 112  if($base) {
 113      // just return the main URL
 114      echo '    <url>'.LF;
 115      echo '        <loc>'.PHPWCMS_URL.'</loc>'.LF;
 116      echo '        <lastmod>'.date('Y-m-d').'</lastmod>'.LF;
 117      echo '    </url>'.LF;  
 118  }
 119  
 120  echo '</urlset>';
 121  
 122  ?>


Generated: Wed Dec 30 05:55:15 2009 Cross-referenced by PHPXref 0.7