[3417] | 1 | <?php |
---|
| 2 | defined('PHPWG_ROOT_PATH') or die('Hacking attempt!'); |
---|
| 3 | |
---|
[8984] | 4 | define('RVS_DIR' , basename(dirname(__FILE__))); |
---|
| 5 | define('RVS_PATH' , PHPWG_PLUGINS_PATH . RVS_DIR . '/'); |
---|
| 6 | load_language('plugin.lang', RVS_PATH); |
---|
| 7 | |
---|
[3417] | 8 | function sitemaps_get_config_file_name() |
---|
| 9 | { |
---|
| 10 | global $conf; |
---|
| 11 | $dir = $conf['local_data_dir'].'/plugins/'; |
---|
| 12 | mkgetdir( $dir ); |
---|
| 13 | return $dir.basename(dirname(__FILE__)).'.dat'; |
---|
| 14 | } |
---|
| 15 | |
---|
| 16 | function start_xml($filename, $gzip) |
---|
| 17 | { |
---|
| 18 | global $file; |
---|
| 19 | $file = fopen( $filename.($gzip?'.gz':''), 'w' ); |
---|
| 20 | out_xml('<?xml version="1.0" encoding="UTF-8"?'.'> |
---|
| 21 | <?xml-stylesheet type="text/xsl" href="'.get_root_url().'plugins/'.basename(dirname(__FILE__)).'/sitemap.xsl"?'.'> |
---|
| 22 | <urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">', $gzip ); |
---|
| 23 | } |
---|
| 24 | |
---|
| 25 | function out_xml($xml, $gzip) |
---|
| 26 | { |
---|
| 27 | global $file; |
---|
| 28 | if ($gzip) |
---|
| 29 | fwrite($file, gzencode($xml, 9) ); |
---|
| 30 | else |
---|
| 31 | fwrite($file, $xml); |
---|
| 32 | } |
---|
| 33 | |
---|
| 34 | function end_xml($gzip) |
---|
| 35 | { |
---|
| 36 | global $file; |
---|
| 37 | out_xml('</urlset>',$gzip ); |
---|
| 38 | fclose( $file ); |
---|
| 39 | } |
---|
| 40 | |
---|
| 41 | function add_url($url, $lastmod=null, $changefreq=null, $priority=null) |
---|
| 42 | { |
---|
| 43 | $xml= |
---|
| 44 | '<url> |
---|
| 45 | <loc>'.$url.'</loc>'; |
---|
| 46 | |
---|
| 47 | if ( isset($lastmod) and strlen($lastmod)>0 ) |
---|
| 48 | { |
---|
| 49 | if (strlen($lastmod)>11) |
---|
| 50 | { |
---|
| 51 | $lastmod[10] = 'T'; |
---|
| 52 | if (strlen($lastmod)==19) |
---|
| 53 | $lastmod .= '-05:00'; |
---|
| 54 | } |
---|
| 55 | $xml.=' |
---|
| 56 | <lastmod>'.$lastmod.'</lastmod>'; |
---|
| 57 | } |
---|
| 58 | |
---|
| 59 | if ( isset($changefreq) and $changefreq!='' ) $xml.=' |
---|
| 60 | <changefreq>'.$changefreq.'</changefreq>'; |
---|
| 61 | |
---|
| 62 | if ( isset($priority) and $priority!='' ) $xml.=' |
---|
| 63 | <priority>'.$priority.'</priority>'; |
---|
| 64 | |
---|
| 65 | $xml .= ' |
---|
| 66 | </url>'; |
---|
| 67 | global $gzip,$url_count; |
---|
| 68 | $url_count++; |
---|
| 69 | out_xml($xml, $gzip); |
---|
| 70 | } |
---|
| 71 | |
---|
| 72 | |
---|
| 73 | |
---|
| 74 | include_once(PHPWG_ROOT_PATH.'admin/include/functions.php'); |
---|
| 75 | check_status(ACCESS_ADMINISTRATOR); |
---|
| 76 | |
---|
| 77 | |
---|
| 78 | |
---|
[8984] | 79 | $frequenciesT = array( |
---|
| 80 | '', |
---|
| 81 | l10n('always'), |
---|
| 82 | l10n('hourly'), |
---|
| 83 | l10n('daily'), |
---|
| 84 | l10n('weekly'), |
---|
| 85 | l10n('monthly'), |
---|
| 86 | l10n('yearly'), |
---|
| 87 | l10n('never'), |
---|
| 88 | ); |
---|
| 89 | |
---|
[3417] | 90 | $frequencies = array( |
---|
| 91 | '', |
---|
| 92 | 'always', |
---|
| 93 | 'hourly', |
---|
| 94 | 'daily', |
---|
| 95 | 'weekly', |
---|
| 96 | 'monthly', |
---|
| 97 | 'yearly', |
---|
| 98 | 'never', |
---|
| 99 | ); |
---|
[8984] | 100 | |
---|
[3417] | 101 | $specials = array( |
---|
[6260] | 102 | 'categories' => array('L'=>l10n('Home'), 'P'=>0.9), |
---|
[8984] | 103 | 'best_rated' => array('L'=>l10n('Best rated'), 'P'=>0.8 ) , |
---|
[6260] | 104 | 'most_visited' => array('L'=>l10n('Most visited'), 'P'=>0.8 ), |
---|
[8666] | 105 | 'recent_pics' => array('L'=>l10n('Recent photos'), 'P'=>0.8, 'F'=>'weekly' ), |
---|
[3417] | 106 | 'tags' => array('L'=>l10n('Tags'), 'PAGE'=>'tags' . ($conf['php_extension_in_urls'] ? '.php' : '' ), 'P'=>0.8 ), |
---|
| 107 | ); |
---|
| 108 | |
---|
| 109 | $url_count=0; |
---|
| 110 | |
---|
| 111 | // BEGIN AS GUEST |
---|
| 112 | $save_user = $user; |
---|
| 113 | $user = build_user( $conf['guest_id'], true); |
---|
| 114 | |
---|
| 115 | $query = ' |
---|
| 116 | SELECT id, name, permalink, uppercats, global_rank, IFNULL(date_last, max_date_last) AS date_last |
---|
| 117 | FROM '.CATEGORIES_TABLE.' INNER JOIN '.USER_CACHE_CATEGORIES_TABLE.' |
---|
| 118 | ON id = cat_id AND user_id = '.$conf['guest_id'].' |
---|
| 119 | WHERE max_date_last IS NOT NULL |
---|
| 120 | ORDER BY global_rank'; |
---|
| 121 | $result = pwg_query($query); |
---|
| 122 | $categories = array(); |
---|
| 123 | while ($row = mysql_fetch_assoc($result)) |
---|
| 124 | { |
---|
| 125 | array_push($categories, $row); |
---|
| 126 | } |
---|
| 127 | usort($categories, 'global_rank_compare'); |
---|
| 128 | |
---|
| 129 | $tags = get_available_tags(); |
---|
| 130 | usort($tags, 'name_compare'); |
---|
| 131 | |
---|
| 132 | // END AS GUEST |
---|
| 133 | $user = $save_user; |
---|
| 134 | |
---|
| 135 | if ( isset($_POST['submit']) ) |
---|
| 136 | { |
---|
| 137 | // echo('<pre>'.var_export($_POST,true).'</pre>' ); |
---|
| 138 | |
---|
| 139 | if ( $_POST['filename'] != '' ) |
---|
| 140 | $filename = $_POST['filename']; |
---|
| 141 | $gzip = @$_POST['gzip']=='on' ? true : false; |
---|
| 142 | |
---|
| 143 | $selected_specials = array(); |
---|
| 144 | foreach ($specials as $key=>$value) |
---|
| 145 | { |
---|
| 146 | if ( @$_POST['special_'.$key]=='on' ) |
---|
| 147 | array_push( $selected_specials, $key ); |
---|
| 148 | $specials[$key]['P'] = $_POST['special_prio_'.$key]; |
---|
| 149 | $specials[$key]['F'] = $_POST['special_freq_'.$key]; |
---|
| 150 | } |
---|
| 151 | if ( isset($_POST['categories']) ) |
---|
| 152 | $selected_categories = $_POST['categories']; |
---|
| 153 | else |
---|
| 154 | $selected_categories = array(); |
---|
| 155 | $prio_categories = $_POST['prio_categories']; |
---|
| 156 | $freq_categories = $_POST['freq_categories']; |
---|
| 157 | |
---|
| 158 | if ( isset($_POST['tags']) ) |
---|
| 159 | $selected_tags = $_POST['tags']; |
---|
| 160 | else |
---|
| 161 | $selected_tags = array(); |
---|
| 162 | $prio_tags = $_POST['prio_tags']; |
---|
| 163 | $freq_tags = $_POST['freq_tags']; |
---|
| 164 | |
---|
| 165 | set_make_full_url(); |
---|
| 166 | |
---|
| 167 | start_xml($filename, $gzip); |
---|
| 168 | |
---|
| 169 | $r_selected_specials = array_flip($selected_specials); |
---|
| 170 | foreach ($specials as $key=>$value) |
---|
| 171 | { |
---|
| 172 | if (! isset ($r_selected_specials[$key]) ) |
---|
| 173 | continue; |
---|
| 174 | if ( isset($value['PAGE']) ) |
---|
| 175 | $url = get_root_url().$value['PAGE']; |
---|
| 176 | else |
---|
| 177 | $url = make_index_url( array('section'=>$key) ); |
---|
| 178 | add_url($url, null, $value['F'], $value['P'] ); |
---|
| 179 | } |
---|
| 180 | |
---|
| 181 | |
---|
| 182 | $r_selected_categories = array_flip($selected_categories); |
---|
| 183 | foreach ($categories as $cat) |
---|
| 184 | { |
---|
| 185 | if (! isset ($r_selected_categories[$cat['id']]) ) |
---|
| 186 | continue; |
---|
| 187 | |
---|
| 188 | $url = make_index_url( |
---|
| 189 | array( |
---|
| 190 | 'category'=>$cat |
---|
| 191 | ) |
---|
| 192 | ); |
---|
| 193 | add_url($url, $cat['date_last'], $freq_categories, $prio_categories); |
---|
| 194 | } |
---|
| 195 | |
---|
| 196 | $r_selected_tags = array_flip($selected_tags); |
---|
| 197 | if ( !empty($selected_tags) ) |
---|
| 198 | { |
---|
| 199 | $query = 'SELECT tag_id, MAX(date_available) AS da, MAX(date_creation) AS dc, MAX(date_metadata_update) AS dm |
---|
| 200 | FROM '.IMAGE_TAG_TABLE.' INNER JOIN '.IMAGES_TABLE.' ON image_id=id |
---|
| 201 | WHERE tag_id IN ('.implode(',',$selected_tags).') |
---|
| 202 | GROUP BY tag_id'; |
---|
| 203 | $result = pwg_query($query); |
---|
| 204 | $tag_infos = array(); |
---|
| 205 | while ($row = mysql_fetch_assoc($result)) |
---|
| 206 | { |
---|
| 207 | $tag_infos[$row['tag_id']]= max( $row['da'],$row['dc'],$row['dm']); |
---|
| 208 | } |
---|
| 209 | |
---|
| 210 | foreach( $tags as $tag) |
---|
| 211 | { |
---|
| 212 | if (!isset($r_selected_tags[ $tag['id'] ] ) ) |
---|
| 213 | continue; |
---|
| 214 | |
---|
| 215 | $url = make_index_url( |
---|
| 216 | array( |
---|
| 217 | 'section'=>'tags', |
---|
| 218 | 'tags'=> array( $tag ) |
---|
| 219 | ) |
---|
| 220 | ); |
---|
| 221 | |
---|
| 222 | add_url($url, $tag_infos[ $tag['id'] ], $freq_tags, $prio_tags); |
---|
| 223 | } |
---|
| 224 | } |
---|
| 225 | unset_make_full_url(); |
---|
| 226 | end_xml($gzip); |
---|
| 227 | |
---|
| 228 | $page['infos'][] = $url_count.' urls saved'; |
---|
| 229 | |
---|
| 230 | // save the data for future use |
---|
| 231 | $selected_tag_urls = array(); |
---|
| 232 | foreach( $tags as $tag) |
---|
| 233 | { |
---|
| 234 | if (isset($r_selected_tags[ $tag['id'] ] ) ) |
---|
| 235 | array_push($selected_tag_urls, $tag['url_name']); |
---|
| 236 | } |
---|
| 237 | $x = compact( 'filename', 'selected_tag_urls', 'prio_tags', 'freq_tags', |
---|
| 238 | 'selected_categories', 'prio_categories', 'freq_categories', |
---|
| 239 | 'selected_specials' ); |
---|
| 240 | $file = fopen( sitemaps_get_config_file_name(), 'w' ); |
---|
| 241 | fwrite($file, serialize($x) ); |
---|
| 242 | fclose( $file ); |
---|
| 243 | } |
---|
| 244 | else |
---|
| 245 | { |
---|
| 246 | $filename = 'sitemap.xml'; |
---|
| 247 | $gzip = false; |
---|
| 248 | $selected_specials = 'all'; |
---|
| 249 | $prio_categories = 0.5; |
---|
| 250 | $prio_tags = 0.6; |
---|
| 251 | $freq_categories = 'monthly'; |
---|
| 252 | $freq_tags = 'monthly'; |
---|
| 253 | |
---|
| 254 | $conf_file_name = sitemaps_get_config_file_name(); |
---|
| 255 | $old_file = dirname(__FILE__).'/_sitemap.dat'; |
---|
| 256 | if (file_exists($old_file) and !file_exists($conf_file_name) ) |
---|
| 257 | { |
---|
| 258 | copy($old_file, $conf_file_name); |
---|
| 259 | unlink($old_file); |
---|
| 260 | } |
---|
| 261 | |
---|
| 262 | $x = @file_get_contents( $conf_file_name ); |
---|
| 263 | if ($x!==false) |
---|
| 264 | { |
---|
| 265 | $x = unserialize($x); |
---|
| 266 | extract($x); |
---|
| 267 | $selected_tags = array(); |
---|
| 268 | if (isset($selected_tag_urls)) |
---|
| 269 | { |
---|
| 270 | foreach($tags as $tag) |
---|
| 271 | { |
---|
| 272 | if ( in_array($tag['url_name'], $selected_tag_urls ) ) |
---|
| 273 | array_push($selected_tags, $tag['id']); |
---|
| 274 | } |
---|
| 275 | unset($selected_tag_urls); |
---|
| 276 | } |
---|
| 277 | } |
---|
| 278 | |
---|
| 279 | if (!is_array(@$selected_categories)) $selected_categories = array(); |
---|
| 280 | if (!is_array(@$selected_tags)) $selected_tags = array(); |
---|
| 281 | } |
---|
| 282 | |
---|
| 283 | |
---|
| 284 | $template->assign( array( |
---|
| 285 | 'FILENAME' => $filename, |
---|
| 286 | 'U_FILENAME' => get_root_url().$filename.($gzip?'.gz':''), |
---|
| 287 | 'GZIP_CHECKED' => $gzip ? 'checked="checked"' : '', |
---|
| 288 | 'PRIO_CATEGORIES' => $prio_categories, |
---|
| 289 | 'PRIO_TAGS' => $prio_tags, |
---|
| 290 | ) |
---|
| 291 | ); |
---|
| 292 | |
---|
| 293 | foreach( $specials as $key=>$value) |
---|
| 294 | { |
---|
| 295 | $checked=''; |
---|
| 296 | if ($selected_specials=='all' or in_array($key, $selected_specials) ) |
---|
| 297 | $checked = 'checked="checked"'; |
---|
| 298 | |
---|
| 299 | $template->append( 'specials', |
---|
| 300 | array( |
---|
| 301 | 'NAME' => $key, |
---|
| 302 | 'LABEL' => $value['L'], |
---|
| 303 | 'CHECKED' => $checked, |
---|
| 304 | 'PRIO' => $value['P'], |
---|
| 305 | 'FREQ' => isset($value['F']) ? $value['F'] : 'monthly', |
---|
| 306 | ) |
---|
| 307 | ); |
---|
| 308 | } |
---|
| 309 | |
---|
| 310 | display_select_categories($categories, $selected_categories, 'categories', false ); |
---|
| 311 | $template->assign('freq_categories_selected', $freq_categories); |
---|
| 312 | |
---|
| 313 | |
---|
| 314 | foreach( $tags as $tag) |
---|
| 315 | $template->append( 'tags', array($tag['id']=>$tag['name']), true ); |
---|
| 316 | $template->assign('tags_selected', $selected_tags); |
---|
| 317 | $template->assign('freq_tags_selected', $freq_tags); |
---|
| 318 | |
---|
| 319 | |
---|
| 320 | $template->assign('frequencies', $frequencies); |
---|
[8984] | 321 | $template->assign('frequenciesT', $frequenciesT); |
---|
[3417] | 322 | |
---|
| 323 | $template->set_filename('sitemap', dirname(__FILE__).'/sitemap.tpl'); |
---|
| 324 | $template->assign_var_from_handle('ADMIN_CONTENT', 'sitemap'); |
---|
| 325 | |
---|
| 326 | ?> |
---|