热门推荐
WordPress文章下载增强插件源码 支持几乎所有网盘
2024-12-26 10:35
<?php namespace core_download; class Plugin { static function init() { add_action('admin_menu', [static::class, 'regMenu']); add_action('add_meta_boxes', [static::class, 'addmetaBox']); add_action('save_post', [static::class, 'savemetaBox']); add_filter('the_content', [static::class, 'addDownloadWrap']); add_action('wp_footer', [static::class, 'handleFooter']); add_action('admin_footer', [static::class, 'adminFooter']); } static function handleFooter() { global $core_download_set; print_r("<style>.core-download-warp {--theme-color: " . $core_download_set['set']['theme_color'] . ";--border-radius:" . $core_download_set['set']['border_radius'] . "px;}</style>"); } static function addDownloadWrap($content) { $post_id = get_the_ID(); $download_data = Options::getmetaBoxOptions($post_id); global $core_download_set; if (!$download_data['open'] || count($download_data['download_list']) == 0 || $core_download_set['set']['open'] === false) { return $content; } $list = $download_data['download_list']; $download_data_html = ''; foreach ($list as $item) { $item['icon'] = file_get_contents(Config::$img_dir . "/icon/{$item['name']}.svg"); $item['copy_icon'] = Config::$img_url . "/copy.svg"; $item['netdisk_name'] = self::netdiskNameToWord($item['name']); if ($item['resource_name'] == '') { $item['hide_netdisk_name'] = 'true'; } if ($item['key'] == '') { $item['hide_key'] = 'true'; $item['key'] = '无'; } $download_data_html .= Template::getTemplateHtmlByDOMdocument('download-url-item', $item); } $data['download_data'] = $download_data_html; $data['title'] = get_the_title(); $data['open_link'] = file_get_contents(Config::$img_dir . "/open-link.svg"); $data['content'] = stripslashes(base64_decode($download_data['content'])); $data['copyright_str'] = $core_download_set['set']['copyright_str']; $data['front_logo'] = file_get_contents(Config::$img_dir . "/front_logo.svg"); $data['warn_icon'] = file_get_contents(Config::$img_dir . "/warn_icon.svg"); $data['complaint_url'] = $core_download_set['set']['complaint_url']; $content .= Template::getTemplateHtml('download-warp', $data); return $content; } static function netdiskNameToWord($name) { $cloud_list = [ 'local' => '本地下载', 'aliyun' => '阿里云盘', 'baidu' => '百度云盘', '360' => '360网盘', 'ct' => '诚通网盘', 'lanzou' => '蓝奏云', '123' => '123盘', 'github' => 'github', 'quark' => '夸克', 'uc' => 'UC', 'weiyun' => '微云', 'wenshushu' => '文叔叔', 'xunlei' => '迅雷', 'jianguo' => '坚果云', 'tianyi' => '天翼云', 'hecai' => '和彩云', 'onedrive' => 'OneDrive' ]; return $cloud_list[$name]; } static function regMenu()

WordPress文章下载增强插件源码 支持几乎所有网盘

{ global $core_download_set; if ($core_download_set['set']['need_update'] === true) { $menu_html = '<span class="awaiting-mod">new</span>'; } else { $menu_html = ''; } add_menu_page('下载增强 CoreDownload', '下载增强' . $menu_html, 'administrator', 'core_download_set', function () { require_once Config::$plugin_dir . '/pages/admin-set.php'; }, 'dashicons-icon-core-download'); } static function addmetaBox() { add_meta_box( 'core_download_meta_box', '<div class="core_download_meta_box-title">Core Download 下载增强</div>', [static::class, 'rendermetaBox'], // 渲染meta Box的回调函数 'post', 'normal', 'high' ); } static function rendermetaBox() { $data = Options::getmetaBoxOptions(get_the_ID()); WordPress::echoJson('core_download_mete_box', $data); WordPress::echoJson('core_download_download_url_default', Options::getmetaBoxDownLoadUrlDefaultOptions()); $editor_settings = array( 'media_buttons' => false, 'teeny' => false, 'tinymce' => array( 'toolbar1' => 'formatselect,bold,underline,blockquote,forecolor,alignleft,aligncenter,alignright,link,unlink,bullist,numlist,,undo,redo,fullscreen,wp_help', 'toolbar2' => '', 'height' => 100, ), ); wp_editor(stripslashes(base64_decode($data['content'])), 'core_download_content', $editor_settings); ?> <div id="core-download-meta-box"></div> <?php } static function savemetaBox($post_id) { if (defined('DOING_AUTOSAVE') && DOING_AUTOSAVE) { return; } if (!current_user_can('edit_post', $post_id)) { return; } if (isset($_POST['core_download_meta_box']) && isset($_POST['core_download_content'])) { $data = json_decode(stripslashes($_POST['core_download_meta_box']), true); $data['content'] = base64_encode($_POST['core_download_content']); // file_put_contents(Config::$plugin_dir . "/log1.txt", stripslashes(base64_decode($data['content']))); Options::savemetaBoxData($post_id, base64_encode(json_encode($data))); } } static function adminFooter() { $data['ajax_url'] = admin_url('admin-ajax.php'); $data['ajax_name'] = Config::$plugin_name; print_r("<script>jQuery.post('" . $data['ajax_url'] . "',{action:'" . $data['ajax_name'] . "',fun:'checkUpdate'})</script>"); ?> <?php } static function getPluginInfo() { $url = Config::$plugin_server_url . "&url=" . $_SERVER['HTTP_HOST']; $request = new WP_Http; $result = $request->request($url); if (!is_wp_error($result)) { $json = json_decode($result['body'], true); if ($json['code'] == 200) { $data['version'] = $json['data']['version']; $data['dev_version'] = $json['data']['dev_version']; $data['all_package_url'] = $json['data']['all_package_url']; $data['all_package_url_md5'] = $json['data']['all_package_url_md5']; return $data; } } else { return false; } return false; }
    以上就是本篇文章【WordPress文章下载增强插件源码 支持几乎所有网盘】的全部内容了,欢迎阅览 ! 文章地址:https://sicmodule.kub2b.com/quote/13303.html 
     栏目首页      相关文章      动态      同类文章      热门文章      网站地图      返回首页 企库往资讯移动站https://sicmodule.kub2b.com/mobile/,查看更多   
发表评论
0评