# HG changeset patch # User Dan # Date 1229919015 18000 # Node ID 4d19ad17b07cae13927f51966bb5e9a651c85a5c First revision, seems working. Yes, using a className of "autofill floodlight" will give your theme/whatever support for this plugin. diff -r 000000000000 -r 4d19ad17b07c Floodlight.php --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Floodlight.php Sun Dec 21 23:10:15 2008 -0500 @@ -0,0 +1,177 @@ +attachHook('sidebar_fetch_return', 'floodlight_inject_searchflags($return);'); +$plugins->attachHook('autofill_json_request', 'floodlight_perform_search($dataset);'); +$plugins->attachHook('session_started', 'floodlight_add_js_page();'); +$plugins->attachHook('common_post', 'floodlight_intercept_search();'); +$plugins->attachHook('compile_template', 'floodlight_add_js();'); + +function floodlight_inject_searchflags(&$return) +{ + if ( strstr($return[0], ' 5 ) + { + $results = array_slice($results, 0, 5); + } + foreach ( $results as $result ) + { + $dataset[] = array( + 0 => "go:{$paths->nslist[$result['namespace']]}{$result['page_id']}", + 'title' => str_replace(array('', ''), array('', ''), $result['page_name']), + 'score' => $result['score'], + 'type' => $result['page_note'], + 'size' => $result['page_length'], + ); + } + } +} + +function floodlight_add_js_page() +{ + global $db, $session, $paths, $template, $plugins; // Common objects + $paths->add_page(array( + 'name' => 'Floodlight Javascript', + 'urlname' => 'FloodlightJS', + 'namespace' => 'Special', + 'visible' => 0, + 'protected' => 0, + 'comments_on' => 0, + 'special' => 0 + )); +} + +function floodlight_intercept_search() +{ + global $db, $session, $paths, $template, $plugins; // Common objects + if ( $paths->page_id == 'Search' && $paths->namespace == 'Special' ) + { + if ( isset($_GET['q']) && preg_match('/^go:/', $_GET['q']) ) + { + redirect(makeUrl(preg_replace('/^go:/', '', $_GET['q'])), '', '', 0); + } + } +} + +function floodlight_add_js() +{ + global $db, $session, $paths, $template, $plugins; // Common objects + $template->add_header(''); +} + +function page_Special_FloodlightJS() +{ + global $db, $session, $paths, $template, $plugins; // Common objects + header('Content-type: text/javascript'); + header('ETag: ' . sha1(__FILE__)); + + global $aggressive_optimize_html; + $aggressive_optimize_html = false; + + echo << ' + type + ''; + html += '
' + \$lang.get('floodlight_lbl_score') + row.score + '% | ' + row.size + ''; + return html; + }, + tableHeader: '' + \$lang.get('floodlight_table_heading') + '', + showWhenNoResults: true, + onItemSelect: function(li) + { + window.location = makeUrl(li.selectValue.replace(/^go:/, '')); + }, + width: 300, + noResultsHTML: '' + \$lang.get('floodlight_msg_no_results') + '', + }); + } + }; +}); +EOF; +} + +/**!language** + +The following text up to the closing comment tag is JSON language data. +It is not PHP code but your editor or IDE may highlight it as such. This +data is imported when the plugin is loaded for the first time; it provides +the strings displayed by this plugin's interface. + +You should copy and paste this block when you create your own plugins so +that these comments and the basic structure of the language data is +preserved. All language data is in the same format as the Enano core +language files in the /language/* directories. See the Enano Localization +Guide and Enano API Documentation for further information on the format of +language files. + +The exception in plugin language file format is that multiple languages +may be specified in the language block. This should be done by way of making +the top-level elements each a JSON language object, with elements named +according to the ISO-639-1 language they are representing. The path should be: + + root => language ID => categories array, ( strings object => category \ + objects => strings ) + +All text leading up to first curly brace is stripped by the parser; using +a code tag makes jEdit and other editors do automatic indentation and +syntax highlighting on the language data. The use of the code tag is not +necessary; it is only included as a tool for development. + + +{ + // english + eng: { + categories: [ 'meta', 'floodlight' ], + strings: { + meta: { + floodlight: 'Floodlight plugin' + }, + floodlight: { + table_heading: 'Search results', + msg_no_results: 'No results', + lbl_score: 'Relevance: ', + } + } + } +} + +**!*/