diff options
author | mattab <matthieu.aubry@gmail.com> | 2013-03-28 03:42:39 +0400 |
---|---|---|
committer | mattab <matthieu.aubry@gmail.com> | 2013-03-28 03:42:40 +0400 |
commit | ae4b03163792f0b6e933933e5d37df87dc3fd566 (patch) | |
tree | d1d7510a9728f587d3d63ebd03e4ecf3d904838b /plugins/Widgetize | |
parent | 158c2150f5f2e13ece459b8d131244c11b763997 (diff) |
Mass conversion of all files to the newly agreed coding standard: PSR 1/2
Converting Piwik core source files, PHP, JS, TPL, CSS
More info: http://piwik.org/participate/coding-standards/
Diffstat (limited to 'plugins/Widgetize')
-rw-r--r-- | plugins/Widgetize/Controller.php | 120 | ||||
-rw-r--r-- | plugins/Widgetize/Widgetize.php | 112 | ||||
-rw-r--r-- | plugins/Widgetize/templates/iframe.tpl | 24 | ||||
-rw-r--r-- | plugins/Widgetize/templates/index.tpl | 165 | ||||
-rw-r--r-- | plugins/Widgetize/templates/js.tpl | 36 | ||||
-rw-r--r-- | plugins/Widgetize/templates/test_jsinclude.tpl | 7 | ||||
-rw-r--r-- | plugins/Widgetize/templates/widgetize.js | 148 |
7 files changed, 317 insertions, 295 deletions
diff --git a/plugins/Widgetize/Controller.php b/plugins/Widgetize/Controller.php index cf084197b1..6441a84b48 100644 --- a/plugins/Widgetize/Controller.php +++ b/plugins/Widgetize/Controller.php @@ -1,77 +1,77 @@ <?php /** * Piwik - Open source web analytics - * + * * @link http://piwik.org * @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later - * + * * @category Piwik_Plugins * @package Piwik_Widgetize */ /** - * + * * @package Piwik_Widgetize */ class Piwik_Widgetize_Controller extends Piwik_Controller { - function index() - { - $view = Piwik_View::factory('index'); - $view->availableWidgets = Piwik_Common::json_encode(Piwik_GetWidgetsList()); - $this->setGeneralVariablesView($view); - echo $view->render(); - } + function index() + { + $view = Piwik_View::factory('index'); + $view->availableWidgets = Piwik_Common::json_encode(Piwik_GetWidgetsList()); + $this->setGeneralVariablesView($view); + echo $view->render(); + } - function testJsInclude1() - { - $view = Piwik_View::factory('test_jsinclude'); - $view->url1 = '?module=Widgetize&action=js&moduleToWidgetize=UserSettings&actionToWidgetize=getBrowser&idSite=1&period=day&date=yesterday'; - $view->url2 = '?module=Widgetize&action=js&moduleToWidgetize=API&actionToWidgetize=index&method=ExamplePlugin.getGoldenRatio&format=original'; - echo $view->render(); - } - - function testJsInclude2() - { - $view = Piwik_View::factory('test_jsinclude2'); - $view->url1 = '?module=Widgetize&action=js&moduleToWidgetize=UserSettings&actionToWidgetize=getBrowser&idSite=1&period=day&date=yesterday'; - $view->url2 = '?module=Widgetize&action=js&moduleToWidgetize=UserCountry&actionToWidgetize=getCountry&idSite=1&period=day&date=yesterday&viewDataTable=cloud&show_footer=0'; - $view->url3 = '?module=Widgetize&action=js&moduleToWidgetize=Referers&actionToWidgetize=getKeywords&idSite=1&period=day&date=yesterday&viewDataTable=table&show_footer=0'; - echo $view->render(); - } - - /** - * Disabled for now, not obvious that this is useful (iframe sounds like a better solution) - */ - private function js() - { - Piwik_API_Request::reloadAuthUsingTokenAuth(); - $controllerName = Piwik_Common::getRequestVar('moduleToWidgetize'); - $actionName = Piwik_Common::getRequestVar('actionToWidgetize'); - $parameters = array ( $fetch = true ); - $content = Piwik_FrontController::getInstance()->fetchDispatch( $controllerName, $actionName, $parameters); - $view = Piwik_View::factory('js'); - $content = str_replace(array("\t","\n","\r\n","\r"), "", $content); - $view->content = $content; - echo $view->render(); - } + function testJsInclude1() + { + $view = Piwik_View::factory('test_jsinclude'); + $view->url1 = '?module=Widgetize&action=js&moduleToWidgetize=UserSettings&actionToWidgetize=getBrowser&idSite=1&period=day&date=yesterday'; + $view->url2 = '?module=Widgetize&action=js&moduleToWidgetize=API&actionToWidgetize=index&method=ExamplePlugin.getGoldenRatio&format=original'; + echo $view->render(); + } - function iframe() - { - Piwik_API_Request::reloadAuthUsingTokenAuth(); - $this->init(); - $controllerName = Piwik_Common::getRequestVar('moduleToWidgetize'); - $actionName = Piwik_Common::getRequestVar('actionToWidgetize'); - $parameters = array ( $fetch = true ); - $outputDataTable = Piwik_FrontController::getInstance()->fetchDispatch( $controllerName, $actionName, $parameters); - if($controllerName == 'Dashboard' && $actionName == 'index') { - $view = Piwik_View::factory('empty'); - } else { - $view = Piwik_View::factory('iframe'); - } - $this->setGeneralVariablesView($view); - $view->setXFrameOptions('allow'); - $view->content = $outputDataTable; - echo $view->render(); - } + function testJsInclude2() + { + $view = Piwik_View::factory('test_jsinclude2'); + $view->url1 = '?module=Widgetize&action=js&moduleToWidgetize=UserSettings&actionToWidgetize=getBrowser&idSite=1&period=day&date=yesterday'; + $view->url2 = '?module=Widgetize&action=js&moduleToWidgetize=UserCountry&actionToWidgetize=getCountry&idSite=1&period=day&date=yesterday&viewDataTable=cloud&show_footer=0'; + $view->url3 = '?module=Widgetize&action=js&moduleToWidgetize=Referers&actionToWidgetize=getKeywords&idSite=1&period=day&date=yesterday&viewDataTable=table&show_footer=0'; + echo $view->render(); + } + + /** + * Disabled for now, not obvious that this is useful (iframe sounds like a better solution) + */ + private function js() + { + Piwik_API_Request::reloadAuthUsingTokenAuth(); + $controllerName = Piwik_Common::getRequestVar('moduleToWidgetize'); + $actionName = Piwik_Common::getRequestVar('actionToWidgetize'); + $parameters = array($fetch = true); + $content = Piwik_FrontController::getInstance()->fetchDispatch($controllerName, $actionName, $parameters); + $view = Piwik_View::factory('js'); + $content = str_replace(array("\t", "\n", "\r\n", "\r"), "", $content); + $view->content = $content; + echo $view->render(); + } + + function iframe() + { + Piwik_API_Request::reloadAuthUsingTokenAuth(); + $this->init(); + $controllerName = Piwik_Common::getRequestVar('moduleToWidgetize'); + $actionName = Piwik_Common::getRequestVar('actionToWidgetize'); + $parameters = array($fetch = true); + $outputDataTable = Piwik_FrontController::getInstance()->fetchDispatch($controllerName, $actionName, $parameters); + if ($controllerName == 'Dashboard' && $actionName == 'index') { + $view = Piwik_View::factory('empty'); + } else { + $view = Piwik_View::factory('iframe'); + } + $this->setGeneralVariablesView($view); + $view->setXFrameOptions('allow'); + $view->content = $outputDataTable; + echo $view->render(); + } } diff --git a/plugins/Widgetize/Widgetize.php b/plugins/Widgetize/Widgetize.php index 556e46c396..0201cfd9ef 100644 --- a/plugins/Widgetize/Widgetize.php +++ b/plugins/Widgetize/Widgetize.php @@ -2,74 +2,74 @@ /** * Piwik - Open source web analytics - * + * * @link http://piwik.org * @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later - * + * * @category Piwik_Plugins * @package Piwik_Widgetize */ /** - * + * * @package Piwik_Widgetize */ -class Piwik_Widgetize extends Piwik_Plugin +class Piwik_Widgetize extends Piwik_Plugin { - public function getInformation() - { - return array( - 'description' => Piwik_Translate('Widgetize_PluginDescription'), - 'author' => 'Piwik', - 'author_homepage' => 'http://piwik.org/', - 'version' => Piwik_Version::VERSION, - ); - } - - public function getListHooksRegistered() - { - return array( - 'AssetManager.getJsFiles' => 'getJsFiles', - 'AssetManager.getCssFiles' => 'getCssFiles', - 'TopMenu.add' => 'addTopMenu', - ); - } - - public function addTopMenu() - { - $tooltip = Piwik_Translate('Widgetize_TopLinkTooltip'); - $urlParams = array('module' => 'Widgetize', 'action' => 'index'); - - Piwik_AddTopMenu('General_Widgets', $urlParams, true, 5, $isHTML = false, $tooltip); - } + public function getInformation() + { + return array( + 'description' => Piwik_Translate('Widgetize_PluginDescription'), + 'author' => 'Piwik', + 'author_homepage' => 'http://piwik.org/', + 'version' => Piwik_Version::VERSION, + ); + } - /** - * @param Piwik_Event_Notification $notification notification object - */ - function getJsFiles($notification) - { - $jsFiles = &$notification->getNotificationObject(); + public function getListHooksRegistered() + { + return array( + 'AssetManager.getJsFiles' => 'getJsFiles', + 'AssetManager.getCssFiles' => 'getCssFiles', + 'TopMenu.add' => 'addTopMenu', + ); + } - $jsFiles[] = "libs/jquery/jquery.tooltip.js"; - $jsFiles[] = "libs/jquery/jquery.truncate.js"; - $jsFiles[] = "libs/jquery/jquery.scrollTo.js"; - $jsFiles[] = "themes/default/common.js"; - $jsFiles[] = "plugins/CoreHome/templates/datatable.js"; - $jsFiles[] = "plugins/Dashboard/templates/widgetMenu.js"; - $jsFiles[] = "plugins/Widgetize/templates/widgetize.js"; - } + public function addTopMenu() + { + $tooltip = Piwik_Translate('Widgetize_TopLinkTooltip'); + $urlParams = array('module' => 'Widgetize', 'action' => 'index'); - /** - * @param Piwik_Event_Notification $notification notification object - */ - function getCssFiles($notification) - { - $cssFiles = &$notification->getNotificationObject(); - - $cssFiles[] = "plugins/CoreHome/templates/styles.css"; - $cssFiles[] = "plugins/CoreHome/templates/datatable.css"; - $cssFiles[] = "plugins/CoreHome/templates/cloud.css"; - $cssFiles[] = "plugins/Dashboard/templates/dashboard.css"; - } + Piwik_AddTopMenu('General_Widgets', $urlParams, true, 5, $isHTML = false, $tooltip); + } + + /** + * @param Piwik_Event_Notification $notification notification object + */ + function getJsFiles($notification) + { + $jsFiles = & $notification->getNotificationObject(); + + $jsFiles[] = "libs/jquery/jquery.tooltip.js"; + $jsFiles[] = "libs/jquery/jquery.truncate.js"; + $jsFiles[] = "libs/jquery/jquery.scrollTo.js"; + $jsFiles[] = "themes/default/common.js"; + $jsFiles[] = "plugins/CoreHome/templates/datatable.js"; + $jsFiles[] = "plugins/Dashboard/templates/widgetMenu.js"; + $jsFiles[] = "plugins/Widgetize/templates/widgetize.js"; + } + + /** + * @param Piwik_Event_Notification $notification notification object + */ + function getCssFiles($notification) + { + $cssFiles = & $notification->getNotificationObject(); + + $cssFiles[] = "plugins/CoreHome/templates/styles.css"; + $cssFiles[] = "plugins/CoreHome/templates/datatable.css"; + $cssFiles[] = "plugins/CoreHome/templates/cloud.css"; + $cssFiles[] = "plugins/Dashboard/templates/dashboard.css"; + } } diff --git a/plugins/Widgetize/templates/iframe.tpl b/plugins/Widgetize/templates/iframe.tpl index 9ca106f5ef..eb8287098a 100644 --- a/plugins/Widgetize/templates/iframe.tpl +++ b/plugins/Widgetize/templates/iframe.tpl @@ -1,22 +1,22 @@ <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" - "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> + "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> -<meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> -{loadJavascriptTranslations plugins='CoreHome'} -{include file="CoreHome/templates/js_global_variables.tpl"} -<!--[if lt IE 9]> -<script language="javascript" type="text/javascript" src="libs/jqplot/excanvas.min.js"></script> -<![endif]--> -{include file="CoreHome/templates/js_css_includes.tpl"} -<!--[if IE]> -<link rel="stylesheet" type="text/css" href="themes/default/ieonly.css" /> -<![endif]--> + <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/> + {loadJavascriptTranslations plugins='CoreHome'} + {include file="CoreHome/templates/js_global_variables.tpl"} + <!--[if lt IE 9]> + <script language="javascript" type="text/javascript" src="libs/jqplot/excanvas.min.js"></script> + <![endif]--> + {include file="CoreHome/templates/js_css_includes.tpl"} + <!--[if IE]> + <link rel="stylesheet" type="text/css" href="themes/default/ieonly.css"/> + <![endif]--> </head> <body> <div class="widget"> -{$content} + {$content} </div> </body> diff --git a/plugins/Widgetize/templates/index.tpl b/plugins/Widgetize/templates/index.tpl index 854e4e92da..d29684958f 100644 --- a/plugins/Widgetize/templates/index.tpl +++ b/plugins/Widgetize/templates/index.tpl @@ -6,71 +6,74 @@ {literal} -<style type="text/css"> -.widgetize{ - width:100%; - padding:15px 15px 0 15px; - font-size:13px; -} -.widgetize p{ - padding: 0 0 20px 0; -} -.menu { - display: inline; -} -.widgetize .formEmbedCode{ - font-size: 11px; - text-decoration: none; - background-color: #FBFDFF; - border: 1px solid #ECECEC; - width:220px; -} - -#periodString { - margin-left:15px; -} - -.widgetize label { - color:#666666; - line-height:18px; - margin-right:5px; - font-weight:bold; - padding-bottom:100px; -} - -#embedThisWidgetIframe, -#embedThisWidgetFlash, -#embedThisWidgetEverywhere { - margin-top:5px; -} - -.menuSelected{ - font-weight:bold; -} -</style> + <style type="text/css"> + .widgetize { + width: 100%; + padding: 15px 15px 0 15px; + font-size: 13px; + } + + .widgetize p { + padding: 0 0 20px 0; + } + + .menu { + display: inline; + } + + .widgetize .formEmbedCode { + font-size: 11px; + text-decoration: none; + background-color: #FBFDFF; + border: 1px solid #ECECEC; + width: 220px; + } + + #periodString { + margin-left: 15px; + } + + .widgetize label { + color: #666666; + line-height: 18px; + margin-right: 5px; + font-weight: bold; + padding-bottom: 100px; + } + + #embedThisWidgetIframe, + #embedThisWidgetFlash, + #embedThisWidgetEverywhere { + margin-top: 5px; + } + + .menuSelected { + font-weight: bold; + } + </style> {/literal} <script type="text/javascript"> -{literal} -$(document).ready( function() { - var widgetized = new widgetize(); - var urlPath = document.location.protocol + '//' + document.location.hostname + (document.location.port == '' ? '' : (':' + document.location.port)) + document.location.pathname ; - var dashboardUrl = urlPath + '?module=Widgetize&action=iframe&moduleToWidgetize=Dashboard&actionToWidgetize=index&idSite='+piwik.idSite+'&period=week&date=yesterday'; - $('#exportFullDashboard').html( - widgetized.getInputFormWithHtml( 'dashboardEmbed', '<iframe src="'+ dashboardUrl +'" frameborder="0" marginheight="0" marginwidth="0" width="100%" height="100%"></iframe>') - ); - $('#linkDashboardUrl').attr('href',dashboardUrl); - - var allWebsitesDashboardUrl = urlPath + '?module=Widgetize&action=iframe&moduleToWidgetize=MultiSites&actionToWidgetize=standalone&idSite='+piwik.idSite+'&period=week&date=yesterday'; - $('#exportAllWebsitesDashboard').html( - widgetized.getInputFormWithHtml( 'allWebsitesDashboardEmbed', '<iframe src="'+ allWebsitesDashboardUrl +'" frameborder="0" marginheight="0" marginwidth="0" width="100%" height="100%"></iframe>') - ); - $('#linkAllWebsitesDashboardUrl').attr('href',allWebsitesDashboardUrl); - $('#widgetPreview').widgetPreview({ - onPreviewLoaded: widgetized.callbackAddExportButtonsUnderWidget + {literal} + $(document).ready(function () { + var widgetized = new widgetize(); + var urlPath = document.location.protocol + '//' + document.location.hostname + (document.location.port == '' ? '' : (':' + document.location.port)) + document.location.pathname; + var dashboardUrl = urlPath + '?module=Widgetize&action=iframe&moduleToWidgetize=Dashboard&actionToWidgetize=index&idSite=' + piwik.idSite + '&period=week&date=yesterday'; + $('#exportFullDashboard').html( + widgetized.getInputFormWithHtml('dashboardEmbed', '<iframe src="' + dashboardUrl + '" frameborder="0" marginheight="0" marginwidth="0" width="100%" height="100%"></iframe>') + ); + $('#linkDashboardUrl').attr('href', dashboardUrl); + + var allWebsitesDashboardUrl = urlPath + '?module=Widgetize&action=iframe&moduleToWidgetize=MultiSites&actionToWidgetize=standalone&idSite=' + piwik.idSite + '&period=week&date=yesterday'; + $('#exportAllWebsitesDashboard').html( + widgetized.getInputFormWithHtml('allWebsitesDashboardEmbed', '<iframe src="' + allWebsitesDashboardUrl + '" frameborder="0" marginheight="0" marginwidth="0" width="100%" height="100%"></iframe>') + ); + $('#linkAllWebsitesDashboardUrl').attr('href', allWebsitesDashboardUrl); + $('#widgetPreview').widgetPreview({ + onPreviewLoaded: widgetized.callbackAddExportButtonsUnderWidget + }); }); -}); -{/literal} + {/literal} </script> <div class="top_controls_inner"> @@ -78,24 +81,34 @@ $(document).ready( function() { </div> <div class="widgetize"> - <p>With Piwik, you can export your Web Analytics reports on your blog, website, or intranet dashboard... in one click. - <p><b>› Widget authentication:</b> If you want your widgets to be viewable by everybody, you first have to set the 'view' permissions - to the anonymous user in the <a href='index.php?module=UsersManager' target='_blank'>Users Management section</a>. - <br />Alternatively, if you are publishing widgets on a password protected or private page, - you don't necessarily have to allow 'anonymous' to view your reports. In this case, you can add the secret token_auth parameter (found in the <a href='{url module=API action=listAllAPI}' target='_blank'>API page</a>) in the widget URL. - </p> - <p><b>› Widgetize the full dashboard:</b> You can also display the full Piwik dashboard in your application or website in an IFRAME (<a href='' target='_blank' id='linkDashboardUrl'>see example</a>). - The date parameter can be set to a specific calendar date, "today", or "yesterday". The period parameter can be set to "day", "week", "month", or "year". - The language parameter can be set to the language code of a translation, such as language=fr. - For example, for idSite=1 and date=yesterday, you can write: <span id='exportFullDashboard'></span> - </p> - <p><b>› Widgetize the all websites dashboard in an IFRAME</b> (<a href='' target='_blank' id='linkAllWebsitesDashboardUrl'>see example</a>) <span id='exportAllWebsitesDashboard'></span> - </p> - <p> <b>› Select a report, and copy paste in your page the embed code below the widget:</b> + <p>With Piwik, you can export your Web Analytics reports on your blog, website, or intranet dashboard... in one click. + + <p><b>› Widget authentication:</b> If you want your widgets to be viewable by everybody, you first have to set the 'view' permissions + to the anonymous user in the <a href='index.php?module=UsersManager' target='_blank'>Users Management section</a>. + <br/>Alternatively, if you are publishing widgets on a password protected or private page, + you don't necessarily have to allow 'anonymous' to view your reports. In this case, you can add the secret token_auth parameter (found in the <a + href='{url module=API action=listAllAPI}' target='_blank'>API page</a>) in the widget URL. + </p> + + <p><b>› Widgetize the full dashboard:</b> You can also display the full Piwik dashboard in your application or website in an IFRAME (<a href='' + target='_blank' + id='linkDashboardUrl'>see + example</a>). + The date parameter can be set to a specific calendar date, "today", or "yesterday". The period parameter can be set to "day", "week", "month", or + "year". + The language parameter can be set to the language code of a translation, such as language=fr. + For example, for idSite=1 and date=yesterday, you can write: <span id='exportFullDashboard'></span> + </p> + + <p><b>› Widgetize the all websites dashboard in an IFRAME</b> (<a href='' target='_blank' id='linkAllWebsitesDashboardUrl'>see example</a>) <span + id='exportAllWebsitesDashboard'></span> + </p> + + <p><b>› Select a report, and copy paste in your page the embed code below the widget:</b> <div id="widgetPreview"></div> - <div id='iframeDivToExport' style='display:none;'></div> + <div id='iframeDivToExport' style='display:none;'></div> </div> diff --git a/plugins/Widgetize/templates/js.tpl b/plugins/Widgetize/templates/js.tpl index 8c81a44bf1..8976875413 100644 --- a/plugins/Widgetize/templates/js.tpl +++ b/plugins/Widgetize/templates/js.tpl @@ -1,18 +1,30 @@ {loadJavascriptTranslations disableOutputScriptTag=1 plugins='CoreHome'} -document.write('<link rel="stylesheet" type="text/css" href="{$piwikUrl}themes/default/common.css" />'); -document.write('<link rel="stylesheet" type="text/css" href="{$piwikUrl}plugins/CoreHome/templates/styles.css" />'); -document.write('<link rel="stylesheet" type="text/css" href="{$piwikUrl}plugins/CoreHome/templates/datatable.css" />'); -document.write('<link rel="stylesheet" type="text/css" href="{$piwikUrl}plugins/CoreHome/templates/cloud.css" />'); +document.write(' +<link rel="stylesheet" type="text/css" href="{$piwikUrl}themes/default/common.css"/>'); +document.write(' +<link rel="stylesheet" type="text/css" href="{$piwikUrl}plugins/CoreHome/templates/styles.css"/>'); +document.write(' +<link rel="stylesheet" type="text/css" href="{$piwikUrl}plugins/CoreHome/templates/datatable.css"/>'); +document.write(' +<link rel="stylesheet" type="text/css" href="{$piwikUrl}plugins/CoreHome/templates/cloud.css"/>'); -document.write('<scr'+'ipt type="text/javascript" src="{$piwikUrl}libs/jquery/jquery.js"></scr'+'ipt>'); -document.write('<scr'+'ipt type="text/javascript" src="{$piwikUrl}libs/jquery/jquery-ui.js"></scr'+'ipt>'); -document.write('<scr'+'ipt type="text/javascript" src="{$piwikUrl}libs/jquery/jquery.tooltip.js"></scr'+'ipt>'); -document.write('<scr'+'ipt type="text/javascript" src="{$piwikUrl}libs/jquery/jquery.truncate.js"></scr'+'ipt>'); -document.write('<scr'+'ipt type="text/javascript" src="{$piwikUrl}libs/javascript/sprintf.js"></scr'+'ipt>'); -document.write('<scr'+'ipt type="text/javascript" src="{$piwikUrl}themes/default/common.js"></scr'+'ipt>'); -document.write('<scr'+'ipt type="text/javascript" src="{$piwikUrl}plugins/CoreHome/templates/datatable.js"></scr'+'ipt>'); +document.write(' +<scr'+'ipt type="text/javascript" src="{$piwikUrl}libs/jquery/jquery.js"></scr'+'ipt>'); +document.write(' +<scr'+'ipt type="text/javascript" src="{$piwikUrl}libs/jquery/jquery-ui.js"></scr'+'ipt>'); +document.write(' +<scr'+'ipt type="text/javascript" src="{$piwikUrl}libs/jquery/jquery.tooltip.js"></scr'+'ipt>'); +document.write(' +<scr'+'ipt type="text/javascript" src="{$piwikUrl}libs/jquery/jquery.truncate.js"></scr'+'ipt>'); +document.write(' +<scr'+'ipt type="text/javascript" src="{$piwikUrl}libs/javascript/sprintf.js"></scr'+'ipt>'); +document.write(' +<scr'+'ipt type="text/javascript" src="{$piwikUrl}themes/default/common.js"></scr'+'ipt>'); +document.write(' +<scr'+'ipt type="text/javascript" src="{$piwikUrl}plugins/CoreHome/templates/datatable.js"></scr'+'ipt>'); var content = '{$content|escape:'javascript'}'; -document.write('<scr'+'ipt type="text/javascript">document.write(content)</scr'+'ipt>'); +document.write(' +<scr'+'ipt type="text/javascript">document.write(content)</scr'+'ipt>'); diff --git a/plugins/Widgetize/templates/test_jsinclude.tpl b/plugins/Widgetize/templates/test_jsinclude.tpl index b2416acee3..10800a14c2 100644 --- a/plugins/Widgetize/templates/test_jsinclude.tpl +++ b/plugins/Widgetize/templates/test_jsinclude.tpl @@ -6,12 +6,15 @@ <h2>Test tag cloud in a JS include</h2> <div style="width:500px"> -<script type="text/javascript" src="{$url1}"></script> -<noscript>Powered by <a href="http://piwik.org">Piwik</a></div></noscript> + <script type="text/javascript" src="{$url1}"></script> + <noscript>Powered by <a href="http://piwik.org">Piwik</a> +</div> +</noscript> </div> <p>This text is after the JS INCLUDE</p> <h2>Test calling the API in Javascript</h2> + <p>using a javascript include. This is a dirty way (much better to ajax call the API!) but an interesting show case.</P> <script type="text/javascript" src="{$url2}"></script> <noscript>Powered by <a href="http://piwik.org">Piwik</a></div></noscript> diff --git a/plugins/Widgetize/templates/widgetize.js b/plugins/Widgetize/templates/widgetize.js index ec8595eabf..e54210642f 100644 --- a/plugins/Widgetize/templates/widgetize.js +++ b/plugins/Widgetize/templates/widgetize.js @@ -5,84 +5,78 @@ * @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later */ -function widgetize() -{ - var self = this; - - this.getInputFormWithHtml = function(inputId, htmlEmbed) - { - return '<input class="formEmbedCode" id="'+inputId+'" value="'+ htmlEmbed.replace(/"/g, '"') +'" onclick="javascript:document.getElementById(\''+inputId+'\').focus();document.getElementById(\''+inputId+'\').select();" readonly="true" type="text" />'; - } - - this.getEmbedUrl = function( parameters, exportFormat ) - { - copyParameters = {}; - for(var variableName in parameters) { - copyParameters[variableName] = parameters[variableName]; - } - copyParameters['moduleToWidgetize'] = parameters['module']; - copyParameters['actionToWidgetize'] = parameters['action']; - delete copyParameters['action']; - delete copyParameters['module']; - var sourceUrl; - sourceUrl = document.location.protocol + '//' + document.location.hostname + (document.location.port == '' ? '' : (':' + document.location.port)) + document.location.pathname + '?'; - sourceUrl += "module=Widgetize" + - "&action="+exportFormat+ - "&"+piwikHelper.getQueryStringFromParameters(copyParameters)+ - "&idSite="+piwik.idSite+ - "&period="+piwik.period+ - "&date="+broadcast.getValueFromUrl('date')+ - "&disableLink=1&widget=1"; - return sourceUrl; - } - - this.htmlentities = function(s) - { - return s.replace( /[<>&]/g, function(m) { return "&" + m.charCodeAt(0) + ";"; }); - } - - this.callbackAddExportButtonsUnderWidget = function ( widgetUniqueId, - loadedWidgetElement) - { - widget = widgetsHelper.getWidgetObjectFromUniqueId(widgetUniqueId); - widgetName = widget["name"]; - widgetParameters = widget['parameters']; - - var exportButtonsElement = $('<span id="exportButtons">'); +function widgetize() { + var self = this; - var urlIframe = self.getEmbedUrl(widgetParameters, "iframe"); - // We first build the HTML code that will load the widget in an IFRAME - var widgetIframeHtml = '<div id="widgetIframe">'+ - '<iframe width="100%" height="350" src="'+ - urlIframe + - '" scrolling="no" frameborder="0" marginheight="0" marginwidth="0">'+ - '</iframe>'+ - '</div>'; + this.getInputFormWithHtml = function (inputId, htmlEmbed) { + return '<input class="formEmbedCode" id="' + inputId + '" value="' + htmlEmbed.replace(/"/g, '"') + '" onclick="javascript:document.getElementById(\'' + inputId + '\').focus();document.getElementById(\'' + inputId + '\').select();" readonly="true" type="text" />'; + } - // Add the input field containing the widget in an Iframe - $(exportButtonsElement).append( - '<div id="embedThisWidgetIframe">'+ - '<label for="embedThisWidgetIframeInput">› Embed Iframe</label>'+ - '<span id="embedThisWidgetIframeInput">'+ - self.getInputFormWithHtml('iframeEmbed', widgetIframeHtml)+ - '</span>'+ - '</div>' + - '<div> <label for="embedThisWidgetDirectLink">› Direct Link</label>'+ - '<span id="embedThisWidgetDirectLink"> '+self.getInputFormWithHtml('directLinkEmbed', urlIframe)+' - <a href="'+urlIframe+'" target="_blank">'+_pk_translate('General_OpenInNewWindow_js')+'</a></span>' - +'</div>' - ); - - // We then replace the div iframeDivToExport with the actual Iframe html - $('#iframeDivToExport') - .html(widgetIframeHtml); + this.getEmbedUrl = function (parameters, exportFormat) { + copyParameters = {}; + for (var variableName in parameters) { + copyParameters[variableName] = parameters[variableName]; + } + copyParameters['moduleToWidgetize'] = parameters['module']; + copyParameters['actionToWidgetize'] = parameters['action']; + delete copyParameters['action']; + delete copyParameters['module']; + var sourceUrl; + sourceUrl = document.location.protocol + '//' + document.location.hostname + (document.location.port == '' ? '' : (':' + document.location.port)) + document.location.pathname + '?'; + sourceUrl += "module=Widgetize" + + "&action=" + exportFormat + + "&" + piwikHelper.getQueryStringFromParameters(copyParameters) + + "&idSite=" + piwik.idSite + + "&period=" + piwik.period + + "&date=" + broadcast.getValueFromUrl('date') + + "&disableLink=1&widget=1"; + return sourceUrl; + } - // Finally we append the content to the parent widget DIV - $(loadedWidgetElement) - .parent() - .append(exportButtonsElement); - - // JS is buggy at least on IE - //var widgetJS = '<script type="text/javascript" src="'+ getEmbedUrl(pluginId, actionId, "js") +'"></scr'+'ipt>'; - //divEmbedThisWidget.append('<br />Embed JS: '+ getInputFormWithHtml('javascriptEmbed', widgetJS)); - } + this.htmlentities = function (s) { + return s.replace(/[<>&]/g, function (m) { return "&" + m.charCodeAt(0) + ";"; }); + } + + this.callbackAddExportButtonsUnderWidget = function (widgetUniqueId, loadedWidgetElement) { + widget = widgetsHelper.getWidgetObjectFromUniqueId(widgetUniqueId); + widgetName = widget["name"]; + widgetParameters = widget['parameters']; + + var exportButtonsElement = $('<span id="exportButtons">'); + + var urlIframe = self.getEmbedUrl(widgetParameters, "iframe"); + // We first build the HTML code that will load the widget in an IFRAME + var widgetIframeHtml = '<div id="widgetIframe">' + + '<iframe width="100%" height="350" src="' + + urlIframe + + '" scrolling="no" frameborder="0" marginheight="0" marginwidth="0">' + + '</iframe>' + + '</div>'; + + // Add the input field containing the widget in an Iframe + $(exportButtonsElement).append( + '<div id="embedThisWidgetIframe">' + + '<label for="embedThisWidgetIframeInput">› Embed Iframe</label>' + + '<span id="embedThisWidgetIframeInput">' + + self.getInputFormWithHtml('iframeEmbed', widgetIframeHtml) + + '</span>' + + '</div>' + + '<div> <label for="embedThisWidgetDirectLink">› Direct Link</label>' + + '<span id="embedThisWidgetDirectLink"> ' + self.getInputFormWithHtml('directLinkEmbed', urlIframe) + ' - <a href="' + urlIframe + '" target="_blank">' + _pk_translate('General_OpenInNewWindow_js') + '</a></span>' + + '</div>' + ); + + // We then replace the div iframeDivToExport with the actual Iframe html + $('#iframeDivToExport') + .html(widgetIframeHtml); + + // Finally we append the content to the parent widget DIV + $(loadedWidgetElement) + .parent() + .append(exportButtonsElement); + + // JS is buggy at least on IE + //var widgetJS = '<script type="text/javascript" src="'+ getEmbedUrl(pluginId, actionId, "js") +'"></scr'+'ipt>'; + //divEmbedThisWidget.append('<br />Embed JS: '+ getInputFormWithHtml('javascriptEmbed', widgetJS)); + } } |