[google_sitemap]

Description

Link: [google_sitemap]
Author: Jason Huck
Category: Technical
Version: 8.x
License:
Posted: Jun. 30, 2006
Updated: Jan. 01, 0001
More by this author...
This is a custom type for generating Google Sitemaps. It contains the following member tags:

->addurl - Used to add a URL node to the map. Per the API, accepts -loc, -lastmod, -changefreq, and -priority. Only -loc is required. For specific usage instructions, refer to the API reference.

->save - Saves a gzip-compressed copy of the map to the provided folder path with the name 'sitemap.gz'. Requires file tags permissions and the [compress_gzip] tag.

->output - Used internally, outputs an XML representation of the sitemap. The onConvert callback calls this tag.

->createnode - Used internally, converts a map of URL parameters into an xml node.

Parameters

none


Sample Usage

inline( -username='xxxxxx', -password='xxxxxx');
	var('mySiteMap') = google_sitemap;
	
	$mySiteMap->addurl(
		-loc='http://www.yahoo.com/blah.html?foo=bar&red=blue',
		-lastmod=date,
		-changefreq='always',
		-priority=1.0
	);
	
	$mySiteMap->save(response_path);
/inline;
						

Source Code

Click the "Download" button below to retrieve a copy of this tag, including the complete documentation and sample usage shown on this page. Place the downloaded ".inc" file in your LassoStartup folder, restart Lasso, and you can begin using this tag immediately.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
define_type(
		'sitemap',
		-namespace='google_',
		-prototype,
		-description='Custom type for creating Google Sitemaps.'
	);
		local('urls' = array);		


		define_tag(
			'addurl',
			-req='loc', -type='string', -copy,
			-opt='lastmod', -type='date',
			-opt='changefreq', -type='string',
			-opt='priority', -type='decimal'
		);
			fail_if(
				(!valid_url(#loc) || #loc->size >= 2048),
				-1,
				'Location must be a valid URL and less than 2048 characters.'
			);
	
			#loc = encode_xml(decode_xml(#loc));	// avoid double encoding
						
			local_defined('lastmod') ? #lastmod->setformat('%Y-%m-%d');
			
			if(local_defined('changefreq'));
				local('freqs') = array(
					'always',
					'hourly',
					'daily',
					'weekly',
					'monthly',
					'yearly',
					'never'
				);
			
				#freqs !>> #changefreq ? #changefreq = null;
			else;
				local('changefreq' = null);
			/if;
			
			if(local_defined('priority'));
				select(true);
					case(#priority < 0.0);
						#priority = 0.0;
					case(#priority > 1.0);
						#priority = 1.0;
					case;
						#priority->setformat( -precision=1);
				/select;
			else;
				local('priority' = 0.5);
			/if;
			
			local('out' = map);
			#out->insert('loc' = #loc);
			#out->insert('lastmod' = #lastmod);
			#out->insert('changefreq' = #changefreq);
			#out->insert('priority' = #priority);
			
			self->urls->insert(#out);
		/define_tag;


		define_tag('createnode', -req='in');
			local('out') = xml('<url />');
			
			#out->newchild('loc')->addcontent(#in->find('loc'));
			#in->find('lastmod') != null ? #out->newchild('lastmod')->addcontent(#in->find('lastmod'));
			#in->find('changefreq') != '' ? #out->newchild('changefreq')->addcontent(#in->find('changefreq'));
			#out->newchild('priority')->addcontent(#in->find('priority'));
			
			return(@#out);
		/define_tag;

		
		define_tag('output');
			local('out') = xml('\
<urlset xmlns="http://www.google.com/schemas/sitemap/0.84"
	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
	xsi:schemaLocation="http://www.google.com/schemas/sitemap/0.84
	http://www.google.com/schemas/sitemap/0.84/sitemap.xsd" />
\			');
			
			iterate(self->urls, local('i'));
				#out->addchild(self->createnode(#i));
			/iterate;
			
			return('<?xml version="1.0" encoding="UTF-8"?>\n' + #out);
		/define_tag;
	
	
		define_tag('onConvert');
			return(@self->output);
		/define_tag;
	
	
		define_tag('save', -req='path');
			local('filepath' = #path);
			#filepath->removetrailing('/')&append('/sitemap.gz');
		
			file_write(
				#filepath,
				compress_gzip(self->output),
				-fileoverwrite
			);
		/define_tag;
	/define_type;

 

Related Tags



Comments

none

Email:


Password:



Newest

Most Popular

Support tagSwap.net