'admin/votingapi_actions', 'title' => t('voting actions'), 'callback' => 'votingapi_actions_admin_page', 'access' => user_access('administer voting actions'), 'type' => MENU_NORMAL_ITEM); $items[] = array('path' => 'admin/votingapi_actions/list', 'title' => t('list'), 'callback' => 'votingapi_actions_admin_page', 'access' => user_access('administer voting actions'), 'type' => MENU_DEFAULT_LOCAL_TASK, 'weight' => '-1'); $items[] = array('path' => 'admin/votingapi_actions/add', 'title' => t('add'), 'callback' => 'votingapi_actions_admin_add_page', 'access' => user_access('administer voting actions'), 'type' => MENU_LOCAL_TASK); $items[] = array('path' => 'admin/votingapi_actions/edit', 'title' => t('edit action set'), 'callback' => 'votingapi_actions_admin_edit_page', 'access' => user_access('administer voting actions'), 'type' => MENU_CALLBACK); $items[] = array('path' => 'admin/votingapi_actions/import', 'title' => t('import'), 'callback' => 'votingapi_actions_admin_import_page', 'access' => user_access('administer voting actions'), 'type' => MENU_LOCAL_TASK); $items[] = array('path' => 'admin/votingapi_actions/export', 'title' => t('export action set'), 'callback' => 'votingapi_actions_admin_export_page', 'access' => user_access('administer voting actions'), 'type' => MENU_CALLBACK); $items[] = array('path' => 'admin/votingapi_actions/delete', 'title' => t('edit action set'), 'callback' => 'votingapi_actions_admin_delete_page', 'access' => user_access('administer voting actions'), 'type' => MENU_CALLBACK); $items[] = array('path' => 'admin/votingapi_actions/enable', 'callback' => 'votingapi_actions_admin_enable_page', 'access' => user_access('administer voting actions'), 'type' => MENU_CALLBACK); $items[] = array('path' => 'admin/votingapi_actions/disable', 'callback' => 'votingapi_actions_admin_disable_page', 'access' => user_access('administer voting actions'), 'type' => MENU_CALLBACK); } return $items; } /** * hunmonk's module dependency check: see http://drupal.org/node/54463 */ function votingapi_actions_form_alter($form_id, &$form) { if ($form_id == 'system_modules' && !$_POST) { votingapi_actions_system_module_validate($form); } } /** * hunmonk's module dependency check: see http://drupal.org/node/54463 */ function votingapi_actions_system_module_validate(&$form) { $module = 'votingapi_actions'; $dependencies = array('votingapi', 'actions'); foreach ($dependencies as $dependency) { if (!in_array($dependency, $form['status']['#default_value'])) { $missing_dependency = TRUE; $missing_dependency_list[] = $dependency; } } if (in_array($module, $form['status']['#default_value']) && isset($missing_dependency)) { db_query("UPDATE {system} SET status = 0 WHERE type = 'module' AND name = '%s'", $module); $key = array_search($module, $form['status']['#default_value']); unset($form['status']['#default_value'][$key]); drupal_set_message(t('The module %module was deactivated--it requires the following disabled/non-existant modules to function properly: %dependencies', array('%module' => $module, '%dependencies' => implode(', ', $missing_dependency_list))), 'error'); } } function votingapi_actions_admin_page() { $numSets = 25; drupal_set_title(t('administer voting actions')); foreach (_votingapi_load_action_sets_from_db() as $name => $set) { $items[] = array($name, $set['description'], theme('links', array(l(t('edit'), "admin/votingapi_actions/edit/$name"), l(t('export'), "admin/votingapi_actions/export/$name"), l(t('delete'), "admin/votingapi_actions/delete/$name")))); $used[$name] = true; } if ($items) { $output = theme('table', array(t('Name'), t('Description'), t('Actions')), $items, array("cellpadding" => "4"), t('User-Defined Action Sets')); $output .= theme('pager', NULL, $numSets); } else { $output .= '

'. t('No action sets have currently been defined.') .'

'; } $output .= '

'. t('Below are system default action sets; if you clone one of these, or create another set with the same name, it will override the default.') .'

'; $items = array(); $default_actions = _votingapi_load_action_sets_from_modules(); $set_status = variable_get('votingapi_action_status', array()); foreach ($default_actions as $name => $set) { if ($used[$name]) { $status = t('Overridden'); } else if (isset($set_status[$name])) { if ($set_status[$name]) { $status = t('Enabled'); } else { $status = t('Disabled'); } } else if ($set['enabled']) { $status = t('Enabled'); } else { $status = t('Disabled'); } if ($status == t('Enabled')) { $links = array(l(t('clone'), "admin/votingapi_actions/add/$name")); $links[] = l(t('disable'), "admin/votingapi_actions/disable/$name"); $links[] = l(t('export'), "admin/votingapi_actions/export/$name"); } else if ($status == t('Disabled')) { $links = array(l(t('clone'), "admin/votingapi_actions/add/$name")); $links[] = l(t('enable'), "admin/votingapi_actions/enable/$name"); $links[] = l(t('export'), "admin/votingapi_actions/export/$name"); } $items[] = array($name, $set['source'], $set['description'], $status, theme('links', $links)); } if ($items) { $output .= theme('table', array(t('Name'), t('Source'), t('Description'), t('Status'), t('Actions')), $items, array("cellpadding" => "4"), t('Default Action Sets')); } else { $output .= '

'. t('No action sets have currently been defined.') .'

'; } return $output; } function votingapi_actions_admin_add_page($set_name = NULL) { $code = _votingapi_create_set_code($set_name); $lines = substr_count($code, "\n"); if ($lines == 0) { $lines = 20; } $form['set'] = array( '#type' => 'textarea', '#title' => $set_name, '#default_value' => $code, '#rows' => $lines ); $form['submit'] = array( '#type' => 'submit', '#value' => t("Submit"), ); return drupal_get_form('votingapi_actions_set_import', $form); } function votingapi_actions_admin_edit_page($set_name) { $code = _votingapi_create_set_code($set_name); $lines = substr_count($code, "\n"); $form['old_name'] = array( '#type' => 'hidden', '#value' => $set_name, ); $form['set'] = array( '#type' => 'textarea', '#title' => $set_name, '#default_value' => $code, '#rows' => $lines ); $form['submit'] = array( '#type' => 'submit', '#value' => t("Submit"), ); return drupal_get_form('votingapi_actions_set_edit', $form); } function votingapi_actions_admin_import_page() { $form['set'] = array( '#type' => 'textarea', '#title' => t('Import Action Set Code'), '#cols' => 60, '#rows' => 20, '#description' => t('Cut and paste the results of an Export action set here.'), ); $form['submit'] = array( '#type' => 'submit', '#value' => t("Submit"), ); return drupal_get_form('votingapi_actions_set_import', $form); } /* * Handle the submit button on importing an action set. */ function votingapi_actions_set_import_validate($form_id, &$form) { ob_start(); eval($form['set']); ob_end_clean(); if (is_array($sets)) { foreach($sets as $name => $set) { if ($name) { $errors = _votingapi_validate_action_set($name, $set); foreach($errors as $error) { form_set_error('', $error); } } } } } /* * Handle the submit button on importing an action set. */ function votingapi_actions_set_import_submit($formid, $form) { ob_start(); eval($form['set']); ob_end_clean(); if (is_array($sets)) { foreach($sets as $name => $set) { if ($name) { $errors = _votingapi_validate_action_set($name, $set); if (count($errors) == 0) { _votingapi_insert_set($name, $set); votingapi_rebuild_action_cache(); drupal_goto('admin/votingapi_actions'); } else { foreach ($errors as $error) { drupal_set_message($error); } } } else { drupal_set_message(t('Unable to get an action set out of that.')); return; } } } } /* * Handle the submit button on importing an action set. */ function votingapi_actions_set_edit_validate($form_id, &$form) { ob_start(); eval($form['set']); ob_end_clean(); if (is_array($sets)) { foreach($sets as $name => $set) { if ($name) { $errors = _votingapi_validate_action_set($name, $set); foreach($errors as $error) { form_set_error('', $error); } } } } } /* * Handle the submit button on importing an action set. */ function votingapi_actions_set_edit_submit($formid, $form) { ob_start(); eval($form['set']); ob_end_clean(); if (is_array($sets)) { foreach($sets as $name => $set) { if ($name) { $errors = _votingapi_validate_action_set($name, $set); if (count($errors) == 0) { _votingapi_update_set($name, $form['old_name'], $set); votingapi_rebuild_action_cache(); drupal_goto('admin/votingapi_actions'); } else { foreach ($errors as $error) { drupal_set_message($error); } } } else { drupal_set_message(t('Unable to get an action set out of that.')); return; } } } } function votingapi_actions_admin_export_page($set_name) { $code = _votingapi_create_set_code($set_name); $lines = substr_count($code, "\n"); $form['code'] = array( '#type' => 'textarea', '#title' => $set['name'], '#default_value' => $code, '#rows' => $lines ); return drupal_get_form('votingapi_actions_set_export', $form); } function votingapi_actions_admin_delete_page($set_name) { $form['set'] = array('#type' => 'value', '#value' => $set_name); return confirm_form('votingapi_actions_admin_delete_confirm', $form, t('Are you sure you want to delete %title?', array('%title' => $set_name)), $_GET['destination'] ? $_GET['destination'] : 'admin/votingapi_actions', t('This action cannot be undone.'), t('Delete'), t('Cancel') ); } /* * Handle the submit button to delete a view. */ function votingapi_actions_admin_delete_confirm_submit($formid, $form) { if ($form['confirm']) { $name = $form['set']; $sets = _votingapi_load_action_sets_from_db(); if ($sets[$name]) { _votingapi_delete_set($name, $set[$name]); votingapi_rebuild_action_cache(); } drupal_goto('admin/votingapi_actions'); } } function votingapi_actions_admin_enable_page($set_name) { _votingapi_set_action_status($set_name, true); drupal_goto('admin/votingapi_actions'); } function votingapi_actions_admin_disable_page($set_name) { _votingapi_set_action_status($set_name, false); drupal_goto('admin/votingapi_actions'); } function _votingapi_create_set_code($set_name) { $data = cache_get('votingapi_action_sets'); $action_sets = unserialize($data->data); $set = $action_sets[$set_name]; if ($set) { unset($set['name']); $code = "\n\$sets = array(\n"; $code .= "'$set_name' => "; ob_start(); var_export($set); $code .= ob_get_clean(); ob_end_clean(); $code .= "\n);\n"; } return $code; }