/
keywords_display.php
149 lines (121 loc) · 5.92 KB
/
keywords_display.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
<?php
$response = array();
if(isset($_POST['keyword_to_link-new'])) {
$insertKeywordList = array();
if(isset($_POST['keyword_to_link_link_new_bidimensional']))
$insertKeywordList = $_POST['keyword_to_link_link_new'];
else
$insertKeywordList[] = $_POST['keyword_to_link_link_new'];
foreach($insertKeywordList as $insert_information) {
$insert_information['keyword'] = trim($insert_information['keyword']);
$existing_information = KeywordToLink::getInstance()->database->getLinkByKeyword($insert_information['keyword']);
if($insert_information['keyword'] == '') {
if(!isset($_POST['keyword_to_link_link_new_bidimensional']))
$response['errors'][] = 'Your keyword cannot be empty';
} elseif(empty($existing_information)) {
KeywordToLink::getInstance()->database->insertLink($insert_information);
$response['success'][] = 'Added Keyword "' . $insert_information['keyword']. '"';
} else {
$response['errors'][] = 'Keyword "' . $insert_information['keyword']. '" already exists - Not Added';
}
}
}elseif(isset($_POST['keyword_to_link-update'])) {
$arrayKeysOfUpdate = array_keys($_POST['keyword_to_link-update']);
$to_update = array_shift($arrayKeysOfUpdate);
$update_information = $_POST['keyword_to_link_link'][$to_update];
$update_information['keyword'] = trim($update_information['keyword']);
$existing_information = KeywordToLink::getInstance()->database->getLinkByKeyword($update_information['keyword']);
$to_update_information = KeywordToLink::getInstance()->database->getLinkById($to_update);
if($update_information['keyword'] == '')
$response['errors'][] = 'Keyword "' . $update_information['keyword']. '" cannot be empty';
elseif(empty($existing_information) || $existing_information->id == $to_update) {
KeywordToLink::getInstance()->database->updateLink($update_information, $to_update);
$response['success'][] = 'Updated Keyword "' . $update_information['keyword']. '"';
} else {
$response['errors'][] = 'Keyword "' . $update_information['keyword']. '" already exists - "' . $to_update_information->keyword .'" was not updated';
}
}elseif(isset($_POST['keyword_to_link-delete'])) {
$deleteKeys = array_keys($_POST['keyword_to_link-delete']);
foreach($deleteKeys as $toDelete) {
$delete_information = $_POST['keyword_to_link_link'][$toDelete];
KeywordToLink::getInstance()->database->deleteLink($toDelete);
$response['warnings'][] = 'Deleted Keyword "' . $delete_information['keyword']. '"';
}
}elseif(isset($_POST['keyword_to_link-bulk-delete'])) {
$deleteKeys = $_POST['keyword_to_link-bulk'];
foreach($deleteKeys as $toDelete) {
$delete_information = $_POST['keyword_to_link_link'][$toDelete];
KeywordToLink::getInstance()->database->deleteLink($toDelete);
$response['warnings'][] = 'Deleted Keyword "' . $delete_information['keyword']. '"';
}
}
$keywords_information = KeywordToLink::getInstance()->database->getAllLinksWithInformation();
if(isset($response['errors']))
foreach($response['errors'] as $error)
echo '<div class="alert alert-danger">' . $error . '</div>';
if(isset($response['notifications']))
foreach($response['notifications'] as $notification)
echo '<div class="alert alert-info">' . $notification . '</div>';
if(isset($response['success']))
foreach($response['success'] as $success)
echo '<div class="alert alert-success">' . $success . '</div>';
if(isset($response['warnings']))
foreach($response['warnings'] as $warning)
echo '<div class="alert alert-warning">' . $warning . '</div>';
// Do more rendering to avoid the wordpress annoying ajax sistem while making the script be more fun
?>
<form method="POST" id="keyword_to_link_form">
<input type="submit" name="keyword_to_link-bulk-delete" value="Bulk Delete »" class="btn btn-danger bulk-operation" style="display: none;">
<div class="clear"></div>
<br/>
<?php if(KeywordToLink::getInstance()->settings->getGroupByLinks() == 0) : ?>
<?php require_once("partials/_keywords_display-classic.php");?>
<?php else : ?>
<?php if(count($keywords_information) == 0) : ?>
<div class="alert alert-info">
<?php echo __("Add at least a keyword in order to activate the group by links feature"); ?>
</div>
<?php require_once("partials/_keywords_display-classic.php");?>
<?php else : ?>
<?php require_once("partials/_keywords_display-group-by-links.php");?>
<?php endif;?>
<?php endif;?>
</form>
<script>
var form = jQuery('#keyword_to_link_form');
form.find('a.close-edit').bind('click', function(event){
event.preventDefault();
jQuery('#ap-edit-' + jQuery(this).attr('entry-id')).hide();
jQuery('#ap-information-' + jQuery(this).attr('entry-id')).show();
});
form.find('a.open-edit').bind('click', function(event){
event.preventDefault();
jQuery('#ap-edit-' + jQuery(this).attr('entry-id')).show();
jQuery('#ap-information-' + jQuery(this).attr('entry-id')).hide();
});
form.find('input[name="keyword_to_link-bulk-mark"]').bind('click change', function(event){
var bulkCheckboxes = jQuery(this).parents("thead:first").next().find('input[name="keyword_to_link-bulk[]"]');
if(jQuery(this).is(":checked"))
bulkCheckboxes.attr("checked", "checked");
else
bulkCheckboxes.removeAttr("checked");
bulkCheckboxes.first().trigger("click").trigger("click");
});
form.find('input[name="keyword_to_link-bulk[]"]').bind('click change', function(event){
if(form.find('input[name="keyword_to_link-bulk[]"]:checked').length > 0) {
form.find(".bulk-operation").stop().fadeIn("slow");
} else {
form.find(".bulk-operation").stop().fadeOut("slow");
form.find('input[name="keyword_to_link-bulk-mark"]').removeAttr("checked");
}
});
form.find("table.tablesorter").tablesorter({
theme : 'blue',
cssInfoBlock : "avoid-sort",
widgets: [ 'zebra' ],
headers: {
0: {sorter: false},
6: {sorter: false}
}
});
</script>