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