Category: open source
DJson 1.6 released
Today I want to announce a new release of DJson. The 1.6 is now using a different method to create the cache-file, which allows running multiple djson-scripts (like filterscripts) at the same time.
Also it features a method to define own DJSON_MAX_STRING (before include of djson), if you need really big content.
The internal djson cache allows a maximum of ~ 70 characters (255-filenamelength-keylength-170) for a value, if DJSON_MAX_STRING is set to just 255.
Head over to the official DJson page or directly to the djson 1.6 download.
Mounting SSH/SFTP Remote Folders in Eclipse
If you are using windows as operating system and want to access files available on unix-based remote file systems, you have only limited amount of options. In case you are using Eclipse as development environment, we'll have a look at an alternative, which does not use samba-shares.
A nice option is the plugin Target Management (RSE). It allows you to add any remote systems to the remote file system explorer.
Once RSE is installed, you are able to add a folder (like you did before) but link it to local or RSE location. Select RSE and choose the path on your remote system!
Fixing compiling issues with magnet.c
Jan Kneschke maintains lighttpd and posted a simple FCGI for lua. This magnet.c should be easily compiled with
This may not work if your lua-include is not in the path for compiling.
And you'll run into such error messages:
2
3
4
5
magnet.c:4:21: error: lauxlib.h: No such file or directory
magnet.c:11: Error: expected »)« before »*« token
magnet.c:19: Error: expected »)« before »*« token
magnet.c:59: Error: expected »)« before »*« token
Since you may not be used to compiling, I think it might be good to post a reason for that and a solution.
The reason is, that lualib.h is not in include path. To add it specific folder for the compiling to the include path you may use the -I /path/name/ parameter.
There are some distributions, where the -llua5.1 may not work and result in cannot find -llua5.1. In this cases try -llua instead.
Have fun compiling!
Detect action/view/module and matched route in agavi
For each executed Module/Action(+View) there is an ExecutionContainer (AgaviExecutionContainer). So if you want to retrieve the current executed action, module or view, best is to do
2
3
$view = $this->getContext()->getViewName();
$module = $container->getModuleName();
But what if you want to retrieve the "real" action, the one and only for the request? That's a little bit more difficult, so here a short introduction how to deal with that.
Whenever the routing of agavi does the work for you, by turning the input data and webbrowser call of a user, into a action and validated data, it triggers an action, executes the view for the outputtype and fills the template. But Slots can be used from the view and trigger then again validation+action+view for their parameters.
This is why the real request route can not be found in the execution container and must be found somewhere else. In the Request.
2
3
'matched_routes', 'org.agavi.routing'
);
The route_names is nothing but an array, for instance:
2
3
4
5
'product.edit'
// because our current route is named "product.edit"
// in routing.xml
)
This information does help us indirectly to determine the action, which got called! Since the WebRouting has also a getRoute-method, which expects just a route_name, we can retrieve the info now easily:
2
3
4
5
6
7
// thatswhy list($first) = $array style
list($route_name) = $this->getContext()->getRequest()->getAttribute(
'matched_routes', 'org.agavi.routing'
);
$route = $this->getContext()->getRouting()->getRoute($route_name);
The new $route-Variable now holds an array of all information about the route. In our case, just some are interesting.
2
$action = $route['opt']['action'];
One really should use that only in case of a default slot, which is used directly in the output_types.xml or used on serveral different pages and has to determine on its own and by using module+action where it's actually embedded.
PDT auto completion tips (for agavi)
In PDT (php development tools for eclipse) you are able to do auto completion (e.g. ctrl+space) on most of the classes, as long as they are defined properly or you have a proper php-doc set up. Check that tutorial, if you want to set up PDT.
Graste posted a snippet, which tells eclipse for the project (in this example it's agavi) that the variables (which are common for templates), like $template (or $ro, $rd and so on) are defined with correct type.
Here is a slightly modified autocomplete.php:
2
3
4
5
6
7
8
9
10
11
12
exit();
$slots = array();
$template = array(); // agavi 0.11 default
$t = array(); // agavi 1.0 default
$tm = new AgaviTranslationManager();
$ro = new AgaviWebRouting();
$rq = new AgaviWebRequest();
$ct = new AgaviController();
$us = new AgaviSecurityUser();
$rd = new AgaviWebRequestDataHolder();
?>
Just save that file to autocomplete.php in your project structure -> eclipse will use this classes as default, so you have neat auto completion even in agavi templates.
If you have return type for a function, and want the caller to be able to autocomplete: just use proper php-docs. For example, the following will give SomeClass-typed elements on a function test123:
2
3
4
5
6
* @return SomeClass
*/
function test123() {
/* ... */
}
If you just want autocomplete for a specific scope, you may use the following:
or better
and auto completion on $instance will work like if it was a SomeClass.
Got another tip? Feel free to add it in the comments!
Preloading CSS-images for :hover
The top navigation here at dracoblue.net is done with css images, which also have a :hover-effect (showing a lighter version of the image).
So there is a:
and a
In CSS it looked like that:
2
3
4
5
6
background: transparent url('menu_news.png') no-repeat;
}
a#newsLink:hover {
background: transparent url('menu_news_hover.png') no-repeat;
}
All this is quite common, but I was facing a usability problem here. The *hover.png files won't be loaded until one of the links got hover'd. In the perspective of the server owner, you might be happy about that. But for the user, the image is unavailable for nearly a second, because it takes time to deliver the image to the user.
So here is my solution to preload the image (without using javascript or stub-<img>'s).
2
3
4
5
6
7
8
9
10
11
12
13
background: transparent url('menu_news.png') no-repeat;
}
td#newsLink a:hover {
background: transparent url('menu_news_hover.png') no-repeat;
}
td#newsLink {
background:
transparent
url('menu_news_hover.png')
fixed no-repeat
-120px -120px;
}
I moved the #newsLink to the td surrouding the newsLink. And at the end, I added a new decleration for a non-repeating and - with coordinates -120x-120 - clearly invisible image.




