If this is your first visit, check our documentation. To post, register or login.
Forums / Code Matters / Zen Cart Code Suggestions / How about controlling a site's color(s) with the database?

How about controlling a site's color(s) with the database?

Started by dbltoe on 14 Dec 2017, 12:30 AM · Views: 231

Results 1 to 14 of 14
14 Dec 2017, 12:30 AM
#1
dbltoe avatar

dbltoe

Totally Zenned

Join Date:
Jan 2004
Location:
N of San Antonio TX
Posts:
9,906
Plugin Contributions:
23

How about controlling a site's color(s) with the database?

It's been around for a long time. The ability to insert variables into stylesheets (.css), that is. Over eight years ago the idea of "variable" in CSS was discussed.

It seems to be fairly easy to accomplish. One simply renames a stylesheet to .php vs .css. It's still listed as a stylesheet.```

<link rel='stylesheet' type='text/css' href='css/colorstyle.php' /> ``` In the colorstyle.php file, the first line would re-establish the main purpose of the file by stating``` </php header("Content-type: text/css; charset: UTF-8"); ?> ``` Then, the code would establish colors of the site. If one were using the Color Change mod, there would be nine colors to establish.``` </php header("Content-type: text/css; charset: UTF-8"); $warningColor1 = "#CC3333"; $warningColor2 = "#CC6600"; $mainColor1 ="#6699CC"; $mainColor2 ="#99CCFF"; $mainColor3 ="#CCFFFF"; $formColor1 ="#DCDCDC"; $formColor2 ="#EEEEEE"; $textColor1 ="#FFFFFF"; $textColor2 ="#000000"; ?> ``` Then, in the same file, you would continue on with the insertion of variables using some PHP``` #MainWrapper {background-color: <php echo $mainColor3; ?>;} ``` Of course, the next logical step would be to allow the site owner to place these selections in the database through a menu in the admin. Then, the file would run a query on the database to find the colors and assign them to their variable.

I'm thinking of this as a replacement for the Classic and Template Default that would allow quicker up time for new users. One could even add a transparency level in the Admin form for rgba submission.

Of course the user can still go to specific spots in the file and "adjust" at will.

Thoughts?

Need a hand with Zen Cart? Hire the team at myZenCartZone.com for upgrades, repairs, and custom plugins.
Zen Cart Certified hosting at myZenCartHost.com

14 Dec 2017, 6:45 PM
#2
lat9 avatar

lat9

Administrator

Join Date:
Sep 2009
Location:
Stuart, FL
Posts:
14,142
Plugin Contributions:
56

Re: How about controlling a site's color(s) with the database?

I believe that the CSS/JS Loader plugin has supported .php extensions in a template's /css directory for a while. In that implementation, the /css/mystyle.php files looked similar to:

<?php
// PHP stuff
?>
<style type="text/css">
{insert css styles, modified by the PHP code here}
</style>

I think that having that kind of processing built into Zen Cart would be a good thing and a store and/or template designer could then decide whether their customizations would be stored in the database or simply coded into the .php file itself.

What would need to be defined as part of the change is (like for the jscript_.js and jscript_.php files) a statement of the standard load-order for those files. There's already a "pecking order" for the css-files' loading; do the associated .css files get loaded prior to the .php ones?

14 Dec 2017, 7:14 PM
#3
design75 avatar

design75

Totally Zenned

Join Date:
Dec 2009
Location:
Amersfoort, The Netherlands
Posts:
2,862
Plugin Contributions:
5

Re: How about controlling a site's color(s) with the database?

You can stil use it in css/js loader, and it is very handy.
Although I must admit I never used php for css files, I do regularly use it in JavaScript files

lat9:

I believe that the CSS/JS Loader plugin has supported .php extensions in a template's /css directory for a while. In that implementation, the /css/mystyle.php files looked similar to:

<?php // PHP stuff ?> <style type="text/css"> {insert css styles, modified by the PHP code here} </style>
> I think that having that kind of processing built into Zen Cart would be a good thing and a store and/or template designer could then decide whether their customizations would be stored in the database or simply coded into the .php file itself.
> 
> What would need to be defined as part of the change is (like for the jscript_*.js and jscript_*.php files) a statement of the standard load-order for those files.  There's already a "pecking order" for the css-files' loading; do the associated .css files get loaded prior to the .php ones?
14 Dec 2017, 8:32 PM
#4
mc12345678 avatar

mc12345678

Totally Zenned

Join Date:
Jul 2012
Posts:
16,908
Plugin Contributions:
2

Re: How about controlling a site's color(s) with the database?

My thoughts would be and in order to permit the php files to offer the desired flexibility without modification of existing css files would to expand the existing pecking order (see includes/templates/template_default/css/CSS_read_me.txt) such that the php files loaded after the existing css files. Otherwise, the css files could blanketly override the change that was intended to override an existing css file and require more "smaller" targeted files to obtain the desired effect. Whether the inclusion is by notifier(s) or other inserted code.

Regardless it would be good to see such overrides available for the layouts such as the ZC 1.5.5 responsive_xxx.css files wether that template remains with ZC or not.

ZC Installation/Maintenance Support <- Site
Contribution for contributions welcome...

14 Dec 2017, 9:17 PM
#5
dbltoe avatar

dbltoe

Totally Zenned

Join Date:
Jan 2004
Location:
N of San Antonio TX
Posts:
9,906
Plugin Contributions:
23

Re: How about controlling a site's color(s) with the database?

Apologies if i was not clear in my proposal.

This suggestion is based on the Color Change Mod which separates color calls from nearly all other calls.

Therefore, with a little more cleansing and the addition of color variables, it would not matter when the file loaded as long as it loaded with the other css files.

The "colorlist.php" would replace the stylesheet_colors_split.css to just change colors. All other calls in the standard stylesheets would not be affected. IF a "special" css per the readme is needed, they seldom address color BUT, could be set to load last to preclude any problem.

Need a hand with Zen Cart? Hire the team at myZenCartZone.com for upgrades, repairs, and custom plugins.
Zen Cart Certified hosting at myZenCartHost.com

14 Dec 2017, 9:37 PM
#6
mc12345678 avatar

mc12345678

Totally Zenned

Join Date:
Jul 2012
Posts:
16,908
Plugin Contributions:
2

Re: How about controlling a site's color(s) with the database?

Yes you specifically proposed addressing one targeted aspect, but if implementation to address just that is as "easy" as applying to a larger concept, why stop short? :) it would "fix" your specialized vision, but could be used for broader application.

You can step away from anything bigger, but as a topic of discussion likely some form of credit would be yours. :) inspiring the "masses". :)

ZC Installation/Maintenance Support <- Site
Contribution for contributions welcome...

14 Jan 2018, 9:34 PM
#7
drbyte avatar

drbyte

Sensei

Join Date:
Jan 2004
Posts:
63,512
Plugin Contributions:
176

Re: How about controlling a site's color(s) with the database?

Getting to full db-driven control requires a few phases.
The first is getting the colors stylesheet to be php-driven.

Using today's v156-dev-alpha as a base, this involves a small addition to html_header.php around line 124 (putting it before the print-stylesheet is loaded):

// Load the main color palette
?>
<link rel="stylesheet" type="text/css" href="<?php echo $template->get_template_dir('.php',DIR_WS_TEMPLATE, $current_page_base,'css') . '/' . 'stylesheet_colors_main.php'; ?>" />
<?php

and converting the stylesheet_color_split.css to stylesheet_colors_main.php, something like the file attached.

However, there are a number of additional colors therein which need converting to a PHP variable.

I also notice that there's a duplicate entry for messageStackSuccess, and that the Warning and Caution are the same color.

.
Zen Cart - putting the dream of business ownership within reach of anyone!
Donate to: DrByte directly or to the Zen Cart team as a whole

Remember: Any code suggestions you see here are merely suggestions. You assume full responsibility for your use of any such suggestions, including any impact ANY alterations you make to your site may have on your PCI compliance.
Furthermore, any advice you see here about PCI matters is merely an opinion, and should not be relied upon as "official". Official PCI information should be obtained from the PCI Security Council directly or from one of their authorized Assessors.

18 Jan 2018, 12:01 PM
#8
dbltoe avatar

dbltoe

Totally Zenned

Join Date:
Jan 2004
Location:
N of San Antonio TX
Posts:
9,906
Plugin Contributions:
23

Re: How about controlling a site's color(s) with the database?

This is looking good. I've come up with a database layout that includes all the combos that we have found useful with this method. It would look like```
-- ------------------------------ Table structure for template_color


DROP TABLE IF EXISTS template_color;
CREATE TABLE template_color (
template_color_id int(11) NOT NULL AUTO_INCREMENT COMMENT 'ID for responsive_classic color table',
main1 varchar(12) CHARACTER SET utf8 DEFAULT '6699CC' COMMENT 'Color 1 for Responsive Classic',
main1rgb varchar(25) CHARACTER SET utf8 DEFAULT '102,153,204' COMMENT 'Color 1 RGBA Transparency Settings',
main2 varchar(12) CHARACTER SET utf8 DEFAULT '99CCFF' COMMENT 'Color 2 for Responsive Classic',
main2rgb varchar(25) CHARACTER SET utf8 DEFAULT '153,204,255' COMMENT 'Color 2 RGBA Transparency Settings',
main3 varchar(12) CHARACTER SET utf8 DEFAULT 'CCFFFF' COMMENT 'Color 3 for Responsive Classic',
main3rgb varchar(25) CHARACTER SET utf8 DEFAULT '204,255,255' COMMENT 'Color 3 RGBA Transparency Settings',
links varchar(12) CHARACTER SET utf8 DEFAULT 'CC3333' COMMENT 'Link Color for Responsive Classic',
warn varchar(12) CHARACTER SET utf8 DEFAULT 'CC6600' COMMENT 'Warning Color for Responsive Classic',
form1 varchar(12) CHARACTER SET utf8 DEFAULT 'DCDCDC' COMMENT 'Form Color 1 for Responsive Classic',
form1rgb varchar(25) CHARACTER SET utf8 DEFAULT '220,220,220' COMMENT 'Form RGB Color 1 for Responsive Classic',
form2 varchar(12) CHARACTER SET utf8 DEFAULT 'EEEEEE' COMMENT 'Form Color 2 for Responsive Classic',
form2rgb varchar(25) CHARACTER SET utf8 DEFAULT '238,238,238' COMMENT 'Form RGB Color 2 for Responsive Classic',
text1 varchar(12) CHARACTER SET utf8 DEFAULT 'FFFFFF' COMMENT 'Default Text Color for Dark Background in Responsive Classic',
text1rgb varchar(25) CHARACTER SET utf8 DEFAULT '255,255,255' COMMENT 'Default Text RGB Color for Dark Background in Responsive Classic',
text2 varchar(12) CHARACTER SET utf8 DEFAULT '000000' COMMENT 'Default Text Color for Light Background in Responsive Classic',
defaultbg varchar(12) CHARACTER SET utf8 DEFAULT 'FFFFFF' COMMENT 'Default Background Color for Responsive Classic',
PRIMARY KEY (template_color_id)
) ENGINE=MyISAM AUTO_INCREMENT=6 DEFAULT CHARSET=latin1;


-- Records of template_color


INSERT INTO template_color VALUES ('1', '6699CC', '102,153,204', '99CCFF', '153,204,255', 'CCFFFF', '204,255,255', 'CC3333', 'CC6600', 'DCDCDC', '220,220,220', 'EEEEEE', '238,238,238', 'FFFFFF', '255,255,255', '000000', 'FFFFFF');
INSERT INTO template_color VALUES ('2', 'C6C78C', '204,102,0', 'E7C39C', '231,195,156', 'E7DF9C', '204,255,255', 'CC3333', 'CC6600', 'DCDCDC', '220,220,220', 'EEEEEE', '238,238,238', 'FFFFFF', '255,255,255', '000000', 'FFFFFF');
INSERT INTO template_color VALUES ('3', 'CC9966', '204,153,102', '6969CC', '105,105,204', '85C285', '133,194,133', 'CBD2031', 'CC6600', 'DCDCDC', '220,220,220', 'EEEEEE', '238,238,238', 'FFFFFF', '255,255,255', '000000', 'FFFFFF');
INSERT INTO template_color VALUES ('4', '6F674E', '111,103,78', 'D2B48C', '210,180,140', 'FDCFA0', '253,207,160', 'BD2031', 'CC6600', 'DCDCDC', '220,220,220', 'EEEEEE', '238,238,238', 'FFFFFF', '255,255,255', '000000', 'FFFFFF');
INSERT INTO template_color VALUES ('5', 'DAB600', '218,182,0', 'E9D700', '233,215,0', 'F8ED62', '248,237,98', 'CC3333', 'CC6600', 'DCDCDC', '220,220,220', 'EEEEEE', '238,238,238', 'FFFFFF', '255,255,255', '000000', 'FFFFFF');


I can envision moving the logo into this as well.  Adding a logo image column with additional width and height would not be that difficult.  It would also give the ability to easily change the graphic with the color scheme all in one location.

I also think this should be in the Tools menu between Template Selection and Layout Boxes Controller.

I modified DrByte's zip to match the database column name info above and loaded the file with the header BUT I keep getting a 403 no matter what I do.

Some solutions say to leave as .css and add .htaccess to tell the system to parse the file as php.  Is this viable or not?

 [Attachment no longer available]

Need a hand with Zen Cart? Hire the team at myZenCartZone.com for upgrades, repairs, and custom plugins.
Zen Cart Certified hosting at myZenCartHost.com

18 Jan 2018, 12:59 PM
#9
lat9 avatar

lat9

Administrator

Join Date:
Sep 2009
Location:
Stuart, FL
Posts:
14,142
Plugin Contributions:
56

Re: How about controlling a site's color(s) with the database?

dbltoe:

... I modified DrByte's zip to match the database column name info above and loaded the file with the header BUT I keep getting a 403 no matter what I do. ...
I believe that, in a manner similar to the jscript_xxx.php files' generation of any <script> tags, the stylesheet_colors_main.php file must be responsible for generating an in-line <style> tag with the computed color values.

That said, the change to the html_header.php file would look like:

// Load the main color palette 
require $template->get_template_dir('.php',DIR_WS_TEMPLATE, $current_page_base,'css') . '/' . 'stylesheet_colors_main.php';

... and the file's processing would look like:

<?php
// some commentary
?>
<style type="text/css">
<!--
{required styling output here}
-->
</style>
18 Jan 2018, 11:16 PM
#10
dbltoe avatar

dbltoe

Totally Zenned

Join Date:
Jan 2004
Location:
N of San Antonio TX
Posts:
9,906
Plugin Contributions:
23

Re: How about controlling a site's color(s) with the database?

in html_header.php```
/** * load main color stylesheet as php file
*/
?>

<link rel="stylesheet" type="text/css" href="<?php echo $template->get_template_dir('.php',DIR_WS_TEMPLATE, $current_page_base,'css') . '/' . 'stylesheet_colors_main2.php'; ?>" /> <?php ``` At start of stylesheet_colors_main2.php``` <?php// IMPORTANT NOTE: THIS IS NOT READY FOR FINAL PRODUCTION USE. IT IS A SAMPLE ONLY. // IF YOU ARE TRYING TO USE THIS FOR A LIVE SITE, YOU SHOULD DOWNLOAD THE COMPLETED VERSION, not this file. //

header("Content-type: text/css; charset: UTF-8");

$tplColor = array();
$tplColor['links'] = '#CC3333';
$tplColor['warn'] = '#CC6600';
$tplColor['main1'] ='#6699CC';
$tplColor['main1rgb'] = '102,153,204';
$tplColor['main2'] ='#99CCFF';
$tplColor['main2rbg'] = '153,204,255';
$tplColor['main3'] ='#CCFFFF';
$tplColor['main3rgb'] = '204,255,255';
$tplColor['form1'] ='#DCDCDC';
$tplColor['form1rgb'] = '220,220,220';
$tplColor['form2'] ='#EEEEEE';
$tplColor['form2rgb'] = '238,238,238';
$tplColor['text1'] ='#FFFFFF';
$tplColor['text1rgb'] = '255,255,255';
$tplColor['text2'] ='#000000';
$tplColor['defaultbg'] = '#FFF';

// @TODO: will replace the above array from a function lookup: $tplColors = zen_get_template_colors();

?>

View source shows the file but console shows 403.

Need a hand with Zen Cart? Hire the team at myZenCartZone.com for upgrades, repairs, and custom plugins.
Zen Cart Certified hosting at myZenCartHost.com

19 Jan 2018, 11:29 PM
#11
drbyte avatar

drbyte

Sensei

Join Date:
Jan 2004
Posts:
63,512
Plugin Contributions:
176

Re: How about controlling a site's color(s) with the database?

dbltoe:

This is looking good. I've come up with a database layout
I was envisioning that perhaps the suggested default color scheme might be defined in a json array in the template_info.php file, so it could "ship with" the template.
Perhaps even offer up to 5 suggested schemes for said template.

dbltoe:

I can envision moving the logo into this as well. Adding a logo image column with additional width and height would not be that difficult. It would also give the ability to easily change the graphic with the color scheme all in one location.I understand your thinking here, but I wonder if that becomes too rigid when it's tied to the color palette if there are also other templates installed?

dbltoe:

I also think this should be in the Tools menu between Template Selection and Layout Boxes Controller.Makes sense. But could also be a tool within the TemplateSelect page.

dbltoe:

Some solutions say to leave as .css and add .htaccess to tell the system to parse the file as php. Is this viable or not?No, don't rely on .htaccess, else it won't work unless Apache is the web engine.

lat9:

I believe that, in a manner similar to the jscript_xxx.php files' generation of any <script> tags, the stylesheet_colors_main.php file must be responsible for generating an in-line <style> tag with the computed color values.
Not necessary since the .php file is outputting the CSS mime type in the header.

.
Zen Cart - putting the dream of business ownership within reach of anyone!
Donate to: DrByte directly or to the Zen Cart team as a whole

Remember: Any code suggestions you see here are merely suggestions. You assume full responsibility for your use of any such suggestions, including any impact ANY alterations you make to your site may have on your PCI compliance.
Furthermore, any advice you see here about PCI matters is merely an opinion, and should not be relied upon as "official". Official PCI information should be obtained from the PCI Security Council directly or from one of their authorized Assessors.

20 Jan 2018, 12:07 AM
#12
drbyte avatar

drbyte

Sensei

Join Date:
Jan 2004
Posts:
63,512
Plugin Contributions:
176

Re: How about controlling a site's color(s) with the database?

Your 403 problem is because we're attempting to load a .php file from below the 'includes' directory, an action which is blocked for security reasons via .htaccess.

I'm toying with another way to do it, much like making an ajax call to a handler file.

But maybe the better way is to just have the admin generate the css file (not unlike a preprocessor or minify tool would do, but including color details). This way caching doesn't become necessary for db performance reasons.

Lots of ways to tackle it ... hmmmm ...

.
Zen Cart - putting the dream of business ownership within reach of anyone!
Donate to: DrByte directly or to the Zen Cart team as a whole

Remember: Any code suggestions you see here are merely suggestions. You assume full responsibility for your use of any such suggestions, including any impact ANY alterations you make to your site may have on your PCI compliance.
Furthermore, any advice you see here about PCI matters is merely an opinion, and should not be relied upon as "official". Official PCI information should be obtained from the PCI Security Council directly or from one of their authorized Assessors.

20 Jan 2018, 6:53 PM
#13
dbltoe avatar

dbltoe

Totally Zenned

Join Date:
Jan 2004
Location:
N of San Antonio TX
Posts:
9,906
Plugin Contributions:
23

Re: How about controlling a site's color(s) with the database?

I was envisioning that perhaps the suggested default color scheme might be defined in a json array in the template_info.php file, so it could "ship with" the template.
Perhaps even offer up to 5 suggested schemes for said template.I throw them out knowing you can translate it to better ways.:P
I understand your thinking here, but I wonder if that becomes too rigid when it's tied to the color palette if there are also other templates installed?
Perhaps leave the logo AND add to scheme. Existing logo overrides scheme. Just hate to see opportunity to have logo display in different colors, holiday theme, etc.
Makes sense. But could also be a tool within the TemplateSelect page.See first item above.:yes:

I am enjoying the education!

Need a hand with Zen Cart? Hire the team at myZenCartZone.com for upgrades, repairs, and custom plugins.
Zen Cart Certified hosting at myZenCartHost.com

19 Jul 2018, 2:42 AM
#14
dbltoe avatar

dbltoe

Totally Zenned

Join Date:
Jan 2004
Location:
N of San Antonio TX
Posts:
9,906
Plugin Contributions:
23

Re: How about controlling a site's color(s) with the database?

Three rodeos and a granddaughter's wedding later, let's get this thing rolling again.

I have five color combos already in the download.

I know there are a few minor errors in the stylesheet_colors_split.css as a customer's file got loaded instead of the clean stylesheet for the mod.

I also believe the same process will work with bootstrap. A few extra calls and the combination of background and font colors in one call may need work, but the overall goal is to get better, easier, whichever way works.

Need a hand with Zen Cart? Hire the team at myZenCartZone.com for upgrades, repairs, and custom plugins.
Zen Cart Certified hosting at myZenCartHost.com