Drupal 7 FileTree Not Working On Some Directories

PROBLEM
FileTree isn’t working properly. We need it to only show a certain directory but only the root will work. Only the following works:

[filetree dir="/" dirtitle="Click to toggle." filename="%basename (%extension - %size)" filetitle="Click to download this %extension file. (%extension - %size)"]

SOLUTION
I couldn’t solve this one for a while. I tried modifying the Full HTML filter, only saving it in code view for CKEditor… nothing. Other directories would work though, so it was weird.

I then thought it was something to do with the permissions and it turns out I was correct. We modified the permissions on the folder and traversed those permissions. Now FileTree can access all the files underneath the folder.

[filetree dir="committees/disorders/Disorders 2004-2014" dirtitle="Click to toggle." filename="%basename (%extension - %size)" filetitle="Click to download this %extension file. (%extension - %size)"]

Drupal 7 CKEditor Warning: failed to open stream: Permission denied Error

PROBLEM
The content editor complained of strange errors on the Drupal 7 site we have when he went to upload an image. To follow the steps, he went to a page and clicked Edit then went into the CKEditor. He clicked on the Image icon to upload an image. He already had the image on the website so he chose “Browse Server” under the “Image Info” tab.

First, some of the images didn’t come up as thumbnails; which seemed fine. He double clicked on the image that he wanted and clicked “OK” to insert it onto the page.

He then saved the page and at the top of the page there were errors like these:

  • Warning: imagejpeg(/sites/default/files/_thumbs/Images/ANMI-FPO.jpg): failed to open stream: Permission denied in CKFinder_Connector_CommandHandler_Thumbnail::createThumb() (line 260 of …path…/sites/all/modules/ckeditor/ckfinder/core/connector/php/php5/CommandHandler/Thumbnail.php).
  • Warning: filesize(): stat failed for …path…/sites/default/files/_thumbs/Images/ANMI-FPO.jpg in CKFinder_Connector_CommandHandler_Thumbnail->sendResponse() (line 91 of …path…/sites/all/modules/ckeditor/ckfinder/core/connector/php/php5/CommandHandler/Thumbnail.php).
  • Warning: getimagesize(…path…/sites/default/files/_thumbs/Images/ANMI-FPO.jpg): failed to open stream: No such file or directory in CKFinder_Connector_CommandHandler_Thumbnail->sendResponse() (line 92 of …path…/sites/all/modules/ckeditor/ckfinder/core/connector/php/php5/CommandHandler/Thumbnail.php).
  • Warning: filemtime(): stat failed for …path…/sites/default/files/_thumbs/Images/ANMI-FPO.jpg in CKFinder_Connector_CommandHandler_Thumbnail->sendResponse() (line 96 of …path…/sites/all/modules/ckeditor/ckfinder/core/connector/php/php5/CommandHandler/Thumbnail.php).
  • Warning: imagejpeg(…path…/sites/default/files/_thumbs/Images/candi_face2.jpg): failed to open stream: Permission denied in CKFinder_Connector_CommandHandler_Thumbnail::createThumb() (line 260 of …path…/sites/all/modules/ckeditor/ckfinder/core/connector/php/php5/CommandHandler/Thumbnail.php).
  • Warning: filesize(): stat failed for …path…/sites/default/files/_thumbs/Images/candi_face2.jpg in CKFinder_Connector_CommandHandler_Thumbnail->sendResponse() (line 91 of …path…/sites/all/modules/ckeditor/ckfinder/core/connector/php/php5/CommandHandler/Thumbnail.php).
  • Warning: getimagesize(…path…/sites/default/files/_thumbs/Images/candi_face2.jpg): failed to open stream: No such file or directory in CKFinder_Connector_CommandHandler_Thumbnail->sendResponse() (line 92 of …path…/sites/all/modules/ckeditor/ckfinder/core/connector/php/php5/CommandHandler/Thumbnail.php).
  • Warning: filemtime(): stat failed for …path…/sites/default/files/_thumbs/Images/candi_face2.jpg in CKFinder_Connector_CommandHandler_Thumbnail->sendResponse() (line 96 of …path…/sites/all/modules/ckeditor/ckfinder/core/connector/php/php5/CommandHandler/Thumbnail.php).

SOLUTION
Google was almost no help since those errors are like PHP and not Drupal or CKEditor/CKFinder. However I did stumble upon this forum on CKEditor. The last post said that the Images directory was images in the configuration.

As a shot in the dark I decided to rename the Images folder to images under the _thumbs directory. So here were steps in the Linux/Unix Putty shell:

$ cd ..path../htdocs/sites/default/files/_thumbs
$ ls
Images

$ mv Images images
$ ls

images

That seemed to have worked. The errors no longer appear and when you go into “Browse Server” in CKEditor/CKFinder you actually see the thumbnail images.

Drupal 7 Notes I

Well this post isn’t exactly a PROBLEM/SOLUTION post but more of an entry to put the few things I need to remember on Drupal 7. Here are three things I should remember for the next time I need help with it. I’m naming it I just in case I want more than one.

Limit Site Search Results By Content Type

If you ever need to exclude some content types from the site search, do the following:

  1. Install and enable the search_config module.
  2. Go to #overlay=admin/people/permissions%23module-search_config and at the bottom you can limit anonymous users by content type.

Remove Authoring Information From Search Results

On the search results page, by default, the authoring information is displayed. This kind of stuff should be turned off my default (in my opinion) since sites usually do not expose this information to the user. Only blogs or news articles have author info so it should be turned off for site search, on pages, etc but that’s a different vent. Anyway to turn this information off, do the following:

  1. In /modules/search copy the search-result.tpl.php and paste it into the theme root (like /sites/all/themes/your_theme/ )
  2. Remove the authoring information code.
  3. Save the page.
  4. Clear the Drupal cache.

Search Title & Content Body In View Block

  1. In the view, select the Tontent: Title and Content:Body under the Fields
  2. If you do not want the Body (or any other thing exposed in the list) select the “Exclude from display” in the Configure field: Content:Body.
  3. Under Filter Criteria, choose the “Global: Combine fields filter”.
  4. Check the “Expose this filter to visitors, to allow them to change it”, “Single filter”.
  5. For the Operator, choose “Contains” and select both/all fields under “Choose fields to combine for filtering”.

Permissions On The /sites/default/files Folder

I struggled with permissions issues for like two days. Between going back and forth with IT on what’s allowed and what isn’t allowed. Blogs everywhere say that the files directory should be 777. But that’s access to everything for everybody.

Ours has this access for the directory:

drwxrwsr-x

Every folder underneath this one should be granted the same privileges. By the way, this is on a UNIX box.

Strip White Space From Element Using JQuery

PROBLEM
I don’t think I’m going to explain this very well. Here’s a short story long.

So what I was trying to do was kind of confusing as it is. I’ll try to explain… In Drupal 7 there is a cool module called field group table. I needed this module to display data in a table format. However, one of the limitations of this module is that it doesn’t display the label in the th for grouped elements. So say you have an address that you’d like to display in a table. You can use this module but it won’t display the group name in the th. It’ll go above the information.

The "location" text and "CRS Coordinator" text is above the data and not in the t h

I used some slick JQuery to move the “Location” text inside the empty th like so:

$(".table_site_map_info .group_table td #site_map_location_th div span").first().appendTo(".table_site_map_info .group_table th.field-label-hidden:eq(0)");

That did the trick. However I noticed that there was a space added and the “Location” and “CRS Coordinator” didn’t line up correctly with the “Phone” (which isn’t a group).

The "location" and "CRS coordinator" were moved to the t h but there was a space before them which doesn't align

SOLUTION
Unfortunately the JQuery trim function needs a parameter and all the examples on JQuery and around the web always had it using a JavaScript variable. I just needed to trim elements; not variables.

So in other words, I wanted to do something like $(“.table_site_map_info .group_table th”).trim() . However that didn’t work.

I had to go back tho the drawing board kind of. I first got it out of its span (which I thought initially was the spacing problem). I used:

$(".table_site_map_info .group_table th span").contents().unwrap();

This didn’t work. It got rid of the span but it still had the space. After looking at the HTML in FireBug, I saw an added space in the th. I needed to remove the space. Unfortunately, like I said earlier, the trim function was useless. I had to individually set each HTML element to its trimmed self.

So, here’s my code:

$(".table_site_map_info .group_table th.field-label-hidden:eq(0)").text($.trim($(".table_site_map_info .group_table th.field-label-hidden:eq(0)").text()));

Sorry that this is a long post and it’s mostly useless but I hope it can help someone. I wanted to post this to remember it.

a screen shot of what it's supposed to look like

If anyone has a more efficient way to do all the above using JQuery or Drupal, I’d love to hear it.

Warning In common.inc File When Calling module_invoke Function In Drupal 7

PROBLEM
So I want to create a carousel on the homepage of a website. The carousel items should be their own content type. Two of the carousel items need to generate a random publication and a random study (both content types). These can be generated by creating a View for both. I need to call this view though inside the carousel item content type.

I used the module_invoke method like this inside the body of the node (using the PHP filter):

<?php

$block = module_invoke(‘views’, ‘block_view’, ‘studies-block_1’);
print render($block);

?>

It outputted the content great. Exactly what I wanted it to do. However, it generated the following errors:

Warning: Invalid argument supplied for foreach() in element_children() (line 6428 of C:\xampp\htdocs\drupal_project\includes\common.inc).
Warning: Illegal string offset ‘#children’ in drupal_render() (line 5893 of C:\xampp\htdocs\drupal_project\includes\common.inc).
Warning: Illegal string offset ‘#children’ in drupal_render() (line 5903 of C:\xampp\htdocs\drupal_project\includes\common.inc).
Warning: Illegal string offset ‘#children’ in drupal_render() (line 5941 of C:\xampp\htdocs\drupal_project\includes\common.inc).
Warning: Illegal string offset ‘#printed’ in drupal_render() (line 5948 of C:\xampp\htdocs\drupal_project\includes\common.inc).

SOLUTION
Apparently these kinds of errors are very difficult to track down. It usually means some third-party module has passed in something wrong to one of Drupal’s common functions.

Since I’m using the render function from Drupal 7, I decided to output what the $block would be. It’s an array. As I’m already using PHP inside a block, what’s the harm in using some more? I just needed the first part of the array…

<?php

$block = module_invoke(‘views’, ‘block_view’, ‘studies-block_1’);
print($block[“content”][“#markup”]);

?>

Very handy to know the module_invoke function to call specific blocks so you can include them in your content without having to put them into the structure… however it does make the content harder to maintain as you’ll have to remember where you’re calling the blocks.

Add HTML5 Shiv To Drupal

PROBLEM
I’m using HTML5 in my theme. I want older browsers (ie, IE) to recognize some of the new tags such as header, footer, etc. Google has a shiv out there you can download. I use this on like all my sites.

You can link to it directly but I want the print shiv as well… I’m not sure where they keep that so you can directly link to it.

I’m a novice at Drupal 7 and they’ve changed a bunch since Drupal 6. The JavaScript calls are different. Also these JS files are a little unique as I want to put them in an less than IE9 comment.

SOLUTION
After playing around with getting the URL to the theme, having that not work exactly since I’m working on a local environment, I got the function calls I needed to link to the /javascript/ folder I created in the theme where the shivs will go.

I modified the html.tpl.php file which is in the themes folder. I added the following two lines of code which go to the two shivs:

<!--[if lt IE 9]><script src="<?= base_path().path_to_theme(); ?>/javascript/html5shiv.js"></script><![endif]-->
<!--[if lt IE 9]><script src="<?= base_path().path_to_theme(); ?>/javascript/html5shiv-printshiv.js"></script><![endif]-->

If there’s another way, I’d like to know. I’m sure there’s a module out there you can download to get the HTML5 support like a shiv, but I think linking to the shivs is a lot easier.

Date Field Not Showing Up On Add/Edit Content In Drupal

ISSUE
So I don’t know what it is about Drupal 7, but it just seems to been more difficult to work with and a lot more frustrating than Drupal 6. I really think it hates me.

Anyway, so I was setting up this website with different content types, one being a news article. I wanted to put a field where they could choose a date easily so I installed the Date module. I created some SQL in a block to get the latest news articles and sort by date (since I loathe Views). Everything was working well. About a month later the client wants me to put another news article on their site. I originally had hoped that would be something they’d be doing themselves but whatever.

So I go to add it and the date field does not appear on the news article on add and it wasn’t on edit either.

I’m baffled for a few minutes and click around. I then checked the modules to see if any configuration was wrong. It turns out, Date was inactivated for some reason.

I activated it which I would image would solve the problem but it did not. The date was still not showing up on content types.

I was tempted to make another date and replace that date instead since I wanted to get this done.  Well to make the short story long, my SQL I came up with after I created another date field didn’t work and I couldn’t remember the credentials for the DB. I was left to actually solve the problem… Gasp!

SOLUTION
I went back and forth with trying to edit the date. That was my first instict. However that kept not working. I then noticed a screen after the initial save screen (when editing a date). It contained just a select menu that was required. I noticed the value “Please Select” or something like it. So I chose the “Pop-up calendar”. Wow that worked!

Here’s what the screen looks like in edit mode:
Change Widget, Widget TypeI hope this can try to help someone else out. I was googling everything and anything with the Date module.

Blocks Only Seen By Administrator In Drupal

ISSUE
It really does erk me that Drupal doesn’t have an option for administrators in the Show blocks for specific roles when editing a block.

I needed a customized menu for a role (reg_user). This role had limited, basic access to do things. They needed to add news articles (a news content type I created) as well as edit them and edit pages. Rather them clicking Create content –> News, I just wanted a link on the left navigation, as well as a few other customizable links.

I could have edit the navigation menu through Administrator –> Site building –> Menus –> Navigation, etc etc. However, that would also change for the administrator as well as the role I wanted it to be customized for.

Well, long story short, after a while of research, it seemed the only option was to create another menu.

I did create another menu.

Then I ran into another problem. How to display the menu (Reg User Menu) to the reg_user and NOT the administrator, and the Navigation menu to the administrator and NOT the reg_user. It seemed easy enough to do via the specific roles, however, that doesn’t have the option for an administrator.

I also had another issue, the menu was to not be displayed on node/1 (the home page).

FIX
To accomplish all of this:

Reg User Menu – It’s a block when you create a new menu. I gave access to the reg_user. It doesn’t show up for administrators.

Navigation menu – No options were chosen for Show block for specific roles. Instead I did the following in the ‘Navigation’ block:

Page Specific Visibility Settings In Navigation BlockThe code being:

<?php

$r = false;

if (user_access(‘administer’)) { $r = true; }
if (($_GET[“q”] == “node/1”) || ($_GET[“q”] == “node/1/edit”)) { $r = false; }

return $r;

?>

The if statement with user_access tests if it’s an administrator, if so, display the block. The $_GET[“q”] if statement tests if they’re on the home page, if so, don’t display the block.

I really wish Drupal had easier ways to do this. Like I said before, it’d be a lot easier if they only had an Administrator option for the Show block for specific roles.

Currently, I’m dealing with a module issue that needs Clean URLs (which is disabled on our Windows system).

I hope someone can get help from this not well written post…

Dropdown/Flyout Menu Not Working With Drupal Sky Theme

ISSUE
While working on a new Drupal site, the theme I chose, Sky, I noticed the menu wasn’t dropping or flying out in IE. After a few tests, it was actually found out, the menu was working but it was only working on the page where it was linked (or one if its children).

At first I thought this was an IE issue. It wouldn’t work in IE8, so I only imagined it wouldn’t work in IE6 and IE7.

After a few searches, I found nothing. However, since I have so many windows open, I tested it again but it turns out I was in FireFox and it wasn’t working…

Dah, long story short, the menu wasn’t working in any browser except when it was on its proper page or one of its child pages.

FIX
Really simple and stupid and most people wouldn’t even think of it… at least us non Drupal experts.

By going to Administrator then Site Building then Menus then Primary Links, you see a list of all your links and their children. Click on the checkbox under the Expanded column of your drop down. That makes sure it can be expanded or is expandable in other pages.

How To Insert Images Into Links In Drupal

ISSUE
I only struggled with this for about an hour. I’m not sure why Drupal hasn’t thought of this before, but it would be nice to have images as links once in a while. I needed one for my menu… a home link that was an image of a little house (how cute).

FIX
I read on a blog to edit the theme_menu_item_link function located in includes/menu.inc . I then added my <img tag to the Description. Well, that didn’t work. I investigated it further and looked at the code and instead put it in the Menu Link Title. That didn’t work either. I even tried the PHP function html_entity_decode, but that didn’t work either. It was still escaping the characters.

Anyway, after googling and reading up on how to do it, I tried to edit the template.php file with no luck. I read some other blogs and tried to edit some other files but it still kept escaping the code. I didn’t want to mess with the other files Drupal had put there.

I finally formed my own solution. I decided to edit the files Dupal put in. I looked for the l() function which is the function that actually forms links.

I added the following to the function l() in the file includes/common.inc on line 1598, right after the default options are declared in the $options array:

if (strpos($text, ‘<img’) === 0) {
$options[‘html’] = TRUE;
}

Yes, I know it’s unsafe but that’s the only way I could get it to NOT escape. I can now add HTML img script to the Menu Link Title and it display an image.

SPECIAL COMMENT
I’ll make this brief. I don’t know why Drupal didn’t think about images in link lists before. You think that would be obvious. The more and more I learn about Drupal, the more and more I realize how LESS flexible it is than I thought. I will say at least they have a community that can help, which is something that Microsoft seems to lack.

Come on, Drupal, think common sense.