|
| 1 | +<?php |
| 2 | +/** |
| 3 | + * 一款清爽的BGM播放器,需要您的主题支持pjax或者instantclick才能保证页面切换依旧播放 |
| 4 | + * |
| 5 | + * @package YoduPlayer |
| 6 | + * @author Jrotty |
| 7 | + * @version 1.2.0 |
| 8 | + * @link http://qqdie.com/archives/typecho-yoduplayer.html |
| 9 | + */ |
| 10 | +class YoduPlayer_Plugin implements Typecho_Plugin_Interface |
| 11 | +{ |
| 12 | + public static function activate() |
| 13 | + { |
| 14 | + Typecho_Plugin::factory('Widget_Archive')->header = array('YoduPlayer_Plugin', 'header'); |
| 15 | + Typecho_Plugin::factory('Widget_Archive')->footer = array('YoduPlayer_Plugin', 'footer'); |
| 16 | + } |
| 17 | + /* 禁用插件方法 */ |
| 18 | + public static function deactivate(){} |
| 19 | + public static function config(Typecho_Widget_Helper_Form $form){ |
| 20 | + |
| 21 | +$yoduc = new Typecho_Widget_Helper_Form_Element_Radio( |
| 22 | + 'yoduc', array('0'=> '默认', '1'=> 'YoDu主题'), 0, '主题选择', |
| 23 | + '使用默认即可,如果你是用的YoDu主题模板,选择第二个不会额外加载字体文件,并且会根据yodu主题皮肤自动变色'); |
| 24 | + $form->addInput($yoduc); |
| 25 | + |
| 26 | + |
| 27 | + |
| 28 | + $bof = new Typecho_Widget_Helper_Form_Element_Radio( |
| 29 | + 'bof', array('0'=> '不自动播放', '1'=> '自动播放'), 0, '播放设置', |
| 30 | + '自动播放顾名思义,就是页面打开后音乐就会自动播放'); |
| 31 | + $form->addInput($bof); |
| 32 | + |
| 33 | +$sxj = new Typecho_Widget_Helper_Form_Element_Radio( |
| 34 | + 'sxj', array('0'=> '隐藏', '1'=> '不隐藏'), 0, '手机端是/否隐藏', |
| 35 | + ''); |
| 36 | + $form->addInput($sxj); |
| 37 | + $musicList = new Typecho_Widget_Helper_Form_Element_Textarea('musicList', NULL, |
| 38 | +'{title:"Alice",artist:"米白",mp3:"//p2.music.126.net/7_DtDbZXhlm-FWGzplUocg==/18802748347310691.mp3",cover:"//p3.music.126.net/R86tDfWlpXzhJFO1KJgfbQ==/17924238556217288.jpg?param=106x106",}, |
| 39 | +{title:"Old Memory",artist:"三輪学",mp3:"//p2.music.126.net/_b_IF6-KM0UHDJwP9u0Bdw==/1394180758436430.mp3",cover:"//p3.music.126.net/OpgpNNPKznDDMxoBqVJy-Q==/2464005557906815.jpg?param=106x106",}, |
| 40 | +',_t('歌曲列表'), _t('格式: {title:"xxx", artist:"xxx", mp3:"http:xxxx",cover:"图片地址",} ,每个歌曲之间用英文,隔开。请保证歌曲列表里至少有一首歌!<br><br><div style="background-color:#56A5CE;padding:5px 8px;max-width:250px;border-radius: 2px;"><a href="'.Helper::options()->pluginUrl.'/YoduPlayer/wyapi.php" target="_blank" style="font-size:14px;color:#fff;outline:none;text-decoration:none;">网易云音乐id解析(主机需支持curl扩展)</a> |
| 41 | + </div>请自行去网易云音乐网页版获取音乐id(具体在每个音乐项目的网址最后会有个id)。<b>将解析出的音乐链接复制到上面歌曲列表里(注意检查与现有歌曲是否用英文,隔开)</b>')); |
| 42 | + $form->addInput($musicList); |
| 43 | + |
| 44 | + $sok = new Typecho_Widget_Helper_Form_Element_Textarea('sok', NULL, |
| 45 | +'',_t('自定义css'), _t('直接在这里输入css即可对播放器样式进行修改')); |
| 46 | + $form->addInput($sok); |
| 47 | + } |
| 48 | + |
| 49 | + public static function personalConfig(Typecho_Widget_Helper_Form $form){} |
| 50 | + public static function header(){ |
| 51 | +if(Typecho_Widget::widget('Widget_Options')->Plugin('YoduPlayer')->yoduc=='1'){ |
| 52 | + $cssUrl = Helper::options()->pluginUrl . '/YoduPlayer/yodu/player.css'; |
| 53 | + }else{ |
| 54 | + $cssUrl = Helper::options()->pluginUrl . '/YoduPlayer/css/player.css'; |
| 55 | +} |
| 56 | + echo '<link rel="stylesheet" href="' . $cssUrl . '">'; |
| 57 | +if(Typecho_Widget::widget('Widget_Options')->Plugin('YoduPlayer')->sxj=='0'){ |
| 58 | + echo '<style>@media only screen and (max-width:767px){#bgmplayer{display:none}}</style>'. "\n"; |
| 59 | +} |
| 60 | +if(Typecho_Widget::widget('Widget_Options')->Plugin('YoduPlayer')->yoduc=='1'){ |
| 61 | + |
| 62 | +if(Typecho_Widget::widget('Widget_Options')->skin && 'red'==Typecho_Widget::widget('Widget_Options')->skin){ |
| 63 | + echo '<style>#bgmplayer {background: #F1587E;}</style>'; |
| 64 | +} |
| 65 | +if(Typecho_Widget::widget('Widget_Options')->skin && 'purple'==Typecho_Widget::widget('Widget_Options')->skin){ |
| 66 | + echo '<style>#bgmplayer {background: #800080;}#jindu {background-color: #FF6363;}</style>'; |
| 67 | +} |
| 68 | +if(Typecho_Widget::widget('Widget_Options')->skin && 'black'==Typecho_Widget::widget('Widget_Options')->skin){ |
| 69 | + echo '<style>#bgmplayer {background: #000000;}#jindu {background-color: #CCC;}</style>'; |
| 70 | +} |
| 71 | +if(Typecho_Widget::widget('Widget_Options')->skin && 'hei'==Typecho_Widget::widget('Widget_Options')->skin){ |
| 72 | + echo '<style>#bgmplayer {background: rgba(0, 0, 0, 0.5);}#jindu {background-color: rgba(251, 251, 251, 0.68);}</style>'; |
| 73 | +} |
| 74 | +if(Typecho_Widget::widget('Widget_Options')->skin && 'bai'==Typecho_Widget::widget('Widget_Options')->skin){ |
| 75 | + echo '<style>#bgmplayer {background: rgba(255,255,255,0.8);color: black;box-shadow: 0 0 5px #ccc;}#jindu {background-color: rgba(0, 0, 0, 0.32);}</style>'; |
| 76 | +} |
| 77 | +if(Typecho_Widget::widget('Widget_Options')->skin && 'block'==Typecho_Widget::widget('Widget_Options')->skin){ |
| 78 | + echo '<style>#bgmplayer {box-shadow: 0 0 5px #5D5D5D;border-radius: 0 0 0 5px;}#jindu {border-radius: 0 0 0 5px;}</style>'; |
| 79 | +} |
| 80 | +if(Typecho_Widget::widget('Widget_Options')->skin && 'old'==Typecho_Widget::widget('Widget_Options')->skin){ |
| 81 | + echo '<style>#bgmplayer {background: #888;}</style>'; |
| 82 | +} |
| 83 | + |
| 84 | +} |
| 85 | + |
| 86 | + echo '<style>'.Typecho_Widget::widget('Widget_Options')->plugin('YoduPlayer')->sok.'</style>'; |
| 87 | + } |
| 88 | + |
| 89 | + public static function footer(){ |
| 90 | + $options = Typecho_Widget::widget('Widget_Options')->plugin('YoduPlayer'); |
| 91 | + |
| 92 | + echo ' |
| 93 | +<div id="bgmplayer" class="bgmplayer"> |
| 94 | +<span class="bgmbuttom" onClick="qiehuan();" > |
| 95 | +<i id="ydmusic" class="iconfont icon-music"></i> |
| 96 | +</span> |
| 97 | +<div id="bgmpanel"> |
| 98 | +<div class="bgmfm"><img id="ydfm" src=""></div> |
| 99 | +<div class="bgmtitle"><span id="ydtitle">音乐加载中... |
| 100 | +</span></div> |
| 101 | +<div class="bgmtime"><span id="ytime">0:00</span></div> |
| 102 | +<div class="bgmbtn"> |
| 103 | +<span onClick="previous();"><i class="iconfont icon-zuo"></i></span> |
| 104 | +<span onclick="playbtu();"><i id="ydmc"></i></span> |
| 105 | +<span onclick="next();"><i class="iconfont icon-you"></i></span> |
| 106 | +</div> |
| 107 | +</div><div id="jindu"></div></div> |
| 108 | + '; |
| 109 | + |
| 110 | + echo '<script data-no-instant> |
| 111 | +var yaudio = new Audio(); |
| 112 | +yaudio.controls = true; |
| 113 | +yaudio.loop = false; |
| 114 | +var musicArr=[ |
| 115 | +'.$options->musicList.' |
| 116 | + ]; |
| 117 | +var a=0; |
| 118 | +var sj=musicArr[a]; |
| 119 | +yaudio.src=sj.mp3; |
| 120 | +yaudio.ti=sj.title; |
| 121 | +yaudio.art=sj.artist; |
| 122 | +yaudio.fm=sj.cover;'; |
| 123 | +if(Typecho_Widget::widget('Widget_Options')->Plugin('YoduPlayer')->bof=='1'){ |
| 124 | + echo 'yaudio.play();'. "\n"; |
| 125 | +} |
| 126 | +echo '</script>'; |
| 127 | + |
| 128 | + echo '<script src="'.Helper::options()->pluginUrl . '/YoduPlayer/js/player.js" data-no-instant></script>' . "\n"; |
| 129 | + echo '<script src="'.Helper::options()->pluginUrl . '/YoduPlayer/js/prpr.js"></script>' . "\n"; |
| 130 | + } |
| 131 | + |
| 132 | +} |
0 commit comments