function plgSh404sefAnalyticsCustomVars(&$customVars, $sefConfig) { // add custom variable : page creation time if ($sefConfig->analyticsEnableTimeCollection) { $profiler =& JProfiler::getInstance('sh404sef_profiler'); $profiler->mark(''); $pageCreationTime = $profiler->getBuffer(); //extract Data $pageCreationTime = str_replace('sh404sef_profiler : ', '', $pageCreationTime[0]); $tmp = explode(', ', $pageCreationTime); // we may have memory report attached $time = str_replace(' seconds', '', $tmp[0]); // classify exact time into predefined categories for encoding $time = Sh404sefHelperAnalytics::classifyTime($time); // same for memory used $memory = empty($tmp[1]) ? 0 : sh404sefHelperAnalytics::classifyMemory(str_replace(' MB', '', trim($tmp[1]))); // store results into incoming array $customVars[SH404SEF_ANALYTICS_TIME_CUSTOM_VAR]->name = 'Page creation time and ram'; $customVars[SH404SEF_ANALYTICS_TIME_CUSTOM_VAR]->value = ($time << 4) + $memory; } // add custom variable : user logged in if ($sefConfig->analyticsEnableUserCollection) { $user = JFactory::getUser(); $customVars[SH404SEF_ANALYTICS_USER_CUSTOM_VAR]->name = 'Logged-in user'; $userType = empty($user->usertype) ? 'anonymous' : $user->usertype; $customVars[SH404SEF_ANALYTICS_USER_CUSTOM_VAR]->value = htmlentities($userType, ENT_QUOTES, 'UTF-8'); } return true; }
/** * Prepare and display the control panel * dashboard, which is a simplified view * of main analytics results * * @param string $tpl layout name */ private function _makeViewDashboard($tpl) { // get configuration object $sefConfig =& Sh404sefFactory::getConfig(); // push it into to the view $this->assignRef('sefConfig', $sefConfig); // get analytics data using helper, possibly from cache $analyticsData = Sh404sefHelperAnalytics::getData($this->options); // push analytics stats into view $this->assign('analytics', $analyticsData); }
public function display($tpl = null) { // prepare the view, based on request // do we force reading updates from server ? $options = Sh404sefHelperAnalytics::getRequestOptions(); $method = '_makeView' . ucfirst($options['report']); if (is_callable(array($this, $method))) { $this->{$method}($tpl); } // push display options into template $this->assign('options', $options); // add our javascript JHTML::script('cp.js', Sh404sefHelperGeneral::getComponentUrl() . '/assets/js/'); // add Joomla calendar behavior, needed to input start and end dates if ($options['showFilters'] == 'yes') { JHTML::_('behavior.calendar'); } // add our own css JHtml::styleSheet('cp.css', Sh404sefHelperGeneral::getComponentUrl() . '/assets/css/'); // add tooltips handler JHTML::_('behavior.tooltip'); // add title $app =& JFactory::getApplication(); $title = Sh404sefHelperGeneral::makeToolbarTitle(JText16::_('COM_SH404SEF_ANALYTICS_MANAGER'), $icon = 'sh404sef', $class = 'sh404sef-toolbar-title'); $app->set('JComponentTitle', $title); // add a div to display our ajax-call-in-progress indicator // Get the JComponent instance of JToolBar $bar =& JToolBar::getInstance('toolbar'); $bar->addButtonPath(JPATH_COMPONENT . DS . 'classes'); $html = '<div id="sh-progress-cpprogress"></div>'; $bar->appendButton('custom', $html, 'sh-progress-button-cpprogress'); // add quick control panel loader $js = 'window.addEvent(\'domready\', function(){ shSetupAnalytics({report:" ' . $options['report'] . '"});});'; $document =& JFactory::getDocument(); $document->addScriptDeclaration($js); // flag to know if we should display placeholder for ajax fillin $this->assign('isAjaxTemplate', true); parent::display($tpl = null); }
/** * Connects to analytics supplier * * Meant to be overloaded by adapter * * @param $config , sef config object, holding connecton parameters */ protected function _connect() { // get the http client $hClient = & Sh404sefHelperAnalytics::getHttpClient(); // establish connection with available methods $adapters = array( 'Sh_Zend_Http_Client_Adapter_Curl', 'Sh_Zend_Http_Client_Adapter_Socket'); $rawResponse = null; // perform connect request foreach( $adapters as $adapter) { try { $hClient->setAdapter( $adapter); $rawResponse = $hClient->request(); break; } catch (Exception $e) { // need that to be Exception, so as to catch Sh_Zend_Exceptions.. as well // we failed, let's try another method //echo '<br />exception in _connect' . $e->getMessage(); } } // return if error if (empty( $rawResponse)) { $msg = 'unknown code'; throw new Sh404sefExceptionDefault( JText::sprintf('COM_SH404SEF_ERROR_CHECKING_ANALYTICS', $msg)); } if (!is_object( $rawResponse) || $rawResponse->isError()) { $msg = method_exists( $rawResponse, 'getStatus') ? $rawResponse->getStatus() : 'unknown code'; throw new Sh404sefExceptionDefault( JText::sprintf('COM_SH404SEF_ERROR_CHECKING_ANALYTICS', $msg)); } // success, return response return $rawResponse; }
case 'ga:visits': $title = JText16::_('COM_SH404SEF_ANALYTICS_DATA_VISITS_DESC_RAW'); break; case 'ga:visitors': $title = JText16::_('COM_SH404SEF_ANALYTICS_DATA_VISITORS_DESC_RAW'); break; case 'ga:pageviews': $title = JText16::_('COM_SH404SEF_ANALYTICS_GLOBAL_PAGEVIEWS_DESC_RAW'); break; default: $title = ''; break; } $title = Sh404sefHelperAnalytics::getDataTypeTitle() . (empty($title) ? '' : '::' . $title); ?> <div class="hasAnalyticsTip" title="<?php echo $title; ?> " > <fieldset> <?php echo '<legend>' . Sh404sefHelperAnalytics::getDataTypeTitle() . '</legend>'; echo '<div class="analytics-report-image"><img src="' . $this->analytics->analyticsData->images['visits'] . '" /></div>'; ?> </fieldset> </div>
/** * prepare html filters to allow user to select the way she likes * to view reports */ protected function _prepareFilters() { // array to hold various filters $filters = array(); // find if we must display all filters. On dashboard, only a reduced set $allFilters = $this->_options['showFilters'] == 'yes'; // select account to retrieve data for (or rather, profile $customSubmit = ' onchange="shSetupAnalytics({' . ($allFilters ? '' : 'showFilters:\'no\'') . '});"'; $select = Sh404sefHelperHtml::buildSelectList($this->_accounts, $this->_options['accountId'], 'accountId', $autoSubmit = false, $addSelectAll = false, $selectAllTitle = '', $customSubmit); $filters[] = JText::_('COM_SH404SEF_ANALYTICS_ACCOUNT') . ': ' . $select; // dashboard only has account selection, no room for anything else // only shows main selection drop downs on analytics view if ($allFilters) { // select start date $select = JHTML::_('calendar', $this->_options['startDate'], 'startDate', 'startDate', '%Y-%m-%d', 'class="textinput"'); $filters[] = ' ' . JText::_('COM_SH404SEF_ANALYTICS_START_DATE') . ': ' . $select; // select end date $select = JHTML::_('calendar', $this->_options['endDate'], 'endDate', 'endDate', '%Y-%m-%d', 'class="textinput"'); $filters[] = ' ' . JText::_('COM_SH404SEF_ANALYTICS_END_DATE') . ': ' . $select; // select groupBy (day, week, month) $select = Sh404sefHelperAnalytics::buildAnalyticsGroupBySelectList($this->_options['groupBy'], 'groupBy', $autoSubmit = false, $addSelectAll = false, $selectAllTitle = '', $customSubmit); $filters[] = ' ' . JText::_('COM_SH404SEF_ANALYTICS_GROUP_BY') . ': ' . $select; // add a click to update link $filters[] = ' <a href="javascript: void(0);" onclick="javascript: shSetupAnalytics({forced:1' . ($allFilters ? '' : ',showFilters:\'no\'') . '});" > [' . JText::_('COM_SH404SEF_CHECK_ANALYTICS') . ']</a>'; } else { // on dashboard, there is no date select, so we must display the date range $filters[] = ' ' . JText::_('COM_SH404SEF_ANALYTICS_DATE_RANGE') . ' <div class="largertext">' . $this->_options['startDate'] . ' >> ' . $this->_options['endDate'] . '</div>'; } return $filters; }
/** * Search for current site in account list, in order * to find its Google id. If not found, defaults to * first site in list * * @param array of object $accounts */ public static function getDefaultAccountId($accounts) { $id = 0; if (!empty($accounts)) { // search for current site $current = Sh404sefHelperAnalytics::getWebsiteName(); foreach ($accounts as $account) { if (strpos($current, $account->title) !== false or strpos(str_replace('www.', '', $current), $account->title) !== false) { $id = $account->id; break; } } // default to first account if no match found $id = empty($id) ? $accounts[0]->id : $id; } return $id; }
*/ // Security check to ensure this file is being included by a parent file. if (!defined('_JEXEC')) { die('Direct Access to this location is not allowed.'); } $title = JText::_('COM_SH404SEF_ANALYTICS_REPORT_SOURCES') . '::' . JText::_('COM_SH404SEF_ANALYTICS_DATA_SOURCES_DESC_RAW'); ?> <div class="hasAnalyticsTip width-100" title="<?php echo $title; ?> "> <fieldset class="adminform"> <legend> <?php echo JText::_('COM_SH404SEF_ANALYTICS_REPORT_SOURCES') . JText::_('COM_SH404SEF_ANALYTICS_REPORT_BY_LABEL') . Sh404sefHelperAnalytics::getDataTypeTitle(); ?> </legend> <ul class="adminformlist"> <li> <div class="analytics-report-image"><img src="<?php echo $this->analytics->analyticsData->images['sources']; ?> " /></div> </li> </ul> </fieldset> </div>
<?php /** * SEF module for Joomla! * * @author $Author: shumisha $ * @copyright Yannick Gaultier - 2007-2010 * @package sh404SEF-15 * @license http://www.gnu.org/copyleft/gpl.html GNU/GPL * @version $Id: default_sources.php 1600 2010-09-03 10:55:18Z silianacom-svn $ */ // Security check to ensure this file is being included by a parent file. if (!defined('_JEXEC')) { die('Direct Access to this location is not allowed.'); } $title = JText16::_('COM_SH404SEF_ANALYTICS_REPORT_SOURCES') . '::' . JText16::_('COM_SH404SEF_ANALYTICS_DATA_SOURCES_DESC_RAW'); ?> <div class="hasAnalyticsTip" title="<?php echo $title; ?> "> <fieldset > <?php echo '<legend>' . JText16::_('COM_SH404SEF_ANALYTICS_REPORT_SOURCES') . JText16::_('COM_SH404SEF_ANALYTICS_REPORT_BY_LABEL') . Sh404sefHelperAnalytics::getDataTypeTitle() . '</legend>'; echo '<div class="analytics-report-image"><img src="' . $this->analytics->analyticsData->images['sources'] . '" /></div>'; ?> </fieldset> </div>
protected function _query($type) { //perform request $response = $this->_client->request(); // check if authentified Sh404sefHelperAnalytics::verifyAuthResponse($response); // analyze response $parser = new DOMDocument(); $parser->loadXML($response->getBody()); $this->_rawData[$type] = $parser->getElementsByTagName('entry'); $this->_decodeXml($type); }
die('Direct Access to this location is not allowed.'); } switch ($this->sefConfig->analyticsDashboardDataType) { case 'ga:visits': $title = JText::_('COM_SH404SEF_ANALYTICS_DATA_VISITS_DESC_RAW'); break; case 'ga:visitors': $title = JText::_('COM_SH404SEF_ANALYTICS_DATA_VISITORS_DESC_RAW'); break; case 'ga:pageviews': $title = JText::_('COM_SH404SEF_ANALYTICS_GLOBAL_PAGEVIEWS_DESC_RAW'); break; default: $title = ''; break; } ?> <h2><?php echo Sh404sefHelperAnalytics::getDataTypeTitle(); ?> </h2> <div class="analytics-report-image"> <img rel="tooltip" <?php echo Sh404sefHelperHtml::wrapBootstrapTipTitle(Sh404sefHelperAnalytics::getDataTypeTitle(), $title); ?> src="<?php echo $this->analytics->analyticsData->images['visits']; ?> " /> </div>
/** * Connects to analytics supplier * * Meant to be overloaded by adapter * * @param $config , sef config object, holding connecton parameters */ protected function _connect() { // get the http client $hClient = Sh404sefHelperAnalytics::getHttpClient(); // establish connection with available methods $adapters = array('Zendshl_Http_Client_Adapter_Curl', 'Zendshl_Http_Client_Adapter_Socket'); $rawResponse = null; // perform connect request foreach ($adapters as $adapter) { try { $hClient->setAdapter($adapter); $rawResponse = $hClient->request(); break; } catch (Exception $e) { // we failed, let's try another method } } // return if error if (empty($rawResponse)) { $msg = 'unknown code'; ShlSystem_Log::debug('sh404sef', '%s::%s::%d: %s', __CLASS__, __METHOD__, __LINE__, JText::sprintf('COM_SH404SEF_ERROR_CHECKING_ANALYTICS', $msg)); throw new Sh404sefExceptionDefault(JText::sprintf('COM_SH404SEF_ERROR_CHECKING_ANALYTICS', $msg)); } if (!is_object($rawResponse) || $rawResponse->isError()) { $msg = method_exists($rawResponse, 'getStatus') ? $rawResponse->getStatus() : 'unknown code'; ShlSystem_Log::debug('sh404sef', '%s::%s::%d: %s', __CLASS__, __METHOD__, __LINE__, JText::sprintf('COM_SH404SEF_ERROR_CHECKING_ANALYTICS', $msg)); throw new Sh404sefExceptionDefault(JText::sprintf('COM_SH404SEF_ERROR_CHECKING_ANALYTICS', $msg)); } // success, return response return $rawResponse; }
public function display($tpl = null) { // version prefix $this->joomlaVersionPrefix = Sh404sefHelperGeneral::getJoomlaVersionPrefix(); // prepare the view, based on request // do we force reading updates from server ? $options = Sh404sefHelperAnalytics::getRequestOptions(); // push display options into template $this->assign('options', $options); // Get the JComponent instance of JToolBar $bar = JToolBar::getInstance('toolbar'); if (version_compare(JVERSION, '3.0', 'ge')) { $document = JFactory::getDocument(); // render submenu sidebar $this->sidebar = Sh404sefHelperHtml::renderSubmenu(); // add custom css JHtml::styleSheet(Sh404sefHelperGeneral::getComponentUrl() . '/assets/css/' . $this->joomlaVersionPrefix . '_list.css'); // add modal css and js ShlHtmlBs_helper::addBootstrapCss(JFactory::getDocument()); ShlHtmlBs_helper::addBootstrapJs(JFactory::getDocument()); // add title JToolbarHelper::title('sh404SEF: ' . JText::_('COM_SH404SEF_ANALYTICS_MANAGER'), 'sh404sef-toolbar-title'); // needed javascript jimport('joomla.html.html.bootstrap'); JHtml::_('formbehavior.chosen', 'select'); // add Joomla calendar behavior, needed to input start and end dates if ($options['showFilters'] == 'yes') { JHTML::_('behavior.calendar'); } // add quick control panel loader $js = 'jQuery(document).ready(function(){ shSetupAnalytics({report:" ' . $options['report'] . '"});});'; $document = JFactory::getDocument(); $document->addScriptDeclaration($js); } else { // add Joomla calendar behavior, needed to input start and end dates if ($options['showFilters'] == 'yes') { JHTML::_('behavior.calendar'); } // add tooltips handler JHTML::_('behavior.tooltip'); // add title $app = JFactory::getApplication(); $title = Sh404sefHelperGeneral::makeToolbarTitle(JText::_('COM_SH404SEF_ANALYTICS_MANAGER'), $icon = 'sh404sef', $class = 'sh404sef-toolbar-title'); JFactory::getApplication()->JComponentTitle = $title; // add quick control panel loader $js = 'window.addEvent(\'domready\', function(){ shSetupAnalytics({report:" ' . $options['report'] . '"});});'; $document = JFactory::getDocument(); $document->addScriptDeclaration($js); } // call methods to prepare display based on report type $method = '_makeView' . ucfirst($options['report']); if (is_callable(array($this, $method))) { $this->{$method}($tpl); } // add our javascript JHTML::script(Sh404sefHelperGeneral::getComponentUrl() . '/assets/js/' . $this->joomlaVersionPrefix . '_cp.js'); // add our own css JHtml::styleSheet(Sh404sefHelperGeneral::getComponentUrl() . '/assets/css/' . $this->joomlaVersionPrefix . '_cp.css'); // flag to know if we should display placeholder for ajax fillin $this->assign('isAjaxTemplate', true); parent::display($this->joomlaVersionPrefix); }