';
global $post;
$homeLink = home_url();
echo '
' . $hometitle . ' ' . $delimiter . ' ';
if (is_category()) {
// 分类 存档
global $wp_query;
$cat_obj = $wp_query->get_queried_object();
$thisCat = $cat_obj->term_id;
$thisCat = get_category($thisCat);
$parentCat = get_category($thisCat->parent);
if ($thisCat->parent != 0) {
$cat_code = get_category_parents($parentCat, true, ' ' . $delimiter . ' ');
echo $cat_code = str_replace('
' . get_the_time('Y') . ' ' . $delimiter . ' ';
echo '
' . get_the_time('F') . ' ' . $delimiter . ' ';
echo $before . get_the_time('d') . $after;
} elseif (is_month()) {
// 月 存档
echo '
' . get_the_time('Y') . ' ' . $delimiter . ' ';
echo $before . get_the_time('F') . $after;
} elseif (is_year()) {
// 年 存档
echo $before . get_the_time('Y') . $after;
} elseif (is_single() && !is_attachment()) {
// 文章
if (get_post_type() != 'post') {
// 自定义文章类型
$post_type = get_post_type_object(get_post_type());
$slug = $post_type->rewrite;
echo '
' . $post_type->labels->singular_name . ' ' . $delimiter . ' ';
echo $before . get_the_title() . $after;
} else {
// 文章 post
$cat = get_the_category();
$cat = $cat[0];
$cat_code = get_category_parents($cat, true, ' ' . $delimiter . ' ');
echo $cat_code = str_replace('
labels->singular_name . $after;
} elseif (is_attachment()) {
// 附件
$parent = get_post($post->post_parent);
$cat = get_the_category($parent->ID);
$cat = $cat[0];
echo '' . $parent->post_title . ' ' . $delimiter . ' ';
echo $before . get_the_title() . $after;
} elseif (is_page() && !$post->post_parent) {
// 页面
echo $before . get_the_title() . $after;
} elseif (is_page() && $post->post_parent) {
// 父级页面
$parent_id = $post->post_parent;
$breadcrumbs = array();
while ($parent_id) {
$page = get_page($parent_id);
$breadcrumbs[] = '
' . get_the_title($page->ID) . '';
$parent_id = $page->post_parent;
}
$breadcrumbs = array_reverse($breadcrumbs);
foreach ($breadcrumbs as $crumb) {
echo $crumb . ' ' . $delimiter . ' ';
}
echo $before . get_the_title() . $after;
} elseif (is_search()) {
// 搜索结果
echo $before;
printf(__('Search Results for: %s', 'cmp'), get_search_query());
echo $after;
} elseif (is_tag()) {
//标签 存档
echo $before;
printf(__('Tag Archives: %s', 'cmp'), single_tag_title('', false));
echo $after;
} elseif (is_author()) {
// 作者存档
global $author;
$userdata = get_userdata($author);
echo $before;
printf(__('Author Archives: %s', 'cmp'), $userdata->display_name);
echo $after;
} elseif (is_404()) {
// 404 页面
echo $before;
_e('Not Found', 'cmp');
echo $after;
}
if (get_query_var('paged')) {
// 分页
if (is_category() || is_day() || is_month() || is_year() || is_search() || is_tag() || is_author()) {
echo sprintf(__('( Page %s )', 'cmp'), get_query_var('paged'));
}
}
echo '
';
}
}
//设置cookie数据
function gdk_set_cookie($key, $value, $expire)
{
$expire = ($expire < time()) ? $expire + time() : $expire;
$secure = ('https' === parse_url(get_option('home'), PHP_URL_SCHEME));
setcookie($key, $value, $expire, COOKIEPATH, COOKIE_DOMAIN, $secure);
if (COOKIEPATH != SITECOOKIEPATH) {
setcookie($key, $value, $expire, SITECOOKIEPATH, COOKIE_DOMAIN, $secure);
}
$_COOKIE[$key] = $value;
}
//判断是否是电话号码,是号码返回 true 不是返回false
function gdk_is_mobile_number($number)
{
return (bool)preg_match('/^0{0,1}(1[3,5,8][0-9]|14[5,7]|166|17[0,1,3,6,7,8]|19[8,9])[0-9]{8}$/', $number);
}
//获取纯文本
function gdk_plain_text($text)
{
$text = wp_strip_all_tags($text);
$text = str_replace('"', '', $text);
$text = str_replace('\'', '', $text);
$text = str_replace("\r\n", ' ', $text);
$text = str_replace("\n", ' ', $text);
$text = str_replace(" ", ' ', $text);
return trim($text);
}
// 获取第一段
function gdk_first_p($text)
{
if ($text) {
$text = explode("\n", trim(strip_tags($text)));
$text = trim($text['0']);
}
return $text;
}
//获取当前页面链接
function gdk_get_current_url()
{
$ssl = (!empty($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == 'on') ? true : false;
$sp = strtolower($_SERVER['SERVER_PROTOCOL']);
$protocol = substr($sp, 0, strpos($sp, '/')) . (($ssl) ? 's' : '');
$port = $_SERVER['SERVER_PORT'];
$port = ((!$ssl && $port == '80') || ($ssl && $port == '443')) ? '' : ':' . $port;
$host = $_SERVER['HTTP_X_FORWARDED_HOST'] ?? $_SERVER['HTTP_HOST'] ?? $_SERVER['SERVER_NAME'];
return $protocol . '://' . $host . $port . $_SERVER['REQUEST_URI'];
}
//发起HTTP请求
function gdk_http_request($url, $args = array(), $err_args = array())
{
$args = wp_parse_args($args, array(
'timeout' => 3,
'method' => '',
'body' => array(),
'sslverify' => false,
'blocking' => true, // 如果不需要立刻知道结果,可以设置为 false
'stream' => false, // 如果是保存远程的文件,这里需要设置为 true
'filename' => null, // 设置保存下来文件的路径和名字
'need_json_decode' => true, //对结果进行解码,一般都需要
'need_json_encode' => false, //对发起参数编码
// 'headers' => array('Accept-Encoding'=>'gzip;'), //使用压缩传输数据
// 'headers' => array('Accept-Encoding'=>''),
// 'compress' => false,
'decompress' => true,
));
$need_json_decode = $args['need_json_decode'];
$need_json_encode = $args['need_json_encode'];
$method = ($args['method']) ? strtoupper($args['method']) : ($args['body'] ? 'POST' : 'GET');
unset($args['need_json_decode']);
unset($args['need_json_encode']);
unset($args['method']);
if ($method == 'GET') {
$response = wp_remote_get($url, $args);
} elseif ($method == 'POST') {
if ($need_json_encode && is_array($args['body'])) {
$args['body'] = json_encode($args['body']);
}
$response = wp_remote_post($url, $args);
} elseif ($method == 'HEAD') {
if ($need_json_encode && is_array($args['body'])) {
$args['body'] = json_encode($args['body']);
}
$response = wp_remote_head($url, $args);
} else {
if ($need_json_encode && is_array($args['body'])) {
$args['body'] = json_encode($args['body']);
}
$response = wp_remote_request($url, $args);
}
if (is_wp_error($response)) {
trigger_error($url . "\n" . $response->get_error_code() . ' : ' . $response->get_error_message() . "\n" . var_export($args['body'], true));
return $response;
}
$headers = $response['headers'];
$response = $response['body'];
if ($need_json_decode || isset($headers['content-type']) && strpos($headers['content-type'], '/json')) {
if ($args['stream']) {
$response = file_get_contents($args['filename']);
}
$response = json_decode($response, true);
if (is_wp_error($response)) {
return $response;
}
}
extract(wp_parse_args($err_args, array(
'errcode' => 'errcode',
'errmsg' => 'errmsg',
'detail' => 'detail',
'success' => 0,
)));
if (isset($response[$errcode]) && $response[$errcode] != $success) {
$errcode = $response[$errcode];
$errmsg = isset($response[$errmsg]) ? $response[$errmsg] : '';
if (isset($response[$detail])) {
$detail = $response[$detail];
trigger_error($url . "\n" . $errcode . ' : ' . $errmsg . "\n" . var_export($detail, true) . "\n" . var_export($args['body'], true));
return new WP_Error($errcode, $errmsg, $detail);
} else {
trigger_error($url . "\n" . $errcode . ' : ' . $errmsg . "\n" . var_export($args['body'], true));
return new WP_Error($errcode, $errmsg);
}
}
return $response;
}
//根据腾讯视频网址或者ID互相转化
function gdk_get_qq_vid($id_or_url)
{
if (filter_var($id_or_url, FILTER_VALIDATE_URL)) {
if (preg_match('#https://v.qq.com/x/page/(.*?).html#i', $id_or_url, $matches)) {
return $matches[1];
} elseif (preg_match('#https://v.qq.com/x/cover/.*/(.*?).html#i', $id_or_url, $matches)) {
return $matches[1];
} else {
return '';
}
} else {
return $id_or_url;
}
}
//根据秒拍id或者网站获取视频直连
function get_video_mp4($id_or_url)
{
if (filter_var($id_or_url, FILTER_VALIDATE_URL)) {
if (preg_match('#http://www.miaopai.com/show/(.*?).htm#i', $id_or_url, $matches)) {
return 'http://gslb.miaopai.com/stream/' . esc_attr($matches[1]) . '.mp4';
} elseif (preg_match('#https://v.qq.com/x/page/(.*?).html#i', $id_or_url, $matches)) {
return get_qqv_mp4($matches[1]);
} elseif (preg_match('#https://v.qq.com/x/cover/.*/(.*?).html#i', $id_or_url, $matches)) {
return get_qqv_mp4($matches[1]);
} else {
return str_replace(['%3A', '%2F'], [':', '/'], urlencode($id_or_url));
}
} else {
return get_qqv_mp4($id_or_url);
}
}
//获取腾讯视频
function get_qqv_mp4($vid)
{
if (strlen($vid) > 20) {
return new WP_Error('invalid_qqv_vid', '非法的腾讯视频 ID');
}
$mp4 = wp_cache_get($vid, 'qqv_mp4');
if ($mp4 === false) {
$response = gdk_http_request('http://vv.video.qq.com/getinfo?otype=json&platform=11001&vid=' . $vid, array(
'timeout' => 4,
'need_json_decode' => false,
));
if (is_wp_error($response)) {
return $response;
}
$response = trim(substr($response, strpos($response, '{')), ';');
$response = json_decode($response);
if (is_wp_error($response)) {
return $response;
}
if (empty($response['vl'])) {
return new WP_Error('illegal_qqv', '该腾讯视频不存在或者为收费视频!');
}
$u = $response['vl']['vi'][0];
$p0 = $u['ul']['ui'][0]['url'];
$p1 = $u['fn'];
$p2 = $u['fvkey'];
$mp4 = $p0 . $p1 . '?vkey=' . $p2;
wp_cache_set($vid, $mp4, 'qqv_mp4', HOUR_IN_SECONDS * 6);
}
return $mp4;
}
//字符串转数组,默认分隔符是:,
function gdk_str2arr($data, $delimiter = ',')
{
// 数组原样返回
if (is_array($data)) {
return $data;
}
// 字符串处理
$string = (string)$data;
if (empty($string)) {
$result = [];
} elseif (preg_match('/^{.*?}$/', $string) || preg_match('/^\[.*?]$/', $string)) {
$result = json_decode($string, true);
} elseif (preg_match('/^a:.*?(})$/', $string)) {
$result = unserialize($string, null);
} elseif (strpos($string, $delimiter) >= 1) {
$result = explode($delimiter, $string);
} else {
$result = [];
}
if (!is_array($result) || count($result) < 1) {
return [];
}
return $result;
}
//根据连接特征获取网盘连接来源
function gdk_panlinks($links)
{
if (!filter_var($url, FILTER_VALIDATE_URL)) {
return false;
}
if (in_string($links, 'baidu')) {
$linknane = '百度网盘';
} elseif (in_string($links, 'yunpan')) {
$linknane = '360云盘';
} elseif (in_string($links, 'lanzous')) {
$linknane = '蓝奏网盘';
} elseif (in_string($links, '189')) {
$linknane = '天翼云盘';
} elseif (in_string($links, 'mega')) {
$linknane = 'MEGA云盘';
} elseif (in_string($links, 'yadi.sk')) {
$linknane = '毛子云盘';
} elseif (in_string($links, 'cdn')) {
$linknane = 'CDN';
} elseif (in_string($links, 'ctfile')) {
$linknane = '360云盘';
} elseif (in_string($links, 'weiyun')) {
$linknane = '腾讯微云';
} else {
$linknane = '下载';
}
return $linknane;
}
//一个简单可重复使用的邮件模板
function mail_temp($mail_title, $mail_cotent, $link, $link_title)
{
$content = '/i', $post->post_content, $matches);
$gdk_thumbnail_src = $matches[1][0]; //获取该图片 src
if (empty($gdk_thumbnail_src)) {
//如果日志中没有图片,则显示随机图片
$random = mt_rand(1, 12);
$gdk_thumbnail_src = GDK_BASE_URL . 'assets/img/thumb/' . $random . '.jpg';
}
}
;
return $gdk_thumbnail_src;
}
/**
* 获取略缩图,输出img标签代码
* @param [init] $way 缩略图方案代码,1=cdn,2=timthumb,3=aq_resize
* @param [init] $width 缩略图宽度
* @param [init] $height 缩略图高度
* @param [string] $atrr img标签的属性
* @return [string] img标签的图片代码
*/
function gdk_thumb_img($way, $width, $height, $atrr = 'class="thumb_img"')
{
$url = gdk_thumbnail_src();
if ($way === 1) {
//cdn
$src = $url . gdk_thumb_style($width, $height);
} elseif ($way === 2) {
$src = GDK_BASE_URL . 'public/timthumb.php?src=' . $url . '&h=' . $height . '&w=' . $width . '&q=90&zc=1&ct=1';
} elseif ($way === 3) {
$src = aq_resize($url, $width, $height, true);
if (empty($src)) {
$src = GDK_BASE_URL . 'public/timthumb.php?src=' . $url . '&h=' . $height . '&w=' . $width . '&q=90&zc=1&ct=1';
}
} else {
return false;
}
echo '';
}
//生成订单号编码
function gdk_order_id()
{
date_default_timezone_set('Asia/Shanghai');
$order_id = 'E' . date("YmdHis") . mt_rand(10000, 99999);
return $order_id;
}
//生成随机数
function randomString($length = 11)
{
return substr(str_shuffle(str_repeat($x = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ', ceil($length / strlen($x)))), 1, $length);
}
//获取云落的远程通知,加入缓存,12小时一次
function gdk_Remote_Notice($url = 'https: //u.gitcafe.net/api/notice.txt', $hours = 12)
{
$Yunluo_Notice = get_transient('Yunluo_Notice');
if (false === $Yunluo_Notice) {
$response = wp_remote_get($url);
if (is_array($response) && !is_wp_error($response)) {
set_transient('Yunluo_Notice', $response['body'], 60 * 60 * $hours); //缓存12小时
} else {
set_transient('Yunluo_Notice', '有点小尴尬哈啊,服务器菌暂时有点累了呢,先休息一会儿~,', 60 * 60 * $hours); //缓存12小时
}
}
return $Yunluo_Notice;
}
//获取页面id,并且不可重用
function gdk_page_id($pagephp)
{
global $wpdb;
$pagephp = esc_sql($pagephp);
$pageid = $wpdb->get_row("SELECT `post_id` FROM `{$wpdb->postmeta}` WHERE `meta_value` = 'pages/{$pagephp}.php'", ARRAY_A)['post_id'];
return $pageid;
}
//根据订单描述金币数据,d=订单号 u=用户id
function gdk_check($d, $u = null)
{
global $wpdb;
$des = " WHERE `description` = '" . $d . "'";
$userid = "";
if (isset($u) && ($u !== null)) {
$userid = " AND `user_id` = '" . $u . "'";
}
$result = $wpdb->query("SELECT `point_id` FROM " . GDK_Points_Database::points_get_table("users") . $des . $userid . " AND `status` = 'accepted' LIMIT 3", ARRAY_A);
return $result; //0=无订单结果,1=有订单结果,>1均为异常重复入库数据
}
//导航单页函数
function gdk_get_the_link_items($id = null)
{
$bookmarks = get_bookmarks('orderby=date&category=' . $id);
$output = '';
if (!empty($bookmarks)) {
foreach ($bookmarks as $bookmark) {
$output .= '';
}
}
return $output;
}
function gdk_get_link_items()
{
$linkcats = get_terms('link_category', 'orderby=count&hide_empty=1&exclude=' . gdk_option('gdk_link_id'));
$result = '';
foreach ($linkcats as $linkcat) {
$result .= '
' . $linkcat->name . '
';
$result .= gdk_get_the_link_items($linkcat->term_id);
$result .= '
';
}
return $result;
}
function gdk_get_Version()
{
echo '';
}
/*
* Payjs支付操作函数
* 订单标题
* 订单备注
* $_POST['money'] = 提交的金额,$_POST['way'] = 支付方式,支付宝为alipay,不设置默认微信,
*/
function payjs_action($body, $attach, $money)
{
$config = [
'mchid' => gdk_option('gdk_payjs_id'), // 配置商户号
'key' => gdk_option('gdk_payjs_key'), // 配置通信密钥
];
// 初始化
$payjs = new GDK_Payjs($config);
$data = [
'body' => $body, // 订单标题
'attach' => $attach, // 订单备注
'out_trade_no' => gdk_order_id(), // 订单号
'total_fee' => intval($money) * 100, // 金额,单位:分
'notify_url' => GDK_BASE_URL . '/public/notify.php', //异步通知文件
'hide' => '1',
];
$result['money'] = intval($money); //RMB金额
$result['trade_no'] = $data['out_trade_no'];
if ($_POST['way'] == 'alipay') {
$data['type'] = 'alipay';
$result['way'] = '支付宝';
} else {
$result['way'] = '微信';
}
if (gdk_is_mobile()) {
$rst = $payjs->cashier($data); //手机使用收银台
$result['img'] = $rst;
} else {
$rst = $payjs->native($data); //电脑使用扫码
$result['img'] = $rst['code_url'];
}
if (in_string($attach, 'PP')) { //如果是付费可见,增加一个参数
$result['mode'] = '1'; //1=付费可见
} else {
$result['mode'] = '0';
}
exit(implode('|', $result)); //以字符串形式返回并停止运行
}
//接受payjs支付结果推送
function payjs_notify()
{
// 配置通信参数
$config = [
'mchid' => gdk_option('gdk_payjs_id'), // 配置商户号
'key' => gdk_option('gdk_payjs_key'), // 配置通信密钥
];
$payjs = new GDK_Payjs($config);
$data = $payjs->notify(); //需要做签名性检查
// 对返回码判断
if ($data['return_code'] == 1) {
echo 'success';
return $data;
} else {
exit($data['return_msg']);
}
}
//充值按钮
function buy_points()
{
if (is_user_logged_in()) {
//logined
$result = '
点击充值
';
} else {
// no login
$result = '本页面需要您登录才可以操作,请先 ' . weixin_login_btn() . ' 或者
立即注册 ';
}
return $result;
}
//获取bing图
function get_bing_img()
{
$bing_imgurl = get_transient('Bing_img');
if (false === $bing_imgurl) {
$arr = json_decode(file_get_contents('https://cn.bing.com/HPImageArchive.aspx?format=js&idx=0&n=1'), true);
$bing_imgurl = 'https://cn.bing.com' . $arr['images'][0]['url'];
set_transient('Bing_img', $bing_imgurl, 60 * 60 * 12);
}
return $bing_imgurl;
}
function login_modal()
{
$result = '登录
';
$result .= wp_login_form(array(
'echo' => false,
'value_remember' => true,
'value_username' => '请输入用户名...',
));
$result .= '
';
return $result;
}
/**开始微信* */
//生成随机字符
//sk是12位随机字符, key格式是域名@sk
function gdk_weauth_token()
{
$strs = 'QWERTYUIOPASDFGHJKLZXCVBNM1234567890qwertyuiopasdfghjklzxcvbnm';
$sk = substr(str_shuffle($strs), mt_rand(0, strlen($strs) - 11), 12); //12位
set_transient($sk . '-OK', 1, 60); //1分钟缓存 get_transient($sk.'OK') == 1
$key = $_SERVER['HTTP_HOST'] . '@' . $sk;
return $key;
}
function gdk_weauth_qr()
{
$qr64 = [];
$qr64['key'] = gdk_weauth_token();
$qr64['qrcode'] = gdk_http_request('https://wa.isdot.net/qrcode?str=' . $qr64['key'])['qrcode'];
//$qr64['qrcode'] = gdk_http_request('https://api.goauth.jysafe.cn/qrcode?str='.$qr64['key'])['qrcode'];//预备使用,备胎
return $qr64;
}
/**
* 微信登陆按钮
*/
function weixin_login_btn()
{
$result = '微信登陆';
if (is_user_logged_in()) {
$user_id = get_current_user_id();
$user = get_user_by('id', $user_id);
if ($user_id > 0) {
if (!empty($user->user_email)) {
$result .= '';
}
}
//$result .= '您已登陆
您的ID是:'.$user_id.'
您的昵称是:'.$user->nickname.'
';
}
return $result;
}
//获取用户ID
function create_user_id($userdata)
{
$nickname = $userdata[0];
$wxavatar = $userdata[6];
$openid = $userdata[7];
$password = wp_generate_password(12, false);
$login_name = 'wx_' . wp_create_nonce($openid);
if (is_user_logged_in()) {
$user_id = get_current_user_id();
update_user_meta($user_id, 'wx_openid', $openid);
update_user_meta($user_id, 'wx_avatar', $wxavatar);
} else {
$weauth_user = get_users(array(
'meta_key ' => 'wx_openid',
'meta_value' => $openid,
)
);
if (is_wp_error($weauth_user) || !count($weauth_user)) {
$user_info = array(
'user_login' => $login_name,
'display_name' => $nickname,
'user_pass' => $password,
'nickname' => $nickname,
);
$user_id = wp_insert_user($user_info);
update_user_meta($user_id, 'wx_openid', $openid);
update_user_meta($user_id, 'wx_avatar', $wxavatar);
} else {
$user_id = $weauth_user[0]->ID;
}
}
return $user_id;
}
//生成hover颜色
function editorial_hover_color($hex, $steps)
{
// Steps should be between -255 and 255. Negative = darker, positive = lighter
$steps = max(-255, min(255, $steps));
// Normalize into a six character long hex string
$hex = str_replace('#', '', $hex);
if (strlen($hex) == 3) {
$hex = str_repeat(substr($hex, 0, 1), 2) . str_repeat(substr($hex, 1, 1), 2) . str_repeat(substr($hex, 2, 1), 2);
}
// Split into three parts: R, G and B
$color_parts = str_split($hex, 2);
$return = '#';
foreach ($color_parts as $color) {
$color = hexdec($color);
// Convert to decimal
$color = max(0, min(255, $color + $steps));
// Adjust color
$return .= str_pad(dechex($color), 2, '0', STR_PAD_LEFT);
// Make two char hex code
}
return $return;
}
/**
* Get minified css and removed space
*/
function pwd_minify_css($css)
{
// Normalize whitespace
$css = preg_replace('/\s+/', ' ', $css);
// Remove ; before }
$css = preg_replace('/;(?=\s*})/', '', $css);
// Remove space after , : ; { } */ >
$css = preg_replace('/(,|:|;|\{|}|\*\/|>) /', '$1', $css);
// Remove space before , ; { }
$css = preg_replace('/ (,|;|\{|})/', '$1', $css);
// Strips leading 0 on decimal values (converts 0.5px into .5px)
$css = preg_replace('/(:| )0\.([0-9]+)(%|em|ex|px|in|cm|mm|pt|pc)/i', '${1}.${2}${3}', $css);
// Strips units if value is 0 (converts 0px to 0)
$css = preg_replace('/(:| )(\.?)0(%|em|ex|px|in|cm|mm|pt|pc)/i', '${1}0', $css);
// Return minified CSS
return trim($css);
}
//生成微信验证码
function wx_captcha()
{
date_default_timezone_set('Asia/Shanghai');
$min = floor(date("i") / 2);
$day = date("d");
$day = ltrim($day, 0);
$home = home_url();
$wx_token = trim(gdk_option('gdk_wxmp_token'));
$captcha = sha1($min . $home . $wx_token);
$captcha = substr($captcha, $day, 6);
return $captcha;
}
function gdk_post_dropdown()
{
/* Option list of all post */
$gdk_options_posts = [];
$gdk_options_posts_obj = get_posts('posts_per_page=-1');
foreach ($gdk_options_posts_obj as $gdk_posts) {
$gdk_options_posts[$gdk_posts->ID] = $gdk_posts->post_title;
}
return $gdk_options_posts;
}
function gdk_categories_dropdown()
{
/* Option list of all categories */
$gdk_args = array(
'type' => 'post',
'orderby' => 'name',
'order' => 'ASC',
'hide_empty' => 1,
'hierarchical' => 1,
'taxonomy' => 'category',
);
$gdk_option_categories = [];
$gdk_category_lists = get_categories($gdk_args);
foreach ($gdk_category_lists as $gdk_category) {
$gdk_option_categories[$gdk_category->term_id] = $gdk_category->name;
}
return $gdk_option_categories;
}
function gdk_tag_dropdown()
{
/* Option list of all tags */
$gdk_args = array(
'type' => 'post',
'orderby' => 'name',
'order' => 'ASC',
'hide_empty' => 1,
'hierarchical' => 1,
'taxonomy' => 'tag',
);
$gdk_option_tags = [];
$gdk_tag_lists = get_tags($gdk_args);
$gdk_option_tags[''] = '选择标签';
foreach ($gdk_tag_lists as $gdk_tag) {
$gdk_option_tags[$gdk_tag->term_id] = $gdk_tag->name;
}
return $gdk_option_tag;
}
//转化图片为base64格式
function base64img($image_file)
{
$base64_image = '';
$image_info = getimagesize($image_file);
$image_data = file_get_contents($image_file);
$base64_image = 'data:' . $image_info['mime'] . ';base64,' . base64_encode($image_data);
return $base64_image;
}
//生成二维码
function getQrcode($url)
{
//引入phpqrcode类库
require_once GDK_ROOT_PATH . '/class/qrcode.class.php';
$errorCorrectionLevel = 'L'; //容错级别
$matrixPointSize = 6; //生成图片大小
ob_start();
QRcode::png($url, false, $errorCorrectionLevel, $matrixPointSize, 2);
$data = ob_get_contents();
ob_end_clean();
$imageString = base64_encode($data);
header("content-type:application/json; charset=utf-8");
return 'data:image/jpeg;base64,' . $imageString;
}
function unzip_url($url, $where)
{
$zippath = $where . '/' . (basename($url)) . '.zip';
wp_remote_get($url,
[
'timeout' => 300,
'stream' => true,
'filename' => $zippath,
]
);
require_once ABSPATH . 'wp-admin/includes/file.php';
\WP_Filesystem();
\unzip_file($zippath, $where);
usleep(300000);
@unlink($zippath);
}
//新窗口打开
function blank_open()
{
if (!gdk_option('gdk_target_blank')) {
echo 'target="_blank"';
}
}
function gdk_guest_form()
{
?>