Esempio n. 1
0
function connect_block_view($nid = 0)
{
    $return = array();
    $parent_node = node_load($nid);
    if ($parent_node) {
        $parent_node =& _connect_parent_node($parent_node);
        // only display if the block option is turned on
        //$parent_actions = connect_get_actions($nid);
        if (!in_array('connect_action_provide_block', connect_get_actions($nid))) {
            return;
        }
        // require a CAPTCHA on the form?
        if (!_connect_captcha_test('connect_form_block')) {
            return;
        }
        // visibility control
        $visibility = connect_node_options($nid, 'provide_block_visibility');
        if ($visibility > 0) {
            $parent_path = "node/{$nid}";
            $current_path = arg(0) . '/' . arg(1);
            if ($visibility == CONNECT_BLOCK_NOT_PARENT && $parent_path == $current_path || $visibility == CONNECT_BLOCK_PARENT_ONLY && $parent_path != $current_path) {
                return;
            }
        }
        $form = drupal_get_form('connect_form_block', 'block', $nid);
        $text = connect_node_options($nid, 'provide_block_text');
        $link = empty($text) ? '' : '<p>&raquo;&nbsp;' . l($text, "node/{$nid}") . '</p>';
        $return['subject'] = $parent_node->title;
        $return['content'] = $form . $link;
    }
    return $return;
}
Esempio n. 2
0
function connect_node_settings_form_submit($form, &$form_state)
{
    // save overall settings
    foreach ($form_state['values']['campaign_variables'] as $function => $vars) {
        _connect_set_values_from_form($vars, $form_state['values']['parent_id']);
    }
    // save variable->field mapping
    $options = array();
    foreach (array('variables_parent', 'variables_child') as $formitem) {
        if (isset($form_state['values'][$formitem])) {
            foreach ($form_state['values'][$formitem] as $key => $value) {
                if (!empty($value)) {
                    $options[$key] = $value;
                }
            }
        }
    }
    connect_node_options($form_state['values']['parent_id'], 'connect_map', $options);
    $null = drupal_get_messages(NULL);
    // clear bogus _connect_hook_check_requirements errors
    drupal_set_message('The campaign configuration has been updated.');
}
Esempio n. 3
0
function _connect_action_process_opt_in($pid, $cid, $token)
{
    if (!is_numeric($pid) || !is_numeric($cid)) {
        drupal_goto('node');
    }
    $parent = node_load($pid);
    $child = node_load($cid);
    if ($parent && $child && connect_get_parent($child) == $pid) {
        $test = connect_value('double_optin_token', $parent, $child, 'child');
        if ($test == $token) {
            connect_value('double_optin_token', $parent, $child, 'child', 'yes');
            node_save($child);
            drupal_set_message(connect_node_options($parent->nid, 'double_optin_message'));
        }
    }
    drupal_goto("node/{$pid}");
}
Esempio n. 4
0
function connect_lookup_mp($op = 'lookup', &$parent, &$child)
{
    switch ($op) {
        case 'cache':
            return array('EDID2MP' => 'Federal riding to MP', 'pc2riding_federal_federal_ca' => 'Postal code to Federal riding');
            break;
        case 'requires':
            $return['variables'] = array('makethechange_key' => array('#type' => 'textfield', '#title' => 'Makethechange web service key', '#default_value' => connect_node_options($parent->nid, 'makethechange_key'), '#required' => TRUE), 'mp_lookup_cache' => array('#type' => 'radios', '#title' => 'Cache the lookup data?', '#options' => array('no' => 'No', 'yes' => 'Yes'), '#default_value' => connect_node_options($parent->nid, 'mp_lookup_cache'), '#required' => TRUE));
            $return['child'] = array('postal_code' => 'Postal code', 'lookup_mp_data_edid' => 'Riding');
            return $return;
        case 'validate':
            $code = connect_value('postal_code', $parent, $child, 'child');
            if (!connect_is_postalcode($code)) {
                form_set_error('', 'Please enter a valid postal code.');
            }
            break;
        case 'lookup':
            $return = array();
            $use_cache = connect_node_options($parent->nid, 'mp_lookup_cache') == 'yes';
            $mtc_key = connect_node_options($parent->nid, 'makethechange_key');
            $postalcode = connect_value('postal_code', $parent, $child, 'child');
            $edid = _connect_get_riding($mtc_key, $postalcode, 'federal', 'federal', $use_cache);
            if ($edid) {
                // save the riding in the child node
                connect_value('lookup_mp_data_edid', $parent, $child, 'child', $edid[0]['id']);
                /* Danger! in rare cases there may be > 1 matches: this
                 * just grabs the first one; if this is a problem,
                 * use the CCK MPautocomplete version to allow users to select a riding
                 * or write a two-stage version of the participation form
                 */
                $mp = _connect_get_MP_by_EDID($mtc_key, $edid[0]['id'], $use_cache);
                if (!empty($mp)) {
                    $return['name'] = $mp->mp_name;
                    $return['email'] = $mp->Email;
                    $return['fax'] = $mp->HillFax;
                } else {
                    watchdog('connect', "connect_lookup_mp: MP not found for {$edid['0']}[id]");
                }
            } else {
                watchdog('connect', "connect_lookup_mp: EDID not found for {$postalcode}");
            }
            return $return;
            break;
    }
}