This commit is contained in:
2012-10-31 21:13:20 +08:00
parent aa5ae34544
commit d5f3b47056
14 changed files with 223 additions and 264 deletions

View File

@@ -3,4 +3,11 @@ emlog 定时发布插件
定时自动发布保存为草稿的日志。
[插件主页](http://xiaosong.org/share/auto-pub-plugin-update)
使用方法:
--------------------
1. 通过后台安装插件;
2. 将你要预发布的文章统统写好但不要点发布,而是保存成草稿;
3. 在插件后台去设置插件的触发条件和设置你要发布文章的时间,并保存;
4. 木有了~元芳,对于此插件,你怎么看?
[插件主页](http://xiaosong.org/share/new-version-automatically-publish-plugin-released)

View File

@@ -1,35 +1,55 @@
<?php
/*
Plugin Name: 自动发布
Version: 1.9.3
Plugin URL: http://xiaosong.org/share/auto-pub-plugin-update
Version: 2.0.0
Plugin URL: http://xiaosong.org/share/new-version-automatically-publish-plugin-released
Description: 自动发布文章,修正时区问题,增加相关挂载点,自动删除缓存文件。
Author: 小松
Author Email: sahala_2007@126.com
Author URL: http://xiaosong.org
*/
!defined('EMLOG_ROOT') && exit('access deined!');
!defined('AUTOPUB_CACHE_DIR') && define('AUTOPUB_CACHE_DIR', EMLOG_ROOT.'/content/plugins/autopub/cache/');
function dir_is_empty($dir){
if($handle = opendir($dir)){
while($item = readdir($handle)){
if ($item != "." && $item != "..") {
return false;
function autopubAjax(){
echo '<script type="text/javascript">$(function(){$.get("'.BLOG_URL.'?plugin=autopub");})</script>'."\n";
}
function autopubPhp(){
echo '<script type="text/javascript">$(function(){$.ajax({url: "'.BLOG_URL.'content/plugins/autopub/autopub_cron.php",timeout: 1000,cache: false});})</script>'."\n";
}
function doPub(){
$DB = MySql::getInstance();
$CACHE = Cache::getInstance();
$autopub = unserialize(Option::get('autopub'));
$sql = "SELECT gid, content FROM ".DB_PREFIX."blog where hide ='y' order by date DESC";
$result = $DB->query($sql);
while($row = $DB->fetch_array($result)){
$key = 'post-'.$row['gid'];
if (isset($autopub[$key])) {
$pub_time = $autopub[$key];
if (time() >= $pub_time) {
$autopubCopyRight = '<!-- (此文通过<a href="http://xiaosong.org/share/auto-pub-plugin-update">emlog自动发布插件</a>发布) -->';
$condition = strpos($row['content'], $autopubCopyRight) === false ? ",content = '".addslashes($row['content'].$autopubCopyRight)."'" : "";
$sql_do = "UPDATE ".DB_PREFIX."blog SET hide = 'n',date = '".$pub_time."'".$condition." WHERE gid='".$row['gid']."'";
$DB->query($sql_do);
doAction('save_log', $row['gid']);
unset($autopub[$key]);
}
}
}
return true;
Option::updateOption('autopub', serialize($autopub));
$CACHE->updateCache();
}
function autopub(){
echo '<script type="text/javascript">$(function(){$.get("'.BLOG_URL.'?plugin=autopub");})</script>'."\n";
}
if (!dir_is_empty(AUTOPUB_CACHE_DIR)) {
emLoadJQuery();
addAction('index_footer', 'autopub');
addAction('adm_footer', 'autopub');
$autopubArray = unserialize(Option::get('autopub'));
if (count($autopubArray) > 1) {
if (isset($autopubArray['trigger']) && $autopubArray['trigger'] == 'ajax') {
emLoadJQuery();
addAction('index_footer', 'autopubAjax');
addAction('adm_footer', 'autopubAjax');
} else if (isset($autopubArray['trigger']) && $autopubArray['trigger'] == 'php') {
addAction('adm_footer', 'autopubPhp');
}
}
function autopub_menu() {

33
autopub_callback.php Normal file
View File

@@ -0,0 +1,33 @@
<?php
/**
* 自动发布插件
* @copyright (c) xiaosong.org All Rights Reserved
*/
if(!defined('EMLOG_ROOT')) {exit('error!');}
function callback_init(){
$DB = MySql::getInstance();
$is_exist_option = $DB->query("SELECT 1 FROM ".DB_PREFIX."options WHERE option_name='autopub'");
if (!$DB->num_rows($is_exist_option)) {
$DB->query("INSERT INTO ".DB_PREFIX."options (option_name, option_value) VALUES('autopub', '".serialize(array())."')");
}
$cacheDir = EMLOG_ROOT.'/content/plugins/autopub/cache/';
$sql = "SELECT gid FROM ".DB_PREFIX."blog where hide ='y' order by date DESC";
$result = $DB->query($sql);
$autopub = array();
while ($row = $DB->fetch_array($result)) {
if (file_exists($cacheDir.$row['gid'].'.php')) {
include_once($cacheDir.$row['gid'].'.php');
$pub_time = emStrtotime($year.'-'.$month.'-'.$day.' '.$hour.':'.$minute.':'.$second);
$key = 'post-'.$row['gid'];
$autopub[$key] = $pub_time;
unlink($cacheDir.$row['gid'].'.php');
}
}
emDeleteFile($cacheDir);
Option::updateOption('autopub', serialize($autopub));
$CACHE = Cache::getInstance();
$CACHE->updateCache('options');
}
?>

21
autopub_cron.php Normal file
View File

@@ -0,0 +1,21 @@
<?php
/**
* 自动发布插件
* @copyright (c) xiaosong.org All Rights Reserved
*/
ignore_user_abort(true);
set_time_limit(0);
if (!defined('EMLOG_ROOT')) {
require_once('../../../init.php');
}
do {
clearstatcache();
$run = EMLOG_ROOT.'/content/plugins/autopub/autopub_cron_pid.php';
if(!file_exists($run)) die('do nothing');
doPub();
sleep(30);
} while (true);
?>

0
autopub_cron_pid.php Normal file
View File

View File

@@ -1,75 +1,91 @@
<?php
/**
* autopub_setting.php
* design by 小松
* 自动发布插件
* @copyright (c) xiaosong.org All Rights Reserved
*/
!defined('EMLOG_ROOT') && exit('access deined!');
!defined('AUTOPUB_CACHE_DIR') && define('AUTOPUB_CACHE_DIR', EMLOG_ROOT.'/content/plugins/autopub/cache/');
function plugin_setting_view(){
$autopubArray = unserialize(Option::get('autopub'));
}
function adminview(){
$DB = MySql::getInstance();
$sql = "SELECT gid,title FROM ".DB_PREFIX."blog where hide ='y' and type = 'blog' order by date DESC";
$autopubArray = unserialize(Option::get('autopub'));
$timezone = Option::get('timezone');
$DB = MySql::getInstance();
$sql = "SELECT gid, title FROM ".DB_PREFIX."blog where hide ='y' and type = 'blog' order by date DESC";
$result = $DB->query($sql);
$i = 1;
while($row = $DB->fetch_array($result)){
if(file_exists(AUTOPUB_CACHE_DIR.$row['gid'].'.php')){
include_once(AUTOPUB_CACHE_DIR.$row['gid'].'.php');
}else{
$year = $month = $day = $hour = $minute = $second = '';
while ($row = $DB->fetch_array($result)) {
$key = 'post-'.$row['gid'];
if (isset($autopubArray[$key])) {
$pub_time = gmdate('Y-m-d H:i:s', $autopubArray[$key] + $timezone * 3600);
} else {
$pub_time = '';
}
$output .= '<form action="plugin.php?plugin=autopub&action=setting&pub='.$row['gid'].'" method="post"><p>';
$output .= $i.'、<a href="'.BLOG_URL.'admin/write_log.php?action=edit&gid='.$row['gid'].'">'.$row['title'].'</a>&nbsp;&nbsp;';
$output .= '预发布时间:<input name="year" type="text" value="'.$year.'" size="3" />年<input name="month" type="text" value="'.$month.'" size="3" />月<input name="day" type="text" value="'.$day.'" size="3" />日<input name="hour" type="text" value="'.$hour.'" size="3" />时<input name="minute" type="text" value="'.$minute.'" size="3" />分<input name="second" type="text" value="'.$second.'" size="3" />&nbsp;&nbsp;';
$output .= '预发布时间:<input name="pubTime" type="text" value="'.$pub_time.'" class="calendar" />&nbsp;&nbsp;';
$output .= '<input type="submit" value="保 存" class="submit" /></p></form>';
$i++;
}
if(empty($output)){
$output = '<p>暂无待发布日志!请将待发布日志保存为草稿!</p>';
if (empty($output)) {
$output = '<p>暂无待发布日志!请将待发布日志保存为草稿!</p>';
}
echo $output;
}
?>
<style type="text/css">
.calendar { background: url(<?php echo BLOG_URL; ?>content/plugins/autopub/skins/default/calendar.gif) no-repeat right 1px; cursor: pointer; padding-right: 20px; border: 1px solid #ABADB3; outline: 0 none; height: 18px; width: 160px; }
</style>
<script type="text/javascript" src="<?php echo BLOG_URL; ?>content/plugins/autopub/lhgcalendar.min.js"></script>
<script type="text/javascript">
$(function(){
$("#autopub").addClass('sidebarsubmenu1');
$('#autopub').addClass('sidebarsubmenu1');
$('input.calendar').calendar({format: 'yyyy-MM-dd HH:mm:ss'});
})
</script>
<div class="containertitle"><b>自动发布</b>
<?php if(isset($_GET['setting'])):?><span class="actived">插件设置完成</span><?php endif;?>
<?php if(isset($_GET['error'])):?><span class="error">插件设置失败,请填写合理日期!年月日必填</span><?php endif;?>
<?php if(isset($_GET['error'])):?><span class="error">插件设置失败</span><?php endif;?>
</div>
<div class="line"></div>
<div>
<p><b>插件设置:</b></p>
<form action="plugin.php?plugin=autopub&action=setting" method="post">
<p><label for="trigger_ajax"><input type="radio" name="trigger" value="ajax" id="trigger_ajax"<?php if (isset($autopubArray['trigger']) && $autopubArray['trigger'] == "ajax"): ?> checked<?php endif; ?>> ajax请求的方式触发自动发布有访客就能自动发布</label> <label for="trigger_php"><input type="radio" name="trigger" value="php" id="trigger_php"<?php if (isset($autopubArray['trigger']) && $autopubArray['trigger'] == "php"): ?> checked<?php endif; ?>> php定时触发自动发布无访客也能自动发布但会增加系统开销</label></p>
<p><input type="submit" value="保 存" class="submit" /></p>
</form>
<div class="line"></div>
<p><b>自动发布列表:</b></p>
<?php adminview(); ?>
</div>
<?php
function plugin_setting(){
if(isset($_GET['pub']))
{
$gid = isset($_GET['pub']) ? intval($_GET['pub']) : -1;
$year = isset($_POST['year']) ? intval($_POST['year']) : 0;
$month = isset($_POST['month']) ? intval($_POST['month']) : 0;
$day = isset($_POST['day']) ? intval($_POST['day']) : 0;
$hour = isset($_POST['hour']) ? intval($_POST['hour']) : 0;
$minute = isset($_POST['minute']) ? intval($_POST['minute']) : 0;
$second = isset($_POST['second']) ? intval($_POST['second']) : 0;
$data = "<?php
\$year = ".$year.";
\$month = ".$month.";
\$day = ".$day.";
\$hour = ".$hour.";
\$minute = ".$minute.";
\$second = ".$second.";
?>";
$file = AUTOPUB_CACHE_DIR.$gid.'.php';
if($year != 0 && $month != 0 && $day != 0){
@ $fp = fopen($file, 'wb') OR emMsg('读取文件失败如果您使用的是Unix/Linux主机请修改/content/plugins/autopub/cache/目录的权限为777。如果您使用的是Windows主机请联系管理员将该文件设为everyone可写');
@ $fw = fwrite($fp,$data) OR emMsg('写入文件失败如果您使用的是Unix/Linux主机请修改/content/plugins/autopub/cache/目录的权限为777。如果您使用的是Windows主机请联系管理员将该文件设为everyone可写');
fclose($fp);
}else{
return false;
$autopubArray = unserialize(Option::get('autopub'));
if (!isset($autopubArray['trigger'])) {
$autopubArray['trigger'] = 'ajax';
}
}
$trigger = isset($_POST['trigger']) ? trim($_POST['trigger']) : $autopubArray['trigger'];
$autopubArray['trigger'] = $trigger;
$run = EMLOG_ROOT.'/content/plugins/autopub/autopub_cron_pid.php';
clearstatcache();
if ($trigger == 'php') {
if (!file_exists($run)) {
$fp = fopen($run, 'wb') OR emMsg('读取文件失败如果您使用的是Unix/Linux主机请修改文件/content/plugins/autopub/的权限为755或777。如果您使用的是Windows主机请联系管理员将该文件设为everyone可写');
fclose($fp);
}
} else {
unlink($run);
}
if (isset($_GET['pub'])) {
$gid = isset($_GET['pub']) ? intval($_GET['pub']) : -1;
$pubTime = isset($_POST['pubTime']) ? trim($_POST['pubTime']) : '';
if ($gid > 0 && !empty($pubTime)) {
$key = 'post-'.$gid;
$autopubArray[$key] = emStrtotime($pubTime);
} else {
return false;
}
}
Option::updateOption('autopub', serialize($autopubArray));
$CACHE = Cache::getInstance();
$CACHE->updateCache('options');
}

View File

@@ -1,24 +1,13 @@
<?php
/**
* 自动发布插件
* @copyright (c) xiaosong.org All Rights Reserved
*/
!defined('EMLOG_ROOT') && exit('access deined!');
!defined('AUTOPUB_CACHE_DIR') && define('AUTOPUB_CACHE_DIR', EMLOG_ROOT.'/content/plugins/autopub/cache/');
set_time_limit(0);
$DB = MySql::getInstance();
$CACHE = Cache::getInstance();
$sql = "SELECT gid, content FROM ".DB_PREFIX."blog where hide ='y' order by date DESC";
$result = $DB->query($sql);
while($row = $DB->fetch_array($result)){
if(file_exists(AUTOPUB_CACHE_DIR.$row['gid'].'.php')){
include_once(AUTOPUB_CACHE_DIR.$row['gid'].'.php');
$pub_time = emStrtotime($year.'-'.$month.'-'.$day.' '.$hour.':'.$minute.':'.$second);
$autopubCopyRight = '<p style="text-align:right;font-size:12px;">(此文通过<a href="http://xiaosong.org/share/auto-pub-plugin-update">emlog自动发布插件</a>发布)</p>';
$content = $row['content'].$autopubCopyRight;
if(time() > $pub_time){
$sql_do = "UPDATE ".DB_PREFIX."blog SET hide = 'n',date = '".$pub_time."',content = '".addslashes($content)."' WHERE gid='".$row['gid']."'";
$DB->query($sql_do);
$CACHE->updateCache();
doAction('save_log', $row['gid']);
unlink(AUTOPUB_CACHE_DIR.$row['gid'].'.php');
}
}
$isAjax = (isset($_SERVER['HTTP_X_REQUESTED_WITH']) && strstr($_SERVER['HTTP_X_REQUESTED_WITH'], 'XMLHttpRequest')) ? 1 : 0;
if ($isAjax) {
doPub();
exit();
}
emDirect(BLOG_URL);
?>

22
cache/.gitattributes vendored
View File

@@ -1,22 +0,0 @@
# Auto detect text files and perform LF normalization
* text=auto
# Custom for Visual Studio
*.cs diff=csharp
*.sln merge=union
*.csproj merge=union
*.vbproj merge=union
*.fsproj merge=union
*.dbproj merge=union
# Standard to msysgit
*.doc diff=astextplain
*.DOC diff=astextplain
*.docx diff=astextplain
*.DOCX diff=astextplain
*.dot diff=astextplain
*.DOT diff=astextplain
*.pdf diff=astextplain
*.PDF diff=astextplain
*.rtf diff=astextplain
*.RTF diff=astextplain

162
cache/.gitignore vendored
View File

@@ -1,162 +0,0 @@
#################
## Eclipse
#################
*.pydevproject
.project
.metadata
bin/
tmp/
*.tmp
*.bak
*.swp
*~.nib
local.properties
.classpath
.settings/
.loadpath
# External tool builders
.externalToolBuilders/
# Locally stored "Eclipse launch configurations"
*.launch
# CDT-specific
.cproject
# PDT-specific
.buildpath
#################
## Visual Studio
#################
## Ignore Visual Studio temporary files, build results, and
## files generated by popular Visual Studio add-ons.
# User-specific files
*.suo
*.user
*.sln.docstates
# Build results
[Dd]ebug/
[Rr]elease/
*_i.c
*_p.c
*.ilk
*.meta
*.obj
*.pch
*.pdb
*.pgc
*.pgd
*.rsp
*.sbr
*.tlb
*.tli
*.tlh
*.tmp
*.vspscc
.builds
*.dotCover
## TODO: If you have NuGet Package Restore enabled, uncomment this
#packages/
# Visual C++ cache files
ipch/
*.aps
*.ncb
*.opensdf
*.sdf
# Visual Studio profiler
*.psess
*.vsp
# ReSharper is a .NET coding add-in
_ReSharper*
# Installshield output folder
[Ee]xpress
# DocProject is a documentation generator add-in
DocProject/buildhelp/
DocProject/Help/*.HxT
DocProject/Help/*.HxC
DocProject/Help/*.hhc
DocProject/Help/*.hhk
DocProject/Help/*.hhp
DocProject/Help/Html2
DocProject/Help/html
# Click-Once directory
publish
# Others
[Bb]in
[Oo]bj
sql
TestResults
ClientBin
stylecop.*
~$*
*.dbmdl
Generated_Code #added for RIA/Silverlight projects
# Backup & report files from converting an old project file to a newer
# Visual Studio version. Backup files are not needed, because we have git ;-)
_UpgradeReport_Files/
Backup*/
UpgradeLog*.XML
############
## Windows
############
# Windows image file caches
Thumbs.db
# Folder config file
Desktop.ini
#############
## Python
#############
*.py[co]
# Packages
*.egg
*.egg-info
dist
build
eggs
parts
bin
var
sdist
develop-eggs
.installed.cfg
# Installer logs
pip-log.txt
# Unit test / coverage reports
.coverage
.tox
#Translations
*.mo
#Mr Developer
.mr.developer.cfg
# Mac crap
.DS_Store

6
lhgcalendar.min.js vendored Normal file

File diff suppressed because one or more lines are too long

BIN
skins/default/calendar.gif Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 207 B

BIN
skins/default/default_s.gif Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 937 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 79 B

51
skins/lhgcalendar.css Normal file
View File

@@ -0,0 +1,51 @@
/*!
* lhgcore Calendar Plugin StyleSheet
* Copyright (c) 2009 - 2012 By Li Hui Gang
*/
.lcui_border{ font:12px/1.333 tahoma,arial,\5b8b\4f53,sans-serif;background-color:#fff; }
.lcui_lt,.lcui_rt,.lcui_lb,.lcui_rb,.lcui_l,.lcui_r,.cui_py,.cui_ny,.cui_pm,.cui_nm{ width:3px;background:url(default/default_s.gif) no-repeat; }
.lcui_lt,.lcui_rt{ height:10px; }
.lcui_lt{ background-position:-65px 0; }
.lcui_rt{ background-position:-69px 0; }
.lcui_lb,.lcui_rb{ height:3px; }
.lcui_lb{ background-position:-65px -11px; }
.lcui_rb{ background-position:-69px -11px; }
.lcui_l,.lcui_r{ background-repeat:repeat-y; }
.lcui_l{ background-position:-73px 0; }
.lcui_r{ background-position:-77px 0; }
.lcui_t,.lcui_b{ background:url(default/default_s2.gif) repeat-x;font-size:0; }
.lcui_t{ background-position:0 0; }
.lcui_b{ background-position:0 -10px; }
.lcui_head{ padding:5px 8px 3px; }
.lcui_body thead{ text-align:center;color:#0597db;font:14px "幼圆",Tahoma,Arial,sans-serif;font-weight:bold;height:18px; }
.cui_py{ display:block;width:9px;height:16px;background-position:-25px 0; }
.cui_ny{ display:block;width:9px;height:16px;background-position:-35px 0; }
.cui_iy{ width:40px;margin:0;padding:0;border:1px solid #eee;height:14px;font:12px tahoma,arial;cursor:pointer;text-align:center;_vertical-align:middle;margin-right:2px; }
.cui_pm{ display:block;width:9px;height:16px;background-position:-45px 0; }
.cui_nm{ display:block;width:9px;height:16px;background-position:-55px 0; }
.cui_im{ width:20px;margin:0;padding:0;border:1px solid #eee;height:14px;font:12px tahoma,arial;cursor:pointer;text-align:center;_vertical-align:middle;margin-right:2px; }
.cui_db td{ background-color:#f7f7f7;color:#999;font:11px verdana,arial,sans-serif;cursor:default;height:20px;width:24px;text-align:center; }
.cui_db a{ color:#000;text-decoration:none;display:block;height:20px;line-height:20px;width:24px;cursor:default; }
.cui_db a:hover,.cui_today{ background:#f3f3f3 url(default/default_s.gif) no-repeat;background-position:0 0; }
.cui_foot{ padding:2px 0 1px 0;_padding:1px 0 0; }
.lcui_today,.lcui_empty{ width:44px; }
.cui_tbtn,.cui_dbtn{ display:block;border:1px solid #999;color:#000;text-decoration:none;background-color:#f2f2f2;width:38px;height:17px;line-height:17px;line-height:20px\0; }
.cui_tbtn:hover,.cui_dbtn:hover{ border:1px solid #0a246a;background-color:#c2cbe0; }
.lcui_time input{margin:0;padding:0;border:1px solid #999;width:20px;height:17px;font:11px Verdana,Arial;text-align:center;background-color:#f2f2f2;line-height:17px;}
.cui_ymlist{ position:absolute;border:1px solid #0093d1;background-color:#fff;width:120px; }
.cui_lbox a{ display:block;padding:3px 0;background:#f7f7f7;text-decoration:none;cursor:default;color:#000;text-align:center;font:11px verdana,arial,sans-serif; }
.cui_lbox a:hover{ background:#3991d1;color:#fff; }
.cui_ybar{ background-color:#f7f7f7; }
.cui_ybar a{ display:block;text-decoration:none;text-align:center;color:#000; }