function wikiplugin_piwik($data, $params) { global $prefs; $plugininfo = wikiplugin_piwik_info(); $default = array(); foreach ($plugininfo['params'] as $key => $param) { $default["{$key}"] = $param['default']; } $params = array_merge($default, $params); if (empty($params['piwikserverurl'])) { $params['piwikserverurl'] = $prefs['site_piwik_analytics_server_url']; } if (empty($params['piwikserverurl'])) { return tra('Plugin Piwik error:') . ' ' . tra('Piwik server url is required.'); } if (empty($params['idSite'])) { $params['idSite'] = $prefs['site_piwik_site_id']; } if (empty($params['idSite'])) { return tra('Plugin Piwik error:') . ' ' . tra('Site Id is required.'); } if (empty($params['moduleToWidgetize'])) { return tra('Plugin Piwik error:') . ' ' . tra('moduleToWidgetize is required.'); } else { $arr = explode(',', $params['moduleToWidgetize']); $params['moduleToWidgetize'] = $arr[0]; $params['actionToWidgetize'] = $arr[1]; } if ($params['period'] === 'range') { if ($params['enddate']) { $params['date'] .= ',' . $params['enddate']; unset($params['enddate']); } else { return tra('Plugin Piwik error:') . ' ' . tra('Period set to range but no end date provided.'); } } // grab out the params that aren't going to be part of the url, they will be iframe attributes and start with an underscore $attributes = ''; foreach ($params as $key => $value) { if (strpos($key, '_') === 0) { if ($value) { $attributes .= ' ' . substr($key, 1) . '="' . $value . '"'; } unset($params[$key]); } } // parse the main url param and unset it $url_parts = parse_url($params['piwikserverurl']); unset($params['piwikserverurl']); // add the fixed query params $params['module'] = 'Widgetize'; $params['action'] = 'iframe'; $params['disableLink'] = 1; $params['widget=1'] = 1; // parse the query part of the url into an array parse_str($url_parts['query'], $query); // merge the params and the fixed ones $query = array_merge($params, $query); // convert back to a string and replace in the parts array $url_parts['query'] = http_build_query($query, '', '&'); $url = TikiLib::unparse_url($url_parts); $iframe = '<iframe src="' . $url . '" ' . $attributes . ' frameborder="0"></iframe>'; return $iframe; }