Commit ff12f5ed authored by platyhouse's avatar platyhouse

.

parent 09c3224c

Too many changes to show.

To preserve performance only 1000 of 1000+ files are displayed.

# CLAUDE.md
This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
## 개요
ptyLibrary_PHP는 PlatyHouse 프레임워크용 PHP 유틸리티 라이브러리입니다. 데이터베이스 작업, HTML 생성, CLI 유틸리티, 파일 관리, 웹 크롤링, 미디어 처리를 위한 재사용 가능한 컴포넌트를 제공합니다. 모든 코드는 `platyFramework` 네임스페이스를 사용합니다.
## 프로젝트 구조
```
ptyLibrary_PHP/
├── ptyLibrary.php # 메인 진입점 - 모든 코어 모듈 include
├── common/ # 핵심 유틸리티 함수 (ptyArray, ptyString, 디버그, HTTP)
├── database/ # MySQL 데이터베이스 추상화 레이어 (ptyMysql 클래스)
├── dbTableList/ # 데이터 목록 렌더링 및 페이지네이션
├── forms/ # 파일 업로드 관리 (ptyFormFileManager)
├── cli/ # CLI 유틸리티 및 ANSI 컬러 (ptyCliColor, ptyCliLog)
├── crawling/ # 웹 스크래핑 유틸리티 (ptyCrawling)
├── media/ # 미디어 처리 (ptyYoutubePlay)
├── postBlog/ # XML-RPC 블로그 포스팅 (네이버, TypePad)
└── external/ # 외부 라이브러리 (PhpSpreadsheet, simpleHtmlDom, html2text)
```
## 주요 컴포넌트
### 데이터베이스 (ptyMysql)
Fluent 인터페이스 방식의 쿼리 빌더:
- `addSelect()`, `addFrom()`, `addJoin()`, `addWhere()`, `addWhereOr()`
- `addSet()`, `addOrderBy()`, `setLimit()`, `addGroupBy()`
- `insert()`, `update()`, `delete()`, `sql_query()`, `sql_fetch()`, `sql_list()`
- 날짜 필터: `getWhere이번달()`, `getWhere지난달()`, `getWhere1개월전부터()`
- Prepared statement 지원 (`binds` 파라미터), 쿼리 캐싱, 슬로우 쿼리 감지
헬퍼 함수: `mre()` (이스케이프), `mrea()` (따옴표 포함 이스케이프), `mreb()` (백틱 이스케이프)
### 공통 유틸리티 (common/common.php)
- **유효성 검사**: `ptyCheckEmpty()`, `ptyCheckNull()`, `ptyCheckEmptys()`
- **배열 처리**: `ptyTransformArray()`, `ptyGetMagicArray()`, `ptyArrayValueToKey()`
- **문자열 처리**: `ptyCutStr()`, `ptyCutLength()`, `ptyTrim()`, `ptyGetMiddleStr()`
- **HTTP**: `ptyGetCurrentUrl()`, `ptyGetUrlContent()`, `ptyCurlGet()`, `ptyCurlPost()`
- **디버그**: `ptyDebug()`, `ptyDebugXmp()`, `ptyDebugBackTrace()`, `ptyShowCallstack()`
- **JSON 응답**: `ptyJsonReturn()`, `ptyJsonReturnTrue()`, `ptyJsonReturnFalse()`
- **환경 감지**: `ptyIsCli()`, `ptyIsPC()`, `ptyIsCurl()`
- **크론 락**: `ptyCheckCronRunningDuplicate()`, `ptyEndCronRunningDuplicate()`
### CLI 로깅 (ptyCliLog)
컬러 터미널 출력, 로그 타입: 'info', 'success', 'warning', 'error', 'url', 'verbose', 'data', 'response'
## 사용 예시
```php
<?php
namespace platyFramework;
require_once("ptyLibrary.php");
// 데이터베이스 사용
$db = new ptyMysql($host, $user, $pass, $dbname);
$db->addSelect("*")->addFrom("users")->addWhere("active", 1);
$users = $db->sql_list();
```
## 코드 컨벤션
- **네임스페이스**: 모든 코드는 `platyFramework` 네임스페이스 사용
- **메소드 체이닝**: setter 메소드는 `$this` 반환
- **전역 상태**: 공유 설정에 `$GLOBALS['platyFramework']` 사용
- **Composer 미사용**: 직접 require를 통한 파일 기반 오토로딩
<?php
namespace platyFramework;
/**
* ptyCliColor - CLI 색상 상수 정의 클래스
*
* 터미널에서 사용할 수 있는 다양한 색상 상수를 제공합니다.
*/
class ptyCliColor
{
// 기본 색상 (밝은 색상)
const LIGHT_WHITE = "\033[1;37m"; // 밝은 흰색
const RED = "\033[1;31m"; // 밝은 빨간색
const GREEN = "\033[1;32m"; // 밝은 녹색
const YELLOW = "\033[1;33m"; // 밝은 노란색
const BLUE = "\033[1;34m"; // 밝은 파란색
const MAGENTA = "\033[1;35m"; // 밝은 보라색
const CYAN = "\033[1;36m"; // 밝은 청록색
const BLACK = "\033[1;30m"; // 밝은 검정색 (회색)
// 일반 색상 (어두운 색상)
const DARK_WHITE = "\033[0;37m"; // 어두운 흰색
const DARK_RED = "\033[0;31m"; // 어두운 빨간색
const DARK_GREEN = "\033[0;32m"; // 어두운 녹색
const DARK_YELLOW = "\033[0;33m"; // 어두운 노란색
const DARK_BLUE = "\033[0;34m"; // 어두운 파란색
const DARK_MAGENTA = "\033[0;35m"; // 어두운 보라색
const DARK_CYAN = "\033[0;36m"; // 어두운 청록색
const DARK_BLACK = "\033[0;30m"; // 어두운 검정색
// 배경 색상
const BG_WHITE = "\033[47m"; // 흰색 배경
const BG_RED = "\033[41m"; // 빨간색 배경
const BG_GREEN = "\033[42m"; // 녹색 배경
const BG_YELLOW = "\033[43m"; // 노란색 배경
const BG_BLUE = "\033[44m"; // 파란색 배경
const BG_MAGENTA = "\033[45m"; // 보라색 배경
const BG_CYAN = "\033[46m"; // 청록색 배경
const BG_BLACK = "\033[40m"; // 검정색 배경
// 특수 스타일
const BOLD = "\033[1m"; // 굵게
const DIM = "\033[2m"; // 흐리게
const ITALIC = "\033[3m"; // 기울임
const UNDERLINE = "\033[4m"; // 밑줄
const BLINK = "\033[5m"; // 깜빡임
const REVERSE = "\033[7m"; // 반전
const HIDDEN = "\033[8m"; // 숨김
// 리셋
const RESET = "\033[0m"; // 모든 스타일 리셋
// 자주 사용하는 조합 색상
const SUCCESS = self::GREEN; // 성공 (녹색)
const ERROR = self::RED; // 에러 (빨간색)
const WARNING = self::YELLOW; // 경고 (노란색)
const INFO = self::CYAN; // 정보 (청록색)
const DEBUG = self::MAGENTA; // 디버그 (보라색)
/**
* 텍스트에 색상 적용
*
* @param string $text 텍스트
* @param string $color 색상 상수
* @return string 색상이 적용된 텍스트
*/
public static function colorize($text, $color)
{
return $color . $text . self::RESET;
}
/**
* 사용 가능한 모든 색상 출력
*/
public static function showAllColors()
{
$colors = [
'WHITE' => self::WHITE,
'RED' => self::RED,
'GREEN' => self::GREEN,
'YELLOW' => self::YELLOW,
'BLUE' => self::BLUE,
'MAGENTA' => self::MAGENTA,
'CYAN' => self::CYAN,
'BLACK' => self::BLACK,
];
echo "\n=== 밝은 색상 ===\n";
foreach ($colors as $name => $code) {
echo self::colorize("$name: This is a sample text", $code) . "\n";
}
echo "\n=== 어두운 색상 ===\n";
$darkColors = [
'DARK_WHITE' => self::DARK_WHITE,
'DARK_RED' => self::DARK_RED,
'DARK_GREEN' => self::DARK_GREEN,
'DARK_YELLOW' => self::DARK_YELLOW,
'DARK_BLUE' => self::DARK_BLUE,
'DARK_MAGENTA' => self::DARK_MAGENTA,
'DARK_CYAN' => self::DARK_CYAN,
'DARK_BLACK' => self::DARK_BLACK,
];
foreach ($darkColors as $name => $code) {
echo self::colorize("$name: This is a sample text", $code) . "\n";
}
echo "\n=== 자주 사용하는 조합 ===\n";
echo self::colorize("SUCCESS: 작업이 성공적으로 완료되었습니다.", self::SUCCESS) . "\n";
echo self::colorize("ERROR: 오류가 발생했습니다.", self::ERROR) . "\n";
echo self::colorize("WARNING: 경고 메시지입니다.", self::WARNING) . "\n";
echo self::colorize("INFO: 정보 메시지입니다.", self::INFO) . "\n";
echo self::colorize("DEBUG: 디버그 메시지입니다.", self::DEBUG) . "\n";
}
}
\ No newline at end of file
<?php
namespace platyFramework;
require_once __DIR__ . '/ptyCliColor.php';
class ptyCliLog
{
// 하위 호환성을 위한 색상 상수 (ptyCliColor 사용 권장)
const COLOR_WHITE = ptyCliColor::LIGHT_WHITE;
const COLOR_RED = ptyCliColor::RED;
const COLOR_GREEN = ptyCliColor::GREEN;
const COLOR_YELLOW = ptyCliColor::YELLOW;
const COLOR_BLUE = ptyCliColor::BLUE;
const COLOR_MAGENTA = ptyCliColor::MAGENTA;
const COLOR_CYAN = ptyCliColor::CYAN;
const COLOR_RESET = ptyCliColor::RESET;
private $prefix;
private $color;
private $debug;
private $colors;
public function __construct($prefix = "APP", $color = ptyCliColor::LIGHT_WHITE, $debug = true)
{
$this->prefix = $prefix;
$this->color = $color;
$this->debug = $debug;
$this->colors = [
'info' => ptyCliColor::CYAN,
'success' => ptyCliColor::GREEN,
'warning' => ptyCliColor::YELLOW,
'error' => ptyCliColor::RED,
'url' => ptyCliColor::MAGENTA,
'verbose' => ptyCliColor::DARK_WHITE,
'data' => ptyCliColor::LIGHT_WHITE,
'response' => ptyCliColor::CYAN,
'reset' => ptyCliColor::RESET
];
date_default_timezone_set('Asia/Seoul');
if ($prefix != "URL" && $prefix != "ELASTIC") {
$this->url = new ptyCliLog("URL", ptyCliColor::DARK_MAGENTA, $debug);
$this->elastic = new ptyCliLog("URL", ptyCliColor::DARK_WHITE, $debug);
}
}
public function log($message, $type = 'info', $data = null)
{
if (!$this->debug) return;
if ($message == "") {
echo "\n";
return;
}
// 타임스탬프 생성 (밀리초 포함)
$now = microtime(true);
// $milliseconds = sprintf("%03d", ($now - floor($now)) * 1000);
// $timestamp = date('Y-m-d H:i:s', (int)$now) . '.' . $milliseconds;
$timestamp = date('H:i:s', (int)$now);
$typeColor = $this->colors[$type] ?? $this->colors['info'];
$reset = $this->colors['reset'];
// verbose 타입일 때 호출한 함수명 추가
$functionName = "";
// if ($type === 'verbose') {
if (true) {
$backtrace = debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS, 3);
if (isset($backtrace[2])) {
$caller = $backtrace[2];
if (isset($caller['class'])) {
$functionName = $caller['class'] . $caller['type'] . $caller['function'];
} else if (isset($caller['function'])) {
$functionName = $caller['function'];
}
if ($functionName) {
// closure인 경우 파일명:라인번호 형식으로 변환
if (preg_match('/\{closure:(.+):(\d+)\}/', $functionName, $matches)) {
$filePath = $matches[1];
$lineNumber = $matches[2];
$fileName = basename($filePath);
$functionName = $fileName . ':' . $lineNumber;
}
else {
$functionName.= "()";
}
$functionName = ptyCliColor::DARK_WHITE . $functionName . " ". $reset;
}
}
}
// 타임스탬프 + prefix에 지정된 색상 사용, type은 타입 색상 사용
echo ptyCliColor::DARK_WHITE . $timestamp . " " . $reset;
echo sprintf("%-45s", $functionName);
echo $this->color . sprintf("[%-8s] ", strtoupper($this->prefix)) . $reset;
echo $typeColor . $message . $reset . "\n";
if ($data !== null) {
echo $this->colors['data'] . json_encode($data, JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE) . $reset . "\n";
}
}
public function verbose($message, $data = null)
{
$this->log($message, 'verbose', $data);
}
public function info($message, $data = null)
{
$this->log($message, 'info', $data);
}
public function success($message, $data = null)
{
$this->log($message, 'success', $data);
}
public function warning($message, $data = null)
{
$this->log($message, 'warning', $data);
}
public function error($message, $data = null)
{
$this->log($message, 'error', $data);
}
public function url($message, $data = null)
{
$this->log($message, 'url', $data);
}
public function mysql($message, $data = null)
{
$this->log($message, 'mysql', $data);
}
public function elastic($message, $data = null)
{
$this->log($message, 'elastic', $data);
}
public function data($message, $data = null)
{
$this->log($message, 'data', $data);
}
public function response($message, $data = null)
{
$this->log($message, 'response', $data);
}
public function setDebug($debug)
{
$this->debug = $debug;
$this->log("디버그 모드 " . ($debug ? "활성화" : "비활성화"), 'info');
}
public function isDebugEnabled()
{
return $this->debug;
}
public function separator($length = 50)
{
$this->log("\n".str_repeat("=", $length), 'info');
}
}
/**
* ptyCliLog 헬퍼 함수
*
* @param string $prefix 로그 prefix (기본값: "APP")
* @param string $color 로그 색상 (기본값: ptyCliLog::COLOR_WHITE)
* @param bool $debug 디버그 모드 (기본값: true)
* @return ptyCliLog
*/
function ptyCliLog($prefix = "APP", $color = ptyCliLog::COLOR_WHITE, $debug = true)
{
return new ptyCliLog($prefix, $color, $debug);
}
\ No newline at end of file
<?php
namespace platyFramework;
class ptyAes256
{
function encrypt($plain_text, $key)
{
return base64_encode(openssl_encrypt($plain_text, "aes-256-cbc", $key, TRUE, str_repeat(chr(0), 16)));
}
function decrypt($base64_text, $key)
{
return openssl_decrypt(base64_decode($base64_text), "aes-256-cbc", $key, TRUE, str_repeat(chr(0), 16));
}
/*
function encrypt_noopenssl($key, $value)
{
$padSize = 16 - (strlen($value) % 16);
$value = $value . str_repeat(chr($padSize), $padSize);
$output = mcrypt_encrypt(MCRYPT_RIJNDAEL_128, $key, $value, MCRYPT_MODE_CBC, str_repeat(chr(0), 16));
return base64_encode($output);
}
function decrypt_noopenssl($key, $value)
{
$value = base64_decode($value);
$output = mcrypt_decrypt(MCRYPT_RIJNDAEL_128, $key, $value, MCRYPT_MODE_CBC, str_repeat(chr(0), 16));
$valueLen = strlen($output);
if ($valueLen % 16 > 0)
$output = "";
$padSize = ord($output{$valueLen - 1});
if (($padSize < 1) or ($padSize > 16))
$output = ""; // Check padding.
for ($i = 0; $i < $padSize; $i++) {
if (ord($output{$valueLen - $i - 1}) != $padSize)
$output = "";
}
$output = substr($output, 0, $valueLen - $padSize);
return $output;
}
*/
}
?>
\ No newline at end of file
<?php
namespace platyFramework;
class ptyAppErrorModel
{
var $tableName = "t_platy_error_logs";
public function __construct()
{
$this->_checkTableExistsAndCreate();
}
function _checkTableExistsAndCreate()
{
GLOBAL $platyFramework;
$this->db = $platyFramework->db;
if (!$this->db->sql_result("SHOW TABLES LIKE '$this->tableName'")) {
$this->db->sql_query("
CREATE TABLE IF NOT EXISTS `{$this->tableName}` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`regDateTime` datetime NULL,
`ip` varchar(64) COLLATE utf8mb4_unicode_ci NULL,
`userAgent` varchar(128) COLLATE utf8mb4_unicode_ci NULL,
`errorType` varchar(32) COLLATE utf8mb4_unicode_ci NULL,
`errorMessage` longtext COLLATE utf8mb4_unicode_ci NULL,
`errorFileName` varchar(128) COLLATE utf8mb4_unicode_ci NULL,
`errorLine` varchar(32) COLLATE utf8mb4_unicode_ci NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci AUTO_INCREMENT=1;
");
}
if (!$this->db->sql_result("SHOW COLUMNS FROM `{$this->tableName}` LIKE 'requestUrl'")) {
$this->db->sql_query("ALTER TABLE `{$this->tableName}` ADD `requestUrl` longtext null;");
}
}
public function insert($num, $str, $file, $line)
{
$fullUrl = (isset($_SERVER['HTTPS']) ? "https" : "http") . "://" . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'];
$str = ptyCutLength($str, 2000);
GLOBAL $platyFramework;
$n = $platyFramework->db->query("INSERT INTO {$this->tableName} (regDateTime, ip, userAgent, errorType, errorMessage, errorFileName, errorLine, requestUrl) VALUES
(NOW(), '{$_SERVER['REMOTE_ADDR']}', '{$_SERVER['HTTP_USER_AGENT']}',
'" . addslashes($num) . "',
'" . addslashes($str) . "',
'" . addslashes($file) . "',
'" . addslashes($line) . "',
'" . addslashes(ptyCutLength($fullUrl, 65000)) . "'
)");
if ($n)
echo "error reported.<br>";
else
echo "error cannot reported.<br>";
}
}
?>
This diff is collapsed.
<?php
/**
* Created by PhpStorm.
* User: cpueblo
* Date: 2016. 8. 30.
* Time: 오후 4:56
*/
namespace platyFramework;
class ptyDBListModel extends model
{
public $_tableName;
public $itemModelClassName;
public $pageName;
public $itemsPerPage;
private $totalCount;
function __construct($tableName, $itemModelClassName, $pageName = "page", $itemsPerPage = 0)
{
parent::__construct();
$this->_tableName = $tableName;
$this->itemModelClassName = $itemModelClassName;
$this->pageName = $pageName;
$this->itemsPerPage = $itemsPerPage;
$this->init();
}
function init($enabled = true)
{
$this->db->clear();
$this->db->addSelect("*");
$this->db->addFrom($this->_tableName);
if ($enabled)
$this->db->addWhereEqual("enabled", "1");
return $this;
}
function addWhereEnabled()
{
$this->db->addWhereEqual("enabled", "1");
return $this;
}
function getItemBy($key, $value)
{
$this->db->addWhereEqual($key, $value);
return $this->getItem();
}
function addWhere($values)
{
// $this->db->addWhere()
// $this->db->addWhere($values);
}
function get()
{
if ($this->itemsPerPage && $this->pageName) {
$this->db->pageName = $this->pageName;
$this->db->setLimit($this->itemsPerPage);
$this->totalCount = $this->db->getCount();
}
$lst = $this->db->sql_list ();
$lst = $this->buildWithItems($lst);
return $lst;
}
function getItem()
{
$this->db->setLimit(0);
$item = $this->db->sql_fetch();
if ($item) {
$className = $this->itemModelClassName;
return $className::build($item);
}
else
{
return null;
}
}
public function buildWithItems($items)
{
$ret = array();
$className = $this->itemModelClassName;
foreach ($items as $k => $v) {
$ret[] = $className::build($v);
}
return $ret;
}
public function getPaging($maxPagesToShow = 10)
{
if ($this->itemsPerPage == 0) return "";
$page = (int)$this->request->request[$this->pageName];
if ($page == 0)
$page = 1;
$p = new Paginator($this->totalCount, $this->itemsPerPage, $page, '');
$p->setMaxPagesToShow($maxPagesToShow);
$first = ptyRebuildUrl(array($this->pageName => 1));
$prev = ptyRebuildUrl(array($this->pageName => $p->getPrevPage() ? $p->getPrevPage() : 1));
$next = ptyRebuildUrl(array($this->pageName => $p->getNextPage() ? $p->getNextPage() : $p->getNumPages()));
$last = ptyRebuildUrl(array($this->pageName => $p->getNumPages()));
$out = "<ul class='pull-right pagination clearfix'>";
$out .= "<li class='prev'><a href='$first' class='first'>처음</a></li>";
$out .= "<li class='prev'><a href='$prev' class='prev'>이전</a></li>";
foreach ($p->getPages() as $item) {
if ($item['num'] == "...")
$url = "";
else
$url = ptyRebuildUrl(array($this->pageName => $item['num']));
if ($item[isCurrent])
$out .= "<li class='active'><a href='$url'>" . $item[num] . "</a></li>";
else
$out .= "<li><a href='$url'>" . $item[num] . "</a></li>";
}
$out .= "<li class='next'><a href='$next' class='next'>다음</a></li>";
$out .= "<li class='prev'><a href='$last' class='last'>마지막</a></li>";
$out .= "</ul>";
return $out;
}
public function remove($id)
{
$this->db->clear()->addFrom($this->_tableName)->addWhere("id = '$id'")->addSet("enabled = 0")->update();
}
public function delete($id)
{
$this->db->clear()->addFrom($this->_tableName)->addWhere("id = '$id'")->delete();
}
public function insert($item)
{
/** @var ptyDBItem $item */
$this->db->clear()->addFrom($this->_tableName)->addSet($item->_item)->insert();
$item->id = $this->db->getInsertId();
return $item->id;
}
}
This diff is collapsed.
<?php
/**
* Created by PhpStorm.
* User: cpueblo
* Date: 2016. 8. 30.
* Time: 오후 4:56
*/
namespace platyFramework;
class ptyDBItemManager extends model
{
var $pageLimit = 0;
var $_tableName = "";
public function __construct($tableName)
{
parent::__construct();
$this->_tableName = $tableName;
}
function init()
{
$this->db->clear();
$this->db->addFrom($this->_tableName);
return $this;
}
function adminInit()
{
$this->db->clear();
$this->db->addFrom($this->_tableName);
return $this;
}
function getTotalCount()
{
GLOBAL $db;
$this->db->clear()->addSelect("COUNT(*)")->addFrom($this->_tableName)->addWhere("enabled = '1'");
return $this->db->getCount();
}
public function getItemById($id)
{
GLOBAL $db;
$this->db->clear()->addSelect("*")->addFrom($this->_tableName)->addWhere("id = '$id'");
$data = $this->db->sql_fetch();
if (!$data)
return null;
$item = new ptyDBItem($this->_tableName, $data);
return $item;
}
public function getItemBy($key, $value)
{
GLOBAL $db;
$this->db->clear()->addSelect("*")->addFrom($this->_tableName)->addWhere("$key = '$value'");
$data = $this->db->sql_fetch();
if (!$data)
return null;
$item = new ptyDBItem($this->_tableName, $data);
return $item;
}
public function getItemByArray($array)
{
$this->db->clear()->addSelect("*")->addFrom($this->_tableName);
foreach ($array as $k => $v) {
if ($k && $v)
$this->db->addWhereEqual($k, $v);
}
$data = $this->db->sql_fetch();
if (!$data)
return null;
$item = new ptyDBItem($this->_tableName, $data);
return $item;
}
public function remove($id)
{
$this->db->clear()->addFrom($this->_tableName)->addWhere("id = '$id'")->addSet("enabled = 0")->update();
}
public function delete($id)
{
$this->db->clear()->addFrom($this->_tableName)->addWhere("id = '$id'")->delete();
}
public function add($data)
{
$this->db->clear()->addFrom($this->_tableName)->addSet($data)->insert();
return $this->db->getInsertId();
}
function get($wheres = null, $orderBy = null)
{
$lst = $this->getRaw($wheres, $orderBy);
$lst = ptyDBItem::buildWithItems($lst);
return $lst;
}
function getRaw($wheres = null, $orderBy = null)
{
$this->init();
if ($this->pageLimit)
$this->db->setLimit($this->pageLimit);
foreach ($wheres as $k => $v) {
if (isset($k) && isset($v) && !is_null($v)) {
$this->db->addWhereEqual($k, $v);
}
else if (isset($k)) {
$this->db->addWhere($k);
}
}
if (is_null($orderBy))
$this->db->addOrderBy("id desc");
else
{
foreach ($orderBy as $o)
$this->db->addOrderBy($o);
}
$this->totalCount = $this->getTotalCount();
// echo "totalCnt = ".$this->totalCount;
$lst = $this->db->addSelect($this->_tableName . ".*")->sql_list();
return $lst;
}
function getPaging()
{
if ($this->pageLimit == 0) return;
// pg ==> board paging
$page = (int)$this->request->request['pg'];
if ($page == 0)
$page = 1;
$p = new Paginator($this->totalCount, $this->pageLimit, $page, '');
$p->setMaxPagesToShow($this->pageLimit);
$first = ptyRebuildUrl(array("pg" => 1));
$prev = ptyRebuildUrl(array("pg" => $p->getPrevPage() ? $p->getPrevPage() : 1));
$next = ptyRebuildUrl(array("pg" => $p->getNextPage() ? $p->getNextPage() : $p->getNumPages()));
$last = ptyRebuildUrl(array("pg" => $p->getNumPages()));
$out = "<a href='$first' class='first'>처음</a>";
$out .= "<a href='$prev' class='prev'>이전</a>";
foreach ($p->getPages() as $item) {
$url = ptyRebuildUrl(array("pg" => $item['num']));
if ($item[isCurrent])
$out .= "<a href='$url' class='on'>" . $item[num] . "</a>";
else
$out .= "<a href='$url'>" . $item[num] . "</a>";
}
$out .= "<a href='$next' class='next'>다음</a>";
$out .= "<a href='$last' class='last'>마지막</a>";
return $out;
}
function getCurrentPageNo()
{
if ($this->pageLimit == 0) return 1;
// pg ==> board paging
$page = (int)$this->request->request['pg'];
if ($page == 0) $page = 1;
$p = new Paginator($this->totalCount, $this->pageLimit, $page, '');
$p->setMaxPagesToShow($this->pageLimit);
return $p->getCurrentPage();
}
function hasMorePaging()
{
if ($this->pageLimit == 0) return false;
// pg ==> board paging
$page = (int)$this->request->request['pg'];
if ($page == 0) $page = 1;
$p = new Paginator($this->totalCount, $this->pageLimit, $page, '');
$p->setMaxPagesToShow($this->pageLimit);
if ($p->getCurrentPage() != $p->getNumPages())
return true;
else
return false;
}
}
class ptyDBItem extends ptyItem
{
var $db;
var $tableName = "";
public function __construct($tableName, $item = "")
{
GLOBAL $platyFramework;
$this->db = $platyFramework->db;
parent::__construct($item);
$this->tableName = $tableName;
$this->init();
}
public static function buildItemById($tableName, $id)
{
$item = new static($tableName);
// $item->db->setDebug(1);
$item->db->clear()->addSelect("*")->addFrom($item->tableName)->addWher("id = '$id'");
$data = $item->db->sql_fetch();
if (!$data)
return null;
$item->_item = $data;
return $item;
}
public static function buildItemBy($tableName, $by, $value)
{
$item = new static($tableName);
$item->db->clear()->addSelect("*")->addFrom($item->tableName)->addWhere("$by = '$value'");
$data = $item->db->sql_fetch();
if (!$data)
return null;
$item->_item = $data;
return $item;
}
public function init()
{
$this->db->clear();
return $this;
}
public function insert()
{
$this->db->clear()
->addFrom($this->tableName)
->addSet($this->_item)
->insert();
$this->id = $this->db->getInsertId();
return $this->id;
}
public function update()
{
GLOBAL $db;
$this->db->clear();
foreach ($this->_item as $k => $v) {
if (!isset($v)) $v = '';
if ($k == "id")
continue;
$this->db->addSet($k, $v);
}
$this->db->addFrom($this->tableName)
->addWhereEqual("id", $this->id)
->update();
}
}
/**
* Class ptyItem
*
* Getter 와 Setter 를 배열에서 객체로 변환하여 사용하게 합니다.
* 주의 : 없는 변수에 대해서는 null 이 아닌 "" 를 리턴합니다
*
* @package platyFramework
* @author cpueblo <cpueblo@platyhouse.com>
*/
abstract class ptyList
{
protected $_items;
public function __construct($lst)
{
}
public function getCount()
{
return count($this->_items);
}
public function getItems()
{
return $this->_items;
}
public function getArrayItems()
{
$ret = array();
foreach ($this->_items as $item) {
$ret[] = $item->_item;
}
return $ret;
}
public function addLists($n)
{
if (!isset($this->_items))
$this->_items = array();
$this->_items = array_merge($this->_items, $n->_items);
}
public function addItem($item)
{
$this->_items[] = $item;
}
}
\ No newline at end of file
This diff is collapsed.
<?php
namespace platyFramework;
class ptyDateTime
{
}
/**
* 과거일 경우 -, 지났을 경우 +
*
* @param string $datetime
* @return int|null
*/
function ptyGetPassedMinutes(string $datetime)
{
try {
// 현재 시간 가져오기
$now = new \DateTime();
// 입력된 날짜를 DateTime 객체로 변환
$date = new \DateTime($datetime);
// 현재 시간과 입력된 시간의 차이를 계산
$diff = $now->getTimestamp() - $date->getTimestamp();
$passMinute = floor($diff / 60); // 초 단위 차이를 분 단위로 변환
return (int)$passMinute;
} catch (\Exception $e) {
// 예외 발생 시 false 반환, $passMinute은 -1로 설정
return null;
}
}
/**
* 일자만으로 차이 비교, 과거일 경우 -, 지났을 경우 +
*
* @param string $datetime
* @return int|null
*/
function ptyGetPassedDay(string $datetime)
{
try {
$date = new \DateTime($datetime);
$datetime = $date->format('Y-m-d');
// 현재 시간 가져오기
$now = new \DateTime();
// 입력된 날짜를 DateTime 객체로 변환
$date = new \DateTime($datetime);
// 현재 시간과 입력된 시간의 차이를 계산
$diff = $now->diff($date);
// 날짜 차이를 일(day) 단위로 반환
$passDays = (int)$diff->format('%r%a'); // %r: 음수일 경우 부호를 유지, %a: 전체 일 수
return (int)$passDays;
} catch (\Exception $e) {
// 예외 발생 시 false 반환, $passMinute은 -1로 설정
return null;
}
}
/**
* 특정 시간의 '오전', '오후' 리턴
* @param string $s
* @return string '오전, 오후"
* @throws \DateMalformedStringException
*/
function ptyGetAmPm(string $s)
{
return ($amPm = (new \DateTime($s))->format('A') === 'AM' ? '오전' : '오후') . ' ' . (new \DateTime($s))->format('g시 i분');
}
?>
\ No newline at end of file
<?php
namespace platyFramework;
class ptyElapsedTime
{
private $startTime;
public function __construct()
{
$this->startTime = microtime(true);
}
/**
* 경과 시간을 밀리초(ms) 단위로 반환
* @return int 경과 시간 (밀리초)
*/
public function get()
{
$endTime = microtime(true);
$elapsedSeconds = $endTime - $this->startTime;
return round($elapsedSeconds * 1000); // 초를 밀리초로 변환 후 반올림
}
/**
* 시작 시간을 현재 시간으로 리셋
*/
public function reset()
{
$this->startTime = microtime(true);
}
}
\ No newline at end of file
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
<?php
namespace PhpOffice\PhpSpreadsheet\Calculation;
abstract class Category
{
// Function categories
const CATEGORY_CUBE = 'Cube';
const CATEGORY_DATABASE = 'Database';
const CATEGORY_DATE_AND_TIME = 'Date and Time';
const CATEGORY_ENGINEERING = 'Engineering';
const CATEGORY_FINANCIAL = 'Financial';
const CATEGORY_INFORMATION = 'Information';
const CATEGORY_LOGICAL = 'Logical';
const CATEGORY_LOOKUP_AND_REFERENCE = 'Lookup and Reference';
const CATEGORY_MATH_AND_TRIG = 'Math and Trig';
const CATEGORY_STATISTICAL = 'Statistical';
const CATEGORY_TEXT_AND_DATA = 'Text and Data';
const CATEGORY_WEB = 'Web';
const CATEGORY_UNCATEGORISED = 'Uncategorised';
const CATEGORY_MICROSOFT_INTERNAL = 'MS Internal';
}
<?php
namespace PhpOffice\PhpSpreadsheet\Calculation\Engine\Operands;
interface Operand
{
/** @param string[] $matches */
public static function fromParser(string $formula, int $index, array $matches): self;
public function value(): string;
}
<?php
namespace PhpOffice\PhpSpreadsheet\Calculation\Engineering;
class Constants
{
/**
* EULER.
*/
public const EULER = 2.71828182845904523536;
}
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment