CSS/JS Code injection doesn't work in Multisite installation

OnkelTem - August 8, 2008 - 07:46
Project:Active Template
Version:5.x-1.0
Component:Code
Category:bug report
Priority:normal
Assigned:Steve Dondley
Status:closed
Description

from template_file.inc:

<?php
define
('TAPI_ROOT_DIR', 'files/template');
define('TAPI_CSS_DIR'TAPI_ROOT_DIR . '/css');
define('TAPI_JS_DIR',   TAPI_ROOT_DIR . '/javascript');
?>

Drupal filesystem settings simply ignored...

#1

OnkelTem - August 8, 2008 - 07:57

Sorry, I'v posted above by mistake. The rest of the post:

Well, then later in function template_api_inject_files($tpid) we have:

<?php
1
function template_api_inject_files($tpid) {
2   // Inject template css file into the html page header.
3   $css_path = TAPI_CSS_DIR . '/id' . $tpid . '.css';
4    if (file_exists($css_path) && filesize($css_path) > 0) {
5        drupal_add_css($css_path, 'theme');
6    }
7   
8   
// Inject template javascript file into the html page header.
9    $js_path  = TAPI_JS_DIR . '/id' . $tpid . '.js';
a    if (file_exists($js_path) && filesize($js_path) > 0) {
b        drupal_add_js($js_path, 'theme');
c   }   
d}
?>

On 4th line file_exists check is performed against not expanded path (not taking into account filesystem Dru setting). I haven't check it yet, but will drupal_add_css() expand path by itself? If not, we need to do it correctly, using Drupal way.

The second issue with code injection. When saving template it creates directory structure under root 'files/' directory, not where it is located according to filesystem settings.

And third. When saving css/js code for the first time, it tries to save it into the wrong place. For example on installation it failed to save code at all until I created needed directory structure under 'sites/all/mysite/files/files/templates' [note doubling 'files']. (My filesystem setting is set to 'sites/all/mysite/files'.

#2

OnkelTem - August 8, 2008 - 08:17

Simple fix, not tested much:

replace:

<?php
define
('TAPI_ROOT_DIR', 'files/template');
?>

to

<?php
define
('TAPI_ROOT_DIR', file_create_path().'/template');
?>

in template_file.inc

#3

OnkelTem - August 8, 2008 - 08:17
Priority:critical» normal
Status:active» needs review

#4

deeporange1 - August 9, 2008 - 12:47
Assigned to:Anonymous» deeporange1

Looks reasonable. Thanks for the keen eye! We'll have a look and see if we can get that patched soon.

Thank you!

Regards, Derek

#5

Steve Dondley - August 12, 2008 - 11:24
Assigned to:deeporange1» Steve Dondley

The Drupal way of creating and testing directories to see if they are writable is with the file_check_directory() function. Patch attached.

If the user wants to change which directory the template files get saved in, they can just change the files setting in the drupal admin interface so there is no need for those TAPI constants.

AttachmentSize
create_dirs.patch 3.53 KB

#6

deeporange1 - August 15, 2008 - 06:23
Status:needs review» fixed

This has been fixed (hopefully) in the 5-1.1 version of Active Template. Thanks for your help on this.

#7

Anonymous (not verified) - August 29, 2008 - 06:24
Status:fixed» closed

Automatically closed -- issue fixed for two weeks with no activity.

 
 

Drupal is a registered trademark of Dries Buytaert.