| 1 |
<?php
|
| 2 |
// $Id$
|
| 3 |
require_once("default_settings.inc");
|
| 4 |
|
| 5 |
|
| 6 |
/**
|
| 7 |
* FAPI definition for Google Ajax Search settings form.
|
| 8 |
*
|
| 9 |
* @ingroup forms
|
| 10 |
* @see googleajaxsearch_settings_validate()
|
| 11 |
*
|
| 12 |
* @return
|
| 13 |
* array with settings form.
|
| 14 |
*/
|
| 15 |
function googleajaxsearch_settings() {
|
| 16 |
$form['block_count'] = array(
|
| 17 |
'#type' => 'textfield',
|
| 18 |
'#title' => t('Number of search blocks'),
|
| 19 |
'#default_value' => variable_get('block_count', GAS_BLOCKS_NUMBER_DEFAULT),
|
| 20 |
'#size' => 60,
|
| 21 |
'#maxlength' => 64,
|
| 22 |
'#description' => t('Description'),
|
| 23 |
);
|
| 24 |
$form['api_key'] = array(
|
| 25 |
'#type' => 'textfield',
|
| 26 |
'#title' => t('Google Ajax Search Api Key'),
|
| 27 |
'#default_value' => variable_get('api_key', GAS_API_KEY_DEFAULT),
|
| 28 |
'#size' => 60,
|
| 29 |
'#maxlength' => 64,
|
| 30 |
'#description' => t('Description'),
|
| 31 |
);
|
| 32 |
|
| 33 |
return system_settings_form($form);
|
| 34 |
}
|
| 35 |
|
| 36 |
/**
|
| 37 |
* Returns rendered settings form for Google Ajax Search module.
|
| 38 |
*
|
| 39 |
* @return
|
| 40 |
* rendered form.
|
| 41 |
*/
|
| 42 |
function googleajaxsearch_settings_page() {
|
| 43 |
return drupal_get_form('googleajaxsearch_settings');
|
| 44 |
}
|
| 45 |
|
| 46 |
/**
|
| 47 |
* Returns block in which google searcher will be embeded.
|
| 48 |
*
|
| 49 |
* @param mixed $delta
|
| 50 |
* selects which block should be returned
|
| 51 |
* @return
|
| 52 |
* block for embedding.
|
| 53 |
*/
|
| 54 |
function googleajaxsearch_display_block($delta) {
|
| 55 |
drupal_add_css(drupal_get_path('module', 'googleajaxsearch') . '/googleajaxsearch.css');
|
| 56 |
gas_add_api();
|
| 57 |
gas_add_settings($delta);
|
| 58 |
gas_add_scripts();
|
| 59 |
|
| 60 |
$display = gas_get_settings(array('delta' => $delta, 'param' => 'form_display'));
|
| 61 |
|
| 62 |
$display == 0 ? $content = "<div id='searchcontrol-$delta'>Loading...</div>" :
|
| 63 |
$content = "<div id='searchcontrol-$delta'>Loading...</div>
|
| 64 |
<div id='searchcontrol-branding-$delta'>Branding...</div>";
|
| 65 |
|
| 66 |
$block = array(
|
| 67 |
'subject' => t('Title of block'),
|
| 68 |
'content' => $content,
|
| 69 |
);
|
| 70 |
return $block;
|
| 71 |
}
|
| 72 |
|
| 73 |
/**
|
| 74 |
* Returns settings form for block $delta.
|
| 75 |
*
|
| 76 |
* @param mixed $delta
|
| 77 |
* selects for which block, settings form should be returned
|
| 78 |
* @return
|
| 79 |
* array with settings form.
|
| 80 |
*/
|
| 81 |
function gas_block_form($delta) {
|
| 82 |
$settings = gas_get_settings();
|
| 83 |
|
| 84 |
$form[$field = 'search_options'] = array(
|
| 85 |
'#type' => 'checkboxes',
|
| 86 |
'#title' => t('Search type'),
|
| 87 |
'#default_value' => gas_get_settings(array('delta' => $delta, 'param' => $field)),
|
| 88 |
'#options' => array(
|
| 89 |
'web_search' => t('Web search'),
|
| 90 |
'local_search' => t('Local search'),
|
| 91 |
'video_search' => t('Video search'),
|
| 92 |
'blog_search' => t('Blog search'),
|
| 93 |
'news_search' => t('News search'),
|
| 94 |
'image_search' => t('Image search'),
|
| 95 |
'book_search' => t('Book search'),
|
| 96 |
'patent_search' => t('Patent search'),
|
| 97 |
),
|
| 98 |
'#description' => t('Select types of content in which do you want to search.'),
|
| 99 |
);
|
| 100 |
//hide
|
| 101 |
$form[$field = 'form_display'] = array(
|
| 102 |
'#type' => 'select',
|
| 103 |
'#title' => t('Form display'),
|
| 104 |
'#default_value' => gas_get_settings(array('delta' => $delta, 'param' => $field)),
|
| 105 |
'#options' => array(
|
| 106 |
0 => t('Show'),
|
| 107 |
1 => t('Hide')),
|
| 108 |
'#description' => t('If selected \'hide\', form for entering queries will not be displayed and only results will be published.'),
|
| 109 |
);
|
| 110 |
//displaying of results
|
| 111 |
$form[$field = 'results_display'] = array(
|
| 112 |
'#type' => 'select',
|
| 113 |
'#title' => t('Display of results'),
|
| 114 |
'#default_value' => gas_get_settings(array('delta' => $delta, 'param' => $field)),
|
| 115 |
'#options' => array(
|
| 116 |
'DRAW_MODE_LINEAR' => t('inline'),
|
| 117 |
'DRAW_MODE_TABBED' => t('tabbed')),
|
| 118 |
'#description' => t('How the results should be displayed.'),
|
| 119 |
);
|
| 120 |
//place for results
|
| 121 |
$form[$field = 'results_place'] = array(
|
| 122 |
'#type' => 'textfield',
|
| 123 |
'#title' => t('Place of displaying results'),
|
| 124 |
'#default_value' => gas_get_settings(array('delta' => $delta, 'param' => $field)),
|
| 125 |
'#description' => t('Where the results should be displayed. Enter fields html ID.'),
|
| 126 |
);
|
| 127 |
// setLinkTarget
|
| 128 |
$form[$field = 'target_place'] = array(
|
| 129 |
'#type' => 'select',
|
| 130 |
'#title' => t('Target of opened links'),
|
| 131 |
'#default_value' => gas_get_settings(array('delta' => $delta, 'param' => $field)),
|
| 132 |
'#options' => array(
|
| 133 |
'LINK_TARGET_BLANK' => t('open in a new window'),
|
| 134 |
'LINK_TARGET_SELF' => t('open in the same window and frame'),
|
| 135 |
'LINK_TARGET_TOP' => t('open in the topmost frame'),
|
| 136 |
'LINK_TARGET_PARENT' => t('open in either the topmost frame, or replace the current frame')),
|
| 137 |
'#description' => t('Specifies how links should be opened.'),
|
| 138 |
);
|
| 139 |
//number of results
|
| 140 |
$form[$field = 'results_number'] = array(
|
| 141 |
'#type' => 'select',
|
| 142 |
'#title' => t('Number of results'),
|
| 143 |
'#default_value' => gas_get_settings(array('delta' => $delta, 'param' => $field)),
|
| 144 |
'#options' => array(
|
| 145 |
'SMALL_RESULTSET' => t("Small (typically 4 results)"),
|
| 146 |
'LARGE_RESULTSET' => t("Large (typically 8 results)")),
|
| 147 |
'#description' => t('Number of results in each search.'),
|
| 148 |
);
|
| 149 |
//keywords
|
| 150 |
$form[$field = 'keywords'] = array(
|
| 151 |
'#type' => 'textfield',
|
| 152 |
'#title' => t('Default keywords'),
|
| 153 |
'#default_value' => gas_get_settings(array('delta' => $delta, 'param' => $field)),
|
| 154 |
'#description' => t('Default keywords for searcher.'),
|
| 155 |
);
|
| 156 |
//branding
|
| 157 |
$form['branding'] = array(
|
| 158 |
'#type' => 'fieldset',
|
| 159 |
'#title' => t('Branding options'),
|
| 160 |
'#collapsible' => true,
|
| 161 |
'#collapsed' => true,
|
| 162 |
);
|
| 163 |
$form['branding'][$field = 'branding_place'] = array(
|
| 164 |
'#type' => 'textfield',
|
| 165 |
'#title' => t('Branding place'),
|
| 166 |
'#default_value' => gas_get_settings(array('delta' => $delta, 'param' => $field)),
|
| 167 |
'#description' => t('Where the branding should be displayed. Enter fields html ID.'),
|
| 168 |
);
|
| 169 |
$form['branding'][$field = 'branding_orientation'] = array(
|
| 170 |
'#type' => 'select',
|
| 171 |
'#title' => t('Branding orientation'),
|
| 172 |
'#default_value' => gas_get_settings(array('delta' => $delta, 'param' => $field)),
|
| 173 |
'#options' => array(
|
| 174 |
'HORIZONTAL_BRANDING' => t('Horizontal'),
|
| 175 |
'VERTICAL_BRANDING' => t('Vertical')),
|
| 176 |
'#description' => t('Specifies the orientation of the branding node.'),
|
| 177 |
);
|
| 178 |
//advanced
|
| 179 |
$form['results_restriction'] = array(
|
| 180 |
'#type' => 'fieldset',
|
| 181 |
'#title' => t('Advanced'),
|
| 182 |
'#collapsible' => true,
|
| 183 |
'#collapsed' => true,
|
| 184 |
);
|
| 185 |
$form['results_restriction']['web'] = array(
|
| 186 |
'#type' => 'fieldset',
|
| 187 |
'#title' => t('Web searcher'),
|
| 188 |
'#collapsible' => true,
|
| 189 |
'#collapsed' => true,
|
| 190 |
);
|
| 191 |
//web
|
| 192 |
$form['results_restriction']['web'][$field = 'results_web_language_restriction'] = array(
|
| 193 |
'#type' => 'select',
|
| 194 |
'#title' => t('Restrict results to specified language'),
|
| 195 |
'#default_value' => gas_get_settings(array('delta' => $delta, 'param' => $field)),
|
| 196 |
'#options' => gas_get_web_restriction_languages(),
|
| 197 |
'#description' => t('Language to which results will be limited.'),
|
| 198 |
);
|
| 199 |
$form['results_restriction']['web'][$field = 'results_web_duplicate_content_filter'] = array(
|
| 200 |
'#type' => 'select',
|
| 201 |
'#title' => t('Duplicate content filter'),
|
| 202 |
'#default_value' => gas_get_settings(array('delta' => $delta, 'param' => $field)),
|
| 203 |
'#options' => array(
|
| 204 |
0 => t('off'),
|
| 205 |
1 => t('on')),
|
| 206 |
'#description' => t('If turned on, duplicates will not be show.'),
|
| 207 |
);
|
| 208 |
$form['results_restriction']['web'][$field = 'results_web_site_restriction'] = array(
|
| 209 |
'#type' => 'textfield',
|
| 210 |
'#title' => t('Restrict results to page'),
|
| 211 |
'#default_value' => gas_get_settings(array('delta' => $delta, 'param' => $field)),
|
| 212 |
'#description' => t('Site to which the results will be limited, e.g. \'www.meant4.com\''),
|
| 213 |
);
|
| 214 |
//local
|
| 215 |
$form['results_restriction']['local'] = array(
|
| 216 |
'#type' => 'fieldset',
|
| 217 |
'#title' => t('Local searcher'),
|
| 218 |
'#collapsible' => true,
|
| 219 |
'#collapsed' => true,
|
| 220 |
);
|
| 221 |
$form['results_restriction']['local'][$field = 'results_local_restrict_type'] = array(
|
| 222 |
'#type' => 'select',
|
| 223 |
'#title' => t('Result type'),
|
| 224 |
'#default_value' => gas_get_settings(array('delta' => $delta, 'param' => $field)),
|
| 225 |
'#options' => array(
|
| 226 |
'' => '',
|
| 227 |
'TYPE_BLENDED_RESULT' => t('return a mix of both KML results and normal, local listings and geocodes'),
|
| 228 |
'TYPE_KMLONLY_RESULTS' => t('return only KML results and geocode results'),
|
| 229 |
'TYPE_LOCALONLY_RESULTS' => t('return only LOCAL listing results and geocode results')),
|
| 230 |
'#description' => t('Description'),
|
| 231 |
);
|
| 232 |
|
| 233 |
//video - youtube only?
|
| 234 |
$form['results_restriction']['video'] = array(
|
| 235 |
'#type' => 'fieldset',
|
| 236 |
'#title' => t('Video searcher'),
|
| 237 |
'#collapsible' => true,
|
| 238 |
'#collapsed' => true,
|
| 239 |
);
|
| 240 |
$form['results_restriction']['video'][$field = 'results_video_order'] = array(
|
| 241 |
'#type' => 'select',
|
| 242 |
'#title' => t('Results order'),
|
| 243 |
'#default_value' => gas_get_settings(array('delta' => $delta, 'param' => $field)),
|
| 244 |
'#options' => array(
|
| 245 |
'by relevance' => t('by relevance'),
|
| 246 |
'by date' => t('by date')),
|
| 247 |
'#description' => t('Used to change the result order.'),
|
| 248 |
);
|
| 249 |
//blog - not exist
|
| 250 |
$form['results_restriction']['blog'] = array(
|
| 251 |
'#type' => 'fieldset',
|
| 252 |
'#title' => t('Blog searcher'),
|
| 253 |
'#collapsible' => true,
|
| 254 |
'#collapsed' => true,
|
| 255 |
);
|
| 256 |
$form['results_restriction']['blog'][$field = 'blog_site_restriction'] = array(
|
| 257 |
'#type' => 'textfield',
|
| 258 |
'#title' => t('Restrict results to page'),
|
| 259 |
'#default_value' => gas_get_settings(array('delta' => $delta, 'param' => $field)),
|
| 260 |
'#description' => t('Site to which the results will be limited, e.g. \'www.meant4.com\''),
|
| 261 |
);
|
| 262 |
$form['results_restriction']['blog'][$field = 'results_blog_order'] = array(
|
| 263 |
'#type' => 'select',
|
| 264 |
'#title' => t('Results order'),
|
| 265 |
'#default_value' => gas_get_settings(array('delta' => $delta, 'param' => $field)),
|
| 266 |
'#options' => array(
|
| 267 |
t('by relevance'),
|
| 268 |
t('by date')),
|
| 269 |
'#description' => t('Used to change the result order.'),
|
| 270 |
);
|
| 271 |
//news
|
| 272 |
$form['results_restriction']['news'] = array(
|
| 273 |
'#type' => 'fieldset',
|
| 274 |
'#title' => t('News searcher'),
|
| 275 |
'#collapsible' => true,
|
| 276 |
'#collapsed' => true,
|
| 277 |
);
|
| 278 |
$form['results_restriction']['news'][$field = 'results_news_restrict_topic'] = array(
|
| 279 |
'#type' => 'select',
|
| 280 |
'#title' => t('Search particular topic'),
|
| 281 |
'#default_value' => gas_get_settings(array('delta' => $delta, 'param' => $field)),
|
| 282 |
'#options' => array(
|
| 283 |
'' => t(''),
|
| 284 |
'h' => t('top headlines topic'),
|
| 285 |
'w' => t('world topic'),
|
| 286 |
'b' => t('business'),
|
| 287 |
'n' => t('nation topic'),
|
| 288 |
't' => t('science and technology topic'),
|
| 289 |
'el' => t('elections topic'),
|
| 290 |
'p' => t('politics topic'),
|
| 291 |
'e' => t('entertainment topic'),
|
| 292 |
's' => t('sports topic'),
|
| 293 |
'm' => t('health topic')),
|
| 294 |
'#description' => t('Restricts news search results to news of particular topic.'),
|
| 295 |
);
|
| 296 |
$form['results_restriction']['news'][$field = 'results_news_site_restriction'] = array(
|
| 297 |
'#type' => 'textfield',
|
| 298 |
'#title' => t('Restrict results to page'),
|
| 299 |
'#default_value' => gas_get_settings(array('delta' => $delta, 'param' => $field)),
|
| 300 |
'#description' => t('Site to which the results will be limited, e.g. \'www.meant4.com\''),
|
| 301 |
);
|
| 302 |
$form['results_restriction']['news'][$field = 'results_news_order'] = array(
|
| 303 |
'#type' => 'select',
|
| 304 |
'#title' => t('Results order'),
|
| 305 |
'#default_value' => gas_get_settings(array('delta' => $delta, 'param' => $field)),
|
| 306 |
'#options' => array(
|
| 307 |
t('by relevance'),
|
| 308 |
t('by date')),
|
| 309 |
'#description' => t('Used to change the result order.'),
|
| 310 |
);
|
| 311 |
//book
|
| 312 |
$form['results_restriction']['book'] = array(
|
| 313 |
'#type' => 'fieldset',
|
| 314 |
'#title' => t('Book searcher'),
|
| 315 |
'#collapsible' => true,
|
| 316 |
'#collapsed' => true,
|
| 317 |
);
|
| 318 |
$form['results_restriction']['book'][$field = 'results_book_restrict_type'] = array(
|
| 319 |
'#type' => 'select',
|
| 320 |
'#title' => t('Search particular type of books'),
|
| 321 |
'#default_value' => gas_get_settings(array('delta' => $delta, 'param' => $field)),
|
| 322 |
'#options' => array(
|
| 323 |
'TYPE_FULL_VIEW_BOOKS' => t('Full view books'),
|
| 324 |
'TYPE_ALL_BOOKS' => t('All books')),
|
| 325 |
'#description' => t('Description'),
|
| 326 |
);
|
| 327 |
|
| 328 |
//image
|
| 329 |
$form['results_restriction']['image'] = array(
|
| 330 |
'#type' => 'fieldset',
|
| 331 |
'#title' => t('Image searcher'),
|
| 332 |
'#collapsible' => true,
|
| 333 |
'#collapsed' => true,
|
| 334 |
);
|
| 335 |
$form['results_restriction']['image'][$field = 'results_image_restrict_safesearch'] = array(
|
| 336 |
'#type' => 'select',
|
| 337 |
'#title' => t('Safesearch filter'),
|
| 338 |
'#default_value' => gas_get_settings(array('delta' => $delta, 'param' => $field)),
|
| 339 |
'#options' => array(
|
| 340 |
'SAFESEARCH_STRICT' => t('apply strict filtering for both explicit text and explicit images'),
|
| 341 |
'SAFESEARCH_MODERATE' => t('apply filtering for explicit images'),
|
| 342 |
'SAFESEARCH_OFF' => t('do not apply safe search filtering')),
|
| 343 |
'#description' => t('Restricts image search results to images based on the safesearch value.'),
|
| 344 |
);
|
| 345 |
$form['results_restriction']['image'][$field = 'results_image_restrict_imagesize'] = array(
|
| 346 |
'#type' => 'select',
|
| 347 |
'#title' => t('Image size'),
|
| 348 |
'#default_value' => gas_get_settings(array('delta' => $delta, 'param' => $field)),
|
| 349 |
'#options' => array(
|
| 350 |
'' => t('do not restrict size images'),
|
| 351 |
'IMAGESIZE_SMALL' => t('restrict to small images, icons'),
|
| 352 |
'IMAGESIZE_MEDIUM' => t('restrict to medium images'),
|
| 353 |
'IMAGESIZE_LARGE' => t('restrict to large images'),
|
| 354 |
'IMAGESIZE_EXTRA_LARGE' => t('restrict to extra large images')),
|
| 355 |
'#description' => t('Restricts image search results to images with certain pixel dimensions.'),
|
| 356 |
);
|
| 357 |
$form['results_restriction']['image'][$field = 'results_image_restrict_colorization'] = array(
|
| 358 |
'#type' => 'select',
|
| 359 |
'#title' => t('Image colorization'),
|
| 360 |
'#default_value' => gas_get_settings(array('delta' => $delta, 'param' => $field)),
|
| 361 |
'#options' => array(
|
| 362 |
'' => t('do not restrict images colorization'),
|
| 363 |
'COLORIZATION_GRAYSCALE' => t('restrict to grayscale images'),
|
| 364 |
'COLORIZATION_COLOR' => t('restrict to color images')),
|
| 365 |
'#description' => t('Restricts image search results to images with certain colorization.'),
|
| 366 |
);
|
| 367 |
$form['results_restriction']['image'][$field = 'results_image_restrict_colorfilter'] = array(
|
| 368 |
'#type' => 'select',
|
| 369 |
'#title' => t('Filter images by the selected color'),
|
| 370 |
'#default_value' => gas_get_settings(array('delta' => $delta, 'param' => $field)),
|
| 371 |
'#options' => array(
|
| 372 |
'' => t('do not filter images by color'),
|
| 373 |
'COLOR_BLACK' => t('BLACK'),
|
| 374 |
'COLOR_BLUE' => t('BLUE'),
|
| 375 |
'COLOR_BROWN' => t('BROWN'),
|
| 376 |
'COLOR_GRAY' => t('GRAY'),
|
| 377 |
'COLOR_GREEN' => t('GREEN'),
|
| 378 |
'COLOR_ORANGE' => t('ORANGE'),
|
| 379 |
'COLOR_PINK' => t('PINK'),
|
| 380 |
'COLOR_PURPLE' => t('PURPLE'),
|
| 381 |
'COLOR_RED' => t('RED'),
|
| 382 |
'COLOR_TEAL' => t('TEAL'),
|
| 383 |
'COLOR_WHITE' => t('WHITE'),
|
| 384 |
'COLOR_YELLOW' => t('YELLOW')),
|
| 385 |
'#description' => t('Image search results will be filtered based on the selected color.'),
|
| 386 |
);
|
| 387 |
$form['results_restriction']['image'][$field = 'results_image_restrict_filetype'] = array(
|
| 388 |
'#type' => 'select',
|
| 389 |
'#title' => t('Image file type'),
|
| 390 |
'#default_value' => gas_get_settings(array('delta' => $delta, 'param' => $field)),
|
| 391 |
'#options' => array(
|
| 392 |
'' => t('do not restrict images file type'),
|
| 393 |
'FILETYPE_JPG' => t('restrict to only jpeg images'),
|
| 394 |
'FILETYPE_PNG' => t('restrict to only png images'),
|
| 395 |
'FILETYPE_GIF' => t('restrict to only gif images'),
|
| 396 |
'FILETYPE_BMP' => t('restrict to only bmp images')),
|
| 397 |
'#description' => t('Restricts image search results to images only of a certain filetype, e.g. JPG.'),
|
| 398 |
);
|
| 399 |
$form['results_restriction']['image'][$field = 'results_image_restrict_imagetype'] = array(
|
| 400 |
'#type' => 'select',
|
| 401 |
'#title' => t('Image type'),
|
| 402 |
'#default_value' => gas_get_settings(array('delta' => $delta, 'param' => $field)),
|
| 403 |
'#options' => array(
|
| 404 |
'' => t('do not restrict images type'),
|
| 405 |
'IMAGETYPE_FACES' => t('restrict to images with faces in them'),
|
| 406 |
'IMAGETYPE_PHOTO' => t('restrict to photos'),
|
| 407 |
'IMAGETYPE_CLIPART' => t('restrict to clipart images'),
|
| 408 |
'IMAGETYPE_LINEART' => t('restrict to images of line drawings')),
|
| 409 |
'#description' => t('Restricts image search results to images of certain type'),
|
| 410 |
);
|
| 411 |
$form['results_restriction']['image'][$field = 'results_image_site_restriction'] = array(
|
| 412 |
'#type' => 'textfield',
|
| 413 |
'#title' => t('Restrict results to page'),
|
| 414 |
'#default_value' => gas_get_settings(array('delta' => $delta, 'param' => $field)),
|
| 415 |
'#description' => t('Site to which the results will be limited, e.g. \'www.meant4.com\''),
|
| 416 |
);
|
| 417 |
|
| 418 |
//patent
|
| 419 |
$form['results_restriction']['patent'] = array(
|
| 420 |
'#type' => 'fieldset',
|
| 421 |
'#title' => t('Patent searcher'),
|
| 422 |
'#collapsible' => true,
|
| 423 |
'#collapsed' => true,
|
| 424 |
);
|
| 425 |
$form['results_restriction']['patent'][$field = 'results_patent_restrict_type'] = array(
|
| 426 |
'#type' => 'select',
|
| 427 |
'#title' => t('Restrict type of patents to'),
|
| 428 |
'#default_value' => gas_get_settings(array('delta' => $delta, 'param' => $field)),
|
| 429 |
'#options' => array(
|
| 430 |
'TYPE_ISSUED_PATENTS' => t('patents that have been issued'),
|
| 431 |
'TYPE_APPLICATIONS' => t('patents that have been filled but not yet issued'),
|
| 432 |
'TYPE_ANY_STATUS' => t('all patents')),
|
| 433 |
'#description' => t('Description'),
|
| 434 |
);
|
| 435 |
$form['results_restriction']['patent'][$field = 'results_patent_order'] = array(
|
| 436 |
'#type' => 'select',
|
| 437 |
'#title' => t('Results order'),
|
| 438 |
'#default_value' => gas_get_settings(array('delta' => $delta, 'param' => $field)),
|
| 439 |
'#options' => array(
|
| 440 |
t('by relevance'),
|
| 441 |
t('by date')),
|
| 442 |
'#description' => t('Used to change the result order.'),
|
| 443 |
);
|
| 444 |
|
| 445 |
$plugins = gas_get_plugins();
|
| 446 |
|
| 447 |
if (!empty($plugins)) {
|
| 448 |
$form['plugins'] = array(
|
| 449 |
'#type' => 'fieldset',
|
| 450 |
'#title' => t('Plugins'),
|
| 451 |
'#collapsible' => TRUE,
|
| 452 |
'#collapsed' => TRUE,
|
| 453 |
);
|
| 454 |
|
| 455 |
foreach ($plugins as $name => $plugin) {
|
| 456 |
$settings_form = $plugin['settings_form'];
|
| 457 |
$form['plugins'][$name] = array(
|
| 458 |
'#type' => 'fieldset',
|
| 459 |
'#title' => t($plugin['title']),
|
| 460 |
'#collapsible' => TRUE,
|
| 461 |
'#collapsed' => TRUE,
|
| 462 |
);
|
| 463 |
$form['plugins'][$name][$field = $name . "_status"] = array(
|
| 464 |
'#type' => 'checkbox',
|
| 465 |
'#title' => t('Enabled'),
|
| 466 |
'#default_value' => $settings['gas'][$delta][$field] ? $settings['gas'][$delta][$field] : GAS_PLUGIN_STATUS_DEFAULT,
|
| 467 |
);
|
| 468 |
|
| 469 |
$form['plugins'][$name] += plugin_func_safe($settings_form, $settings['gas'][$delta]);
|
| 470 |
}
|
| 471 |
}
|
| 472 |
|
| 473 |
return $form;
|
| 474 |
}
|
| 475 |
|
| 476 |
/**
|
| 477 |
* Saves all settings from $edit for block $delta.
|
| 478 |
*
|
| 479 |
* @param mixed $delta
|
| 480 |
* selects as which block settings, settings will be saved
|
| 481 |
* @param mixed $edit
|
| 482 |
* array with settings to save (from hook_block)
|
| 483 |
* @return
|
| 484 |
* array with settings for block $delta.
|
| 485 |
*/
|
| 486 |
function gas_set_settings($delta, $edit) {
|
| 487 |
$settings = gas_get_settings();
|
| 488 |
$settings['gas'][$delta] = $edit;
|
| 489 |
variable_set('googleajaxsearch', $settings);
|
| 490 |
|
| 491 |
return $settings;
|
| 492 |
}
|
| 493 |
|
| 494 |
/**
|
| 495 |
* Return settings for block $delta.
|
| 496 |
*
|
| 497 |
* Example usage:
|
| 498 |
* @code
|
| 499 |
* $all = gas_get_settings();
|
| 500 |
* $block = gas_get_settings(array('delta' => 1));
|
| 501 |
* $value = gas_get_settings(array('delta' => 2, 'param' => 'search_options'));
|
| 502 |
* @endcode
|
| 503 |
*
|
| 504 |
* @param mixed $arguments
|
| 505 |
* array with optional keys delta and param
|
| 506 |
* @return
|
| 507 |
* array with settings for all blocks if $arguments is empty,
|
| 508 |
* or settings for block $delta if $arguments has a key 'delta', with numeric value,
|
| 509 |
* or value for $parameter if 'delta' and 'param' is given.
|
| 510 |
*/
|
| 511 |
function gas_get_settings($arguments = array()) {
|
| 512 |
$default = "";
|
| 513 |
$block_count = variable_get('block_count', GAS_BLOCKS_NUMBER_DEFAULT);
|
| 514 |
|
| 515 |
for ($i = 0; $i < $block_count; $i++) {
|
| 516 |
$default = array('gas' => array($i => gas_default_settings()));
|
| 517 |
}
|
| 518 |
$settings = variable_get('googleajaxsearch', $default);
|
| 519 |
|
| 520 |
if (!empty($arguments)) {
|
| 521 |
if (array_key_exists('delta', $arguments)) {
|
| 522 |
$delta = $arguments['delta'];
|
| 523 |
|
| 524 |
if (is_numeric($delta) && !array_key_exists($delta, $settings['gas'])) {
|
| 525 |
$settings = gas_set_settings($delta, gas_default_settings());
|
| 526 |
}
|
| 527 |
|
| 528 |
$settings = $settings['gas'][$delta];
|
| 529 |
|
| 530 |
if (array_key_exists('param', $arguments)) {
|
| 531 |
$param = $arguments['param'];
|
| 532 |
$settings = $settings[$param];
|
| 533 |
}
|
| 534 |
}
|
| 535 |
}
|
| 536 |
|
| 537 |
return $settings;
|
| 538 |
}
|
| 539 |
|
| 540 |
/**
|
| 541 |
* Returns module settings
|
| 542 |
*
|
| 543 |
* @return array with module settings.
|
| 544 |
*/
|
| 545 |
function gas_get_module_settings() {
|
| 546 |
$settings['gas']['block_count'] = variable_get('block_count', GAS_BLOCKS_NUMBER_DEFAULT);
|
| 547 |
$settings['gas']['api_key'] = variable_get('api_key', GAS_API_KEY_DEFAULT);
|
| 548 |
return $settings;
|
| 549 |
}
|
| 550 |
|
| 551 |
/**
|
| 552 |
* Adds Google Ajax Search API to html header. Without that no searcher will be loaded.
|
| 553 |
*/
|
| 554 |
function gas_add_api() {
|
| 555 |
// Add only one jsapi.
|
| 556 |
static $added = false;
|
| 557 |
|
| 558 |
$api_key = variable_get('gas_api_key', GAS_API_KEY_DEFAULT);
|
| 559 |
$api_key ? $api_key = "?key=$api_key" : '';
|
| 560 |
|
| 561 |
if($added == false) {
|
| 562 |
drupal_set_html_head('<script src="'. check_url(url('http://www.google.com/jsapi')).$api_key.'" type="text/javascript"></script>');
|
| 563 |
$added = true;
|
| 564 |
}
|
| 565 |
}
|
| 566 |
|
| 567 |
/**
|
| 568 |
* Adds block and module settings to drupal settings. This lets the javascript load aproppriate options during embeding searcher.
|
| 569 |
*
|
| 570 |
* @param mixed $delta
|
| 571 |
* selects for which block, the settings are adding now
|
| 572 |
*/
|
| 573 |
function gas_add_settings($delta) {
|
| 574 |
$settings = gas_get_settings();
|
| 575 |
|
| 576 |
static $added = false;
|
| 577 |
if(!$added) {
|
| 578 |
$settings['gas']['block_count'] = variable_get('block_count', GAS_BLOCKS_NUMBER_DEFAULT);
|
| 579 |
$added = true;
|
| 580 |
}
|
| 581 |
|
| 582 |
foreach ($settings['gas'] as $key => $value) {
|
| 583 |
$settings['gas']['api_key'] = variable_get('api_key', GAS_API_KEY_DEFAULT);
|
| 584 |
$settings['gas']['current_block'] = $delta;
|
| 585 |
$settings['gas'][$key]['keywords'] = gas_get_plugin_keywords($key);
|
| 586 |
}
|
| 587 |
drupal_add_js($settings, 'setting');
|
| 588 |
}
|
| 589 |
|
| 590 |
/**
|
| 591 |
* Adds module javascript to html header.
|
| 592 |
*/
|
| 593 |
function gas_add_scripts() {
|
| 594 |
drupal_add_js(drupal_get_path('module', 'googleajaxsearch') . '/googleajaxsearch.js');
|
| 595 |
}
|
| 596 |
|
| 597 |
/**
|
| 598 |
* Returns array with languages from Google Ajax Search - WebSearcher. Used in block settings form to give aproppriate aptions.
|
| 599 |
*/
|
| 600 |
function gas_get_web_restriction_languages() {
|
| 601 |
return array(
|
| 602 |
'0' => '',
|
| 603 |
'lang_ar' => t('Arabic'),
|
| 604 |
'lang_bg' => t('Bulgarian'),
|
| 605 |
'lang_ca' => t('Catalan'),
|
| 606 |
'lang_zh-CN' => t('Chinese (Simplified)'),
|
| 607 |
'lang_zh-TW' => t('Chinese (Traditional)'),
|
| 608 |
'lang_hr' => t('Croation'),
|
| 609 |
'lang_cs' => t('Czech'),
|
| 610 |
'lang_da' => t('Danish'),
|
| 611 |
'lang_nl' => t('Dutch'),
|
| 612 |
'lang_en' => t('English'),
|
| 613 |
'lang_et' => t('Estonian'),
|
| 614 |
'lang_fi' => t('Finnish'),
|
| 615 |
'lang_fr' => t('French'),
|
| 616 |
'lang_de' => t('German'),
|
| 617 |
'lang_el' => t('Greek'),
|
| 618 |
'lang_iw' => t('Hebrew'),
|
| 619 |
'lang_hu' => t('Hungarian'),
|
| 620 |
'lang_is' => t('Icelandic'),
|
| 621 |
'lang_id' => t('Indonesian'),
|
| 622 |
'lang_it' => t('Italian'),
|
| 623 |
'lang_ja' => t('Japanese'),
|
| 624 |
'lang_ko' => t('Korean'),
|
| 625 |
'lang_lv' => t('Latvian'),
|
| 626 |
'lang_lt' => t('Lithuanian'),
|
| 627 |
'lang_no' => t('Norwegian'),
|
| 628 |
'lang_pl' => t('Polish'),
|
| 629 |
'lang_pt' => t('Portuguese'),
|
| 630 |
'lang_ro' => t('Romanian'),
|
| 631 |
'lang_ru' => t('Russian'),
|
| 632 |
'lang_sr' => t('Serbian'),
|
| 633 |
'lang_sk' => t('Slovak'),
|
| 634 |
'lang_sl' => t('Slovenian'),
|
| 635 |
'lang_es' => t('Spanish'),
|
| 636 |
'lang_sv' => t('Swedish'),
|
| 637 |
'lang_tr' => t('Turkish'),
|
| 638 |
);
|
| 639 |
}
|
| 640 |
|
| 641 |
/**
|
| 642 |
* Returns all keywords processed by enabled plugins for block $delta.
|
| 643 |
*
|
| 644 |
* Example usage:
|
| 645 |
* @code
|
| 646 |
* $keywords = gas_get_plugin_keywords(1);
|
| 647 |
* @endcode
|
| 648 |
*
|
| 649 |
* @param mixed $delta
|
| 650 |
* selects block which keywords should be returned.
|
| 651 |
* @return
|
| 652 |
* string with keywords
|
| 653 |
*/
|
| 654 |
function gas_get_plugin_keywords($delta) {
|
| 655 |
$plugins = gas_get_plugins();
|
| 656 |
$settings = gas_get_settings(array('delta' => $delta));
|
| 657 |
$keywords = '';
|
| 658 |
|
| 659 |
foreach ($plugins as $key => $plugin) {
|
| 660 |
if ($settings[$key . '_status'] == 1) {
|
| 661 |
$keywords[] = plugin_func_safe($plugin['execute'], $settings);
|
| 662 |
}
|
| 663 |
}
|
| 664 |
// AND is being used to concatenate different plugin keywords, not separate keywords at all!
|
| 665 |
if (is_array($keywords) && !empty($keywords)) {
|
| 666 |
$keywords = implode(' AND ',$keywords);
|
| 667 |
}
|
| 668 |
|
| 669 |
return $keywords;
|
| 670 |
}
|
| 671 |
|
| 672 |
/**
|
| 673 |
* Safely calls function $function using $delta as argument. If calling function isn't exists it does nothing.
|
| 674 |
*
|
| 675 |
* Example usage:
|
| 676 |
* @code
|
| 677 |
* $result = plugin_func_safe('example_function_name', 1);
|
| 678 |
* @endcode
|
| 679 |
*
|
| 680 |
* @param mixed $function function name needed to call
|
| 681 |
* @param mixed $delta argument for function.
|
| 682 |
*/
|
| 683 |
function plugin_func_safe($function, $delta) {
|
| 684 |
if (function_exists($function)) {
|
| 685 |
return call_user_func($function, $delta);
|
| 686 |
}
|
| 687 |
}
|
| 688 |
|
| 689 |
/**
|
| 690 |
* Invokes all hook_googleajaxsearch_info() functions.
|
| 691 |
*/
|
| 692 |
function gas_get_plugins() {
|
| 693 |
return module_invoke_all('googleajaxsearch_info');
|
| 694 |
}
|