-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathadmin_panel.php
181 lines (109 loc) · 4.36 KB
/
admin_panel.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
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
<?php
/**
* @Author Michael Pande
*/
if(isset($_POST["NewKey"])){
updateAPIkey();
}else{
createAPIkey();
}
// Returns the API key from the Wordpress Database
function getAPIkey(){
if(strlen(get_option("nml2-plugin-api-key")) < 1){
return createAPIkey();
}
return get_option("nml2-plugin-api-key");
}
// Stores API key in database
function createAPIkey(){
$key = bin2hex(openssl_random_pseudo_bytes(32));
add_option( 'nml2-plugin-api-key', $key, '', 'yes' );
return $key;
}
// Stores API key in database
function updateAPIkey(){
$key = bin2hex(openssl_random_pseudo_bytes(32));
update_option( 'nml2-plugin-api-key', $key, '', 'yes' );
return $key;
}
?>
<!-- Import file -->
<script language="javascript">
window.onload = function(e){
// Appends / Removes HTTP_GET parameter from URL
var urlInput = document.getElementById('url');
var url = urlInput.value;
var debugbox = document.getElementById('debugbox');
var updatebox = document.getElementById('updatebox');
var validatebox = document.getElementById('validatebox');
debugbox.addEventListener("click", function(){
updateURL();
});
updatebox.addEventListener("click", function(){
updateURL();
});
validatebox.addEventListener("click", function(){
updateURL();
});
function updateURL(){
var full_url = url;
if(updatebox.checked)
full_url = full_url + "&update_override=true";
if(debugbox.checked)
full_url = full_url + "&debug=true"
if(!validatebox.checked)
full_url = full_url + "&validate=false"
urlInput.value = full_url;
}
};
</script>
<h1>Rewpert-G2</h1><br>
<h2>Usage</h2>
<ul class="indent">
<li>The API returns <strong>HTTP Status Codes</strong> and <strong>requires authentication</strong> (API Key)</li>
<li>Content-Type: <strong>application/xml</strong></li>
</ul>
<br>
<?php echo '<form class="well" action="'.htmlspecialchars($_SERVER["PHP_SELF"]).'?page=rewpert-g2" method="post" enctype="multipart/form-data">' ?>
<h3>POST the XML to the following url</h3>
<label for="validatebox" >Validate NewsML-G2</label> <input type="checkbox" name="validatebox" id="validatebox" value="true" checked/>
<label for="debugbox" >Debug</label> <input type="checkbox" name="debugbox" id="debugbox" value="false" />
<label for="updatebox" >Update Override</label> <input type="checkbox" name="updatebox" id="updatebox" value="false" /><br><br>
<input style='width:100%' id="url" type="text" value='<?php echo getPathToPluginDir();?>RESTApi.php?key=<?php echo getAPIkey(); ?>' />
<br><br>
<br>
<form class="well" action="" method="post">
<input type="hidden" name="NewKey" value="true" /><br>
<input type="submit" value="Create new API key and update the URL" />
</form><br><br>
<div class="nml2-container">
<h2>Manual Upload</h2><br>
<p class="indent"><strong>Supports: </strong>NewsItems & KnowledgeItems. </p>
<p class="indent"><strong>Update: </strong>It overwrites existing post with GUID, and ignores version.</p>
<br>
<form class="indent" id="manual" action='<?php echo getPathToPluginDir();?>RESTApi.php?key=<?php echo getAPIkey(); ?>&manual=true&update_override=true' enctype="multipart/form-data" method="post">
<input type="file" name="uploaded_file" id="uploaded_file" ><br><br>
<input type="submit" id="startImport" value="Start import" name="submit" >
</form><br><br>
<div id="response">
</div>
<h2>Quick reference</h2>
<div class="nml2-right">
<h4>Documentation</h4>
<a href="http://demo-nmlg2wp.rhcloud.com/documentation.php">Documentation</a><br>
<a href="https://bitbucket.org/michaelpande/newsml-g2-restful-wordpress-import">Source code</a><br>
</div>
<div class="nml2-right">
<h4>Links</h4>
<a href="http://demo-nmlg2wp.rhcloud.com">Plugin page</a><br>
<a href="http://www.iptc.org/site/News_Exchange_Formats/NewsML-G2/">IPTC NewsML-G2</a><br>
</div>
</div>
<br><br>
<h2>Security</h2>
<ul class="indent">
<li>The API key will be <strong>hidden when using SSL</strong></li>
<li>The API key is generated with openssl_random_pseudo_bytes(32)</li>
<li>The API key is stored in the Wordpress Database </li>
</ul>
<br><br><br><br>