'http://'
) , $atts));
return '' . $content . '';
}
add_shortcode("dl", "DownloadUrl");
//添加钮git
function GithubUrl($atts, $content = null) {
extract(shortcode_atts(array(
"href" => 'http://'
) , $atts));
return '' . $content . '';
}
add_shortcode('gt', 'GithubUrl');
//添加钮Demo
function DemoUrl($atts, $content = null) {
extract(shortcode_atts(array(
"href" => 'http://'
) , $atts));
return '' . $content . '';
}
add_shortcode('dm', 'DemoUrl');
//使用短代码添加回复后可见内容开始
function reply_to_read($atts, $content = null) {
extract(shortcode_atts(array(
"notice" => '
注意:本段内容须成功“回复本文”后“刷新本页”方可查看!
'
) , $atts));
$email = null;
$user_ID = get_current_user_id();
if ($user_ID > 0) {
$email = get_user_by('id', $user_ID)->user_email;
//对博主直接显示内容
$admin_email = get_bloginfo('admin_email');
if ($email == $admin_email) {
return $content;
}
} else if (isset($_COOKIE['comment_author_email_' . COOKIEHASH])) {
$email = str_replace('%40', '@', $_COOKIE['comment_author_email_' . COOKIEHASH]);
} else {
return $notice;
}
if (empty($email)) {
return $notice;
}
global $wpdb;
$post_id = get_the_ID();
$query = "SELECT `comment_ID` FROM {$wpdb->comments} WHERE `comment_post_ID`={$post_id} and `comment_approved`='1' and `comment_author_email`='{$email}' LIMIT 1";
if ($wpdb->get_results($query)) {
return do_shortcode($content);
} else {
return $notice;
}
}
add_shortcode('reply', 'reply_to_read');
//绿色提醒框
function toz($atts, $content = null) {
return '' . $content . '
';
}
add_shortcode('v_notice', 'toz');
//红色提醒框
function toa($atts, $content = null) {
return '' . $content . '
';
}
add_shortcode('v_error', 'toa');
//黄色提醒框
function toc($atts, $content = null) {
return '' . $content . '
';
}
add_shortcode('v_warn', 'toc');
//灰色提醒框
function tob($atts, $content = null) {
return '' . $content . '
';
}
add_shortcode('v_tips', 'tob');
//蓝色提醒框
function tod($atts, $content = null) {
return '' . $content . '
';
}
add_shortcode('v_blue', 'tod');
//蓝边文本框
function toe($atts, $content = null) {
return '' . $content . '
';
}
add_shortcode('v_act', 'toe');
//灵魂按钮
function tom($atts, $content = null) {
extract(shortcode_atts(array(
"href" => 'http://'
) , $atts));
return '' . $content . '';
}
add_shortcode('lhb', 'tom');
//添加视频按钮
function too($atts, $content = null) {
extract(shortcode_atts(array(
"play" => '0'
) , $atts));
if ($play == 0) {
return '';
}
if ($play == 1) {
return '';
}
}
add_shortcode('video', 'too');
//添加音频按钮
function tkk($atts, $content = null) {
extract(shortcode_atts(array(
"play" => '0'
) , $atts));
if ($play == 0) {
return '';
}
if ($play == 1) {
return '';
}
}
add_shortcode('audio', 'tkk');
//弹窗下载
function ton($atts, $content = null) {
extract(shortcode_atts(array(
"href" => 'http://',
"filename" => '',
"filesize" => '',
"filedown" => ''
) , $atts));
return '文件下载下载声明:
' . gdk_option('gdk_fancydlcp') . '
文件信息:
文件名称:' . $filename . '
文件大小:' . $filesize . '
发布日期:' . get_the_modified_time('Y年n月j日') . '
[更多地址] : ' . $content . '
';
}
add_shortcode('fanctdl', 'ton');
//代码演示短代码
function gdk_demo($atts, $content = null) {
return '' . $content . '';
}
add_shortcode('demo', 'gdk_demo');
//下载单页短代码
function gdk_download($atts, $content = null) {
return '' . $content . '';
}
add_shortcode('download', 'gdk_download');
//为WordPress添加展开收缩功能
function xcollapse($atts, $content = null) {
extract(shortcode_atts(array(
"title" => ""
) , $atts));
return '';
}
add_shortcode('collapse', 'xcollapse');
//简单的下载面板
function xdltable($atts, $content = null) {
extract(shortcode_atts(array(
"file" => "",
"size" => ""
) , $atts));
return '文件下载 | 文件名称:' . $file . ' | 文件大小:' . $size . ' |
下载声明:' . gdk_option('gdk_dltable_b') . ' |
下载地址:' . $content . ' |
';
}
add_shortcode('dltable', 'xdltable');
//网易云音乐
function music163($atts, $content = null) {
extract(shortcode_atts(array(
"play" => "1"
) , $atts));
return '';
}
add_shortcode('netmusic', 'music163');
//登录可见
function login_to_read($atts, $content = null) {
$logina = '登录';
extract(shortcode_atts(array(
"notice" => '注意:本段内容须“' . $logina . '”后方可查看!
'
) , $atts));
if (is_user_logged_in() && !is_null($content) && !is_feed()) {
return '';
}
return $notice;
}
add_shortcode('vip', 'login_to_read');
// 部分内容输入密码可见
function e_secret($atts, $content = null) {
extract(shortcode_atts(array('wx' => null) , $atts));
$pid = get_the_ID();
add_post_meta($pid, '_pass_content', $content, true) or update_post_meta($pid, '_pass_content', $content);
if ( current_user_can( 'administrator' ) || gdk_is_weixin()) { return $content; }//admin show
return '
';
}
add_shortcode('secret', 'e_secret');
// 支持文章和页面运行PHP代码id
function php_include($attr) {
$file = $attr['file'];
$upload_dir = wp_upload_dir();
$folder = $upload_dir['basedir'] . '/php-content' . "/{$file}.php";
ob_start();
include $folder;
return ob_get_clean();
}
add_shortcode('phpcode', 'php_include');
//给文章加内链短代码
function gdk_insert_posts($atts, $content = null) {
extract(shortcode_atts(array(
'ids' => ''
) , $atts));
global $post;
$content = '';
$postids = explode(',', $ids);
$inset_posts = get_posts(array(
'post__in' => $postids
));
foreach ($inset_posts as $key => $post) {
setup_postdata($post);
$content.= '';
}
wp_reset_postdata();
return $content;
}
add_shortcode('neilian', 'gdk_insert_posts');
//给文章加内链短代码
function gdk_insert_temp($atts, $content = null) {
extract(shortcode_atts(array( 'id' => '' ) , $atts));
$data = get_post($id);
$content = $data->post_content;
return $content;
}
add_shortcode('temp', 'gdk_insert_temp');
//快速插入列表
function gdk_list_shortcode_handler($atts, $content = '') {
$lists = explode("\n", $content);
$ouput = '';
foreach ($lists as $li) {
if (trim($li) != '') {
$output.= "{$li}";
}
}
$output .= "\n";
return $output;
}
add_shortcode('list', 'gdk_list_shortcode_handler');
//表格短代码
function table_shortcode_handler( $atts, $content='' ) {
extract( shortcode_atts( ['width' => '100%'], $atts ) );
$output = '';
$content = trim($content);
$trs = explode("\r\n", $content);
$ths = explode(" ", $trs[0]);//表头数组
$output .= '';
//var_dump($ths);
foreach($ths as $th){
$th = trim($th);
$output .= ''.$th.' | ';
}
$output .= '
';
$output .= '';
unset($trs[0]);
foreach($trs as $tr){
$tr = trim($tr);
if($tr){
$tds = explode(" ", $tr);
$output .= '';
foreach($tds as $td){
$td = trim($td);
if($td){
$output .= ''.$td.' | ';
}
}
$output .= '
';
}
}
$output .= '';
$width = ' width="'.$width.'"';
$output = '';
return $output;
}
add_shortcode( 'table', 'table_shortcode_handler' );
add_shortcode('youku', function( $atts, $content='') {
extract( shortcode_atts( array(
'width' => '510',
'height' => '498'
), $atts ) );
$width = (isset($_GET['width']) && intval($_GET['width']))?intval($_GET['width']):$width; // 用于 JSON 接口
$height = round($width/4*3);
if(preg_match('#http://v.youku.com/v_show/id_(.*?).html#i',$content,$matches)){
return '';
}
});
add_shortcode('qqv', function($atts, $content='') {
extract( shortcode_atts( array(
'width' => '510',
'height' => '498'
), $atts ) );
$width = (isset($_GET['width']) && intval($_GET['width']))?intval($_GET['width']):$width; // 用于 JSON 接口
$height = round($width/4*3);
if(preg_match('#//v.qq.com/iframe/player.html\?vid=(.+)#i',$content,$matches)){
//var_dump($matches);exit();
return '';
}elseif(preg_match('#//v.qq.com/iframe/preview.html\?vid=(.+)#i',$content,$matches)){
//var_dump($matches);exit();
return '';
}
});
add_shortcode('tudou', function($atts, $content=''){
extract( shortcode_atts( array(
'width' => '480',
'height' => '400'
), $atts ) );
$width = (isset($_GET['width']) && intval($_GET['width']))?intval($_GET['width']):$width; // 用于 JSON 接口
$height = round($width/4*3);
if(preg_match('#http://www.tudou.com/programs/view/(.*?)#i',$content, $matches)){
return '';
}
});
add_shortcode('sohutv', function($atts, $content=''){
extract( shortcode_atts( array(
'width' => '510',
'height' => '498'
), $atts ) );
$width = (isset($_GET['width']) && intval($_GET['width']))?intval($_GET['width']):$width; // 用于 JSON 接口
$height = round($width/4*3);
if(preg_match('#http://tv.sohu.com/upload/static/share/share_play.html\#(.+)#i',$content,$matches)){
//var_dump($matches);exit();
return '';
}
});
//WordPress 段代码按钮集合
function gdk_shortcode_list() {
$wpshortcodes = [
'横线'=>'
',
'H2标题'=>'
',
'H3标题'=>'
',
'记号笔'=>' ',
'链接按钮'=>'[dm href=] [/dm]',
'下载按钮'=>'[dl href=] [/dl]',
'透明按钮'=>'[lhb href=] [/lhb]',
'视频按钮'=>'[video play=0] [/video]',
'音频按钮'=>'[audio play=0] [/audio]',
'绿色通知'=>'[v_notice] [/v_notice]',
'红色警告'=>'[v_error] [/v_error]',
'黄色错误'=>'[v_warn] [/v_warn]',
'灰色提示'=>'[v_tips] [/v_tips]',
'蓝边提示'=>'[v_act] [/v_act]',
'隐藏收缩'=>'[collapse title=\'\'] [/collapse]',
'回复可见'=>'[reply] [/reply]',
'登陆可见'=>'[vip] [/vip]',
'密码可见'=>'[secret wx=0] [/secret]',
'积分购买可见'=>'[pay point=\'10\']这里是需要付费的内容[/pay]',
'游客付费可见'=>'[pax money=1]',
'弹窗下载'=>'[fanctdl filename=\'这里填写文件名\' filepass=\'这里填写文件密码什么的\' href=\'这里填写的主下载链接\' filedown=\'这里填写的是文件的主下载名称\']这里填写的文件的辅助下载链接,可写多个,空格间隔[/fanctdl]',
'面板下载'=>'[dltable file=\'在此处写下文件名称\' pass=\'在这里写下文件密码\']这里填写的文件的辅助下载链接,可写多个,空格间隔[/dltable]',
'单页下载'=>'[pdownload title=]',
'文章内链'=>'[neilian ids=]',
'无序列表'=>'[list] [/list]',
'表格简码'=>'[table] [/table]'
];
$output = '';
foreach ($wpshortcodes as $name => $alt) {
$output.= '' . $name . '';
}
return $output;
}
function gdk_shortcode_button($context) {
$context = '短代码' . gdk_shortcode_list() . '
';
return $context;
}
add_action('media_buttons_context', 'gdk_shortcode_button');