[22201] | 1 | <?php /* |
---|
| 2 | Plugin Name: RV autocomplete |
---|
[22214] | 3 | Version: 0.beta |
---|
[22201] | 4 | Description: Autocompletes the quick search with albums, tags or custom suggestions |
---|
[22214] | 5 | Plugin URI: http://piwigo.org/ext/extension_view.php?eid=694 |
---|
[22201] | 6 | Author: rvelices |
---|
| 7 | Author URI: http://www.modusoptimus.com/ |
---|
| 8 | */ |
---|
| 9 | defined('PHPWG_ROOT_PATH') or die('Hacking attempt!'); |
---|
| 10 | |
---|
| 11 | define('RVAC_ID', $plugin['id']); |
---|
| 12 | |
---|
| 13 | global $prefixeTable; |
---|
| 14 | define('RVAC_SUGGESTIONS', $prefixeTable.'suggestions'); |
---|
[22375] | 15 | define('RVAC_DIR' , basename(dirname(__FILE__))); |
---|
| 16 | define('RVAC_PATH' , PHPWG_PLUGINS_PATH . RVAC_DIR . '/'); |
---|
[22201] | 17 | |
---|
| 18 | function rvac_get_data_file() { |
---|
[22214] | 19 | global $user,$conf; |
---|
| 20 | $f = PWG_COMBINED_DIR.'acds-'; |
---|
| 21 | $f .= $conf['rvac_version']; |
---|
| 22 | $keys = array( $user['language'], $user['nb_total_images'], $user['level'], strlen($user['forbidden_categories']) ); |
---|
| 23 | $f .= '-'.base_convert(crc32( implode('-', $keys ) ), 10, 36); |
---|
| 24 | $f .= '.js'; |
---|
| 25 | return $f; |
---|
[22201] | 26 | } |
---|
| 27 | |
---|
| 28 | add_event_handler('get_admin_plugin_menu_links', function ($menu) { |
---|
| 29 | $menu[] = array( |
---|
| 30 | 'NAME' => 'Autocomplete', |
---|
| 31 | 'URL' => 'admin.php?page=plugin-'.RVAC_ID |
---|
| 32 | ); |
---|
| 33 | return $menu; |
---|
| 34 | } |
---|
| 35 | ); |
---|
| 36 | |
---|
| 37 | add_event_handler('ws_add_methods', function($srv_arr) { |
---|
| 38 | include_once( 'admin/functions.inc.php' ); |
---|
| 39 | rvac_ws_add_methods($srv_arr); |
---|
| 40 | }); |
---|
| 41 | |
---|
| 42 | |
---|
| 43 | add_event_handler('blockmanager_apply', function($mb_arr) { |
---|
| 44 | if ($mb_arr[0]->get_id() != 'menubar' ) |
---|
| 45 | return; |
---|
[22214] | 46 | |
---|
[22201] | 47 | global $template; |
---|
| 48 | |
---|
[22246] | 49 | $plug_root = get_root_url().'plugins/'.RVAC_ID.'/'; |
---|
| 50 | $core_src = $plug_root.'res/suggest-core.js'; |
---|
[22201] | 51 | |
---|
| 52 | $data_src = rvac_get_data_file(); |
---|
| 53 | if (file_exists(PHPWG_ROOT_PATH.$data_src)) |
---|
| 54 | $data_src = get_root_url().$data_src; |
---|
| 55 | else |
---|
[22246] | 56 | $data_src = $plug_root.'suggestions.php'; |
---|
[22201] | 57 | |
---|
[22246] | 58 | $fs = 'var RVAC={root:"'.$plug_root.'"}; |
---|
[22201] | 59 | $("#qsearchInput").one("focus", function() { |
---|
| 60 | var s; |
---|
| 61 | '; |
---|
| 62 | foreach (array($data_src,$core_src) as $src) |
---|
| 63 | $fs .='s=document.createElement("script");s.type="text/javascript";s.async=true;s.src="'.$src.'";document.body.appendChild(s); |
---|
| 64 | '; |
---|
| 65 | |
---|
| 66 | $css_src = get_root_url().'plugins/'.RVAC_ID.'/res/dark-hive/custom.min.css'; |
---|
| 67 | $fs .= 's="'.$css_src.'"; |
---|
| 68 | if (document.createStyleSheet) document.createStyleSheet(s); else $("head").append($("<link rel=\'stylesheet\' href=\'"+s+"\' type=\'text/css\'>"));'; |
---|
| 69 | $fs .= ' |
---|
| 70 | });'; |
---|
| 71 | $template->block_footer_script( array(), $fs); |
---|
| 72 | $template->func_combine_script( array('id'=>'jquery','load'=>'footer')); |
---|
| 73 | } |
---|
| 74 | ); |
---|
| 75 | ?> |
---|