class BotchaForm in BOTCHA Spam Prevention 6.3
Same name and namespace in other branches
- 6.2 controller/botcha_form.controller.inc \BotchaForm
- 7.2 controller/botcha_form.controller.inc \BotchaForm
- 7.3 controller/form/botcha.form.controller.inc \BotchaForm
Hierarchy
- class \BotchaForm
Expanded class hierarchy of BotchaForm
File
- controller/
form/ botcha.form.controller.inc, line 91 - Controller layer of the BotchaForm objects.
View source
class BotchaForm {
protected $recipebook;
public function __construct($form_id) {
$this->id = $form_id;
$this->form_id = $form_id;
}
public function setRecipebook($rbid) {
$this->recipebook = $rbid;
return $this;
}
function unsetRecipebook() {
unset($this->recipebook);
return $this;
}
/**
* @todo BotchaForm getRecipebook Description.
* @return BotchaRecipebook
*/
public function getRecipebook() {
if (!isset($this->recipebook)) {
$rbs = BotchaModel::getRecipebooksForms(array(
'mode' => 'recipebook',
'forms' => $this->id,
));
// In fact there is not more than 1 item.
// @todo Remove hardcode.
$this->recipebook = !empty($rbs) ? current($rbs) : 'none';
}
return $this->recipebook;
}
public function isEnabled() {
$form_id = $this->id;
$isEnabled = variable_get("botcha_enabled_{$form_id}", 0);
return $isEnabled;
}
public function setEnabled($enabled) {
$form_id = $this->id;
// Cast to boolean first.
$enabled = (bool) $enabled;
// Cast to integer.
$enabled = (int) $enabled;
variable_set("botcha_enabled_{$form_id}", $enabled);
return $this;
}
public function addAdminLinks(&$form) {
$form_id = $form['form_id']['#value'];
if (variable_get('botcha_administration_mode', FALSE) && user_access('administer BOTCHA settings') && (arg(0) != 'admin' || variable_get('botcha_allow_on_admin_pages', FALSE) || $form_id == 'user_register') && $form_id != 'update_script_selection_form') {
// Add BOTCHA administration tools.
$botcha_element = $this
->createAdminLinksFieldset($form_id);
// Get placement in form and insert in form.
// @todo Make away with a dependency from botcha.inc.
$botcha_placement = _botcha_get_botcha_placement($form_id, $form);
_botcha_insert_botcha_element($form, $botcha_placement, $botcha_element);
}
}
protected function createAdminLinksFieldset($form_id) {
// For administrators: show BOTCHA info and offer link to configure it.
$botcha_element = array(
'#type' => 'fieldset',
'#title' => t('BOTCHA'),
'#collapsible' => TRUE,
'#collapsed' => TRUE,
// @todo Abstract it.
'#attributes' => array(
'class' => 'botcha-admin-links',
),
);
$rbid = $this
->getRecipebook();
// @todo Remove hardcode.
if ($rbid === 'none') {
$botcha_element['#title'] = t('BOTCHA: no protection enabled');
$botcha_element['add_botcha'] = array(
// @todo Abstract it.
'#value' => l(t('Add BOTCHA protection on form'), Botcha::ADMIN_PATH . "/form/add", array(
'query' => drupal_get_destination() . "&botcha_form_id={$form_id}",
'html' => TRUE,
)),
);
}
else {
$botcha_element['#title'] = t('BOTCHA: protection enabled (@recipebook recipe book)', array(
'@recipebook' => $rbid,
));
$botcha_element['#description'] = t('Untrusted users will have form %form_id protected by BOTCHA (!recipebook_settings, !general_settings).', array(
'%form_id' => $form_id,
'!recipebook_settings' => l(t('Recipe book settings'), Botcha::ADMIN_PATH . "/recipebook/{$rbid}"),
'!general_settings' => l(t('General BOTCHA settings'), Botcha::ADMIN_PATH),
));
$botcha_element['protection'] = array(
'#type' => 'item',
'#title' => t('Enabled protection'),
// @todo Abstract it.
'#value' => t('Form is protected by "@recipebook" recipe book (!edit, !disable)', array(
//'#markup' => t('Form is protected by "@recipebook" recipe book (!edit, !disable)', array(
'@recipebook' => $rbid,
'!edit' => l(t('edit'), Botcha::ADMIN_PATH . "/form/{$form_id}", array(
'query' => drupal_get_destination(),
'html' => TRUE,
)),
'!disable' => l(t('disable'), Botcha::ADMIN_PATH . "/form/{$form_id}/disable", array(
'query' => drupal_get_destination(),
'html' => TRUE,
)),
)),
);
}
return $botcha_element;
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
BotchaForm:: |
protected | property | ||
BotchaForm:: |
public | function | 1 | |
BotchaForm:: |
protected | function | ||
BotchaForm:: |
public | function | @todo BotchaForm getRecipebook Description. | 1 |
BotchaForm:: |
public | function | ||
BotchaForm:: |
public | function | ||
BotchaForm:: |
public | function | ||
BotchaForm:: |
function | |||
BotchaForm:: |
public | function | 1 |