Code Authors: Forums
 

 

View next topic
View previous topic
Post new topic   Reply to topic    Code Authors Forum Index -> phpNuke Hints, Tips and Tweaks
Author Message
Guardian
Site Admin
Site Admin



Joined: Jan 06, 2006
Posts: 4465
Location: Vsetin, Czech Republic

PostPosted: Mon Mar 26, 2012 9:51 am Share on Linked InShare on FacebookShare on Twitter Reply with quote

I needed this for a module I was working on for someone because he wanted to style the modules block file.
It isn't a perfect solution because I would personally prefer to be looking in the module itself for the block stylesheet to ensure that when a module was deleted, so was the stylesheet but it was the best I could come up with in the few seconds I had.
Code:


// filename: includes/addons/head-blockCSS.php
// in case the mainfile function isn't loaded
if(!function_exists('readDIRtoArray')) {
    function readDIRtoArray($dir, $filter) {
   $files = array();
   $handle = opendir($dir);
   while (false !== ($file = readdir($handle))) {
      if (preg_match($filter, $file)) {
         $files[] = $file;
      }
   }
   closedir($handle);
   return $files;
}
}

$blockCSSfiles = readDIRtoArray('blocks/css', '/^style\-(.+)\.css/');
   foreach ($blockCSSfiles as $blockStyle) {
            addCSSToHead('blocks/css/'.$blockStyle.'', 'file');
}

This assumes your stylesheet is in webroot/blocks/css/
and your naming convention must be
style-XXXX.css
In my case I'm actually appending the block file name so I know which block it relates to like this;
webroot/blocks/css/style-block-PlayerOfTheMonth.css

_________________
TPD 
View user's profile Send private message Send e-mail Visit poster's website
Guardian
Site Admin
Site Admin



Joined: Jan 06, 2006
Posts: 4465
Location: Vsetin, Czech Republic

PostPosted: Tue Mar 27, 2012 12:30 am Share on Linked InShare on FacebookShare on Twitter Reply with quote

I had some other tweaks I had to do to get the code in the previous post to work correctly because htaccess directiives were blocking the addCSSToHead function from loading the CSS files correctly.

I wasn't entirely happy with the other tweaks I had to do so I actually change my methodology to using a file;includes/addons/head-BlockCSS.php
and just putting a straightforward call to the file there
Code:
addCSSToHead('path/to/modules/MY_MODULE/style.css','file');

Because the function creates an array, it doesn't matter if you try to load the same CSS file at the module level (it gets ignored).

_________________
TPD 
View user's profile Send private message Send e-mail Visit poster's website
montego
Site Admin
Site Admin



Joined: Jan 06, 2006
Posts: 308

PostPosted: Wed Mar 28, 2012 5:09 pm Share on Linked InShare on FacebookShare on Twitter Reply with quote

Interesting approach. I've always felt that all styles really should be tied to the theme, not really the module, but that really only applies on sites which have multiple themes enabled.

_________________
Where Do YOU Stand?
HTML Newsletter :: ShortLinks :: DynamicTitles :: Approved Membership Lite :: And more... 
View user's profile Send private message Visit poster's website
Guardian
Site Admin
Site Admin



Joined: Jan 06, 2006
Posts: 4465
Location: Vsetin, Czech Republic

PostPosted: Tue Jun 26, 2012 6:11 am Share on Linked InShare on FacebookShare on Twitter Reply with quote

Not sure I would agree with that, because if styling is required at the block level, the chances are fairly high that the data in the block belongs to a module. This is not always the case but as a percentage, I think it would be pretty high.
Since one would normally aim for modularity, I think there is even a valid argument for module dependent block files being moved to within the module structure so you could potentially (ideally?) end up with something like;
modules/module_name/
modules/module_name/module_name-config.xml
modules/module_name/styles
modules/module_name/blocks

Example config file so you can see why it appears in this example even though it isn't related to the OP.
xml Code:
<?xml version="1.0" ?>

<module>
<name>CA Donations</name>
<date>26/06/2011</date>
<author>Guardian</author>
<email>example@example.com</email>
<url>http://www.code-authors.com</url>
<copyright>GNU/GPL License</copyright>
<version>1.0</version>
<description>Donations Module</description>
<install>
<query>CREATE TABLE....</query>
<query>INSERT INTO...</query>
</install>
<uninstall>
<query>DROP TABLE....</query>
</uninstall>
</module>

_________________
TPD 
View user's profile Send private message Send e-mail Visit poster's website
montego
Site Admin
Site Admin



Joined: Jan 06, 2006
Posts: 308

PostPosted: Sun Jul 01, 2012 1:24 pm Share on Linked InShare on FacebookShare on Twitter Reply with quote

No issues with blocks being tied to modules. However, wouldn't it get rather messy on a multi-themed site to have style sheets spread all over the place? We typically style our sites by theme, so was thinking it just made more sense to add them there. But, maybe the module has a default set of CSS and then overrides are in the themes.

_________________
Where Do YOU Stand?
HTML Newsletter :: ShortLinks :: DynamicTitles :: Approved Membership Lite :: And more... 
View user's profile Send private message Visit poster's website
Display posts from previous:       
Post new topic   Reply to topic    Code Authors Forum Index -> phpNuke Hints, Tips and Tweaks

View next topic
View previous topic
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You cannot download files in this forum

 
Forums ©
linear-bunch