그누보드5 정식버전
This commit is contained in:
BIN
lib/Excel/itemexcel.xls
Normal file
BIN
lib/Excel/itemexcel.xls
Normal file
Binary file not shown.
271
lib/Excel/oleread.inc
Normal file
271
lib/Excel/oleread.inc
Normal file
@ -0,0 +1,271 @@
|
||||
<?php
|
||||
define('NUM_BIG_BLOCK_DEPOT_BLOCKS_POS', 0x2c);
|
||||
define('SMALL_BLOCK_DEPOT_BLOCK_POS', 0x3c);
|
||||
define('ROOT_START_BLOCK_POS', 0x30);
|
||||
define('BIG_BLOCK_SIZE', 0x200);
|
||||
define('SMALL_BLOCK_SIZE', 0x40);
|
||||
define('EXTENSION_BLOCK_POS', 0x44);
|
||||
define('NUM_EXTENSION_BLOCK_POS', 0x48);
|
||||
define('PROPERTY_STORAGE_BLOCK_SIZE', 0x80);
|
||||
define('BIG_BLOCK_DEPOT_BLOCKS_POS', 0x4c);
|
||||
define('SMALL_BLOCK_THRESHOLD', 0x1000);
|
||||
// property storage offsets
|
||||
define('SIZE_OF_NAME_POS', 0x40);
|
||||
define('TYPE_POS', 0x42);
|
||||
define('START_BLOCK_POS', 0x74);
|
||||
define('SIZE_POS', 0x78);
|
||||
define('IDENTIFIER_OLE', pack("CCCCCCCC",0xd0,0xcf,0x11,0xe0,0xa1,0xb1,0x1a,0xe1));
|
||||
|
||||
//echo 'ROOT_START_BLOCK_POS = '.ROOT_START_BLOCK_POS."\n";
|
||||
|
||||
//echo bin2hex($data[ROOT_START_BLOCK_POS])."\n";
|
||||
//echo "a=";
|
||||
//echo $data[ROOT_START_BLOCK_POS];
|
||||
//function log
|
||||
|
||||
function GetInt4d($data, $pos)
|
||||
{
|
||||
$value = ord($data[$pos]) | (ord($data[$pos+1]) << 8) | (ord($data[$pos+2]) << 16) | (ord($data[$pos+3]) << 24);
|
||||
if ($value>=4294967294)
|
||||
{
|
||||
$value=-2;
|
||||
}
|
||||
return $value;
|
||||
}
|
||||
|
||||
|
||||
class OLERead {
|
||||
var $data = '';
|
||||
|
||||
|
||||
function OLERead(){
|
||||
|
||||
|
||||
}
|
||||
|
||||
function read($sFileName){
|
||||
|
||||
// check if file exist and is readable (Darko Miljanovic)
|
||||
if(!is_readable($sFileName)) {
|
||||
$this->error = 1;
|
||||
return false;
|
||||
}
|
||||
|
||||
$this->data = @file_get_contents($sFileName);
|
||||
if (!$this->data) {
|
||||
$this->error = 1;
|
||||
return false;
|
||||
}
|
||||
//echo IDENTIFIER_OLE;
|
||||
//echo 'start';
|
||||
if (substr($this->data, 0, 8) != IDENTIFIER_OLE) {
|
||||
$this->error = 1;
|
||||
return false;
|
||||
}
|
||||
$this->numBigBlockDepotBlocks = GetInt4d($this->data, NUM_BIG_BLOCK_DEPOT_BLOCKS_POS);
|
||||
$this->sbdStartBlock = GetInt4d($this->data, SMALL_BLOCK_DEPOT_BLOCK_POS);
|
||||
$this->rootStartBlock = GetInt4d($this->data, ROOT_START_BLOCK_POS);
|
||||
$this->extensionBlock = GetInt4d($this->data, EXTENSION_BLOCK_POS);
|
||||
$this->numExtensionBlocks = GetInt4d($this->data, NUM_EXTENSION_BLOCK_POS);
|
||||
|
||||
/*
|
||||
echo $this->numBigBlockDepotBlocks." ";
|
||||
echo $this->sbdStartBlock." ";
|
||||
echo $this->rootStartBlock." ";
|
||||
echo $this->extensionBlock." ";
|
||||
echo $this->numExtensionBlocks." ";
|
||||
*/
|
||||
//echo "sbdStartBlock = $this->sbdStartBlock\n";
|
||||
$bigBlockDepotBlocks = array();
|
||||
$pos = BIG_BLOCK_DEPOT_BLOCKS_POS;
|
||||
// echo "pos = $pos";
|
||||
$bbdBlocks = $this->numBigBlockDepotBlocks;
|
||||
|
||||
if ($this->numExtensionBlocks != 0) {
|
||||
$bbdBlocks = (BIG_BLOCK_SIZE - BIG_BLOCK_DEPOT_BLOCKS_POS)/4;
|
||||
}
|
||||
|
||||
for ($i = 0; $i < $bbdBlocks; $i++) {
|
||||
$bigBlockDepotBlocks[$i] = GetInt4d($this->data, $pos);
|
||||
$pos += 4;
|
||||
}
|
||||
|
||||
|
||||
for ($j = 0; $j < $this->numExtensionBlocks; $j++) {
|
||||
$pos = ($this->extensionBlock + 1) * BIG_BLOCK_SIZE;
|
||||
$blocksToRead = min($this->numBigBlockDepotBlocks - $bbdBlocks, BIG_BLOCK_SIZE / 4 - 1);
|
||||
|
||||
for ($i = $bbdBlocks; $i < $bbdBlocks + $blocksToRead; $i++) {
|
||||
$bigBlockDepotBlocks[$i] = GetInt4d($this->data, $pos);
|
||||
$pos += 4;
|
||||
}
|
||||
|
||||
$bbdBlocks += $blocksToRead;
|
||||
if ($bbdBlocks < $this->numBigBlockDepotBlocks) {
|
||||
$this->extensionBlock = GetInt4d($this->data, $pos);
|
||||
}
|
||||
}
|
||||
|
||||
// var_dump($bigBlockDepotBlocks);
|
||||
|
||||
// readBigBlockDepot
|
||||
$pos = 0;
|
||||
$index = 0;
|
||||
$this->bigBlockChain = array();
|
||||
|
||||
for ($i = 0; $i < $this->numBigBlockDepotBlocks; $i++) {
|
||||
$pos = ($bigBlockDepotBlocks[$i] + 1) * BIG_BLOCK_SIZE;
|
||||
//echo "pos = $pos";
|
||||
for ($j = 0 ; $j < BIG_BLOCK_SIZE / 4; $j++) {
|
||||
$this->bigBlockChain[$index] = GetInt4d($this->data, $pos);
|
||||
$pos += 4 ;
|
||||
$index++;
|
||||
}
|
||||
}
|
||||
|
||||
//var_dump($this->bigBlockChain);
|
||||
//echo '=====2';
|
||||
// readSmallBlockDepot();
|
||||
$pos = 0;
|
||||
$index = 0;
|
||||
$sbdBlock = $this->sbdStartBlock;
|
||||
$this->smallBlockChain = array();
|
||||
|
||||
while ($sbdBlock != -2) {
|
||||
|
||||
$pos = ($sbdBlock + 1) * BIG_BLOCK_SIZE;
|
||||
|
||||
for ($j = 0; $j < BIG_BLOCK_SIZE / 4; $j++) {
|
||||
$this->smallBlockChain[$index] = GetInt4d($this->data, $pos);
|
||||
$pos += 4;
|
||||
$index++;
|
||||
}
|
||||
|
||||
$sbdBlock = $this->bigBlockChain[$sbdBlock];
|
||||
}
|
||||
|
||||
|
||||
// readData(rootStartBlock)
|
||||
$block = $this->rootStartBlock;
|
||||
$pos = 0;
|
||||
$this->entry = $this->__readData($block);
|
||||
|
||||
/*
|
||||
while ($block != -2) {
|
||||
$pos = ($block + 1) * BIG_BLOCK_SIZE;
|
||||
$this->entry = $this->entry.substr($this->data, $pos, BIG_BLOCK_SIZE);
|
||||
$block = $this->bigBlockChain[$block];
|
||||
}
|
||||
*/
|
||||
//echo '==='.$this->entry."===";
|
||||
$this->__readPropertySets();
|
||||
|
||||
}
|
||||
|
||||
function __readData($bl) {
|
||||
$block = $bl;
|
||||
$pos = 0;
|
||||
$data = '';
|
||||
|
||||
while ($block != -2) {
|
||||
$pos = ($block + 1) * BIG_BLOCK_SIZE;
|
||||
$data = $data.substr($this->data, $pos, BIG_BLOCK_SIZE);
|
||||
//echo "pos = $pos data=$data\n";
|
||||
$block = $this->bigBlockChain[$block];
|
||||
}
|
||||
return $data;
|
||||
}
|
||||
|
||||
function __readPropertySets(){
|
||||
$offset = 0;
|
||||
//var_dump($this->entry);
|
||||
while ($offset < strlen($this->entry)) {
|
||||
$d = substr($this->entry, $offset, PROPERTY_STORAGE_BLOCK_SIZE);
|
||||
|
||||
$nameSize = ord($d[SIZE_OF_NAME_POS]) | (ord($d[SIZE_OF_NAME_POS+1]) << 8);
|
||||
|
||||
$type = ord($d[TYPE_POS]);
|
||||
//$maxBlock = strlen($d) / BIG_BLOCK_SIZE - 1;
|
||||
|
||||
$startBlock = GetInt4d($d, START_BLOCK_POS);
|
||||
$size = GetInt4d($d, SIZE_POS);
|
||||
|
||||
$name = '';
|
||||
for ($i = 0; $i < $nameSize ; $i++) {
|
||||
$name .= $d[$i];
|
||||
}
|
||||
|
||||
$name = str_replace("\x00", "", $name);
|
||||
|
||||
$this->props[] = array (
|
||||
'name' => $name,
|
||||
'type' => $type,
|
||||
'startBlock' => $startBlock,
|
||||
'size' => $size);
|
||||
|
||||
if (($name == "Workbook") || ($name == "Book")) {
|
||||
$this->wrkbook = count($this->props) - 1;
|
||||
}
|
||||
|
||||
if ($name == "Root Entry") {
|
||||
$this->rootentry = count($this->props) - 1;
|
||||
}
|
||||
|
||||
//echo "name ==$name=\n";
|
||||
|
||||
|
||||
$offset += PROPERTY_STORAGE_BLOCK_SIZE;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
function getWorkBook(){
|
||||
if ($this->props[$this->wrkbook]['size'] < SMALL_BLOCK_THRESHOLD){
|
||||
// getSmallBlockStream(PropertyStorage ps)
|
||||
|
||||
$rootdata = $this->__readData($this->props[$this->rootentry]['startBlock']);
|
||||
|
||||
$streamData = '';
|
||||
$block = $this->props[$this->wrkbook]['startBlock'];
|
||||
//$count = 0;
|
||||
$pos = 0;
|
||||
while ($block != -2) {
|
||||
$pos = $block * SMALL_BLOCK_SIZE;
|
||||
$streamData .= substr($rootdata, $pos, SMALL_BLOCK_SIZE);
|
||||
|
||||
$block = $this->smallBlockChain[$block];
|
||||
}
|
||||
|
||||
return $streamData;
|
||||
|
||||
|
||||
}else{
|
||||
|
||||
$numBlocks = $this->props[$this->wrkbook]['size'] / BIG_BLOCK_SIZE;
|
||||
if ($this->props[$this->wrkbook]['size'] % BIG_BLOCK_SIZE != 0) {
|
||||
$numBlocks++;
|
||||
}
|
||||
|
||||
if ($numBlocks == 0) return '';
|
||||
|
||||
//echo "numBlocks = $numBlocks\n";
|
||||
//byte[] streamData = new byte[numBlocks * BIG_BLOCK_SIZE];
|
||||
//print_r($this->wrkbook);
|
||||
$streamData = '';
|
||||
$block = $this->props[$this->wrkbook]['startBlock'];
|
||||
//$count = 0;
|
||||
$pos = 0;
|
||||
//echo "block = $block";
|
||||
while ($block != -2) {
|
||||
$pos = ($block + 1) * BIG_BLOCK_SIZE;
|
||||
$streamData .= substr($this->data, $pos, BIG_BLOCK_SIZE);
|
||||
$block = $this->bigBlockChain[$block];
|
||||
}
|
||||
//echo 'stream'.$streamData;
|
||||
return $streamData;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
?>
|
||||
209
lib/Excel/php_writeexcel/class.writeexcel_biffwriter.inc.php
Normal file
209
lib/Excel/php_writeexcel/class.writeexcel_biffwriter.inc.php
Normal file
@ -0,0 +1,209 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* Copyleft 2002 Johann Hanne
|
||||
*
|
||||
* This is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2.1 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This software is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this software; if not, write to the
|
||||
* Free Software Foundation, Inc., 59 Temple Place,
|
||||
* Suite 330, Boston, MA 02111-1307 USA
|
||||
*/
|
||||
|
||||
/*
|
||||
* This is the Spreadsheet::WriteExcel Perl package ported to PHP
|
||||
* Spreadsheet::WriteExcel was written by John McNamara, jmcnamara@cpan.org
|
||||
*/
|
||||
|
||||
class writeexcel_biffwriter {
|
||||
var $byte_order;
|
||||
var $BIFF_version;
|
||||
var $_byte_order;
|
||||
var $_data;
|
||||
var $_datasize;
|
||||
var $_limit;
|
||||
var $_debug;
|
||||
|
||||
/*
|
||||
* Constructor
|
||||
*/
|
||||
function writeexcel_biffwriter() {
|
||||
|
||||
$this->byte_order = '';
|
||||
$this->BIFF_version = 0x0500;
|
||||
$this->_byte_order = '';
|
||||
$this->_data = false;
|
||||
$this->_datasize = 0;
|
||||
$this->_limit = 2080;
|
||||
|
||||
$this->_set_byte_order();
|
||||
}
|
||||
|
||||
/*
|
||||
* Determine the byte order and store it as class data to avoid
|
||||
* recalculating it for each call to new().
|
||||
*/
|
||||
function _set_byte_order() {
|
||||
$this->byteorder=0;
|
||||
// Check if "pack" gives the required IEEE 64bit float
|
||||
$teststr = pack("d", 1.2345);
|
||||
$number = pack("C8", 0x8D, 0x97, 0x6E, 0x12, 0x83, 0xC0, 0xF3, 0x3F);
|
||||
|
||||
if ($number == $teststr) {
|
||||
$this->byte_order = 0; // Little Endian
|
||||
} elseif ($number == strrev($teststr)) {
|
||||
$this->byte_order = 1; // Big Endian
|
||||
} else {
|
||||
// Give up
|
||||
trigger_error("Required floating point format not supported ".
|
||||
"on this platform. See the portability section ".
|
||||
"of the documentation.", E_USER_ERROR);
|
||||
}
|
||||
|
||||
$this->_byte_order = $this->byte_order;
|
||||
}
|
||||
|
||||
/*
|
||||
* General storage function
|
||||
*/
|
||||
function _prepend($data) {
|
||||
|
||||
if (func_num_args()>1) {
|
||||
trigger_error("writeexcel_biffwriter::_prepend() ".
|
||||
"called with more than one argument", E_USER_ERROR);
|
||||
}
|
||||
|
||||
if ($this->_debug) {
|
||||
print "*** writeexcel_biffwriter::_prepend() called:";
|
||||
for ($c=0;$c<strlen($data);$c++) {
|
||||
if ($c%16==0) {
|
||||
print "\n";
|
||||
}
|
||||
printf("%02X ", ord($data[$c]));
|
||||
}
|
||||
print "\n";
|
||||
}
|
||||
|
||||
if (strlen($data) > $this->_limit) {
|
||||
$data = $this->_add_continue($data);
|
||||
}
|
||||
|
||||
$this->_data = $data . $this->_data;
|
||||
$this->_datasize += strlen($data);
|
||||
}
|
||||
|
||||
/*
|
||||
* General storage function
|
||||
*/
|
||||
function _append($data) {
|
||||
|
||||
if (func_num_args()>1) {
|
||||
trigger_error("writeexcel_biffwriter::_append() ".
|
||||
"called with more than one argument", E_USER_ERROR);
|
||||
}
|
||||
|
||||
if ($this->_debug) {
|
||||
print "*** writeexcel_biffwriter::_append() called:";
|
||||
for ($c=0;$c<strlen($data);$c++) {
|
||||
if ($c%16==0) {
|
||||
print "\n";
|
||||
}
|
||||
printf("%02X ", ord($data[$c]));
|
||||
}
|
||||
print "\n";
|
||||
}
|
||||
|
||||
if (strlen($data) > $this->_limit) {
|
||||
$data = $this->_add_continue($data);
|
||||
}
|
||||
|
||||
$this->_data = $this->_data . $data;
|
||||
$this->_datasize += strlen($data);
|
||||
}
|
||||
|
||||
/*
|
||||
* Writes Excel BOF record to indicate the beginning of a stream or
|
||||
* sub-stream in the BIFF file.
|
||||
*
|
||||
* $type = 0x0005, Workbook
|
||||
* $type = 0x0010, Worksheet
|
||||
*/
|
||||
function _store_bof($type) {
|
||||
|
||||
$record = 0x0809; // Record identifier
|
||||
$length = 0x0008; // Number of bytes to follow
|
||||
|
||||
$version = $this->BIFF_version;
|
||||
|
||||
// According to the SDK $build and $year should be set to zero.
|
||||
// However, this throws a warning in Excel 5. So, use these
|
||||
// magic numbers.
|
||||
$build = 0x096C;
|
||||
$year = 0x07C9;
|
||||
|
||||
$header = pack("vv", $record, $length);
|
||||
$data = pack("vvvv", $version, $type, $build, $year);
|
||||
|
||||
$this->_prepend($header . $data);
|
||||
}
|
||||
|
||||
/*
|
||||
* Writes Excel EOF record to indicate the end of a BIFF stream.
|
||||
*/
|
||||
function _store_eof() {
|
||||
|
||||
$record = 0x000A; // Record identifier
|
||||
$length = 0x0000; // Number of bytes to follow
|
||||
|
||||
$header = pack("vv", $record, $length);
|
||||
|
||||
$this->_append($header);
|
||||
}
|
||||
|
||||
/*
|
||||
* Excel limits the size of BIFF records. In Excel 5 the limit is 2084
|
||||
* bytes. In Excel 97 the limit is 8228 bytes. Records that are longer
|
||||
* than these limits must be split up into CONTINUE blocks.
|
||||
*
|
||||
* This function take a long BIFF record and inserts CONTINUE records as
|
||||
* necessary.
|
||||
*/
|
||||
function _add_continue($data) {
|
||||
|
||||
$limit = $this->_limit;
|
||||
$record = 0x003C; // Record identifier
|
||||
|
||||
// The first 2080/8224 bytes remain intact. However, we have to change
|
||||
// the length field of the record.
|
||||
$tmp = substr($data, 0, $limit);
|
||||
$data = substr($data, $limit);
|
||||
$tmp = substr($tmp, 0, 2) . pack ("v", $limit-4) . substr($tmp, 4);
|
||||
|
||||
// Strip out chunks of 2080/8224 bytes +4 for the header.
|
||||
while (strlen($data) > $limit) {
|
||||
$header = pack("vv", $record, $limit);
|
||||
$tmp .= $header;
|
||||
$tmp .= substr($data, 0, $limit);
|
||||
$data = substr($data, $limit);
|
||||
}
|
||||
|
||||
// Mop up the last of the data
|
||||
$header = pack("vv", $record, strlen($data));
|
||||
$tmp .= $header;
|
||||
$tmp .= $data;
|
||||
|
||||
return $tmp;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
?>
|
||||
695
lib/Excel/php_writeexcel/class.writeexcel_format.inc.php
Normal file
695
lib/Excel/php_writeexcel/class.writeexcel_format.inc.php
Normal file
@ -0,0 +1,695 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* Copyleft 2002 Johann Hanne
|
||||
*
|
||||
* This is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2.1 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This software is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this software; if not, write to the
|
||||
* Free Software Foundation, Inc., 59 Temple Place,
|
||||
* Suite 330, Boston, MA 02111-1307 USA
|
||||
*/
|
||||
|
||||
/*
|
||||
* This is the Spreadsheet::WriteExcel Perl package ported to PHP
|
||||
* Spreadsheet::WriteExcel was written by John McNamara, jmcnamara@cpan.org
|
||||
*/
|
||||
|
||||
class writeexcel_format {
|
||||
|
||||
var $_xf_index;
|
||||
var $_font_index;
|
||||
var $_font;
|
||||
var $_size;
|
||||
var $_bold;
|
||||
var $_italic;
|
||||
var $_color;
|
||||
var $_underline;
|
||||
var $_font_strikeout;
|
||||
var $_font_outline;
|
||||
var $_font_shadow;
|
||||
var $_font_script;
|
||||
var $_font_family;
|
||||
var $_font_charset;
|
||||
var $_num_format;
|
||||
var $_hidden;
|
||||
var $_locked;
|
||||
var $_text_h_align;
|
||||
var $_text_wrap;
|
||||
var $_text_v_align;
|
||||
var $_text_justlast;
|
||||
var $_rotation;
|
||||
var $_fg_color;
|
||||
var $_bg_color;
|
||||
var $_pattern;
|
||||
var $_bottom;
|
||||
var $_top;
|
||||
var $_left;
|
||||
var $_right;
|
||||
var $_bottom_color;
|
||||
var $_top_color;
|
||||
var $_left_color;
|
||||
var $_right_color;
|
||||
|
||||
/*
|
||||
* Constructor
|
||||
*/
|
||||
function writeexcel_format() {
|
||||
$_=func_get_args();
|
||||
|
||||
$this->_xf_index = (sizeof($_)>0) ? array_shift($_) : 0;
|
||||
|
||||
$this->_font_index = 0;
|
||||
$this->_font = 'Arial';
|
||||
$this->_size = 10;
|
||||
$this->_bold = 0x0190;
|
||||
$this->_italic = 0;
|
||||
$this->_color = 0x7FFF;
|
||||
$this->_underline = 0;
|
||||
$this->_font_strikeout = 0;
|
||||
$this->_font_outline = 0;
|
||||
$this->_font_shadow = 0;
|
||||
$this->_font_script = 0;
|
||||
$this->_font_family = 0;
|
||||
$this->_font_charset = 0;
|
||||
|
||||
$this->_num_format = 0;
|
||||
|
||||
$this->_hidden = 0;
|
||||
$this->_locked = 1;
|
||||
|
||||
$this->_text_h_align = 0;
|
||||
$this->_text_wrap = 0;
|
||||
$this->_text_v_align = 2;
|
||||
$this->_text_justlast = 0;
|
||||
$this->_rotation = 0;
|
||||
|
||||
$this->_fg_color = 0x40;
|
||||
$this->_bg_color = 0x41;
|
||||
|
||||
$this->_pattern = 0;
|
||||
|
||||
$this->_bottom = 0;
|
||||
$this->_top = 0;
|
||||
$this->_left = 0;
|
||||
$this->_right = 0;
|
||||
|
||||
$this->_bottom_color = 0x40;
|
||||
$this->_top_color = 0x40;
|
||||
$this->_left_color = 0x40;
|
||||
$this->_right_color = 0x40;
|
||||
|
||||
// Set properties passed to writeexcel_workbook::addformat()
|
||||
if (sizeof($_)>0) {
|
||||
call_user_func_array(array(&$this, 'set_properties'), $_);
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Copy the attributes of another writeexcel_format object.
|
||||
*/
|
||||
function copy($other) {
|
||||
$xf = $this->_xf_index; // Backup XF index
|
||||
foreach ($other as $key->$value) {
|
||||
$this->{$key} = $value;
|
||||
}
|
||||
$this->_xf_index = $xf; // Restore XF index
|
||||
}
|
||||
|
||||
/*
|
||||
* Generate an Excel BIFF XF record.
|
||||
*/
|
||||
function get_xf() {
|
||||
|
||||
$_=func_get_args();
|
||||
|
||||
// $record Record identifier
|
||||
// $length Number of bytes to follow
|
||||
|
||||
// $ifnt Index to FONT record
|
||||
// $ifmt Index to FORMAT record
|
||||
// $style Style and other options
|
||||
// $align Alignment
|
||||
// $icv fg and bg pattern colors
|
||||
// $fill Fill and border line style
|
||||
// $border1 Border line style and color
|
||||
// $border2 Border color
|
||||
|
||||
// Set the type of the XF record and some of the attributes.
|
||||
if ($_[0] == "style") {
|
||||
$style = 0xFFF5;
|
||||
} else {
|
||||
$style = $this->_locked;
|
||||
$style |= $this->_hidden << 1;
|
||||
}
|
||||
|
||||
// Flags to indicate if attributes have been set.
|
||||
$atr_num = ($this->_num_format != 0) ? 1 : 0;
|
||||
$atr_fnt = ($this->_font_index != 0) ? 1 : 0;
|
||||
$atr_alc = $this->_text_wrap ? 1 : 0;
|
||||
$atr_bdr = ($this->_bottom ||
|
||||
$this->_top ||
|
||||
$this->_left ||
|
||||
$this->_right) ? 1 : 0;
|
||||
$atr_pat = ($this->_fg_color != 0x41 ||
|
||||
$this->_bg_color != 0x41 ||
|
||||
$this->_pattern != 0x00) ? 1 : 0;
|
||||
$atr_prot = 0;
|
||||
|
||||
// Reset the default colors for the non-font properties
|
||||
if ($this->_fg_color == 0x7FFF) $this->_fg_color = 0x40;
|
||||
if ($this->_bg_color == 0x7FFF) $this->_bg_color = 0x41;
|
||||
if ($this->_bottom_color == 0x7FFF) $this->_bottom_color = 0x41;
|
||||
if ($this->_top_color == 0x7FFF) $this->_top_color = 0x41;
|
||||
if ($this->_left_color == 0x7FFF) $this->_left_color = 0x41;
|
||||
if ($this->_right_color == 0x7FFF) $this->_right_color = 0x41;
|
||||
|
||||
// Zero the default border colour if the border has not been set.
|
||||
if ($this->_bottom == 0) {
|
||||
$this->_bottom_color = 0;
|
||||
}
|
||||
if ($this->_top == 0) {
|
||||
$this->_top_color = 0;
|
||||
}
|
||||
if ($this->_right == 0) {
|
||||
$this->_right_color = 0;
|
||||
}
|
||||
if ($this->_left == 0) {
|
||||
$this->_left_color = 0;
|
||||
}
|
||||
|
||||
// The following 2 logical statements take care of special cases in
|
||||
// relation to cell colors and patterns:
|
||||
// 1. For a solid fill (_pattern == 1) Excel reverses the role of
|
||||
// foreground and background colors
|
||||
// 2. If the user specifies a foreground or background color
|
||||
// without a pattern they probably wanted a solid fill, so we
|
||||
// fill in the defaults.
|
||||
if ($this->_pattern <= 0x01 &&
|
||||
$this->_bg_color != 0x41 &&
|
||||
$this->_fg_color == 0x40 )
|
||||
{
|
||||
$this->_fg_color = $this->_bg_color;
|
||||
$this->_bg_color = 0x40;
|
||||
$this->_pattern = 1;
|
||||
}
|
||||
|
||||
if ($this->_pattern <= 0x01 &&
|
||||
$this->_bg_color == 0x41 &&
|
||||
$this->_fg_color != 0x40 )
|
||||
{
|
||||
$this->_bg_color = 0x40;
|
||||
$this->_pattern = 1;
|
||||
}
|
||||
|
||||
$record = 0x00E0;
|
||||
$length = 0x0010;
|
||||
|
||||
$ifnt = $this->_font_index;
|
||||
$ifmt = $this->_num_format;
|
||||
|
||||
$align = $this->_text_h_align;
|
||||
$align |= $this->_text_wrap << 3;
|
||||
$align |= $this->_text_v_align << 4;
|
||||
$align |= $this->_text_justlast << 7;
|
||||
$align |= $this->_rotation << 8;
|
||||
$align |= $atr_num << 10;
|
||||
$align |= $atr_fnt << 11;
|
||||
$align |= $atr_alc << 12;
|
||||
$align |= $atr_bdr << 13;
|
||||
$align |= $atr_pat << 14;
|
||||
$align |= $atr_prot << 15;
|
||||
|
||||
$icv = $this->_fg_color;
|
||||
$icv |= $this->_bg_color << 7;
|
||||
|
||||
$fill = $this->_pattern;
|
||||
$fill |= $this->_bottom << 6;
|
||||
$fill |= $this->_bottom_color << 9;
|
||||
|
||||
$border1 = $this->_top;
|
||||
$border1 |= $this->_left << 3;
|
||||
$border1 |= $this->_right << 6;
|
||||
$border1 |= $this->_top_color << 9;
|
||||
|
||||
$border2 = $this->_left_color;
|
||||
$border2 |= $this->_right_color << 7;
|
||||
|
||||
$header = pack("vv", $record, $length);
|
||||
$data = pack("vvvvvvvv", $ifnt, $ifmt, $style, $align,
|
||||
$icv, $fill,
|
||||
$border1, $border2);
|
||||
|
||||
return($header . $data);
|
||||
}
|
||||
|
||||
/*
|
||||
* Generate an Excel BIFF FONT record.
|
||||
*/
|
||||
function get_font() {
|
||||
|
||||
// $record Record identifier
|
||||
// $length Record length
|
||||
|
||||
// $dyHeight Height of font (1/20 of a point)
|
||||
// $grbit Font attributes
|
||||
// $icv Index to color palette
|
||||
// $bls Bold style
|
||||
// $sss Superscript/subscript
|
||||
// $uls Underline
|
||||
// $bFamily Font family
|
||||
// $bCharSet Character set
|
||||
// $reserved Reserved
|
||||
// $cch Length of font name
|
||||
// $rgch Font name
|
||||
|
||||
$dyHeight = $this->_size * 20;
|
||||
$icv = $this->_color;
|
||||
$bls = $this->_bold;
|
||||
$sss = $this->_font_script;
|
||||
$uls = $this->_underline;
|
||||
$bFamily = $this->_font_family;
|
||||
$bCharSet = $this->_font_charset;
|
||||
$rgch = $this->_font;
|
||||
|
||||
$cch = strlen($rgch);
|
||||
$record = 0x31;
|
||||
$length = 0x0F + $cch;
|
||||
$reserved = 0x00;
|
||||
|
||||
$grbit = 0x00;
|
||||
|
||||
if ($this->_italic) {
|
||||
$grbit |= 0x02;
|
||||
}
|
||||
|
||||
if ($this->_font_strikeout) {
|
||||
$grbit |= 0x08;
|
||||
}
|
||||
|
||||
if ($this->_font_outline) {
|
||||
$grbit |= 0x10;
|
||||
}
|
||||
|
||||
if ($this->_font_shadow) {
|
||||
$grbit |= 0x20;
|
||||
}
|
||||
|
||||
$header = pack("vv", $record, $length);
|
||||
$data = pack("vvvvvCCCCC", $dyHeight, $grbit, $icv, $bls,
|
||||
$sss, $uls, $bFamily,
|
||||
$bCharSet, $reserved, $cch);
|
||||
|
||||
return($header . $data . $this->_font);
|
||||
}
|
||||
|
||||
/*
|
||||
* Returns a unique hash key for a font.
|
||||
* Used by writeexcel_workbook::_store_all_fonts()
|
||||
*/
|
||||
function get_font_key() {
|
||||
|
||||
# The following elements are arranged to increase the probability of
|
||||
# generating a unique key. Elements that hold a large range of numbers
|
||||
# eg. _color are placed between two binary elements such as _italic
|
||||
#
|
||||
$key = $this->_font.$this->_size.
|
||||
$this->_font_script.$this->_underline.
|
||||
$this->_font_strikeout.$this->_bold.$this->_font_outline.
|
||||
$this->_font_family.$this->_font_charset.
|
||||
$this->_font_shadow.$this->_color.$this->_italic;
|
||||
|
||||
$key = preg_replace('/ /', '_', $key); # Convert the key to a single word
|
||||
|
||||
return $key;
|
||||
}
|
||||
|
||||
/*
|
||||
* Returns the used by Worksheet->_XF()
|
||||
*/
|
||||
function get_xf_index() {
|
||||
return $this->_xf_index;
|
||||
}
|
||||
|
||||
/*
|
||||
* Used in conjunction with the set_xxx_color methods to convert a color
|
||||
* string into a number. Color range is 0..63 but we will restrict it
|
||||
* to 8..63 to comply with Gnumeric. Colors 0..7 are repeated in 8..15.
|
||||
*/
|
||||
function _get_color($color=false) {
|
||||
|
||||
$colors = array(
|
||||
'aqua' => 0x0F,
|
||||
'cyan' => 0x0F,
|
||||
'black' => 0x08,
|
||||
'blue' => 0x0C,
|
||||
'brown' => 0x10,
|
||||
'magenta' => 0x0E,
|
||||
'fuchsia' => 0x0E,
|
||||
'gray' => 0x17,
|
||||
'grey' => 0x17,
|
||||
'green' => 0x11,
|
||||
'lime' => 0x0B,
|
||||
'navy' => 0x12,
|
||||
'orange' => 0x35,
|
||||
'purple' => 0x14,
|
||||
'red' => 0x0A,
|
||||
'silver' => 0x16,
|
||||
'white' => 0x09,
|
||||
'yellow' => 0x0D
|
||||
);
|
||||
|
||||
// Return the default color, 0x7FFF, if undef,
|
||||
if ($color===false) {
|
||||
return 0x7FFF;
|
||||
}
|
||||
|
||||
// or the color string converted to an integer,
|
||||
if (isset($colors[strtolower($color)])) {
|
||||
return $colors[strtolower($color)];
|
||||
}
|
||||
|
||||
// or the default color if string is unrecognised,
|
||||
if (preg_match('/\D/', $color)) {
|
||||
return 0x7FFF;
|
||||
}
|
||||
|
||||
// or an index < 8 mapped into the correct range,
|
||||
if ($color<8) {
|
||||
return $color + 8;
|
||||
}
|
||||
|
||||
// or the default color if arg is outside range,
|
||||
if ($color>63) {
|
||||
return 0x7FFF;
|
||||
}
|
||||
|
||||
// or an integer in the valid range
|
||||
return $color;
|
||||
}
|
||||
|
||||
/*
|
||||
* Set cell alignment.
|
||||
*/
|
||||
function set_align($location) {
|
||||
|
||||
// Ignore numbers
|
||||
if (preg_match('/\d/', $location)) {
|
||||
return;
|
||||
}
|
||||
|
||||
$location = strtolower($location);
|
||||
|
||||
switch ($location) {
|
||||
|
||||
case 'left':
|
||||
$this->set_text_h_align(1);
|
||||
break;
|
||||
|
||||
case 'centre':
|
||||
case 'center':
|
||||
$this->set_text_h_align(2);
|
||||
break;
|
||||
|
||||
case 'right':
|
||||
$this->set_text_h_align(3);
|
||||
break;
|
||||
|
||||
case 'fill':
|
||||
$this->set_text_h_align(4);
|
||||
break;
|
||||
|
||||
case 'justify':
|
||||
$this->set_text_h_align(5);
|
||||
break;
|
||||
|
||||
case 'merge':
|
||||
$this->set_text_h_align(6);
|
||||
break;
|
||||
|
||||
case 'equal_space':
|
||||
$this->set_text_h_align(7);
|
||||
break;
|
||||
|
||||
case 'top':
|
||||
$this->set_text_v_align(0);
|
||||
break;
|
||||
|
||||
case 'vcentre':
|
||||
case 'vcenter':
|
||||
$this->set_text_v_align(1);
|
||||
break;
|
||||
break;
|
||||
|
||||
case 'bottom':
|
||||
$this->set_text_v_align(2);
|
||||
break;
|
||||
|
||||
case 'vjustify':
|
||||
$this->set_text_v_align(3);
|
||||
break;
|
||||
|
||||
case 'vequal_space':
|
||||
$this->set_text_v_align(4);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Set vertical cell alignment. This is required by the set_properties()
|
||||
* method to differentiate between the vertical and horizontal properties.
|
||||
*/
|
||||
function set_valign($location) {
|
||||
$this->set_align($location);
|
||||
}
|
||||
|
||||
/*
|
||||
* This is an alias for the unintuitive set_align('merge')
|
||||
*/
|
||||
function set_merge() {
|
||||
$this->set_text_h_align(6);
|
||||
}
|
||||
|
||||
/*
|
||||
* Bold has a range 0x64..0x3E8.
|
||||
* 0x190 is normal. 0x2BC is bold.
|
||||
*/
|
||||
function set_bold($weight=1) {
|
||||
|
||||
if ($weight == 1) {
|
||||
// Bold text
|
||||
$weight = 0x2BC;
|
||||
}
|
||||
|
||||
if ($weight == 0) {
|
||||
// Normal text
|
||||
$weight = 0x190;
|
||||
}
|
||||
|
||||
if ($weight < 0x064) {
|
||||
// Lower bound
|
||||
$weight = 0x190;
|
||||
}
|
||||
|
||||
if ($weight > 0x3E8) {
|
||||
// Upper bound
|
||||
$weight = 0x190;
|
||||
}
|
||||
|
||||
$this->_bold = $weight;
|
||||
}
|
||||
|
||||
/*
|
||||
* Set all cell borders (bottom, top, left, right) to the same style
|
||||
*/
|
||||
function set_border($style) {
|
||||
$this->set_bottom($style);
|
||||
$this->set_top($style);
|
||||
$this->set_left($style);
|
||||
$this->set_right($style);
|
||||
}
|
||||
|
||||
/*
|
||||
* Set all cell borders (bottom, top, left, right) to the same color
|
||||
*/
|
||||
function set_border_color($color) {
|
||||
$this->set_bottom_color($color);
|
||||
$this->set_top_color($color);
|
||||
$this->set_left_color($color);
|
||||
$this->set_right_color($color);
|
||||
}
|
||||
|
||||
/*
|
||||
* Convert hashes of properties to method calls.
|
||||
*/
|
||||
function set_properties() {
|
||||
|
||||
$_=func_get_args();
|
||||
|
||||
$properties=array();
|
||||
foreach($_ as $props) {
|
||||
if (is_array($props)) {
|
||||
$properties=array_merge($properties, $props);
|
||||
} else {
|
||||
$properties[]=$props;
|
||||
}
|
||||
}
|
||||
|
||||
foreach ($properties as $key=>$value) {
|
||||
|
||||
// Strip leading "-" from Tk style properties eg. -color => 'red'.
|
||||
$key = preg_replace('/^-/', '', $key);
|
||||
|
||||
/* Make sure method names are alphanumeric characters only, in
|
||||
case tainted data is passed to the eval(). */
|
||||
if (preg_match('/\W/', $key)) {
|
||||
trigger_error("Unknown property: $key.",
|
||||
E_USER_ERROR);
|
||||
}
|
||||
|
||||
/* Evaling all $values as a strings gets around the problem of
|
||||
some numerical format strings being evaluated as numbers, for
|
||||
example "00000" for a zip code. */
|
||||
if (is_int($key)) {
|
||||
eval("\$this->set_$value();");
|
||||
} else {
|
||||
eval("\$this->set_$key('$value');");
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
function set_font($font) {
|
||||
$this->_font=$font;
|
||||
}
|
||||
|
||||
function set_size($size) {
|
||||
$this->_size=$size;
|
||||
}
|
||||
|
||||
function set_italic($italic=1) {
|
||||
$this->_italic=$italic;
|
||||
}
|
||||
|
||||
function set_color($color) {
|
||||
$this->_color=$this->_get_color($color);
|
||||
}
|
||||
|
||||
function set_underline($underline=1) {
|
||||
$this->_underline=$underline;
|
||||
}
|
||||
|
||||
function set_font_strikeout($font_strikeout=1) {
|
||||
$this->_font_strikeout=$font_strikeout;
|
||||
}
|
||||
|
||||
function set_font_outline($font_outline=1) {
|
||||
$this->_font_outline=$font_outline;
|
||||
}
|
||||
|
||||
function set_font_shadow($font_shadow=1) {
|
||||
$this->_font_shadow=$font_shadow;
|
||||
}
|
||||
|
||||
function set_font_script($font_script=1) {
|
||||
$this->_font_script=$font_script;
|
||||
}
|
||||
|
||||
/* Undocumented */
|
||||
function set_font_family($font_family=1) {
|
||||
$this->_font_family=$font_family;
|
||||
}
|
||||
|
||||
/* Undocumented */
|
||||
function set_font_charset($font_charset=1) {
|
||||
$this->_font_charset=$font_charset;
|
||||
}
|
||||
|
||||
function set_num_format($num_format=1) {
|
||||
$this->_num_format=$num_format;
|
||||
}
|
||||
|
||||
function set_hidden($hidden=1) {
|
||||
$this->_hidden=$hidden;
|
||||
}
|
||||
|
||||
function set_locked($locked=1) {
|
||||
$this->_locked=$locked;
|
||||
}
|
||||
|
||||
function set_text_h_align($align) {
|
||||
$this->_text_h_align=$align;
|
||||
}
|
||||
|
||||
function set_text_wrap($wrap=1) {
|
||||
$this->_text_wrap=$wrap;
|
||||
}
|
||||
|
||||
function set_text_v_align($align) {
|
||||
$this->_text_v_align=$align;
|
||||
}
|
||||
|
||||
function set_text_justlast($text_justlast=1) {
|
||||
$this->_text_justlast=$text_justlast;
|
||||
}
|
||||
|
||||
function set_rotation($rotation=1) {
|
||||
$this->_rotation=$rotation;
|
||||
}
|
||||
|
||||
function set_fg_color($color) {
|
||||
$this->_fg_color=$this->_get_color($color);
|
||||
}
|
||||
|
||||
function set_bg_color($color) {
|
||||
$this->_bg_color=$this->_get_color($color);
|
||||
}
|
||||
|
||||
function set_pattern($pattern=1) {
|
||||
$this->_pattern=$pattern;
|
||||
}
|
||||
|
||||
function set_bottom($bottom=1) {
|
||||
$this->_bottom=$bottom;
|
||||
}
|
||||
|
||||
function set_top($top=1) {
|
||||
$this->_top=$top;
|
||||
}
|
||||
|
||||
function set_left($left=1) {
|
||||
$this->_left=$left;
|
||||
}
|
||||
|
||||
function set_right($right=1) {
|
||||
$this->_right=$right;
|
||||
}
|
||||
|
||||
function set_bottom_color($color) {
|
||||
$this->_bottom_color=$this->_get_color($color);
|
||||
}
|
||||
|
||||
function set_top_color($color) {
|
||||
$this->_top_color=$this->_get_color($color);
|
||||
}
|
||||
|
||||
function set_left_color($color) {
|
||||
$this->_left_color=$this->_get_color($color);
|
||||
}
|
||||
|
||||
function set_right_color($color) {
|
||||
$this->_right_color=$this->_get_color($color);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
?>
|
||||
1610
lib/Excel/php_writeexcel/class.writeexcel_formula.inc.php
Normal file
1610
lib/Excel/php_writeexcel/class.writeexcel_formula.inc.php
Normal file
File diff suppressed because it is too large
Load Diff
353
lib/Excel/php_writeexcel/class.writeexcel_olewriter.inc.php
Normal file
353
lib/Excel/php_writeexcel/class.writeexcel_olewriter.inc.php
Normal file
@ -0,0 +1,353 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* Copyleft 2002 Johann Hanne
|
||||
*
|
||||
* This is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2.1 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This software is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this software; if not, write to the
|
||||
* Free Software Foundation, Inc., 59 Temple Place,
|
||||
* Suite 330, Boston, MA 02111-1307 USA
|
||||
*/
|
||||
|
||||
/*
|
||||
* This is the Spreadsheet::WriteExcel Perl package ported to PHP
|
||||
* Spreadsheet::WriteExcel was written by John McNamara, jmcnamara@cpan.org
|
||||
*/
|
||||
|
||||
class writeexcel_olewriter {
|
||||
var $_OLEfilename;
|
||||
var $_OLEtmpfilename; /* ABR */
|
||||
var $_filehandle;
|
||||
var $_fileclosed;
|
||||
var $_internal_fh;
|
||||
var $_biff_only;
|
||||
var $_size_allowed;
|
||||
var $_biffsize;
|
||||
var $_booksize;
|
||||
var $_big_blocks;
|
||||
var $_list_blocks;
|
||||
var $_root_start;
|
||||
var $_block_count;
|
||||
|
||||
/*
|
||||
* Constructor
|
||||
*/
|
||||
function writeexcel_olewriter($filename) {
|
||||
|
||||
$this->_OLEfilename = $filename;
|
||||
$this->_filehandle = false;
|
||||
$this->_fileclosed = 0;
|
||||
$this->_internal_fh = 0;
|
||||
$this->_biff_only = 0;
|
||||
$this->_size_allowed = 0;
|
||||
$this->_biffsize = 0;
|
||||
$this->_booksize = 0;
|
||||
$this->_big_blocks = 0;
|
||||
$this->_list_blocks = 0;
|
||||
$this->_root_start = 0;
|
||||
$this->_block_count = 4;
|
||||
|
||||
$this->_initialize();
|
||||
}
|
||||
|
||||
/*
|
||||
* Check for a valid filename and store the filehandle.
|
||||
*/
|
||||
function _initialize() {
|
||||
$OLEfile = $this->_OLEfilename;
|
||||
|
||||
/* Check for a filename. Workbook.pm will catch this first. */
|
||||
if ($OLEfile == '') {
|
||||
trigger_error("Filename required", E_USER_ERROR);
|
||||
}
|
||||
|
||||
/*
|
||||
* If the filename is a resource it is assumed that it is a valid
|
||||
* filehandle, if not we create a filehandle.
|
||||
*/
|
||||
if (is_resource($OLEfile)) {
|
||||
$fh = $OLEfile;
|
||||
} else {
|
||||
// Create a new file, open for writing
|
||||
$fh = fopen($OLEfile, "wb");
|
||||
// The workbook class also checks this but something may have
|
||||
// happened since then.
|
||||
if (!$fh) {
|
||||
trigger_error("Can't open $OLEfile. It may be in use or ".
|
||||
"protected", E_USER_ERROR);
|
||||
}
|
||||
|
||||
$this->_internal_fh = 1;
|
||||
}
|
||||
|
||||
// Store filehandle
|
||||
$this->_filehandle = $fh;
|
||||
}
|
||||
|
||||
/*
|
||||
* Set the size of the data to be written to the OLE stream
|
||||
*
|
||||
* $big_blocks = (109 depot block x (128 -1 marker word)
|
||||
* - (1 x end words)) = 13842
|
||||
* $maxsize = $big_blocks * 512 bytes = 7087104
|
||||
*/
|
||||
function set_size($size) {
|
||||
$maxsize = 7087104;
|
||||
|
||||
if ($size > $maxsize) {
|
||||
trigger_error("Maximum file size, $maxsize, exceeded. To create ".
|
||||
"files bigger than this limit please use the ".
|
||||
"workbookbig class.", E_USER_ERROR);
|
||||
return ($this->_size_allowed = 0);
|
||||
}
|
||||
|
||||
$this->_biffsize = $size;
|
||||
|
||||
// Set the min file size to 4k to avoid having to use small blocks
|
||||
if ($size > 4096) {
|
||||
$this->_booksize = $size;
|
||||
} else {
|
||||
$this->_booksize = 4096;
|
||||
}
|
||||
|
||||
return ($this->_size_allowed = 1);
|
||||
}
|
||||
|
||||
/*
|
||||
* Calculate various sizes needed for the OLE stream
|
||||
*/
|
||||
function _calculate_sizes() {
|
||||
$datasize = $this->_booksize;
|
||||
|
||||
if ($datasize % 512 == 0) {
|
||||
$this->_big_blocks = $datasize/512;
|
||||
} else {
|
||||
$this->_big_blocks = floor($datasize/512)+1;
|
||||
}
|
||||
// There are 127 list blocks and 1 marker blocks for each big block
|
||||
// depot + 1 end of chain block
|
||||
$this->_list_blocks = floor(($this->_big_blocks)/127)+1;
|
||||
$this->_root_start = $this->_big_blocks;
|
||||
|
||||
//print $this->_biffsize. "\n";
|
||||
//print $this->_big_blocks. "\n";
|
||||
//print $this->_list_blocks. "\n";
|
||||
}
|
||||
|
||||
/*
|
||||
* Write root entry, big block list and close the filehandle.
|
||||
* This method must be called so that the file contents are
|
||||
* actually written.
|
||||
*/
|
||||
function close() {
|
||||
|
||||
if (!$this->_size_allowed) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!$this->_biff_only) {
|
||||
$this->_write_padding();
|
||||
$this->_write_property_storage();
|
||||
$this->_write_big_block_depot();
|
||||
}
|
||||
|
||||
// Close the filehandle if it was created internally.
|
||||
if ($this->_internal_fh) {
|
||||
fclose($this->_filehandle);
|
||||
}
|
||||
/* ABR */
|
||||
if ($this->_OLEtmpfilename != '') {
|
||||
$fh = fopen($this->_OLEtmpfilename, "rb");
|
||||
if ($fh == false) {
|
||||
trigger_error("Can't read temporary file.", E_USER_ERROR);
|
||||
}
|
||||
fpassthru($fh);
|
||||
fclose($fh);
|
||||
unlink($this->_OLEtmpfilename);
|
||||
};
|
||||
|
||||
$this->_fileclosed = 1;
|
||||
}
|
||||
|
||||
/*
|
||||
* Write BIFF data to OLE file.
|
||||
*/
|
||||
function write($data) {
|
||||
fputs($this->_filehandle, $data);
|
||||
}
|
||||
|
||||
/*
|
||||
* Write OLE header block.
|
||||
*/
|
||||
function write_header() {
|
||||
if ($this->_biff_only) {
|
||||
return;
|
||||
}
|
||||
|
||||
$this->_calculate_sizes();
|
||||
|
||||
$root_start = $this->_root_start;
|
||||
$num_lists = $this->_list_blocks;
|
||||
|
||||
$id = pack("C8", 0xD0, 0xCF, 0x11, 0xE0,
|
||||
0xA1, 0xB1, 0x1A, 0xE1);
|
||||
$unknown1 = pack("VVVV", 0x00, 0x00, 0x00, 0x00);
|
||||
$unknown2 = pack("vv", 0x3E, 0x03);
|
||||
$unknown3 = pack("v", -2);
|
||||
$unknown4 = pack("v", 0x09);
|
||||
$unknown5 = pack("VVV", 0x06, 0x00, 0x00);
|
||||
$num_bbd_blocks = pack("V", $num_lists);
|
||||
$root_startblock = pack("V", $root_start);
|
||||
$unknown6 = pack("VV", 0x00, 0x1000);
|
||||
$sbd_startblock = pack("V", -2);
|
||||
$unknown7 = pack("VVV", 0x00, -2 ,0x00);
|
||||
$unused = pack("V", -1);
|
||||
|
||||
fputs($this->_filehandle, $id);
|
||||
fputs($this->_filehandle, $unknown1);
|
||||
fputs($this->_filehandle, $unknown2);
|
||||
fputs($this->_filehandle, $unknown3);
|
||||
fputs($this->_filehandle, $unknown4);
|
||||
fputs($this->_filehandle, $unknown5);
|
||||
fputs($this->_filehandle, $num_bbd_blocks);
|
||||
fputs($this->_filehandle, $root_startblock);
|
||||
fputs($this->_filehandle, $unknown6);
|
||||
fputs($this->_filehandle, $sbd_startblock);
|
||||
fputs($this->_filehandle, $unknown7);
|
||||
|
||||
for ($c=1;$c<=$num_lists;$c++) {
|
||||
$root_start++;
|
||||
fputs($this->_filehandle, pack("V", $root_start));
|
||||
}
|
||||
|
||||
for ($c=$num_lists;$c<=108;$c++) {
|
||||
fputs($this->_filehandle, $unused);
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Write big block depot.
|
||||
*/
|
||||
function _write_big_block_depot() {
|
||||
$num_blocks = $this->_big_blocks;
|
||||
$num_lists = $this->_list_blocks;
|
||||
$total_blocks = $num_lists * 128;
|
||||
$used_blocks = $num_blocks + $num_lists + 2;
|
||||
|
||||
$marker = pack("V", -3);
|
||||
$end_of_chain = pack("V", -2);
|
||||
$unused = pack("V", -1);
|
||||
|
||||
for ($i=1;$i<=($num_blocks-1);$i++) {
|
||||
fputs($this->_filehandle, pack("V", $i));
|
||||
}
|
||||
|
||||
fputs($this->_filehandle, $end_of_chain);
|
||||
fputs($this->_filehandle, $end_of_chain);
|
||||
|
||||
for ($c=1;$c<=$num_lists;$c++) {
|
||||
fputs($this->_filehandle, $marker);
|
||||
}
|
||||
|
||||
for ($c=$used_blocks;$c<=$total_blocks;$c++) {
|
||||
fputs($this->_filehandle, $unused);
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Write property storage. TODO: add summary sheets
|
||||
*/
|
||||
function _write_property_storage() {
|
||||
$rootsize = -2;
|
||||
$booksize = $this->_booksize;
|
||||
|
||||
// name type dir start size
|
||||
$this->_write_pps('Root Entry', 0x05, 1, -2, 0x00);
|
||||
$this->_write_pps('Book', 0x02, -1, 0x00, $booksize);
|
||||
$this->_write_pps('', 0x00, -1, 0x00, 0x0000);
|
||||
$this->_write_pps('', 0x00, -1, 0x00, 0x0000);
|
||||
}
|
||||
|
||||
/*
|
||||
* Write property sheet in property storage
|
||||
*/
|
||||
function _write_pps($name, $type, $dir, $start, $size) {
|
||||
$names = array();
|
||||
$length = 0;
|
||||
|
||||
if ($name != '') {
|
||||
$name = $name . "\0";
|
||||
// Simulate a Unicode string
|
||||
$chars=preg_split("''", $name, -1, PREG_SPLIT_NO_EMPTY);
|
||||
foreach ($chars as $char) {
|
||||
array_push($names, ord($char));
|
||||
}
|
||||
$length = strlen($name) * 2;
|
||||
}
|
||||
|
||||
$rawname = call_user_func_array('pack', array_merge(array("v*"), $names));
|
||||
$zero = pack("C", 0);
|
||||
|
||||
$pps_sizeofname = pack("v", $length); //0x40
|
||||
$pps_type = pack("v", $type); //0x42
|
||||
$pps_prev = pack("V", -1); //0x44
|
||||
$pps_next = pack("V", -1); //0x48
|
||||
$pps_dir = pack("V", $dir); //0x4c
|
||||
|
||||
$unknown1 = pack("V", 0);
|
||||
|
||||
$pps_ts1s = pack("V", 0); //0x64
|
||||
$pps_ts1d = pack("V", 0); //0x68
|
||||
$pps_ts2s = pack("V", 0); //0x6c
|
||||
$pps_ts2d = pack("V", 0); //0x70
|
||||
$pps_sb = pack("V", $start); //0x74
|
||||
$pps_size = pack("V", $size); //0x78
|
||||
|
||||
fputs($this->_filehandle, $rawname);
|
||||
fputs($this->_filehandle, str_repeat($zero, (64-$length)));
|
||||
fputs($this->_filehandle, $pps_sizeofname);
|
||||
fputs($this->_filehandle, $pps_type);
|
||||
fputs($this->_filehandle, $pps_prev);
|
||||
fputs($this->_filehandle, $pps_next);
|
||||
fputs($this->_filehandle, $pps_dir);
|
||||
fputs($this->_filehandle, str_repeat($unknown1, 5));
|
||||
fputs($this->_filehandle, $pps_ts1s);
|
||||
fputs($this->_filehandle, $pps_ts1d);
|
||||
fputs($this->_filehandle, $pps_ts2d);
|
||||
fputs($this->_filehandle, $pps_ts2d);
|
||||
fputs($this->_filehandle, $pps_sb);
|
||||
fputs($this->_filehandle, $pps_size);
|
||||
fputs($this->_filehandle, $unknown1);
|
||||
}
|
||||
|
||||
/*
|
||||
* Pad the end of the file
|
||||
*/
|
||||
function _write_padding() {
|
||||
$biffsize = $this->_biffsize;
|
||||
|
||||
if ($biffsize < 4096) {
|
||||
$min_size = 4096;
|
||||
} else {
|
||||
$min_size = 512;
|
||||
}
|
||||
|
||||
if ($biffsize % $min_size != 0) {
|
||||
$padding = $min_size - ($biffsize % $min_size);
|
||||
fputs($this->_filehandle, str_repeat("\0", $padding));
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
?>
|
||||
1149
lib/Excel/php_writeexcel/class.writeexcel_workbook.inc.php
Normal file
1149
lib/Excel/php_writeexcel/class.writeexcel_workbook.inc.php
Normal file
File diff suppressed because it is too large
Load Diff
@ -0,0 +1,55 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* Copyleft 2002 Johann Hanne
|
||||
*
|
||||
* This is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2.1 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This software is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this software; if not, write to the
|
||||
* Free Software Foundation, Inc., 59 Temple Place,
|
||||
* Suite 330, Boston, MA 02111-1307 USA
|
||||
*/
|
||||
|
||||
/*
|
||||
* This is the Spreadsheet::WriteExcel Perl package ported to PHP
|
||||
* Spreadsheet::WriteExcel was written by John McNamara, jmcnamara@cpan.org
|
||||
*/
|
||||
|
||||
require_once "class.writeexcel_workbook.inc.php";
|
||||
require_once "class.ole_pps_root.php";
|
||||
require_once "class.ole_pps_file.php";
|
||||
|
||||
class writeexcel_workbookbig extends writeexcel_workbook {
|
||||
|
||||
function writeexcel_workbookbig($filename) {
|
||||
$this->writeexcel_workbook($filename);
|
||||
}
|
||||
|
||||
function _store_OLE_file() {
|
||||
$file=new ole_pps_file(asc2ucs("Book"));
|
||||
$file->append($this->_data);
|
||||
|
||||
for ($c=0;$c<sizeof($this->_worksheets);$c++) {
|
||||
$worksheet=&$this->_worksheets[$c];
|
||||
while ($data=$worksheet->get_data()) {
|
||||
$file->append($data);
|
||||
}
|
||||
$worksheet->cleanup();
|
||||
}
|
||||
|
||||
$ole=new ole_pps_root(false, false, array($file));
|
||||
$ole->save($this->_filename);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
?>
|
||||
2968
lib/Excel/php_writeexcel/class.writeexcel_worksheet.inc.php
Normal file
2968
lib/Excel/php_writeexcel/class.writeexcel_worksheet.inc.php
Normal file
File diff suppressed because it is too large
Load Diff
1084
lib/Excel/reader.php
Normal file
1084
lib/Excel/reader.php
Normal file
File diff suppressed because it is too large
Load Diff
2713
lib/common.lib.php
Normal file
2713
lib/common.lib.php
Normal file
File diff suppressed because it is too large
Load Diff
28
lib/connect.lib.php
Normal file
28
lib/connect.lib.php
Normal file
@ -0,0 +1,28 @@
|
||||
<?php
|
||||
if (!defined('_GNUBOARD_')) exit;
|
||||
|
||||
// 현재 접속자수 출력
|
||||
function connect($skin_dir='basic')
|
||||
{
|
||||
global $config, $g5;
|
||||
|
||||
// 회원, 방문객 카운트
|
||||
$sql = " select sum(IF(mb_id<>'',1,0)) as mb_cnt, count(*) as total_cnt from {$g5['login_table']} where mb_id <> '{$config['cf_admin']}' ";
|
||||
$row = sql_fetch($sql);
|
||||
|
||||
if(G5_IS_MOBILE) {
|
||||
$connect_skin_path = G5_MOBILE_PATH.'/'.G5_SKIN_DIR.'/connect/'.$skin_dir;
|
||||
$connect_skin_url = G5_MOBILE_URL.'/'.G5_SKIN_DIR.'/connect/'.$skin_dir;
|
||||
} else {
|
||||
$connect_skin_path = G5_SKIN_PATH.'/connect/'.$skin_dir;
|
||||
$connect_skin_url = G5_SKIN_URL.'/connect/'.$skin_dir;
|
||||
}
|
||||
|
||||
ob_start();
|
||||
include_once ($connect_skin_path.'/connect.skin.php');
|
||||
$content = ob_get_contents();
|
||||
ob_end_clean();
|
||||
|
||||
return $content;
|
||||
}
|
||||
?>
|
||||
27
lib/editor.lib.php
Normal file
27
lib/editor.lib.php
Normal file
@ -0,0 +1,27 @@
|
||||
<?php
|
||||
if (!defined('_GNUBOARD_')) exit; // 개별 페이지 접근 불가
|
||||
|
||||
/*
|
||||
환경설정에서 에디터 선택이 없는 경우에 사용하는 라이브러리 입니다.
|
||||
에디터 선택시 "선택없음"이 아닌 경우 plugin/editor 하위 디렉토리의 각 에디터이름/editor.lib.php 를 수정하시기 바랍니다.
|
||||
*/
|
||||
|
||||
function editor_html($id, $content)
|
||||
{
|
||||
return "<textarea id=\"$id\" name=\"$id\" style=\"width:100%;\" maxlength=\"65536\">$content</textarea>";
|
||||
}
|
||||
|
||||
|
||||
// textarea 로 값을 넘긴다. javascript 반드시 필요
|
||||
function get_editor_js($id)
|
||||
{
|
||||
return "var {$id}_editor = document.getElementById('{$id}');\n";
|
||||
}
|
||||
|
||||
|
||||
// textarea 의 값이 비어 있는지 검사
|
||||
function chk_editor_js($id)
|
||||
{
|
||||
return "if (!{$id}_editor.value) { alert(\"내용을 입력해 주십시오.\"); {$id}_editor.focus(); return false; }\n";
|
||||
}
|
||||
?>
|
||||
146
lib/icode.sms.lib.php
Normal file
146
lib/icode.sms.lib.php
Normal file
@ -0,0 +1,146 @@
|
||||
<?php
|
||||
if (!defined('_GNUBOARD_')) exit;
|
||||
// 아이코드에서 제공하는 함수
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////////////////
|
||||
// 이 부분은 건드릴 필요가 없습니다.
|
||||
|
||||
function spacing($text,$size) {
|
||||
for ($i=0; $i<$size; $i++) $text.=" ";
|
||||
$text = substr($text,0,$size);
|
||||
return $text;
|
||||
}
|
||||
|
||||
function cut_char($word, $cut) {
|
||||
// $word=trim(stripslashes($word));
|
||||
$word=substr($word,0,$cut); // 필요한 길이만큼 취함.
|
||||
for ($k=$cut-1; $k>1; $k--) {
|
||||
if (ord(substr($word,$k,1))<128) break; // 한글값은 160 이상.
|
||||
}
|
||||
$word=substr($word,0,$cut-($cut-$k+1)%2);
|
||||
return $word;
|
||||
}
|
||||
|
||||
function CheckCommonType($dest, $rsvTime) {
|
||||
//$dest=eregi_replace("[^0-9]","",$dest);
|
||||
$dest=preg_replace("/[^0-9]/i","",$dest);
|
||||
if (strlen($dest)<10 || strlen($dest)>11) return "휴대폰 번호가 틀렸습니다";
|
||||
$CID=substr($dest,0,3);
|
||||
//if ( eregi("[^0-9]",$CID) || ($CID!='010' && $CID!='011' && $CID!='016' && $CID!='017' && $CID!='018' && $CID!='019') ) return "휴대폰 앞자리 번호가 잘못되었습니다";
|
||||
if ( preg_match("/[^0-9]/i",$CID) || ($CID!='010' && $CID!='011' && $CID!='016' && $CID!='017' && $CID!='018' && $CID!='019') ) return "휴대폰 앞자리 번호가 잘못되었습니다";
|
||||
//$rsvTime=eregi_replace("[^0-9]","",$rsvTime);
|
||||
$rsvTime=preg_replace("/[^0-9]/i","",$rsvTime);
|
||||
if ($rsvTime) {
|
||||
if (!checkdate(substr($rsvTime,4,2),substr($rsvTime,6,2),substr($rsvTime,0,4))) return "예약날짜가 잘못되었습니다";
|
||||
if (substr($rsvTime,8,2)>23 || substr($rsvTime,10,2)>59) return "예약시간이 잘못되었습니다";
|
||||
}
|
||||
}
|
||||
|
||||
class SMS {
|
||||
var $ID;
|
||||
var $PWD;
|
||||
var $SMS_Server;
|
||||
var $port;
|
||||
var $SMS_Port;
|
||||
var $Data = array();
|
||||
var $Result = array();
|
||||
|
||||
function SMS_con($sms_server,$sms_id,$sms_pw,$port) {
|
||||
$this->ID=$sms_id; // 계약 후 지정
|
||||
$this->PWD=$sms_pw; // 계약 후 지정
|
||||
$this->SMS_Server=$sms_server;
|
||||
$this->SMS_Port=$port;
|
||||
$this->ID = spacing($this->ID,10);
|
||||
$this->PWD = spacing($this->PWD,10);
|
||||
}
|
||||
|
||||
function Init() {
|
||||
$this->Data = "";
|
||||
$this->Result = "";
|
||||
}
|
||||
|
||||
function Add($dest, $callBack, $Caller, $msg, $rsvTime="") {
|
||||
global $g5;
|
||||
|
||||
// 내용 검사 1
|
||||
$Error = CheckCommonType($dest, $rsvTime);
|
||||
if ($Error) return $Error;
|
||||
// 내용 검사 2
|
||||
//if ( eregi("[^0-9]",$callBack) ) return "회신 전화번호가 잘못되었습니다";
|
||||
if ( preg_match("/[^0-9]/i",$callBack) ) return "회신 전화번호가 잘못되었습니다";
|
||||
|
||||
$msg=cut_char($msg,80); // 80자 제한
|
||||
// 보낼 내용을 배열에 집어넣기
|
||||
$dest = spacing($dest,11);
|
||||
$callBack = spacing($callBack,11);
|
||||
$Caller = spacing($Caller,10);
|
||||
$rsvTime = spacing($rsvTime,12);
|
||||
$msg = spacing($msg,80);
|
||||
|
||||
$this->Data[] = '01144 '.$this->ID.$this->PWD.$dest.$callBack.$Caller.$rsvTime.$msg;
|
||||
return "";
|
||||
}
|
||||
|
||||
function AddURL($dest, $callBack, $URL, $msg, $rsvTime="") {
|
||||
// 내용 검사 1
|
||||
$Error = CheckCommonType($dest, $rsvTime);
|
||||
if ($Error) return $Error;
|
||||
// 내용 검사 2
|
||||
//$URL=str_replace("http://","",$URL);
|
||||
if (strlen($URL)>50) return "URL이 50자가 넘었습니다";
|
||||
switch (substr($dest,0,3)) {
|
||||
case '010': //20바이트
|
||||
$msg=cut_char($msg,20);
|
||||
break;
|
||||
case '011': //80바이트
|
||||
$msg=cut_char($msg,80);
|
||||
break;
|
||||
case '016': // 80바이트
|
||||
$msg=cut_char($msg,80);
|
||||
break;
|
||||
case '017': // URL 포함 80바이트
|
||||
$msg=cut_char($msg,80-strlen($URL));
|
||||
break;
|
||||
case '018': // 20바이트
|
||||
$msg=cut_char($msg,20);
|
||||
break;
|
||||
case '019': // 20바이트
|
||||
$msg=cut_char($msg,20);
|
||||
break;
|
||||
default:
|
||||
return "아직 URL CallBack이 지원되지 않는 번호입니다";
|
||||
break;
|
||||
}
|
||||
// 보낼 내용을 배열에 집어넣기
|
||||
$dest = spacing($dest,11);
|
||||
$URL = spacing($URL,50);
|
||||
$callBack = spacing($callBack,11);
|
||||
$rsvTime = spacing($rsvTime,12);
|
||||
$msg = spacing($msg,80);
|
||||
$this->Data[] = '05173 '.$this->ID.$this->PWD.$dest.$callBack.$URL.$rsvTime.$msg;
|
||||
return "";
|
||||
}
|
||||
|
||||
function Send () {
|
||||
$fp=@fsockopen(trim($this->SMS_Server),trim($this->SMS_Port));
|
||||
if (!$fp) return false;
|
||||
set_time_limit(300);
|
||||
|
||||
## php4.3.10일경우
|
||||
## zend 최신버전으로 업해주세요..
|
||||
## 또는 122번째 줄을 $this->Data as $tmp => $puts 로 변경해 주세요.
|
||||
|
||||
foreach($this->Data as $puts) {
|
||||
$dest = substr($puts,26,11);
|
||||
fputs($fp,$puts);
|
||||
while(!$gets) { $gets=fgets($fp,30); }
|
||||
if (substr($gets,0,19)=="0223 00".$dest) $this->Result[]=$dest.":".substr($gets,19,10);
|
||||
else $this->Result[$dest]=$dest.":Error";
|
||||
$gets="";
|
||||
}
|
||||
fclose($fp);
|
||||
$this->Data="";
|
||||
return true;
|
||||
}
|
||||
}
|
||||
?>
|
||||
78
lib/latest.lib.php
Normal file
78
lib/latest.lib.php
Normal file
@ -0,0 +1,78 @@
|
||||
<?php
|
||||
if (!defined('_GNUBOARD_')) exit;
|
||||
|
||||
// 최신글 추출
|
||||
// $cache_time 캐시 갱신시간
|
||||
function latest($skin_dir='', $bo_table, $rows=10, $subject_len=40, $cache_time=1, $options='')
|
||||
{
|
||||
global $g5;
|
||||
//static $css = array();
|
||||
|
||||
if (!$skin_dir) $skin_dir = 'basic';
|
||||
|
||||
if(G5_IS_MOBILE) {
|
||||
$latest_skin_path = G5_MOBILE_PATH.'/'.G5_SKIN_DIR.'/latest/'.$skin_dir;
|
||||
$latest_skin_url = G5_MOBILE_URL.'/'.G5_SKIN_DIR.'/latest/'.$skin_dir;
|
||||
} else {
|
||||
$latest_skin_path = G5_SKIN_PATH.'/latest/'.$skin_dir;
|
||||
$latest_skin_url = G5_SKIN_URL.'/latest/'.$skin_dir;
|
||||
}
|
||||
|
||||
$cache_fwrite = false;
|
||||
if(G5_USE_CACHE) {
|
||||
$cache_file = G5_DATA_PATH."/cache/latest-{$bo_table}-{$skin_dir}-{$rows}-{$subject_len}.php";
|
||||
|
||||
if(!file_exists($cache_file)) {
|
||||
$cache_fwrite = true;
|
||||
} else {
|
||||
if($cache_time > 0) {
|
||||
$filetime = filemtime($cache_file);
|
||||
if($filetime && $filetime < (G5_SERVER_TIME - 3600 * $cache_time)) {
|
||||
@unlink($cache_file);
|
||||
$cache_fwrite = true;
|
||||
}
|
||||
}
|
||||
|
||||
if(!$cache_fwrite)
|
||||
include($cache_file);
|
||||
}
|
||||
}
|
||||
|
||||
if(!G5_USE_CACHE || $cache_fwrite) {
|
||||
$list = array();
|
||||
|
||||
$sql = " select * from {$g5['board_table']} where bo_table = '{$bo_table}' ";
|
||||
$board = sql_fetch($sql);
|
||||
$bo_subject = get_text($board['bo_subject']);
|
||||
|
||||
$tmp_write_table = $g5['write_prefix'] . $bo_table; // 게시판 테이블 전체이름
|
||||
$sql = " select * from {$tmp_write_table} where wr_is_comment = 0 order by wr_num limit 0, {$rows} ";
|
||||
$result = sql_query($sql);
|
||||
for ($i=0; $row = sql_fetch_array($result); $i++) {
|
||||
$list[$i] = get_list($row, $board, $latest_skin_url, $subject_len);
|
||||
}
|
||||
|
||||
if($cache_fwrite) {
|
||||
$handle = fopen($cache_file, 'w');
|
||||
$cache_content = "<?php\nif (!defined('_GNUBOARD_')) exit;\n\$bo_subject=\"".$bo_subject."\";\n\$list=".var_export($list, true)."?>";
|
||||
fwrite($handle, $cache_content);
|
||||
fclose($handle);
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
// 같은 스킨은 .css 를 한번만 호출한다.
|
||||
if (!in_array($skin_dir, $css) && is_file($latest_skin_path.'/style.css')) {
|
||||
echo '<link rel="stylesheet" href="'.$latest_skin_url.'/style.css">';
|
||||
$css[] = $skin_dir;
|
||||
}
|
||||
*/
|
||||
|
||||
ob_start();
|
||||
include $latest_skin_path.'/latest.skin.php';
|
||||
$content = ob_get_contents();
|
||||
ob_end_clean();
|
||||
|
||||
return $content;
|
||||
}
|
||||
?>
|
||||
409
lib/mailer.lib.php
Normal file
409
lib/mailer.lib.php
Normal file
@ -0,0 +1,409 @@
|
||||
<?php
|
||||
if (!defined('_GNUBOARD_')) exit;
|
||||
|
||||
include_once(G5_PHPMAILER_PATH.'/class.phpmailer.php');
|
||||
|
||||
// 메일 보내기 (파일 여러개 첨부 가능)
|
||||
// type : text=0, html=1, text+html=2
|
||||
function mailer($fname, $fmail, $to, $subject, $content, $type=0, $file="", $cc="", $bcc="")
|
||||
{
|
||||
global $config;
|
||||
global $g5;
|
||||
|
||||
// 메일발송 사용을 하지 않는다면
|
||||
if (!$config['cf_email_use']) return;
|
||||
|
||||
if ($type != 1)
|
||||
$content = nl2br($content);
|
||||
|
||||
$mail = new PHPMailer(); // defaults to using php "mail()"
|
||||
if (defined('G5_SMTP') && G5_SMTP) {
|
||||
$mail->IsSMTP(); // telling the class to use SMTP
|
||||
$mail->Host = G5_SMTP; // SMTP server
|
||||
}
|
||||
$mail->From = $fmail;
|
||||
$mail->FromName = $fname;
|
||||
$mail->Subject = $subject;
|
||||
$mail->AltBody = ""; // optional, comment out and test
|
||||
$mail->MsgHTML($content);
|
||||
$mail->AddAddress($to);
|
||||
if ($cc)
|
||||
$mail->AddCC($cc);
|
||||
if ($bcc)
|
||||
$mail->AddBCC($bcc);
|
||||
//print_r2($file); exit;
|
||||
if ($file != "") {
|
||||
foreach ($file as $f) {
|
||||
$mail->AddAttachment($f['path'], $f['name']);
|
||||
}
|
||||
}
|
||||
return $mail->Send();
|
||||
}
|
||||
|
||||
// 파일을 첨부함
|
||||
function attach_file($filename, $tmp_name)
|
||||
{
|
||||
// 서버에 업로드 되는 파일은 확장자를 주지 않는다. (보안 취약점)
|
||||
$dest_file = G5_DATA_PATH.'/tmp/'.str_replace('/', '_', $tmp_name);
|
||||
move_uploaded_file($tmp_name, $dest_file);
|
||||
/*
|
||||
$fp = fopen($tmp_name, "r");
|
||||
$tmpfile = array(
|
||||
"name" => $filename,
|
||||
"tmp_name" => $tmp_name,
|
||||
"data" => fread($fp, filesize($tmp_name)));
|
||||
fclose($fp);
|
||||
*/
|
||||
$tmpfile = array("name" => $filename, "path" => $dest_file);
|
||||
return $tmpfile;
|
||||
}
|
||||
|
||||
/*
|
||||
// 메일 보내기 (파일 여러개 첨부 가능)
|
||||
// type : text=0, html=1, text+html=2
|
||||
function mailer($fname, $fmail, $to, $subject, $content, $type=0, $file="", $cc="", $bcc="")
|
||||
{
|
||||
global $config;
|
||||
global $g5;
|
||||
|
||||
// 메일발송 사용을 하지 않는다면
|
||||
if (!$config['cf_email_use']) return;
|
||||
|
||||
$boundary = uniqid(time());
|
||||
|
||||
$header = "Message-ID: <".generate_mail_id(preg_replace("/@.+$/i","",$to)).">\r\n".
|
||||
"From:=?utf-8?B?".base64_encode($fname)."?=<$fmail>\r\n";
|
||||
if ($cc) $header .= "Cc: $cc\n";
|
||||
if ($bcc) $header .= "Bcc: $bcc\n";
|
||||
$header .= "MIME-Version: 1.0\n";
|
||||
$header .= "X-Mailer: SIR Mailer 0.94 : {$_SERVER['SERVER_ADDR']} : {$_SERVER['REMOTE_ADDR']} : ".G5_URL." : {$_SERVER['PHP_SELF']} : {$_SERVER['HTTP_REFERER']} \n";
|
||||
$header .= "Date: ".date ("D, j M Y H:i:s T",time())."\r\n".
|
||||
"To: $to\r\n".
|
||||
"Subject: =?utf-8?B?".base64_encode($subject)."?=\r\n";
|
||||
|
||||
if ($file == "") {
|
||||
$header .= "Content-Type: MULTIPART/ALTERNATIVE;\n".
|
||||
" BOUNDARY=\"$boundary\"\n\n";
|
||||
} else {
|
||||
$header .= "Content-Type: MULTIPART/MIXED;\n".
|
||||
" BOUNDARY=\"$boundary\"\n\n";
|
||||
}
|
||||
|
||||
if ($type == 2)
|
||||
$content = nl2br($content);
|
||||
|
||||
$strip_content = stripslashes(trim($content));
|
||||
$encode_content = chunk_split(base64_encode($strip_content));
|
||||
|
||||
$body = "";
|
||||
$body .= "\n--$boundary\n";
|
||||
$body .= "Content-Type: TEXT/PLAIN; charset=utf-8\n";
|
||||
$body .= "Content-Transfer-Encoding: BASE64\n\n";
|
||||
$body .= $encode_content;
|
||||
$body .= "\n--$boundary\n";
|
||||
|
||||
if ($type) {
|
||||
$body .= "Content-Type: TEXT/HTML; charset=utf-8\n";
|
||||
$body .= "Content-Transfer-Encoding: BASE64\n\n";
|
||||
$body .= $encode_content;
|
||||
$body .= "\n--$boundary\n";
|
||||
}
|
||||
|
||||
if ($file != "") {
|
||||
foreach ($file as $f) {
|
||||
$body .= "n--$boundary\n";
|
||||
$body .= "Content-Type: APPLICATION/OCTET-STREAM; name=$fname\n";
|
||||
$body .= "Content-Transfer-Encoding: BASE64\n";
|
||||
$body .= "Content-Disposition: inline; filename=$fname\n";
|
||||
|
||||
$body .= "\n";
|
||||
$body .= chunk_split(base64_encode($f['data']));
|
||||
$body .= "\n";
|
||||
}
|
||||
$body .= "--$boundary--\n";
|
||||
}
|
||||
|
||||
$mails['to'] = $to;
|
||||
$mails['from'] = $fmail;
|
||||
$mails['text'] = $header.$body;
|
||||
|
||||
if (defined(G5_SMTP)) {
|
||||
ini_set('SMTP', G5_SMTP);
|
||||
@mail($to, $subject, $body, $header, "-f $fmail");
|
||||
} else {
|
||||
new maildaemon($mails);
|
||||
}
|
||||
}
|
||||
|
||||
// 파일 첨부시
|
||||
$fp = fopen(__FILE__, "r");
|
||||
$file[] = array(
|
||||
"name"=>basename(__FILE__),
|
||||
"data"=>fread($fp, filesize(__FILE__)));
|
||||
fclose($fp);
|
||||
|
||||
// 메일 유효성 검사
|
||||
// core PHP Programming 책 참고
|
||||
// hanmail.net , hotmail.com , kebi.com 등이 정상적이지 않음으로 사용 불가
|
||||
function verify_email($address, &$error)
|
||||
{
|
||||
global $g5;
|
||||
|
||||
$WAIT_SECOND = 3; // ?초 기다림
|
||||
|
||||
list($user, $domain) = explode("@", $address);
|
||||
|
||||
// 도메인에 메일 교환기가 존재하는지 검사
|
||||
if (checkdnsrr($domain, "MX")) {
|
||||
// 메일 교환기 레코드들을 얻는다
|
||||
if (!getmxrr($domain, $mxhost, $mxweight)) {
|
||||
$error = '메일 교환기를 회수할 수 없음';
|
||||
return false;
|
||||
}
|
||||
} else {
|
||||
// 메일 교환기가 없으면, 도메인 자체가 편지를 받는 것으로 간주
|
||||
$mxhost[] = $domain;
|
||||
$mxweight[] = 1;
|
||||
}
|
||||
|
||||
// 메일 교환기 호스트의 배열을 만든다.
|
||||
for ($i=0; $i<count($mxhost); $i++)
|
||||
$weighted_host[($mxweight[$i])] = $mxhost[$i];
|
||||
ksort($weighted_host);
|
||||
|
||||
// 각 호스트를 검사
|
||||
foreach($weighted_host as $host) {
|
||||
// 호스트의 SMTP 포트에 연결
|
||||
if (!($fp = @fsockopen($host, 25))) continue;
|
||||
|
||||
// 220 메세지들은 건너뜀
|
||||
// 3초가 지나도 응답이 없으면 포기
|
||||
socket_set_blocking($fp, false);
|
||||
$stoptime = G5_SERVER_TIME + $WAIT_SECOND;
|
||||
$gotresponse = false;
|
||||
|
||||
while (true) {
|
||||
// 메일서버로부터 한줄 얻음
|
||||
$line = fgets($fp, 1024);
|
||||
|
||||
if (substr($line, 0, 3) == '220') {
|
||||
// 타이머를 초기화
|
||||
$stoptime = G5_SERVER_TIME + $WAIT_SECOND;
|
||||
$gotresponse = true;
|
||||
} else if ($line == '' && $gotresponse)
|
||||
break;
|
||||
else if (G5_SERVER_TIME > $stoptime)
|
||||
break;
|
||||
}
|
||||
|
||||
// 이 호스트는 응답이 없음. 다음 호스트로 넘어간다
|
||||
if (!$gotresponse) continue;
|
||||
|
||||
socket_set_blocking($fp, true);
|
||||
|
||||
// SMTP 서버와의 대화를 시작
|
||||
fputs($fp, "HELO {$_SERVER['SERVER_NAME']}\r\n");
|
||||
echo "HELO {$_SERVER['SERVER_NAME']}\r\n";
|
||||
fgets($fp, 1024);
|
||||
|
||||
// From을 설정
|
||||
fputs($fp, "MAIL FROM: <info@$domain>\r\n");
|
||||
echo "MAIL FROM: <info@$domain>\r\n";
|
||||
fgets($fp, 1024);
|
||||
|
||||
// 주소를 시도
|
||||
fputs($fp, "RCPT TO: <$address>\r\n");
|
||||
echo "RCPT TO: <$address>\r\n";
|
||||
$line = fgets($fp, 1024);
|
||||
|
||||
// 연결을 닫음
|
||||
fputs($fp, "QUIT\r\n");
|
||||
fclose($fp);
|
||||
|
||||
if (substr($line, 0, 3) != '250') {
|
||||
// SMTP 서버가 이 주소를 인식하지 못하므로 잘못된 주소임
|
||||
$error = $line;
|
||||
return false;
|
||||
} else
|
||||
// 주소를 인식했음
|
||||
return true;
|
||||
|
||||
}
|
||||
|
||||
$error = '메일 교환기에 도달하지 못하였습니다.';
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
# jsboard 의 메일보내기 class를 추가합니다. 130808
|
||||
# http://kldp.net/projects/jsboard/
|
||||
|
||||
# mail 보내기 함수 2001.11.30 김정균
|
||||
# $Id: include/sendmail.php,v 1.4 2009/11/19 05:29:51 oops Exp $
|
||||
|
||||
# 서버상의 smtp daemon 에 의존하지 않고 직접 발송하는 smtp class
|
||||
#
|
||||
# 특정 배열로 class 에 전달을 하여 메일을 발송한다. 배열은 아래을 참조한다.
|
||||
#
|
||||
# debug -> debug 를 할지 안할지를 결정한다.
|
||||
# ofhtml -> 웹상에서 사용할지 쉘상에서 사용할지를 결정한다.
|
||||
# from -> 메일을 발송하는 사람의 메일주소
|
||||
# to -> 메일을 받을 사람의 메일 주소
|
||||
# text -> 헤더 내용을 포함한 메일 본문
|
||||
#
|
||||
class maildaemon {
|
||||
var $failed = 0;
|
||||
|
||||
function __construct($v) {
|
||||
$this->debug = $v['debug'];
|
||||
$this->ofhtml = $v['ofhtml'];
|
||||
if($_SERVER['SERVER_NAME']) $this->helo = $_SERVER['SERVER_NAME'];
|
||||
if(!$this->helo || preg_match("/^[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}$/i",$this->helo))
|
||||
$this->helo = "JSBoardMessage";
|
||||
|
||||
$this->from = $v['from'];
|
||||
$this->to = $v['to'];
|
||||
$this->body = $v['text']."\r\n.";
|
||||
|
||||
//die($v['text']);
|
||||
$this->newline = $this->ofhtml ? "<br>\n" : "\n";
|
||||
|
||||
$this->mx = $this->getMX($this->to);
|
||||
|
||||
if($this->debug) {
|
||||
echo "DEBUG: ".$this->mx." start".$this->newline;
|
||||
echo "################################################################".$this->newline;
|
||||
}
|
||||
$this->sockets("open");
|
||||
$this->send("HELO ".$this->helo);
|
||||
$this->send("MAIL FROM: <".$this->from.">");
|
||||
$this->send("RCPT TO: <".$this->to.">");
|
||||
$this->send("data");
|
||||
$this->send($this->body);
|
||||
$this->send("quit");
|
||||
$this->sockets("close");
|
||||
}
|
||||
|
||||
function getMX($email) {
|
||||
$dev = explode("@",$email);
|
||||
$account = $dev[0];
|
||||
$host = $dev[1];
|
||||
|
||||
if(checkdnsrr($host,"MX") && getmxrr($host,$mx,$weight)) {
|
||||
$idx = 0;
|
||||
for($i=0;$i<sizeof($mx);$i++) {
|
||||
$dest = $dest ? $dest : $weight[$i];
|
||||
if($dest > $weight[$i]) {
|
||||
$dest = $weight[$i];
|
||||
$idx = $i;
|
||||
}
|
||||
}
|
||||
} else return $host;
|
||||
return $mx[$idx];
|
||||
}
|
||||
|
||||
# 디버그 함수
|
||||
# $t -> 1 (debug of socket open,close)
|
||||
# 0 (regular smtp message)
|
||||
# $p -> 1 (print detail debug)
|
||||
#
|
||||
# return 1 -> success
|
||||
# return 0 -> failed
|
||||
#
|
||||
function debug($str,$t=0,$p=0) {
|
||||
if($t) {
|
||||
if(!$str) $this->failed = 1;
|
||||
if($this->sock) $returnmsg = trim(fgets($this->sock,1024));
|
||||
} else {
|
||||
if(!preg_match("/^(220|221|250|251|354)$/",substr(trim($str),0,3)))
|
||||
$this->failed = 1;
|
||||
}
|
||||
|
||||
# DEBUG mode -> 모든 메세지 출력
|
||||
if($p) {
|
||||
if($t) {
|
||||
$str = "Conncet ".$this->mx;
|
||||
$str .= $this->failed ? " Failed" : " Success";
|
||||
$str .= $this->newline."DEBUG: $returnmsg";
|
||||
}
|
||||
echo "DEBUG: $str".$this->newline;
|
||||
}
|
||||
|
||||
# DEBUG 모드가 아닐때, 에러 메세지 출력
|
||||
if(!$p && $this->failed) {
|
||||
if($this->ofhtml) echo "<SCRIPT>\nalert('$str')\n</SCRIPT>\n";
|
||||
else "ERROR: $str\n";
|
||||
}
|
||||
}
|
||||
|
||||
function sockets($option=0) {
|
||||
switch($option) {
|
||||
case "open" :
|
||||
$this->sock = @fsockopen($this->mx,25,$this->errno,$this->errstr,30);
|
||||
$this->debug($this->sock,1,$this->debug);
|
||||
break;
|
||||
default :
|
||||
if($this->sock) fclose($this->sock);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
function send($str,$chk=0) {
|
||||
if(!$this->failed) {
|
||||
if($this->debug) {
|
||||
if(preg_match("/\r\n/",trim($str)))
|
||||
$str_debug = trim(str_replace("\r\n","\r\n ",$str));
|
||||
else $str_debug = $str;
|
||||
}
|
||||
fputs($this->sock,"$str\r\n");
|
||||
$recv = trim(fgets($this->sock,1024));
|
||||
$recvchk = $recv;
|
||||
$this->debug($recv,0,$this->debug);
|
||||
|
||||
if(preg_match("/Mail From:/i",$str) && preg_match("/exist|require|error/i",$recvchk) && !$chk) {
|
||||
$this->failed = 0;
|
||||
$this->send("MAIL FROM: <".$this->to.">",1);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
function generate_mail_id($uid) {
|
||||
$id = date("YmdHis",time());
|
||||
mt_srand((float) microtime() * 1000000);
|
||||
$randval = mt_rand();
|
||||
$id .= $randval."@$uid";
|
||||
return $id;
|
||||
}
|
||||
|
||||
|
||||
function mail_header($to,$from,$title,$mta=0) {
|
||||
global $langs,$boundary;
|
||||
|
||||
# mail header 를 작성
|
||||
$boundary = get_boundary_msg();
|
||||
$header = "Message-ID: <".generate_mail_id(preg_replace("/@.+$/i","",$to)).">\r\n".
|
||||
"From:=?utf-8?B?".base64_encode('보내는사람')."?=<$from>\r\n".
|
||||
"MIME-Version: 1.0\r\n";
|
||||
|
||||
if(!$mta) $header .= "Date: ".date ("D, j M Y H:i:s T",time())."\r\n".
|
||||
"To: $to\r\n".
|
||||
"Subject: $title\r\n";
|
||||
|
||||
$header .= "Content-Type: multipart/alternative;\r\n".
|
||||
" boundary=\"$boundary\"\r\n\r\n";
|
||||
|
||||
return $header;
|
||||
}
|
||||
|
||||
|
||||
function get_boundary_msg() {
|
||||
$uniqchr = uniqid("");
|
||||
$one = strtoupper($uniqchr[0]);
|
||||
$two = strtoupper(substr($uniqchr,0,8));
|
||||
$three = strtoupper(substr(strrev($uniqchr),0,8));
|
||||
return "----=_NextPart_000_000${one}_${two}.${three}";
|
||||
}
|
||||
*/
|
||||
?>
|
||||
145
lib/mobile.lib.php
Normal file
145
lib/mobile.lib.php
Normal file
@ -0,0 +1,145 @@
|
||||
<?php
|
||||
if (!defined('_GNUBOARD_')) exit;
|
||||
|
||||
// 원본 이미지를 넘기면 비율에 따라 썸네일 이미지를 생성함
|
||||
function mobile_create_thumb($srcImg, $width, $thumb)
|
||||
{
|
||||
$size = @getimagesize($srcImg);
|
||||
if ($size[2] == 1)
|
||||
$source = @imagecreatefromgif($srcImg);
|
||||
else if ($size[2] == 2)
|
||||
$source = @imagecreatefromjpeg($srcImg);
|
||||
else if ($size[2] == 3)
|
||||
$source = @imagecreatefrompng($srcImg);
|
||||
else
|
||||
return "";
|
||||
|
||||
if (!$source)
|
||||
return "";
|
||||
|
||||
if ($size[0] < $width) {
|
||||
$width = $size[0];
|
||||
$height = $size[1];
|
||||
}
|
||||
else {
|
||||
$rate = $width / $size[0];
|
||||
$height = (int)($size[1] * $rate);
|
||||
}
|
||||
|
||||
$target = @imagecreatetruecolor($width, $height);
|
||||
$bgcolor = @imagecolorallocate($target, 255, 255, 255); // 썸네일 배경
|
||||
imagefilledrectangle($target, 0, 0, $width, $height, $bgcolor);
|
||||
imagecopyresampled($source, $source, 0, 0, 0, 0, $width, $height, $size[0], $size[1]);
|
||||
imagecopy($target, $source, 0, 0, 0, 0, $size[0], $size[1]);
|
||||
|
||||
imagejpeg($target, $thumb, 100);
|
||||
chmod($thumb, G5_FILE_PERMISSION); // 추후 삭제를 위하여 파일모드 변경
|
||||
|
||||
return $thumb;
|
||||
}
|
||||
|
||||
|
||||
function mobile_thumb($matches)
|
||||
{
|
||||
global $is_admin;
|
||||
global $g5, $bo_table, $wr_id;
|
||||
|
||||
$width = 300; // (소스이미지 width pixel)
|
||||
|
||||
//if ($is_admin) print_r2($matches);
|
||||
|
||||
if ($is_admin) {
|
||||
foreach ($matches as $img) {
|
||||
echo "<p>";
|
||||
|
||||
preg_match("/src=[\"\']?([^\"\'\s>]+)/i", $img, $m);
|
||||
$src = trim($m[1]);
|
||||
//echo $src;
|
||||
|
||||
// 상대경로(..)로 시작되면 sir.co.kr 도메인으로 여긴다.
|
||||
$src = preg_replace("/^\.\.\//", "http://m.sir.co.kr/", $src);
|
||||
$absolute = preg_replace("/^http\:\/\/(www\.)?sir\.co\.kr\/(.*)$/", "/home/sir/$2", $src);
|
||||
|
||||
$thumb_dir = G5_DATA_PATH.'/thumb/'.$bo_table;
|
||||
if (!is_dir($thumb_dir)) {
|
||||
@mkdir($thumb_dir, G5_DIR_PERMISSION);
|
||||
@chmod($thumb_dir, G5_DIR_PERMISSION);
|
||||
}
|
||||
|
||||
$result = true;
|
||||
|
||||
if (preg_match("/\.(jpe?g|png)$/i", $src)) {
|
||||
// 유일한 파일명을 만든다.
|
||||
$src_md5 = md5($src.$width);
|
||||
$thumb = "$thumb_dir/{$wr_id}-{$src_md5}";
|
||||
|
||||
if (!file_exists($thumb)) {
|
||||
$result = mobile_create_thumb($src, $width, $thumb);
|
||||
}
|
||||
}
|
||||
else {
|
||||
$thumb = $src;
|
||||
}
|
||||
|
||||
if ($result) {
|
||||
$size = @getimagesize($absolute);
|
||||
if ($size[2] == IMAGETYPE_GIF)
|
||||
$w = ($size[0] < $width) ? $size[0] : $width;
|
||||
else
|
||||
$w = ($size[0] < $width) ? $size[0] : "100%";
|
||||
return "<img src='$thumb' width='$w' />";
|
||||
}
|
||||
}
|
||||
} else {
|
||||
|
||||
foreach ($matches as $img) {
|
||||
preg_match("/src=[\"\']?([^\"\'\s>]+)/i", $img, $m);
|
||||
|
||||
$result = true;
|
||||
|
||||
$src = trim($m[1]);
|
||||
//if ($is_admin) echo $src."<br>";
|
||||
if (preg_match("/\.(jpe?g|png)$/i", $src)) {
|
||||
// 상대경로(..)로 시작되면 도메인으로 여긴다.
|
||||
$src = preg_replace("/^\.\.\//", 'http://'.$_SERVER['SERVER_NAME'].'/', $src);
|
||||
|
||||
// 유일한 파일명을 만든다.
|
||||
$src_md5 = md5($src.$width);
|
||||
$thumb = G5_DATA_PATH.'/thumb/'.$bo_table.'-'.$wr_id.'-'.$src_md5;
|
||||
|
||||
if (!file_exists($thumb)) {
|
||||
$result = mobile_create_thumb($src, $width, $thumb);
|
||||
}
|
||||
}
|
||||
else {
|
||||
$thumb = $src;
|
||||
}
|
||||
|
||||
if ($result) {
|
||||
//if ($is_admin) { $begin_time = get_microtime(); }
|
||||
//echo $thumb;
|
||||
$size = @getimagesize($thumb);
|
||||
//if ($is_admin) print_r2($size);
|
||||
if ($size[2] == IMAGETYPE_GIF)
|
||||
$w = ($size[0] < $width) ? $size[0] : $width;
|
||||
else
|
||||
$w = ($size[0] < $width) ? $size[0] : "100%";
|
||||
//if ($is_admin) { echo "<p>time : "; echo get_microtime() - $begin_time; }
|
||||
return "<img src='$thumb' width='$w' />";
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
function mobile_embed($matches)
|
||||
{
|
||||
foreach ($matches as $embed) {
|
||||
//$embed = preg_replace("#height\=\d+#i", "", $embed);
|
||||
//$embed = preg_replace("#width\=\d+#i", "", $embed);
|
||||
|
||||
return $embed;
|
||||
}
|
||||
}
|
||||
?>
|
||||
50
lib/outlogin.lib.php
Normal file
50
lib/outlogin.lib.php
Normal file
@ -0,0 +1,50 @@
|
||||
<?php
|
||||
if (!defined('_GNUBOARD_')) exit;
|
||||
|
||||
// 외부로그인
|
||||
function outlogin($skin_dir='basic')
|
||||
{
|
||||
global $config, $member, $g5, $urlencode, $is_admin, $is_member;
|
||||
|
||||
if (array_key_exists('mb_nick', $member)) {
|
||||
$nick = cut_str($member['mb_nick'], $config['cf_cut_name']);
|
||||
}
|
||||
if (array_key_exists('mb_point', $member)) {
|
||||
$point = number_format($member['mb_point']);
|
||||
}
|
||||
|
||||
if (G5_IS_MOBILE) {
|
||||
$outlogin_skin_path = G5_MOBILE_PATH.'/'.G5_SKIN_DIR.'/outlogin/'.$skin_dir;
|
||||
$outlogin_skin_url = G5_MOBILE_URL.'/'.G5_SKIN_DIR.'/outlogin/'.$skin_dir;
|
||||
} else {
|
||||
$outlogin_skin_path = G5_SKIN_PATH.'/outlogin/'.$skin_dir;
|
||||
$outlogin_skin_url = G5_SKIN_URL.'/outlogin/'.$skin_dir;
|
||||
}
|
||||
|
||||
// 읽지 않은 쪽지가 있다면
|
||||
if ($is_member) {
|
||||
$sql = " select count(*) as cnt from {$g5['memo_table']} where me_recv_mb_id = '{$member['mb_id']}' and me_read_datetime = '0000-00-00 00:00:00' ";
|
||||
$row = sql_fetch($sql);
|
||||
$memo_not_read = $row['cnt'];
|
||||
|
||||
$is_auth = false;
|
||||
$sql = " select count(*) as cnt from {$g5['auth_table']} where mb_id = '{$member['mb_id']}' ";
|
||||
$row = sql_fetch($sql);
|
||||
if ($row['cnt'])
|
||||
$is_auth = true;
|
||||
}
|
||||
|
||||
$outlogin_url = login_url($urlencode);
|
||||
$outlogin_action_url = G5_HTTPS_BBS_URL.'/login_check.php';
|
||||
|
||||
ob_start();
|
||||
if ($is_member)
|
||||
include_once ($outlogin_skin_path.'/outlogin.skin.2.php');
|
||||
else // 로그인 전이라면
|
||||
include_once ($outlogin_skin_path.'/outlogin.skin.1.php');
|
||||
$content = ob_get_contents();
|
||||
ob_end_clean();
|
||||
|
||||
return $content;
|
||||
}
|
||||
?>
|
||||
34
lib/poll.lib.php
Normal file
34
lib/poll.lib.php
Normal file
@ -0,0 +1,34 @@
|
||||
<?php
|
||||
if (!defined('_GNUBOARD_')) exit;
|
||||
|
||||
// 설문조사
|
||||
function poll($skin_dir='basic', $po_id=false)
|
||||
{
|
||||
global $config, $member, $g5, $is_admin;
|
||||
|
||||
// 투표번호가 넘어오지 않았다면 가장 큰(최근에 등록한) 투표번호를 얻는다
|
||||
if (!$po_id) {
|
||||
$row = sql_fetch(" select MAX(po_id) as max_po_id from {$g5['poll_table']} ");
|
||||
$po_id = $row['max_po_id'];
|
||||
}
|
||||
|
||||
if(!$po_id)
|
||||
return;
|
||||
|
||||
$po = sql_fetch(" select * from {$g5['poll_table']} where po_id = '$po_id' ");
|
||||
|
||||
ob_start();
|
||||
if (G5_IS_MOBILE) {
|
||||
$poll_skin_path = G5_MOBILE_PATH.'/'.G5_SKIN_DIR.'/poll/'.$skin_dir;
|
||||
$poll_skin_url = G5_MOBILE_URL.'/'.G5_SKIN_DIR.'/poll/'.$skin_dir;
|
||||
} else {
|
||||
$poll_skin_path = G5_SKIN_PATH.'/poll/'.$skin_dir;
|
||||
$poll_skin_url = G5_SKIN_URL.'/poll/'.$skin_dir;
|
||||
}
|
||||
include_once ($poll_skin_path.'/poll.skin.php');
|
||||
$content = ob_get_contents();
|
||||
ob_end_clean();
|
||||
|
||||
return $content;
|
||||
}
|
||||
?>
|
||||
37
lib/popular.lib.php
Normal file
37
lib/popular.lib.php
Normal file
@ -0,0 +1,37 @@
|
||||
<?php
|
||||
if (!defined('_GNUBOARD_')) exit;
|
||||
|
||||
// 인기검색어 출력
|
||||
// $skin_dir : 스킨 디렉토리
|
||||
// $pop_cnt : 검색어 몇개
|
||||
// $date_cnt : 몇일 동안
|
||||
function popular($skin_dir='basic', $pop_cnt=7, $date_cnt=3)
|
||||
{
|
||||
global $config, $g5;
|
||||
|
||||
if (!$skin_dir) $skin_dir = 'basic';
|
||||
|
||||
$date_gap = date("Y-m-d", G5_SERVER_TIME - ($date_cnt * 86400));
|
||||
$sql = " select pp_word, count(*) as cnt from {$g5['popular_table']} where pp_date between '$date_gap' and '".G5_TIME_YMD."' group by pp_word order by cnt desc, pp_word limit 0, $pop_cnt ";
|
||||
$result = sql_query($sql);
|
||||
for ($i=0; $row=sql_fetch_array($result); $i++) {
|
||||
$list[$i] = $row;
|
||||
// 스크립트등의 실행금지
|
||||
$list[$i]['pp_word'] = get_text($list[$i]['pp_word']);
|
||||
}
|
||||
|
||||
ob_start();
|
||||
if(G5_IS_MOBILE) {
|
||||
$popular_skin_path = G5_MOBILE_PATH.'/'.G5_SKIN_DIR.'/popular/'.$skin_dir;
|
||||
$popular_skin_url = G5_MOBILE_URL.'/'.G5_SKIN_DIR.'/popular/'.$skin_dir;
|
||||
} else {
|
||||
$popular_skin_path = G5_SKIN_PATH.'/popular/'.$skin_dir;
|
||||
$popular_skin_url = G5_SKIN_URL.'/popular/'.$skin_dir;
|
||||
}
|
||||
include_once ($popular_skin_path.'/popular.skin.php');
|
||||
$content = ob_get_contents();
|
||||
ob_end_clean();
|
||||
|
||||
return $content;
|
||||
}
|
||||
?>
|
||||
181
lib/register.lib.php
Normal file
181
lib/register.lib.php
Normal file
@ -0,0 +1,181 @@
|
||||
<?php
|
||||
if (!defined('_GNUBOARD_')) exit;
|
||||
|
||||
function empty_mb_id($reg_mb_id)
|
||||
{
|
||||
if (trim($reg_mb_id)=='')
|
||||
return "회원아이디를 입력해 주십시오.";
|
||||
else
|
||||
return "";
|
||||
}
|
||||
|
||||
function valid_mb_id($reg_mb_id)
|
||||
{
|
||||
if (preg_match("/[^0-9a-z_]+/i", $reg_mb_id))
|
||||
return "회원아이디는 영문자, 숫자, _ 만 입력하세요.";
|
||||
else
|
||||
return "";
|
||||
}
|
||||
|
||||
function count_mb_id($reg_mb_id)
|
||||
{
|
||||
if (strlen($reg_mb_id) < 3)
|
||||
return "회원아이디는 최소 3글자 이상 입력하세요.";
|
||||
else
|
||||
return "";
|
||||
}
|
||||
|
||||
function exist_mb_id($reg_mb_id)
|
||||
{
|
||||
global $g5;
|
||||
|
||||
$reg_mb_id = trim($reg_mb_id);
|
||||
if ($reg_mb_id == "") return "";
|
||||
|
||||
$sql = " select count(*) as cnt from `{$g5['member_table']}` where mb_id = '$reg_mb_id' ";
|
||||
$row = sql_fetch($sql);
|
||||
if ($row['cnt'])
|
||||
return "이미 사용중인 회원아이디 입니다.";
|
||||
else
|
||||
return "";
|
||||
}
|
||||
|
||||
function reserve_mb_id($reg_mb_id)
|
||||
{
|
||||
global $config;
|
||||
if (preg_match("/[\,]?{$reg_mb_id}/i", $config['cf_prohibit_id']))
|
||||
return "이미 예약된 단어로 사용할 수 없는 회원아이디 입니다.";
|
||||
else
|
||||
return "";
|
||||
}
|
||||
|
||||
function empty_mb_nick($reg_mb_nick)
|
||||
{
|
||||
if (!trim($reg_mb_nick))
|
||||
return "닉네임을 입력해 주십시오.";
|
||||
else
|
||||
return "";
|
||||
}
|
||||
|
||||
function valid_mb_nick($reg_mb_nick)
|
||||
{
|
||||
if (!check_string($reg_mb_nick, G5_HANGUL + G5_ALPHABETIC + G5_NUMERIC))
|
||||
return "닉네임은 공백없이 한글, 영문, 숫자만 입력 가능합니다.";
|
||||
else
|
||||
return "";
|
||||
}
|
||||
|
||||
function count_mb_nick($reg_mb_nick)
|
||||
{
|
||||
if (strlen($reg_mb_nick) < 4)
|
||||
return "닉네임은 한글 2글자, 영문 4글자 이상 입력 가능합니다.";
|
||||
else
|
||||
return "";
|
||||
}
|
||||
|
||||
function exist_mb_nick($reg_mb_nick, $reg_mb_id)
|
||||
{
|
||||
global $g5;
|
||||
$row = sql_fetch(" select count(*) as cnt from {$g5['member_table']} where mb_nick = '$reg_mb_nick' and mb_id <> '$reg_mb_id' ");
|
||||
if ($row['cnt'])
|
||||
return "이미 존재하는 닉네임입니다.";
|
||||
else
|
||||
return "";
|
||||
}
|
||||
|
||||
function reserve_mb_nick($reg_mb_nick)
|
||||
{
|
||||
global $config;
|
||||
if (preg_match("/[\,]?{$reg_mb_nick}/i", $config['cf_prohibit_id']))
|
||||
return "이미 예약된 단어로 사용할 수 없는 닉네임 입니다.";
|
||||
else
|
||||
return "";
|
||||
}
|
||||
|
||||
function empty_mb_email($reg_mb_email)
|
||||
{
|
||||
if (!trim($reg_mb_email))
|
||||
return "E-mail 주소를 입력해 주십시오.";
|
||||
else
|
||||
return "";
|
||||
}
|
||||
|
||||
function valid_mb_email($reg_mb_email)
|
||||
{
|
||||
if (!preg_match("/([0-9a-zA-Z_-]+)@([0-9a-zA-Z_-]+)\.([0-9a-zA-Z_-]+)/", $reg_mb_email))
|
||||
return "E-mail 주소가 형식에 맞지 않습니다.";
|
||||
else
|
||||
return "";
|
||||
}
|
||||
|
||||
// 금지 메일 도메인 검사
|
||||
function prohibit_mb_email($reg_mb_email)
|
||||
{
|
||||
global $config;
|
||||
list($id, $domain) = explode("@", $reg_mb_email);
|
||||
$email_domains = explode("\n", trim($config['cf_prohibit_email']));
|
||||
for ($i=0; $i<count($email_domains); $i++) {
|
||||
if (strtolower($domain) == strtolower($email_domains[$i]))
|
||||
return "$domain 메일은 사용할 수 없습니다.";
|
||||
}
|
||||
return "";
|
||||
}
|
||||
|
||||
function exist_mb_email($reg_mb_email, $reg_mb_id)
|
||||
{
|
||||
global $g5;
|
||||
$row = sql_fetch(" select count(*) as cnt from `{$g5['member_table']}` where mb_email = '$reg_mb_email' and mb_id <> '$reg_mb_id' ");
|
||||
if ($row['cnt'])
|
||||
return "이미 사용중인 E-mail 주소입니다.";
|
||||
else
|
||||
return "";
|
||||
}
|
||||
|
||||
function empty_mb_name($reg_mb_name)
|
||||
{
|
||||
if (!trim($reg_mb_name))
|
||||
return "이름을 입력해 주십시오.";
|
||||
else
|
||||
return "";
|
||||
}
|
||||
|
||||
function valid_mb_name($mb_name)
|
||||
{
|
||||
if (!check_string($mb_name, G5_HANGUL))
|
||||
return "이름은 공백없이 한글만 입력 가능합니다.";
|
||||
else
|
||||
return "";
|
||||
}
|
||||
|
||||
function valid_mb_hp($reg_mb_hp)
|
||||
{
|
||||
$reg_mb_hp = preg_replace("/[^0-9]/", "", $reg_mb_hp);
|
||||
if(!$reg_mb_hp)
|
||||
return "휴대폰번호를 입력해 주십시오.";
|
||||
else {
|
||||
if(preg_match("/^01[0-9]{8,9}$/", $reg_mb_hp))
|
||||
return "";
|
||||
else
|
||||
return "휴대폰번호를 올바르게 입력해 주십시오.";
|
||||
}
|
||||
}
|
||||
|
||||
function exist_mb_hp($reg_mb_hp, $reg_mb_id)
|
||||
{
|
||||
global $g5;
|
||||
|
||||
if (!trim($reg_mb_hp)) return "";
|
||||
|
||||
$reg_mb_hp = hyphen_hp_number($reg_mb_hp);
|
||||
|
||||
$sql = "select count(*) as cnt from {$g5['member_table']} where mb_hp = '$reg_mb_hp' and mb_id <> '$reg_mb_id' ";
|
||||
$row = sql_fetch($sql);
|
||||
|
||||
if($row['cnt'])
|
||||
return " 이미 사용 중인 휴대폰번호입니다. ".$reg_mb_hp;
|
||||
else
|
||||
return "";
|
||||
}
|
||||
|
||||
return;
|
||||
?>
|
||||
562
lib/thumbnail.lib.php
Normal file
562
lib/thumbnail.lib.php
Normal file
@ -0,0 +1,562 @@
|
||||
<?php
|
||||
if (!defined('_GNUBOARD_')) exit;
|
||||
|
||||
@ini_set('memory_limit', '512M');
|
||||
|
||||
// 게시글리스트 썸네일 생성
|
||||
function get_list_thumbnail($bo_table, $wr_id, $thumb_width, $thumb_height, $is_create=false, $is_crop=true, $crop_mode='center', $is_sharpen=true, $um_value='80/0.5/3')
|
||||
{
|
||||
global $g5, $config;
|
||||
$filename = $alt = "";
|
||||
$edt = false;
|
||||
|
||||
$sql = " select bf_file, bf_content from {$g5['board_file_table']}
|
||||
where bo_table = '$bo_table' and wr_id = '$wr_id' and bf_type between '1' and '3' order by bf_no limit 0, 1 ";
|
||||
$row = sql_fetch($sql);
|
||||
|
||||
if($row['bf_file']) {
|
||||
$filename = $row['bf_file'];
|
||||
$filepath = G5_DATA_PATH.'/file/'.$bo_table;
|
||||
$alt = get_text($row['bf_content']);
|
||||
} else {
|
||||
$write_table = $g5['write_prefix'].$bo_table;
|
||||
$sql = " select wr_content from $write_table where wr_id = '$wr_id' ";
|
||||
$write = sql_fetch($sql);
|
||||
$matches = get_editor_image($write['wr_content'], false);
|
||||
$edt = true;
|
||||
|
||||
for($i=0; $i<count($matches[1]); $i++)
|
||||
{
|
||||
// 이미지 path 구함
|
||||
$p = parse_url($matches[1][$i]);
|
||||
if(strpos($p['path'], '/'.G5_DATA_DIR.'/') != 0)
|
||||
$data_path = preg_replace('/^\/.*\/'.G5_DATA_DIR.'/', '/'.G5_DATA_DIR, $p['path']);
|
||||
else
|
||||
$data_path = $p['path'];
|
||||
|
||||
$srcfile = G5_PATH.$data_path;
|
||||
|
||||
if(preg_match("/\.({$config['cf_image_extension']})$/i", $srcfile) && is_file($srcfile)) {
|
||||
$size = @getimagesize($srcfile);
|
||||
if(empty($size))
|
||||
continue;
|
||||
|
||||
$filename = basename($srcfile);
|
||||
$filepath = dirname($srcfile);
|
||||
|
||||
preg_match("/alt=[\"\']?([^\"\']*)[\"\']?/", $matches[0][$i], $malt);
|
||||
$alt = get_text($malt[1]);
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if(!$filename)
|
||||
return false;
|
||||
|
||||
$tname = thumbnail($filename, $filepath, $filepath, $thumb_width, $thumb_height, $is_create, $is_crop, $crop_mode, $is_sharpen, $um_value);
|
||||
|
||||
if($tname) {
|
||||
if($edt) {
|
||||
$src = G5_URL.str_replace($filename, $tname, $data_path);
|
||||
} else {
|
||||
$src = G5_DATA_URL.'/file/'.$bo_table.'/'.$tname;
|
||||
}
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
|
||||
$thumb = array("src"=>$src, "alt"=>$alt);
|
||||
|
||||
return $thumb;
|
||||
}
|
||||
|
||||
// 게시글보기 썸네일 생성
|
||||
function get_view_thumbnail($contents, $thumb_width=0)
|
||||
{
|
||||
global $board, $config;
|
||||
|
||||
if (!$thumb_width)
|
||||
$thumb_width = $board['bo_image_width'];
|
||||
|
||||
// $contents 중 img 태그 추출
|
||||
$matches = get_editor_image($contents, true);
|
||||
|
||||
if(empty($matches))
|
||||
return $contents;
|
||||
|
||||
for($i=0; $i<count($matches[1]); $i++) {
|
||||
|
||||
$img = $matches[1][$i];
|
||||
preg_match("/src=[\'\"]?([^>\'\"]+[^>\'\"]+)/i", $img, $m);
|
||||
$src = $m[1];
|
||||
preg_match("/style=[\"\']?([^\"\'>]+)/i", $img, $m);
|
||||
$style = $m[1];
|
||||
preg_match("/width:\s*(\d+)px/", $style, $m);
|
||||
$width = $m[1];
|
||||
preg_match("/height:\s*(\d+)px/", $style, $m);
|
||||
$height = $m[1];
|
||||
preg_match("/alt=[\"\']?([^\"\']*)[\"\']?/", $img, $m);
|
||||
$alt = get_text($m[1]);
|
||||
|
||||
// 이미지 path 구함
|
||||
$p = parse_url($src);
|
||||
if(strpos($p['path'], '/'.G5_DATA_DIR.'/') != 0)
|
||||
$data_path = preg_replace('/^\/.*\/'.G5_DATA_DIR.'/', '/'.G5_DATA_DIR, $p['path']);
|
||||
else
|
||||
$data_path = $p['path'];
|
||||
|
||||
$srcfile = G5_PATH.$data_path;
|
||||
|
||||
if(is_file($srcfile)) {
|
||||
$size = @getimagesize($srcfile);
|
||||
if(empty($size))
|
||||
continue;
|
||||
|
||||
// jpg 이면 exif 체크
|
||||
if($size[2] == 2 && function_exists('exif_read_data')) {
|
||||
$degree = 0;
|
||||
$exif = @exif_read_data($srcfile);
|
||||
if(!empty($exif['Orientation'])) {
|
||||
switch($exif['Orientation']) {
|
||||
case 8:
|
||||
$degree = 90;
|
||||
break;
|
||||
case 3:
|
||||
$degree = 180;
|
||||
break;
|
||||
case 6:
|
||||
$degree = -90;
|
||||
break;
|
||||
}
|
||||
|
||||
// 세로사진의 경우 가로, 세로 값 바꿈
|
||||
if($degree == 90 || $degree == -90) {
|
||||
$tmp = $size;
|
||||
$size[0] = $tmp[1];
|
||||
$size[1] = $tmp[0];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 원본 width가 thumb_width보다 작다면
|
||||
if($size[0] <= $thumb_width)
|
||||
continue;
|
||||
|
||||
// Animated GIF 체크
|
||||
$is_animated = false;
|
||||
if($size[2] == 1) {
|
||||
$is_animated = is_animated_gif($srcfile);
|
||||
}
|
||||
|
||||
// 썸네일 높이
|
||||
$thumb_height = round(($thumb_width * $size[1]) / $size[0]);
|
||||
$filename = basename($srcfile);
|
||||
$filepath = dirname($srcfile);
|
||||
|
||||
// 썸네일 생성
|
||||
if(!$is_animated)
|
||||
$thumb_file = thumbnail($filename, $filepath, $filepath, $thumb_width, $thumb_height, false);
|
||||
else
|
||||
$thumb_file = $filename;
|
||||
|
||||
if(!$thumb_file)
|
||||
continue;
|
||||
|
||||
if ($width) {
|
||||
$thumb_tag = '<img src="'.G5_URL.str_replace($filename, $thumb_file, $data_path).'" alt="'.$alt.'" width="'.$width.'" height="'.$height.'"/>';
|
||||
} else {
|
||||
$thumb_tag = '<img src="'.G5_URL.str_replace($filename, $thumb_file, $data_path).'" alt="'.$alt.'"/>';
|
||||
}
|
||||
|
||||
// $img_tag에 editor 경로가 있으면 원본보기 링크 추가
|
||||
$img_tag = $matches[0][$i];
|
||||
if(strpos($img_tag, G5_DATA_DIR.'/'.G5_EDITOR_DIR) && preg_match("/\.({$config['cf_image_extension']})$/i", $filename)) {
|
||||
$imgurl = str_replace(G5_URL, "", $src);
|
||||
$thumb_tag = '<a href="'.G5_BBS_URL.'/view_image.php?fn='.urlencode($imgurl).'" target="_blank" class="view_image">'.$thumb_tag.'</a>';
|
||||
}
|
||||
|
||||
$contents = str_replace($img_tag, $thumb_tag, $contents);
|
||||
}
|
||||
}
|
||||
|
||||
return $contents;
|
||||
}
|
||||
|
||||
function thumbnail($filename, $source_path, $target_path, $thumb_width, $thumb_height, $is_create, $is_crop=false, $crop_mode='center', $is_sharpen=true, $um_value='80/0.5/3')
|
||||
{
|
||||
global $g5;
|
||||
|
||||
if(!$thumb_width && !$thumb_height)
|
||||
return;
|
||||
|
||||
$thumb_filename = preg_replace("/\.[^\.]+$/i", "", $filename); // 확장자제거
|
||||
$thumb_file = "$target_path/thumb-{$thumb_filename}_{$thumb_width}x{$thumb_height}.jpg";
|
||||
$source_file = "$source_path/$filename";
|
||||
|
||||
if(!is_file($source_file)) // 원본 파일이 없다면
|
||||
return;
|
||||
|
||||
$size = @getimagesize($source_file);
|
||||
if($size[2] < 1 || $size[2] > 3) // gif, jpg, png 에 대해서만 적용
|
||||
return;
|
||||
|
||||
if (!is_dir($target_path)) {
|
||||
@mkdir($target_path, G5_DIR_PERMISSION);
|
||||
@chmod($target_path, G5_DIR_PERMISSION);
|
||||
}
|
||||
|
||||
// 디렉토리가 존재하지 않거나 쓰기 권한이 없으면 썸네일 생성하지 않음
|
||||
if(!(is_dir($target_path) && is_writable($target_path)))
|
||||
return '';
|
||||
|
||||
// Animated GIF는 썸네일 생성하지 않음
|
||||
if($size[2] == 1) {
|
||||
if(is_animated_gif($source_file))
|
||||
return basename($source_file);
|
||||
}
|
||||
|
||||
$thumb_time = @filemtime($thumb_file);
|
||||
$source_time = @filemtime($source_file);
|
||||
|
||||
if (file_exists($thumb_file)) {
|
||||
if ($is_create == false && $source_time < $thumb_time) {
|
||||
return basename($thumb_file);
|
||||
}
|
||||
}
|
||||
|
||||
// 원본파일의 GD 이미지 생성
|
||||
$src = null;
|
||||
$degree = 0;
|
||||
|
||||
if ($size[2] == 1) {
|
||||
$src = imagecreatefromgif($source_file);
|
||||
} else if ($size[2] == 2) {
|
||||
$src = imagecreatefromjpeg($source_file);
|
||||
|
||||
if(function_exists('exif_read_data')) {
|
||||
// exif 정보를 기준으로 회전각도 구함
|
||||
$exif = @exif_read_data($source_file);
|
||||
if(!empty($exif['Orientation'])) {
|
||||
switch($exif['Orientation']) {
|
||||
case 8:
|
||||
$degree = 90;
|
||||
break;
|
||||
case 3:
|
||||
$degree = 180;
|
||||
break;
|
||||
case 6:
|
||||
$degree = -90;
|
||||
break;
|
||||
}
|
||||
|
||||
// 회전각도 있으면 이미지 회전
|
||||
if($degree) {
|
||||
$src = imagerotate($src, $degree, 0);
|
||||
|
||||
// 세로사진의 경우 가로, 세로 값 바꿈
|
||||
if($degree == 90 || $degree == -90) {
|
||||
$tmp = $size;
|
||||
$size[0] = $tmp[1];
|
||||
$size[1] = $tmp[0];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
} else if ($size[2] == 3) {
|
||||
$src = imagecreatefrompng($source_file);
|
||||
} else {
|
||||
return;
|
||||
}
|
||||
|
||||
if(!$src)
|
||||
return;
|
||||
|
||||
$is_large = true;
|
||||
// width, height 설정
|
||||
if($thumb_width) {
|
||||
if(!$thumb_height) {
|
||||
$thumb_height = round(($thumb_width * $size[1]) / $size[0]);
|
||||
} else {
|
||||
if($size[0] < $thumb_width || $size[1] < $thumb_height)
|
||||
$is_large = false;
|
||||
}
|
||||
} else {
|
||||
if($thumb_height) {
|
||||
$thumb_width = round(($thumb_height * $size[0]) / $size[1]);
|
||||
}
|
||||
}
|
||||
|
||||
$dst_x = 0;
|
||||
$dst_y = 0;
|
||||
$src_x = 0;
|
||||
$src_y = 0;
|
||||
$dst_w = $thumb_width;
|
||||
$dst_h = $thumb_height;
|
||||
$src_w = $size[0];
|
||||
$src_h = $size[1];
|
||||
|
||||
$ratio = $dst_h / $dst_w;
|
||||
|
||||
if($is_large) {
|
||||
// 크롭처리
|
||||
if($is_crop) {
|
||||
switch($crop_mode)
|
||||
{
|
||||
case 'center':
|
||||
if($size[1] / $size[0] >= $ratio) {
|
||||
$src_h = round($src_w * $ratio);
|
||||
$src_y = round(($size[1] - $src_h) / 2);
|
||||
} else {
|
||||
$src_w = round($size[1] / $ratio);
|
||||
$src_x = round(($size[0] - $src_w) / 2);
|
||||
}
|
||||
break;
|
||||
default:
|
||||
if($size[1] / $size[0] >= $ratio) {
|
||||
$src_h = round($src_w * $ratio);
|
||||
} else {
|
||||
$src_w = round($size[1] / $ratio);
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
$dst = imagecreatetruecolor($dst_w, $dst_h);
|
||||
} else {
|
||||
$dst = imagecreatetruecolor($dst_w, $dst_h);
|
||||
|
||||
if($src_w < $dst_w) {
|
||||
if($src_h >= $dst_h) {
|
||||
$dst_x = round(($dst_w - $src_w) / 2);
|
||||
$src_h = $dst_h;
|
||||
} else {
|
||||
$dst_x = round(($dst_w - $src_w) / 2);
|
||||
$dst_y = round(($dst_h - $src_h) / 2);
|
||||
$dst_w = $src_w;
|
||||
$dst_h = $src_h;
|
||||
}
|
||||
} else {
|
||||
if($src_h < $dst_h) {
|
||||
$dst_y = round(($dst_h - $src_h) / 2);
|
||||
$dst_h = $src_h;
|
||||
$src_w = $dst_w;
|
||||
}
|
||||
}
|
||||
|
||||
$bgcolor = imagecolorallocate($dst, 255, 255, 255); // 배경색
|
||||
imagefill($dst, 0, 0, $bgcolor);
|
||||
}
|
||||
|
||||
imagecopyresampled($dst, $src, $dst_x, $dst_y, $src_x, $src_y, $dst_w, $dst_h, $src_w, $src_h);
|
||||
|
||||
// sharpen 적용
|
||||
if($is_sharpen && $is_large) {
|
||||
$val = explode('/', $um_value);
|
||||
UnsharpMask($dst, $val[0], $val[1], $val[2]);
|
||||
}
|
||||
|
||||
if(!defined('G5_THUMB_JPG_QUALITY'))
|
||||
$jpg_quality = 90;
|
||||
else
|
||||
$jpg_quality = G5_THUMB_JPG_QUALITY;
|
||||
|
||||
imagejpeg($dst, $thumb_file, $jpg_quality);
|
||||
chmod($thumb_file, G5_FILE_PERMISSION); // 추후 삭제를 위하여 파일모드 변경
|
||||
|
||||
imagedestroy($src);
|
||||
imagedestroy($dst);
|
||||
|
||||
return basename($thumb_file);
|
||||
}
|
||||
|
||||
function UnsharpMask($img, $amount, $radius, $threshold) {
|
||||
|
||||
/*
|
||||
출처 : http://vikjavev.no/computing/ump.php
|
||||
New:
|
||||
- In version 2.1 (February 26 2007) Tom Bishop has done some important speed enhancements.
|
||||
- From version 2 (July 17 2006) the script uses the imageconvolution function in PHP
|
||||
version >= 5.1, which improves the performance considerably.
|
||||
|
||||
|
||||
Unsharp masking is a traditional darkroom technique that has proven very suitable for
|
||||
digital imaging. The principle of unsharp masking is to create a blurred copy of the image
|
||||
and compare it to the underlying original. The difference in colour values
|
||||
between the two images is greatest for the pixels near sharp edges. When this
|
||||
difference is subtracted from the original image, the edges will be
|
||||
accentuated.
|
||||
|
||||
The Amount parameter simply says how much of the effect you want. 100 is 'normal'.
|
||||
Radius is the radius of the blurring circle of the mask. 'Threshold' is the least
|
||||
difference in colour values that is allowed between the original and the mask. In practice
|
||||
this means that low-contrast areas of the picture are left unrendered whereas edges
|
||||
are treated normally. This is good for pictures of e.g. skin or blue skies.
|
||||
|
||||
Any suggenstions for improvement of the algorithm, expecially regarding the speed
|
||||
and the roundoff errors in the Gaussian blur process, are welcome.
|
||||
|
||||
*/
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
////
|
||||
//// Unsharp Mask for PHP - version 2.1.1
|
||||
////
|
||||
//// Unsharp mask algorithm by Torstein Hønsi 2003-07.
|
||||
//// thoensi_at_netcom_dot_no.
|
||||
//// Please leave this notice.
|
||||
////
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
|
||||
|
||||
// $img is an image that is already created within php using
|
||||
// imgcreatetruecolor. No url! $img must be a truecolor image.
|
||||
|
||||
// Attempt to calibrate the parameters to Photoshop:
|
||||
if ($amount > 500) $amount = 500;
|
||||
$amount = $amount * 0.016;
|
||||
if ($radius > 50) $radius = 50;
|
||||
$radius = $radius * 2;
|
||||
if ($threshold > 255) $threshold = 255;
|
||||
|
||||
$radius = abs(round($radius)); // Only integers make sense.
|
||||
if ($radius == 0) {
|
||||
return $img; imagedestroy($img); break; }
|
||||
$w = imagesx($img); $h = imagesy($img);
|
||||
$imgCanvas = imagecreatetruecolor($w, $h);
|
||||
$imgBlur = imagecreatetruecolor($w, $h);
|
||||
|
||||
|
||||
// Gaussian blur matrix:
|
||||
//
|
||||
// 1 2 1
|
||||
// 2 4 2
|
||||
// 1 2 1
|
||||
//
|
||||
//////////////////////////////////////////////////
|
||||
|
||||
|
||||
if (function_exists('imageconvolution')) { // PHP >= 5.1
|
||||
$matrix = array(
|
||||
array( 1, 2, 1 ),
|
||||
array( 2, 4, 2 ),
|
||||
array( 1, 2, 1 )
|
||||
);
|
||||
$divisor = array_sum(array_map('array_sum', $matrix));
|
||||
$offset = 0;
|
||||
|
||||
imagecopy ($imgBlur, $img, 0, 0, 0, 0, $w, $h);
|
||||
imageconvolution($imgBlur, $matrix, $divisor, $offset);
|
||||
}
|
||||
else {
|
||||
|
||||
// Move copies of the image around one pixel at the time and merge them with weight
|
||||
// according to the matrix. The same matrix is simply repeated for higher radii.
|
||||
for ($i = 0; $i < $radius; $i++) {
|
||||
imagecopy ($imgBlur, $img, 0, 0, 1, 0, $w - 1, $h); // left
|
||||
imagecopymerge ($imgBlur, $img, 1, 0, 0, 0, $w, $h, 50); // right
|
||||
imagecopymerge ($imgBlur, $img, 0, 0, 0, 0, $w, $h, 50); // center
|
||||
imagecopy ($imgCanvas, $imgBlur, 0, 0, 0, 0, $w, $h);
|
||||
|
||||
imagecopymerge ($imgBlur, $imgCanvas, 0, 0, 0, 1, $w, $h - 1, 33.33333 ); // up
|
||||
imagecopymerge ($imgBlur, $imgCanvas, 0, 1, 0, 0, $w, $h, 25); // down
|
||||
}
|
||||
}
|
||||
|
||||
if($threshold>0){
|
||||
// Calculate the difference between the blurred pixels and the original
|
||||
// and set the pixels
|
||||
for ($x = 0; $x < $w-1; $x++) { // each row
|
||||
for ($y = 0; $y < $h; $y++) { // each pixel
|
||||
|
||||
$rgbOrig = ImageColorAt($img, $x, $y);
|
||||
$rOrig = (($rgbOrig >> 16) & 0xFF);
|
||||
$gOrig = (($rgbOrig >> 8) & 0xFF);
|
||||
$bOrig = ($rgbOrig & 0xFF);
|
||||
|
||||
$rgbBlur = ImageColorAt($imgBlur, $x, $y);
|
||||
|
||||
$rBlur = (($rgbBlur >> 16) & 0xFF);
|
||||
$gBlur = (($rgbBlur >> 8) & 0xFF);
|
||||
$bBlur = ($rgbBlur & 0xFF);
|
||||
|
||||
// When the masked pixels differ less from the original
|
||||
// than the threshold specifies, they are set to their original value.
|
||||
$rNew = (abs($rOrig - $rBlur) >= $threshold)
|
||||
? max(0, min(255, ($amount * ($rOrig - $rBlur)) + $rOrig))
|
||||
: $rOrig;
|
||||
$gNew = (abs($gOrig - $gBlur) >= $threshold)
|
||||
? max(0, min(255, ($amount * ($gOrig - $gBlur)) + $gOrig))
|
||||
: $gOrig;
|
||||
$bNew = (abs($bOrig - $bBlur) >= $threshold)
|
||||
? max(0, min(255, ($amount * ($bOrig - $bBlur)) + $bOrig))
|
||||
: $bOrig;
|
||||
|
||||
|
||||
|
||||
if (($rOrig != $rNew) || ($gOrig != $gNew) || ($bOrig != $bNew)) {
|
||||
$pixCol = ImageColorAllocate($img, $rNew, $gNew, $bNew);
|
||||
ImageSetPixel($img, $x, $y, $pixCol);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else{
|
||||
for ($x = 0; $x < $w; $x++) { // each row
|
||||
for ($y = 0; $y < $h; $y++) { // each pixel
|
||||
$rgbOrig = ImageColorAt($img, $x, $y);
|
||||
$rOrig = (($rgbOrig >> 16) & 0xFF);
|
||||
$gOrig = (($rgbOrig >> 8) & 0xFF);
|
||||
$bOrig = ($rgbOrig & 0xFF);
|
||||
|
||||
$rgbBlur = ImageColorAt($imgBlur, $x, $y);
|
||||
|
||||
$rBlur = (($rgbBlur >> 16) & 0xFF);
|
||||
$gBlur = (($rgbBlur >> 8) & 0xFF);
|
||||
$bBlur = ($rgbBlur & 0xFF);
|
||||
|
||||
$rNew = ($amount * ($rOrig - $rBlur)) + $rOrig;
|
||||
if($rNew>255){$rNew=255;}
|
||||
elseif($rNew<0){$rNew=0;}
|
||||
$gNew = ($amount * ($gOrig - $gBlur)) + $gOrig;
|
||||
if($gNew>255){$gNew=255;}
|
||||
elseif($gNew<0){$gNew=0;}
|
||||
$bNew = ($amount * ($bOrig - $bBlur)) + $bOrig;
|
||||
if($bNew>255){$bNew=255;}
|
||||
elseif($bNew<0){$bNew=0;}
|
||||
$rgbNew = ($rNew << 16) + ($gNew <<8) + $bNew;
|
||||
ImageSetPixel($img, $x, $y, $rgbNew);
|
||||
}
|
||||
}
|
||||
}
|
||||
imagedestroy($imgCanvas);
|
||||
imagedestroy($imgBlur);
|
||||
|
||||
return true;
|
||||
|
||||
}
|
||||
|
||||
function is_animated_gif($filename) {
|
||||
if(!($fh = @fopen($filename, 'rb')))
|
||||
return false;
|
||||
$count = 0;
|
||||
// 출처 : http://www.php.net/manual/en/function.imagecreatefromgif.php#104473
|
||||
// an animated gif contains multiple "frames", with each frame having a
|
||||
// header made up of:
|
||||
// * a static 4-byte sequence (\x00\x21\xF9\x04)
|
||||
// * 4 variable bytes
|
||||
// * a static 2-byte sequence (\x00\x2C) (some variants may use \x00\x21 ?)
|
||||
|
||||
// We read through the file til we reach the end of the file, or we've found
|
||||
// at least 2 frame headers
|
||||
while(!feof($fh) && $count < 2) {
|
||||
$chunk = fread($fh, 1024 * 100); //read 100kb at a time
|
||||
$count += preg_match_all('#\x00\x21\xF9\x04.{4}\x00(\x2C|\x21)#s', $chunk, $matches);
|
||||
}
|
||||
|
||||
fclose($fh);
|
||||
return $count > 1;
|
||||
}
|
||||
?>
|
||||
86
lib/visit.lib.php
Normal file
86
lib/visit.lib.php
Normal file
@ -0,0 +1,86 @@
|
||||
<?php
|
||||
if (!defined('_GNUBOARD_')) exit;
|
||||
|
||||
// 방문자수 출력
|
||||
function visit($skin_dir='basic')
|
||||
{
|
||||
global $config, $g5;
|
||||
|
||||
// visit 배열변수에
|
||||
// $visit[1] = 오늘
|
||||
// $visit[2] = 어제
|
||||
// $visit[3] = 최대
|
||||
// $visit[4] = 전체
|
||||
// 숫자가 들어감
|
||||
preg_match("/오늘:(.*),어제:(.*),최대:(.*),전체:(.*)/", $config['cf_visit'], $visit);
|
||||
settype($visit[1], "integer");
|
||||
settype($visit[2], "integer");
|
||||
settype($visit[3], "integer");
|
||||
settype($visit[4], "integer");
|
||||
|
||||
ob_start();
|
||||
if(G5_IS_MOBILE) {
|
||||
$visit_skin_path = G5_MOBILE_PATH.'/'.G5_SKIN_DIR.'/visit/'.$skin_dir;
|
||||
$visit_skin_url = G5_MOBILE_URL.'/'.G5_SKIN_DIR.'/visit/'.$skin_dir;
|
||||
} else {
|
||||
$visit_skin_path = G5_SKIN_PATH.'/visit/'.$skin_dir;
|
||||
$visit_skin_url = G5_SKIN_URL.'/visit/'.$skin_dir;
|
||||
}
|
||||
include_once ($visit_skin_path.'/visit.skin.php');
|
||||
$content = ob_get_contents();
|
||||
ob_end_clean();
|
||||
|
||||
return $content;
|
||||
}
|
||||
|
||||
// get_browser() 함수는 이미 있음
|
||||
function get_brow($agent)
|
||||
{
|
||||
$agent = strtolower($agent);
|
||||
|
||||
//echo $agent; echo "<br/>";
|
||||
|
||||
if (preg_match("/msie ([1-9][0-9]\.[0-9]+)/", $agent, $m)) { $s = 'MSIE '.$m[1]; }
|
||||
else if(preg_match("/firefox/", $agent)) { $s = "FireFox"; }
|
||||
else if(preg_match("/chrome/", $agent)) { $s = "Chrome"; }
|
||||
else if(preg_match("/x11/", $agent)) { $s = "Netscape"; }
|
||||
else if(preg_match("/opera/", $agent)) { $s = "Opera"; }
|
||||
else if(preg_match("/gec/", $agent)) { $s = "Gecko"; }
|
||||
else if(preg_match("/bot|slurp/", $agent)) { $s = "Robot"; }
|
||||
else if(preg_match("/internet explorer/", $agent)) { $s = "IE"; }
|
||||
else if(preg_match("/mozilla/", $agent)) { $s = "Mozilla"; }
|
||||
else { $s = "기타"; }
|
||||
|
||||
return $s;
|
||||
}
|
||||
|
||||
function get_os($agent)
|
||||
{
|
||||
$agent = strtolower($agent);
|
||||
|
||||
//echo $agent; echo "<br/>";
|
||||
|
||||
if (preg_match("/windows 98/", $agent)) { $s = "98"; }
|
||||
else if(preg_match("/windows 95/", $agent)) { $s = "95"; }
|
||||
else if(preg_match("/windows nt 4\.[0-9]*/", $agent)) { $s = "NT"; }
|
||||
else if(preg_match("/windows nt 5\.0/", $agent)) { $s = "2000"; }
|
||||
else if(preg_match("/windows nt 5\.1/", $agent)) { $s = "XP"; }
|
||||
else if(preg_match("/windows nt 5\.2/", $agent)) { $s = "2003"; }
|
||||
else if(preg_match("/windows nt 6\.0/", $agent)) { $s = "Vista"; }
|
||||
else if(preg_match("/windows nt 6\.1/", $agent)) { $s = "Windows7"; }
|
||||
else if(preg_match("/windows nt 6\.2/", $agent)) { $s = "Windows8"; }
|
||||
else if(preg_match("/windows 9x/", $agent)) { $s = "ME"; }
|
||||
else if(preg_match("/windows ce/", $agent)) { $s = "CE"; }
|
||||
else if(preg_match("/mac/", $agent)) { $s = "MAC"; }
|
||||
else if(preg_match("/linux/", $agent)) { $s = "Linux"; }
|
||||
else if(preg_match("/sunos/", $agent)) { $s = "sunOS"; }
|
||||
else if(preg_match("/irix/", $agent)) { $s = "IRIX"; }
|
||||
else if(preg_match("/phone/", $agent)) { $s = "Phone"; }
|
||||
else if(preg_match("/bot|slurp/", $agent)) { $s = "Robot"; }
|
||||
else if(preg_match("/internet explorer/", $agent)) { $s = "IE"; }
|
||||
else if(preg_match("/mozilla/", $agent)) { $s = "Mozilla"; }
|
||||
else { $s = "기타"; }
|
||||
|
||||
return $s;
|
||||
}
|
||||
?>
|
||||
Reference in New Issue
Block a user