JasonWoof Got questions, comments, patches, etc.? Contact Jason Woofenden
c1e25890699bcaa3cf588fa00796e8ad2e55b627
[wfpl-cms.git] / code / cms.php
1 <?php
2
3 function cms_display($basename, &$tem) {
4         $nav_items = db_get_assocs('cms_pages', "coalesce(nullif(nav_title,''), title) as title,filename", 'where navbar!=0 order by navbar');
5         if($nav_items) {
6                 foreach($nav_items as &$nav_item) {
7                         if($nav_item['filename'] == 'index') {
8                                 $nav_item['filename'] = './';
9                         }
10                         if($nav_item['title'] == '') {
11                                 $nav_item['title'] = '-- blank --';
12                         }
13                 }
14                 $tem->set('$navbar_items', $nav_items);
15         }
16
17         $cms_page_id = cms_display_content($tem, 'where filename=%"', $basename);
18
19         if(logged_in_as_admin()) {
20                 $admin_links = array();
21                 if($cms_page_id) {
22                         $admin_links['id'] = $cms_page_id;
23                 }
24                 $tem->set('$admin_links', $admin_links);
25         }
26
27         if($cms_page_id) {
28                 return true;
29         } else {
30                 return false;
31         }
32 }
33
34 function cms_display_content(&$tem /*, 'where clause %", %i', string, int */) {
35         $args = array_slice(func_get_args(), 1);
36         $args = array_merge(array('cms_pages', 'id,title,keywords,description,content'), $args);
37         $row = call_user_func_array('db_get_assoc', $args);
38         if($row) {
39                 $tem->set('$cms_title', $row['title']);
40                 $tem->set('$meta_keywords', $row['keywords']);
41                 $tem->set('$meta_description', $row['description']);
42                 $tem->set('$cms_body', $row['content']);
43                 return $row['id'];
44         }
45         return false;
46 }