user stylesheets and colorset stylesheets

Skinning and designing Serendipity (CSS, HTML, Smarty)
Timbalu
Regular
Posts: 4598
Joined: Sun May 02, 2004 3:04 pm

Re: user stylesheets and colorset stylesheets

Post by Timbalu »

Don Chambers wrote:I thought I was onto something with this:

[...]

Problem I am having is that $template_loaded_config['colorset'] is empty, even though the config option is set to a selected color....

I've probably missed something really simple, but it is late, and I need sleep. Any suggestions appreciated.
Yes, that "[...]" is what I meant, or use the example down below.
Just change global $serendipity; to global $template_loaded_config; and read about how to prepend/append to serendipity.css in my following example.

Code: Select all

function serendipity_plugin_api_event_hook($event, &$bag, &$eventData, $addData = null) {
    global $serendipity; # use only when needed!
    
    switch($event) {
        case 'frontend_footer':
            echo '<!--PLUGIN API-->';
            break;

        case 'css':
            echo "\n place styles directly \n\n"; // - will prepend to serendipity.css
            $eventData .= "\n place styles \n\n"; // - will append to serendipity css

            # both will apply to plugin section, say before user.css data.
            break;

        default:
            return false;

    }
    return true;
}
Regards,
Ian

Serendipity Styx Edition and additional_plugins @ https://ophian.github.io/ @ https://github.com/ophian
onli
Regular
Posts: 2825
Joined: Tue Sep 09, 2008 10:04 pm
Contact:

Re: user stylesheets and colorset stylesheets

Post by onli »

I hope I did not miss that yet, but: What happens if you use the css hook to emit the colorset style? Won't that always be both before the userstyle.css and after the css of the theme in serendipity.css? *Edit*: Ah, Ians code looks like you just arrived there.

Otherwise: If there is a specific small change to the loading order you agree on, I would invest some time to look whether it is possible to do. But in general, the loading order is not always that easy to change as it depends on when the plugin-api is loaded and how the code is arranged, something that might collide with other aspects of s9y. Not saying changes there are impossible, just saying it is not something I can promise can be done easily.
Don Chambers
Regular
Posts: 3652
Joined: Mon Feb 13, 2006 2:40 am
Location: Chicago, IL, USA
Contact:

Re: user stylesheets and colorset stylesheets

Post by Don Chambers »

$eventData was the missing piece! Thank you!

global $serendipity & global $template_loaded_config - neither is getting me $template_loaded_config['colorset'] inside a function.....
=Don=
Timbalu
Regular
Posts: 4598
Joined: Sun May 02, 2004 3:04 pm

Re: user stylesheets and colorset stylesheets

Post by Timbalu »

Is the function placed in config.inc before or after the $template_loaded_config creation ? :)
I should be placed below, IMHO.

Code: Select all

$template_global_config = array('navigation' => true);
$template_loaded_config = serendipity_loadThemeOptions($template_config, $serendipity['smarty_vars']['template_option'], true);
serendipity_loadGlobalThemeOptions($template_config, $template_loaded_config, $template_global_config);

function serendipity_plugin_api_event_hook($event, &$bag, &$eventData, $addData = null) {
   global $template_loaded_config;
...
}
Regards,
Ian

Serendipity Styx Edition and additional_plugins @ https://ophian.github.io/ @ https://github.com/ophian
Don Chambers
Regular
Posts: 3652
Joined: Mon Feb 13, 2006 2:40 am
Location: Chicago, IL, USA
Contact:

Re: user stylesheets and colorset stylesheets

Post by Don Chambers »

yes, after. Still no good.
=Don=
Don Chambers
Regular
Posts: 3652
Joined: Mon Feb 13, 2006 2:40 am
Location: Chicago, IL, USA
Contact:

Re: user stylesheets and colorset stylesheets

Post by Don Chambers »

Global wasn't working for me, and I do not know why. However, I found a way to do it, but I want to know if this is ok or a bad idea...

I am loading the colorset as shown earlier in this thread, then using define like this:

Code: Select all

$themestyle_data = array();  
$themestyle_data['colorset'] = '';
$themestyle_data['skinset'] = ''; // I'll deal with this later when colorset is working...
$colorset_file = dirname(__FILE__) . '/' . $template_loaded_config['colorset'] . '_style.css';
if (is_readable($colorset_file)) {
    $colorset_css = file_get_contents($colorset_file);
    if (!empty($colorset_css)) {
        $themestyle_data['colorset'] = $colorset_css;
    }
}
define(THEMESETDATA, $themestyle_data['colorset']);
$template_loaded_config['themestyle_data'] = $themestyle_data;
Then, inside the function serendipity_plugin_api_pre_event_hook,

Code: Select all

        case 'css':
            $eventData .='/* colorset css */ \n\n' . THEMESETDATA;
Thoughts?
=Don=
Timbalu
Regular
Posts: 4598
Joined: Sun May 02, 2004 3:04 pm

Re: user stylesheets and colorset stylesheets

Post by Timbalu »

Don Chambers wrote:yes, after. Still no good.
Strange...

I think I got it:

Code: Select all

function serendipity_plugin_api_event_hook($event, &$bag, &$eventData, $addData = null) {
    global $serendipity;
    
    switch($event) {
        case 'frontend_footer':
            echo "\n<!--PLUGIN API-->\n";
            break;

        case 'css':
            // by file
            #echo file_get_contents(dirname(__FILE__) . 'theme_colours.css');
            // or direct by
            echo '
/* test for theme colours start */

.test_colourful { color: red; }

/* test prepend theme colours end */

'; // - will prepend to serendipity.css

            // by file
            #$eventData .= file_get_contents(dirname(__FILE__) . 'theme_colours.css');
            // or direct by
            $eventData .= '
/* test for theme colours start */

.test_colourful { color: red; }

/* test append theme colours end */

'; // - will append to serendipity css


            # both will apply to plugin section, say before user.css data.

				$themestyle_data = array(); 
				$themestyle_data['colorset'] = '';
				$themestyle_data['skinset'] = ''; // I'll deal with this later when colorset is working...
				$colorset_file = dirname(__FILE__) . '/' . $serendipity['template_loaded_config']['colorset'] . '_style.css';
				if (is_readable($colorset_file)) {
					$colorset_css = file_get_contents($colorset_file);
					if (!empty($colorset_css)) {
						$themestyle_data['colorset'] = $colorset_css;
						$eventData .= $themestyle_data['colorset'];
					}
				}
				#print_r($serendipity['template_loaded_config']);
				echo "\n\n";
				break;

        default:
            return false;

    }
    return true;
}

and

Code: Select all

$template_global_config = array('navigation' => true);
$serendipity['template_loaded_config'] = $template_loaded_config = serendipity_loadThemeOptions($template_config, $serendipity['smarty_vars']['template_option'], true);
serendipity_loadGlobalThemeOptions($template_config, $template_loaded_config, $template_global_config);
Place of function serendipity_plugin_api_event_hook() does not matter.

Code: Select all

$template_config = array(
    array(
        'var'           => 'colorset',
        'name'          => 'THEME_COLORSET',
        'type'          => 'custom',
/*        'type'          => 'select',*/
        'default'       => 'testColorSetFile'/*,
        'select_values' => $colorsets*/
    ),
	array(
....
Don't ask me why, but it seems only the universal global $serendipity will do here.... since serendipity_loadGlobalThemeOptions() somehow destroys $template_loaded_config...
Regards,
Ian

Serendipity Styx Edition and additional_plugins @ https://ophian.github.io/ @ https://github.com/ophian
Timbalu
Regular
Posts: 4598
Joined: Sun May 02, 2004 3:04 pm

Re: user stylesheets and colorset stylesheets

Post by Timbalu »

Oh - I see we were heading to some similar approach... :)
Using a constant is as much global too, I assume - but not as good as an additional $serendipity subarray.
Regards,
Ian

Serendipity Styx Edition and additional_plugins @ https://ophian.github.io/ @ https://github.com/ophian
Don Chambers
Regular
Posts: 3652
Joined: Mon Feb 13, 2006 2:40 am
Location: Chicago, IL, USA
Contact:

Re: user stylesheets and colorset stylesheets

Post by Don Chambers »

Yes that does work Ian.... There were only two lines that made the difference between what I had, and what you suggested....

I had this:

Code: Select all

$template_loaded_config = serendipity_loadThemeOptions($template_config, $serendipity['smarty_vars']['template_option'], true);
Yours is this:

Code: Select all

$serendipity['template_loaded_config'] = $template_loaded_config = serendipity_loadThemeOptions($template_config, $serendipity['smarty_vars']['template_option'], true);
And in the function, I had this:

Code: Select all

$colorset_file = dirname(__FILE__) . '/' . $template_loaded_config['colorset'] . '_style.css';
and you have this:

Code: Select all

$colorset_file = dirname(__FILE__) . '/' . $serendipity['template_loaded_config']['colorset'] . '_style.css';
Was there a change in s9y recently, or have I been doing this wrong for awhile? :wink:
=Don=
Timbalu
Regular
Posts: 4598
Joined: Sun May 02, 2004 3:04 pm

Re: user stylesheets and colorset stylesheets

Post by Timbalu »

Don Chambers wrote:Was there a change in s9y recently, or have I been doing this wrong for awhile?
I don't think so... we just did not have that situation yet, I assume.
Its somehow related to serendipity_loadGlobalThemeOptions() I think and may be some referencing "issue"...
Regards,
Ian

Serendipity Styx Edition and additional_plugins @ https://ophian.github.io/ @ https://github.com/ophian
Don Chambers
Regular
Posts: 3652
Joined: Mon Feb 13, 2006 2:40 am
Location: Chicago, IL, USA
Contact:

Re: user stylesheets and colorset stylesheets

Post by Don Chambers »

Whatever it is, it seems to be working... Thanks again!

but onto the next problem..

when referencing images in the folder /templates/mytemplate/img/ we do this in style.css:

Code: Select all

background-image: url('{TEMPLATE_PATH}img/image.png')
This works fine in style.css, but does not work in additionally loaded stylesheets.... So we use this in additional stylesheets (ie, red_style.css):

Code: Select all

background-image: url('img/image.png')
- we do not use {TEMPLATE_PATH}.

Neither of these methods works when injecting the colorset.css file into serendipity.css.
=Don=
Don Chambers
Regular
Posts: 3652
Joined: Mon Feb 13, 2006 2:40 am
Location: Chicago, IL, USA
Contact:

Re: user stylesheets and colorset stylesheets

Post by Don Chambers »

I looked at this a little closer, and still do not have an answer.

{TEMPLATE_PATH} is not seen as a variable/constant in the colorset... it just appears literally as part of the path.

img/image.png isn't sufficient as it would otherwise be when loading stylesheets from index.tpl via <link...>.

So, did I find a dead end in this process of merging stylesheets into serendipity.css?
=Don=
yellowled
Regular
Posts: 7111
Joined: Fri Jan 13, 2006 11:46 am
Location: Eutin, Germany
Contact:

Re: user stylesheets and colorset stylesheets

Post by yellowled »

Don Chambers wrote:{TEMPLATE_PATH} is not seen as a variable/constant in the colorset... it just appears literally as part of the path.
I did not follow all your code, but that might mean that the colorset stylesheet is not included using serendipity_printStylesheet because that is the function in serendipity.css.php which replaces {TEMPLATE_PATH} with the actual path.

YL
Timbalu
Regular
Posts: 4598
Joined: Sun May 02, 2004 3:04 pm

Re: user stylesheets and colorset stylesheets

Post by Timbalu »

Right. Since outside the normal routine, you need to do this on your own in this case...

Code: Select all

case 'css':
    ....
    // load colorset file (with fallback scope)
    $tfile = serendipity_getTemplateFile($serendipity['template_loaded_config']['colorset'] . '_styles.css', 'serendipityPath');
    // or the way defined you did...
    $tfile = dirname(__FILE__) . '/' . $serendipity['template_loaded_config']['colorset'] . '_style.css';
    if ($tfile) {
        $tfilecontent = str_replace('{TEMPLATE_PATH}', 'templates/' . $serendipity['template'] . '/', @file_get_contents($tfile));
    }
    if (!empty($tfilecontent)) {
        $eventData .= $tfilecontent;
    }
    break;
Regards,
Ian

Serendipity Styx Edition and additional_plugins @ https://ophian.github.io/ @ https://github.com/ophian
Timbalu
Regular
Posts: 4598
Joined: Sun May 02, 2004 3:04 pm

Re: user stylesheets and colorset stylesheets

Post by Timbalu »

Oh ... and since being an example for others too, it might be better(!) to replace all occurrences for get of

Code: Select all

$serendipity['template_loaded_config']
with

Code: Select all

$serendipity['template_loaded_config'][$serendipity['template']]
and set it like this

Code: Select all

$template_global_config = array('navigation' => true);
$template_loaded_config = serendipity_loadThemeOptions($template_config, $serendipity['smarty_vars']['template_option'], true);
$serendipity['template_loaded_config'][$serendipity['template']] = $template_loaded_config; // copy into global scope for extended plugin API usage
serendipity_loadGlobalThemeOptions($template_config, $template_loaded_config, $template_global_config);
Then one theme config could not accidently overwrite another.
Regards,
Ian

Serendipity Styx Edition and additional_plugins @ https://ophian.github.io/ @ https://github.com/ophian
Post Reply