-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathPlugin.php
More file actions
155 lines (131 loc) · 4.47 KB
/
Plugin.php
File metadata and controls
155 lines (131 loc) · 4.47 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
<?
/**
* 博客时间线
*
* @package storyline
* @author letonode
* @version 0.0.1
* @link http://www.letonife.com
*/
class Storyline_Plugin implements Typecho_Plugin_Interface
{
/**
* 激活插件方法,如果激活失败,直接抛出异常
*
* @access public
* @return void
* @throws Typecho_Plugin_Exception
*/
public static function activate(){
return _t('日志时间线 启用成功 : 建议使用独立页面模板内.');
}
/**
* 禁用插件方法,如果禁用失败,直接抛出异常
*
* @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() {
$userJSON = FALSE;
$init = '';
if($userJSON == TRUE){
$init = "timeline.init('/usr/Storyline.json');";
} else {
$init = "timeline.init();";
}
$options = Helper::options();
if($userJSON == TRUE){
$file="./usr/Storyline.json";
if($file){
writeStoryData($file,$options);
}
}
$style = Typecho_Common::url('Storyline/Timeline/timeline.css', $options->pluginUrl);
$jquery = Typecho_Common::url('Storyline/Timeline/jquery-min.js', $options->pluginUrl);
$timelinejs = Typecho_Common::url('Storyline/Timeline/timeline-min.js', $options->pluginUrl);
echo "<link rel=\"stylesheet\" type=\"text/css\" media=\"all\" href=\"{$style}\" /> ";
echo "<script type=\"text/javascript\" src=\"{$jquery}\"></script>";
echo "<script type=\"text/javascript\" src=\"{$timelinejs}\"></script>";
echo "<script>
$(document).ready(function() {
timeline = new VMM.Timeline();
timeline.init();
});
</script>";
echo "\n";
if($userJSON == TRUE){
echo "<div id=\"timeline\"></div>";
} else {
$pagedata = getPageData($options);
echo $pagedata;
}
}
}
function getPageData($options){
$pagedata = '<div id="timeline"><section><time>2006,1,1</time><h2>'.$options->title.'</h2><article><p>'.$options->description.'</p></article></section><ul>';
/**获取适配器名称 , Typecho_Db::SORT_DESC*/
$db = Typecho_Db::get();
/**获取日志总数*/
$result = $db->fetchAll($db->select()->from('table.contents')
->where('table.contents.status = ?', 'publish')
->where('table.contents.type = ?', 'post')
->order('table.contents.created'));
$size = sizeof($result);
for($i =0;$i < $size ; ++$i)
{
$post = $result[$i];
$value = Typecho_Widget::widget('Widget_Abstract_Contents')->push($post);
$pagedata = $pagedata.'<li>'.'<time> '.$value['date']->year.','.$value['date']->month.','. $value['date']->day .'</time>'.'<h3>'.$value['title'].'</h3>'.'</li>';
}
$pagedata = $pagedata.'</ul></div>';
return $pagedata;
}
function writeStoryData($file,$options){
$jsondata = '{"timeline":{"headline":"'.$options->title.'","type":"default","startDate":"2006","text":"'.$options->description.'","date": [';
/**获取适配器名称 , Typecho_Db::SORT_DESC*/
$db = Typecho_Db::get();
/**获取日志总数*/
$result = $db->fetchAll($db->select()->from('table.contents')
->where('table.contents.status = ?', 'publish')
->where('table.contents.type = ?', 'post')
->order('table.contents.created'));
$size = sizeof($result);
for($i =0;$i < 50; ++$i)
{
$post = $result[$i];
$value = Typecho_Widget::widget('Widget_Abstract_Contents')->push($post);
$jsondata = $jsondata.'{"startDate":"'.$value['date']->year.','.$value['date']->month.','.$value['date']->day.'","headline":"'.$value['title'].'"}';
if($i != 49){
$jsondata = $jsondata.',';
}
}
$jsondata = $jsondata.']}}';
$fp=@fopen($file,'w');
fwrite($fp,$jsondata);
fclose($fp);
}