JasonWoof Got questions, comments, patches, etc.? Contact Jason Woofenden
db_upgrade rework, admin_header, cleanup
[wfpl-cms.git] / inc / cms.php
index 02dc63e..06324f0 100644 (file)
@@ -2,6 +2,12 @@
 
 # This function (which loads the navbar and page content from the database) is
 # called automatically by wfpl_main()
+
+function enc_css_str($str) {
+       $str = str_replace("\\", "\\00005c", $str);
+       return str_replace("\"", "\\000022", $str);
+}
+
 function cms_display($basename, &$tem) {
        if(preg_match('/([.]l(ocal)?$)|^192[.]168[.]|^127.0.0.1$|^10[.]/', $_SERVER['HTTP_HOST'])) {
                $GLOBALS['wfpl_main_template']->set('$running_locally');
@@ -24,8 +30,36 @@ function cms_display($basename, &$tem) {
                $tem->set('$navbar_items', $nav_items);
        }
 
+       $header_image = persistent_get('wfplcms_header_image');
+       if ($header_image) {
+               $hi_css  = "\n<style>\n";
+               if ($header_image['width'] != WFPL_SITE_WIDTH) {
+                       $hi_css .= "#site_header {\n";
+                       $hi_css .=   'width: ' . $header_image['width'] . "px;\n";
+                       $hi_css .= "}\n";
+               }
+               $hi_css .= "#site_header:before {\n";
+               $hi_css .=   "content: \"\";\n";
+               $hi_css .=   'background-image: url(' . $header_image['url'] . ");\n";
+               $hi_css .=   'padding-top: ' . ($header_image['height'] / $header_image['width'] * 100) . "%;\n";
+               $hi_css .= "}\n";
+               if ($header_image['caption']) {
+                       $hi_css .= "#site_header:after {\n";
+                       $hi_css .=   "content: \"" . enc_css_str($header_image['caption']) . "\";\n";
+                       $hi_css .= "}\n";
+               }
+               $hi_css .= "</style>\n";
+
+               $tem->set('$cms_css', $hi_css);
+       }
+
        $cms_page_id = cms_display_content($tem, 'where filename=%"', $basename);
 
+       $footer = db_get_value('cms_pages', 'content', 'where filename="_footer"');
+       if ($footer) {
+               $tem->set('$cms_footer', $footer);
+       }
+
        if(session_auth_can('admin_links')) {
                $admin_links = array();
                if($cms_page_id) {
@@ -43,14 +77,27 @@ function cms_display($basename, &$tem) {
 
 function cms_display_content(&$tem /*, 'where clause %", %i', string, int */) {
        $args = array_slice(func_get_args(), 1);
-       $args = array_merge(array('cms_pages', 'id,title,keywords,description,content'), $args);
+       $args = array_merge(array('cms_pages', 'id,title,keywords,description,layout,content,sidebar_content'), $args);
        $row = call_user_func_array('db_get_assoc', $args);
        if($row) {
                $tem->set('$cms_title', $row['title']);
                $tem->set('$meta_keywords', $row['keywords']);
                $tem->set('$meta_description', $row['description']);
                $tem->set('$cms_body', $row['content']);
+               if ($row['layout'] === '' || $row['layout'] === '0') {
+                       $tem->set('$layout_centerer_class', 'full');
+               } else {
+                       $tem->set('$layout_centerer_class', 'with_sidebar');
+                       if ($row['layout'] === '1') {
+                               $tem->set('$layout_sidebar_class', 'plain');
+                       } else {
+                               $tem->set('$layout_sidebar_class', 'bordered');
+                       }
+                       $tem->set('$cms_sidebar', $row['sidebar_content']);
+               }
                return $row['id'];
+       } else {
+               $tem->set('$layout_centerer_class', 'full');
        }
        return false;
 }