From af8bd4b45f66e88d3535d688eb3ae88789db3867 Mon Sep 17 00:00:00 2001 From: rabuzarus <> Date: Tue, 21 Mar 2017 03:35:25 +0100 Subject: [PATCH 01/32] frio: gui work for fbrowser + switch between image and file mode --- view/theme/frio/css/style.css | 41 +++++++++++++ view/theme/frio/js/filebrowser.js | 70 ++++++++++++++--------- view/theme/frio/templates/filebrowser.tpl | 48 +++++++++------- 3 files changed, 110 insertions(+), 49 deletions(-) diff --git a/view/theme/frio/css/style.css b/view/theme/frio/css/style.css index e0a0b09b76..7f3d522a9d 100644 --- a/view/theme/frio/css/style.css +++ b/view/theme/frio/css/style.css @@ -1273,6 +1273,47 @@ section #jotOpen { } /* Filebrowser */ +.fbrowser .breadcrumb { + margin-bottom: 0px; +} +.fbrowser .path a:before { + content: ""; + padding: 0; +} +.fbrowser .breadcrumb > li:last-of-type a{ + color: #777; + pointer-events: none; + cursor: default; +} +.fbrowser .folders { + box-shadow: -1.5px 0 0 0 rgba(0, 0, 0, .1) inset; + padding-right: 1px; +} +.fbrowser .folders ul { + padding-left: 0px; + margin-left: -15px; +} +.fbrowser .folders li { + padding-left: 20px; + padding-right: 10px; + padding-top: 2px; + padding-bottom: 2px; +} +.fbrowser .folders li:hover { + z-index: 2; + color: #555; + background-color: rgba(247, 247, 247, $contentbg_transp); + border-left: 3px solid $link_color !important; + padding-left: 17px; +} +.fbrowser .folders li a, +.fbrowser .folders li a:hover { + color: #555; + font-size: 13px; +} +.fbrowser .folders + .list { + padding-left: 10px; +} .fbrowser .profile-rotator-wrapper { min-height: 200px; } diff --git a/view/theme/frio/js/filebrowser.js b/view/theme/frio/js/filebrowser.js index a66309865d..5c60c44cad 100644 --- a/view/theme/frio/js/filebrowser.js +++ b/view/theme/frio/js/filebrowser.js @@ -81,15 +81,14 @@ var FileBrowser = { FileBrowser.id = h.split("-")[1]; FileBrowser.event = FileBrowser.event + "." + destination; if (destination == "comment") { - // get the comment textimput field + // Get the comment textimput field var commentElm = document.getElementById("comment-edit-text-" + FileBrowser.id); } }; console.log("FileBrowser:", nickname, type,FileBrowser.event, FileBrowser.id ); - // We need to add the AjaxUpload to the button - FileBrowser.uploadButtons(); + FileBrowser.postLoad(); $(".error a.close").on("click", function(e) { e.preventDefault(); @@ -100,22 +99,11 @@ var FileBrowser = { $(".fbrowser").on("click", ".folders a, .path a", function(e) { e.preventDefault(); var url = baseurl + "/fbrowser/" + FileBrowser.type + "/" + this.dataset.folder + "?mode=none"; - $(".fbrowser-content").hide(); - $(".fbrowser .profile-rotator-wrapper").show(); - // load new content to fbrowser window - $(".fbrowser").load(url, function(responseText, textStatus){ - $(".profile-rotator-wrapper").hide(); - if (textStatus === 'success') { - $(".fbrowser_content").show(); - // We need to add the AjaxUpload to the button - FileBrowser.uploadButtons(); - } - }); - + FileBrowser.loadContent(url); }); - //embed on click + //Embed on click $(".fbrowser").on('click', ".photo-album-photo-link", function(e) { e.preventDefault(); @@ -123,7 +111,7 @@ var FileBrowser = { if (FileBrowser.type == "image") { embed = "[url="+this.dataset.link+"][img]"+this.dataset.img+"[/img][/url]"; } - if (FileBrowser.type=="file") { + if (FileBrowser.type == "file") { // attachment links are "baseurl/attach/id"; we need id embed = "[attachment]"+this.dataset.link.split("/").pop()+"[/attachment]"; } @@ -149,13 +137,24 @@ var FileBrowser = { this.dataset.img, ]); - // close model + // Close model $('#modal').modal('hide'); - // update autosize for this textarea + // Update autosize for this textarea autosize.update($(".text-autosize")); }); + + // EventListener for switching between image and file mode + $(".fbrowser").on('click', ".fbswitcher .btn", function(e) { + e.preventDefault(); + FileBrowser.type = this.getAttribute("data-mode"); + $(".fbrowser").removeClass().addClass("fbrowser " + FileBrowser.type); + url = baseurl + "/fbrowser/" + FileBrowser.type + "?mode=none"; + + FileBrowser.loadContent(url); + }); }, + // Initialize the AjaxUpload for the upload buttons uploadButtons: function() { if ($("#upload-image").length) { var image_uploader = new window.AjaxUpload( @@ -176,15 +175,12 @@ var FileBrowser = { return; } - $(".profile-rotator-wrapper").hide(); - $(".fbrowser_content").show(); - // location = baseurl + "/fbrowser/image/?mode=none"+location['hash']; // location.reload(true); var url = baseurl + "/fbrowser/" + FileBrowser.type + "?mode=none" // load new content to fbrowser window - $(".fbrowser").load(url); + FileBrowser.loadContent(url); } } ); @@ -208,18 +204,36 @@ var FileBrowser = { return; } - $(".profile-rotator-wrapper").hide(); - $(".fbrowser_content").show(); - // location = baseurl + "/fbrowser/file/?mode=none"+location['hash']; // location.reload(true); var url = baseurl + "/fbrowser/" + FileBrowser.type + "?mode=none" - // load new content to fbrowser window - $(".fbrowser").load(url); + // Load new content to fbrowser window + FileBrowser.loadContent(url) } } ); } + }, + + postLoad: function() { + $(".fbrowser .fbswitcher .btn").removeClass("active"); + $(".fbrowser .fbswitcher [data-mode=" + FileBrowser.type + "]").addClass("active"); + // We need to add the AjaxUpload to the button + FileBrowser.uploadButtons(); + }, + + loadContent: function(url) { + $(".fbrowser-content").hide(); + $(".fbrowser .profile-rotator-wrapper").show(); + + // load new content to fbrowser window + $(".fbrowser").load(url, function(responseText, textStatus){ + $(".profile-rotator-wrapper").hide(); + if (textStatus === 'success') { + $(".fbrowser_content").show(); + FileBrowser.postLoad(); + } + }); } }; diff --git a/view/theme/frio/templates/filebrowser.tpl b/view/theme/frio/templates/filebrowser.tpl index 1a1bd9a675..dc8a9593a3 100644 --- a/view/theme/frio/templates/filebrowser.tpl +++ b/view/theme/frio/templates/filebrowser.tpl @@ -16,27 +16,33 @@ X -
{{$f.1}}
- + + +{{$f.1}}
+ +{{$f.1}}
- +{{$f.1}}
+ +' . $o . '
');
+ return '' . $o . '
';
}
diff --git a/library/Text_Highlighter/README b/library/Text_Highlighter/README
deleted file mode 100644
index 88f71aed27..0000000000
--- a/library/Text_Highlighter/README
+++ /dev/null
@@ -1,455 +0,0 @@
-# $Id$
-
-Introduction
-============
-
-Text_Highlighter is a class for syntax highlighting. The main idea is to
-simplify creation of subclasses implementing syntax highlighting for
-particular language. Subclasses do not implement any new functioanality, they
-just provide syntax highlighting rules. The rules sources are in XML format.
-To create a highlighter for a language, there is no need to code a new class
-manually. Simply describe the rules in XML file and use Text_Highlighter_Generator
-to create a new class.
-
-
-This document does not contain a formal description of API - it is very
-simple, and I believe providing some examples of code is sufficient.
-
-
-Highlighter XML source
-======================
-
-Basics
-------
-
-Creating a new syntax highlighter begins with describing the highlighting
-rules. There are two basic elements: block and region. A block is just a
-portion of text matching a regular expression and highlighted with a single
-color. Keyword is an example of a block. A region is defined by two regular
-expressions: one for start of region, and another for the end. The main
-difference from a block is that a region can contain blocks and regions
-(including same-named regions). An example of a region is a group of
-statements enclosed in curly brackets (this is used in many languages, for
-example PHP and C). Also, characters matching start and end of a region may be
-highlighted with their own color, and region contents with another.
-
-Blocks and regions may be declared as contained. Contained blocks and regions
-can only appear inside regions. If a region or a block is not declared as
-contained, it can appear both on top level and inside regions. Block or region
-declared as not-contained can only appear on top level.
-
-For any region, a list of blocks and regions that can appear inside this
-region can be specified.
-
-In this document, the term "color group" is used. Chunks of text assigned to
-same color group will be highlighted with same color. Note that in versions
-prior 0.5.0 color goups were refered as CSS classes, but since 0.5.0 not only
-HTML output is supported, so "color group" is more appropriate term.
-
-Elements
---------
-
-The toplevel element is
+ * array('pkg' => 'package_name', 'file' => '/path/to/local/file',
+ * 'info' => array() // parsed package.xml
+ * );
+ *
+ * @access private
+ * @var array
+ */
+ var $_downloadedPackages = array();
+
+ /**
+ * Packages slated for download.
+ *
+ * This is used to prevent downloading a package more than once should it be a dependency
+ * for two packages to be installed.
+ * Format of each entry:
+ *
+ * + * array('package_name1' => parsed package.xml, 'package_name2' => parsed package.xml, + * ); + *+ * @access private + * @var array + */ + var $_toDownload = array(); + + /** + * Array of every package installed, with names lower-cased. + * + * Format: + *
+ * array('package1' => 0, 'package2' => 1, );
+ *
+ * @var array
+ */
+ var $_installed = array();
+
+ /**
+ * @var array
+ * @access private
+ */
+ var $_errorStack = array();
+
+ /**
+ * @var boolean
+ * @access private
+ */
+ var $_internalDownload = false;
+
+ /**
+ * Temporary variable used in sorting packages by dependency in {@link sortPkgDeps()}
+ * @var array
+ * @access private
+ */
+ var $_packageSortTree;
+
+ /**
+ * Temporary directory, or configuration value where downloads will occur
+ * @var string
+ */
+ var $_downloadDir;
+
+ /**
+ * List of methods that can be called both statically and non-statically.
+ * @var array
+ */
+ protected static $bivalentMethods = array(
+ 'setErrorHandling' => true,
+ 'raiseError' => true,
+ 'throwError' => true,
+ 'pushErrorHandling' => true,
+ 'popErrorHandling' => true,
+ 'downloadHttp' => true,
+ );
+
+ /**
+ * @param PEAR_Frontend_*
+ * @param array
+ * @param PEAR_Config
+ */
+ function __construct($ui = null, $options = array(), $config = null)
+ {
+ parent::__construct();
+ $this->_options = $options;
+ if ($config !== null) {
+ $this->config = &$config;
+ $this->_preferredState = $this->config->get('preferred_state');
+ }
+ $this->ui = &$ui;
+ if (!$this->_preferredState) {
+ // don't inadvertently use a non-set preferred_state
+ $this->_preferredState = null;
+ }
+
+ if ($config !== null) {
+ if (isset($this->_options['installroot'])) {
+ $this->config->setInstallRoot($this->_options['installroot']);
+ }
+ $this->_registry = &$config->getRegistry();
+ }
+
+ if (isset($this->_options['alldeps']) || isset($this->_options['onlyreqdeps'])) {
+ $this->_installed = $this->_registry->listAllPackages();
+ foreach ($this->_installed as $key => $unused) {
+ if (!count($unused)) {
+ continue;
+ }
+ $strtolower = create_function('$a','return strtolower($a);');
+ array_walk($this->_installed[$key], $strtolower);
+ }
+ }
+ }
+
+ /**
+ * Attempt to discover a channel's remote capabilities from
+ * its server name
+ * @param string
+ * @return boolean
+ */
+ function discover($channel)
+ {
+ $this->log(1, 'Attempting to discover channel "' . $channel . '"...');
+ PEAR::pushErrorHandling(PEAR_ERROR_RETURN);
+ $callback = $this->ui ? array(&$this, '_downloadCallback') : null;
+ if (!class_exists('System')) {
+ require_once 'System.php';
+ }
+
+ $tmpdir = $this->config->get('temp_dir');
+ $tmp = System::mktemp('-d -t "' . $tmpdir . '"');
+ $a = $this->downloadHttp('http://' . $channel . '/channel.xml', $this->ui, $tmp, $callback, false);
+ PEAR::popErrorHandling();
+ if (PEAR::isError($a)) {
+ // Attempt to fallback to https automatically.
+ PEAR::pushErrorHandling(PEAR_ERROR_RETURN);
+ $this->log(1, 'Attempting fallback to https instead of http on channel "' . $channel . '"...');
+ $a = $this->downloadHttp('https://' . $channel . '/channel.xml', $this->ui, $tmp, $callback, false);
+ PEAR::popErrorHandling();
+ if (PEAR::isError($a)) {
+ return false;
+ }
+ }
+
+ list($a, $lastmodified) = $a;
+ if (!class_exists('PEAR_ChannelFile')) {
+ require_once 'PEAR/ChannelFile.php';
+ }
+
+ $b = new PEAR_ChannelFile;
+ if ($b->fromXmlFile($a)) {
+ unlink($a);
+ if ($this->config->get('auto_discover')) {
+ $this->_registry->addChannel($b, $lastmodified);
+ $alias = $b->getName();
+ if ($b->getName() == $this->_registry->channelName($b->getAlias())) {
+ $alias = $b->getAlias();
+ }
+
+ $this->log(1, 'Auto-discovered channel "' . $channel .
+ '", alias "' . $alias . '", adding to registry');
+ }
+
+ return true;
+ }
+
+ unlink($a);
+ return false;
+ }
+
+ /**
+ * For simpler unit-testing
+ * @param PEAR_Downloader
+ * @return PEAR_Downloader_Package
+ */
+ function newDownloaderPackage(&$t)
+ {
+ if (!class_exists('PEAR_Downloader_Package')) {
+ require_once 'PEAR/Downloader/Package.php';
+ }
+ $a = new PEAR_Downloader_Package($t);
+ return $a;
+ }
+
+ /**
+ * For simpler unit-testing
+ * @param PEAR_Config
+ * @param array
+ * @param array
+ * @param int
+ */
+ function &getDependency2Object(&$c, $i, $p, $s)
+ {
+ if (!class_exists('PEAR_Dependency2')) {
+ require_once 'PEAR/Dependency2.php';
+ }
+ $z = new PEAR_Dependency2($c, $i, $p, $s);
+ return $z;
+ }
+
+ function &download($params)
+ {
+ if (!count($params)) {
+ $a = array();
+ return $a;
+ }
+
+ if (!isset($this->_registry)) {
+ $this->_registry = &$this->config->getRegistry();
+ }
+
+ $channelschecked = array();
+ // convert all parameters into PEAR_Downloader_Package objects
+ foreach ($params as $i => $param) {
+ $params[$i] = $this->newDownloaderPackage($this);
+ PEAR::staticPushErrorHandling(PEAR_ERROR_RETURN);
+ $err = $params[$i]->initialize($param);
+ PEAR::staticPopErrorHandling();
+ if (!$err) {
+ // skip parameters that were missed by preferred_state
+ continue;
+ }
+
+ if (PEAR::isError($err)) {
+ if (!isset($this->_options['soft']) && $err->getMessage() !== '') {
+ $this->log(0, $err->getMessage());
+ }
+
+ $params[$i] = false;
+ if (is_object($param)) {
+ $param = $param->getChannel() . '/' . $param->getPackage();
+ }
+
+ if (!isset($this->_options['soft'])) {
+ $this->log(2, 'Package "' . $param . '" is not valid');
+ }
+
+ // Message logged above in a specific verbose mode, passing null to not show up on CLI
+ $this->pushError(null, PEAR_INSTALLER_SKIPPED);
+ } else {
+ do {
+ if ($params[$i] && $params[$i]->getType() == 'local') {
+ // bug #7090 skip channel.xml check for local packages
+ break;
+ }
+
+ if ($params[$i] && !isset($channelschecked[$params[$i]->getChannel()]) &&
+ !isset($this->_options['offline'])
+ ) {
+ $channelschecked[$params[$i]->getChannel()] = true;
+ PEAR::staticPushErrorHandling(PEAR_ERROR_RETURN);
+ if (!class_exists('System')) {
+ require_once 'System.php';
+ }
+
+ $curchannel = $this->_registry->getChannel($params[$i]->getChannel());
+ if (PEAR::isError($curchannel)) {
+ PEAR::staticPopErrorHandling();
+ return $this->raiseError($curchannel);
+ }
+
+ if (PEAR::isError($dir = $this->getDownloadDir())) {
+ PEAR::staticPopErrorHandling();
+ break;
+ }
+
+ $mirror = $this->config->get('preferred_mirror', null, $params[$i]->getChannel());
+ $url = 'http://' . $mirror . '/channel.xml';
+ $a = $this->downloadHttp($url, $this->ui, $dir, null, $curchannel->lastModified());
+
+ PEAR::staticPopErrorHandling();
+ if ($a === false) {
+ //channel.xml not modified
+ break;
+ } else if (PEAR::isError($a)) {
+ // Attempt fallback to https automatically
+ PEAR::pushErrorHandling(PEAR_ERROR_RETURN);
+ $a = $this->downloadHttp('https://' . $mirror .
+ '/channel.xml', $this->ui, $dir, null, $curchannel->lastModified());
+
+ PEAR::staticPopErrorHandling();
+ if (PEAR::isError($a) || !$a) {
+ break;
+ }
+ }
+ $this->log(0, 'WARNING: channel "' . $params[$i]->getChannel() . '" has ' .
+ 'updated its protocols, use "' . PEAR_RUNTYPE . ' channel-update ' . $params[$i]->getChannel() .
+ '" to update');
+ }
+ } while (false);
+
+ if ($params[$i] && !isset($this->_options['downloadonly'])) {
+ if (isset($this->_options['packagingroot'])) {
+ $checkdir = $this->_prependPath(
+ $this->config->get('php_dir', null, $params[$i]->getChannel()),
+ $this->_options['packagingroot']);
+ } else {
+ $checkdir = $this->config->get('php_dir',
+ null, $params[$i]->getChannel());
+ }
+
+ while ($checkdir && $checkdir != '/' && !file_exists($checkdir)) {
+ $checkdir = dirname($checkdir);
+ }
+
+ if ($checkdir == '.') {
+ $checkdir = '/';
+ }
+
+ if (!is_writeable($checkdir)) {
+ return PEAR::raiseError('Cannot install, php_dir for channel "' .
+ $params[$i]->getChannel() . '" is not writeable by the current user');
+ }
+ }
+ }
+ }
+
+ unset($channelschecked);
+ PEAR_Downloader_Package::removeDuplicates($params);
+ if (!count($params)) {
+ $a = array();
+ return $a;
+ }
+
+ if (!isset($this->_options['nodeps']) && !isset($this->_options['offline'])) {
+ $reverify = true;
+ while ($reverify) {
+ $reverify = false;
+ foreach ($params as $i => $param) {
+ //PHP Bug 40768 / PEAR Bug #10944
+ //Nested foreaches fail in PHP 5.2.1
+ key($params);
+ $ret = $params[$i]->detectDependencies($params);
+ if (PEAR::isError($ret)) {
+ $reverify = true;
+ $params[$i] = false;
+ PEAR_Downloader_Package::removeDuplicates($params);
+ if (!isset($this->_options['soft'])) {
+ $this->log(0, $ret->getMessage());
+ }
+ continue 2;
+ }
+ }
+ }
+ }
+
+ if (isset($this->_options['offline'])) {
+ $this->log(3, 'Skipping dependency download check, --offline specified');
+ }
+
+ if (!count($params)) {
+ $a = array();
+ return $a;
+ }
+
+ while (PEAR_Downloader_Package::mergeDependencies($params));
+ PEAR_Downloader_Package::removeDuplicates($params, true);
+ $errorparams = array();
+ if (PEAR_Downloader_Package::detectStupidDuplicates($params, $errorparams)) {
+ if (count($errorparams)) {
+ foreach ($errorparams as $param) {
+ $name = $this->_registry->parsedPackageNameToString($param->getParsedPackage());
+ $this->pushError('Duplicate package ' . $name . ' found', PEAR_INSTALLER_FAILED);
+ }
+ $a = array();
+ return $a;
+ }
+ }
+
+ PEAR_Downloader_Package::removeInstalled($params);
+ if (!count($params)) {
+ $this->pushError('No valid packages found', PEAR_INSTALLER_FAILED);
+ $a = array();
+ return $a;
+ }
+
+ PEAR::pushErrorHandling(PEAR_ERROR_RETURN);
+ $err = $this->analyzeDependencies($params);
+ PEAR::popErrorHandling();
+ if (!count($params)) {
+ $this->pushError('No valid packages found', PEAR_INSTALLER_FAILED);
+ $a = array();
+ return $a;
+ }
+
+ $ret = array();
+ $newparams = array();
+ if (isset($this->_options['pretend'])) {
+ return $params;
+ }
+
+ $somefailed = false;
+ foreach ($params as $i => $package) {
+ PEAR::staticPushErrorHandling(PEAR_ERROR_RETURN);
+ $pf = &$params[$i]->download();
+ PEAR::staticPopErrorHandling();
+ if (PEAR::isError($pf)) {
+ if (!isset($this->_options['soft'])) {
+ $this->log(1, $pf->getMessage());
+ $this->log(0, 'Error: cannot download "' .
+ $this->_registry->parsedPackageNameToString($package->getParsedPackage(),
+ true) .
+ '"');
+ }
+ $somefailed = true;
+ continue;
+ }
+
+ $newparams[] = &$params[$i];
+ $ret[] = array(
+ 'file' => $pf->getArchiveFile(),
+ 'info' => &$pf,
+ 'pkg' => $pf->getPackage()
+ );
+ }
+
+ if ($somefailed) {
+ // remove params that did not download successfully
+ PEAR::pushErrorHandling(PEAR_ERROR_RETURN);
+ $err = $this->analyzeDependencies($newparams, true);
+ PEAR::popErrorHandling();
+ if (!count($newparams)) {
+ $this->pushError('Download failed', PEAR_INSTALLER_FAILED);
+ $a = array();
+ return $a;
+ }
+ }
+
+ $this->_downloadedPackages = $ret;
+ return $newparams;
+ }
+
+ /**
+ * @param array all packages to be installed
+ */
+ function analyzeDependencies(&$params, $force = false)
+ {
+ if (isset($this->_options['downloadonly'])) {
+ return;
+ }
+
+ PEAR::staticPushErrorHandling(PEAR_ERROR_RETURN);
+ $redo = true;
+ $reset = $hasfailed = $failed = false;
+ while ($redo) {
+ $redo = false;
+ foreach ($params as $i => $param) {
+ $deps = $param->getDeps();
+ if (!$deps) {
+ $depchecker = &$this->getDependency2Object($this->config, $this->getOptions(),
+ $param->getParsedPackage(), PEAR_VALIDATE_DOWNLOADING);
+ $send = $param->getPackageFile();
+
+ $installcheck = $depchecker->validatePackage($send, $this, $params);
+ if (PEAR::isError($installcheck)) {
+ if (!isset($this->_options['soft'])) {
+ $this->log(0, $installcheck->getMessage());
+ }
+ $hasfailed = true;
+ $params[$i] = false;
+ $reset = true;
+ $redo = true;
+ $failed = false;
+ PEAR_Downloader_Package::removeDuplicates($params);
+ continue 2;
+ }
+ continue;
+ }
+
+ if (!$reset && $param->alreadyValidated() && !$force) {
+ continue;
+ }
+
+ if (count($deps)) {
+ $depchecker = &$this->getDependency2Object($this->config, $this->getOptions(),
+ $param->getParsedPackage(), PEAR_VALIDATE_DOWNLOADING);
+ $send = $param->getPackageFile();
+ if ($send === null) {
+ $send = $param->getDownloadURL();
+ }
+
+ $installcheck = $depchecker->validatePackage($send, $this, $params);
+ if (PEAR::isError($installcheck)) {
+ if (!isset($this->_options['soft'])) {
+ $this->log(0, $installcheck->getMessage());
+ }
+ $hasfailed = true;
+ $params[$i] = false;
+ $reset = true;
+ $redo = true;
+ $failed = false;
+ PEAR_Downloader_Package::removeDuplicates($params);
+ continue 2;
+ }
+
+ $failed = false;
+ if (isset($deps['required']) && is_array($deps['required'])) {
+ foreach ($deps['required'] as $type => $dep) {
+ // note: Dependency2 will never return a PEAR_Error if ignore-errors
+ // is specified, so soft is needed to turn off logging
+ if (!isset($dep[0])) {
+ if (PEAR::isError($e = $depchecker->{"validate{$type}Dependency"}($dep,
+ true, $params))) {
+ $failed = true;
+ if (!isset($this->_options['soft'])) {
+ $this->log(0, $e->getMessage());
+ }
+ } elseif (is_array($e) && !$param->alreadyValidated()) {
+ if (!isset($this->_options['soft'])) {
+ $this->log(0, $e[0]);
+ }
+ }
+ } else {
+ foreach ($dep as $d) {
+ if (PEAR::isError($e =
+ $depchecker->{"validate{$type}Dependency"}($d,
+ true, $params))) {
+ $failed = true;
+ if (!isset($this->_options['soft'])) {
+ $this->log(0, $e->getMessage());
+ }
+ } elseif (is_array($e) && !$param->alreadyValidated()) {
+ if (!isset($this->_options['soft'])) {
+ $this->log(0, $e[0]);
+ }
+ }
+ }
+ }
+ }
+
+ if (isset($deps['optional']) && is_array($deps['optional'])) {
+ foreach ($deps['optional'] as $type => $dep) {
+ if (!isset($dep[0])) {
+ if (PEAR::isError($e =
+ $depchecker->{"validate{$type}Dependency"}($dep,
+ false, $params))) {
+ $failed = true;
+ if (!isset($this->_options['soft'])) {
+ $this->log(0, $e->getMessage());
+ }
+ } elseif (is_array($e) && !$param->alreadyValidated()) {
+ if (!isset($this->_options['soft'])) {
+ $this->log(0, $e[0]);
+ }
+ }
+ } else {
+ foreach ($dep as $d) {
+ if (PEAR::isError($e =
+ $depchecker->{"validate{$type}Dependency"}($d,
+ false, $params))) {
+ $failed = true;
+ if (!isset($this->_options['soft'])) {
+ $this->log(0, $e->getMessage());
+ }
+ } elseif (is_array($e) && !$param->alreadyValidated()) {
+ if (!isset($this->_options['soft'])) {
+ $this->log(0, $e[0]);
+ }
+ }
+ }
+ }
+ }
+ }
+
+ $groupname = $param->getGroup();
+ if (isset($deps['group']) && $groupname) {
+ if (!isset($deps['group'][0])) {
+ $deps['group'] = array($deps['group']);
+ }
+
+ $found = false;
+ foreach ($deps['group'] as $group) {
+ if ($group['attribs']['name'] == $groupname) {
+ $found = true;
+ break;
+ }
+ }
+
+ if ($found) {
+ unset($group['attribs']);
+ foreach ($group as $type => $dep) {
+ if (!isset($dep[0])) {
+ if (PEAR::isError($e =
+ $depchecker->{"validate{$type}Dependency"}($dep,
+ false, $params))) {
+ $failed = true;
+ if (!isset($this->_options['soft'])) {
+ $this->log(0, $e->getMessage());
+ }
+ } elseif (is_array($e) && !$param->alreadyValidated()) {
+ if (!isset($this->_options['soft'])) {
+ $this->log(0, $e[0]);
+ }
+ }
+ } else {
+ foreach ($dep as $d) {
+ if (PEAR::isError($e =
+ $depchecker->{"validate{$type}Dependency"}($d,
+ false, $params))) {
+ $failed = true;
+ if (!isset($this->_options['soft'])) {
+ $this->log(0, $e->getMessage());
+ }
+ } elseif (is_array($e) && !$param->alreadyValidated()) {
+ if (!isset($this->_options['soft'])) {
+ $this->log(0, $e[0]);
+ }
+ }
+ }
+ }
+ }
+ }
+ }
+ } else {
+ foreach ($deps as $dep) {
+ if (PEAR::isError($e = $depchecker->validateDependency1($dep, $params))) {
+ $failed = true;
+ if (!isset($this->_options['soft'])) {
+ $this->log(0, $e->getMessage());
+ }
+ } elseif (is_array($e) && !$param->alreadyValidated()) {
+ if (!isset($this->_options['soft'])) {
+ $this->log(0, $e[0]);
+ }
+ }
+ }
+ }
+ $params[$i]->setValidated();
+ }
+
+ if ($failed) {
+ $hasfailed = true;
+ $params[$i] = false;
+ $reset = true;
+ $redo = true;
+ $failed = false;
+ PEAR_Downloader_Package::removeDuplicates($params);
+ continue 2;
+ }
+ }
+ }
+
+ PEAR::staticPopErrorHandling();
+ if ($hasfailed && (isset($this->_options['ignore-errors']) ||
+ isset($this->_options['nodeps']))) {
+ // this is probably not needed, but just in case
+ if (!isset($this->_options['soft'])) {
+ $this->log(0, 'WARNING: dependencies failed');
+ }
+ }
+ }
+
+ /**
+ * Retrieve the directory that downloads will happen in
+ * @access private
+ * @return string
+ */
+ function getDownloadDir()
+ {
+ if (isset($this->_downloadDir)) {
+ return $this->_downloadDir;
+ }
+
+ $downloaddir = $this->config->get('download_dir');
+ if (empty($downloaddir) || (is_dir($downloaddir) && !is_writable($downloaddir))) {
+ if (is_dir($downloaddir) && !is_writable($downloaddir)) {
+ $this->log(0, 'WARNING: configuration download directory "' . $downloaddir .
+ '" is not writeable. Change download_dir config variable to ' .
+ 'a writeable dir to avoid this warning');
+ }
+
+ if (!class_exists('System')) {
+ require_once 'System.php';
+ }
+
+ if (PEAR::isError($downloaddir = System::mktemp('-d'))) {
+ return $downloaddir;
+ }
+ $this->log(3, '+ tmp dir created at ' . $downloaddir);
+ }
+
+ if (!is_writable($downloaddir)) {
+ if (PEAR::isError(System::mkdir(array('-p', $downloaddir))) ||
+ !is_writable($downloaddir)) {
+ return PEAR::raiseError('download directory "' . $downloaddir .
+ '" is not writeable. Change download_dir config variable to ' .
+ 'a writeable dir');
+ }
+ }
+
+ return $this->_downloadDir = $downloaddir;
+ }
+
+ function setDownloadDir($dir)
+ {
+ if (!@is_writable($dir)) {
+ if (PEAR::isError(System::mkdir(array('-p', $dir)))) {
+ return PEAR::raiseError('download directory "' . $dir .
+ '" is not writeable. Change download_dir config variable to ' .
+ 'a writeable dir');
+ }
+ }
+ $this->_downloadDir = $dir;
+ }
+
+ function configSet($key, $value, $layer = 'user', $channel = false)
+ {
+ $this->config->set($key, $value, $layer, $channel);
+ $this->_preferredState = $this->config->get('preferred_state', null, $channel);
+ if (!$this->_preferredState) {
+ // don't inadvertently use a non-set preferred_state
+ $this->_preferredState = null;
+ }
+ }
+
+ function setOptions($options)
+ {
+ $this->_options = $options;
+ }
+
+ function getOptions()
+ {
+ return $this->_options;
+ }
+
+
+ /**
+ * @param array output of {@link parsePackageName()}
+ * @access private
+ */
+ function _getPackageDownloadUrl($parr)
+ {
+ $curchannel = $this->config->get('default_channel');
+ $this->configSet('default_channel', $parr['channel']);
+ // getDownloadURL returns an array. On error, it only contains information
+ // on the latest release as array(version, info). On success it contains
+ // array(version, info, download url string)
+ $state = isset($parr['state']) ? $parr['state'] : $this->config->get('preferred_state');
+ if (!$this->_registry->channelExists($parr['channel'])) {
+ do {
+ if ($this->config->get('auto_discover') && $this->discover($parr['channel'])) {
+ break;
+ }
+
+ $this->configSet('default_channel', $curchannel);
+ return PEAR::raiseError('Unknown remote channel: ' . $parr['channel']);
+ } while (false);
+ }
+
+ $chan = $this->_registry->getChannel($parr['channel']);
+ if (PEAR::isError($chan)) {
+ return $chan;
+ }
+
+ PEAR::staticPushErrorHandling(PEAR_ERROR_RETURN);
+ $version = $this->_registry->packageInfo($parr['package'], 'version', $parr['channel']);
+ $stability = $this->_registry->packageInfo($parr['package'], 'stability', $parr['channel']);
+ // package is installed - use the installed release stability level
+ if (!isset($parr['state']) && $stability !== null) {
+ $state = $stability['release'];
+ }
+ PEAR::staticPopErrorHandling();
+ $base2 = false;
+
+ $preferred_mirror = $this->config->get('preferred_mirror');
+ if (!$chan->supportsREST($preferred_mirror) ||
+ (
+ !($base2 = $chan->getBaseURL('REST1.3', $preferred_mirror))
+ &&
+ !($base = $chan->getBaseURL('REST1.0', $preferred_mirror))
+ )
+ ) {
+ return $this->raiseError($parr['channel'] . ' is using a unsupported protocol - This should never happen.');
+ }
+
+ if ($base2) {
+ $rest = &$this->config->getREST('1.3', $this->_options);
+ $base = $base2;
+ } else {
+ $rest = &$this->config->getREST('1.0', $this->_options);
+ }
+
+ $downloadVersion = false;
+ if (!isset($parr['version']) && !isset($parr['state']) && $version
+ && !PEAR::isError($version)
+ && !isset($this->_options['downloadonly'])
+ ) {
+ $downloadVersion = $version;
+ }
+
+ $url = $rest->getDownloadURL($base, $parr, $state, $downloadVersion, $chan->getName());
+ if (PEAR::isError($url)) {
+ $this->configSet('default_channel', $curchannel);
+ return $url;
+ }
+
+ if ($parr['channel'] != $curchannel) {
+ $this->configSet('default_channel', $curchannel);
+ }
+
+ if (!is_array($url)) {
+ return $url;
+ }
+
+ $url['raw'] = false; // no checking is necessary for REST
+ if (!is_array($url['info'])) {
+ return PEAR::raiseError('Invalid remote dependencies retrieved from REST - ' .
+ 'this should never happen');
+ }
+
+ if (!isset($this->_options['force']) &&
+ !isset($this->_options['downloadonly']) &&
+ $version &&
+ !PEAR::isError($version) &&
+ !isset($parr['group'])
+ ) {
+ if (version_compare($version, $url['version'], '=')) {
+ return PEAR::raiseError($this->_registry->parsedPackageNameToString(
+ $parr, true) . ' is already installed and is the same as the ' .
+ 'released version ' . $url['version'], -976);
+ }
+
+ if (version_compare($version, $url['version'], '>')) {
+ return PEAR::raiseError($this->_registry->parsedPackageNameToString(
+ $parr, true) . ' is already installed and is newer than detected ' .
+ 'released version ' . $url['version'], -976);
+ }
+ }
+
+ if (isset($url['info']['required']) || $url['compatible']) {
+ require_once 'PEAR/PackageFile/v2.php';
+ $pf = new PEAR_PackageFile_v2;
+ $pf->setRawChannel($parr['channel']);
+ if ($url['compatible']) {
+ $pf->setRawCompatible($url['compatible']);
+ }
+ } else {
+ require_once 'PEAR/PackageFile/v1.php';
+ $pf = new PEAR_PackageFile_v1;
+ }
+
+ $pf->setRawPackage($url['package']);
+ $pf->setDeps($url['info']);
+ if ($url['compatible']) {
+ $pf->setCompatible($url['compatible']);
+ }
+
+ $pf->setRawState($url['stability']);
+ $url['info'] = &$pf;
+ if (!extension_loaded("zlib") || isset($this->_options['nocompress'])) {
+ $ext = '.tar';
+ } else {
+ $ext = '.tgz';
+ }
+
+ if (is_array($url) && isset($url['url'])) {
+ $url['url'] .= $ext;
+ }
+
+ return $url;
+ }
+
+ /**
+ * @param array dependency array
+ * @access private
+ */
+ function _getDepPackageDownloadUrl($dep, $parr)
+ {
+ $xsdversion = isset($dep['rel']) ? '1.0' : '2.0';
+ $curchannel = $this->config->get('default_channel');
+ if (isset($dep['uri'])) {
+ $xsdversion = '2.0';
+ $chan = $this->_registry->getChannel('__uri');
+ if (PEAR::isError($chan)) {
+ return $chan;
+ }
+
+ $version = $this->_registry->packageInfo($dep['name'], 'version', '__uri');
+ $this->configSet('default_channel', '__uri');
+ } else {
+ if (isset($dep['channel'])) {
+ $remotechannel = $dep['channel'];
+ } else {
+ $remotechannel = 'pear.php.net';
+ }
+
+ if (!$this->_registry->channelExists($remotechannel)) {
+ do {
+ if ($this->config->get('auto_discover')) {
+ if ($this->discover($remotechannel)) {
+ break;
+ }
+ }
+ return PEAR::raiseError('Unknown remote channel: ' . $remotechannel);
+ } while (false);
+ }
+
+ $chan = $this->_registry->getChannel($remotechannel);
+ if (PEAR::isError($chan)) {
+ return $chan;
+ }
+
+ $version = $this->_registry->packageInfo($dep['name'], 'version', $remotechannel);
+ $this->configSet('default_channel', $remotechannel);
+ }
+
+ $state = isset($parr['state']) ? $parr['state'] : $this->config->get('preferred_state');
+ if (isset($parr['state']) && isset($parr['version'])) {
+ unset($parr['state']);
+ }
+
+ if (isset($dep['uri'])) {
+ $info = $this->newDownloaderPackage($this);
+ PEAR::staticPushErrorHandling(PEAR_ERROR_RETURN);
+ $err = $info->initialize($dep);
+ PEAR::staticPopErrorHandling();
+ if (!$err) {
+ // skip parameters that were missed by preferred_state
+ return PEAR::raiseError('Cannot initialize dependency');
+ }
+
+ if (PEAR::isError($err)) {
+ if (!isset($this->_options['soft'])) {
+ $this->log(0, $err->getMessage());
+ }
+
+ if (is_object($info)) {
+ $param = $info->getChannel() . '/' . $info->getPackage();
+ }
+ return PEAR::raiseError('Package "' . $param . '" is not valid');
+ }
+ return $info;
+ } elseif ($chan->supportsREST($this->config->get('preferred_mirror'))
+ &&
+ (
+ ($base2 = $chan->getBaseURL('REST1.3', $this->config->get('preferred_mirror')))
+ ||
+ ($base = $chan->getBaseURL('REST1.0', $this->config->get('preferred_mirror')))
+ )
+ ) {
+ if ($base2) {
+ $base = $base2;
+ $rest = &$this->config->getREST('1.3', $this->_options);
+ } else {
+ $rest = &$this->config->getREST('1.0', $this->_options);
+ }
+
+ $url = $rest->getDepDownloadURL($base, $xsdversion, $dep, $parr,
+ $state, $version, $chan->getName());
+ if (PEAR::isError($url)) {
+ return $url;
+ }
+
+ if ($parr['channel'] != $curchannel) {
+ $this->configSet('default_channel', $curchannel);
+ }
+
+ if (!is_array($url)) {
+ return $url;
+ }
+
+ $url['raw'] = false; // no checking is necessary for REST
+ if (!is_array($url['info'])) {
+ return PEAR::raiseError('Invalid remote dependencies retrieved from REST - ' .
+ 'this should never happen');
+ }
+
+ if (isset($url['info']['required'])) {
+ if (!class_exists('PEAR_PackageFile_v2')) {
+ require_once 'PEAR/PackageFile/v2.php';
+ }
+ $pf = new PEAR_PackageFile_v2;
+ $pf->setRawChannel($remotechannel);
+ } else {
+ if (!class_exists('PEAR_PackageFile_v1')) {
+ require_once 'PEAR/PackageFile/v1.php';
+ }
+ $pf = new PEAR_PackageFile_v1;
+
+ }
+ $pf->setRawPackage($url['package']);
+ $pf->setDeps($url['info']);
+ if ($url['compatible']) {
+ $pf->setCompatible($url['compatible']);
+ }
+
+ $pf->setRawState($url['stability']);
+ $url['info'] = &$pf;
+ if (!extension_loaded("zlib") || isset($this->_options['nocompress'])) {
+ $ext = '.tar';
+ } else {
+ $ext = '.tgz';
+ }
+
+ if (is_array($url) && isset($url['url'])) {
+ $url['url'] .= $ext;
+ }
+
+ return $url;
+ }
+
+ return $this->raiseError($parr['channel'] . ' is using a unsupported protocol - This should never happen.');
+ }
+
+ /**
+ * @deprecated in favor of _getPackageDownloadUrl
+ */
+ function getPackageDownloadUrl($package, $version = null, $channel = false)
+ {
+ if ($version) {
+ $package .= "-$version";
+ }
+ if ($this === null || $this->_registry === null) {
+ $package = "http://pear.php.net/get/$package";
+ } else {
+ $chan = $this->_registry->getChannel($channel);
+ if (PEAR::isError($chan)) {
+ return '';
+ }
+ $package = "http://" . $chan->getServer() . "/get/$package";
+ }
+ if (!extension_loaded("zlib")) {
+ $package .= '?uncompress=yes';
+ }
+ return $package;
+ }
+
+ /**
+ * Retrieve a list of downloaded packages after a call to {@link download()}.
+ *
+ * Also resets the list of downloaded packages.
+ * @return array
+ */
+ function getDownloadedPackages()
+ {
+ $ret = $this->_downloadedPackages;
+ $this->_downloadedPackages = array();
+ $this->_toDownload = array();
+ return $ret;
+ }
+
+ function _downloadCallback($msg, $params = null)
+ {
+ switch ($msg) {
+ case 'saveas':
+ $this->log(1, "downloading $params ...");
+ break;
+ case 'done':
+ $this->log(1, '...done: ' . number_format($params, 0, '', ',') . ' bytes');
+ break;
+ case 'bytesread':
+ static $bytes;
+ if (empty($bytes)) {
+ $bytes = 0;
+ }
+ if (!($bytes % 10240)) {
+ $this->log(1, '.', false);
+ }
+ $bytes += $params;
+ break;
+ case 'start':
+ if($params[1] == -1) {
+ $length = "Unknown size";
+ } else {
+ $length = number_format($params[1], 0, '', ',')." bytes";
+ }
+ $this->log(1, "Starting to download {$params[0]} ($length)");
+ break;
+ }
+ if (method_exists($this->ui, '_downloadCallback'))
+ $this->ui->_downloadCallback($msg, $params);
+ }
+
+ function _prependPath($path, $prepend)
+ {
+ if (strlen($prepend) > 0) {
+ if (OS_WINDOWS && preg_match('/^[a-z]:/i', $path)) {
+ if (preg_match('/^[a-z]:/i', $prepend)) {
+ $prepend = substr($prepend, 2);
+ } elseif ($prepend{0} != '\\') {
+ $prepend = "\\$prepend";
+ }
+ $path = substr($path, 0, 2) . $prepend . substr($path, 2);
+ } else {
+ $path = $prepend . $path;
+ }
+ }
+ return $path;
+ }
+
+ /**
+ * @param string
+ * @param integer
+ */
+ function pushError($errmsg, $code = -1)
+ {
+ array_push($this->_errorStack, array($errmsg, $code));
+ }
+
+ function getErrorMsgs()
+ {
+ $msgs = array();
+ $errs = $this->_errorStack;
+ foreach ($errs as $err) {
+ $msgs[] = $err[0];
+ }
+ $this->_errorStack = array();
+ return $msgs;
+ }
+
+ /**
+ * for BC
+ *
+ * @deprecated
+ */
+ function sortPkgDeps(&$packages, $uninstall = false)
+ {
+ $uninstall ?
+ $this->sortPackagesForUninstall($packages) :
+ $this->sortPackagesForInstall($packages);
+ }
+
+ /**
+ * Sort a list of arrays of array(downloaded packagefilename) by dependency.
+ *
+ * This uses the topological sort method from graph theory, and the
+ * Structures_Graph package to properly sort dependencies for installation.
+ * @param array an array of downloaded PEAR_Downloader_Packages
+ * @return array array of array(packagefilename, package.xml contents)
+ */
+ function sortPackagesForInstall(&$packages)
+ {
+ require_once 'Structures/Graph.php';
+ require_once 'Structures/Graph/Node.php';
+ require_once 'Structures/Graph/Manipulator/TopologicalSorter.php';
+ $depgraph = new Structures_Graph(true);
+ $nodes = array();
+ $reg = &$this->config->getRegistry();
+ foreach ($packages as $i => $package) {
+ $pname = $reg->parsedPackageNameToString(
+ array(
+ 'channel' => $package->getChannel(),
+ 'package' => strtolower($package->getPackage()),
+ ));
+ $nodes[$pname] = new Structures_Graph_Node;
+ $nodes[$pname]->setData($packages[$i]);
+ $depgraph->addNode($nodes[$pname]);
+ }
+
+ $deplinks = array();
+ foreach ($nodes as $package => $node) {
+ $pf = &$node->getData();
+ $pdeps = $pf->getDeps(true);
+ if (!$pdeps) {
+ continue;
+ }
+
+ if ($pf->getPackagexmlVersion() == '1.0') {
+ foreach ($pdeps as $dep) {
+ if ($dep['type'] != 'pkg' ||
+ (isset($dep['optional']) && $dep['optional'] == 'yes')) {
+ continue;
+ }
+
+ $dname = $reg->parsedPackageNameToString(
+ array(
+ 'channel' => 'pear.php.net',
+ 'package' => strtolower($dep['name']),
+ ));
+
+ if (isset($nodes[$dname])) {
+ if (!isset($deplinks[$dname])) {
+ $deplinks[$dname] = array();
+ }
+
+ $deplinks[$dname][$package] = 1;
+ // dependency is in installed packages
+ continue;
+ }
+
+ $dname = $reg->parsedPackageNameToString(
+ array(
+ 'channel' => 'pecl.php.net',
+ 'package' => strtolower($dep['name']),
+ ));
+
+ if (isset($nodes[$dname])) {
+ if (!isset($deplinks[$dname])) {
+ $deplinks[$dname] = array();
+ }
+
+ $deplinks[$dname][$package] = 1;
+ // dependency is in installed packages
+ continue;
+ }
+ }
+ } else {
+ // the only ordering we care about is:
+ // 1) subpackages must be installed before packages that depend on them
+ // 2) required deps must be installed before packages that depend on them
+ if (isset($pdeps['required']['subpackage'])) {
+ $t = $pdeps['required']['subpackage'];
+ if (!isset($t[0])) {
+ $t = array($t);
+ }
+
+ $this->_setupGraph($t, $reg, $deplinks, $nodes, $package);
+ }
+
+ if (isset($pdeps['group'])) {
+ if (!isset($pdeps['group'][0])) {
+ $pdeps['group'] = array($pdeps['group']);
+ }
+
+ foreach ($pdeps['group'] as $group) {
+ if (isset($group['subpackage'])) {
+ $t = $group['subpackage'];
+ if (!isset($t[0])) {
+ $t = array($t);
+ }
+
+ $this->_setupGraph($t, $reg, $deplinks, $nodes, $package);
+ }
+ }
+ }
+
+ if (isset($pdeps['optional']['subpackage'])) {
+ $t = $pdeps['optional']['subpackage'];
+ if (!isset($t[0])) {
+ $t = array($t);
+ }
+
+ $this->_setupGraph($t, $reg, $deplinks, $nodes, $package);
+ }
+
+ if (isset($pdeps['required']['package'])) {
+ $t = $pdeps['required']['package'];
+ if (!isset($t[0])) {
+ $t = array($t);
+ }
+
+ $this->_setupGraph($t, $reg, $deplinks, $nodes, $package);
+ }
+
+ if (isset($pdeps['group'])) {
+ if (!isset($pdeps['group'][0])) {
+ $pdeps['group'] = array($pdeps['group']);
+ }
+
+ foreach ($pdeps['group'] as $group) {
+ if (isset($group['package'])) {
+ $t = $group['package'];
+ if (!isset($t[0])) {
+ $t = array($t);
+ }
+
+ $this->_setupGraph($t, $reg, $deplinks, $nodes, $package);
+ }
+ }
+ }
+ }
+ }
+
+ $this->_detectDepCycle($deplinks);
+ foreach ($deplinks as $dependent => $parents) {
+ foreach ($parents as $parent => $unused) {
+ $nodes[$dependent]->connectTo($nodes[$parent]);
+ }
+ }
+
+ $installOrder = Structures_Graph_Manipulator_TopologicalSorter::sort($depgraph);
+ $ret = array();
+ for ($i = 0, $count = count($installOrder); $i < $count; $i++) {
+ foreach ($installOrder[$i] as $index => $sortedpackage) {
+ $data = &$installOrder[$i][$index]->getData();
+ $ret[] = &$nodes[$reg->parsedPackageNameToString(
+ array(
+ 'channel' => $data->getChannel(),
+ 'package' => strtolower($data->getPackage()),
+ ))]->getData();
+ }
+ }
+
+ $packages = $ret;
+ return;
+ }
+
+ /**
+ * Detect recursive links between dependencies and break the cycles
+ *
+ * @param array
+ * @access private
+ */
+ function _detectDepCycle(&$deplinks)
+ {
+ do {
+ $keepgoing = false;
+ foreach ($deplinks as $dep => $parents) {
+ foreach ($parents as $parent => $unused) {
+ // reset the parent cycle detector
+ $this->_testCycle(null, null, null);
+ if ($this->_testCycle($dep, $deplinks, $parent)) {
+ $keepgoing = true;
+ unset($deplinks[$dep][$parent]);
+ if (count($deplinks[$dep]) == 0) {
+ unset($deplinks[$dep]);
+ }
+
+ continue 3;
+ }
+ }
+ }
+ } while ($keepgoing);
+ }
+
+ function _testCycle($test, $deplinks, $dep)
+ {
+ static $visited = array();
+ if ($test === null) {
+ $visited = array();
+ return;
+ }
+
+ // this happens when a parent has a dep cycle on another dependency
+ // but the child is not part of the cycle
+ if (isset($visited[$dep])) {
+ return false;
+ }
+
+ $visited[$dep] = 1;
+ if ($test == $dep) {
+ return true;
+ }
+
+ if (isset($deplinks[$dep])) {
+ if (in_array($test, array_keys($deplinks[$dep]), true)) {
+ return true;
+ }
+
+ foreach ($deplinks[$dep] as $parent => $unused) {
+ if ($this->_testCycle($test, $deplinks, $parent)) {
+ return true;
+ }
+ }
+ }
+
+ return false;
+ }
+
+ /**
+ * Set up the dependency for installation parsing
+ *
+ * @param array $t dependency information
+ * @param PEAR_Registry $reg
+ * @param array $deplinks list of dependency links already established
+ * @param array $nodes all existing package nodes
+ * @param string $package parent package name
+ * @access private
+ */
+ function _setupGraph($t, $reg, &$deplinks, &$nodes, $package)
+ {
+ foreach ($t as $dep) {
+ $depchannel = !isset($dep['channel']) ? '__uri': $dep['channel'];
+ $dname = $reg->parsedPackageNameToString(
+ array(
+ 'channel' => $depchannel,
+ 'package' => strtolower($dep['name']),
+ ));
+
+ if (isset($nodes[$dname])) {
+ if (!isset($deplinks[$dname])) {
+ $deplinks[$dname] = array();
+ }
+ $deplinks[$dname][$package] = 1;
+ }
+ }
+ }
+
+ function _dependsOn($a, $b)
+ {
+ return $this->_checkDepTree(strtolower($a->getChannel()), strtolower($a->getPackage()), $b);
+ }
+
+ function _checkDepTree($channel, $package, $b, $checked = array())
+ {
+ $checked[$channel][$package] = true;
+ if (!isset($this->_depTree[$channel][$package])) {
+ return false;
+ }
+
+ if (isset($this->_depTree[$channel][$package][strtolower($b->getChannel())]
+ [strtolower($b->getPackage())])) {
+ return true;
+ }
+
+ foreach ($this->_depTree[$channel][$package] as $ch => $packages) {
+ foreach ($packages as $pa => $true) {
+ if ($this->_checkDepTree($ch, $pa, $b, $checked)) {
+ return true;
+ }
+ }
+ }
+
+ return false;
+ }
+
+ function _sortInstall($a, $b)
+ {
+ if (!$a->getDeps() && !$b->getDeps()) {
+ return 0; // neither package has dependencies, order is insignificant
+ }
+ if ($a->getDeps() && !$b->getDeps()) {
+ return 1; // $a must be installed after $b because $a has dependencies
+ }
+ if (!$a->getDeps() && $b->getDeps()) {
+ return -1; // $b must be installed after $a because $b has dependencies
+ }
+ // both packages have dependencies
+ if ($this->_dependsOn($a, $b)) {
+ return 1;
+ }
+ if ($this->_dependsOn($b, $a)) {
+ return -1;
+ }
+ return 0;
+ }
+
+ /**
+ * Download a file through HTTP. Considers suggested file name in
+ * Content-disposition: header and can run a callback function for
+ * different events. The callback will be called with two
+ * parameters: the callback type, and parameters. The implemented
+ * callback types are:
+ *
+ * 'setup' called at the very beginning, parameter is a UI object
+ * that should be used for all output
+ * 'message' the parameter is a string with an informational message
+ * 'saveas' may be used to save with a different file name, the
+ * parameter is the filename that is about to be used.
+ * If a 'saveas' callback returns a non-empty string,
+ * that file name will be used as the filename instead.
+ * Note that $save_dir will not be affected by this, only
+ * the basename of the file.
+ * 'start' download is starting, parameter is number of bytes
+ * that are expected, or -1 if unknown
+ * 'bytesread' parameter is the number of bytes read so far
+ * 'done' download is complete, parameter is the total number
+ * of bytes read
+ * 'connfailed' if the TCP/SSL connection fails, this callback is called
+ * with array(host,port,errno,errmsg)
+ * 'writefailed' if writing to disk fails, this callback is called
+ * with array(destfile,errmsg)
+ *
+ * If an HTTP proxy has been configured (http_proxy PEAR_Config
+ * setting), the proxy will be used.
+ *
+ * @param string $url the URL to download
+ * @param object $ui PEAR_Frontend_* instance
+ * @param object $config PEAR_Config instance
+ * @param string $save_dir directory to save file in
+ * @param mixed $callback function/method to call for status
+ * updates
+ * @param false|string|array $lastmodified header values to check against for caching
+ * use false to return the header values from this download
+ * @param false|array $accept Accept headers to send
+ * @param false|string $channel Channel to use for retrieving authentication
+ * @return mixed Returns the full path of the downloaded file or a PEAR
+ * error on failure. If the error is caused by
+ * socket-related errors, the error object will
+ * have the fsockopen error code available through
+ * getCode(). If caching is requested, then return the header
+ * values.
+ * If $lastmodified was given and the there are no changes,
+ * boolean false is returned.
+ *
+ * @access public
+ */
+ public static function _downloadHttp(
+ $object, $url, &$ui, $save_dir = '.', $callback = null, $lastmodified = null,
+ $accept = false, $channel = false
+ ) {
+ static $redirect = 0;
+ // always reset , so we are clean case of error
+ $wasredirect = $redirect;
+ $redirect = 0;
+ if ($callback) {
+ call_user_func($callback, 'setup', array(&$ui));
+ }
+
+ $info = parse_url($url);
+ if (!isset($info['scheme']) || !in_array($info['scheme'], array('http', 'https'))) {
+ return PEAR::raiseError('Cannot download non-http URL "' . $url . '"');
+ }
+
+ if (!isset($info['host'])) {
+ return PEAR::raiseError('Cannot download from non-URL "' . $url . '"');
+ }
+
+ $host = isset($info['host']) ? $info['host'] : null;
+ $port = isset($info['port']) ? $info['port'] : null;
+ $path = isset($info['path']) ? $info['path'] : null;
+
+ if ($object !== null) {
+ $config = $object->config;
+ } else {
+ $config = &PEAR_Config::singleton();
+ }
+
+ $proxy = new PEAR_Proxy($config);
+
+ if ($proxy->isProxyConfigured() && $callback) {
+ call_user_func($callback, 'message', "Using HTTP proxy $host:$port");
+ }
+
+ if (empty($port)) {
+ $port = (isset($info['scheme']) && $info['scheme'] == 'https') ? 443 : 80;
+ }
+
+ $scheme = (isset($info['scheme']) && $info['scheme'] == 'https') ? 'https' : 'http';
+ $secure = ($scheme == 'https');
+
+ $fp = $proxy->openSocket($host, $port, $secure);
+ if (PEAR::isError($fp)) {
+ if ($callback) {
+ $errno = $fp->getCode();
+ $errstr = $fp->getMessage();
+ call_user_func($callback, 'connfailed', array($host, $port,
+ $errno, $errstr));
+ }
+ return $fp;
+ }
+
+ $requestPath = $path;
+ if ($proxy->isProxyConfigured()) {
+ $requestPath = $url;
+ }
+
+ if ($lastmodified === false || $lastmodified) {
+ $request = "GET $requestPath HTTP/1.1\r\n";
+ } else {
+ $request = "GET $requestPath HTTP/1.0\r\n";
+ }
+ $request .= "Host: $host\r\n";
+
+ $ifmodifiedsince = '';
+ if (is_array($lastmodified)) {
+ if (isset($lastmodified['Last-Modified'])) {
+ $ifmodifiedsince = 'If-Modified-Since: ' . $lastmodified['Last-Modified'] . "\r\n";
+ }
+
+ if (isset($lastmodified['ETag'])) {
+ $ifmodifiedsince .= "If-None-Match: $lastmodified[ETag]\r\n";
+ }
+ } else {
+ $ifmodifiedsince = ($lastmodified ? "If-Modified-Since: $lastmodified\r\n" : '');
+ }
+
+ $request .= $ifmodifiedsince .
+ "User-Agent: PEAR/1.10.3/PHP/" . PHP_VERSION . "\r\n";
+
+ if ($object !== null) { // only pass in authentication for non-static calls
+ $username = $config->get('username', null, $channel);
+ $password = $config->get('password', null, $channel);
+ if ($username && $password) {
+ $tmp = base64_encode("$username:$password");
+ $request .= "Authorization: Basic $tmp\r\n";
+ }
+ }
+
+ $proxyAuth = $proxy->getProxyAuth();
+ if ($proxyAuth) {
+ $request .= 'Proxy-Authorization: Basic ' .
+ $proxyAuth . "\r\n";
+ }
+
+ if ($accept) {
+ $request .= 'Accept: ' . implode(', ', $accept) . "\r\n";
+ }
+
+ $request .= "Connection: close\r\n";
+ $request .= "\r\n";
+ fwrite($fp, $request);
+ $headers = array();
+ $reply = 0;
+ while (trim($line = fgets($fp, 1024))) {
+ if (preg_match('/^([^:]+):\s+(.*)\s*\\z/', $line, $matches)) {
+ $headers[strtolower($matches[1])] = trim($matches[2]);
+ } elseif (preg_match('|^HTTP/1.[01] ([0-9]{3}) |', $line, $matches)) {
+ $reply = (int)$matches[1];
+ if ($reply == 304 && ($lastmodified || ($lastmodified === false))) {
+ return false;
+ }
+
+ if (!in_array($reply, array(200, 301, 302, 303, 305, 307))) {
+ return PEAR::raiseError("File $scheme://$host:$port$path not valid (received: $line)");
+ }
+ }
+ }
+
+ if ($reply != 200) {
+ if (!isset($headers['location'])) {
+ return PEAR::raiseError("File $scheme://$host:$port$path not valid (redirected but no location)");
+ }
+
+ if ($wasredirect > 4) {
+ return PEAR::raiseError("File $scheme://$host:$port$path not valid (redirection looped more than 5 times)");
+ }
+
+ $redirect = $wasredirect + 1;
+ return static::_downloadHttp($object, $headers['location'],
+ $ui, $save_dir, $callback, $lastmodified, $accept);
+ }
+
+ if (isset($headers['content-disposition']) &&
+ preg_match('/\sfilename=\"([^;]*\S)\"\s*(;|\\z)/', $headers['content-disposition'], $matches)) {
+ $save_as = basename($matches[1]);
+ } else {
+ $save_as = basename($url);
+ }
+
+ if ($callback) {
+ $tmp = call_user_func($callback, 'saveas', $save_as);
+ if ($tmp) {
+ $save_as = $tmp;
+ }
+ }
+
+ $dest_file = $save_dir . DIRECTORY_SEPARATOR . $save_as;
+ if (is_link($dest_file)) {
+ return PEAR::raiseError('SECURITY ERROR: Will not write to ' . $dest_file . ' as it is symlinked to ' . readlink($dest_file) . ' - Possible symlink attack');
+ }
+
+ if (!$wp = @fopen($dest_file, 'wb')) {
+ fclose($fp);
+ if ($callback) {
+ call_user_func($callback, 'writefailed', array($dest_file, $php_errormsg));
+ }
+ return PEAR::raiseError("could not open $dest_file for writing");
+ }
+
+ $length = isset($headers['content-length']) ? $headers['content-length'] : -1;
+
+ $bytes = 0;
+ if ($callback) {
+ call_user_func($callback, 'start', array(basename($dest_file), $length));
+ }
+
+ while ($data = fread($fp, 1024)) {
+ $bytes += strlen($data);
+ if ($callback) {
+ call_user_func($callback, 'bytesread', $bytes);
+ }
+ if (!@fwrite($wp, $data)) {
+ fclose($fp);
+ if ($callback) {
+ call_user_func($callback, 'writefailed', array($dest_file, $php_errormsg));
+ }
+ return PEAR::raiseError("$dest_file: write failed ($php_errormsg)");
+ }
+ }
+
+ fclose($fp);
+ fclose($wp);
+ if ($callback) {
+ call_user_func($callback, 'done', $bytes);
+ }
+
+ if ($lastmodified === false || $lastmodified) {
+ if (isset($headers['etag'])) {
+ $lastmodified = array('ETag' => $headers['etag']);
+ }
+
+ if (isset($headers['last-modified'])) {
+ if (is_array($lastmodified)) {
+ $lastmodified['Last-Modified'] = $headers['last-modified'];
+ } else {
+ $lastmodified = $headers['last-modified'];
+ }
+ }
+ return array($dest_file, $lastmodified, $headers);
+ }
+ return $dest_file;
+ }
+}
diff --git a/vendor/pear-pear.php.net/PEAR/PEAR/Downloader/Package.php b/vendor/pear-pear.php.net/PEAR/PEAR/Downloader/Package.php
new file mode 100644
index 0000000000..925c0ecd56
--- /dev/null
+++ b/vendor/pear-pear.php.net/PEAR/PEAR/Downloader/Package.php
@@ -0,0 +1,1981 @@
+
+ * @copyright 1997-2009 The Authors
+ * @license http://opensource.org/licenses/bsd-license.php New BSD License
+ * @link http://pear.php.net/package/PEAR
+ * @since File available since Release 1.4.0a1
+ */
+
+/**
+ * Error code when parameter initialization fails because no releases
+ * exist within preferred_state, but releases do exist
+ */
+define('PEAR_DOWNLOADER_PACKAGE_STATE', -1003);
+/**
+ * Error code when parameter initialization fails because no releases
+ * exist that will work with the existing PHP version
+ */
+define('PEAR_DOWNLOADER_PACKAGE_PHPVERSION', -1004);
+
+/**
+ * Coordinates download parameters and manages their dependencies
+ * prior to downloading them.
+ *
+ * Input can come from three sources:
+ *
+ * - local files (archives or package.xml)
+ * - remote files (downloadable urls)
+ * - abstract package names
+ *
+ * The first two elements are handled cleanly by PEAR_PackageFile, but the third requires
+ * accessing pearweb's xml-rpc interface to determine necessary dependencies, and the
+ * format returned of dependencies is slightly different from that used in package.xml.
+ *
+ * This class hides the differences between these elements, and makes automatic
+ * dependency resolution a piece of cake. It also manages conflicts when
+ * two classes depend on incompatible dependencies, or differing versions of the same
+ * package dependency. In addition, download will not be attempted if the php version is
+ * not supported, PEAR installer version is not supported, or non-PECL extensions are not
+ * installed.
+ * @category pear
+ * @package PEAR
+ * @author Greg Beaver + * array( + * 'package1' => PEAR_ErrorStack object, + * 'package2' => PEAR_ErrorStack object, + * ... + * ) + *+ * @access private + * @global array $GLOBALS['_PEAR_ERRORSTACK_SINGLETON'] + */ +$GLOBALS['_PEAR_ERRORSTACK_SINGLETON'] = array(); + +/** + * Global error callback (default) + * + * This is only used if set to non-false. * is the default callback for + * all packages, whereas specific packages may set a default callback + * for all instances, regardless of whether they are a singleton or not. + * + * To exclude non-singletons, only set the local callback for the singleton + * @see PEAR_ErrorStack::setDefaultCallback() + * @access private + * @global array $GLOBALS['_PEAR_ERRORSTACK_DEFAULT_CALLBACK'] + */ +$GLOBALS['_PEAR_ERRORSTACK_DEFAULT_CALLBACK'] = array( + '*' => false, +); + +/** + * Global Log object (default) + * + * This is only used if set to non-false. Use to set a default log object for + * all stacks, regardless of instantiation order or location + * @see PEAR_ErrorStack::setDefaultLogger() + * @access private + * @global array $GLOBALS['_PEAR_ERRORSTACK_DEFAULT_LOGGER'] + */ +$GLOBALS['_PEAR_ERRORSTACK_DEFAULT_LOGGER'] = false; + +/** + * Global Overriding Callback + * + * This callback will override any error callbacks that specific loggers have set. + * Use with EXTREME caution + * @see PEAR_ErrorStack::staticPushCallback() + * @access private + * @global array $GLOBALS['_PEAR_ERRORSTACK_DEFAULT_LOGGER'] + */ +$GLOBALS['_PEAR_ERRORSTACK_OVERRIDE_CALLBACK'] = array(); + +/**#@+ + * One of four possible return values from the error Callback + * @see PEAR_ErrorStack::_errorCallback() + */ +/** + * If this is returned, then the error will be both pushed onto the stack + * and logged. + */ +define('PEAR_ERRORSTACK_PUSHANDLOG', 1); +/** + * If this is returned, then the error will only be pushed onto the stack, + * and not logged. + */ +define('PEAR_ERRORSTACK_PUSH', 2); +/** + * If this is returned, then the error will only be logged, but not pushed + * onto the error stack. + */ +define('PEAR_ERRORSTACK_LOG', 3); +/** + * If this is returned, then the error is completely ignored. + */ +define('PEAR_ERRORSTACK_IGNORE', 4); +/** + * If this is returned, then the error is logged and die() is called. + */ +define('PEAR_ERRORSTACK_DIE', 5); +/**#@-*/ + +/** + * Error code for an attempt to instantiate a non-class as a PEAR_ErrorStack in + * the singleton method. + */ +define('PEAR_ERRORSTACK_ERR_NONCLASS', 1); + +/** + * Error code for an attempt to pass an object into {@link PEAR_ErrorStack::getMessage()} + * that has no __toString() method + */ +define('PEAR_ERRORSTACK_ERR_OBJTOSTRING', 2); +/** + * Error Stack Implementation + * + * Usage: + *
+ * // global error stack
+ * $global_stack = &PEAR_ErrorStack::singleton('MyPackage');
+ * // local error stack
+ * $local_stack = new PEAR_ErrorStack('MyPackage');
+ *
+ * @author Greg Beaver
+ * array(
+ * 'code' => $code,
+ * 'params' => $params,
+ * 'package' => $this->_package,
+ * 'level' => $level,
+ * 'time' => time(),
+ * 'context' => $context,
+ * 'message' => $msg,
+ * //['repackage' => $err] repackaged error array/Exception class
+ * );
+ *
+ *
+ * Normally, the previous array is returned.
+ */
+ function push($code, $level = 'error', $params = array(), $msg = false,
+ $repackage = false, $backtrace = false)
+ {
+ $context = false;
+ // grab error context
+ if ($this->_contextCallback) {
+ if (!$backtrace) {
+ $backtrace = debug_backtrace();
+ }
+ $context = call_user_func($this->_contextCallback, $code, $params, $backtrace);
+ }
+
+ // save error
+ $time = explode(' ', microtime());
+ $time = $time[1] + $time[0];
+ $err = array(
+ 'code' => $code,
+ 'params' => $params,
+ 'package' => $this->_package,
+ 'level' => $level,
+ 'time' => $time,
+ 'context' => $context,
+ 'message' => $msg,
+ );
+
+ if ($repackage) {
+ $err['repackage'] = $repackage;
+ }
+
+ // set up the error message, if necessary
+ if ($this->_msgCallback) {
+ $msg = call_user_func_array($this->_msgCallback,
+ array(&$this, $err));
+ $err['message'] = $msg;
+ }
+ $push = $log = true;
+ $die = false;
+ // try the overriding callback first
+ $callback = $this->staticPopCallback();
+ if ($callback) {
+ $this->staticPushCallback($callback);
+ }
+ if (!is_callable($callback)) {
+ // try the local callback next
+ $callback = $this->popCallback();
+ if (is_callable($callback)) {
+ $this->pushCallback($callback);
+ } else {
+ // try the default callback
+ $callback = isset($GLOBALS['_PEAR_ERRORSTACK_DEFAULT_CALLBACK'][$this->_package]) ?
+ $GLOBALS['_PEAR_ERRORSTACK_DEFAULT_CALLBACK'][$this->_package] :
+ $GLOBALS['_PEAR_ERRORSTACK_DEFAULT_CALLBACK']['*'];
+ }
+ }
+ if (is_callable($callback)) {
+ switch(call_user_func($callback, $err)){
+ case PEAR_ERRORSTACK_IGNORE:
+ return $err;
+ break;
+ case PEAR_ERRORSTACK_PUSH:
+ $log = false;
+ break;
+ case PEAR_ERRORSTACK_LOG:
+ $push = false;
+ break;
+ case PEAR_ERRORSTACK_DIE:
+ $die = true;
+ break;
+ // anything else returned has the same effect as pushandlog
+ }
+ }
+ if ($push) {
+ array_unshift($this->_errors, $err);
+ if (!isset($this->_errorsByLevel[$err['level']])) {
+ $this->_errorsByLevel[$err['level']] = array();
+ }
+ $this->_errorsByLevel[$err['level']][] = &$this->_errors[0];
+ }
+ if ($log) {
+ if ($this->_logger || $GLOBALS['_PEAR_ERRORSTACK_DEFAULT_LOGGER']) {
+ $this->_log($err);
+ }
+ }
+ if ($die) {
+ die();
+ }
+ if ($this->_compat && $push) {
+ return $this->raiseError($msg, $code, null, null, $err);
+ }
+ return $err;
+ }
+
+ /**
+ * Static version of {@link push()}
+ *
+ * @param string $package Package name this error belongs to
+ * @param int $code Package-specific error code
+ * @param string $level Error level. This is NOT spell-checked
+ * @param array $params associative array of error parameters
+ * @param string $msg Error message, or a portion of it if the message
+ * is to be generated
+ * @param array $repackage If this error re-packages an error pushed by
+ * another package, place the array returned from
+ * {@link pop()} in this parameter
+ * @param array $backtrace Protected parameter: use this to pass in the
+ * {@link debug_backtrace()} that should be used
+ * to find error context
+ * @return PEAR_Error|array if compatibility mode is on, a PEAR_Error is also
+ * thrown. see docs for {@link push()}
+ */
+ public static function staticPush(
+ $package, $code, $level = 'error', $params = array(),
+ $msg = false, $repackage = false, $backtrace = false
+ ) {
+ $s = &PEAR_ErrorStack::singleton($package);
+ if ($s->_contextCallback) {
+ if (!$backtrace) {
+ if (function_exists('debug_backtrace')) {
+ $backtrace = debug_backtrace();
+ }
+ }
+ }
+ return $s->push($code, $level, $params, $msg, $repackage, $backtrace);
+ }
+
+ /**
+ * Log an error using PEAR::Log
+ * @param array $err Error array
+ * @param array $levels Error level => Log constant map
+ * @access protected
+ */
+ function _log($err)
+ {
+ if ($this->_logger) {
+ $logger = &$this->_logger;
+ } else {
+ $logger = &$GLOBALS['_PEAR_ERRORSTACK_DEFAULT_LOGGER'];
+ }
+ if (is_a($logger, 'Log')) {
+ $levels = array(
+ 'exception' => PEAR_LOG_CRIT,
+ 'alert' => PEAR_LOG_ALERT,
+ 'critical' => PEAR_LOG_CRIT,
+ 'error' => PEAR_LOG_ERR,
+ 'warning' => PEAR_LOG_WARNING,
+ 'notice' => PEAR_LOG_NOTICE,
+ 'info' => PEAR_LOG_INFO,
+ 'debug' => PEAR_LOG_DEBUG);
+ if (isset($levels[$err['level']])) {
+ $level = $levels[$err['level']];
+ } else {
+ $level = PEAR_LOG_INFO;
+ }
+ $logger->log($err['message'], $level, $err);
+ } else { // support non-standard logs
+ call_user_func($logger, $err);
+ }
+ }
+
+
+ /**
+ * Pop an error off of the error stack
+ *
+ * @return false|array
+ * @since 0.4alpha it is no longer possible to specify a specific error
+ * level to return - the last error pushed will be returned, instead
+ */
+ function pop()
+ {
+ $err = @array_shift($this->_errors);
+ if (!is_null($err)) {
+ @array_pop($this->_errorsByLevel[$err['level']]);
+ if (!count($this->_errorsByLevel[$err['level']])) {
+ unset($this->_errorsByLevel[$err['level']]);
+ }
+ }
+ return $err;
+ }
+
+ /**
+ * Pop an error off of the error stack, static method
+ *
+ * @param string package name
+ * @return boolean
+ * @since PEAR1.5.0a1
+ */
+ function staticPop($package)
+ {
+ if ($package) {
+ if (!isset($GLOBALS['_PEAR_ERRORSTACK_SINGLETON'][$package])) {
+ return false;
+ }
+ return $GLOBALS['_PEAR_ERRORSTACK_SINGLETON'][$package]->pop();
+ }
+ }
+
+ /**
+ * Determine whether there are any errors on the stack
+ * @param string|array Level name. Use to determine if any errors
+ * of level (string), or levels (array) have been pushed
+ * @return boolean
+ */
+ function hasErrors($level = false)
+ {
+ if ($level) {
+ return isset($this->_errorsByLevel[$level]);
+ }
+ return count($this->_errors);
+ }
+
+ /**
+ * Retrieve all errors since last purge
+ *
+ * @param boolean set in order to empty the error stack
+ * @param string level name, to return only errors of a particular severity
+ * @return array
+ */
+ function getErrors($purge = false, $level = false)
+ {
+ if (!$purge) {
+ if ($level) {
+ if (!isset($this->_errorsByLevel[$level])) {
+ return array();
+ } else {
+ return $this->_errorsByLevel[$level];
+ }
+ } else {
+ return $this->_errors;
+ }
+ }
+ if ($level) {
+ $ret = $this->_errorsByLevel[$level];
+ foreach ($this->_errorsByLevel[$level] as $i => $unused) {
+ // entries are references to the $_errors array
+ $this->_errorsByLevel[$level][$i] = false;
+ }
+ // array_filter removes all entries === false
+ $this->_errors = array_filter($this->_errors);
+ unset($this->_errorsByLevel[$level]);
+ return $ret;
+ }
+ $ret = $this->_errors;
+ $this->_errors = array();
+ $this->_errorsByLevel = array();
+ return $ret;
+ }
+
+ /**
+ * Determine whether there are any errors on a single error stack, or on any error stack
+ *
+ * The optional parameter can be used to test the existence of any errors without the need of
+ * singleton instantiation
+ * @param string|false Package name to check for errors
+ * @param string Level name to check for a particular severity
+ * @return boolean
+ */
+ public static function staticHasErrors($package = false, $level = false)
+ {
+ if ($package) {
+ if (!isset($GLOBALS['_PEAR_ERRORSTACK_SINGLETON'][$package])) {
+ return false;
+ }
+ return $GLOBALS['_PEAR_ERRORSTACK_SINGLETON'][$package]->hasErrors($level);
+ }
+ foreach ($GLOBALS['_PEAR_ERRORSTACK_SINGLETON'] as $package => $obj) {
+ if ($obj->hasErrors($level)) {
+ return true;
+ }
+ }
+ return false;
+ }
+
+ /**
+ * Get a list of all errors since last purge, organized by package
+ * @since PEAR 1.4.0dev BC break! $level is now in the place $merge used to be
+ * @param boolean $purge Set to purge the error stack of existing errors
+ * @param string $level Set to a level name in order to retrieve only errors of a particular level
+ * @param boolean $merge Set to return a flat array, not organized by package
+ * @param array $sortfunc Function used to sort a merged array - default
+ * sorts by time, and should be good for most cases
+ *
+ * @return array
+ */
+ public static function staticGetErrors(
+ $purge = false, $level = false, $merge = false,
+ $sortfunc = array('PEAR_ErrorStack', '_sortErrors')
+ ) {
+ $ret = array();
+ if (!is_callable($sortfunc)) {
+ $sortfunc = array('PEAR_ErrorStack', '_sortErrors');
+ }
+ foreach ($GLOBALS['_PEAR_ERRORSTACK_SINGLETON'] as $package => $obj) {
+ $test = $GLOBALS['_PEAR_ERRORSTACK_SINGLETON'][$package]->getErrors($purge, $level);
+ if ($test) {
+ if ($merge) {
+ $ret = array_merge($ret, $test);
+ } else {
+ $ret[$package] = $test;
+ }
+ }
+ }
+ if ($merge) {
+ usort($ret, $sortfunc);
+ }
+ return $ret;
+ }
+
+ /**
+ * Error sorting function, sorts by time
+ * @access private
+ */
+ public static function _sortErrors($a, $b)
+ {
+ if ($a['time'] == $b['time']) {
+ return 0;
+ }
+ if ($a['time'] < $b['time']) {
+ return 1;
+ }
+ return -1;
+ }
+
+ /**
+ * Standard file/line number/function/class context callback
+ *
+ * This function uses a backtrace generated from {@link debug_backtrace()}
+ * and so will not work at all in PHP < 4.3.0. The frame should
+ * reference the frame that contains the source of the error.
+ * @return array|false either array('file' => file, 'line' => line,
+ * 'function' => function name, 'class' => class name) or
+ * if this doesn't work, then false
+ * @param unused
+ * @param integer backtrace frame.
+ * @param array Results of debug_backtrace()
+ */
+ public static function getFileLine($code, $params, $backtrace = null)
+ {
+ if ($backtrace === null) {
+ return false;
+ }
+ $frame = 0;
+ $functionframe = 1;
+ if (!isset($backtrace[1])) {
+ $functionframe = 0;
+ } else {
+ while (isset($backtrace[$functionframe]['function']) &&
+ $backtrace[$functionframe]['function'] == 'eval' &&
+ isset($backtrace[$functionframe + 1])) {
+ $functionframe++;
+ }
+ }
+ if (isset($backtrace[$frame])) {
+ if (!isset($backtrace[$frame]['file'])) {
+ $frame++;
+ }
+ $funcbacktrace = $backtrace[$functionframe];
+ $filebacktrace = $backtrace[$frame];
+ $ret = array('file' => $filebacktrace['file'],
+ 'line' => $filebacktrace['line']);
+ // rearrange for eval'd code or create function errors
+ if (strpos($filebacktrace['file'], '(') &&
+ preg_match(';^(.*?)\((\d+)\) : (.*?)\\z;', $filebacktrace['file'],
+ $matches)) {
+ $ret['file'] = $matches[1];
+ $ret['line'] = $matches[2] + 0;
+ }
+ if (isset($funcbacktrace['function']) && isset($backtrace[1])) {
+ if ($funcbacktrace['function'] != 'eval') {
+ if ($funcbacktrace['function'] == '__lambda_func') {
+ $ret['function'] = 'create_function() code';
+ } else {
+ $ret['function'] = $funcbacktrace['function'];
+ }
+ }
+ }
+ if (isset($funcbacktrace['class']) && isset($backtrace[1])) {
+ $ret['class'] = $funcbacktrace['class'];
+ }
+ return $ret;
+ }
+ return false;
+ }
+
+ /**
+ * Standard error message generation callback
+ *
+ * This method may also be called by a custom error message generator
+ * to fill in template values from the params array, simply
+ * set the third parameter to the error message template string to use
+ *
+ * The special variable %__msg% is reserved: use it only to specify
+ * where a message passed in by the user should be placed in the template,
+ * like so:
+ *
+ * Error message: %msg% - internal error
+ *
+ * If the message passed like so:
+ *
+ *
+ * $stack->push(ERROR_CODE, 'error', array(), 'server error 500');
+ *
+ *
+ * The returned error message will be "Error message: server error 500 -
+ * internal error"
+ * @param PEAR_ErrorStack
+ * @param array
+ * @param string|false Pre-generated error message template
+ *
+ * @return string
+ */
+ public static function getErrorMessage(&$stack, $err, $template = false)
+ {
+ if ($template) {
+ $mainmsg = $template;
+ } else {
+ $mainmsg = $stack->getErrorMessageTemplate($err['code']);
+ }
+ $mainmsg = str_replace('%__msg%', $err['message'], $mainmsg);
+ if (is_array($err['params']) && count($err['params'])) {
+ foreach ($err['params'] as $name => $val) {
+ if (is_array($val)) {
+ // @ is needed in case $val is a multi-dimensional array
+ $val = @implode(', ', $val);
+ }
+ if (is_object($val)) {
+ if (method_exists($val, '__toString')) {
+ $val = $val->__toString();
+ } else {
+ PEAR_ErrorStack::staticPush('PEAR_ErrorStack', PEAR_ERRORSTACK_ERR_OBJTOSTRING,
+ 'warning', array('obj' => get_class($val)),
+ 'object %obj% passed into getErrorMessage, but has no __toString() method');
+ $val = 'Object';
+ }
+ }
+ $mainmsg = str_replace('%' . $name . '%', $val, $mainmsg);
+ }
+ }
+ return $mainmsg;
+ }
+
+ /**
+ * Standard Error Message Template generator from code
+ * @return string
+ */
+ function getErrorMessageTemplate($code)
+ {
+ if (!isset($this->_errorMsgs[$code])) {
+ return '%__msg%';
+ }
+ return $this->_errorMsgs[$code];
+ }
+
+ /**
+ * Set the Error Message Template array
+ *
+ * The array format must be:
+ * + * array(error code => 'message template',...) + *+ * + * Error message parameters passed into {@link push()} will be used as input + * for the error message. If the template is 'message %foo% was %bar%', and the + * parameters are array('foo' => 'one', 'bar' => 'six'), the error message returned will + * be 'message one was six' + * @return string + */ + function setErrorMessageTemplate($template) + { + $this->_errorMsgs = $template; + } + + + /** + * emulate PEAR::raiseError() + * + * @return PEAR_Error + */ + function raiseError() + { + require_once 'PEAR.php'; + $args = func_get_args(); + return call_user_func_array(array('PEAR', 'raiseError'), $args); + } +} +$stack = &PEAR_ErrorStack::singleton('PEAR_ErrorStack'); +$stack->pushCallback(array('PEAR_ErrorStack', '_handleError')); +?> diff --git a/vendor/pear-pear.php.net/PEAR/PEAR/Exception.php b/vendor/pear-pear.php.net/PEAR/PEAR/Exception.php new file mode 100644 index 0000000000..d83950b13a --- /dev/null +++ b/vendor/pear-pear.php.net/PEAR/PEAR/Exception.php @@ -0,0 +1,388 @@ + + * @author Hans Lellelid
+ * require_once 'PEAR/Exception.php';
+ *
+ * class Test {
+ * function foo() {
+ * throw new PEAR_Exception('Error Message', ERROR_CODE);
+ * }
+ * }
+ *
+ * function myLogger($pear_exception) {
+ * echo $pear_exception->getMessage();
+ * }
+ * // each time a exception is thrown the 'myLogger' will be called
+ * // (its use is completely optional)
+ * PEAR_Exception::addObserver('myLogger');
+ * $test = new Test;
+ * try {
+ * $test->foo();
+ * } catch (PEAR_Exception $e) {
+ * print $e;
+ * }
+ *
+ *
+ * @category pear
+ * @package PEAR
+ * @author Tomas V.V.Cox + * array('name' => $name, 'context' => array(...)) + *+ * @return array + */ + public function getErrorData() + { + return array(); + } + + /** + * Returns the exception that caused this exception to be thrown + * @access public + * @return Exception|array The context of the exception + */ + public function getCause() + { + return $this->cause; + } + + /** + * Function must be public to call on caused exceptions + * @param array + */ + public function getCauseMessage(&$causes) + { + $trace = $this->getTraceSafe(); + $cause = array('class' => get_class($this), + 'message' => $this->message, + 'file' => 'unknown', + 'line' => 'unknown'); + if (isset($trace[0])) { + if (isset($trace[0]['file'])) { + $cause['file'] = $trace[0]['file']; + $cause['line'] = $trace[0]['line']; + } + } + $causes[] = $cause; + if ($this->cause instanceof PEAR_Exception) { + $this->cause->getCauseMessage($causes); + } elseif ($this->cause instanceof Exception) { + $causes[] = array('class' => get_class($this->cause), + 'message' => $this->cause->getMessage(), + 'file' => $this->cause->getFile(), + 'line' => $this->cause->getLine()); + } elseif (class_exists('PEAR_Error') && $this->cause instanceof PEAR_Error) { + $causes[] = array('class' => get_class($this->cause), + 'message' => $this->cause->getMessage(), + 'file' => 'unknown', + 'line' => 'unknown'); + } elseif (is_array($this->cause)) { + foreach ($this->cause as $cause) { + if ($cause instanceof PEAR_Exception) { + $cause->getCauseMessage($causes); + } elseif ($cause instanceof Exception) { + $causes[] = array('class' => get_class($cause), + 'message' => $cause->getMessage(), + 'file' => $cause->getFile(), + 'line' => $cause->getLine()); + } elseif (class_exists('PEAR_Error') && $cause instanceof PEAR_Error) { + $causes[] = array('class' => get_class($cause), + 'message' => $cause->getMessage(), + 'file' => 'unknown', + 'line' => 'unknown'); + } elseif (is_array($cause) && isset($cause['message'])) { + // PEAR_ErrorStack warning + $causes[] = array( + 'class' => $cause['package'], + 'message' => $cause['message'], + 'file' => isset($cause['context']['file']) ? + $cause['context']['file'] : + 'unknown', + 'line' => isset($cause['context']['line']) ? + $cause['context']['line'] : + 'unknown', + ); + } + } + } + } + + public function getTraceSafe() + { + if (!isset($this->_trace)) { + $this->_trace = $this->getTrace(); + if (empty($this->_trace)) { + $backtrace = debug_backtrace(); + $this->_trace = array($backtrace[count($backtrace)-1]); + } + } + return $this->_trace; + } + + public function getErrorClass() + { + $trace = $this->getTraceSafe(); + return $trace[0]['class']; + } + + public function getErrorMethod() + { + $trace = $this->getTraceSafe(); + return $trace[0]['function']; + } + + public function __toString() + { + if (isset($_SERVER['REQUEST_URI'])) { + return $this->toHtml(); + } + return $this->toText(); + } + + public function toHtml() + { + $trace = $this->getTraceSafe(); + $causes = array(); + $this->getCauseMessage($causes); + $html = '
' + . str_repeat('-', $i) . ' ' . $cause['class'] . ': ' + . htmlspecialchars($cause['message']) . ' in ' . $cause['file'] . ' ' + . 'on line ' . $cause['line'] . '' + . " | ||
Exception trace | ||
# | ' + . 'Function | ' + . 'Location |
' . $k . ' | ' + . ''; + if (!empty($v['class'])) { + $html .= $v['class'] . $v['type']; + } + $html .= $v['function']; + $args = array(); + if (!empty($v['args'])) { + foreach ($v['args'] as $arg) { + if (is_null($arg)) $args[] = 'null'; + elseif (is_array($arg)) $args[] = 'Array'; + elseif (is_object($arg)) $args[] = 'Object('.get_class($arg).')'; + elseif (is_bool($arg)) $args[] = $arg ? 'true' : 'false'; + elseif (is_int($arg) || is_double($arg)) $args[] = $arg; + else { + $arg = (string)$arg; + $str = htmlspecialchars(substr($arg, 0, 16)); + if (strlen($arg) > 16) $str .= '…'; + $args[] = "'" . $str . "'"; + } + } + } + $html .= '(' . implode(', ',$args) . ')' + . ' | ' + . '' . (isset($v['file']) ? $v['file'] : 'unknown') + . ':' . (isset($v['line']) ? $v['line'] : 'unknown') + . ' |
' . ($k+1) . ' | ' + . '{main} | ' + . '
+ * - if any install-as/platform exist, create a generic release and fill it with + * o+ * + * It does this by accessing the $package parameter, which contains an array with + * indices: + * + * - platform: mapping of file => OS the file should be installed on + * - install-as: mapping of file => installed name + * - osmap: mapping of OS => list of files that should be installed + * on that OS + * - notosmap: mapping of OS => list of files that should not be + * installed on that OS + * + * @param array + * @param array + * @access private + */ + function _convertRelease2_0(&$release, $package) + { + //- if any install-as/platform exist, create a generic release and fill it with + if (count($package['platform']) || count($package['install-as'])) { + $generic = array(); + $genericIgnore = array(); + foreach ($package['install-as'] as $file => $as) { + //otags for + * o tags for + * o tags for + * o tags for + * - create a release for each platform encountered and fill with + * o tags for + * o tags for + * o tags for + * o tags for + * o tags for + * o tags for + * o tags for + *