c161fedc1bd6098130196d6bfafbe08de9307729
[com.zyxware.civiwci.git] / CRM / Wci / Page / Embed.php
1 <?php
2 /*
3 +--------------------------------------------------------------------+
4 | CiviCRM Widget Creation Interface (WCI) Version 1.0 |
5 +--------------------------------------------------------------------+
6 | Copyright Zyxware Technologies (c) 2014 |
7 | Copyright (C) 2014 David Thompson <davet@gnu.org> |
8 +--------------------------------------------------------------------+
9 | This file is a part of CiviCRM WCI. |
10 | |
11 | CiviCRM WCI is free software; you can copy, modify, and distribute |
12 | it under the terms of the GNU Affero General Public License |
13 | Version 3, 19 November 2007. |
14 | |
15 | CiviCRM WCI is distributed in the hope that it will be useful, |
16 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
17 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
18 | See the GNU Affero General Public License for more details. |
19 | |
20 | You should have received a copy of the GNU Affero General Public |
21 | License along with this program; if not, contact Zyxware |
22 | Technologies at info[AT]zyxware[DOT]com. |
23 +--------------------------------------------------------------------+
24 */
25
26 require_once 'CRM/Core/Page.php';
27
28 class CRM_Wci_Page_Embed extends CRM_Core_Page {
29 function run() {
30 $license_text = '
31 /**
32 * @licstart The following is the entire license notice for the
33 * JavaScript code in this page.
34 *
35 * Copyright (C) 2014 Zyxware Technologies.
36 *
37 * This JavaScript is part of the CiviCRM WCI extension for
38 * CiviCRM. This JavaScript is free software: you can
39 * redistribute it and/or modify it under the terms of the GNU
40 * Affero General Public License as published by the Free
41 * Software Foundation, either version 3 of the License, or (at
42 * your option) any later version.
43 *
44 * The code is distributed WITHOUT ANY WARRANTY; without even the
45 * implied warranty of MERCHANTABILITY or FITNESS FOR A
46 * PARTICULAR PURPOSE. See the GNU Affero General Public License
47 * for more details.
48 *
49 * You should have received a copy of the GNU General Public
50 * License along with FSF Member Dashboard. If not, see
51 * <http://www.gnu.org/licenses/>.
52 *
53 * @licend The above is the entire license notice for the
54 * JavaScript code in this page
55 */
56 ';
57
58 $wciembed_js = '
59 // Cleanup functions for the document ready method
60 if ( document.addEventListener ) {
61 DOMContentLoaded = function() {
62 document.removeEventListener( "DOMContentLoaded", DOMContentLoaded, false );
63 onReady();
64 };
65 } else if ( document.attachEvent ) {
66 DOMContentLoaded = function() {
67 // Make sure body exists, at least, in case IE gets a little overzealous
68 if ( document.readyState === "complete" ) {
69 document.detachEvent( "onreadystatechange", DOMContentLoaded );
70 onReady();
71 }
72 };
73 }
74 if ( document.readyState === "complete" ) {
75 // Handle it asynchronously to allow scripts the opportunity to delay ready
76 setTimeout( onReady, 1 );
77 }
78
79 // Mozilla, Opera and webkit support this event
80 if ( document.addEventListener ) {
81 // Use the handy event callback
82 document.addEventListener( "DOMContentLoaded", DOMContentLoaded, false );
83 // A fallback to window.onload, that will always work
84 window.addEventListener( "load", onReady, false );
85 // If IE event model is used
86 } else if ( document.attachEvent ) {
87 // ensure firing before onload,
88 // maybe late but safe also for iframes
89 document.attachEvent("onreadystatechange", DOMContentLoaded);
90
91 // A fallback to window.onload, that will always work
92 window.attachEvent( "onload", onReady );
93 }
94
95 function onReady( ) {
96 document.getElementById("widgetwci").innerHTML = wciwidgetcode;
97 }';
98
99 $config = CRM_Core_Config::singleton();
100
101 $embedId = CRM_Utils_Request::retrieve('id', 'Positive', CRM_Core_DAO::$_nullObject);
102 $preview = CRM_Utils_Request::retrieve('preview', 'Positive', CRM_Core_DAO::$_nullObject);
103
104 $output = $license_text;
105 $output .= 'var wciwidgetcode = ' . CRM_Wci_WidgetCode::get_widget_code($embedId, $preview) . ';';
106 $output .= $wciembed_js;
107
108 header('Content-Type: text/javascript');
109 echo $output;
110 CRM_Utils_System::civiExit();
111 }
112 }