Pathfilter for system paths?
amontero - May 28, 2009 - 18:59
| Project: | Path Filter |
| Version: | 6.x-1.0 |
| Component: | Code |
| Category: | feature request |
| Priority: | normal |
| Assigned: | Unassigned |
| Status: | closed |
Jump to:
Description
I'm creating a website with a custom theme, and I need to include some theme images inside blocks.
As I don't want to resort to enabling PHP filter to retrieve the theme path, I would like to propose adding another namespace for system-related paths such as [system:theme] and more [system:xxxx] paths in the future.
It seems now an easy patch to do, but I would hear what do you think or if there is a better way to do this or any other useful input/ideas/feedback.
I'm not sure if it will need another permission such as 'use [system] namespace' or similar, since it may raise security issues.

#1
I don't really think you should be referencing theme images from a block or any other part of the site other than the theme. Why do you want to do that, rather that upload the image to your files dir one way or another (IMCE perhaps) and referencec them in the normal way? What if you change your theme?... will these blocks not then be broken?
#2
It sounds a bit strange, but I need it for referencing theme provided icons.
This theme in particular includes some graphical images meant to be used as icons inside of user-definable blocks. For example, the 'get phone support' buddy-like icon is included in the theme and each theme will provide its own style-matching icon.
The point is, the icons are part of the theme (think it as a feature) and I need the user to be able to reference them.
#3
hmm. I can understand your use case, though I don't really think it's the right way to do what your trying to do. If I were trying to do this I think I would write a small module that provides a block, who's content (or part of it's content) is output by a theme_ function. Then, in each of your themes you can override the theme_ function as appropriate in order to provide your theme specific icons.
A very basic (untested) module that could do this - mymodule.module
<?php
/**
* Implements hook_block().
*/
function mymodule_block($op = 'list', $delta = NULL, $edit = NULL) {
if ($op == 'list') {
$blocks[0] = array(
"info" => t("Name of block"),
'status' => TRUE,
'visibility' => 1,
);
return $blocks;
}
else if ($op == 'view') {
$block = array();
switch ($delta) {
case 0:
$items = some_function_to_get_your_data();
$block['subject'] = t('Default block title here');
$block['content'] = theme('mymodule_list', $items);
break;
}
return $block;
}
}
/**
* Implements hook_theme().
*/
function mymodule_theme() {
return array(
'mymodule_list' => array('arguments' => array('items' => NULL)),
'mymodule_list_item' => array('arguments' => array('item' => NULL)),
);
}
function theme_mymodule_list($items) {
$output = "<ul>";
foreach ($items as $item) {
$output .= theme('mymodule_list_item', $item);
}
$output .= "<ul>";
return $output;
}
function theme_mymodule_list_item($item) {
$output .= "<li id='mymodule-list-item-".$item->id.">".$item->name."</li>";
}
?>
Then, in each of your themes you could override the theme_ functions in template.php:
<?phpfunction mytheme_1_mymodule_list_item($item) {
$output .= "<li id='mymodule-list-item-".$item->id.">".$item->name."</li>";
}
?>
Alternatively, you can just use CSS to add the icons in each of your themes. Notice how I gave each of the items a unique css id which you can use to target the elements in your CSS very easily.
Or, perhaps you don't even need a module to provide the block - are you sure you can't do what you are trying to do with theme specific css alone?
#4
Thanks a lot for the explanation. Firstly, I want to state that my CSS and theming knowlege is somewhat limited, so I'm more inclined to solve things 'the code way', so maybe I don't understand deeply the solution. Thus said, let me explain.
The setup I have is a multi-site D install for development accessible via a subdomain (someweb.devmachine.com) that later gets moved to a single-site setup (someweb.com). The root of the problem is that with that setup, the images usually break when deploying.
The module option you mention (to the extent I understand) it's meant for a single module. By contrast, I want the trick to work in the user editable blocks. The only solution I find is a tag that dynamically expands to those system paths, the site root directory, the files directory, etc. So that's when I found your module that does this in a easy and lean way for images that I think I could take advantage of.
Added to the initial problem, now I'm having the same problem when inserting attached images in the node bodies. I've tried IMCE but it adds full, absolute paths.
Maybe it's that there is some other way to do it and I'm trying to solve the problem with the wrong approach, but I suppose it's the price you have to pay for the "there's more than one way to do it". Of course, any suggestion will be welcomed.
Thanks in advance.
#5
I think there is a setting to tell IMCE weather or not it should insert absolute URLs (http://...) or paths (/path/from/site/root).
As for the problem of images being broken when you move the site, or attempt to access it via another domain name - I understand, and have faced the same problem myself as I use a similar setup. The way I counter this is actually by using filesystem aliases. So for example, if your site will be example.com, I would create use the directory /sites/example.com for the site (for themes, modules, files etc etc).
Now, When I'm on my local development machine, and want to access the site with the domain example.dev.mydomain.com, I create the following filesystem alias:
/sites/example.dev.mydomain.com -> /sites/example.com
If I want to access the same site in a Staging environment at example.stage.mydomain.com, I create the following filesystem alias:
/sites/example.stage.mydomain.com -> /sites/example.com
And on the live environment there is no need for an alias, as the site already exists in the correct directory: /sites/example.com
So, whatever domain I want to access the site at, is generally an alias that points to the real sites directory, which is named after the name of the live site. Does that help?
#6
Hi mrfelton.
Back from vacation.
First, thanks a lot for your help. I like very much the solution you propose using site aliases (I understand: symbolic links). Thats a perfect fit for environments in which I have complete control or sufficient permission shell access, which is most of the cases.
Anyway, I use some "copy and paste" snippets for content on some blocks and the proposed tags would be the icing on the cake. So I will try your solution and try to work out later this annoyance.
So, I'll set the issue status by now to 'postponed' if you don't mind it and reopen it (hopefully with the appropriate patch) if I have the need.
Thanks a lot for your help and advice.
Regards.