Initial commit

This commit is contained in:
2021-06-15 09:41:50 -04:00
commit 1426db528b
20 changed files with 582 additions and 0 deletions

81
tmpl/main.php Executable file
View File

@@ -0,0 +1,81 @@
<?php
/**
* Cognito Forms WordPress Plugin.
*
* The Cognito Forms WordPress Plugin is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License, version 2, as
* published by the Free Software Foundation.
*
* The Cognito Forms WordPress Plugin is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
require_once dirname(__FILE__) . '/../api.php';
$url = CognitoAPI::$formsBase;
if ($_GET['page'] == 'CognitoCreateForm') {
$url = $url . 'forms/new';
} elseif ($_GET['page'] == "CognitoTemplates") {
$url = $url . 'forms/templates';
} else {
$url = $url . 'forms';
}
?>
<iframe id="cognito-frame" src="<?php print $url; ?>" style="width:100%; overflow-x: hidden;"></iframe>
<style>
body { overflow: hidden; }
</style>
<script language="javascript">
var element = document.getElementById('cognito-frame');
for (; element; element = element.previousSibling) {
if (element.nodeType === 1 && element.id !== 'cognito-frame') {
element.style.display = 'none';
}
}
var adminheight = document.getElementById('wpadminbar').clientHeight;
document.getElementById('cognito-frame').height = (document.body.clientHeight - adminheight) + "px";
window.addEventListener("message", messageListener);
window.addEventListener('resize', resizeListener);
// Handler to watch for window resize to correctly update iframe height
function resizeListener(event) {
var adminheight = document.getElementById('wpadminbar').clientHeight;
document.getElementById('cognito-frame').height = (document.body.clientHeight) + "px";
}
// Handler to listen for session tokens being broadcast from the Cognito iframe
function messageListener(event) {
var data = event.data;
var found = data.indexOf("token:");
if (found == 0) {
var token = data.substring("token:".length);
// If a session token was received, and no api key is present, update
fetchApiKey(token);
}
}
// Posts token to a hidden iframe so that a separate script can fetch necessary keys
function fetchApiKey(token) {
if (!token) return;
var data = {
action: "fetch_api_keys",
token: token
};
jQuery.post(ajaxurl, data, function(response) { });
}
</script>

29
tmpl/options.php Executable file
View File

@@ -0,0 +1,29 @@
<h2>Cognito Forms</h2>
<form method="post" action="options.php">
<?php settings_fields('cognito_plugin'); ?>
<table class="form-table">
<tr valign="top">
<th scope="row">API Key</th>
<td><input type="text" name="cognito_api_key" style="width:300px;" value="<?php echo get_option('cognito_api_key'); ?>" /></td>
</tr>
<tr valign="top">
<th scope="row">Admin API Key</th>
<td><input type="text" name="cognito_admin_key" style="width:300px;" value="<?php echo get_option('cognito_admin_key'); ?>" /></td>
</tr>
<tr valign="top">
<th scope="row">Public API Key</th>
<td><input type="text" name="cognito_public_key" style="width:300px;" value="<?php echo get_option('cognito_public_key'); ?>" /></td>
</tr>
<tr valign="top">
<th scope="row">Organization Code</th>
<td><input type="text" name="cognito_organization" style="width:300px;" value="<?php echo get_option('cognito_organization'); ?>" /></td>
</tr>
</table>
<p class="submit">
<input type="submit" class="button-primary" value="<?php _e('Save Changes') ?>" />
</p>
</form>