Exemple #1
0
 /**
  * Class constructor
  *
  * @access private
  */
 function __construct()
 {
     global $civicrm_root;
     $config = CRM_Core_Config::singleton();
     $localfile = $civicrm_root . DIRECTORY_SEPARATOR . self::LOCALFILE_NAME;
     $cachefile = $config->uploadDir . self::CACHEFILE_NAME;
     if (file_exists($localfile)) {
         require_once $localfile;
         if (function_exists('civicrmVersion')) {
             $info = civicrmVersion();
             $this->localVersion = trim($info['version']);
         }
     }
     if ($config->versionCheck) {
         $expiryTime = time() - self::CACHEFILE_EXPIRE;
         // if there's a cachefile and it's not stale use it to
         // read the latestVersion, else read it from the Internet
         if (file_exists($cachefile) && filemtime($cachefile) > $expiryTime) {
             $this->latestVersion = trim(file_get_contents($cachefile));
         } else {
             $siteKey = md5(defined('CIVICRM_SITE_KEY') ? CIVICRM_SITE_KEY : '');
             $this->stats = array('hash' => md5($siteKey . $config->userFrameworkBaseURL), 'version' => $this->localVersion, 'uf' => $config->userFramework, 'lang' => $config->lcMessages, 'co' => $config->defaultContactCountry, 'ufv' => $config->userFrameworkVersion, 'PHP' => phpversion(), 'MySQL' => CRM_CORE_DAO::singleValueQuery('SELECT VERSION()'), 'communityMessagesUrl' => CRM_Core_BAO_Setting::getItem(CRM_Core_BAO_Setting::SYSTEM_PREFERENCES_NAME, 'communityMessagesUrl', NULL, '*default*'));
             // Add usage stats
             $this->payProcStats();
             $this->entityStats();
             $this->extensionStats();
             // Get the latest version and send site info
             $this->pingBack();
             // Update cache file
             if ($this->latestVersion) {
                 $fp = @fopen($cachefile, 'w');
                 if (!$fp) {
                     if (CRM_Core_Permission::check('administer CiviCRM')) {
                         CRM_Core_Session::setStatus(ts('Unable to write file') . ":{$cachefile}<br />" . ts('Please check your system file permissions.'), ts('File Error'), 'error');
                     }
                     return;
                 }
                 fwrite($fp, $this->latestVersion);
                 fclose($fp);
             }
         }
     }
 }
 /**
  * Collect info about the site to be sent as pingback data.
  */
 private function getSiteStats()
 {
     $config = CRM_Core_Config::singleton();
     $siteKey = md5(defined('CIVICRM_SITE_KEY') ? CIVICRM_SITE_KEY : '');
     // Calorie-free pingback for alphas
     $this->stats = array('version' => $this->localVersion);
     // Non-alpha versions get the full treatment
     if ($this->localVersion && !strpos($this->localVersion, 'alpha')) {
         $this->stats += array('hash' => md5($siteKey . $config->userFrameworkBaseURL), 'uf' => $config->userFramework, 'lang' => $config->lcMessages, 'co' => $config->defaultContactCountry, 'ufv' => $config->userSystem->getVersion(), 'PHP' => phpversion(), 'MySQL' => CRM_CORE_DAO::singleValueQuery('SELECT VERSION()'), 'communityMessagesUrl' => Civi::settings()->get('communityMessagesUrl'));
         $this->getPayProcStats();
         $this->getEntityStats();
         $this->getExtensionStats();
     }
 }