NHAPPY.NET 델버네 warehouse의 델버님이 작성한 글입니다. 테터툴즈의 기능 추가에 대해 필요한 내용이라 퍼왔습니다. 어제 델버님의 글을 읽고 나도 수정을 했기에…
==================
카테고리 좌측에 일정시간 이내에 새글이 올라왔을 때 new 이미지를 출력하는 팁입니다.
수정 파일은 inc_presswork.php와 inc_function.php입니다.
두개의 함수를 덮어 씌우시면 됩니다.
수정 부분을 강조하려고 했는데 잘 안나오네요^^
1. inc_presswork.php
원본
global $db, $dbid, $p_tree, $p_tree_limit, $s_tree_path;
$g_array = array();
$m_array = array();
$total_cnt = 0;
$sql = "select no, sortno, label, cnt from t3_".$dbid."_ct1 order by sortno asc";
$result = @mysql_query($sql);
while(list($pno, $psortno, $plabel, $pcnt) = @mysql_fetch_array($result)) {
$sql = "select no, sortno, label, cnt from t3_".$dbid."_ct2 where pno = $pno order by sortno asc";
$result2 = @mysql_query($sql);
while(list($no, $sortno, $label, $cnt) = @mysql_fetch_array($result2)) {
array_push($m_array, array("num"=>$no, "label"=>$label, "link"=>"location.href='index.php?ct1=$pno&ct2=$no';", "cnt"=>$cnt));
}
array_push($g_array , array("num"=>$pno, "label"=>$plabel, "link"=>"location.href='index.php?ct1=$pno';", "cnt"=>$pcnt, "items"=>$m_array));
$m_array = array();
$total_cnt += $pcnt;
}
$rtval = array("label"=>"분류 전체보기", "link"=>"location.href='index.php?ct1=-1';", "cnt" => $total_cnt);
if (count($g_array)) {
ob_start();
print_tree($rtval, $g_array, $p_tree_limit, $s_tree_path.$p_tree."/",0);
$tree_str = ob_get_contents();
ob_end_clean();
}
return $tree_str;
}[/CODE]
수정 후
아래 보시면 바로 아래와 같은 각각의 코드를 볼 수 있습니다.
$sub_new_image와 $main_new_image에 /tt/images/new.gif 와 같이 이미지가 있는 경로를 넣어주세요.
[CODE]$today=" <img src=$sub_new_image hspace=0 vspace=0 border=0 align=absmiddle>";
$today=" <img src=$main_new_image hspace=0 align=absmiddle vspace=0 border=0>";[/CODE]
global $db, $dbid, $p_tree, $p_tree_limit, $s_tree_path;
global $main_new_image, $sub_new_image;
$g_array = array();
$m_array = array();
$c_array = get_today_article();
$total_cnt = 0;
$sql = "select no, sortno, label, cnt from t3_".$dbid."_ct1 order by sortno asc";
$result = @mysql_query($sql);
while(list($pno, $psortno, $plabel, $pcnt) = @mysql_fetch_array($result)) {
$sql = "select no, sortno, label, cnt from t3_".$dbid."_ct2 where pno = $pno order by sortno asc";
$result2 = @mysql_query($sql);
$category_count = 0;
while(list($no, $sortno, $label, $cnt) = @mysql_fetch_array($result2)) {
if($c_array[$pno][$no]!=0)
$today=" <img src=$sub_new_image hspace=0 vspace=0 border=0 align=absmiddle>";
else
$today="";
array_push($m_array, array("num"=>$no, "label"=>$label, "link"=>"location.href='index.php?ct1=$pno&ct2=$no';", "cnt"=>$cnt, "today"=>$today));
}
if(count($c_array[$pno])>0)
$today=" <img src=$main_new_image hspace=0 align=absmiddle vspace=0 border=0>";
else
$today="";
array_push($g_array , array("num"=>$pno, "label"=>$plabel, "link"=>"location.href='index.php?ct1=$pno';", "cnt"=>$pcnt, "items"=>$m_array, "ptoday"=>$today));
$m_array = array();
$total_cnt += $pcnt;
}
$rtval = array("label"=>"전체보기", "link"=>"location.href='index.php?ct1=-1';", "cnt" => $total_cnt);
if (count($g_array)) {
ob_start();
print_tree($rtval, $g_array, $p_tree_limit, $s_tree_path.$p_tree."/",0);
$tree_str = ob_get_contents();
ob_end_clean();
}
return $tree_str;
}[/CODE]
2. inc_function.php
아래의 함수를 파일 하단에 추가합니다.
* 오늘 쓴 글이 있는지 체크하는 함수
**************************************/
function get_today_article(){
global $dbid;
// $today = mktime(0,0,0,date(m),date(d),date(Y)) – 86400;
//현재 시간에서 하루 빼기
$today = time() – 24*60*60;
$sql = "select category1, category2 from t3_".$dbid." where regdate > '$today' and is_public = '1'";
$result = mysql_query($sql);
while(list($cat1, $cat2)=mysql_fetch_array($result)){
$c_array[$cat1][$cat2]= 1;
}
return $c_array;
}[/CODE]
변경되는 함수의 변경 전/후입니다.
원본
global $p_tree_back, $p_tree_c, $p_tree_bc, $p_tree_c2, $p_tree_bc2, $p_show_tree_cnt;
?>
<script type="text/javascript">
var t_ary = new Array();
var d_ary = new Array();
t_ary = t_ary.concat('imp');
<?
foreach ($trval as $row) {
?>
t_ary = t_ary.concat('imp<?=$row[num]?>');
d_ary = d_ary.concat([['<?=$row[num]?>', '<?=count($row[items])?>']]);
<?
foreach ($row[items] as $irow) {
?> t_ary = t_ary.concat('imp<?=$row[num]."_".$irow[num]?>'); <?
}
}
?>
var c_ary = new Array();
c_ary = c_ary.concat('<?=$p_tree_c?>');
c_ary = c_ary.concat('<?=$p_tree_c2?>');
c_ary = c_ary.concat('<?=$p_tree_bc?>');
c_ary = c_ary.concat('<?=$p_tree_bc2?>');
var ac = '0';
</script>
<table cellpadding="0" cellspacing="0" width="100%" bgcolor="<?=$p_tree_back?>"><tr><td>
<table cellpadding=0 cellspacing=0><tr>
<td width=0><img class=ib src="<?=$tree_path?>tab_top.gif" width=16 onclick="if (ac == '0') { ac = 1; } else { ac = 0; } onclick_all_process(window, '<?=$tree_path?>', ac, d_ary);" alt=""></td>
<td valign=top style="font-size:9pt; padding-left:3px;">
<table class=branch2 onclick="<? if ($action == 1) { ?> onclick_setimp(window, this, c_ary, t_ary); <? } ?>" id=imp cellpadding=0 cellspacing=0 style="color:<?=$p_tree_c?>;background-color:<?=$p_tree_bc?>;"><tr>
<td class=branch3 height="18" onclick="<?=$rtval[link]?>"><?=$rtval[label]?> <? if ($p_show_tree_cnt) print "<span class=c_cnt>($rtval[cnt])</span>";?></td>
</tr></table>
</td>
</tr></table>
<?
$i = count($trval);
foreach ($trval as $row) {
$i–;
?>
<table cellpadding=0 cellspacing=0><tr>
<td class=branch3 width=39 style="background-image:url('<?=$tree_path?>navi_back_noactive<? if (!$i) print "_end"; ?>.gif')"><a class=click onclick="onclick_folder(document.getElementById('hidden_category<?=$row[num]?>'), document.getElementById('folder<?=$row[num]?>'), '<?=$tree_path?>', '<? if (count($row[items])) print "1"; else print "0"; ?>')"><img id=folder<?=$row[num]?> src="<?=$tree_path?>tab_<? if (count($row[items])) print "closed"; else print "none"; ?>.gif" width=39 height=17 alt=""></a></td>
<td>
<table class=branch2 cellpadding=0 cellspacing=0 onclick="<? if ($action == 1) { ?> onclick_setimp(window, this, c_ary, t_ary); <? } ?>" id="imp<?=$row[num]?>" style="color:<?=$p_tree_c?>;background-color:<?=$p_tree_bc?>;"><tr>
<td class=branch3 onclick="<?=$row[link]?>"><?=str_cut($row[label],$limit,1)?> <? if ($p_show_tree_cnt) print "<span class=c_cnt>($row[cnt])</span>";?></td>
</tr></table>
</td>
</tr></table>
<div id=hidden_category<?=$row[num]?> style=display:none>
<?
$j = count($row[items]);
foreach ($row[items] as $irow) {
$j–;
?>
<table cellpadding=0 cellspacing=0><tr>
<td width=39><img src="<?=$tree_path?>navi_back_active<? if (!$i) print "_end"; ?>.gif" width=17 height=18 alt=""><img src="<?=$tree_path?>tab_treed<? if (!$j) print "_end"; ?>.gif" width=22 height=18 alt=""></td>
<td>
<table class=branch2 border=0 onclick="<? if ($action == 1) { ?> onclick_setimp(window, this, c_ary, t_ary); <? } ?> <?=$irow[link]?>" id=imp<?=$row[num]."_".$irow[num]?> cellpadding=0 cellspacing=0 style="color:<?=$p_tree_c?>;background-color:<?=$p_tree_bc?>;"><tr>
<td class=branch3><?=str_cut($irow[label], $limit, 1)?> <? if ($p_show_tree_cnt) print "<span class=c_cnt>($irow[cnt])</span>";?></td>
</tr></table>
</td>
</tr></table>
<?
}
?></div><?
}
?></td></tr></table><?
}[/CODE]
수정 후
global $p_tree_back, $p_tree_c, $p_tree_bc, $p_tree_c2, $p_tree_bc2, $p_show_tree_cnt;
?>
<script type="text/javascript">
var t_ary = new Array();
var d_ary = new Array();
t_ary = t_ary.concat('imp');
<?
foreach ($trval as $row) {
?>
t_ary = t_ary.concat('imp<?=$row[num]?>');
d_ary = d_ary.concat([['<?=$row[num]?>', '<?=count($row[items])?>']]);
<?
foreach ($row[items] as $irow) {
?> t_ary = t_ary.concat('imp<?=$row[num]."_".$irow[num]?>'); <?
}
}
?>
var c_ary = new Array();
c_ary = c_ary.concat('<?=$p_tree_c?>');
c_ary = c_ary.concat('<?=$p_tree_c2?>');
c_ary = c_ary.concat('<?=$p_tree_bc?>');
c_ary = c_ary.concat('<?=$p_tree_bc2?>');
var ac = '0';
</script>
<table cellpadding="0" cellspacing="0" width="100%" bgcolor="<?=$p_tree_back?>"><tr><td>
<table cellpadding=0 cellspacing=0><tr>
<td width=0><img class=ib src="<?=$tree_path?>tab_top.gif" width=16 onclick="if (ac == '0') { ac = 1; } else { ac = 0; } onclick_all_process(window, '<?=$tree_path?>', ac, d_ary);" alt=""></td>
<td valign=top style="font-size:9pt; padding-left:3px;">
<table class=branch2 onclick="<? if ($action == 1) { ?> onclick_setimp(window, this, c_ary, t_ary); <? } ?>" id=imp cellpadding=0 cellspacing=0 style="color:<?=$p_tree_c?>;background-color:<?=$p_tree_bc?>;"><tr>
<td class=branch3 height="18" onclick="<?=$rtval[link]?>"><?=$rtval[label]?> <? if ($p_show_tree_cnt) print "<span class=c_cnt>($rtval[cnt])</span>";?></td>
</tr></table>
</td>
</tr></table>
<?
$i = count($trval);
foreach ($trval as $row) {
$i–;
?>
<table cellpadding=0 cellspacing=0><tr>
<td class=branch3 width=39 style="background-image:url('<?=$tree_path?>navi_back_noactive<? if (!$i) print "_end"; ?>.gif')"><a class=click onclick="onclick_folder(document.getElementById('hidden_category<?=$row[num]?>'), document.getElementById('folder<?=$row[num]?>'), '<?=$tree_path?>', '<? if (count($row[items])) print "1"; else print "0"; ?>')"><img id=folder<?=$row[num]?> src="<?=$tree_path?>tab_<? if (count($row[items])) print "closed"; else print "none"; ?>.gif" width=39 height=17 alt=""></a></td>
<td>
<table class=branch2 cellpadding=0 cellspacing=0 onclick="<? if ($action == 1) { ?> onclick_setimp(window, this, c_ary, t_ary); <? } ?>" id="imp<?=$row[num]?>" style="color:<?=$p_tree_c?>;background-color:<?=$p_tree_bc?>;"><tr>
<td class=branch3 onclick="<?=$row[link]?>"><?=str_cut($row[label],$limit,1)?> <? if ($p_show_tree_cnt) print "<span class=c_cnt>($row[cnt])</span>";?></td><td><?=$row[ptoday]?></td>
</tr></table>
</td>
</tr></table>
<div id=hidden_category<?=$row[num]?> style=display:none>
<?
$j = count($row[items]);
foreach ($row[items] as $irow) {
$j–;
?>
<table cellpadding=0 cellspacing=0><tr>
<td width=39><img src="<?=$tree_path?>navi_back_active<? if (!$i) print "_end"; ?>.gif" width=17 height=18 alt=""><img src="<?=$tree_path?>tab_treed<? if (!$j) print "_end"; ?>.gif" width=22 height=18 alt=""></td>
<td>
<table class=branch2 border=0 onclick="<? if ($action == 1) { ?> onclick_setimp(window, this, c_ary, t_ary); <? } ?> <?=$irow[link]?>" id=imp<?=$row[num]."_".$irow[num]?> cellpadding=0 cellspacing=0 style="color:<?=$p_tree_c?>;background-color:<?=$p_tree_bc?>;"><tr>
<td class=branch3><?=str_cut($irow[label], $limit, 1)?> <? if ($p_show_tree_cnt) print "<span class=c_cnt>($irow[cnt])</span>";?></td><td><?=$irow[today]?></td>
</tr></table>
</td>
</tr></table>
<?
}
?></div><?
}
?></td></tr></table>
<?
}[/CODE]
[이 게시물은 라이노님에 의해 2008-04-15 18:57:52 홈페이지관리에서 이동 됨]