/////////////////////////////////////////////////
// PukiWiki - Yet another WikiWikiWeb clone.
//
-// $Id: func.php,v 1.3 2004/08/01 13:37:13 henoheno Exp $
+// $Id: func.php,v 1.4 2004/08/02 13:11:09 henoheno Exp $
//
// ʸ»úÎó¤¬InterWikiName¤«¤É¤¦¤«
{
global $InterWikiName;
- return preg_match("/^$InterWikiName$/",$str);
+ return preg_match("/^$InterWikiName$/", $str);
}
// ʸ»úÎ󤬥ڡ¼¥¸Ì¾¤«¤É¤¦¤«
{
global $BracketName;
- $is_pagename = (!is_interwiki($str) and preg_match("/^(?!\/)$BracketName$(?<!\/$)/",$str)
- and !preg_match('/(^|\/)\.{1,2}(\/|$)/',$str));
-
- if (defined('SOURCE_ENCODING'))
- {
- if (SOURCE_ENCODING == 'UTF-8')
- {
- $is_pagename = ($is_pagename and preg_match('/^(?:[\x00-\x7F]|(?:[\xC0-\xDF][\x80-\xBF])|(?:[\xE0-\xEF][\x80-\xBF][\x80-\xBF]))+$/',$str)); // UTF-8
- }
- else if (SOURCE_ENCODING == 'EUC-JP')
- {
- $is_pagename = ($is_pagename and preg_match('/^(?:[\x00-\x7F]|(?:[\x8E\xA1-\xFE][\xA1-\xFE])|(?:\x8F[\xA1-\xFE][\xA1-\xFE]))+$/',$str)); // EUC-JP
+ $is_pagename = (! is_interwiki($str) and
+ preg_match("/^(?!\/)$BracketName$(?<!\/$)/", $str) and
+ ! preg_match('/(^|\/)\.{1,2}(\/|$)/', $str));
+
+ if (defined('SOURCE_ENCODING')) {
+ if (SOURCE_ENCODING == 'UTF-8') {
+ $pattern = '/^(?:[\x00-\x7F]|(?:[\xC0-\xDF][\x80-\xBF])|(?:[\xE0-\xEF][\x80-\xBF][\x80-\xBF]))+$/';
+ $is_pagename = ($is_pagename and preg_match($pattern, $str));
+ } else if (SOURCE_ENCODING == 'EUC-JP') {
+ $pattern = '/^(?:[\x00-\x7F]|(?:[\x8E\xA1-\xFE][\xA1-\xFE])|(?:\x8F[\xA1-\xFE][\xA1-\xFE]))+$/';
+ $is_pagename = ($is_pagename and preg_match($pattern, $str));
}
}
}
// ʸ»úÎó¤¬URL¤«¤É¤¦¤«
-function is_url($str,$only_http=FALSE)
+function is_url($str, $only_http = FALSE)
{
$scheme = $only_http ? 'https?' : 'https?|ftp|news';
return preg_match('/^('.$scheme.')(:\/\/[-_.!~*\'()a-zA-Z0-9;\/?:\@&=+\$,%#]*)$/', $str);
}
// ¥Ú¡¼¥¸¤¬Â¸ºß¤¹¤ë¤«
-function is_page($page,$reload=FALSE)
+function is_page($page, $reload = FALSE)
{
return file_exists(get_filename($page));
}
global $cantedit;
static $is_editable = array();
- if (!array_key_exists($page,$is_editable))
+ if (!array_key_exists($page, $is_editable))
{
$is_editable[$page] = (
is_pagename($page) and
- !is_freeze($page) and
- !in_array($page,$cantedit)
+ ! is_freeze($page) and
+ ! in_array($page, $cantedit)
);
}
{
global $function_freeze;
- if (!$function_freeze or !is_page($page))
- {
- return FALSE;
- }
+ if (! $function_freeze or ! is_page($page)) return FALSE;
list($lines) = get_source($page);
return (rtrim($lines) == '#freeze');
// ¼«Æ°¥Æ¥ó¥×¥ì¡¼¥È
function auto_template($page)
{
- global $auto_template_func,$auto_template_rules;
+ global $auto_template_func, $auto_template_rules;
- if (!$auto_template_func)
- {
- return '';
- }
+ if (! $auto_template_func) return '';
$body = '';
$matches = array();
foreach ($auto_template_rules as $rule => $template)
{
- if (preg_match("/$rule/",$page,$matches))
+ if (preg_match("/$rule/", $page, $matches))
{
- $template_page = preg_replace("/$rule/",$template,$page);
+ $template_page = preg_replace("/$rule/", $template, $page);
if (is_page($template_page))
{
- $body = join('',get_source($template_page));
+ $body = join('', get_source($template_page));
// ¸«½Ð¤·¤Î¸ÇÍIDÉô¤òºï½ü
- $body = preg_replace('/^(\*{1,3}.*)\[#[A-Za-z][\w-]+\](.*)$/m','$1$2',$body);
+ $body = preg_replace('/^(\*{1,3}.*)\[#[A-Za-z][\w-]+\](.*)$/m', '$1$2', $body);
// #freeze¤òºï½ü
- $body = preg_replace('/^#freeze\s*$/m','',$body);
+ $body = preg_replace('/^#freeze\s*$/m', '', $body);
- for ($i = 0; $i < count($matches); $i++)
- {
- $body = str_replace("\$$i",$matches[$i],$body);
+ for ($i = 0; $i < count($matches); $i++) {
+ $body = str_replace("\$$i", $matches[$i], $body);
}
break;
}
}
// ¸¡º÷¸ì¤òŸ³«¤¹¤ë
-function get_search_words($words,$special=FALSE)
+function get_search_words($words, $special = FALSE)
{
$retval = array();
// Perl¥á¥â - Àµ¤·¤¯¥Ñ¥¿¡¼¥ó¥Þ¥Ã¥Á¤µ¤»¤ë
// # JIS X 0208 ¤¬ 0ʸ»ú°Ê¾å³¤¤¤Æ # ASCII, SS2, SS3 ¤Þ¤¿¤Ï½ªÃ¼
$eucpost = '(?=(?:[\xA1-\xFE][\xA1-\xFE])*(?:[\x00-\x7F\x8E\x8F]|\z))';
}
- $quote_func = create_function('$str','return preg_quote($str,"/");');
+ $quote_func = create_function('$str', 'return preg_quote($str, "/");');
+
// LANG=='ja'¤Ç¡¢mb_convert_kana¤¬»È¤¨¤ë¾ì¹ç¤Ïmb_convert_kana¤ò»ÈÍÑ
- $convert_kana = create_function('$str,$option',
+ $convert_kana = create_function('$str, $option',
(LANG == 'ja' and function_exists('mb_convert_kana')) ?
- 'return mb_convert_kana($str,$option);' : 'return $str;'
+ 'return mb_convert_kana($str, $option);' : 'return $str;'
);
foreach ($words as $word)
{
// ±Ñ¿ô»ú¤ÏȾ³Ñ,¥«¥¿¥«¥Ê¤ÏÁ´³Ñ,¤Ò¤é¤¬¤Ê¤Ï¥«¥¿¥«¥Ê¤Ë
- $word_zk = $convert_kana($word,'aKCV');
+ $word_zk = $convert_kana($word, 'aKCV');
$chars = array();
for ($pos = 0; $pos < mb_strlen($word_zk); $pos++)
{
- $char = mb_substr($word_zk,$pos,1);
+ $char = mb_substr($word_zk, $pos,1);
// $special : htmlspecialchars()¤òÄ̤¹¤«
$arr = array($quote_func($special ? htmlspecialchars($char) : $char));
if (strlen($char) == 1) // ±Ñ¿ô»ú
{
- foreach (array(strtoupper($char),strtolower($char)) as $_char)
+ foreach (array(strtoupper($char), strtolower($char)) as $_char)
{
- if ($char != '&')
- {
+ if ($char != '&') {
$arr[] = $quote_func($_char);
}
$ord = ord($_char);
- $arr[] = sprintf('&#(?:%d|x%x);',$ord,$ord); // ¼ÂÂλ²¾È
- $arr[] = $quote_func($convert_kana($_char,"A")); // Á´³Ñ
+ $arr[] = sprintf('&#(?:%d|x%x);', $ord, $ord); // ¼ÂÂλ²¾È
+ $arr[] = $quote_func($convert_kana($_char, 'A')); // Á´³Ñ
}
}
else // ¥Þ¥ë¥Á¥Ð¥¤¥Èʸ»ú
{
- $arr[] = $quote_func($convert_kana($char,"c")); // ¤Ò¤é¤¬¤Ê
- $arr[] = $quote_func($convert_kana($char,"k")); // Ⱦ³Ñ¥«¥¿¥«¥Ê
+ $arr[] = $quote_func($convert_kana($char, 'c')); // ¤Ò¤é¤¬¤Ê
+ $arr[] = $quote_func($convert_kana($char, 'k')); // Ⱦ³Ñ¥«¥¿¥«¥Ê
}
- $chars[] = '(?:'.join('|',array_unique($arr)).')';
+ $chars[] = '(?:' . join('|', array_unique($arr)) . ')';
}
- $retval[$word] = $eucpre.join('',$chars).$eucpost;
+ $retval[$word] = $eucpre.join('', $chars) . $eucpost;
}
return $retval;
}
// ¸¡º÷
-function do_search($word,$type='AND',$non_format=FALSE)
+function do_search($word, $type = 'AND', $non_format = FALSE)
{
global $script, $whatsnew, $non_list, $search_non_list;
global $_msg_andresult, $_msg_orresult, $_msg_notfoundresult;
$retval = array();
$b_type = ($type == 'AND'); // AND:TRUE OR:FALSE
- $keys = get_search_words(preg_split('/\s+/',$word,-1,PREG_SPLIT_NO_EMPTY));
+ $keys = get_search_words(preg_split('/\s+/', $word, -1, PREG_SPLIT_NO_EMPTY));
$_pages = get_existpages();
$pages = array();
foreach ($_pages as $page)
{
- if ($page == $whatsnew
- or (!$search_non_list and preg_match("/$non_list/",$page)))
- {
+ if ($page == $whatsnew or (! $search_non_list and preg_match("/$non_list/", $page)))
continue;
- }
// ¸¡º÷Âоݥڡ¼¥¸¤ÎÀ©¸Â¤ò¤«¤±¤ë¤«¤É¤¦¤« (¥Ú¡¼¥¸Ì¾¤ÏÀ©¸Â³°)
- if ($search_auth and !check_readable($page,false,false)) {
+ if ($search_auth and ! check_readable($page, false, false)) {
$source = get_source(); // ¸¡º÷Âоݥڡ¼¥¸ÆâÍƤò¶õ¤Ë¡£
} else {
$source = get_source($page);
}
- if (!$non_format)
- {
- array_unshift($source,$page); // ¥Ú¡¼¥¸Ì¾¤â¸¡º÷ÂоݤË
- }
+ if (! $non_format)
+ array_unshift($source, $page); // ¥Ú¡¼¥¸Ì¾¤â¸¡º÷ÂоݤË
$b_match = FALSE;
- foreach ($keys as $key)
- {
- $tmp = preg_grep("/$key/",$source);
+ foreach ($keys as $key) {
+ $tmp = preg_grep("/$key/", $source);
$b_match = (count($tmp) > 0);
if ($b_match xor $b_type)
- {
break;
- }
}
- if ($b_match)
- {
+ if ($b_match) {
$pages[$page] = get_filetime($page);
}
}
- if ($non_format)
- {
+ if ($non_format) {
return array_keys($pages);
}
+
$r_word = rawurlencode($word);
$s_word = htmlspecialchars($word);
- if (count($pages) == 0)
- {
- return str_replace('$1',$s_word,$_msg_notfoundresult);
+ if (count($pages) == 0) {
+ return str_replace('$1', $s_word, $_msg_notfoundresult);
}
+
ksort($pages);
$retval = "<ul>\n";
foreach ($pages as $page=>$time)
$r_page = rawurlencode($page);
$s_page = htmlspecialchars($page);
$passage = get_passage($time);
- $retval .= " <li><a href=\"$script?cmd=read&page=$r_page&word=$r_word\">$s_page</a>$passage</li>\n";
+ $retval .= " <li><a href=\"$script?cmd=read&page=$r_page&word=$r_word\">$s_page</a>$passage</li>\n";
}
$retval .= "</ul>\n";
- $retval .= str_replace('$1',$s_word,str_replace('$2',count($pages),
- str_replace('$3',count($_pages),$b_type ? $_msg_andresult : $_msg_orresult)));
+ $retval .= str_replace('$1', $s_word, str_replace('$2', count($pages),
+ str_replace('$3', count($_pages), $b_type ? $_msg_andresult : $_msg_orresult)));
return $retval;
}
{
global $vars;
- return array_key_exists('cmd',$vars) and (strpos($vars['cmd'],$str) === 0);
+ return array_key_exists('cmd', $vars) and (strpos($vars['cmd'], $str) === 0);
}
// ¥Ú¡¼¥¸Ì¾¤Î¥¨¥ó¥³¡¼¥É
function encode($key)
{
- return ($key == '') ? '' : strtoupper(join('',unpack('H*0',$key)));
+ return ($key == '') ? '' : strtoupper(join('', unpack('H*0', $key)));
}
// ¥Ú¡¼¥¸Ì¾¤Î¥Ç¥³¡¼¥É
function decode($key)
{
- return ($key == '') ? '' : substr(pack('H*','20202020'.$key),4);
+ return ($key == '') ? '' : substr(pack('H*', '20202020' . $key), 4);
}
// [[ ]] ¤ò¼è¤ê½ü¤¯
}
// ¥Ú¡¼¥¸°ìÍ÷¤ÎºîÀ®
-function page_list($pages, $cmd = 'read', $withfilename=FALSE)
+function page_list($pages, $cmd = 'read', $withfilename = FALSE)
{
- global $script,$list_index,$top;
- global $_msg_symbol,$_msg_other;
+ global $script, $list_index, $top;
+ global $_msg_symbol, $_msg_other;
global $pagereading_enable;
// ¥½¡¼¥È¥¡¼¤ò·èÄꤹ¤ë¡£ ' ' < '[a-zA-Z]' < 'zz'¤È¤¤¤¦Á°Äó¡£
foreach($pages as $file=>$page)
{
$r_page = rawurlencode($page);
- $s_page = htmlspecialchars($page,ENT_QUOTES);
+ $s_page = htmlspecialchars($page, ENT_QUOTES);
$passage = get_pg_passage($page);
- $str = " <li><a href=\"$script?cmd=$cmd&page=$r_page\">$s_page</a>$passage";
+ $str = " <li><a href=\"$script?cmd=$cmd&page=$r_page\">$s_page</a>$passage";
- if ($withfilename)
- {
+ if ($withfilename) {
$s_file = htmlspecialchars($file);
$str .= "\n <ul><li>$s_file</li></ul>\n ";
}
$str .= "</li>";
if($pagereading_enable) {
- if(mb_ereg('^([A-Za-z])',mb_convert_kana($page,'a'),$matches)) {
+ if(mb_ereg('^([A-Za-z])', mb_convert_kana($page, 'a'), $matches)) {
$head = $matches[1];
}
- elseif(mb_ereg('^([¥¡-¥ö])',$readings[$page],$matches)) {
+ elseif(mb_ereg('^([¥¡-¥ö])', $readings[$page], $matches)) {
$head = $matches[1];
}
- elseif (mb_ereg('^[ -~]|[^¤¡-¤ó°¡-ô¦]',$page)) {
+ elseif (mb_ereg('^[ -~]|[^¤¡-¤ó°¡-ô¦]', $page)) {
$head = $symbol;
}
else {
}
}
else {
- $head = (preg_match('/^([A-Za-z])/',$page,$matches)) ? $matches[1] :
- (preg_match('/^([ -~])/',$page,$matches) ? $symbol : $other);
+ $head = (preg_match('/^([A-Za-z])/', $page, $matches)) ? $matches[1] :
+ (preg_match('/^([ -~])/', $page, $matches) ? $symbol : $other);
}
$list[$head][$page] = $str;
$retval .= "<ul>\n";
foreach ($list as $head=>$pages)
{
- if ($head === $symbol)
- {
+ if ($head === $symbol) {
$head = $_msg_symbol;
- }
- else if ($head === $other)
- {
+ } else if ($head === $other) {
$head = $_msg_other;
}
$retval .= " <li><a id=\"head_$cnt\" href=\"#top_$cnt\"><strong>$head</strong></a>\n <ul>\n";
}
ksort($pages);
- $retval .= join("\n",$pages);
+ $retval .= join("\n", $pages);
if ($list_index)
{
$retval .= "\n </ul>\n </li>\n";
if ($list_index and $cnt > 0)
{
$top = array();
- while (count($arr_index) > 0)
- {
- $top[] = join(" | \n",array_splice($arr_index,0,16))."\n";
+ while (count($arr_index) > 0) {
+ $top[] = join(" | \n", array_splice($arr_index, 0, 16)) . "\n";
}
- $retval = "<div id=\"top\" style=\"text-align:center\">\n".
- join("<br />",$top)."</div>\n".$retval;
+ $retval = "<div id=\"top\" style=\"text-align:center\">\n" .
+ join('<br />', $top) . "</div>\n" . $retval;
}
return $retval;
}
{
global $rule_page;
- if (!is_page($rule_page))
+ if (! is_page($rule_page))
{
return "<p>sorry, $rule_page unavailable.</p>";
}
<strong>Error message : $msg</strong>
EOD;
- if(defined('SKIN_FILE') && file_exists(SKIN_FILE) && is_readable(SKIN_FILE))
- {
- catbody($title,$page,$body);
- }
- else
- {
+ if(defined('SKIN_FILE') && file_exists(SKIN_FILE) && is_readable(SKIN_FILE)) {
+ catbody($title, $page, $body);
+ } else {
header('Content-Type: text/html; charset=euc-jp');
print <<<EOD
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
// ¸½ºß»þ¹ï¤ò¥Þ¥¤¥¯¥íÉäǼèÆÀ
function getmicrotime()
{
- list($usec, $sec) = explode(' ',microtime());
+ list($usec, $sec) = explode(' ', microtime());
return ((float)$sec + (float)$usec);
}
// Æü»þ¤òÆÀ¤ë
-function get_date($format,$timestamp = NULL)
+function get_date($format, $timestamp = NULL)
{
$time = ($timestamp === NULL) ? UTIME : $timestamp;
$time += ZONETIME;
- $format = preg_replace('/(?<!\\\)T/',preg_replace('/(.)/','\\\$1',ZONE),$format);
+ $format = preg_replace('/(?<!\\\)T/', preg_replace('/(.)/', '\\\$1', ZONE), $format);
- return date($format,$time);
+ return date($format, $time);
}
// Æü»þʸ»úÎó¤òºî¤ë
function format_date($val, $paren = FALSE)
{
- global $date_format,$time_format,$weeklabels;
+ global $date_format, $time_format, $weeklabels;
$val += ZONETIME;
- $ins_date = date($date_format,$val);
- $ins_time = date($time_format,$val);
- $ins_week = '('.$weeklabels[date('w',$val)].')';
+ $ins_date = date($date_format, $val);
+ $ins_time = date($time_format, $val);
+ $ins_week = '(' . $weeklabels[date('w', $val)] . ')';
$ins = "$ins_date $ins_week $ins_time";
return $paren ? "($ins)" : $ins;
// ·Ð²á»þ¹ïʸ»úÎó¤òºî¤ë
function get_passage($time, $paren = TRUE)
{
- static $units = array('m'=>60,'h'=>24,'d'=>1);
+ static $units = array('m'=>60, 'h'=>24, 'd'=>1);
- $time = max(0,(UTIME - $time) / 60); //minutes
+ $time = max(0, (UTIME - $time) / 60); // minutes
- foreach ($units as $unit=>$card)
- {
- if ($time < $card)
- {
- break;
- }
+ foreach ($units as $unit=>$card) {
+ if ($time < $card) break;
$time /= $card;
}
- $time = floor($time).$unit;
+ $time = floor($time) . $unit;
return $paren ? "($time)" : $time;
}
-//<input type="(submit|button|image)"...>¤ò±£¤¹
+// <input type="(submit|button|image)"...>¤ò±£¤¹
function drop_submit($str)
{
return preg_replace(
// AutoLink¤Î¥Ñ¥¿¡¼¥ó¤òÀ¸À®¤¹¤ë
// thx for hirofummy
-function get_autolink_pattern(&$pages)
+function get_autolink_pattern(& $pages)
{
- global $WikiName,$autolink,$nowikiname;
+ global $WikiName, $autolink, $nowikiname;
$config = &new Config('AutoLink');
$config->read();
$ignorepages = $config->get('IgnoreList');
$forceignorepages = $config->get('ForceIgnoreList');
unset($config);
- $auto_pages = array_merge($ignorepages,$forceignorepages);
+ $auto_pages = array_merge($ignorepages, $forceignorepages);
- foreach ($pages as $page)
- {
- if (preg_match("/^$WikiName$/",$page) ?
- $nowikiname : strlen($page) >= $autolink)
- {
+ foreach ($pages as $page) {
+ if (preg_match("/^$WikiName$/", $page) ?
+ $nowikiname : strlen($page) >= $autolink)
$auto_pages[] = $page;
- }
}
- if (count($auto_pages) == 0)
- {
+ if (count($auto_pages) == 0) {
return $nowikiname ? '(?!)' : $WikiName;
}
$auto_pages = array_unique($auto_pages);
- sort($auto_pages,SORT_STRING);
- $auto_pages_a = array_values(preg_grep('/^[A-Z]+$/i',$auto_pages));
- $auto_pages = array_values(array_diff($auto_pages,$auto_pages_a));
+ sort($auto_pages, SORT_STRING);
+
+ $auto_pages_a = array_values(preg_grep('/^[A-Z]+$/i', $auto_pages));
+ $auto_pages = array_values(array_diff($auto_pages, $auto_pages_a));
- $result = get_autolink_pattern_sub($auto_pages,0,count($auto_pages),0);
- $result_a = get_autolink_pattern_sub($auto_pages_a,0,count($auto_pages_a),0);
+ $result = get_autolink_pattern_sub($auto_pages, 0, count($auto_pages), 0);
+ $result_a = get_autolink_pattern_sub($auto_pages_a, 0, count($auto_pages_a), 0);
- return array($result,$result_a,$forceignorepages);
+ return array($result, $result_a, $forceignorepages);
}
-function get_autolink_pattern_sub(&$pages,$start,$end,$pos)
+function get_autolink_pattern_sub(& $pages, $start, $end, $pos)
{
- if ($end == 0)
- {
- return '(?!)';
- }
+ if ($end == 0) return '(?!)';
$result = '';
$count = 0;
for ($i = $start; $i < $end; $i = $j) // What is the initial state of $j?
{
- $char = mb_substr($pages[$i],$pos,1);
- for ($j = $i; $j < $end; $j++)
- {
- if (mb_substr($pages[$j],$pos,1) != $char)
- {
+ $char = mb_substr($pages[$i], $pos, 1);
+ for ($j = $i; $j < $end; $j++) {
+ if (mb_substr($pages[$j], $pos, 1) != $char)
break;
- }
}
- if ($i != $start)
- {
+ if ($i != $start) {
$result .= '|';
}
- if ($i >= ($j - 1))
- {
- $result .= str_replace(' ','\\ ',preg_quote(mb_substr($pages[$i],$pos),'/'));
- }
- else
- {
- $result .=
- str_replace(' ','\\ ',preg_quote($char,'/')).
- get_autolink_pattern_sub($pages,$i,$j,$pos + 1);
+ if ($i >= ($j - 1)) {
+ $result .= str_replace(' ', '\\ ', preg_quote(mb_substr($pages[$i], $pos), '/'));
+ } else {
+ $result .= str_replace(' ', '\\ ', preg_quote($char, '/')) .
+ get_autolink_pattern_sub($pages, $i, $j, $pos + 1);
}
++$count;
}
- if ($x or $count > 1)
- {
- $result = '(?:'.$result.')';
+ if ($x or $count > 1) {
+ $result = '(?:' . $result . ')';
}
- if ($x)
- {
+ if ($x) {
$result .= '?';
}
return $result;
// REQUEST_URI¤ò¥Ñ¡¼¥¹¤·¡¢pathÉôʬ¤À¤±¤ò¼è¤ê½Ð¤¹
$parse_url = parse_url($script.$_SERVER['REQUEST_URI']);
- if (!isset($parse_url['path']) or $parse_url['path']{0} != '/')
+ if (! isset($parse_url['path']) or $parse_url['path']{0} != '/')
return FALSE;
$path = $parse_url['path'];
{
$retval = $matches = array();
- $_separator = preg_quote($separator,'/');
- if (!preg_match_all('/("[^"]*(?:""[^"]*)*"|[^' . $_separator . ']*)' .
+ $_separator = preg_quote($separator, '/');
+ if (! preg_match_all('/("[^"]*(?:""[^"]*)*"|[^' . $_separator . ']*)' .
$_separator . '/', $string . $separator, $matches))
return array();
}
}
-//is_a
-//(PHP 4 >= 4.2.0)
-//
-//is_a -- Returns TRUE if the object is of this class or has this class as one of its parents
-if (!function_exists('is_a'))
+//// Compat ////
+
+// is_a -- Returns TRUE if the object is of this class or has this class as one of its parents
+// (PHP 4 >= 4.2.0)
+if (! function_exists('is_a'))
{
function is_a($class, $match)
{
- if (empty($class))
- {
- return false;
- }
+ if (empty($class)) return false;
+
$class = is_object($class) ? get_class($class) : $class;
- if (strtolower($class) == strtolower($match))
- {
+ if (strtolower($class) == strtolower($match)) {
return true;
+ } else {
+ return is_a(get_parent_class($class), $match); // Recurse
}
- return is_a(get_parent_class($class), $match);
}
}
-//array_fill
-//(PHP 4 >= 4.2.0)
-//
-//array_fill -- Fill an array with values
-
-if (!function_exists('array_fill'))
+// array_fill -- Fill an array with values
+// (PHP 4 >= 4.2.0)
+if (! function_exists('array_fill'))
{
- function array_fill($start_index,$num,$value)
+ function array_fill($start_index, $num, $value)
{
$ret = array();
-
- while ($num-- > 0)
- {
- $ret[$start_index++] = $value;
- }
+ while ($num-- > 0) $ret[$start_index++] = $value;
return $ret;
}
}
-//md5_file
-//(PHP 4 >= 4.2.0)
-//
-//md5_file -- Calculates the md5 hash of a given filename
-
-if (!function_exists('md5_file'))
+// md5_file -- Calculates the md5 hash of a given filename
+// (PHP 4 >= 4.2.0)
+if (! function_exists('md5_file'))
{
function md5_file($filename)
{
- if (!file_exists($filename))
- {
- return FALSE;
- }
+ if (! file_exists($filename)) return FALSE;
+
$fd = fopen($filename, 'rb');
$data = fread($fd, filesize($filename));
fclose($fd);