/** * Поиск доступного обновления. * * @return string номер доступной версии. */ private static function getAvailable() { $release = mcms::version(mcms::VERSION_RELEASE); $content = http::fetch('http://code.google.com/p/molinos-cms' . '/downloads/list?q=label:R' . $release, http::CONTENT); if (preg_match($re = "@http://molinos-cms\\.googlecode\\.com/files/molinos-cms-({$release}\\.[0-9]+)\\.zip@", $content, $m)) { return $m[1]; } else { return $version; } }
public static function getSignature(Context $ctx = null, $full = false) { $result = array('version' => mcms::version(), 'client' => $_SERVER['REMOTE_ADDR']); try { if (null === $ctx) { $ctx = Context::last(); } $result['at'] = $ctx->host() . $ctx->folder(); $result['version_link'] = 'http://code.google.com/p/molinos-cms/wiki/ChangeLog_' . str_replace('.', '_', mcms::version(mcms::VERSION_STABLE)); if ($full) { $options = array(); if (count($parts = explode(':', mcms::config('db')))) { if (in_array($parts[0], Database::listDrivers())) { $options[] = $parts[0]; } } $options[] = str_replace('_provider', '', get_class(cache::getInstance())); $options[] = ini_get('memory_limit'); $result['options'] = join('+', $options); } } catch (Exception $e) { } return $result; }
/** * Возвращает список источников обновлений. */ public static function getSources() { if (!is_array($urls = mcms::config('sources'))) { $urls = array(); } $default = 'http://molinos-cms.googlecode.com/svn/dist/' . mcms::version(mcms::VERSION_RELEASE) . '/modules.ini'; if (!in_array($default, $urls)) { $urls[] = $default; } asort($urls); return $urls; }
public static function fetch($url, $options = null) { // FIXME: придумать нормальное решение! try { $tmpdir = Context::last()->config->getPath('main/tmpdir'); } catch (Exception $e) { $tmpdir = null; } if (!$tmpdir) { $tmpdir = 'tmp'; } $outfile = os::path(os::mkdir($tmpdir), 'mcms-fetch.' . md5($url)); $ttl = mcms::config('file.cache.ttl', 3600); if (file_exists($outfile) and ($options & self::NO_CACHE or time() - $ttl > @filectime($outfile))) { if (is_writable(dirname($outfile))) { Logger::log('removing cached copy of ' . $url, 'fetch'); unlink($outfile); } } // Скачиваем файл только если его нет на диске во временной директории if (file_exists($outfile)) { Logger::log('found in cache: ' . $url, 'fetch'); } else { if (function_exists('curl_init')) { $ch = curl_init($url); $fp = fopen($outfile, "w+"); curl_setopt($ch, CURLOPT_FILE, $fp); curl_setopt($ch, CURLOPT_HEADER, 0); if (null !== ($time = ini_get('max_execution_time'))) { curl_setopt($ch, CURLOPT_TIMEOUT, $time); } curl_setopt($ch, CURLOPT_USERAGENT, 'Molinos.CMS/' . mcms::version() . '; http://' . MCMS_HOST_NAME); if (!ini_get('safe_mode')) { curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1); } curl_exec($ch); $code = curl_getinfo($ch, CURLINFO_HTTP_CODE); curl_close($ch); fclose($fp); if (200 != $code) { Logger::log($url . ': error ' . $code, 'fetch'); unlink($outfile); return null; } } elseif ($f = @fopen($url, 'rb')) { if (!($out = fopen($outfile, 'w'))) { throw new RuntimeException(t('Не удалось сохранить временный файл %name', array('%name' => $outfile))); } while (!feof($f)) { fwrite($out, fread($f, 1024)); } fclose($f); fclose($out); } else { Logger::log($url . ': failed.', 'fetch'); throw new RuntimeException(t('Не удалось загрузить файл: ' . 'модуль CURL отсутствует, ' . 'открыть поток HTTP тоже не удалось.')); } if (function_exists('get_headers')) { $headers = get_headers($url, true); if (!empty($headers['Content-Length']) and ($real = $headers['Content-Length']) != ($got = filesize($outfile))) { unlink($outfile); throw new RuntimeException(t('Не удалось скачать файл: вместо %real байтов было получено %got.', array('%got' => $got, '%real' => $real))); } } } if ($options & self::CONTENT) { $content = file_get_contents($outfile); return $content; } else { return $outfile; } }