[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; |
---|
[17516] | 11 | $dir = PHPWG_ROOT_PATH.$conf['data_location'].'plugins/'; |
---|
[3417] | 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"?'.'> |
---|
[16301] | 22 | <urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9" xmlns:image="http://www.google.com/schemas/sitemap-image/1.1">', $gzip ); |
---|
[3417] | 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 | |
---|
[16301] | 41 | function add_url($url, $lastmod=null, $changefreq=null, $priority=null, $images_xml=null) |
---|
[3417] | 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 | |
---|
[16301] | 65 | if ( isset($images_xml) ) |
---|
| 66 | $xml .= "\n".$images_xml; |
---|
[16940] | 67 | |
---|
[3417] | 68 | $xml .= ' |
---|
| 69 | </url>'; |
---|
| 70 | global $gzip,$url_count; |
---|
| 71 | $url_count++; |
---|
| 72 | out_xml($xml, $gzip); |
---|
| 73 | } |
---|
| 74 | |
---|
| 75 | |
---|
| 76 | |
---|
| 77 | include_once(PHPWG_ROOT_PATH.'admin/include/functions.php'); |
---|
| 78 | check_status(ACCESS_ADMINISTRATOR); |
---|
| 79 | |
---|
| 80 | |
---|
| 81 | |
---|
[8984] | 82 | $frequenciesT = array( |
---|
| 83 | '', |
---|
| 84 | l10n('always'), |
---|
| 85 | l10n('hourly'), |
---|
| 86 | l10n('daily'), |
---|
| 87 | l10n('weekly'), |
---|
| 88 | l10n('monthly'), |
---|
| 89 | l10n('yearly'), |
---|
| 90 | l10n('never'), |
---|
| 91 | ); |
---|
| 92 | |
---|
[3417] | 93 | $frequencies = array( |
---|
| 94 | '', |
---|
| 95 | 'always', |
---|
| 96 | 'hourly', |
---|
| 97 | 'daily', |
---|
| 98 | 'weekly', |
---|
| 99 | 'monthly', |
---|
| 100 | 'yearly', |
---|
| 101 | 'never', |
---|
| 102 | ); |
---|
[16940] | 103 | |
---|
[3417] | 104 | $specials = array( |
---|
[6260] | 105 | 'categories' => array('L'=>l10n('Home'), 'P'=>0.9), |
---|
[8984] | 106 | 'best_rated' => array('L'=>l10n('Best rated'), 'P'=>0.8 ) , |
---|
[6260] | 107 | 'most_visited' => array('L'=>l10n('Most visited'), 'P'=>0.8 ), |
---|
[8666] | 108 | 'recent_pics' => array('L'=>l10n('Recent photos'), 'P'=>0.8, 'F'=>'weekly' ), |
---|
[13075] | 109 | 'tags' => array('L'=>l10n('Tags'), 'PAGE'=>'tags.php' , 'P'=>0.8 ), |
---|
[3417] | 110 | ); |
---|
| 111 | |
---|
| 112 | $url_count=0; |
---|
| 113 | |
---|
| 114 | // BEGIN AS GUEST |
---|
| 115 | $save_user = $user; |
---|
| 116 | $user = build_user( $conf['guest_id'], true); |
---|
| 117 | |
---|
| 118 | $query = ' |
---|
| 119 | SELECT id, name, permalink, uppercats, global_rank, IFNULL(date_last, max_date_last) AS date_last |
---|
| 120 | FROM '.CATEGORIES_TABLE.' INNER JOIN '.USER_CACHE_CATEGORIES_TABLE.' |
---|
| 121 | ON id = cat_id AND user_id = '.$conf['guest_id'].' |
---|
| 122 | WHERE max_date_last IS NOT NULL |
---|
| 123 | ORDER BY global_rank'; |
---|
[20461] | 124 | $categories = array_from_query($query); |
---|
[3417] | 125 | usort($categories, 'global_rank_compare'); |
---|
| 126 | |
---|
| 127 | $tags = get_available_tags(); |
---|
| 128 | usort($tags, 'name_compare'); |
---|
| 129 | |
---|
| 130 | if ( isset($_POST['submit']) ) |
---|
| 131 | { |
---|
| 132 | // echo('<pre>'.var_export($_POST,true).'</pre>' ); |
---|
| 133 | |
---|
| 134 | if ( $_POST['filename'] != '' ) |
---|
| 135 | $filename = $_POST['filename']; |
---|
| 136 | $gzip = @$_POST['gzip']=='on' ? true : false; |
---|
| 137 | |
---|
| 138 | $selected_specials = array(); |
---|
| 139 | foreach ($specials as $key=>$value) |
---|
| 140 | { |
---|
| 141 | if ( @$_POST['special_'.$key]=='on' ) |
---|
| 142 | array_push( $selected_specials, $key ); |
---|
| 143 | $specials[$key]['P'] = $_POST['special_prio_'.$key]; |
---|
| 144 | $specials[$key]['F'] = $_POST['special_freq_'.$key]; |
---|
| 145 | } |
---|
| 146 | if ( isset($_POST['categories']) ) |
---|
| 147 | $selected_categories = $_POST['categories']; |
---|
| 148 | else |
---|
| 149 | $selected_categories = array(); |
---|
| 150 | $prio_categories = $_POST['prio_categories']; |
---|
| 151 | $freq_categories = $_POST['freq_categories']; |
---|
| 152 | |
---|
| 153 | if ( isset($_POST['tags']) ) |
---|
| 154 | $selected_tags = $_POST['tags']; |
---|
| 155 | else |
---|
| 156 | $selected_tags = array(); |
---|
| 157 | $prio_tags = $_POST['prio_tags']; |
---|
| 158 | $freq_tags = $_POST['freq_tags']; |
---|
| 159 | |
---|
[16301] | 160 | $photo_count = intval($_POST['photo_count']); |
---|
[16940] | 161 | |
---|
[3417] | 162 | set_make_full_url(); |
---|
| 163 | |
---|
| 164 | start_xml($filename, $gzip); |
---|
| 165 | |
---|
| 166 | $r_selected_specials = array_flip($selected_specials); |
---|
| 167 | foreach ($specials as $key=>$value) |
---|
| 168 | { |
---|
| 169 | if (! isset ($r_selected_specials[$key]) ) |
---|
| 170 | continue; |
---|
| 171 | if ( isset($value['PAGE']) ) |
---|
| 172 | $url = get_root_url().$value['PAGE']; |
---|
| 173 | else |
---|
| 174 | $url = make_index_url( array('section'=>$key) ); |
---|
| 175 | add_url($url, null, $value['F'], $value['P'] ); |
---|
| 176 | } |
---|
| 177 | |
---|
| 178 | |
---|
| 179 | $r_selected_categories = array_flip($selected_categories); |
---|
| 180 | foreach ($categories as $cat) |
---|
| 181 | { |
---|
| 182 | if (! isset ($r_selected_categories[$cat['id']]) ) |
---|
| 183 | continue; |
---|
| 184 | |
---|
| 185 | $url = make_index_url( |
---|
| 186 | array( |
---|
| 187 | 'category'=>$cat |
---|
| 188 | ) |
---|
| 189 | ); |
---|
| 190 | add_url($url, $cat['date_last'], $freq_categories, $prio_categories); |
---|
| 191 | } |
---|
| 192 | |
---|
| 193 | $r_selected_tags = array_flip($selected_tags); |
---|
| 194 | if ( !empty($selected_tags) ) |
---|
| 195 | { |
---|
| 196 | $query = 'SELECT tag_id, MAX(date_available) AS da, MAX(date_creation) AS dc, MAX(date_metadata_update) AS dm |
---|
| 197 | FROM '.IMAGE_TAG_TABLE.' INNER JOIN '.IMAGES_TABLE.' ON image_id=id |
---|
| 198 | WHERE tag_id IN ('.implode(',',$selected_tags).') |
---|
| 199 | GROUP BY tag_id'; |
---|
| 200 | $result = pwg_query($query); |
---|
| 201 | $tag_infos = array(); |
---|
[20461] | 202 | while ($row = pwg_db_fetch_assoc($result)) |
---|
[3417] | 203 | { |
---|
| 204 | $tag_infos[$row['tag_id']]= max( $row['da'],$row['dc'],$row['dm']); |
---|
| 205 | } |
---|
| 206 | |
---|
| 207 | foreach( $tags as $tag) |
---|
| 208 | { |
---|
| 209 | if (!isset($r_selected_tags[ $tag['id'] ] ) ) |
---|
| 210 | continue; |
---|
| 211 | |
---|
| 212 | $url = make_index_url( |
---|
| 213 | array( |
---|
| 214 | 'section'=>'tags', |
---|
| 215 | 'tags'=> array( $tag ) |
---|
| 216 | ) |
---|
| 217 | ); |
---|
| 218 | |
---|
| 219 | add_url($url, $tag_infos[ $tag['id'] ], $freq_tags, $prio_tags); |
---|
| 220 | } |
---|
| 221 | } |
---|
[16940] | 222 | |
---|
[17144] | 223 | $selected_derivatives = array(); |
---|
[16301] | 224 | if ($photo_count > 0) |
---|
| 225 | { |
---|
[17144] | 226 | if (isset($_POST['selected_derivatives'])) |
---|
| 227 | $selected_derivatives = $_POST['selected_derivatives']; |
---|
| 228 | |
---|
[21597] | 229 | $selected_derivatives_params = array(); |
---|
[17144] | 230 | foreach($selected_derivatives as $type) |
---|
| 231 | $selected_derivatives_params[] = ImageStdParams::get_by_type($type); |
---|
| 232 | |
---|
[16301] | 233 | $query = 'SELECT DISTINCT i.* FROM '.IMAGES_TABLE.' i |
---|
[16940] | 234 | INNER JOIN '.IMAGE_CATEGORY_TABLE.' on i.id=image_id |
---|
[16301] | 235 | '.get_sql_condition_FandF( array('forbidden_categories' => 'category_id', 'forbidden_images'=>'i.id'), 'WHERE ' ).' |
---|
| 236 | ORDER BY date_available DESC |
---|
| 237 | LIMIT '.$photo_count; |
---|
| 238 | $result = pwg_query($query); |
---|
[20461] | 239 | while ($row = pwg_db_fetch_assoc($result)) |
---|
[16301] | 240 | { |
---|
| 241 | $url = make_picture_url( array( |
---|
| 242 | 'image_id' => $row['id'], |
---|
| 243 | 'image_file' => $row['file'], |
---|
| 244 | ) ); |
---|
| 245 | $src_image = new SrcImage($row); |
---|
| 246 | $images_xml = ''; |
---|
[17144] | 247 | $done_iurls=array(); |
---|
| 248 | foreach( $selected_derivatives_params as $params ) |
---|
[16301] | 249 | { |
---|
[17144] | 250 | $deriv_url = DerivativeImage::url($params, $src_image); |
---|
| 251 | if (!isset($done_iurls[$deriv_url])) |
---|
| 252 | { |
---|
| 253 | $done_iurls[$deriv_url] = 1; |
---|
| 254 | $images_xml .= '<image:image><image:loc>'.$deriv_url.'</image:loc></image:image>'; |
---|
| 255 | } |
---|
[16301] | 256 | } |
---|
| 257 | add_url($url, $row['date_available'], null, null, $images_xml); |
---|
| 258 | } |
---|
| 259 | } |
---|
[3417] | 260 | unset_make_full_url(); |
---|
| 261 | end_xml($gzip); |
---|
| 262 | |
---|
| 263 | $page['infos'][] = $url_count.' urls saved'; |
---|
| 264 | |
---|
| 265 | // save the data for future use |
---|
| 266 | $selected_tag_urls = array(); |
---|
| 267 | foreach( $tags as $tag) |
---|
| 268 | { |
---|
| 269 | if (isset($r_selected_tags[ $tag['id'] ] ) ) |
---|
| 270 | array_push($selected_tag_urls, $tag['url_name']); |
---|
| 271 | } |
---|
| 272 | $x = compact( 'filename', 'selected_tag_urls', 'prio_tags', 'freq_tags', |
---|
| 273 | 'selected_categories', 'prio_categories', 'freq_categories', |
---|
[17232] | 274 | 'selected_specials', 'photo_count', 'selected_derivatives' ); |
---|
[3417] | 275 | $file = fopen( sitemaps_get_config_file_name(), 'w' ); |
---|
| 276 | fwrite($file, serialize($x) ); |
---|
| 277 | fclose( $file ); |
---|
| 278 | } |
---|
| 279 | else |
---|
| 280 | { |
---|
| 281 | $filename = 'sitemap.xml'; |
---|
| 282 | $gzip = false; |
---|
| 283 | $selected_specials = 'all'; |
---|
| 284 | $prio_categories = 0.5; |
---|
| 285 | $prio_tags = 0.6; |
---|
| 286 | $freq_categories = 'monthly'; |
---|
| 287 | $freq_tags = 'monthly'; |
---|
[16301] | 288 | $photo_count = 0; |
---|
[17144] | 289 | $selected_derivatives = array(); |
---|
[16940] | 290 | |
---|
[3417] | 291 | $conf_file_name = sitemaps_get_config_file_name(); |
---|
| 292 | $old_file = dirname(__FILE__).'/_sitemap.dat'; |
---|
| 293 | if (file_exists($old_file) and !file_exists($conf_file_name) ) |
---|
| 294 | { |
---|
| 295 | copy($old_file, $conf_file_name); |
---|
| 296 | unlink($old_file); |
---|
| 297 | } |
---|
| 298 | |
---|
| 299 | $x = @file_get_contents( $conf_file_name ); |
---|
| 300 | if ($x!==false) |
---|
| 301 | { |
---|
| 302 | $x = unserialize($x); |
---|
| 303 | extract($x); |
---|
| 304 | $selected_tags = array(); |
---|
| 305 | if (isset($selected_tag_urls)) |
---|
| 306 | { |
---|
| 307 | foreach($tags as $tag) |
---|
| 308 | { |
---|
| 309 | if ( in_array($tag['url_name'], $selected_tag_urls ) ) |
---|
| 310 | array_push($selected_tags, $tag['id']); |
---|
| 311 | } |
---|
| 312 | unset($selected_tag_urls); |
---|
| 313 | } |
---|
| 314 | } |
---|
| 315 | |
---|
| 316 | if (!is_array(@$selected_categories)) $selected_categories = array(); |
---|
| 317 | if (!is_array(@$selected_tags)) $selected_tags = array(); |
---|
| 318 | } |
---|
| 319 | |
---|
[16301] | 320 | // END AS GUEST |
---|
| 321 | $user = $save_user; |
---|
[3417] | 322 | |
---|
[16301] | 323 | |
---|
[3417] | 324 | $template->assign( array( |
---|
| 325 | 'FILENAME' => $filename, |
---|
| 326 | 'U_FILENAME' => get_root_url().$filename.($gzip?'.gz':''), |
---|
| 327 | 'GZIP_CHECKED' => $gzip ? 'checked="checked"' : '', |
---|
| 328 | 'PRIO_CATEGORIES' => $prio_categories, |
---|
| 329 | 'PRIO_TAGS' => $prio_tags, |
---|
[16301] | 330 | 'PHOTO_COUNT' => $photo_count, |
---|
[3417] | 331 | ) |
---|
| 332 | ); |
---|
| 333 | |
---|
| 334 | foreach( $specials as $key=>$value) |
---|
| 335 | { |
---|
| 336 | $checked=''; |
---|
| 337 | if ($selected_specials=='all' or in_array($key, $selected_specials) ) |
---|
| 338 | $checked = 'checked="checked"'; |
---|
| 339 | |
---|
| 340 | $template->append( 'specials', |
---|
| 341 | array( |
---|
| 342 | 'NAME' => $key, |
---|
| 343 | 'LABEL' => $value['L'], |
---|
| 344 | 'CHECKED' => $checked, |
---|
| 345 | 'PRIO' => $value['P'], |
---|
| 346 | 'FREQ' => isset($value['F']) ? $value['F'] : 'monthly', |
---|
| 347 | ) |
---|
| 348 | ); |
---|
| 349 | } |
---|
| 350 | |
---|
| 351 | display_select_categories($categories, $selected_categories, 'categories', false ); |
---|
| 352 | $template->assign('freq_categories_selected', $freq_categories); |
---|
| 353 | |
---|
| 354 | |
---|
| 355 | foreach( $tags as $tag) |
---|
| 356 | $template->append( 'tags', array($tag['id']=>$tag['name']), true ); |
---|
| 357 | $template->assign('tags_selected', $selected_tags); |
---|
| 358 | $template->assign('freq_tags_selected', $freq_tags); |
---|
| 359 | |
---|
| 360 | |
---|
| 361 | $template->assign('frequencies', $frequencies); |
---|
[8984] | 362 | $template->assign('frequenciesT', $frequenciesT); |
---|
[3417] | 363 | |
---|
[17144] | 364 | $available_derivatives = array(); |
---|
| 365 | foreach(array_keys(ImageStdParams::get_defined_type_map()) as $type) |
---|
| 366 | { |
---|
| 367 | $available_derivatives[$type] = l10n($type); |
---|
| 368 | } |
---|
| 369 | $template->assign( array('available_derivatives'=>$available_derivatives, 'selected_derivatives' => $selected_derivatives)); |
---|
| 370 | |
---|
[3417] | 371 | $template->set_filename('sitemap', dirname(__FILE__).'/sitemap.tpl'); |
---|
| 372 | $template->assign_var_from_handle('ADMIN_CONTENT', 'sitemap'); |
---|
| 373 | |
---|
| 374 | ?> |
---|