/** * Parses a sitemap entry * @param XTemplate $t CoTemplate object * @param int &$items Total items count * @param array $item Item to be rendered */ function sitemap_parse($t, &$items, $item) { global $cfg; $perpage = (int) $cfg['plugin']['sitemap']['perpage']; if ($items > 0 && $items % $perpage == 0) { // Save previous page $d = $items / $perpage - 1; $t->parse(); sitemap_save($t->text(), $d); // Start another $t->reset(); } // Parse another row $t->assign(array('SITEMAP_ROW_URL' => strpos($item['url'], '://') === false ? COT_ABSOLUTE_URL . $item['url'] : $item['url'], 'SITEMAP_ROW_DATE' => sitemap_date($item['date']), 'SITEMAP_ROW_FREQ' => sitemap_freq($item['freq']), 'SITEMAP_ROW_PRIO' => sitemap_prio($item['prio']))); $t->parse('MAIN.SITEMAP_ROW'); $items++; }
} /* ===== */ $sitemap_where = count($sitemap_where) > 0 ? 'WHERE ' . join(' AND ', $sitemap_where) : ''; $res = $db->query("SELECT u.user_id, u.user_name {$sitemap_join_columns}\n\t\t\tFROM {$db_users} AS u {$sitemap_join_tables}\n\t\t\t{$sitemap_where}\n\t\t\tORDER BY user_id"); foreach ($res->fetchAll() as $row) { sitemap_parse($t, $items, array('url' => cot_url('users', array('m' => 'details', 'id' => $row['user_id'], 'u' => $row['user_name'])), 'date' => '', 'freq' => $cfg['plugin']['sitemap']['users_freq'], 'prio' => $cfg['plugin']['sitemap']['users_prio'])); } } /* === Hook === */ foreach (cot_getextplugins('sitemap.main') as $pl) { include $pl; } /* ===== */ // Save the last page $t->parse(); sitemap_save($t->text(), (int) ceil($items / $perpage) - 1); // Save count file file_put_contents($count_file, $items); } if ($a == 'index') { // Show sitemap index $t = new XTemplate(cot_tplfile('sitemap.index', 'plug')); $pages = (int) ceil($items / $perpage); foreach (range(0, $pages - 1) as $pg) { $durl = $pg > 0 ? "&d={$pg}" : ''; $filename = $pg > 0 ? $cfg['cache_dir'] . "/sitemap/sitemap.{$pg}.xml" : $cfg['cache_dir'] . "/sitemap/sitemap.xml"; $t->assign(array('SITEMAP_ROW_URL' => COT_ABSOLUTE_URL . cot_url('plug', 'r=sitemap' . $durl), 'SITEMAP_ROW_DATE' => sitemap_date(filemtime($filename)))); $t->parse('MAIN.SITEMAP_ROW'); } $t->parse(); echo sitemap_compress($t->text());