From ae4b03163792f0b6e933933e5d37df87dc3fd566 Mon Sep 17 00:00:00 2001 From: mattab Date: Thu, 28 Mar 2013 12:42:39 +1300 Subject: 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/ --- misc/others/ExamplePiwikTracker.php | 2 +- misc/others/api_rest_call.php | 16 +- misc/others/geoipUpdateRows.php | 419 ++++++++++----------- misc/others/iframeWidget.htm | 10 +- misc/others/iframeWidget_localhost.php | 61 +-- ...t_cookies_GenerateHundredsWebsitesAndVisits.php | 7 +- misc/others/test_generateLotsVisitsWebsites.php | 205 +++++----- misc/others/tracker_simpleImageTracker.php | 10 +- misc/others/uninstall-delete-piwik-directory.php | 24 +- misc/others/widget_example_lastvisits.html | 10 +- 10 files changed, 371 insertions(+), 393 deletions(-) (limited to 'misc/others') diff --git a/misc/others/ExamplePiwikTracker.php b/misc/others/ExamplePiwikTracker.php index 036831289d..f787a0847a 100644 --- a/misc/others/ExamplePiwikTracker.php +++ b/misc/others/ExamplePiwikTracker.php @@ -4,7 +4,7 @@ require_once '../../libs/PiwikTracker/PiwikTracker.php'; PiwikTracker::$URL = 'http://localhost/trunk/'; -$piwikTracker = new PiwikTracker( $idSite = 1 ); +$piwikTracker = new PiwikTracker($idSite = 1); // You can manually set the Visitor details (resolution, time, plugins) // See all other ->set* functions available in the PiwikTracker class $piwikTracker->setResolution(1600, 1400); diff --git a/misc/others/api_rest_call.php b/misc/others/api_rest_call.php index f7a7bfe995..d286e92f49 100644 --- a/misc/others/api_rest_call.php +++ b/misc/others/api_rest_call.php @@ -16,17 +16,15 @@ $fetched = file_get_contents($url); $content = unserialize($fetched); // case error -if(!$content) -{ - print("Error, content fetched = ".$fetched); +if (!$content) { + print("Error, content fetched = " . $fetched); } print("

Keywords for the last month

"); -foreach($content as $row) -{ - $keyword = htmlspecialchars(html_entity_decode(urldecode($row['label']), ENT_QUOTES), ENT_QUOTES); - $hits = $row['nb_visits']; - - print("$keyword ($hits hits)
"); +foreach ($content as $row) { + $keyword = htmlspecialchars(html_entity_decode(urldecode($row['label']), ENT_QUOTES), ENT_QUOTES); + $hits = $row['nb_visits']; + + print("$keyword ($hits hits)
"); } diff --git a/misc/others/geoipUpdateRows.php b/misc/others/geoipUpdateRows.php index 9028651ac2..37c841947b 100755 --- a/misc/others/geoipUpdateRows.php +++ b/misc/others/geoipUpdateRows.php @@ -1,19 +1,16 @@ log['logger_message'][] = 'screen'; Piwik_FrontController::getInstance()->init(); -$query = "SELECT count(*) FROM ".Piwik_Common::prefixTable('log_visit'); +$query = "SELECT count(*) FROM " . Piwik_Common::prefixTable('log_visit'); $count = Piwik_FetchOne($query); // when script run via browser, check for Super User & output html page to do conversion via AJAX -if (!Piwik_Common::isPhpCliMode()) -{ - try { - Piwik::checkUserIsSuperUser(); - } catch(Exception $e) { - Piwik::log('[error] You must be logged in as Super User to run this script. Please login in to Piwik and refresh this page.'); - exit; - } - // the 'start' query param will be supplied by the AJAX requests, so if it's not there, the - // user is viewing the page in the browser. - if (Piwik_Common::getRequestVar('start', false) === false) - { - // output HTML page that runs update via AJAX - ?> - - - - - - - - - - + + + + + + + + + + isAvailable()) -{ - if ($displayNotes) - { - Piwik::log("[note] The GeoIP PECL extension is not installed."); - } - - $provider = null; -} -else -{ - $workingOrError = $provider->isWorking(); - if ($workingOrError !== true) - { - if ($displayNotes) - { - Piwik::log("[note] The GeoIP PECL extension is broken: $workingOrError"); - } - if (Piwik_Common::isPhpCliMode()) - { - Piwik::log("[note] Make sure your command line PHP is configured to use the PECL extension."); - } - $provider = null; - } +if (!$provider->isAvailable()) { + if ($displayNotes) { + Piwik::log("[note] The GeoIP PECL extension is not installed."); + } + + $provider = null; +} else { + $workingOrError = $provider->isWorking(); + if ($workingOrError !== true) { + if ($displayNotes) { + Piwik::log("[note] The GeoIP PECL extension is broken: $workingOrError"); + } + if (Piwik_Common::isPhpCliMode()) { + Piwik::log("[note] Make sure your command line PHP is configured to use the PECL extension."); + } + $provider = null; + } } // use php api if pecl extension cannot be used -if (is_null($provider)) -{ - if ($displayNotes) - { - Piwik::log("[note] Falling back to PHP API. This may become too slow for you. If so, you can read this link on how to install the PECL extension: http://piwik.org/faq/how-to/#faq_164"); - } - - $provider = new Piwik_UserCountry_LocationProvider_GeoIp_Php(); - if (!$provider->isAvailable()) - { - if ($displayNotes) - { - Piwik::log("[note] The GeoIP PHP API is not available. This means you do not have a GeoIP location database in your ./misc directory. The database must be named either GeoIP.dat or GeoIPCity.dat based on the type of database it is."); - } - $provider = null; - } - else - { - $workingOrError = $provider->isWorking(); - if ($workingOrError !== true) - { - if ($displayNotes) - { - Piwik::log("[note] The GeoIP PHP API is broken: $workingOrError"); - } - $provider = null; - } - } +if (is_null($provider)) { + if ($displayNotes) { + Piwik::log("[note] Falling back to PHP API. This may become too slow for you. If so, you can read this link on how to install the PECL extension: http://piwik.org/faq/how-to/#faq_164"); + } + + $provider = new Piwik_UserCountry_LocationProvider_GeoIp_Php(); + if (!$provider->isAvailable()) { + if ($displayNotes) { + Piwik::log("[note] The GeoIP PHP API is not available. This means you do not have a GeoIP location database in your ./misc directory. The database must be named either GeoIP.dat or GeoIPCity.dat based on the type of database it is."); + } + $provider = null; + } else { + $workingOrError = $provider->isWorking(); + if ($workingOrError !== true) { + if ($displayNotes) { + Piwik::log("[note] The GeoIP PHP API is broken: $workingOrError"); + } + $provider = null; + } + } } -if (is_null($provider)) -{ - geoipUpdateError("\n[error] There is no location provider that can be used with this script. Only the GeoIP PECL module or the GeoIP PHP API can be used at present. Please install and configure one of these first."); +if (is_null($provider)) { + geoipUpdateError("\n[error] There is no location provider that can be used with this script. Only the GeoIP PECL module or the GeoIP PHP API can be used at present. Please install and configure one of these first."); } $info = $provider->getInfo(); -if ($displayNotes) -{ - Piwik::log("[note] Found working provider: {$info['id']}"); +if ($displayNotes) { + Piwik::log("[note] Found working provider: {$info['id']}"); } // perform update $logVisitFieldsToUpdate = array('location_country' => Piwik_UserCountry_LocationProvider::COUNTRY_CODE_KEY, - 'location_region' => Piwik_UserCountry_LocationProvider::REGION_CODE_KEY, - 'location_city' => Piwik_UserCountry_LocationProvider::CITY_NAME_KEY, - 'location_latitude' => Piwik_UserCountry_LocationProvider::LATITUDE_KEY, - 'location_longitude' => Piwik_UserCountry_LocationProvider::LONGITUDE_KEY); - -if ($displayNotes) -{ - Piwik::log("\n$count rows to process in ".Piwik_Common::prefixTable('log_visit') - . " and ".Piwik_Common::prefixTable('log_conversion')."..."); + 'location_region' => Piwik_UserCountry_LocationProvider::REGION_CODE_KEY, + 'location_city' => Piwik_UserCountry_LocationProvider::CITY_NAME_KEY, + 'location_latitude' => Piwik_UserCountry_LocationProvider::LATITUDE_KEY, + 'location_longitude' => Piwik_UserCountry_LocationProvider::LONGITUDE_KEY); + +if ($displayNotes) { + Piwik::log("\n$count rows to process in " . Piwik_Common::prefixTable('log_visit') + . " and " . Piwik_Common::prefixTable('log_conversion') . "..."); } flush(); -for (; $start < $end; $start += $limit) -{ - $rows = Piwik_FetchAll("SELECT idvisit, location_ip, ".implode(',', array_keys($logVisitFieldsToUpdate))." - FROM ".Piwik_Common::prefixTable('log_visit')." +for (; $start < $end; $start += $limit) { + $rows = Piwik_FetchAll("SELECT idvisit, location_ip, " . implode(',', array_keys($logVisitFieldsToUpdate)) . " + FROM " . Piwik_Common::prefixTable('log_visit') . " LIMIT $start, $limit"); - if(!count($rows)) - { - continue; - } - - foreach ( $rows as $i => $row ) - { - $fieldsToSet = array(); - foreach ($logVisitFieldsToUpdate as $field => $ignore) - { - if (empty($fieldsToSet[$field])) - { - $fieldsToSet[] = $field; - } - } - - // skip if it already has a location - if (empty($fieldsToSet)) - { - continue; - } - - $ip = Piwik_IP::N2P($row['location_ip']); - $location = $provider->getLocation(array('ip' => $ip)); - - if (!empty($location[Piwik_UserCountry_LocationProvider::COUNTRY_CODE_KEY])) - { - $location[Piwik_UserCountry_LocationProvider::COUNTRY_CODE_KEY] = - strtolower($location[Piwik_UserCountry_LocationProvider::COUNTRY_CODE_KEY]); - } - $row['location_country'] = strtolower($row['location_country']); - - $columnsToSet = array(); - $bind = array(); - foreach ($logVisitFieldsToUpdate as $column => $locationKey) - { - if (!empty($location[$locationKey]) - && $location[$locationKey] != $row[$column]) - { - $columnsToSet[] = $column.' = ?'; - $bind[] = $location[$locationKey]; - } - } - - if (empty($columnsToSet)) - { - continue; - } - - $bind[] = $row['idvisit']; - - // update log_visit - $sql = "UPDATE ".Piwik_Common::prefixTable('log_visit')." - SET ".implode(', ', $columnsToSet)." + if (!count($rows)) { + continue; + } + + foreach ($rows as $i => $row) { + $fieldsToSet = array(); + foreach ($logVisitFieldsToUpdate as $field => $ignore) { + if (empty($fieldsToSet[$field])) { + $fieldsToSet[] = $field; + } + } + + // skip if it already has a location + if (empty($fieldsToSet)) { + continue; + } + + $ip = Piwik_IP::N2P($row['location_ip']); + $location = $provider->getLocation(array('ip' => $ip)); + + if (!empty($location[Piwik_UserCountry_LocationProvider::COUNTRY_CODE_KEY])) { + $location[Piwik_UserCountry_LocationProvider::COUNTRY_CODE_KEY] = + strtolower($location[Piwik_UserCountry_LocationProvider::COUNTRY_CODE_KEY]); + } + $row['location_country'] = strtolower($row['location_country']); + + $columnsToSet = array(); + $bind = array(); + foreach ($logVisitFieldsToUpdate as $column => $locationKey) { + if (!empty($location[$locationKey]) + && $location[$locationKey] != $row[$column] + ) { + $columnsToSet[] = $column . ' = ?'; + $bind[] = $location[$locationKey]; + } + } + + if (empty($columnsToSet)) { + continue; + } + + $bind[] = $row['idvisit']; + + // update log_visit + $sql = "UPDATE " . Piwik_Common::prefixTable('log_visit') . " + SET " . implode(', ', $columnsToSet) . " WHERE idvisit = ?"; - Piwik_Query($sql, $bind); - - // update log_conversion - $sql = "UPDATE ".Piwik_Common::prefixTable('log_conversion')." - SET ".implode(', ', $columnsToSet)." + Piwik_Query($sql, $bind); + + // update log_conversion + $sql = "UPDATE " . Piwik_Common::prefixTable('log_conversion') . " + SET " . implode(', ', $columnsToSet) . " WHERE idvisit = ?"; - Piwik_Query($sql, $bind); - } - Piwik::log(round($start * 100 / $count) . "% done..."); - flush(); + Piwik_Query($sql, $bind); + } + Piwik::log(round($start * 100 / $count) . "% done..."); + flush(); } -if ($start >= $count) -{ - Piwik::log("100% done!"); - Piwik::log(""); - Piwik::log("[note] Now that you've geolocated your old visits, you need to force your reports to be re-processed. See this FAQ entry: http://piwik.org/faq/how-to/#faq_59"); +if ($start >= $count) { + Piwik::log("100% done!"); + Piwik::log(""); + Piwik::log("[note] Now that you've geolocated your old visits, you need to force your reports to be re-processed. See this FAQ entry: http://piwik.org/faq/how-to/#faq_59"); } diff --git a/misc/others/iframeWidget.htm b/misc/others/iframeWidget.htm index f26a8ba463..9b7c4261f1 100644 --- a/misc/others/iframeWidget.htm +++ b/misc/others/iframeWidget.htm @@ -2,6 +2,12 @@

Embedding the Piwik Country widget in an Iframe

-
- +
+ +
+ + + diff --git a/misc/others/iframeWidget_localhost.php b/misc/others/iframeWidget_localhost.php index ad105a7c9c..d01ba89227 100644 --- a/misc/others/iframeWidget_localhost.php +++ b/misc/others/iframeWidget_localhost.php @@ -9,9 +9,13 @@ $url = "http://localhost/trunk/index.php?token_auth=0b809661490d605bfd77f57ed11f

Embedding the Piwik Country widget in an Iframe

-

Loads a widget from localhost/trunk/ with login=root, pwd=test. Widget URL

-
+ +

Loads a widget from localhost/trunk/ with login=root, pwd=test. Widget URL

+ +
+ +

@@ -26,32 +30,29 @@ require_once PIWIK_INCLUDE_PATH . "/core/API/Request.php"; Piwik_FrontController::getInstance()->init(); $widgets = Piwik_GetWidgetsList(); -foreach($widgets as $category => $widgetsInCategory) -{ - echo '

'.$category . '

'; - foreach($widgetsInCategory as $widget) - { - echo '

'.$widget['name'].'

'; - $widgetUrl = Piwik_Common::getArrayFromQueryString($url); - $widgetUrl['moduleToWidgetize'] = $widget['parameters']['module']; - $widgetUrl['actionToWidgetize'] = $widget['parameters']['action']; - $parameters = $widget['parameters']; - unset($parameters['module']); - unset($parameters['action']); - foreach($parameters as $name => $value) - { - if(is_array($value)) - { - $value = current($value); - } - $widgetUrl[$name] = $value; - } - $widgetUrl = Piwik_Url::getQueryStringFromParameters($widgetUrl); - - echo '
'; - - } +foreach ($widgets as $category => $widgetsInCategory) { + echo '

' . $category . '

'; + foreach ($widgetsInCategory as $widget) { + echo '

' . $widget['name'] . '

'; + $widgetUrl = Piwik_Common::getArrayFromQueryString($url); + $widgetUrl['moduleToWidgetize'] = $widget['parameters']['module']; + $widgetUrl['actionToWidgetize'] = $widget['parameters']['action']; + $parameters = $widget['parameters']; + unset($parameters['module']); + unset($parameters['action']); + foreach ($parameters as $name => $value) { + if (is_array($value)) { + $value = current($value); + } + $widgetUrl[$name] = $value; + } + $widgetUrl = Piwik_Url::getQueryStringFromParameters($widgetUrl); + + echo '
'; + + } } ?> - + + diff --git a/misc/others/test_cookies_GenerateHundredsWebsitesAndVisits.php b/misc/others/test_cookies_GenerateHundredsWebsitesAndVisits.php index 8ce69cdf5b..4f51391b96 100644 --- a/misc/others/test_cookies_GenerateHundredsWebsitesAndVisits.php +++ b/misc/others/test_cookies_GenerateHundredsWebsitesAndVisits.php @@ -14,10 +14,9 @@ require_once PIWIK_INCLUDE_PATH . "/libs/PiwikTracker/PiwikTracker.php"; Piwik_FrontController::getInstance()->init(); Piwik::setUserIsSuperUser(); $count = 100; -for($i = 0; $i <= $count; $i++) -{ - $id = Piwik_SitesManager_API::getInstance()->addSite(Piwik_Common::getRandomString(), 'http://piwik.org'); +for ($i = 0; $i <= $count; $i++) { + $id = Piwik_SitesManager_API::getInstance()->addSite(Piwik_Common::getRandomString(), 'http://piwik.org'); $t = new PiwikTracker($id, 'http://localhost/trunk/piwik.php'); - echo $id . "
"; + echo $id . "
"; } diff --git a/misc/others/test_generateLotsVisitsWebsites.php b/misc/others/test_generateLotsVisitsWebsites.php index e8819bb9c8..eeb5b22e5a 100644 --- a/misc/others/test_generateLotsVisitsWebsites.php +++ b/misc/others/test_generateLotsVisitsWebsites.php @@ -1,5 +1,5 @@ init(); // SECURITY: DO NOT DELETE THIS LINE! -if(!Piwik_Common::isPhpCliMode()) { die("ERROR: Must be executed in CLI"); } +if (!Piwik_Common::isPhpCliMode()) { + die("ERROR: Must be executed in CLI"); +} $process = new Piwik_StressTests_CopyLogs; $process->init(); @@ -19,118 +21,121 @@ $process->run(); class Piwik_StressTests_CopyLogs { - function init() - { - $config = Piwik_Config::getInstance(); - $config->log['log_only_when_debug_parameter'] = 0; - $config->log['logger_message'] = array("logger_message" => "screen"); - Piwik::createLogObject(); - } - - function run() - { - // Copy all visits in date range into TODAY + function init() + { + $config = Piwik_Config::getInstance(); + $config->log['log_only_when_debug_parameter'] = 0; + $config->log['logger_message'] = array("logger_message" => "screen"); + Piwik::createLogObject(); + } + + function run() + { + // Copy all visits in date range into TODAY $startDate = '2011-08-12'; $endDate = '2011-08-12'; - + $this->log("Starting..."); - $db = Zend_Registry::get('db'); - - $initial = $this->getVisitsToday(); - $this->log(" Visits today so far: " . $initial); - $initialActions = $this->getActionsToday(); - $this->log(" Actions today: " . $initialActions); - $initialPurchasedItems = $this->getConversionItemsToday(); - $this->log(" Purchased items today: " . $initialPurchasedItems); - $initialConversions = $this->getConversionsToday(); - $this->log(" Conversions today: " . $initialConversions); - - $this->log(" Now copying visits between '$startDate' and '$endDate'..."); - $sql = "INSERT INTO ". Piwik_Common::prefixTable('log_visit')." (`idsite`, `idvisitor`, `visitor_localtime`, `visitor_returning`, `visitor_count_visits`, `visit_first_action_time`, `visit_last_action_time`, `visit_exit_idaction_url`, `visit_exit_idaction_name`, `visit_entry_idaction_url`, `visit_entry_idaction_name`, `visit_total_actions`, `visit_total_time`, `visit_goal_converted`, `visit_goal_buyer`, `referer_type`, `referer_name`, `referer_url`, `referer_keyword`, `config_id`, `config_os`, `config_browser_name`, `config_browser_version`, `config_resolution`, `config_pdf`, `config_flash`, `config_java`, `config_director`, `config_quicktime`, `config_realplayer`, `config_windowsmedia`, `config_gears`, `config_silverlight`, `config_cookie`, `location_ip`, `location_browser_lang`, `location_country`, `location_provider`, `custom_var_k1`, `custom_var_v1`, `custom_var_k2`, `custom_var_v2`, `custom_var_k3`, `custom_var_v3`, `custom_var_k4`, `custom_var_v4`, `custom_var_k5`, `custom_var_v5`, `visitor_days_since_last`, `visitor_days_since_order`, `visitor_days_since_first`) + $db = Zend_Registry::get('db'); + + $initial = $this->getVisitsToday(); + $this->log(" Visits today so far: " . $initial); + $initialActions = $this->getActionsToday(); + $this->log(" Actions today: " . $initialActions); + $initialPurchasedItems = $this->getConversionItemsToday(); + $this->log(" Purchased items today: " . $initialPurchasedItems); + $initialConversions = $this->getConversionsToday(); + $this->log(" Conversions today: " . $initialConversions); + + $this->log(" Now copying visits between '$startDate' and '$endDate'..."); + $sql = "INSERT INTO " . Piwik_Common::prefixTable('log_visit') . " (`idsite`, `idvisitor`, `visitor_localtime`, `visitor_returning`, `visitor_count_visits`, `visit_first_action_time`, `visit_last_action_time`, `visit_exit_idaction_url`, `visit_exit_idaction_name`, `visit_entry_idaction_url`, `visit_entry_idaction_name`, `visit_total_actions`, `visit_total_time`, `visit_goal_converted`, `visit_goal_buyer`, `referer_type`, `referer_name`, `referer_url`, `referer_keyword`, `config_id`, `config_os`, `config_browser_name`, `config_browser_version`, `config_resolution`, `config_pdf`, `config_flash`, `config_java`, `config_director`, `config_quicktime`, `config_realplayer`, `config_windowsmedia`, `config_gears`, `config_silverlight`, `config_cookie`, `location_ip`, `location_browser_lang`, `location_country`, `location_provider`, `custom_var_k1`, `custom_var_v1`, `custom_var_k2`, `custom_var_v2`, `custom_var_k3`, `custom_var_v3`, `custom_var_k4`, `custom_var_v4`, `custom_var_k5`, `custom_var_v5`, `visitor_days_since_last`, `visitor_days_since_order`, `visitor_days_since_first`) SELECT `idsite`, `idvisitor`, `visitor_localtime`, `visitor_returning`, `visitor_count_visits`, CONCAT(CURRENT_DATE() , \" \", FLOOR(RAND()*24) , \":\",FLOOR(RAND()*60),\":\",FLOOR(RAND()*60)), CONCAT(CURRENT_DATE() , \" \", FLOOR(RAND()*24) , \":\",FLOOR(RAND()*60),\":\",FLOOR(RAND()*60)), `visit_exit_idaction_url`, `visit_exit_idaction_name`, `visit_entry_idaction_url`, `visit_entry_idaction_name`, `visit_total_actions`, `visit_total_time`, `visit_goal_converted`, `visit_goal_buyer`, `referer_type`, `referer_name`, `referer_url`, `referer_keyword`, `config_id`, `config_os`, `config_browser_name`, `config_browser_version`, `config_resolution`, `config_pdf`, `config_flash`, `config_java`, `config_director`, `config_quicktime`, `config_realplayer`, `config_windowsmedia`, `config_gears`, `config_silverlight`, `config_cookie`, `location_ip`, `location_browser_lang`, `location_country`, `location_provider`, `custom_var_k1`, `custom_var_v1`, `custom_var_k2`, `custom_var_v2`, `custom_var_k3`, `custom_var_v3`, `custom_var_k4`, `custom_var_v4`, `custom_var_k5`, `custom_var_v5`, `visitor_days_since_last`, `visitor_days_since_order`, `visitor_days_since_first` - FROM `". Piwik_Common::prefixTable('log_visit')."` + FROM `" . Piwik_Common::prefixTable('log_visit') . "` WHERE idsite >= 1 AND date(visit_last_action_time) between '$startDate' and '$endDate' ;"; - $result = $db->query($sql); - - $this->log(" Copying actions..."); - $sql = "INSERT INTO ". Piwik_Common::prefixTable('log_link_visit_action')." (`idsite`, `idvisitor`, `server_time`, `idvisit`, `idaction_url`, `idaction_url_ref`, `idaction_name`, `idaction_name_ref`, `time_spent_ref_action`, `custom_var_k1`, `custom_var_v1`, `custom_var_k2`, `custom_var_v2`, `custom_var_k3`, `custom_var_v3`, `custom_var_k4`, `custom_var_v4`, `custom_var_k5`, `custom_var_v5`) + $result = $db->query($sql); + + $this->log(" Copying actions..."); + $sql = "INSERT INTO " . Piwik_Common::prefixTable('log_link_visit_action') . " (`idsite`, `idvisitor`, `server_time`, `idvisit`, `idaction_url`, `idaction_url_ref`, `idaction_name`, `idaction_name_ref`, `time_spent_ref_action`, `custom_var_k1`, `custom_var_v1`, `custom_var_k2`, `custom_var_v2`, `custom_var_k3`, `custom_var_v3`, `custom_var_k4`, `custom_var_v4`, `custom_var_k5`, `custom_var_v5`) SELECT `idsite`, `idvisitor`, CONCAT(CURRENT_DATE() , \" \", FLOOR(RAND()*24) , \":\",FLOOR(RAND()*60),\":\",FLOOR(RAND()*60)), `idvisit`, `idaction_url`, `idaction_url_ref`, `idaction_name`, `idaction_name_ref`, `time_spent_ref_action`, `custom_var_k1`, `custom_var_v1`, `custom_var_k2`, `custom_var_v2`, `custom_var_k3`, `custom_var_v3`, `custom_var_k4`, `custom_var_v4`, `custom_var_k5`, `custom_var_v5` - FROM `". Piwik_Common::prefixTable('log_link_visit_action')."` + FROM `" . Piwik_Common::prefixTable('log_link_visit_action') . "` WHERE idsite >= 1 AND date(server_time) between '$startDate' and '$endDate' ;"; // LIMIT 1000000 - $result = $db->query($sql); - - $this->log(" Copying conversions..."); - $sql = "INSERT IGNORE INTO `". Piwik_Common::prefixTable('log_conversion')."` (`idvisit`, `idsite`, `visitor_days_since_first`, `visitor_days_since_order`, `visitor_count_visits`, `idvisitor`, `server_time`, `idaction_url`, `idlink_va`, `referer_visit_server_date`, `referer_type`, `referer_name`, `referer_keyword`, `visitor_returning`, `location_country`, `url`, `idgoal`, `revenue`, `buster`, `idorder`, `custom_var_k1`, `custom_var_v1`, `custom_var_k2`, `custom_var_v2`, `custom_var_k3`, `custom_var_v3`, `custom_var_k4`, `custom_var_v4`, `custom_var_k5`, `custom_var_v5`, `items`, `revenue_subtotal`, `revenue_tax`, `revenue_shipping`, `revenue_discount`) + $result = $db->query($sql); + + $this->log(" Copying conversions..."); + $sql = "INSERT IGNORE INTO `" . Piwik_Common::prefixTable('log_conversion') . "` (`idvisit`, `idsite`, `visitor_days_since_first`, `visitor_days_since_order`, `visitor_count_visits`, `idvisitor`, `server_time`, `idaction_url`, `idlink_va`, `referer_visit_server_date`, `referer_type`, `referer_name`, `referer_keyword`, `visitor_returning`, `location_country`, `url`, `idgoal`, `revenue`, `buster`, `idorder`, `custom_var_k1`, `custom_var_v1`, `custom_var_k2`, `custom_var_v2`, `custom_var_k3`, `custom_var_v3`, `custom_var_k4`, `custom_var_v4`, `custom_var_k5`, `custom_var_v5`, `items`, `revenue_subtotal`, `revenue_tax`, `revenue_shipping`, `revenue_discount`) SELECT `idvisit`, `idsite`, `visitor_days_since_first`, `visitor_days_since_order`, `visitor_count_visits`, `idvisitor`, CONCAT(CURRENT_DATE() , \" \", FLOOR(RAND()*24) , \":\",FLOOR(RAND()*60),\":\",FLOOR(RAND()*60)), `idaction_url`, `idlink_va`, `referer_visit_server_date`, `referer_type`, `referer_name`, `referer_keyword`, `visitor_returning`, `location_country`, `url`, `idgoal`, `revenue`, FLOOR(`buster` * RAND()), CONCAT(`idorder`,SUBSTRING(MD5(RAND()) FROM 1 FOR 9)) , `custom_var_k1`, `custom_var_v1`, `custom_var_k2`, `custom_var_v2`, `custom_var_k3`, `custom_var_v3`, `custom_var_k4`, `custom_var_v4`, `custom_var_k5`, `custom_var_v5`, `items`, `revenue_subtotal`, `revenue_tax`, `revenue_shipping`, `revenue_discount` - FROM `". Piwik_Common::prefixTable('log_conversion')."` + FROM `" . Piwik_Common::prefixTable('log_conversion') . "` WHERE idsite >= 1 AND date(server_time) between '$startDate' and '$endDate' ;"; - $result = $db->query($sql); - - $this->log(" Copying purchased items..."); - $sql = "INSERT INTO `". Piwik_Common::prefixTable('log_conversion_item')."` (`idsite`, `idvisitor`, `server_time`, `idvisit`, `idorder`, `idaction_sku`, `idaction_name`, `idaction_category`, `price`, `quantity`, `deleted`) + $result = $db->query($sql); + + $this->log(" Copying purchased items..."); + $sql = "INSERT INTO `" . Piwik_Common::prefixTable('log_conversion_item') . "` (`idsite`, `idvisitor`, `server_time`, `idvisit`, `idorder`, `idaction_sku`, `idaction_name`, `idaction_category`, `price`, `quantity`, `deleted`) SELECT `idsite`, `idvisitor`, CONCAT(CURRENT_DATE() , \" \", TIME(`server_time`)), `idvisit`, CONCAT(`idorder`,SUBSTRING(MD5(RAND()) FROM 1 FOR 9)) , `idaction_sku`, `idaction_name`, `idaction_category`, `price`, `quantity`, `deleted` - FROM `". Piwik_Common::prefixTable('log_conversion_item')."` + FROM `" . Piwik_Common::prefixTable('log_conversion_item') . "` WHERE idsite >= 1 AND date(server_time) between '$startDate' and '$endDate' ;"; - $result = $db->query($sql); - - $now = $this->getVisitsToday(); - $actions = $this->getActionsToday(); - $purchasedItems = $this->getConversionItemsToday(); - $conversions = $this->getConversionsToday(); - - $this->log(" -------------------------------------"); - $this->log(" Today visits after import: " . $now); - $this->log(" Actions: " . $actions); - $this->log(" Purchased items: " . $purchasedItems); - $this->log(" Conversions: " . $conversions); - $this->log(" - New visits created: " . ($now-$initial)); - $this->log(" - Actions created: " . ($actions-$initialActions)); - $this->log(" - New conversions created: " . ($conversions-$initialConversions)); - $this->log(" - New purchased items created: " . ($purchasedItems-$initialPurchasedItems)); + $result = $db->query($sql); + + $now = $this->getVisitsToday(); + $actions = $this->getActionsToday(); + $purchasedItems = $this->getConversionItemsToday(); + $conversions = $this->getConversionsToday(); + + $this->log(" -------------------------------------"); + $this->log(" Today visits after import: " . $now); + $this->log(" Actions: " . $actions); + $this->log(" Purchased items: " . $purchasedItems); + $this->log(" Conversions: " . $conversions); + $this->log(" - New visits created: " . ($now - $initial)); + $this->log(" - Actions created: " . ($actions - $initialActions)); + $this->log(" - New conversions created: " . ($conversions - $initialConversions)); + $this->log(" - New purchased items created: " . ($purchasedItems - $initialPurchasedItems)); $this->log("done"); - } - - function delete() - { - $this->log("Deleting logs for today..."); - $db = Zend_Registry::get('db'); - $sql = "DELETE FROM ". Piwik_Common::prefixTable('log_visit')." + } + + function delete() + { + $this->log("Deleting logs for today..."); + $db = Zend_Registry::get('db'); + $sql = "DELETE FROM " . Piwik_Common::prefixTable('log_visit') . " WHERE date(visit_last_action_time) = CURRENT_DATE();"; - $db->query($sql); - foreach(array('log_link_visit_action', 'log_conversion', 'log_conversion_item') as $table) - { - $sql = "DELETE FROM ".Piwik_Common::prefixTable($table)." + $db->query($sql); + foreach (array('log_link_visit_action', 'log_conversion', 'log_conversion_item') as $table) { + $sql = "DELETE FROM " . Piwik_Common::prefixTable($table) . " WHERE date(server_time) = CURRENT_DATE();"; - $db->query($sql); - } - $sql = "OPTIMIZE TABLE ". Piwik_Common::prefixTable('log_link_visit_action').", ". Piwik_Common::prefixTable('log_conversion').", ". Piwik_Common::prefixTable('log_conversion_item').", ". Piwik_Common::prefixTable('log_visit').""; - $db->query($sql); - $this->log("done"); - } - - function log($m) - { - Piwik::log($m); - } - function getVisitsToday() - { - $sql = "SELECT count(*) FROM `". Piwik_Common::prefixTable('log_visit')."` WHERE idsite >= 1 AND DATE(`visit_last_action_time`) = CURRENT_DATE;"; - return Zend_Registry::get('db')->fetchOne($sql); - } - function getConversionItemsToday($table = 'log_conversion_item') - { - $sql = "SELECT count(*) FROM `".Piwik_Common::prefixTable($table)."` WHERE idsite >= 1 AND DATE(`server_time`) = CURRENT_DATE;"; - return Zend_Registry::get('db')->fetchOne($sql); - } - function getConversionsToday() - { - return $this->getConversionItemsToday($table = "log_conversion"); - } - function getActionsToday() - { - $sql = "SELECT count(*) FROM `". Piwik_Common::prefixTable('log_link_visit_action')."` WHERE idsite >= 1 AND DATE(`server_time`) = CURRENT_DATE;"; - return Zend_Registry::get('db')->fetchOne($sql); - } + $db->query($sql); + } + $sql = "OPTIMIZE TABLE " . Piwik_Common::prefixTable('log_link_visit_action') . ", " . Piwik_Common::prefixTable('log_conversion') . ", " . Piwik_Common::prefixTable('log_conversion_item') . ", " . Piwik_Common::prefixTable('log_visit') . ""; + $db->query($sql); + $this->log("done"); + } + + function log($m) + { + Piwik::log($m); + } + + function getVisitsToday() + { + $sql = "SELECT count(*) FROM `" . Piwik_Common::prefixTable('log_visit') . "` WHERE idsite >= 1 AND DATE(`visit_last_action_time`) = CURRENT_DATE;"; + return Zend_Registry::get('db')->fetchOne($sql); + } + + function getConversionItemsToday($table = 'log_conversion_item') + { + $sql = "SELECT count(*) FROM `" . Piwik_Common::prefixTable($table) . "` WHERE idsite >= 1 AND DATE(`server_time`) = CURRENT_DATE;"; + return Zend_Registry::get('db')->fetchOne($sql); + } + + function getConversionsToday() + { + return $this->getConversionItemsToday($table = "log_conversion"); + } + + function getActionsToday() + { + $sql = "SELECT count(*) FROM `" . Piwik_Common::prefixTable('log_link_visit_action') . "` WHERE idsite >= 1 AND DATE(`server_time`) = CURRENT_DATE;"; + return Zend_Registry::get('db')->fetchOne($sql); + } } diff --git a/misc/others/tracker_simpleImageTracker.php b/misc/others/tracker_simpleImageTracker.php index ae7502874a..373ed31474 100644 --- a/misc/others/tracker_simpleImageTracker.php +++ b/misc/others/tracker_simpleImageTracker.php @@ -1,4 +1,5 @@ - + + This page loads a Simple Tracker request to Piwik website id=1 @@ -7,7 +8,8 @@ This page loads a Simple Tracker request to Piwik website id=1 require_once "../libs/PiwikTracker/PiwikTracker.php"; PiwikTracker::$URL = 'http://example.org/piwik/'; // Example 1: Tracks a pageview for Website id = {$IDSITE} -$trackingURL = Piwik_getUrlTrackPageView( $idSite = 1, $customTitle = 'This title will appear in the report Actions > Page titles'); -echo ''; +$trackingURL = Piwik_getUrlTrackPageView($idSite = 1, $customTitle = 'This title will appear in the report Actions > Page titles'); +echo ''; ?> - \ No newline at end of file + + \ No newline at end of file diff --git a/misc/others/uninstall-delete-piwik-directory.php b/misc/others/uninstall-delete-piwik-directory.php index b51ae63577..e05f70259c 100644 --- a/misc/others/uninstall-delete-piwik-directory.php +++ b/misc/others/uninstall-delete-piwik-directory.php @@ -9,18 +9,18 @@ // please let us know at hello@piwik.org - we are interested by your experience function unlinkRecursive($dir) { - if(!$dh = @opendir($dir)) return "Warning: folder $dir couldn't be read by PHP"; - while (false !== ($obj = readdir($dh))) { - if($obj == '.' || $obj == '..') { - continue; - } - if (!@unlink($dir . '/' . $obj)) { - unlinkRecursive($dir.'/'.$obj, true); - } - } - closedir($dh); - @rmdir($dir); - return "Folder $dir deleted!"; + if (!$dh = @opendir($dir)) return "Warning: folder $dir couldn't be read by PHP"; + while (false !== ($obj = readdir($dh))) { + if ($obj == '.' || $obj == '..') { + continue; + } + if (!@unlink($dir . '/' . $obj)) { + unlinkRecursive($dir . '/' . $obj, true); + } + } + closedir($dh); + @rmdir($dir); + return "Folder $dir deleted!"; } echo unlinkRecursive('piwik/'); diff --git a/misc/others/widget_example_lastvisits.html b/misc/others/widget_example_lastvisits.html index 403a3d4f88..a515255d03 100644 --- a/misc/others/widget_example_lastvisits.html +++ b/misc/others/widget_example_lastvisits.html @@ -1,5 +1,11 @@ - + +

Number of visits per week for the last 52 weeks

-
+ +
+ +
-- cgit v1.2.3