| 1 |
<?php
|
| 2 |
// $Id$
|
| 3 |
|
| 4 |
define('CONNECT_BLOCK_PARENT_ONLY', 1);
|
| 5 |
define('CONNECT_BLOCK_NOT_PARENT', 2);
|
| 6 |
|
| 7 |
function connect_block_list() {
|
| 8 |
$return = array();
|
| 9 |
|
| 10 |
// find all the connect parent node types
|
| 11 |
$parent_nodetypes = variable_get('connect_parent_nodes', array());
|
| 12 |
if (empty($parent_nodetypes)) {
|
| 13 |
return $return;
|
| 14 |
}
|
| 15 |
foreach ($parent_nodetypes as $type) {
|
| 16 |
$types .= "'$type',";
|
| 17 |
}
|
| 18 |
$types = substr($types, 0, strlen($types)-1);
|
| 19 |
|
| 20 |
// determine which parent nodes expose the child form as a block
|
| 21 |
$sql = "SELECT nid FROM {node} WHERE type IN ($types);";
|
| 22 |
$result = db_query($sql);
|
| 23 |
while ($row = db_fetch_object($result)) {
|
| 24 |
$parent_node = node_load($row->nid);
|
| 25 |
$parent_actions = connect_get_actions($parent_node->nid);
|
| 26 |
if (in_array('connect_action_provide_block', $parent_actions)) {
|
| 27 |
$return[$parent_node->nid] = array('info' => 'Connect: '. $parent_node->title);
|
| 28 |
}
|
| 29 |
}
|
| 30 |
|
| 31 |
return $return;
|
| 32 |
}
|
| 33 |
|
| 34 |
// TODO -- prevent block from displaying wrong form
|
| 35 |
// when main page is another action without a block
|
| 36 |
function connect_block_view($nid = 0) {
|
| 37 |
$return = array();
|
| 38 |
$parent_node = node_load($nid);
|
| 39 |
if ($parent_node) {
|
| 40 |
$parent_node =& _connect_parent_node($parent_node);
|
| 41 |
|
| 42 |
// only display if the block option is turned on
|
| 43 |
//$parent_actions = connect_get_actions($nid);
|
| 44 |
if (!in_array('connect_action_provide_block', connect_get_actions($nid))) {
|
| 45 |
return;
|
| 46 |
}
|
| 47 |
|
| 48 |
// require a CAPTCHA on the form?
|
| 49 |
if (!_connect_captcha_test('connect_form_block')) {
|
| 50 |
return;
|
| 51 |
}
|
| 52 |
|
| 53 |
// visibility control
|
| 54 |
$visibility = connect_node_options($nid, 'provide_block_visibility');
|
| 55 |
if ($visibility > 0) {
|
| 56 |
$parent_path = "node/$nid";
|
| 57 |
$current_path = arg(0) .'/'. arg(1);
|
| 58 |
if (($visibility == CONNECT_BLOCK_NOT_PARENT && $parent_path == $current_path) ||
|
| 59 |
($visibility == CONNECT_BLOCK_PARENT_ONLY && $parent_path != $current_path))
|
| 60 |
{
|
| 61 |
return;
|
| 62 |
}
|
| 63 |
}
|
| 64 |
|
| 65 |
$form = drupal_get_form('connect_form_block', 'block', $nid);
|
| 66 |
$text = connect_node_options($nid, 'provide_block_text');
|
| 67 |
$link = empty($text) ? '' : '<p>» '. l($text, "node/$nid") .'</p>';
|
| 68 |
$return['subject'] = $parent_node->title;
|
| 69 |
$return['content'] = $form . $link;
|
| 70 |
}
|
| 71 |
return $return;
|
| 72 |
}
|
| 73 |
|
| 74 |
/*
|
| 75 |
* these just call the regular form functions, but with form_id = 'connect_form_block'
|
| 76 |
*/
|
| 77 |
/*
|
| 78 |
function connect_form_block() {
|
| 79 |
$form = connect_form();
|
| 80 |
return $form;
|
| 81 |
}
|
| 82 |
|
| 83 |
function connect_form_block_validate($form_id, &$form_values) {
|
| 84 |
return connect_form_validate($form_id, $form_values);
|
| 85 |
}
|
| 86 |
|
| 87 |
function connect_form_block_submit($form_id, &$form_values) {
|
| 88 |
return connect_form_submit($form_id, $form_values);
|
| 89 |
}
|
| 90 |
*/
|