Частичная синхронизация с CMS
This commit is contained in:
parent
312f18a20a
commit
b26e521657
62 changed files with 827 additions and 5992 deletions
|
|
@ -6,7 +6,7 @@ class Excel_Number
|
|||
|
||||
function __construct($value)
|
||||
{
|
||||
$this->value = $value;
|
||||
$this->value = intval($value);
|
||||
}
|
||||
|
||||
function getString()
|
||||
|
|
@ -70,13 +70,13 @@ class TableRow
|
|||
*/
|
||||
class ExcelTable
|
||||
{
|
||||
static $index;
|
||||
static $index;
|
||||
private $name;
|
||||
private $style;
|
||||
protected $rows = array();
|
||||
protected $rows = array();
|
||||
|
||||
protected $splitVertical = false;
|
||||
protected $splitHorizontal = false;
|
||||
protected $_splitVertical = false;
|
||||
protected $_splitHorizontal = false;
|
||||
|
||||
function __construct()
|
||||
{
|
||||
|
|
@ -94,7 +94,8 @@ class ExcelTable
|
|||
if(! isset($this->rows[$x])) {
|
||||
$this->rows[$x] = new TableRow();
|
||||
}
|
||||
$this->rows[$x]->setCell($y, $value);
|
||||
/*.TableRow.*/$row = $this->rows[$x];
|
||||
$row->setCell($y, $value);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -142,12 +143,13 @@ class ExcelTable
|
|||
* @param $cell Номер столбца
|
||||
* @param $merge Количество клеток для обьединения
|
||||
*/
|
||||
function setCellMerge ($row, $cell, $merge)
|
||||
function setCellMerge($x, $cell, $merge)
|
||||
{
|
||||
assert(is_numeric($row) && $row > 0);
|
||||
assert(is_numeric($x) && $x > 0);
|
||||
assert(is_numeric($cell) && $cell > 0);
|
||||
|
||||
$this->rows[$row]->cells[$cell]->merge = $merge;
|
||||
/*.TableRow.*/$row = $this->rows[$x];
|
||||
$row->cells[$cell]->merge = $merge;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -181,7 +183,8 @@ class ExcelTable
|
|||
*/
|
||||
function getRows()
|
||||
{
|
||||
return max(array_keys($this->rows));
|
||||
/*.array.*/$keys = array_keys($this->rows);
|
||||
return max($keys);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -189,27 +192,26 @@ class ExcelTable
|
|||
*
|
||||
* @return int
|
||||
*/
|
||||
function getRowCells($row)
|
||||
function getRowCells(TableRow $row)
|
||||
{
|
||||
return max(array_keys($row->cells));
|
||||
/*.array.*/$keys = array_keys($row->cells);
|
||||
return max($keys);
|
||||
}
|
||||
|
||||
/**
|
||||
* Разделяет таблицу на две части по вертикали
|
||||
* @param $n integer Количество столбцов слева
|
||||
*/
|
||||
function splitVertical($n)
|
||||
{
|
||||
$this->splitVertical = $n;
|
||||
function splitVertical($n) {
|
||||
$this->_splitVertical = $n;
|
||||
}
|
||||
|
||||
/**
|
||||
* Разделяет таблицу на две части по горизонтали
|
||||
* @param $n integer Количество столбцов сверху
|
||||
*/
|
||||
function splitHorizontal($n)
|
||||
{
|
||||
$this->splitHorizontal = $n;
|
||||
function splitHorizontal($n) {
|
||||
$this->_splitHorizontal = $n;
|
||||
}
|
||||
|
||||
|
||||
|
|
@ -218,8 +220,7 @@ class ExcelTable
|
|||
*
|
||||
* @return int
|
||||
*/
|
||||
function getColumns()
|
||||
{
|
||||
function getColumns() {
|
||||
return max(array_map(array($this, 'getRowCells'), $this->rows));
|
||||
}
|
||||
|
||||
|
|
@ -231,7 +232,7 @@ class ExcelTable
|
|||
/**
|
||||
* Генерация клетки таблицы (Переработать)
|
||||
*/
|
||||
function createCell ($ncell, XMLWriter $doc, $j, $value, $setIndex) {
|
||||
function createCell (TableCell $ncell, XMLWriter $doc, $j, /*.any.*/$value, $setIndex) {
|
||||
$doc->startElement("Cell");
|
||||
|
||||
if ($ncell->style) {
|
||||
|
|
@ -291,7 +292,7 @@ class ExcelTable
|
|||
$doc->writeAttribute('ss:Height', $this->rows[$i]->height);
|
||||
}
|
||||
|
||||
$nrow = $this->rows[$i];
|
||||
/*.TableRow.*/$nrow = $this->rows[$i];
|
||||
// Флаг индикатор подстановки номера столбца
|
||||
$setIndex = false;
|
||||
for ($j = 1; $j <= $columns; $j++) {
|
||||
|
|
@ -321,17 +322,17 @@ class ExcelTable
|
|||
$doc->writeAttribute('xmlns', 'urn:schemas-microsoft-com:office:excel');
|
||||
|
||||
$doc->writeElement('FrozenNoSplit');
|
||||
if ($this->splitVertical) {
|
||||
$doc->writeElement('SplitVertical', $this->splitVertical);
|
||||
$doc->writeElement('LeftColumnRightPane', $this->splitVertical);
|
||||
if ($this->_splitVertical) {
|
||||
$doc->writeElement('SplitVertical', $this->_splitVertical);
|
||||
$doc->writeElement('LeftColumnRightPane', $this->_splitVertical);
|
||||
}
|
||||
if ($this->splitHorizontal) {
|
||||
$doc->writeElement('SplitHorizontal', $this->splitHorizontal);
|
||||
$doc->writeElement('TopRowBottomPane', $this->splitHorizontal);
|
||||
if ($this->_splitHorizontal) {
|
||||
$doc->writeElement('SplitHorizontal', $this->_splitHorizontal);
|
||||
$doc->writeElement('TopRowBottomPane', $this->_splitHorizontal);
|
||||
}
|
||||
if ($this->splitHorizontal && $this->splitVertical) {
|
||||
if ($this->_splitHorizontal && $this->_splitVertical) {
|
||||
$doc->writeElement('ActivePane', 0);
|
||||
} else if($this->splitHorizontal) {
|
||||
} else if($this->_splitHorizontal) {
|
||||
$doc->writeElement('ActivePane', 2);
|
||||
}
|
||||
$doc->endElement();
|
||||
|
|
@ -377,6 +378,7 @@ class ExcelDocument {
|
|||
if ($type == 'Borders') {
|
||||
$doc->startElement('Borders');
|
||||
foreach ($s as $border) {
|
||||
/*.array.*/$border = $border;
|
||||
$doc->startElement('Border');
|
||||
foreach ($border as $key => $value) {
|
||||
$doc->writeAttribute('ss:' . $key, $value);
|
||||
|
|
@ -403,7 +405,7 @@ class ExcelDocument {
|
|||
function clean ($s) {
|
||||
assert(is_string($s));
|
||||
|
||||
return strtr($s, array ("\n" => ' '));
|
||||
return strtr($s, array ("\n" => " "));
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -412,7 +414,7 @@ class ExcelDocument {
|
|||
*/
|
||||
function save($filename)
|
||||
{
|
||||
$doc = new xmlWriter();
|
||||
$doc = new XMLWriter();
|
||||
$doc->openURI($filename);
|
||||
$doc->setIndent(false);
|
||||
$doc->startDocument('1.0','utf-8');
|
||||
|
|
|
|||
|
|
@ -16,7 +16,6 @@ class Tools_Image
|
|||
{
|
||||
$width = imagesx($image);
|
||||
$height = imagesy($image);
|
||||
|
||||
$percent = min($prewidth / $width, $preheight / $height);
|
||||
if ($percent > 1 && !$force) $percent = 1;
|
||||
$new_width = $width * $percent;
|
||||
|
|
|
|||
|
|
@ -1,32 +0,0 @@
|
|||
<?php
|
||||
|
||||
function generatePassword($length = 9, $strength = 0) {
|
||||
$vowels = 'aeuy';
|
||||
$consonants = 'bdghjmnpqrstvz';
|
||||
if ($strength & 1) {
|
||||
$consonants .= 'BDGHJLMNPQRSTVWXZ';
|
||||
}
|
||||
if ($strength & 2) {
|
||||
$vowels .= "AEUY";
|
||||
}
|
||||
if ($strength & 4) {
|
||||
$consonants .= '23456789';
|
||||
}
|
||||
if ($strength & 8) {
|
||||
$consonants .= '@#$%';
|
||||
}
|
||||
|
||||
$password = '';
|
||||
$alt = time() % 2;
|
||||
for ($i = 0; $i < $length; $i++) {
|
||||
if ($alt == 1) {
|
||||
$password .= $consonants[(rand() % strlen($consonants))];
|
||||
$alt = 0;
|
||||
} else {
|
||||
$password .= $vowels[(rand() % strlen($vowels))];
|
||||
$alt = 1;
|
||||
}
|
||||
}
|
||||
return $password;
|
||||
}
|
||||
|
||||
164
src/Tools/SQLStatementExtractor.php
Normal file
164
src/Tools/SQLStatementExtractor.php
Normal file
|
|
@ -0,0 +1,164 @@
|
|||
<?php
|
||||
/*
|
||||
* $Id: SQLStatementExtractor.php,v 1.5 2004/07/27 23:13:46 hlellelid Exp $
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* This software consists of voluntary contributions made by many individuals
|
||||
* and is licensed under the LGPL. For more information please see
|
||||
* <http://creole.phpdb.org>.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Static class for extracting SQL statements from a string or file.
|
||||
*
|
||||
* @author Hans Lellelid <hans@xmpl.org>
|
||||
* @version $Revision: 1.5 $
|
||||
* @package creole.util.sql
|
||||
*/
|
||||
class Tools_SQLStatementExtractor {
|
||||
|
||||
protected static $delimiter = ';';
|
||||
|
||||
/**
|
||||
* Get SQL statements from file.
|
||||
*
|
||||
* @param string $filename Path to file to read.
|
||||
* @return array SQL statements
|
||||
*/
|
||||
public static function extractFile($filename) {
|
||||
$buffer = file_get_contents($filename);
|
||||
if ($buffer === false) {
|
||||
throw new Exception("Unable to read file: " . $filename);
|
||||
}
|
||||
return self::extractStatements(self::getLines($buffer));
|
||||
}
|
||||
|
||||
/**
|
||||
* Extract statements from string.
|
||||
*
|
||||
* @param string $txt
|
||||
* @return array
|
||||
*/
|
||||
public static function extract($buffer) {
|
||||
return self::extractStatements(self::getLines($buffer));
|
||||
}
|
||||
|
||||
/**
|
||||
* Extract SQL statements from array of lines.
|
||||
*
|
||||
* @param array $lines Lines of the read-in file.
|
||||
* @return string
|
||||
*/
|
||||
protected static function extractStatements($lines) {
|
||||
|
||||
$statements = array();
|
||||
$sql = "";
|
||||
|
||||
foreach($lines as $line) {
|
||||
|
||||
$line = trim($line);
|
||||
|
||||
if (self::startsWith("//", $line) ||
|
||||
self::startsWith("--", $line) ||
|
||||
self::startsWith("#", $line)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (strlen($line) > 4 && strtoupper(substr($line,0, 4)) == "REM ") {
|
||||
continue;
|
||||
}
|
||||
|
||||
$sql .= " " . $line;
|
||||
$sql = trim($sql);
|
||||
|
||||
// SQL defines "--" as a comment to EOL
|
||||
// and in Oracle it may contain a hint
|
||||
// so we cannot just remove it, instead we must end it
|
||||
if (strpos($line, "--") !== false) {
|
||||
$sql .= "\n";
|
||||
}
|
||||
|
||||
if (self::endsWith(self::$delimiter, $sql)) {
|
||||
$statements[] = self::substring($sql, 0, strlen($sql)-1 - strlen(self::$delimiter));
|
||||
$sql = "";
|
||||
}
|
||||
}
|
||||
return $statements;
|
||||
}
|
||||
|
||||
//
|
||||
// Some string helper methods
|
||||
//
|
||||
|
||||
/**
|
||||
* Tests if a string starts with a given string.
|
||||
* @param string $check The substring to check.
|
||||
* @param string $string The string to check in (haystack).
|
||||
* @return boolean True if $string starts with $check, or they are equal, or $check is empty.
|
||||
*/
|
||||
protected static function startsWith($check, $string) {
|
||||
if ($check === "" || $check === $string) {
|
||||
return true;
|
||||
} else {
|
||||
return (strpos($string, $check) === 0) ? true : false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests if a string ends with a given string.
|
||||
* @param string $check The substring to check.
|
||||
* @param string $string The string to check in (haystack).
|
||||
* @return boolean True if $string ends with $check, or they are equal, or $check is empty.
|
||||
*/
|
||||
protected static function endsWith($check, $string) {
|
||||
if ($check === "" || $check === $string) {
|
||||
return true;
|
||||
} else {
|
||||
return (strpos(strrev($string), strrev($check)) === 0) ? true : false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* a natural way of getting a subtring, php's circular string buffer and strange
|
||||
* return values suck if you want to program strict as of C or friends
|
||||
*/
|
||||
protected static function substring($string, $startpos, $endpos = -1) {
|
||||
$len = strlen($string);
|
||||
$endpos = (int) (($endpos === -1) ? $len-1 : $endpos);
|
||||
if ($startpos > $len-1 || $startpos < 0) {
|
||||
trigger_error("substring(), Startindex out of bounds must be 0<n<$len", E_USER_ERROR);
|
||||
}
|
||||
if ($endpos > $len-1 || $endpos < $startpos) {
|
||||
trigger_error("substring(), Endindex out of bounds must be $startpos<n<".($len-1), E_USER_ERROR);
|
||||
}
|
||||
if ($startpos === $endpos) {
|
||||
return (string) $string{$startpos};
|
||||
} else {
|
||||
$len = $endpos-$startpos;
|
||||
}
|
||||
return substr($string, $startpos, $len+1);
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert string buffer into array of lines.
|
||||
*
|
||||
* @param string $filename
|
||||
* @return array string[] lines of file.
|
||||
*/
|
||||
protected static function getLines($buffer) {
|
||||
$lines = preg_split("/\r?\n|\r/", $buffer);
|
||||
return $lines;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -1,94 +0,0 @@
|
|||
<?php
|
||||
|
||||
class TableExcelView {
|
||||
private $list = array();
|
||||
private $data = array();
|
||||
|
||||
function setColumns(array $list) {
|
||||
$this->list = $list;
|
||||
}
|
||||
|
||||
function makeTable() {
|
||||
$xls = new ExcelTable();
|
||||
$xls->setRow(1, 1, array_keys($this->list));
|
||||
|
||||
foreach($this->data as $n => $item) {
|
||||
$result = array();
|
||||
foreach($this->list as $key => $c) {
|
||||
if (is_callable($c)) {
|
||||
$result [] = call_user_func($c, $item, $n);
|
||||
} else {
|
||||
if (is_numeric($item[$c])) {
|
||||
$result [] = new Excel_Number($item[$c]);
|
||||
} else {
|
||||
$result [] = $item[$c];
|
||||
}
|
||||
}
|
||||
}
|
||||
$xls->addRow(1, $result);
|
||||
}
|
||||
|
||||
return $xls;
|
||||
}
|
||||
|
||||
function writeTable($data, $file) {
|
||||
$this->data = $data;
|
||||
|
||||
$xls = new ExcelDocument();
|
||||
$xls->addTable(array($this, 'makeTable'));
|
||||
$xls->save($file);
|
||||
}
|
||||
}
|
||||
|
||||
class TableHTMLView {
|
||||
private $list = array();
|
||||
private $stack = array();
|
||||
private $result = array();
|
||||
|
||||
function writeElement($name, $content) {
|
||||
echo "<".$name.">";
|
||||
echo $content;
|
||||
echo "</".$name.">";
|
||||
}
|
||||
|
||||
function startElement($name) {
|
||||
array_push($this->stack, $name);
|
||||
echo "<".$name.">";
|
||||
}
|
||||
|
||||
function endElement() {
|
||||
$name = array_pop($this->stack);
|
||||
echo "</".$name.">";
|
||||
}
|
||||
|
||||
function setColumns(array $list) {
|
||||
$this->list = $list;
|
||||
}
|
||||
|
||||
function writeTable($data) {
|
||||
$this->startElement('table');
|
||||
$this->startElement('thead');
|
||||
$this->startElement('tr');
|
||||
foreach($this->list as $key => $c) {
|
||||
$this->writeElement('th', $key);
|
||||
}
|
||||
$this->endElement();
|
||||
$this->endElement();
|
||||
|
||||
$this->startElement('tbody');
|
||||
foreach($data as $n => $item) {
|
||||
$this->startElement('tr');
|
||||
foreach($this->list as $key => $c) {
|
||||
if (is_callable($c)) {
|
||||
$this->writeElement('td', call_user_func($c, $item, $n));
|
||||
} else {
|
||||
$this->writeElement('td', $item[$c]);
|
||||
}
|
||||
}
|
||||
$this->endElement();
|
||||
}
|
||||
$this->endElement();
|
||||
$this->endElement();
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
Add table
Add a link
Reference in a new issue