I can't get %u and %n wildcard tokens to work.

I'm trying to set the path in the FCKeditor Global profile advanced settings, but no matter what I set it to the upload/browser just create folders named "%n", and the next time I enter that settings page it says the field is blank and it says (just above the field) that the Current path is /var/www/... -- whatever is set as my Drupal file system path. (I do have the line: require_once '../../../../../filemanager.config.php'; in config.php)

Also, the %b%f/ and %d%b%f/ strings show in no matter how I set the paths, whether in the drupal interface, or hard coded $fck_user_files_path in fckeditor.filemanager.php, or UserFilesPath in fckeditor/editor/filemanager/connectors/php/config.php, etc.

I'm on 6.x-2.0-alpha5 and FCKeditor 2.6.4.

Any idea how to get these tokens working? How about global, node, and filefield_paths tokens [user-name], [title], [field_name-*], etc?

Comments

Jorrit’s picture

Status: Active » Postponed (maintainer needs more info)

Are you using private folders?

mudd’s picture

Yes.

Jorrit’s picture

%n does not (yet) work there. %u was fixed as part of #409038: %u wild card does not work in private folders. You could try 6.x-2.x-dev, please let me know if it works.

mudd’s picture

Hi Jorrit,
Thanks for pointing that out. So will %n ever be added? How about recognizing other tokens, such as I outline below?

I installed 6.x-2.x Aug 3rd nightly build and set path to %u. I uploaded files and they appear where I'd expect them to.

Note that fields "Path to uploaded files:" and "Absolute path to uploaded files:" WERE FIRST BLANK and I set them to "%u". But now they're set to %d%b%f and %b%f respecfully and are grayed out so I can't change them.

When I set "%u" in "Location of files uploaded with FCKeditor in the private folder:" in the Global proile the setting will not stick and each time I re-edit this settings page the field is blank.

Anyway, here's what I see. I realize that some of the issues below are FCKeditor gripes and have nothing to do with the FCKeditor module you wrote. But if you think I'm doing something wrong then please offer advice, and you you want me to try anything in my environment then I'm happy to give it a shot.

When I open the image tool I see the Upload tab, and I browse to a file and "Send it to Server"...

1. URL field shows UID.

My first question is this: The next windows shows the following in the URL field: /system/files/32/ok.png , where 32 is the uid. Understandably this needs to be actual path portion of the HREF for the image to be shown in the node view. BUT, showing this here gives the user their UID, so I'd much rather have %n than %u. I also dislike drupal' "system/files" string in private downloads -- it's completely arbitrary and non-configurable. (I also have big problems with the My Account functions, since they're mostly void of dynamic URL aliases; missing for Edit and any 3rd party module that stuffs their UI in there.)

My site is setup so that any user should not know about any other user. As nodes are created, users upload files via CCK Filefield, and the files are put into .../filessytem_root/username/parent-node/sub-node. For example, [author-name]/[field_project-title]/[title]/ ("project is a content-type). This way users' files are kept private and sorted very neatly. So I'd like to be able to use these global tokens in FCKeditor so image files go into the same folder as all the other files the belong to the node.

2. Browse server

When "Browse server" is clicked I get a new window, and the following is the URL:

https://mysite.com/sites/all/modules/fckeditor/fckeditor/editor/ filemanager/browser/default/browser.html?Type=Image&Connector=/sites/all/modules/fckeditor/fckeditor/editor/filemanager/connectors/php/connector.php&ServerPath=//var/www/htmml/files

where /var/www/html/files is the root of my private files directory. (I inserted the space before 'filemanager' above because this site wanted to truncate the long URL)

Granted, when a file is uploaded here, the file goes into /var/www/html/files/UID/image. But the URL shows a lot of information to the visitor, such as the editor and a hint of what CMS is behind the site.

3. Broken image icon

After uploading a file, the editor shows a broken image icon, as if I've specified an incorrect file/path that doesn't exist. But it does exist and is correct - and the image tool is the what generated the code. Perhaps I have a setting incorrect ??

4. Broken image icon disappears

When I either view source or save and then re-edit the node, the broken image icon no longer shows (but the image tags in the source remains: <p><img src="/system/files/32/ok.png" alt="" /></p>) so I have to view source to edit.

Jorrit’s picture

Version: 6.x-2.0-alpha5 » 6.x-2.x-dev

%n might be considered as a feature request, it definitely looks usefull.

The greyed out values are because of the private upload method.

1) system/files is something inherent to the private files functionality
2) Hiding all details of the implementation is impossible
3) Might be, I don't know
4) OK

You could follow the steps at http://drupal.fckeditor.net/supportrequest so I can have a look at your system and configuration. Please prepare a throrough guide that allows me to reproduce the problem.

Jorrit’s picture

I have opened a separate feature request for the %n wildcard: #539122: Support %n token in private folder

mudd’s picture

Thanks for starting that feature request!

EDIT: Okay - but again, in the global profile when I try to set %u or %n (as I note below - test to see if that guess is correct) the setting won't stick. After saving and then re-entering admin/settings/fckeditor/editg the field is reset to blank!

--

BTW, I found this closed thread #233664: question about config.php which talks about using config.php to set this value. I think that info is very useful, and to ask in #539122: Support %n token in private folder would be off topic so I'll ask here...

I'm reading that as I use either A) the first one to hard code the path, or B) the second one to get values from $user and/or other globals.

$Config['UserFilesAbsolutePath'] = strtr($Config['UserFilesAbsolutePath'], array("%f" => file_directory_path(), "%u" => $user->uid, "%b" => base_path(), "%d" => $_SERVER['DOCUMENT_ROOT']));

Can I replace "%u" => $user->uid, with "%n" => $user->name, and then use "%n" in the admin settings UI? Can you please spell this out a little (sorry if I've missed something obvious).

Background: Let's say the user wants to upload an image to show inline with the body/abstract of their node. When using an upload tool, unless they've uploaded other files, they should see no other files at all. Note that I'm using Filefield (CCK) to upload presentations, data files, etc, but those are being managed in a very secure way, with download record keeping, etc, and I don't want to mix them. The user should also notbe able to browse to any folder above their private images folder. Well, since I already have user folders on my file-system root location, so it makes sense for me set FCKeditor's location to file_directory_path/user-name/images.

Thanks!

Jorrit’s picture

You shouldn't edit config.php. If the setting is cleared every time, this is a bug. Please allow me to look at your installation, see http://drupal.fckeditor.net/supportrequest.

Jorrit’s picture

Title: wildcard %u %n not working; global/node tokens? » Custom upload path not working when using private folders
Assigned: Unassigned » Jorrit
Category: support » bug
Status: Postponed (maintainer needs more info) » Active

I have been able to reproduce the bug, I will look into it asap.

Jorrit’s picture

Status: Active » Fixed

Fixed in CVS, 6.x-2.x-dev

mudd’s picture

Thanks for the update. So I gave it a try, and I want to report back what happened. I don't know if this is a config issue with FCKeditor, Apache, etc.

Note that prior to this update I could upload images, but the paths being written into the node source were wrong.

Using quick upload, I browse to the file and click Send to server, then just get the hoz squares animated forever. And in ssl_error_log:

[warn] [client xxx.xx.xx.xx] mod_include: Options +Includes (or IncludesNoExec) wasn't set, INCLUDES filter removed, referer: https://mysite.com/node/46/edit

The GETs and POSTs in ssl_request_log look fine.

When I use the standard Browse Server method I get this error when the browser window loads (it's a popup over the new window) and any attempted operation (create a folder, etc) results in the same popup:

The server didn't send back a proper XML response. Please contact your system administrator.

XML request error: Internal Server Error (500)

Requested URL:
/sites/all/modules/fckeditor/fckeditor/editor/filemanager/connectors/php/connector.php?ServerPath=%2F%2Fvar%2Fwww%2Ffoo_files&Command=GetFoldersAndFiles&Type=Image&CurrentFolder=%2F&uuid=1250860476660

Response text:

... and I see the same warn error in ssl_error_log. I see pretty much the same in FireFox 3.0.12 and IE7.

Any advice? Thanks!

Jorrit’s picture

I think it will be solved the fastest when I take a look at it. Please see http://drupal.fckeditor.net/supportrequest to get an overview of the information I need.

mudd’s picture

Title: Custom upload path not working when using private folders and tokens » Custom upload path not working when using private folders
Status: Active » Fixed

Same broken image.

Note: I fixed my apache config (which was giving the [warn] error above -- I forgot to change a path when I moved drupal's DocumentRoot), and I reverted the changes I made earlier to modules/fckeditor/fckeditor/editor/filemanager/connectors/php/config.php.

So the settings are fixed (now it saves the values), but I still have the broken image icon as described in #4.3 & #4.4 above in this thread. The files appear to upload fine, but their shown in the editor as a broken file and they don't show in node pages when being viewed, tho they're in the browser source and the paths (both relative and absolute) look okay.

When I access a node that has an image (but shows as broken when I first insert it, and not at all after I save the node, but the Only local images are allowed. tag + code exists and is not being filtered by input format) in ssl_error_log I get:

Aug 21 15:07:54 corp drupal: https://mysite.edu|1250881674|page not found|10.10.xx.xx|https://mysite.edu/system/files/32/image/apple.jpg|https://mysite.edu/sites/all/modules/fckeditor/fckeditor/editor/fckeditor.html?InstanceName=edit-body&Toolbar=DrupalFiltered|32||system/files/32/image/apple.jpg

When i try to place https://mysite.edu/system/files/32/image/apple.jpg in the browser address bar I get Drupal's page-not-found. Does it seem like something else is blocking it?

Jorrit’s picture

What do your settings in http://fck2.drupal6.local/admin/settings/file-system read? Does /32/image/apple.jpg exist? Are there errors in the Drupal error log at /admin/reports/dblog?

mudd’s picture

Title: Custom upload path not working when using private folders » Custom upload path not working when using private folders and tokens
Status: Fixed » Active

Jorrit, I don't understand why you marked this fixed. The images still don't work when using private files and setting the Global profile | Advanced setting | Location of files uploaded with FCKeditor in the private folder | to "%u". I get a broken image icon and drupal logs "page not found" errors when ever an images is inserted.

Re: Filesystem settings -- mine are set to: "/var/www/snl-s0/snl_files" and "/tmp" (my docroot is "/var/www/snl-s0/lib")

Re: Log -- anytime a node with files inserted into the body (where I'm setting up fckeditor) is accessed, I see a log entry:
page not found 08/21/2009 - 15:17 system/files/32/DOG.jpg Sally
which correlate to the ssl_error_log page not found errors i mentioned earlier.

Yes, the image files exist and the paths are correct. What breaks it is the token. As soon as I enable the token, tho they're placed in the folder system/files//images and the paths in the node body (browser code) are correct AND they're in the correct path on the server, something produces a page not found error (it's as if there's a .htaccess rule somewhere but I do see any). I'll investigate further and report back.

So again, I need to keep the users entirely separated -- I have contractors from many unrelated agencies, and when they create nodes I can't have one user seeing images that others have uploaded. Thus the need for tokens.

I've completely replaced fckeditor module and the latest fckeditor from scratch.

I'm very sorry I can't give you an account on my server -- it's a private site under a strict contract. But I'm very happy to help in any other way I can.

Thank you very much in advance.

Jorrit’s picture

Title: Custom upload path not working when using private folders » Custom upload path not working when using private folders and tokens
Status: Fixed » Active

If you set the path (as a test) to bla, will the files end up in /var/www/snl-s0/snl_files/bla/ ?

[edit]
And where are they placed if you set the path to bla%ubla

mudd’s picture

Yes, when I set the path to "blah" it works fine (but then all users see a common folder). So it seems the token is not behaving.

Also, when I changed the path from " " to blah, the image I inserted when the setting was at " " disappeared from both the editor AND the node normal view. I expect the former, but not the latter since the both the browser HTML and the file location match. Note this observation is by the authoring user, so permissions aren't the cause (I don't think drupal manages perm's on file upload basis)

Are you seeing different results -- do you have the %u token working with private files? (meaning, is my system acting different from the norm?)

Jorrit’s picture

For me it worked, that's why I set the bug to fixed. I will check later if it did indeed work. That disappearing image is strange.

mudd’s picture

Oh and FWIW I have the Token module installed, as well as a few others:

action_email_role, advanced_help, backup_migrate, cck, certificatelogin, collapsiblock, faceted_search, fckeditor, front, globalredirect, jstools, mass_contact, menu_per_role, mimemail, node_edit_protection, override_node_options, pathauto, realname, rules, token, transliteration, views, workflow, , workspace.

Jorrit’s picture

The %u is working, but I've found another bug. However, you said that %u did not get replaced at all, and I can't find the cause of that. I know you have been spending a lot of time on this issue, but I would like to request you to reproduce the problem on a new installation, perhaps one that is publicly accessible.

This night, a -dev update will be released, perhaps you could try it to find if it works better. The thing it fixes is the display of images from the private folder that use tokens. It does not address the problem of tokens not getting replaced itself, as I can't reproduce it.

mudd’s picture

The token %u DOES get replaced, and both the correct path is in the browser source and actual file location is fine (I thought I was clear on that, sorry).

So, the image resides in say /var/www/html/files/22/foo.jpg and the browser source code is Only local images are allowed.

Now, while in the editor, just after I insert the image, I see a broken image icon. And once I save it and go back into the editor I don't. And the image doesn't show in View either, but is in the source code and I think the 'page not found' error is related to that. Soooo....

I setup a clean install of just Drupal 6.13 and FCKeditor and you're right, the problem is gone. So there's something else at work. So I've just mirrored my site so I can start dissecting it.

I'll report back soon. Thanks!

Jorrit’s picture

I must say that two days ago, I made a change that might have caused the problem to go away. So try out the new version at your existing site as well.

mudd’s picture

Solved!
I had a stray copy of fckeditor in the modules directory. I'd been testing with Quick Uploads, but when I checked the other upload method "Browse Server" the URL that's shown on the top of the page is:
... &Connector=/sites/all/modules/tempp/fckeditor/fckeditor/editor/filemanager/connectors/php/connector.php&ServerPath=//var/www/html/files

AH HA!! I just noticed "tempp" in the above path. In upgrading FCKeditor since your broken image fix I copied the original directory into a temp dir just so I could compare the config files, and this confused Drupal. Removed it and re-saved the settings, and Voila!

Thanks for your help!

Jorrit’s picture

Status: Active » Fixed

Great! I know that can be a really obscure problem to find. I'll close this bug, hopefully for good.

mudd’s picture

First, thanks for your patience and not beating me up for being a dufus :)

2nd, not to beat a dead horse, but I just want to mention that in my semi-infinite desire to use login name rather than uid, I added 3 lines and changed 1 in fckeditor.module ~line#687:

            drupal_set_message('value of $private_dir = '.$private_dir, 'error');
            if ($private_dir == '%u') $private_dir = strtr($private_dir, array('%u' => $user->uid));  // Added if test
            if ($private_dir == '%n') $private_dir = strtr($private_dir, array('%n' => $user->name));
            drupal_set_message('value of $private_dir = '.$private_dir, 'error');

The result is that FCKeditor [mostly] succeeds with %n -- it puts the uploaded file in the correct directory (AND renames if file exists), and puts the proper path in the browser code. BUT the file is shown in the editor as a broken image, the image isn't displayed, and Drupal gives me the "page not found" error. the drupal_set_message's give me:

* value of $private_dir = %n
* value of $private_dir = testuser

Changing back to %u works great. So, even though you clearly said that %n doesn't work, I just thought I'd try to pry into the code to see why. Finding the hard coded %u made me hope that %n could work.

Anyhoo, if this gets you closer to having the uname token work then great! (I'm going to keep trying also)

Cheers! and thanks again!

EDIT: I'm also curious about line#388, which seems to only allow digits:
$private_dir = strtr($private_dir, array('%u' => '(\d+)'));

Jorrit’s picture

I have created feature request #539122: Support %n token in private folder for this, so it would be best if we continued there.

Status: Fixed » Closed (fixed)

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