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