What is a direct link to a stylesheet?

General project discussion. NOT for help questions.
Wishbone
Power Poster
Power Poster
Posts: 1368
Joined: Tue Dec 23, 2008 8:39 pm

Re: What is a direct link to a stylesheet?

Post by Wishbone »

Augustas wrote:
mcDavid wrote:I think using the old stylesheet.php file for this would actually be a very good solution.
But using this old file does not guarantee that with the next CMSMS update this old stylesheet.php code will work. Looking to the long-run, I think best would be to avoid old version codes.
If you upgrade a site, this stays, and still works.. I believe that if they end up finding a security issue, the next upgrade release would delete this file, and remove the {stylesheet} tag.

Using the static file wouldn't work, because this gets re-generated using a temp name if the CSS changes.
uniqu3

Re: What is a direct link to a stylesheet?

Post by uniqu3 »

If extrenal system that is going to be used supports PHP then it is fairly easy to do it.

Step 1:
Create new template in your CMSMS, for example simply named "Blank"
And simply call only stylesheet in there:

Code: Select all

{strip}{content assign='foo'}{cms_stylesheet nolinks=1}{/strip}
Save that Template.

Step 2:
Attach stylesheets you want to use to newly created Template or edit cms_stylesheet tag in step one to include stylesheet with parameter name=

Step 3:
Create new page in your CMSMS and apply your newly created template to that page.
Hide it from menu and save it.

Output of that page would be for example:
Step 4:
Make sure that this page isn't being indexed or something, so edit your robots.txt or well it's up to you :)

Step 5:
Now simply add few lines of PHP:

Code: Select all

<?php
$url = file_get_contents('http://yourdomain.com/index.php?page=WHATEVER_YOUR_ALIAS_IS'); // url to page to read content from
$data = file_get_contents(trim($url)); // if that page has only one url read that content
$file = md5(serialize($url)) . '.css'; // filename
$cache_file = './cache/' . $file; // cached file and folder

if (!file_exists($cache_file) || filemtime($cache_file) < (time() - 3600)) {
    if (!file_exists($cache_file)) {
        mkdir('./cache', 0777);
    }
    file_put_contents($cache_file, $data);
    chmod($cache_file, 0664);
    $html = '<link rel="stylesheet" href="cache/' . $file . '" type="text/css" />';
} else {
    $html = '<link rel="stylesheet" href="cache/' . $file . '" type="text/css" />';
}
echo $html;
?>
Thats it, the output would be:

Code: Select all

<link rel="stylesheet" href="cache/74324b7a7dc71e971e07e8fc3869d8b1.css" type="text/css" />
Basically what was done is reading content of your created page, then reading content of url that we have as content in that page.
After that is done a file is saved in "cache" folder.
If saved file is older then one hour it will be resaved again.
calguy1000
Support Guru
Support Guru
Posts: 8169
Joined: Tue Oct 19, 2004 6:44 pm
Location: Fernie British Columbia, Canada

Re: What is a direct link to a stylesheet?

Post by calguy1000 »

Sorry goran, but slightly faster, and simpler solution would be:

a: create a new template with:

Code: Select all

{strip}{content assign='junk'}{cms_stylesheet}{/strip}
b: create a new page using that template,
b.1 mark it as not shown in menu
b.2 give it a custom alias like: 'stylesheets' (or use a custom url)
b.3 make sure that it isn't being indexed in the robots.txt etc.

c: in your other application (i.e: wordpress) php code would be something similar to:

Code: Select all

    $url = 'http://the/complete/url/to/page/created/in/stepb';
    $cachefile = '/tmp/website_stylesheet.cache';  // pick any unique filename and writable location
    if( !file_exists($cachefile) || filemtime($cachefile) < time() - 3600 ) {
       file_put_contents($cachefile,file_get_contents($url));
    }
    echo file_get_contents($cachefile);
Follow me on twitter
Please post system information from "Extensions >> System Information" (there is a bbcode option) on all posts asking for assistance.
--------------------
If you can't bother explaining your problem well, you shouldn't expect much in the way of assistance.
uniqu3

Re: What is a direct link to a stylesheet?

Post by uniqu3 »

Cool :) thx
Just a proof that there is nothing like "can't be done" with cmsms ;D
User avatar
Augustas
Forum Members
Forum Members
Posts: 241
Joined: Wed Oct 17, 2007 6:09 pm
Location: the world

Re: What is a direct link to a stylesheet?

Post by Augustas »

That's a great idea! Thank you - this is what I was looking for.
Post Reply

Return to “General Discussion”