New feature for updating background image on front
authorSteve Sutton <steve@gaslightmedia.com>
Mon, 9 May 2016 20:00:32 +0000 (16:00 -0400)
committerSteve Sutton <steve@gaslightmedia.com>
Mon, 9 May 2016 20:00:32 +0000 (16:00 -0400)
Toolkit/Page.php
Toolkit/Smarty.php [new file with mode: 0644]
admin/backgroundImage/Database/application.sql [new file with mode: 0644]
admin/backgroundImage/Database/tables/background.sql [new file with mode: 0644]
admin/backgroundImage/index.php [new file with mode: 0644]
admin/backgroundImage/smarty_comp/74702a15f989dbc8f6253a674d3d01ba61a34cd6.file.index.tpl.php [new file with mode: 0644]
admin/backgroundImage/smarty_tmp/index.tpl [new file with mode: 0644]
admin/nav.phtml
css/background.css [new file with mode: 0644]
styles.css
templates/template.html

index 91a82bb..e6f9be5 100755 (executable)
@@ -472,6 +472,7 @@ class Toolkit_Page
             }
         }
         $this->pageTitle = $this->_getPageTitle($this->_catid);
+        $this->_getBackgroundStyle();
 
         $bodyFactory = new Toolkit_Template_Page_BodyFactory(
             $this->_breadCrumbs,
@@ -863,6 +864,19 @@ class Toolkit_Page
         $this->hasHeadlines = !empty($this->headlines);
     }
 
+    private function _getBackgroundStyle()
+    {
+        $cache = new Cache_Lite($GLOBALS['cacheOptions']);
+        if ($bgVersion = $cache->get('bgVersion')) {
+        } else {
+            $dbh = Toolkit_Database::getInstance();
+            $sql = "SELECT version FROM background.image";
+            $bgVersion = $dbh->query($sql)->fetchColumn();
+            $cache->save($bgVersion, 'bgVersion');
+        }
+        $this->bgVersion = $bgVersion; 
+    }
+
     /**
      * Check if this page has photo gallery in it
      *
diff --git a/Toolkit/Smarty.php b/Toolkit/Smarty.php
new file mode 100644 (file)
index 0000000..6a58f14
--- /dev/null
@@ -0,0 +1,51 @@
+<?php
+
+/**
+ * Smarty.php
+ *
+ * PHP version 5.3
+ *
+ * @category  Toolkit
+ * @package   Package
+ * @author    Steve Sutton <steve@gaslightmedia.com>
+ * @copyright 2013 Gaslight Media
+ * @license   Gaslight Media
+ * @version   SVN: (0.1)
+ * @link      <>
+ */
+if (!defined('SMARTY_DIR')) {
+    define('SMARTY_DIR', '/var/www/server/CommonApps/Smarty/3.1/');
+}
+require_once SMARTY_DIR . 'Smarty.class.php';
+/**
+ * Toolkit_HeaderImages_Smarty
+ *
+ * Smarty Class Extension
+ *
+ * @category  Toolkit
+ * @package   Package
+ * @author    Steve Sutton <steve@gaslightmedia.com>
+ * @copyright 2013 Gaslight Media
+ * @license   Gaslight Media
+ * @release   Release: (0.1)
+ * @link      <>
+ */
+class Toolkit_Smarty
+    extends Smarty
+{
+
+    function __construct(
+        $templateDir,
+        $compileDir,
+        $configDir,
+        $cacheDir
+    ) {
+        parent::__construct();
+
+        $this->setTemplateDir($templateDir);
+        $this->setCompileDir($compileDir);
+        $this->setConfigDir($configDir);
+        $this->setCacheDir($cacheDir);
+    }
+
+}
diff --git a/admin/backgroundImage/Database/application.sql b/admin/backgroundImage/Database/application.sql
new file mode 100644 (file)
index 0000000..739d826
--- /dev/null
@@ -0,0 +1,12 @@
+--
+-- setup schema
+--
+
+CREATE SCHEMA background;
+GRANT ALL ON SCHEMA background TO nobody;
+
+--
+-- Tables
+--
+
+\i ./tables/background.sql
diff --git a/admin/backgroundImage/Database/tables/background.sql b/admin/backgroundImage/Database/tables/background.sql
new file mode 100644 (file)
index 0000000..02527fc
--- /dev/null
@@ -0,0 +1,12 @@
+--
+-- Background image database
+--
+DROP TABLE IF EXISTS background.image;
+CREATE TABLE background.image (
+    image TEXT,
+    updated DATE,
+    version INTEGER
+);
+
+INSERT INTO background.image (image, updated, version) values ('', current_date, 1);
+GRANT ALL ON background.image TO nobody;
diff --git a/admin/backgroundImage/index.php b/admin/backgroundImage/index.php
new file mode 100644 (file)
index 0000000..df830c5
--- /dev/null
@@ -0,0 +1,76 @@
+<?php
+/**
+ * File: backfroundImage.php
+ *
+ * PHP script to change the background image for the website.
+ */
+require '../../setup.phtml';
+$debug = false;
+
+$smarty = new Toolkit_Smarty(
+    BASE_PATH . 'admin/backgroundImage/smarty_tmp/',
+    BASE_PATH . 'admin/backgroundImage/smarty_comp/',
+    BASE_PATH . 'admin/backgroundImage/smarty_conf/',
+    BASE_PATH . 'admin/backgroundImage/smarty_cache/'
+);
+$dbh = Toolkit_Database::getInstance();
+if ($_FILES) {
+    $data = '<pre>' . print_r($_FILES, true) . '</pre>';
+    if ($_FILES['new_image']['size'] > 0 && !$_FILES['new_image']['error']) {
+        $mimeTypes = array(
+            'image/jpeg',
+            'image/jpg',
+            'image/gif',
+            'image/png',
+        );
+        if (in_array($_FILES['new_image']['type'], $mimeTypes)) {
+            try {
+                $dbh = Toolkit_Database::getInstance();
+                $ia = new Toolkit_FileServer_ImageAdapter();
+                $upload = $ia->upload('new_image');
+                $sql = "
+                UPDATE background.image
+                   SET image = :image,
+                       updated = current_date,
+                       version = version + 1";
+                $stmt = $dbh->prepare($sql);
+                $stmt->bindParam(':image', $upload['name']);
+                $stmt->execute();
+                $message = '<p>Image upload Successful!</p>';
+            } catch(FileServerException $e) {
+                echo '<pre>$e: ' . print_r($e, true) . '</pre>';
+            } 
+            // write the style sheet file out to disk
+            $styleSheetContent = '
+body {
+    background-image: url("' . FILE_SERVER_URL . IS_OWNER_ID . '/backgroundImage/' . $upload['name'] . '");
+}
+';
+            file_put_contents(BASE . 'css/background.css', $styleSheetContent);
+            // clean the cache file for the version
+        } else {
+            $message = '<p>Image uploaded is not jpeg, png, or gif. Please upload only these types</p>';
+        }
+    } else if ($_FILES['new_image']['error']) {
+        $message = '<p>There was an ERROR uploading your file!</p>';
+    } 
+} 
+
+$sql = "
+SELECT *
+  FROM background.image";
+$image_data = $dbh->query($sql)->fetch(PDO::FETCH_ASSOC);
+$bg_image   = $image_data['image'];
+$bg_version = $image_data['version'];
+$bg_updated = $image_data['updated'];
+
+$smarty->assign('message', $message);
+$smarty->assign('image_path', FILE_SERVER_URL . IS_OWNER_ID . '/original/');
+$smarty->assign('bg_image', $bg_image);
+$smarty->assign('bg_version', $bg_version);
+$smarty->assign('bg_updated', $bg_updated);
+if ($debug) {
+    $smarty->assign('debug', '<pre>' . print_r($_FILES, true) . '</pre>');
+}
+
+$smarty->display('index.tpl');
diff --git a/admin/backgroundImage/smarty_comp/74702a15f989dbc8f6253a674d3d01ba61a34cd6.file.index.tpl.php b/admin/backgroundImage/smarty_comp/74702a15f989dbc8f6253a674d3d01ba61a34cd6.file.index.tpl.php
new file mode 100644 (file)
index 0000000..8ac59cf
--- /dev/null
@@ -0,0 +1,60 @@
+<?php /* Smarty version Smarty-3.1.14, created on 2016-05-06 12:03:49
+         compiled from "/var/www/server/www.cityofmi.org/admin/backgroundImage/smarty_tmp/index.tpl" */ ?>
+<?php /*%%SmartyHeaderCode:1074262171572b6b836dead9-11134679%%*/if(!defined('SMARTY_DIR')) exit('no direct access allowed');
+$_valid = $_smarty_tpl->decodeProperties(array (
+  'file_dependency' => 
+  array (
+    '74702a15f989dbc8f6253a674d3d01ba61a34cd6' => 
+    array (
+      0 => '/var/www/server/www.cityofmi.org/admin/backgroundImage/smarty_tmp/index.tpl',
+      1 => 1462550627,
+      2 => 'file',
+    ),
+  ),
+  'nocache_hash' => '1074262171572b6b836dead9-11134679',
+  'function' => 
+  array (
+  ),
+  'version' => 'Smarty-3.1.14',
+  'unifunc' => 'content_572b6b8370cdf3_84747520',
+  'variables' => 
+  array (
+    'message' => 0,
+    'image_path' => 0,
+    'bg_image' => 0,
+    'bg_updated' => 0,
+    'bg_version' => 0,
+    'debug' => 0,
+  ),
+  'has_nocache_code' => false,
+),false); /*/%%SmartyHeaderCode%%*/?>
+<?php if ($_valid && !is_callable('content_572b6b8370cdf3_84747520')) {function content_572b6b8370cdf3_84747520($_smarty_tpl) {?><html>
+<head>
+    <title>Background Image</title>
+</head>
+<body>
+<h1>Background Image</h1>
+<?php if ($_smarty_tpl->tpl_vars['message']->value){?>
+    <?php echo $_smarty_tpl->tpl_vars['message']->value;?>
+
+<?php }?>
+<form action="index.php" method="post" enctype="multipart/form-data">
+<p>This image needs to be 1900 x 1400 (height x width)</p>
+<span>Only upload images of type jpg png or gif)</span>
+<input type="file" name="new_image" />
+<input type="submit" value="Upload New Image" />
+</form>
+<div><img src="<?php echo $_smarty_tpl->tpl_vars['image_path']->value;?>
+<?php echo $_smarty_tpl->tpl_vars['bg_image']->value;?>
+"></div>
+<div><strong>Last Update</strong> <?php echo $_smarty_tpl->tpl_vars['bg_updated']->value;?>
+</div>
+<div><strong>Version</strong> <?php echo $_smarty_tpl->tpl_vars['bg_version']->value;?>
+</div>
+<?php if ($_smarty_tpl->tpl_vars['debug']->value){?>
+    <?php echo $_smarty_tpl->tpl_vars['debug']->value;?>
+
+<?php }?>
+</body>
+</html>
+<?php }} ?>
\ No newline at end of file
diff --git a/admin/backgroundImage/smarty_tmp/index.tpl b/admin/backgroundImage/smarty_tmp/index.tpl
new file mode 100644 (file)
index 0000000..27b7700
--- /dev/null
@@ -0,0 +1,23 @@
+<html>
+<head>
+    <title>Background Image</title>
+</head>
+<body>
+<h1>Background Image</h1>
+{if $message}
+    {$message}
+{/if}
+<form action="index.php" method="post" enctype="multipart/form-data">
+<p>This image needs to be 1900 x 1400 (height x width)</p>
+<span>Only upload images of type jpg png or gif)</span>
+<input type="file" name="new_image" />
+<input type="submit" value="Upload New Image" />
+</form>
+<div><img src="{$image_path}{$bg_image}"></div>
+<div><strong>Last Update</strong> {$bg_updated}</div>
+<div><strong>Version</strong> {$bg_version}</div>
+{if $debug}
+    {$debug}
+{/if}
+</body>
+</html>
index e2de4de..30294c7 100644 (file)
@@ -55,6 +55,7 @@ li a:hover { background-color: #2C788F; color: #fff; }
 $conf = new Config;
 
 $nav['Home']    = MEDIA_BASE_URL.'admin/splash.phtml';
+$nav['Background Image'] = MEDIA_BASE_URL.'admin/backgroundImage/index.php';
 $nav['Toolbox'] = MEDIA_BASE_URL.'admin/toolbox.php';
 if (defined('GLM_BLOCKS') && GLM_BLOCKS) {
     $blocksConfig = new Zend_Config_Ini(
diff --git a/css/background.css b/css/background.css
new file mode 100644 (file)
index 0000000..d42fe84
--- /dev/null
@@ -0,0 +1,4 @@
+
+body {
+    background-image: url("http://is0.gaslightmedia.com/cityofmi/backgroundImage/is13-1462823942-73195.jpeg");
+}
index 9f8f152..b0e71b2 100755 (executable)
@@ -25,7 +25,7 @@ ShadowWhenNeeded {
     }
 body {
     background-color: #e8e5db;
-    background-image: url(assets/Spring_2016.jpeg);
+    /*background-image: url(assets/Spring_2016.jpeg);*/
     background-size: cover;
     background-attachment: fixed;
     font-size: 1.3rem;
index 60be10b..b8d9bd2 100755 (executable)
@@ -12,6 +12,7 @@
                <link rel="stylesheet" href="{mediaBaseURL:h}css/superfish.css" media="screen">
                <script src="{mediaBaseURL:h}js/hoverIntent.js"></script>
                <script src="{mediaBaseURL:h}js/superfish.js"></script>
+        <link rel="stylesheet" href="{mediaBaseURL:h}css/background.css?v={bgVersion}">
         <!-- initialise Superfish -->
         <script>
         jQuery(document).ready(function(){