1: <?php
2: 3: 4: 5: 6: 7: 8: 9:
10: $plugin_is_filter = 9 | THEME_PLUGIN;
11: $plugin_description = gettext("Enables jQuery tag suggestions on the search field.");
12: $plugin_author = "Malte Müller (acrylian), Stephen Billard (sbillard)";
13: $option_interface = 'tagsuggest';
14: zp_register_filter('theme_head', 'tagSuggestJS_frontend');
15: zp_register_filter('admin_head', 'tagSuggestJS_admin');
16:
17: class tagsuggest {
18:
19: function __construct() {
20: setOptionDefault('tagsuggest_excludeunassigned', 1);
21: setOptionDefault('tagsuggest_checkaccess', 0);
22: }
23:
24: function getOptionsSupported() {
25: $options = array(
26: gettext('Exclude unassigned')
27: => array(
28: 'key' => 'tagsuggest_excludeunassigned',
29: 'type' => OPTION_TYPE_CHECKBOX,
30: 'desc' => gettext("Check if you wish to exclude tags are not assigned to any item.")),
31: gettext('Check tag access')
32: => array(
33: 'key' => 'tagsuggest_checkaccess',
34: 'type' => OPTION_TYPE_CHECKBOX,
35: 'desc' => gettext("Check if you wish to exclude tags that are assigned to items (or are not assigned at all) the visitor is not allowed to see. This overrides the exlude unassigned option. <p class='notebox'><strong>Note:</strong> Beware that this may cause overhead on larger sites. The usage of the static_html_cache plugin is recommended.</p>"))
36: );
37: return $options;
38: }
39: }
40:
41: function tagSuggestJS_admin() {
42: tagSuggestJS(false);
43: }
44:
45: function tagSuggestJS_frontend() {
46: $exclude_unassigned = getOption('tagsuggest_excludeunassigned');
47: $checkaccess = getOption('tagsuggest_checkaccess');
48: tagSuggestJS($exclude_unassigned,$checkaccess);
49: }
50:
51: function tagSuggestJS($exclude_unassigned = false, $checkaccess = false) {
52:
53: ?>
54: <script type="text/javascript" src="<?php echo WEBPATH . '/' . ZENFOLDER; ?>/js/encoder.js"></script>
55: <script type="text/javascript" src="<?php echo WEBPATH . '/' . ZENFOLDER; ?>/js/tag.js"></script>
56: <?php
57: $css = getPlugin('tag_suggest/tag.css', true, true);
58: ?>
59: <link type="text/css" rel="stylesheet" href="<?php echo pathurlencode($css); ?>" />
60: <?php
61: if ($checkaccess) {
62: $taglist = getAllTagsUnique(true);
63: } else {
64: if ($exclude_unassigned) {
65: $taglist = getAllTagsCount(true);
66: $taglist = array_keys($taglist);
67: } else {
68: $taglist = getAllTagsUnique(false);
69: }
70: }
71: $c = 0;
72: $list = '';
73: foreach ($taglist AS $tag) {
74: if ($c > 0)
75: $list .= ',';
76: $c++;
77: $list .= '"' . addslashes($tag) . '"';
78: }
79: if (OFFSET_PATH || getOption('search_space_is') == 'OR') {
80: $tagseparator = ' ';
81: } else {
82: $tagseparator = ',';
83: }
84: ?>
85: <script type="text/javascript">
86:
87: var _tagList = [<?php echo $list; ?>];
88: $(function() {
89: $('#search_input, #edit-editable_4, .tagsuggest').tagSuggest({separator: '<?php echo $tagseparator; ?>', tags: _tagList})
90: });
91:
92: </script>
93: <?php
94: }
95: ?>