JasonWoof Got questions, comments, patches, etc.? Contact Jason Woofenden
auto-choose full layout if no cms
[wfpl-cms.git] / inc / cms.php
1 <?php
2
3 # This function (which loads the navbar and page content from the database) is
4 # called automatically by wfpl_main()
5 function cms_display($basename, &$tem) {
6         if(preg_match('/([.]l(ocal)?$)|^192[.]168[.]|^127.0.0.1$|^10[.]/', $_SERVER['HTTP_HOST'])) {
7                 $GLOBALS['wfpl_main_template']->set('$running_locally');
8         }
9         $tem->set('$host', this_host());
10         $nav_items = db_get_assocs('cms_pages', "coalesce(nullif(nav_title,''), title) as title,filename", 'where navbar!=0 order by navbar');
11         if($nav_items) {
12                 foreach($nav_items as &$item) {
13                         $item['basename'] = $item['filename']; # for nav-links as images
14                         if($item['filename'] == $basename) {
15                                 $item['current'] = true;
16                         }
17                         if($item['filename'] == 'index') {
18                                 $item['filename'] = './';
19                         }
20                         if($item['title'] == '') {
21                                 $item['title'] = '(untitled)';
22                         }
23                 }
24                 $tem->set('$navbar_items', $nav_items);
25         }
26
27         $cms_page_id = cms_display_content($tem, 'where filename=%"', $basename);
28
29         if(session_auth_can('admin_links')) {
30                 $admin_links = array();
31                 if($cms_page_id) {
32                         $admin_links['$edit_page_id'] = $cms_page_id;
33                 }
34                 $tem->set('$admin_links', $admin_links);
35         }
36
37         if($cms_page_id) {
38                 return true;
39         } else {
40                 return false;
41         }
42 }
43
44 function cms_display_content(&$tem /*, 'where clause %", %i', string, int */) {
45         $args = array_slice(func_get_args(), 1);
46         $args = array_merge(array('cms_pages', 'id,title,keywords,description,layout,content,sidebar_content'), $args);
47         $row = call_user_func_array('db_get_assoc', $args);
48         if($row) {
49                 $tem->set('$cms_title', $row['title']);
50                 $tem->set('$meta_keywords', $row['keywords']);
51                 $tem->set('$meta_description', $row['description']);
52                 $tem->set('$cms_body', $row['content']);
53                 if ($row['layout'] === '' || $row['layout'] === '0') {
54                         $tem->set('$layout_centerer_class', 'full');
55                 } else {
56                         $tem->set('$layout_centerer_class', 'with_sidebar');
57                         if ($row['layout'] === '1') {
58                                 $tem->set('$layout_sidebar_class', 'plain');
59                         } else {
60                                 $tem->set('$layout_sidebar_class', 'bordered');
61                         }
62                         $tem->set('$cms_sidebar', $row['sidebar_content']);
63                 }
64                 return $row['id'];
65         } else {
66                 $tem->set('$layout_centerer_class', 'full');
67         }
68         return false;
69 }