add piwik installation
This commit is contained in:
parent
90aa4ef157
commit
8c5d4f0c31
3197 changed files with 563902 additions and 0 deletions
82
www/analytics/core/Unzip/Gzip.php
Executable file
82
www/analytics/core/Unzip/Gzip.php
Executable file
|
|
@ -0,0 +1,82 @@
|
|||
<?php
|
||||
/**
|
||||
* Piwik - Open source web analytics
|
||||
*
|
||||
* @link http://piwik.org
|
||||
* @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later
|
||||
*
|
||||
*/
|
||||
|
||||
namespace Piwik\Unzip;
|
||||
|
||||
|
||||
/**
|
||||
* Unzip implementation for .gz files.
|
||||
*
|
||||
*/
|
||||
class Gzip implements UncompressInterface
|
||||
{
|
||||
/**
|
||||
* Name of .gz file.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
private $filename = null;
|
||||
|
||||
/**
|
||||
* Error string.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
private $error = null;
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
* @param string $filename Name of .gz file.
|
||||
*/
|
||||
public function __construct($filename)
|
||||
{
|
||||
$this->filename = $filename;
|
||||
}
|
||||
|
||||
/**
|
||||
* Extracts the contents of the .gz file to $pathExtracted.
|
||||
*
|
||||
* @param string $pathExtracted Must be file, not directory.
|
||||
* @return bool true if successful, false if otherwise.
|
||||
*/
|
||||
public function extract($pathExtracted)
|
||||
{
|
||||
$file = gzopen($this->filename, 'r');
|
||||
if ($file === false) {
|
||||
$this->error = "gzopen failed";
|
||||
return false;
|
||||
}
|
||||
|
||||
$output = fopen($pathExtracted, 'w');
|
||||
while (!feof($file)) {
|
||||
fwrite($output, fread($file, 1024 * 1024));
|
||||
}
|
||||
fclose($output);
|
||||
|
||||
$success = gzclose($file);
|
||||
if ($success === false) {
|
||||
$this->error = "gzclose failed";
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get error status string for the latest error.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function errorInfo()
|
||||
{
|
||||
return $this->error;
|
||||
}
|
||||
}
|
||||
|
||||
89
www/analytics/core/Unzip/PclZip.php
Normal file
89
www/analytics/core/Unzip/PclZip.php
Normal file
|
|
@ -0,0 +1,89 @@
|
|||
<?php
|
||||
/**
|
||||
* Piwik - Open source web analytics
|
||||
*
|
||||
* @link http://piwik.org
|
||||
* @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later
|
||||
*
|
||||
*/
|
||||
namespace Piwik\Unzip;
|
||||
|
||||
|
||||
/**
|
||||
* @see libs/PclZip
|
||||
*/
|
||||
require_once PIWIK_INCLUDE_PATH . '/libs/PclZip/pclzip.lib.php';
|
||||
|
||||
/**
|
||||
* Unzip wrapper around PclZip
|
||||
*
|
||||
*/
|
||||
class PclZip implements UncompressInterface
|
||||
{
|
||||
/**
|
||||
* @var PclZip
|
||||
*/
|
||||
private $pclzip;
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
public $filename;
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @param string $filename Name of the .zip archive
|
||||
*/
|
||||
public function __construct($filename)
|
||||
{
|
||||
$this->pclzip = new \PclZip($filename);
|
||||
$this->filename = $filename;
|
||||
}
|
||||
|
||||
/**
|
||||
* Extract files from archive to target directory
|
||||
*
|
||||
* @param string $pathExtracted Absolute path of target directory
|
||||
* @return mixed Array of filenames if successful; or 0 if an error occurred
|
||||
*/
|
||||
public function extract($pathExtracted)
|
||||
{
|
||||
$pathExtracted = str_replace('\\', '/', $pathExtracted);
|
||||
$list = $this->pclzip->listContent();
|
||||
if (empty($list)) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
foreach ($list as $entry) {
|
||||
$filename = str_replace('\\', '/', $entry['stored_filename']);
|
||||
$parts = explode('/', $filename);
|
||||
|
||||
if (!strncmp($filename, '/', 1) ||
|
||||
array_search('..', $parts) !== false ||
|
||||
strpos($filename, ':') !== false
|
||||
) {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
// PCLZIP_CB_PRE_EXTRACT callback returns 0 to skip, 1 to resume, or 2 to abort
|
||||
return $this->pclzip->extract(
|
||||
PCLZIP_OPT_PATH, $pathExtracted,
|
||||
PCLZIP_OPT_STOP_ON_ERROR,
|
||||
PCLZIP_OPT_REPLACE_NEWER,
|
||||
PCLZIP_CB_PRE_EXTRACT, function ($p_event, &$p_header) use ($pathExtracted) {
|
||||
return strncmp($p_header['filename'], $pathExtracted, strlen($pathExtracted)) ? 0 : 1;
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get error status string for the latest error
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function errorInfo()
|
||||
{
|
||||
return $this->pclzip->errorInfo(true);
|
||||
}
|
||||
}
|
||||
84
www/analytics/core/Unzip/Tar.php
Executable file
84
www/analytics/core/Unzip/Tar.php
Executable file
|
|
@ -0,0 +1,84 @@
|
|||
<?php
|
||||
/**
|
||||
* Piwik - Open source web analytics
|
||||
*
|
||||
* @link http://piwik.org
|
||||
* @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later
|
||||
*
|
||||
*/
|
||||
namespace Piwik\Unzip;
|
||||
|
||||
use Archive_Tar;
|
||||
|
||||
/**
|
||||
* @see libs/Archive_Tar
|
||||
*/
|
||||
require_once PIWIK_INCLUDE_PATH . '/libs/Archive_Tar/Tar.php';
|
||||
|
||||
/**
|
||||
* Unzip implementation for Archive_Tar PEAR lib.
|
||||
*
|
||||
*/
|
||||
class Tar implements UncompressInterface
|
||||
{
|
||||
/**
|
||||
* Archive_Tar instance.
|
||||
*
|
||||
* @var Archive_Tar
|
||||
*/
|
||||
private $tarArchive = null;
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
* @param string $filename Path to tar file.
|
||||
* @param string|null $compression Either 'gz', 'bz2' or null for no compression.
|
||||
*/
|
||||
public function __construct($filename, $compression = null)
|
||||
{
|
||||
$this->tarArchive = new Archive_Tar($filename, $compression);
|
||||
}
|
||||
|
||||
/**
|
||||
* Extracts the contents of the tar file to $pathExtracted.
|
||||
*
|
||||
* @param string $pathExtracted Directory to extract into.
|
||||
* @return bool true if successful, false if otherwise.
|
||||
*/
|
||||
public function extract($pathExtracted)
|
||||
{
|
||||
return $this->tarArchive->extract($pathExtracted);
|
||||
}
|
||||
|
||||
/**
|
||||
* Extracts one file held in a tar archive and returns the deflated file
|
||||
* as a string.
|
||||
*
|
||||
* @param string $inArchivePath Path to file in the tar archive.
|
||||
* @return bool true if successful, false if otherwise.
|
||||
*/
|
||||
public function extractInString($inArchivePath)
|
||||
{
|
||||
return $this->tarArchive->extractInString($inArchivePath);
|
||||
}
|
||||
|
||||
/**
|
||||
* Lists the files held in the tar archive.
|
||||
*
|
||||
* @return array List of paths describing everything held in the tar archive.
|
||||
*/
|
||||
public function listContent()
|
||||
{
|
||||
return $this->tarArchive->listContent();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get error status string for the latest error.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function errorInfo()
|
||||
{
|
||||
return $this->tarArchive->error_object->getMessage();
|
||||
}
|
||||
}
|
||||
39
www/analytics/core/Unzip/UncompressInterface.php
Normal file
39
www/analytics/core/Unzip/UncompressInterface.php
Normal file
|
|
@ -0,0 +1,39 @@
|
|||
<?php
|
||||
/**
|
||||
* Piwik - Open source web analytics
|
||||
*
|
||||
* @link http://piwik.org
|
||||
* @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later
|
||||
*
|
||||
*/
|
||||
|
||||
namespace Piwik\Unzip;
|
||||
|
||||
/**
|
||||
* Unzip interface
|
||||
*
|
||||
*/
|
||||
interface UncompressInterface
|
||||
{
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @param string $filename Name of the .zip archive
|
||||
*/
|
||||
public function __construct($filename);
|
||||
|
||||
/**
|
||||
* Extract files from archive to target directory
|
||||
*
|
||||
* @param string $pathExtracted Absolute path of target directory
|
||||
* @return mixed Array of filenames if successful; or 0 if an error occurred
|
||||
*/
|
||||
public function extract($pathExtracted);
|
||||
|
||||
/**
|
||||
* Get error status string for the latest error
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function errorInfo();
|
||||
}
|
||||
132
www/analytics/core/Unzip/ZipArchive.php
Normal file
132
www/analytics/core/Unzip/ZipArchive.php
Normal file
|
|
@ -0,0 +1,132 @@
|
|||
<?php
|
||||
/**
|
||||
* Piwik - Open source web analytics
|
||||
*
|
||||
* @link http://piwik.org
|
||||
* @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later
|
||||
*
|
||||
*/
|
||||
namespace Piwik\Unzip;
|
||||
|
||||
use Exception;
|
||||
|
||||
/**
|
||||
* Unzip wrapper around ZipArchive
|
||||
*
|
||||
*/
|
||||
class ZipArchive implements UncompressInterface
|
||||
{
|
||||
/**
|
||||
* @var \ZipArchive
|
||||
*/
|
||||
private $ziparchive;
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
public $filename;
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @param string $filename Name of the .zip archive
|
||||
* @throws Exception
|
||||
*/
|
||||
public function __construct($filename)
|
||||
{
|
||||
$this->filename = $filename;
|
||||
$this->ziparchive = new \ZipArchive;
|
||||
if ($this->ziparchive->open($filename) !== true) {
|
||||
throw new Exception('Error opening ' . $filename);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Extract files from archive to target directory
|
||||
*
|
||||
* @param string $pathExtracted Absolute path of target directory
|
||||
* @return mixed Array of filenames if successful; or 0 if an error occurred
|
||||
*/
|
||||
public function extract($pathExtracted)
|
||||
{
|
||||
if (substr_compare($pathExtracted, '/', -1))
|
||||
$pathExtracted .= '/';
|
||||
|
||||
$fileselector = array();
|
||||
$list = array();
|
||||
$count = $this->ziparchive->numFiles;
|
||||
if ($count === 0) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
for ($i = 0; $i < $count; $i++) {
|
||||
$entry = $this->ziparchive->statIndex($i);
|
||||
|
||||
$filename = str_replace('\\', '/', $entry['name']);
|
||||
$parts = explode('/', $filename);
|
||||
|
||||
if (!strncmp($filename, '/', 1) ||
|
||||
array_search('..', $parts) !== false ||
|
||||
strpos($filename, ':') !== false
|
||||
) {
|
||||
return 0;
|
||||
}
|
||||
$fileselector[] = $entry['name'];
|
||||
$list[] = array(
|
||||
'filename' => $pathExtracted . $entry['name'],
|
||||
'stored_filename' => $entry['name'],
|
||||
'size' => $entry['size'],
|
||||
'compressed_size' => $entry['comp_size'],
|
||||
'mtime' => $entry['mtime'],
|
||||
'index' => $i,
|
||||
'crc' => $entry['crc'],
|
||||
);
|
||||
}
|
||||
|
||||
$res = $this->ziparchive->extractTo($pathExtracted, $fileselector);
|
||||
if ($res === false)
|
||||
return 0;
|
||||
return $list;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get error status string for the latest error
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function errorInfo()
|
||||
{
|
||||
static $statusStrings = array(
|
||||
\ZIPARCHIVE::ER_OK => 'No error',
|
||||
\ZIPARCHIVE::ER_MULTIDISK => 'Multi-disk zip archives not supported',
|
||||
\ZIPARCHIVE::ER_RENAME => 'Renaming temporary file failed',
|
||||
\ZIPARCHIVE::ER_CLOSE => 'Closing zip archive failed',
|
||||
\ZIPARCHIVE::ER_SEEK => 'Seek error',
|
||||
\ZIPARCHIVE::ER_READ => 'Read error',
|
||||
\ZIPARCHIVE::ER_WRITE => 'Write error',
|
||||
\ZIPARCHIVE::ER_CRC => 'CRC error',
|
||||
\ZIPARCHIVE::ER_ZIPCLOSED => 'Containing zip archive was closed',
|
||||
\ZIPARCHIVE::ER_NOENT => 'No such file',
|
||||
\ZIPARCHIVE::ER_EXISTS => 'File already exists',
|
||||
\ZIPARCHIVE::ER_OPEN => 'Can\'t open file',
|
||||
\ZIPARCHIVE::ER_TMPOPEN => 'Failure to create temporary file',
|
||||
\ZIPARCHIVE::ER_ZLIB => 'Zlib error',
|
||||
\ZIPARCHIVE::ER_MEMORY => 'Malloc failure',
|
||||
\ZIPARCHIVE::ER_CHANGED => 'Entry has been changed',
|
||||
\ZIPARCHIVE::ER_COMPNOTSUPP => 'Compression method not supported',
|
||||
\ZIPARCHIVE::ER_EOF => 'Premature EOF',
|
||||
\ZIPARCHIVE::ER_INVAL => 'Invalid argument',
|
||||
\ZIPARCHIVE::ER_NOZIP => 'Not a zip archive',
|
||||
\ZIPARCHIVE::ER_INTERNAL => 'Internal error',
|
||||
\ZIPARCHIVE::ER_INCONS => 'Zip archive inconsistent',
|
||||
\ZIPARCHIVE::ER_REMOVE => 'Can\'t remove file',
|
||||
\ZIPARCHIVE::ER_DELETED => 'Entry has been deleted',
|
||||
);
|
||||
|
||||
if (isset($statusStrings[$this->ziparchive->status])) {
|
||||
$statusString = $statusStrings[$this->ziparchive->status];
|
||||
} else {
|
||||
$statusString = 'Unknown status';
|
||||
}
|
||||
return $statusString . '(' . $this->ziparchive->status . ')';
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue