stid] = $template->name; } $form["{$profile}{$type}_template"] = array( '#type' => 'select', '#title' => t('Email Template'), '#options' => $options, '#default_value' => send_value('template', $profile, $nodetype, $node), ); $form["{$profile}{$type}_fulltext"] = array( '#type' => 'checkbox', '#title' => t('Allow visitors to send full item text'), '#default_value' => send_value('fulltext', $profile, $nodetype, $node), '#description' => t("Send the full body of the node via email. If this setting is not enabled, messages will only contain a teaser view."), ); $form["{$profile}{$type}_linktext"] = array( '#type' => 'textfield', '#title' => t("Link text"), '#default_value' => send_value('linktext', $profile, $nodetype, $node), '#size' => 30, '#maxsize' => 100, '#description' => t('The text for the link to the email form. Use <none> to hide this link.'), ); $form["{$profile}{$type}_subject"] = array( '#type' => 'textfield', '#title' => t("E-mail subject line"), '#default_value' => send_value('subject', $profile, $nodetype, $node), '#size' => 30, '#maxsize' => 100, ); $form["{$profile}{$type}_message"] = array( '#type' => 'textarea', '#title' => t("Default message text"), '#default_value' => send_value('message', $profile, $nodetype, $node), '#cols' => 70, '#rows' => 10, ); return $form; } /** * profile-specific settings */ function _send_profile_form($form_state, $profile='default') { $form = send_admin_form($profile); $form['#submit'][] = '_send_settings_submit'; $form["{$profile}_threshold"] = array( '#type' => 'textfield', '#title' => t('Send Threshold'), '#description' => t('The maximum number of times per hour a user can send a message. 0 for unlimited'), '#default_value' => send_value('threshold', $profile), '#size' => 3, '#maxlength' => 3, '#weight' => -9, ); $form['profile'] = array('#type' => 'value', '#value' => $profile); $form['submit'] = array('#type' => 'submit', '#value' => t('Save configuration')); return $form; } /** * nodetype-specific settings */ function _send_nodetype_form($form) { $form['#submit'][] = '_send_settings_submit'; $form['send'] = array(); if ($type = $form['#node_type']->type) { $form['send']['send_type'] = array( '#type' => 'value', '#value' => $type); } // goofy hack to get the buttons at the end of the array :( $form['submit']['#weight'] += 1; $form['delete']['#weight'] += 1; foreach (send_profiles() as $profile => $info) { $form['send'][$profile] = send_admin_form($profile, $type); $form['send'][$profile]['#title'] = $info['title']; $form['send'][$profile]['#type'] = 'fieldset'; $form['send'][$profile]['#collapsible'] = TRUE; $form['send'][$profile]['#collapsed'] = !variable_get("{$profile}_{$type}", 0); // enable this send type $form['send'][$profile]["{$profile}_{$type}"] = array( '#type' => 'checkbox', '#weight' => -10, '#title' => t('Enable "%name" functionality', array('%name' => $info['title'])), '#default_value' => variable_get("{$profile}_{$type}", 0), '#description' => t("Adds a link to a form that generates an HTML-formatted e-mail from your site's content."), ); // allow per-node overrides $form['send'][$profile]["{$profile}_{$type}_pernode"] = array( '#type' => 'checkbox', '#weight' => -9, '#title' => t('Permit changes on every post'), '#default_value' => send_value('pernode', $profile, $type), '#description' => t("Show this settings form on all nodes of this type, permitting you to cusomize the link text, template and other settings for each node."), ); } return $form; } /** * node-specific settings */ function _send_node_form($form) { $type = $form['type']['#value']; $node = $form['#node']; $form['send'] = array('#weight' => 50); foreach (send_profiles() as $profile => $info) { if (!variable_get("{$profile}_{$type}", 0)) continue; if (!variable_get("{$profile}_{$type}_pernode", 0)) continue; $form['send']['send_type'] = array('#type' => 'value', '#value' => $type); $form['send'][$profile] = send_admin_form($profile, $type, $node); $form['send'][$profile]['#title'] = $info['name']; $form['send'][$profile]['#type'] = 'fieldset'; $form['send'][$profile]['#collapsible'] = TRUE; $form['send'][$profile]['#collapsed'] = TRUE; } return $form; } function _send_settings_submit($form, &$form_state) { /* We don't want to junk up the variable namespace with our profile settings since we're relying on our own cascading variable storage. Import the variables into our storage handler and then delete them */ $values = $form_state['values']; $type = isset($values['send_type']) ? $values['send_type'] : NULL; $node = isset($values['nid']) ? (object)$values : NULL; foreach (send_profiles() as $profile => $name) { $namespace = "{$profile}_"; if ($type) { $namespace .= "{$type}_"; if (!$node) { db_query("DELETE FROM {variable} WHERE name LIKE '%s_%%_%s'", $profile, $type); // variables to keep in $conf foreach (array('linktext', 'pernode') as $var) { $varname = $namespace . $var; variable_set($varname, $values[$varname]); } $varname = $profile .'_'. $type; variable_set($varname, $values[$varname]); } } foreach ($values as $varname => $value) { $name = str_replace($namespace, '', $varname); if ($name != $varname) { send_value($name, $profile, $type, $node, $value); } } } }