1 |
85ad3d82
|
Assos Assos
|
<?php
|
2 |
|
|
|
3 |
|
|
if (module_exists('search')) {
|
4 |
|
|
/**
|
5 |
|
|
* Plugins are described by creating a $plugin array which will be used
|
6 |
|
|
* by the system that includes this file.
|
7 |
|
|
*/
|
8 |
|
|
$plugin = array(
|
9 |
|
|
'single' => TRUE,
|
10 |
|
|
'title' => t('Advanced search form'),
|
11 |
|
|
'icon' => 'icon_search.png',
|
12 |
|
|
'description' => t('A search form with advanced options.'),
|
13 |
|
|
'required context' => new ctools_context_optional(t('Keywords'), 'string'),
|
14 |
|
|
'category' => t('Widgets'),
|
15 |
|
|
'defaults' => array(
|
16 |
|
|
'type' => 'node',
|
17 |
|
|
'form' => 'advanced',
|
18 |
|
|
'path_type' => 'default',
|
19 |
|
|
'path' => '',
|
20 |
|
|
'override_prompt' => FALSE,
|
21 |
|
|
'prompt' => '',
|
22 |
|
|
),
|
23 |
|
|
);
|
24 |
|
|
}
|
25 |
|
|
|
26 |
|
|
/**
|
27 |
|
|
* Render the custom content type.
|
28 |
|
|
*/
|
29 |
|
|
function ctools_search_form_content_type_render($subtype, $conf, $panel_args, $context) {
|
30 |
|
|
if (empty($context) || empty($context->data)) {
|
31 |
|
|
$keys = '';
|
32 |
|
|
}
|
33 |
|
|
else {
|
34 |
|
|
$keys = $context->data;
|
35 |
|
|
}
|
36 |
|
|
|
37 |
|
|
// Build the content type block.
|
38 |
|
|
$block = new stdClass();
|
39 |
|
|
$block->module = 'search';
|
40 |
|
|
$block->delta = 'form';
|
41 |
|
|
$block->title = '';
|
42 |
|
|
|
43 |
|
|
switch ($conf['path_type']) {
|
44 |
|
|
default:
|
45 |
|
|
case 'default':
|
46 |
|
|
$path = 'search/' . $conf['type'];
|
47 |
|
|
break;
|
48 |
|
|
case 'same':
|
49 |
|
|
$path = $_GET['q'];
|
50 |
|
|
$path = str_replace($keys, '', $path);
|
51 |
|
|
break;
|
52 |
|
|
case 'custom':
|
53 |
|
|
$path = $conf['path'];
|
54 |
|
|
break;
|
55 |
|
|
}
|
56 |
|
|
|
57 |
|
|
$prompt = $conf['override_prompt'] ? $conf['prompt'] : NULL;
|
58 |
|
|
|
59 |
|
|
$form_state = array(
|
60 |
|
|
'build_info' => array(
|
61 |
|
|
'args' => array($path, $keys, $conf['type'], $prompt),
|
62 |
|
|
),
|
63 |
|
|
);
|
64 |
|
|
|
65 |
|
|
module_load_include('inc', 'search', 'search.pages');
|
66 |
|
|
|
67 |
|
|
$block->content = drupal_build_form('search_form', $form_state);
|
68 |
|
|
if ($conf['form'] == 'simple' && isset($block->content['advanced'])) {
|
69 |
|
|
$block->content['advanced']['#access'] = FALSE;
|
70 |
|
|
}
|
71 |
|
|
|
72 |
|
|
return $block;
|
73 |
|
|
}
|
74 |
|
|
|
75 |
|
|
/**
|
76 |
|
|
* Returns an edit form for custom type settings.
|
77 |
|
|
*/
|
78 |
|
|
function ctools_search_form_content_type_edit_form($form, &$form_state) {
|
79 |
|
|
$conf = $form_state['conf'];
|
80 |
|
|
|
81 |
|
|
$types = array();
|
82 |
|
|
foreach (search_get_info() as $module => $info) {
|
83 |
|
|
$types[$module] = $info['title'];
|
84 |
|
|
}
|
85 |
|
|
|
86 |
|
|
$form['type'] = array(
|
87 |
|
|
'#type' => 'select',
|
88 |
|
|
'#title' => t('Search type'),
|
89 |
|
|
'#options' => $types,
|
90 |
|
|
'#default_value' => $conf['type'],
|
91 |
|
|
);
|
92 |
|
|
|
93 |
|
|
$form['form'] = array(
|
94 |
|
|
'#type' => 'select',
|
95 |
|
|
'#title' => t('Search form'),
|
96 |
|
|
'#options' => array(
|
97 |
|
|
'simple' => t('Simple'),
|
98 |
|
|
'advanced' => t('Advanced'),
|
99 |
|
|
),
|
100 |
|
|
'#default_value' => $conf['form'],
|
101 |
|
|
'#description' => t('The advanced form may have additional options based upon the search type. For example the advanced content (node) search form will allow searching by node type and taxonomy term.'),
|
102 |
|
|
);
|
103 |
|
|
|
104 |
|
|
$form['path_type'] = array(
|
105 |
|
|
'#prefix' => '<div class="container-inline">',
|
106 |
|
|
'#type' => 'select',
|
107 |
|
|
'#title' => t('Path'),
|
108 |
|
|
'#options' => array(
|
109 |
|
|
'default' => t('Default'),
|
110 |
|
|
'same' => t('Same page'),
|
111 |
|
|
'custom' => t('Custom'),
|
112 |
|
|
),
|
113 |
|
|
'#default_value' => $conf['path_type'],
|
114 |
|
|
);
|
115 |
|
|
|
116 |
|
|
$form['path'] = array(
|
117 |
|
|
'#type' => 'textfield',
|
118 |
|
|
'#default_value' => $conf['path'],
|
119 |
|
|
'#dependency' => array('edit-path-type' => array('custom')),
|
120 |
|
|
'#suffix' => '</div>',
|
121 |
|
|
);
|
122 |
|
|
|
123 |
|
|
$form['override_prompt'] = array(
|
124 |
|
|
'#prefix' => '<div class="container-inline">',
|
125 |
|
|
'#type' => 'checkbox',
|
126 |
|
|
'#default_value' => $conf['override_prompt'],
|
127 |
|
|
'#title' => t('Override default prompt'),
|
128 |
|
|
);
|
129 |
|
|
|
130 |
|
|
$form['prompt'] = array(
|
131 |
|
|
'#type' => 'textfield',
|
132 |
|
|
'#default_value' => $conf['prompt'],
|
133 |
|
|
'#dependency' => array('edit-override-prompt' => array(1)),
|
134 |
|
|
'#suffix' => '</div>',
|
135 |
|
|
);
|
136 |
|
|
return $form;
|
137 |
|
|
}
|
138 |
|
|
|
139 |
|
|
/**
|
140 |
|
|
* Submit handler for search form.
|
141 |
|
|
*/
|
142 |
|
|
function ctools_search_form_content_type_edit_form_submit($form, &$form_state) {
|
143 |
|
|
// Copy everything from our defaults.
|
144 |
|
|
foreach (array_keys($form_state['plugin']['defaults']) as $key) {
|
145 |
|
|
$form_state['conf'][$key] = $form_state['values'][$key];
|
146 |
|
|
}
|
147 |
|
|
}
|
148 |
|
|
|
149 |
|
|
/**
|
150 |
|
|
* Returns the administrative title for a type.
|
151 |
|
|
*/
|
152 |
|
|
function ctools_search_form_content_type_admin_title($subtype, $conf, $context) {
|
153 |
|
|
$info = search_get_info();
|
154 |
|
|
$type = isset($info[$conf['type']]['title']) ? $info[$conf['type']]['title'] : t('Missing/broken type');
|
155 |
|
|
return t('@type search form', array('@type' => $type));
|
156 |
|
|
} |