This commit is contained in:
2013-04-02 01:03:29 +08:00
parent 5b5e2c4d66
commit 0a2903e20d
5 changed files with 230 additions and 230 deletions

View File

@@ -1,6 +1,6 @@
emlog 读者墙插件 emlog 读者墙插件
==================== ====================
貌似没什么好介绍的了最初模仿的是wordpress的读者墙其实就是模仿wordpress的根据emlog的特殊性移植过来。有周读者墙月读者墙总读者墙取决于你怎么调用。 貌似没什么好介绍的了最初模仿的是wordpress的读者墙其实就是模仿wordpress的根据emlog的特殊性移植过来。有周读者墙月读者墙总读者墙取决于你怎么调用。
[插件主页](http://xiaosong.org/share/emlog-readers-wall-plug-reloaded) [插件主页](http://xiaosong.org/share/emlog-readers-wall-plug-reloaded)

View File

@@ -1,109 +1,109 @@
<?php <?php
/* /*
Plugin Name: 读者墙 Plugin Name: 读者墙
Version: 4.2.3 Version: 4.2.3
Plugin URL: http://xiaosong.org/share/emlog-readers-wall-plug-reloaded Plugin URL: http://xiaosong.org/share/emlog-readers-wall-plug-reloaded
Description: 页面或文章正文,侧边栏显示读者墙 Description: 页面或文章正文,侧边栏显示读者墙
ForEmlog: 4.1.0以上 ForEmlog: 4.1.0以上
Author: 小松 Author: 小松
Author Email: sahala_2007@126.com Author Email: sahala_2007@126.com
Author URL: http://xiaosong.org Author URL: http://xiaosong.org
*/ */
!defined('EMLOG_ROOT') && exit('access deined!'); !defined('EMLOG_ROOT') && exit('access deined!');
require_once('reader_wall_config.php'); require_once('reader_wall_config.php');
function reader_wall(){ function reader_wall(){
global $imgnum_week,$imgnum_month,$imgnum_all,$imgsize_week,$imgsize_month,$imgsize_all,$tip; global $imgnum_week,$imgnum_month,$imgnum_all,$imgsize_week,$imgsize_month,$imgsize_all,$tip;
$CACHE = Cache::getInstance(); $CACHE = Cache::getInstance();
$user_cache = $CACHE->readCache('user'); $user_cache = $CACHE->readCache('user');
$content = ob_get_clean(); $content = ob_get_clean();
if (Option::get('isgzipenable') == 'y' && function_exists('ob_gzhandler')){ if (Option::get('isgzipenable') == 'y' && function_exists('ob_gzhandler')){
ob_start('ob_gzhandler'); ob_start('ob_gzhandler');
} else { } else {
ob_start(); ob_start();
} }
$content = explode("<body",$content); $content = explode("<body",$content);
$log_content = $content[1]; $log_content = $content[1];
if(strpos($log_content, '[READERWALL-WEEK]') > -1) { if(strpos($log_content, '[READERWALL-WEEK]') > -1) {
$cur_time_span = strtotime('last Monday',strtotime('Sunday')); $cur_time_span = strtotime('last Monday',strtotime('Sunday'));
$option = 0; $option = 0;
$imgnums = $imgnum_week; $imgnums = $imgnum_week;
$imgsize = $imgsize_week; $imgsize = $imgsize_week;
} }
elseif(strpos($log_content, '[READERWALL-MONTH]') > -1){ elseif(strpos($log_content, '[READERWALL-MONTH]') > -1){
$cur_time_span = strtotime('this month',strtotime(date('m/01/y'))); $cur_time_span = strtotime('this month',strtotime(date('m/01/y')));
$option = 1; $option = 1;
$imgnums = $imgnum_month; $imgnums = $imgnum_month;
$imgsize = $imgsize_month; $imgsize = $imgsize_month;
} }
else{$cur_time_span = 0;$option = 2;$imgnums = $imgnum_all;$imgsize = $imgsize_all;} else{$cur_time_span = 0;$option = 2;$imgnums = $imgnum_all;$imgsize = $imgsize_all;}
if(empty($imgsize)){$imgsize = 32;} if(empty($imgsize)){$imgsize = 32;}
$DB = MySql::getInstance(); $DB = MySql::getInstance();
$userName = $user_cache[1]['name']; $userName = $user_cache[1]['name'];
$userMail = $user_cache[1]['mail']; $userMail = $user_cache[1]['mail'];
$sql = "SELECT count(1) AS comment_nums,poster,mail,url FROM ".DB_PREFIX."comment where date > $cur_time_span and mail != '' and mail != '$userMail' and poster != '$userName' and hide = 'n' group by mail order by comment_nums DESC limit 0,$imgnums"; $sql = "SELECT count(1) AS comment_nums,poster,mail,url FROM ".DB_PREFIX."comment where date > $cur_time_span and mail != '' and mail != '$userMail' and poster != '$userName' and hide = 'n' group by mail order by comment_nums DESC limit 0,$imgnums";
$result = $DB->query($sql); $result = $DB->query($sql);
while($row = $DB->fetch_array($result)){ while($row = $DB->fetch_array($result)){
$img = "<img width='".$imgsize."' height='".$imgsize."' title='".$row['poster']." (".$row['comment_nums'].")' alt='' src='".getGravatar($row['mail'],$imgsize)."' />"; $img = "<img width='".$imgsize."' height='".$imgsize."' title='".$row['poster']." (".$row['comment_nums'].")' alt='' src='".getGravatar($row['mail'],$imgsize)."' />";
if($row['url']){ if($row['url']){
$tmp = "<a href='".$row['url']."' target='_blank'>".$img."</a>"; $tmp = "<a href='".$row['url']."' target='_blank'>".$img."</a>";
}else{$tmp = $img;} }else{$tmp = $img;}
$output .= $tmp; $output .= $tmp;
} }
if(empty($output)){ if(empty($output)){
$output = "<p style='text-align:center'>".$tip."</p>"; $output = "<p style='text-align:center'>".$tip."</p>";
}else{ }else{
$output = "<div id='readerswall'>".$output."</div>";} $output = "<div id='readerswall'>".$output."</div>";}
if($option == 0) if($option == 0)
$log_content = preg_replace("'\[READERWALL-WEEK\]'i", $output, $log_content, 1); $log_content = preg_replace("'\[READERWALL-WEEK\]'i", $output, $log_content, 1);
elseif($option == 1) elseif($option == 1)
$log_content = preg_replace("'\[READERWALL-MONTH\]'i", $output, $log_content, 1); $log_content = preg_replace("'\[READERWALL-MONTH\]'i", $output, $log_content, 1);
else else
$log_content = preg_replace("'\[READERWALL\]'i", $output, $log_content, 1); $log_content = preg_replace("'\[READERWALL\]'i", $output, $log_content, 1);
echo $content[0].'<body'.$log_content; echo $content[0].'<body'.$log_content;
unset($content); unset($content);
unset($log_content); unset($log_content);
} }
addAction('index_footer', 'reader_wall'); addAction('index_footer', 'reader_wall');
function reader_wall_side(){ function reader_wall_side(){
global $imgsize_side,$imgnum_side,$type_wall,$tip,$open; global $imgsize_side,$imgnum_side,$type_wall,$tip,$open;
$CACHE = Cache::getInstance(); $CACHE = Cache::getInstance();
$user_cache = $CACHE->readCache('user'); $user_cache = $CACHE->readCache('user');
if($type_wall == 'week'){ if($type_wall == 'week'){
$time_side = strtotime('last Monday',strtotime('Sunday')); $time_side = strtotime('last Monday',strtotime('Sunday'));
}elseif($type_wall == 'month'){ }elseif($type_wall == 'month'){
$time_side = strtotime('this month',strtotime(date('m/01/y'))); $time_side = strtotime('this month',strtotime(date('m/01/y')));
}else{ }else{
$time_side = 0; $time_side = 0;
} }
if(empty($imgsize_side)){ if(empty($imgsize_side)){
$imgsize_side = 32; $imgsize_side = 32;
} }
$DB = MySql::getInstance(); $DB = MySql::getInstance();
$userName = $user_cache[1]['name']; $userName = $user_cache[1]['name'];
$sql_side = "SELECT count(1) AS comment_nums,poster,mail,url FROM ".DB_PREFIX."comment where date > $time_side and mail != '' and poster != '$userName' and hide ='n' group by mail order by comment_nums DESC limit 0,$imgnum_side"; $sql_side = "SELECT count(1) AS comment_nums,poster,mail,url FROM ".DB_PREFIX."comment where date > $time_side and mail != '' and poster != '$userName' and hide ='n' group by mail order by comment_nums DESC limit 0,$imgnum_side";
$result_side = $DB->query($sql_side); $result_side = $DB->query($sql_side);
while($row_side = $DB->fetch_array($result_side)){ while($row_side = $DB->fetch_array($result_side)){
$img_side = "<img width='".$imgsize_side."' height='".$imgsize_side."' title='".$row_side['poster']." (".$row_side['comment_nums'].")' alt='' src='".getGravatar($row_side['mail'],$imgsize_side)."' />"; $img_side = "<img width='".$imgsize_side."' height='".$imgsize_side."' title='".$row_side['poster']." (".$row_side['comment_nums'].")' alt='' src='".getGravatar($row_side['mail'],$imgsize_side)."' />";
if($row_side['url']){ if($row_side['url']){
$tmp_side = "<a href='".$row_side['url']."' target='_blank'>".$img_side."</a>"; $tmp_side = "<a href='".$row_side['url']."' target='_blank'>".$img_side."</a>";
}else{ }else{
$tmp_side = $img_side; $tmp_side = $img_side;
} }
$output_side .= $tmp_side; $output_side .= $tmp_side;
} }
if(empty($output_side)){ if(empty($output_side)){
$output_side = "<p style='text-align:center'>".$tip."</p>"; $output_side = "<p style='text-align:center'>".$tip."</p>";
}else{ }else{
$output_side = "<div id='readerswall_side'>".$output_side."</div>"; $output_side = "<div id='readerswall_side'>".$output_side."</div>";
} }
return $output_side; return $output_side;
} }
if(isset($_GET['reader_wall_widgets'])){ if(isset($_GET['reader_wall_widgets'])){
echo 'document.write("'.reader_wall_side().'")'; echo 'document.write("'.reader_wall_side().'")';
exit; exit;
} }
function reader_wall_menu(){ function reader_wall_menu(){
echo '<div class="sidebarsubmenu" id="reader_wall"><a href="./plugin.php?plugin=reader_wall">读者墙设置</a></div>'; echo '<div class="sidebarsubmenu" id="reader_wall"><a href="./plugin.php?plugin=reader_wall">读者墙设置</a></div>';
} }
addAction('adm_sidebar_ext', 'reader_wall_menu'); addAction('adm_sidebar_ext', 'reader_wall_menu');
?> ?>

View File

@@ -1,28 +1,28 @@
<?php <?php
if(!defined('EMLOG_ROOT')) {exit('error!');} if(!defined('EMLOG_ROOT')) {exit('error!');}
function callback_init(){ function callback_init(){
$CACHE = Cache::getInstance(); $CACHE = Cache::getInstance();
$DB = MySql::getInstance(); $DB = MySql::getInstance();
$options_cache = $CACHE->readCache('options'); $options_cache = $CACHE->readCache('options');
//写入widgest //写入widgest
$custom_widget = $options_cache['custom_widget'] ? @unserialize($options_cache['custom_widget']) : array(); $custom_widget = $options_cache['custom_widget'] ? @unserialize($options_cache['custom_widget']) : array();
$reader_wall_widgets_content = '<script type="text/javascript" src="'.BLOG_URL.'index.php?reader_wall_widgets"></script>'; $reader_wall_widgets_content = '<script type="text/javascript" src="'.BLOG_URL.'index.php?reader_wall_widgets"></script>';
if(is_array($custom_widget)) if(is_array($custom_widget))
{ {
if(!in_array('custom_wg_reader_wall',array_keys($custom_widget))) if(!in_array('custom_wg_reader_wall',array_keys($custom_widget)))
{ {
//添加 //添加
$custom_wg_index = 'custom_wg_reader_wall'; $custom_wg_index = 'custom_wg_reader_wall';
$custom_widget[$custom_wg_index] = array('title'=>"读者墙",'content'=>$reader_wall_widgets_content); $custom_widget[$custom_wg_index] = array('title'=>"读者墙",'content'=>$reader_wall_widgets_content);
$custom_widget_str = addslashes(serialize($custom_widget)); $custom_widget_str = addslashes(serialize($custom_widget));
$DB->query("update ".DB_PREFIX."options set option_value='$custom_widget_str' where option_name='custom_widget'"); $DB->query("update ".DB_PREFIX."options set option_value='$custom_widget_str' where option_name='custom_widget'");
//启用 //启用
$widgets = !empty($options_cache['widgets1']) ? unserialize($options_cache['widgets1']) : array(); $widgets = !empty($options_cache['widgets1']) ? unserialize($options_cache['widgets1']) : array();
$widgets[] = "custom_wg_reader_wall"; $widgets[] = "custom_wg_reader_wall";
$widgets = serialize($widgets); $widgets = serialize($widgets);
$DB->query("update ".DB_PREFIX."options set option_value='$widgets' where option_name='widgets1'"); $DB->query("update ".DB_PREFIX."options set option_value='$widgets' where option_name='widgets1'");
$CACHE->updateCache('options'); $CACHE->updateCache('options');
} }
} }
} }
?> ?>

View File

@@ -1,12 +1,12 @@
<?php <?php
$imgnum_week = 20; $imgnum_week = 20;
$imgsize_week = 32; $imgsize_week = 32;
$imgnum_month = 30; $imgnum_month = 30;
$imgsize_month = 32; $imgsize_month = 32;
$imgnum_all = 40; $imgnum_all = 40;
$imgsize_all = 32; $imgsize_all = 32;
$imgnum_side = 8; $imgnum_side = 8;
$imgsize_side = 32; $imgsize_side = 32;
$type_wall = 'all'; $type_wall = 'all';
$tip = '墙上还没人,快抢沙发啦~'; $tip = '墙上还没人,快抢沙发啦~';
?> ?>

View File

@@ -1,80 +1,80 @@
<?php <?php
/* /*
* 读者墙插件 * 读者墙插件
* design by 小松 * design by 小松
*/ */
function plugin_setting_view(){ function plugin_setting_view(){
require_once('reader_wall_config.php'); require_once('reader_wall_config.php');
} }
?> ?>
<script type="text/javascript"> <script type="text/javascript">
$("#reader_wall").addClass('sidebarsubmenu1'); $("#reader_wall").addClass('sidebarsubmenu1');
</script> </script>
<div class="containertitle"><b>读者墙设置</b> <div class="containertitle"><b>读者墙设置</b>
<?php if(isset($_GET['setting'])):?><span class="actived">插件设置完成</span><?php endif;?> <?php if(isset($_GET['setting'])):?><span class="actived">插件设置完成</span><?php endif;?>
</div> </div>
<div class="line"></div> <div class="line"></div>
<form action="plugin.php?plugin=reader_wall&action=setting" method="post"> <form action="plugin.php?plugin=reader_wall&action=setting" method="post">
<div> <div>
<p>①、一周评论排行显示头像数: <p>①、一周评论排行显示头像数:
<input size="3" name="imgnum_week" type="text" value="<?php echo $imgnum_week; ?>" /> <input size="3" name="imgnum_week" type="text" value="<?php echo $imgnum_week; ?>" />
&nbsp;&nbsp;头像大小单位为px &nbsp;&nbsp;头像大小单位为px
<input size="3" name="imgsize_week" type="text" value="<?php echo $imgsize_week; ?>" /> <input size="3" name="imgsize_week" type="text" value="<?php echo $imgsize_week; ?>" />
</p> </p>
<p>②、一月评论排行显示头像数: <p>②、一月评论排行显示头像数:
<input size="3" name="imgnum_month" type="text" value="<?php echo $imgnum_month; ?>" /> <input size="3" name="imgnum_month" type="text" value="<?php echo $imgnum_month; ?>" />
&nbsp;&nbsp;头像大小单位为px &nbsp;&nbsp;头像大小单位为px
<input size="3" name="imgsize_month" type="text" value="<?php echo $imgsize_month; ?>" /> <input size="3" name="imgsize_month" type="text" value="<?php echo $imgsize_month; ?>" />
</p> </p>
<p>③、开博至今评论排行显示头像数: <p>③、开博至今评论排行显示头像数:
<input size="3" name="imgnum_all" type="text" value="<?php echo $imgnum_all; ?>" /> <input size="3" name="imgnum_all" type="text" value="<?php echo $imgnum_all; ?>" />
&nbsp;&nbsp;头像大小单位为px &nbsp;&nbsp;头像大小单位为px
<input size="3" name="imgsize_all" type="text" value="<?php echo $imgsize_all; ?>" /> <input size="3" name="imgsize_all" type="text" value="<?php echo $imgsize_all; ?>" />
</p> </p>
<p>④、侧边栏评论排行显示头像数: <p>④、侧边栏评论排行显示头像数:
<input size="3" name="imgnum_side" type="text" value="<?php echo $imgnum_side; ?>" /> <input size="3" name="imgnum_side" type="text" value="<?php echo $imgnum_side; ?>" />
&nbsp;&nbsp;头像大小单位为px &nbsp;&nbsp;头像大小单位为px
<input size="3" name="imgsize_side" type="text" value="<?php echo $imgsize_side; ?>" /> <input size="3" name="imgsize_side" type="text" value="<?php echo $imgsize_side; ?>" />
&nbsp;&nbsp;统计区间: &nbsp;&nbsp;统计区间:
<select name="type_wall"> <select name="type_wall">
<option value="week"<?php if($type_wall == 'week'):?> selected<?php endif;?>>week</option> <option value="week"<?php if($type_wall == 'week'):?> selected<?php endif;?>>week</option>
<option value="month"<?php if($type_wall == 'month'):?> selected<?php endif;?>>month</option> <option value="month"<?php if($type_wall == 'month'):?> selected<?php endif;?>>month</option>
<option value="all"<?php if($type_wall == 'all'):?> selected<?php endif;?>>all</option> <option value="all"<?php if($type_wall == 'all'):?> selected<?php endif;?>>all</option>
</select> </select>
</p> </p>
<p>⑤、如果统计区间内数据为空,则显示如下: <p>⑤、如果统计区间内数据为空,则显示如下:
<input size="50" name="tip" type="text" value="<?php echo $tip; ?>" /> <input size="50" name="tip" type="text" value="<?php echo $tip; ?>" />
</p> </p>
<p><input type="submit" value="保 存" class="submit" /></p> <p><input type="submit" value="保 存" class="submit" /></p>
</div> </div>
</form> </form>
<?php <?php
function plugin_setting(){ function plugin_setting(){
$imgnum_week = isset($_POST['imgnum_week']) ? intval($_POST['imgnum_week']) : 20; $imgnum_week = isset($_POST['imgnum_week']) ? intval($_POST['imgnum_week']) : 20;
$imgsize_week = isset($_POST['imgsize_week']) ? intval($_POST['imgsize_week']) : 32; $imgsize_week = isset($_POST['imgsize_week']) ? intval($_POST['imgsize_week']) : 32;
$imgnum_month = isset($_POST['imgnum_month']) ? intval($_POST['imgnum_month']) : 30; $imgnum_month = isset($_POST['imgnum_month']) ? intval($_POST['imgnum_month']) : 30;
$imgsize_month = isset($_POST['imgsize_month']) ? intval($_POST['imgsize_month']) : 32; $imgsize_month = isset($_POST['imgsize_month']) ? intval($_POST['imgsize_month']) : 32;
$imgnum_all = isset($_POST['imgnum_all']) ? intval($_POST['imgnum_all']) : 40; $imgnum_all = isset($_POST['imgnum_all']) ? intval($_POST['imgnum_all']) : 40;
$imgsize_all = isset($_POST['imgsize_all']) ? intval($_POST['imgsize_all']) : 32; $imgsize_all = isset($_POST['imgsize_all']) ? intval($_POST['imgsize_all']) : 32;
$imgnum_side = isset($_POST['imgnum_side']) ? intval($_POST['imgnum_side']) : 8; $imgnum_side = isset($_POST['imgnum_side']) ? intval($_POST['imgnum_side']) : 8;
$imgsize_side = isset($_POST['imgsize_side']) ? intval($_POST['imgsize_side']) : 32; $imgsize_side = isset($_POST['imgsize_side']) ? intval($_POST['imgsize_side']) : 32;
$type_wall = isset($_POST['type_wall']) ? addslashes(trim($_POST['type_wall'])) : ''; $type_wall = isset($_POST['type_wall']) ? addslashes(trim($_POST['type_wall'])) : '';
$tip = isset($_POST['tip']) ? addslashes(trim($_POST['tip'])) : ''; $tip = isset($_POST['tip']) ? addslashes(trim($_POST['tip'])) : '';
$data = "<?php $data = "<?php
\$imgnum_week = ".$imgnum_week."; \$imgnum_week = ".$imgnum_week.";
\$imgsize_week = ".$imgsize_week."; \$imgsize_week = ".$imgsize_week.";
\$imgnum_month = ".$imgnum_month."; \$imgnum_month = ".$imgnum_month.";
\$imgsize_month = ".$imgsize_month."; \$imgsize_month = ".$imgsize_month.";
\$imgnum_all = ".$imgnum_all."; \$imgnum_all = ".$imgnum_all.";
\$imgsize_all = ".$imgsize_all."; \$imgsize_all = ".$imgsize_all.";
\$imgnum_side = ".$imgnum_side."; \$imgnum_side = ".$imgnum_side.";
\$imgsize_side = ".$imgsize_side."; \$imgsize_side = ".$imgsize_side.";
\$type_wall = '".$type_wall."'; \$type_wall = '".$type_wall."';
\$tip = '".$tip."'; \$tip = '".$tip."';
?>"; ?>";
$file = EMLOG_ROOT.'/content/plugins/reader_wall/reader_wall_config.php'; $file = EMLOG_ROOT.'/content/plugins/reader_wall/reader_wall_config.php';
@ $fp = fopen($file, 'wb') OR emMsg('读取文件失败如果您使用的是Unix/Linux主机请修改文件/content/plugins/reader_wall/reader_wall_config.php的权限为777。如果您使用的是Windows主机请联系管理员将该文件设为everyone可写'); @ $fp = fopen($file, 'wb') OR emMsg('读取文件失败如果您使用的是Unix/Linux主机请修改文件/content/plugins/reader_wall/reader_wall_config.php的权限为777。如果您使用的是Windows主机请联系管理员将该文件设为everyone可写');
@ $fw = fwrite($fp,$data) OR emMsg('写入文件失败如果您使用的是Unix/Linux主机请修改文件/content/plugins/reader_wall/reader_wall_config.php的权限为777。如果您使用的是Windows主机请联系管理员将该文件设为everyone可写'); @ $fw = fwrite($fp,$data) OR emMsg('写入文件失败如果您使用的是Unix/Linux主机请修改文件/content/plugins/reader_wall/reader_wall_config.php的权限为777。如果您使用的是Windows主机请联系管理员将该文件设为everyone可写');
fclose($fp); fclose($fp);
} }
?> ?>