JasonWoof Got questions, comments, patches, etc.? Contact Jason Woofenden
db_upgrade rework, admin_header, cleanup
[wfpl-cms.git] / inc / cms.php
index f8154a9..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,6 +30,29 @@ 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"');
@@ -31,19 +60,6 @@ function cms_display($basename, &$tem) {
                $tem->set('$cms_footer', $footer);
        }
 
-       $header = db_get_value('cms_images', 'image', 'where name="Header"');
-       if ($header) {
-               $parts = explode(' ', $header . '      ', 7);
-               $tem->set('$cms_header',
-                       '<div style="'
-                       . 'padding-top: ' . round(100000 * (int)$parts[2] / (int)$parts[1] / 1000) . '%;'
-                       . 'background-image: url(' . $parts[0] . ');'
-                       . 'background-repeat: no-repeat;'
-                       . 'background-size: 100% auto;'
-                       . '"></div>'
-               );
-       }
-
        if(session_auth_can('admin_links')) {
                $admin_links = array();
                if($cms_page_id) {