11
trabis
Re: Xoops cache and stylesheets :-(
  • 2011/8/25 0:16

  • trabis

  • Core Developer

  • Posts: 2269

  • Since: 2006/9/1 1


The solution I'm working on looks like this:
//bootstraping Xoops and module constants
include_once dirname(dirname(dirname(__FILE__))) . '/mainfile.php';
include_once 
dirname(__FILE__) . '/include/common.php';

//setting template for this page
xoopsOption['template_main'] = 'publisher_display_item.html';

//setting stylesheets, scripts and feed
$GLOBALS['xoopsOption']['xoops_module_header'][] = array('stylesheet',PUBLISHER_URL '/css/publisher.css');
$GLOBALS['xoopsOption']['xoops_module_header'][] = array('script''browse.php?Frameworks/jquery/jquery.js');
$GLOBALS['xoopsOption']['xoops_module_header'][] = array('script'PUBLISHER_URL '/js/publisher.js');
$GLOBALS['xoopsOption']['xoops_module_header'][] = array('script'PUBLISHER_URL '/js/ui.core.js');
$GLOBALS['xoopsOption']['xoops_module_header'][] = array('script'PUBLISHER_URL '/js/ui.tabs.js');
$GLOBALS['xoopsOption']['xoops_module_header'][] = array('script'PUBLISHER_URL '/js/ajaxupload.3.9.js');
$GLOBALS['xoopsOption']['xoops_module_header'][] = array('stylesheet'PUBLISHER_URL '/css/jquery-ui-1.7.1.custom.css');
$GLOBALS['xoopsOption']['xoops_module_header'][] = array('link','alternate'PUBLISHER_URL '/backend.php',array(
            
'href' => PUBLISHER_URL '/backend.php','type'=>'application/rss+xml',
            
'title'=> 'My feed'
        
));


//starting template engine, render blocks and check cache
include_once XOOPS_ROOT_PATH '/header.php';

//logic code that is not executed when using cache;

//theme and template rendering
include_once XOOPS_ROOT_PATH '/footer.php';
?>


We need to type a little more but the interface/arguments are the same as when using $xoTheme.
I can implement this on 2.5.2 but I would like to know what do you think first.

Thanks.

12
trabis
Re: Xoops cache and stylesheets :-(
  • 2011/8/25 0:29

  • trabis

  • Core Developer

  • Posts: 2269

  • Since: 2006/9/1 1


Maybe better to understand:

Instead of doing
include_once XOOPS_ROOT_PATH '/header.php';
$xoTheme->addScript(XOOPS_URL '/browse.php?Frameworks/jquery/jquery.js');


We do:
$GLOBALS['xoopsOption']['xoops_module_header'][] = array('script''browse.php?Frameworks/jquery/jquery.js');        
include_once 
XOOPS_ROOT_PATH '/header.php';

13
trabis
Re: Xoops cache and stylesheets :-(
  • 2011/8/25 14:12

  • trabis

  • Core Developer

  • Posts: 2269

  • Since: 2006/9/1 1


Well, the above does not work with blocks :(
When block is cached the block file will not be included and there is no way of pushing js and css.

Other solution I'm working now is callback functions .declared in xoops_version.php

example:
$modversion['onCache']['file'] = "include/functions.php";
$modversion['onCache']['func'] = "publisher_onCache";
So everytime XOOPS hit a page cache or a block cache, it will call a module function.

This seems to work fine!

Imagine a module that has 3 pages and uses 3 different scripts
page 1 -> script 1
page 2 -> script 2
page 3 -> script 3
block1 -> script 1

There is no need to load script 1,2,3 for page one. I can use xoTheme in each page to assign the desired script as we usually do.(no changes needed for existing modules)

However, when module is cached it will not load any of this scripts and it will call this "onCache" function.
In this function I can use $xoTheme but I will have to load the 3 scripts because I'm not aware of the page I am at the moment.
Results when using cache:
page 1 -> script 1,2,3
page 2 -> script 1,2,3
page 3 -> script 1,2,3
block1 -> script 1,2,3


What do you think of this solution?



14
trabis
Re: Xoops cache and stylesheets :-(
  • 2011/8/25 16:00

  • trabis

  • Core Developer

  • Posts: 2269

  • Since: 2006/9/1 1


This callback solution works very good and was added to core.
It is a new feature but it was the only way to allow module developers to address this problem.

an example of how to fix publisher:

add this code in xoops_version.php
//Cache
$modversion['onCache']['file'] = "include/functions.php";
$modversion['onCache']['func'] = "publisher_onCache";


add this code on functions.php
function publisher_onCache()
{
    
$GLOBALS['xoTheme']->addStylesheet(PUBLISHER_URL '/css/publisher.css');
    
$GLOBALS['xoTheme']->addStylesheet(PUBLISHER_URL '/css/jquery.popeye.style.css');
    
$GLOBALS['xoTheme']->addStylesheet(PUBLISHER_URL '/css/jquery-ui-1.7.1.custom.css');

    
$GLOBALS['xoTheme']->addScript(XOOPS_URL '/browse.php?Frameworks/jquery/jquery.js');

    
$GLOBALS['xoTheme']->addScript(PUBLISHER_URL '/js/jquery.popeye-2.0.4.js');

    
$GLOBALS['xoTheme']->addScript(PUBLISHER_URL '/js/behavior.js');
    
$GLOBALS['xoTheme']->addScript(PUBLISHER_URL '/js/rating.js');

    
$GLOBALS['xoTheme']->addScript(PUBLISHER_URL '/js/ui.core.js');
    
$GLOBALS['xoTheme']->addScript(PUBLISHER_URL '/js/ui.tabs.js');

    
$GLOBALS['xoTheme']->addScript(PUBLISHER_URL '/js/ajaxupload.3.9.js');
    
$GLOBALS['xoTheme']->addScript(PUBLISHER_URL '/js/jquery.easing.js');
    
$GLOBALS['xoTheme']->addScript(PUBLISHER_URL '/js/script.easing.js');
    
$GLOBALS['xoTheme']->addScript(PUBLISHER_URL '/js/publisher.js');
}

15
trabis
Re: Xoops cache and stylesheets :-(
  • 2011/9/10 21:59

  • trabis

  • Core Developer

  • Posts: 2269

  • Since: 2006/9/1 1


I've managed to fix this perfectly.

We use xoops_cache to store metadata from blocks and modules.
On cache hits, we get templates from smarty_cache and metadata from xoops_cache.

Cached metadata is then merged with current metadata.
This fixes following problems:
- missing js and css
- missing pagetitles
- missing description and keywords
- any other metadata set by modules and blocks

It also works for custom php blocks.
The best thing is that it wont require module changes.

16
Mamba
Re: Xoops cache and stylesheets :-(
  • 2011/9/11 0:15

  • Mamba

  • Moderator

  • Posts: 11409

  • Since: 2004/4/23


Excellent news!

I'll be testing it this weekend on couple of my Websites...
Support XOOPS => DONATE
Use 2.5.11 | Docs | Modules | Bugs

17
timgno
Re: Xoops cache and stylesheets :-(
  • 2011/9/11 9:06

  • timgno

  • Module Developer

  • Posts: 1504

  • Since: 2007/6/21


Quote:

trabis wrote:
Maybe better to understand:

Instead of doing
include_once XOOPS_ROOT_PATH '/header.php';
$xoTheme->addScript(XOOPS_URL '/browse.php?Frameworks/jquery/jquery.js');


We do:
$GLOBALS['xoopsOption']['xoops_module_header'][] = array('script''browse.php?Frameworks/jquery/jquery.js');        
include_once 
XOOPS_ROOT_PATH '/header.php';


I think that question would be better to plug it directly into the core, and administration to decide whether or not with yes or no radio buttons.

Why do I say this?

When I built my site, I added the line of code on theme to call jquery and I have had problems since, or system / module or other modules in the same row was activated jquery, and this created conflict, getting high all the layout of the site. To solve the problem every time you install a module, I had to go and I must go and comment the line of jQuery code.

I think it's possible to do this

Login

Who's Online

269 user(s) are online (132 user(s) are browsing Support Forums)


Members: 0


Guests: 269


more...

Donat-O-Meter

Stats
Goal: $100.00
Due Date: Nov 30
Gross Amount: $0.00
Net Balance: $0.00
Left to go: $100.00
Make donations with PayPal!

Latest GitHub Commits