1: <?php
   2: 
   3:    4:    5:    6:    7:    8:    9:   10:   11:   12:   13:   14:   15:   16:   17:   18:   19:   20: 
  21: $plugin_is_filter = 0 | CLASS_PLUGIN;
  22: $plugin_description = gettext('Generates sitemap.org compatible XML files for use with Google and other search engines.');
  23: $plugin_notice = gettext('<strong>Note:</strong> The index links may not match if using the Zenpage option "news on index" that some themes provide! Also it does not "know" about "custom pages" outside Zenpage or any special custom theme setup!!');
  24: $plugin_author = 'Malte Müller (acrylian)';
  25: 
  26: $option_interface = 'sitemap';
  27: 
  28: zp_register_filter('admin_utilities_buttons', 'sitemap::button');
  29: 
  30: $sitemapfolder = SERVERPATH . '/' . STATIC_CACHE_FOLDER . '/sitemap';
  31: if (!file_exists($sitemapfolder)) {
  32:     if (!mkdir_recursive($sitemapfolder, FOLDER_MOD)) {
  33:         die(gettext("sitemap cache folder could not be created. Please try to create it manually via FTP with chmod 0777."));
  34:     }
  35: }
  36: 
  37: define('SITEMAP_CHUNK', getOption('sitemap_processing_chunk'));
  38: define('GOOGLE_SITEMAP', getOption('sitemap_google'));
  39: if (getOption('multi_lingual') && defined('LOCALE_TYPE')) {
  40:     define('SITEMAP_LOCALE_TYPE', LOCALE_TYPE);
  41: } else {
  42:     define('SITEMAP_LOCALE_TYPE', 0);
  43: }
  44: 
  45:   46:   47:   48: 
  49: class sitemap {
  50: 
  51:     var $startmtime;
  52:     var $disable = false; 
  53: 
  54:     function __construct() {
  55:         setOptionDefault('sitemap_changefreq_index', 'daily');
  56:         setOptionDefault('sitemap_changefreq_albums', 'daily');
  57:         setOptionDefault('sitemap_changefreq_images', 'daily');
  58:         setOptionDefault('sitemap_changefreq_pages', 'weekly');
  59:         setOptionDefault('sitemap_changefreq_newsindex', 'daily');
  60:         setOptionDefault('sitemap_changefreq_news', 'daily');
  61:         setOptionDefault('sitemap_changefreq_newscats', 'weekly');
  62:         setOptionDefault('sitemap_lastmod_albums', 'mtime');
  63:         setOptionDefault('sitemap_lastmod_images', 'mtime');
  64:         setOptionDefault('sitemap_processing_chunk', 25);
  65:         setOptionDefault('sitemap_galleryindex', '');
  66:         setOptionDefault('sitemap_google', 0);
  67:         setOptionDefault('sitemap_google_fullimage', 0);
  68:     }
  69: 
  70:     function getOptionsSupported() {
  71:         global $_common_locale_type;
  72:         $localdesc = '<p>' . gettext('If checked links to the alternative languages will be in the form <code><em>language</em>.domain</code> where <code><em>language</em></code> is the language code, e.g. <code><em>fr</em></code> for French.') . '</p>';
  73:         if (!$_common_locale_type) {
  74:             $localdesc .= '<p>' . gettext('This requires that you have created the appropriate subdomains pointing to your Zenphoto installation. That is <code>fr.mydomain.com/zenphoto/</code> must point to the same location as <code>mydomain.com/zenphoto/</code>. (Some providers will automatically redirect undefined subdomains to the main domain. If your provider does this, no subdomain creation is needed.)') . '</p>';
  75:         }
  76:         $options = array(
  77:                         gettext('Gallery index page')                                                    => array('key'                  => 'sitemap_galleryindex', 'type'               => OPTION_TYPE_TEXTBOX,
  78:                                         'order'              => 11,
  79:                                         'multilingual' => false,
  80:                                         'desc'               => gettext('If your theme does not use the theme index.php page as the gallery index, enter the name of the page here. In the Zenpage theme for example this could be gallery.php. In that case you enter "gallery". If this is not empty the index.php sitemap is not generated.')),
  81:                         gettext('Album date')                                                                    => array('key'              => 'sitemap_lastmod_albums', 'type'             => OPTION_TYPE_SELECTOR,
  82:                                         'order'          => 0,
  83:                                         'selections' => array(gettext("date")    => "date",
  84:                                                         gettext("mtime") => "mtime"),
  85:                                         'desc'           => gettext('Field to use for the last modification date of albums.')),
  86:                         gettext('Image date')                                                                    => array('key'              => 'sitemap_lastmod_images', 'type'             => OPTION_TYPE_SELECTOR,
  87:                                         'order'          => 1,
  88:                                         'selections' => array(gettext("date")    => "date",
  89:                                                         gettext("mtime") => "mtime"),
  90:                                         'desc'           => gettext('Field to use for the last modification date of images.')),
  91:                         gettext('Change frequency - Zenphoto index')                     => array('key'              => 'sitemap_changefreq_index', 'type'           => OPTION_TYPE_SELECTOR,
  92:                                         'order'          => 2,
  93:                                         'selections' => array(gettext("always")  => "always",
  94:                                                         gettext("hourly")    => "hourly",
  95:                                                         gettext("daily")     => "daily",
  96:                                                         gettext("weekly")    => "weekly",
  97:                                                         gettext("monthly") => "monthly",
  98:                                                         gettext("yearly")    => "yearly",
  99:                                                         gettext("never")     => "never"),
 100:                                         'desc'           => ''),
 101:                         gettext('Change frequency - albums')                                     => array('key'              => 'sitemap_changefreq_albums', 'type'          => OPTION_TYPE_SELECTOR,
 102:                                         'order'          => 3,
 103:                                         'selections' => array(gettext("always")  => "always",
 104:                                                         gettext("hourly")    => "hourly",
 105:                                                         gettext("daily")     => "daily",
 106:                                                         gettext("weekly")    => "weekly",
 107:                                                         gettext("monthly") => "monthly",
 108:                                                         gettext("yearly")    => "yearly",
 109:                                                         gettext("never")     => "never"),
 110:                                         'desc'           => ''),
 111:                         gettext('Change frequency - images')                                     => array('key'              => 'sitemap_changefreq_images', 'type'          => OPTION_TYPE_SELECTOR,
 112:                                         'order'          => 4,
 113:                                         'selections' => array(gettext("always")  => "always",
 114:                                                         gettext("hourly")    => "hourly",
 115:                                                         gettext("daily")     => "daily",
 116:                                                         gettext("weekly")    => "weekly",
 117:                                                         gettext("monthly") => "monthly",
 118:                                                         gettext("yearly")    => "yearly",
 119:                                                         gettext("never")     => "never"),
 120:                                         'desc'           => ''),
 121:                         gettext('Change frequency - Zenpage pages')                      => array('key'              => 'sitemap_changefreq_pages', 'type'           => OPTION_TYPE_SELECTOR,
 122:                                         'order'          => 5,
 123:                                         'selections' => array(gettext("always")  => "always",
 124:                                                         gettext("hourly")    => "hourly",
 125:                                                         gettext("daily")     => "daily",
 126:                                                         gettext("weekly")    => "weekly",
 127:                                                         gettext("monthly") => "monthly",
 128:                                                         gettext("yearly")    => "yearly",
 129:                                                         gettext("never")     => "never"),
 130:                                         'desc'           => ''),
 131:                         gettext('Change frequency - Zenpage news index')             => array('key'              => 'sitemap_changefreq_newsindex', 'type'           => OPTION_TYPE_SELECTOR,
 132:                                         'order'          => 6,
 133:                                         'selections' => array(gettext("always")  => "always",
 134:                                                         gettext("hourly")    => "hourly",
 135:                                                         gettext("daily")     => "daily",
 136:                                                         gettext("weekly")    => "weekly",
 137:                                                         gettext("monthly") => "monthly",
 138:                                                         gettext("yearly")    => "yearly",
 139:                                                         gettext("never")     => "never"),
 140:                                         'desc'           => ''),
 141:                         gettext('Change frequency: Zenpage news articles')       => array('key'              => 'sitemap_changefreq_news', 'type'            => OPTION_TYPE_SELECTOR,
 142:                                         'order'          => 7,
 143:                                         'selections' => array(gettext("always")  => "always",
 144:                                                         gettext("hourly")    => "hourly",
 145:                                                         gettext("daily")     => "daily",
 146:                                                         gettext("weekly")    => "weekly",
 147:                                                         gettext("monthly") => "monthly",
 148:                                                         gettext("yearly")    => "yearly",
 149:                                                         gettext("never")     => "never"),
 150:                                         'desc'           => ''),
 151:                         gettext('Change frequency - Zenpage news categories')    => array('key'              => 'sitemap_changefreq_newscats', 'type'            => OPTION_TYPE_SELECTOR,
 152:                                         'order'          => 8,
 153:                                         'selections' => array(gettext("always")  => "always",
 154:                                                         gettext("hourly")    => "hourly",
 155:                                                         gettext("daily")     => "daily",
 156:                                                         gettext("weekly")    => "weekly",
 157:                                                         gettext("monthly") => "monthly",
 158:                                                         gettext("yearly")    => "yearly",
 159:                                                         gettext("never")     => "never"),
 160:                                         'desc'           => ''),
 161:                         gettext('Enable Google image and video extension')       => array('key'      => 'sitemap_google', 'type'     => OPTION_TYPE_CHECKBOX,
 162:                                         'order'  => 9,
 163:                                         'desc'   => gettext('If checked, the XML output file will be formatted using the Google XML image and video extensions where applicable.') . '<p class="notebox">' . gettext('<strong>Note:</strong> Other search engines (Yahoo, Bing) might not be able to read your sitemap. Also the Google extensions cover only image and video formats. If you use custom file types that are not covered by Zenphoto standard plugins or types like .mp3, .txt and .html you should probably not use this or modify the plugin. Also, if your site is really huge think about if you really need this setting as the creation may cause extra workload of your server and result in timeouts') . '</p>'),
 164:                         gettext('Google image and video extension: Link full image ')        => array('key'      => 'sitemap_google_fullimage', 'type'   => OPTION_TYPE_CHECKBOX,
 165:                                         'order'  => 10,
 166:                                         'desc'   => gettext('If checked, the original full image is referenced instead of the sized images in the cache. For image formats only.')),
 167:                         gettext('Google - URL to image license')                             => array('key'                  => 'sitemap_license', 'type'                => OPTION_TYPE_TEXTBOX,
 168:                                         'order'              => 12,
 169:                                         'multilingual' => true,
 170:                                         'desc'               => gettext('Optional. Used only if the Google extension is checked. Must be an absolute URL address of the form: http://mydomain.com/license.html')),
 171:                         gettext('Sitemap processing chunk')                                      => array('key'      => 'sitemap_processing_chunk', 'type'   => OPTION_TYPE_TEXTBOX,
 172:                                         'order'  => 13,
 173:                                         'desc'   => gettext('The number of albums that will be processed for each sitemap file. Lower this value if you get script timeouts when creating the files.')),
 174:                         gettext('Use subdomains') . '*'                                              => array('key'          => 'dynamic_locale_subdomain', 'type'       => OPTION_TYPE_CHECKBOX,
 175:                                         'order'      => 14,
 176:                                         'disabled' => $_common_locale_type,
 177:                                         'desc'       => $localdesc)
 178:         );
 179:         if ($_common_locale_type) {
 180:             $options['note'] = array('key'       => 'sitemap_locale_type', 'type'    => OPTION_TYPE_NOTE,
 181:                             'order'  => 15,
 182:                             'desc'   => '<p class="notebox">' . $_common_locale_type . '</p>');
 183:         } else {
 184:             $_common_locale_type = gettext('* This option may be set via the <a href="javascript:gotoName(\'sitemap-extended\');"><em>sitemap-extended</em></a> plugin options.');
 185:             $options['note'] = array('key'       => 'sitemap_locale_type',
 186:                             'type'   => OPTION_TYPE_NOTE,
 187:                             'order'  => 16,
 188:                             'desc'   => gettext('<p class="notebox">*<strong>Note:</strong> The setting of this option is shared with other plugins.</p>'));
 189:         }
 190:         return $options;
 191:     }
 192: 
 193:     function handleOption($option, $currentValue) {
 194: 
 195:     }
 196: 
 197:      198:  199:  200:  201: 
 202:     static function button($buttons) {
 203:         $buttons[] = array(
 204:                         'category'       => gettext('Seo'),
 205:                         'enable'             => true,
 206:                         'button_text'    => gettext('Sitemap tools'),
 207:                         'formname'       => 'sitemap_button',
 208:                         'action'             => PLUGIN_FOLDER . '/sitemap-extended/sitemap-extended-admin.php',
 209:                         'icon'               => 'images/cache.png',
 210:                         'title'              => gettext('Generate or purge sitemap cache files.'),
 211:                         'alt'                    => '',
 212:                         'hidden'             => '',
 213:                         'rights'             => ADMIN_RIGHTS
 214:         );
 215:         return $buttons;
 216:     }
 217: 
 218: }
 219: 
 220: if (isset($_GET['sitemap'])) {
 221:     $sitemappath = SERVERPATH . '/' . STATIC_CACHE_FOLDER . '/sitemap/sitemapindex.xml';
 222:     if (file_exists($sitemappath)) {
 223:         $sitemapfile = file_get_contents($sitemappath);
 224:         echo $sitemapfile;
 225:     }
 226:     exitZP();
 227: }
 228: 
 229:  230:  231:  232:  233: 
 234: function sitemap_echonl($string) {
 235:     return $string . "\n";
 236: }
 237: 
 238:  239:  240:  241:  242:  243: 
 244: function generateSitemapCacheFile($filename, $data) {
 245:     if (!empty($data)) {
 246:         $filepath = SERVERPATH . '/' . STATIC_CACHE_FOLDER . '/sitemap/' . $filename . '.xml';
 247:         $handler = fopen($filepath, 'w');
 248:         fwrite($handler, $data);
 249:         fclose($handler);
 250:         echo '<li>' . $filename . '</li>';
 251:     }
 252: }
 253: 
 254:  255:  256:  257: 
 258: function generateSitemapIndexCacheFile() {
 259:     $data = '';
 260:     $cachefolder = SERVERPATH . '/' . STATIC_CACHE_FOLDER . '/sitemap/';
 261:     $dirs = array_diff(scandir($cachefolder), array('.', '..', '.DS_Store', 'Thumbs.db', '.htaccess', '.svn'));
 262:     if ($dirs) {
 263:         $data .= sitemap_echonl('<?xml version="1.0" encoding="UTF-8"?>');
 264:         $data .= sitemap_echonl('<sitemapindex xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.sitemaps.org/schemas/sitemap/0.9 http://www.sitemaps.org/schemas/sitemap/0.9/siteindex.xsd" xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">');
 265:         foreach ($dirs as $dir) {
 266:             $data .= sitemap_echonl("\t<sitemap>");
 267:             $data .= sitemap_echonl("\t\t<loc>" . FULLWEBPATH . '/' . STATIC_CACHE_FOLDER . '/sitemap/' . $dir . '</loc>');
 268:             $data .= sitemap_echonl("\t\t<lastmod>" . sitemap_getISO8601Date() . '</lastmod>');
 269:             $data .= sitemap_echonl("\t</sitemap>");
 270:         }
 271:         $data .= sitemap_echonl('</sitemapindex>');
 272:         $filepath = SERVERPATH . '/' . STATIC_CACHE_FOLDER . '/sitemap/sitemapindex.xml';
 273:         $handler = fopen($filepath, 'w');
 274:         fwrite($handler, $data);
 275:         fclose($handler);
 276:         echo '<p>sitemapindex.xml created.</p>';
 277:     }
 278: }
 279: 
 280:  281:  282:  283:  284: 
 285: function sitemap_getChangefreq($changefreq = '') {
 286:     $changefreq = sanitize($changefreq);
 287:     switch ($changefreq) {
 288:         case 'always':
 289:         case 'hourly':
 290:         case 'daily':
 291:         case 'weekly':
 292:         case 'monthly':
 293:         case 'yearly':
 294:         case 'never':
 295:             $changefreq = $changefreq;
 296:             break;
 297:         default:
 298:             $changefreq = 'daily';
 299:             break;
 300:     }
 301:     return $changefreq;
 302: }
 303: 
 304:  305:  306:  307:  308:  309: 
 310: function sitemap_getDateformat($obj, $option) {
 311:     $date = '';
 312:     switch ($option) {
 313:         case 'date':
 314:         default:
 315:             $date = $obj->getDatetime();
 316:             break;
 317:         case 'mtime':
 318:             $timestamp = $obj->get('mtime');
 319:             if ($timestamp == 0) {
 320:                 $date = $obj->getDatetime();
 321:             } else {
 322:                 return gmstrftime('%Y-%m-%dT%H:%M:%SZ', $timestamp);
 323:                 
 324:                 
 325:             }
 326:             break;
 327:     }
 328:     return sitemap_getISO8601Date($date);
 329:     
 330:     
 331: }
 332: 
 333:  334:  335:  336:  337: 
 338: function sitemap_getDBLimit($items_per_sitemap = 2) {
 339:     global $sitemap_number;
 340:     if ($sitemap_number < 1) {
 341:         $sitemap_number = 1;
 342:     }
 343:     $offset = ($sitemap_number - 1) * $items_per_sitemap;
 344:     $limit = " LIMIT " . $offset . "," . $items_per_sitemap;
 345:     return $limit;
 346: }
 347: 
 348:  349:  350:  351:  352:  353: 
 354: 
 355: function getSitemapIndexLinks() {
 356:     global $_zp_gallery, $sitemap_number;
 357:     $data = '';
 358:     if ($sitemap_number < 2) {
 359:         set_context(ZP_INDEX);
 360:         $albums_per_page = getOption('albums_per_page');
 361:         if (getOption('sitemap_galleryindex')) {
 362:             $galleryindex_mod = _PAGE_ . '/' . getOption('sitemap_galleryindex');
 363:             $galleryindex_nomod = 'index.php?p=' . getOption('sitemap_galleryindex') . '&page=';
 364:         } else {
 365:             $galleryindex_mod = '';
 366:             $galleryindex_nomod = 'index.php?page=';
 367:         }
 368:         $toplevelpages = getTotalPages();
 369:         $data .= sitemap_echonl('<?xml version="1.0" encoding="UTF-8"?>');
 370:         $data .= sitemap_echonl('<urlset xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.sitemaps.org/schemas/sitemap/0.9 http://www.sitemaps.org/schemas/sitemap/0.9/sitemap.xsd" xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">');
 371:         $sitemap_locales = generateLanguageList();
 372:         $changefreq = sitemap_getChangefreq(getOption('sitemap_changefreq_index'));
 373:         
 374:         switch (SITEMAP_LOCALE_TYPE) {
 375:             case 1:
 376:                 foreach ($sitemap_locales as $locale) {
 377:                     $data .= sitemap_echonl("\t<url>\n\t\t<loc>" . seo_locale::localePath(true, $locale) . "/</loc>\n\t\t<lastmod>" . sitemap_getISO8601Date() . "</lastmod>\n\t\t<changefreq>" . $changefreq . "</changefreq>\n\t\t<priority>0.9</priority>\n\t</url>");
 378:                 }
 379:                 break;
 380:             case 2:
 381:                 foreach ($sitemap_locales as $locale) {
 382:                     $data .= sitemap_echonl("\t<url>\n\t\t<loc>" . dynamic_locale::fullHostPath($locale) . "/</loc>\n\t\t<lastmod>" . sitemap_getISO8601Date() . "</lastmod>\n\t\t<changefreq>" . $changefreq . "</changefreq>\n\t\t<priority>0.9</priority>\n\t</url>");
 383:                 }
 384:                 break;
 385:             default:
 386:                 $data .= sitemap_echonl("\t<url>\n\t\t<loc>" . FULLWEBPATH . "</loc>\n\t\t<lastmod>" . sitemap_getISO8601Date() . "</lastmod>\n\t\t<changefreq>" . $changefreq . "</changefreq>\n\t\t<priority>0.9</priority>\n\t</url>");
 387:                 break;
 388:         }
 389:         
 390:         if (getOption('sitemap_galleryindex')) {
 391:             switch (SITEMAP_LOCALE_TYPE) {
 392:                 case 1:
 393:                     foreach ($sitemap_locales as $locale) {
 394:                         $data .= sitemap_echonl("\t<url>\n\t\t<loc>" . seo_locale::localePath(true, $locale) . '/' . $galleryindex_mod . "</loc>\n\t\t<lastmod>" . sitemap_getISO8601Date() . "</lastmod>\n\t\t<changefreq>" . $changefreq . "</changefreq>\n\t\t<priority>0.9</priority>\n\t</url>");
 395:                     }
 396:                     break;
 397:                 case 2:
 398:                     foreach ($sitemap_locales as $locale) {
 399:                         $data .= sitemap_echonl("\t<url>\n\t\t<loc>" . rewrite_path(dynamic_locale::fullHostPath($locale) . '/' . $galleryindex_mod, dynamic_locale::fullHostPath($locale) . '/' . $galleryindex_nomod) . "</loc>\n\t\t<lastmod>" . sitemap_getISO8601Date() . "</lastmod>\n\t\t<changefreq>" . $changefreq . "</changefreq>\n\t\t<priority>0.9</priority>\n\t</url>");
 400:                     }
 401:                     break;
 402:                 default:
 403:                     $data .= sitemap_echonl("\t<url>\n\t\t<loc>" . rewrite_path($galleryindex_mod, $galleryindex_nomod, FULLWEBPATH) . "</loc>\n\t\t<lastmod>" . sitemap_getISO8601Date() . "</lastmod>\n\t\t<changefreq>" . $changefreq . "</changefreq>\n\t\t<priority>0.9</priority>\n\t</url>");
 404:                     break;
 405:             }
 406:         }
 407:         
 408:         if ($toplevelpages) {
 409:             if (getOption('sitemap_galleryindex')) {
 410:                 $galleryindex_mod = $galleryindex_mod . '/';
 411:             } else {
 412:                 $galleryindex_mod = $galleryindex_mod . _PAGE_ . '/';
 413:             }
 414:             for ($x = 2; $x <= $toplevelpages; $x++) {
 415:                 switch (SITEMAP_LOCALE_TYPE) {
 416:                     case 1:
 417:                         foreach ($sitemap_locales as $locale) {
 418:                             $url = seo_locale::localePath(true, $locale) . '/' . $galleryindex_mod . $x;
 419:                             $data .= sitemap_echonl("\t<url>\n\t\t<loc>" . $url . "</loc>\n\t\t<lastmod>" . sitemap_getISO8601Date() . "</lastmod>\n\t\t<changefreq>" . $changefreq . "</changefreq>\n\t\t<priority>0.9</priority>\n\t</url>");
 420:                         }
 421:                         break;
 422:                     case 2:
 423:                         foreach ($sitemap_locales as $locale) {
 424:                             $url = rewrite_path($galleryindex_mod . $x, $galleryindex_nomod . $x, dynamic_locale::fullHostPath($locale));
 425:                             $data .= sitemap_echonl("\t<url>\n\t\t<loc>" . $url . "</loc>\n\t\t<lastmod>" . sitemap_getISO8601Date() . "</lastmod>\n\t\t<changefreq>" . $changefreq . "</changefreq>\n\t\t<priority>0.9</priority>\n\t</url>");
 426:                         }
 427:                         break;
 428:                     default:
 429:                         $url = rewrite_path($galleryindex_mod . $x, $galleryindex_nomod . $x, FULLWEBPATH);
 430:                         $data .= sitemap_echonl("\t<url>\n\t\t<loc>" . $url . "</loc>\n\t\t<lastmod>" . sitemap_getISO8601Date() . "</lastmod>\n\t\t<changefreq>" . $changefreq . "</changefreq>\n\t\t<priority>0.9</priority>\n\t</url>");
 431:                         break;
 432:                 }
 433:             }
 434:         }
 435:         $data .= sitemap_echonl('</urlset>'); 
 436:         restore_context();
 437:         return $data;
 438:     } 
 439: }
 440: 
 441:  442:  443:  444:  445:  446:  447: 
 448: function getSitemapAlbumList($obj, &$albumlist, $gateway) {
 449:     global $_zp_gallery;
 450:     $locallist = $obj->getAlbums();
 451:     foreach ($locallist as $folder) {
 452:         $album = newAlbum($folder);
 453:         if ($album->getShow() && $gateway($album)) {
 454:             $albumlist[] = array('folder' => $album->name, 'date' => $album->getDateTime(), 'title' => $album->getTitle());
 455:             if (!$album->isDynamic()) {
 456:                 getSitemapAlbumList($album, $albumlist, $gateway);
 457:             }
 458:         }
 459:     }
 460: }
 461: 
 462:  463:  464:  465: 
 466: function passAlbums($album) {
 467:     return true;
 468: }
 469: 
 470:  471:  472:  473: 
 474: function passImages($album) {
 475:     return !$album->isDynamic() && !$album->getPassword();
 476: }
 477: 
 478:  479:  480:  481:  482:  483:  484:  485:  486:  487: 
 488: function getSitemapAlbums() {
 489:     global $_zp_gallery, $sitemap_number;
 490:     $data = '';
 491:     $sitemap_locales = generateLanguageList();
 492:     $albumchangefreq = getOption('sitemap_changefreq_albums');
 493:     $imagechangefreq = getOption('sitemap_changefreq_images');
 494:     $albumlastmod = getOption('sitemap_lastmod_albums');
 495:     $albumlastmod = sanitize($albumlastmod);
 496:     $imagelastmod = getOption('sitemap_lastmod_images');
 497: 
 498:     $albums = array();
 499:     getSitemapAlbumList($_zp_gallery, $albums, 'passAlbums');
 500:     $offset = ($sitemap_number - 1);
 501:     $albums = array_slice($albums, $offset, SITEMAP_CHUNK);
 502:     if (!empty($albums)) {
 503:         $data .= sitemap_echonl('<?xml version="1.0" encoding="UTF-8"?>');
 504:         $data .= sitemap_echonl('<urlset xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.sitemaps.org/schemas/sitemap/0.9 http://www.sitemaps.org/schemas/sitemap/0.9/sitemap.xsd" xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">');
 505:         foreach ($albums as $album) {
 506:             $albumobj = newAlbum($album['folder']);
 507:             set_context(ZP_ALBUM);
 508:             makeAlbumCurrent($albumobj);
 509:             $pageCount = getTotalPages();
 510:             
 511:             
 512:             $date = sitemap_getDateformat($albumobj, $albumlastmod);
 513:             switch (SITEMAP_LOCALE_TYPE) {
 514:                 case 1:
 515:                     foreach ($sitemap_locales as $locale) {
 516:                         $url = seo_locale::localePath(true, $locale) . '/' . pathurlencode($albumobj->name) . '/';
 517:                         $data .= sitemap_echonl("\t<url>\n\t\t<loc>" . $url . "</loc>\n\t\t<lastmod>" . $date . "</lastmod>\n\t\t<changefreq>" . $albumchangefreq . "</changefreq>\n\t\t<priority>0.8</priority>\n");
 518:                         $data .= sitemap_echonl("\t</url>");
 519:                     }
 520:                     break;
 521:                 case 2:
 522:                     foreach ($sitemap_locales as $locale) {
 523:                         $url = rewrite_path(pathurlencode($albumobj->name) . '/', '?album=' . pathurlencode($albumobj->name), dynamic_locale::fullHostPath($locale));
 524:                         $data .= sitemap_echonl("\t<url>\n\t\t<loc>" . $url . "</loc>\n\t\t<lastmod>" . $date . "</lastmod>\n\t\t<changefreq>" . $albumchangefreq . "</changefreq>\n\t\t<priority>0.8</priority>\n");
 525:                         $data .= sitemap_echonl("\t</url>");
 526:                     }
 527:                     break;
 528:                 default:
 529:                     $url = rewrite_path(pathurlencode($albumobj->name) . '/', '?album=' . pathurlencode($albumobj->name), FULLWEBPATH);
 530:                     $data .= sitemap_echonl("\t<url>\n\t\t<loc>" . $url . "</loc>\n\t\t<lastmod>" . $date . "</lastmod>\n\t\t<changefreq>" . $albumchangefreq . "</changefreq>\n\t\t<priority>0.8</priority>\n");
 531:                     $data .= sitemap_echonl("\t</url>");
 532:                     break;
 533:             }
 534:             
 535:             if ($pageCount > 1) {
 536:                 for ($x = 2; $x <= $pageCount; $x++) {
 537:                     switch (SITEMAP_LOCALE_TYPE) {
 538:                         case 1:
 539:                             foreach ($sitemap_locales as $locale) {
 540:                                 $url = seo_locale::localePath(true, $locale) . '/' . pathurlencode($albumobj->name) . '/' . _PAGE_ . '/' . $x . '/';
 541:                                 $data .= sitemap_echonl("\t<url>\n\t\t<loc>" . $url . "</loc>\n\t\t<lastmod>" . $date . "</lastmod>\n\t\t<changefreq>" . $albumchangefreq . "</changefreq>\n\t\t<priority>0.8</priority>\n");
 542:                                 $data .= sitemap_echonl("\t</url>");
 543:                             }
 544:                             break;
 545:                         case 2:
 546:                             foreach ($sitemap_locales as $locale) {
 547:                                 $url = rewrite_path(pathurlencode($albumobj->name) . '/' . _PAGE_ . '/' . $x . '/', '?album=' . pathurlencode($albumobj->name) . '&page=' . $x, dynamic_locale::fullHostPath($locale));
 548:                                 $data .= sitemap_echonl("\t<url>\n\t\t<loc>" . $url . "</loc>\n\t\t<lastmod>" . $date . "</lastmod>\n\t\t<changefreq>" . $albumchangefreq . "</changefreq>\n\t\t<priority>0.8</priority>\n");
 549:                                 $data .= sitemap_echonl("\t</url>");
 550:                             }
 551:                             break;
 552:                         default:
 553:                             $url = rewrite_path(pathurlencode($albumobj->name) . '/' . _PAGE_ . '/' . $x . '/', '?album=' . pathurlencode($albumobj->name) . '&page=' . $x, FULLWEBPATH);
 554:                             $data .= sitemap_echonl("\t<url>\n\t\t<loc>" . $url . "</loc>\n\t\t<lastmod>" . $date . "</lastmod>\n\t\t<changefreq>" . $albumchangefreq . "</changefreq>\n\t\t<priority>0.8</priority>\n");
 555:                             $data .= sitemap_echonl("\t</url>");
 556:                             break;
 557:                     }
 558:                 }
 559:             }
 560:         }
 561:         $data .= sitemap_echonl('</urlset>'); 
 562:     }
 563:     restore_context();
 564:     return $data;
 565: }
 566: 
 567:  568:  569:  570:  571:  572:  573: 
 574: function getSitemapImages() {
 575:     global $_zp_gallery, $sitemap_number;
 576:     $data = '';
 577:     $sitemap_locales = generateLanguageList();
 578:     $imagechangefreq = getOption('sitemap_changefreq_images');
 579:     $imagelastmod = getOption('sitemap_lastmod_images');
 580:     $limit = sitemap_getDBLimit(1);
 581:     $albums = array();
 582:     getSitemapAlbumList($_zp_gallery, $albums, 'passImages');
 583:     $offset = ($sitemap_number - 1);
 584:     $albums = array_slice($albums, $offset, SITEMAP_CHUNK);
 585:     if ($albums) {
 586:         $data .= sitemap_echonl('<?xml version="1.0" encoding="UTF-8"?>');
 587:         if (GOOGLE_SITEMAP) {
 588:             $data .= sitemap_echonl('<urlset xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.sitemaps.org/schemas/sitemap/0.9 http://www.sitemaps.org/schemas/sitemap/0.9/sitemap.xsd" xmlns="http://www.sitemaps.org/schemas/sitemap/0.9" xmlns:image="http://www.google.com/schemas/sitemap-image/1.1" xmlns:video="http://www.google.com/schemas/sitemap-video/1.1">');
 589:         } else {
 590:             $data .= sitemap_echonl('<urlset xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.sitemaps.org/schemas/sitemap/0.9 http://www.sitemaps.org/schemas/sitemap/0.9/sitemap.xsd" xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">');
 591:         }
 592:         foreach ($albums as $album) {
 593:             @set_time_limit(120); 
 594:             $albumobj = newAlbum($album['folder']);
 595:             $images = $albumobj->getImages();
 596:             
 597:             if ($images) {
 598:                 foreach ($images as $image) {
 599:                     $imageobj = newImage($albumobj, $image);
 600:                     $ext = getSuffix($imageobj->filename);
 601:                     $date = sitemap_getDateformat($imageobj, $imagelastmod);
 602:                     switch (SITEMAP_LOCALE_TYPE) {
 603:                         case 1:
 604:                             foreach ($sitemap_locales as $locale) {
 605:                                 $path = seo_locale::localePath(true, $locale) . '/' . pathurlencode($albumobj->name) . '/' . urlencode($imageobj->filename) . IM_SUFFIX;
 606:                                 $data .= sitemap_echonl("\t<url>\n\t\t<loc>" . $path . "</loc>\n\t\t<lastmod>" . $date . "</lastmod>\n\t\t<changefreq>" . $imagechangefreq . "</changefreq>\n\t\t<priority>0.6</priority>\n");
 607:                                 if (GOOGLE_SITEMAP) {
 608:                                     $data .= getSitemapGoogleImageVideoExtras($albumobj, $imageobj, $locale);
 609:                                 }
 610:                                 $data .= sitemap_echonl("</url>");
 611:                             }
 612:                             break;
 613:                         case 2:
 614:                             foreach ($sitemap_locales as $locale) {
 615:                                 $path = rewrite_path(pathurlencode($albumobj->name) . '/' . urlencode($imageobj->filename) . IM_SUFFIX, '?album=' . pathurlencode($albumobj->name) . '&image=' . urlencode($imageobj->filename), dynamic_locale::fullHostPath($locale));
 616:                                 $data .= sitemap_echonl("\t<url>\n\t\t<loc>" . $path . "</loc>\n\t\t<lastmod>" . $date . "</lastmod>\n\t\t<changefreq>" . $imagechangefreq . "</changefreq>\n\t\t<priority>0.6</priority>\n");
 617:                                 if (GOOGLE_SITEMAP) {
 618:                                     $data .= getSitemapGoogleImageVideoExtras($albumobj, $imageobj, $locale);
 619:                                 }
 620:                                 $data .= sitemap_echonl("</url>");
 621:                             }
 622:                             break;
 623:                         default:
 624:                             $path = rewrite_path(pathurlencode($albumobj->name) . '/' . urlencode($imageobj->filename) . IM_SUFFIX, '?album=' . pathurlencode($albumobj->name) . '&image=' . urlencode($imageobj->filename), FULLWEBPATH);
 625:                             $data .= sitemap_echonl("\t<url>\n\t\t<loc>" . $path . "</loc>\n\t\t<lastmod>" . $date . "</lastmod>\n\t\t<changefreq>" . $imagechangefreq . "</changefreq>\n\t\t<priority>0.6</priority>\n");
 626:                             if (GOOGLE_SITEMAP) {
 627:                                 $data .= getSitemapGoogleImageVideoExtras($albumobj, $imageobj, NULL);
 628:                             }
 629:                             $data .= sitemap_echonl("</url>");
 630:                             break;
 631:                     }
 632:                 }
 633:             }
 634:         }
 635:         $data .= sitemap_echonl('</urlset>'); 
 636:     }
 637:     return $data;
 638: }
 639: 
 640:  641:  642: 
 643: function getSitemapGoogleLoopIndex($imageCount, $pageCount) {
 644:     if (GOOGLE_SITEMAP) {
 645:         $loop_index = array();
 646:         for ($x = 1; $x <= $pageCount; $x++) {
 647:             if ($imageCount < ($x * getOption('images_per_page'))) {
 648:                 $val = $imageCount - (($x - 1) * getOption('images_per_page'));
 649:             } else {
 650:                 $val = getOption('images_per_page');
 651:             }
 652:             array_push($loop_index, $val);
 653:         }
 654:         return $loop_index;
 655:     }
 656:     return NULL;
 657: }
 658: 
 659:  660:  661:  662: 
 663: function getSitemapGoogleImageVideoExtras($albumobj, $imageobj, $locale) {
 664:     $data = '';
 665:     $host = PROTOCOL . '://' . html_encode($_SERVER["HTTP_HOST"]);
 666:     $ext = strtolower(strrchr($imageobj->filename, "."));
 667:     $location = '';
 668:     if ($imageobj->getLocation()) {
 669:         $location .= $imageobj->getLocation($locale) . ', ';
 670:     }
 671:     if ($imageobj->getCity()) {
 672:         $location .= $imageobj->getCity($locale) . ', ';
 673:     }
 674:     if ($imageobj->getState()) {
 675:         $location .= $imageobj->getState($locale) . ', ';
 676:     }
 677:     if ($imageobj->getCountry()) {
 678:         $location .= $imageobj->getCountry($locale);
 679:     }
 680:     $license = get_language_string(getOption('sitemap_license'), $locale);
 681:     if (isImageVideo($imageobj) && in_array($ext, array('.mpg', '.mpeg', '.mp4', '.m4v', '.mov', '.wmv', '.asf', '.avi', '.ra', '.ram', '.flv', '.swf'))) { 
 682:         $data .= sitemap_echonl("\t\t<video:video>\n\t\t\t<video:thumbnail_loc>" . $host . html_encode($imageobj->getThumb()) . "</video:thumbnail_loc>\n");
 683:         $data .= sitemap_echonl("\t\t\t<video:title>" . html_encode($imageobj->getTitle($locale)) . "</video:title>");
 684:         if ($imageobj->getDesc()) {
 685:             $data .= sitemap_echonl("\t\t\t<video:description>" . html_encode(getBare($imageobj->getDesc($locale))) . "</video:description>");
 686:         }
 687:         $data .= sitemap_echonl("\t\t\t<video:content_loc>" . $host . pathurlencode($imageobj->getFullImageURL()) . "</video:content_loc>");
 688:         $data .= sitemap_echonl("\t\t</video:video>");
 689:     } else if (in_array($ext, array('.jpg', '.jpeg', '.gif', '.png'))) { 
 690:         if(getOption('sitemap_google_fullimage')) {
 691:             $imagelocation = $host . pathurlencode($imageobj->getFullImageURL());
 692:         } else {
 693:             $imagelocation = $host . html_encode($imageobj->getSizedImage(getOption('image_size')));
 694:         }
 695:         $data .= sitemap_echonl("\t\t<image:image>\n\t\t\t<image:loc>" . $imagelocation . "</image:loc>\n");
 696:         
 697:         $data .= sitemap_echonl("\t\t\t<image:title>" . html_encode($imageobj->getTitle($locale)) . "</image:title>");
 698:         if ($imageobj->getDesc()) {
 699:             $data .= sitemap_echonl("\t\t\t<image:caption>" . html_encode(getBare($imageobj->getDesc($locale))) . "</image:caption>");
 700:         }
 701:         if (!empty($license)) {
 702:             $data .= sitemap_echonl("\t\t\t<image:license>" . $license . "</image:license>");
 703:         }
 704:         
 705:         if (!empty($location)) {
 706:             $data .= sitemap_echonl("\t\t\t<image:geo_location>" . $location . "</image:geo_location>");
 707:         }
 708:         $data .= sitemap_echonl("\t\t</image:image>");
 709:     }
 710:     return $data;
 711: }
 712: 
 713:  714:  715:  716:  717: 
 718: function getSitemapZenpagePages() {
 719:     global $_zp_zenpage, $sitemap_number;
 720:     
 721:     if ($sitemap_number == 1) {
 722:         $data = '';
 723:         $limit = sitemap_getDBLimit(2);
 724:         $sitemap_locales = generateLanguageList();
 725:         $changefreq = getOption('sitemap_changefreq_pages');
 726:         $pages = $_zp_zenpage->getPages(true);
 727:         if ($pages) {
 728:             $data .= sitemap_echonl('<?xml version="1.0" encoding="UTF-8"?>');
 729:             $data .= sitemap_echonl('<urlset xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.sitemaps.org/schemas/sitemap/0.9 http://www.sitemaps.org/schemas/sitemap/0.9/sitemap.xsd" xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">');
 730:             foreach ($pages as $page) {
 731:                 $pageobj = new ZenpagePage($page['titlelink']);
 732:                 $date = substr($pageobj->getDatetime(), 0, 10);
 733:                 $lastchange = '';
 734:                 if (!is_null($pageobj->getLastchange()))
 735:                     $lastchange = substr($pageobj->getLastchange(), 0, 10);
 736:                 if ($date > $lastchange && !empty($lastchangedate))
 737:                     $date = $lastchange;
 738:                 if (!$pageobj->isProtected()) {
 739:                     switch (SITEMAP_LOCALE_TYPE) {
 740:                         case 1:
 741:                             foreach ($sitemap_locales as $locale) {
 742:                                 $url = seo_locale::localePath(true, $locale) . '/' . _PAGES_ . '/' . urlencode($page['titlelink']);
 743:                                 $data .= sitemap_echonl("\t<url>\n\t\t<loc>" . $url . "</loc>\n\t\t<lastmod>" . $date . "</lastmod>\n\t\t<changefreq>" . $changefreq . "</changefreq>\n\t\t<priority>0.9</priority>\n\t</url>");
 744:                             }
 745:                             break;
 746:                         case 2:
 747:                             foreach ($sitemap_locales as $locale) {
 748:                                 $url = rewrite_path(_PAGES_ . '/' . urlencode($page['titlelink']), '?p=pages&title=' . urlencode($page['titlelink']), dynamic_locale::fullHostPath($locale));
 749:                                 $data .= sitemap_echonl("\t<url>\n\t\t<loc>" . $url . "</loc>\n\t\t<lastmod>" . $date . "</lastmod>\n\t\t<changefreq>" . $changefreq . "</changefreq>\n\t\t<priority>0.9</priority>\n\t</url>");
 750:                             }
 751:                             break;
 752:                         default:
 753:                             $url = rewrite_path(_PAGES_ . '/' . urlencode($page['titlelink']), '?p=pages&title=' . urlencode($page['titlelink']), FULLWEBPATH);
 754:                             $data .= sitemap_echonl("\t<url>\n\t\t<loc>" . $url . "</loc>\n\t\t<lastmod>" . $date . "</lastmod>\n\t\t<changefreq>" . $changefreq . "</changefreq>\n\t\t<priority>0.9</priority>\n\t</url>");
 755:                             break;
 756:                     }
 757:                 }
 758:             }
 759:             $data .= sitemap_echonl('</urlset>'); 
 760:         }
 761:         return $data;
 762:     }
 763: }
 764: 
 765:  766:  767:  768:  769: 
 770: function getSitemapZenpageNewsIndex() {
 771:     global $_zp_zenpage, $sitemap_number;
 772:     
 773:     if ($sitemap_number == 1) {
 774:         $data = '';
 775:         $data .= sitemap_echonl('<?xml version="1.0" encoding="UTF-8"?>');
 776:         $data .= sitemap_echonl('<urlset xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.sitemaps.org/schemas/sitemap/0.9 http://www.sitemaps.org/schemas/sitemap/0.9/sitemap.xsd" xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">');
 777:         $sitemap_locales = generateLanguageList();
 778:         $changefreq = getOption('sitemap_changefreq_newsindex');
 779:         switch (SITEMAP_LOCALE_TYPE) {
 780:             case 1:
 781:                 foreach ($sitemap_locales as $locale) {
 782:       $url = seo_locale::localePath(true, $locale) . '/' . _NEWS_ . '/1';
 783:           $data .= sitemap_echonl("\t<url>\n\t\t<loc>" . $url . "</loc>\n\t\t<lastmod>" . sitemap_getISO8601Date() . "</lastmod>\n\t\t<changefreq>" . $changefreq . "</changefreq>\n\t\t<priority>0.9</priority>\n\t</url>");
 784:                 }
 785:                 Break;
 786:             case 2:
 787:                 foreach ($sitemap_locales as $locale) {
 788:                     $url = rewrite_path(_NEWS_ . '/1', '?p=news&page=1', dynamic_locale::fullHostPath($locale));
 789:                     $data .= sitemap_echonl("\t<url>\n\t\t<loc>" . $url . "</loc>\n\t\t<lastmod>" . sitemap_getISO8601Date() . "</lastmod>\n\t\t<changefreq>" . $changefreq . "</changefreq>\n\t\t<priority>0.9</priority>\n\t</url>");
 790:                 }
 791:                 Break;
 792:             default:
 793:                 $url = rewrite_path(_NEWS_ . '/1', '?p=news&page=1', FULLWEBPATH);
 794:                 $data .= sitemap_echonl("\t<url>\n\t\t<loc>" . $url . "</loc>\n\t\t<lastmod>" . sitemap_getISO8601Date() . "</lastmod>\n\t\t<changefreq>" . $changefreq . "</changefreq>\n\t\t<priority>0.9</priority>\n\t</url>");
 795:                 Break;
 796:         }
 797:         
 798:          799:  800:  801:  802:  803: 
 804:         $zenpage_articles_per_page = ZP_ARTICLES_PER_PAGE;
 805:         $newspages = ceil($_zp_zenpage->getTotalArticles() / $zenpage_articles_per_page);
 806:         if ($newspages > 1) {
 807:             for ($x = 2; $x <= $newspages; $x++) {
 808:                 switch (SITEMAP_LOCALE_TYPE) {
 809:                     case 1:
 810:                         foreach ($sitemap_locales as $locale) {
 811:                             $url = seo_locale::localePath(true, $locale) . '/' . _NEWS_ . '/' . $x;
 812:                             $data .= sitemap_echonl("\t<url>\n\t\t<loc>" . $url . "</loc>\n\t\t<lastmod>" . sitemap_getISO8601Date() . "</lastmod>\n\t\t<changefreq>" . $changefreq . "</changefreq>\n\t\t<priority>0.9</priority>\n\t</url>");
 813:                         }
 814:                         break;
 815:                     case 2:
 816:                         foreach ($sitemap_locales as $locale) {
 817:                             $url = rewrite_path(_NEWS_ . '/' . $x, '?p=news&page=' . $x, dynamic_locale::fullHostPath($locale));
 818:                             $data .= sitemap_echonl("\t<url>\n\t\t<loc>" . $url . "</loc>\n\t\t<lastmod>" . sitemap_getISO8601Date() . "</lastmod>\n\t\t<changefreq>" . $changefreq . "</changefreq>\n\t\t<priority>0.9</priority>\n\t</url>");
 819:                         }
 820:                         break;
 821:                     default:
 822:                         $url = rewrite_path(_NEWS_ . '/' . $x, '?p=news&page=' . $x, FULLWEBPATH);
 823:                         $data .= sitemap_echonl("\t<url>\n\t\t<loc>" . $url . "</loc>\n\t\t<lastmod>" . sitemap_getISO8601Date() . "</lastmod>\n\t\t<changefreq>" . $changefreq . "</changefreq>\n\t\t<priority>0.9</priority>\n\t</url>");
 824:                         break;
 825:                 }
 826:             }
 827:         }
 828:         $data .= sitemap_echonl('</urlset>'); 
 829:         return $data;
 830:     }
 831: }
 832: 
 833:  834:  835:  836:  837:  838: 
 839: function getSitemapZenpageNewsArticles() {
 840:     global $_zp_zenpage, $sitemap_number;
 841:     
 842:     if ($sitemap_number == 1) {
 843:         $data = '';
 844:         $sitemap_locales = generateLanguageList();
 845:         $changefreq = getOption('sitemap_changefreq_news');
 846:         $articles = $_zp_zenpage->getArticles('', 'published', true, "date", "desc");
 847:         if ($articles) {
 848:             $data .= sitemap_echonl('<?xml version="1.0" encoding="UTF-8"?>');
 849:             $data .= sitemap_echonl('<urlset xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.sitemaps.org/schemas/sitemap/0.9 http://www.sitemaps.org/schemas/sitemap/0.9/sitemap.xsd" xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">');
 850:             foreach ($articles as $article) {
 851:                 $articleobj = new ZenpageNews($article['titlelink']);
 852:                 $date = substr($articleobj->getDatetime(), 0, 10);
 853:                 $lastchange = '';
 854:                 if (!is_null($articleobj->getLastchange()))
 855:                     $lastchange = substr($articleobj->getLastchange(), 0, 10);
 856:                 if ($date > $lastchange && !empty($lastchangedate))
 857:                     $date = $lastchange;
 858:                 if (!$articleobj->inProtectedCategory()) {
 859:                     switch (SITEMAP_LOCALE_TYPE) {
 860:                         case 1:
 861:                             foreach ($sitemap_locales as $locale) {
 862:                                 $url = seo_locale::localePath(true, $locale) . '/' . _NEWS_ . '/' . urlencode($articleobj->getTitlelink());
 863:                                 $data .= sitemap_echonl("\t<url>\n\t\t<loc>" . $url . "</loc>\n\t\t<lastmod>" . $date . "</lastmod>\n\t\t<changefreq>" . $changefreq . "</changefreq>\n\t\t<priority>0.9</priority>\n\t</url>");
 864:                             }
 865:                             break;
 866:                         case 2:
 867:                             foreach ($sitemap_locales as $locale) {
 868:                                 $url = rewrite_path(_NEWS_ . '/' . urlencode($articleobj->getTitlelink()), '?p=news&title=' . urlencode($articleobj->getTitlelink()), dynamic_locale::fullHostPath($locale));
 869:                                 $data .= sitemap_echonl("\t<url>\n\t\t<loc>" . $url . "</loc>\n\t\t<lastmod>" . $date . "</lastmod>\n\t\t<changefreq>" . $changefreq . "</changefreq>\n\t\t<priority>0.9</priority>\n\t</url>");
 870:                             }
 871:                             break;
 872:                         default:
 873:                             $url = rewrite_path(_NEWS_ . '/' . urlencode($articleobj->getTitlelink()), '?p=news&title=' . urlencode($articleobj->getTitlelink()), FULLWEBPATH);
 874:                             $data .= sitemap_echonl("\t<url>\n\t\t<loc>" . $url . "</loc>\n\t\t<lastmod>" . $date . "</lastmod>\n\t\t<changefreq>" . $changefreq . "</changefreq>\n\t\t<priority>0.9</priority>\n\t</url>");
 875:                             break;
 876:                     }
 877:                 }
 878:             }
 879:             $data .= sitemap_echonl('</urlset>'); 
 880:         }
 881:         return $data;
 882:     }
 883: }
 884: 
 885:  886:  887:  888:  889: 
 890: function getSitemapZenpageNewsCategories() {
 891:     global $_zp_zenpage, $sitemap_number;
 892:     
 893:     if ($sitemap_number == 1) {
 894:         $data = '';
 895:         $sitemap_locales = generateLanguageList();
 896:         $changefreq = getOption('sitemap_changefreq_newscats');
 897:         $newscats = $_zp_zenpage->getAllCategories();
 898:         if ($newscats) {
 899:             $data .= sitemap_echonl('<?xml version="1.0" encoding="UTF-8"?>');
 900:             $data .= sitemap_echonl('<urlset xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.sitemaps.org/schemas/sitemap/0.9 http://www.sitemaps.org/schemas/sitemap/0.9/sitemap.xsd" xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">');
 901:             foreach ($newscats as $newscat) {
 902:                 $catobj = new ZenpageCategory($newscat['titlelink']);
 903:                 if (!$catobj->isProtected()) {
 904:                     switch (SITEMAP_LOCALE_TYPE) {
 905:                         case 1:
 906:                             foreach ($sitemap_locales as $locale) {
 907:                                 $url = seo_locale::localePath(true, $locale) . '/' . _CATEGORY_ . '/' . urlencode($catobj->getTitlelink()) . '/1';
 908:                                 $data .= sitemap_echonl("\t<url>\n\t\t<loc>" . $url . "</loc>\n\t\t<changefreq>" . $changefreq . "</changefreq>\n\t\t<priority>0.9</priority>\n\t</url>");
 909:                             }
 910:                             break;
 911:                         case 2:
 912:                             foreach ($sitemap_locales as $locale) {
 913:                                 $url = rewrite_path(_CATEGORY_ . '/' . urlencode($catobj->getTitlelink()) . '/1', '?p=news&category=' . urlencode($catobj->getTitlelink()) . '&page=1', dynamic_locale::fullHostPath($locale));
 914:                                 $data .= sitemap_echonl("\t<url>\n\t\t<loc>" . $url . "</loc>\n\t\t<changefreq>" . $changefreq . "</changefreq>\n\t\t<priority>0.9</priority>\n\t</url>");
 915:                             }
 916:                             break;
 917:                         default:
 918:                             $url = rewrite_path(_CATEGORY_ . '/' . urlencode($catobj->getTitlelink()) . '/1', '?p=news&category=' . urlencode($catobj->getTitlelink()) . '&page=1', FULLWEBPATH);
 919:                             $data .= sitemap_echonl("\t<url>\n\t\t<loc>" . $url . "</loc>\n\t\t<changefreq>" . $changefreq . "</changefreq>\n\t\t<priority>0.9</priority>\n\t</url>");
 920:                             break;
 921:                     }
 922:                     
 923:                      924:  925:  926:  927:  928: 
 929:                     $zenpage_articles_per_page = ZP_ARTICLES_PER_PAGE;
 930:                     $articlecount = count($catobj->getArticles());
 931:                     $catpages = ceil($articlecount / $zenpage_articles_per_page);
 932:                     if ($catpages > 1) {
 933:                         for ($x = 2; $x <= $catpages; $x++) {
 934:                             switch (SITEMAP_LOCALE_TYPE) {
 935:                                 case 1:
 936:                                     foreach ($sitemap_locales as $locale) {
 937:                                         $url = seo_locale::localePath(true, $locale) . '/' . _CATEGORY_ . '/' . urlencode($catobj->getTitlelink()) . '/' . $x;
 938:                                         $data .= sitemap_echonl("\t<url>\n\t\t<loc>" . $url . "</loc>\n\t\t<changefreq>" . $changefreq . "</changefreq>\n\t\t<priority>0.9</priority>\n\t</url>");
 939:                                     }
 940:                                     break;
 941:                                 case 2:
 942:                                     foreach ($sitemap_locales as $locale) {
 943:                                         $url = rewrite_path(_CATEGORY_ . '/' . urlencode($catobj->getTitlelink()) . '/' . $x, '?p=news&category=' . urlencode($catobj->getTitlelink()) . '&page=' . $x, dynamic_locale::fullHostPath($locale));
 944:                                         $data .= sitemap_echonl("\t<url>\n\t\t<loc>" . $url . "</loc>\n\t\t<changefreq>" . $changefreq . "</changefreq>\n\t\t<priority>0.9</priority>\n\t</url>");
 945:                                     }
 946:                                     break;
 947:                                 default:
 948:                                     $url = rewrite_path(_CATEGORY_ . '/' . urlencode($catobj->getTitlelink()) . '/' . $x, '?p=news&category=' . urlencode($catobj->getTitlelink()) . '&page=' . $x, FULLWEBPATH);
 949:                                     $data .= sitemap_echonl("\t<url>\n\t\t<loc>" . $url . "</loc>\n\t\t<changefreq>" . $changefreq . "</changefreq>\n\t\t<priority>0.9</priority>\n\t</url>");
 950:                                     break;
 951:                             }
 952:                         }
 953:                     }
 954:                 }
 955:             }
 956:             $data .= sitemap_echonl('</urlset>'); 
 957:         }
 958:         return $data;
 959:     }
 960: }
 961: 
 962:  963:  964:  965: 
 966: function clearSitemapCache() {
 967:     $cachefolder = SERVERPATH . '/' . STATIC_CACHE_FOLDER . '/sitemap/';
 968:     if (is_dir($cachefolder)) {
 969:         $handle = opendir($cachefolder);
 970:         while (false !== ($filename = readdir($handle))) {
 971:             $fullname = $cachefolder . '/' . $filename;
 972:             if (is_dir($fullname) && !(substr($filename, 0, 1) == '.')) {
 973:                 if (($filename != '.') && ($filename != '..')) {
 974:                     RSS::clearRSSCache($fullname);
 975:                     rmdir($fullname);
 976:                 }
 977:             } else {
 978:                 if (file_exists($fullname) && !(substr($filename, 0, 1) == '.')) {
 979:                     @chmod($fullname, 0777);
 980:                     unlink($fullname);
 981:                 }
 982:             }
 983:         }
 984:         closedir($handle);
 985:     }
 986: }
 987: 
 988:  989:  990:  991:  992:  993:  994:  995: 
 996: function sitemap_getISO8601Date($date = '') {
 997:     if (empty($date)) {
 998:         return gmstrftime('%Y-%m-%dT%H:%M:%SZ');
 999:     } else {
1000:         return gmstrftime('%Y-%m-%dT%H:%M:%SZ', strtotime($date));
1001:     }
1002: }
1003: