forked from typecho-fans/plugins
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
12 changed files
with
504 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,120 @@ | ||
<?php | ||
/** | ||
* 虾米音乐播放器 Hermit for typecho xiami music player | ||
* | ||
* @package Hermit | ||
* @author mufeng | ||
* @version 1.0.0 | ||
* @update: 2014.2.11 | ||
* @link http://mufeng.me/ | ||
*/ | ||
class Hermit_Plugin implements Typecho_Plugin_Interface | ||
{ | ||
/** | ||
* 激活插件方法,如果激活失败,直接抛出异常 | ||
* | ||
* @access public | ||
* @return void | ||
* @throws Typecho_Plugin_Exception | ||
*/ | ||
public static function activate() | ||
{ | ||
/** 添加文章 */ | ||
Typecho_Plugin::factory('admin/write-post.php')->bottom = array('Hermit_Plugin', 'render'); | ||
Typecho_Plugin::factory('admin/write-page.php')->bottom = array('Hermit_Plugin', 'render'); | ||
|
||
/** 前端输出处理接口 */ | ||
Typecho_Plugin::factory('Widget_Abstract_Contents')->excerptEx = array('Hermit_Plugin', 'parse'); | ||
Typecho_Plugin::factory('Widget_Abstract_Contents')->contentEx = array('Hermit_Plugin', 'parse'); | ||
Typecho_Plugin::factory('Widget_Archive')->header = array('Hermit_Plugin', 'headerScript'); | ||
Typecho_Plugin::factory('Widget_Archive')->footer = array('Hermit_Plugin', 'footerScript'); | ||
} | ||
|
||
/** | ||
* 禁用插件方法,如果禁用失败,直接抛出异常 | ||
* | ||
* @static | ||
* @access public | ||
* @return void | ||
* @throws Typecho_Plugin_Exception | ||
*/ | ||
public static function deactivate(){} | ||
|
||
/** | ||
* 获取插件配置面板 | ||
* | ||
* @access public | ||
* @param Typecho_Widget_Helper_Form $form 配置面板 | ||
* @return void | ||
*/ | ||
public static function config(Typecho_Widget_Helper_Form $form){} | ||
|
||
/** | ||
* 个人用户的配置面板 | ||
* | ||
* @access public | ||
* @param Typecho_Widget_Helper_Form $form | ||
* @return void | ||
*/ | ||
public static function personalConfig(Typecho_Widget_Helper_Form $form){} | ||
|
||
/** | ||
* 文章页添加一个发布音乐按钮 | ||
* | ||
* @access public | ||
* @return void | ||
*/ | ||
public static function render() | ||
{ | ||
$options = Helper::options(); | ||
$img_url = Typecho_Common::url('Hermit/assets/images/iconx.png', $options->pluginUrl); | ||
$css_url = Typecho_Common::url('Hermit/assets/style/hermit.admin.css', $options->pluginUrl); | ||
$js_url = Typecho_Common::url('Hermit/assets/script/hermit.admin.js', $options->pluginUrl); | ||
echo "<link rel=\"stylesheet\" type=\"text/css\" href=\"{$css_url}\" />\n"; | ||
echo "<script>var hermit_img_url = \"{$img_url}\";\n</script><script src='{$js_url}'></script>\n"; | ||
} | ||
|
||
/** | ||
* 短代码实现方法 [hermit]songlist#:1772276934,1772276930,1772276933[/hermit] [hermit]album#:1772276934[/hermit] | ||
* | ||
* @access public | ||
* @return void | ||
*/ | ||
public static function parse($text, $widget, $lastResult) | ||
{ | ||
$text = empty($lastResult) ? $text : $lastResult; | ||
if ($widget instanceof Widget_Archive) { | ||
$text = preg_replace("/\[hermit\](.+?)\[\/hermit\]/is", | ||
"<!--Hermit for typecho v1.0.0 start--><div class=\"hermit\" songs=\"\\1\"><div class=\"hermit-box\"><div class=\"hermit-controls\"><div class=\"hermit-button\"></div><div class=\"hermit-detail\">单击鼠标左键播放或暂停。</div><div class=\"hermit-duration\"></div><div class=\"hermit-listbutton\"></div></div><div class=\"hermit-prosess\"><div class=\"hermit-loaded\"></div><div class=\"hermit-prosess-bar\"><div class=\"hermit-prosess-after\"></div></div></div></div><div class=\"hermit-list\"></div></div><!--Hermit for typecho v1.0.0 end-->", | ||
$text); | ||
} | ||
return $text; | ||
} | ||
|
||
/** | ||
* 顶部CSS加载 | ||
* | ||
* @access public | ||
* @return void | ||
*/ | ||
public static function headerScript() | ||
{ | ||
$options = Helper::options(); | ||
$css_url = Typecho_Common::url('Hermit/assets/style/hermit.min.css', $options->pluginUrl); | ||
echo "<link rel=\"stylesheet\" type=\"text/css\" href=\"{$css_url}\" media=\"all\" />\n"; | ||
} | ||
|
||
/** | ||
* 底部Javascript加载 | ||
* | ||
* @access public | ||
* @return void | ||
*/ | ||
public static function footerScript() | ||
{ | ||
$options = Helper::options(); | ||
$swf_url = Typecho_Common::url('Hermit/assets/swf', $options->pluginUrl); | ||
$js_url = Typecho_Common::url('Hermit/assets/script/hermit.min.js', $options->pluginUrl); | ||
echo "<script>var hermit = {url: \"{$swf_url}\"};\n</script><script src='{$js_url}'></script>\n"; | ||
} | ||
} |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,123 @@ | ||
jQuery(document).ready(function($){ | ||
|
||
var _body = $('.body').first(); | ||
|
||
$('#wmd-button-bar').before('<div id="gohermit-container"><button id="gohermit" title="添加虾米音乐"><img src="'+hermit_img_url+'" width="16" height="16" />添加虾米音乐</button></div>'); | ||
|
||
|
||
|
||
|
||
var type = ['songlist', 'album'], | ||
|
||
send_to_editor = function(val){ | ||
$('#text').val( $('#text').val() + val ) | ||
}, | ||
|
||
do_songlist = function(){ | ||
var val = $('#hermit-song').val(), | ||
song = [], | ||
preg = /http:\/\/www.xiami.com\/song\/(\d+).*?/; | ||
|
||
|
||
val = val.split(/\r?\n/g); | ||
|
||
val = $.grep(val, function(e){ | ||
|
||
if( preg.test(e) ){ | ||
|
||
return true | ||
}else{ | ||
return false; | ||
} | ||
}); | ||
|
||
if( val.length > 0 ){ | ||
|
||
$.each(val, function(index, value){ | ||
song.push( value.match(preg)[1] ); | ||
|
||
}); | ||
|
||
val = '[hermit]songlist#:' + song.join(',') + '[/hermit]'; | ||
|
||
send_to_editor( val ); | ||
|
||
remove_hermit(); | ||
}else{ | ||
alert('错误的虾米歌曲地址'); | ||
} | ||
}, | ||
|
||
do_album = function(){ | ||
var val = $('#hermit-album').val(), | ||
//song = [], | ||
preg = /http:\/\/www.xiami.com\/album\/(\d+).*?/; | ||
|
||
|
||
if( preg.test(val) ){ | ||
|
||
val = val.match(preg)[1]; | ||
|
||
val = '[hermit]album#:' + val + '[/hermit]'; | ||
|
||
send_to_editor( val ); | ||
|
||
remove_hermit(); | ||
}else{ | ||
alert('错误的虾米专辑地址'); | ||
} | ||
}, | ||
|
||
remove_hermit = function(){ | ||
$('#gohermit').removeClass('selected'); | ||
$('#hermit-box').remove(); | ||
|
||
} | ||
|
||
|
||
_body.on('click', '#gohermit', function(e){ | ||
e.preventDefault(); | ||
|
||
$('#hermit-box').length > 0 ? ($(this).removeClass('selected'), $('#hermit-box').remove()) : ( $(this).addClass('selected'), $('#gohermit-container').after('<div id="hermit-box" class="postbox"><div id="hermit-content"><div id="hermit-tab"><ul id="hermit-tabul"><li class="hermit-tabli current">单曲</li><li class="hermit-tabli">专辑</li></ul></div><div id="hermit-body"><ul id="hermit-bodyul"><li class="hermit-bodyli current"><textarea id="hermit-song" placeholder="输入虾米歌曲地址,多个地址请回车换行"></textarea></li><li class="hermit-bodyli"><input type="text" id="hermit-album" placeholder="输入虾米专辑地址" /></li></ul></div></div><div id="hermit-action" class="clear"><a id="hermit-delete" class="submitdelete deletion" href="javascript:;">取消</a><button id="hermit-publish" class="primary">添加到文章中</button></div></div>') ); | ||
|
||
return false; | ||
}); | ||
|
||
|
||
_body.on('click', '#hermit-delete', function(e){ | ||
e.preventDefault(); | ||
remove_hermit() }); | ||
|
||
|
||
_body.on('click', '.hermit-tabli', function(e){ | ||
e.preventDefault(); | ||
if( !$(this).hasClass('current') ){ | ||
var index = $('.hermit-tabli').index($(this)); | ||
|
||
$('.hermit-tabli, .hermit-bodyli').removeClass('current'); | ||
|
||
$('.hermit-tabli:eq('+index+'), .hermit-bodyli:eq('+index+')').addClass('current') | ||
} | ||
return false; | ||
}); | ||
|
||
|
||
_body.on('click', '#hermit-publish', function(e){ | ||
|
||
e.preventDefault(); | ||
|
||
var index = $('.hermit-tabli').index( $('.hermit-tabli.current') ); | ||
|
||
switch( type[index] ){ | ||
case 'songlist': | ||
do_songlist(); | ||
break; | ||
|
||
case 'album': | ||
do_album(); | ||
break; | ||
} | ||
}); | ||
|
||
|
||
}); |
Oops, something went wrong.