자기가 자기글에 댓글달면 관리자에게 알림 채택완료
나인티
11년 전
조회 6,160
</p><p><?php
* 알리미 플러그인
*
* @package net.lovelyus.g5.plugin.pushmsg
* @author Chongmyung Park <byfun@byfun.com>
* @copyright Chongmyung Park
* @license GPLv2 License <a href="<a href="http://www.gnu.org/licenses/gpl-2.0.html" target="_blank" rel="noopener noreferrer">http://www.gnu.org/licenses/gpl-2.0.html</a>"><a href="http://www.gnu.org/licenses/gpl-2.0.html" target="_blank" rel="noopener noreferrer">http://www.gnu.org/licenses/gpl-2.0.html</a></a>
* @link <a href="<a href="http://lovelyus.net/" target="_blank" rel="noopener noreferrer">http://lovelyus.net/</a>"><a href="http://lovelyus.net" target="_blank" rel="noopener noreferrer">http://lovelyus.net</a></a>
*/
if (!defined("_GNUBOARD_")) exit; // 개별 페이지 접근 불가 </p><p>define('PUSHMSG_CONFIG_FILE', 'cfg.plugin.pushmsg.php');</p><p>$luPushmsg = new LUPushmsg();
$luPushmsg->hook($gp_scope);</p><p>
function psm_unreads()
{
global $member;
$res = sql_query("SELECT * FROM gpf_pushmsg WHERE receiver='{$member['mb_id']}' AND checked IS NULL ");
$info = array('total'=>0, 'reply'=>0, 'comment'=>0, 'comment_reply'=>0, 'memo'=>0, 'list'=>array());
$info['push_list_link'] = GP_URL.'/do.php?id='.gp_plugin_id(__FILE__).'&act=psm_list';
while($row = sql_fetch_array($res))
{
$info[$row['push_type']]++;
$info['total']++;</p><p> $row['prop'] = $prop = unserialize($row['prop']);
$time = psm_time_ago($row['reg_date'], 1);
switch($row['push_type'])
{
case 'reply' :
$row['subject'] = '<b>'.$row['sender'].'</b>님이 내 BOOKING에 REMARKS을 남기셨습니다.';
$row['link'] = G5_BBS_URL.'/board.php?bo_table='.$prop['bo_table'].'&wr_id='.$prop['wr_id_from'];
break;
case 'comment' :
$row['subject'] = '<b>'.$row['sender'].'</b>님이 내 BOOKING에 REMARKS을 남기셨습니다.';
$row['link'] = G5_BBS_URL.'/board.php?bo_table='.$prop['bo_table'].'&wr_id='.$prop['wr_id_to'].'#c_'.$prop['cmt_id_from'];
break;
case 'comment_reply' :
$row['subject'] = '<b>'.$row['sender'].'</b>님이 내 REMARKS에 REPLY을 남기셨습니다.';
$row['link'] = G5_BBS_URL.'/board.php?bo_table='.$prop['bo_table'].'&wr_id='.$prop['wr_id_to'].'#c_'.$prop['cmt_id_from'];
break;
case 'memo' :
$row['subject'] = '<b>'.$row['sender'].'</b>님으로부터 쪽지가 도착했습니다.';
$row['link'] = G5_BBS_URL.'/memo_view.php?me_id='.$prop['me_id'].'&kind=recv';
break;
default:
$row['subject'] = gp_do_filter('pushmsg_subj', $row);
$row['link'] = gp_do_filter('pushmsg_link', $prop);
break;
}
array_push($info['list'], $row);
}
return $info;
}</p><p>function psm_time_ago($date,$granularity=2) {
$date = strtotime($date);
$difference = time() - $date;
$periods = array(
'십년' => 315360000,
'년' => 31536000,
'월' => 2628000,
'주' => 604800,
'일' => 86400,
'시간' => 3600,
'분' => 60,
'초' => 1);
foreach ($periods as $key => $value) {
if ($difference >= $value) {
$time = floor($difference/$value);
$difference %= $value;
$retval .= ($retval ? ' ' : '').$time.'';
$retval .= (($time > 1) ? $key.'' : $key);
$granularity--;
}
if ($granularity == '0') { break; }
}
return $retval.' 전';
}</p><p>/**
*
*
* @author Chongmyung Park <byfun@byfun.com>
* @copyright Chongmyung Park
* @license GPLv2 License <a href="<a href="http://www.gnu.org/licenses/gpl-2.0.html" target="_blank" rel="noopener noreferrer">http://www.gnu.org/licenses/gpl-2.0.html</a>"><a href="http://www.gnu.org/licenses/gpl-2.0.html" target="_blank" rel="noopener noreferrer">http://www.gnu.org/licenses/gpl-2.0.html</a></a>
* @link <a href="<a href="http://lovelyus.net/" target="_blank" rel="noopener noreferrer">http://lovelyus.net/</a>"><a href="http://lovelyus.net" target="_blank" rel="noopener noreferrer">http://lovelyus.net</a></a>
*/
class LUPushmsg
{
var $id;
var $scope;
var $plugin_url;
var $plugin_path;
var $plugin_config;
var $config_file = PUSHMSG_CONFIG_FILE;
var $do_url;</p><p> /**
* hook : gpf 후킹
*
* @access public
* @return void
*/
function hook($gp_scope)
{
$this->scope = $gp_scope;
$this->id = gp_plugin_id(__FILE__);
$this->plugin_path = dirname(__FILE__);
$this->plugin_url = gp_plugin_url(__FILE__);
$this->plugin_config = gp_read_config($this->config_file, array('uid'=>'mb_id'), $this->scope);</p><p> define('PUSHMSG_UID', $this->plugin_config['uid']);</p><p> $this->do_url = GP_URL . '/do.php?id='.$this->id.'&act=';</p><p> gp_add_filter('gpa_menu_plugin_'.$this->id, array($this, 'plugin_menu'));
gp_add_filter('gpa_settings', array($this, 'plugin_setting'), 10);
gp_add_action('pxa_psm_save_setting', array($this, 'plugin_save_setting'));
gp_add_action('pxa_psm_install', array($this, 'plugin_install'));
gp_add_action('pxa_psm_uninstall', array($this, 'plugin_uninstall'));</p><p> if(basename($_SERVER['SCRIPT_NAME']) == 'memo_form_update.php') set_session('gpf_pushmsg_memo_updated', true);</p><p> gp_add_action('post_write_update', array($this, 'on_write_update'));
gp_add_action('post_write_comment_update', array($this, 'on_write_comment_update'));
gp_add_action('post_memo', array($this, 'on_memo'));</p><p>
foreach(glob($this->plugin_path."/pages/*.php") as $file)
{
$filename = basename($file);
if($filename{0} == '_') continue;
$px = str_replace('.php', '', $filename);
gp_add_action('px_psm_'.$px, array($this, 'on_px'));
}
}</p><p> /**
* 설정페이지에 항목 추가
*
* @param mixed $gpa_settings
* @access public
* @return void
*/
function plugin_setting($gpa_settings)
{
array_push($gpa_settings, array('ID'=>$this->id, 'title'=>'알리미', 'print_contents'=>array($this, 'plugin_config_contents'), 'order'=>10) );
return $gpa_settings;
}</p><p> /**
* 플러그인 설정 페이지
*
* @access public
* @return void
*/
function plugin_config_contents()
{
$plugin_config = $this->plugin_config;
$plugin_id = $this->id;
$plugin_path = $this->plugin_path;
$plugin_url = $this->plugin_url;
include_once $this->plugin_path."/tpl/config.form.php";
}</p><p> /**
* 설정 저장
*
* @access public
* @return void
*/
function plugin_save_setting()
{
global $id;
if($this->id != $id) return;</p><p> gp_write_config($this->config_file, gp_strip_slashes($_REQUEST['plugin_config']), $this->scope );
alert('알리미 플러그인 설정 저장 완료');
}</p><p> function on_px()
{
global $id;
if($this->id != $id) return;</p><p> extract($GLOBALS);
if($is_guest) alert('로그인 후 사용하세요');
$scope = $this->scope;
$plugin_id = $this->id;
$plugin_path = $this->plugin_path;
$plugin_url = $this->plugin_url;
$plugin_config = $this->plugin_config;
$px_url = GP_URL . '/do.php?id='.$this->id;
$inc_file = $this->plugin_path.DS.'pages'.DS.basename(str_replace('psm_', '', $act)).'.php';
if(!file_exists($inc_file)) {
gp_alert('알리미 : 잘못된 접근');
}
include_once $inc_file;
}</p><p> function on_memo()
{
global $list, $kind, $member;</p><p> $sess = get_session('gpf_pushmsg_memo_updated');
set_session('gpf_pushmsg_memo_updated', false);</p><p> if($kind != 'send' || empty($list) || !$sess) return;</p><p> foreach($list as $item)
{
if(substr($item['me_read_datetime'], 0, 1) != 0) continue;
$mb = get_member($item['me_send_mb_id']);
$sender = $mb[PUSHMSG_UID];
$receiver = $item['me_recv_mb_id'];
$me_id = $item['me_id'];
$prop = serialize(compact('me_id'));
if(sql_fetch("SELECT id FROM gpf_pushmsg WHERE push_type='memo' AND prop='{$prop}'")) continue;</p><p> sql_query("INSERT INTO gpf_pushmsg SET
push_type = 'memo'
,sender = '{$sender}'
,receiver = '{$receiver}'
,prop = '{$prop}'
,reg_date = '".G5_TIME_YMDHIS."'
");
}
}</p><p> function on_write_update()
{
global $w, $bo_table, $wr_id, $wr_name, $write, $member;
if($w != 'r' || !$write['mb_id']) return;
$sender = ($member[PUSHMSG_UID] ? $member[PUSHMSG_UID] : $wr_name);
$receiver = $write['mb_id'];</p><p> if($member['mb_id'] == $receiver) return;</p><p> $wr_id_from = $_POST['wr_id'];
$wr_id_to = $wr_id;</p><p> $prop = serialize(compact('bo_table', 'wr_id_from', 'wr_id_to'));</p><p> sql_query("INSERT INTO gpf_pushmsg SET
push_type = 'reply'
,sender = '{$sender}'
,receiver = '{$receiver}'
,prop = '{$prop}'
,reg_date = '".G5_TIME_YMDHIS."'
");
}</p><p> function on_write_comment_update()
{
global $w, $bo_table, $member, $comment_id, $write, $write_table, $wr_name;</p><p> if($w != 'c') return;</p><p> $mb_id_to = '';</p><p> // comment reply
if($_POST['comment_id'])
{
$type = 'comment_reply';
$reply = sql_fetch("select mb_id from $write_table where wr_id = '{$_POST['comment_id']}' ");
$receiver = $reply['mb_id'];
} else {
$type = 'comment';
$receiver = $write['mb_id'];
}</p><p> if(!$receiver) return;</p><p> $sender = ($member[PUSHMSG_UID] ? $member[PUSHMSG_UID] : $wr_name);</p><p> if($member['mb_id'] == $receiver) return;</p><p> $wr_id_to = $_POST['wr_id'];
$cmt_id_to = $_POST['comment_id'];
$cmt_id_from = $comment_id;</p><p> $prop = serialize(compact('bo_table', 'wr_id_to', 'cmt_id_to', 'cmt_id_from'));</p><p> sql_query("INSERT INTO gpf_pushmsg SET
push_type = '{$type}'
,sender = '{$sender}'
,receiver = '{$receiver}'
,prop = '{$prop}'
,reg_date = '".G5_TIME_YMDHIS."'
");
}</p><p> /**
* plugins 페이지에 메뉴 추가
*
* @param mixed $menus
* @access public
* @return void
*/
function plugin_menu($menus)
{
global $bo_table;</p><p> if(gp_table_exists('gpf_pushmsg'))
{
array_push($menus, array('href'=>gp_url('setting.php', $this->scope, $noqm=false, $this->id), 'text'=>'설정'));</p><p> array_push($menus, array('href'=>gp_url('admin_do.php', $this->scope).'&id='.$this->id.'&act=psm_uninstall', 'attr'=>'onclick="return confirm(\'등록된 모든 DB 정보가 삭제됩니다.\\n진행하시겠습니까?\');"', 'text'=>'DB삭제'));</p><p> $res = sql_query("SHOW COLUMNS FROM gpf_pushmsg");
while ($row = sql_fetch_array($res)) {
if($row['Field'] == 'push_type' && strpos($row['Type'], 'enum') !== false)
{
sql_query("ALTER TABLE gpf_pushmsg CHANGE push_type push_type VARCHAR(20) NOT NULL");
break;
}
}
} else {
array_push($menus, array('href'=>gp_url('admin_do.php', $this->scope).'&id='.$this->id.'&act=psm_install', 'text'=>'DB생성', 'attr'=>''));
}
return $menus;
}</p><p>
/**
* 플러그인 설치
*
* @access public
* @return void
*/
function plugin_install()
{
global $id;
if($this->id != $id) return;</p><p> $install_script =<<<EOF
CREATE TABLE IF NOT EXISTS gpf_pushmsg (
id INT NOT NULL AUTO_INCREMENT,
push_type VARCHAR(20) NOT NULL,
sender VARCHAR(50) NOT NULL,
receiver VARCHAR(50) NOT NULL,
prop VARCHAR(255) NOT NULL,
checked BOOL NULL,
reg_date DATETIME NULL,
PRIMARY KEY(id)
) ENGINE=MyISAM DEFAULT CHARSET=utf8;
;
EOF;
$f = explode(";", $install_script);
for ($i=0; $i<count($f); $i++) {
if (trim($f[$i]) == "") continue;
sql_query($f[$i]);
}
goto_url(gp_url('plugins.php', $this->scope));
}</p><p>
/**
* 플러그인 제거
*
* @access public
* @return void
*/
function plugin_uninstall()
{
global $id;
if($this->id != $id) return;</p><p> sql_query("DROP TABLE gpf_pushmsg", false);
gp_deactivate_plugin($this->id, $this->scope);
goto_url(gp_url('plugins.php', $this->scope));
}
}
?>
</p><p>
그누보드 사이트처럼 다른사람이 자기글에 댓글을 달면 알림이 뜨는 플러그인 입니다.
여기서 추가해야 하는 기능이 자기글에 자기가 댓글을 달면 관리자에게 알림이 뜨게해야 합니다.
어떤 소스를 추가해야 가능할까요?
댓글을 작성하려면 로그인이 필요합니다.
답변 2개
채택된 답변
+20 포인트
11년 전
아래 코드처럼 한줄을 주석처리 하시면, 자신이 자신의 글에 댓글을 달아도 알림이 올겁니다.
</p><p> function on_write_comment_update()
{ </p><p> .... </p><p> // if($member['mb_id'] == $receiver) return;</p><p> ....</p><p>} </p><p>
로그인 후 평가할 수 있습니다
답변에 대한 댓글 1개
�
나인티
11년 전
앗 자기가 자신의글에 댓글을 달면 관리자에게 뜨게할 수는 없을까요?
댓글을 작성하려면 로그인이 필요합니다.
11년 전
아래처럼 하면 될듯 합니다
</p><p> </p><pre> function on_write_comment_update()
{
....
....
sql_query("INSERT INTO gpf_pushmsg SET
push_type = '{$type}'
,sender = '{$sender}'
,receiver = '{$receiver}'
,prop = '{$prop}'
,reg_date = '".G5_TIME_YMDHIS."'
");
// 다음 추가
if($member['mb_id'] == $receiver) {
$receiver = '관리자 아이디';
sql_query("INSERT INTO gpf_pushmsg SET
push_type = '{$type}'
,sender = '{$sender}'
,receiver = '{$receiver}'
,prop = '{$prop}'
,reg_date = '".G5_TIME_YMDHIS."'
");
}
}</pre><p>
로그인 후 평가할 수 있습니다
댓글을 작성하려면 로그인이 필요합니다.
답변을 작성하려면 로그인이 필요합니다.
로그인