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