-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtaxonomy.php
150 lines (141 loc) · 5.45 KB
/
taxonomy.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
<?php
// Taxonomy
require_once('functions.php');
if(empty($_GET['tax'])){
echo "<p>Taxonomy not specified.</p>";
return;
}
if(empty($_POST['host']) || empty($_POST['host']) || empty($_POST['host'])){
echo "<p>Blog Credentials not specified.</p>";
return;
}
$tax_type = $_GET['tax'];
$host = xmlrpc_host_script($_POST['host']);
$user = $_POST['user'];
$pass = $_POST['pass'];
switch($tax_type){
case 'tag':
$tax_request = 'wp.getTags';
$para_id = 'tagcloud-post_tag';
$para_class = 'the-tagcloud';
$anchor_class = 'tag-link';
$returnIDKey = 'tag_id';
$returnNameKey = 'name';
$jvariable = 'posttags';
$input_id = 'newtag';
$tax_name = 'Tags';
break;
case 'cat':
$tax_request = 'wp.getCategories';
$para_id = 'catlist-post_cat';
$para_class = 'the-catlist';
$anchor_class = 'cat-link';
$returnIDKey = 'categoryId';
$returnNameKey = 'categoryName';
$jvariable = 'postcats';
$input_id = 'newcat';
$tax_name = 'Categories';
break;
}
$rpcTaxArry = array();
xmlrpc_request(
$host,
$user,
$pass,
$tax_request,
0,
array(),
$rpcTaxArry
);
//var_dump($rpcTaxArry);
$taxList = array();
$taxListHTML = "<p id=\"$para_id\" class=\"$para_class\">\n";
if (!empty($rpcTaxArry)){
foreach($rpcTaxArry[0] as $taxArry){
$taxListHTML .="<a href=\"#\" class=\"$anchor_class-" . $taxArry[$returnIDKey] . "\" title=\"" . $taxArry[$returnNameKey] . " Posts\" style=\"font-size: " . (($tax_type == 'tag') ? (8 + min(intval($taxArry['count']), 20)) : "12") . "pt;\">" . $taxArry[$returnNameKey] . "</a>\n";
$taxList[] = $taxArry[$returnNameKey];
}
}
$taxListHTML .= "</p>\n";
?>
<script type="text/javascript">
$(function(){
$('.<?php echo $para_class; ?> A').click(function(e){
e.preventDefault();
var taxName = $(this).text();
var current_value = $("#<?php echo $input_id; ?>").val();
$("#<?php echo $input_id; ?>").val(current_value + ((current_value.lastIndexOf(",") >= ((current_value.length - 2))) ? "" : (", ")) + taxName + ", ");
$("#<?php echo $input_id; ?>").trigger("change");
return false;
});
$(".<?php echo $tax_type; ?>checklist").hide();
$("#existing_<?php echo $tax_type; ?>s").click(function(e){
e.preventDefault();
$(".<?php echo $tax_type; ?>checklist").toggle();
return false;
});
<?php echo "var availableTerms = [\"" . implode('","', $taxList) . "\"];\n"; ?>
function split( val ) {
return val.split( /,\s*/ );
}
function extractLast( term ) {
return split( term ).pop();
}
$( "#<?php echo $input_id; ?>" ).val(<?php echo $jvariable; ?>)
.bind("keydown", function(event){
if(event.keyCode === $.ui.keyCode.TAB && $( this ).data( "autocomplete" ).menu.active ) {
event.preventDefault();
}
})
.autocomplete({
minLength: 2,
// source: availableTerms,
source: function (request, response) {
// delegate back to autocomplete, but extract the last term
response( $.ui.autocomplete.filter(
availableTerms, extractLast( request.term )
));
},
focus: function() {
// prevent value inserted on focus when navigating the drop down list
return false;
},
select: function( event, ui ) {
var terms = split( this.value );
// remove the current input
terms.pop();
// add the selected item
terms.push( ui.item.value );
// add placeholder to get the comma-and-space at the end
terms.push( "" );
this.value = terms.join( ", " );
<?php echo $jvariable; ?> = terms.join( ", " );
return false;
}
})
.change(function(){
<?php echo $jvariable; ?> = $(this).val();
});
});
</script>
<div class="wrap">
<h2>Select <?php echo ucwords($tax_name); ?></h2>
<p style="font-size: 10pt; font-style: italic;">Select or enter a comma-separated list of <?php echo strtolower($tax_name); ?>.</p>
<form name="<?php echo $tax_type; ?>s_select">
<p><input type="text" id="<?php echo $input_id; ?>" name="<?php echo $input_id; ?>" style="width:100%;" /></p>
<div class="existing_terms_container">
<div>
<div class="fl">
<a href="#" id="existing_<?php echo $tax_type; ?>s">Choose from existing <?php echo strtolower($tax_name); ?></a>
</div>
<div class="fr">
<button class="button-primary" onclick="handleFBClose('<?php echo $tax_type; ?>'); return false;">Update <?php echo ucwords($tax_name); ?></button>
</div>
</div>
<br class="clearboth" />
<div class="<?php echo $tax_type; ?>checklist">
<?php echo $taxListHTML; ?>
</div>
</div>
</form>
</div>