Skip to content

Commit

Permalink
ereg를 preg_match로 대치
Browse files Browse the repository at this point in the history
  • Loading branch information
hyeonseok committed Sep 20, 2015
1 parent a600a42 commit 0bb75a1
Show file tree
Hide file tree
Showing 9 changed files with 41 additions and 41 deletions.
2 changes: 1 addition & 1 deletion classes/Archive.class.php
Expand Up @@ -72,7 +72,7 @@ function getArchive($name) {
function getArchiveList() {
$archives = array();
$files = array();
$filenames = Entry::getEntryList("^[0-9].+[.]entry$");
$filenames = Entry::getEntryList("/^[0-9].+[.]entry$/");
foreach($filenames as $filename) {
$t = substr($filename, 9);
$t = substr($t, 0, 6);
Expand Down
2 changes: 1 addition & 1 deletion classes/Calendar.class.php
Expand Up @@ -90,7 +90,7 @@ function getCalendar() {

function getEntriesForCalendar($year, $month) {
$entries = array();
$filenames = Soojung::queryFilenameMatch(sprintf("^%04d%02d[^.]+[.]entry$", $year, $month));
$filenames = Soojung::queryFilenameMatch(sprintf("/^%04d%02d[^.]+[.]entry$/", $year, $month));
sort($filenames);
foreach($filenames as $filename) {
list($datetime, $category, $entryid) = explode("_", substr(basename($filename), 0, -6));
Expand Down
6 changes: 3 additions & 3 deletions classes/Category.class.php
Expand Up @@ -32,7 +32,7 @@ function getRssHref() {

function getEntries($count = -1, $page = 1) {
$entries = array();
$query = "^[0-9].+_" . str_replace("+", "\\+", $this->getHashID()) . "_.+[.]entry$";
$query = "/^[0-9].+_" . str_replace("+", "\\+", $this->getHashID()) . "_.+[.]entry$/";
$filenames = Soojung::queryFilenameMatch($query);
usort($filenames, "cmp_base_filename");

Expand All @@ -50,7 +50,7 @@ function getEntries($count = -1, $page = 1) {
}

function getEntryCount() {
$query = "^[0-9].+_" . str_replace("+", "\\+", $this->getHashID()) . "_.+[.]entry$";
$query = "/^[0-9].+_" . str_replace("+", "\\+", $this->getHashID()) . "_.+[.]entry$/";
return Soojung::queryNumFilenameMatch($query);
}

Expand All @@ -59,7 +59,7 @@ function getEntryCount() {
*/
function getCategoryList() {
$categories = $categoryentries = array();
$filenames = Entry::getEntryList("^[0-9].+[.]entry$");
$filenames = Entry::getEntryList("/^[0-9].+[.]entry$/");
foreach($filenames as $filename) {
$entry = new Entry($filename);
$filenamepart = explode("_", $filename);
Expand Down
4 changes: 2 additions & 2 deletions classes/Comment.class.php
Expand Up @@ -83,9 +83,9 @@ function writeComment($entryId, $name, $email, $homepage, $body, $date) {
*/
function cacheCommentList() {
$comment_filenames = array();
$dirs = Soojung::queryFilenameMatch("^[0-9]+$", "contents/");
$dirs = Soojung::queryFilenameMatch("/^[0-9]+$/", "contents/");
foreach ($dirs as $dir) {
$files = Soojung::queryFilenameMatch("[.]comment$", $dir . "/");
$files = Soojung::queryFilenameMatch("/[.]comment$/", $dir . "/");
foreach ($files as $file) {
$comment_filenames[] = $file;
}
Expand Down
26 changes: 13 additions & 13 deletions classes/Entry.class.php
Expand Up @@ -94,12 +94,12 @@ function getBody() {
}

function getCommentCount() {
return Soojung::queryNumFilenameMatch("[.]comment$", "contents/" . $this->entryId . "/");
return Soojung::queryNumFilenameMatch("/[.]comment$/", "contents/" . $this->entryId . "/");
}

function getComments() {
$comments = array();
$filenames = Soojung::queryFilenameMatch("[.]comment$", "contents/" . $this->entryId . "/");
$filenames = Soojung::queryFilenameMatch("/[.]comment$/", "contents/" . $this->entryId . "/");
sort($filenames);
foreach($filenames as $filename) {
$comments[] = new Comment($filename);
Expand All @@ -108,12 +108,12 @@ function getComments() {
}

function getTrackbackCount() {
return Soojung::queryNumFilenameMatch("[.]trackback$", "contents/" . $this->entryId);
return Soojung::queryNumFilenameMatch("/[.]trackback$/", "contents/" . $this->entryId);
}

function getTrackbacks() {
$trackbacks = array();
$filenames = Soojung::queryFilenameMatch("[.]trackback$", "contents/" . $this->entryId . "/");
$filenames = Soojung::queryFilenameMatch("/[.]trackback$/", "contents/" . $this->entryId . "/");
sort($filenames);
foreach($filenames as $filename) {
$trackbacks[] = new Trackback($filename);
Expand Down Expand Up @@ -178,16 +178,16 @@ public static function getEntry($entryId) {

private static function _getQuery($hide) {
if ($hide == false) {
$query = "[.]entry$";
$query = "/[.]entry$/";
} else {
$query = "^[0-9].+[.]entry$";
$query = "/^[0-9].+[.]entry$/";
}
return $query;
}

public static function cacheEntryList() {
$entry_filenames = array();
$files = Soojung::queryFilenameMatch("[.]entry$");
$files = Soojung::queryFilenameMatch("/[.]entry$/");
foreach ($files as $file) {
$entry_filenames[] = $file;
}
Expand All @@ -204,7 +204,7 @@ public static function getEntryList($query, $length = false) {
$fp = fopen('contents/.entryList', 'r');
while (($buffer = fgets($fp)) !== false) {
$buffer = trim($buffer);
if (ereg($query, str_replace('contents/', '', trim($buffer))) !== false) {
if (preg_match($query, str_replace('contents/', '', trim($buffer))) === 1) {
$entries[] = $buffer;
if ($length && count($entries) >= $length) {
break;
Expand Down Expand Up @@ -244,7 +244,7 @@ public static function getRecentEntries($count=10, $hide=true) {

public static function getStaticEntries($count = -1, $page = 1) {
$entries = array();
$query = "^[0-9].+S_.+[.]entry$";
$query = "/^[0-9].+\S_.+\.entry$/";
$filenames = Soojung::queryFilenameMatch($query);
usort($filenames, "cmp_base_filename");

Expand All @@ -263,12 +263,12 @@ public static function getStaticEntries($count = -1, $page = 1) {
}

function getStaticEntryCount() {
return Soojung::queryNumFilenameMatch("^[0-9].+S_.+[.]entry$");
return Soojung::queryNumFilenameMatch("^[0-9].+\S_.+[.]entry$");
}

public static function getSecretEntries($count = -1, $page = 1) {
$entries = array();
$query = "^[.][0-9]+.+[.]entry$";
$query = "/^[.][0-9]+.+[.]entry$/";
$filenames = Soojung::queryFilenameMatch($query);
usort($filenames, "cmp_base_filename");

Expand Down Expand Up @@ -296,7 +296,7 @@ public static function search($keyword, $mode = "all") {
return $founds;
}
if ($mode == "all") {
$filenames = Soojung::queryFilenameMatch("^[0-9].+[.]entry$");
$filenames = Soojung::queryFilenameMatch("/^[0-9].+[.]entry$/");
rsort($filenames);
foreach($filenames as $f) {
$fd = fopen($f, "r");
Expand All @@ -317,7 +317,7 @@ function searchByTitle($keyword) {
if ($keyword == "") {
return $founds;
}
$filenames = Soojung::queryFilenameMatch("^[0-9].+[.]entry$");
$filenames = Soojung::queryFilenameMatch("/^[0-9].+[.]entry$/");
rsort($filenames);
foreach($filenames as $f) {
$fd = fopen($f, "r");
Expand Down
8 changes: 4 additions & 4 deletions classes/Soojung.class.php
Expand Up @@ -12,7 +12,7 @@ public static function queryFilenameMatch($query, $path="contents/") {
return $list;
}
foreach($file_list as $file) {
if (ereg($query, $file)) {
if (preg_match($query, $file)) {
$list[] = $path . $file;
}
}
Expand All @@ -29,15 +29,15 @@ public static function queryNumFilenameMatch($query, $path="contents/") {
return $number;
}
foreach($file_list as $file) {
if (ereg($query, $file)) {
if (preg_match($query, $file)) {
$number++;
}
}
return $number;
}

public static function entryIdToFilename($entryId) {
$f = Entry::getEntryList("_" . $entryId . "[.]entry$", 1);
$f = Entry::getEntryList("/_" . $entryId . "[.]entry$/", 1);
return $f[0];
}

Expand Down Expand Up @@ -82,7 +82,7 @@ public static function createNewEntryId() {

public static function getTemplates() {
$list = array();
$filenames = Soojung::queryFilenameMatch(".+", "templates/");
$filenames = Soojung::queryFilenameMatch("/.+/", "templates/");
foreach($filenames as $filename) {
$filename = basename($filename);
if ($filename == "admin" or $filename == "CVS") {
Expand Down
8 changes: 4 additions & 4 deletions classes/Trackback.class.php
Expand Up @@ -102,9 +102,9 @@ function writeTrackback($entryId, $url, $name, $title, $excerpt, $date = false)
*/
function cacheTrackbackList() {
$filenames = array();
$dirs = Soojung::queryFilenameMatch("^[0-9]+$", "contents/");
$dirs = Soojung::queryFilenameMatch("/^[0-9]+$/", "contents/");
foreach ($dirs as $dir) {
$files = Soojung::queryFilenameMatch("[.]trackback$", $dir . "/");
$files = Soojung::queryFilenameMatch("/[.]trackback$/", $dir . "/");
foreach ($files as $file) {
$filenames[] = $file;
}
Expand Down Expand Up @@ -204,9 +204,9 @@ function sendTrackbackPing($entryId, $trackbackUrl, $encoding="UTF-8") {
$line .= fgets ($fp, 1024);
}

if (ereg("<error>[^<0-9]*([0-9]*)[^<0-9]*</error>", $line, $regs)) {
if (preg_match("/<error>[^<0-9]*([0-9]*)[^<0-9]*</error>/", $line, $regs)) {
$response['error'] = $regs[1];
if ($response == 0 && ereg("<message>([<]*)</message>", $line, $regs)) {
if ($response == 0 && preg_match("/<message>([<]*)</message>/", $line, $regs)) {
$response['message'] = $regs[1];
}
}
Expand Down
20 changes: 10 additions & 10 deletions libs/xmlrpc.inc
Expand Up @@ -206,7 +206,7 @@
$i=0;
while($i<sizeof($top))
{
if (ereg("^([#a-zA-Z0-9]+);", $top[$i], $regs))
if (preg_match("/^([#a-zA-Z0-9]+);/", $top[$i], $regs))
{
$op.=ereg_replace("^[#a-zA-Z0-9]+;",
xmlrpc_lookup_entity($regs[1]),
Expand Down Expand Up @@ -236,7 +236,7 @@
{
return $xmlEntities[strtolower($ent)];
}
if (ereg("^#([0-9]+)$", $ent, $regs))
if (preg_match("/^#([0-9]+)$/", $ent, $regs))
{
return chr($regs[1]);
}
Expand Down Expand Up @@ -767,7 +767,7 @@
{
// we have a DOUBLE
// we must check that only 0123456789-.<space> are characters here
if (!ereg("^[+-]?[eE0123456789 \\t\\.]+$", $_xh[$parser]['ac']))
if (!preg_match("/^[+-]?[eE0123456789 \\t\\.]+$/", $_xh[$parser]['ac']))
{
// TODO: find a better way of throwing an error
// than this!
Expand All @@ -786,7 +786,7 @@
{
// we have an I4/INT
// we must check that only 0123456789-<space> are characters here
if (!ereg("^[+-]?[0123456789 \\t]+$", $_xh[$parser]['ac']))
if (!preg_match("/^[+-]?[0123456789 \\t]+$/", $_xh[$parser]['ac']))
{
// TODO: find a better way of throwing an error
// than this!
Expand Down Expand Up @@ -897,7 +897,7 @@
{
global $_xh, $xmlrpc_backslash;

//if (ereg("^[\n\r \t]+$", $data)) return;
//if (preg_match("/^[\n\r \t]+$/", $data)) return;
// print "adding [${data}]\n";

// skip processing if xml fault already detected
Expand Down Expand Up @@ -1459,10 +1459,10 @@
}
// see if we got an HTTP 200 OK, else bomb
// but only do this if we're using the HTTP protocol.
if(ereg("^HTTP",$data))
if(preg_match("/^HTTP/",$data))
{
// Strip HTTP 1.1 100 Continue header if present
while (ereg('^HTTP/1.1 1[0-9]{2}', $data))
while (preg_match('/^HTTP/1.1 1[0-9]{2}/', $data))
{
$pos = strpos($data, 'HTTP', 12);
// server sent a Continue header without any (valid) content following...
Expand All @@ -1471,7 +1471,7 @@
break;
$data = substr($data, $pos);
}
if (!ereg("^HTTP/[0-9\\.]+ 200 ", $data))
if (!preg_match("/^HTTP/[0-9\\.]+ 200 /", $data))
{
$errstr= substr($data, 0, strpos($data, "\n")-1);
error_log('HTTP error, got response: ' .$errstr);
Expand All @@ -1493,7 +1493,7 @@
$_xh[$parser]['vsp'] = 0;

// separate HTTP headers from data
if (ereg("^HTTP", $data))
if (preg_match("/^HTTP/", $data))
{
// be tolerant to usage of \n instead of \r\n to separate headers and data
// (even though it is not valid http)
Expand Down Expand Up @@ -2004,7 +2004,7 @@
{
// return a timet in the localtime, or UTC
$t=0;
if (ereg("([0-9]{4})([0-9]{2})([0-9]{2})T([0-9]{2}):([0-9]{2}):([0-9]{2})", $idate, $regs))
if (preg_match("/([0-9]{4})([0-9]{2})([0-9]{2})T([0-9]{2}):([0-9]{2}):([0-9]{2})/", $idate, $regs))
{
if ($utc)
{
Expand Down
6 changes: 3 additions & 3 deletions libs/xmlrpcs.inc
Expand Up @@ -68,7 +68,7 @@

$methName=$m->getParam(0);
$methName=$methName->scalarval();
if (ereg("^system\.", $methName))
if (preg_match("/^system\./", $methName))
{
$dmap=$_xmlrpcs_dmap; $sysCall=1;
}
Expand Down Expand Up @@ -115,7 +115,7 @@

$methName=$m->getParam(0);
$methName=$methName->scalarval();
if (ereg("^system\.", $methName))
if (preg_match("/^system\./", $methName))
{
$dmap=$_xmlrpcs_dmap; $sysCall=1;
}
Expand Down Expand Up @@ -454,7 +454,7 @@
global $xmlrpcerr, $xmlrpcstr, $_xmlrpcs_dmap;
// now to deal with the method
$methName = $m->method();
$sysCall = ereg("^system\.", $methName);
$sysCall = preg_match("/^system\./", $methName);
$dmap = $sysCall ? $_xmlrpcs_dmap : $this->dmap;

if (!isset($dmap[$methName]['function']))
Expand Down

0 comments on commit 0bb75a1

Please sign in to comment.