JasonWoof Got questions, comments, patches, etc.? Contact Jason Woofenden
set timezone in code/config.php
[wfpl-cms.git] / code / cms.php
1 <?php
2
3 function cms_display($basename, &$tem) {
4         if(preg_match('/([.]l(ocal)?$)|^[0-9.]*$/', $_SERVER['HTTP_HOST'])) {
5                 $GLOBALS['wfpl_main_template']->set('$running_locally');
6         }
7         $tem->set('$host', this_host());
8         $nav_items = db_get_assocs('cms_pages', "coalesce(nullif(nav_title,''), title) as title,filename", 'where navbar!=0 order by navbar');
9         if($nav_items) {
10                 foreach($nav_items as &$item) {
11                         $item['basename'] = $item['filename']; # for nav-links as images
12                         if($item['filename'] == $basename) {
13                                 $item['current'] = true;
14                         }
15                         if($item['filename'] == 'index') {
16                                 $item['filename'] = './';
17                         }
18                         if($item['title'] == '') {
19                                 $item['title'] = '(untitled)';
20                         }
21                 }
22                 $tem->set('$navbar_items', $nav_items);
23         }
24
25         $cms_page_id = cms_display_content($tem, 'where filename=%"', $basename);
26
27         if(logged_in_as_admin()) {
28                 $admin_links = array();
29                 if($cms_page_id) {
30                         $admin_links['id'] = $cms_page_id;
31                 }
32                 $tem->set('$admin_links', $admin_links);
33         }
34
35         if($cms_page_id) {
36                 return true;
37         } else {
38                 return false;
39         }
40 }
41
42 function cms_display_content(&$tem /*, 'where clause %", %i', string, int */) {
43         $args = array_slice(func_get_args(), 1);
44         $args = array_merge(array('cms_pages', 'id,title,keywords,description,content'), $args);
45         $row = call_user_func_array('db_get_assoc', $args);
46         if($row) {
47                 $tem->set('$cms_title', $row['title']);
48                 $tem->set('$meta_keywords', $row['keywords']);
49                 $tem->set('$meta_description', $row['description']);
50                 $tem->set('$cms_body', $row['content']);
51                 return $row['id'];
52         }
53         return false;
54 }