From: Steve Sutton Date: Mon, 9 May 2016 20:00:32 +0000 (-0400) Subject: New feature for updating background image on front X-Git-Tag: v1.2^2~1^2~3 X-Git-Url: http://cvs2.gaslightmedia.com/gitweb/?a=commitdiff_plain;h=2008c693b4112ff950ce07cee955531902703a5d;p=web%2FCityofMI.git New feature for updating background image on front --- diff --git a/Toolkit/Page.php b/Toolkit/Page.php index 91a82bb..e6f9be5 100755 --- a/Toolkit/Page.php +++ b/Toolkit/Page.php @@ -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 index 0000000..6a58f14 --- /dev/null +++ b/Toolkit/Smarty.php @@ -0,0 +1,51 @@ + + * @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 + * @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 index 0000000..739d826 --- /dev/null +++ b/admin/backgroundImage/Database/application.sql @@ -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 index 0000000..02527fc --- /dev/null +++ b/admin/backgroundImage/Database/tables/background.sql @@ -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 index 0000000..df830c5 --- /dev/null +++ b/admin/backgroundImage/index.php @@ -0,0 +1,76 @@ +' . print_r($_FILES, true) . ''; + 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 = '

Image upload Successful!

'; + } catch(FileServerException $e) { + echo '
$e: ' . print_r($e, true) . '
'; + } + // 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 = '

Image uploaded is not jpeg, png, or gif. Please upload only these types

'; + } + } else if ($_FILES['new_image']['error']) { + $message = '

There was an ERROR uploading your file!

'; + } +} + +$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', '
' . print_r($_FILES, true) . '
'); +} + +$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 index 0000000..8ac59cf --- /dev/null +++ b/admin/backgroundImage/smarty_comp/74702a15f989dbc8f6253a674d3d01ba61a34cd6.file.index.tpl.php @@ -0,0 +1,60 @@ + +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%%*/?> + + + Background Image + + +

Background Image

+tpl_vars['message']->value){?> + tpl_vars['message']->value;?> + + +
+

This image needs to be 1900 x 1400 (height x width)

+Only upload images of type jpg png or gif) + + +
+
+
Last Update tpl_vars['bg_updated']->value;?> +
+
Version tpl_vars['bg_version']->value;?> +
+tpl_vars['debug']->value){?> + tpl_vars['debug']->value;?> + + + + + \ 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 index 0000000..27b7700 --- /dev/null +++ b/admin/backgroundImage/smarty_tmp/index.tpl @@ -0,0 +1,23 @@ + + + Background Image + + +

Background Image

+{if $message} + {$message} +{/if} +
+

This image needs to be 1900 x 1400 (height x width)

+Only upload images of type jpg png or gif) + + +
+
+
Last Update {$bg_updated}
+
Version {$bg_version}
+{if $debug} + {$debug} +{/if} + + diff --git a/admin/nav.phtml b/admin/nav.phtml index e2de4de..30294c7 100644 --- a/admin/nav.phtml +++ b/admin/nav.phtml @@ -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 index 0000000..d42fe84 --- /dev/null +++ b/css/background.css @@ -0,0 +1,4 @@ + +body { + background-image: url("http://is0.gaslightmedia.com/cityofmi/backgroundImage/is13-1462823942-73195.jpeg"); +} diff --git a/styles.css b/styles.css index 9f8f152..b0e71b2 100755 --- a/styles.css +++ b/styles.css @@ -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; diff --git a/templates/template.html b/templates/template.html index 60be10b..b8d9bd2 100755 --- a/templates/template.html +++ b/templates/template.html @@ -12,6 +12,7 @@ +