Example #1
0
 /**
  * Check with the webtrees.net server for the latest version of webtrees.
  * Fetching the remote file can be slow, so check infrequently, and cache the result.
  * Pass the current versions of webtrees, PHP and MySQL, as the response
  * may be different for each.  The server logs are used to generate
  * installation statistics which can be found at http://svn.webtrees.net/statistics.html
  *
  * @return null|string
  */
 public static function fetchLatestVersion()
 {
     $last_update_timestamp = Site::getPreference('LATEST_WT_VERSION_TIMESTAMP');
     if ($last_update_timestamp < WT_TIMESTAMP - 24 * 60 * 60) {
         $row = Database::prepare("SHOW VARIABLES LIKE 'version'")->fetchOneRow();
         $params = '?w=' . WT_VERSION . '&p=' . PHP_VERSION . '&m=' . $row->value . '&o=' . (DIRECTORY_SEPARATOR === '/' ? 'u' : 'w');
         $latest_version_txt = File::fetchUrl('http://dev.webtrees.net/build/latest-version.txt' . $params);
         if ($latest_version_txt) {
             Site::setPreference('LATEST_WT_VERSION', $latest_version_txt);
             Site::setPreference('LATEST_WT_VERSION_TIMESTAMP', WT_TIMESTAMP);
             return $latest_version_txt;
         } else {
             // Cannot connect to server - use cached version (if we have one)
             return Site::getPreference('LATEST_WT_VERSION');
         }
     } else {
         return Site::getPreference('LATEST_WT_VERSION');
     }
 }
Example #2
0
 /**
  * Retrieve the number of visitors from Piwik, for a given period.
  * 
  * @param string $block_id
  * @param string $period
  * @param (null|int) Number of visits
  */
 private function getNumberOfVisitsPiwik($block_id, $period = 'year')
 {
     $piwik_url = $this->module->getBlockSetting($block_id, 'piwik_url');
     $piwik_siteid = $this->module->getBlockSetting($block_id, 'piwik_siteid');
     $piwik_token = $this->module->getBlockSetting($block_id, 'piwik_token');
     if ($piwik_url && strlen($piwik_url) > 0 && $piwik_siteid && strlen($piwik_siteid) > 0 && $piwik_token && strlen($piwik_token)) {
         // calling Piwik REST API
         $url = $piwik_url;
         $url .= '?module=API&method=VisitsSummary.getVisits';
         $url .= '&idSite=' . $piwik_siteid . '&period=' . $period . '&date=today';
         $url .= '&format=PHP';
         $url .= '&token_auth=' . $piwik_token;
         if ($fetched = File::fetchUrl($url)) {
             $content = @unserialize($fetched);
             if (is_numeric($content)) {
                 return $content;
             }
         }
     }
     return null;
 }
        echo '<br>', I18N::translate('The family tree has been exported to %s.', Html::filename($filename)), $icon_success;
    } catch (\ErrorException $ex) {
        echo '<br>', I18N::translate('The file %s could not be created.', Html::filename($filename)), $icon_failure;
    }
}
echo '</li>';
////////////////////////////////////////////////////////////////////////////////
// Download a .ZIP file containing the new code
////////////////////////////////////////////////////////////////////////////////
echo '<li>', I18N::translate('Download %s…', Html::filename($download_url_html));
$zip_file = WT_DATA_DIR . basename($download_url);
$zip_dir = WT_DATA_DIR . basename($download_url, '.zip');
$zip_stream = fopen($zip_file, 'w');
reset_timeout();
$start_time = microtime(true);
File::fetchUrl($download_url, $zip_stream);
$end_time = microtime(true);
$zip_size = filesize($zip_file);
fclose($zip_stream);
echo '<br>', I18N::translate('%1$s KB were downloaded in %2$s seconds.', I18N::number($zip_size / 1024), I18N::number($end_time - $start_time, 2));
if ($zip_size) {
    echo $icon_success;
} else {
    echo $icon_failure;
    // Guess why we might have failed...
    if (preg_match('/^https:/', $download_url) && !in_array('ssl', stream_get_transports())) {
        echo '<br>', I18N::translate('This server does not support secure downloads using HTTPS.');
    }
}
echo '</li>';
////////////////////////////////////////////////////////////////////////////////