From 9e4494ed4017324726d0e47a12418efd67d7dda6 Mon Sep 17 00:00:00 2001 From: David Thompson Date: Tue, 2 Dec 2014 15:07:33 -0500 Subject: [PATCH] Fix widget preview and embed codes. --- CRM/Wci/Form/CreateWidget.php | 5 +++ CRM/Wci/Form/NewEmbedCode.php | 4 +++ extern/embed.php => CRM/Wci/Page/Embed.php | 36 +++++++++++----------- CRM/Wci/WidgetCode.php | 2 +- templates/CRM/Wci/Form/CreateWidget.tpl | 10 ++---- templates/CRM/Wci/Form/NewEmbedCode.tpl | 21 +++++-------- wci-helper-functions.php | 10 ------ xml/Menu/wci.xml | 6 ++++ 8 files changed, 44 insertions(+), 50 deletions(-) rename extern/embed.php => CRM/Wci/Page/Embed.php (83%) diff --git a/CRM/Wci/Form/CreateWidget.php b/CRM/Wci/Form/CreateWidget.php index 0d12c30..6ffdb8c 100644 --- a/CRM/Wci/Form/CreateWidget.php +++ b/CRM/Wci/Form/CreateWidget.php @@ -43,6 +43,11 @@ class CRM_Wci_Form_CreateWidget extends CRM_Core_Form { function preProcess() { CRM_Core_Resources::singleton()->addScriptFile('com.zyxware.civiwci', 'js/createwidget.js'); parent::preProcess(); + + if(isset($_REQUEST['id'])) { + $this->assign('emb_id', $_REQUEST['id']); + } + $this->_id = CRM_Utils_Request::retrieve('id', 'Positive', $this, FALSE, NULL, 'REQUEST' ); diff --git a/CRM/Wci/Form/NewEmbedCode.php b/CRM/Wci/Form/NewEmbedCode.php index a7755e7..3f2e761 100644 --- a/CRM/Wci/Form/NewEmbedCode.php +++ b/CRM/Wci/Form/NewEmbedCode.php @@ -34,6 +34,10 @@ class CRM_Wci_Form_NewEmbedCode extends CRM_Core_Form { protected $_id; function preProcess() { + if(isset($_REQUEST['id'])) { + $this->assign('emb_id', $_REQUEST['id']); + } + $this->_id = CRM_Utils_Request::retrieve('id', 'Positive', $this, FALSE, NULL, 'REQUEST' ); } diff --git a/extern/embed.php b/CRM/Wci/Page/Embed.php similarity index 83% rename from extern/embed.php rename to CRM/Wci/Page/Embed.php index fd6cce4..a9bd1da 100644 --- a/extern/embed.php +++ b/CRM/Wci/Page/Embed.php @@ -4,6 +4,7 @@ | CiviCRM Widget Creation Interface (WCI) Version 1.0 | +--------------------------------------------------------------------+ | Copyright Zyxware Technologies (c) 2014 | + | Copyright (C) 2014 David Thompson | +--------------------------------------------------------------------+ | This file is a part of CiviCRM WCI. | | | @@ -21,16 +22,12 @@ | Technologies at info[AT]zyxware[DOT]com. | +--------------------------------------------------------------------+ */ -/** - * - * @package CRM - * @copyright CiviCRM LLC (c) 2004-2013 - * $Id$ - */ -require_once '../../../civicrm.config.php'; +require_once 'CRM/Core/Page.php'; -$license_text = ' +class CRM_Wci_Page_Embed extends CRM_Core_Page { + function run() { + $license_text = ' /** * @licstart The following is the entire license notice for the JavaScript * code included by CiviCRM WCI extension. @@ -49,7 +46,8 @@ $license_text = ' * code included by CiviCRM WCI extension. */ '; -$wciembed_js = ' + + $wciembed_js = ' // Cleanup functions for the document ready method if ( document.addEventListener ) { DOMContentLoaded = function() { @@ -90,15 +88,17 @@ function onReady( ) { document.getElementById("widgetwci").innerHTML = wciwidgetcode; }'; -$config = CRM_Core_Config::singleton(); - -$embedId = CRM_Utils_Request::retrieve('id', 'Positive', CRM_Core_DAO::$_nullObject); -$preview = CRM_Utils_Request::retrieve('preview', 'Positive', CRM_Core_DAO::$_nullObject); + $config = CRM_Core_Config::singleton(); -$output = $license_text; -$output .= 'var wciwidgetcode = ' . CRM_Wci_WidgetCode::get_widget_code($embedId, $preview) . ';'; -$output .= $wciembed_js; + $embedId = CRM_Utils_Request::retrieve('id', 'Positive', CRM_Core_DAO::$_nullObject); + $preview = CRM_Utils_Request::retrieve('preview', 'Positive', CRM_Core_DAO::$_nullObject); -echo $output; + $output = $license_text; + $output .= 'var wciwidgetcode = ' . CRM_Wci_WidgetCode::get_widget_code($embedId, $preview) . ';'; + $output .= $wciembed_js; -CRM_Utils_System::civiExit(); + header('Content-Type: text/javascript'); + echo $output; + CRM_Utils_System::civiExit(); + } +} diff --git a/CRM/Wci/WidgetCode.php b/CRM/Wci/WidgetCode.php index a1c7f36..c243cd0 100644 --- a/CRM/Wci/WidgetCode.php +++ b/CRM/Wci/WidgetCode.php @@ -22,7 +22,7 @@ +--------------------------------------------------------------------+ */ -require_once '../wci-helper-functions.php'; +require_once 'wci-helper-functions.php'; class CRM_Wci_WidgetCode { diff --git a/templates/CRM/Wci/Form/CreateWidget.tpl b/templates/CRM/Wci/Form/CreateWidget.tpl index 3cccadd..fb6a44a 100644 --- a/templates/CRM/Wci/Form/CreateWidget.tpl +++ b/templates/CRM/Wci/Form/CreateWidget.tpl @@ -3,6 +3,7 @@ | CiviCRM Widget Creation Interface (WCI) Version 1.0 | +--------------------------------------------------------------------+ | Copyright Zyxware Technologies (c) 2014 | + | Copyright (C) 2014 David Thompson | +--------------------------------------------------------------------+ | This file is a part of CiviCRM WCI. | | | @@ -27,13 +28,6 @@ {if $form.title.value != ""} - {php} - if(isset($_REQUEST['id'])) { - $widget_controller_path = getWciWidgetControllerPath(); - $extension_root_path = getExtensionRootPath(); - } - {/php} -
Widget Preview
@@ -42,7 +36,7 @@
Click Save & Preview to save any changes to your settings, and preview the widget again on this page.
- +
{help id="preview" file="CRM/Wci/Form/CreateWidget"}
diff --git a/templates/CRM/Wci/Form/NewEmbedCode.tpl b/templates/CRM/Wci/Form/NewEmbedCode.tpl index 68172c7..f2ad29f 100644 --- a/templates/CRM/Wci/Form/NewEmbedCode.tpl +++ b/templates/CRM/Wci/Form/NewEmbedCode.tpl @@ -3,6 +3,7 @@ | CiviCRM Widget Creation Interface (WCI) Version 1.0 | +--------------------------------------------------------------------+ | Copyright Zyxware Technologies (c) 2014 | + | Copyright (C) 2014 David Thompson | +--------------------------------------------------------------------+ | This file is a part of CiviCRM WCI. | | | @@ -35,16 +36,8 @@
{/foreach} - {if $form.title.value != ""} - {php} - if(isset($_REQUEST['id'])) { - $emb_id = $_REQUEST['id']; - $wid_id = CRM_Wci_BAO_EmbedCode::getWidgetId($emb_id); - $widget_controller_path = getWciWidgetControllerPath(); - $extension_root_path = getExtensionRootPath(); - } - {/php} + {if $form.title.value != ""}
@@ -54,15 +47,17 @@
Click Save & Preview to save any changes to your settings, and preview the widget again on this page.
- -
+ +
Add this widget to any web page by copying and pasting the code below.
- +
» Select Code diff --git a/wci-helper-functions.php b/wci-helper-functions.php index 8dc4b0f..b2c021b 100644 --- a/wci-helper-functions.php +++ b/wci-helper-functions.php @@ -35,16 +35,6 @@ return $options; } - function getExtensionRootPath() { - return 'http://' . $_SERVER['SERVER_NAME'] . str_replace($_SERVER['DOCUMENT_ROOT'], '', __DIR__); - } - - function getWciWidgetControllerPath() { - $widget_controller_path = getExtensionRootPath() . '/extern/embed.php'; - - return $widget_controller_path; - } - function getWciWidgetTemplatePath() { $widget_tpl_path = __DIR__ . '/templates/CRM/Wci/Page'; diff --git a/xml/Menu/wci.xml b/xml/Menu/wci.xml index d073232..7284cbb 100644 --- a/xml/Menu/wci.xml +++ b/xml/Menu/wci.xml @@ -48,4 +48,10 @@ ManageEmbedCode access CiviCRM + + civicrm/wci/embed + CRM_Wci_Page_Embed + Embed + access CiviCRM + -- 2.25.1