Results tagged “drupal” from muse

This is a solution to mix public downloads and protected folders.

For this, you will need CCK, specifically CCK FileField and Content Permission. Also mod_rewrite should be enabld.

First, add a new file field to a content type, and configure its path to the directory that will be protected. For example, if /files/protected is the directory that will contain protected files, then you can either set that as the path or a folder within it.

If you have already set /files as your file system path, then there should be a .htaccess file created by drupal. You should copy that into each of the protected folders. If you don't, you may get 404 errors.

Open the .htaccess file in your root drupal directory, add the following line to the end of mod_rewrite rules:

RewriteRule ^files\/(protected\/.*)$ index.php?q=system/files/$1 [L,QSA]

Replace protected with your top-level protected folder name. If you have other custom rewrite rules you should be more careful about where you put the above line. Putting it at the end works for me.

Lastly, on your 403 page, you can examine if user is requesting a file in a protected directory using request_uri() and strpos().

Customize Ubercart Product Page

|

Here's a little snippet of code to customize ubercart product page template so that the contents are grouped into tabs.

You need Tabs and CCK Fieldgroups Tabs.

Go to yoursite/admin/content/node-type/product/fields and add some cck groups and fields, then display them properly (tabs for full node).

Create node-product.tpl.php. Paste the following php code in (enclose it with php tags):

$form = array();
$form['ptabs'] = array(
'#tabset_name' => 'ptabs',
'#type' => 'tabset',
);
$i = 0;

// shows a summary of the product
$summary;
$summary .= $node->content['weight']['#value'];
$summary .= $node->content['dimensions']['#value'];
$summary .= $node->content['body']['#value'];
$form['ptabs'][$i] = array(
'#type' => 'tabpage',
'#title' => t('Summary'),
'#content' => $summary,
);
$i++;

// add other tabs if applicable
if (!empty($node->content['fieldgroup_tabs'])) {
	foreach ($node->content['fieldgroup_tabs'] as $key => $value) {
		if (is_array($value)) {
			if ($value['#type'] == 'tabpage') {
				$form['ptabs'][$i] = array(
				'#type' => 'tabpage',
				'#title' => $value['group']['#title'],
				'#content' => $value['group']['#children'],
				);
				$i++;
			}
		}
	}
}

The page should always have a tab called Summary, and other tabs that you added for the content type if they are not empty (cck fieldgroup tabs module validates this). If you don't wish to have the Summary tab, simply delete that part of code.

Feel free to share the code.

Webform is a great module, but it doesn't send confirmation email, so here is a quick fix if you are running on Drupal 6.x.

To get the submitted value of a form component, you can use $form_values['submitted_tree']['component_key'] where component_key should be replaced by your component key. If the component is in a fieldset, access it by $form_values['submitted_tree']['fieldset_key']['component_key'] where fieldset_key should be replaced by your fieldset key.

To send the email I chose to use drupal_mail() function, of course there are other ways.

Here is an example:

$from = "example@example.com";
$to = $form_values['submitted_tree']['email'];
$user = $form_values['submitted_tree'['name'];
$body = "Hello " . $user . ",\nThis is a message.";
drupal_mail('webform_extra', 'confirmation_key', $to, language_default(), array('body' => $body), $from, TRUE);
function webform_extra_mail($key, &$message, $params) {
$message['subject'] = "Confirmation email";
$message['body'] = $params['body'];
}