Forum OpenACS Q&A: understanding paths and structure

Collapse
Posted by Iuri Sampaio on
I've playing around on my website and I can't understand how the css files are included on the pages.

For example:

On the adp file, "site-master-kelp.adp" which is located in "/home/yabtdev/yabtdev/www/"
i have the variable:@css_url@
link rel="stylesheet" type="text/css" href="@css_url@" media="all"

On the respective tcl page "site-master-kelp.tcl", located in the same folder "/home/yabtdev/yabtdev/www/"
i have this include call:
set css_url "/resources/acs-subsite/site-master.css"

But the file "site-master.css" is located on:
"/home/yabtdev/yabtdev/packages/acs-subsite/www/resources/site-master.css"

and the thing is that the folder "/acs-subsite/" bellow /resources/ doesn't even exist.

In my view it should be like this:
set css_url "/packages/acs-subsite/www/resources/site-master.css"

Since the root folder is "/home/yabtdev/yabtev/"

Another example:

on the file: "dotlrn-master-kelp.adp" located in "/home/yabtdev/yabtdev/packages/dotlrn/www/"

I have the tag
link rel="stylesheet" type="text/css" href="/resources/dotlrn/dotlrn-master-kelp.css" media="all"

and the file "dotlrn-master-kelp.css" is located on
/home/yabtdev/yabtdev/packages/dotlrn/www/resources/dotlrn-master-kelp.css

but the folder /dotlrn/ bellow /resources/ doesn't even exist.
In my view the right path should be
link rel="stylesheet" type="text/css" href="/packages/dotlrn/www/resources/dotlrn-master-kelp.css" media="all"

So what does the tcl code do to recognize and find the file on the exactly folder?
What is the logical sense to these files being included?

Collapse
Posted by Dave Bauer on
/resources/package-key/* is a special URL

It serves files without checking the site map or permissions. Its used for resources like icons, css files etc.

the url
/resources/acs-subsite/ will resolve to packages/acs-subsite/www/resources

so to make files available in this way you put them under package-key/www/resources/

Collapse
Posted by Iuri Sampaio on
That's weird!
Do you know the reason of this?
Why is it "structurized" like that?

I don't understand TCL at all!! :)

Collapse
Posted by Dave Bauer on
It is a special feature of the OpenACS request processor.

OpenACS site nodes are normally checked for permission on every request.

Since one "page" will include requests for the tcl/adp pair for the URL, plus all images/icons/css/javascript etc.. we want to minimize hits on the database for common files that do not need permission checking.

Therefore the specially handled "resources" directory was added to allow a packge to add custom files without requiring permission checks.

Dave

Collapse
Posted by Iuri Sampaio on
I barely understood what you meant. I'm sure it's because i'm not that furhter on oacs yet. I just need more time.
What about the requests those don't use the database, even permissons, like the second one that is only on the adp file. and it seems to be inverted

**********************
on the file: "dotlrn-master-kelp.adp" located in "/home/yabtdev/yabtdev/packages/dotlrn/www/"

I have the tag
link rel="stylesheet" type="text/css" href="/resources/dotlrn/dotlrn-master-kelp.css" media="all"

and the file "dotlrn-master-kelp.css" is located on
/home/yabtdev/yabtdev/packages/dotlrn/www/resources/dotlrn-master-kelp.css

but the folder /dotlrn/ bellow /resources/ doesn't even exist.
In my view the right path should be
link rel="stylesheet" type="text/css" href="/packages/dotlrn/www/resources/dotlrn-master-kelp.css" media="all"
************************************

Collapse
Posted by Don Baccus on
It is inverted (/resources/package-key rather than /package-key/www/resources) to simplify the recognition of the URL pattern for resources.

This is done for performance reasons. Dynamic pages are served by the request processor (see the Tcl proc "rp_filter" in packages/acs-tcl/tcl/request-processor-procs.tcl). Before being served, the request processor checks to see that the user has READ permission for the requested page, and sets up many the ad_conn structure with information that's useful for dynamic pages (the user_id associated with the request, the package_id of the package owning the page, etc etc).

The permissions checking and the setting up of the ad_conn structure takes a few milliseconds on typical x86 hardware running Postgres, AOLserver and Linux.

Static files like images, CSS files etc do not need the information set up in the ad_conn structure. It is typically OK to allow those used internally in .adp files to be read by any visitor. Therefore the permission checking and ad_conn set-up is skipped for files whose URL starts with /resources. We save a few milliseconds per resource request, and for sites that are decorated with many GIFs or heavily use CSS files the savings per page view can be significant.

Hope this helps ...

Collapse
Posted by Iuri Sampaio on
I've read the page "packages/acs-tcl/tcl/request-processor-procs.tcl". I could understand some points but It's still sort of chinese to me. =)

ad_proc -private rp_resources_filter { why } {

This filter runs on all URLs of the form /resources/*. The acs-resources package
mounts itself at /resources but we short circuit references here in order to
maximize throughput for resource files. We just ns_returnfile the file, no
permissions are checked, the ad_conn structure is not initialized, etc.

There are two mapping possibilities:

/resources/package-key/* maps to root/packages/package-key/www/resources/*

*******************8
" Keep in mind that if you do an internal redirect to something other than
the current directory, relative links returned to the clients
browser may be broken (since the client will have the original URL).""

I understood "internal redirect" as if i try to include pages those are "i don't knnow" or if the pages needs permission. Is that correct?

Another thing is...
I couldn't match this with the header metatags. I mean, how do they go to the final page, on the client side(i.e. on the user's browse). Can you tell how they go to the page? Where are the metatags actually located?

I want to track and debug the whole process that it takes since the begining(i.e. the first step) to the end(i.e. user's browser).