Things to Note:
<?
1 /*
2
3 Tuesday, May 03, 2005, 9:52:45 PM
4 The sitemap table and page is created. 2 years ago I would have said this was impossible but now its here. The index page once had a switch structure where
5
6 if ($type='category') require category_code.php
7
8 all that has been placed into a table called sitemap, which the index.php of the website now loops against. creating both a centralised way of keeping track of the code, page hits, page breadcrumbs, page relationships, and access validation / rules. IT mean that I lose the ability to control the site by editing index.php but I gain a nice sitemap page for user to view.
9
10 I am proud to say that the code is all original and brainstormed by me. probably the only true new piece of code I have written in a over a year. (original version Thursday, August 12, 2004, 9:33:07 PM, I am sitting on alot of unused code). It originated out of my desire to build a tree hierarcy using one query. The original is slightly simpler than this.
11
12
13
14 */
15 /*
16
17 7/6/2005 10:11 PM owen
18
19 today I modified the site map so that it not only shows the site structure as entered in the sitemap table. But also runs queries assigned to particular sitemap records. These queries stored in the coulmn 'branch_query' can run and add nodes to the current sitemap tree. Not only is the sitemap dynamic but now it is alive, showing data from all parts of the website. yes its going to get long but I know- ALIVE!!!! hahahaha
20
21 Took almost two hours to things up and write i.e. with my current knowledge of how ever thing work. it is now 7/6/2005 10:48 PM.
22
23 Executon time comparision:
24 old : exec time: 0.122798, queries: 2, records: 52, file size: 5.6kb, templates: 8
25 new (with 3 batch_queries) : exec time: 0.142088, queries: 5, records: 79, file size: 8.1kb, templates: 8
26
27
28 Added the first couple batch queries to test it out
29 ---------------------------------------
30 //sample branch_queries. must look like the sitemap table or the links generated will be malformed
31
32 #show category structure below site content page. probably most important
33 select id, name, parent, tooltip as 'info', 'category' as 'p_type', id as 'p_record', '*' as 'p_option' from category where hidden != 1
34
35 #show top 5 recent items
36 select id, name, 0 as 'parent', CONCAT( (TO_DAYS(NOW()) - TO_DAYS(thedate)), ' days ago' ) as 'info', 'item' as 'p_type', id as 'p_record', '*' as 'p_option' from post p order by p.id desc limit 5
37
38 #show years below archive link in sitemap
39 SELECT DATE_FORMAT( p.thedate, '%Y' ) AS 'ord', DATE_FORMAT( p.thedate, '%Y' ) AS 'id', 0 as 'parent', DATE_FORMAT( p.thedate, '%Y' ) AS 'name', CONCAT( count( * ) , ' posts, ', SUM( photo > 0 ) , ' photos' ) AS 'info', 'archive' AS 'p_type', DATE_FORMAT( p.thedate, '%Y' ) AS 'p_record', '*' AS 'p_option' FROM post p WHERE 0 = 0 GROUP BY ord ORDER BY p.thedate
40
41 others-----------------------------
42
43 select p.id, p.name, 0 as 'parent', CONCAT( 'by ', u.name) as 'info', 'playlist' as 'p_type', p.id as 'p_record', '*' as 'p_option' from playlist p, user u where p.user = u.id and private != 1
44
45 select id, name, 0 as parent, short_info as 'info', 'user' as 'p_type', id as 'p_record', '*' as 'p_option' from user LIMIT 5
46
47 */
48
49 $pagetitle = 'Sitemap';
50
51 //--------------------------------------------------------------------------------------------
52
53 $struct ='';
54 //$site_paths = array();
55
56 $struct =spawn( " select * from sitemap where is_disabled!=1 and is_hidden!=1 ", $struct ); //new code converted to function
57
58 //--------------------------------------------------------------------------------------------
59
60 //die('here');
61 require_once("head.php");
62
63 //--------------------------------------------------------------------------------------------
64
65 echo include(template('sitemap', 'heading'));
66
67 write_select_struct( $struct, 'category_id' );
68 //pre($struct);
69
70 echo include(template('sitemap', 'footing'));
71 //--------------------------------------------------------------------------------------------
72
73 require_once("foot.php");
74
75
76
77 //--------------------------------------------------------------------------------------------
78
79 function spawn( $query, &$struct, $parent_node_key=0, $node_key_prefix='' ) { //funky naming conventions yay 7/6/2005 9:13 PM
80 global $os;
81
82 $os->execsql2($query, 'CACHE'); //
83
84 if( !is_array($struct) ) $struct=array();
85 $sub_struct = array();
86
87 while( $row = $os->fetch_array() ) {
88 //print_r($row);
89
90 if( !isset( $struct[$node_key_prefix . $row['id']] ) ) {
91 $struct[$node_key_prefix . $row['id']]=array( 'id'=>$row['id'], 'name'=>$row['name'], 'parent'=>$node_key_prefix . $row['parent'], 'data'=>$row );
92 } else {
93 $struct[$node_key_prefix . $row['id']]['id']=$row['id'];
94 $struct[$node_key_prefix . $row['id']]['name']=$row['name'];
95 $struct[$node_key_prefix . $row['id']]['parent']=$node_key_prefix . $row['parent'];
96 $struct[$node_key_prefix . $row['id']]['data']=$row;
97 }
98
99 if( $row['parent'] != 0 ) {
100 if( !isset($struct[$node_key_prefix . $row['parent']]) ) {
101 continue;
102 //$struct[$node_key_prefix . $row['parent']]=array( 'id'=>'undefined', 'name'=>'undefined', 'parent'=>'undefined', 'data'=>'undefined' );
103 }
104
105 if( !isset($struct[$node_key_prefix . $row['parent']]['child']) ) $struct[$node_key_prefix . $row['parent']]['child'] = array();
106 $struct[$node_key_prefix . $row['parent']]['child'][$node_key_prefix . $row['id']]= &$struct[$node_key_prefix . $row['id']];
107 //print($struct[$row['parent']]);
108 } else {
109 $struct[$node_key_prefix . $row['id']]['parent'] = $parent_node_key;
110
111 if($parent_node_key!=0) {
112 if( !isset($struct[$parent_node_key]['child']) ) $struct[$parent_node_key]['child'] = array();
113 $struct[$parent_node_key]['child'][$node_key_prefix . $row['id']]= &$struct[$node_key_prefix . $row['id']];
114 }
115
116 }
117
118 if( !isset($row['branch_query']) ) $row['branch_query']='';
119
120 if( $row['branch_query'] != '' ) {
121 $sub_struct[] = $row;
122 }
123
124 }
125 //print('<pre>');
126 //print_r($sub_struct);
127
128 foreach( $sub_struct as $key=>$value) {
129 //die( $value['branch_query'] );
130 //print($value['id']);
131
132 $sub_array = spawn( $value['branch_query'], $struct, $node_key_prefix . $value['id'], $node_key_prefix . $value['id'] );
133
134 //print('<pre>');
135 //print_r($struct);
136
137 // die(count($struct));
138 //$struct = array_merge( $struct, $sub_array );
139 //
140 }
141
142 return $struct;
143 }
144 //--------------------------------------------------------------------------------------------
145
146 function write_select_struct( $struct, $name ) {
147
148 foreach ( $struct as $key => $value) {
149 if( $value['parent'] == 0 ) {
150
151 if( isset($value['data']['is_hidden']) )
152 if( $value['data']['is_hidden'] ==1 ) continue;
153
154 print( '<h3>' . $value['name'] . '</h3>' );
155 print('
156 <ul>'); //style="text-align:center"
157 write_option_struct($value, '');
158 print '</ul>';
159 }
160 }
161 }
162
163 function write_option_struct($a, $path) {
164
165 // global $site_paths;
166
167 if( isset($a['data']['is_hidden']) )
168 if( $a['data']['is_hidden'] ==1 ) return;
169
170 print('<li><p>');
171
172 /*print('<pre>');
173 print($a['id']);
174 print('</pre>');
175 */
176 print('<a href="');
177 // phpinfo(); die();
178 $link = '/v4/';
179 if( $a['data']['p_type'] != '' ) $link .= '' . $a['data']['p_type'] . '/';
180 if( $a['data']['p_record'] != '' & $a['data']['p_record'] != 'integer' & $a['data']['p_record'] != '*' ) $link .= $a['data']['p_record'] . '/';
181 if( $a['data']['p_option'] != '' & $a['data']['p_option'] != '*' ) $link .= '' . $a['data']['p_option'] . '/';
182
183 $path .= '<a href="' . $link . '" >' . $a['name'] . '</a>' . ' » ' ;
184
185 // $site_paths[$link] = $path;
186 // $site_paths[$a['id']] = $path;
187
188 print $link . '"> '. $a['name'] . '</a>';// - . $path
189
190
191 if( is_array($a['data']) )
192 if( $a['data']['info'] != '' ) print ': <span>' . fstr($a['data']['info']) . '</span>';
193
194 if( isset($a['child']) ) {
195 print('<ul>');
196 foreach ( $a['child'] as $key => $value) write_option_struct( $value, $path );
197 print('</ul>');
198 }
199 print('</p></li>');
200
201
202 }
203
204 ?>