| 1 |
<?php // $Id$ |
<?php // $Id: votesmart.module,v 1.1 2008/08/06 00:27:37 vauxia Exp $ |
| 2 |
|
|
| 3 |
/** |
/** |
| 4 |
* Implementation of hook_menu(). |
* Implementation of hook_menu(). |
| 5 |
*/ |
*/ |
| 6 |
function votesmart_menu() { |
function votesmart_menu() { |
| 7 |
return array( |
return array( |
| 8 |
'admin/settings/votesmart' => array( |
'admin/build/votesmart' => array( |
| 9 |
'title' => 'API information', |
'title' => 'Project Vote Smart', |
| 10 |
'page callback' => 'drupal_get_form', |
'page callback' => 'drupal_get_form', |
| 11 |
'page arguments' => array('votesmart_settings'), |
'page arguments' => array('votesmart_settings'), |
| 12 |
'access arguments' => array('administer votesmart'), |
'access arguments' => array('administer votesmart'), |
| 13 |
'file' => 'votesmart.inc', |
'file' => 'votesmart.inc', |
| 14 |
), |
), |
| 15 |
'admin/settings/votesmart/overview' => array( |
'admin/build/votesmart/overview' => array( |
| 16 |
'title' => 'Settings', |
'title' => 'API information', |
| 17 |
'weight' => -10, |
'weight' => -10, |
| 18 |
'type' => MENU_DEFAULT_LOCAL_TASK, |
'type' => MENU_DEFAULT_LOCAL_TASK, |
| 19 |
), |
), |
| 35 |
$args = func_get_args(); |
$args = func_get_args(); |
| 36 |
return call_user_func_array('_votesmart_api', $args); |
return call_user_func_array('_votesmart_api', $args); |
| 37 |
} |
} |
| 38 |
|
|
| 39 |
|
function votesmart_get_record($table, $id) { |
| 40 |
|
$table = current(votesmart_tables($table)); |
| 41 |
|
$request = $table['votesmart']; |
| 42 |
|
// TODO not the right way at all. |
| 43 |
|
$keys = array(); |
| 44 |
|
foreach($request[1] as $name) $keys[$name] = $id; |
| 45 |
|
$request[1] = $keys; |
| 46 |
|
$data = call_user_func_array('votesmart_api', $request); |
| 47 |
|
return _votesmart_field_values($table, $data); |
| 48 |
|
} |
| 49 |
|
|
| 50 |
|
function votesmart_lists($filter = NULL) { |
| 51 |
|
require_once dirname(__FILE__) . '/votesmart.inc'; |
| 52 |
|
return _votesmart_lists($filter); |
| 53 |
|
} |
| 54 |
|
|
| 55 |
|
function votesmart_tables($filter = NULL) { |
| 56 |
|
require_once dirname(__FILE__) . '/votesmart.inc'; |
| 57 |
|
return _votesmart_tables($filter); |
| 58 |
|
} |
| 59 |
|
|
| 60 |
|
function votesmart_token_list($type = 'all') { |
| 61 |
|
if ($type == 'all' || substr($type, 0, 10) == 'votesmart_') { |
| 62 |
|
$tokens = array(); |
| 63 |
|
$filter = ($type == 'all') ? NULL : str_replace('votesmart_', '', $type); |
| 64 |
|
foreach (votesmart_tables($filter) as $table_name => $table) { |
| 65 |
|
if (!isset($table['fields'])) return; |
| 66 |
|
$tokens['votesmart_'. $table_name] = array(); |
| 67 |
|
foreach ($table['fields'] as $field_name => $field) { |
| 68 |
|
$tokens['votesmart_'. $table_name][$field_name] = $field['description']; |
| 69 |
|
} |
| 70 |
|
} |
| 71 |
|
|
| 72 |
|
return $tokens; |
| 73 |
|
} |
| 74 |
|
} |
| 75 |
|
|
| 76 |
|
function votesmart_token_values($type, $object = NULL, $options = array()) { |
| 77 |
|
$object = (object) $object; |
| 78 |
|
$values = array(); |
| 79 |
|
$table = str_replace('votesmart_', '', $type); |
| 80 |
|
|
| 81 |
|
if ($object->votesmart_id && $data = votesmart_get_record($table, $object->votesmart_id)) { |
| 82 |
|
} |
| 83 |
|
return $values; |
| 84 |
|
} |