PluginProbe
Cognito Forms / 2.0.4
Cognito Forms v2.0.4
2.0.12 2.0.11 trunk 1.0 1.1.0 1.1.1 1.1.2 1.1.3 1.1.4 1.1.5 1.1.6 1.1.7 1.1.8 2.0.0 2.0.1 2.0.10 2.0.2 2.0.3 2.0.4 2.0.5 2.0.6 2.0.7 2.0.8 2.0.9
cognito-forms / api.php

api.php in Cognito Forms 2.0.4, at api.php

60 lines 2.0 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Cognito Forms WordPress Plugin.
4 *
5 * The Cognito Forms WordPress Plugin is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License, version 2, as
7 * published by the Free Software Foundation.
8 *
9 * The Cognito Forms WordPress Plugin is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
17 */
18
19 // Cognito API access
20 if ( !class_exists('CognitoAPI') ) {
21 class CognitoAPI {
22 public static $formsBase;
23
24 public static function __constructStatic() {
25 self::$formsBase = ( get_option( 'cognito_dev_environment' ) !== false && !empty( get_option( 'cognito_dev_environment' ) ) )
26 ? get_option( 'cognito_dev_environment' )
27 : 'https://www.cognitoforms.com';
28 }
29
30 // Convert MS GUID to Short GUID
31 private static function guid_to_short_guid($guid) {
32 $guid_byte_order = [ 3,2,1,0,5,4,7,6,8,9,10,11,12,13,14,15 ];
33 $guid = preg_replace( "/[^a-zA-Z0-9]+/", "", $guid );
34 $hex = "";
35 for ( $i = 0; $i < 16; $i++ )
36 $hex .= substr( $guid, 2 * $guid_byte_order[$i], 2 );
37 $bin = hex2bin( $hex );
38 $encoded = base64_encode( $bin );
39 $encoded = str_replace( "/", "_", $encoded );
40 $encoded = str_replace( "+", "-", $encoded );
41 $encoded = substr ( $encoded, 0, 22 );
42 return $encoded;
43 }
44
45 // Builds form embed script
46 public static function get_form_embed_script( $public_key, $formId ) {
47 $base = self::$formsBase;
48 $public_short_guid = self::guid_to_short_guid( $public_key );
49
50 return <<< EOF
51 <script src="{$base}/f/seamless.js" data-key="{$public_short_guid}" data-form="{$formId}"></script>
52 EOF;
53 }
54 }
55
56 CognitoAPI::__constructStatic();
57 }
58
59 ?>
60