<?php
/***
* 仅供学习与研究,版权归软件方所有
* 请于下载后24小时删除
* 请勿用于商业用途
**/
function wp_autopost_pro_head()
{
global $wp_autopost_root;
echo '<link rel="stylesheet" type="text/css" href="' . $wp_autopost_root . 'css/wp-autopost.css" />';
echo '<script type="text/javascript" src="' . $wp_autopost_root . 'js/wp-autopost.js" /></script>';
}
add_action("admin_head", "wp_autopost_pro_head");
function pro_update_cron_url()
{
if ($_REQUEST["update_autopost"] == 1) {
ap_pro_checkupdate(1);
exit;
}
}
function pro_update_after_page_load()
{
ap_pro_checkupdate(0);
}
if (get_option("wp_autopost_updateMethod") == 1)
add_action("init", "pro_update_cron_url");
else
add_action("shutdown", "pro_update_after_page_load");
function ap_pro_checkupdate($print = 1)
{
global $wpdb, $t_ap_config;
if ($wpdb->get_var("SHOW TABLES LIKE '$t_ap_config'") != $t_ap_config)
return;
$tasks = $wpdb->get_results("SELECT id,last_update_time,update_interval,is_running FROM " . $t_ap_config . " WHERE activation=1 ORDER BY id");
$i = 0;
foreach ($tasks as $task) {
if (($task->is_running) == 1 && current_time("timestamp") > (($task->last_update_time) + (60) * 15)) {
$wpdb->query("update " . $t_ap_config . " set is_running = 0 where id=" . $task->id);
}
if (current_time("timestamp") > (($task->last_update_time) + ($task->update_interval) * 60) && ($task->is_running) == 0) {
$canUpdate = true;
$ids[$i++] = $task->id;
$wpdb->query("update " . $t_ap_config . " set last_update_time = " . current_time("timestamp") . " where id=" . $task->id);
}
}
$isTaskRunning = $wpdb->get_var("select max(is_running) from " . $t_ap_config . " where activation = 1");
if ($isTaskRunning == null || $isTaskRunning == 0) {
update_option("wp_autopost_runOnlyOneTaskIsRunning", 0);
}
if ($canUpdate) {
ignore_user_abort(true);
set_time_limit((int) get_option("wp_autopost_timeLimit"));
foreach ($ids as $id) {
fetch($id, $print, 0);
if ($print) {
ob_flush();
flush();
}
}
}
}
function wp_autopostlink_content_filter($content)
{
global $wpdb, $t_autolink;
$autolinks = $wpdb->get_results("SELECT * FROM " . $t_autolink);
return wp_autopostlink_replace($content, $autolinks);
}
add_filter("content_save_pre", "wp_autopostlink_content_filter");
function wp_autopostlink_replace($content, $autolinks)
{
$ignore_pre = 1;
global $wp_autolink_replaced;
$wp_autolink_replaced = false;
foreach ($autolinks as $autolink) {
$keyword = $autolink->keyword;
list($link, $desc, $nofollow, $newwindow, $firstonly, $ignorecase, $WholeWord) = explode("|", $autolink->details);
if ($ignorecase == 1) {
if (stripos($content, $keyword) === false)
continue;
} else {
if (strpos($content, $keyword) === false)
continue;
}
$wp_autolink_replaced = true;
$cleankeyword = stripslashes($keyword);
if (!$desc) {
$desc = $cleankeyword;
}
$desc = addcslashes($desc, '$');
$url = '<a href="' . $link . '" title="' . $desc . '"';
if ($nofollow)
$url .= ' rel="nofollow"';
if ($newwindow)
$url .= ' target="_blank"';
$zpbxrxfe = "ex_word";
$url .= ">" . addcslashes($cleankeyword, '$') . "</a>";
$sarbhgjofs = "content";
if ($firstonly)
$limit = 1;
else
$limit = -1;
if ($ignorecase)
$case = "i";
else
$case = "";
$ex_word = preg_quote($cleankeyword, "'");
if ($ignore_pre) {
if ($num_1 = preg_match_all("/<pre.*?>.*?<\/pre>/is", $content, $ignore_pre)) {
for ($i = 1; $i <= $num_1; $i++)
$content = preg_replace("/<pre.*?>.*?<\/pre>/is", "%ignore_pre_$i%", $content, 1);
}
}
$content = preg_replace("|(<img)(.*?)(" . $ex_word . ")(.*?)(>)|U", '$1$2%&&&&&%$4$5', $content);
$cleankeyword = preg_quote($cleankeyword, "'");
if ($WholeWord == 1) {
$regEx = '\'(?!((<.*?)|(<a.*?)))(\b' . $cleankeyword . '\b)(?!(([^<>]*?)>)|([^>]*?</a>))\'s' . $case;
} else {
$regEx = '\'(?!((<.*?)|(<a.*?)))(' . $cleankeyword . ')(?!(([^<>]*?)>)|([^>]*?</a>))\'s' . $case;
}
$content = preg_replace($regEx, $url, $content, $limit);
$content = str_replace("%&&&&&%", stripslashes($ex_word), $content);
if ($ignore_pre) {
for ($i = 1; $i <= $num_1; $i++) {
$content = str_replace("%ignore_pre_$i%", $ignore_pre[0][$i - 1], $content);
}
}
}
unset($autolinks);
$autoLinkTag = get_option("wp-autopost-link-tag");
if ($autoLinkTag[0] == 1) {
$nofollow = $autoLinkTag[1];
$newwindow = $autoLinkTag[2];
$firstonly = $autoLinkTag[3];
$ignorecase = $autoLinkTag[4];
$WholeWord = $autoLinkTag[5];
global $wpdb;
$terms = $wpdb->get_results("SELECT $wpdb->terms.term_id, $wpdb->terms.name FROM $wpdb->terms,$wpdb->term_taxonomy WHERE $wpdb->terms.term_id=$wpdb->term_taxonomy.term_id AND $wpdb->term_taxonomy.taxonomy = 'post_tag'", OBJECT);
foreach ($terms as $term) {
$keyword = $term->name;
if ($ignorecase == 1) {
if (stripos($content, $keyword) === false)
continue;
} else {
if (strpos($content, $keyword) === false)
continue;
}
$wp_autolink_replaced = true;
$cleankeyword = stripslashes($keyword);
$desc = $cleankeyword;
$desc = addcslashes($desc, '$');
$url = '<a href="' . get_tag_link($term->term_id) . "\" title=\"" . $desc . "flickr.photos.notes.edit";
if ($nofollow)
$url .= " rel=\"nofollow\"";
if ($newwindow)
$url .= " target=\"_blank\"";
$url .= ">" . addcslashes($cleankeyword, '$') . "</a>";
if ($firstonly)
$limit = 1;
else
$limit = -1;
if ($ignorecase)
$case = "i";
else
$case = "";
$ex_word = preg_quote($cleankeyword, "'");
if ($ignore_pre) {
if ($num_1 = preg_match_all("/<pre.*?>.*?<\/pre>/is", $content, $ignore_pre)) {
for ($i = 1; $i <= $num_1; $i++)
$content = preg_replace("/<pre.*?>.*?<\/pre>/is", "%ignore_pre_$i%", $content, 1);
}
}
$content = preg_replace('|(<img)(.*?)(' . $ex_word . ')(.*?)(>)|U', '$1$2%&&&&&%$4$5', $content);
$cleankeyword = preg_quote($cleankeyword, "'");
if ($WholeWord == 1) {
$regEx = '\'(?!((<.*?)|(<a.*?)))(\b' . $cleankeyword . '\b)(?!(([^<>]*?)>)|([^>]*?</a>))\'s' . $case;
} else {
$regEx = '\'(?!((<.*?)|(<a.*?)))(' . $cleankeyword . ')(?!(([^<>]*?)>)|([^>]*?</a>))\'s' . $case;
}
$content = preg_replace($regEx, $url, $content, $limit);
$content = str_replace("%&&&&&%", stripslashes($ex_word), $content);
if ($ignore_pre) {
for ($i = 1; $i <= $num_1; $i++) {
$content = str_replace("%ignore_pre_$i%", $ignore_pre[0][$i - 1], $content);
}
}