Initial commit
|
@ -0,0 +1,64 @@
|
|||
<?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
|
||||
*/
|
||||
|
||||
// Cognito API access
|
||||
class CognitoAPI {
|
||||
public static $servicesBase = 'https://services.cognitoforms.com/';
|
||||
public static $formsBase = 'https://www.cognitoforms.com/';
|
||||
|
||||
// Fetches all forms for an organization
|
||||
// $api_key - API Key for the organization
|
||||
public static function get_forms($api_key) {
|
||||
$response = wp_remote_fopen(self::$servicesBase . 'forms/api/' . $api_key . '/forms');
|
||||
|
||||
return $response;
|
||||
}
|
||||
|
||||
// Fetches organization information for a given member
|
||||
// $session_token - Valid session token
|
||||
public static function get_organization($session_token) {
|
||||
$response = wp_remote_fopen(self::$servicesBase . 'member/admin/organization?token=' . urlencode($session_token));
|
||||
$organization = json_decode($response);
|
||||
|
||||
return $organization;
|
||||
}
|
||||
|
||||
// Builds form embed script
|
||||
public static function get_form_embed_script($public_key, $formId) {
|
||||
$base = self::$servicesBase;
|
||||
return <<< EOF
|
||||
<div class="cognito">
|
||||
<script src="{$base}session/script/{$public_key}"></script>
|
||||
<script>Cognito.load("forms", { id: "{$formId}" });</script>
|
||||
</div>
|
||||
EOF;
|
||||
}
|
||||
|
||||
// Builds Cognito module embed script
|
||||
public static function get_embed_script($key, $module) {
|
||||
$base = self::$servicesBase;
|
||||
return <<< EOF
|
||||
<div class="cognito">
|
||||
<script src="{$base}session/script/{$key}"></script>
|
||||
<script>Cognito.load("{$module}");</script>
|
||||
</div>
|
||||
EOF;
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
After Width: | Height: | Size: 1.1 KiB |
After Width: | Height: | Size: 1.1 KiB |
|
@ -0,0 +1,188 @@
|
|||
<?php
|
||||
|
||||
/*
|
||||
Plugin Name: Cognito Forms
|
||||
Plugin URI: http://wordpress.org/plugins/cognito-forms/
|
||||
Description: Cognito Forms is a free online form builder that integrates seemlessly with WordPress. Create contact forms, registrations forms, surveys, and more!
|
||||
Version: 1.1.8
|
||||
Author: Cognito Apps
|
||||
Author URI: https://www.cognitoforms.com
|
||||
*/
|
||||
|
||||
/**
|
||||
* 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';
|
||||
|
||||
// The Cognito Plugin!
|
||||
class Cognito_Plugin {
|
||||
// Initialization actions
|
||||
private static $actions = array(
|
||||
'admin_init',
|
||||
'admin_menu',
|
||||
'wp_ajax_fetch_api_keys',
|
||||
'wp_ajax_get_forms',
|
||||
'wp_enqueue_scripts'
|
||||
);
|
||||
|
||||
// Supported shortcodes
|
||||
private static $shortcodes = array(
|
||||
'Cognito' => 'renderCognitoShortcode',
|
||||
'cognito' => 'renderCognitoShortcode',
|
||||
'CognitoForms' => 'renderCognitoFormsShortcode',
|
||||
'cognitoforms' => 'renderCognitoFormsShortcode'
|
||||
);
|
||||
|
||||
// Entrypoint
|
||||
public function __construct() {
|
||||
$this->addActions(self::$actions);
|
||||
$this->addShortcodes(self::$shortcodes);
|
||||
}
|
||||
|
||||
// Initialize plug-in
|
||||
public function admin_init() {
|
||||
if(!current_user_can('edit_posts') && !current_user_can('edit_pages')) return;
|
||||
|
||||
register_setting('cognito_plugin', 'cognito_api_key');
|
||||
register_setting('cognito_plugin', 'cognito_admin_key');
|
||||
register_setting('cognito_plugin', 'cognito_public_key');
|
||||
register_setting('cognito_plugin', 'cognito_organization');
|
||||
|
||||
// If the flag to delete options was passed-in, delete them
|
||||
if (isset($_GET['cog_clear']) && $_GET['cog_clear'] == '1') {
|
||||
delete_option('cognito_api_key');
|
||||
delete_option('cognito_admin_key');
|
||||
delete_option('cognito_public_key');
|
||||
delete_option('cognito_organization');
|
||||
}
|
||||
|
||||
// Add tinyMCE plug-in
|
||||
if(get_user_option('rich_editing') == 'true') {
|
||||
$this->addfilters(array(
|
||||
'mce_buttons',
|
||||
'mce_external_plugins'
|
||||
));
|
||||
}
|
||||
}
|
||||
|
||||
// Register required scripts
|
||||
public function wp_enqueue_scripts() {
|
||||
wp_enqueue_script('jquery');
|
||||
}
|
||||
|
||||
// Ajax callback to allow fetching of API keys based on session token
|
||||
public function wp_ajax_fetch_api_keys() {
|
||||
$organization = CognitoAPI::get_organization($_POST['token']);
|
||||
|
||||
if (!is_null($organization)) {
|
||||
delete_option('cognito_api_key');
|
||||
delete_option('cognito_admin_key');
|
||||
delete_option('cognito_public_key');
|
||||
delete_option('cognito_organization');
|
||||
|
||||
update_option('cognito_api_key', $organization->apiKey);
|
||||
update_option('cognito_admin_key', $organization->adminKey);
|
||||
update_option('cognito_public_key', $organization->publicKey);
|
||||
update_option('cognito_organization', $organization->code);
|
||||
}
|
||||
|
||||
die;
|
||||
}
|
||||
|
||||
// Ajax callback to allow fetching of forms for a given organization
|
||||
public function wp_ajax_get_forms() {
|
||||
$api_key = get_option('cognito_api_key');
|
||||
|
||||
if ($api_key) {
|
||||
$forms = CognitoAPI::get_forms($api_key);
|
||||
|
||||
echo $forms;
|
||||
}
|
||||
|
||||
die;
|
||||
}
|
||||
|
||||
// Initialize administration menu (left-bar)
|
||||
public function admin_menu() {
|
||||
add_menu_page('Cognito Forms', 'Cognito Forms', 'manage_options', 'Cognito', array($this, 'main_page'), '../wp-content/plugins/cognito-forms/cogicon.ico');
|
||||
add_submenu_page('Cognito', 'Cognito Forms', 'View Forms', 'manage_options', 'Cognito', array($this, 'main_page'));
|
||||
add_submenu_page('Cognito', 'Create Form', 'New Form', 'manage_options', 'CognitoCreateForm', array($this, 'main_page'));
|
||||
add_submenu_page('Cognito', 'Templates', 'Templates', 'manage_options', 'CognitoTemplates', array($this, 'main_page'));
|
||||
|
||||
add_options_page('Cognito Options', 'Cognito Forms', 'manage_options', 'CognitoOptions', array($this, 'options_page'));
|
||||
}
|
||||
|
||||
// Called when a 'Cognito' shortcode is encountered, renders embed script
|
||||
public function renderCognitoShortcode($atts, $content = null, $code = '') {
|
||||
// Default to key setting, unless overridden in shortcode (allows for modules from multiple orgs)
|
||||
$key = empty($atts['key']) ? get_option('cognito_public_key') : $atts['key'];
|
||||
if (empty($atts['module']) || empty($atts['key'])) return '';
|
||||
|
||||
return CognitoAPI::get_embed_script($key, $atts['module']);
|
||||
}
|
||||
|
||||
// Called when a 'CognitoForms' shortcode is encountered, renders form embed script
|
||||
public function renderCognitoFormsShortcode($atts, $content = null, $code = '') {
|
||||
// Default to key setting, unless overridden in shortcode (allows for modules from multiple orgs)
|
||||
$key = empty($atts['key']) ? get_option('cognito_public_key') : $atts['key'];
|
||||
if (empty($atts['id']) || empty($key)) return '';
|
||||
|
||||
return CognitoAPI::get_form_embed_script($key, $atts['id']);
|
||||
}
|
||||
|
||||
// Entrypoint for Cognito Forms access
|
||||
public function main_page() {
|
||||
include 'tmpl/main.php';
|
||||
}
|
||||
|
||||
public function options_page() {
|
||||
include 'tmpl/options.php';
|
||||
}
|
||||
|
||||
// Set up tinyMCE buttons
|
||||
public function mce_buttons($buttons) {
|
||||
array_push($buttons, '|', 'cognito');
|
||||
return $buttons;
|
||||
}
|
||||
|
||||
// Initialize tinyMCE plug-in
|
||||
public function mce_external_plugins($plugins) {
|
||||
$plugins['cognito'] = plugin_dir_url( __FILE__ ) . 'tinymce/plugin.js';
|
||||
return $plugins;
|
||||
}
|
||||
|
||||
// Registers plug-in actions
|
||||
private function addActions($actions) {
|
||||
foreach($actions as $action)
|
||||
add_action($action, array($this, $action));
|
||||
}
|
||||
|
||||
// Registers shortcodes
|
||||
private function addShortcodes($shortcodes) {
|
||||
foreach($shortcodes as $tag => $func)
|
||||
add_shortcode($tag, array($this, $func));
|
||||
}
|
||||
|
||||
// Registers tinyMCE filters
|
||||
private function addFilters($filters) {
|
||||
foreach($filters as $filter)
|
||||
add_filter($filter, array($this, $filter));
|
||||
}
|
||||
}
|
||||
|
||||
new Cognito_Plugin;
|
||||
?>
|
|
@ -0,0 +1,93 @@
|
|||
=== Cognito Forms ===
|
||||
Contributors: cognitoapps
|
||||
Donate link: https://www.cognitoforms.com
|
||||
Tags: form, forms, cognito, cognito forms, create form, create forms, form builder, form creator, form generator, html form, online form, online form builder, online forms, registration, survey, surveys, web form, web forms, embed, anti-spam, email form, email, responsive, payment
|
||||
Requires at least: 3.5
|
||||
Tested up to: 5.6
|
||||
Stable tag: 1.1.8
|
||||
License: GPLv2 or later
|
||||
License URI: http://www.gnu.org/licenses/gpl-2.0.html
|
||||
|
||||
Create responsive contact forms, order forms, registration forms and more. For free and without ever leaving WordPress.
|
||||
|
||||
== Description ==
|
||||
Basic or advanced, we have all the features you need to quickly create powerful online forms.
|
||||
|
||||
FREE Features:
|
||||
-----------
|
||||
|
||||
[Unlimited Forms & Fields](https://www.cognitoforms.com/features/unlimited-forms-fields)
|
||||
Collect all the data you need, no matter what - make as many forms as you want, with as many fields as you want.
|
||||
[Calculations](https://www.cognitoforms.com/features/calculations)
|
||||
Let us do the math for you - build forms with powerful calculations that can total costs, compare dates and so much more.
|
||||
[Conditional Logic](https://www.cognitoforms.com/features/conditional-logic)
|
||||
Take each of your users on a unique path through your forms and control what they see with Conditional Logic.
|
||||
[Countries, Languages & Currencies](https://www.cognitoforms.com/features/countries-languages-currencies)
|
||||
18 languages. 121 countries. 137 currencies. Awesome forms.
|
||||
[Email Notifications](https://www.cognitoforms.com/features/email-notifications)
|
||||
Create custom autoresponder emails that include all the details of your customer's purchase or entry so they can review their order at any time.
|
||||
[Entry Management](https://www.cognitoforms.com/features/entry-management)
|
||||
Sort, filter, and organize your form submissions to help you smoothly run your business or organization.
|
||||
[File Uploads](https://www.cognitoforms.com/features/file-uploads)
|
||||
Capturing multiple files at once, setting file size and type limits - it all comes free with every single Cognito Forms account.
|
||||
[Form Confirmations](https://www.cognitoforms.com/features/form-confirmations)
|
||||
Create a personalized message to confirm a user's submission and allow them to review their order or entry data.
|
||||
[Multi-Page Forms](https://www.cognitoforms.com/features/multi-page-forms)
|
||||
Get more responses to your complex surveys and long forms with page breaks, progress bars and conditional pages.
|
||||
[Payment](https://www.cognitoforms.com/features/payment)
|
||||
Secure credit and debit card payment processing through Stripe. Or upgrade to use PayPal.
|
||||
[Rating Scales](https://www.cognitoforms.com/features/rating-scales)
|
||||
Give your customers an outlet for feedback right on your forms with customizable rating scales.
|
||||
[Repeating Sections & Tables](https://www.cognitoforms.com/features/repeating-sections)
|
||||
Collect as much or as little data as your customers can give, without any extra work or adding a lot of clutter.
|
||||
[SPAM Prevention](https://www.cognitoforms.com/features/spam-prevention)
|
||||
Keep your forms easy-to-use while eliminating rogue entries with our powerful, automatic spam prevention.
|
||||
[Template Sharing](https://www.cognitoforms.com/features/template-sharing)
|
||||
Made an awesome form? Share your form as a template so others can bask in your awesomeness.
|
||||
|
||||
**Premium Features**
|
||||
[Data Encryption](https://www.cognitoforms.com/features/data-encryption)
|
||||
Keep your form data safe and sound.
|
||||
[Document Merging](https://www.cognitoforms.com/features/document-merging)
|
||||
Create PDF and Word docs from your entry data, completely customized the way you want.
|
||||
[Electronic Signatures](https://www.cognitoforms.com/features/electronic-signatures)
|
||||
Collect signatures on every form and on any device.
|
||||
[Entry Sharing](https://www.cognitoforms.com/features/entry-sharing)
|
||||
Give your users the ability to update their entries even after they've already been submitted.
|
||||
[HIPAA Compliance](https://www.cognitoforms.com/features/hipaa-compliance)
|
||||
Easily create secure forms to engage with your patients and protect their data.
|
||||
[Save & Resume](https://www.cognitoforms.com/features/save-resume)
|
||||
Allow users to pick up right where they left off by saving their progress on partially completed form responses.
|
||||
[Saved Entry Views](https://www.cognitoforms.com/features/entry-management#saved)
|
||||
After you sort and filter your entry data, save those settings to create a unique entry view.
|
||||
|
||||
Learn more at [cognitoforms.com](https://www.cognitoforms.com).
|
||||
|
||||
== Installation ==
|
||||
|
||||
1. Install and activate the plugin through the "Plugins" menu in WordPress.
|
||||
2. If you have not already done so, install and activate the "Classic Editor" plugin from the WordPress store.
|
||||
|
||||
== Frequently Asked Questions ==
|
||||
|
||||
= Is Cognito Forms cloud-hosted? =
|
||||
|
||||
Yes, your forms and your submissions are securely stored in the cloud.
|
||||
|
||||
= How do I create a form? =
|
||||
|
||||
In order to create a form, you need to create a Cognito Forms account through the plugin. Once you design your form, you can embed it onto a post or a page by using the Cognito Forms icon, the orange cog, that shows up on the editor toolbar. We'll automatically add the short code for you.
|
||||
|
||||
|
||||
== Screenshots ==
|
||||
|
||||
1. After activation, the Cognito Forms plugin will appear in your menu. Click on the plugin to be taken to Cognito Forms.
|
||||
2. Click on the menu icon in the upper right to log in or sign up.
|
||||
3. Once logged in, build a new form from a template or from scratch.
|
||||
4. Build your form and click "Save".
|
||||
5. In your WordPress menu, add a new Page or Post.
|
||||
6. In the editor, click on the orange Cog icon for Cognito Forms.
|
||||
7. Select the form name from the drop down and click "Insert Form".
|
||||
8. The plugin inserts the Cognito Forms short code for you.
|
||||
9. Preview or post your new form!
|
||||
|
After Width: | Height: | Size: 94 KiB |
After Width: | Height: | Size: 71 KiB |
After Width: | Height: | Size: 105 KiB |
After Width: | Height: | Size: 85 KiB |
After Width: | Height: | Size: 94 KiB |
After Width: | Height: | Size: 70 KiB |
After Width: | Height: | Size: 68 KiB |
After Width: | Height: | Size: 70 KiB |
After Width: | Height: | Size: 31 KiB |
After Width: | Height: | Size: 1.1 KiB |
|
@ -0,0 +1,103 @@
|
|||
<?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
|
||||
*/
|
||||
?>
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<style>
|
||||
body { overflow: hidden; }
|
||||
button{margin-top:20px;color: #fff !important;text-shadow: 0 1px 1px rgba(0,0,0,.3);outline: none;cursor: pointer;text-align: center;text-decoration: none;font: 14px/100% 'Open Sans Condensed', sans-serif !important;font-weight: 700 !important;padding: 5px 15px 6px;border: solid 1px #95ba14;background: #aed136;}
|
||||
.clearlooks2 .mceTop .mceLeft, .clearlooks2 .mceTop .mceRight{background:#00B4AC;padding:20px;font-family: 'Open Sans Condensed', Arial, Helvetica, sans-serif;font-size: 18px;font-weight: 700;color: #fff;}
|
||||
body{padding: 10px 20px!important;font-family: 'Open Sans', Arial, Helvetica, sans-serif;font-size: 14px;font-weight: 400;}
|
||||
h3 {margin-bottom:20px!important;color:#444!important;}
|
||||
</style>
|
||||
<script src="../../../../wp-includes/js/jquery/jquery.js"></script>
|
||||
<script src="../../../../wp-includes/js/tinymce/tiny_mce_popup.js"></script>
|
||||
<script src="../../../../wp-includes/js/tinymce/utils/mctabs.js"></script>
|
||||
<script src="../../../../wp-includes/js/tinymce/utils/form_utils.js"></script>
|
||||
<title>Cognito Forms</title>
|
||||
<script>
|
||||
var titleElements = tinyMCEPopup.getWin().document.querySelectorAll('.mceTop .mceLeft, .mceTop .mceRight, .mce-title');
|
||||
for (var i = 0; i < titleElements.length; i++) {
|
||||
titleElements[i].style.background = '#00B4AC';
|
||||
titleElements[i].style.color = '#fff';
|
||||
}
|
||||
|
||||
var closeElement = tinyMCEPopup.getWin().document.querySelector('.mceClose, .mce-close');
|
||||
if (closeElement) closeElement.style.color = '#fff';
|
||||
|
||||
function cognito_submit() {
|
||||
var formSelect = document.getElementById('formSelect');
|
||||
var shortcode = '[CognitoForms id="' + formSelect.value + '"]';
|
||||
|
||||
if (window.tinyMCE) {
|
||||
if (window.tinyMCE.execInstanceCommand) {
|
||||
window.tinyMCE.execInstanceCommand('content', 'mceInsertContent', false, shortcode);
|
||||
tinyMCEPopup.editor.execCommand('mceRepaint');
|
||||
}
|
||||
else if (window.tinyMCE.focusedEditor) {
|
||||
window.tinyMCE.focusedEditor.insertContent(shortcode);
|
||||
}
|
||||
|
||||
tinyMCEPopup.close();
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
jQuery(function() {
|
||||
var data = {
|
||||
action: "get_forms"
|
||||
};
|
||||
jQuery.post(tinyMCEPopup.params.ajax_url, data, function(response) {
|
||||
if (response) {
|
||||
var forms = JSON.parse(response);
|
||||
|
||||
var formSelect = jQuery("#formSelect");
|
||||
jQuery.each(forms, function() {
|
||||
formSelect.append(jQuery("<option></option>")
|
||||
.attr("value", this.Id)
|
||||
.text(this.Name));
|
||||
});
|
||||
|
||||
jQuery("#form-list").show();
|
||||
} else {
|
||||
jQuery("#no-forms").show();
|
||||
}
|
||||
});
|
||||
});
|
||||
</script>
|
||||
</head>
|
||||
|
||||
<body>
|
||||
<div id="no-forms" style="display:none;">
|
||||
<h3>You are not logged into your Cognito Forms account.</h3>
|
||||
<p>Please click on the "Cognito Forms" link in the menu on the left and log in to register this plug-in with your account.</p>
|
||||
</div>
|
||||
|
||||
<div id="form-list" style="display:none;">
|
||||
<h3>Embed a Form</h3>
|
||||
<form method="post" action="">
|
||||
<label for="formSelect">Choose a form</label>
|
||||
<select id="formSelect">
|
||||
</select><br/>
|
||||
<button id="cognito-insert-form" type="button" onclick="cognito_submit();">Insert Form</button>
|
||||
</form>
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
After Width: | Height: | Size: 1.1 KiB |
|
@ -0,0 +1,24 @@
|
|||
(function(){
|
||||
tinymce.create('tinymce.plugins.cognito', {
|
||||
init : function(ed, url) {
|
||||
ed.addCommand('cognito_embed_window', function() {
|
||||
ed.windowManager.open({
|
||||
file : url + '/dialog.php',
|
||||
width : 400,
|
||||
height : 160,
|
||||
inline: 1
|
||||
}, { plugin_url : url, ajax_url: ajaxurl });
|
||||
});
|
||||
|
||||
ed.addButton('cognito', {
|
||||
title : 'Cognito Forms',
|
||||
cmd : 'cognito_embed_window',
|
||||
image : url + '/cogicon.ico'
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
tinymce.PluginManager.add('cognito', tinymce.plugins.cognito);
|
||||
|
||||
})()
|
||||
|
|
@ -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>
|
|
@ -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>
|