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